mirror of
https://github.com/ineedbots/cod2m.git
synced 2025-04-19 08:02:52 +00:00
Some custom scruipt loading hooks
This commit is contained in:
parent
e0b9522e34
commit
984825fe51
@ -5,25 +5,24 @@ namespace Components
|
||||
{
|
||||
std::unordered_map<std::string, Game::scr_function_t> Script::CustomScrFunctions;
|
||||
std::unordered_map<std::string, Game::scr_method_t> Script::CustomScrMethods;
|
||||
std::vector<unsigned int> Script::CustomScrHandles;
|
||||
|
||||
void Script::AddFunction(const char* name, Game::xfunction_t func, int type)
|
||||
{
|
||||
Game::scr_function_t toAdd;
|
||||
toAdd.call = func;
|
||||
toAdd.name = name;
|
||||
toAdd.developer = type;
|
||||
|
||||
CustomScrFunctions.insert_or_assign(name, toAdd);
|
||||
CustomScrFunctions.insert_or_assign(Utils::String::ToLower(name), toAdd);
|
||||
}
|
||||
|
||||
void Script::AddMethod(const char* name, Game::xmethod_t func, int type)
|
||||
{
|
||||
Game::scr_method_t toAdd;
|
||||
toAdd.call = func;
|
||||
toAdd.name = name;
|
||||
toAdd.developer = type;
|
||||
|
||||
CustomScrMethods.insert_or_assign(name, toAdd);
|
||||
CustomScrMethods.insert_or_assign(Utils::String::ToLower(name), toAdd);
|
||||
}
|
||||
|
||||
Game::xmethod_t Script::Player_GetMethod_Hook(const char** name)
|
||||
@ -36,6 +35,16 @@ namespace Components
|
||||
return got->second.call;
|
||||
}
|
||||
|
||||
void Script::GScr_LoadGameTypeScript_Hook()
|
||||
{
|
||||
Game::GScr_LoadGameTypeScript();
|
||||
}
|
||||
|
||||
void Script::G_LoadStructs_Hook()
|
||||
{
|
||||
Game::G_LoadStructs();
|
||||
}
|
||||
|
||||
Game::xfunction_t Script::Scr_GetFunction_Hook(const char** name, int* isDev)
|
||||
{
|
||||
auto got = CustomScrFunctions.find(*name);
|
||||
@ -43,18 +52,26 @@ namespace Components
|
||||
if (got == CustomScrFunctions.end())
|
||||
return Game::Scr_GetFunction(name, isDev);
|
||||
|
||||
*isDev = got->second.developer;
|
||||
return got->second.call;
|
||||
}
|
||||
|
||||
Script::Script()
|
||||
{
|
||||
// custom gsc calls
|
||||
Utils::Hook(0x46E9CB, Player_GetMethod_Hook, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x46E7BF, Scr_GetFunction_Hook, HOOK_CALL).install()->quick();
|
||||
|
||||
// load custom scripts
|
||||
Utils::Hook(0x4FC75F, G_LoadStructs_Hook, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x5043FA, GScr_LoadGameTypeScript_Hook, HOOK_CALL).install()->quick();
|
||||
|
||||
}
|
||||
|
||||
Script::~Script()
|
||||
{
|
||||
CustomScrFunctions.clear();
|
||||
CustomScrMethods.clear();
|
||||
CustomScrHandles.clear();
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,12 @@ namespace Components
|
||||
private:
|
||||
static std::unordered_map<std::string, Game::scr_function_t> CustomScrFunctions;
|
||||
static std::unordered_map<std::string, Game::scr_method_t> CustomScrMethods;
|
||||
static std::vector<unsigned int> CustomScrHandles;
|
||||
|
||||
static Game::xmethod_t Player_GetMethod_Hook(const char**);
|
||||
static Game::xfunction_t Scr_GetFunction_Hook(const char**, int*);
|
||||
|
||||
static void GScr_LoadGameTypeScript_Hook();
|
||||
static void G_LoadStructs_Hook();
|
||||
};
|
||||
}
|
||||
|
@ -28,14 +28,19 @@ namespace Game
|
||||
|
||||
bgs_s** bgs_ptr;
|
||||
|
||||
|
||||
Player_GetMethod_t* Player_GetMethod;
|
||||
Scr_LoadScript_t* Scr_LoadScript;
|
||||
Scr_GetFunction_t* Scr_GetFunction;
|
||||
Player_GetMethod_t* Player_GetMethod;
|
||||
GScr_LoadGameTypeScript_t* GScr_LoadGameTypeScript;
|
||||
G_LoadStructs_t* G_LoadStructs;
|
||||
|
||||
void Init(GAMEEXE)
|
||||
{
|
||||
Player_GetMethod = ASSIGN(Player_GetMethod_t*, 0x52E050);
|
||||
Scr_GetFunction = ASSIGN(Scr_GetFunction_t*, 0x50D280);
|
||||
Scr_LoadScript = ASSIGN(Scr_LoadScript_t*, 0x474D80);
|
||||
GScr_LoadGameTypeScript = ASSIGN(GScr_LoadGameTypeScript_t*, 0x503F90);
|
||||
G_LoadStructs = ASSIGN(G_LoadStructs_t*, 0x5118A0);
|
||||
|
||||
|
||||
cls = ASSIGN(clientStatic_t*, 0x68A408);
|
||||
@ -65,6 +70,49 @@ namespace Game
|
||||
bgs_ptr = ASSIGN(bgs_s**, 0x19A1C78);
|
||||
}
|
||||
|
||||
unsigned int Scr_GetFunctionHandle(char* filename, const char* funcHandle)
|
||||
{
|
||||
int func_loc = 0x474950;
|
||||
unsigned int answer;
|
||||
|
||||
__asm
|
||||
{
|
||||
push funcHandle;
|
||||
mov eax, filename;
|
||||
call func_loc;
|
||||
add esp, 4;
|
||||
mov answer, eax;
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
__int16 Scr_ExecThread(int handle)
|
||||
{
|
||||
int func_loc = 0x482080;
|
||||
__int16 answer;
|
||||
|
||||
__asm
|
||||
{
|
||||
mov eax, handle;
|
||||
call func_loc;
|
||||
mov answer, ax;
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
void RemoveRefToObject(int obj)
|
||||
{
|
||||
int func_loc = 0x479660;
|
||||
|
||||
__asm
|
||||
{
|
||||
mov eax, obj;
|
||||
call func_loc;
|
||||
}
|
||||
}
|
||||
|
||||
void G_SelectWeaponIndex(int wpIdx, int clNum)
|
||||
{
|
||||
int func_loc = 0x5282E0;
|
||||
|
@ -32,6 +32,19 @@ namespace Game
|
||||
extern stringIndex_t* scr_const;
|
||||
|
||||
extern bgs_s** bgs_ptr;
|
||||
|
||||
typedef int (Scr_LoadScript_t)(char*);
|
||||
extern Scr_LoadScript_t* Scr_LoadScript;
|
||||
|
||||
typedef void (GScr_LoadGameTypeScript_t)();
|
||||
extern GScr_LoadGameTypeScript_t* GScr_LoadGameTypeScript;
|
||||
|
||||
typedef void (G_LoadStructs_t)();
|
||||
extern G_LoadStructs_t* G_LoadStructs;
|
||||
|
||||
extern unsigned int Scr_GetFunctionHandle(char*, const char*);
|
||||
extern __int16 Scr_ExecThread(int);
|
||||
extern void RemoveRefToObject(int);
|
||||
|
||||
typedef Game::xmethod_t (Player_GetMethod_t)(const char**);
|
||||
extern Player_GetMethod_t* Player_GetMethod;
|
||||
|
Loading…
x
Reference in New Issue
Block a user