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
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
+1 -1
View File
@@ -248,7 +248,7 @@ public:
}
}
}
if (middleMouseKey&&MouseState.rgbButtons[2]) {
if (middleMouseKey && MouseState.rgbButtons[2]) {
if (!middleMouseDown) {
TapKey(middleMouseKey);
middleMouseDown = true;
+7 -8
View File
@@ -689,13 +689,12 @@ skip:
static void __declspec(naked) inven_pickup_hack() {
__asm {
mov edx, ds:[FO_VAR_pud]
mov edx, [edx] // itemsCount
dec edx
sub edx, eax
lea edx, ds:0[edx*8]
push 0x470EC9
retn
mov edx, ds:[FO_VAR_pud];
mov edx, [edx]; // itemsCount
dec edx;
sub edx, eax;
lea edx, ds:0[edx * 8];
retn;
}
}
@@ -2204,7 +2203,7 @@ void BugFixes::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
// 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);
+22 -26
View File
@@ -32,37 +32,33 @@ namespace script
{
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;
call ForceEncounterRestore;
pop ecx;
pop eax;
retn;
mov eax, ForceEnconterMapID;
jmp fo::funcoffs::map_load_idx_;
}
}
static void __fastcall ForceEncounter2(DWORD mapID, DWORD flags) {
static void __fastcall ForceEncounter(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);
}
@@ -71,9 +67,9 @@ void __declspec(naked) op_force_encounter() {
push ecx;
push edx;
_GET_ARG_INT(end);
xor edx, edx;
mov ecx, eax;
call ForceEncounter2;
xor edx, edx; // flags
mov ecx, eax; // mapID
call ForceEncounter;
end:
pop edx;
pop ecx;
@@ -83,7 +79,7 @@ end:
void __declspec(naked) op_force_encounter_with_flags() {
__asm {
pushad
pushad;
mov ecx, eax;
call fo::funcoffs::interpretPopShort_;
mov edx, eax;
@@ -99,11 +95,11 @@ void __declspec(naked) op_force_encounter_with_flags() {
jnz end;
cmp di, VAR_TYPE_INT;
jnz end;
mov edx, ebx;
mov ecx, eax;
call ForceEncounter2;
mov edx, ebx; // flags
mov ecx, eax; // mapID
call ForceEncounter;
end:
popad
popad;
retn;
}
}
+22
View File
@@ -25,4 +25,26 @@ void ToLowerCase(std::string& line) {
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);
bool isSpace(char c);
void strtrim(char* str);
}