2017-01-20 08:36:52 -05:00
|
|
|
#pragma once
|
2017-05-13 06:09:58 -04:00
|
|
|
#include "Game/Structs.hpp"
|
2017-01-20 08:36:52 -05:00
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Script : public Component
|
|
|
|
{
|
|
|
|
public:
|
2017-05-13 06:09:58 -04:00
|
|
|
class Function
|
|
|
|
{
|
|
|
|
public:
|
2018-12-17 08:29:18 -05:00
|
|
|
Function(const std::string& _name, Game::scr_function_t _callback, bool _dev) : name(_name), callback(_callback), dev(_dev) {}
|
2017-05-13 06:09:58 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
Script();
|
|
|
|
~Script();
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
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);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2017-05-31 09:45:12 -04:00
|
|
|
static void OnVMShutdown(Utils::Slot<Scheduler::Callback> callback);
|
2017-05-14 14:14:52 -04:00
|
|
|
|
2022-01-07 16:00:44 -05:00
|
|
|
static Game::gentity_t* GetEntFromEntRef(const Game::scr_entref_t entref);
|
|
|
|
static Game::client_t* GetClientFromEnt(const Game::gentity_t* gentity);
|
2020-07-22 23:36:35 -04:00
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
private:
|
|
|
|
static std::string ScriptName;
|
|
|
|
static std::vector<int> ScriptHandles;
|
2017-05-13 06:09:58 -04:00
|
|
|
static std::vector<Function> ScriptFunctions;
|
2017-01-19 16:23:59 -05:00
|
|
|
static std::vector<std::string> ScriptNameStack;
|
|
|
|
static unsigned short FunctionName;
|
2020-12-04 17:42:47 -05:00
|
|
|
static std::unordered_map<std::string, std::string> ScriptStorage;
|
2020-12-16 22:49:26 -05:00
|
|
|
static std::unordered_map<int, std::string> ScriptBaseProgramNum;
|
2021-11-13 08:15:27 -05:00
|
|
|
static std::unordered_map<const char*, const char*> ReplacedFunctions;
|
|
|
|
static const char* ReplacedPos;
|
2020-12-19 17:50:51 -05:00
|
|
|
static int LastFrameTime;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2017-05-31 09:45:12 -04:00
|
|
|
static Utils::Signal<Scheduler::Callback> VMShutdownSignal;
|
2017-05-14 14:14:52 -04:00
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
static void CompileError(unsigned int offset, const char* message, ...);
|
|
|
|
static void PrintSourcePos(const char* filename, unsigned int offset);
|
|
|
|
|
|
|
|
static void FunctionError();
|
|
|
|
static void StoreFunctionNameStub();
|
2022-01-23 14:32:20 -05:00
|
|
|
static void RuntimeError(const char* codePos, unsigned int index, const char* msg, const char* dialogMessage);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
static void StoreScriptName(const char* name);
|
|
|
|
static void StoreScriptNameStub();
|
|
|
|
|
|
|
|
static void RestoreScriptName();
|
|
|
|
static void RestoreScriptNameStub();
|
|
|
|
|
|
|
|
static void LoadGameType();
|
|
|
|
static void LoadGameTypeScript();
|
2017-04-29 17:08:41 -04:00
|
|
|
|
2017-05-14 14:14:52 -04:00
|
|
|
static Game::scr_function_t GetFunction(void* caller, const char** name, int* isDev);
|
2017-05-13 06:09:58 -04:00
|
|
|
static void GetFunctionStub();
|
|
|
|
|
2017-05-14 14:14:52 -04:00
|
|
|
static void ScrShutdownSystemStub(int);
|
2020-12-08 17:14:47 -05:00
|
|
|
static void StoreScriptBaseProgramNumStub();
|
|
|
|
static void StoreScriptBaseProgramNum();
|
|
|
|
static void Scr_PrintPrevCodePosStub();
|
|
|
|
static void Scr_PrintPrevCodePos(int);
|
2017-05-14 14:14:52 -04:00
|
|
|
|
2021-11-13 08:22:06 -05:00
|
|
|
static unsigned int SetExpFogStub();
|
2020-12-04 17:42:47 -05:00
|
|
|
|
2021-11-13 15:46:58 -05:00
|
|
|
static const char* GetCodePosForParam(int index);
|
2021-11-13 08:15:27 -05:00
|
|
|
static void GetReplacedPos(const char* pos);
|
|
|
|
static void SetReplacedPos(const char* what, const char* with);
|
|
|
|
static void VMExecuteInternalStub();
|
|
|
|
|
2020-12-04 17:42:47 -05:00
|
|
|
static void AddFunctions();
|
2017-01-19 16:23:59 -05:00
|
|
|
};
|
|
|
|
}
|