#pragma once #include "Game/Structs.hpp" namespace Components { class Script : public Component { public: class Function { public: Function(const std::string& _name, Game::scr_function_t _callback, bool _dev) : name(_name), callback(_callback), dev(_dev) {} const char* getName() const { return this->name.data(); } bool isDev() const { return this->dev; } Game::scr_function_t getFunction() const { return this->callback; } private: std::string name; Game::scr_function_t callback; bool dev; }; Script(); ~Script(); static int LoadScriptAndLabel(const std::string& script, const std::string& label); static void AddFunction(const std::string& name, Game::scr_function_t function, bool isDev = false); static void OnVMShutdown(Utils::Slot callback); static Game::gentity_t* GetEntFromEntRef(const Game::scr_entref_t entref); static Game::client_t* GetClientFromEnt(const Game::gentity_t* gentity); private: static std::string ScriptName; static std::vector ScriptHandles; static std::vector ScriptFunctions; static std::vector ScriptNameStack; static unsigned short FunctionName; static std::unordered_map ScriptStorage; static std::unordered_map ScriptBaseProgramNum; static std::unordered_map ReplacedFunctions; static const char* ReplacedPos; static int LastFrameTime; static Utils::Signal VMShutdownSignal; static void CompileError(unsigned int offset, const char* message, ...); static void PrintSourcePos(const char* filename, unsigned int offset); static void FunctionError(); static void StoreFunctionNameStub(); static void RuntimeError(const char*, unsigned int, const char*, const char*); static void StoreScriptName(const char* name); static void StoreScriptNameStub(); static void RestoreScriptName(); static void RestoreScriptNameStub(); static void LoadGameType(); static void LoadGameTypeScript(); static Game::scr_function_t GetFunction(void* caller, const char** name, int* isDev); static void GetFunctionStub(); static void ScrShutdownSystemStub(int); static void StoreScriptBaseProgramNumStub(); static void StoreScriptBaseProgramNum(); static void Scr_PrintPrevCodePosStub(); static void Scr_PrintPrevCodePos(int); static unsigned int SetExpFogStub(); static const char* GetCodePosForParam(int index); static void GetReplacedPos(const char* pos); static void SetReplacedPos(const char* what, const char* with); static void VMExecuteInternalStub(); static void AddFunctions(); }; }