Probe mappin route slots
This commit is contained in:
@@ -97,6 +97,9 @@ constexpr uintptr_t kTrackMappinCoreRva = 0x27C11D0;
|
|||||||
constexpr uintptr_t kSetMappinTrackingAlternativeWrapperRva = 0x1246794;
|
constexpr uintptr_t kSetMappinTrackingAlternativeWrapperRva = 0x1246794;
|
||||||
constexpr uintptr_t kMappinSetTrackedSlotOffset = 0x220;
|
constexpr uintptr_t kMappinSetTrackedSlotOffset = 0x220;
|
||||||
constexpr uintptr_t kMappinClearTrackedSlotOffset = 0x228;
|
constexpr uintptr_t kMappinClearTrackedSlotOffset = 0x228;
|
||||||
|
constexpr uintptr_t kMappinPositionQuerySlotOffset = 0x2E0;
|
||||||
|
constexpr uintptr_t kMappinReleaseQuerySlotOffset = 0x368;
|
||||||
|
constexpr uintptr_t kMappinActiveRouteSlotOffset = 0x3A8;
|
||||||
|
|
||||||
HMODULE gModule = nullptr;
|
HMODULE gModule = nullptr;
|
||||||
std::mutex gLogMutex;
|
std::mutex gLogMutex;
|
||||||
@@ -111,10 +114,16 @@ uint32_t gSetMappinTrackingAlternativeLogCount = 0;
|
|||||||
uint32_t gMappinSystemSlotLogCount = 0;
|
uint32_t gMappinSystemSlotLogCount = 0;
|
||||||
uint32_t gMappinSetTrackedLogCount = 0;
|
uint32_t gMappinSetTrackedLogCount = 0;
|
||||||
uint32_t gMappinClearTrackedLogCount = 0;
|
uint32_t gMappinClearTrackedLogCount = 0;
|
||||||
|
uint32_t gMappinPositionQueryLogCount = 0;
|
||||||
|
uint32_t gMappinReleaseQueryLogCount = 0;
|
||||||
|
uint32_t gMappinActiveRouteLogCount = 0;
|
||||||
uint64_t gLogStartTick = 0;
|
uint64_t gLogStartTick = 0;
|
||||||
uint64_t gLogFrequency = 0;
|
uint64_t gLogFrequency = 0;
|
||||||
void* gMappinSetTrackedTarget = nullptr;
|
void* gMappinSetTrackedTarget = nullptr;
|
||||||
void* gMappinClearTrackedTarget = nullptr;
|
void* gMappinClearTrackedTarget = nullptr;
|
||||||
|
void* gMappinPositionQueryTarget = nullptr;
|
||||||
|
void* gMappinReleaseQueryTarget = nullptr;
|
||||||
|
void* gMappinActiveRouteTarget = nullptr;
|
||||||
bool gMappinSlotHookAttachAttempted = false;
|
bool gMappinSlotHookAttachAttempted = false;
|
||||||
|
|
||||||
using ProbeFunc = void (*)(void* aThis, void* a2, void* a3, void* a4);
|
using ProbeFunc = void (*)(void* aThis, void* a2, void* a3, void* a4);
|
||||||
@@ -123,12 +132,18 @@ using MappinSystemResolverFunc = void* (*)(void* aThis);
|
|||||||
using TrackMappinCoreFunc = void (*)(void* aThis, void* aMappinHandle);
|
using TrackMappinCoreFunc = void (*)(void* aThis, void* aMappinHandle);
|
||||||
using MappinSetTrackedFunc = void (*)(void* aSystem, void* aMappinId);
|
using MappinSetTrackedFunc = void (*)(void* aSystem, void* aMappinId);
|
||||||
using MappinClearTrackedFunc = void (*)(void* aSystem);
|
using MappinClearTrackedFunc = void (*)(void* aSystem);
|
||||||
|
using MappinPositionQueryFunc = void* (*)(void* aSystem, void* a2, void* a3, void* a4, void* a5);
|
||||||
|
using MappinReleaseQueryFunc = void (*)(void* aSystem, void* aHandle);
|
||||||
|
using MappinActiveRouteFunc = void* (*)(void* aSystem);
|
||||||
ProbeFunc gOriginalGpsSystemTick = nullptr;
|
ProbeFunc gOriginalGpsSystemTick = nullptr;
|
||||||
ScriptNativeVoidFunc gOriginalTrackMappinWrapper = nullptr;
|
ScriptNativeVoidFunc gOriginalTrackMappinWrapper = nullptr;
|
||||||
TrackMappinCoreFunc gOriginalTrackMappinCore = nullptr;
|
TrackMappinCoreFunc gOriginalTrackMappinCore = nullptr;
|
||||||
ScriptNativeVoidFunc gOriginalSetMappinTrackingAlternativeWrapper = nullptr;
|
ScriptNativeVoidFunc gOriginalSetMappinTrackingAlternativeWrapper = nullptr;
|
||||||
MappinSetTrackedFunc gOriginalMappinSetTracked = nullptr;
|
MappinSetTrackedFunc gOriginalMappinSetTracked = nullptr;
|
||||||
MappinClearTrackedFunc gOriginalMappinClearTracked = nullptr;
|
MappinClearTrackedFunc gOriginalMappinClearTracked = nullptr;
|
||||||
|
MappinPositionQueryFunc gOriginalMappinPositionQuery = nullptr;
|
||||||
|
MappinReleaseQueryFunc gOriginalMappinReleaseQuery = nullptr;
|
||||||
|
MappinActiveRouteFunc gOriginalMappinActiveRoute = nullptr;
|
||||||
|
|
||||||
std::filesystem::path GetLogPath()
|
std::filesystem::path GetLogPath()
|
||||||
{
|
{
|
||||||
@@ -278,12 +293,12 @@ void LogMappinSystemSlots(uint32_t aCount, void* aSystem, void* aVtable)
|
|||||||
line << "mappin-system slots call=" << aCount;
|
line << "mappin-system slots call=" << aCount;
|
||||||
AppendPointerWithRva(line, "system", aSystem);
|
AppendPointerWithRva(line, "system", aSystem);
|
||||||
AppendPointerWithRva(line, "vtable", aVtable);
|
AppendPointerWithRva(line, "vtable", aVtable);
|
||||||
AppendPointerWithRva(line, "slot220", readSlot(0x220));
|
AppendPointerWithRva(line, "slot220", readSlot(kMappinSetTrackedSlotOffset));
|
||||||
AppendPointerWithRva(line, "slot228", readSlot(0x228));
|
AppendPointerWithRva(line, "slot228", readSlot(kMappinClearTrackedSlotOffset));
|
||||||
AppendPointerWithRva(line, "slot250", readSlot(0x250));
|
AppendPointerWithRva(line, "slot250", readSlot(0x250));
|
||||||
AppendPointerWithRva(line, "slot2e0", readSlot(0x2E0));
|
AppendPointerWithRva(line, "slot2e0", readSlot(kMappinPositionQuerySlotOffset));
|
||||||
AppendPointerWithRva(line, "slot368", readSlot(0x368));
|
AppendPointerWithRva(line, "slot368", readSlot(kMappinReleaseQuerySlotOffset));
|
||||||
AppendPointerWithRva(line, "slot3a8", readSlot(0x3A8));
|
AppendPointerWithRva(line, "slot3a8", readSlot(kMappinActiveRouteSlotOffset));
|
||||||
LogRed4ext(line.str());
|
LogRed4ext(line.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -543,6 +558,89 @@ void DetourMappinClearTracked(void* aSystem)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* DetourMappinPositionQuery(void* aSystem, void* a2, void* a3, void* a4, void* a5)
|
||||||
|
{
|
||||||
|
const auto shouldLog = gMappinPositionQueryLogCount < 32;
|
||||||
|
if (shouldLog)
|
||||||
|
{
|
||||||
|
std::ostringstream line;
|
||||||
|
line << "hook MappinSystem::PositionQuery slot2e0 call=" << gMappinPositionQueryLogCount;
|
||||||
|
AppendPointerWithRva(line, "system", aSystem);
|
||||||
|
AppendPointerWithRva(line, "a2", a2);
|
||||||
|
AppendPointerWithRva(line, "a3", a3);
|
||||||
|
AppendPointerWithRva(line, "a4", a4);
|
||||||
|
AppendPointerWithRva(line, "a5", a5);
|
||||||
|
AppendReturnRva(line, __builtin_return_address(0));
|
||||||
|
LogRed4ext(line.str());
|
||||||
|
++gMappinPositionQueryLogCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* result = nullptr;
|
||||||
|
if (gOriginalMappinPositionQuery)
|
||||||
|
{
|
||||||
|
result = gOriginalMappinPositionQuery(aSystem, a2, a3, a4, a5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldLog)
|
||||||
|
{
|
||||||
|
std::ostringstream line;
|
||||||
|
line << "hook MappinSystem::PositionQuery slot2e0 result";
|
||||||
|
AppendPointerWithRva(line, "value", result);
|
||||||
|
LogRed4ext(line.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DetourMappinReleaseQuery(void* aSystem, void* aHandle)
|
||||||
|
{
|
||||||
|
if (gMappinReleaseQueryLogCount < 32)
|
||||||
|
{
|
||||||
|
std::ostringstream line;
|
||||||
|
line << "hook MappinSystem::ReleaseQuery slot368 call=" << gMappinReleaseQueryLogCount;
|
||||||
|
AppendPointerWithRva(line, "system", aSystem);
|
||||||
|
AppendPointerWithRva(line, "handle", aHandle);
|
||||||
|
AppendReturnRva(line, __builtin_return_address(0));
|
||||||
|
LogRed4ext(line.str());
|
||||||
|
++gMappinReleaseQueryLogCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gOriginalMappinReleaseQuery)
|
||||||
|
{
|
||||||
|
gOriginalMappinReleaseQuery(aSystem, aHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void* DetourMappinActiveRoute(void* aSystem)
|
||||||
|
{
|
||||||
|
const auto shouldLog = gMappinActiveRouteLogCount < 32;
|
||||||
|
if (shouldLog)
|
||||||
|
{
|
||||||
|
std::ostringstream line;
|
||||||
|
line << "hook MappinSystem::ActiveRoute slot3a8 call=" << gMappinActiveRouteLogCount;
|
||||||
|
AppendPointerWithRva(line, "system", aSystem);
|
||||||
|
AppendReturnRva(line, __builtin_return_address(0));
|
||||||
|
LogRed4ext(line.str());
|
||||||
|
++gMappinActiveRouteLogCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* result = nullptr;
|
||||||
|
if (gOriginalMappinActiveRoute)
|
||||||
|
{
|
||||||
|
result = gOriginalMappinActiveRoute(aSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldLog)
|
||||||
|
{
|
||||||
|
std::ostringstream line;
|
||||||
|
line << "hook MappinSystem::ActiveRoute slot3a8 result";
|
||||||
|
AppendPointerWithRva(line, "value", result);
|
||||||
|
LogRed4ext(line.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
if (!gSdk || !gSdk->hooking || !gSdk->hooking->Attach)
|
if (!gSdk || !gSdk->hooking || !gSdk->hooking->Attach)
|
||||||
@@ -639,6 +737,12 @@ void InspectAndHookMappinSystem(void* aThis)
|
|||||||
*reinterpret_cast<void**>(reinterpret_cast<uintptr_t>(vtable) + kMappinSetTrackedSlotOffset);
|
*reinterpret_cast<void**>(reinterpret_cast<uintptr_t>(vtable) + kMappinSetTrackedSlotOffset);
|
||||||
gMappinClearTrackedTarget =
|
gMappinClearTrackedTarget =
|
||||||
*reinterpret_cast<void**>(reinterpret_cast<uintptr_t>(vtable) + kMappinClearTrackedSlotOffset);
|
*reinterpret_cast<void**>(reinterpret_cast<uintptr_t>(vtable) + kMappinClearTrackedSlotOffset);
|
||||||
|
gMappinPositionQueryTarget =
|
||||||
|
*reinterpret_cast<void**>(reinterpret_cast<uintptr_t>(vtable) + kMappinPositionQuerySlotOffset);
|
||||||
|
gMappinReleaseQueryTarget =
|
||||||
|
*reinterpret_cast<void**>(reinterpret_cast<uintptr_t>(vtable) + kMappinReleaseQuerySlotOffset);
|
||||||
|
gMappinActiveRouteTarget =
|
||||||
|
*reinterpret_cast<void**>(reinterpret_cast<uintptr_t>(vtable) + kMappinActiveRouteSlotOffset);
|
||||||
|
|
||||||
AttachAbsoluteHook("MappinSystem::SetTracked slot220", gMappinSetTrackedTarget,
|
AttachAbsoluteHook("MappinSystem::SetTracked slot220", gMappinSetTrackedTarget,
|
||||||
reinterpret_cast<void*>(&DetourMappinSetTracked),
|
reinterpret_cast<void*>(&DetourMappinSetTracked),
|
||||||
@@ -646,6 +750,15 @@ void InspectAndHookMappinSystem(void* aThis)
|
|||||||
AttachAbsoluteHook("MappinSystem::ClearTracked slot228", gMappinClearTrackedTarget,
|
AttachAbsoluteHook("MappinSystem::ClearTracked slot228", gMappinClearTrackedTarget,
|
||||||
reinterpret_cast<void*>(&DetourMappinClearTracked),
|
reinterpret_cast<void*>(&DetourMappinClearTracked),
|
||||||
reinterpret_cast<void**>(&gOriginalMappinClearTracked));
|
reinterpret_cast<void**>(&gOriginalMappinClearTracked));
|
||||||
|
AttachAbsoluteHook("MappinSystem::PositionQuery slot2e0", gMappinPositionQueryTarget,
|
||||||
|
reinterpret_cast<void*>(&DetourMappinPositionQuery),
|
||||||
|
reinterpret_cast<void**>(&gOriginalMappinPositionQuery));
|
||||||
|
AttachAbsoluteHook("MappinSystem::ReleaseQuery slot368", gMappinReleaseQueryTarget,
|
||||||
|
reinterpret_cast<void*>(&DetourMappinReleaseQuery),
|
||||||
|
reinterpret_cast<void**>(&gOriginalMappinReleaseQuery));
|
||||||
|
AttachAbsoluteHook("MappinSystem::ActiveRoute slot3a8", gMappinActiveRouteTarget,
|
||||||
|
reinterpret_cast<void*>(&DetourMappinActiveRoute),
|
||||||
|
reinterpret_cast<void**>(&gOriginalMappinActiveRoute));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnRunningEnter(void* aApp)
|
bool OnRunningEnter(void* aApp)
|
||||||
@@ -739,6 +852,9 @@ RED4EXT_C_EXPORT bool RED4EXT_CALL Main(RED4ext::v1::PluginHandle aHandle, RED4e
|
|||||||
DetachProbeHook("SetMappinTrackingAlternativeWrapper", kSetMappinTrackingAlternativeWrapperRva);
|
DetachProbeHook("SetMappinTrackingAlternativeWrapper", kSetMappinTrackingAlternativeWrapperRva);
|
||||||
DetachAbsoluteHook("MappinSystem::SetTracked slot220", gMappinSetTrackedTarget);
|
DetachAbsoluteHook("MappinSystem::SetTracked slot220", gMappinSetTrackedTarget);
|
||||||
DetachAbsoluteHook("MappinSystem::ClearTracked slot228", gMappinClearTrackedTarget);
|
DetachAbsoluteHook("MappinSystem::ClearTracked slot228", gMappinClearTrackedTarget);
|
||||||
|
DetachAbsoluteHook("MappinSystem::PositionQuery slot2e0", gMappinPositionQueryTarget);
|
||||||
|
DetachAbsoluteHook("MappinSystem::ReleaseQuery slot368", gMappinReleaseQueryTarget);
|
||||||
|
DetachAbsoluteHook("MappinSystem::ActiveRoute slot3a8", gMappinActiveRouteTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user