compiles for 2.202/2.2011 whatever we'll call it

This commit is contained in:
matcool 2024-01-08 16:48:21 -03:00
parent b6a6b40913
commit 198948319b
6 changed files with 69 additions and 12 deletions

View file

@ -10,8 +10,6 @@ if (GEODE_BUILDING_DOCS)
set(GEODE_DONT_BUILD_TEST_MODS On)
endif()
set(GEODE_GD_VERSION 2.200)
# Read version
file(READ VERSION GEODE_VERSION)
string(STRIP "${GEODE_VERSION}" GEODE_VERSION)
@ -78,6 +76,17 @@ include(cmake/Platform.cmake)
include(cmake/GeodeFile.cmake)
include(cmake/CPM.cmake)
if (NOT DEFINED GEODE_GD_VERSION)
if (${GEODE_TARGET_PLATFORM} STREQUAL "Win32")
set(GEODE_GD_VERSION 2.202)
else()
set(GEODE_GD_VERSION 2.200)
endif()
endif()
target_compile_definitions(${PROJECT_NAME} INTERFACE GEODE_GD_VERSION=${GEODE_GD_VERSION})
set(MAT_JSON_AS_INTERFACE ON)
CPMAddPackage("gh:geode-sdk/json#49bdff7")
CPMAddPackage("gh:fmtlib/fmt#10.1.1")

View file

@ -42,7 +42,6 @@ enum class SearchType {
FavouriteLists = 103
};
// jesus fucking christ (painfully written by @hjfod)
enum class GameObjectType {
Solid = 0,
Hazard = 2,

Binary file not shown.

View file

@ -0,0 +1,46 @@
#pragma once
#include <unordered_map>
#include <string_view>
#include <Windows.h>
// Original by absolute
// https://gist.github.com/absoIute/ebe5da42d118109a03632c9751d86e19
inline std::string_view detectGDVersion() {
static const std::unordered_map<uint32_t, std::string_view> buildMap = {
{ 1419173053, "1.900" },
{ 1419880840, "1.910" },
{ 1421745341, "1.920" },
{ 1440638199, "2.000" },
{ 1440643927, "2.001" },
{ 1443053232, "2.010" },
{ 1443077847, "2.011" },
{ 1443077847, "2.020" },
{ 1484612867, "2.100" },
{ 1484626658, "2.101" },
{ 1484737207, "2.102" },
{ 1510526914, "2.110" },
{ 1510538091, "2.111" },
{ 1510619253, "2.112" },
{ 1511220108, "2.113" },
{ 1702921605, "2.200" },
{ 1704582672, "2.201" },
{ 1704601266, "2.202" },
};
auto hMod = GetModuleHandleA(NULL);
auto dosHeader = reinterpret_cast<PIMAGE_DOS_HEADER>(hMod);
if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
auto ntHeader = reinterpret_cast<PIMAGE_NT_HEADERS>(reinterpret_cast<uintptr_t>(hMod) + dosHeader->e_lfanew);
if (ntHeader->Signature == IMAGE_NT_SIGNATURE) {
auto timeStamp = ntHeader->FileHeader.TimeDateStamp;
if (auto it = buildMap.find(timeStamp); it != buildMap.end())
return it->second;
}
}
return "";
}

View file

@ -4,6 +4,7 @@
#include "../load.hpp"
#include <Windows.h>
#include "VersionDetect.hpp"
#include "loader/LoaderImpl.hpp"
using namespace geode::prelude;
@ -41,8 +42,10 @@ int WINAPI gdMainHook(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
return reinterpret_cast<decltype(&wWinMain)>(mainTrampolineAddr)(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}
bool loadGeode() {
// TODO: add version check or something
std::string loadGeode() {
if (detectGDVersion() != GEODE_STR(GEODE_GD_VERSION)) {
return "GD version mismatch, not loading geode.";
}
auto process = GetCurrentProcess();
@ -52,7 +55,7 @@ bool loadGeode() {
MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE
);
static constexpr uintptr_t MAIN_OFFSET = 0x3ba7d0;
static constexpr uintptr_t MAIN_OFFSET = 0x3bdfd0;
auto patchAddr = geode::base::get() + MAIN_OFFSET;
constexpr size_t patchSize = 6;
@ -86,10 +89,10 @@ bool loadGeode() {
DWORD oldProtect;
if (!VirtualProtectEx(process, reinterpret_cast<void*>(patchAddr), patchSize, PAGE_EXECUTE_READWRITE, &oldProtect))
return false;
return "Geode could not hook the main function, not loading geode.";
std::memcpy(reinterpret_cast<void*>(patchAddr), patchBytes, patchSize);
VirtualProtectEx(process, reinterpret_cast<void*>(patchAddr), patchSize, oldProtect, &oldProtect);
return true;
return "";
}
DWORD WINAPI upgradeThread(void*) {
@ -156,9 +159,9 @@ BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID) {
}
else if (oldBootstrapperExists)
CreateThread(nullptr, 0, upgradeThread, nullptr, 0, nullptr);
else if (!loadGeode()) {
earlyError("There was an unknown error hooking the GD main function.");
return FALSE;
else if (auto error = loadGeode(); !error.empty()) {
earlyError(error);
return TRUE;
}
}
catch(...) {

View file

@ -1,6 +1,6 @@
#include "Common.hpp"
#ifdef GEODE_IS_WINDOWS
#if 0
using namespace cocos2d;