diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index e6de7352..4e1471d2 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -629,10 +629,14 @@ UseWalkDistance=3 ;Set to 1 to fix the bug of being unable to sell used geiger counters or stealth boys CanSellUsedGeiger=1 -;Set to 1 to fix the issue with being able to charge the car by using cells on other scenary/critters +;Set to 1 to fix the issue with being able to charge the car by using cells on other scenery/critters ;Set to 0 if another mod you're using has custom vehicles CarChargingFix=1 +;Set to 1 to prevent the car from being lost when entering a location via the Town/World button and then leaving on foot +;Note that the global variable 633 (GVAR_CAR_PLACED_TILE) will be set to -1 when the player leaves a location +CarPlacedTileFix=1 + ;Set to 1 to skip weapon equip/unequip animations when performing various actions InstantWeaponEquip=0 diff --git a/sfall/BugFixes.cpp b/sfall/BugFixes.cpp index 6f6c85ab..e50b4af7 100644 --- a/sfall/BugFixes.cpp +++ b/sfall/BugFixes.cpp @@ -2241,6 +2241,20 @@ break: } } +static void __declspec(naked) wmInterfaceInit_hack() { + __asm { + mov eax, 633; // GVAR_CAR_PLACED_TILE + cmp eax, dword ptr ds:[_num_game_global_vars]; + jge skip; + mov edx, ds:[_game_global_vars]; + lea edx, [edx + eax * 4]; + mov dword ptr [edx], -1; // set gvar +skip: + mov edx, 12; + retn; + } +} + void BugFixesInit() { #ifndef NDEBUG @@ -2825,4 +2839,12 @@ void BugFixesInit() // Fix for combat not ending automatically when there are no hostile critters MakeCall(0x422CF3, combat_should_end_hack); SafeWrite16(0x422CEA, 0x0C74); // jz 0x422CF8 (skip party members) + + // Fix for the car being lost when entering a location via the Town/World button and then leaving on foot + // (sets GVAR_CAR_PLACED_TILE (633) to -1 on exit to the world map) + if (GetPrivateProfileIntA("Misc", "CarPlacedTileFix", 1, ini)) { + dlog("Applying car placed tile fix.", DL_INIT); + MakeCall(0x4C2367, wmInterfaceInit_hack); + dlogr(" Done", DL_INIT); + } } diff --git a/sfall/ScriptOps/WorldmapOps.hpp b/sfall/ScriptOps/WorldmapOps.hpp index 33965267..f68b800b 100644 --- a/sfall/ScriptOps/WorldmapOps.hpp +++ b/sfall/ScriptOps/WorldmapOps.hpp @@ -69,7 +69,7 @@ static void _stdcall ForceEncounter2() { ForceEnconterMapID = mapID; DWORD flags = 0; if (opHandler.numArgs() > 1) { - flags = opHandler.arg(1).asInt(); + flags = opHandler.arg(1).asInt(); // no arg check if (flags & 2) { // _Lock flag flags |= (1 << 31); // set bit 31 } else {