From 2bd8a6223d9de6f809734fe0954bc7029253d96c Mon Sep 17 00:00:00 2001 From: NovaRain Date: Tue, 20 Aug 2019 16:47:37 +0800 Subject: [PATCH] Added OverrideCriticalFile option for specifying alternative crit file Added code for preparing clearing map_update_event in queue. Fixed a crash bug in message_str_game function when passing a negative fileId value. Corrected/edited some code. --- artifacts/ddraw.ini | 6 ++++-- sfall/Criticals.cpp | 14 ++++++++----- sfall/FalloutEngine.cpp | 1 + sfall/FalloutEngine.h | 2 ++ sfall/ScriptExtender.cpp | 21 ++++++++++++++----- sfall/ScriptOps/ScriptUtils.hpp | 37 +++++++++++++++++---------------- sfall/Stats.cpp | 2 +- sfall/main.cpp | 8 +++---- sfall/skills.cpp | 4 ++-- 9 files changed, 57 insertions(+), 38 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 4e1471d2..ee8feff4 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -319,7 +319,7 @@ OverrideArtCacheSize=0 ;Set to 2 to block all saving in combat SaveInCombatFix=1 -;Point at an ini file containing elevator data +;Point to an ini file containing elevator data ;ElevatorsFile=Elevators.ini ;Uncomment and set a comma delimited list of numbers to use a custom xp table. @@ -347,6 +347,8 @@ AdditionalWeaponAnims=1 ;If the ExtraKillTypes option is enabled, this should be set to 3, with containing entries for any new types ;Must be non-zero to use the edit/get/reset_critical script functions OverrideCriticalTable=2 +;To change the path and filename of the critical table file, uncomment the next line +;OverrideCriticalFile=CriticalOverrides.ini ;Set to 1 to get notification of karma changes in the notification window DisplayKarmaChanges=0 @@ -489,7 +491,7 @@ FastShotFix=1 BoostScriptDialogLimit=0 ;Allows you to edit the skill tables -;Point the next line at an ini file containing the replacement skill data +;Point the next line to an ini file containing the replacement skill data ;SkillsFile=Skills.ini ;To change the relationship between SPECIAL stats and derived stats, uncomment the next line diff --git a/sfall/Criticals.cpp b/sfall/Criticals.cpp index bfef6f19..9463d923 100644 --- a/sfall/Criticals.cpp +++ b/sfall/Criticals.cpp @@ -23,7 +23,8 @@ #include "FalloutEngine.h" #include "Logging.h" -static const char* CritTableFile = ".\\CriticalOverrides.ini"; +static std::string critTableFile(".\\"); + static const DWORD CritTableCount = 2 * 19 + 1; // Number of species in new critical table //static const DWORD origCritTableSize = 6 * 9 * 20; // Number of entries in original table static const DWORD CritTableSize = 6 * 9 * CritTableCount; // Number of entries in new critical table @@ -99,7 +100,7 @@ void CritLoad() { int slot1 = crit + part * 6 + critter * 9 * 6; int slot2 = crit + part * 6 + ((critter == 19) ? 38 : critter) * 9 * 6; for (int i = 0; i < 7; i++) { - baseCritTable[slot2].values[i] = GetPrivateProfileIntA(section, CritNames[i], defaultTable[slot1].values[i], CritTableFile); + baseCritTable[slot2].values[i] = GetPrivateProfileIntA(section, CritNames[i], defaultTable[slot1].values[i], critTableFile.c_str()); if (isDebug) { char logmsg[256]; if (baseCritTable[slot2].values[i] != defaultTable[slot1].values[i]) { @@ -122,11 +123,11 @@ void CritLoad() { for (int critter = 0; critter < CritTableCount; critter++) { sprintf_s(buf, "c_%02d", critter); int all; - if (!(all = GetPrivateProfileIntA(buf, "Enabled", 0, CritTableFile))) continue; + if (!(all = GetPrivateProfileIntA(buf, "Enabled", 0, critTableFile.c_str()))) continue; for (int part = 0; part < 9; part++) { if (all < 2) { sprintf_s(buf2, "Part_%d", part); - if (!GetPrivateProfileIntA(buf, buf2, 0, CritTableFile)) continue; + if (!GetPrivateProfileIntA(buf, buf2, 0, critTableFile.c_str())) continue; } sprintf_s(buf2, "c_%02d_%d", critter, part); @@ -134,7 +135,7 @@ void CritLoad() { int slot = crit + part * 6 + critter * 9 * 6; for (int i = 0; i < 7; i++) { sprintf_s(buf3, "e%d_%s", crit, CritNames[i]); - baseCritTable[slot].values[i] = GetPrivateProfileIntA(buf2, buf3, baseCritTable[slot].values[i], CritTableFile); + baseCritTable[slot].values[i] = GetPrivateProfileIntA(buf2, buf3, baseCritTable[slot].values[i], critTableFile.c_str()); } } } @@ -273,6 +274,9 @@ void CritInit() { mode = GetPrivateProfileIntA("Misc", "OverrideCriticalTable", 2, ini); if (mode < 0 || mode > 3) mode = 0; if (mode) { + char critFile[MAX_PATH]; + GetPrivateProfileStringA("Misc", "OverrideCriticalFile", "CriticalOverrides.ini", critFile, MAX_PATH, ini); + critTableFile += critFile; CriticalTableOverride(); } diff --git a/sfall/FalloutEngine.cpp b/sfall/FalloutEngine.cpp index fcdb1007..86b677db 100644 --- a/sfall/FalloutEngine.cpp +++ b/sfall/FalloutEngine.cpp @@ -163,6 +163,7 @@ DWORD* ptr_pipmesg = reinterpret_cast(_pipmesg); DWORD* ptr_preload_list_index = reinterpret_cast(_preload_list_index); DWORD* ptr_procTableStrs = reinterpret_cast(_procTableStrs); // table of procId (from define.h) => procName map DWORD* ptr_proto_main_msg_file = reinterpret_cast(_proto_main_msg_file); +DWORD* ptr_proto_msg_files = reinterpret_cast(_proto_msg_files); DWORD* ptr_ptable = reinterpret_cast(_ptable); DWORD* ptr_pud = reinterpret_cast(_pud); DWORD* ptr_queue = reinterpret_cast(_queue); diff --git a/sfall/FalloutEngine.h b/sfall/FalloutEngine.h index a0dce1aa..08be3e63 100644 --- a/sfall/FalloutEngine.h +++ b/sfall/FalloutEngine.h @@ -195,6 +195,7 @@ #define _preload_list_index 0x519640 #define _procTableStrs 0x51C758 // table of procId (from define.h) => procName map #define _proto_main_msg_file 0x6647FC +#define _proto_msg_files 0x6647AC #define _ptable 0x59E934 #define _pud 0x59E960 #define _quest_count 0x51C12C @@ -404,6 +405,7 @@ extern DWORD* ptr_pipmesg; extern DWORD* ptr_preload_list_index; extern DWORD* ptr_procTableStrs; // table of procId (from define.h) => procName map extern DWORD* ptr_proto_main_msg_file; +extern DWORD* ptr_proto_msg_files; extern DWORD* ptr_ptable; extern DWORD* ptr_pud; extern DWORD* ptr_queue; diff --git a/sfall/ScriptExtender.cpp b/sfall/ScriptExtender.cpp index 65ab407b..cd3ec2a9 100644 --- a/sfall/ScriptExtender.cpp +++ b/sfall/ScriptExtender.cpp @@ -107,7 +107,7 @@ public: return _type == DATATYPE_STR; } - DWORD rawValue() const { + unsigned long rawValue() const { return _val.dw; } @@ -1354,7 +1354,15 @@ static void __declspec(naked) map_save_in_game_hook() { jmp game_time_; } } - +/* +static void ClearEventUpdateMapProc() { + __asm { + mov eax, map_update_event; // type + xor edx, edx; // func + call queue_clear_type_; + } +} +*/ void ScriptExtenderSetup() { toggleHighlightsKey = GetPrivateProfileIntA("Input", "ToggleItemHighlightsKey", 0, ini); if (toggleHighlightsKey) { @@ -1423,7 +1431,7 @@ void ScriptExtenderSetup() { long long data = 0x397401C1F6; // test cl, 1; jz 0x483CF2 SafeWriteBytes(0x483CB4, (BYTE*)&data, 5); - // Set the DAM_BACKWASH_ flag for the attacker before calling compute_damage_ + // Set the DAM_BACKWASH flag for the attacker before calling compute_damage_ SafeWrite32(0x423DE7, 0x40164E80); // or [esi+ctd.flags3Source], DAM_BACKWASH_ long idata = 0x146E09; // or dword ptr [esi+ctd.flagsSource], ebp SafeWriteBytes(0x423DF0, (BYTE*)&idata, 3); @@ -2015,11 +2023,14 @@ static DWORD _stdcall HandleMapUpdateForScripts(const DWORD procId) { for (SfallProgsMap::iterator it = sfallProgsMap.begin(); it != sfallProgsMap.end(); it++) { DWORD progPtr = it->second.ptr; __asm { - mov eax, progPtr; + mov eax, progPtr; call runProgram_; } } - } + } /*else if (procId == map_exit_p_proc) { + ClearEventUpdateMapProc(); + }*/ + RunGlobalScriptsAtProc(procId); // gl* scripts of types 0 and 3 RunHookScriptsAtProc(procId); // all hs_ scripts diff --git a/sfall/ScriptOps/ScriptUtils.hpp b/sfall/ScriptOps/ScriptUtils.hpp index 7a88019d..7f692ec9 100644 --- a/sfall/ScriptOps/ScriptUtils.hpp +++ b/sfall/ScriptOps/ScriptUtils.hpp @@ -813,31 +813,32 @@ static const DWORD game_msg_files[] = { 0x672FB0, // WORLDMAP }; -// TODO: move to FalloutEngine -static const DWORD* proto_msg_files = (DWORD*)0x006647AC; - static void _stdcall op_message_str_game2() { - const char* msg = 0; + const char* msg = nullptr; const ScriptValue &fileIdArg = opHandler.arg(0), &msgIdArg = opHandler.arg(1); + if (fileIdArg.isInt() && msgIdArg.isInt()) { - int fileId = fileIdArg.asInt(); - int msgId = msgIdArg.asInt(); - if (fileId < 20) { // main msg files - msg = GetMessageStr(game_msg_files[fileId], msgId); - } else if (fileId >= 0x1000 && fileId <= 0x1005) { // proto msg files - msg = GetMessageStr((DWORD)&proto_msg_files[2*(fileId - 0x1000)], msgId); - } else if (fileId >= 0x2000) { // Extra game message files. - ExtraGameMessageListsMap::iterator it = gExtraGameMsgLists.find(fileId); - if (it != gExtraGameMsgLists.end()) { - msg = GetMsg(it->second, msgId, 2); + int fileId = fileIdArg.rawValue(); + if (fileId >= 0) { + int msgId = msgIdArg.rawValue(); + if (fileId < 20) { // main msg files + msg = GetMessageStr(game_msg_files[fileId], msgId); + } else if (fileId >= 0x1000 && fileId <= 0x1005) { // proto msg files + msg = GetMessageStr((DWORD)&ptr_proto_msg_files[2 * (fileId - 0x1000)], msgId); + } else if (fileId >= 0x2000) { // Extra game message files. + ExtraGameMessageListsMap::iterator it = gExtraGameMsgLists.find(fileId); + if (it != gExtraGameMsgLists.end()) { + msg = GetMsg(it->second, msgId, 2); + } } } + if (msg == nullptr) msg = "Error"; + opHandler.setReturn(msg); + } else { + OpcodeInvalidArgs("message_str_game"); + opHandler.setReturn(-1); } - if (msg == 0) { - msg = "Error"; - } - opHandler.setReturn(msg); } static void __declspec(naked) op_message_str_game() { diff --git a/sfall/Stats.cpp b/sfall/Stats.cpp index 28a19611..efd378d3 100644 --- a/sfall/Stats.cpp +++ b/sfall/Stats.cpp @@ -245,7 +245,7 @@ void StatsInit() { StatMulti[31 * 7 + 2] = 2; // rad resist StatMulti[32 * 7 + 2] = 5; // poison resist - char key[6], buf2[256], buf3[256]; + char key[6], buf2[256], buf3[MAX_PATH]; strcpy_s(buf3, table); sprintf(table, ".\\%s", buf3); for (int i = STAT_max_hit_points; i <= STAT_poison_resist; i++) { diff --git a/sfall/main.cpp b/sfall/main.cpp index 004b01c5..9261d8e2 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -644,8 +644,6 @@ static void __declspec(naked) display_stats_hook() { } static void DllMain2() { - //SafeWrite8(0x4B15E8, 0xc3); - //SafeWrite8(0x4B30C4, 0xc3); //this is the one I need to override for bigger tiles DWORD tmp; dlogr("In DllMain2", DL_MAIN); @@ -809,8 +807,8 @@ static void DllMain2() { dlogr(" Done", DL_INIT); } - char elevPath[MAX_PATH]; - GetPrivateProfileString("Misc", "ElevatorsFile", "", elevPath, MAX_PATH, ini); + char elevPath[MAX_PATH - 3]; + GetPrivateProfileString("Misc", "ElevatorsFile", "", elevPath, MAX_PATH - 3, ini); if (strlen(elevPath) > 0) { dlog("Applying elevator patch.", DL_INIT); ElevatorsInit(elevPath); @@ -1336,7 +1334,7 @@ bool _stdcall DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) { strcpy_s(ini, ".\\ddraw.ini"); } - GetPrivateProfileStringA("Main", "TranslationsINI", "./Translations.ini", translationIni, 65, ini); + GetPrivateProfileStringA("Main", "TranslationsINI", ".\\Translations.ini", translationIni, 65, ini); modifiedIni = GetPrivateProfileIntA("Main", "ModifiedIni", 0, ini); DllMain2(); diff --git a/sfall/skills.cpp b/sfall/skills.cpp index f6a61f30..d5ee4fe6 100644 --- a/sfall/skills.cpp +++ b/sfall/skills.cpp @@ -290,8 +290,8 @@ void SkillsInit() { // 0x00000400 - Energy Weapon (forces weapon to use Energy Weapons skill) HookCall(0x47831E, item_w_skill_hook); - char buf[512], key[16], file[64]; - if (GetPrivateProfileStringA("Misc", "SkillsFile", "", buf, 62, ini) > 0) { + char buf[512], key[16], file[MAX_PATH]; + if (GetPrivateProfileStringA("Misc", "SkillsFile", "", buf, MAX_PATH - 3, ini) > 0) { SkillInfo *skills = (SkillInfo*)_skill_data; sprintf(file, ".\\%s", buf);