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
|
#include "2s2h/config/ConfigUpdaters.h"
#include "2s2h/Enhancements/Enhancements.h"
#include "2s2h/Enhancements/Trackers/DisplayOverlay.h"
namespace Ben {
struct Migration {
const char* from;
const char* to;
};
static void ApplyMigrationActions(const Migration* migrations) {
while (migrations->from != nullptr) {
if (migrations->to != nullptr) {
CVarCopy(migrations->from, migrations->to);
}
CVarClear(migrations->from);
migrations++;
}
}
static const Migration version1Migrations[] = {
{ "gFixes.FixAmmoCountEnvColor", "gFixes.FixButtonEnvColor" },
{ nullptr, nullptr },
};
static bool HasDisplayOverlayModeInConfig(Ship::Config* conf) {
if (!conf->GetNestedJson().contains("CVars")) {
return false;
}
const auto& cvars = conf->GetNestedJson()["CVars"];
return cvars.contains("gDisplayOverlay") && cvars["gDisplayOverlay"].is_object() &&
cvars["gDisplayOverlay"].contains("Mode");
}
static void MigrateDisplayOverlayTimerMode(Ship::Config* conf) {
if (!HasDisplayOverlayModeInConfig(conf)) {
return;
}
int oldVal = CVarGetInteger("gWindows.DisplayOverlay", 0);
if (oldVal == TIMER_DISPLAY_RTA || oldVal == TIMER_DISPLAY_IGT) {
CVarSetInteger(CVAR_DISPLAY_OVERLAY_MODE, oldVal);
CVarSetInteger("gWindows.DisplayOverlay", 1);
} else {
CVarSetInteger(CVAR_DISPLAY_OVERLAY_MODE, TIMER_DISPLAY_NONE);
CVarSetInteger("gWindows.DisplayOverlay", 0);
}
}
static void MigrateWarpPoints(Ship::Config* conf) {
if (conf->GetNestedJson().contains("CVars")) {
if (CVarGetInteger("gDeveloperTools.WarpPoint.Saved", 0) != 0) {
auto warpPoints = nlohmann::json::object();
s32 entranceId = CVarGetInteger("gDeveloperTools.WarpPoint.Entrance", 0);
s8 roomNum = CVarGetInteger("gDeveloperTools.WarpPoint.Room", 0);
Vec3f pos = { CVarGetFloat("gDeveloperTools.WarpPoint.X", 0.0f),
CVarGetFloat("gDeveloperTools.WarpPoint.Y", 0.0f),
CVarGetFloat("gDeveloperTools.WarpPoint.Z", 0.0f) };
s16 rotY = CVarGetFloat("gDeveloperTools.WarpPoint.Rotation", 0.0f);
bool bootToPoint = CVarGetInteger("gDeveloperTools.WarpPoint.BootToWarpPoint", 0) > 0;
warpPoints["Debug Warp Point"] = { { "entranceId", entranceId },
{ "roomNum", roomNum },
{ "pos", { { "x", pos.x }, { "y", pos.y }, { "z", pos.z } } },
{ "rotY", rotY },
{ "bootToPoint", bootToPoint } };
Ship::Context::GetRawInstance()->GetConfig()->SetBlock("WarpPoints", warpPoints);
}
}
}
ConfigVersion1Updater::ConfigVersion1Updater() : ConfigVersionUpdater(1) {
}
void ConfigVersion1Updater::Update(Ship::Config* conf) {
ApplyMigrationActions(version1Migrations);
MigrateDisplayOverlayTimerMode(conf);
MigrateWarpPoints(conf);
}
} // namespace Ben
|