mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Added use_item_on_dude macro to sfall.h
Various code edits: * Implemented more HookCalls/MakeCalls/SafeWriteBatch in code. * Moved return/jump address consts into their respective functions. * Changed for-loop with iterators to use pre-increment.
This commit is contained in:
@@ -266,6 +266,12 @@
|
||||
#define ADD_PERK_MODE_PERK (2) // add to the player's perks
|
||||
#define ADD_PERK_MODE_REMOVE (4) // remove from the list of selectable perks (after added to the player)
|
||||
|
||||
// instantly apply the item to dude_obj (w/o animation)
|
||||
#define use_item_on_dude(item) set_self(dude_obj); \
|
||||
set_self(dude_obj); \
|
||||
use_obj_on_obj(item, dude_obj); \
|
||||
set_self(0)
|
||||
|
||||
// sfall_funcX macros
|
||||
#define add_extra_msg_file(name) sfall_func1("add_extra_msg_file", name)
|
||||
#define add_global_timer_event(time, fixedParam) sfall_func2("add_g_timer_event", time, fixedParam)
|
||||
|
||||
@@ -11,13 +11,13 @@ ModuleManager::ModuleManager() {
|
||||
}
|
||||
|
||||
ModuleManager::~ModuleManager() {
|
||||
for (auto it = _modules.cbegin(); it != _modules.cend(); it++) {
|
||||
for (auto it = _modules.cbegin(); it != _modules.cend(); ++it) {
|
||||
(*it)->exit();
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleManager::initAll() {
|
||||
for (auto it = _modules.cbegin(); it != _modules.cend(); it++) {
|
||||
for (auto it = _modules.cbegin(); it != _modules.cend(); ++it) {
|
||||
dlog_f("Initializing module %s...\n", DL_INIT, (*it)->name());
|
||||
(*it)->init();
|
||||
}
|
||||
|
||||
@@ -191,9 +191,9 @@ static DWORD __fastcall CheckSetSad(BYTE openFlag, DWORD valueMul) {
|
||||
return result;
|
||||
}
|
||||
|
||||
static const DWORD object_move_back0 = 0x417611;
|
||||
static const DWORD object_move_back1 = 0x417616;
|
||||
static void __declspec(naked) object_move_hack() {
|
||||
static const DWORD object_move_back0 = 0x417611;
|
||||
static const DWORD object_move_back1 = 0x417616;
|
||||
__asm {
|
||||
mov ecx, ds:[ecx + 0x3C]; // openFlag
|
||||
mov edx, [esp + 0x4C - 0x20]; // valueMul
|
||||
|
||||
@@ -61,9 +61,9 @@ static const DWORD bboxSlotAddr[] = {
|
||||
0x4616F7, 0x46170F, 0x461736, 0x4616B1, 0x46151D, 0x4615B3
|
||||
};
|
||||
|
||||
static const DWORD DisplayBoxesRet1 = 0x4615A8;
|
||||
static const DWORD DisplayBoxesRet2 = 0x4615BE;
|
||||
static void __declspec(naked) DisplayBoxesHack() {
|
||||
static const DWORD DisplayBoxesRet1 = 0x4615A8;
|
||||
static const DWORD DisplayBoxesRet2 = 0x4615BE;
|
||||
__asm {
|
||||
mov edx, [boxText];
|
||||
xor ebx, ebx;
|
||||
@@ -115,8 +115,8 @@ skip:
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD SetIndexBoxRet = 0x4612E8;
|
||||
static void __declspec(naked) BarBoxesIndexHack() {
|
||||
static const DWORD SetIndexBoxRet = 0x4612E8;
|
||||
__asm {
|
||||
mov eax, ds:[0x4612E2]; // fontnum
|
||||
mov ecx, setBoxIndex; // start index
|
||||
@@ -125,9 +125,9 @@ static void __declspec(naked) BarBoxesIndexHack() {
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD SizeLoopBoxRet = 0x461477;
|
||||
static const DWORD ExitLoopBoxRet = 0x461498;
|
||||
static void __declspec(naked) BarBoxesSizeHack() {
|
||||
static const DWORD SizeLoopBoxRet = 0x461477;
|
||||
static const DWORD ExitLoopBoxRet = 0x461498;
|
||||
__asm {
|
||||
cmp edx, sizeBox;
|
||||
jz exitLoop;
|
||||
|
||||
@@ -45,8 +45,8 @@ static sBook* __fastcall FindBook(DWORD pid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const DWORD obj_use_book_hook_back = 0x49BA5A;
|
||||
static void __declspec(naked) obj_use_book_hook() {
|
||||
static const DWORD obj_use_book_hook_back = 0x49BA5A;
|
||||
__asm {
|
||||
mov edi, -1;
|
||||
mov ecx, eax;
|
||||
|
||||
@@ -41,7 +41,7 @@ void BugFixes::DrugsSaveFix(HANDLE file) {
|
||||
DWORD sizeWrite, count = drugsPid.size();
|
||||
WriteFile(file, &count, 4, &sizeWrite, 0);
|
||||
if (!count) return;
|
||||
for (auto it = drugsPid.begin(); it != drugsPid.end(); it++) {
|
||||
for (auto it = drugsPid.begin(); it != drugsPid.end(); ++it) {
|
||||
int pid = *it;
|
||||
WriteFile(file, &pid, 4, &sizeWrite, 0);
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ static long __fastcall ComputeSpray(DWORD* roundsLeftOut, DWORD* roundsRightOut,
|
||||
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() {
|
||||
static const DWORD compute_spray_rounds_back = 0x42353A;
|
||||
__asm {
|
||||
push ecx;
|
||||
lea ecx, [esp + 8 + 4]; // roundsLeft - out
|
||||
|
||||
@@ -132,9 +132,9 @@ static void __declspec(naked) ai_search_inven_weap_hook() {
|
||||
}
|
||||
|
||||
// switch weapon mode from secondary to primary if there is not enough ammo to shoot
|
||||
static const DWORD ai_try_attack_search_ammo = 0x42AA1E;
|
||||
static const DWORD ai_try_attack_continue = 0x42A929;
|
||||
static void __declspec(naked) ai_try_attack_hook() {
|
||||
static const DWORD ai_try_attack_search_ammo = 0x42AA1E;
|
||||
static const DWORD ai_try_attack_continue = 0x42A929;
|
||||
using namespace fo;
|
||||
using namespace Fields;
|
||||
__asm {
|
||||
@@ -221,8 +221,8 @@ static void __declspec(naked) compute_damage_hack() {
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD KnockbackRetAddr = 0x4136E1;
|
||||
static void __declspec(naked) compute_dmg_damage_hack() {
|
||||
static const DWORD KnockbackRetAddr = 0x4136E1;
|
||||
__asm {
|
||||
push ecx
|
||||
push esi; // Target
|
||||
@@ -376,9 +376,9 @@ static int __fastcall AimedShotTest(DWORD pid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const DWORD aimedShotRet1 = 0x478EE4;
|
||||
static const DWORD aimedShotRet2 = 0x478EEA;
|
||||
static void __declspec(naked) item_w_called_shot_hook() {
|
||||
static const DWORD aimedShotRet1 = 0x478EE4;
|
||||
static const DWORD aimedShotRet2 = 0x478EEA;
|
||||
__asm {
|
||||
push edx;
|
||||
mov ecx, edx; // item
|
||||
|
||||
@@ -31,8 +31,8 @@ static void __stdcall ConsoleFilePrint(const char* msg) {
|
||||
consoleFile << msg << std::endl;
|
||||
}
|
||||
|
||||
static const DWORD ConsoleHookRet = 0x431871;
|
||||
static void __declspec(naked) ConsoleHook() {
|
||||
static const DWORD ConsoleHookRet = 0x431871;
|
||||
__asm {
|
||||
pushadc;
|
||||
push eax;
|
||||
|
||||
@@ -366,8 +366,8 @@ static void __declspec(naked) DisplayBonusHtHDmg1_hook() {
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD DisplayBonusHtHDmg2Exit = 0x472569;
|
||||
static void __declspec(naked) DisplayBonusHtHDmg2_hack() {
|
||||
static const DWORD DisplayBonusHtHDmg2Exit = 0x472569;
|
||||
__asm {
|
||||
mov ecx, eax;
|
||||
call fo::funcoffs::stat_level_;
|
||||
|
||||
@@ -296,8 +296,8 @@ void RunDebugEditor() {
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
static const DWORD dbg_error_ret = 0x453FD8;
|
||||
static void __declspec(naked) dbg_error_hack() {
|
||||
static const DWORD dbg_error_ret = 0x453FD8;
|
||||
__asm {
|
||||
cmp ebx, 1;
|
||||
je hide;
|
||||
|
||||
@@ -151,8 +151,8 @@ static long __fastcall PrintAddictionList(long isSeparator) {
|
||||
return isSelect;
|
||||
}
|
||||
|
||||
static const DWORD list_karma_Ret = 0x43C1A3;
|
||||
static void __declspec(naked) list_karma_hack() {
|
||||
static const DWORD list_karma_Ret = 0x43C1A3;
|
||||
__asm {
|
||||
mov ecx, [esp + 0x168 - 0x1C + 4];
|
||||
call PrintAddictionList;
|
||||
|
||||
@@ -144,19 +144,15 @@ void ElevatorsInit() {
|
||||
//HookCall(0x43F2D2, UnknownHook2); // unused
|
||||
|
||||
SafeWrite8(0x43EF76, (BYTE)elevatorCount);
|
||||
SafeWrite32(0x43EFA4, (DWORD)elevatorExits);
|
||||
SafeWrite32(0x43EFB9, (DWORD)elevatorExits);
|
||||
SafeWrite32(0x43F2FC, (DWORD)elevatorExits);
|
||||
SafeWrite32(0x43EFEA, (DWORD)&elevatorExits[0][0].tile);
|
||||
SafeWrite32(0x43F315, (DWORD)&elevatorExits[0][0].tile);
|
||||
SafeWriteBatch<DWORD>((DWORD)elevatorExits, {0x43EFA4, 0x43EFB9, 0x43F2FC});
|
||||
SafeWriteBatch<DWORD>((DWORD)&elevatorExits[0][0].tile, {0x43EFEA, 0x43F315});
|
||||
SafeWrite32(0x43F309, (DWORD)&elevatorExits[0][0].elevation);
|
||||
|
||||
SafeWrite32(0x43F438, (DWORD)&elevatorsFrms[0].main);
|
||||
SafeWrite32(0x43F475, (DWORD)&elevatorsFrms[0].buttons);
|
||||
|
||||
// _btncnt
|
||||
SafeWrite32(0x43F65E, (DWORD)elevatorsBtnCount);
|
||||
SafeWrite32(0x43F6BB, (DWORD)elevatorsBtnCount);
|
||||
SafeWriteBatch<DWORD>((DWORD)elevatorsBtnCount, {0x43F65E, 0x43F6BB});
|
||||
MakeCall(0x43F05D, GetNumButtonsHook1, 2);
|
||||
MakeCall(0x43F184, GetNumButtonsHook2, 2);
|
||||
MakeCall(0x43F1E4, GetNumButtonsHook3, 2);
|
||||
|
||||
@@ -37,11 +37,11 @@ struct fsFile {
|
||||
BYTE isSave;
|
||||
};
|
||||
|
||||
struct openFile {
|
||||
struct OpenFile {
|
||||
DWORD pos; // current xread/xwrite position
|
||||
fsFile* file;
|
||||
|
||||
openFile(fsFile* pFile) {
|
||||
OpenFile(fsFile* pFile) {
|
||||
pos = 0;
|
||||
file = pFile;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ struct openFile {
|
||||
|
||||
struct sFile {
|
||||
DWORD type;
|
||||
openFile* opnFile;
|
||||
OpenFile* openFile;
|
||||
};
|
||||
|
||||
std::vector<fsFile> files;
|
||||
@@ -58,7 +58,7 @@ static DWORD loadedFiles = 0; // used for internal sfall data
|
||||
bool FileSystem::UsingFileSystem = false;
|
||||
|
||||
static long _stdcall xfclose(sFile* file) {
|
||||
delete file->opnFile;
|
||||
delete file->openFile;
|
||||
delete file;
|
||||
return 0;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ static sFile* _stdcall xfopen(const char* path, const char* mode) {
|
||||
if (!_stricmp(path, files[i].name)) {
|
||||
sFile* file = new sFile();
|
||||
file->type = 3;
|
||||
file->opnFile = new openFile(&files[i]);
|
||||
file->openFile = new OpenFile(&files[i]);
|
||||
return file;
|
||||
}
|
||||
}
|
||||
@@ -128,8 +128,8 @@ end:
|
||||
}
|
||||
|
||||
static DWORD _stdcall xfgetc(sFile* file) {
|
||||
if (file->opnFile->pos >= file->opnFile->file->length) return -1;
|
||||
return static_cast<DWORD>(file->opnFile->file->data[file->opnFile->pos++]);
|
||||
if (file->openFile->pos >= file->openFile->file->length) return -1;
|
||||
return static_cast<DWORD>(file->openFile->file->data[file->openFile->pos++]);
|
||||
}
|
||||
|
||||
static __declspec(naked) int asm_xfgetc(sFile* file) {
|
||||
@@ -149,7 +149,7 @@ end:
|
||||
}
|
||||
|
||||
static char* _stdcall xfgets(char* buf, int max_count, sFile* file) {
|
||||
if (file->opnFile->pos >= file->opnFile->file->length) return 0;
|
||||
if (file->openFile->pos >= file->openFile->file->length) return 0;
|
||||
for (int i = 0; i < max_count; i++) {
|
||||
int c = xfgetc(file);
|
||||
if (c == -1) {
|
||||
@@ -218,9 +218,9 @@ end:
|
||||
}
|
||||
|
||||
static int _stdcall xfungetc(int c, sFile* file) {
|
||||
if (file->opnFile->pos == 0) return -1;
|
||||
if (file->opnFile->file->data[file->opnFile->pos - 1] != static_cast<BYTE>(c)) return -1;
|
||||
file->opnFile->pos--;
|
||||
if (file->openFile->pos == 0) return -1;
|
||||
if (file->openFile->file->data[file->openFile->pos - 1] != static_cast<BYTE>(c)) return -1;
|
||||
file->openFile->pos--;
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -241,10 +241,10 @@ end:
|
||||
|
||||
static int __fastcall xfread(sFile* file, int elsize, void* buf, int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (file->opnFile->pos + elsize > file->opnFile->file->length) return i;
|
||||
if (file->openFile->pos + elsize > file->openFile->file->length) return i;
|
||||
|
||||
memcpy(buf, &file->opnFile->file->data[file->opnFile->pos], elsize);
|
||||
file->opnFile->pos += elsize;
|
||||
memcpy(buf, &file->openFile->file->data[file->openFile->pos], elsize);
|
||||
file->openFile->pos += elsize;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
@@ -301,13 +301,13 @@ end:
|
||||
static int _stdcall xfseek(sFile* file, long pos, int origin) {
|
||||
switch(origin) {
|
||||
case 0:
|
||||
file->opnFile->pos = pos;
|
||||
file->openFile->pos = pos;
|
||||
break;
|
||||
case 1:
|
||||
file->opnFile->pos += pos;
|
||||
file->openFile->pos += pos;
|
||||
break;
|
||||
case 2:
|
||||
file->opnFile->pos = file->opnFile->file->length + pos;
|
||||
file->openFile->pos = file->openFile->file->length + pos;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
@@ -330,7 +330,7 @@ end:
|
||||
}
|
||||
|
||||
static long _stdcall xftell(sFile* file) {
|
||||
return file->opnFile->pos;
|
||||
return file->openFile->pos;
|
||||
}
|
||||
|
||||
static __declspec(naked) long asm_xftell(sFile* file) {
|
||||
@@ -350,7 +350,7 @@ end:
|
||||
}
|
||||
|
||||
static void _stdcall xfrewind(sFile* file) {
|
||||
file->opnFile->pos = 0;
|
||||
file->openFile->pos = 0;
|
||||
}
|
||||
|
||||
static __declspec(naked) void asm_xfrewind(sFile* file) {
|
||||
@@ -368,7 +368,7 @@ end:
|
||||
}
|
||||
|
||||
static int _stdcall xfeof(sFile* file) {
|
||||
if (file->opnFile->pos >= file->opnFile->file->length) {
|
||||
if (file->openFile->pos >= file->openFile->file->length) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -391,7 +391,7 @@ end:
|
||||
}
|
||||
|
||||
static int _stdcall xfilelength(sFile* file) {
|
||||
return file->opnFile->file->length;
|
||||
return file->openFile->file->length;
|
||||
}
|
||||
|
||||
static __declspec(naked) int asm_xfilelength(sFile* file) {
|
||||
@@ -458,8 +458,8 @@ static void FileSystemLoad() {
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD LoadHookRetAddr = 0x47CCEE;
|
||||
static void __declspec(naked) FSLoadHook() {
|
||||
static const DWORD LoadHookRetAddr = 0x47CCEE;
|
||||
__asm {
|
||||
pushadc;
|
||||
call FileSystemLoad;
|
||||
|
||||
@@ -1296,8 +1296,8 @@ endFunc:
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD op_obj_art_fid_Ret = 0x45C5D9;
|
||||
static void __declspec(naked) op_obj_art_fid_hack() {
|
||||
static const DWORD op_obj_art_fid_Ret = 0x45C5D9;
|
||||
using namespace Fields;
|
||||
__asm {
|
||||
mov esi, [edi + artFid];
|
||||
|
||||
@@ -419,8 +419,8 @@ skip:
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD combat_hook_end_combat = 0x422E91;
|
||||
static void __declspec(naked) combat_hook_fix_load() {
|
||||
static const DWORD combat_hook_end_combat = 0x422E91;
|
||||
__asm {
|
||||
call fo::funcoffs::combat_sequence_;
|
||||
mov eax, countCombat;
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
namespace sfall
|
||||
{
|
||||
|
||||
static const DWORD _obj_blocking_at = 0x48B84E;
|
||||
static void __declspec(naked) HexMBlockingHook() {
|
||||
static const DWORD _obj_blocking_at = 0x48B84E;
|
||||
__asm {
|
||||
HookBegin;
|
||||
mov args[0], eax;
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
namespace sfall
|
||||
{
|
||||
|
||||
static const DWORD RemoveObjHookRet = 0x477497;
|
||||
static void __declspec(naked) RemoveObjHook() {
|
||||
static const DWORD RemoveObjHookRet = 0x477497;
|
||||
__asm {
|
||||
mov ecx, [esp + 8]; // call addr
|
||||
HookBegin;
|
||||
@@ -126,10 +126,10 @@ static int __fastcall InventoryMoveHook_Script(DWORD itemReplace, DWORD item, in
|
||||
return result;
|
||||
}
|
||||
|
||||
static const DWORD UseArmorHack_back = 0x4713AF; // normal operation (old 0x4713A9)
|
||||
static const DWORD UseArmorHack_skip = 0x471481; // skip code, prevent wearing armor
|
||||
// This hack is called when an armor is dropped into the armor slot at inventory screen
|
||||
static void __declspec(naked) UseArmorHack() {
|
||||
static const DWORD UseArmorHack_back = 0x4713AF; // normal operation (old 0x4713A9)
|
||||
static const DWORD UseArmorHack_skip = 0x471481; // skip code, prevent wearing armor
|
||||
__asm {
|
||||
mov ecx, ds:[FO_VAR_i_worn]; // replacement item (override code)
|
||||
mov edx, [esp + 0x58 - 0x40]; // item
|
||||
@@ -236,9 +236,9 @@ static int __fastcall DropIntoContainer(DWORD ptrCont, DWORD item, DWORD addrCal
|
||||
return InventoryMoveHook_Script(ptrCont, item, type);
|
||||
}
|
||||
|
||||
static const DWORD DropIntoContainer_back = 0x47649D; // normal operation
|
||||
static const DWORD DropIntoContainer_skip = 0x476503;
|
||||
static void __declspec(naked) DropIntoContainerHack() {
|
||||
static const DWORD DropIntoContainer_back = 0x47649D; // normal operation
|
||||
static const DWORD DropIntoContainer_skip = 0x476503;
|
||||
__asm {
|
||||
pushadc;
|
||||
mov ecx, ebp; // contaner ptr
|
||||
@@ -256,17 +256,17 @@ skipdrop:
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD DropIntoContainerRet = 0x471481;
|
||||
static void __declspec(naked) DropIntoContainerHandSlotHack() {
|
||||
static const DWORD DropIntoContainerRet = 0x471481;
|
||||
__asm {
|
||||
call fo::funcoffs::drop_into_container_;
|
||||
jmp DropIntoContainerRet;
|
||||
}
|
||||
}
|
||||
|
||||
//static const DWORD DropAmmoIntoWeaponHack_back = 0x47658D; // proceed with reloading
|
||||
static const DWORD DropAmmoIntoWeaponHack_return = 0x476643;
|
||||
static void __declspec(naked) DropAmmoIntoWeaponHook() {
|
||||
//static const DWORD DropAmmoIntoWeaponHack_back = 0x47658D; // proceed with reloading
|
||||
static const DWORD DropAmmoIntoWeaponHack_return = 0x476643;
|
||||
__asm {
|
||||
pushadc;
|
||||
mov ecx, ebp; // weapon ptr
|
||||
|
||||
@@ -358,8 +358,8 @@ static void CarTravelHook_Script() {
|
||||
EndHook();
|
||||
}
|
||||
|
||||
static const DWORD CarTravelHack_back = 0x4BFF43;
|
||||
static void __declspec(naked) CarTravelHack() {
|
||||
static const DWORD CarTravelHack_back = 0x4BFF43;
|
||||
__asm {
|
||||
pushad;
|
||||
call CarTravelHook_Script;
|
||||
|
||||
@@ -66,8 +66,8 @@ static void __declspec(naked) intface_init_hack() {
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD intface_update_move_points_ret = 0x45EE3E;
|
||||
static void __declspec(naked) intface_update_move_points_hack() {
|
||||
static const DWORD intface_update_move_points_ret = 0x45EE3E;
|
||||
__asm {
|
||||
mov eax, 16 * 9
|
||||
push eax;
|
||||
@@ -237,8 +237,8 @@ static const DWORD wmViewportEndBottom[] = {
|
||||
0x4C44BE, // wmCursorIsVisible_
|
||||
};
|
||||
|
||||
static const DWORD wmInterfaceInit_Ret = 0x4C23A7;
|
||||
static void __declspec(naked) wmInterfaceInit_hack() {
|
||||
static const DWORD wmInterfaceInit_Ret = 0x4C23A7;
|
||||
__asm {
|
||||
push eax;
|
||||
mov eax, 640 - WMAP_WIN_WIDTH;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user