Skip to content

Commit

Permalink
Added a new value to the 'mark_state' arg of mark_area_known function
Browse files Browse the repository at this point in the history
* 3 - uncovers locations without highlighting their sub-tiles.
(Fallout 1 behavior)
  • Loading branch information
NovaRain committed Feb 29, 2020
1 parent ac0b0ef commit e7e5da8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
44 changes: 26 additions & 18 deletions sfall/Modules/BugFixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Drugs.h"
#include "LoadGameHook.h"
#include "ScriptExtender.h"
#include "Worldmap.h"

#include "BugFixes.h"

Expand Down Expand Up @@ -2269,27 +2270,30 @@ static void __declspec(naked) action_climb_ladder_hack() {
}
}

//static const DWORD wmAreaMarkVisitedState_Error = 0x4C4698;
static const DWORD wmAreaMarkVisitedState_Ret = 0x4C46A2;
static void __declspec(naked) wmAreaMarkVisitedState_hack() {
static const DWORD wmAreaMarkVisitedState_Ret = 0x4C46A2;
//static const DWORD wmAreaMarkVisitedState_Error = 0x4C4698;
static long isNoRadius;

isNoRadius = Worldmap::AreaMarkStateIsNoRadius(); // F1 behavior radius
__asm {
mov [ecx + 0x40], esi; // wmAreaInfoList.visited
test esi, esi; // mark "unknown" state
jz skip;
jz noRadius;
mov eax, [ecx + 0x2C]; // wmAreaInfoList.world_posx
mov edx, [ecx + 0x30]; // wmAreaInfoList.world_posy
// fix loc coordinates
cmp [ecx + 0x34], 1; // wmAreaInfoList.size
jg largeLoc;
je mediumLoc;
//smallLoc:
sub eax, 5;
lea edx, [edx - 5];
sub eax, 5;
lea edx, [edx - 5];
mediumLoc:
sub eax, 10;
lea edx, [edx - 10];
sub eax, 10;
lea edx, [edx - 10];
largeLoc:
mov ebx, esp; // ppSubTile out
lea ebx, [esp]; // ppSubTile out
push edx;
push eax;
call fo::funcoffs::wmFindCurSubTileFromPos_;
Expand All @@ -2298,19 +2302,23 @@ static void __declspec(naked) wmAreaMarkVisitedState_hack() {
pop eax;
pop edx;
mov ebx, [esp];
mov ebx, [ebx + 0x18]; // sub-tile state
mov ebx, [ebx + 0x18]; // sub-tile state: 0 - black, 1 - uncovered, 2 - visited
test ebx, ebx;
jnz skip;
inc ebx; // 1
inc ebx; // set 1
skip:
cmp [ecx + 0x38], 1; // wmAreaInfoList.start_state
jne hideLoc;
cmp esi, 2; // mark visited state
jne fix;
///////// check F1 behavior radius result /////////
cmp isNoRadius, 1;
je noRadius;
///////////////////////////////////////////////////
cmp [ecx + 0x38], 1; // wmAreaInfoList.start_state
jne noRadius; // hidden location
cmp esi, 2; // mark visited state
jne fixRadius;
call fo::funcoffs::wmMarkSubTileRadiusVisited_;
hideLoc:
noRadius:
jmp wmAreaMarkVisitedState_Ret;
fix:
fixRadius:
push ebx;
mov ebx, 1; // radius (fix w/o PERK_scout)
call fo::funcoffs::wmSubTileMarkRadiusVisited_;
Expand Down Expand Up @@ -2359,8 +2367,8 @@ static void __declspec(naked) wmTownMapFunc_hack() {
}
}

static const DWORD combat_should_end_break = 0x422D00;
static void __declspec(naked) combat_should_end_hack() {
static const DWORD combat_should_end_break = 0x422D00;
__asm { // ecx = dude.team_num
cmp ecx, [ebp + 0x50]; // npc who_hit_me.team_num
je break;
Expand Down Expand Up @@ -2596,8 +2604,8 @@ static void __declspec(naked) combat_ai_hook() {
}
}

static const DWORD wmSubTileMarkRadiusVisited_Ret = 0x4C3730;
static void __declspec(naked) wmSubTileMarkRadiusVisited_hack() {
static const DWORD wmSubTileMarkRadiusVisited_Ret = 0x4C3730;
__asm {
call fo::funcoffs::wmMarkSubTileOffsetVisitedFunc_;
cmp ebp, 7; // count of horizontal sub-tiles
Expand Down
14 changes: 14 additions & 0 deletions sfall/Modules/Worldmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,20 @@ static void __declspec(naked) wmRndEncounterOccurred_hook() {
}
}

// Fallout 1 behavior: No radius for uncovered locations on the world map
// for the mark_area_known script function when the mark_state argument of the function is set to 3
long __declspec(naked) Worldmap::AreaMarkStateIsNoRadius() {
__asm {
xor eax, eax;
cmp esi, 3; // esi - mark_state value
jne skip;
mov esi, 1; // revert value to town known state
skip:
cmove eax, esi; // eax: 1 for Fallout 1 behavior
retn;
}
}

static void RestRestore() {
if (!restMode) return;
restMode = false;
Expand Down
2 changes: 2 additions & 0 deletions sfall/Modules/Worldmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Worldmap : public Module {
static bool AreaTitlesIsEmpty();
static const char* GetCustomAreaTitle(long areaId);
static void SetCustomAreaTitle(long areaId, const char* msg);

static long AreaMarkStateIsNoRadius();
};

void _stdcall SetMapMulti(float value);
Expand Down

5 comments on commit e7e5da8

@ghost2238
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, great work! If all works as it should, we can retire another hack, that one especially bad since it's modifying sfall code :)

@Lexx2k and @wipe2238: Guess it's just a matter of adding #define MARK_STATE_FALLOUT1 (3) or something like that to define.h and then change the mark_on_map macro to use this.

@Lexx2k
Copy link

@Lexx2k Lexx2k commented on e7e5da8 Feb 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem is that I don't know how to differentiate between "is classic wm mod loaded or not" - because I'd like cities only uncover like that with the classic wm mod enabled, in case someone likes the Fo2-way of things more.

@ghost2238
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the mod can set a GVAR which is then used in mark_on_map to check which way it should be?

@wipe2238
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

@Lexx2k
Copy link

@Lexx2k Lexx2k commented on e7e5da8 Feb 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done already. Our gl_0 script will set a gvar to 0 (because it always runs first), and the classic wm mod gl script will set it to 1 again.

Please sign in to comment.