upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/mods.h
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 23:14:27 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 23:14:27 -0500
commit98fa503f8a19c3ed65df1f4f2f0e4571aa42c4f7 (patch)
tree9f17c922e8deebaa4d0cd0a8eb59125349f5bda0 /runtime/src/mods.h
parent0db7fed551c4d48d7b97a9c4d609fc11d17ae19c (diff)
Mods: first-person view, the base (camera section, view-mode getter hook)
mod.json gains "camera": {"view_mode": "first_person"|"default", "first_person_value", "contexts"}. gta6rt --view-mode-getter RVA hooks the game's view-mode getter with a result-override thunk (code_hooks.h: the original runs, then its result and first argument go through leonida::mods::override_view_mode), so the listed contexts answer first person and the others keep the game's mode. mods/first_person asks for it on foot. docs/modding.md records why switching a mode is enough: the game's tuning data refers to a first-person view (FirstPersonDirectionDot, UseFirstPersonCameraMatrix on cloth capsules, FIRST_PERSON_VIEW hit-reaction recovery, a firstpersonshooter HUD texture; RDR2's engine branch), while GTA V's camera class names are not present by joaat. The context numbering and the first-person enum value (4, GTA V's) are manifest settings to confirm in the executable. ctest mods and code_hooks cover the parser, the override and the thunk on x64 code in memory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/mods.h')
-rw-r--r--runtime/src/mods.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/runtime/src/mods.h b/runtime/src/mods.h
index 5f23e9883..c308ed7db 100644
--- a/runtime/src/mods.h
+++ b/runtime/src/mods.h
@@ -49,12 +49,24 @@ struct ArchetypeSwap {
49 std::string when = "always"; 49 std::string when = "always";
50}; 50};
51 51
52// "camera": the view mode the game's view-mode getter answers (docs/modding.md, "First-person view"). The getter
53// takes a context (on foot, in a vehicle, ...) and returns an enum; `first_person_value` is that enum's first-person
54// value, 4 in GTA V's camViewModeSettings, to be confirmed in the executable. `contexts`: the getter's first-argument
55// values to override; empty = every context.
56struct CameraView {
57 bool set = false; // the mod has a "camera" section
58 bool first_person = false; // "view_mode": "first_person" (else "default": leave the game's choice)
59 uint32_t first_person_value = 4;
60 std::vector<uint32_t> contexts;
61};
62
52struct Mod { 63struct Mod {
53 std::string folder; // the folder name under mods/ 64 std::string folder; // the folder name under mods/
54 std::string name; 65 std::string name;
55 std::string game_version; 66 std::string game_version;
56 bool enabled = true; 67 bool enabled = true;
57 std::vector<ArchetypeSwap> archetype_swaps; 68 std::vector<ArchetypeSwap> archetype_swaps;
69 CameraView camera;
58}; 70};
59 71
60struct LoadResult { 72struct LoadResult {
@@ -135,6 +147,40 @@ inline bool parse_mod(std::string_view text, const std::string& folder, Mod& mod
135 mod.archetype_swaps.push_back(std::move(swap)); 147 mod.archetype_swaps.push_back(std::move(swap));
136 } 148 }
137 } 149 }
150 if (const Json* cam = root.find("camera")) {
151 if (cam->kind != Json::Kind::object) {
152 error = "\"camera\" must be an object";
153 return false;
154 }
155 mod.camera.set = true;
156 const Json* view = cam->find("view_mode");
157 if (!view || view->kind != Json::Kind::string ||
158 (view->string != "first_person" && view->string != "default")) {
159 error = "\"camera\": \"view_mode\" must be \"first_person\" or \"default\"";
160 return false;
161 }
162 mod.camera.first_person = view->string == "first_person";
163 if (const Json* v = cam->find("first_person_value")) {
164 if (v->kind != Json::Kind::number || v->number < 0 || v->number > 255 || v->number != static_cast<int>(v->number)) {
165 error = "\"camera\": \"first_person_value\" must be a whole number 0-255";
166 return false;
167 }
168 mod.camera.first_person_value = static_cast<uint32_t>(v->number);
169 }
170 if (const Json* c = cam->find("contexts")) {
171 if (c->kind != Json::Kind::array) {
172 error = "\"camera\": \"contexts\" must be a list of numbers";
173 return false;
174 }
175 for (const Json& x : c->array) {
176 if (x.kind != Json::Kind::number || x.number < 0 || x.number != static_cast<int>(x.number)) {
177 error = "\"camera\": \"contexts\" must be a list of whole numbers";
178 return false;
179 }
180 mod.camera.contexts.push_back(static_cast<uint32_t>(x.number));
181 }
182 }
183 }
138 return true; 184 return true;
139} 185}
140 186
@@ -199,4 +245,30 @@ inline ArchetypeSwaps& active_slot() {
199inline void set_active(ArchetypeSwaps swaps) { active_slot() = std::move(swaps); } 245inline void set_active(ArchetypeSwaps swaps) { active_slot() = std::move(swaps); }
200inline const ArchetypeSwaps& active() { return active_slot(); } 246inline const ArchetypeSwaps& active() { return active_slot(); }
201 247
248// The camera override of the enabled mods: the last one (in folder order) with a "camera" section decides.
249inline CameraView camera_of(const std::vector<Mod>& mods) {
250 CameraView view;
251 for (const Mod& m : mods)
252 if (m.enabled && m.camera.set) view = m.camera;
253 return view;
254}
255
256inline CameraView& camera_slot() {
257 static CameraView view;
258 return view;
259}
260inline void set_active_camera(CameraView view) { camera_slot() = std::move(view); }
261
262// What the hooked view-mode getter returns: the mod's first-person value for an overridden context, else the game's.
263inline uint32_t override_view_mode(uint32_t result, uint32_t context) {
264 const CameraView& v = camera_slot();
265 if (!v.first_person) return result;
266 if (!v.contexts.empty()) {
267 bool listed = false;
268 for (uint32_t c : v.contexts) listed = listed || c == context;
269 if (!listed) return result;
270 }
271 return v.first_person_value;
272}
273
202} // namespace leonida::mods 274} // namespace leonida::mods