Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Split event hooks into separate files
- Loading branch information
1 parent
bf28fb3
commit 2cebbb2
Showing
6 changed files
with
143 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include "stdafx.h" | ||
#include "Events.h" | ||
#include "CodeParser.hpp" | ||
|
||
std::vector<ModEvent> modFrameEvents; | ||
std::vector<ModEvent> modInputEvents; | ||
CodeParser codeParser; | ||
|
||
/** | ||
* Registers an event to the specified event list. | ||
* @param eventList The event list to add to. | ||
* @param module The module for the mod DLL. | ||
* @param name The name of the exported function from the module (i.e OnFrame) | ||
*/ | ||
void RegisterEvent(std::vector<ModEvent>& eventList, HMODULE module, const char* name) | ||
{ | ||
const ModEvent modEvent = (const ModEvent)GetProcAddress(module, name); | ||
|
||
if (modEvent != nullptr) | ||
eventList.push_back(modEvent); | ||
} | ||
|
||
void __cdecl OnFrame() | ||
{ | ||
codeParser.processCodeList(); | ||
RaiseEvents(modFrameEvents); | ||
} | ||
|
||
#pragma region OnFrame Initialization | ||
|
||
void* caseDefault_ptr = (void*)0x004340CC; | ||
void* case08_ptr = (void*)0x0043405D; | ||
void* case09_ptr = (void*)0x0043407E; | ||
void* case10_ptr = (void*)0x0043407E; | ||
|
||
void __declspec(naked) OnFrame_MidJump() | ||
{ | ||
__asm | ||
{ | ||
push eax | ||
call OnFrame | ||
pop eax | ||
|
||
pop edi | ||
pop esi | ||
pop ebp | ||
pop ebx | ||
pop ecx | ||
retn | ||
} | ||
} | ||
|
||
void* OnFrame_Hook_ptr = (void*)0x004340E7; | ||
void __declspec(naked) OnFrame_Hook() | ||
{ | ||
__asm | ||
{ | ||
push eax | ||
call OnFrame | ||
pop eax | ||
retn | ||
} | ||
} | ||
|
||
void InitOnFrame() | ||
{ | ||
WriteJump(case08_ptr, OnFrame_MidJump); | ||
WriteJump(case09_ptr, OnFrame_MidJump); | ||
WriteJump(case10_ptr, OnFrame_MidJump); | ||
|
||
// OnFrame caseDefault | ||
// Occurs if the current game mode isn't 8, 9 or 10, and byte_174AFF9 == 1 | ||
WriteJump(caseDefault_ptr, OnFrame_MidJump); | ||
|
||
// OnFrame OnFrame_Hook | ||
// Occurs at the end of the function (effectively the "else" to the statement above) | ||
WriteJump(OnFrame_Hook_ptr, OnFrame_Hook); | ||
} | ||
|
||
#pragma endregion | ||
|
||
void __cdecl OnInput() | ||
{ | ||
RaiseEvents(modInputEvents); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include "SA2ModLoader.h" | ||
#include "CodeParser.hpp" | ||
#include <vector> | ||
|
||
extern std::vector<ModEvent> modFrameEvents; | ||
extern std::vector<ModEvent> modInputEvents; | ||
extern CodeParser codeParser; | ||
|
||
void RegisterEvent(std::vector<ModEvent>& eventList, HMODULE module, const char* name); | ||
|
||
/** | ||
* Calls all registered events in the specified event list. | ||
* @param eventList The list of events to trigger. | ||
*/ | ||
static inline void RaiseEvents(const std::vector<ModEvent>& eventList) | ||
{ | ||
for (auto& i : eventList) | ||
i(); | ||
} | ||
|
||
void InitOnFrame(); | ||
void __cdecl OnInput(); | ||
void __cdecl OnFrame(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters