Skip to content

Commit

Permalink
Rewrote Force Encounter script function code.
Browse files Browse the repository at this point in the history
Changed set_global_script_repeat/type & set_self to use fastcall.
Minor edits to BugFixes.cpp and ddraw.ini.
  • Loading branch information
NovaRain committed Apr 24, 2019
1 parent 45baeff commit 560eead
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 71 deletions.
5 changes: 3 additions & 2 deletions artifacts/ddraw.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ GraphicsHeight=0
;GPU is faster, but requires v2.0 pixel shader support
GPUBlt=0

;Set to 1 to allow using 32-bit .png textures for talking heads
;Set to 1 to allow using 32-bit textures for talking heads
;The texture files should be placed in art/heads/<name of the talking head FRM file>/ (w/o extension)
;The files in the folder should be numbered according to the number of frames in the talking head FRM file (e.g. 0.png - 10.png)
;The files in the folder should be numbered according to the number of frames in the talking head FRM file (0.png, 1.png, etc.)
;See the text file in the modders pack for a detailed description
;Requires DX9 graphics mode and v2.0 pixel shader support (see GPUBlt option)
Use32BitHeadGraphics=0

Expand Down
15 changes: 7 additions & 8 deletions sfall/Bugs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,12 @@ static void __declspec(naked) item_c_curr_size_hack() {

static void __declspec(naked) inven_pickup_hack() {
__asm {
mov edx, ds:[_pud]
mov edx, [edx] // itemsCount
dec edx
sub edx, eax
lea edx, ds:0[edx*8]
push 0x470EC9
retn
mov edx, ds:[_pud];
mov edx, [edx]; // itemsCount
dec edx;
sub edx, eax;
lea edx, ds:0[edx * 8];
retn;
}
}

Expand Down Expand Up @@ -2166,7 +2165,7 @@ void BugsInit()
dlog("Applying inventory reverse order issues fix.", DL_INIT);
// Fix for minor visual glitch when picking up solo item from the top of inventory
// and there is multiple item stack at the bottom of inventory
MakeJump(0x470EC2, inven_pickup_hack);
MakeCall(0x470EC2, inven_pickup_hack, 2);
// Fix for error in player's inventory, related to IFACE_BAR_MODE=1 in f2_res.ini, and
// also for reverse order error
MakeJump(0x47114A, inven_pickup_hack2);
Expand Down
1 change: 1 addition & 0 deletions sfall/FalloutEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ const DWORD make_path_func_ = 0x415EFC;
const DWORD make_straight_path_func_ = 0x4163C8;
const DWORD map_disable_bk_processes_ = 0x482104;
const DWORD map_enable_bk_processes_ = 0x4820C0;
const DWORD map_load_idx_ = 0x482B34;
const DWORD mem_free_ = 0x4C5C24;
const DWORD mem_malloc_ = 0x4C5AD0;
const DWORD mem_realloc_ = 0x4C5B50;
Expand Down
1 change: 1 addition & 0 deletions sfall/FalloutEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ extern const DWORD make_path_func_;
extern const DWORD make_straight_path_func_; // (TGameObj *aObj<eax>, int aTileFrom<edx>, int a3<ecx>, signed int aTileTo<ebx>, TGameObj **aObjResult, int a5, int (*a6)(void))
extern const DWORD map_disable_bk_processes_;
extern const DWORD map_enable_bk_processes_;
extern const DWORD map_load_idx_;
extern const DWORD mem_free_;
extern const DWORD mem_malloc_;
extern const DWORD mem_realloc_;
Expand Down
62 changes: 29 additions & 33 deletions sfall/ScriptExtender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,19 +495,21 @@ TScript OverrideScriptStruct = {0};



static void _stdcall SetGlobalScriptRepeat2(DWORD script, DWORD frames) {
static void __fastcall SetGlobalScriptRepeat2(DWORD script, DWORD frames) {
for (DWORD d = 0; d < globalScripts.size(); d++) {
if (globalScripts[d].prog.ptr == script) {
if (frames == 0xFFFFFFFF) globalScripts[d].mode = !globalScripts[d].mode;
else globalScripts[d].repeat = frames;
if (frames == 0xFFFFFFFF) {
globalScripts[d].mode = !globalScripts[d].mode;
} else {
globalScripts[d].repeat = frames;
}
break;
}
}
}

static void __declspec(naked) SetGlobalScriptRepeat() {
__asm {
push ebx;
push ecx;
push edx;
mov ecx, eax;
Expand All @@ -517,30 +519,28 @@ static void __declspec(naked) SetGlobalScriptRepeat() {
call interpretPopLong_;
cmp dx, VAR_TYPE_INT;
jnz end;
push eax;
push ecx;
call SetGlobalScriptRepeat2;
mov edx, eax; // frames
call SetGlobalScriptRepeat2; // ecx - script
end:
pop edx;
pop ecx;
pop ebx;
retn;
}
}

static void _stdcall SetGlobalScriptType2(DWORD script, DWORD type) {
if (type > 3) return;
for (DWORD d = 0; d < globalScripts.size(); d++) {
if (globalScripts[d].prog.ptr == script) {
globalScripts[d].mode = type;
break;
static void __fastcall SetGlobalScriptType2(DWORD script, DWORD type) {
if (type <= 3) {
for (size_t d = 0; d < globalScripts.size(); d++) {
if (globalScripts[d].prog.ptr == script) {
globalScripts[d].mode = type;
break;
}
}
}
}

static void __declspec(naked) SetGlobalScriptType() {
__asm {
push ebx;
push ecx;
push edx;
mov ecx, eax;
Expand All @@ -550,20 +550,17 @@ static void __declspec(naked) SetGlobalScriptType() {
call interpretPopLong_;
cmp dx, VAR_TYPE_INT;
jnz end;
push eax;
push ecx;
call SetGlobalScriptType2;
mov edx, eax; // type
call SetGlobalScriptType2; // ecx - script
end:
pop edx;
pop ecx;
pop ebx;
retn;
}
}

static void __declspec(naked) GetGlobalScriptTypes() {
__asm {
push ebx;
push ecx;
push edx;
mov edx, AvailableGlobalScriptTypes;
Expand All @@ -574,7 +571,6 @@ static void __declspec(naked) GetGlobalScriptTypes() {
call interpretPushShort_;
pop edx;
pop ecx;
pop ebx;
retn;
}
}
Expand Down Expand Up @@ -770,7 +766,6 @@ static void __declspec(naked) SetSfallArg() {

static void __declspec(naked) SetSfallReturn() {
__asm {
push ebx;
push ecx;
push edx;
mov ecx, eax;
Expand All @@ -785,7 +780,6 @@ static void __declspec(naked) SetSfallReturn() {
end:
pop edx;
pop ecx;
pop ebx;
retn;
}
}
Expand All @@ -806,7 +800,7 @@ static void __declspec(naked) InitHook() {
}
}

static void _stdcall set_self2(DWORD script, TGameObj* obj) {
static void __fastcall SetSelfObject(DWORD script, TGameObj* obj) {
stdext::hash_map<DWORD, SelfOverrideObj>::iterator it = selfOverrideMap.find(script);
bool isFind = (it != selfOverrideMap.end());
if (obj) {
Expand All @@ -830,22 +824,24 @@ static void _stdcall set_self2(DWORD script, TGameObj* obj) {

static void __declspec(naked) set_self() {
__asm {
pushad;
mov ebp, eax;
push ecx;
push edx;
mov ecx, eax;
call interpretPopShort_;
mov edi, eax;
mov eax, ebp;
mov edx, eax;
mov eax, ecx;
call interpretPopLong_;
cmp di, VAR_TYPE_INT;
cmp dx, VAR_TYPE_INT;
jnz end;
push eax;
push ebp;
call set_self2;
mov edx, eax; // object
call SetSelfObject; // ecx - script
end:
popad;
pop edx;
pop ecx;
retn;
}
}

static void __declspec(naked) register_hook() {
__asm {
pushad;
Expand Down
52 changes: 25 additions & 27 deletions sfall/ScriptOps/WorldmapOps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,38 @@


static DWORD EncounteredHorrigan;
static void _stdcall ForceEncounter4() {
static DWORD ForceEnconterMapID;

static void _stdcall ForceEncounterRestore() {
*(DWORD*)0x672E04 = EncounteredHorrigan;
SafeWrite32(0x4C070E, 0x95);
SafeWrite32(0x4C0718, 0x95);
SafeWrite32(0x4C06D1, 0x2E043D83);
SafeWrite32(0x4C070E, *(DWORD*)0x4C0718); // map id
SafeWrite16(0x4C06D8, 0x5175);
SafeWrite32(0x4C071D, 0xFFFC2413);
SafeWrite8(0x4C0706, 0x75);
}
static void __declspec(naked) ForceEncounter3() {

static void __declspec(naked) wmRndEncounterOccurred_hook() {
__asm {
push eax;
push ecx;
push edx;
mov eax, [esp + 0xC];
sub eax, 5;
mov [esp + 0xC], eax;
call ForceEncounter4;
pop edx;
pop ecx;
pop eax;
retn;
call ForceEncounterRestore;
pop ecx;
mov eax, ForceEnconterMapID;
jmp map_load_idx_;
}
}
static void _stdcall ForceEncounter2(DWORD mapID, DWORD flags) {

static void __fastcall ForceEncounter2(DWORD mapID, DWORD flags) {
EncounteredHorrigan = *(DWORD*)0x672E04;
ForceEnconterMapID = mapID;
SafeWrite32(0x4C070E, mapID);
SafeWrite32(0x4C0718, mapID);
SafeWrite32(0x4C06D1, 0x18EBD231); //xor edx, edx / jmp 0x18
HookCall(0x4C071C, &ForceEncounter3);
SafeWrite16(0x4C06D8, 0x13EB); // jmp 0x4C06ED
HookCall(0x4C071C, wmRndEncounterOccurred_hook);

if (flags & 1) SafeWrite8(0x4C0706, 0xEB);
}

static void __declspec(naked) ForceEncounter() {
__asm {
push ebx;
push ecx;
push edx;
mov ecx, eax;
Expand All @@ -67,19 +65,19 @@ static void __declspec(naked) ForceEncounter() {
call interpretPopLong_;
cmp dx, VAR_TYPE_INT;
jnz end;
push 0;
push eax;
xor edx, edx; // flags
mov ecx, eax; // mapID
call ForceEncounter2;
end:
pop edx;
pop ecx;
pop ebx;
retn;
}
}

static void __declspec(naked) ForceEncounterWithFlags() {
__asm {
pushad
pushad;
mov ecx, eax;
call interpretPopShort_;
mov edx, eax;
Expand All @@ -95,11 +93,11 @@ static void __declspec(naked) ForceEncounterWithFlags() {
jnz end;
cmp di, VAR_TYPE_INT;
jnz end;
push ebx;
push eax;
mov edx, ebx; // flags
mov ecx, eax; // mapID
call ForceEncounter2;
end:
popad
popad;
retn;
}
}
Expand Down
2 changes: 1 addition & 1 deletion sfall/dinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class FakeDirectInputDevice : public IDirectInputDeviceA {
}
}
}
if (MiddleMouseKey&&MouseState.rgbButtons[2]) {
if (MiddleMouseKey && MouseState.rgbButtons[2]) {
if (!MiddleMouseDown) {
TapKey(MiddleMouseKey);
MiddleMouseDown = true;
Expand Down

1 comment on commit 560eead

@NovaRain
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

While set_global_script_repeat/type changes are pretty straightforward, I'm not 100% sure about set_self(). I tested it with drop_obj and use_obj_on_obj on dude_obj and the script works as usual, so I guess it's A-OK.

Please sign in to comment.