Rewrote Force Encounter script function code.

Added two functions to Utils.cpp.
Minor edits to BugFixes.cpp and ddraw.ini.
This commit is contained in:
NovaRain
2019-04-24 10:05:47 +08:00
parent 28493432db
commit 1b1b85c3b4
6 changed files with 62 additions and 40 deletions
+3 -2
View File
@@ -78,9 +78,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
+1 -1
View File
@@ -248,7 +248,7 @@ public:
} }
} }
} }
if (middleMouseKey&&MouseState.rgbButtons[2]) { if (middleMouseKey && MouseState.rgbButtons[2]) {
if (!middleMouseDown) { if (!middleMouseDown) {
TapKey(middleMouseKey); TapKey(middleMouseKey);
middleMouseDown = true; middleMouseDown = true;
+7 -8
View File
@@ -689,13 +689,12 @@ skip:
static void __declspec(naked) inven_pickup_hack() { static void __declspec(naked) inven_pickup_hack() {
__asm { __asm {
mov edx, ds:[FO_VAR_pud] mov edx, ds:[FO_VAR_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
} }
} }
@@ -2204,7 +2203,7 @@ void BugFixes::init()
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);
+23 -27
View File
@@ -32,37 +32,33 @@ namespace script
{ {
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 fo::funcoffs::map_load_idx_;
call ForceEncounter4;
pop edx;
pop ecx;
pop eax;
retn;
} }
} }
static void __fastcall ForceEncounter2(DWORD mapID, DWORD flags) { static void __fastcall ForceEncounter(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);
} }
@@ -71,9 +67,9 @@ void __declspec(naked) op_force_encounter() {
push ecx; push ecx;
push edx; push edx;
_GET_ARG_INT(end); _GET_ARG_INT(end);
xor edx, edx; xor edx, edx; // flags
mov ecx, eax; mov ecx, eax; // mapID
call ForceEncounter2; call ForceEncounter;
end: end:
pop edx; pop edx;
pop ecx; pop ecx;
@@ -83,7 +79,7 @@ end:
void __declspec(naked) op_force_encounter_with_flags() { void __declspec(naked) op_force_encounter_with_flags() {
__asm { __asm {
pushad pushad;
mov ecx, eax; mov ecx, eax;
call fo::funcoffs::interpretPopShort_; call fo::funcoffs::interpretPopShort_;
mov edx, eax; mov edx, eax;
@@ -99,11 +95,11 @@ void __declspec(naked) op_force_encounter_with_flags() {
jnz end; jnz end;
cmp di, VAR_TYPE_INT; cmp di, VAR_TYPE_INT;
jnz end; jnz end;
mov edx, ebx; mov edx, ebx; // flags
mov ecx, eax; mov ecx, eax; // mapID
call ForceEncounter2; call ForceEncounter;
end: end:
popad popad;
retn; retn;
} }
} }
+24 -2
View File
@@ -1,9 +1,9 @@
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#include "Utils.h" #include "Utils.h"
namespace sfall namespace sfall
{ {
std::vector<std::string> split(const std::string &s, char delim) { std::vector<std::string> split(const std::string &s, char delim) {
@@ -25,4 +25,26 @@ void ToLowerCase(std::string& line) {
std::transform(line.begin(), line.end(), line.begin(), ::tolower); std::transform(line.begin(), line.end(), line.begin(), ::tolower);
} }
bool isSpace(char c) {
return (c == ' ' || c == '\t' /*|| c == '\n' || c == '\r'*/);
}
void strtrim(char* str) {
if (str[0] == 0) return;
int len = strlen(str) - 1;
int i = len;
while (len >= 0 && isSpace(str[len])) len--;
if (i != len) str[len + 1] = '\0'; // delete all spaces on the right
i = 0;
while (i < len && isSpace(str[i])) i++;
if (i > 0) {
int j = 0;
do {
str[j] = str[j + i]; // shift all chars (including null char) to the left
} while (++j <= len);
}
}
} }
+4
View File
@@ -28,4 +28,8 @@ std::string trim(const std::string& str);
void ToLowerCase(std::string& line); void ToLowerCase(std::string& line);
bool isSpace(char c);
void strtrim(char* str);
} }