mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 22:58:37 +00:00
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>
115 lines
6.1 KiB
C++
115 lines
6.1 KiB
C++
// mods.h: mod.json manifests and archetype swaps (docs/modding.md). No game files.
|
|
#include "../src/mods.h"
|
|
|
|
#include <cstdio>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <string>
|
|
|
|
namespace {
|
|
|
|
int g_checks = 0, g_failures = 0;
|
|
|
|
void check(bool ok, const char* what) {
|
|
++g_checks;
|
|
if (!ok) {
|
|
++g_failures;
|
|
std::printf("FAIL %s\n", what);
|
|
}
|
|
}
|
|
|
|
void write(const std::filesystem::path& p, const std::string& text) {
|
|
std::filesystem::create_directories(p.parent_path());
|
|
std::ofstream(p, std::ios::binary) << text;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main() {
|
|
using namespace leonida::mods;
|
|
|
|
// The model ids docs/character_skeleton.md measured in the packs tables are the joaat of their names.
|
|
static_assert(joaat("player_story000_00") == 0xE472B687u, "Lucia's player model id");
|
|
static_assert(joaat("cs_mandy") == 0xD7C0CDFFu, "cs_mandy's model id");
|
|
static_assert(joaat("mandy") == 0x03A885E6u, "Mandy's PERSCHARS name hash");
|
|
static_assert(joaat("CS_Mandy") == joaat("cs_mandy"), "joaat lower-cases");
|
|
|
|
uint32_t id = 0;
|
|
check(parse_model_id("0xD7C0CDFF", id) && id == 0xD7C0CDFFu, "a 0x hash is taken as it is");
|
|
check(parse_model_id("cs_monalisa", id) && id == 0x9CB9BCC6u, "a name is hashed");
|
|
check(!parse_model_id("0x123456789", id), "a hash wider than 32 bits is refused");
|
|
check(!parse_model_id("0xZZ", id), "a malformed hash is refused");
|
|
check(!parse_model_id("", id), "an empty name is refused");
|
|
|
|
Mod mod;
|
|
std::string error;
|
|
check(parse_mod(R"({"name":"Mandy","archetype_swaps":[{"from":"player_story000_00","to":"cs_mandy"}]})", "m",
|
|
mod, error) && mod.enabled && mod.archetype_swaps.size() == 1 &&
|
|
mod.archetype_swaps[0].from == 0xE472B687u && mod.archetype_swaps[0].to == 0xD7C0CDFFu,
|
|
"a swap parses into the two model ids");
|
|
check(!parse_mod(R"({"archetype_swaps":[{"from":"a","to":"b","when":"mission:intro"}]})", "m", mod, error) &&
|
|
error.find("\"when\"") != std::string::npos,
|
|
"a condition the runtime cannot honour yet is refused, not ignored");
|
|
check(!parse_mod(R"({"archetype_swaps":[{"from":"cs_mandy","to":"0xD7C0CDFF"}]})", "m", mod, error),
|
|
"a swap of a model with itself is refused");
|
|
check(!parse_mod(R"({"enabled":"yes"})", "m", mod, error), "\"enabled\" must be a boolean");
|
|
check(!parse_mod("[1,2]", "m", mod, error), "a manifest that is not an object is refused");
|
|
check(parse_mod("{}", "folder_name", mod, error) && mod.name == "folder_name", "the name defaults to the folder");
|
|
|
|
// "camera": first-person view (docs/modding.md, "First-person view")
|
|
check(parse_mod(R"({"camera":{"view_mode":"first_person","first_person_value":4,"contexts":[0]}})", "fp", mod,
|
|
error) && mod.camera.set && mod.camera.first_person && mod.camera.first_person_value == 4 &&
|
|
mod.camera.contexts.size() == 1 && mod.camera.contexts[0] == 0,
|
|
"a first-person camera section parses");
|
|
check(parse_mod(R"({"camera":{"view_mode":"default"}})", "d", mod, error) && mod.camera.set &&
|
|
!mod.camera.first_person,
|
|
"\"default\" leaves the game's view mode");
|
|
check(!parse_mod(R"({"camera":{"view_mode":"top_down"}})", "x", mod, error), "an unknown view mode is refused");
|
|
check(!parse_mod(R"({"camera":{"view_mode":"first_person","first_person_value":4.5}})", "x", mod, error),
|
|
"a fractional enum value is refused");
|
|
check(!parse_mod(R"({"camera":{"view_mode":"first_person","contexts":"all"}})", "x", mod, error),
|
|
"contexts must be a list");
|
|
|
|
Mod fp_on_foot, fp_everywhere, off;
|
|
check(parse_mod(R"({"camera":{"view_mode":"first_person","contexts":[0]}})", "a", fp_on_foot, error) &&
|
|
parse_mod(R"({"camera":{"view_mode":"first_person","first_person_value":7}})", "b", fp_everywhere,
|
|
error) &&
|
|
parse_mod(R"({"enabled":false,"camera":{"view_mode":"default"}})", "c", off, error),
|
|
"three camera mods parse");
|
|
set_active_camera(camera_of({fp_on_foot}));
|
|
check(override_view_mode(2, 0) == 4, "on foot (context 0) the view becomes first person");
|
|
check(override_view_mode(2, 1) == 2, "a context the mod does not list keeps the game's view");
|
|
set_active_camera(camera_of({fp_on_foot, fp_everywhere, off}));
|
|
check(override_view_mode(1, 5) == 7, "the last enabled camera mod decides (a disabled one is skipped)");
|
|
set_active_camera(camera_of({}));
|
|
check(override_view_mode(3, 0) == 3, "with no camera mod the game's view mode passes through");
|
|
|
|
const auto dir = std::filesystem::temp_directory_path() / "leonida_mods_test";
|
|
std::filesystem::remove_all(dir);
|
|
write(dir / "a_mandy" / "mod.json",
|
|
R"({"name":"Mandy","archetype_swaps":[{"from":"player_story000_00","to":"cs_mandy","when":"always"}]})");
|
|
write(dir / "b_off" / "mod.json",
|
|
R"({"name":"Off","enabled":false,"archetype_swaps":[{"from":"cs_mandy","to":"cs_monalisa"}]})");
|
|
write(dir / "c_broken" / "mod.json", "{not json");
|
|
write(dir / "d_notes" / "readme.txt", "not a mod");
|
|
write(dir / "e_later" / "mod.json", R"({"archetype_swaps":[{"from":"player_story000_00","to":"cs_monalisa"}]})");
|
|
|
|
const LoadResult loaded = load_mods(dir);
|
|
check(loaded.mods.size() == 3, "three manifests load (the broken one and the folder without one do not)");
|
|
check(loaded.errors.size() == 1 && loaded.errors[0].rfind("c_broken:", 0) == 0, "the broken one is reported");
|
|
|
|
const ArchetypeSwaps swaps(loaded.mods);
|
|
check(swaps.remap(0xE472B687u) == joaat("cs_monalisa"), "a later folder wins for the same model");
|
|
check(swaps.remap(0xD7C0CDFFu) == 0xD7C0CDFFu, "a disabled mod swaps nothing");
|
|
check(swaps.remap(0x12345678u) == 0x12345678u, "a model no mod names is left alone");
|
|
|
|
const ArchetypeSwaps mandy_only({loaded.mods[0]});
|
|
check(mandy_only.remap(0xE472B687u) == 0xD7C0CDFFu, "the Mandy mod swaps Lucia's player model for cs_mandy");
|
|
|
|
check(load_mods(dir / "missing").mods.empty(), "no mods folder is no mods");
|
|
std::filesystem::remove_all(dir);
|
|
|
|
std::printf("mods_test: %d checks, %d failures\n", g_checks, g_failures);
|
|
return g_failures == 0 ? 0 : 1;
|
|
}
|