From 0aad511e3eec36f8cbcd56f2fbc5318ea0a54cb8 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 5 Oct 2018 10:13:01 +0800 Subject: [PATCH] Refactored ASM code in ScriptExtender.cpp according to the develop branch, and edited the code style. Moved NegateFix to Bugs.cpp and simplified its code. --- sfall/Bugs.cpp | 32 ++ sfall/HeroAppearance.cpp | 4 +- sfall/ScriptExtender.cpp | 864 ++++++++++++++++---------------- sfall/ScriptExtender.h | 4 +- sfall/ScriptOps/ScriptUtils.hpp | 27 - sfall/main.cpp | 1 + sfall/main.h | 1 + 7 files changed, 481 insertions(+), 452 deletions(-) diff --git a/sfall/Bugs.cpp b/sfall/Bugs.cpp index 99eda0d8..625191d3 100644 --- a/sfall/Bugs.cpp +++ b/sfall/Bugs.cpp @@ -19,6 +19,28 @@ void GameInitialization() { *(DWORD*)_gDialogMusicVol = *(DWORD*)_background_volume; // fix dialog music } +// fix for vanilla negate operator not working on floats +static const DWORD NegateFixHack_Back = 0x46AB77; +static void __declspec(naked) NegateFixHack() { + __asm { + mov eax, [ecx + 0x1C]; + cmp si, VAR_TYPE_FLOAT; + je isFloat; + neg ebx; + retn; +isFloat: + push ebx; + fld[esp]; + fchs; + fstp[esp]; + pop ebx; + call pushLongStack_; + mov edx, VAR_TYPE_FLOAT; + add esp, 4; // Destroy the return address + jmp NegateFixHack_Back; + } +} + static void __declspec(naked) SharpShooterFix() { __asm { call stat_level_ // Perception @@ -1383,6 +1405,16 @@ skip: void BugsInit() { + // fix vanilla negate operator on float values + MakeCall(0x46AB68, NegateFixHack); + // fix incorrect int-to-float conversion + // op_mult: + SafeWrite16(0x46A3F4, 0x04DB); // replace operator to "fild 32bit" + SafeWrite16(0x46A3A8, 0x04DB); + // op_div: + SafeWrite16(0x46A566, 0x04DB); + SafeWrite16(0x46A4E7, 0x04DB); + //if (GetPrivateProfileIntA("Misc", "SharpshooterFix", 1, ini)) { dlog("Applying Sharpshooter patch.", DL_INIT); // http://www.nma-fallout.com/threads/fo2-engine-tweaks-sfall.178390/page-119#post-4050162 diff --git a/sfall/HeroAppearance.cpp b/sfall/HeroAppearance.cpp index 4b3f7b0e..f45b82b4 100644 --- a/sfall/HeroAppearance.cpp +++ b/sfall/HeroAppearance.cpp @@ -639,10 +639,10 @@ int GetFont(void) { //--------------------------------------------------------- //print text to surface void PrintText(char *DisplayText, BYTE ColourIndex, DWORD Xpos, DWORD Ypos, DWORD TxtWidth, DWORD ToWidth, BYTE *ToSurface) { - DWORD posOffset = Ypos*ToWidth + Xpos; + DWORD posOffset = Ypos * ToWidth + Xpos; __asm { xor eax, eax - MOV AL, ColourIndex + mov al, ColourIndex push eax mov edx, DisplayText mov ebx, TxtWidth diff --git a/sfall/ScriptExtender.cpp b/sfall/ScriptExtender.cpp index 28c69648..335b1ec3 100644 --- a/sfall/ScriptExtender.cpp +++ b/sfall/ScriptExtender.cpp @@ -39,7 +39,7 @@ #include "Cpp11_emu.h" #endif -void _stdcall HandleMapUpdateForScripts(DWORD procId); +static DWORD _stdcall HandleMapUpdateForScripts(const DWORD procId); // variables for new opcodes #define OP_MAX_ARGUMENTS (10) @@ -248,7 +248,7 @@ public: va_end(args); const char* procName = FindCurrentProc(_program); - DebugPrintf("\nOPCODE ERROR: %s\n Current script: %s, procedure %s.", msg, _program->fileName, procName); + DebugPrintf("\nOPCODE ERROR: %s\n > Script: %s, procedure %s.", msg, _program->fileName, procName); } // Validate opcode arguments against type masks @@ -405,10 +405,10 @@ struct sGlobalScript { sGlobalScript() {} sGlobalScript(sScriptProgram script) { - prog=script; - count=0; - repeat=0; - mode=0; + prog = script; + count = 0; + repeat = 0; + mode = 0; } }; @@ -436,8 +436,7 @@ typedef stdext::hash_map<__int64, int> :: const_iterator glob_citr; typedef std::pair<__int64, int> glob_pair; static void* opcodes[0x300]; -DWORD AddUnarmedStatToGetYear=0; -DWORD AvailableGlobalScriptTypes=0; +DWORD AvailableGlobalScriptTypes = 0; bool isGameLoading; TScript OverrideScriptStruct; @@ -453,14 +452,15 @@ TScript OverrideScriptStruct; static void _stdcall SetGlobalScriptRepeat2(DWORD script, DWORD frames) { - for(DWORD d=0;d3) return; - for(DWORD d=0;d 3) return; + for (DWORD d = 0; d < globalScripts.size(); d++) { + if (globalScripts[d].prog.ptr == script) { + globalScripts[d].mode = type; break; } } } + static void __declspec(naked) SetGlobalScriptType() { __asm { push ebx; @@ -514,6 +516,7 @@ end: retn; } } + static void __declspec(naked) GetGlobalScriptTypes() { __asm { push ebx; @@ -531,21 +534,25 @@ static void __declspec(naked) GetGlobalScriptTypes() { retn; } } + static void SetGlobalVarInternal(__int64 var, int val) { - glob_itr itr=globalVars.find(var); - if (itr==globalVars.end()) globalVars.insert(glob_pair(var, val)); + glob_itr itr = globalVars.find(var); + if (itr == globalVars.end()) globalVars.insert(glob_pair(var, val)); else { if (val == 0) globalVars.erase(itr); // applies for both float 0.0 and integer 0 - else itr->second=val; + else itr->second = val; } } + static void _stdcall SetGlobalVar2(const char* var, int val) { - if(strlen(var)!=8) return; + if (strlen(var) != 8) return; SetGlobalVarInternal(*(__int64*)var, val); } + static void _stdcall SetGlobalVar2Int(DWORD var, int val) { SetGlobalVarInternal(var, val); } + static void __declspec(naked) SetGlobalVar() { __asm { push ebx; @@ -589,18 +596,22 @@ end: retn; } } + static DWORD GetGlobalVarInternal(__int64 val) { - glob_citr itr=globalVars.find(val); - if(itr==globalVars.end()) return 0; + glob_citr itr = globalVars.find(val); + if (itr == globalVars.end()) return 0; else return itr->second; } + static DWORD _stdcall GetGlobalVar2(const char* var) { - if(strlen(var)!=8) return 0; + if (strlen(var) != 8) return 0; return GetGlobalVarInternal(*(__int64*)var); } + static DWORD _stdcall GetGlobalVar2Int(DWORD var) { return GetGlobalVarInternal(var); } + static void __declspec(naked) GetGlobalVarInt() { __asm { push ebx; @@ -646,6 +657,7 @@ end: retn; } } + static void __declspec(naked) GetGlobalVarFloat() { __asm { push ebx; @@ -708,13 +720,17 @@ static void __declspec(naked) GetSfallArg() { retn; } } + static DWORD _stdcall GetSfallArgs2() { DWORD argCount=GetHSArgCount(); DWORD id=TempArray(argCount, 4); DWORD* args = GetHSArgs(); - for(DWORD i=0;i::iterator it = selfOverrideMap.find(script); - if (it != selfOverrideMap.end()) + if (it != selfOverrideMap.end()) { selfOverrideMap.erase(it); + } } } @@ -866,6 +886,7 @@ static void __declspec(naked) sfall_ver_major() { _RET_VAL_INT(ebp) _OP_END } + static void __declspec(naked) sfall_ver_minor() { _OP_BEGIN(ebp) __asm { @@ -874,6 +895,7 @@ static void __declspec(naked) sfall_ver_minor() { _RET_VAL_INT(ebp) _OP_END } + static void __declspec(naked) sfall_ver_build() { _OP_BEGIN(ebp) __asm { @@ -885,11 +907,11 @@ static void __declspec(naked) sfall_ver_build() { //END OF SCRIPT FUNCTIONS -static const DWORD scr_find_sid_from_program=scr_find_sid_from_program_ + 5; -static const DWORD scr_ptr=scr_ptr_ + 5; -static const DWORD scr_find_obj_from_program=scr_find_obj_from_program_ + 7; +static const DWORD scr_ptr_back = scr_ptr_ + 5; +static const DWORD scr_find_sid_from_program = scr_find_sid_from_program_ + 5; +static const DWORD scr_find_obj_from_program = scr_find_obj_from_program_ + 7; -DWORD _stdcall FindSidHook2(DWORD script) { +static DWORD _stdcall FindSid(DWORD script) { stdext::hash_map::iterator overrideIt = selfOverrideMap.find(script); if (overrideIt != selfOverrideMap.end()) { DWORD scriptId = overrideIt->second->scriptID; @@ -910,42 +932,45 @@ DWORD _stdcall FindSidHook2(DWORD script) { return -1; // change nothing } -static void __declspec(naked) FindSidHook() { +static void __declspec(naked) FindSidHack() { __asm { - sub esp, 4; - pushad; push eax; - call FindSidHook2; - mov [esp+32], eax; // to save value after popad - popad; - add esp, 4; - cmp [esp-4], -1; - jz end; - cmp [esp-4], -2; - jz override_script; - mov eax, [esp-4]; + push edx; + push ecx; + push eax; + call FindSid; + pop ecx; + pop edx; + cmp eax, -1; // eax = scriptId + jz end; + cmp eax, -2; + jz override_script; + add esp, 4; retn; override_script: test edx, edx; - jz end; - lea eax, OverrideScriptStruct; - mov [edx], eax; - mov eax, -2; + jz end; + add esp, 4; + lea eax, OverrideScriptStruct; + mov [edx], eax; + mov eax, -2; retn; end: + pop eax; push ebx; push ecx; push edx; push esi; push ebp; - jmp scr_find_sid_from_program; + jmp scr_find_sid_from_program; } } -static void __declspec(naked) ScrPtrHook() { + +static void __declspec(naked) ScrPtrHack() { __asm { - cmp eax, -2; - jnz end; - xor eax, eax; + cmp eax, -2; + jnz end; + xor eax, eax; retn; end: push ebx; @@ -953,7 +978,7 @@ end: push esi; push edi; push ebp; - jmp scr_ptr; + jmp scr_ptr_back; } } @@ -972,6 +997,7 @@ static void __declspec(naked) MainGameLoopHook() { retn; } } + static void __declspec(naked) CombatLoopHook() { __asm { pushad; @@ -980,6 +1006,7 @@ static void __declspec(naked) CombatLoopHook() { jmp get_input_ } } + static void __declspec(naked) AfterCombatAttackHook() { __asm { pushad; @@ -990,19 +1017,21 @@ static void __declspec(naked) AfterCombatAttackHook() { retn; } } -static void __declspec(naked) ExecMapScriptsHook() { + +static const DWORD ExecMapScriptsRet = 0x4A67F5; +static void __declspec(naked) ExecMapScriptsHack() { __asm { - sub esp, 32; - mov [esp+12], eax; - pushad; + push edi; + push ebp; + sub esp, 0x20; + //------ push eax; // int procId call HandleMapUpdateForScripts; - popad; - push 0x4A67F9; // jump back - retn; + jmp ExecMapScriptsRet; } } -static DWORD __stdcall GetGlobalExportedVarPtr(const char* name) { + +static DWORD __cdecl GetGlobalExportedVarPtr(const char* name) { std::string str(name); ExportedVarsMap::iterator it = globalExportedVars.find(str); //dlog_f("\n Trying to find exported var %s... ", DL_MAIN, name); @@ -1012,12 +1041,13 @@ static DWORD __stdcall GetGlobalExportedVarPtr(const char* name) { } return 0; } -static DWORD __stdcall CreateGlobalExportedVar(DWORD scr, const char* name) { + +static void __stdcall CreateGlobalExportedVar(DWORD scr, const char* name) { //dlog_f("\nTrying to export variable %s (%d)\n", DL_MAIN, name, isGlobalScriptLoading); std::string str(name); globalExportedVars[str] = sExportedVar(); // add new - return 1; } + /* when fetching/storing into exported variables, first search in our own hash table instead, then (if not found), resume normal search @@ -1028,48 +1058,34 @@ static DWORD __stdcall CreateGlobalExportedVar(DWORD scr, const char* name) { */ static void __declspec(naked) Export_FetchOrStore_FindVar_Hook() { __asm { - push eax; - push edx; push ecx; - push ebx; - push edx // char* varName - call GetGlobalExportedVarPtr; + push edx; // char* varName + call GetGlobalExportedVarPtr; //_cdecl + pop edx; + pop ecx; test eax, eax - jz proceedNormal; - pop ebx; - pop ecx; - pop edx; - pop edx; - sub eax, 0x24; // adjust pointer for the code + jz proceedNormal; + sub eax, 0x24; // adjust pointer for the code retn; - - proceedNormal: - pop ebx; - pop ecx; - pop edx; - pop eax; - call findVar_ - retn +proceedNormal: + mov eax, edx; // varName + jmp findVar_ } } -static const DWORD Export_Export_FindVar_back1 = 0x4414CD; -static const DWORD Export_Export_FindVar_back2 = 0x4414AC; + +static const DWORD Export_Export_FindVar_back = 0x4414AE; static void __declspec(naked) Export_Export_FindVar_Hook() { __asm { - pushad; - mov eax, isGlobalScriptLoading; - test eax, eax; - jz proceedNormal; - push edx; // char* - var name + cmp isGlobalScriptLoading, 0; + jz proceedNormal; + push edx; // var name push ebp; // script ptr call CreateGlobalExportedVar; - popad; - jmp Export_Export_FindVar_back2; // if sfall exported var, jump to the end of function - + xor eax, eax; + add esp, 4; // destroy return + jmp Export_Export_FindVar_back; // if sfall exported var, jump to the end of function proceedNormal: - popad; - call findVar_; // else - proceed normal - jmp Export_Export_FindVar_back1; + jmp findVar_; // else - proceed normal } } @@ -1082,12 +1098,15 @@ static void _stdcall FreeProgramHook2(DWORD progPtr) { } } } + static void __declspec(naked) FreeProgramHook() { __asm { - pushad; + push ecx; + push edx; push eax; call FreeProgramHook2; - popad; + pop edx; + pop ecx; retn; } } @@ -1216,336 +1235,328 @@ void ScriptExtenderSetup() { } modifiedIni = GetPrivateProfileIntA("Main", "ModifiedIni", 0, ini); - dlogr("Adding additional opcodes", DL_SCRIPT); - if(AllowUnsafeScripting) dlogr(" Unsafe opcodes enabled.", DL_SCRIPT); - else dlogr(" Unsafe opcodes disabled.", DL_SCRIPT); - arraysBehavior = GetPrivateProfileIntA("Misc", "arraysBehavior", 1, ini); if (arraysBehavior > 0) { arraysBehavior = 1; // only 1 and 0 allowed at this time dlogr("New arrays behavior enabled.", DL_SCRIPT); } else dlogr("Arrays in backward-compatiblity mode.", DL_SCRIPT); - SafeWrite32(0x46E370, 0x300); //Maximum number of allowed opcodes - SafeWrite32(0x46ce34, (DWORD)opcodes); //cmp check to make sure opcode exists - SafeWrite32(0x46ce6c, (DWORD)opcodes); //call that actually jumps to the opcode - SafeWrite32(0x46e390, (DWORD)opcodes); //mov that writes to the opcode - HookCall(0x480E7B, MainGameLoopHook); //hook the main game loop HookCall(0x422845, CombatLoopHook); //hook the combat loop - MakeJump(0x4A390C, FindSidHook); - MakeJump(0x4A5E34, ScrPtrHook); + MakeJump(0x4A390C, FindSidHack); + MakeJump(0x4A5E34, ScrPtrHack); memset(&OverrideScriptStruct, 0, sizeof(TScript)); MakeJump(0x4230D5, AfterCombatAttackHook); - MakeJump(0x4A67F2, ExecMapScriptsHook); + MakeJump(0x4A67F0, ExecMapScriptsHack); // this patch makes it possible to export variables from sfall global scripts - MakeJump(0x4414C8, Export_Export_FindVar_Hook); + HookCall(0x4414C8, Export_Export_FindVar_Hook); HookCall(0x441285, &Export_FetchOrStore_FindVar_Hook); // store HookCall(0x4413D9, &Export_FetchOrStore_FindVar_Hook); // fetch - // fix vanilla negate operator on float values - MakeJump(0x46AB63, NegateFixHook); - // fix incorrect int-to-float conversion - // op_mult: - SafeWrite16(0x46A3F4, 0x04DB); // replace operator to "fild 32bit" - SafeWrite16(0x46A3A8, 0x04DB); - // op_div: - SafeWrite16(0x46A566, 0x04DB); - SafeWrite16(0x46A4E7, 0x04DB); - HookCall(0x46E141, FreeProgramHook); // combat_is_starting_p_proc / combat_is_over_p_proc HookCall(0x421B72, CombatBeginHook); HookCall(0x421FC1, CombatOverHook); - if(AllowUnsafeScripting) { - opcodes[0x156]=ReadByte; - opcodes[0x157]=ReadShort; - opcodes[0x158]=ReadInt; - opcodes[0x159]=ReadString; + dlogr("Adding additional opcodes", DL_SCRIPT); + if (AllowUnsafeScripting) dlogr(" Unsafe opcodes enabled.", DL_SCRIPT); + else dlogr(" Unsafe opcodes disabled.", DL_SCRIPT); + + SafeWrite32(0x46E370, 0x300); //Maximum number of allowed opcodes + SafeWrite32(0x46ce34, (DWORD)opcodes); //cmp check to make sure opcode exists + SafeWrite32(0x46ce6c, (DWORD)opcodes); //call that actually jumps to the opcode + SafeWrite32(0x46e390, (DWORD)opcodes); //mov that writes to the opcode + + if (AllowUnsafeScripting) { + opcodes[0x156] = ReadByte; + opcodes[0x157] = ReadShort; + opcodes[0x158] = ReadInt; + opcodes[0x159] = ReadString; } - opcodes[0x15a]=SetPCBaseStat; - opcodes[0x15b]=SetPCExtraStat; - opcodes[0x15c]=GetPCBaseStat; - opcodes[0x15d]=GetPCExtraStat; - opcodes[0x15e]=SetCritterBaseStat; - opcodes[0x15f]=SetCritterExtraStat; - opcodes[0x160]=GetCritterBaseStat; - opcodes[0x161]=GetCritterExtraStat; - opcodes[0x162]=funcTapKey; - opcodes[0x163]=GetYear; - opcodes[0x164]=GameLoaded; - opcodes[0x165]=GraphicsFuncsAvailable; - opcodes[0x166]=funcLoadShader; - opcodes[0x167]=funcFreeShader; - opcodes[0x168]=funcActivateShader; - opcodes[0x169]=funcDeactivateShader; - opcodes[0x16a]=SetGlobalScriptRepeat; - opcodes[0x16b]=InputFuncsAvailable; - opcodes[0x16c]=KeyPressed; - opcodes[0x16d]=funcSetShaderInt; - opcodes[0x16e]=funcSetShaderFloat; - opcodes[0x16f]=funcSetShaderVector; - opcodes[0x170]=funcInWorldMap; - opcodes[0x171]=ForceEncounter; - opcodes[0x172]=SetWorldMapPos; - opcodes[0x173]=GetWorldMapXPos; - opcodes[0x174]=GetWorldMapYPos; - opcodes[0x175]=SetDMModel; - opcodes[0x176]=SetDFModel; - opcodes[0x177]=SetMoviePath; - for(int i=0x178;i<0x189;i++) - opcodes[i]=funcSetPerkValue; - opcodes[0x189]=funcSetPerkName; - opcodes[0x18a]=funcSetPerkDesc; - opcodes[0x18b]=SetPipBoyAvailable; - if(UsingExtraKillTypes()) { - opcodes[0x18c]=GetKillCounter2; - opcodes[0x18d]=ModKillCounter2; + opcodes[0x15a] = SetPCBaseStat; + opcodes[0x15b] = SetPCExtraStat; + opcodes[0x15c] = GetPCBaseStat; + opcodes[0x15d] = GetPCExtraStat; + opcodes[0x15e] = SetCritterBaseStat; + opcodes[0x15f] = SetCritterExtraStat; + opcodes[0x160] = GetCritterBaseStat; + opcodes[0x161] = GetCritterExtraStat; + opcodes[0x162] = funcTapKey; + opcodes[0x163] = GetYear; + opcodes[0x164] = GameLoaded; + opcodes[0x165] = GraphicsFuncsAvailable; + opcodes[0x166] = funcLoadShader; + opcodes[0x167] = funcFreeShader; + opcodes[0x168] = funcActivateShader; + opcodes[0x169] = funcDeactivateShader; + opcodes[0x16a] = SetGlobalScriptRepeat; + opcodes[0x16b] = InputFuncsAvailable; + opcodes[0x16c] = KeyPressed; + opcodes[0x16d] = funcSetShaderInt; + opcodes[0x16e] = funcSetShaderFloat; + opcodes[0x16f] = funcSetShaderVector; + opcodes[0x170] = funcInWorldMap; + opcodes[0x171] = ForceEncounter; + opcodes[0x172] = SetWorldMapPos; + opcodes[0x173] = GetWorldMapXPos; + opcodes[0x174] = GetWorldMapYPos; + opcodes[0x175] = SetDMModel; + opcodes[0x176] = SetDFModel; + opcodes[0x177] = SetMoviePath; + for (int i = 0x178; i < 0x189; i++) { + opcodes[i] = funcSetPerkValue; + } + opcodes[0x189] = funcSetPerkName; + opcodes[0x18a] = funcSetPerkDesc; + opcodes[0x18b] = SetPipBoyAvailable; + if (UsingExtraKillTypes()) { + opcodes[0x18c] = GetKillCounter2; + opcodes[0x18d] = ModKillCounter2; } else { - opcodes[0x18c]=GetKillCounter; - opcodes[0x18d]=ModKillCounter; + opcodes[0x18c] = GetKillCounter; + opcodes[0x18d] = ModKillCounter; } - opcodes[0x18e]=GetPerkOwed; - opcodes[0x18f]=SetPerkOwed; - opcodes[0x190]=GetPerkAvailable; - opcodes[0x191]=GetCritterAP; - opcodes[0x192]=SetCritterAP; - opcodes[0x193]=GetActiveHand; - opcodes[0x194]=ToggleActiveHand; - opcodes[0x195]=SetWeaponKnockback; - opcodes[0x196]=SetTargetKnockback; - opcodes[0x197]=SetAttackerKnockback; - opcodes[0x198]=RemoveWeaponKnockback; - opcodes[0x199]=RemoveTargetKnockback; - opcodes[0x19a]=RemoveAttackerKnockback; - opcodes[0x19b]=SetGlobalScriptType; - opcodes[0x19c]=GetGlobalScriptTypes; - opcodes[0x19d]=SetGlobalVar; - opcodes[0x19e]=GetGlobalVarInt; - opcodes[0x19f]=GetGlobalVarFloat; - opcodes[0x1a0]=fSetPickpocketMax; - opcodes[0x1a1]=fSetHitChanceMax; - opcodes[0x1a2]=fSetSkillMax; - opcodes[0x1a3]=EaxAvailable; - //opcodes[0x1a4]=SetEaxEnvironmentFunc; - opcodes[0x1a5]=IncNPCLevel; - opcodes[0x1a6]=GetViewportX; - opcodes[0x1a7]=GetViewportY; - opcodes[0x1a8]=SetViewportX; - opcodes[0x1a9]=SetViewportY; - opcodes[0x1aa]=SetXpMod; - opcodes[0x1ab]=SetPerkLevelMod; - opcodes[0x1ac]=GetIniSetting; - opcodes[0x1ad]=funcGetShaderVersion; - opcodes[0x1ae]=funcSetShaderMode; - opcodes[0x1af]=GetGameMode; - opcodes[0x1b0]=funcForceGraphicsRefresh; - opcodes[0x1b1]=funcGetShaderTexture; - opcodes[0x1b2]=funcSetShaderTexture; - opcodes[0x1b3]=funcGetTickCount; - opcodes[0x1b4]=SetStatMax; - opcodes[0x1b5]=SetStatMin; - opcodes[0x1b6]=SetCarTown; - opcodes[0x1b7]=fSetPCStatMax; - opcodes[0x1b8]=fSetPCStatMin; - opcodes[0x1b9]=fSetNPCStatMax; - opcodes[0x1ba]=fSetNPCStatMin; - opcodes[0x1bb]=fSetFakePerk; - opcodes[0x1bc]=fSetFakeTrait; - opcodes[0x1bd]=fSetSelectablePerk; - opcodes[0x1be]=fSetPerkboxTitle; - opcodes[0x1bf]=fIgnoreDefaultPerks; - opcodes[0x1c0]=fRestoreDefaultPerks; - opcodes[0x1c1]=fHasFakePerk; - opcodes[0x1c2]=fHasFakeTrait; - opcodes[0x1c3]=fAddPerkMode; - opcodes[0x1c4]=fClearSelectablePerks; - opcodes[0x1c5]=SetCritterHitChance; - opcodes[0x1c6]=SetBaseHitChance; - opcodes[0x1c7]=SetCritterSkillMod; - opcodes[0x1c8]=SetBaseSkillMod; - opcodes[0x1c9]=SetCritterPickpocket; - opcodes[0x1ca]=SetBasePickpocket; - opcodes[0x1cb]=SetPyromaniacMod; - opcodes[0x1cc]=fApplyHeaveHoFix; - opcodes[0x1cd]=SetSwiftLearnerMod; - opcodes[0x1ce]=SetLevelHPMod; - if(AllowUnsafeScripting) { - opcodes[0x1cf]=WriteByte; - opcodes[0x1d0]=WriteShort; - opcodes[0x1d1]=WriteInt; - for(int i=0x1d2;i<0x1dc;i++) - opcodes[i]=CallOffset; + opcodes[0x18e] = GetPerkOwed; + opcodes[0x18f] = SetPerkOwed; + opcodes[0x190] = GetPerkAvailable; + opcodes[0x191] = GetCritterAP; + opcodes[0x192] = SetCritterAP; + opcodes[0x193] = GetActiveHand; + opcodes[0x194] = ToggleActiveHand; + opcodes[0x195] = SetWeaponKnockback; + opcodes[0x196] = SetTargetKnockback; + opcodes[0x197] = SetAttackerKnockback; + opcodes[0x198] = RemoveWeaponKnockback; + opcodes[0x199] = RemoveTargetKnockback; + opcodes[0x19a] = RemoveAttackerKnockback; + opcodes[0x19b] = SetGlobalScriptType; + opcodes[0x19c] = GetGlobalScriptTypes; + opcodes[0x19d] = SetGlobalVar; + opcodes[0x19e] = GetGlobalVarInt; + opcodes[0x19f] = GetGlobalVarFloat; + opcodes[0x1a0] = fSetPickpocketMax; + opcodes[0x1a1] = fSetHitChanceMax; + opcodes[0x1a2] = fSetSkillMax; + opcodes[0x1a3] = EaxAvailable; + //opcodes[0x1a4] = SetEaxEnvironmentFunc; + opcodes[0x1a5] = IncNPCLevel; + opcodes[0x1a6] = GetViewportX; + opcodes[0x1a7] = GetViewportY; + opcodes[0x1a8] = SetViewportX; + opcodes[0x1a9] = SetViewportY; + opcodes[0x1aa] = SetXpMod; + opcodes[0x1ab] = SetPerkLevelMod; + opcodes[0x1ac] = GetIniSetting; + opcodes[0x1ad] = funcGetShaderVersion; + opcodes[0x1ae] = funcSetShaderMode; + opcodes[0x1af] = GetGameMode; + opcodes[0x1b0] = funcForceGraphicsRefresh; + opcodes[0x1b1] = funcGetShaderTexture; + opcodes[0x1b2] = funcSetShaderTexture; + opcodes[0x1b3] = funcGetTickCount; + opcodes[0x1b4] = SetStatMax; + opcodes[0x1b5] = SetStatMin; + opcodes[0x1b6] = SetCarTown; + opcodes[0x1b7] = fSetPCStatMax; + opcodes[0x1b8] = fSetPCStatMin; + opcodes[0x1b9] = fSetNPCStatMax; + opcodes[0x1ba] = fSetNPCStatMin; + opcodes[0x1bb] = fSetFakePerk; + opcodes[0x1bc] = fSetFakeTrait; + opcodes[0x1bd] = fSetSelectablePerk; + opcodes[0x1be] = fSetPerkboxTitle; + opcodes[0x1bf] = fIgnoreDefaultPerks; + opcodes[0x1c0] = fRestoreDefaultPerks; + opcodes[0x1c1] = fHasFakePerk; + opcodes[0x1c2] = fHasFakeTrait; + opcodes[0x1c3] = fAddPerkMode; + opcodes[0x1c4] = fClearSelectablePerks; + opcodes[0x1c5] = SetCritterHitChance; + opcodes[0x1c6] = SetBaseHitChance; + opcodes[0x1c7] = SetCritterSkillMod; + opcodes[0x1c8] = SetBaseSkillMod; + opcodes[0x1c9] = SetCritterPickpocket; + opcodes[0x1ca] = SetBasePickpocket; + opcodes[0x1cb] = SetPyromaniacMod; + opcodes[0x1cc] = fApplyHeaveHoFix; + opcodes[0x1cd] = SetSwiftLearnerMod; + opcodes[0x1ce] = SetLevelHPMod; + if (AllowUnsafeScripting) { + opcodes[0x1cf] = WriteByte; + opcodes[0x1d0] = WriteShort; + opcodes[0x1d1] = WriteInt; + for (int i = 0x1d2; i < 0x1dc; i++) { + opcodes[i] = CallOffset; + } } - opcodes[0x1dc]=ShowIfaceTag; - opcodes[0x1dd]=HideIfaceTag; - opcodes[0x1de]=IsIfaceTagActive; - opcodes[0x1df]=GetBodypartHitModifier; - opcodes[0x1e0]=SetBodypartHitModifier; - opcodes[0x1e1]=funcSetCriticalTable; - opcodes[0x1e2]=funcGetCriticalTable; - opcodes[0x1e3]=funcResetCriticalTable; - opcodes[0x1e4]=GetSfallArg; - opcodes[0x1e5]=SetSfallReturn; - opcodes[0x1e6]=SetApAcBonus; - opcodes[0x1e7]=GetApAcBonus; - opcodes[0x1e8]=SetApAcEBonus; - opcodes[0x1e9]=GetApAcEBonus; - opcodes[0x1ea]=InitHook; - opcodes[0x1eb]=GetIniString; - opcodes[0x1ec]=funcSqrt; - opcodes[0x1ed]=funcAbs; - opcodes[0x1ee]=funcSin; - opcodes[0x1ef]=funcCos; - opcodes[0x1f0]=funcTan; - opcodes[0x1f1]=funcATan; - opcodes[0x1f2]=SetPalette; - opcodes[0x1f3]=RemoveScript; - opcodes[0x1f4]=SetScript; - opcodes[0x1f5]=GetScript; - opcodes[0x1f6]=NBCreateChar; - opcodes[0x1f7]=fs_create; - opcodes[0x1f8]=fs_copy; - opcodes[0x1f9]=fs_find; - opcodes[0x1fa]=fs_write_byte; - opcodes[0x1fb]=fs_write_short; - opcodes[0x1fc]=fs_write_int; - opcodes[0x1fd]=fs_write_int; - opcodes[0x1fe]=fs_write_string; - opcodes[0x1ff]=fs_delete; - opcodes[0x200]=fs_size; - opcodes[0x201]=fs_pos; - opcodes[0x202]=fs_seek; - opcodes[0x203]=fs_resize; - opcodes[0x204]=get_proto_data; - opcodes[0x205]=set_proto_data; - opcodes[0x206]=set_self; - opcodes[0x207]=register_hook; - opcodes[0x208]=fs_write_bstring; - opcodes[0x209]=fs_read_byte; - opcodes[0x20a]=fs_read_short; - opcodes[0x20b]=fs_read_int; - opcodes[0x20c]=fs_read_float; - opcodes[0x20d]=list_begin; - opcodes[0x20e]=list_next; - opcodes[0x20f]=list_end; - opcodes[0x210]=sfall_ver_major; - opcodes[0x211]=sfall_ver_minor; - opcodes[0x212]=sfall_ver_build; - opcodes[0x213]=funcHeroSelectWin; - opcodes[0x214]=funcSetHeroRace; - opcodes[0x215]=funcSetHeroStyle; - opcodes[0x216]=set_critter_burst_disable; - opcodes[0x217]=get_weapon_ammo_pid; - opcodes[0x218]=set_weapon_ammo_pid; - opcodes[0x219]=get_weapon_ammo_count; - opcodes[0x21a]=set_weapon_ammo_count; - if(AllowUnsafeScripting) { - opcodes[0x21b]=WriteString; + opcodes[0x1dc] = ShowIfaceTag; + opcodes[0x1dd] = HideIfaceTag; + opcodes[0x1de] = IsIfaceTagActive; + opcodes[0x1df] = GetBodypartHitModifier; + opcodes[0x1e0] = SetBodypartHitModifier; + opcodes[0x1e1] = funcSetCriticalTable; + opcodes[0x1e2] = funcGetCriticalTable; + opcodes[0x1e3] = funcResetCriticalTable; + opcodes[0x1e4] = GetSfallArg; + opcodes[0x1e5] = SetSfallReturn; + opcodes[0x1e6] = SetApAcBonus; + opcodes[0x1e7] = GetApAcBonus; + opcodes[0x1e8] = SetApAcEBonus; + opcodes[0x1e9] = GetApAcEBonus; + opcodes[0x1ea] = InitHook; + opcodes[0x1eb] = GetIniString; + opcodes[0x1ec] = funcSqrt; + opcodes[0x1ed] = funcAbs; + opcodes[0x1ee] = funcSin; + opcodes[0x1ef] = funcCos; + opcodes[0x1f0] = funcTan; + opcodes[0x1f1] = funcATan; + opcodes[0x1f2] = SetPalette; + opcodes[0x1f3] = RemoveScript; + opcodes[0x1f4] = SetScript; + opcodes[0x1f5] = GetScript; + opcodes[0x1f6] = NBCreateChar; + opcodes[0x1f7] = fs_create; + opcodes[0x1f8] = fs_copy; + opcodes[0x1f9] = fs_find; + opcodes[0x1fa] = fs_write_byte; + opcodes[0x1fb] = fs_write_short; + opcodes[0x1fc] = fs_write_int; + opcodes[0x1fd] = fs_write_int; + opcodes[0x1fe] = fs_write_string; + opcodes[0x1ff] = fs_delete; + opcodes[0x200] = fs_size; + opcodes[0x201] = fs_pos; + opcodes[0x202] = fs_seek; + opcodes[0x203] = fs_resize; + opcodes[0x204] = get_proto_data; + opcodes[0x205] = set_proto_data; + opcodes[0x206] = set_self; + opcodes[0x207] = register_hook; + opcodes[0x208] = fs_write_bstring; + opcodes[0x209] = fs_read_byte; + opcodes[0x20a] = fs_read_short; + opcodes[0x20b] = fs_read_int; + opcodes[0x20c] = fs_read_float; + opcodes[0x20d] = list_begin; + opcodes[0x20e] = list_next; + opcodes[0x20f] = list_end; + opcodes[0x210] = sfall_ver_major; + opcodes[0x211] = sfall_ver_minor; + opcodes[0x212] = sfall_ver_build; + opcodes[0x213] = funcHeroSelectWin; + opcodes[0x214] = funcSetHeroRace; + opcodes[0x215] = funcSetHeroStyle; + opcodes[0x216] = set_critter_burst_disable; + opcodes[0x217] = get_weapon_ammo_pid; + opcodes[0x218] = set_weapon_ammo_pid; + opcodes[0x219] = get_weapon_ammo_count; + opcodes[0x21a] = set_weapon_ammo_count; + if (AllowUnsafeScripting) { + opcodes[0x21b] = WriteString; } - opcodes[0x21c]=get_mouse_x; - opcodes[0x21d]=get_mouse_y; - opcodes[0x21e]=get_mouse_buttons; - opcodes[0x21f]=get_window_under_mouse; - opcodes[0x220]=get_screen_width; - opcodes[0x221]=get_screen_height; - opcodes[0x222]=stop_game; - opcodes[0x223]=resume_game; - opcodes[0x224]=create_message_window; - opcodes[0x225]=remove_trait; - opcodes[0x226]=get_light_level; - opcodes[0x227]=refresh_pc_art; - opcodes[0x228]=get_attack_type; - opcodes[0x229]=ForceEncounterWithFlags; - opcodes[0x22a]=set_map_time_multi; - opcodes[0x22b]=play_sfall_sound; - opcodes[0x22c]=stop_sfall_sound; - opcodes[0x22d]=create_array; - opcodes[0x22e]=set_array; - opcodes[0x22f]=get_array; - opcodes[0x230]=free_array; - opcodes[0x231]=len_array; - opcodes[0x232]=resize_array; - opcodes[0x233]=temp_array; - opcodes[0x234]=fix_array; - opcodes[0x235]=string_split; - opcodes[0x236]=list_as_array; - opcodes[0x237]=str_to_int; - opcodes[0x238]=str_to_flt; - opcodes[0x239]=scan_array; - opcodes[0x23a]=get_tile_pid; - opcodes[0x23b]=modified_ini; - opcodes[0x23c]=GetSfallArgs; - opcodes[0x23d]=SetSfallArg; - opcodes[0x23e]=force_aimed_shots; - opcodes[0x23f]=disable_aimed_shots; - opcodes[0x240]=mark_movie_played; - opcodes[0x241]=get_npc_level; - opcodes[0x242]=set_critter_skill_points; - opcodes[0x243]=get_critter_skill_points; - opcodes[0x244]=set_available_skill_points; - opcodes[0x245]=get_available_skill_points; - opcodes[0x246]=mod_skill_points_per_level; - opcodes[0x247]=set_perk_freq; - opcodes[0x248]=get_last_attacker; - opcodes[0x249]=get_last_target; - opcodes[0x24a]=block_combat; - opcodes[0x24b]=tile_under_cursor; - opcodes[0x24c]=gdialog_get_barter_mod; - opcodes[0x24d]=set_inven_ap_cost; - opcodes[0x24e]=op_substr; - opcodes[0x24f]=op_strlen; - opcodes[0x250]=op_sprintf; - opcodes[0x251]=op_ord; - // opcodes[0x252]= RESERVED - opcodes[0x253]=op_typeof; - opcodes[0x254]=op_save_array; - opcodes[0x255]=op_load_array; - opcodes[0x256]=op_get_array_key; - opcodes[0x257]=op_stack_array; - // opcodes[0x258]= RESERVED for arrays - // opcodes[0x259]= RESERVED for arrays - opcodes[0x25a]=op_reg_anim_destroy; - opcodes[0x25b]=op_reg_anim_animate_and_hide; - opcodes[0x25c]=op_reg_anim_combat_check; - opcodes[0x25d]=op_reg_anim_light; - opcodes[0x25e]=op_reg_anim_change_fid; - opcodes[0x25f]=op_reg_anim_take_out; - opcodes[0x260]=op_reg_anim_turn_towards; - opcodes[0x261]=op_explosions_metarule; - opcodes[0x262]=register_hook_proc; - opcodes[0x263]=funcPow; - opcodes[0x264]=funcLog; - opcodes[0x265]=funcExp; - opcodes[0x266]=funcCeil; - opcodes[0x267]=funcRound; - // opcodes[0x268]= RESERVED - // opcodes[0x269]= RESERVED - // opcodes[0x26a]=op_game_ui_redraw; - opcodes[0x26b]=op_message_str_game; - opcodes[0x26c]=op_sneak_success; - opcodes[0x26d]=op_tile_light; - opcodes[0x26e]=op_make_straight_path; - opcodes[0x26f]=op_obj_blocking_at; - opcodes[0x270]=op_tile_get_objects; - opcodes[0x271]=op_get_party_members; - opcodes[0x272]=op_make_path; - opcodes[0x273]=op_create_spatial; - opcodes[0x274]=op_art_exists; - opcodes[0x275]=op_obj_is_carrying_obj; + opcodes[0x21c] = get_mouse_x; + opcodes[0x21d] = get_mouse_y; + opcodes[0x21e] = get_mouse_buttons; + opcodes[0x21f] = get_window_under_mouse; + opcodes[0x220] = get_screen_width; + opcodes[0x221] = get_screen_height; + opcodes[0x222] = stop_game; + opcodes[0x223] = resume_game; + opcodes[0x224] = create_message_window; + opcodes[0x225] = remove_trait; + opcodes[0x226] = get_light_level; + opcodes[0x227] = refresh_pc_art; + opcodes[0x228] = get_attack_type; + opcodes[0x229] = ForceEncounterWithFlags; + opcodes[0x22a] = set_map_time_multi; + opcodes[0x22b] = play_sfall_sound; + opcodes[0x22c] = stop_sfall_sound; + opcodes[0x22d] = create_array; + opcodes[0x22e] = set_array; + opcodes[0x22f] = get_array; + opcodes[0x230] = free_array; + opcodes[0x231] = len_array; + opcodes[0x232] = resize_array; + opcodes[0x233] = temp_array; + opcodes[0x234] = fix_array; + opcodes[0x235] = string_split; + opcodes[0x236] = list_as_array; + opcodes[0x237] = str_to_int; + opcodes[0x238] = str_to_flt; + opcodes[0x239] = scan_array; + opcodes[0x23a] = get_tile_pid; + opcodes[0x23b] = modified_ini; + opcodes[0x23c] = GetSfallArgs; + opcodes[0x23d] = SetSfallArg; + opcodes[0x23e] = force_aimed_shots; + opcodes[0x23f] = disable_aimed_shots; + opcodes[0x240] = mark_movie_played; + opcodes[0x241] = get_npc_level; + opcodes[0x242] = set_critter_skill_points; + opcodes[0x243] = get_critter_skill_points; + opcodes[0x244] = set_available_skill_points; + opcodes[0x245] = get_available_skill_points; + opcodes[0x246] = mod_skill_points_per_level; + opcodes[0x247] = set_perk_freq; + opcodes[0x248] = get_last_attacker; + opcodes[0x249] = get_last_target; + opcodes[0x24a] = block_combat; + opcodes[0x24b] = tile_under_cursor; + opcodes[0x24c] = gdialog_get_barter_mod; + opcodes[0x24d] = set_inven_ap_cost; + opcodes[0x24e] = op_substr; + opcodes[0x24f] = op_strlen; + opcodes[0x250] = op_sprintf; + opcodes[0x251] = op_ord; + // opcodes[0x252] = RESERVED + opcodes[0x253] = op_typeof; + opcodes[0x254] = op_save_array; + opcodes[0x255] = op_load_array; + opcodes[0x256] = op_get_array_key; + opcodes[0x257] = op_stack_array; + // opcodes[0x258] = RESERVED for arrays + // opcodes[0x259] = RESERVED for arrays + opcodes[0x25a] = op_reg_anim_destroy; + opcodes[0x25b] = op_reg_anim_animate_and_hide; + opcodes[0x25c] = op_reg_anim_combat_check; + opcodes[0x25d] = op_reg_anim_light; + opcodes[0x25e] = op_reg_anim_change_fid; + opcodes[0x25f] = op_reg_anim_take_out; + opcodes[0x260] = op_reg_anim_turn_towards; + opcodes[0x261] = op_explosions_metarule; + opcodes[0x262] = register_hook_proc; + opcodes[0x263] = funcPow; + opcodes[0x264] = funcLog; + opcodes[0x265] = funcExp; + opcodes[0x266] = funcCeil; + opcodes[0x267] = funcRound; + // opcodes[0x268] = RESERVED + // opcodes[0x269] = RESERVED + // opcodes[0x26a] = op_game_ui_redraw; + opcodes[0x26b] = op_message_str_game; + opcodes[0x26c] = op_sneak_success; + opcodes[0x26d] = op_tile_light; + opcodes[0x26e] = op_make_straight_path; + opcodes[0x26f] = op_obj_blocking_at; + opcodes[0x270] = op_tile_get_objects; + opcodes[0x271] = op_get_party_members; + opcodes[0x272] = op_make_path; + opcodes[0x273] = op_create_spatial; + opcodes[0x274] = op_art_exists; + opcodes[0x275] = op_obj_is_carrying_obj; // universal opcodes - opcodes[0x276]=op_sfall_metarule0; - opcodes[0x277]=op_sfall_metarule1; - opcodes[0x278]=op_sfall_metarule2; - opcodes[0x279]=op_sfall_metarule3; - opcodes[0x27a]=op_sfall_metarule4; - opcodes[0x27b]=op_sfall_metarule5; - opcodes[0x27c]=op_sfall_metarule6; // if you need more arguments - use arrays + opcodes[0x276] = op_sfall_metarule0; + opcodes[0x277] = op_sfall_metarule1; + opcodes[0x278] = op_sfall_metarule2; + opcodes[0x279] = op_sfall_metarule3; + opcodes[0x27a] = op_sfall_metarule4; + opcodes[0x27b] = op_sfall_metarule5; + opcodes[0x27c] = op_sfall_metarule6; // if you need more arguments - use arrays InitOpcodeMetaTable(); InitMetaruleTable(); @@ -1575,7 +1586,7 @@ void LoadScriptProgram(sScriptProgram &prog, const char* fileName) { const char** procTable = (const char **)_procTableStrs; prog.ptr = scriptPtr; // fill lookup table - for (int i=0; i<=SCRIPT_PROC_MAX; i++) { + for (int i = 0; i <= SCRIPT_PROC_MAX; i++) { prog.procLookup[i] = GetScriptProcByName(prog.ptr, procTable[i]); } prog.initialized = 0; @@ -1610,8 +1621,9 @@ sScriptProgram* GetGlobalScriptProgram(DWORD scriptPtr) { } bool _stdcall isGameScript(const char* filename) { + if ((filename[0] != 'g' || filename[1] != 'l') && (filename[0] != 'h' || filename[1] != 's')) return true; for (DWORD i = 0; i < *(DWORD*)_maxScriptNum; i++) { - if (strcmp(filename, (char*)(*(DWORD*)_scriptListInfo + i*20)) == 0) return true; + if (strcmp(filename, (char*)(*(DWORD*)_scriptListInfo + i * 20)) == 0) return true; } return false; } @@ -1662,12 +1674,11 @@ void LoadGlobalScripts() { call db_free_file_list_ } dlogr("Finished loading global scripts.", DL_SCRIPT|DL_INIT); - //ButtonsReload(); } static DWORD _stdcall ScriptHasLoaded(DWORD script) { - for(DWORD d=0;dptr; DWORD procNum = GetScriptProcByName(sptr, procName); @@ -1722,6 +1735,7 @@ void RunScriptProc(sScriptProgram* prog, const char* procName) { RunScriptProcByNum(sptr, procNum); } } + void RunScriptProc(sScriptProgram* prog, DWORD procId) { if (procId > 0 && procId <= SCRIPT_PROC_MAX) { DWORD sptr = prog->ptr; @@ -1731,6 +1745,7 @@ void RunScriptProc(sScriptProgram* prog, DWORD procId) { } } } + static void RunScript(sGlobalScript* script) { script->count=0; RunScriptProc(&script->prog, start); // run "start" @@ -1813,6 +1828,7 @@ void RunGlobalScripts2() { } ResetStateAfterFrame(); } + void RunGlobalScripts3() { if (idle > -1 && idle <= 127) Sleep(idle); for (DWORD d = 0; d < globalScripts.size(); d++) { @@ -1824,7 +1840,7 @@ void RunGlobalScripts3() { ResetStateAfterFrame(); } -void _stdcall HandleMapUpdateForScripts(DWORD procId) { +static DWORD _stdcall HandleMapUpdateForScripts(const DWORD procId) { if (procId == map_enter_p_proc) { // map changed, all game objects were destroyed and scripts detached, need to re-insert global scripts into the game for (SfallProgsMap::iterator it = sfallProgsMap.begin(); it != sfallProgsMap.end(); it++) { @@ -1837,6 +1853,8 @@ void _stdcall HandleMapUpdateForScripts(DWORD procId) { } RunGlobalScriptsAtProc(procId); // gl* scripts of types 0 and 3 RunHookScriptsAtProc(procId); // all hs_ scripts + + return procId; // restore eax (don't delete) } // run all global scripts of types 0 and 3 at specific procedure (if exist) @@ -1850,9 +1868,9 @@ void _stdcall RunGlobalScriptsAtProc(DWORD procId) { void LoadGlobals(HANDLE h) { DWORD count, unused; ReadFile(h, &count, 4, &unused, 0); - if(unused!=4) return; + if (unused != 4) return; sGlobalVar var; - for(DWORD i=0;ifirst; - var.val=itr->second; + glob_citr itr = globalVars.begin(); + while (itr != globalVars.end()) { + var.id = itr->first; + var.val = itr->second; WriteFile(h, &var, sizeof(sGlobalVar), &unused, 0); itr++; } @@ -1874,26 +1892,32 @@ void SaveGlobals(HANDLE h) { void ClearGlobals() { globalVars.clear(); - for (array_itr it = arrays.begin(); it != arrays.end(); ++it) + for (array_itr it = arrays.begin(); it != arrays.end(); ++it) { it->second.clear(); + } arrays.clear(); savedArrays.clear(); } -int GetNumGlobals() { return globalVars.size(); } + +int GetNumGlobals() { + return globalVars.size(); +} + void GetGlobals(sGlobalVar* globals) { - glob_citr itr=globalVars.begin(); - int i=0; - while(itr!=globalVars.end()) { - globals[i].id=itr->first; - globals[i++].val=itr->second; + glob_citr itr = globalVars.begin(); + int i = 0; + while (itr != globalVars.end()) { + globals[i].id = itr->first; + globals[i++].val = itr->second; itr++; } } + void SetGlobals(sGlobalVar* globals) { - glob_itr itr=globalVars.begin(); - int i=0; - while(itr!=globalVars.end()) { - itr->second=globals[i++].val; + glob_itr itr = globalVars.begin(); + int i = 0; + while (itr != globalVars.end()) { + itr->second = globals[i++].val; itr++; } } diff --git a/sfall/ScriptExtender.h b/sfall/ScriptExtender.h index 43c44f76..f56e39be 100644 --- a/sfall/ScriptExtender.h +++ b/sfall/ScriptExtender.h @@ -60,9 +60,6 @@ int GetNumGlobals(); void GetGlobals(sGlobalVar* globals); void SetGlobals(sGlobalVar* globals); -extern DWORD AddUnarmedStatToGetYear; -extern DWORD AvailableGlobalScriptTypes; - void SetAppearanceGlobals(int race, int style); void GetAppearanceGlobals(int *race, int *style); @@ -89,6 +86,7 @@ char* _stdcall mysubstr(char* str, int pos, int length); // variables static char reg_anim_combat_check = 1; extern DWORD isGlobalScriptLoading; +extern DWORD AvailableGlobalScriptTypes; // types for script variables #define VAR_TYPE_INT (0xC001) diff --git a/sfall/ScriptOps/ScriptUtils.hpp b/sfall/ScriptOps/ScriptUtils.hpp index d365465a..809ff638 100644 --- a/sfall/ScriptOps/ScriptUtils.hpp +++ b/sfall/ScriptOps/ScriptUtils.hpp @@ -742,33 +742,6 @@ static void __declspec(naked) op_typeof() { } } -// fix for vanilla negate operator not working on floats -static const DWORD NegateFixHook_Back = 0x46AB79; -static void __declspec(naked) NegateFixHook() { - __asm { - mov ebx, edi; - lea edx, [ecx+36]; - mov eax, [ecx+28]; - cmp si, VAR_TYPE_FLOAT; - jne notfloat; - push ebx; - fld [esp]; - fchs - fstp [esp]; - pop ebx; - call pushLongStack_ - mov edx, VAR_TYPE_FLOAT - jmp end -notfloat: - neg ebx - call pushLongStack_ - mov edx, VAR_TYPE_INT -end: - mov eax, ecx - jmp NegateFixHook_Back; - } -} - static void funcPow2() { const ScriptValue &base = opHandler.arg(0), &power = opHandler.arg(1); diff --git a/sfall/main.cpp b/sfall/main.cpp index 60a162af..9bcef4c8 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -84,6 +84,7 @@ static const char* debugGnw = "GNW"; static const char* musicOverridePath = "data\\sound\\music\\"; +DWORD AddUnarmedStatToGetYear = 0; bool npcautolevel; static int* scriptDialog = nullptr; diff --git a/sfall/main.h b/sfall/main.h index ecffd4c8..ca3b1ad6 100644 --- a/sfall/main.h +++ b/sfall/main.h @@ -36,6 +36,7 @@ extern char translationIni[65]; extern char dmModelName[65]; extern char dfModelName[65]; +extern DWORD AddUnarmedStatToGetYear; extern bool npcautolevel; template