From 477ff9668c8ab3e907c25815a465eaa7e0988f4b Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 22 Aug 2019 13:12:32 +0800 Subject: [PATCH] Added a new argument to HOOK_ADJUSTFID. Fixed incorrect FRM being displayed for opened bag/backpack in the inventory when Hero Appearance Mod is enabled (#262) Fixed MainMenuFontColour not changing the font color for the copyright text on the main menu (#261) Code correction in main.cpp. --- artifacts/ddraw.ini | 2 +- artifacts/scripting/hookscripts.txt | 3 ++- sfall/Modules/HeroAppearance.cpp | 18 +++++++-------- sfall/Modules/HookScripts/InventoryHs.cpp | 5 ++-- sfall/Modules/Interface.cpp | 4 ---- sfall/Modules/MainMenu.cpp | 28 ++++++++++++----------- sfall/main.cpp | 15 ++++++++---- sfall/main.h | 1 + 8 files changed, 41 insertions(+), 35 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index a61cc0dd..095f2eec 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -503,7 +503,7 @@ RemoveCriticalTimelimits=0 ;Set to 1 to enable party members with level 6 protos to reach level 6 NPCStage6Fix=0 -;Change the colour of the font used on the main menu for the Fallout/sfall version number +;Change the colour of the font used on the main menu for the Fallout/sfall version number and copyright text ;It's the last byte ('3c' by default) that picks the colour used. The first byte supplies additional flags ;MainMenuFontColour=0x0600003c diff --git a/artifacts/scripting/hookscripts.txt b/artifacts/scripting/hookscripts.txt index 42d29c69..d7da9086 100644 --- a/artifacts/scripting/hookscripts.txt +++ b/artifacts/scripting/hookscripts.txt @@ -452,7 +452,8 @@ Also happens on other screens, like barter. NOTE: FID has following format: 0x0ABBCDDD, where A is object type, BB - animation code (always 0 in this case), C - weapon code, DDD - FRM index in LST file. -int arg1 - the vanilla fid calculated by the engine according to critter base FID and armor/weapon being used +int arg1 - the vanilla FID calculated by the engine according to critter base FID and armor/weapon being used +int arg2 - the modified FID calculated by the internal sfall code (like Hero Appearance Mod) int ret1 - overrides the calculated FID with provided value diff --git a/sfall/Modules/HeroAppearance.cpp b/sfall/Modules/HeroAppearance.cpp index c5baea0d..93e176d8 100644 --- a/sfall/Modules/HeroAppearance.cpp +++ b/sfall/Modules/HeroAppearance.cpp @@ -63,7 +63,7 @@ typedef struct LineNode { } } LineNode; -/////////////////////////////////////////////////////////////////TEXT FUNCTIONS//////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////TEXT FUNCTIONS////////////////////////////////////////////////////////////////////// static void SetFont(long ref) { fo::func::text_font(ref); @@ -141,7 +141,7 @@ static void DeleteWordWrapList(LineNode *CurrentLine) { } } -/////////////////////////////////////////////////////////////////DAT FUNCTIONS//////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////DAT FUNCTIONS/////////////////////////////////////////////////////////////////////// static void* LoadDat(char*fileName) { return fo::func::dbase_open(fileName); @@ -151,7 +151,7 @@ static void UnloadDat(void *dat) { fo::func::dbase_close(dat); } -/////////////////////////////////////////////////////////////////OTHER FUNCTIONS//////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////OTHER FUNCTIONS///////////////////////////////////////////////////////////////////// static DWORD BuildFrmId(DWORD lstRef, DWORD lstNum) { return fo::func::art_id(lstRef, lstNum, 0, 0, 0); @@ -164,7 +164,7 @@ static void PlayAcm(char *acmName) { } } -/////////////////////////////////////////////////////////////////APP MOD FUNCTIONS//////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////APP MOD FUNCTIONS/////////////////////////////////////////////////////////////////// static char GetSex() { return (fo::HeroIsFemale()) ? 'F' : 'M'; @@ -275,7 +275,7 @@ static void __declspec(naked) AdjustHeroBaseArt() { // adjust armor art if num below hero art range static void AdjustHeroArmorArt(DWORD fid) { - if (!PartyControl::IsNpcControlled()) { + if ((fid & 0xF000000) == (fo::OBJ_TYPE_CRITTER << 24) && !PartyControl::IsNpcControlled()) { DWORD fidBase = fid & 0xFFF; if (fidBase <= critterListSize) { fo::var::i_fid += critterListSize; @@ -349,7 +349,7 @@ static long _stdcall AddHeroCritNames() { // art_init_ return critterArt.total; } -///////////////////////////////////////////////////////////////GRAPHICS HERO FUNCTIONS////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////GRAPHICS HERO FUNCTIONS/////////////////////////////////////////////////////////////// static void DrawPC() { fo::RedrawObject(fo::var::obj_dude); @@ -479,7 +479,7 @@ endFunc: } } -/////////////////////////////////////////////////////////////////INTERFACE FUNCTIONS/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////INTERFACE FUNCTIONS///////////////////////////////////////////////////////////////// static void sub_draw(long subWidth, long subHeight, long fromWidth, long fromHeight, long fromX, long fromY, BYTE *fromBuff, long toWidth, long toHeight, long toX, long toY, BYTE *toBuff, int maskRef) { @@ -1263,7 +1263,7 @@ static void __declspec(naked) CharScrnEnd() { } } -//////////////////////////////////////////////////////////////////////FIX FUNCTIONS//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////FIX FUNCTIONS////////////////////////////////////////////////////////////////// // Adjust PC SFX acm name. Skip Underscore char at the start of PC App Name static void __declspec(naked) FixPcSFX() { @@ -1323,7 +1323,7 @@ skip: } } -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Load Appearance data from GCD file static void __fastcall LoadGCDAppearance(fo::DbFile* fileStream) { diff --git a/sfall/Modules/HookScripts/InventoryHs.cpp b/sfall/Modules/HookScripts/InventoryHs.cpp index bf8ff054..6a54abe9 100644 --- a/sfall/Modules/HookScripts/InventoryHs.cpp +++ b/sfall/Modules/HookScripts/InventoryHs.cpp @@ -432,8 +432,9 @@ void AdjustFidHook(DWORD vanillaFid) { if (!HookScripts::HookHasScript(HOOK_ADJUSTFID)) return; BeginHook(); - argCount = 1; + argCount = 2; args[0] = vanillaFid; + args[1] = fo::var::i_fid; // modified FID by sfall code RunHookScript(HOOK_ADJUSTFID); if (cRet > 0) { fo::var::i_fid = rets[0]; @@ -502,7 +503,7 @@ void InitInventoryHookScripts() { LoadHookScript("hs_invenwield", HOOK_INVENWIELD); LoadHookScript("hs_adjustfid", HOOK_ADJUSTFID); - Inventory::OnAdjustFid() += AdjustFidHook; + Inventory::OnAdjustFid() += AdjustFidHook; // should be registered last } } diff --git a/sfall/Modules/Interface.cpp b/sfall/Modules/Interface.cpp index ab08acbb..bba7f6fd 100644 --- a/sfall/Modules/Interface.cpp +++ b/sfall/Modules/Interface.cpp @@ -26,8 +26,6 @@ namespace sfall { -bool hrpIsEnabled = false; - static BYTE movePointBackground[16 * 9 * 5]; static fo::UnlistedFrm* ifaceFrm = nullptr; @@ -447,8 +445,6 @@ static void WorldMapInterfacePatch() { } void Interface::init() { - hrpIsEnabled = (*(DWORD*)0x4E4480 != 0x278805C7); // check if HRP is enabled - if (GetConfigInt("Interface", "ActionPointsBar", 0)) { ActionPointsBarPatch(); if (hrpIsEnabled) LoadGameHook::OnAfterGameInit() += APBarRectPatch; diff --git a/sfall/Modules/MainMenu.cpp b/sfall/Modules/MainMenu.cpp index b9ad291b..82a2bdf0 100644 --- a/sfall/Modules/MainMenu.cpp +++ b/sfall/Modules/MainMenu.cpp @@ -25,9 +25,17 @@ namespace sfall { +#ifdef NDEBUG +static const char* VerString1 = "SFALL " VERSION_STRING; +#else +static const char* VerString1 = "SFALL " VERSION_STRING " Debug Build"; +#endif + static DWORD MainMenuYOffset; static DWORD MainMenuTextOffset; +static long OverrideColour; + static const DWORD MainMenuButtonYHookRet = 0x48184A; static void __declspec(naked) MainMenuButtonYHook() { __asm { @@ -45,23 +53,16 @@ static void __declspec(naked) MainMenuTextYHook() { } } -#ifdef NDEBUG -static const char* VerString1 = "SFALL " VERSION_STRING; -#else -static const char* VerString1 = "SFALL " VERSION_STRING " Debug Build"; -#endif - -static DWORD OverrideColour; static void __declspec(naked) FontColour() { __asm { cmp OverrideColour, 0; - je skip; - mov eax, OverrideColour; - retn; -skip: + jg override; movzx eax, byte ptr ds:[0x6A8B33]; or eax, 0x6000000; retn; +override: + mov eax, OverrideColour; + retn; } } @@ -121,8 +122,9 @@ void MainMenu::init() { MakeJump(0x4817AB, MainMenuTextHook); OverrideColour = GetConfigInt("Misc", "MainMenuFontColour", 0); - if (OverrideColour) { - MakeCall(0x48174C, FontColour); + if (OverrideColour > 0) { + OverrideColour |= 0x6000000; + SafeWrite32(0x481748, (DWORD)&OverrideColour); } } diff --git a/sfall/main.cpp b/sfall/main.cpp index e4cf2cdb..6ba8ebac 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -86,10 +86,12 @@ namespace sfall { bool isDebug = false; +bool hrpIsEnabled = false; const char ddrawIni[] = ".\\ddraw.ini"; static char ini[65] = ".\\"; static char translationIni[65]; + DWORD modifiedIni; unsigned int GetConfigInt(const char* section, const char* setting, int defaultValue) { @@ -144,6 +146,8 @@ static void InitModules() { manager.add(); manager.add(); manager.add(); + manager.add(); + manager.add(); manager.add(); manager.add(); manager.add(); @@ -163,7 +167,6 @@ static void InitModules() { manager.add(); manager.add(); manager.add(); - manager.add(); manager.add(); // should be loaded before PartyControl manager.add(); manager.add(); @@ -172,7 +175,6 @@ static void InitModules() { manager.add(); manager.add(); manager.add(); - manager.add(); // manager.add(); manager.add(); @@ -271,23 +273,26 @@ inline void SfallInit() { } } - if (cmdlineexists && strlen(cmdline)) { + if (cmdlineexists && *cmdline != 0) { HANDLE h = CreateFileA(cmdline, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); if (h != INVALID_HANDLE_VALUE) { CloseHandle(h); strcat_s(ini, cmdline); } else { MessageBox(0, "You gave a command line argument to fallout, but it couldn't be matched to a file\n" \ - "Using default ddraw.ini instead", "Warning", MB_TASKMODAL); - strcpy_s(ini, ::sfall::ddrawIni); + "Using default ddraw.ini instead", "Warning", MB_TASKMODAL); + goto defaultIni; } } else { +defaultIni: strcpy_s(ini, ::sfall::ddrawIni); } GetConfigString("Main", "TranslationsINI", ".\\Translations.ini", translationIni, 65); modifiedIni = GetConfigInt("Main", "ModifiedIni", 0); + hrpIsEnabled = (*(DWORD*)0x4E4480 != 0x278805C7); // check if HRP is enabled + InitModules(); } diff --git a/sfall/main.h b/sfall/main.h index ba68c901..7cf9bc53 100644 --- a/sfall/main.h +++ b/sfall/main.h @@ -92,5 +92,6 @@ size_t Translate(const char* section, const char* setting, const char* defaultVa extern const char ddrawIni[]; extern DWORD modifiedIni; +extern bool hrpIsEnabled; }