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