From e5f7d29a03176d7744a542e36121cc54790f9fc8 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Mon, 11 Apr 2022 09:56:35 +0800 Subject: [PATCH 01/20] [HRP] Fixed movie subtitles not showing up when setting MOVIE_SIZE=1 * happens with certain combinations of screen and movie aspect ratios. Minor edit to Credits.cpp. Updated version number. --- sfall/HRP/MoviesScreen.cpp | 4 ++++ sfall/Modules/Credits.cpp | 1 + sfall/version.h | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sfall/HRP/MoviesScreen.cpp b/sfall/HRP/MoviesScreen.cpp index 57cc65c2..e3261447 100644 --- a/sfall/HRP/MoviesScreen.cpp +++ b/sfall/HRP/MoviesScreen.cpp @@ -41,6 +41,10 @@ static void __fastcall SetMovieSize() { long aspectH = sHeight; long x = 0; long y = 0; + + float movieAspect = (float)bW / (float)bH; + float marginHeight = (sHeight - (sWidth / movieAspect)) / 2; + if (marginHeight < subtitleHeight) aspectH -= subtitleHeight; // reserve space Image::GetAspectSize(bW, bH, &x, &y, aspectW, aspectH); movieToSize.left = x; diff --git a/sfall/Modules/Credits.cpp b/sfall/Modules/Credits.cpp index ee31efde..d771ea24 100644 --- a/sfall/Modules/Credits.cpp +++ b/sfall/Modules/Credits.cpp @@ -40,6 +40,7 @@ static const char* ExtraLines[] = { "Timeslip", "", "@Contributors", + "@(in chronological order)", "ravachol", "Noid", "Glovz", diff --git a/sfall/version.h b/sfall/version.h index 854984b9..40790b1f 100644 --- a/sfall/version.h +++ b/sfall/version.h @@ -25,6 +25,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 3 #define VERSION_BUILD 4 -#define VERSION_REV 0 +#define VERSION_REV 1 -#define VERSION_STRING "4.3.4" +#define VERSION_STRING "4.3.4.1" From 144d57243c065c628cc0afad7888d35c8309f0d1 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Mon, 18 Apr 2022 14:22:08 +0800 Subject: [PATCH 02/20] [HRP] Disabled scaling of main menu buttons/text for Chinese version * to prevent garbled text from Image::ScaleText() --- sfall/HRP/Init.cpp | 2 +- sfall/HRP/MainMenu.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sfall/HRP/Init.cpp b/sfall/HRP/Init.cpp index 3e1a1dc7..361bd1a4 100644 --- a/sfall/HRP/Init.cpp +++ b/sfall/HRP/Init.cpp @@ -185,7 +185,7 @@ void Setting::init(const char* exeFileName, std::string &cmdline) { if (cmdline.find(" -restart") != std::string::npos) { GetBackupFileName(exeFileName, true); // delete after restart } - if (hiResMode == false) return; + if (!hiResMode) return; if (Setting::ExternalEnabled()) { char infoMsg[512]; diff --git a/sfall/HRP/MainMenu.cpp b/sfall/HRP/MainMenu.cpp index 5b75140c..68cfbefe 100644 --- a/sfall/HRP/MainMenu.cpp +++ b/sfall/HRP/MainMenu.cpp @@ -136,7 +136,7 @@ static long __fastcall main_menu_create_hook_add_win(long h, long y, long color, scaleHeight = (h / 480.0f); // is not scaled if USE_HIRES_IMAGES is used and the SCALE_BUTTONS_AND_TEXT_MENU option is disabled - if (MainMenuScreen::USE_HIRES_IMAGES == false || (MainMenuScreen::USE_HIRES_IMAGES && MainMenuScreen::SCALE_BUTTONS_AND_TEXT_MENU)) { + if (!sf::versionCHI && (!MainMenuScreen::USE_HIRES_IMAGES || (MainMenuScreen::USE_HIRES_IMAGES && MainMenuScreen::SCALE_BUTTONS_AND_TEXT_MENU))) { scaleFactor = scaleHeight; } else { if (w != 640) { From e9581cd92b1c5236ac7b1fa0a03acefa904573f0 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Wed, 20 Apr 2022 09:45:52 +0800 Subject: [PATCH 03/20] Corrected placeholders for obsolete opcodes Minor edit to documents. --- artifacts/scripting/functions.yml | 2 +- artifacts/scripting/sfall opcode list.md | 2 +- artifacts/scripting/sfall opcode list.txt | 2 +- sfall/Modules/Scripting/Handlers/Misc.cpp | 14 +++++++++++++- sfall/Modules/Scripting/Handlers/Misc.h | 2 ++ sfall/Modules/Scripting/Opcodes.cpp | 2 +- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/artifacts/scripting/functions.yml b/artifacts/scripting/functions.yml index 887c2642..ca305d7e 100644 --- a/artifacts/scripting/functions.yml +++ b/artifacts/scripting/functions.yml @@ -983,7 +983,7 @@ detail: int gdialog_get_barter_mod opcode: 0x824c - name: set_inven_ap_cost - detail: void set_inven_ap_cost + detail: void set_inven_ap_cost(int cost) opcode: 0x824d - name: game_loaded detail: int game_loaded() diff --git a/artifacts/scripting/sfall opcode list.md b/artifacts/scripting/sfall opcode list.md index a18b34cc..a1c14a97 100644 --- a/artifacts/scripting/sfall opcode list.md +++ b/artifacts/scripting/sfall opcode list.md @@ -325,7 +325,7 @@ _^ - These functions require AllowUnsafeScripting to be enabled in ddraw.ini_ 0x824b - `int tile_under_cursor()`\ 0x824c - `int gdialog_get_barter_mod()`\ -0x824d - `void set_inven_ap_cost()` +0x824d - `void set_inven_ap_cost(int cost)` 0x825c - `void reg_anim_combat_check(int enable)`\ 0x825a - `void reg_anim_destroy(object object)`\ diff --git a/artifacts/scripting/sfall opcode list.txt b/artifacts/scripting/sfall opcode list.txt index eda12054..f0d6656a 100644 --- a/artifacts/scripting/sfall opcode list.txt +++ b/artifacts/scripting/sfall opcode list.txt @@ -325,7 +325,7 @@ 0x824b - int tile_under_cursor() 0x824c - int gdialog_get_barter_mod() -0x824d - void set_inven_ap_cost() +0x824d - void set_inven_ap_cost(int cost) 0x825c - void reg_anim_combat_check(int enable) 0x825a - void reg_anim_destroy(object object) diff --git a/sfall/Modules/Scripting/Handlers/Misc.cpp b/sfall/Modules/Scripting/Handlers/Misc.cpp index caab0781..13ec9aed 100644 --- a/sfall/Modules/Scripting/Handlers/Misc.cpp +++ b/sfall/Modules/Scripting/Handlers/Misc.cpp @@ -103,6 +103,15 @@ void __declspec(naked) op_eax_available() { } } +void __declspec(naked) op_set_eax_environment() { + __asm { + _GET_ARG_INT(end); + xor eax, eax; // EAX support has been removed since 2.1a +end: + retn; + } +} + static bool IsSpecialIni(const char* str, const char* end) { const char* pos = strfind(str, &IniReader::GetConfigFile()[2]); // TODO test if (pos && pos < end) return true; @@ -245,7 +254,10 @@ void op_set_palette(OpcodeContext& ctx) { //numbers subgame functions void __declspec(naked) op_nb_create_char() { - __asm retn; + __asm { + xor edx, edx; + _J_RET_VAL_TYPE(VAR_TYPE_INT); + } } void __declspec(naked) op_hero_select_win() { // for opening the appearance selection window diff --git a/sfall/Modules/Scripting/Handlers/Misc.h b/sfall/Modules/Scripting/Handlers/Misc.h index fb379476..50b24102 100644 --- a/sfall/Modules/Scripting/Handlers/Misc.h +++ b/sfall/Modules/Scripting/Handlers/Misc.h @@ -47,6 +47,8 @@ void op_get_year(OpcodeContext&); void __declspec() op_eax_available(); +void __declspec() op_set_eax_environment(); + void op_get_ini_setting(OpcodeContext&); void op_get_ini_string(OpcodeContext&); diff --git a/sfall/Modules/Scripting/Opcodes.cpp b/sfall/Modules/Scripting/Opcodes.cpp index fca27678..081241be 100644 --- a/sfall/Modules/Scripting/Opcodes.cpp +++ b/sfall/Modules/Scripting/Opcodes.cpp @@ -342,7 +342,7 @@ void Opcodes::InitNew() { opcodes[0x1a1] = op_set_hit_chance_max; opcodes[0x1a2] = op_set_skill_max; opcodes[0x1a3] = op_eax_available; - //opcodes[0x1a4] = op_set_eax_environment; + opcodes[0x1a4] = op_set_eax_environment; opcodes[0x1a6] = op_get_viewport_x; opcodes[0x1a7] = op_get_viewport_y; opcodes[0x1a8] = op_set_viewport_x; From f985af96db6345608e9dd2127c0d73de31e6ce8a Mon Sep 17 00:00:00 2001 From: Markus Date: Thu, 21 Apr 2022 13:49:48 +0200 Subject: [PATCH 04/20] Fallout 1 worldmap sfx implementation (#434) Implemented FO1 worldmap sfx (#373) Added obj_drop call definition. --- sfall/FalloutEngine/Functions_def.h | 1 + sfall/Modules/MiscPatches.cpp | 61 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/sfall/FalloutEngine/Functions_def.h b/sfall/FalloutEngine/Functions_def.h index 8b844476..e7d9c0db 100644 --- a/sfall/FalloutEngine/Functions_def.h +++ b/sfall/FalloutEngine/Functions_def.h @@ -191,6 +191,7 @@ WRAP_WATCOM_FUNC0(long, new_obj_id) WRAP_WATCOM_FUNC2(void, obj_bound, fo::GameObject*, object, fo::BoundRect*, boundRect) // Calculates bounding box (rectangle) for a given object WRAP_WATCOM_FUNC1(long, obj_destroy, fo::GameObject*, object) WRAP_WATCOM_FUNC2(long, obj_dist, fo::GameObject*, obj_src, fo::GameObject*, obj_trg) +WRAP_WATCOM_FUNC2(void, obj_drop, fo::GameObject*, dropFrom, fo::GameObject*, objectToDrop) WRAP_WATCOM_FUNC2(long, obj_erase_object, fo::GameObject*, object, fo::BoundRect*, boundRect) WRAP_WATCOM_FUNC0(fo::GameObject*, obj_find_first) WRAP_WATCOM_FUNC0(fo::GameObject*, obj_find_next) diff --git a/sfall/Modules/MiscPatches.cpp b/sfall/Modules/MiscPatches.cpp index bd6ca2ae..c6c42fb3 100644 --- a/sfall/Modules/MiscPatches.cpp +++ b/sfall/Modules/MiscPatches.cpp @@ -774,6 +774,66 @@ static void UseWalkDistancePatch() { } } +bool wmPressed = false; +void __declspec(naked) clickedWMHotspotSound() { + __asm { + mov eax, 0x503E34 // Ib2p1xx1_1 + call fo::funcoffs::gsound_play_sfx_file_ + mov wmPressed, 1 + mov eax, dword ptr ds : [0x00672E90] + mov edx, 0x4C425C + jmp edx + } +} + +void __declspec(naked) releasedWMHotspotSound() { + __asm { + mov al, wmPressed + cmp al, 1 + jne exit_ + mov eax, 0x503E40 // Ib2lu1x1_1 + call fo::funcoffs::gsound_play_sfx_file_ + mov wmPressed, 0 + exit_: + mov eax, dword ptr ds : [0x00672E88] + mov edx, 0x4C425C + jmp edx + } +} + +void __declspec(naked) moveWMSound() { + __asm { + push eax + mov eax, 0x503E14 + call fo::funcoffs::gsound_play_sfx_file_ + pop eax + call fo::funcoffs::wmPartyInitWalking_ + mov eax, 0x4C02DF + jmp eax + } +} + +static void __declspec(naked) townmapButtonSound() { + __asm { + mov dword ptr ds : [edi + 0x672DD8], eax + mov ebx, 0x451990 // gsound_med_butt_release_ + mov edx, 0x451988 // gsound_med_butt_press_ + call fo::funcoffs::win_register_button_sound_func_ + mov eax, 0x4C4B9A + jmp eax; + } +} + + +// https://github.com/phobos2077/sfall/issues/373 +// See https://www.youtube.com/watch?v=dGZjse7uC_0&t=50m for reference on how it works in FO1. +static void Fallout1WMSoundChanges() { + MakeJump(0x4C02DA, moveWMSound); + MakeJump(0x4C4B94, townmapButtonSound); + MakeJump(0x4C4250, releasedWMHotspotSound); + MakeJump(0x4C4257, clickedWMHotspotSound); +} + static void F1EngineBehaviorPatch() { if (IniReader::GetConfigInt("Misc", "Fallout1Behavior", 0)) { dlog("Applying Fallout 1 engine behavior patch.", DL_INIT); @@ -1027,6 +1087,7 @@ void MiscPatches::init() { if (HRP::Setting::VersionIsValid) SafeWrite8(HRP::Setting::GetAddress(0x10011738), 10); } + Fallout1WMSoundChanges(); F1EngineBehaviorPatch(); DialogueFix(); AdditionalWeaponAnimsPatch(); From 9a6022d92348ae5f0987c2f6892ee1fd340214e1 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 21 Apr 2022 19:53:15 +0800 Subject: [PATCH 05/20] Moved FO1 worldmap sfx code to Interface.cpp Removed extra button release sfx for markers on the world map. (to match the exact FO1 behavior) --- sfall/FalloutEngine/FunctionOffsets_def.h | 3 +- sfall/FalloutEngine/Functions_def.h | 2 +- sfall/Modules/Interface.cpp | 34 +++++++++++++ sfall/Modules/MiscPatches.cpp | 61 ----------------------- 4 files changed, 37 insertions(+), 63 deletions(-) diff --git a/sfall/FalloutEngine/FunctionOffsets_def.h b/sfall/FalloutEngine/FunctionOffsets_def.h index ab011c34..d4eb43db 100644 --- a/sfall/FalloutEngine/FunctionOffsets_def.h +++ b/sfall/FalloutEngine/FunctionOffsets_def.h @@ -1562,6 +1562,8 @@ FUNC(gsound_init_, 0x44FC70) FUNC(gsound_internal_background_callback_, 0x451AB0) FUNC(gsound_internal_effect_callback_, 0x451AD0) FUNC(gsound_internal_speech_callback_, 0x451A90) +FUNC(gsound_lrg_butt_press_, 0x451998) +FUNC(gsound_lrg_butt_release_, 0x4519A0) FUNC(gsound_load_sound_, 0x4510DC) FUNC(gsound_load_sound_volume_, 0x45145C) FUNC(gsound_med_butt_press_, 0x451988) @@ -4088,4 +4090,3 @@ FUNC(zcfree_, 0x4E3B84) FUNC(zero_vid_mem_, 0x4CADFC) FUNC(zlibVersion_, 0x4E3B50) FUNC(zupstr_, 0x4EEFF4) - diff --git a/sfall/FalloutEngine/Functions_def.h b/sfall/FalloutEngine/Functions_def.h index e7d9c0db..3d2451fd 100644 --- a/sfall/FalloutEngine/Functions_def.h +++ b/sfall/FalloutEngine/Functions_def.h @@ -191,7 +191,7 @@ WRAP_WATCOM_FUNC0(long, new_obj_id) WRAP_WATCOM_FUNC2(void, obj_bound, fo::GameObject*, object, fo::BoundRect*, boundRect) // Calculates bounding box (rectangle) for a given object WRAP_WATCOM_FUNC1(long, obj_destroy, fo::GameObject*, object) WRAP_WATCOM_FUNC2(long, obj_dist, fo::GameObject*, obj_src, fo::GameObject*, obj_trg) -WRAP_WATCOM_FUNC2(void, obj_drop, fo::GameObject*, dropFrom, fo::GameObject*, objectToDrop) +WRAP_WATCOM_FUNC2(void, obj_drop, fo::GameObject*, source, fo::GameObject*, objectToDrop) WRAP_WATCOM_FUNC2(long, obj_erase_object, fo::GameObject*, object, fo::BoundRect*, boundRect) WRAP_WATCOM_FUNC0(fo::GameObject*, obj_find_first) WRAP_WATCOM_FUNC0(fo::GameObject*, obj_find_next) diff --git a/sfall/Modules/Interface.cpp b/sfall/Modules/Interface.cpp index 20fd21ee..e989a4c3 100644 --- a/sfall/Modules/Interface.cpp +++ b/sfall/Modules/Interface.cpp @@ -800,6 +800,37 @@ static void __declspec(naked) wmInterfaceInit_hook() { } } +static void __declspec(naked) wmWorldMap_hook() { + __asm { + push eax; + mov eax, 0x503E14; // 'ib1p1xx1' + call fo::funcoffs::gsound_play_sfx_file_; + pop eax; + jmp fo::funcoffs::wmPartyInitWalking_; + } +} + +static void __declspec(naked) wmDrawCursorStopped_hack_hotspot() { + __asm { + mov eax, 0x503E34; // 'ib2p1xx1' + call fo::funcoffs::gsound_play_sfx_file_; + mov eax, dword ptr ds:[0x672E90]; // hotspot2_pic + retn; + } +} + +static void __declspec(naked) wmTownMapInit_hack() { + __asm { + mov dword ptr ds:[edi + 0x672DD8], eax; // _wmTownMapButtonId + push eax; + mov edx, fo::funcoffs::gsound_med_butt_press_; + xor ebx, ebx; // no button release sfx + call fo::funcoffs::win_register_button_sound_func_; + pop eax; + retn; + } +} + static void WorldMapInterfacePatch() { if (IniReader::GetConfigInt("Misc", "WorldMapFontPatch", 0)) { dlog("Applying world map font patch.", DL_INIT); @@ -814,6 +845,9 @@ static void WorldMapInterfacePatch() { 0x4C2D4C, // up 0x4C2D8A // down }); + HookCall(0x4C02DA, wmWorldMap_hook); // destination marker + MakeCall(0x4C4257, wmDrawCursorStopped_hack_hotspot); // triangle markers on the world map + MakeCall(0x4C4B94, wmTownMapInit_hack, 1); // triangle markers on the town map // Fix images for up/down buttons SafeWrite32(0x4C2C0A, 199); // index of UPARWOFF.FRM diff --git a/sfall/Modules/MiscPatches.cpp b/sfall/Modules/MiscPatches.cpp index c6c42fb3..bd6ca2ae 100644 --- a/sfall/Modules/MiscPatches.cpp +++ b/sfall/Modules/MiscPatches.cpp @@ -774,66 +774,6 @@ static void UseWalkDistancePatch() { } } -bool wmPressed = false; -void __declspec(naked) clickedWMHotspotSound() { - __asm { - mov eax, 0x503E34 // Ib2p1xx1_1 - call fo::funcoffs::gsound_play_sfx_file_ - mov wmPressed, 1 - mov eax, dword ptr ds : [0x00672E90] - mov edx, 0x4C425C - jmp edx - } -} - -void __declspec(naked) releasedWMHotspotSound() { - __asm { - mov al, wmPressed - cmp al, 1 - jne exit_ - mov eax, 0x503E40 // Ib2lu1x1_1 - call fo::funcoffs::gsound_play_sfx_file_ - mov wmPressed, 0 - exit_: - mov eax, dword ptr ds : [0x00672E88] - mov edx, 0x4C425C - jmp edx - } -} - -void __declspec(naked) moveWMSound() { - __asm { - push eax - mov eax, 0x503E14 - call fo::funcoffs::gsound_play_sfx_file_ - pop eax - call fo::funcoffs::wmPartyInitWalking_ - mov eax, 0x4C02DF - jmp eax - } -} - -static void __declspec(naked) townmapButtonSound() { - __asm { - mov dword ptr ds : [edi + 0x672DD8], eax - mov ebx, 0x451990 // gsound_med_butt_release_ - mov edx, 0x451988 // gsound_med_butt_press_ - call fo::funcoffs::win_register_button_sound_func_ - mov eax, 0x4C4B9A - jmp eax; - } -} - - -// https://github.com/phobos2077/sfall/issues/373 -// See https://www.youtube.com/watch?v=dGZjse7uC_0&t=50m for reference on how it works in FO1. -static void Fallout1WMSoundChanges() { - MakeJump(0x4C02DA, moveWMSound); - MakeJump(0x4C4B94, townmapButtonSound); - MakeJump(0x4C4250, releasedWMHotspotSound); - MakeJump(0x4C4257, clickedWMHotspotSound); -} - static void F1EngineBehaviorPatch() { if (IniReader::GetConfigInt("Misc", "Fallout1Behavior", 0)) { dlog("Applying Fallout 1 engine behavior patch.", DL_INIT); @@ -1087,7 +1027,6 @@ void MiscPatches::init() { if (HRP::Setting::VersionIsValid) SafeWrite8(HRP::Setting::GetAddress(0x10011738), 10); } - Fallout1WMSoundChanges(); F1EngineBehaviorPatch(); DialogueFix(); AdditionalWeaponAnimsPatch(); From b24df4caad5b9626213625ad429aa61b7b8a3e4c Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 29 Apr 2022 08:09:24 +0800 Subject: [PATCH 06/20] Removed DivisionOperatorFix from ddraw.ini (always enabled) --- artifacts/ddraw.ini | 6 +----- sfall/Modules/BugFixes.cpp | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index d5f1f47d..d93c5549 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -1,5 +1,5 @@ ;sfall configuration settings -;v4.3.4 +;v4.3.4.1 [Main] ;Set to 1 to enable the built-in High Resolution Patch mode that is similar to the hi-res patch by Mash @@ -741,10 +741,6 @@ CreateObjectSidFix=0 ;Note that enabling this option will cause problems for existing grave scripts GraveContainersFix=0 -;Set to 1 to fix the issue with the division operator treating negative integers as unsigned -;Note: To perform the unsigned integer division, use the new 'div' operator -DivisionOperatorFix=1 - ;Set to 1 to fix the priority score calculation for choosing the best weapon for NPCs ;Note that enabling this option can affect the weapon of choice for some NPCs AIBestWeaponFix=1 diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index d2577aef..b8a19a23 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -3195,11 +3195,11 @@ void BugFixes::init() SafeWrite16(0x46A4E7, 0x04DB); // Fix for vanilla division operator treating negative integers as unsigned - if (IniReader::GetConfigInt("Misc", "DivisionOperatorFix", 1)) { + //if (IniReader::GetConfigInt("Misc", "DivisionOperatorFix", 1)) { dlog("Applying division operator fix.", DL_FIX); SafeWrite32(0x46A51D, 0xFBF79990); // xor edx, edx; div ebx > cdq; idiv ebx dlogr(" Done", DL_FIX); - } + //} //if (IniReader::GetConfigInt("Misc", "SpecialUnarmedAttacksFix", 1)) { dlog("Applying Special Unarmed Attacks fix.", DL_FIX); From 64f6647fb0a5edef10fd944f0b107b510fda83bd Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 5 May 2022 09:02:03 +0800 Subject: [PATCH 07/20] Fixed crash when the player equips an "overloaded" weapon Fixed a bug in ReloadWeaponKey that could cause a hang. (only triggerable due to the crash fix for overloaded weapons) --- sfall/Modules/Interface.cpp | 13 +++++++++++++ sfall/Modules/Inventory.cpp | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sfall/Modules/Interface.cpp b/sfall/Modules/Interface.cpp index e989a4c3..af71e236 100644 --- a/sfall/Modules/Interface.cpp +++ b/sfall/Modules/Interface.cpp @@ -999,6 +999,16 @@ static void __declspec(naked) gmouse_bk_process_hook() { } } +static void __declspec(naked) intface_update_ammo_lights_hack() { + __asm { + mov eax, 70; // 70 - full ammo bar + cmp edx, eax; + cmovg edx, eax; + mov eax, 463; // overwritten engine code + retn; + } +} + static void __declspec(naked) display_body_hook() { __asm { mov ebx, [esp + 0x60 - 0x28 + 8]; @@ -1103,6 +1113,9 @@ void Interface::init() { HookCall(0x44B737, gmouse_bk_process_hook); HookCall(0x44C018, gmouse_handle_event_hook); // replaces hack function from HRP by Mash if (HRP::Setting::VersionIsValid) HRP::IFaceBar::IFACE_BAR_MODE = (GetIntHRPValue(HRP_VAR_IFACE_BAR_MODE) != 0); + + // Fix crash when the player equips a weapon that is overloaded with ammo + MakeCall(0x45F94F, intface_update_ammo_lights_hack); } void Interface::exit() { diff --git a/sfall/Modules/Inventory.cpp b/sfall/Modules/Inventory.cpp index d378c543..ed1c7344 100644 --- a/sfall/Modules/Inventory.cpp +++ b/sfall/Modules/Inventory.cpp @@ -48,7 +48,7 @@ void InventoryKeyPressedHook(DWORD dxKey, bool pressed) { if (fo::func::item_get_type(item) == fo::ItemType::item_type_weapon) { long maxAmmo = fo::func::item_w_max_ammo(item); long curAmmo = fo::func::item_w_curr_ammo(item); - if (maxAmmo != curAmmo) { + if (curAmmo < maxAmmo) { long ¤tMode = fo::util::GetActiveItemMode(); long previusMode = currentMode; currentMode = fo::HandSlotMode::Reload; From 4ad77cebc1f459d9d786be2b67fd158571e0203a Mon Sep 17 00:00:00 2001 From: Wipe Date: Tue, 10 May 2022 11:29:25 +0200 Subject: [PATCH 08/20] Added dependabot configuration for GitHub Actions --- .github/dependabot.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..e2c55e12 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" + labels: + - "dependencies" From 2cbc026b7290bbcc44160ca63c611b8e54fc4430 Mon Sep 17 00:00:00 2001 From: Wipe Date: Tue, 10 May 2022 12:01:54 +0200 Subject: [PATCH 09/20] Dependabot will make PRs against develop branch --- .github/dependabot.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e2c55e12..365883a2 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,5 +7,6 @@ updates: directory: "/" schedule: interval: "monthly" + target-branch: "develop" labels: - "dependencies" From 7057e044d0d036e4e2c27cb9cbb01345d0fae21e Mon Sep 17 00:00:00 2001 From: NovaRain Date: Wed, 11 May 2022 21:55:50 +0800 Subject: [PATCH 10/20] Changed Stats::UpdateHPStat() to update the current HP as well Updated German translation file. --- artifacts/translations/german.ini | 2 ++ sfall/Modules/Interface.cpp | 2 +- sfall/Modules/Objects.cpp | 2 +- sfall/Modules/Stats.cpp | 32 +++++++++++++++++-------------- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/artifacts/translations/german.ini b/artifacts/translations/german.ini index 69562899..b158536d 100644 --- a/artifacts/translations/german.ini +++ b/artifacts/translations/german.ini @@ -16,6 +16,8 @@ PartyOrderAttackHuman=Ich k PartyOrderAttackCreature=::Grrrr:: PartyOrderAttackRobot=::Piep:: +HiResInfo=Diese Version von Sfall verfügt über einen integrierten High Resolution Patch-Modus, der mit den Einstellungen des Hi-Res-Patch von Mash kompatibel ist.\n\nWenn der Hi-Res Patch von Mash weiterhin verwenden soll, deaktiviere die 'HiResMode'-Option in der ddraw.ini.\nUm die Grafikverbesserungen von Sfall zu erhalten, muss der originale Hi-Res-Patch deaktiviert werden.\n\nSoll der Hi-Res-Patch von Mash deaktiviert werden? + [AppearanceMod] RaceText=Geschlecht StyleText=Stil diff --git a/sfall/Modules/Interface.cpp b/sfall/Modules/Interface.cpp index af71e236..f561b62c 100644 --- a/sfall/Modules/Interface.cpp +++ b/sfall/Modules/Interface.cpp @@ -1114,7 +1114,7 @@ void Interface::init() { HookCall(0x44C018, gmouse_handle_event_hook); // replaces hack function from HRP by Mash if (HRP::Setting::VersionIsValid) HRP::IFaceBar::IFACE_BAR_MODE = (GetIntHRPValue(HRP_VAR_IFACE_BAR_MODE) != 0); - // Fix crash when the player equips a weapon that is overloaded with ammo + // Fix crash when the player equips a weapon overloaded with ammo (ammo bar overflow) MakeCall(0x45F94F, intface_update_ammo_lights_hack); } diff --git a/sfall/Modules/Objects.cpp b/sfall/Modules/Objects.cpp index c462c775..41b53d9b 100644 --- a/sfall/Modules/Objects.cpp +++ b/sfall/Modules/Objects.cpp @@ -98,7 +98,7 @@ pickNewID: // skip PM range (18000 - 83535) } } -// Reassigns object IDs to all critters upon first loading a map and updates their max HP stat +// Reassigns object IDs to all critters upon first loading a map and updates their HP stats // TODO: for items? static void map_fix_critter_id() { long npcStartID = 4096; // 0x1000 diff --git a/sfall/Modules/Stats.cpp b/sfall/Modules/Stats.cpp index 56482ebb..5b52fa59 100644 --- a/sfall/Modules/Stats.cpp +++ b/sfall/Modules/Stats.cpp @@ -188,26 +188,30 @@ static void __declspec(naked) stat_recalc_derived_hack() { } void Stats::UpdateHPStat(fo::GameObject* critter) { - if (engineDerivedStats) return; - fo::Proto* proto; if (fo::func::proto_ptr(critter->protoId, &proto) == -1) return; - auto getStatFunc = (derivedHPwBonus) ? fo::func::stat_level : fo::func::stat_get_base; + if (!engineDerivedStats) { + auto getStatFunc = (derivedHPwBonus) ? fo::func::stat_level : fo::func::stat_get_base; - double sum = 0; - for (int stat = fo::Stat::STAT_st; stat <= fo::Stat::STAT_lu; stat++) { - sum += (getStatFunc(critter, stat) + statFormulas[fo::Stat::STAT_max_hit_points].shift[stat]) * statFormulas[fo::Stat::STAT_max_hit_points].multi[stat]; + double sum = 0; + for (int stat = fo::Stat::STAT_st; stat <= fo::Stat::STAT_lu; stat++) { + sum += (getStatFunc(critter, stat) + statFormulas[fo::Stat::STAT_max_hit_points].shift[stat]) * statFormulas[fo::Stat::STAT_max_hit_points].multi[stat]; + } + long calcStatValue = statFormulas[fo::Stat::STAT_max_hit_points].base + (int)floor(sum); + if (calcStatValue < statFormulas[fo::Stat::STAT_max_hit_points].min) calcStatValue = statFormulas[fo::Stat::STAT_max_hit_points].min; + + if (proto->critter.base.health != calcStatValue) { + fo::func::debug_printf("\nWarning: critter PID: %d, ID: %d, has an incorrect base value of the max HP stat: %d (must be %d)", + critter->protoId, critter->id, proto->critter.base.health, calcStatValue); + + proto->critter.base.health = calcStatValue; + } } - long calcStatValue = statFormulas[fo::Stat::STAT_max_hit_points].base + (int)floor(sum); - if (calcStatValue < statFormulas[fo::Stat::STAT_max_hit_points].min) calcStatValue = statFormulas[fo::Stat::STAT_max_hit_points].min; - if (proto->critter.base.health != calcStatValue) { - fo::func::debug_printf("\nWarning: critter PID: %d, ID: %d, has an incorrect base value of the max HP stat: %d (must be %d)", - critter->protoId, critter->id, proto->critter.base.health, calcStatValue); - - proto->critter.base.health = calcStatValue; - critter->critter.health = calcStatValue + proto->critter.bonus.health; + // set the current HP to match the maximum HP stat for non-party member critters + if (!fo::util::IsPartyMember(critter)) { // prevent free healing for party members when entering random encounter maps + critter->critter.health = proto->critter.base.health + proto->critter.bonus.health; } } From 7ab89200d70666ed8a3337dc67b4f988ae22048c Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 12 May 2022 21:58:03 +0800 Subject: [PATCH 11/20] Tweaked interface bar redraw in gl_partycontrol --- artifacts/mods/gl_partycontrol.int | Bin 4736 -> 4736 bytes artifacts/mods/gl_partycontrol.ssl | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/artifacts/mods/gl_partycontrol.int b/artifacts/mods/gl_partycontrol.int index 418f41f7b2ac97346ed731bee77a989152551968..2fbc6be8f5bcc8ee595f41dda31a3ae792ef5364 100644 GIT binary patch delta 271 zcmZorZBX4H%gis3nOBmQn4B74l$uhMSUy>bS#@(Db0!+&uOXv)7%ZhU~yF0 z0;nt(RJN;WvOkZC{4B5*#s(uW4KsoTs%X~aNj$cUQzl>F36_Rg!`xuh@ENR{rNIzH t^Oj7u)51{Tk0ssPj64Z>h?sO)419&yHs z$q_uNj2)Bfcw`wnCePuqW$c=Kizk?|VzM5uBxBZO4_;5+3k@t_eY2X%8l)yq;eE_l eF}Z?oKV!vY3;uerN{PuA_!}83HU|mlF#!NcvpK8) diff --git a/artifacts/mods/gl_partycontrol.ssl b/artifacts/mods/gl_partycontrol.ssl index 900fa068..d56bd3b7 100644 --- a/artifacts/mods/gl_partycontrol.ssl +++ b/artifacts/mods/gl_partycontrol.ssl @@ -60,6 +60,7 @@ procedure CombatTurn_Handler begin if (status == 1) then begin set_dude_obj(critter); + intface_redraw; //display_msg("Take control of: " + obj_name(critter)); if (critter != real_dude_obj) then begin @@ -78,7 +79,6 @@ procedure CombatTurn_Handler begin level := has_trait(TRAIT_PERK, real_dude_obj, perkID); if (level) then critter_add_trait(critter, TRAIT_PERK, perkID, level); end - intface_redraw; obj_set_light_level(critter, 100, 4); inControl := true; From 05cd041e799a6066ebc100ad81437a70542058f3 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 20 May 2022 15:36:15 +0800 Subject: [PATCH 12/20] Code edits to Stats::UpdateHPStat() --- sfall/Modules/Stats.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sfall/Modules/Stats.cpp b/sfall/Modules/Stats.cpp index 5b52fa59..76c47219 100644 --- a/sfall/Modules/Stats.cpp +++ b/sfall/Modules/Stats.cpp @@ -202,15 +202,16 @@ void Stats::UpdateHPStat(fo::GameObject* critter) { if (calcStatValue < statFormulas[fo::Stat::STAT_max_hit_points].min) calcStatValue = statFormulas[fo::Stat::STAT_max_hit_points].min; if (proto->critter.base.health != calcStatValue) { - fo::func::debug_printf("\nWarning: critter PID: %d, ID: %d, has an incorrect base value of the max HP stat: %d (must be %d)", - critter->protoId, critter->id, proto->critter.base.health, calcStatValue); + fo::func::debug_printf("\nWarning: %s (PID: %d, ID: %d) has an incorrect base value of the max HP stat: %d, adjusted to %d.", + fo::func::critter_name(critter), critter->protoId, critter->id, proto->critter.base.health, calcStatValue); proto->critter.base.health = calcStatValue; } } - // set the current HP to match the maximum HP stat for non-party member critters - if (!fo::util::IsPartyMember(critter)) { // prevent free healing for party members when entering random encounter maps + // set the current HP to match the max HP stat for non-party member critters + // (prevent full healing for party members when entering random encounter maps) + if (!fo::util::IsPartyMember(critter) && critter->critter.health > 0) { critter->critter.health = proto->critter.base.health + proto->critter.bonus.health; } } From 02b25c325fc12061a50f43b52b80b84afcb7ecf5 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sun, 22 May 2022 14:45:21 +0800 Subject: [PATCH 13/20] Simplified the fix in commit 4e3d8a6 --- sfall/Modules/BugFixes.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index b8a19a23..4c055201 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -3144,20 +3144,15 @@ noObject: } } -// returns 0 (biped) if the critter has the "barter" flag set +// returns 0 (allows adding) if the critter has the "barter" flag set or its body type is "biped" static long __fastcall BarterOverrideBodyType(fo::GameObject* critter) { - return (fo::util::GetProto(critter->protoId)->critter.critterFlags & fo::CritterFlags::Barter) - ? fo::BodyType::Biped - : fo::BodyType::Quadruped; + fo::Proto* proto; + return (fo::util::GetProto(critter->protoId, &proto) && + !(proto->critter.critterFlags & fo::CritterFlags::Barter) && proto->critter.bodyType); } static void __declspec(naked) item_add_mult_hook_body_type() { __asm { - call fo::funcoffs::critter_body_type_; - test eax, eax; - jnz notBiped; - retn; -notBiped: push edx; push ecx; call BarterOverrideBodyType; // ecx - critter From a51bd676e0953f244fc159a3462ab8fd01f9ef1e Mon Sep 17 00:00:00 2001 From: NovaRain Date: Mon, 23 May 2022 11:14:58 +0800 Subject: [PATCH 14/20] Fixed being able to push knocked down team members in combat --- sfall/Modules/BugFixes.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 4c055201..4686830a 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -3145,7 +3145,7 @@ noObject: } // returns 0 (allows adding) if the critter has the "barter" flag set or its body type is "biped" -static long __fastcall BarterOverrideBodyType(fo::GameObject* critter) { +static long __fastcall CheckBarterAndBodyType(fo::GameObject* critter) { fo::Proto* proto; return (fo::util::GetProto(critter->protoId, &proto) && !(proto->critter.critterFlags & fo::CritterFlags::Barter) && proto->critter.bodyType); @@ -3155,13 +3155,30 @@ static void __declspec(naked) item_add_mult_hook_body_type() { __asm { push edx; push ecx; - call BarterOverrideBodyType; // ecx - critter + call CheckBarterAndBodyType; // ecx - critter pop ecx; pop edx; retn; } } +// similar to critter_is_active_ function, with additional check for being knocked down in combat +static long __fastcall TargetIsActiveForPush(fo::GameObject* source, fo::GameObject* target) { + if (target->critter.IsNotActive()) return 0; + if (target->critter.damageFlags & fo::DamageFlag::DAM_KNOCKED_DOWN && fo::var::combat_state & fo::CombatStateFlag::InCombat) return 0; + return (target->critter.IsDead()) ? 0 : 1; +} + +static void __declspec(naked) action_can_be_pushed_hook() { + __asm { + push ecx; + call TargetIsActiveForPush; // ecx - source, edx - target + pop ecx; + mov edx, ebx; // restore target + retn; + } +} + void BugFixes::init() { #ifndef NDEBUG @@ -3982,6 +3999,9 @@ void BugFixes::init() // Fix for being unable to plant items on non-biped critters with the "Barter" flag set (e.g. Skynet and Goris) HookCall(0x477183, item_add_mult_hook_body_type); + + // Fix for being able to use the "Push" action on members of the player's team in combat when they are knocked down + HookCall(0x413718, action_can_be_pushed_hook); } } From fddb71e88a1f6d012802430685ec29eaf91dd1b3 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Tue, 24 May 2022 22:49:40 +0800 Subject: [PATCH 15/20] Added support for SPLASH_SCRN_TIME option to sfall HRP --- sfall/HRP/Init.cpp | 8 ++++++-- sfall/HRP/SplashScreen.cpp | 22 ++++++++++++++++++++++ sfall/HRP/SplashScreen.h | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/sfall/HRP/Init.cpp b/sfall/HRP/Init.cpp index 361bd1a4..cdc97f7b 100644 --- a/sfall/HRP/Init.cpp +++ b/sfall/HRP/Init.cpp @@ -252,7 +252,7 @@ void Setting::init(const char* exeFileName, std::string &cmdline) { MainMenuScreen::MAIN_MENU_SIZE = sf::IniReader::GetInt("MAINMENU", "MAIN_MENU_SIZE", 1, f2ResIni); SplashScreen::SPLASH_SCRN_SIZE = sf::IniReader::GetInt("STATIC_SCREENS", "SPLASH_SCRN_SIZE", 1, f2ResIni); - HelpScreen::HELP_SCRN_SIZE = sf::IniReader::GetInt("STATIC_SCREENS", "HELP_SCRN_SIZE", 0, f2ResIni); + HelpScreen::HELP_SCRN_SIZE = sf::IniReader::GetInt("STATIC_SCREENS", "HELP_SCRN_SIZE", 1, f2ResIni); DeathScreen::DEATH_SCRN_SIZE = sf::IniReader::GetInt("STATIC_SCREENS", "DEATH_SCRN_SIZE", 1, f2ResIni); SlidesScreen::END_SLIDE_SIZE = sf::IniReader::GetInt("STATIC_SCREENS", "END_SLIDE_SIZE", 1, f2ResIni); MoviesScreen::MOVIE_SIZE = sf::IniReader::GetInt("MOVIES", "MOVIE_SIZE", 1, f2ResIni); @@ -267,7 +267,7 @@ void Setting::init(const char* exeFileName, std::string &cmdline) { ViewMap::EDGE_CLIPPING_ON = (sf::IniReader::GetInt("MAPS", "EDGE_CLIPPING_ON", 1, f2ResIni) != 0); IFaceBar::IFACE_BAR_MODE = sf::IniReader::GetInt("IFACE", "IFACE_BAR_MODE", 0, f2ResIni); - IFaceBar::IFACE_BAR_SIDE_ART = sf::IniReader::GetInt("IFACE", "IFACE_BAR_SIDE_ART", 2, f2ResIni); + IFaceBar::IFACE_BAR_SIDE_ART = sf::IniReader::GetInt("IFACE", "IFACE_BAR_SIDE_ART", 1, f2ResIni); IFaceBar::IFACE_BAR_WIDTH = sf::IniReader::GetInt("IFACE", "IFACE_BAR_WIDTH", (!sf::versionCHI && SCR_WIDTH >= 800) ? 800 : 640, f2ResIni); IFaceBar::IFACE_BAR_SIDES_ORI = (sf::IniReader::GetInt("IFACE", "IFACE_BAR_SIDES_ORI", 0, f2ResIni) != 0); @@ -282,6 +282,10 @@ void Setting::init(const char* exeFileName, std::string &cmdline) { sf::WindowRender::EnableRecalculateFadeSteps(); } + int splashTime = sf::IniReader::GetInt("OTHER_SETTINGS", "SPLASH_SCRN_TIME", 0, f2ResIni); + if (splashTime > 10) splashTime = 10; + SplashScreen::SPLASH_SCRN_TIME = splashTime; + int nodes = sf::IniReader::GetInt("MAPS", "NumPathNodes", 1, f2ResIni); if (nodes > 1) game::Tilemap::SetPathMaxNodes((nodes < 20) ? nodes * 2000 : 40000); diff --git a/sfall/HRP/SplashScreen.cpp b/sfall/HRP/SplashScreen.cpp index 5d3199fc..536ea3c9 100644 --- a/sfall/HRP/SplashScreen.cpp +++ b/sfall/HRP/SplashScreen.cpp @@ -23,15 +23,20 @@ namespace sf = sfall; // 2 - image will stretch to fill the screen long SplashScreen::SPLASH_SCRN_SIZE; +long SplashScreen::SPLASH_SCRN_TIME; + static WORD rixWidth; static WORD rixHeight; static BYTE* rixBuffer; +static DWORD splashStartTime; static void __cdecl game_splash_screen_hack_scr_blit(BYTE* srcPixels, long srcWidth, long srcHeight, long srcX, long srcY, long width, long height, long x, long y) { RECT rect; long w = Setting::ScreenWidth(); long h = Setting::ScreenHeight(); + splashStartTime = GetTickCount(); + // TODO: Load an alternative 32-bit BMP image or DirectX texture // stretch texture for DirectX @@ -114,9 +119,26 @@ static void __declspec(naked) game_splash_screen_hook() { } } +static void SplashScreenTime() { + if (SplashScreen::SPLASH_SCRN_TIME >= 1) { + DWORD time = 1000 * SplashScreen::SPLASH_SCRN_TIME; + for (DWORD ticks = GetTickCount() - splashStartTime; ticks < time; ticks = GetTickCount() - splashStartTime) { + Sleep(500); + } + } +} + +static void __declspec(naked) game_init_hook_init_options_menu() { + __asm { + call SplashScreenTime; + jmp fo::funcoffs::init_options_menu_; + } +} + void SplashScreen::init() { sf::HookCall(0x4444FC, game_splash_screen_hook); sf::MakeCall(0x44451E, game_splash_screen_hack_scr_blit, 1); + sf::HookCall(0x442B0B, game_init_hook_init_options_menu); } } diff --git a/sfall/HRP/SplashScreen.h b/sfall/HRP/SplashScreen.h index 783d9d07..e96e5cfb 100644 --- a/sfall/HRP/SplashScreen.h +++ b/sfall/HRP/SplashScreen.h @@ -14,6 +14,7 @@ public: static void init(); static long SPLASH_SCRN_SIZE; + static long SPLASH_SCRN_TIME; }; } From 8bad934279801719d517329a11e3cf9976f8bf23 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Wed, 25 May 2022 21:17:06 +0800 Subject: [PATCH 16/20] Removed ComputeSprayMod from ddraw.ini Updated version number. --- artifacts/ddraw.ini | 17 +++++++---------- sfall/Modules/Animations.cpp | 2 +- sfall/Modules/BurstMods.cpp | 7 +++---- sfall/Modules/Scripting/Opcodes.cpp | 3 +-- sfall/version.h | 6 +++--- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index d93c5549..75b116f8 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -1,5 +1,5 @@ ;sfall configuration settings -;v4.3.4.1 +;v4.3.5 [Main] ;Set to 1 to enable the built-in High Resolution Patch mode that is similar to the hi-res patch by Mash @@ -588,15 +588,12 @@ SuperStimExploitFix=0 InventoryApCost=4 QuickPocketsApCostReduction=2 -;Set to 1 to enable the balanced bullet distribution formula for burst attacks -ComputeSprayMod=0 - -;These options modify the bullet distribution of burst attacks if ComputeSprayMod is 1 -;All the bullets are divided into three groups: central, left and right -;These three groups will then travel along three parallel tracks, trying to hit targets on the way -;CenterMult/Div set the ratio of how many bullets go to the central group, and remaining bullets are divided equally to left and right sides -;TargetMult/Div set the ratio of how many bullets in the central group will attack the primary target directly -;Multipliers are capped at divisor values +;These options modify the bullet distribution of burst attacks +;All the bullets are divided into three groups: center, left, and right +;These groups will then travel along three parallel tracks, trying to hit targets on the way +;CenterMult/Div set the ratio of how many bullets go to the center group, and the remaining are divided equally to the left and right sides +;TargetMult/Div set the ratio of how many bullets in the center group will attack the primary target directly +;Multiplier values are capped at divisor values ComputeSpray_CenterMult=1 ComputeSpray_CenterDiv=3 ComputeSpray_TargetMult=1 diff --git a/sfall/Modules/Animations.cpp b/sfall/Modules/Animations.cpp index 4b60f1b0..447b5331 100644 --- a/sfall/Modules/Animations.cpp +++ b/sfall/Modules/Animations.cpp @@ -567,7 +567,7 @@ static void ApplyAnimationsAtOncePatches(signed char aniMax) { } void Animations::init() { - animationLimit = IniReader::GetConfigInt("Misc", "AnimationsAtOnceLimit", 32); + animationLimit = IniReader::GetConfigInt("Misc", "AnimationsAtOnceLimit", sfall::animationLimit); if (animationLimit < 32) animationLimit = 32; if (animationLimit > 32) { if (animationLimit > 127) animationLimit = 127; diff --git a/sfall/Modules/BurstMods.cpp b/sfall/Modules/BurstMods.cpp index 7d4f7262..efd0e307 100644 --- a/sfall/Modules/BurstMods.cpp +++ b/sfall/Modules/BurstMods.cpp @@ -17,7 +17,6 @@ */ #include "..\main.h" -#include "..\Logging.h" #include "BurstMods.h" @@ -67,8 +66,8 @@ static void __declspec(naked) compute_spray_rounds_distribution() { } void BurstMods::init() { - if (IniReader::GetConfigInt("Misc", "ComputeSprayMod", 0)) { - dlog("Applying ComputeSpray changes.", DL_INIT); + //if (IniReader::GetConfigInt("Misc", "ComputeSprayMod", 0)) { + dlog("Applying ComputeSpray settings to burst attacks.", DL_INIT); compute_spray_center_mult = IniReader::GetConfigInt("Misc", "ComputeSpray_CenterMult", 1); compute_spray_center_div = IniReader::GetConfigInt("Misc", "ComputeSpray_CenterDiv", 3); if (compute_spray_center_div < 1) { @@ -87,7 +86,7 @@ void BurstMods::init() { } MakeJump(0x4234F1, compute_spray_rounds_distribution); dlogr(" Done", DL_INIT); - } + //} } } diff --git a/sfall/Modules/Scripting/Opcodes.cpp b/sfall/Modules/Scripting/Opcodes.cpp index 081241be..d87da720 100644 --- a/sfall/Modules/Scripting/Opcodes.cpp +++ b/sfall/Modules/Scripting/Opcodes.cpp @@ -211,6 +211,7 @@ static SfallOpcodeInfo opcodeInfoArray[] = { {0x267, "round", op_round, 1, true, 0, {ARG_NUMBER}}, // 0x268 RESERVED // 0x269 RESERVED + // 0x26a RESERVED {0x26b, "message_str_game", op_message_str_game, 2, true, 0, {ARG_INT, ARG_INT}}, {0x26c, "sneak_success", op_sneak_success, 0, true}, {0x26d, "tile_light", op_tile_light, 2, true, -1, {ARG_INT, ARG_INT}}, @@ -421,8 +422,6 @@ void Opcodes::InitNew() { opcodes[0x24c] = op_gdialog_get_barter_mod; opcodes[0x24d] = op_set_inven_ap_cost; - //opcodes[0x26a]=op_game_ui_redraw; - // configure default opcode handler for (int i = sfallOpcodeStart; i < opcodeCount; i++) { if (opcodes[i] == nullptr) { diff --git a/sfall/version.h b/sfall/version.h index 40790b1f..a693b455 100644 --- a/sfall/version.h +++ b/sfall/version.h @@ -24,7 +24,7 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 3 -#define VERSION_BUILD 4 -#define VERSION_REV 1 +#define VERSION_BUILD 5 +#define VERSION_REV 0 -#define VERSION_STRING "4.3.4.1" +#define VERSION_STRING "4.3.5" From e8652ca17be1ce546a216df3175a936431143f80 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Wed, 25 May 2022 21:52:24 +0800 Subject: [PATCH 17/20] Some edits to documents --- README.md | 3 +- artifacts/scripting/compiler/sslc_readme.md | 4 +- artifacts/scripting/functions.yml | 8 +- docs/index.md | 4 +- docs/optimization.md | 62 ++++++++++------ docs/sslc.md | 82 ++++++++++++--------- 6 files changed, 95 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index df7ffca3..968e5c59 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,5 @@ Original description: A set of engine modifications for the classic game Fallout --- #### Fallout Engine IDA Database -**[Download](https://www.dropbox.com/s/tm0nyx0lnk4yui0/Fallout_1_and_2_IDA68.rar "Download from Dropbox")** (comments are in Russian) +[Download for IDA Pro 6.8](https://www.dropbox.com/s/tm0nyx0lnk4yui0/Fallout_1_and_2_IDA68.rar?dl=1 "Download from Dropbox") + | [Download for IDA Pro 7.0](https://www.dropbox.com/s/61srq09pn8grfpu/Fallout_1_and_2_IDA70.rar?dl=1 "Download from Dropbox") (comments are in Russian) diff --git a/artifacts/scripting/compiler/sslc_readme.md b/artifacts/scripting/compiler/sslc_readme.md index 5a81e1bf..77aefa50 100644 --- a/artifacts/scripting/compiler/sslc_readme.md +++ b/artifacts/scripting/compiler/sslc_readme.md @@ -11,7 +11,7 @@ When compiling global or hook scripts for sfall 3.4 or below, you _must_ include This version of compiler was designed primarily for new sfall functions, but it can safely (and is recommended) to be used with non-sfall scripts as well, as long as you don't use any of the arrays syntax and any sfall script functions. -The original unmodified sslc source is over here: [http://www.teamx.ru/site_arc/utils/index.html](http://www.teamx.ru/site_arc/utils/index.html) +The original unmodified sslc source is over here: [https://teamx.ru/site_arc/utils/index.html](https://teamx.ru/site_arc/utils/index.html) ### Command line options @@ -121,7 +121,7 @@ Syntax which requires sfall for compiled scripts to be interpreted is marked by ``` __NOTE:__ If your expression starts with a constant (eg. `2 + 2`), enclose it in parentheses, otherwise compiler will be confused and give you errors. -- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers 0 to 9 and A-F are allowed in the number. The number may not have a decimal point. +- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers 0 to 9 and letters A to F are allowed in the number. The number may not have a decimal point. - new: ``` a := 0x1000; diff --git a/artifacts/scripting/functions.yml b/artifacts/scripting/functions.yml index ca305d7e..8b4a9aad 100644 --- a/artifacts/scripting/functions.yml +++ b/artifacts/scripting/functions.yml @@ -542,11 +542,13 @@ - name: Audio items: - name: eax_available - detail: int eax_available + detail: int eax_available() opcode: 0x81a3 + doc: Obsolete since sfall 2.1a. Always returns 0. - name: set_eax_environment detail: void set_eax_environment(int environment) opcode: 0x81a4 + doc: Obsolete since sfall 2.1a. Has no effect. - name: play_sfall_sound detail: int play_sfall_sound(string file, int mode) @@ -631,7 +633,7 @@ doc: Arctangent of x. Pass 1 as y (don't ask...). opcode: 0x81f1 - name: ceil - detail: int ceil(float) + detail: int ceil(float x) opcode: 0x8266 doc: Round x to the nearest integer that is not less than x. - name: ^ @@ -948,7 +950,7 @@ - name: nb_create_char detail: int nb_create_char() opcode: 0x81f6 - doc: "`nb_*` functions are reserved for the brotherhood tactical training mod, and should be avoided." + doc: "`nb_*` functions are reserved for the brotherhood tactical training mod, and should be avoided. Not implemented, always returns 0." - name: get_proto_data detail: int get_proto_data(int pid, int offset) diff --git a/docs/index.md b/docs/index.md index 44b20773..d987a729 100644 --- a/docs/index.md +++ b/docs/index.md @@ -37,5 +37,5 @@ Pay special attention to the [best practices]({{ site.baseurl }}/best-practices/ Next, proceed to discover new functions. They are categorized, use the menu to find the one you need. If you can't, check [uncategorized functions]({{ site.baseurl }}/other/) list and [sfall macros]({{ site.baseurl }}/sfall-funcx-macros/). Also, there's search at the top of the page. ## Questions and problems -* Report bugs and suggest features on [Github](https://github.com/phobos2077/sfall/issues). -* Ask questions and discuss on the [forum](https://nma-fallout.com/threads/fo2-engine-tweaks-sfall.178390/). +* Report bugs and suggest features on [Github](https://github.com/sfall-team/sfall/issues). +* Ask questions and discuss on the [forum](https://www.nma-fallout.com/threads/fo2-engine-tweaks-sfall.178390/). diff --git a/docs/optimization.md b/docs/optimization.md index 87ced15e..c51d1954 100644 --- a/docs/optimization.md +++ b/docs/optimization.md @@ -16,41 +16,48 @@ The executation speed of scripts is not typically important in an unmodded game, ## sslc -O option -The sfall build of sslc supports a -O command line option to perform an optimization pass over the generated code. This isn't a magic make-my-code-go-faster bullet; most of what it does is very limited in scope. It's primary purpose was to strip out the procedures and variables which get automatically pulled into every script that includes define.h, whether you use them or not, and to do something about the additional variables that get created by foreach loops. +The sfall build of sslc supports a `-O` command line option to perform an optimization pass over the generated code. This isn't a magic make-my-code-go-faster bullet; most of what it does is very limited in scope. It's primary purpose was to strip out the procedures and variables which get automatically pulled into every script that includes **define.h**, whether you use them or not, and to do something about the additional variables that get created by `foreach` loops. -There are several levels of optimization available: +**There are several levels of optimization available:** - `-O1` - Basic, only removes unreferenced globals variables and procedures, code itself remains untouched. - `-O2` - Full, most code optimizations are on, but only those that were tested on complex scripts. - `-O3` - Experimental, provides most efficiency, but tend to break some complex code due to bugs. -The following optimizations are performed: +**The following optimizations are performed:** - constant expression folding: if an expression depends only on values which are known at compile time, then the expression is replaced by its result. - `a:=2+2;` -> `a:=4;` + ``` + a := 2 + 2; -> a := 4; + ``` + - constant variable initialization: All variables are initialised to some value, ('0', if you don't specify anything else,) so sslc attempts to make use of that fact to remove the first assignment to a variable if the first assignment is a constant expression. ``` - variable a; -> variable a:=4; - a:=4; -> + variable a; -> variable a := 4; + a := 4; -> ``` + - constant propagation: checks for values assigned to variables which can be computed at compile time, and replaces relevent references to the symbol by the constant. The original store is not removed by this optimization. Global variables are considered for this optimization only if they are not marked import or export, and are not assigned to anywhere in the script. ``` - a:=4 -> a:=4 + a := 4; -> a := 4; foo(a); -> foo(4); ``` + - dead code removal: Checks for and removes code which cannot be reached, either because it is hidden behind a return or because the argument to an if statement can be computed at compile time. ``` - if 1 then begin -> display_msg("foo"); + if (True) then begin -> display_msg("foo"); display_msg("foo"); -> end else begin -> display_msg("bar"); -> end -> ``` -- unreferenced variable elimination: Checks for variables which are never referenced, and removes them. Also applies to global variables, as long as they are not marked for export. + +- unreferenced variable elimination: Checks for variables which are never referenced, and removes them. Also applies to global variables, as long as they are not marked for export. ``` variable i, j, k; -> variable i; - i:=1; -> i:=1; + i := 1; -> i := 1; return; -> return; ``` + - unreferenced procedure elimination: Checks for any procedures which are never called, and removes them. ``` procedure foo begin return "foo"; end -> procedure foo begin return "foo"; end @@ -59,31 +66,36 @@ The following optimizations are performed: display_msg(foo); -> end end -> ``` -- dead store removal: Removes variable assignments if the result of the variable is unused, and if the expression used to compute the value of the variable is provably free of side effects. (See 'pure' keyword) + +- dead store removal: Removes variable assignments if the result of the variable is unused, and if the expression used to compute the value of the variable is provably free of side effects. (See `pure` keyword) ``` - a:="moo"; -> a:="foo"; - a:="foo"; -> display_msg(a); + a := "moo"; -> a := "foo"; + a := "foo"; -> display_msg(a); display_msg(a); -> - a:="bar"; -> + a := "bar"; -> ``` + - store combination: Where there are two stores in a row to the same variable, the two expressions are combined. ``` var1 := var2; -> var1 := var2 + var3; - var1 += var3; -> + var1 += var3; -> ``` -- variable combination: Where usage regions of variables do not overlap, combine the variables to provide additional candidates for unreferenced variable elimination. Very useful for scripts containing multiple foreach loops, which generate 2 or 3 hidden variables each. + +- variable combination: Where usage regions of variables do not overlap, combine the variables to provide additional candidates for unreferenced variable elimination. Very useful for scripts containing multiple `foreach` loops, which generate 2 or 3 hidden variables each. ``` - a:="foo"; -> a:="foo"; + a := "foo"; -> a := "foo"; display_msg(a); -> display_msg(a); - b:="bar"; -> a:="bar"; + b := "bar"; -> a := "bar"; display_msg(b); -> display_msg(a); ``` + - namelist compression: Fallout stores the names of all file scope variables and procedures in a namelist which is saved into the .int. Any of these that are unreferenced can be removed, and the names of global variables can be modified to make them shorter. ## Writing your own code - Don't have global scripts running any more often that you need them to. Not everything needs to be run every single frame. -- Never concat constant strings with the '+' operator, as it forces the operation to be done at runtime. The compiler can cope with constant strings being placed next to each other without the need for a +, which results in far more efficient code as the combination is done at lex time. + +- Never concat constant strings with the `+` operator, as it forces the operation to be done at runtime. The compiler can cope with constant strings being placed next to each other without the need for a `+`, which results in far more efficient code as the combination is done at lex time. ``` #define GLOB_PREFIX "ts__" -> #define GLOB_PREFIX "ts__" @@ -91,15 +103,17 @@ The following optimizations are performed: set_sfall_global(GLOB_PREFIX + "foo1", 0); -> set_sfall_global(GLOB_PREFIX "foo1", 0); end -> end ``` -- Avoid function calls in while loops. function calls are expensive in comparison to variable lookups, so it's more efficient to move the function call out of the loop and store the result in a variable + +- Avoid function calls in `while` loops. Function calls are expensive in comparison to variable lookups, so it's more efficient to move the function call out of the loop and store the result in a variable. ``` - while i < len_array(array) do begin -> tmp:= len_array(array); + while i < len_array(array) do begin -> tmp := len_array(array); ... -> while i < tmp do begin end -> ... -> end ``` -- Mark functions with pure or inline where relevent. - 'pure' is a hint to the optimizer that a procedure has no side effects. (i.e. there's no way to tell that it's been called aside from its return value.) Pure procedures cannot modify global variables, or call any other procedure that isn't itself pure. Functions marked with pure can only be used in expressions (i.e. you cannot use the `call ` syntax to call them.) If there are non-pure terms in an expression, it prevents that expression being considered for dead store removal. Where no such optimizations can be performed, or if optimization is disabled, marking a procedure with pure will have no effect on the compiled code. +- Mark functions with `pure` or `inline` where relevent. - 'inline' is an instruction to the compiler to replace calls to the marked procedure with a copy of the procedures code instead of having a seperate call. inlined procedures cannot use the 'return' command, cannot be predefined, and cannot be used as part of an expression. inlining if a procedure is only going to be called once is always a win, but if there are multiple calls to a procedure you will end up bloating the size of the generated code. + * `pure` is a hint to the optimizer that a procedure has no side effects. (i.e. there's no way to tell that it's been called aside from its return value.) Pure procedures cannot modify global variables, or call any other procedure that isn't itself pure. Functions marked with pure can only be used in expressions (i.e. you cannot use the `call ` syntax to call them.) If there are non-pure terms in an expression, it prevents that expression being considered for dead store removal. Where no such optimizations can be performed, or if optimization is disabled, marking a procedure with pure will have no effect on the compiled code. + + * `inline` is an instruction to the compiler to replace calls to the marked procedure with a copy of the procedures code instead of having a seperate call. Inlined procedures cannot use the `return` command, cannot be predefined, and cannot be used as part of an expression. Inlining if a procedure is only going to be called once is always a win, but if there are multiple calls to a procedure you will end up bloating the size of the generated code. diff --git a/docs/sslc.md b/docs/sslc.md index 84720667..2bd1a479 100644 --- a/docs/sslc.md +++ b/docs/sslc.md @@ -15,13 +15,13 @@ This is a modified copy of sslc, that has a few bugfixes from the original, that Unlike the original script compiler, this has not been compiled as a dos program. When using this in place of the original compile.exe but still using p.bat, you need to either get rid of the dos4gw.exe reference from p.bat or replace the original dos4gw.exe with the one in this archive. -If you use fallout script editor, you can extract `compile.exe` and `dos4gw.exe` to its `\binary` folder, or extract them somewhere else and change your preferences in FSE to point there. FSE doesn't seem to be able to tell when errors occur when using this compiler though, so I'd recommend either using sfall's script editor instead or compiling by hand if possible. +If you use Fallout Script Editor, you can extract `compile.exe` and `dos4gw.exe` to its `\binary` folder, or extract them somewhere else and change your preferences in FSE to point there. FSE doesn't seem to be able to tell when errors occur when using this compiler though, so I'd recommend either using sfall's script editor instead or compiling by hand if possible. -When compiling global or hook scripts for sfall 3.4 or below, you _must_ include the line `procedure start;` before any `#include`s that define procedures to avoid a few weird problems. (this is no longer required starting from 3.5) +When compiling global or hook scripts for sfall 3.4 or below, you _must_ include the line `procedure start;` before any `#include` files that define procedures to avoid a few weird problems. (this is no longer required starting from 3.5) This version of compiler was designed primarily for new sfall functions, but it can safely (and is recommended) to be used with non-sfall scripts as well, as long as you don't use any of the arrays syntax and any sfall script functions. -The original unmodified sslc source is over here: [http://www.teamx.ru/eng/files/srcs/index.shtml](http://www.teamx.ru/eng/files/srcs/index.shtml). +The original unmodified sslc source is over here: [https://teamx.ru/site_arc/utils/index.html](https://teamx.ru/site_arc/utils/index.html) ## Command line options @@ -31,7 +31,9 @@ The original unmodified sslc source is over here: [http://www.teamx.ru/eng/files -b backward compatibility mode -l no logo -p preprocess source --O optimize code (full, see optimization.txt) +-P preprocess only (don't generate .int) +-F write full file paths in "#line" directives +-O optimize code (full by default, see "Optimization" page) -O set specific level of optimization (0 - off, 1 - basic, 2 - full, 3 - experimental) -d print debug messages -D output an abstract syntax tree of the program @@ -45,7 +47,7 @@ The original command line option `-w` to turn on warnings no longer has an effec ## Additional supported syntax -Syntax which requires sfall for compiled scripts to be interpreted, is marked by asterix (*). +Syntax which requires sfall for compiled scripts to be interpreted is marked by asterisk (*). - Optional arguments in user-defined procedures. You can only use constants for default values. It basically puts those constants in place of omitted arguments. @@ -73,14 +75,14 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by If `obj` is `null`, the second condition will not be checked and your script won't fail with "obj is null" error in debug.log - This also has an effect that a value of last computed argument is returned as a result of whole expressions, instead of always 0 (`false`) or 1 (`true`): + This also has an effect that a value of last computed argument is returned as a result of whole expressions, instead of always `false` (0) or `true` (1): ``` obj := false; display_msg(obj orElse "something"); // will print "something" ``` You can also use the `-s` option to enable short-circuit evaluation for all the `AND`, `OR` operators in the script. - NOTE: Be aware that it may break some old scripts because operators behavior is changed slightly. + __NOTE:__ Be aware that it may break some old scripts because operators behavior is changed slightly. - Conditional expressions (Python-inspired), also known as ternary operator: - new: @@ -94,7 +96,8 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by else X := value2; ``` -- To assign values, you can use the alternative assignment operator from C/Java instead of Pascal syntax. + +- To assign values, you can use the alternative assignment operator from **C/Java** instead of **Pascal** syntax. - new: ``` x = 5; @@ -103,7 +106,8 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by ``` x := 5; ``` -- Multiple variable declaration: Multiple variables can be declared on one line, seperated by commas. This is an alterative to the ugly begin/end block, or the bulky single variable per line style. + +- Multiple variable declaration: Multiple variables can be declared on one line, seperated by commas. This is an alterative to the ugly begin/end block, or the bulky single variable per line style. - new: ``` variable a, b, c; @@ -112,6 +116,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by ``` variable begin a; b; c; end ``` + - Variable initialization with expressions: You can now initialize local variables with complex expressions instead of constants. - new: ``` @@ -122,9 +127,9 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by variable tile; tile := tile_num(dude_obj); ``` - NOTE: if your expression starts with a constant (eg. `2+2`), enclose it in parentheses, otherwise compiler will be confused and give you errors. + __NOTE:__ If your expression starts with a constant (eg. `2 + 2`), enclose it in parentheses, otherwise compiler will be confused and give you errors. -- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers `0` to `9` and `a-f` are allowed in the number. The number may not have a decimal point. +- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers 0 to 9 and letters A to F are allowed in the number. The number may not have a decimal point. - new: ``` a := 0x1000; @@ -133,7 +138,8 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by ``` a := 4096; ``` -- Increment/decrement operators: `++` and `--` can be used as shorthand for `+=1` and `-=1` respectively. They are mearly a syntactic shorthand to improve readability, and so their use is only allowed where `+=1` would normally be allowed. + +- Increment/decrement operators: `++` and `--` can be used as shorthand for `+= 1` and `-= 1` respectively. They are mearly a syntactic shorthand to improve readability, and so their use is only allowed where `+= 1` would normally be allowed. - new: ``` a++; @@ -143,7 +149,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by a += 1; ``` -- `break` & `continue` statements: they work just like in most high-level languages. `break` jumps out of the loop. `continue` jumps right to the beginning of the next iteration (see `for` and `foreach` sections for additional details). +- `break` & `continue` statements: They work just like in most high-level languages. `break` jumps out of the loop. `continue` jumps right to the beginning of the next iteration (see `for` and `foreach` sections for additional details). - new: ``` while (i < N) begin @@ -187,18 +193,18 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by - new: ``` for (i := 0; i < 5; i++) begin - display_msg("i = "+i); + display_msg("i = " + i); end ``` - old: ``` i := 0; while (i < 5) do begin - display_msg("i = "+i); + display_msg("i = " + i); i++; end ``` - NOTE: `continue` statement in a `for` loop will recognize increment statement (third statement in parentheses) and will execute it before jumping back to the beginning of loop. This way you will not get an endless loop. + __NOTE:__ `continue` statement in a `for` loop will recognize increment statement (third statement in parentheses) and will execute it before jumping back to the beginning of loop. This way you will not get an endless loop. - `switch` statements: A shorthand way of writing big `if then else if...` blocks - new: @@ -222,7 +228,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by end ``` -- empty statements in blocks are allowed: This is just a convenience to save scripters a bit of memory. Some of the macros in the fallout headers include their own semicolons while others do not. With the original compiler you had to remember which was which, and if you got it wrong the script would not compile. Now it's always safe to include your own semicolon, even if the macro already had its own. For example, this would not compile with the original sslc, but will with the sfall edition: +- Empty statements in blocks are allowed: This is just a convenience to save scripters a bit of memory. Some of the macros in the Fallout headers include their own semicolons while others do not. With the original compiler you had to remember which was which, and if you got it wrong the script would not compile. Now it's always safe to include your own semicolon, even if the macro already had its own. For example, this would not compile with the original sslc, but will with the sfall edition: ``` #define my_macro diplay_msg("foo"); @@ -230,12 +236,9 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by my_macro; end ``` + __NOTE:__ **Does not work currently.** -- Procedure stringify operator `@`: designed to make callback-procedures a better option and allow for basic functional programming. Basically it replaces procedure names preceeded by `@` by a string constant. - Not many people know that since vanilla Fallout you can call procedures by "calling a variable" containing it's name as a string value. There was a couple of problems using this: - - optimizer wasn't aware that you are referencing a procedure, and could remove it, if you don't call it explicitly (can be solved by adding making procedure "critical") - - you couldn't see all references of a procedure from a Script Editor - - it was completely not obvious that you could do such a thing, it was a confusing syntax +- Procedure stringify operator `@`: Designed to make callback-procedures a better option and allow for basic functional programming. Basically it replaces procedure names preceeded by `@` by a string constant. - old: ``` callbackVar := "Node000"; @@ -246,7 +249,12 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by callbackVar := @Node000; callbackVar(); ``` -- *arrays: In vanilla fallout arrays had to be constructed by reserving a block of global/map variables. Since sfall 2.7, specific array targeted functions have been available, but they are fairly messy and long winded to use. The compiler provides additional syntactic shorthand for accessing and setting array variables, as well as for array creation. When declaring an array variable, put a constant integer in []'s to give the number of elements in the array. (before sfall 3.4 you had to specify size in bytes for array elements, now it's not required, see "arrays.txt" for more information) + Not many people know that since vanilla Fallout you can call procedures by "calling a variable" containing it's name as a string value. There was a couple of problems using this: + - optimizer wasn't aware that you are referencing a procedure, and could remove it, if you don't call it explicitly (can be solved by adding making procedure `critical`) + - you couldn't see all references of a procedure from a Script Editor + - it was completely not obvious that you could do such a thing, it was a confusing syntax + +- (*) **Arrays**: In vanilla Fallout, arrays had to be constructed by reserving a block of global/map variables. Since sfall 2.7, specific array targeted functions have been available, but they are fairly messy and long winded to use. The compiler provides additional syntactic shorthand for accessing and setting array variables, as well as for array creation. When declaring an array variable, put a constant integer in `[]`` to give the number of elements in the array. (before sfall 3.4 you had to specify size in bytes for array elements, now it's not required, see "Arrays" page for more information) - new: ``` procedure bingle begin @@ -267,7 +275,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by end ``` -- *array expressions: sometimes you need to construct an array of elements and you will probably want to do it in just one expression. This is now possible: +- (*) **Array expressions**: Sometimes you need to construct an array of elements and you will probably want to do it in just one expression. This is now possible: - new: ``` list := ["A", "B", "C", "D"]; @@ -280,14 +288,14 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by list[2] := "C"; list[3] := "D"; ``` - Syntax specific for associative arrays is also available. (see "arrays.txt" for full introduction to this type of arrays). + Syntax specific for associative arrays is also available. (see "Arrays" page for full introduction to this type of arrays). -- *map array expressions: +- (*) **Map array expressions**: ``` map := {5: "five", 10: "ten", 15: "fifteen", 20: "twelve"}; ``` -- * "dot" syntax to access elements of associative arrays. "dot" syntax allows to work with arrays like objects: +- (*) The dot `.` syntax to access elements of associative arrays and allow to work with arrays like objects: ``` trap.radius := 3; trap.tile := tile_num(dude_obj); @@ -296,16 +304,15 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by ``` collectionList[5].objectList[5].name += " foo"; ``` + __NOTE:__ When using incremental operators like `+=`, `*=`, `++`, `--` compiler will use additional temp variable to get an array at penultimate level in order to avoid making the same chain of `get_array` calls twice. - NOTE: when using incremental operators like `+=`, `*=`, `++`, `--` compiler will use additional temp variable to get an array at penultimate level in order to avoid making the same chain of "get_array" calls twice. - -- * `foreach` loops: A shorthand method of looping over all elements in an array. Syntax is `foreach ( in )`. +- (*) `foreach` loops: A shorthand method of looping over all elements in an array. Syntax is `foreach ( in )`. - new: ``` procedure bingle begin variable critter; foreach (critter in list_as_array(LIST_CRITTERS)) begin - display_msg(""+critter); + display_msg("" + critter); end end ``` @@ -322,6 +329,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by end end ``` + If you want an index array element (or key for "maps") at each iteration, use syntax: `foreach (: in )` ``` foreach (pid: price in itemPriceMap) begin @@ -329,15 +337,13 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by itemPrice := price; end ``` + If you want to add additional condition for continuing the loop, use syntax: `foreach ( in while )`. In this case loop will iterate over elements of an array until last element or until "while" expression is true (whatever comes first). - NOTE: just like `for` loop, "continue" statement will respect increments of a hidden counter variable, so you can safely use it inside `foreach`. - -## int2ssl note - -int2ssl by Anchorite (TeamX) is included in sfall modderspack package. It was updated to support all additional opcodes of sfall, along with some syntax features. You can use it to decompile any sfall or non-sfall script. + __NOTE:__ Just like `for` loop, `continue` statement will respect increments of a hidden counter variable, so you can safely use it inside `foreach`. ## Fixes + - `playmoviealpharect` was using the token for `playmoviealpha`, breaking both functions in the process. - `addbuttonflag` had an entry in the token table, and could be parsed, but was missing an entry in the emit list. This resulted in the compiler accepting it as a valid function, but not outputting any code for it into the compiled script. - The function `tokenize` was missing an entry in the token table, and so would not be recognised by the compiler. @@ -350,3 +356,7 @@ There are several changes in this version of sslc which may result in problems f - Missing a semicolon after a variable declaration is now a hard error. (Originally sslc would check for the semicolon, but would not complain if it was missing.) - The function `addbuttonflag` used to be recognised by the compiler, but would not emit any code into the int file. - The function `playmoviealpharect` compiled as `playmoviealpha`. + +## int2ssl note + +**int2ssl** by Anchorite (TeamX) is included in sfall modderspack package. It was updated to support all additional opcodes of sfall, along with some syntax features. You can use it to decompile any sfall or non-sfall script. From 73ec85b01dce17614924bae4d56cfa4f71175a26 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 26 May 2022 22:55:08 +0800 Subject: [PATCH 18/20] Code edits to gl_npcarmor script --- artifacts/mods/gl_npcarmor.int | Bin 5338 -> 5358 bytes artifacts/mods/gl_npcarmor.ssl | 11 ++++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/artifacts/mods/gl_npcarmor.int b/artifacts/mods/gl_npcarmor.int index 7c89d055c41e9996527da5ab20021a7427b0edc9..9f8c4ba23404195b656605d0a50ebc6b33b1cc95 100644 GIT binary patch delta 877 zcmcbm`A%~}XT1Xh0|PSy1H&Q)6u`a!D!v0nn1Qo_fq{XMfq~%+syMe9l>Z1yLn&T6 zDB~NHhEjYhAPgZ!J_rLw@^9NL#kiA+bz1{VgZAVN{05sjSY|RZYD`|l8l%OgaR6jD zV}lWxW@s>O&&W;8akT`qC z-hk>!dsKEfl z;<^AL!Tgh87ITAf1K4^lzRBk}jU^%SEDb_nS&+vevR;#=xRe|qFH(12!+x-Pt~8awT*^NW>;eXm4?w9F7Nq=Ali%^lGe%A3 z;|Gy?{PK)Fll}O2b6;yrfdsmM#bgnIOvXKv>jYXE=S*f1Y-E&}+$Jc`IBD`SL0`t6 x$zKE;n1nbcmkEI!aYCq{QDkz2urK46$;*Vp8FME86VBwk0|^F^DU%CCvH%c9&8GkW delta 918 zcmaE-c}sIbXT1&s0|PSy1H&Q)6u{mC72km(%)pt$z`(%Bz`$?@Rh(N1%6|lCR=nc(tn4H9r! zkdID4)j?yPA6@?B0dU#`#SJ(y@mEYf#;ZQLlYa{Lp~e(QauHCOtRaxexMK1ofmX(j z$r6H%j4YF93Cc6pP2MHw%UCg)L#TmC@XO>bA&|fB2=y~EOwJMZWqdGsmvA^^#AG3n QOwJRKuoh{U+#-?%0FuJkQ~&?~ diff --git a/artifacts/mods/gl_npcarmor.ssl b/artifacts/mods/gl_npcarmor.ssl index b4c0741d..7719a799 100644 --- a/artifacts/mods/gl_npcarmor.ssl +++ b/artifacts/mods/gl_npcarmor.ssl @@ -224,12 +224,13 @@ procedure update_armor_apperance begin end procedure canuseweapon_handler begin - variable critter, canWield; + variable critter, canUse; critter := get_sfall_arg; if (critter != dude_obj and get_sfall_arg_at(3)) then begin - canWield := check_weapon_change(critter, get_sfall_arg, true); - // override result - set_sfall_arg(3, canWield); - set_sfall_return(canWield); + canUse := check_weapon_change(critter, get_sfall_arg, true); + if (canUse == false) then begin + set_sfall_arg(3, 0); + set_sfall_return(0); // overrides the result of engine function. Any non-zero value allows using the weapon + end end end From 9667b522a8aa0322a616a8c19d00b5996bb18974 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 27 May 2022 13:18:09 +0800 Subject: [PATCH 19/20] Tweaked how the graphics mode setting is read Added a couple of notes to ddraw.ini. Minor code edits. --- artifacts/ddraw.ini | 4 +++- sfall/Game/items.cpp | 4 ++-- sfall/Game/tilemap.cpp | 2 +- sfall/IniReader.cpp | 14 +++++++++++--- sfall/IniReader.h | 2 ++ sfall/Modules/Graphics.cpp | 6 ++++-- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 75b116f8..f8dc30f7 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -4,6 +4,7 @@ [Main] ;Set to 1 to enable the built-in High Resolution Patch mode that is similar to the hi-res patch by Mash ;The required settings will be read from the f2_res.ini configuration file of the original hi-res patch +;This option is always read from the main ini file (i.e. ddraw.ini) HiResMode=1 ;Set to 1 if you want to use command line arguments to tell sfall to use another ini file @@ -57,6 +58,7 @@ SpeedMultiInitial=100 ;Set to 6 for DX9 fullscreen windowed (the resolution in f2_res.ini should be set to the same aspect ratio as your desktop resolution) ;A DX9 mode is required for any graphics related script extender functions to work (i.e. fullscreen shaders) ;Modes 1, 2 and 3 are no longer supported +;This option will always be read from the main ini file (i.e. ddraw.ini) when using the hi-res patch by Mash Mode=0 ;If using a DX9 mode, this changes the resolution @@ -821,7 +823,7 @@ GlobalScriptPaths=scripts\gl*.int,scripts\sfall\gl*.int ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX [Debugging] ;Extra sfall configuration settings that can be used by modders -;This section is not effected by the 'UseCommandLine' option. It will always be read from the main ini +;This section is not affected by the 'UseCommandLine' option. It will always be read from the main ini file (i.e. ddraw.ini) ;Set to 1 to enable sfall debugging mode Enable=0 diff --git a/sfall/Game/items.cpp b/sfall/Game/items.cpp index 53f2a05a..dc0754ea 100644 --- a/sfall/Game/items.cpp +++ b/sfall/Game/items.cpp @@ -232,7 +232,7 @@ long __fastcall Items::item_w_mp_cost(fo::GameObject* source, fo::AttackType hit ); } -static void __declspec(naked) item_w_mp_cost_hack() { +static void __declspec(naked) item_w_mp_cost_replacement() { using namespace fo; __asm { push ebx; // isCalled @@ -248,7 +248,7 @@ void Items::init() { sf::HookCall(0x429A08, ai_search_inven_weap_hook); // Replace the item_w_mp_cost_ function with the sfall implementation - sf::MakeJump(fo::funcoffs::item_w_mp_cost_ + 1, item_w_mp_cost_hack); // 0x478B25 + sf::MakeJump(fo::funcoffs::item_w_mp_cost_ + 1, item_w_mp_cost_replacement); // 0x478B25 fastShotTweak = sf::IniReader::GetConfigInt("Misc", "FastShotFix", 0); } diff --git a/sfall/Game/tilemap.cpp b/sfall/Game/tilemap.cpp index 63ccc89b..620e1fef 100644 --- a/sfall/Game/tilemap.cpp +++ b/sfall/Game/tilemap.cpp @@ -178,7 +178,7 @@ long __fastcall Tilemap::tile_num_beyond(long sourceTile, long targetTile, long } static void __declspec(naked) tile_num_beyond_replacement() { - __asm { //push ecx; + __asm { // push ecx; push ebx; mov ecx, eax; call Tilemap::tile_num_beyond; diff --git a/sfall/IniReader.cpp b/sfall/IniReader.cpp index 7d8d6957..d46d22d0 100644 --- a/sfall/IniReader.cpp +++ b/sfall/IniReader.cpp @@ -50,6 +50,12 @@ static std::vector getList(const char* section, const char* setting return list; } +static int setInt(const char* section, const char* setting, int value, const char* iniFile) { + char buf[33]; + _itoa_s(value, buf, 33, 10); + return WritePrivateProfileStringA(section, setting, buf, iniFile); +} + const char* IniReader::GetConfigFile() { return ini; } @@ -107,9 +113,11 @@ std::vector IniReader::GetList(const char* section, const char* set } int IniReader::SetConfigInt(const char* section, const char* setting, int value) { - char buf[33]; - _itoa_s(value, buf, 33, 10); - return WritePrivateProfileStringA(section, setting, buf, ini); + return setInt(section, setting, value, ini); +} + +int IniReader::SetDefaultConfigInt(const char* section, const char* setting, int value) { + return setInt(section, setting, value, ddrawIni); } int IniReader::SetDefaultConfigString(const char* section, const char* setting, const char* value) { diff --git a/sfall/IniReader.h b/sfall/IniReader.h index eb3b0f89..56324041 100644 --- a/sfall/IniReader.h +++ b/sfall/IniReader.h @@ -65,6 +65,8 @@ public: static int SetConfigInt(const char* section, const char* setting, int value); + static int SetDefaultConfigInt(const char* section, const char* setting, int value); + static int SetDefaultConfigString(const char* section, const char* setting, const char* value); }; diff --git a/sfall/Modules/Graphics.cpp b/sfall/Modules/Graphics.cpp index ecf42161..a9e000c0 100644 --- a/sfall/Modules/Graphics.cpp +++ b/sfall/Modules/Graphics.cpp @@ -1246,7 +1246,9 @@ static __declspec(naked) void dump_screen_hack_replacement() { } void Graphics::init() { - int gMode = IniReader::GetConfigInt("Graphics", "Mode", 0); + int gMode = (HRP::Setting::ExternalEnabled()) // avoid mode mismatch between ddraw.ini and another ini file + ? IniReader::GetIntDefaultConfig("Graphics", "Mode", 0) + : IniReader::GetConfigInt("Graphics", "Mode", 0); if (gMode >= 4) Graphics::mode = gMode; if (Graphics::mode < 0 || Graphics::mode > 6) { @@ -1270,7 +1272,7 @@ void Graphics::init() { SafeWrite8(0x50FB6B, '2'); // Set call DirectDrawCreate2 HookCall(0x44260C, game_init_hook); - MakeJump(fo::funcoffs::GNW95_SetPaletteEntries_ + 1, GNW95_SetPaletteEntries_replacement); // 0x4CB311 + MakeJump(fo::funcoffs::GNW95_SetPaletteEntries_ + 1, GNW95_SetPaletteEntries_replacement); // 0x4CB310 MakeJump(fo::funcoffs::GNW95_SetPalette_, GNW95_SetPalette_replacement); // 0x4CB568 // Replace the screenshot saving implementation for sfall DirectX 9 From a4230c3bad7890f90d040a0d08e96aae0f00eb77 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 28 May 2022 18:40:11 +0800 Subject: [PATCH 20/20] Added a function to EngineUtils.cpp Minor edits to ddraw.ini. --- artifacts/ddraw.ini | 6 +++--- sfall/FalloutEngine/EngineUtils.cpp | 15 +++++++++++++++ sfall/FalloutEngine/EngineUtils.h | 3 +++ sfall/Modules/BugFixes.cpp | 4 ++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index f8dc30f7..780f6ca7 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -4,7 +4,7 @@ [Main] ;Set to 1 to enable the built-in High Resolution Patch mode that is similar to the hi-res patch by Mash ;The required settings will be read from the f2_res.ini configuration file of the original hi-res patch -;This option is always read from the main ini file (i.e. ddraw.ini) +;This option is always read from the main ddraw.ini file HiResMode=1 ;Set to 1 if you want to use command line arguments to tell sfall to use another ini file @@ -58,7 +58,7 @@ SpeedMultiInitial=100 ;Set to 6 for DX9 fullscreen windowed (the resolution in f2_res.ini should be set to the same aspect ratio as your desktop resolution) ;A DX9 mode is required for any graphics related script extender functions to work (i.e. fullscreen shaders) ;Modes 1, 2 and 3 are no longer supported -;This option will always be read from the main ini file (i.e. ddraw.ini) when using the hi-res patch by Mash +;This option will always be read from the main ddraw.ini file when using the hi-res patch by Mash Mode=0 ;If using a DX9 mode, this changes the resolution @@ -823,7 +823,7 @@ GlobalScriptPaths=scripts\gl*.int,scripts\sfall\gl*.int ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX [Debugging] ;Extra sfall configuration settings that can be used by modders -;This section is not affected by the 'UseCommandLine' option. It will always be read from the main ini file (i.e. ddraw.ini) +;This section is not affected by the 'UseCommandLine' option. It will always be read from the main ddraw.ini file ;Set to 1 to enable sfall debugging mode Enable=0 diff --git a/sfall/FalloutEngine/EngineUtils.cpp b/sfall/FalloutEngine/EngineUtils.cpp index 64c151e7..0057a130 100644 --- a/sfall/FalloutEngine/EngineUtils.cpp +++ b/sfall/FalloutEngine/EngineUtils.cpp @@ -214,6 +214,21 @@ fo::AttackSubType GetWeaponType(DWORD weaponFlag) { return (type < 9) ? weapon_types[type] : fo::AttackSubType::NONE; } +// Returns the distance a critter can move in combat based on current APs +long __fastcall GetCombatMoveDistance(fo::GameObject* critter, long freeMove) { + freeMove += critter->critter.movePoints; + long flags = critter->critter.damageFlags & (fo::DamageFlag::DAM_CRIP_LEG_LEFT | fo::DamageFlag::DAM_CRIP_LEG_RIGHT); + + // both legs crippled (8 AP per hex) + if (flags == (fo::DamageFlag::DAM_CRIP_LEG_LEFT | fo::DamageFlag::DAM_CRIP_LEG_RIGHT)) return (freeMove / 8); + + // not crippled + if (flags == 0) return freeMove; + + // one leg crippled (4 AP per hex) + return (freeMove / 4); +} + long ObjIsOpenable(fo::GameObject* object) { long result = 0; if (fo::func::obj_is_openable(object)) { diff --git a/sfall/FalloutEngine/EngineUtils.h b/sfall/FalloutEngine/EngineUtils.h index 72e23fb0..042cb377 100644 --- a/sfall/FalloutEngine/EngineUtils.h +++ b/sfall/FalloutEngine/EngineUtils.h @@ -101,6 +101,9 @@ long GetCurrentAttackMode(); fo::AttackSubType GetWeaponType(DWORD weaponFlag); +// Returns the distance a critter can move in combat based on current APs +long __fastcall GetCombatMoveDistance(fo::GameObject* critter, long freeMove); + long ObjIsOpenable(fo::GameObject* object); bool HeroIsFemale(); diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 4686830a..700393c7 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -3151,7 +3151,7 @@ static long __fastcall CheckBarterAndBodyType(fo::GameObject* critter) { !(proto->critter.critterFlags & fo::CritterFlags::Barter) && proto->critter.bodyType); } -static void __declspec(naked) item_add_mult_hook_body_type() { +static void __declspec(naked) item_add_mult_hook() { __asm { push edx; push ecx; @@ -3998,7 +3998,7 @@ void BugFixes::init() SafeWrite8(0x4B039F, 20); // text_object_create_ (was 19) // Fix for being unable to plant items on non-biped critters with the "Barter" flag set (e.g. Skynet and Goris) - HookCall(0x477183, item_add_mult_hook_body_type); + HookCall(0x477183, item_add_mult_hook); // Fix for being able to use the "Push" action on members of the player's team in combat when they are knocked down HookCall(0x413718, action_can_be_pushed_hook);