mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-22 02:45:49 -04:00
move gd version detection code to proxyloader, now works on 2.1
This commit is contained in:
parent
def39fc3f9
commit
9b22d48352
4 changed files with 69 additions and 60 deletions
loader
|
@ -1,7 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.21)
|
||||
|
||||
add_library(ProxyLoader SHARED proxyLoader.c)
|
||||
target_compile_features(ProxyLoader PUBLIC cxx_std_17)
|
||||
set_target_properties(ProxyLoader PROPERTIES
|
||||
PREFIX ""
|
||||
OUTPUT_NAME "XInput9_1_0"
|
||||
|
@ -18,9 +17,9 @@ set_target_properties(ProxyLoader PROPERTIES
|
|||
RUNTIME_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}/nightly"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}/nightly"
|
||||
)
|
||||
add_library(fake-geode-loader SHARED fakeGeode.c)
|
||||
set_target_properties(fake-geode-loader PROPERTIES OUTPUT_NAME "Geode")
|
||||
target_link_libraries(ProxyLoader PRIVATE fake-geode-loader)
|
||||
|
||||
string(REPLACE "." "_" GEODE_GD_VERSION_IDENTIFIER "_${GEODE_GD_VERSION}")
|
||||
target_compile_definitions(ProxyLoader PRIVATE GEODE_GD_VERSION_IDENTIFIER=${GEODE_GD_VERSION_IDENTIFIER})
|
||||
|
||||
add_executable(Updater Updater.cpp)
|
||||
target_compile_features(Updater PUBLIC cxx_std_17)
|
||||
|
@ -46,16 +45,13 @@ if (MSVC)
|
|||
include(CheckLinkerFlag)
|
||||
check_linker_flag(CXX /NOEXP SUPPORTS_NOEXP)
|
||||
if (SUPPORTS_NOEXP)
|
||||
target_link_options(fake-geode-loader PRIVATE /NOEXP)
|
||||
target_link_options(ProxyLoader PRIVATE /NOEXP)
|
||||
endif()
|
||||
|
||||
target_link_options(fake-geode-loader PRIVATE /DEBUG:NONE)
|
||||
target_link_options(ProxyLoader PRIVATE /NOIMPLIB /DEBUG:NONE)
|
||||
target_link_options(Updater PRIVATE /DEBUG:NONE)
|
||||
|
||||
if (DEFINED ENV{GEODE_CI})
|
||||
target_link_options(fake-geode-loader PRIVATE /INCREMENTAL:NO)
|
||||
target_link_options(ProxyLoader PRIVATE /INCREMENTAL:NO)
|
||||
target_link_options(Updater PRIVATE /INCREMENTAL:NO)
|
||||
endif()
|
||||
|
|
|
@ -45,5 +45,69 @@ DWORD WINAPI xinputGetDSoundAudioDeviceGuids(DWORD dwUserIndex, GUID* pDSoundRen
|
|||
#pragma comment(linker, "/export:XInputGetCapabilities=_xinputGetCapabilities@12")
|
||||
#pragma comment(linker, "/export:XInputGetDSoundAudioDeviceGuids=_xinputGetDSoundAudioDeviceGuids@12")
|
||||
|
||||
__declspec(dllimport) void fake();
|
||||
__declspec(dllexport) void sussy_impostor_sus_red_sus_vote_red_red_was_not_the_impostor() { fake(); }
|
||||
unsigned int getExeTimestamp() {
|
||||
HANDLE hMod = GetModuleHandleA(NULL);
|
||||
PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)hMod;
|
||||
|
||||
if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
|
||||
PIMAGE_NT_HEADERS ntHeader = (PIMAGE_NT_HEADERS)((uintptr_t)(hMod) + dosHeader->e_lfanew);
|
||||
|
||||
if (ntHeader->Signature == IMAGE_NT_SIGNATURE) {
|
||||
return ntHeader->FileHeader.TimeDateStamp;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL fileExists(char const* path) {
|
||||
DWORD attrib = GetFileAttributesA(path);
|
||||
|
||||
return (attrib != INVALID_FILE_ATTRIBUTES && !(attrib & FILE_ATTRIBUTE_DIRECTORY));
|
||||
}
|
||||
|
||||
// Table originally from this gist by absolute:
|
||||
// https://gist.github.com/absoIute/ebe5da42d118109a03632c9751d86e19
|
||||
|
||||
#define TIMESTAMP_FOR_1_900 1419173053
|
||||
#define TIMESTAMP_FOR_1_910 1419880840
|
||||
#define TIMESTAMP_FOR_1_920 1421745341
|
||||
#define TIMESTAMP_FOR_2_000 1440638199
|
||||
#define TIMESTAMP_FOR_2_001 1440643927
|
||||
#define TIMESTAMP_FOR_2_010 1443053232
|
||||
#define TIMESTAMP_FOR_2_011 1443077847
|
||||
#define TIMESTAMP_FOR_2_020 1443077847
|
||||
#define TIMESTAMP_FOR_2_100 1484612867
|
||||
#define TIMESTAMP_FOR_2_101 1484626658
|
||||
#define TIMESTAMP_FOR_2_102 1484737207
|
||||
#define TIMESTAMP_FOR_2_110 1510526914
|
||||
#define TIMESTAMP_FOR_2_111 1510538091
|
||||
#define TIMESTAMP_FOR_2_112 1510619253
|
||||
#define TIMESTAMP_FOR_2_113 1511220108
|
||||
#define TIMESTAMP_FOR_2_200 1702921605
|
||||
#define TIMESTAMP_FOR_2_201 1704582672
|
||||
#define TIMESTAMP_FOR_2_202 1704601266
|
||||
|
||||
#define GEODE_WRAPPER_CONCAT(x, y) x##y
|
||||
#define GEODE_CONCAT(x, y) GEODE_WRAPPER_CONCAT(x, y)
|
||||
|
||||
// Hello future person. if this is erroring then you need to add
|
||||
// the exe timestamp for whatever you set GEODE_GD_VERSION to. hope that helps!
|
||||
#define TIMESTAMP GEODE_CONCAT(TIMESTAMP_FOR, GEODE_GD_VERSION_IDENTIFIER)
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {
|
||||
if (reason != DLL_PROCESS_ATTACH)
|
||||
return TRUE;
|
||||
DisableThreadLibraryCalls(module);
|
||||
|
||||
if (fileExists("Geode.dll")) {
|
||||
if (getExeTimestamp() == TIMESTAMP) {
|
||||
// somehow, this works fine inside of dllmain :-)
|
||||
// yes, even on wine.
|
||||
LoadLibraryA("Geode.dll");
|
||||
} else {
|
||||
MessageBoxA(NULL, "GD version mismatch, not loading Geode.", "Unable to load Geode!", MB_OK | MB_ICONWARNING);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
#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 "";
|
||||
}
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "../load.hpp"
|
||||
#include <Windows.h>
|
||||
#include "VersionDetect.hpp"
|
||||
|
||||
#include "loader/LoaderImpl.hpp"
|
||||
using namespace geode::prelude;
|
||||
|
@ -43,10 +42,6 @@ int WINAPI gdMainHook(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
|
|||
}
|
||||
|
||||
std::string loadGeode() {
|
||||
if (detectGDVersion() != GEODE_STR(GEODE_GD_VERSION)) {
|
||||
return "GD version mismatch, not loading geode.";
|
||||
}
|
||||
|
||||
auto process = GetCurrentProcess();
|
||||
|
||||
constexpr size_t trampolineSize = 12;
|
||||
|
|
Loading…
Reference in a new issue