diff --git a/red4ext/EdgeWeightGPS/src/Main.cpp b/red4ext/EdgeWeightGPS/src/Main.cpp index cf027ac..d8ac54b 100644 --- a/red4ext/EdgeWeightGPS/src/Main.cpp +++ b/red4ext/EdgeWeightGPS/src/Main.cpp @@ -3827,35 +3827,26 @@ float DetourGpsTrafficEdgeScore(void* aSearchContext, void* aCandidate, void* aR baseScore = gOriginalGpsTrafficEdgeScore(aSearchContext, aCandidate, aReferencePoint); } - void* query = nullptr; - void* lane = nullptr; + auto* query = ReadPointerField(aSearchContext, 0x10); + auto* lane = ReadPointerField(aCandidate, 0x00); uint8_t queryMode = 0xFF; uint16_t laneFlags = 0; - - if (aSearchContext) - { - query = *reinterpret_cast(reinterpret_cast(aSearchContext) + 0x10); - } if (query) { - queryMode = *reinterpret_cast(reinterpret_cast(query) + 0x41); - } - if (aCandidate) - { - lane = *reinterpret_cast(aCandidate); + TryReadMemory(reinterpret_cast(reinterpret_cast(query) + 0x41), queryMode); } if (lane) { - laneFlags = *reinterpret_cast(reinterpret_cast(lane) + 0x88); + TryReadMemory(reinterpret_cast(reinterpret_cast(lane) + 0x88), laneFlags); } const auto driving = queryMode == 0; const auto multiplier = TrafficEdgeScoreMultiplier(laneFlags, driving); const auto patchedScore = baseScore * multiplier; - constexpr LONG kMaxLoggedCalls = 256; + constexpr LONG kMaxLoggedCalls = 64; LONG callCount = -1; - if (gGpsTrafficEdgeScoreLogCount < kMaxLoggedCalls) + if (InterlockedCompareExchange(&gGpsTrafficEdgeScoreLogCount, 0, 0) < kMaxLoggedCalls) { callCount = InterlockedIncrement(&gGpsTrafficEdgeScoreLogCount) - 1; }