diff --git a/globals.h b/globals.h deleted file mode 100644 index e4fa1b6..0000000 --- a/globals.h +++ /dev/null @@ -1,76 +0,0 @@ -#pragma once -#include "Inc/Includes.h" - -// Defined at namespace scope but NOT initialized from GetModuleHandle at DLL-load time. -// Suspended-start injection would run those calls when the game hasn't loaded its modules yet, -// dereferencing NULL for NtHeaders and hard-faulting inside DllMain. Instead we set these in -// InitGlobals(), called from InitThread() after the launcher has confirmed the modules are loaded. -uintptr_t GA = 0; -const IMAGE_NT_HEADERS* NtHeaders = nullptr; -uintptr_t Referee = 0; - -uint64_t* RetAddr = nullptr; - -// Called from the DLL's init thread once the game has loaded GameAssembly and Referee. -// Returns true only if both modules are present AND GameAssembly has a readable PE header. -static bool InitGlobals() { - GA = (uintptr_t)GetModuleHandleA("GameAssembly.dll"); - Referee = (uintptr_t)GetModuleHandleA("Referee.dll"); - if (!GA) { printf("[Campus] init: GameAssembly.dll not loaded\n"); return false; } - if (!Referee) { printf("[Campus] init: Referee.dll not loaded\n"); return false; } - auto dos = reinterpret_cast(GA); - if (dos->e_magic != IMAGE_DOS_SIGNATURE) { printf("[Campus] init: GameAssembly has bad DOS header\n"); return false; } - NtHeaders = reinterpret_cast(GA + dos->e_lfanew); - if (NtHeaders->Signature != IMAGE_NT_SIGNATURE) { printf("[Campus] init: GameAssembly has bad NT header\n"); NtHeaders = nullptr; return false; } - printf("[Campus] init: GameAssembly=%p Referee=%p SizeOfImage=0x%X\n", - (void*)GA, (void*)Referee, NtHeaders->OptionalHeader.SizeOfImage); - return true; -} - -template -T read(void* obj, std::ptrdiff_t offset) { - return *(T*)((std::uint8_t*)obj + offset); -} - -template -void set(void* obj, std::ptrdiff_t offset, T val) { - *(T*)((std::uint8_t*)obj + offset) = val; -} - -// Byte-for-byte identical to the pre-refactor version — same offsets, same wcstombs_s call, -// same success/failure branches. Only difference: caller is REQUIRED to delete[] the returned -// buffer (see the ReadIl2CppStringOwned helper below which does that for you). The earlier -// std::string return-by-value refactor was reading empty strings on this build for reasons -// I couldn't pin down without a live debugger, so we revert to the known-working shape. -char* ReadIl2CppString(Il2cppString* il2cppString) { - - if (il2cppString == nullptr) { - return nullptr; - } - - size_t length = static_cast(il2cppString->Length); - const size_t bufferSize = (length + 1) * sizeof(wchar_t); - char* internalString = new char[bufferSize]; - size_t convertedChars = 0; - - errno_t result = wcstombs_s(&convertedChars, internalString, bufferSize, reinterpret_cast(il2cppString) + 0xA, length); - - if (result != 0) { - delete[] internalString; - return nullptr; - } - - return internalString; -} - -// Owning wrapper: reads the IL2CPP string, copies into std::string, frees the intermediate -// buffer. Use this from hot paths (SendRequest_H, log lines) — the raw ReadIl2CppString -// leaks (length+1)*2 bytes per call if the caller doesn't delete[] the return. -#include -inline std::string ReadIl2CppStringOwned(Il2cppString* il2cppString) { - char* raw = ReadIl2CppString(il2cppString); - if (!raw) return {}; - std::string out(raw); - delete[] raw; - return out; -} \ No newline at end of file