Added custom gsc calls

This commit is contained in:
ineedbots 2021-06-29 11:55:00 -06:00
parent aa485079de
commit e0b9522e34
3 changed files with 48 additions and 8 deletions

View File

@ -3,14 +3,47 @@
namespace Components
{
Game::xmethod_t* Script::Player_GetMethod_Hook(const char** name)
std::unordered_map<std::string, Game::scr_function_t> Script::CustomScrFunctions;
std::unordered_map<std::string, Game::scr_method_t> Script::CustomScrMethods;
void Script::AddFunction(const char* name, Game::xfunction_t func, int type)
{
return Game::Player_GetMethod(name);
Game::scr_function_t toAdd;
toAdd.call = func;
toAdd.name = name;
toAdd.developer = type;
CustomScrFunctions.insert_or_assign(name, toAdd);
}
Game::xfunction_t* Script::Scr_GetFunction_Hook(const char** name, int* isDev)
void Script::AddMethod(const char* name, Game::xmethod_t func, int type)
{
return Game::Scr_GetFunction(name, isDev);
Game::scr_method_t toAdd;
toAdd.call = func;
toAdd.name = name;
toAdd.developer = type;
CustomScrMethods.insert_or_assign(name, toAdd);
}
Game::xmethod_t Script::Player_GetMethod_Hook(const char** name)
{
auto got = CustomScrMethods.find(*name);
if (got == CustomScrMethods.end())
return Game::Player_GetMethod(name);
return got->second.call;
}
Game::xfunction_t Script::Scr_GetFunction_Hook(const char** name, int* isDev)
{
auto got = CustomScrFunctions.find(*name);
if (got == CustomScrFunctions.end())
return Game::Scr_GetFunction(name, isDev);
return got->second.call;
}
Script::Script()
@ -21,5 +54,7 @@ namespace Components
Script::~Script()
{
CustomScrFunctions.clear();
CustomScrMethods.clear();
}
}

View File

@ -5,10 +5,15 @@ namespace Components
class Script : public Component
{
public:
static void AddFunction(const char*, Game::xfunction_t, int = 0);
static void AddMethod(const char*, Game::xmethod_t, int = 0);
Script();
~Script();
private:
static Game::xmethod_t* Player_GetMethod_Hook(const char**);
static Game::xfunction_t* Scr_GetFunction_Hook(const char**, int*);
static std::unordered_map<std::string, Game::scr_function_t> CustomScrFunctions;
static std::unordered_map<std::string, Game::scr_method_t> CustomScrMethods;
static Game::xmethod_t Player_GetMethod_Hook(const char**);
static Game::xfunction_t Scr_GetFunction_Hook(const char**, int*);
};
}

View File

@ -33,10 +33,10 @@ namespace Game
extern bgs_s** bgs_ptr;
typedef Game::xmethod_t* (Player_GetMethod_t)(const char**);
typedef Game::xmethod_t (Player_GetMethod_t)(const char**);
extern Player_GetMethod_t* Player_GetMethod;
typedef Game::xfunction_t* (Scr_GetFunction_t)(const char**, int*);
typedef Game::xfunction_t (Scr_GetFunction_t)(const char**, int*);
extern Scr_GetFunction_t* Scr_GetFunction;
extern void G_SelectWeaponIndex(int, int);