mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Separated MainLoopHook.cpp/h from ScriptExtender
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
#include "..\FalloutEngine\Fallout2.h"
|
||||||
|
#include "..\SafeWrite.h"
|
||||||
|
#include "Explosions.h"
|
||||||
|
#include "ScriptExtender.h"
|
||||||
|
|
||||||
|
#include "MainLoopHook.h"
|
||||||
|
|
||||||
|
namespace sfall
|
||||||
|
{
|
||||||
|
|
||||||
|
bool displayWinUpdateState = false;
|
||||||
|
|
||||||
|
static void MainGameLoopResetStates() {
|
||||||
|
displayWinUpdateState = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __stdcall MainGameLoop() { // OnMainLoop
|
||||||
|
RunGlobalScripts1();
|
||||||
|
MainGameLoopResetStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __stdcall CombatLoop() { // OnCombatLoop
|
||||||
|
RunGlobalScripts1();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __stdcall AfterCombatAttack() { // OnAfterCombatAttack
|
||||||
|
ResetExplosionSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __declspec(naked) MainGameLoopHook() {
|
||||||
|
__asm {
|
||||||
|
push ecx;
|
||||||
|
call fo::funcoffs::get_input_;
|
||||||
|
push edx;
|
||||||
|
push eax;
|
||||||
|
call MainGameLoop;
|
||||||
|
pop eax;
|
||||||
|
pop edx;
|
||||||
|
pop ecx;
|
||||||
|
retn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __declspec(naked) CombatLoopHook() {
|
||||||
|
__asm {
|
||||||
|
push ecx;
|
||||||
|
push edx;
|
||||||
|
//push eax;
|
||||||
|
call CombatLoop;
|
||||||
|
//pop eax;
|
||||||
|
pop edx;
|
||||||
|
call fo::funcoffs::get_input_;
|
||||||
|
pop ecx; // fix to prevent the combat turn from being skipped after using Alt+Tab
|
||||||
|
retn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __declspec(naked) AfterCombatAttackHook() {
|
||||||
|
__asm {
|
||||||
|
push ecx;
|
||||||
|
push edx;
|
||||||
|
call AfterCombatAttack;
|
||||||
|
pop edx;
|
||||||
|
pop ecx;
|
||||||
|
mov eax, 1;
|
||||||
|
retn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainLoopHook_Init() {
|
||||||
|
HookCall(0x480E7B, MainGameLoopHook); // hook the main game loop
|
||||||
|
HookCall(0x422845, CombatLoopHook); // hook the combat loop
|
||||||
|
MakeCall(0x4230D5, AfterCombatAttackHook);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace sfall
|
||||||
|
{
|
||||||
|
|
||||||
|
extern bool displayWinUpdateState;
|
||||||
|
|
||||||
|
void MainLoopHook_Init();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#include "..\Translate.h"
|
#include "..\Translate.h"
|
||||||
|
|
||||||
#include "LoadGameHook.h"
|
#include "LoadGameHook.h"
|
||||||
#include "ScriptExtender.h"
|
#include "MainLoopHook.h"
|
||||||
|
|
||||||
#include "MiscPatches.h"
|
#include "MiscPatches.h"
|
||||||
|
|
||||||
@@ -893,7 +893,7 @@ void MiscPatches_Init() {
|
|||||||
if (GetConfigInt("Misc", "OverrideArtCacheSize", 0)) {
|
if (GetConfigInt("Misc", "OverrideArtCacheSize", 0)) {
|
||||||
dlog("Applying override art cache size patch.", DL_INIT);
|
dlog("Applying override art cache size patch.", DL_INIT);
|
||||||
SafeWrite32(0x418867, 0x90909090);
|
SafeWrite32(0x418867, 0x90909090);
|
||||||
SafeWrite32(0x418872, 261); // setup default for 512 MB system memory
|
SafeWrite32(0x418872, 261); // default for 512 MB system memory by installer
|
||||||
dlogr(" Done", DL_INIT);
|
dlogr(" Done", DL_INIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,10 @@
|
|||||||
#include "..\Translate.h"
|
#include "..\Translate.h"
|
||||||
#include "..\version.h"
|
#include "..\version.h"
|
||||||
#include "Arrays.h"
|
#include "Arrays.h"
|
||||||
#include "Explosions.h"
|
|
||||||
#include "HookScripts.h"
|
#include "HookScripts.h"
|
||||||
#include "LoadGameHook.h"
|
#include "LoadGameHook.h"
|
||||||
|
#include "MainLoopHook.h"
|
||||||
|
|
||||||
#include "ScriptExtender.h"
|
#include "ScriptExtender.h"
|
||||||
|
|
||||||
using namespace sfall;
|
using namespace sfall;
|
||||||
@@ -37,7 +38,6 @@ using namespace sfall;
|
|||||||
|
|
||||||
static DWORD __stdcall HandleMapUpdateForScripts(const DWORD procId);
|
static DWORD __stdcall HandleMapUpdateForScripts(const DWORD procId);
|
||||||
|
|
||||||
static void RunGlobalScripts1();
|
|
||||||
static void ClearEventsOnMapExit();
|
static void ClearEventsOnMapExit();
|
||||||
|
|
||||||
// variables for new opcodes
|
// variables for new opcodes
|
||||||
@@ -457,7 +457,6 @@ DWORD availableGlobalScriptTypes = 0;
|
|||||||
static DWORD isGlobalScriptLoading = 0;
|
static DWORD isGlobalScriptLoading = 0;
|
||||||
static bool isGameReset;
|
static bool isGameReset;
|
||||||
bool alwaysFindScripts;
|
bool alwaysFindScripts;
|
||||||
bool displayWinUpdateState = false;
|
|
||||||
|
|
||||||
fo::ScriptInstance overrideScript = {0};
|
fo::ScriptInstance overrideScript = {0};
|
||||||
|
|
||||||
@@ -731,54 +730,6 @@ override: // for scr_find_obj_from_program_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Do some cleaning after each combat attack action
|
|
||||||
*/
|
|
||||||
static void __stdcall AfterCombatAttack() { // OnAfterCombatAttack
|
|
||||||
ResetExplosionSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __declspec(naked) MainGameLoopHook() {
|
|
||||||
__asm {
|
|
||||||
push ecx;
|
|
||||||
call fo::funcoffs::get_input_;
|
|
||||||
push edx;
|
|
||||||
push eax;
|
|
||||||
call RunGlobalScripts1;
|
|
||||||
mov displayWinUpdateState, 0; // reset
|
|
||||||
pop eax;
|
|
||||||
pop edx;
|
|
||||||
pop ecx;
|
|
||||||
retn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __declspec(naked) CombatLoopHook() {
|
|
||||||
__asm {
|
|
||||||
push ecx;
|
|
||||||
push edx;
|
|
||||||
//push eax;
|
|
||||||
call RunGlobalScripts1;
|
|
||||||
//pop eax;
|
|
||||||
pop edx;
|
|
||||||
call fo::funcoffs::get_input_;
|
|
||||||
pop ecx; // fix to prevent the combat turn from being skipped after using Alt+Tab
|
|
||||||
retn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __declspec(naked) AfterCombatAttackHook() {
|
|
||||||
__asm {
|
|
||||||
push ecx;
|
|
||||||
push edx;
|
|
||||||
call AfterCombatAttack;
|
|
||||||
pop edx;
|
|
||||||
pop ecx;
|
|
||||||
mov eax, 1;
|
|
||||||
retn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __declspec(naked) ExecMapScriptsHack() {
|
static void __declspec(naked) ExecMapScriptsHack() {
|
||||||
static const DWORD ExecMapScriptsRet = 0x4A67F5;
|
static const DWORD ExecMapScriptsRet = 0x4A67F5;
|
||||||
__asm {
|
__asm {
|
||||||
@@ -1222,7 +1173,7 @@ static void ResetStateAfterFrame() {
|
|||||||
RegAnimCombatCheck(1);
|
RegAnimCombatCheck(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RunGlobalScripts1() {
|
void RunGlobalScripts1() {
|
||||||
if (idle > -1) Sleep(idle);
|
if (idle > -1) Sleep(idle);
|
||||||
|
|
||||||
if (toggleHighlightsKey) {
|
if (toggleHighlightsKey) {
|
||||||
@@ -1654,10 +1605,6 @@ void ScriptExtender_Init() {
|
|||||||
alwaysFindScripts = isDebug && (GetIntDefaultConfig("Debugging", "AlwaysFindScripts", 0) != 0);
|
alwaysFindScripts = isDebug && (GetIntDefaultConfig("Debugging", "AlwaysFindScripts", 0) != 0);
|
||||||
if (alwaysFindScripts) dlogr("Always searching for global scripts behavior enabled.", DL_SCRIPT);
|
if (alwaysFindScripts) dlogr("Always searching for global scripts behavior enabled.", DL_SCRIPT);
|
||||||
|
|
||||||
HookCall(0x480E7B, MainGameLoopHook); // hook the main game loop
|
|
||||||
HookCall(0x422845, CombatLoopHook); // hook the combat loop
|
|
||||||
MakeCall(0x4230D5, AfterCombatAttackHook);
|
|
||||||
|
|
||||||
MakeJump(0x4A390C, scr_find_sid_from_program_hack);
|
MakeJump(0x4A390C, scr_find_sid_from_program_hack);
|
||||||
MakeJump(0x4A5E34, scr_ptr_hack);
|
MakeJump(0x4A5E34, scr_ptr_hack);
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ void LoadGlobalScripts();
|
|||||||
void InitGlobalScripts();
|
void InitGlobalScripts();
|
||||||
bool __stdcall IsGameScript(const char* filename);
|
bool __stdcall IsGameScript(const char* filename);
|
||||||
|
|
||||||
|
void RunGlobalScripts1();
|
||||||
void RunGlobalScripts2();
|
void RunGlobalScripts2();
|
||||||
void RunGlobalScripts3();
|
void RunGlobalScripts3();
|
||||||
void __stdcall RunGlobalScriptsAtProc(DWORD procId);
|
void __stdcall RunGlobalScriptsAtProc(DWORD procId);
|
||||||
@@ -103,5 +104,4 @@ void ObjectNameReset();
|
|||||||
// variables
|
// variables
|
||||||
extern DWORD availableGlobalScriptTypes;
|
extern DWORD availableGlobalScriptTypes;
|
||||||
extern bool alwaysFindScripts;
|
extern bool alwaysFindScripts;
|
||||||
extern bool displayWinUpdateState;
|
|
||||||
extern bool scriptExtOnMapLeave;
|
extern bool scriptExtOnMapLeave;
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Explosions.h"
|
||||||
|
|
||||||
namespace sfall
|
namespace sfall
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -270,6 +270,7 @@
|
|||||||
<ClInclude Include="Modules\KillCounter.h" />
|
<ClInclude Include="Modules\KillCounter.h" />
|
||||||
<ClInclude Include="Modules\LoadGameHook.h" />
|
<ClInclude Include="Modules\LoadGameHook.h" />
|
||||||
<ClInclude Include="Modules\LoadOrder.h" />
|
<ClInclude Include="Modules\LoadOrder.h" />
|
||||||
|
<ClInclude Include="Modules\MainLoopHook.h" />
|
||||||
<ClInclude Include="Modules\MainMenu.h" />
|
<ClInclude Include="Modules\MainMenu.h" />
|
||||||
<ClInclude Include="Modules\Message.h" />
|
<ClInclude Include="Modules\Message.h" />
|
||||||
<ClInclude Include="Modules\MetaruleExtender.h" />
|
<ClInclude Include="Modules\MetaruleExtender.h" />
|
||||||
@@ -365,6 +366,7 @@
|
|||||||
<ClCompile Include="Modules\KillCounter.cpp" />
|
<ClCompile Include="Modules\KillCounter.cpp" />
|
||||||
<ClCompile Include="Modules\LoadGameHook.cpp" />
|
<ClCompile Include="Modules\LoadGameHook.cpp" />
|
||||||
<ClCompile Include="Modules\LoadOrder.cpp" />
|
<ClCompile Include="Modules\LoadOrder.cpp" />
|
||||||
|
<ClCompile Include="Modules\MainLoopHook.cpp" />
|
||||||
<ClCompile Include="Modules\MainMenu.cpp" />
|
<ClCompile Include="Modules\MainMenu.cpp" />
|
||||||
<ClCompile Include="Modules\Message.cpp" />
|
<ClCompile Include="Modules\Message.cpp" />
|
||||||
<ClCompile Include="Modules\MetaruleExtender.cpp" />
|
<ClCompile Include="Modules\MetaruleExtender.cpp" />
|
||||||
|
|||||||
@@ -100,6 +100,9 @@
|
|||||||
<ClInclude Include="Modules\LoadOrder.h">
|
<ClInclude Include="Modules\LoadOrder.h">
|
||||||
<Filter>Modules</Filter>
|
<Filter>Modules</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Modules\MainLoopHook.h">
|
||||||
|
<Filter>Modules</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="Modules\MainMenu.h">
|
<ClInclude Include="Modules\MainMenu.h">
|
||||||
<Filter>Modules</Filter>
|
<Filter>Modules</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -379,6 +382,9 @@
|
|||||||
<ClCompile Include="Modules\LoadOrder.cpp">
|
<ClCompile Include="Modules\LoadOrder.cpp">
|
||||||
<Filter>Modules</Filter>
|
<Filter>Modules</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Modules\MainLoopHook.cpp">
|
||||||
|
<Filter>Modules</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="Modules\MainMenu.cpp">
|
<ClCompile Include="Modules\MainMenu.cpp">
|
||||||
<Filter>Modules</Filter>
|
<Filter>Modules</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
#include "Modules\KillCounter.h"
|
#include "Modules\KillCounter.h"
|
||||||
#include "Modules\LoadGameHook.h"
|
#include "Modules\LoadGameHook.h"
|
||||||
#include "Modules\LoadOrder.h"
|
#include "Modules\LoadOrder.h"
|
||||||
|
#include "Modules\MainLoopHook.h"
|
||||||
#include "Modules\MainMenu.h"
|
#include "Modules\MainMenu.h"
|
||||||
#include "Modules\Message.h"
|
#include "Modules\Message.h"
|
||||||
#include "Modules\MetaruleExtender.h"
|
#include "Modules\MetaruleExtender.h"
|
||||||
@@ -122,6 +123,9 @@ static void InitModules() {
|
|||||||
dlogr("Running LoadGameHook_Init().", DL_INIT);
|
dlogr("Running LoadGameHook_Init().", DL_INIT);
|
||||||
LoadGameHook_Init();
|
LoadGameHook_Init();
|
||||||
|
|
||||||
|
dlogr("Running MainLoopHook_Init().", DL_INIT);
|
||||||
|
MainLoopHook_Init();
|
||||||
|
|
||||||
dlogr("Running EngineTweaks_Init().", DL_INIT);
|
dlogr("Running EngineTweaks_Init().", DL_INIT);
|
||||||
EngineTweaks_Init();
|
EngineTweaks_Init();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user