From cd4d3b5b2fee123f48ab2486cb63bb237919330d Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 2 Apr 2020 12:00:52 +0800 Subject: [PATCH] Some code/document edits --- artifacts/scripting/hookscripts.txt | 2 +- artifacts/scripting/sfall function notes.txt | 2 +- sfall/ExtraSaveSlots.cpp | 4 +-- sfall/HookScripts.cpp | 4 +-- sfall/Inventory.cpp | 2 +- sfall/LoadGameHook.cpp | 11 ++++---- sfall/LoadGameHook.h | 4 ++- sfall/ScriptOps/MemoryOps.hpp | 24 +++-------------- sfall/ScriptOps/MiscOps.hpp | 2 +- sfall/ScriptOps/ObjectsOps.hpp | 13 +++++----- sfall/ScriptOps/ScriptUtils.hpp | 27 ++++++++++---------- sfall/Worldmap.cpp | 2 +- 12 files changed, 42 insertions(+), 55 deletions(-) diff --git a/artifacts/scripting/hookscripts.txt b/artifacts/scripting/hookscripts.txt index 3be20ad3..f4363578 100644 --- a/artifacts/scripting/hookscripts.txt +++ b/artifacts/scripting/hookscripts.txt @@ -132,7 +132,7 @@ int arg1 - The pid of the weapon performing the attack. (May be -1 if the at critter arg2 - The attacker critter arg3 - The target int arg4 - The amount of damage -int arg5 - Unused, always -1 (since sfall 3.8.24) +int arg5 - Unused, always -1. Use this if you are using the same procedure for HOOK_DEATHANIM1 and HOOK_DEATHANIM2 (since sfall 4.1/3.8.24) int ret1 - The pid of an object to override the attacking weapon with diff --git a/artifacts/scripting/sfall function notes.txt b/artifacts/scripting/sfall function notes.txt index fd0b766d..94e848e0 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -50,7 +50,7 @@ has_fake_trait and has_fake_perk return the number of levels the player has of t perk_add_mode, set_selectable_perk, set_perkbox_title, hide_real_perks, show_real_perks and clear_selectable_perks control the behaviour of the select a perk box. set_selectable_perk can be used to add additional items by setting the 'active' parameter to 1, and to remove them again by setting it to 0. set_perkbox_title can be used to change the title of the box, or by using "" it will be set back to the default. hide and show_real_perks can be used to prevent the dialog from displaying any of the original 119 perks. perk_add_mode modifies what happens when a fake perk is selected from the perks dialog. It is treated as a set of flags - if bit 1 is set then it is added to the player's traits, if bit 2 is set it is added to the player's perks, and if bit 3 is set it is removed from the list of selectable perks. The default is 0x2. clear_selectable_perks restores the dialog to its default state. -show_iface_tag, hide_iface_tag and is_iface_tag_active relate to the boxes that appear above the interface such as SNEAK and LEVEL. You can use 3 for LEVEL and 4 for ADDICT, or the range from 5 to (4 + the value of BoxBarCount in ddraw.ini) for custom boxes. Remember to add your messages to intrface.msg and set up the font colours in ddraw.ini if you're going to use custom boxes. Starting from sfall 3.8.12, is_iface_tag_active can also be used to check 0 for SNEAK, 1 for POISONED, and 2 for RADIATED. +show_iface_tag, hide_iface_tag and is_iface_tag_active relate to the boxes that appear above the interface such as SNEAK and LEVEL. You can use 3 for LEVEL and 4 for ADDICT, or the range from 5 to (4 + the value of BoxBarCount in ddraw.ini) for custom boxes. Remember to add your messages to intrface.msg and set up the font colours in ddraw.ini if you're going to use custom boxes. Starting from sfall 4.1/3.8.12, is_iface_tag_active can also be used to check 0 for SNEAK, 1 for POISONED, and 2 for RADIATED. get/set_bodypart_hit_modifier alter the hit percentage modifiers for aiming at specific bodyparts. Valid bodypart id's are from 0 to 8. Changes are not saved, and will reset to the defaults (or to the values specified in ddraw.ini if they exist) at each reload. diff --git a/sfall/ExtraSaveSlots.cpp b/sfall/ExtraSaveSlots.cpp index 51bbc1a7..ad1a744e 100644 --- a/sfall/ExtraSaveSlots.cpp +++ b/sfall/ExtraSaveSlots.cpp @@ -46,9 +46,9 @@ void SavePageOffsets() { sprintf_s(SavePath, MAX_PATH, filename, *ptr_patches); _itoa_s(*ptr_slot_cursor, buffer, 10); - WritePrivateProfileString("POSITION", "ListNum", buffer, SavePath); + WritePrivateProfileStringA("POSITION", "ListNum", buffer, SavePath); _itoa_s(LSPageOffset, buffer, 10); - WritePrivateProfileString("POSITION", "PageOffset", buffer, SavePath); + WritePrivateProfileStringA("POSITION", "PageOffset", buffer, SavePath); } //------------------------------------------ diff --git a/sfall/HookScripts.cpp b/sfall/HookScripts.cpp index d23d736d..04323d50 100644 --- a/sfall/HookScripts.cpp +++ b/sfall/HookScripts.cpp @@ -856,7 +856,7 @@ skip: } DWORD _stdcall KeyPressHook(DWORD dxKey, bool pressed, DWORD vKey) { - if (!IsMapLoaded()) { + if (!IsGameLoaded()) { return 0; } DWORD result = 0; @@ -873,7 +873,7 @@ DWORD _stdcall KeyPressHook(DWORD dxKey, bool pressed, DWORD vKey) { } void _stdcall MouseClickHook(DWORD button, bool pressed) { - if (!IsMapLoaded()) { + if (!IsGameLoaded()) { return; } BeginHook(); diff --git a/sfall/Inventory.cpp b/sfall/Inventory.cpp index 886c073f..fb3b0082 100644 --- a/sfall/Inventory.cpp +++ b/sfall/Inventory.cpp @@ -40,7 +40,7 @@ TGameObj* GetActiveItem() { } void InventoryKeyPressedHook(DWORD dxKey, bool pressed, DWORD vKey) { - if (pressed && reloadWeaponKey && dxKey == reloadWeaponKey && IsMapLoaded() && (GetLoopFlags() & ~(COMBAT | PCOMBAT)) == 0) { + if (pressed && reloadWeaponKey && dxKey == reloadWeaponKey && IsGameLoaded() && (GetLoopFlags() & ~(COMBAT | PCOMBAT)) == 0) { DWORD maxAmmo, curAmmo; TGameObj* item = GetActiveItem(); __asm { diff --git a/sfall/LoadGameHook.cpp b/sfall/LoadGameHook.cpp index c608654e..4aad9758 100644 --- a/sfall/LoadGameHook.cpp +++ b/sfall/LoadGameHook.cpp @@ -55,10 +55,11 @@ DWORD LoadGameHook_LootTarget = 0; static DWORD inLoop = 0; static DWORD saveInCombatFix; -static bool mapLoaded = false; +static bool gameLoaded = false; -bool IsMapLoaded() { - return mapLoaded; +// True if game was started, false when on the main menu +bool IsGameLoaded() { + return gameLoaded; } DWORD InWorldMap() { @@ -230,7 +231,7 @@ errorLoad: static void _stdcall LoadGame2_After() { CritLoad(); LoadGlobalScripts(); - mapLoaded = true; + gameLoaded = true; } static void __declspec(naked) LoadSlot() { @@ -313,7 +314,7 @@ static void NewGame2() { CritLoad(); LoadGlobalScripts(); LoadHeroAppearance(); - mapLoaded = true; + gameLoaded = true; } static bool DisableHorrigan = false; diff --git a/sfall/LoadGameHook.h b/sfall/LoadGameHook.h index 299dbd8e..8558ccaf 100644 --- a/sfall/LoadGameHook.h +++ b/sfall/LoadGameHook.h @@ -22,7 +22,9 @@ extern DWORD LoadGameHook_LootTarget; void LoadGameHookInit(); -bool IsMapLoaded(); +// True if game was started, false when on the main menu +bool IsGameLoaded(); + DWORD InWorldMap(); DWORD InCombat(); DWORD InDialog(); diff --git a/sfall/ScriptOps/MemoryOps.hpp b/sfall/ScriptOps/MemoryOps.hpp index 7a097618..e9a83578 100644 --- a/sfall/ScriptOps/MemoryOps.hpp +++ b/sfall/ScriptOps/MemoryOps.hpp @@ -93,11 +93,7 @@ error: static void __declspec(naked) WriteByte() { __asm { push ecx; - call interpretPopShort_; - mov ecx, eax; // type - mov eax, ebx; - call interpretPopLong_; - mov esi, eax; // write value + _GET_ARG(esi, ecx); // write value mov eax, ebx; _GET_ARG_INT(end); cmp cx, VAR_TYPE_INT; @@ -123,11 +119,7 @@ end: static void __declspec(naked) WriteShort() { __asm { push ecx; - call interpretPopShort_; - mov ecx, eax; // type - mov eax, ebx; - call interpretPopLong_; - mov esi, eax; // write value + _GET_ARG(esi, ecx); // write value mov eax, ebx; _GET_ARG_INT(end); cmp cx, VAR_TYPE_INT; @@ -153,11 +145,7 @@ end: static void __declspec(naked) WriteInt() { __asm { push ecx; - call interpretPopShort_; - mov ecx, eax; // type - mov eax, ebx; - call interpretPopLong_; - mov esi, eax; // write value + _GET_ARG(esi, ecx); // write value mov eax, ebx; _GET_ARG_INT(end); cmp cx, VAR_TYPE_INT; @@ -191,11 +179,7 @@ static void __fastcall WriteStringInternal(char* addr, long type, long strID, TP static void __declspec(naked) WriteString() { __asm { push ecx; - call interpretPopShort_; - mov ecx, eax; // type - mov eax, ebx; - call interpretPopLong_; - mov esi, eax; // str value + _GET_ARG(esi, ecx); // str value mov eax, ebx; _GET_ARG_INT(end); cmp cx, VAR_TYPE_STR2; diff --git a/sfall/ScriptOps/MiscOps.hpp b/sfall/ScriptOps/MiscOps.hpp index d813ed4d..cbe66686 100644 --- a/sfall/ScriptOps/MiscOps.hpp +++ b/sfall/ScriptOps/MiscOps.hpp @@ -1134,7 +1134,7 @@ static void sf_set_ini_setting() { char section[33], file[67]; int result = ParseIniSetting(opHandler.arg(0).strValue(), key, section, file); if (result > 0) { - result = WritePrivateProfileString(section, key, saveValue, file); + result = WritePrivateProfileStringA(section, key, saveValue, file); } switch (result) { diff --git a/sfall/ScriptOps/ObjectsOps.hpp b/sfall/ScriptOps/ObjectsOps.hpp index 8633cd88..5d38ce82 100644 --- a/sfall/ScriptOps/ObjectsOps.hpp +++ b/sfall/ScriptOps/ObjectsOps.hpp @@ -221,11 +221,13 @@ static void __declspec(naked) set_weapon_ammo_count() { _WRAP_OPCODE(set_weapon_ammo_count2, 2, 0) } -#define BLOCKING_TYPE_BLOCK (0) -#define BLOCKING_TYPE_SHOOT (1) -#define BLOCKING_TYPE_AI (2) -#define BLOCKING_TYPE_SIGHT (3) -#define BLOCKING_TYPE_SCROLL (4) +enum { + BLOCKING_TYPE_BLOCK = 0, + BLOCKING_TYPE_SHOOT = 1, + BLOCKING_TYPE_AI = 2, + BLOCKING_TYPE_SIGHT = 3, + BLOCKING_TYPE_SCROLL = 4 +}; static DWORD getBlockingFunc(DWORD type) { switch (type) { @@ -239,7 +241,6 @@ static DWORD getBlockingFunc(DWORD type) { return obj_sight_blocking_at_; //case 4: // return obj_scroll_blocking_at_; - } } diff --git a/sfall/ScriptOps/ScriptUtils.hpp b/sfall/ScriptOps/ScriptUtils.hpp index 893d5dce..1f84eade 100644 --- a/sfall/ScriptOps/ScriptUtils.hpp +++ b/sfall/ScriptOps/ScriptUtils.hpp @@ -285,17 +285,20 @@ static char* _stdcall mysprintf(const char* format, DWORD value, DWORD valueType valueType = valueType & 0xFFFF; // use lower 2 bytes int fmtlen = strlen(format); int buflen = fmtlen + 1; + for (int i = 0; i < fmtlen; i++) { if (format[i] == '%') buflen++; // will possibly be escaped, need space for that } + // parse format to make it safe char* newfmt = new char[buflen]; - byte mode = 0; - int j = 0; - char c, specifier; + unsigned char mode = 0; + char specifier = 0; bool hasDigits = false; + int j = 0; + for (int i = 0; i < fmtlen; i++) { - c = format[i]; + char c = format[i]; switch (mode) { case 0: // prefix if (c == '%') { @@ -304,12 +307,11 @@ static char* _stdcall mysprintf(const char* format, DWORD value, DWORD valueType break; case 1: // definition if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { - if (c == 'h' || c == 'l' || c == 'j' || c == 'z' || c == 't' || c == 'L') { // ignore sub-specifiers - continue; - } - if (c == 's' && valueType != VAR_TYPE_STR2 && valueType != VAR_TYPE_STR) { // don't allow to treat non-string values as string pointers - c = 'd'; - } else if (c == 'n') { // don't allow "n" specifier + if (c == 'h' || c == 'l' || c == 'j' || c == 'z' || c == 't' || c == 'L') continue; // ignore sub-specifiers + + if (c == 's' && !(valueType == VAR_TYPE_STR2 || valueType == VAR_TYPE_STR) || // don't allow to treat non-string values as string pointers + c == 'n') // don't allow "n" specifier + { c = 'd'; } specifier = c; @@ -322,12 +324,9 @@ static char* _stdcall mysprintf(const char* format, DWORD value, DWORD valueType } break; case 2: // postfix - default: if (c == '%') { // don't allow more than one specifier newfmt[j++] = '%'; // escape it - if (format[i + 1] == '%') { - i++; // skip already escaped - } + if (format[i + 1] == '%') i++; // skip already escaped } break; } diff --git a/sfall/Worldmap.cpp b/sfall/Worldmap.cpp index 339fe582..2fd353bc 100644 --- a/sfall/Worldmap.cpp +++ b/sfall/Worldmap.cpp @@ -92,7 +92,7 @@ static __declspec(naked) void set_game_time_hack() { __asm { mov dword ptr ds:[_fallout_game_time], eax; mov edx, eax; - call IsMapLoaded; + call IsGameLoaded; test al, al; jz end; cmp edx, ONE_GAME_YEAR * 13;