Probe native GPS query helpers
This commit is contained in:
@@ -92,10 +92,8 @@ namespace
|
||||
constexpr uint32_t kGameStateRunning = 2;
|
||||
constexpr uintptr_t kGpsSystemTickRva = 0x0E6B62C;
|
||||
constexpr uintptr_t kTrafficSystemPathfindingRva = 0x0AD1234;
|
||||
constexpr uintptr_t kStopPathfindingA = 0x11C20A8;
|
||||
constexpr uintptr_t kStopPathfindingB = 0x11C2148;
|
||||
constexpr uintptr_t kStartPathfindingA = 0x11C21FC;
|
||||
constexpr uintptr_t kStartPathfindingB = 0x11C22B0;
|
||||
constexpr uintptr_t kRunGpsQueryHelperRva = 0x29BCF14;
|
||||
constexpr uintptr_t kUpdateGpsQueryHelperRva = 0x29BD254;
|
||||
|
||||
HMODULE gModule = nullptr;
|
||||
std::mutex gLogMutex;
|
||||
@@ -105,20 +103,18 @@ uint32_t gUpdateLogCount = 0;
|
||||
bool gScannedExecutable = false;
|
||||
uint32_t gGpsTickLogCount = 0;
|
||||
uint32_t gTrafficPathfindingLogCount = 0;
|
||||
uint32_t gStopPathfindingALogCount = 0;
|
||||
uint32_t gStopPathfindingBLogCount = 0;
|
||||
uint32_t gStartPathfindingALogCount = 0;
|
||||
uint32_t gStartPathfindingBLogCount = 0;
|
||||
uint32_t gRunGpsQueryLogCount = 0;
|
||||
uint32_t gUpdateGpsQueryLogCount = 0;
|
||||
uint64_t gLogStartTick = 0;
|
||||
uint64_t gLogFrequency = 0;
|
||||
|
||||
using ProbeFunc = void (*)(void* aThis, void* a2, void* a3, void* a4);
|
||||
using RunGpsQueryFunc = bool (*)(void* aThis, void* aFrom, void* aTo, void* aDebugText, void* aResultText, float aMaxDistance);
|
||||
using UpdateGpsQueryFunc = bool (*)(void* aThis, uint32_t aRequestType, void* aTarget, void* aDebugText);
|
||||
ProbeFunc gOriginalGpsSystemTick = nullptr;
|
||||
ProbeFunc gOriginalTrafficSystemPathfinding = nullptr;
|
||||
ProbeFunc gOriginalStopPathfindingA = nullptr;
|
||||
ProbeFunc gOriginalStopPathfindingB = nullptr;
|
||||
ProbeFunc gOriginalStartPathfindingA = nullptr;
|
||||
ProbeFunc gOriginalStartPathfindingB = nullptr;
|
||||
RunGpsQueryFunc gOriginalRunGpsQueryHelper = nullptr;
|
||||
UpdateGpsQueryFunc gOriginalUpdateGpsQueryHelper = nullptr;
|
||||
|
||||
std::filesystem::path GetLogPath()
|
||||
{
|
||||
@@ -275,10 +271,13 @@ void ScanExecutableStrings()
|
||||
header << "exe-string scan begin base=0x" << std::hex << imageBase << " size=0x" << imageSize << std::dec;
|
||||
LogRed4ext(header.str());
|
||||
|
||||
constexpr std::array<const char*, 18> kNeedles{
|
||||
constexpr std::array<const char*, 21> kNeedles{
|
||||
"GPSSystem/Tick",
|
||||
"GPSSystem",
|
||||
"GPSSettings",
|
||||
"RunGPSQuery",
|
||||
"UpdateGPSQuery",
|
||||
"gameuiGPSGameController",
|
||||
"OnSetHasGPSPortal",
|
||||
"IsGPSPortal",
|
||||
"m_cookedGpsData",
|
||||
@@ -289,8 +288,6 @@ void ScanExecutableStrings()
|
||||
"Pathfinding Algorithm Failed",
|
||||
"No Path Found in Traffic",
|
||||
"PathFindingFailed",
|
||||
"StartPathfinding",
|
||||
"StopPathfinding",
|
||||
"worldTrafficLanePlayerGPSInfo",
|
||||
"worldTrafficPersistentResource",
|
||||
"worldTrafficConnectivityOutLane",
|
||||
@@ -369,60 +366,47 @@ void DetourTrafficSystemPathfinding(void* aThis, void* a2, void* a3, void* a4)
|
||||
}
|
||||
}
|
||||
|
||||
void DetourStopPathfindingA(void* aThis, void* a2, void* a3, void* a4)
|
||||
bool DetourRunGpsQueryHelper(void* aThis, void* aFrom, void* aTo, void* aDebugText, void* aResultText,
|
||||
float aMaxDistance)
|
||||
{
|
||||
if (gStopPathfindingALogCount < 32)
|
||||
bool result = false;
|
||||
if (gOriginalRunGpsQueryHelper)
|
||||
{
|
||||
LogHookCall("StopPathfindingA", gStopPathfindingALogCount, aThis, a2, a3, a4);
|
||||
++gStopPathfindingALogCount;
|
||||
result = gOriginalRunGpsQueryHelper(aThis, aFrom, aTo, aDebugText, aResultText, aMaxDistance);
|
||||
}
|
||||
|
||||
if (gOriginalStopPathfindingA)
|
||||
if (gRunGpsQueryLogCount < 64)
|
||||
{
|
||||
gOriginalStopPathfindingA(aThis, a2, a3, a4);
|
||||
std::ostringstream line;
|
||||
line << "hook RunGPSQueryHelper call=" << gRunGpsQueryLogCount << " this=" << aThis << " from=" << aFrom
|
||||
<< " to=" << aTo << " debugText=" << aDebugText << " resultText=" << aResultText
|
||||
<< " maxDistance=" << aMaxDistance << " result=" << (result ? "true" : "false");
|
||||
LogRed4ext(line.str());
|
||||
++gRunGpsQueryLogCount;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void DetourStopPathfindingB(void* aThis, void* a2, void* a3, void* a4)
|
||||
bool DetourUpdateGpsQueryHelper(void* aThis, uint32_t aRequestType, void* aTarget, void* aDebugText)
|
||||
{
|
||||
if (gStopPathfindingBLogCount < 32)
|
||||
bool result = false;
|
||||
if (gOriginalUpdateGpsQueryHelper)
|
||||
{
|
||||
LogHookCall("StopPathfindingB", gStopPathfindingBLogCount, aThis, a2, a3, a4);
|
||||
++gStopPathfindingBLogCount;
|
||||
result = gOriginalUpdateGpsQueryHelper(aThis, aRequestType, aTarget, aDebugText);
|
||||
}
|
||||
|
||||
if (gOriginalStopPathfindingB)
|
||||
if (gUpdateGpsQueryLogCount < 64)
|
||||
{
|
||||
gOriginalStopPathfindingB(aThis, a2, a3, a4);
|
||||
}
|
||||
}
|
||||
|
||||
void DetourStartPathfindingA(void* aThis, void* a2, void* a3, void* a4)
|
||||
{
|
||||
if (gStartPathfindingALogCount < 32)
|
||||
{
|
||||
LogHookCall("StartPathfindingA", gStartPathfindingALogCount, aThis, a2, a3, a4);
|
||||
++gStartPathfindingALogCount;
|
||||
std::ostringstream line;
|
||||
line << "hook UpdateGPSQueryHelper call=" << gUpdateGpsQueryLogCount << " this=" << aThis
|
||||
<< " requestType=" << aRequestType << " target=" << aTarget << " debugText=" << aDebugText
|
||||
<< " result=" << (result ? "true" : "false");
|
||||
LogRed4ext(line.str());
|
||||
++gUpdateGpsQueryLogCount;
|
||||
}
|
||||
|
||||
if (gOriginalStartPathfindingA)
|
||||
{
|
||||
gOriginalStartPathfindingA(aThis, a2, a3, a4);
|
||||
}
|
||||
}
|
||||
|
||||
void DetourStartPathfindingB(void* aThis, void* a2, void* a3, void* a4)
|
||||
{
|
||||
if (gStartPathfindingBLogCount < 32)
|
||||
{
|
||||
LogHookCall("StartPathfindingB", gStartPathfindingBLogCount, aThis, a2, a3, a4);
|
||||
++gStartPathfindingBLogCount;
|
||||
}
|
||||
|
||||
if (gOriginalStartPathfindingB)
|
||||
{
|
||||
gOriginalStartPathfindingB(aThis, a2, a3, a4);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void AttachProbeHook(const char* aName, uintptr_t aRva, void* aDetour, void** aOriginal)
|
||||
@@ -534,24 +518,19 @@ RED4EXT_C_EXPORT bool RED4EXT_CALL Main(RED4ext::v1::PluginHandle aHandle, RED4e
|
||||
AttachProbeHook("TrafficSystem_Pathfinding", kTrafficSystemPathfindingRva,
|
||||
reinterpret_cast<void*>(&DetourTrafficSystemPathfinding),
|
||||
reinterpret_cast<void**>(&gOriginalTrafficSystemPathfinding));
|
||||
AttachProbeHook("StopPathfindingA", kStopPathfindingA, reinterpret_cast<void*>(&DetourStopPathfindingA),
|
||||
reinterpret_cast<void**>(&gOriginalStopPathfindingA));
|
||||
AttachProbeHook("StopPathfindingB", kStopPathfindingB, reinterpret_cast<void*>(&DetourStopPathfindingB),
|
||||
reinterpret_cast<void**>(&gOriginalStopPathfindingB));
|
||||
AttachProbeHook("StartPathfindingA", kStartPathfindingA, reinterpret_cast<void*>(&DetourStartPathfindingA),
|
||||
reinterpret_cast<void**>(&gOriginalStartPathfindingA));
|
||||
AttachProbeHook("StartPathfindingB", kStartPathfindingB, reinterpret_cast<void*>(&DetourStartPathfindingB),
|
||||
reinterpret_cast<void**>(&gOriginalStartPathfindingB));
|
||||
AttachProbeHook("RunGPSQueryHelper", kRunGpsQueryHelperRva, reinterpret_cast<void*>(&DetourRunGpsQueryHelper),
|
||||
reinterpret_cast<void**>(&gOriginalRunGpsQueryHelper));
|
||||
AttachProbeHook("UpdateGPSQueryHelper", kUpdateGpsQueryHelperRva,
|
||||
reinterpret_cast<void*>(&DetourUpdateGpsQueryHelper),
|
||||
reinterpret_cast<void**>(&gOriginalUpdateGpsQueryHelper));
|
||||
}
|
||||
|
||||
if (aReason == RED4ext::v1::EMainReason::Unload)
|
||||
{
|
||||
DetachProbeHook("GPSSystem/Tick", kGpsSystemTickRva);
|
||||
DetachProbeHook("TrafficSystem_Pathfinding", kTrafficSystemPathfindingRva);
|
||||
DetachProbeHook("StopPathfindingA", kStopPathfindingA);
|
||||
DetachProbeHook("StopPathfindingB", kStopPathfindingB);
|
||||
DetachProbeHook("StartPathfindingA", kStartPathfindingA);
|
||||
DetachProbeHook("StartPathfindingB", kStartPathfindingB);
|
||||
DetachProbeHook("RunGPSQueryHelper", kRunGpsQueryHelperRva);
|
||||
DetachProbeHook("UpdateGPSQueryHelper", kUpdateGpsQueryHelperRva);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user