Refactored some ASM code in BurstMods.cpp, Inventory.cpp, Credits.cpp, AnimationsAtOnceLimit.cpp.

This commit is contained in:
NovaRain
2019-01-01 10:27:40 +08:00
parent f36bd6fb61
commit 11c15cec93
5 changed files with 192 additions and 209 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ Image=24
;Set the number of buttons
ButtonCount=3
;Set up the appearance of the elevator
;Set the appearance of the elevator
MainFrm=148
ButtonsFrm=151
+3 -3
View File
@@ -162,7 +162,7 @@ skip:
call combat_anim_finished_;
end:
mov [edi][esi], ebx;
push 0x415DF2;
xor dl, dl; // goto 0x415DF2;
retn;
}
}
@@ -226,7 +226,7 @@ void ApplyAnimationsAtOncePatches(signed char aniMax) {
SafeWrite32(animMaxSizeCheck[i], animRecordSize * aniMax);
}
//divert old animation structure list pointers to newly alocated memory
//divert old animation structure list pointers to newly allocated memory
//struct array 1///////////////////
@@ -356,7 +356,7 @@ void AnimationsAtOnceInit() {
dlogr(" Done", DL_INIT);
}
// Fix for calling anim() functions in combat
MakeJump(0x415DE2, anim_set_end_hack);
MakeCall(0x415DE2, anim_set_end_hack, 1);
// Fix crash when the critter goes through a door with animation trigger
MakeJump(0x41755E, object_move_hack);
+41 -42
View File
@@ -20,50 +20,45 @@
#include "Logging.h"
static DWORD compute_spray_center_mult;
static DWORD compute_spray_center_div;
static DWORD compute_spray_target_mult;
static DWORD compute_spray_target_div;
static long compute_spray_center_mult;
static long compute_spray_center_div;
static long compute_spray_target_mult;
static long compute_spray_target_div;
static long __fastcall ComputeSpray(DWORD* roundsLeftOut, DWORD* roundsRightOut, DWORD totalRounds, DWORD* roundsCenterOut) {
// roundsCenter = totalRounds * mult / div
long result = totalRounds * compute_spray_center_mult;
long roundsCenter = result / compute_spray_center_div;
if (result % compute_spray_center_div) roundsCenter++; // if remainder then round up
if (roundsCenter == 0) roundsCenter = 1;
*roundsCenterOut = roundsCenter;
long roundsLeft = (totalRounds - roundsCenter) / 2;
*roundsLeftOut = roundsLeft;
*roundsRightOut = totalRounds - roundsCenter - roundsLeft;
// roundsMainTarget = roundsCenter * mult / div
result = roundsCenter * compute_spray_target_mult;
long roundsMainTarget = result / compute_spray_target_div;
return (result % compute_spray_target_div) ? ++roundsMainTarget : roundsMainTarget; // if remainder then round up
}
static const DWORD compute_spray_rounds_back = 0x42353A;
static void __declspec(naked) compute_spray_rounds_distribution() {
__asm {
// ebp - totalRounds
mov eax, ebp; // roundsCenter = totalRounds * mult / div
mov ebx, compute_spray_center_mult;
imul ebx; // multiply eax by ebx and store result in edx:eax
mov ebx, compute_spray_center_div; // divisor
idiv ebx; // divide edx:eax by ebx and store result in eax (edx)
test edx, edx; // if remainder (edx) is not 0
jz divEnd1;
inc eax; // round up
divEnd1:
mov [esp+16], eax; // roundsCenter
test eax, eax; // if (roundsCenter == 0)
jnz loc_42350F;
mov [esp+16], 1; // roundsCenter = 1;
loc_42350F:
mov eax, ebp; // roundsLeft = (totalRounds - roundsCenter) / 2
sub eax, [esp+16]; // - roundsCenter
sar eax, 1; // /2
mov [esp+8], eax; // roundsLeft
mov eax, ebp; // roundsRight = totalRounds - roundsCenter - roundsLeft
sub eax, [esp+16];
sub eax, [esp+8];
mov [esp+4], eax; // roundsRight
mov eax, [esp+16]; // roundsMainTarget = roundsCenter * mult / div
mov ebx, compute_spray_target_mult;
imul ebx;
mov ebx, compute_spray_target_div;
idiv ebx;
test edx, edx; // if remainder (edx) is not 0
jz divEnd2;
inc eax; // round up
divEnd2:
push ecx;
lea ecx, [esp + 8 + 4]; // roundsLeft - out
lea edx, [esp + 4 + 4]; // roundsRight - out
lea eax, [esp + 16 + 4];
push eax; // roundsCenter - out
push ebp; // totalRounds
call ComputeSpray;
pop ecx;
mov ebp, eax;
mov ebx, [esp + 16];
// at this point, eax should contain the same value as ebp (roundsMainTarget); ebx should contain value of roundsCenter
jmp compute_spray_rounds_back;
jmp compute_spray_rounds_back; // at this point, eax should contain the same value as ebp (roundsMainTarget); ebx should contain value of roundsCenter
}
}
@@ -73,16 +68,20 @@ void ComputeSprayModInit() {
dlog("Applying ComputeSpray changes.", DL_INIT);
compute_spray_center_mult = GetPrivateProfileIntA("Misc", "ComputeSpray_CenterMult", 1, ini);
compute_spray_center_div = GetPrivateProfileIntA("Misc", "ComputeSpray_CenterDiv", 3, ini);
if (compute_spray_center_div < 1)
if (compute_spray_center_div < 1) {
compute_spray_center_div = 1;
if (compute_spray_center_mult > compute_spray_center_div)
}
if (compute_spray_center_mult > compute_spray_center_div) {
compute_spray_center_mult = compute_spray_center_div;
}
compute_spray_target_mult = GetPrivateProfileIntA("Misc", "ComputeSpray_TargetMult", 1, ini);
compute_spray_target_div = GetPrivateProfileIntA("Misc", "ComputeSpray_TargetDiv", 2, ini);
if (compute_spray_target_div < 1)
if (compute_spray_target_div < 1) {
compute_spray_target_div = 1;
if (compute_spray_target_mult > compute_spray_target_div)
}
if (compute_spray_target_mult > compute_spray_target_div) {
compute_spray_target_mult = compute_spray_target_div;
}
MakeJump(0x4234F1, compute_spray_rounds_distribution);
dlogr(" Done", DL_INIT);
}
+32 -29
View File
@@ -29,7 +29,7 @@ static const char* ExtraLines[] = {
"#SFALL " VERSION_STRING,
"",
"sfall is free software, licensed under the GPL",
"Copyright 2008-2018 The sfall team",
"Copyright 2008-2019 The sfall team",
"",
"@Author",
"Timeslip",
@@ -63,29 +63,29 @@ static const char* ExtraLines[] = {
"Rain man",
"Continuum",
"Drobovik",
"Burn",
"Anyone who has used sfall in their own mods",
"The bug reporters and feature requesters",
""
"",
"",
"",
"#FALLOUT 2",
""
};
static DWORD ExtraLineCount = sizeof(ExtraLines) / 4;
//static const char* creditsFile = "credits.txt";
static const char* creditsFile = "credits.txt";
static void _stdcall ShowCreditsHook() {
static void __declspec(naked) ShowCreditsHook() {
InCredits = 1;
CreditsLine = 0;
__asm {
mov eax, creditsFile;
call credits_;
}
//__asm mov eax, creditsFile;
__asm call credits_;
InCredits = 0;
__asm retn;
}
static DWORD _stdcall CreditsNextLine(char* buf, DWORD* font, DWORD* colour) {
static DWORD __fastcall CreditsNextLine(char* buf, DWORD* font, DWORD* colour) {
if (!InCredits || CreditsLine >= ExtraLineCount) return 0;
const char* line = ExtraLines[CreditsLine++];
if (strlen(line)) {
@@ -109,13 +109,12 @@ static DWORD _stdcall CreditsNextLine(char* buf, DWORD* font, DWORD* colour) {
// Additional lines will be at the top of CREDITS.TXT contents
static void __declspec(naked) CreditsNextLineHook_Top() {
__asm {
pushad;
pushadc;
push ebx;
push edx;
push eax;
call CreditsNextLine;
mov ecx, eax;
call CreditsNextLine; // edx - font
test eax, eax;
popad;
popadc;
jz fail;
xor eax, eax;
inc eax;
@@ -128,32 +127,36 @@ fail:
// Additional lines will be at the bottom of CREDITS.TXT contents
static void __declspec(naked) CreditsNextLineHook_Bottom() {
__asm {
pushad;
push eax;
push edx;
push ebx;
call credits_get_next_line_; // call default function
test eax, eax;
popad;
pop ebx;
pop edx;
pop eax;
jnz morelines; // if not the end yet, skip custom code
pushad;
pushadc;
push ebx;
push edx;
push eax;
mov ecx, eax;
call CreditsNextLine; // otherwise call out function
test eax, eax; // if any extra lines left, return 1 (from function), 0 otherwise
popad;
popadc;
jnz morelines;
mov eax, 0x0;
xor eax, eax;
retn;
morelines:
mov eax, 0x1;
mov eax, 1;
retn;
}
}
void CreditsInit() {
HookCall(0x480C49, &ShowCreditsHook);
HookCall(0x43F881, &ShowCreditsHook);
if (GetPrivateProfileIntA("Misc", "CreditsAtBottom", 0, ini))
HookCall(0x42CB49, &CreditsNextLineHook_Bottom);
else
HookCall(0x42CB49, &CreditsNextLineHook_Top);
HookCall(0x480C49, ShowCreditsHook);
HookCall(0x43F881, ShowCreditsHook);
if (GetPrivateProfileIntA("Misc", "CreditsAtBottom", 0, ini)) {
HookCall(0x42CB49, CreditsNextLineHook_Bottom);
} else {
HookCall(0x42CB49, CreditsNextLineHook_Top);
}
}
+110 -129
View File
@@ -529,150 +529,132 @@ static void __declspec(naked) item_add_mult_hook() {
}
}
static void __declspec(naked) inven_pickup_hook() {
static void __declspec(naked) inven_pickup_hack() {
__asm {
mov eax, ds:[_i_wid]
call GNW_find_
mov ebx, [eax+0x8+0x0] // ebx = _i_wid.rect.x
mov ecx, [eax+0x8+0x4] // ecx = _i_wid.rect.y
mov eax, 176
add eax, ebx // x_start
add ebx, 176+60 // x_end
mov edx, 37
add edx, ecx // y_start
add ecx, 37+100 // y_end
call mouse_click_in_
test eax, eax
jz end
mov edx, ds:[_curr_stack]
test edx, edx
jnz end
cmp edi, 1006 // Hands?
jae skip // Yes
skip:
xor eax, eax
end:
retn
mov eax, ds:[_i_wid];
call GNW_find_;
mov ebx, [eax + 8 + 0]; // ebx = _i_wid.rect.x
mov ecx, [eax + 8 + 4]; // ecx = _i_wid.rect.y
lea eax, [ebx + 176]; // x_start
add ebx, 176 + 60; // x_end
lea edx, [ecx + 37]; // y_start
add ecx, 37 + 100; // y_end
retn;
}
}
static void __declspec(naked) loot_container_hack_scroll() {
__asm {
cmp esi, 0x150 // source_down
je scroll
cmp esi, 0x148 // source_up
jne end
cmp esi, 0x150; // source_down
je scroll;
cmp esi, 0x148; // source_up
jne end;
scroll:
push edx
push ecx
push ebx
mov eax, ds:[_i_wid]
call GNW_find_
mov ebx, [eax+0x8+0x0] // ebx = _i_wid.rect.x
mov ecx, [eax+0x8+0x4] // ecx = _i_wid.rect.y
mov eax, 297
add eax, ebx // x_start
add ebx, 297+64 // x_end
mov edx, 37
add edx, ecx // y_start
add ecx, 37+6*48 // y_end
call mouse_click_in_
pop ebx
pop ecx
pop edx
test eax, eax
jz end
cmp esi, 0x150 // source_down
je targetDown
mov esi, 0x18D // target_up
jmp end
mov eax, ds:[_i_wid];
call GNW_find_;
push edx;
push ecx;
push ebx;
mov ebx, [eax + 8 + 0]; // ebx = _i_wid.rect.x
mov ecx, [eax + 8 + 4]; // ecx = _i_wid.rect.y
lea eax, [ebx + 297]; // x_start
add ebx, 297 + 64; // x_end
lea edx, [ecx + 37]; // y_start
add ecx, 37 + 6 * 48; // y_end
call mouse_click_in_;
pop ebx;
pop ecx;
pop edx;
test eax, eax;
jz end;
cmp esi, 0x150; // source_down
je targetDown;
mov esi, 0x18D; // target_up
jmp end;
targetDown:
mov esi, 0x191 // target_down
mov esi, 0x191; // target_down
end:
mov eax, ds:[_curr_stack]
retn
mov eax, ds:[_curr_stack];
retn;
}
}
static void __declspec(naked) barter_inventory_hack_scroll() {
__asm {
push edx
push ecx
push ebx
xchg esi, eax
cmp esi, 0x150 // source_down
je scroll
cmp esi, 0x148 // source_up
jne end
mov esi, eax;
cmp esi, 0x150; // source_down
je scroll;
cmp esi, 0x148; // source_up
jne skip;
scroll:
mov eax, ds:[_i_wid]
call GNW_find_
mov ebx, [eax+0x8+0x0] // ebx = _i_wid.rect.x
mov ecx, [eax+0x8+0x4] // ecx = _i_wid.rect.y
push ebx
push ecx
mov eax, 395
add eax, ebx // x_start
add ebx, 395+64 // x_end
mov edx, 35
add edx, ecx // y_start
add ecx, 35+3*48 // y_end
call mouse_click_in_
pop ecx
pop ebx
test eax, eax
jz notTargetScroll
cmp esi, 0x150 // source_down
je targetDown
mov esi, 0x18D // target_up
jmp end
mov eax, ds:[_i_wid];
call GNW_find_;
push edx;
push ecx;
push ebx;
push ebp;
push edi;
mov ebp, [eax + 8 + 0];
mov edi, [eax + 8 + 4];
mov ebx, ebp; // ebx = _i_wid.rect.x
mov ecx, edi; // ecx = _i_wid.rect.y
lea eax, [ebp + 395]; // x_start
add ebx, 395 + 64; // x_end
lea edx, [edi + 35]; // y_start
add ecx, 35 + 3 * 48; // y_end
call mouse_click_in_;
test eax, eax;
jz notTargetScroll;
cmp esi, 0x150; // source_down
je targetDown;
mov esi, 0x18D; // target_up
jmp end;
targetDown:
mov esi, 0x191 // target_down
jmp end
mov esi, 0x191; // target_down
jmp end;
notTargetScroll:
push ebx
push ecx
mov eax, 250
add eax, ebx // x_start
add ebx, 250+64 // x_end
mov edx, 20
add edx, ecx // y_start
add ecx, 20+3*48 // y_end
call mouse_click_in_
pop ecx
pop ebx
test eax, eax
jz notTargetBarter
cmp esi, 0x150 // source_down
je barterTargetDown
mov esi, 0x184 // target_barter_up
jmp end
mov ebx, ebp;
mov ecx, edi;
lea eax, [ebp + 250]; // x_start
add ebx, 250 + 64; // x_end
lea edx, [edi + 20]; // y_start
add ecx, 20 + 3 * 48; // y_end
call mouse_click_in_;
test eax, eax;
jz notTargetBarter;
cmp esi, 0x150; // source_down
je barterTargetDown;
mov esi, 0x184; // target_barter_up
jmp end;
barterTargetDown:
mov esi, 0x176 // target_barter_down
jmp end
mov esi, 0x176; // target_barter_down
jmp end;
notTargetBarter:
mov eax, 165
add eax, ebx // x_start
add ebx, 165+64 // x_end
mov edx, 20
add edx, ecx // y_start
add ecx, 20+3*48 // y_end
call mouse_click_in_
test eax, eax
jz end
cmp esi, 0x150 // source_down
je barterSourceDown
mov esi, 0x149 // source_barter_up
jmp end
mov ebx, ebp;
mov ecx, edi;
lea eax, [ebp + 165]; // x_start
add ebx, 165 + 64; // x_end
lea edx, [edi + 20]; // y_start
add ecx, 20 + 3 * 48; // y_end
call mouse_click_in_;
test eax, eax;
jz end;
cmp esi, 0x150; // source_down
je barterSourceDown;
mov esi, 0x149; // source_barter_up
jmp end;
barterSourceDown:
mov esi, 0x151 // source_barter_down
mov esi, 0x151; // source_barter_down
end:
pop ebx
pop ecx
pop edx
mov eax, esi
cmp eax, 0x11
retn
pop edi;
pop ebp;
pop ebx;
pop ecx;
pop edx;
mov eax, esi;
skip:
cmp eax, 0x11;
retn;
}
}
@@ -681,7 +663,7 @@ static void __declspec(naked) do_move_timer_hook() {
__asm {
cmp eax, 4;
jnz end;
pushad;
pushadc;
}
KeyDown(ItemFastMoveKey); // check pressed
@@ -689,13 +671,13 @@ static void __declspec(naked) do_move_timer_hook() {
__asm {
cmp SkipFromContainer, 0;
jz noSkip;
cmp dword ptr [esp + 0x14 + 36], 0x474A43;
cmp dword ptr [esp + 0x14 + 16], 0x474A43;
jnz noSkip;
test eax, eax;
setz al;
noSkip:
test eax, eax; // set if pressed
popad;
popadc;
jz end;
add esp, 4; // destroy ret
jmp DoMoveTimer_Ret;
@@ -797,9 +779,8 @@ void InventoryInit() {
BlockCall(0x4768A3); // mov ebx, 1
}
// Move items out of bag/backpack and back into the main inventory list by dragging them to character's image
// (similar to Fallout 1 behavior)
HookCall(0x471457, inven_pickup_hook);
// Move items out of bag/backpack and back into the main inventory list by dragging them to character's image (similar to Fallout 1 behavior)
MakeCall(0x471452, inven_pickup_hack);
// Move items to player's main inventory instead of the opened bag/backpack when confirming a trade
SafeWrite32(0x475CF2, _stack);