blob: df3cd1d3e3a64a16f1c0c12598782ab94ee97da7 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#pragma once
#include "convar.h"
#include <string>
#include <vector>
#include <filesystem>
namespace fs = std::filesystem;
const fs::path MOD_FOLDER_PATH = "R2Northstar/mods";
const fs::path MOD_OVERRIDE_DIR = "mod";
const fs::path COMPILED_ASSETS_PATH = "R2Northstar/runtime/compiled";
struct ModConVar
{
public:
std::string Name;
std::string DefaultValue;
std::string HelpString;
int Flags;
};
struct ModScriptCallback
{
public:
// would've liked to make it possible to hook arbitrary codecallbacks, but couldn't find a function that calls some ui ones
//std::string HookedCodeCallback;
Context Context;
// called before the codecallback is executed
std::string BeforeCallback;
// called after the codecallback has finished executing
std::string AfterCallback;
};
struct ModScript
{
public:
std::string Path;
std::string RsonRunOn;
std::vector<ModScriptCallback> Callbacks;
};
class Mod
{
public:
// runtime stuff
fs::path ModDirectory;
bool Enabled = true;
// mod.json stuff:
// the mod's name
std::string Name;
// the mod's description
std::string Description;
// the mod's version, should be in semver
std::string Version;
// a download link to the mod, for clients that try to join without the mod
std::string DownloadLink;
// whether clients need the mod to join servers running this mod
bool RequiredOnClient;
// the priority for this mod's files, mods with prio 0 are loaded first, then 1, then 2, etc
int LoadPriority;
// custom scripts used by the mod
std::vector<ModScript> Scripts;
// convars created by the mod
std::vector<ModConVar> ConVars;
// custom localisation files created by the mod
std::vector<std::string> LocalisationFiles;
// other files:
std::vector<std::string> Vpks;
std::vector<std::string> KeyValues;
std::vector<size_t> KeyValuesHash; // size_t because we hash these filesnames: faster than string comp
// other stuff
bool wasReadSuccessfully = false;
public:
Mod(fs::path modPath, char* jsonBuf);
};
struct ModOverrideFile
{
public:
Mod* owningMod;
fs::path path;
};
class ModManager
{
public:
std::vector<Mod> m_loadedMods;
std::unordered_map<std::string, ModOverrideFile> m_modFiles;
public:
ModManager();
void LoadMods();
void UnloadMods();
void CompileAssetsForFile(const char* filename);
// compile asset type stuff, these are done in files under Mods/Compiled/
void BuildScriptsRson();
void TryBuildKeyValues(const char* filename);
};
void InitialiseModManager(HMODULE baseAddress);
extern std::unique_ptr<ModManager> g_ModManager;
|