diff --git a/red4ext/EdgeWeightGPS/src/Main.cpp b/red4ext/EdgeWeightGPS/src/Main.cpp index ce71920..20b54a7 100644 --- a/red4ext/EdgeWeightGPS/src/Main.cpp +++ b/red4ext/EdgeWeightGPS/src/Main.cpp @@ -105,6 +105,7 @@ constexpr bool kEnableGpsProviderClassPatch = false; constexpr bool kEnableGpsProviderClassPatchTrace = false; constexpr bool kEnableGpsTraceHooks = true; constexpr bool kEnableGpsQueryLifecycleHooks = false; +constexpr bool kEnableGpsQueryResultTraceHooks = true; constexpr bool kEnableGpsAsyncTrafficProbe = false; constexpr bool kEnableGpsTrafficEdgeWeightPatch = false; constexpr bool kEnableGpsSpatialEdgeWeightPatch = true; @@ -3878,13 +3879,15 @@ int32_t DetourGpsQuerySubmit(void* aManager, void* aQuery) uintptr_t returnRva = 0; TryGetImageRva(returnAddress, returnRva); - const auto callCount = gGpsQuerySubmitLogCount; - const auto shouldLog = callCount < kMaxCalls; + const auto callCount = gGpsQuerySubmitLogCount++; uint32_t queryKind = 0; const auto hasQueryKind = aQuery && TryReadMemory(reinterpret_cast(reinterpret_cast(aQuery) + 0xCC), queryKind); const auto shouldTraceResolver = returnRva == kGpsMapRouteSubmitReturnRva && hasQueryKind && queryKind == 5; + const auto shouldLog = + callCount < kMaxCalls && + (kEnableGpsQueryLifecycleHooks || (returnRva == kGpsMapRouteSubmitReturnRva && hasQueryKind && queryKind == 5)); if (shouldTraceResolver) { ExtendGpsResolveTraceWindow(GetElapsedMs()); @@ -3908,7 +3911,6 @@ int32_t DetourGpsQuerySubmit(void* aManager, void* aQuery) } AppendReturnRva(line, returnAddress); LogRed4ext(line.str()); - ++gGpsQuerySubmitLogCount; } int32_t result = -1; @@ -3975,8 +3977,12 @@ bool DetourGpsQueryResultFetch(void* aManager, uint32_t aQueryId, void* aOutPath TrackedGpsQuery trackedQuery{}; uint32_t perQueryCall = 0; const auto isTracked = NoteTrackedGpsQueryResultFetch(aQueryId, aManager, trackedQuery, perQueryCall); - const auto shouldLog = (isTracked && (perQueryCall < kMaxTrackedSamplesPerQuery || result)) || - (!isTracked && callCount < kMaxUntrackedSamples && aQueryId < 2); + const auto isMapRouteQuery = isTracked && trackedQuery.submitReturnRva == kGpsMapRouteSubmitReturnRva; + const auto shouldLog = + kEnableGpsQueryLifecycleHooks + ? ((isTracked && (perQueryCall < kMaxTrackedSamplesPerQuery || result)) || + (!isTracked && callCount < kMaxUntrackedSamples && aQueryId < 2)) + : (result && isMapRouteQuery); if (shouldLog) { @@ -3992,7 +3998,7 @@ bool DetourGpsQueryResultFetch(void* aManager, uint32_t aQueryId, void* aOutPath AppendPointerWithRva(line, "outPath", aOutPath); AppendReturnRva(line, returnAddress); AppendPathBufferSummary(line, "outPath", aOutPath); - if (result && isTracked && trackedQuery.submitReturnRva == 0x8D20D4) + if (result && isMapRouteQuery) { AppendGpsResultObjectSummary(line, "gpsResult", aOutPath); } @@ -5180,15 +5186,21 @@ RED4EXT_C_EXPORT bool RED4EXT_CALL Main(RED4ext::v1::PluginHandle aHandle, RED4e AttachProbeHook("UpdateGPSQuery body 0x29bd254", kUpdateGpsQueryBodyRva, reinterpret_cast(&DetourUpdateGpsQueryBody), reinterpret_cast(&gOriginalUpdateGpsQueryBody)); + } + if (kEnableGpsQueryLifecycleHooks || kEnableGpsQueryResultTraceHooks) + { AttachProbeHook("GPSQuerySubmit 0x70a42c", kGpsQuerySubmitRva, reinterpret_cast(&DetourGpsQuerySubmit), reinterpret_cast(&gOriginalGpsQuerySubmit)); - AttachProbeHook("GPSQueryDispatch 0x70a570", kGpsQueryDispatchRva, - reinterpret_cast(&DetourGpsQueryDispatch), - reinterpret_cast(&gOriginalGpsQueryDispatch)); AttachProbeHook("GPSQueryResultFetch 0x7094b8", kGpsQueryResultFetchRva, reinterpret_cast(&DetourGpsQueryResultFetch), reinterpret_cast(&gOriginalGpsQueryResultFetch)); + } + if (kEnableGpsQueryLifecycleHooks) + { + AttachProbeHook("GPSQueryDispatch 0x70a570", kGpsQueryDispatchRva, + reinterpret_cast(&DetourGpsQueryDispatch), + reinterpret_cast(&gOriginalGpsQueryDispatch)); AttachProbeHook("GPSQueryStatus 0xaa5704", kGpsQueryStatusRva, reinterpret_cast(&DetourGpsQueryStatus), reinterpret_cast(&gOriginalGpsQueryStatus)); @@ -5395,9 +5407,15 @@ RED4EXT_C_EXPORT bool RED4EXT_CALL Main(RED4ext::v1::PluginHandle aHandle, RED4e { DetachProbeHook("RunGPSQuery body 0x29bd128", kRunGpsQueryBodyRva); DetachProbeHook("UpdateGPSQuery body 0x29bd254", kUpdateGpsQueryBodyRva); + } + if (kEnableGpsQueryLifecycleHooks || kEnableGpsQueryResultTraceHooks) + { DetachProbeHook("GPSQuerySubmit 0x70a42c", kGpsQuerySubmitRva); - DetachProbeHook("GPSQueryDispatch 0x70a570", kGpsQueryDispatchRva); DetachProbeHook("GPSQueryResultFetch 0x7094b8", kGpsQueryResultFetchRva); + } + if (kEnableGpsQueryLifecycleHooks) + { + DetachProbeHook("GPSQueryDispatch 0x70a570", kGpsQueryDispatchRva); DetachProbeHook("GPSQueryStatus 0xaa5704", kGpsQueryStatusRva); } if (kEnableGpsAsyncTrafficProbe)