Rewrote Force Encounter script function code.

Changed set_global_script_repeat/type & set_self to use fastcall.
Minor edits to BugFixes.cpp and ddraw.ini.
This commit is contained in:
NovaRain
2019-04-24 15:06:07 +08:00
parent 45baeff397
commit 560eead694
7 changed files with 67 additions and 71 deletions
+3 -2
View File
@@ -70,9 +70,10 @@ GraphicsHeight=0
;GPU is faster, but requires v2.0 pixel shader support ;GPU is faster, but requires v2.0 pixel shader support
GPUBlt=0 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 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) ;Requires DX9 graphics mode and v2.0 pixel shader support (see GPUBlt option)
Use32BitHeadGraphics=0 Use32BitHeadGraphics=0
+7 -8
View File
@@ -679,13 +679,12 @@ skip:
static void __declspec(naked) inven_pickup_hack() { static void __declspec(naked) inven_pickup_hack() {
__asm { __asm {
mov edx, ds:[_pud] mov edx, ds:[_pud];
mov edx, [edx] // itemsCount mov edx, [edx]; // itemsCount
dec edx dec edx;
sub edx, eax sub edx, eax;
lea edx, ds:0[edx*8] lea edx, ds:0[edx * 8];
push 0x470EC9 retn;
retn
} }
} }
@@ -2166,7 +2165,7 @@ void BugsInit()
dlog("Applying inventory reverse order issues fix.", DL_INIT); dlog("Applying inventory reverse order issues fix.", DL_INIT);
// Fix for minor visual glitch when picking up solo item from the top of inventory // 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 // 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 // Fix for error in player's inventory, related to IFACE_BAR_MODE=1 in f2_res.ini, and
// also for reverse order error // also for reverse order error
MakeJump(0x47114A, inven_pickup_hack2); MakeJump(0x47114A, inven_pickup_hack2);
+1
View File
@@ -472,6 +472,7 @@ const DWORD make_path_func_ = 0x415EFC;
const DWORD make_straight_path_func_ = 0x4163C8; const DWORD make_straight_path_func_ = 0x4163C8;
const DWORD map_disable_bk_processes_ = 0x482104; const DWORD map_disable_bk_processes_ = 0x482104;
const DWORD map_enable_bk_processes_ = 0x4820C0; const DWORD map_enable_bk_processes_ = 0x4820C0;
const DWORD map_load_idx_ = 0x482B34;
const DWORD mem_free_ = 0x4C5C24; const DWORD mem_free_ = 0x4C5C24;
const DWORD mem_malloc_ = 0x4C5AD0; const DWORD mem_malloc_ = 0x4C5AD0;
const DWORD mem_realloc_ = 0x4C5B50; const DWORD mem_realloc_ = 0x4C5B50;
+1
View File
@@ -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 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_disable_bk_processes_;
extern const DWORD map_enable_bk_processes_; extern const DWORD map_enable_bk_processes_;
extern const DWORD map_load_idx_;
extern const DWORD mem_free_; extern const DWORD mem_free_;
extern const DWORD mem_malloc_; extern const DWORD mem_malloc_;
extern const DWORD mem_realloc_; extern const DWORD mem_realloc_;
+29 -33
View File
@@ -495,11 +495,14 @@ 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++) { for (DWORD d = 0; d < globalScripts.size(); d++) {
if (globalScripts[d].prog.ptr == script) { if (globalScripts[d].prog.ptr == script) {
if (frames == 0xFFFFFFFF) globalScripts[d].mode = !globalScripts[d].mode; if (frames == 0xFFFFFFFF) {
else globalScripts[d].repeat = frames; globalScripts[d].mode = !globalScripts[d].mode;
} else {
globalScripts[d].repeat = frames;
}
break; break;
} }
} }
@@ -507,7 +510,6 @@ static void _stdcall SetGlobalScriptRepeat2(DWORD script, DWORD frames) {
static void __declspec(naked) SetGlobalScriptRepeat() { static void __declspec(naked) SetGlobalScriptRepeat() {
__asm { __asm {
push ebx;
push ecx; push ecx;
push edx; push edx;
mov ecx, eax; mov ecx, eax;
@@ -517,30 +519,28 @@ static void __declspec(naked) SetGlobalScriptRepeat() {
call interpretPopLong_; call interpretPopLong_;
cmp dx, VAR_TYPE_INT; cmp dx, VAR_TYPE_INT;
jnz end; jnz end;
push eax; mov edx, eax; // frames
push ecx; call SetGlobalScriptRepeat2; // ecx - script
call SetGlobalScriptRepeat2;
end: end:
pop edx; pop edx;
pop ecx; pop ecx;
pop ebx;
retn; retn;
} }
} }
static void _stdcall SetGlobalScriptType2(DWORD script, DWORD type) { static void __fastcall SetGlobalScriptType2(DWORD script, DWORD type) {
if (type > 3) return; if (type <= 3) {
for (DWORD d = 0; d < globalScripts.size(); d++) { for (size_t d = 0; d < globalScripts.size(); d++) {
if (globalScripts[d].prog.ptr == script) { if (globalScripts[d].prog.ptr == script) {
globalScripts[d].mode = type; globalScripts[d].mode = type;
break; break;
}
} }
} }
} }
static void __declspec(naked) SetGlobalScriptType() { static void __declspec(naked) SetGlobalScriptType() {
__asm { __asm {
push ebx;
push ecx; push ecx;
push edx; push edx;
mov ecx, eax; mov ecx, eax;
@@ -550,20 +550,17 @@ static void __declspec(naked) SetGlobalScriptType() {
call interpretPopLong_; call interpretPopLong_;
cmp dx, VAR_TYPE_INT; cmp dx, VAR_TYPE_INT;
jnz end; jnz end;
push eax; mov edx, eax; // type
push ecx; call SetGlobalScriptType2; // ecx - script
call SetGlobalScriptType2;
end: end:
pop edx; pop edx;
pop ecx; pop ecx;
pop ebx;
retn; retn;
} }
} }
static void __declspec(naked) GetGlobalScriptTypes() { static void __declspec(naked) GetGlobalScriptTypes() {
__asm { __asm {
push ebx;
push ecx; push ecx;
push edx; push edx;
mov edx, AvailableGlobalScriptTypes; mov edx, AvailableGlobalScriptTypes;
@@ -574,7 +571,6 @@ static void __declspec(naked) GetGlobalScriptTypes() {
call interpretPushShort_; call interpretPushShort_;
pop edx; pop edx;
pop ecx; pop ecx;
pop ebx;
retn; retn;
} }
} }
@@ -770,7 +766,6 @@ end:
static void __declspec(naked) SetSfallReturn() { static void __declspec(naked) SetSfallReturn() {
__asm { __asm {
push ebx;
push ecx; push ecx;
push edx; push edx;
mov ecx, eax; mov ecx, eax;
@@ -785,7 +780,6 @@ static void __declspec(naked) SetSfallReturn() {
end: end:
pop edx; pop edx;
pop ecx; pop ecx;
pop ebx;
retn; retn;
} }
} }
@@ -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); stdext::hash_map<DWORD, SelfOverrideObj>::iterator it = selfOverrideMap.find(script);
bool isFind = (it != selfOverrideMap.end()); bool isFind = (it != selfOverrideMap.end());
if (obj) { if (obj) {
@@ -830,22 +824,24 @@ static void _stdcall set_self2(DWORD script, TGameObj* obj) {
static void __declspec(naked) set_self() { static void __declspec(naked) set_self() {
__asm { __asm {
pushad; push ecx;
mov ebp, eax; push edx;
mov ecx, eax;
call interpretPopShort_; call interpretPopShort_;
mov edi, eax; mov edx, eax;
mov eax, ebp; mov eax, ecx;
call interpretPopLong_; call interpretPopLong_;
cmp di, VAR_TYPE_INT; cmp dx, VAR_TYPE_INT;
jnz end; jnz end;
push eax; mov edx, eax; // object
push ebp; call SetSelfObject; // ecx - script
call set_self2;
end: end:
popad; pop edx;
pop ecx;
retn; retn;
} }
} }
static void __declspec(naked) register_hook() { static void __declspec(naked) register_hook() {
__asm { __asm {
pushad; pushad;
+25 -27
View File
@@ -24,40 +24,38 @@
static DWORD EncounteredHorrigan; static DWORD EncounteredHorrigan;
static void _stdcall ForceEncounter4() { static DWORD ForceEnconterMapID;
static void _stdcall ForceEncounterRestore() {
*(DWORD*)0x672E04 = EncounteredHorrigan; *(DWORD*)0x672E04 = EncounteredHorrigan;
SafeWrite32(0x4C070E, 0x95); SafeWrite32(0x4C070E, *(DWORD*)0x4C0718); // map id
SafeWrite32(0x4C0718, 0x95); SafeWrite16(0x4C06D8, 0x5175);
SafeWrite32(0x4C06D1, 0x2E043D83);
SafeWrite32(0x4C071D, 0xFFFC2413); SafeWrite32(0x4C071D, 0xFFFC2413);
SafeWrite8(0x4C0706, 0x75); SafeWrite8(0x4C0706, 0x75);
} }
static void __declspec(naked) ForceEncounter3() {
static void __declspec(naked) wmRndEncounterOccurred_hook() {
__asm { __asm {
push eax;
push ecx; push ecx;
push edx; call ForceEncounterRestore;
mov eax, [esp + 0xC]; pop ecx;
sub eax, 5; mov eax, ForceEnconterMapID;
mov [esp + 0xC], eax; jmp map_load_idx_;
call ForceEncounter4;
pop edx;
pop ecx;
pop eax;
retn;
} }
} }
static void _stdcall ForceEncounter2(DWORD mapID, DWORD flags) {
static void __fastcall ForceEncounter2(DWORD mapID, DWORD flags) {
EncounteredHorrigan = *(DWORD*)0x672E04; EncounteredHorrigan = *(DWORD*)0x672E04;
ForceEnconterMapID = mapID;
SafeWrite32(0x4C070E, mapID); SafeWrite32(0x4C070E, mapID);
SafeWrite32(0x4C0718, mapID); SafeWrite16(0x4C06D8, 0x13EB); // jmp 0x4C06ED
SafeWrite32(0x4C06D1, 0x18EBD231); //xor edx, edx / jmp 0x18 HookCall(0x4C071C, wmRndEncounterOccurred_hook);
HookCall(0x4C071C, &ForceEncounter3);
if (flags & 1) SafeWrite8(0x4C0706, 0xEB); if (flags & 1) SafeWrite8(0x4C0706, 0xEB);
} }
static void __declspec(naked) ForceEncounter() { static void __declspec(naked) ForceEncounter() {
__asm { __asm {
push ebx;
push ecx; push ecx;
push edx; push edx;
mov ecx, eax; mov ecx, eax;
@@ -67,19 +65,19 @@ static void __declspec(naked) ForceEncounter() {
call interpretPopLong_; call interpretPopLong_;
cmp dx, VAR_TYPE_INT; cmp dx, VAR_TYPE_INT;
jnz end; jnz end;
push 0; xor edx, edx; // flags
push eax; mov ecx, eax; // mapID
call ForceEncounter2; call ForceEncounter2;
end: end:
pop edx; pop edx;
pop ecx; pop ecx;
pop ebx;
retn; retn;
} }
} }
static void __declspec(naked) ForceEncounterWithFlags() { static void __declspec(naked) ForceEncounterWithFlags() {
__asm { __asm {
pushad pushad;
mov ecx, eax; mov ecx, eax;
call interpretPopShort_; call interpretPopShort_;
mov edx, eax; mov edx, eax;
@@ -95,11 +93,11 @@ static void __declspec(naked) ForceEncounterWithFlags() {
jnz end; jnz end;
cmp di, VAR_TYPE_INT; cmp di, VAR_TYPE_INT;
jnz end; jnz end;
push ebx; mov edx, ebx; // flags
push eax; mov ecx, eax; // mapID
call ForceEncounter2; call ForceEncounter2;
end: end:
popad popad;
retn; retn;
} }
} }
+1 -1
View File
@@ -229,7 +229,7 @@ public:
} }
} }
} }
if (MiddleMouseKey&&MouseState.rgbButtons[2]) { if (MiddleMouseKey && MouseState.rgbButtons[2]) {
if (!MiddleMouseDown) { if (!MiddleMouseDown) {
TapKey(MiddleMouseKey); TapKey(MiddleMouseKey);
MiddleMouseDown = true; MiddleMouseDown = true;