2019-06-07 11:53:37 +08:00
|
|
|
#include "match.h"
|
|
|
|
#include "engine.h"
|
2018-08-23 23:53:23 +08:00
|
|
|
#include "main.h"
|
2019-06-07 11:53:37 +08:00
|
|
|
#include "native/pchooks.h"
|
2016-01-05 23:01:17 +08:00
|
|
|
|
2019-02-28 00:33:17 +08:00
|
|
|
extern const char* HIJACK_ERROR;
|
|
|
|
|
2019-06-07 11:53:37 +08:00
|
|
|
uintptr_t processStartAddress, processStopAddress;
|
2016-01-05 23:01:17 +08:00
|
|
|
|
2019-06-07 11:53:37 +08:00
|
|
|
namespace Engine
|
2016-01-05 23:01:17 +08:00
|
|
|
{
|
2019-06-07 11:53:37 +08:00
|
|
|
WCHAR* processName, // cached
|
|
|
|
processPath[MAX_PATH]; // cached
|
2016-01-05 23:01:17 +08:00
|
|
|
|
2019-06-07 11:53:37 +08:00
|
|
|
bool UnsafeDetermineEngineType();
|
2016-01-05 23:01:17 +08:00
|
|
|
|
2019-06-07 11:53:37 +08:00
|
|
|
// jichi 10/21/2014: Return whether found the game engine
|
|
|
|
bool DetermineEngineType()
|
|
|
|
{
|
|
|
|
// jichi 9/27/2013: disable game engine for debugging use
|
|
|
|
bool found = false;
|
2018-09-04 06:43:43 +08:00
|
|
|
#ifndef ITH_DISABLE_ENGINE
|
2019-06-07 11:53:37 +08:00
|
|
|
__try { found = UnsafeDetermineEngineType(); }
|
|
|
|
__except (EXCEPTION_EXECUTE_HANDLER) { ConsoleOutput(HIJACK_ERROR); }
|
2018-09-04 06:43:43 +08:00
|
|
|
#endif // ITH_DISABLE_ENGINE
|
2019-06-07 11:53:37 +08:00
|
|
|
if (!found) { // jichi 10/2/2013: Only enable it if no game engine is detected
|
|
|
|
PcHooks::hookOtherPcFunctions();
|
|
|
|
} //else
|
|
|
|
// ConsoleOutput("vnreng: found game engine, IGNORE non gui hooks");
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD InsertDynamicHook(LPVOID addr, DWORD frame, DWORD stack)
|
2018-08-26 03:45:25 +08:00
|
|
|
{
|
2019-06-07 11:53:37 +08:00
|
|
|
return trigger_fun ? !trigger_fun(addr, frame, stack) : 0;
|
|
|
|
}
|
2018-08-26 03:45:25 +08:00
|
|
|
|
2019-06-07 11:53:37 +08:00
|
|
|
void Hijack()
|
|
|
|
{
|
2019-06-17 03:28:59 +08:00
|
|
|
static auto _ = []
|
2019-06-07 11:53:37 +08:00
|
|
|
{
|
2019-06-17 03:28:59 +08:00
|
|
|
GetModuleFileNameW(nullptr, processPath, MAX_PATH);
|
|
|
|
processName = wcsrchr(processPath, L'\\') + 1;
|
|
|
|
|
|
|
|
processStartAddress = processStopAddress = (uintptr_t)GetModuleHandleW(nullptr);
|
|
|
|
MEMORY_BASIC_INFORMATION info;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
VirtualQuery((void*)processStopAddress, &info, sizeof(info));
|
|
|
|
processStopAddress = (uintptr_t)info.BaseAddress + info.RegionSize;
|
|
|
|
} while (info.Protect > PAGE_NOACCESS);
|
|
|
|
processStopAddress -= info.RegionSize;
|
|
|
|
spDefault.minAddress = processStartAddress;
|
|
|
|
spDefault.maxAddress = processStopAddress;
|
|
|
|
ConsoleOutput("Textractor: hijacking process located from 0x%p to 0x%p", processStartAddress, processStopAddress);
|
|
|
|
|
|
|
|
DetermineEngineType();
|
|
|
|
return NULL;
|
|
|
|
}();
|
2019-06-07 11:53:37 +08:00
|
|
|
}
|
2016-01-05 23:01:17 +08:00
|
|
|
}
|