From 0f1072c3020ba41c8539377f80b32a3eb12ad3aa Mon Sep 17 00:00:00 2001 From: NovaRain Date: Tue, 27 Dec 2016 14:19:54 +0800 Subject: [PATCH] Made WorldMapEncounterFix/Rate independent from WorldMapFPSPatch. (#62, with the simplified code from Crafty) --- artifacts/ddraw.ini | 8 ++++---- sfall/Modules/Misc.cpp | 27 ++++++++++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index cf0f48a8..9d353b9c 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -164,6 +164,10 @@ WorldMapFPSPatch=1 ;Controls the world map speed if WorldMapFPSPatch is 1. Higher values cause slower movement WorldMapDelay2=66 +;Set to 1 to enable Ray's patch to make world map encounter rate independent of your travel speed +WorldMapEncounterFix=0 +WorldMapEncounterRate=6 + ;XX OBSOLETE XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ;XX ;XX ;This will change the physical speed at which you move across the map @@ -175,10 +179,6 @@ WorldMapDelay2=66 ;XX ;Only set to 1 if your systems high performance timer is unreliable for some reason ;XX ForceLowResolutionTimer=0 ;XX -;XX ;Set to 1 to enable Ray's patch to make world map encounter rate independent of your travel speed -;XX WorldMapEncounterFix=0 -;XX WorldMapEncounterRate=6 -;XX ;XX ;Obsolete, but can still be used if you know what it does. ;XX ;WorldMapDelay=0 ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX diff --git a/sfall/Modules/Misc.cpp b/sfall/Modules/Misc.cpp index c4cfdc0f..e5c04ded 100644 --- a/sfall/Modules/Misc.cpp +++ b/sfall/Modules/Misc.cpp @@ -224,6 +224,22 @@ static void __declspec(naked) WorldMapEncPatch3() { } } +static DWORD WorldMapEncounterRate; +static void __declspec(naked) wmWorldMapFunc_hook() { + __asm { + inc dword ptr ds:[VARPTR_wmLastRndTime]; + jmp FuncOffs::wmPartyWalkingStep_; + } +} + +static void __declspec(naked) wmRndEncounterOccurred_hack() { + __asm { + xor ecx, ecx; + cmp edx, WorldMapEncounterRate; + retn; + } +} + static void __declspec(naked) Combat_p_procFix() { __asm { push eax; @@ -590,13 +606,10 @@ void ApplyWorldmapFpsPatch() { } if (GetPrivateProfileIntA("Misc", "WorldMapEncounterFix", 0, ini)) { dlog("Applying world map encounter patch.", DL_INIT); - SafeWrite32(0x004bfee1, ((DWORD)&WorldMapEncPatch1) - 0x004bfee5); - SafeWrite32(0x004c0663, ((DWORD)&WorldMapEncPatch3) - 0x004c0667);//replaces 'call Difference(GetTickCount(), TicksSinceLastEncounter)' - SafeWrite16(0x004c0668, GetPrivateProfileIntA("Misc", "WorldMapEncounterRate", 5, ini)); //replaces cmp eax, 0x5dc with cmp eax, - SafeWrite16(0x004c0677, 0xE890); //nop, call relative. Replaces 'mov TicksSinceLastEncounter, ecx' - SafeWrite32(0x004c0679, ((DWORD)&WorldMapEncPatch2) - 0x004c067D); - SafeWrite8(0x004c232d, 0xb8); //'mov eax, 0', replaces 'mov eax, GetTickCount()' - SafeWrite32(0x004c232e, 0); + WorldMapEncounterRate = GetPrivateProfileIntA("Misc", "WorldMapEncounterRate", 5, ini); + SafeWrite32(0x4C232D, 0x01EBC031); // xor eax, eax; jmps 0x4C2332 + HookCall(0x4BFEE0, &wmWorldMapFunc_hook); + MakeCall(0x4C0667, &wmRndEncounterOccurred_hack, false); dlogr(" Done", DL_INIT); } }