Probe mappin tracking route handoff
This commit is contained in:
@@ -91,9 +91,9 @@ namespace
|
||||
{
|
||||
constexpr uint32_t kGameStateRunning = 2;
|
||||
constexpr uintptr_t kGpsSystemTickRva = 0x0E6B62C;
|
||||
constexpr uintptr_t kTrafficSystemPathfindingRva = 0x0AD1234;
|
||||
constexpr uintptr_t kRunGpsQueryHelperRva = 0x29BCF14;
|
||||
constexpr uintptr_t kUpdateGpsQueryHelperRva = 0x29BD254;
|
||||
constexpr uintptr_t kTrackMappinWrapperRva = 0x27C4AB4;
|
||||
constexpr uintptr_t kTrackMappinCoreRva = 0x27C11D0;
|
||||
constexpr uintptr_t kSetMappinTrackingAlternativeWrapperRva = 0x1246794;
|
||||
|
||||
HMODULE gModule = nullptr;
|
||||
std::mutex gLogMutex;
|
||||
@@ -102,19 +102,19 @@ const RED4ext::v1::Sdk* gSdk = nullptr;
|
||||
uint32_t gUpdateLogCount = 0;
|
||||
bool gScannedExecutable = false;
|
||||
uint32_t gGpsTickLogCount = 0;
|
||||
uint32_t gTrafficPathfindingLogCount = 0;
|
||||
uint32_t gRunGpsQueryLogCount = 0;
|
||||
uint32_t gUpdateGpsQueryLogCount = 0;
|
||||
uint32_t gTrackMappinWrapperLogCount = 0;
|
||||
uint32_t gTrackMappinCoreLogCount = 0;
|
||||
uint32_t gSetMappinTrackingAlternativeLogCount = 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);
|
||||
using ScriptNativeVoidFunc = void (*)(void* aThis, void* aStack, void* aResult);
|
||||
using TrackMappinCoreFunc = void (*)(void* aThis, void* aMappinHandle);
|
||||
ProbeFunc gOriginalGpsSystemTick = nullptr;
|
||||
ProbeFunc gOriginalTrafficSystemPathfinding = nullptr;
|
||||
RunGpsQueryFunc gOriginalRunGpsQueryHelper = nullptr;
|
||||
UpdateGpsQueryFunc gOriginalUpdateGpsQueryHelper = nullptr;
|
||||
ScriptNativeVoidFunc gOriginalTrackMappinWrapper = nullptr;
|
||||
TrackMappinCoreFunc gOriginalTrackMappinCore = nullptr;
|
||||
ScriptNativeVoidFunc gOriginalSetMappinTrackingAlternativeWrapper = nullptr;
|
||||
|
||||
std::filesystem::path GetLogPath()
|
||||
{
|
||||
@@ -180,6 +180,21 @@ void LogHookCall(const char* aName, uint32_t aCount, void* aThis, void* a2, void
|
||||
LogRed4ext(line.str());
|
||||
}
|
||||
|
||||
void LogScriptNativeCall(const char* aName, uint32_t aCount, void* aThis, void* aStack, void* aResult)
|
||||
{
|
||||
std::ostringstream line;
|
||||
line << "hook " << aName << " call=" << aCount << " this=" << aThis << " stack=" << aStack
|
||||
<< " result=" << aResult;
|
||||
LogRed4ext(line.str());
|
||||
}
|
||||
|
||||
void LogTrackMappinCoreCall(uint32_t aCount, void* aThis, void* aMappinHandle)
|
||||
{
|
||||
std::ostringstream line;
|
||||
line << "hook TrackMappinCore call=" << aCount << " this=" << aThis << " mappinHandle=" << aMappinHandle;
|
||||
LogRed4ext(line.str());
|
||||
}
|
||||
|
||||
const char* ReasonToString(RED4ext::v1::EMainReason aReason)
|
||||
{
|
||||
switch (aReason)
|
||||
@@ -340,7 +355,7 @@ void ScanExecutableStrings()
|
||||
|
||||
void DetourGpsSystemTick(void* aThis, void* a2, void* a3, void* a4)
|
||||
{
|
||||
if (gGpsTickLogCount < 16)
|
||||
if (gGpsTickLogCount < 8)
|
||||
{
|
||||
LogHookCall("GPSSystem/Tick", gGpsTickLogCount, aThis, a2, a3, a4);
|
||||
++gGpsTickLogCount;
|
||||
@@ -352,61 +367,47 @@ void DetourGpsSystemTick(void* aThis, void* a2, void* a3, void* a4)
|
||||
}
|
||||
}
|
||||
|
||||
void DetourTrafficSystemPathfinding(void* aThis, void* a2, void* a3, void* a4)
|
||||
void DetourTrackMappinWrapper(void* aThis, void* aStack, void* aResult)
|
||||
{
|
||||
if (gTrafficPathfindingLogCount < 16)
|
||||
if (gTrackMappinWrapperLogCount < 64)
|
||||
{
|
||||
LogHookCall("TrafficSystem_Pathfinding", gTrafficPathfindingLogCount, aThis, a2, a3, a4);
|
||||
++gTrafficPathfindingLogCount;
|
||||
LogScriptNativeCall("TrackMappinWrapper", gTrackMappinWrapperLogCount, aThis, aStack, aResult);
|
||||
++gTrackMappinWrapperLogCount;
|
||||
}
|
||||
|
||||
if (gOriginalTrafficSystemPathfinding)
|
||||
if (gOriginalTrackMappinWrapper)
|
||||
{
|
||||
gOriginalTrafficSystemPathfinding(aThis, a2, a3, a4);
|
||||
gOriginalTrackMappinWrapper(aThis, aStack, aResult);
|
||||
}
|
||||
}
|
||||
|
||||
bool DetourRunGpsQueryHelper(void* aThis, void* aFrom, void* aTo, void* aDebugText, void* aResultText,
|
||||
float aMaxDistance)
|
||||
void DetourTrackMappinCore(void* aThis, void* aMappinHandle)
|
||||
{
|
||||
bool result = false;
|
||||
if (gOriginalRunGpsQueryHelper)
|
||||
if (gTrackMappinCoreLogCount < 64)
|
||||
{
|
||||
result = gOriginalRunGpsQueryHelper(aThis, aFrom, aTo, aDebugText, aResultText, aMaxDistance);
|
||||
LogTrackMappinCoreCall(gTrackMappinCoreLogCount, aThis, aMappinHandle);
|
||||
++gTrackMappinCoreLogCount;
|
||||
}
|
||||
|
||||
if (gRunGpsQueryLogCount < 64)
|
||||
if (gOriginalTrackMappinCore)
|
||||
{
|
||||
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;
|
||||
gOriginalTrackMappinCore(aThis, aMappinHandle);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
void DetourSetMappinTrackingAlternativeWrapper(void* aThis, void* aStack, void* aResult)
|
||||
{
|
||||
if (gSetMappinTrackingAlternativeLogCount < 64)
|
||||
{
|
||||
LogScriptNativeCall("SetMappinTrackingAlternativeWrapper", gSetMappinTrackingAlternativeLogCount, aThis,
|
||||
aStack, aResult);
|
||||
++gSetMappinTrackingAlternativeLogCount;
|
||||
}
|
||||
|
||||
bool DetourUpdateGpsQueryHelper(void* aThis, uint32_t aRequestType, void* aTarget, void* aDebugText)
|
||||
if (gOriginalSetMappinTrackingAlternativeWrapper)
|
||||
{
|
||||
bool result = false;
|
||||
if (gOriginalUpdateGpsQueryHelper)
|
||||
{
|
||||
result = gOriginalUpdateGpsQueryHelper(aThis, aRequestType, aTarget, aDebugText);
|
||||
gOriginalSetMappinTrackingAlternativeWrapper(aThis, aStack, aResult);
|
||||
}
|
||||
|
||||
if (gUpdateGpsQueryLogCount < 64)
|
||||
{
|
||||
std::ostringstream line;
|
||||
line << "hook UpdateGPSQueryHelper call=" << gUpdateGpsQueryLogCount << " this=" << aThis
|
||||
<< " requestType=" << aRequestType << " target=" << aTarget << " debugText=" << aDebugText
|
||||
<< " result=" << (result ? "true" : "false");
|
||||
LogRed4ext(line.str());
|
||||
++gUpdateGpsQueryLogCount;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void AttachProbeHook(const char* aName, uintptr_t aRva, void* aDetour, void** aOriginal)
|
||||
@@ -514,22 +515,22 @@ RED4EXT_C_EXPORT bool RED4EXT_CALL Main(RED4ext::v1::PluginHandle aHandle, RED4e
|
||||
|
||||
AttachProbeHook("GPSSystem/Tick", kGpsSystemTickRva, reinterpret_cast<void*>(&DetourGpsSystemTick),
|
||||
reinterpret_cast<void**>(&gOriginalGpsSystemTick));
|
||||
AttachProbeHook("TrafficSystem_Pathfinding", kTrafficSystemPathfindingRva,
|
||||
reinterpret_cast<void*>(&DetourTrafficSystemPathfinding),
|
||||
reinterpret_cast<void**>(&gOriginalTrafficSystemPathfinding));
|
||||
AttachProbeHook("RunGPSQueryHelper", kRunGpsQueryHelperRva, reinterpret_cast<void*>(&DetourRunGpsQueryHelper),
|
||||
reinterpret_cast<void**>(&gOriginalRunGpsQueryHelper));
|
||||
AttachProbeHook("UpdateGPSQueryHelper", kUpdateGpsQueryHelperRva,
|
||||
reinterpret_cast<void*>(&DetourUpdateGpsQueryHelper),
|
||||
reinterpret_cast<void**>(&gOriginalUpdateGpsQueryHelper));
|
||||
AttachProbeHook("TrackMappinWrapper", kTrackMappinWrapperRva,
|
||||
reinterpret_cast<void*>(&DetourTrackMappinWrapper),
|
||||
reinterpret_cast<void**>(&gOriginalTrackMappinWrapper));
|
||||
AttachProbeHook("TrackMappinCore", kTrackMappinCoreRva, reinterpret_cast<void*>(&DetourTrackMappinCore),
|
||||
reinterpret_cast<void**>(&gOriginalTrackMappinCore));
|
||||
AttachProbeHook("SetMappinTrackingAlternativeWrapper", kSetMappinTrackingAlternativeWrapperRva,
|
||||
reinterpret_cast<void*>(&DetourSetMappinTrackingAlternativeWrapper),
|
||||
reinterpret_cast<void**>(&gOriginalSetMappinTrackingAlternativeWrapper));
|
||||
}
|
||||
|
||||
if (aReason == RED4ext::v1::EMainReason::Unload)
|
||||
{
|
||||
DetachProbeHook("GPSSystem/Tick", kGpsSystemTickRva);
|
||||
DetachProbeHook("TrafficSystem_Pathfinding", kTrafficSystemPathfindingRva);
|
||||
DetachProbeHook("RunGPSQueryHelper", kRunGpsQueryHelperRva);
|
||||
DetachProbeHook("UpdateGPSQueryHelper", kUpdateGpsQueryHelperRva);
|
||||
DetachProbeHook("TrackMappinWrapper", kTrackMappinWrapperRva);
|
||||
DetachProbeHook("TrackMappinCore", kTrackMappinCoreRva);
|
||||
DetachProbeHook("SetMappinTrackingAlternativeWrapper", kSetMappinTrackingAlternativeWrapperRva);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user