Reorganize hooks in LoadGameHook: don't hook main menu loop, instead added "before new game" hook.

This commit is contained in:
phobos2077
2017-03-01 02:50:27 +07:00
parent 02658a3801
commit 38e0f21e93
6 changed files with 46 additions and 90 deletions
-23
View File
@@ -70,29 +70,6 @@ void InventoryKeyPressedHook(DWORD dxKey, bool pressed, DWORD vKey) {
} }
} }
/*static DWORD _stdcall item_total_size(void* critter) {
//TODO: Don't really want to be overwriting stuff like this after init. Rewrite properly.
HookCall(0x477EBD, (void*)0x477B68);
HookCall(0x477EF6, (void*)0x477B68);
HookCall(0x477F12, (void*)0x477B68);
HookCall(0x477F2A, (void*)0x477B68);
DWORD result;
__asm {
mov eax, critter;
call FuncOffs::item_total_weight_;
mov result, eax;
}
HookCall(0x477EBD, (void*)0x477B88);
HookCall(0x477EF6, (void*)0x477B88);
HookCall(0x477F12, (void*)0x477B88);
HookCall(0x477F2A, (void*)0x477B88);
return result;
}*/
//TODO: Do we actually want to include this in the limit anyway? //TODO: Do we actually want to include this in the limit anyway?
static __declspec(naked) DWORD item_total_size(void* critter) { static __declspec(naked) DWORD item_total_size(void* critter) {
__asm { __asm {
+32 -57
View File
@@ -44,15 +44,17 @@
#include "Sound.h" #include "Sound.h"
#include "ExtraSaveSlots.h" #include "ExtraSaveSlots.h"
Delegate<> LoadGameHook::OnBeforeLoadGame; Delegate<> LoadGameHook::OnBeforeGameLoad;
Delegate<> LoadGameHook::OnAfterLoadGame; Delegate<> LoadGameHook::OnAfterGameLoaded;
Delegate<> LoadGameHook::OnAfterNewGame; //Delegate<> LoadGameHook::OnAfterNewGame;
Delegate<> LoadGameHook::OnGameStart; //Delegate<> LoadGameHook::OnGameStart;
#define MAX_GLOBAL_SIZE (MaxGlobalVars * 12 + 4) #define MAX_GLOBAL_SIZE (MaxGlobalVars * 12 + 4)
static DWORD InLoop = 0; static DWORD InLoop = 0;
static DWORD SaveInCombatFix; static DWORD SaveInCombatFix;
static bool DisableHorrigan = false;
static bool PipBoyAvailableAtGameStart = false;
DWORD InWorldMap() { DWORD InWorldMap() {
return (InLoop&WORLDMAP) ? 1 : 0; return (InLoop&WORLDMAP) ? 1 : 0;
@@ -80,8 +82,6 @@ static void _stdcall ResetState(DWORD onLoad) {
RegAnimCombatCheck(1); RegAnimCombatCheck(1);
AfterAttackCleanup(); AfterAttackCleanup();
PartyControlReset(); PartyControlReset();
//OnBeforeLoadGame.invoke();
} }
void GetSavePath(char* buf, char* ftype) { void GetSavePath(char* buf, char* ftype) {
@@ -164,9 +164,9 @@ end:
} }
} }
// should be called before savegame is loaded // Called right before savegame slot is being loaded
static void _stdcall LoadGame2_Before() { static void _stdcall LoadGame_Before() {
LoadGameHook::OnBeforeLoadGame.invoke(); LoadGameHook::OnBeforeGameLoad.invoke();
ResetState(1); ResetState(1);
char buf[MAX_PATH]; char buf[MAX_PATH];
@@ -190,19 +190,19 @@ static void _stdcall LoadGame2_Before() {
} }
} }
static void _stdcall LoadGame2_After() { // Called after game was loaded from a save
static void _stdcall LoadGame_After() {
LoadGlobalScripts(); LoadGlobalScripts();
CritLoad(); CritLoad();
LoadHeroAppearance(); LoadHeroAppearance();
LoadGameHook::OnAfterLoadGame.invoke(); LoadGameHook::OnAfterGameLoaded.invoke();
LoadGameHook::OnGameStart.invoke();
} }
static void __declspec(naked) LoadSlot() { static void __declspec(naked) LoadSlot() {
__asm { __asm {
pushad; pushad;
call LoadGame2_Before; call LoadGame_Before;
popad; popad;
call FuncOffs::LoadSlot_; call FuncOffs::LoadSlot_;
retn; retn;
@@ -219,10 +219,9 @@ static void __declspec(naked) LoadGame() {
and InLoop, (-1^LOADGAME); and InLoop, (-1^LOADGAME);
cmp eax, 1; cmp eax, 1;
jne end; jne end;
call LoadGame2_After; call LoadGame_After;
mov eax, 1; mov eax, 1;
end: end:
pop edx; pop edx;
pop ecx; pop ecx;
pop ebx; pop ebx;
@@ -230,58 +229,35 @@ end:
} }
} }
static void NewGame2() { static void __stdcall NewGame_Before() {
LoadGameHook::OnAfterNewGame.invoke(); LoadGameHook::OnBeforeGameLoad.invoke();
LoadGameHook::OnGameStart.invoke(); }
static void __stdcall NewGame_After() {
// TODO: Move this hack out
VarPtr::Meet_Frank_Horrigan = DisableHorrigan;
VarPtr::gmovie_played_list[3] = PipBoyAvailableAtGameStart;
LoadGameHook::OnAfterGameLoaded.invoke();
ResetState(0); ResetState(0);
dlogr("Starting new game", DL_MAIN); dlogr("New Game started.", DL_MAIN);
SetNewCharAppearanceGlobals(); SetNewCharAppearanceGlobals();
/*if (GetPrivateProfileInt("Misc", "PipBoyAvailableAtGameStart", 0, ini)) {
SafeWrite8(0x596C7B, 1);
}
if (GetPrivateProfileInt("Misc", "DisableHorrigan", 0, ini)) {
*(DWORD*)0x672E04 = 1;
}*/
LoadGlobalScripts(); LoadGlobalScripts();
CritLoad(); CritLoad();
LoadHeroAppearance();
} }
static bool DisableHorrigan = false; static void __declspec(naked) main_load_new_hook() {
static void __declspec(naked) NewGame() {
__asm { __asm {
pushad; pushad;
call NewGame2; call NewGame_Before;
mov al, DisableHorrigan; call FuncOffs::main_load_new_;
mov byte ptr ds:[VARPTR_Meet_Frank_Horrigan], al; call NewGame_After;
popad; popad;
call FuncOffs::main_game_loop_;
retn;
}
}
static void ReadExtraGameMsgFilesIfNeeded() {
if (gExtraGameMsgLists.empty()) {
ReadExtraGameMsgFiles();
}
}
static bool PipBoyAvailableAtGameStart = false;
static void __declspec(naked) MainMenuHook() {
__asm {
pushad;
push 0;
call ResetState;
mov al, PipBoyAvailableAtGameStart;
mov byte ptr ds:[VARPTR_gmovie_played_list + 0x3], al;
call ReadExtraGameMsgFilesIfNeeded;
call LoadHeroAppearance;
popad;
call FuncOffs::main_menu_loop_;
retn; retn;
} }
} }
@@ -438,6 +414,7 @@ void LoadGameHook::init() {
GetPrivateProfileString("sfall", "SaveInCombat", "Cannot save at this time", SaveFailMsg, 128, translationIni); GetPrivateProfileString("sfall", "SaveInCombat", "Cannot save at this time", SaveFailMsg, 128, translationIni);
GetPrivateProfileString("sfall", "SaveSfallDataFail", "ERROR saving extended savegame information! Check if other programs interfere with savegame files/folders and try again!", SaveSfallDataFailMsg, 128, translationIni); GetPrivateProfileString("sfall", "SaveSfallDataFail", "ERROR saving extended savegame information! Check if other programs interfere with savegame files/folders and try again!", SaveSfallDataFailMsg, 128, translationIni);
// TODO: move these patches someplace else
switch (GetPrivateProfileInt("Misc", "PipBoyAvailableAtGameStart", 0, ini)) { switch (GetPrivateProfileInt("Misc", "PipBoyAvailableAtGameStart", 0, ini)) {
case 1: case 1:
PipBoyAvailableAtGameStart = true; PipBoyAvailableAtGameStart = true;
@@ -452,7 +429,7 @@ void LoadGameHook::init() {
SafeWrite8(0x4C06D8, 0xEB); // skip the Horrigan encounter check SafeWrite8(0x4C06D8, 0xEB); // skip the Horrigan encounter check
} }
HookCall(0x480AB3, NewGame); HookCall(0x480AAE, main_load_new_hook);
HookCall(0x47C72C, LoadSlot); HookCall(0x47C72C, LoadSlot);
HookCall(0x47D1C9, LoadSlot); HookCall(0x47D1C9, LoadSlot);
@@ -463,8 +440,6 @@ void LoadGameHook::init() {
HookCall(0x443AAC, SaveGame); HookCall(0x443AAC, SaveGame);
HookCall(0x443B1C, SaveGame); HookCall(0x443B1C, SaveGame);
HookCall(0x48FCFF, SaveGame); HookCall(0x48FCFF, SaveGame);
HookCall(0x480A28, MainMenuHook);
HookCall(0x483668, WorldMapHook); HookCall(0x483668, WorldMapHook);
HookCall(0x4A4073, WorldMapHook); HookCall(0x4A4073, WorldMapHook);
+11 -4
View File
@@ -27,10 +27,17 @@ public:
const char* name() { return "LoadGameHook"; } const char* name() { return "LoadGameHook"; }
void init(); void init();
static Delegate<> OnBeforeLoadGame; // Invoked before game is being loaded (new game or saved game)
static Delegate<> OnAfterLoadGame; static Delegate<> OnBeforeGameLoad;
static Delegate<> OnAfterNewGame;
static Delegate<> OnGameStart; // Invoked after game has been loaded (new game or saved game)
static Delegate<> OnAfterGameLoaded;
// Invoked after new game has been started
//static Delegate<> OnAfterNewGame;
// Invoked after game has started (right after loading a save or starting a new game)
//static Delegate<> OnGameStart;
}; };
DWORD InWorldMap(); DWORD InWorldMap();
+1 -1
View File
@@ -110,7 +110,7 @@ void ClearReadExtraGameMsgFiles() {
} }
void Message::init() { void Message::init() {
ReadExtraGameMsgFiles();
} }
void Message::exit() { void Message::exit() {
-3
View File
@@ -34,8 +34,5 @@ class Message : public Module {
void exit() override; void exit() override;
}; };
// TODO: move out
void ReadExtraGameMsgFiles();
MessageNode *GetMsgNode(MessageList *msgList, int msgRef); MessageNode *GetMsgNode(MessageList *msgList, int msgRef);
char* GetMsg(MessageList *MsgList, int msgRef, int msgNum); char* GetMsg(MessageList *MsgList, int msgRef, int msgNum);
+2 -2
View File
@@ -884,6 +884,6 @@ void SetAppearanceGlobals(int race, int style) {
} }
void GetAppearanceGlobals(int *race, int *style) { void GetAppearanceGlobals(int *race, int *style) {
*race=GetGlobalVar("HAp_Race"); *race = GetGlobalVar("HAp_Race");
*style=GetGlobalVar("HApStyle"); *style = GetGlobalVar("HApStyle");
} }