aboutsummaryrefslogtreecommitdiff
path: root/src/plugin.h
blob: 2d3d2d975371297f9ebe2e30fb6cfe5a2e6a82f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef PLUGIN_H
#define PLUGIN_H

#include <vector>

#include "ns_plugin.h"
#include "internal/concommandproxy.h"
#include "internal/convarproxy.h"

class rpc_server;

class Plugin {
    private:
        PluginInitFuncs funcs = { 0 };
        PluginNorthstarData data = { 0 };
        EngineData engine_data = { 0 };

        SquirrelFunctions client_sqvm_funcs = { 0 };
        SquirrelFunctions server_sqvm_funcs = { 0 };

        CSquirrelVM client_vm = { 0 };
        CSquirrelVM server_vm = { 0 };
        CSquirrelVM ui_vm = { 0 }; // uses same functions as client

        HMODULE engine = nullptr;
        struct {
            Cbuf_GetCurrentPlayerType Cbuf_GetCurrentPlayer;
            Cbuf_AddTextType Cbuf_AddText;
            Cbuf_ExecuteType Cbuf_Execute;
        } engine_funcs = { 0 };

        rpc_server* server = nullptr;

        std::vector<ConCommandProxy*> commands;
        std::vector<ConVarProxy*> variables;

        HMODULE GetModuleByName(const char* name);

    public:
        Plugin(PluginInitFuncs* funcs, PluginNorthstarData* data);
        ~Plugin();

        void LoadEngineData(void* data);
        void LoadSQVMFunctions(ScriptContext context, SquirrelFunctions* funcs);
        void LoadSQVM(ScriptContext context, CSquirrelVM* sqvm);
        void RemoveSQVM(ScriptContext context);

        void StartServer();
        void RunCommand(const char* cmd);
        SQRESULT RunSquirrelCode(ScriptContext context, std::string code, SQObject* ret_val);

        // Wraps around the internals we receive
        ConCommandProxy* ConCommand(const char* name, FnCommandCallback_t callback, const char* helpString, int flags, void* parent = nullptr);
        ConVarProxy* ConVar(const char* pszName, const char* pszDefaultValue, int nFlags, const char* pszHelpString, bool bMin = 0, float fMin = 0, bool bMax = 0, float fMax = 0, FnChangeCallback_t pCallback = nullptr);
};

#endif