From 4bb3fa02751c9c35c8e25fb373de59e546d4cdb1 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Tue, 20 Nov 2018 23:44:27 +0800 Subject: [PATCH] Merged two Glovz's fix functions and reorganized Glovz's/YAAM code layout a bit. Fixed a bug in Stats.cpp that caused critical hits to ignore critical table roll value and only have the lowest level effect. Minor edits to MainMenu.cpp. --- artifacts/scripting/headers/define_extra.h | 40 +- sfall/AmmoMod.cpp | 731 ++++++++------------- sfall/MainMenu.cpp | 35 +- sfall/Stats.cpp | 4 +- 4 files changed, 316 insertions(+), 494 deletions(-) diff --git a/artifacts/scripting/headers/define_extra.h b/artifacts/scripting/headers/define_extra.h index f72f0c42..26ef0cb6 100644 --- a/artifacts/scripting/headers/define_extra.h +++ b/artifacts/scripting/headers/define_extra.h @@ -234,26 +234,26 @@ #define CALIBER_7_62MM (18) // hidden perks -#define PERK_add_nuka (53) -#define PERK_add_buffout (54) -#define PERK_add_mentats (55) -#define PERK_add_psycho (56) -#define PERK_add_radaway (57) -#define PERK_weapon_long_range (58) -#define PERK_weapon_accurate (59) -#define PERK_weapon_penetrate (60) -#define PERK_weapon_knockback (61) -#define PERK_armor_powered (62) -#define PERK_armor_combat (63) -#define PERK_weapon_scope_range (64) -#define PERK_weapon_fast_reload (65) -#define PERK_weapon_night_sight (66) -#define PERK_weapon_flameboy (67) -#define PERK_armor_advanced_1 (68) -#define PERK_armor_advanced_2 (69) -#define PERK_add_jet (70) -#define PERK_add_tragic (71) -#define PERK_armor_charisma (72) +#define PERK_add_nuka (53) +#define PERK_add_buffout (54) +#define PERK_add_mentats (55) +#define PERK_add_psycho (56) +#define PERK_add_radaway (57) +#define PERK_weapon_long_range (58) +#define PERK_weapon_accurate (59) +#define PERK_weapon_penetrate (60) +#define PERK_weapon_knockback (61) +#define PERK_armor_powered (62) +#define PERK_armor_combat (63) +#define PERK_weapon_scope_range (64) +#define PERK_weapon_fast_reload (65) +#define PERK_weapon_night_sight (66) +#define PERK_weapon_flameboy (67) +#define PERK_armor_advanced_1 (68) +#define PERK_armor_advanced_2 (69) +#define PERK_add_jet (70) +#define PERK_add_tragic (71) +#define PERK_armor_charisma (72) #define WPN_ANIM_NONE (0x00) // (A) #define WPN_ANIM_KNIFE (0x01) // (D) diff --git a/sfall/AmmoMod.cpp b/sfall/AmmoMod.cpp index 56ae3ce3..02c6f9e0 100644 --- a/sfall/AmmoMod.cpp +++ b/sfall/AmmoMod.cpp @@ -22,484 +22,306 @@ #include "FalloutEngine.h" #include "Logging.h" +static int formula; + static const DWORD DamageFunctionReturn = 0x424A63; -// Damage Fix v5 by Glovz 2014.04.16.xx.xx -static __declspec(naked) void DamageFunction1() { -__asm { - mov ebx,dword ptr ss:[esp+0x1c]; // get the number of hits - xor ecx,ecx; // set the loop counter to 0 - cmp ebx,0x0; // compare the number of hits to 0 - jle end; // exit +// Damage Fix v5 (with v5.1 Damage Multiplier tweak) by Glovz 2014.04.16.xx.xx +static __declspec(naked) void DamageGlovz() { + __asm { + mov ebx, dword ptr ss:[esp + 0x1C]; // get the number of hits + xor ecx, ecx; // set the loop counter to 0 + cmp ebx, 0; // compare the number of hits to 0 + jle end; // exit begin: - mov dword ptr ss:[esp+0x30],0x0; // clear value - mov edx,dword ptr ds:[esi+4]; // get pointer to weapon being used by an attacker (I think) - mov eax,dword ptr ds:[esi]; // get pointer to critter attacking - call item_w_damage_; // get the raw damage value - mov ebx,dword ptr ss:[esp+0x18]; // get the bonus ranged damage value - cmp ebx,0x0; // compare the range bonus damage value to 0 - jle rdJmp; // if the RB value is less than or equal to 0 then goto rdJmp - add eax,ebx; // add the RB value to the RD value - rdJmp: - cmp eax,0x0; // compare the new damage value to 0 - jle noDamageJmp; // goto noDamageJmp - mov ebx,eax; // set the ND value - mov edx,dword ptr ss:[esp+0x28]; // get the armorDT value - cmp edx,0x0; // compare the armorDT value to 0 - jle bJmp; // if the armorDT value is less than or equal to 0 then goto bJmp - mov eax,dword ptr ds:[esi+0x8]; // get pointer to critters ammo being used in their weapon (I think) - call item_w_dam_div_; // get the ammoY value - cmp eax,0x0; // compare the ammoY value to 0 - jg aJmp; // if the ammoY value is greater than 0 then goto aJmp - mov eax,0x1; // set the ammoY value to 1 + mov dword ptr ss:[esp + 0x30], 0; // clear value + mov edx, dword ptr ds:[esi + 4]; // get pointer to weapon being used by an attacker (I think) + mov eax, dword ptr ds:[esi]; // get pointer to critter attacking + call item_w_damage_; // get the raw damage value + mov ebx, dword ptr ss:[esp + 0x18]; // get the bonus ranged damage value + cmp ebx, 0; // compare the range bonus damage value to 0 + jle rdJmp; // if the RB value is less than or equal to 0 then goto rdJmp + add eax, ebx; // add the RB value to the RD value +rdJmp: + cmp eax, 0; // compare the new damage value to 0 + jle noDamageJmp; // goto noDamageJmp + mov ebx, eax; // set the ND value + mov edx, dword ptr ss:[esp + 0x28]; // get the armorDT value + cmp edx, 0; // compare the armorDT value to 0 + jle bJmp; // if the armorDT value is less than or equal to 0 then goto bJmp + mov eax, dword ptr ds:[esi + 0x8]; // get pointer to critters ammo being used in their weapon (I think) + call item_w_dam_div_; // get the ammoY value + cmp eax, 0; // compare the ammoY value to 0 + jg aJmp; // if the ammoY value is greater than 0 then goto aJmp + mov eax, 1; // set the ammoY value to 1 aJmp: - xor ebp,ebp; // clear value - cmp edx,eax; // compare the dividend with the divisor - jl lrThan; // the dividend is less than the divisor then goto lrThan - jg grThan; // the dividend is greater than the divisor then goto grThan - jmp setOne; // if the two values are equal then goto setOne - lrThan: - mov ebp,edx; // store the dividend value temporarily - imul edx,0x2; // multiply dividend value by 2 - sub edx,eax; // subtract divisor value from the dividend value - cmp edx,0x0; // compare the result to 0 - jl setZero; // if the result is less than 0 then goto setZero - jg setOne; // if the result is greater than 0 then goto setOne - mov edx,ebp; // restore dividend value - and edx,0x1; // if true (1) then odd if false (0) then even - jz setZero; // if the result is equal to 0 then setZero - jmp setOne; // if the result is not 0 then goto setOne - grThan: - mov ebp,eax; // assign the divisor value - xor eax,eax; // clear value - bbbJmp: - inc eax; // add 1 to the quotient value - sub edx,ebp; // subtract the divisor value from the dividend value - cmp edx,ebp; // compare the remainder value to the divisor value - jge bbbJmp; // if the remainder value is greater or equal to the divisor value then goto bbbJmp - jz endDiv; // if the remainder value is equal to 0 then goto endDiv - imul edx,0x2; // multiply temp remainder value by 2 - sub edx,ebp; // subtract the divisor value from the temp remainder - cmp edx,0x0; // compare the result to 0 - jl endDiv; // if the result is less than 0 then goto endDiv - jg addOne; // if the result is greater than 0 then goto addOne - mov ebp,eax; // assign the quotient value - and ebp,0x1; // if true (1) then odd if false (0) then even - jz endDiv; // if the result is equal to zero goto endDiv - addOne: - inc eax; // add 1 to the quotient value - jmp endDiv; // goto endDiv - setOne: - mov eax,0x1; // set the quotient value to 1 - jmp endDiv; // goto endDiv - setZero: - xor eax,eax; // clear value - endDiv: - cmp dword ptr ss:[esp+0x30],0x2; // compare value to 2 - je divTwo; // goto divTwo - cmp dword ptr ss:[esp+0x30],0x3; // compare value to 3 - je divThree; // goto divThree - cmp dword ptr ss:[esp+0x30],0x4; // compare value to 4 - je divFour; // goto divFour - cmp dword ptr ss:[esp+0x30],0x5; // compare value to 5 - je divFive; // goto divFive - cmp dword ptr ss:[esp+0x30],0x6; // compare value to 6 - je divSix; // goto divSix - sub ebx,eax; // subtract the new armorDT value from the RD value - jmp cJmp; // goto cJmp + xor ebp, ebp; // clear value + cmp edx, eax; // compare the dividend with the divisor + jl lrThan; // the dividend is less than the divisor then goto lrThan + jg grThan; // the dividend is greater than the divisor then goto grThan + jmp setOne; // if the two values are equal then goto setOne +lrThan: + mov ebp, edx; // store the dividend value temporarily + imul edx, 2; // multiply dividend value by 2 + sub edx, eax; // subtract divisor value from the dividend value + cmp edx, 0; // compare the result to 0 + jl setZero; // if the result is less than 0 then goto setZero + jg setOne; // if the result is greater than 0 then goto setOne + mov edx, ebp; // restore dividend value + and edx, 1; // if true (1) then odd if false (0) then even + jz setZero; // if the result is equal to 0 then setZero + jmp setOne; // if the result is not 0 then goto setOne +grThan: + mov ebp, eax; // assign the divisor value + xor eax, eax; // clear value +bbbJmp: + inc eax; // add 1 to the quotient value + sub edx, ebp; // subtract the divisor value from the dividend value + cmp edx, ebp; // compare the remainder value to the divisor value + jge bbbJmp; // if the remainder value is greater or equal to the divisor value then goto bbbJmp + jz endDiv; // if the remainder value is equal to 0 then goto endDiv + imul edx, 2; // multiply temp remainder value by 2 + sub edx, ebp; // subtract the divisor value from the temp remainder + cmp edx, 0; // compare the result to 0 + jl endDiv; // if the result is less than 0 then goto endDiv + jg addOne; // if the result is greater than 0 then goto addOne + mov ebp, eax; // assign the quotient value + and ebp, 1; // if true (1) then odd if false (0) then even + jz endDiv; // if the result is equal to zero goto endDiv +addOne: + inc eax; // add 1 to the quotient value + jmp endDiv; // goto endDiv +setOne: + mov eax, 1; // set the quotient value to 1 + jmp endDiv; // goto endDiv +setZero: + xor eax, eax; // clear value +endDiv: + cmp dword ptr ss:[esp + 0x30], 2; // compare value to 2 + je divTwo; // goto divTwo + cmp dword ptr ss:[esp + 0x30], 3; // compare value to 3 + je divThree; // goto divThree + cmp dword ptr ss:[esp + 0x30], 4; // compare value to 4 + je divFour; // goto divFour + cmp dword ptr ss:[esp + 0x30], 5; // compare value to 5 + je divFive; // goto divFive + cmp dword ptr ss:[esp + 0x30], 6; // compare value to 6 + je divSix; // goto divSix + cmp dword ptr ss:[esp + 0x30], 7; // compare value to 7 + je divSeven; // goto divSeven + sub ebx, eax; // subtract the new armorDT value from the RD value + jmp cJmp; // goto cJmp bJmp: - mov edx,dword ptr ss:[esp+0x2c]; // get the armorDR value - cmp edx,0x0; // compare the armorDR value to 0 - jle dJmp; // if the armorDR value is less than or equal to 0 then goto dJmp + mov edx, dword ptr ss:[esp + 0x2C]; // get the armorDR value + cmp edx, 0; // compare the armorDR value to 0 + jle dJmp; // if the armorDR value is less than or equal to 0 then goto dJmp cJmp: - cmp ebx,0x0; // compare the new damage value to 0 - jle noDamageJmp; // goto noDamageJmp - mov edx,dword ptr ss:[esp+0x2c]; // get the armorDR value - cmp edx,0x0; // compare the armorDR value to 0 - jle eJmp; // if the armorDR value is less than or equal to 0 then goto eJmp - mov eax,dword ptr ss:[esp+0x20]; // get the CD value - cmp eax,0x64; // compare the CD value to 100 - jg sdrJmp; // if the CD value is greater than 100 then goto sdrJmp - je aSubCJmp; // if the CD value is equal to 100 then goto aSubCJmp - add edx,0x14; // add 20 to the armorDR value - jmp aSubCJmp; // goto aSubCJmp - sdrJmp: - sub edx,0x14; // subtract 20 from the armorDR value - aSubCJmp: - mov eax,dword ptr ds:[esi+0x8]; // get pointer to ammo being used in the critters weapon (I think) - call item_w_dr_adjust_; // get the ammoDRM value - cmp eax,0x0; // compare the ammoDRM value to 0 - jl adrJmp; // if the ammoDRM value is less than 0 then goto adrJmp - je bSubCJmp; // if the ammoDRM value is equal to 0 then goto bSubCJmp - xor ebp,ebp; // clear value - sub ebp,eax; // subtract ammoDRM value from 0 - mov eax,ebp; // set new ammoDRM value - adrJmp: - add edx,eax; // add the ammoDRM value to the armorDR value - bSubCJmp: - mov eax,dword ptr ds:[esi+0x8]; // get pointer to ammo being used in the critters weapon (I think) - call item_w_dam_mult_; // get the ammoX value - cmp eax,0x0; // compare the ammoX value to 0 - jg cSubCJmp; // if the ammoX value is greater than 0 then goto cSubCJmp; - mov eax,0x1; // set the ammoX value to 1 - cSubCJmp: - mov dword ptr ss:[esp+0x30],0x2; // set value to 2 - jmp aJmp; // goto aJmp - divTwo: - mov edx,ebx; // set temp value - imul edx,eax; // multiply the ND value by the armorDR value - mov eax,0x64; // set divisor value to 100 - mov dword ptr ss:[esp+0x30],0x3; // set value to 3 - jmp aJmp; // goto aJmp - divThree: - sub ebx,eax; // subtract the damage resisted value from the ND value - jmp eJmp; // goto eJmp + cmp ebx, 0; // compare the new damage value to 0 + jle noDamageJmp; // goto noDamageJmp + mov edx, dword ptr ss:[esp + 0x2C]; // get the armorDR value + cmp edx, 0; // compare the armorDR value to 0 + jle eJmp; // if the armorDR value is less than or equal to 0 then goto eJmp + mov eax, dword ptr ss:[esp + 0x20]; // get the CD value + cmp eax, 100; // compare the CD value to 100 + jg sdrJmp; // if the CD value is greater than 100 then goto sdrJmp + je aSubCJmp; // if the CD value is equal to 100 then goto aSubCJmp + add edx, 20; // add 20 to the armorDR value + jmp aSubCJmp; // goto aSubCJmp +sdrJmp: + sub edx, 20; // subtract 20 from the armorDR value +aSubCJmp: + mov eax, dword ptr ds:[esi + 0x8]; // get pointer to ammo being used in the critters weapon (I think) + call item_w_dr_adjust_; // get the ammoDRM value + cmp eax, 0; // compare the ammoDRM value to 0 + jl adrJmp; // if the ammoDRM value is less than 0 then goto adrJmp + je bSubCJmp; // if the ammoDRM value is equal to 0 then goto bSubCJmp + xor ebp, ebp; // clear value + sub ebp, eax; // subtract ammoDRM value from 0 + mov eax, ebp; // set new ammoDRM value +adrJmp: + add edx, eax; // add the ammoDRM value to the armorDR value +bSubCJmp: + mov eax, dword ptr ds:[esi + 0x8]; // get pointer to ammo being used in the critters weapon (I think) + call item_w_dam_mult_; // get the ammoX value + cmp eax, 0; // compare the ammoX value to 0 + jg cSubCJmp; // if the ammoX value is greater than 0 then goto cSubCJmp; + mov eax, 1; // set the ammoX value to 1 +cSubCJmp: + mov dword ptr ss:[esp + 0x30], 2; // set value to 2 + jmp aJmp; // goto aJmp +divTwo: + mov edx, ebx; // set temp value + imul edx, eax; // multiply the ND value by the armorDR value + mov eax, 100; // set divisor value to 100 + mov dword ptr ss:[esp + 0x30], 3; // set value to 3 + jmp aJmp; // goto aJmp +divThree: + sub ebx, eax; // subtract the damage resisted value from the ND value + jmp eJmp; // goto eJmp dJmp: - mov eax,dword ptr ds:[esi+0x8]; // get pointer to ammo being used in the critters weapon (I think) - call item_w_dam_mult_; // get the ammoX value - cmp eax,0x1; // compare the ammoX value to 1 - jle bSubDJmp; // if the ammoX value is less than or equal to 1 then goto bSubDJmp; - mov eax,dword ptr ds:[esi+0x8]; // get pointer to critters ammo being used in their weapon (I think) - call item_w_dam_div_; // get the ammoY value - cmp eax,0x1; // compare the ammoY value to 1 - jle aSubDJmp; // if the ammoY value is less than or equal to 1 then goto aSubDJmp - mov edx,ebx; // set temp value - imul edx,0xf; // multiply the ND value by 15 - mov eax,0x64; // set divisor value to 100 - mov dword ptr ss:[esp+0x30],0x4; // set value to 4 - jmp aJmp; // goto aJmp - divFour: - add ebx,eax; // add the quotient value to the ND value - jmp eJmp; // goto eJmp - aSubDJmp: - mov edx,ebx; // set temp value - imul edx,0x14; // multiply the ND value by 20 - mov eax,0x64; // set divisor value to 100 - mov dword ptr ss:[esp+0x30],0x5; // set value to 5 - jmp aJmp; // goto aJmp - divFive: - add ebx,eax; // add the quotient value to the ND value - jmp eJmp; // goto eJmp - bSubDJmp: - mov eax,dword ptr ds:[esi+0x8]; // get pointer to critters ammo being used in their weapon (I think) - call item_w_dam_div_; // get the ammoY value - cmp eax,0x1; // compare the ammoY value to 1 - jle eJmp; // goto eJmp - mov edx,ebx; // set temp value - imul edx,0xa; // multiply the ND value by 10 - mov eax,0x64; // set divisor value to 100 - mov dword ptr ss:[esp+0x30],0x6; // set value to 6 - jmp aJmp; // goto aJmp - divSix: - add ebx,eax; // add the quotient value to the ND value + mov eax, dword ptr ds:[esi + 0x8]; // get pointer to ammo being used in the critters weapon (I think) + call item_w_dam_mult_; // get the ammoX value + cmp eax, 1; // compare the ammoX value to 1 + jle bSubDJmp; // if the ammoX value is less than or equal to 1 then goto bSubDJmp; + mov eax, dword ptr ds:[esi + 0x8]; // get pointer to critters ammo being used in their weapon (I think) + call item_w_dam_div_; // get the ammoY value + cmp eax, 1; // compare the ammoY value to 1 + jle aSubDJmp; // if the ammoY value is less than or equal to 1 then goto aSubDJmp + mov edx, ebx; // set temp value + imul edx, 15; // multiply the ND value by 15 + mov eax, 100; // set divisor value to 100 + mov dword ptr ss:[esp + 0x30], 4; // set value to 4 + jmp aJmp; // goto aJmp +divFour: + add ebx, eax; // add the quotient value to the ND value + jmp eJmp; // goto eJmp +aSubDJmp: + mov edx, ebx; // set temp value + imul edx, 20; // multiply the ND value by 20 + mov eax, 100; // set divisor value to 100 + mov dword ptr ss:[esp + 0x30], 5; // set value to 5 + jmp aJmp; // goto aJmp +divFive: + add ebx, eax; // add the quotient value to the ND value + jmp eJmp; // goto eJmp +bSubDJmp: + mov eax, dword ptr ds:[esi + 0x8]; // get pointer to critters ammo being used in their weapon (I think) + call item_w_dam_div_; // get the ammoY value + cmp eax, 1; // compare the ammoY value to 1 + jle eJmp; // goto eJmp + mov edx, ebx; // set temp value + imul edx, 10; // multiply the ND value by 10 + mov eax, 100; // set divisor value to 100 + mov dword ptr ss:[esp + 0x30], 6; // set value to 6 + jmp aJmp; // goto aJmp +divSix: + add ebx, eax; // add the quotient value to the ND value eJmp: - cmp ebx,0x0; // compare the new damage value to 0 - jle noDamageJmp; // goto noDamageJmp - mov eax,dword ptr ss:[esp+0x24]; // get the CM value - cmp eax,0x2; // compare the CM value to 2 - jle addNDJmp; // if the CM value is less than or equal to 2 then goto addNDJmp - imul ebx,eax; // multiply the ND value by the CM value - sar ebx,0x1; // divide the result by 2 + cmp ebx, 0; // compare the new damage value to 0 + jle noDamageJmp; // goto noDamageJmp + mov eax, dword ptr ss:[esp + 0x24]; // get the CM value + cmp eax, 2; // compare the CM value to 2 + jle addNDJmp; // if the CM value is less than or equal to 2 then goto addNDJmp + cmp formula, 2; // check selected damage formula (added for v5.1 tweak) + jz tweak; + imul ebx, eax; // multiply the ND value by the CM value + sar ebx, 1; // divide the result by 2 + jmp addNDJmp; +//// begin v5.1 tweak //// +tweak: + mov edx, ebx; // set temp ND value + imul edx, eax; // multiply the temp ND value by the CM value + imul edx, 25; // multiply the temp ND value by 25 + mov eax, 100; // set divisor value to 100 + mov dword ptr ss:[esp + 0x30], 7; // set value to 7 + jmp aJmp; // goto aJmp +divSeven: + add ebx, eax; // add the critical damage value to the ND value +//// end v5.1 tweak //// addNDJmp: - add dword ptr ds:[edi],ebx; // accumulate damage + add dword ptr ds:[edi], ebx; // accumulate damage noDamageJmp: - mov eax,dword ptr ss:[esp+0x1c]; // get the number of hits - inc ecx; // the counter value increments by one - cmp ecx,eax; // is the counter value less than the number of hits - jl begin; // goto begin + mov eax, dword ptr ss:[esp + 0x1C]; // get the number of hits + inc ecx; // the counter value increments by one + cmp ecx, eax; // is the counter value less than the number of hits + jl begin; // goto begin end: - jmp DamageFunctionReturn; // exit - } -} - -// Damage Fix v5.1 by Glovz 2014.04.16.xx.xx -static __declspec(naked) void DamageFunction2() { -__asm { - mov ebx,dword ptr ss:[esp+0x1c]; // get the number of hits - xor ecx,ecx; // set the loop counter to 0 - cmp ebx,0x0; // compare the number of hits to 0 - jle end; // exit -begin: - mov dword ptr ss:[esp+0x30],0x0; // clear value - mov edx,dword ptr ds:[esi+4]; // get pointer to weapon being used by an attacker (I think) - mov eax,dword ptr ds:[esi]; // get pointer to critter attacking - call item_w_damage_; // get the raw damage value - mov ebx,dword ptr ss:[esp+0x18]; // get the bonus ranged damage value - cmp ebx,0x0; // compare the range bonus damage value to 0 - jle rdJmp; // if the RB value is less than or equal to 0 then goto rdJmp - add eax,ebx; // add the RB value to the RD value - rdJmp: - cmp eax,0x0; // compare the new damage value to 0 - jle noDamageJmp; // goto noDamageJmp - mov ebx,eax; // set the ND value - mov edx,dword ptr ss:[esp+0x28]; // get the armorDT value - cmp edx,0x0; // compare the armorDT value to 0 - jle bJmp; // if the armorDT value is less than or equal to 0 then goto bJmp - mov eax,dword ptr ds:[esi+0x8]; // get pointer to critters ammo being used in their weapon (I think) - call item_w_dam_div_; // get the ammoY value - cmp eax,0x0; // compare the ammoY value to 0 - jg aJmp; // if the ammoY value is greater than 0 then goto aJmp - mov eax,0x1; // set the ammoY value to 1 -aJmp: - xor ebp,ebp; // clear value - cmp edx,eax; // compare the dividend with the divisor - jl lrThan; // the dividend is less than the divisor then goto lrThan - jg grThan; // the dividend is greater than the divisor then goto grThan - jmp setOne; // if the two values are equal then goto setOne - lrThan: - mov ebp,edx; // store the dividend value temporarily - imul edx,0x2; // multiply dividend value by 2 - sub edx,eax; // subtract divisor value from the dividend value - cmp edx,0x0; // compare the result to 0 - jl setZero; // if the result is less than 0 then goto setZero - jg setOne; // if the result is greater than 0 then goto setOne - mov edx,ebp; // restore dividend value - and edx,0x1; // if true (1) then odd if false (0) then even - jz setZero; // if the result is equal to 0 then setZero - jmp setOne; // if the result is not 0 then goto setOne - grThan: - mov ebp,eax; // assign the divisor value - xor eax,eax; // clear value - bbbJmp: - inc eax; // add 1 to the quotient value - sub edx,ebp; // subtract the divisor value from the dividend value - cmp edx,ebp; // compare the remainder value to the divisor value - jge bbbJmp; // if the remainder value is greater or equal to the divisor value then goto bbbJmp - jz endDiv; // if the remainder value is equal to 0 then goto endDiv - imul edx,0x2; // multiply temp remainder value by 2 - sub edx,ebp; // subtract the divisor value from the temp remainder - cmp edx,0x0; // compare the result to 0 - jl endDiv; // if the result is less than 0 then goto endDiv - jg addOne; // if the result is greater than 0 then goto addOne - mov ebp,eax; // assign the quotient value - and ebp,0x1; // if true (1) then odd if false (0) then even - jz endDiv; // if the result is equal to zero goto endDiv - addOne: - inc eax; // add 1 to the quotient value - jmp endDiv; // goto endDiv - setOne: - mov eax,0x1; // set the quotient value to 1 - jmp endDiv; // goto endDiv - setZero: - xor eax,eax; // clear value - endDiv: - cmp dword ptr ss:[esp+0x30],0x2; // compare value to 2 - je divTwo; // goto divTwo - cmp dword ptr ss:[esp+0x30],0x3; // compare value to 3 - je divThree; // goto divThree - cmp dword ptr ss:[esp+0x30],0x4; // compare value to 4 - je divFour; // goto divFour - cmp dword ptr ss:[esp+0x30],0x5; // compare value to 5 - je divFive; // goto divFive - cmp dword ptr ss:[esp+0x30],0x6; // compare value to 6 - je divSix; // goto divSix - cmp dword ptr ss:[esp+0x30],0x7; // compare value to 7 - je divSeven; // goto divSeven - sub ebx,eax; // subtract the new armorDT value from the RD value - jmp cJmp; // goto cJmp -bJmp: - mov edx,dword ptr ss:[esp+0x2c]; // get the armorDR value - cmp edx,0x0; // compare the armorDR value to 0 - jle dJmp; // if the armorDR value is less than or equal to 0 then goto dJmp -cJmp: - cmp ebx,0x0; // compare the new damage value to 0 - jle noDamageJmp; // goto noDamageJmp - mov edx,dword ptr ss:[esp+0x2c]; // get the armorDR value - cmp edx,0x0; // compare the armorDR value to 0 - jle eJmp; // if the armorDR value is less than or equal to 0 then goto eJmp - mov eax,dword ptr ss:[esp+0x20]; // get the CD value - cmp eax,0x64; // compare the CD value to 100 - jg sdrJmp; // if the CD value is greater than 100 then goto sdrJmp - je aSubCJmp; // if the CD value is equal to 100 then goto aSubCJmp - add edx,0x14; // add 20 to the armorDR value - jmp aSubCJmp; // goto aSubCJmp - sdrJmp: - sub edx,0x14; // subtract 20 from the armorDR value - aSubCJmp: - mov eax,dword ptr ds:[esi+0x8]; // get pointer to ammo being used in the critters weapon (I think) - call item_w_dr_adjust_; // get the ammoDRM value - cmp eax,0x0; // compare the ammoDRM value to 0 - jl adrJmp; // if the ammoDRM value is less than 0 then goto adrJmp - je bSubCJmp; // if the ammoDRM value is equal to 0 then goto bSubCJmp - xor ebp,ebp; // clear value - sub ebp,eax; // subtract ammoDRM value from 0 - mov eax,ebp; // set new ammoDRM value - adrJmp: - add edx,eax; // add the ammoDRM value to the armorDR value - bSubCJmp: - mov eax,dword ptr ds:[esi+0x8]; // get pointer to ammo being used in the critters weapon (I think) - call item_w_dam_mult_; // get the ammoX value - cmp eax,0x0; // compare the ammoX value to 0 - jg cSubCJmp; // if the ammoX value is greater than 0 then goto cSubCJmp; - mov eax,0x1; // set the ammoX value to 1 - cSubCJmp: - mov dword ptr ss:[esp+0x30],0x2; // set value to 2 - jmp aJmp; // goto aJmp - divTwo: - mov edx,ebx; // set temp value - imul edx,eax; // multiply the ND value by the armorDR value - mov eax,0x64; // set divisor value to 100 - mov dword ptr ss:[esp+0x30],0x3; // set value to 3 - jmp aJmp; // goto aJmp - divThree: - sub ebx,eax; // subtract the damage resisted value from the ND value - jmp eJmp; // goto eJmp -dJmp: - mov eax,dword ptr ds:[esi+0x8]; // get pointer to ammo being used in the critters weapon (I think) - call item_w_dam_mult_; // get the ammoX value - cmp eax,0x1; // compare the ammoX value to 1 - jle bSubDJmp; // if the ammoX value is less than or equal to 1 then goto bSubDJmp; - mov eax,dword ptr ds:[esi+0x8]; // get pointer to critters ammo being used in their weapon (I think) - call item_w_dam_div_; // get the ammoY value - cmp eax,0x1; // compare the ammoY value to 1 - jle aSubDJmp; // if the ammoY value is less than or equal to 1 then goto aSubDJmp - mov edx,ebx; // set temp value - imul edx,0xf; // multiply the ND value by 15 - mov eax,0x64; // set divisor value to 100 - mov dword ptr ss:[esp+0x30],0x4; // set value to 4 - jmp aJmp; // goto aJmp - divFour: - add ebx,eax; // add the quotient value to the ND value - jmp eJmp; // goto eJmp - aSubDJmp: - mov edx,ebx; // set temp value - imul edx,0x14; // multiply the ND value by 20 - mov eax,0x64; // set divisor value to 100 - mov dword ptr ss:[esp+0x30],0x5; // set value to 5 - jmp aJmp; // goto aJmp - divFive: - add ebx,eax; // add the quotient value to the ND value - jmp eJmp; // goto eJmp - bSubDJmp: - mov eax,dword ptr ds:[esi+0x8]; // get pointer to critters ammo being used in their weapon (I think) - call item_w_dam_div_; // get the ammoY value - cmp eax,0x1; // compare the ammoY value to 1 - jle eJmp; // goto eJmp - mov edx,ebx; // set temp value - imul edx,0xa; // multiply the ND value by 10 - mov eax,0x64; // set divisor value to 100 - mov dword ptr ss:[esp+0x30],0x6; // set value to 6 - jmp aJmp; // goto aJmp - divSix: - add ebx,eax; // add the quotient value to the ND value -eJmp: - cmp ebx,0x0; // compare the new damage value to 0 - jle noDamageJmp; // goto noDamageJmp - mov eax,dword ptr ss:[esp+0x24]; // get the CM value - cmp eax,0x2; // compare the CM value to 2 - jle addNDJmp; // if the CM value is less than or equal to 2 then goto addNDJmp - mov edx,ebx; // set temp ND value - imul edx,eax; // multiply the temp ND value by the CM value - imul edx,0x19; // multiply the temp ND value by 25 - mov eax,0x64; // set divisor value to 100 - mov dword ptr ss:[esp+0x30],0x7; // set value to 7 - jmp aJmp; // goto aJmp - divSeven: - add ebx,eax; // add the critical damage value to the ND value -addNDJmp: - add dword ptr ds:[edi],ebx; // accumulate damage -noDamageJmp: - mov eax,dword ptr ss:[esp+0x1c]; // get the number of hits - inc ecx; // the counter value increments by one - cmp ecx,eax; // is the counter value less than the number of hits - jl begin; // goto begin -end: - jmp DamageFunctionReturn; // exit + jmp DamageFunctionReturn; // exit } } // YAAM -static __declspec(naked) void DamageFunction5() { +static __declspec(naked) void DamageYAAM() { __asm { - mov eax,dword ptr ds:[esi+0x8]; // Get pointer to critter's weapon - mov edx,dword ptr ss:[esp+0x24]; // Get Critical Multiplier (passed in as argument to function) - call item_w_dam_mult_; // Retrieve Ammo Dividend - imul edx,eax; // Damage Multipler = Critical Multipler * Ammo Dividend - mov eax,dword ptr ds:[esi+0x8]; // Get pointer to critter's weapon - call item_w_dam_div_; // Retrieve Ammo Divisor - imul ebp,eax; // Ammo Divisor = 1 * Ammo Divisor (ebp set to 1 earlier in function) - mov ebx,dword ptr ss:[esp+0x1c]; // Get number of hits - xor ecx,ecx; // Set loop counter to zero - mov dword ptr ss:[esp+0x24],edx; // Store Damage Multiplier - test ebx,ebx; // Is number of hits <= 0? - jle end; // If yes, jump beyond damage calculation loop -ajmp: // Start of damage calculation loop - mov edx,dword ptr ds:[esi+0x4]; // Get pointer to weapon (?) - mov eax,dword ptr ds:[esi]; // Get pointer to critter (?) - mov ebx,dword ptr ss:[esp+0x18]; // Get Bonus Ranged Damage - call item_w_damage_; // Retrieve Raw Damage - add ebx,eax; // Raw Damage = Raw Damage + Bonus Ranged Damage - mov edx,dword ptr ss:[esp+0x28]; // Get armor DT - mov eax,dword ptr ds:[esi+0x8]; // Get pointer to critter's weapon - call item_w_dr_adjust_; // Retrieve ammo DT (well, it's really Retrieve ammo DR, but since we're treating ammo DR as ammo DT...) - sub edx,eax; // DT = armor DT - ammo DT - test edx,edx; // Is DT >= 0? - jge bjmp; // If yes, skip the next instruction - xor edx,edx; // Otherwise, set DT = 0 + mov eax, dword ptr ds:[esi + 0x8]; // Get pointer to critter's weapon + mov edx, dword ptr ss:[esp + 0x24]; // Get Critical Multiplier (passed in as argument to function) + call item_w_dam_mult_; // Retrieve Ammo Dividend + imul edx, eax; // Damage Multipler = Critical Multipler * Ammo Dividend + mov eax, dword ptr ds:[esi + 0x8]; // Get pointer to critter's weapon + call item_w_dam_div_; // Retrieve Ammo Divisor + imul ebp, eax; // Ammo Divisor = 1 * Ammo Divisor (ebp set to 1 earlier in function) + mov ebx, dword ptr ss:[esp + 0x1C]; // Get number of hits + xor ecx, ecx; // Set loop counter to zero + mov dword ptr ss:[esp + 0x24], edx; // Store Damage Multiplier + test ebx, ebx; // Is number of hits <= 0? + jle end; // If yes, jump beyond damage calculation loop +ajmp: // Start of damage calculation loop + mov edx, dword ptr ds:[esi + 0x4]; // Get pointer to weapon (?) + mov eax, dword ptr ds:[esi]; // Get pointer to critter (?) + mov ebx, dword ptr ss:[esp + 0x18]; // Get Bonus Ranged Damage + call item_w_damage_; // Retrieve Raw Damage + add ebx, eax; // Raw Damage = Raw Damage + Bonus Ranged Damage + mov edx, dword ptr ss:[esp + 0x28]; // Get armor DT + mov eax, dword ptr ds:[esi + 0x8]; // Get pointer to critter's weapon + call item_w_dr_adjust_; // Retrieve ammo DT (well, it's really Retrieve ammo DR, but since we're treating ammo DR as ammo DT...) + sub edx, eax; // DT = armor DT - ammo DT + test edx, edx; // Is DT >= 0? + jge bjmp; // If yes, skip the next instruction + xor edx, edx; // Otherwise, set DT = 0 bjmp: - sub ebx,edx; // Raw Damage = Raw Damage - DT - test ebx,ebx; // Is Raw Damage <= 0? - jle cjmp; // If yes, skip damage calculation and go to bottom of loop - imul ebx,dword ptr ss:[esp+0x24]; // Otherwise, Raw Damage = Raw Damage * Damage Multiplier - test ebp,ebp; // Is Ammo Divisor == 0? - je djmp; // If yes, avoid divide by zero error - mov edx,ebx; - mov eax,ebx; - sar edx,0x1f; + sub ebx, edx; // Raw Damage = Raw Damage - DT + test ebx, ebx; // Is Raw Damage <= 0? + jle cjmp; // If yes, skip damage calculation and go to bottom of loop + imul ebx, dword ptr ss:[esp + 0x24]; // Otherwise, Raw Damage = Raw Damage * Damage Multiplier + test ebp, ebp; // Is Ammo Divisor == 0? + je djmp; // If yes, avoid divide by zero error + mov edx, ebx; + mov eax, ebx; + sar edx, 31; idiv ebp; - mov ebx,eax; // Otherwise, Raw Damage = Raw Damage / Ammo Divisor + mov ebx, eax; // Otherwise, Raw Damage = Raw Damage / Ammo Divisor djmp: - mov edx,ebx; - mov eax,ebx; - sar edx,0x1f; - sub eax,edx; - sar eax,0x1; // Raw Damage = Raw Damage / 2 (related to critical hit damage multiplier bonus) - mov edx,dword ptr ss:[esp+0x20]; // Get combat difficulty setting (75 if wimpy, 100 if normal or if attacker is player, 125 if rough) - imul edx,eax; // Raw Damage = Raw Damage * combat difficulty setting - mov ebx,0x64; - mov eax,edx; - sar edx,0x1f; + mov edx, ebx; + mov eax, ebx; + sar edx, 31; + sub eax, edx; + sar eax, 1; // Raw Damage = Raw Damage / 2 (related to critical hit damage multiplier bonus) + mov edx, dword ptr ss:[esp + 0x20]; // Get combat difficulty setting (75 if wimpy, 100 if normal or if attacker is player, 125 if rough) + imul edx, eax; // Raw Damage = Raw Damage * combat difficulty setting + mov ebx, 100; + mov eax, edx; + sar edx, 31; idiv ebx; - mov ebx,eax; // Raw Damage = Raw Damage / 100 - mov edx,dword ptr ss:[esp+0x28]; // Get armor DT - mov eax,dword ptr ds:[esi+0x8]; // Get pointer to critter's weapon - call item_w_dr_adjust_; // Retrieve ammo DT - sub edx,eax; // DT = armor DT - ammo DT - test edx,edx; // Is DT >= 0? - jge ejmp; // If yes, set DT = 0 - mov eax,0x0a; - imul eax,edx; // Otherwise, DT = DT * 10 (note that this should be a negative value) - jmp fjmp; + mov ebx, eax; // Raw Damage = Raw Damage / 100 + mov edx, dword ptr ss:[esp + 0x28]; // Get armor DT + mov eax, dword ptr ds:[esi + 0x8]; // Get pointer to critter's weapon + call item_w_dr_adjust_; // Retrieve ammo DT + sub edx, eax; // DT = armor DT - ammo DT + test edx, edx; // Is DT >= 0? + jge ejmp; // If yes, set DT = 0 + mov eax, 10; + imul eax, edx; // Otherwise, DT = DT * 10 (note that this should be a negative value) + jmp fjmp; ejmp: - xor eax,eax; + xor eax, eax; fjmp: - mov edx,dword ptr ss:[esp+0x2c]; // Get armor DR - add edx,eax; // DR = armor DR + DT (note that DT should be less than or equal to zero) - test edx,edx; // Is DR >= 0? - jge gjmp; - xor edx,edx; // If no, set DR = 0 - jmp hjmp; + mov edx, dword ptr ss:[esp + 0x2C]; // Get armor DR + add edx, eax; // DR = armor DR + DT (note that DT should be less than or equal to zero) + test edx, edx; // Is DR >= 0? + jge gjmp; + xor edx, edx; // If no, set DR = 0 + jmp hjmp; gjmp: - cmp edx,0x64; // Otherwise, is DR >= 100? - jge ijmp; // If yes, damage will be zero, so stop calculating and go to bottom of loop + cmp edx, 100; // Otherwise, is DR >= 100? + jge ijmp; // If yes, damage will be zero, so stop calculating and go to bottom of loop hjmp: - imul edx,ebx; // Otherwise, Resisted Damage = DR * Raw Damage - mov dword ptr ss:[esp+0x30],0x64; - mov eax,edx; - sar edx,0x1f; - idiv dword ptr ss:[esp+0x30]; // Resisted Damage = Resisted Damage / 100 - sub ebx,eax; // Raw Damage = Raw Damage - Resisted Damage + imul edx, ebx; // Otherwise, Resisted Damage = DR * Raw Damage + mov dword ptr ss:[esp + 0x30], 100; + mov eax, edx; + sar edx, 31; + idiv dword ptr ss:[esp + 0x30]; // Resisted Damage = Resisted Damage / 100 + sub ebx, eax; // Raw Damage = Raw Damage - Resisted Damage cjmp: - test ebx,ebx; // Is Raw Damage <= 0? - jle ijmp; // If yes, don't accumulate damage - add dword ptr ds:[edi],ebx; // Otherwise, Accumulated Damage = Accumulated Damage + Raw Damage + test ebx, ebx; // Is Raw Damage <= 0? + jle ijmp; // If yes, don't accumulate damage + add dword ptr ds:[edi], ebx; // Otherwise, Accumulated Damage = Accumulated Damage + Raw Damage ijmp: - mov eax,dword ptr ss:[esp+0x1c]; // Get number of hits - inc ecx; // counter += 1 - cmp ecx,eax; // Is counter < number of hits? - jl ajmp; // If yes, go back to start of damage calcuation loop (calculate damage for next hit) + mov eax, dword ptr ss:[esp + 0x1C]; // Get number of hits + inc ecx; // counter += 1 + cmp ecx, eax; // Is counter < number of hits? + jl ajmp; // If yes, go back to start of damage calcuation loop (calculate damage for next hit) end: - jmp DamageFunctionReturn; // Otherwise, exit loop + jmp DamageFunctionReturn; // Otherwise, exit loop } } //////////////////////////////////////////////////////////////////////////////// @@ -613,14 +435,11 @@ static void __declspec(naked) DisplayBonusHtHDmg2_hack() { } void AmmoModInit() { - int formula; if (formula = GetPrivateProfileIntA("Misc", "DamageFormula", 0, ini)) { switch (formula) { case 1: - MakeJump(0x424995, DamageFunction1); - break; case 2: - MakeJump(0x424995, DamageFunction2); + MakeJump(0x424995, DamageGlovz); break; /*case 3: MakeJump(0x424995, DamageFunction3); @@ -629,7 +448,7 @@ void AmmoModInit() { MakeJump(0x424995, DamageFunction4); break;*/ case 5: - MakeJump(0x424995, DamageFunction5); + MakeJump(0x424995, DamageYAAM); break; } } diff --git a/sfall/MainMenu.cpp b/sfall/MainMenu.cpp index f2b33218..868cec06 100644 --- a/sfall/MainMenu.cpp +++ b/sfall/MainMenu.cpp @@ -24,7 +24,7 @@ static DWORD MainMenuYOffset; static DWORD MainMenuTextOffset; -static const DWORD MainMenuButtonYHookRet=0x48184A; +static const DWORD MainMenuButtonYHookRet = 0x48184A; static void __declspec(naked) MainMenuButtonYHook() { __asm { xor edi, edi; @@ -41,7 +41,7 @@ static void __declspec(naked) MainMenuTextYHook() { } } -static const DWORD MainMenuTextRet=0x4817B0; +static const DWORD MainMenuTextRet = 0x4817B0; static const char* VerString1 = "SFALL " VERSION_STRING; static DWORD OverrideColour; static void __declspec(naked) FontColour() { @@ -56,6 +56,7 @@ skip: retn; } } + static void __declspec(naked) MainMenuTextHook() { __asm { mov edi, [esp]; @@ -82,29 +83,31 @@ static void __declspec(naked) MainMenuTextHook() { } void MainMenuInit() { - int tmp; + int offset; - if(tmp=GetPrivateProfileIntA("Misc", "MainMenuCreditsOffsetX", 0, ini)) { - SafeWrite32(0x481753, 0xf+tmp); + if (offset = GetPrivateProfileIntA("Misc", "MainMenuCreditsOffsetX", 0, ini)) { + SafeWrite32(0x481753, 15 + offset); } - if(tmp=GetPrivateProfileIntA("Misc", "MainMenuCreditsOffsetY", 0, ini)) { - SafeWrite32(0x48175C, 0x1cc+tmp); + if (offset = GetPrivateProfileIntA("Misc", "MainMenuCreditsOffsetY", 0, ini)) { + SafeWrite32(0x48175C, 460 + offset); } - if(tmp=GetPrivateProfileIntA("Misc", "MainMenuOffsetX", 0, ini)) { - SafeWrite32(0x48187C, 0x1e+tmp); - MainMenuTextOffset=tmp; + if (offset = GetPrivateProfileIntA("Misc", "MainMenuOffsetX", 0, ini)) { + SafeWrite32(0x48187C, 30 + offset); + MainMenuTextOffset = offset; } - if(tmp=GetPrivateProfileIntA("Misc", "MainMenuOffsetY", 0, ini)) { - MainMenuYOffset=tmp; - MainMenuTextOffset+=tmp*640; + if (offset = GetPrivateProfileIntA("Misc", "MainMenuOffsetY", 0, ini)) { + MainMenuYOffset = offset; + MainMenuTextOffset += offset * 640; MakeJump(0x481844, MainMenuButtonYHook); } - if(MainMenuTextOffset) { + if (MainMenuTextOffset) { SafeWrite8(0x481933, 0x90); MakeCall(0x481934, MainMenuTextYHook); } MakeJump(0x4817AB, MainMenuTextHook); - OverrideColour=GetPrivateProfileInt("Misc", "MainMenuFontColour", 0, ini); - if(OverrideColour) MakeCall(0x48174C, FontColour); + OverrideColour = GetPrivateProfileInt("Misc", "MainMenuFontColour", 0, ini); + if (OverrideColour) { + MakeCall(0x48174C, FontColour); + } } diff --git a/sfall/Stats.cpp b/sfall/Stats.cpp index b03eb7c6..595e5372 100644 --- a/sfall/Stats.cpp +++ b/sfall/Stats.cpp @@ -49,8 +49,8 @@ static void __declspec(naked) stat_level_hack() { } } -static DWORD __fastcall check_stat_level(register DWORD value, DWORD stat) { - DWORD valLimit; +static int __fastcall check_stat_level(register int value, int stat) { + int valLimit; if (cCritter == *ptr_obj_dude) { valLimit = StatMinimumsPC[stat]; if (value < valLimit) return valLimit;