blob: 5e837a60bac45d6836c92b057f737618db12e896 (
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
|
#include "mods/modmanager.h"
#include "core/filesystem/filesystem.h"
#include "squirrel/squirrel.h"
#include <fstream>
const std::string MOD_SCRIPTS_RSON_SUFFIX = "scripts/vscripts/scripts.rson";
const char* VPK_SCRIPTS_RSON_PATH = "scripts\\vscripts\\scripts.rson";
void ModManager::BuildScriptsRson()
{
spdlog::info("Building custom scripts.rson");
fs::path MOD_SCRIPTS_RSON_PATH = fs::path(GetCompiledAssetsPath() / MOD_SCRIPTS_RSON_SUFFIX);
fs::remove(MOD_SCRIPTS_RSON_PATH);
std::string scriptsRson = R2::ReadVPKOriginalFile(VPK_SCRIPTS_RSON_PATH);
scriptsRson += "\n\n// START MODDED SCRIPT CONTENT\n\n"; // newline before we start custom stuff
for (Mod& mod : GetMods() | ModManager::FilterEnabled)
{
// this isn't needed at all, just nice to have imo
scriptsRson += "// MOD: ";
scriptsRson += mod.Name;
scriptsRson += ":\n\n";
for (ModScript& script : mod.Scripts)
{
/* should create something with this format for each script
When: "CONTEXT"
Scripts:
[
_coolscript.gnut
]*/
scriptsRson += "When: \"";
scriptsRson += script.RunOn;
scriptsRson += "\"\n";
scriptsRson += "Scripts:\n[\n\t";
scriptsRson += script.Path;
scriptsRson += "\n]\n\n";
}
}
fs::create_directories(MOD_SCRIPTS_RSON_PATH.parent_path());
std::ofstream writeStream(MOD_SCRIPTS_RSON_PATH, std::ios::binary);
writeStream << scriptsRson;
writeStream.close();
ModOverrideFile overrideFile;
overrideFile.m_pOwningMod = nullptr;
overrideFile.m_Path = VPK_SCRIPTS_RSON_PATH;
if (GetModFiles().find(VPK_SCRIPTS_RSON_PATH) == GetModFiles().end())
GetModFiles().insert(std::make_pair(VPK_SCRIPTS_RSON_PATH, overrideFile));
else
GetModFiles()[VPK_SCRIPTS_RSON_PATH] = overrideFile;
// todo: for preventing dupe scripts in scripts.rson, we could actually parse when conditions with the squirrel vm, just need a way to
// get a result out of squirrelmanager.ExecuteCode this would probably be the best way to do this, imo
}
|