diff --git a/mods/README.md b/mods/README.md index 46eb160..bfd7a70 100644 --- a/mods/README.md +++ b/mods/README.md @@ -43,6 +43,11 @@ tools/charmod.py hits noctis # every hit of every move A mod folder is data only: JSON, models, skins, pictures, sounds. The build refuses a folder with a script or program in it, so a shared mod can't carry code. Zip `mods//` and send it. Don't share `.blend` files to install (Blender can run scripts saved in them), and never run a script that came with a mod; nothing here needs one. +**A finished mod on a game with no build step (Android, a release install):** put it in the game's mods folder as +`//mod.json` plus `install/` holding the built files at their game paths (`install/obj/...`, +`install/textures/...`). It shows up in *Settings > Mods* and turns on and off from there (next start). Details: +[docs/loose-file-mods.md](../psprecomp/games/dissidia/docs/loose-file-mods.md), "Installed mod folders". + ## Everything else Field by field: `mod.json`, the moveset files, every avatar, bodies, weapons (the model and weapons a character wants), every timeline event and how a move fits together: [docs/character-mods.md](../psprecomp/games/dissidia/docs/character-mods.md). What every event does in the game: [docs/moves-and-events.md](../psprecomp/games/dissidia/docs/moves-and-events.md). diff --git a/psprecomp/ARCHITECTURE.md b/psprecomp/ARCHITECTURE.md index a69043b..aed3b9b 100644 --- a/psprecomp/ARCHITECTURE.md +++ b/psprecomp/ARCHITECTURE.md @@ -104,7 +104,7 @@ lives entirely under `games//`: | Artifact | Consumed by | Carries | |----------|-------------|---------| | `games//game.toml` | `psprecomp recompile --config` | `[recompile]` force entries / force mid-entries (replaces the former hardcoded consts), top-level stubs/skips/patches, and `[game]`/`[boot]`/`[module]`/`[runtime]` choices emitted into `recomp_game_config.h` (the runtime never parses TOML) | -| `games//runtime/*.cpp` | runtime build via `-DPSPRECOMP_GAME=` | Address-keyed dispatch hooks, allocator/CRT override bodies, boot/thread context tweaks, asset layer, IO policy, LOOKUP_MISS handler, GE vertex fallback — everything title-specific that is code, not data (Dissidia: `hooks_main.cpp` overlay resolver and module binding, `hooks_io.cpp` + `package_mods.cpp` loose-file mods, `roster.cpp`, `savedata_theme.cpp`, `camera.cpp`, `input.cpp`, `framerate.cpp` native 60 Hz battle logic, …) | +| `games//runtime/*.cpp` | runtime build via `-DPSPRECOMP_GAME=` | Address-keyed dispatch hooks, allocator/CRT override bodies, boot/thread context tweaks, asset layer, IO policy, LOOKUP_MISS handler, GE vertex fallback — everything title-specific that is code, not data (Dissidia: `hooks_main.cpp` overlay resolver and module binding, `hooks_io.cpp` + `package_mods.cpp` loose-file mods (plus installed mod folders: `//mod.json` + `install/`, served as one more mods root while enabled, so Settings > Mods can turn a finished mod on and off on any platform), `roster.cpp`, `savedata_theme.cpp`, `camera.cpp`, `input.cpp`, `framerate.cpp` native 60 Hz battle logic, …) | | `games//tests/`, `games//scripts/` | manual / CI | Game-coupled tests and scripts (optional; `games/dissidia/tests/`) | The seam is `PspGameModule` (`runtime/include/psp_game_module.h`): one struct of diff --git a/psprecomp/games/dissidia/docs/loose-file-mods.md b/psprecomp/games/dissidia/docs/loose-file-mods.md index c897ef0..284e01e 100644 --- a/psprecomp/games/dissidia/docs/loose-file-mods.md +++ b/psprecomp/games/dissidia/docs/loose-file-mods.md @@ -17,6 +17,23 @@ mods/menu/jp/battle/chara_image/p_fiv100.gim mods/by_crc/0a1b2c3d.bin replaces the entry with that CRC32 (hex) - for assets not in the path list ``` +**Installed mod folders (one toggle per mod, any platform):** a folder in the mods directory with a `mod.json` and an +`install/` folder holding files at their game paths is one mod the settings menu can turn on and off (*Settings > Mods*, +applies at the next start). While its `mod.json` does not say `"enabled": false`, `install/` counts as one more mods +directory: its `obj/`, `by_crc/` ... files override the game's, its `textures/` joins the texture pack, and its `obj/` +counts for the model budget. Loose files in the mods directory itself win over a folder's, and folders go in name order. +A folder with a `mod.json` is never read as part of the loose-file tree. This is how a finished mod ships to a game with no +build step at start (Android, a release install): + +``` +mods/nt-lightning/mod.json {"name": "Lightning: Dissidia NT model", "enabled": true, ...} +mods/nt-lightning/install/obj/p_gst130_1p.gmo +mods/nt-lightning/install/textures/fc0807432147e17e.png +``` + +The log says `[MODS] mod folder on: ...` / `[MODS] mod folder : off` and `[TEXPACK] mod folder pack ...`. (`hooks_io.cpp` +`mod_roots`, `package_mods.cpp` `walk`, `hooks_models.cpp` `prescan_mods_for_budget`, `psp_tex_pack.cpp` extra dirs.) + **Blender add-on:** `blender/` holds the Dissidia character add-on (import from the ISO, model, animate, edit move events, export); `python3 blender/build_addon.py` builds the installable zip. Guide: [blender/README.md](../../../../blender/README.md). **Move Studio:** `studio/index.html` (open in Chrome): one place for a character's moves: the animation in 3D, its events on a timeline, each hit's damage and knock-back, saved straight into the mod folder. Guide: [studio/README.md](../../../../studio/README.md). What every event does: [docs/moves-and-events.md](moves-and-events.md). diff --git a/psprecomp/games/dissidia/runtime/hooks_io.cpp b/psprecomp/games/dissidia/runtime/hooks_io.cpp index cc25c49..7841db9 100644 --- a/psprecomp/games/dissidia/runtime/hooks_io.cpp +++ b/psprecomp/games/dissidia/runtime/hooks_io.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include // roster.cpp: in-flight data patches of the overlay blobs (extra roster slots). @@ -43,6 +44,7 @@ extern bool dissidia_roster_enabled(); extern int dissidia_roster_overlay_of(const char* lower_path); extern void dissidia_roster_patch_overlay(int mod, int64_t off, uint32_t size, uint8_t* dest); std::string dissidia_mods_dir(); +std::vector dissidia_mod_roots(); extern uint32_t dissidia_model_budget_request(uint32_t bytes); extern uint32_t dissidia_model_budget(); @@ -189,6 +191,48 @@ std::string mods_dir() { return parent + "/mods"; } +// Installed mod folders: //mod.json + /install/ holding files at their game paths (obj/..., textures/..., +// by_crc/...). While the mod.json does not say "enabled": false, install/ is one more mods root: its files override the game's +// like loose files in do, its textures/ joins the texture pack. The settings menu's Mods page lists these folders and +// turns them on and off (applies at the next start). Loose files in itself win over a folder's. +bool mod_json_off(const std::string& path) { + std::ifstream f(path, std::ios::binary); + if (!f) return false; + const std::string js((std::istreambuf_iterator(f)), std::istreambuf_iterator()); + const size_t k = js.find("\"enabled\""); + if (k == std::string::npos) return false; + size_t v = js.find(':', k); + if (v == std::string::npos) return false; + ++v; + while (v < js.size() && std::isspace((unsigned char)js[v])) ++v; + return js.compare(v, 5, "false") == 0; +} +std::vector mod_roots() { + static bool logged = false; // asked from several places at start: say which folders are off once + const bool say = !logged; + logged = true; + std::vector out; + const std::string dir = mods_dir(); + DIR* d = ::opendir(dir.c_str()); + if (!d) return out; + std::vector names; + while (dirent* e = ::readdir(d)) { + const std::string n = e->d_name; + if (n.empty() || n[0] == '.' || n[0] == '_') continue; + names.push_back(n); + } + ::closedir(d); + std::sort(names.begin(), names.end()); + struct stat st; + for (const std::string& n : names) { + const std::string root = dir + "/" + n; + if (::stat((root + "/mod.json").c_str(), &st) != 0 || ::stat((root + "/install").c_str(), &st) != 0 || !S_ISDIR(st.st_mode)) continue; + if (mod_json_off(root + "/mod.json")) { if (say) std::fprintf(stderr, "[MODS] mod folder %s: off\n", n.c_str()); continue; } + out.push_back(root + "/install"); + } + return out; +} + // Voice language (settings "Voice", PSPRECOMP_VOICE=en|jp). `jp` serves the Japanese voice pack that // tools/jp_audio.py extracted from an undub / Japanese disc: archive entries from /voice_jp (loose // files, scanned after the mods) and movies from /movie_jp. @@ -221,7 +265,8 @@ void ensure_built(const std::string& host_info_path) { if (g_built) return; g_built = true; std::string dir = mods_dir(); - std::vector extra; + std::vector extra = mod_roots(); // installed mod folders that are on, then the voice pack + for (const std::string& r : extra) std::fprintf(stderr, "[MODS] mod folder on: %s\n", r.c_str()); if (voice_jp_on()) { const std::string vd = work_parent() + "/voice_jp"; if (is_dir(vd)) { extra.push_back(vd); std::fprintf(stderr, "[VOICE] Japanese voice pack: %s\n", vd.c_str()); } @@ -343,6 +388,7 @@ bool overlay_read(int tag, int host_fd, int64_t off, uint32_t size, uint8_t* des } // namespace std::string dissidia_mods_dir() { return mods_dir(); } +std::vector dissidia_mod_roots() { return mod_roots(); } std::string dissidia_package_dir() { return g_data_dir; } void dissidia_add_asset_patch(const std::string& asset, std::function&)> edit) { AssetPatch p; @@ -373,9 +419,18 @@ void dissidia_install_mod_io() { psp_io_set_policy(policy); // The settings menu offers a Voice row once a Japanese voice pack has been extracted (tools/jp_audio.py). psp_settings_set_voice_hook({+[]() { return is_dir(work_parent() + "/voice_jp"); }}); - psp_settings_set_texpack_hook({+[]() { return is_dir(mods_dir() + "/textures"); }}); - // Texture packs (runtime/include/psp_tex_pack.h) live under /textures. + psp_settings_set_texpack_hook({+[]() { + if (is_dir(mods_dir() + "/textures")) return true; + for (const std::string& r : mod_roots()) if (is_dir(r + "/textures")) return true; + return false; + }}); + // Texture packs (runtime/include/psp_tex_pack.h) live under /textures, and the textures/ of each installed mod folder that is on. psp_texpack_set_dir_provider([]() -> std::string { return mods_dir() + "/textures"; }); + psp_texpack_set_extra_dirs_provider([]() -> std::vector { + std::vector v; + for (const std::string& r : mod_roots()) if (is_dir(r + "/textures")) v.push_back(r + "/textures"); + return v; + }); // FX shader overrides (runtime/include/psp_fx_shader.h, FX_SHADERS.md) live under /fx_shaders. psp_fx_set_dir_provider([]() -> std::string { return mods_dir() + "/fx_shaders"; }); } diff --git a/psprecomp/games/dissidia/runtime/hooks_models.cpp b/psprecomp/games/dissidia/runtime/hooks_models.cpp index 91ac292..81a4740 100644 --- a/psprecomp/games/dissidia/runtime/hooks_models.cpp +++ b/psprecomp/games/dissidia/runtime/hooks_models.cpp @@ -48,8 +48,10 @@ #include #include #include +#include std::string dissidia_mods_dir(); +std::vector dissidia_mod_roots(); // hooks_io.cpp: installed mod folders that are on uint32_t dissidia_model_budget_request(uint32_t bytes); namespace { @@ -126,20 +128,24 @@ void reserve_blocks() { void prescan_mods_for_budget() { namespace fs = std::filesystem; std::error_code ec; - const std::string dir = dissidia_mods_dir(); - if (dir.empty() || !fs::is_directory(dir, ec)) return; + std::vector dirs{dissidia_mods_dir()}; + for (const std::string& r : dissidia_mod_roots()) dirs.push_back(r); uint64_t biggest = 0; - // Only the obj/ folder holds model overrides, so only it is walked. (The whole mods tree also holds the HD texture pack, thousands of - // files; walking it with fs::relative() canonicalised every path and took about 5 s of the start-up on Android's shared storage.) - for (fs::directory_iterator top(dir, fs::directory_options::skip_permission_denied, ec), tend; !ec && top != tend; top.increment(ec)) { - std::string name = top->path().filename().generic_string(); - for (char& c : name) c = static_cast(std::tolower(static_cast(c))); - if (name != "obj" || !top->is_directory(ec)) continue; - std::error_code ec2; - for (fs::recursive_directory_iterator it(top->path(), fs::directory_options::skip_permission_denied, ec2), end; !ec2 && it != end; it.increment(ec2)) { - if (!it->is_regular_file(ec2)) continue; - biggest = std::max(biggest, it->file_size(ec2)); + for (const std::string& dir : dirs) { // and the installed mod folders that are on + if (dir.empty() || !fs::is_directory(dir, ec)) { ec.clear(); continue; } + // Only the obj/ folder holds model overrides, so only it is walked. (The whole mods tree also holds the HD texture pack, thousands of + // files; walking it with fs::relative() canonicalised every path and took about 5 s of the start-up on Android's shared storage.) + for (fs::directory_iterator top(dir, fs::directory_options::skip_permission_denied, ec), tend; !ec && top != tend; top.increment(ec)) { + std::string name = top->path().filename().generic_string(); + for (char& c : name) c = static_cast(std::tolower(static_cast(c))); + if (name != "obj" || !top->is_directory(ec)) continue; + std::error_code ec2; + for (fs::recursive_directory_iterator it(top->path(), fs::directory_options::skip_permission_denied, ec2), end; !ec2 && it != end; it.increment(ec2)) { + if (!it->is_regular_file(ec2)) continue; + biggest = std::max(biggest, it->file_size(ec2)); + } } + ec.clear(); } if (biggest > g_staging) { const uint32_t b = dissidia_model_budget_request(static_cast(std::min(biggest, 0xFFFFFFFFull))); diff --git a/psprecomp/games/dissidia/runtime/package_mods.cpp b/psprecomp/games/dissidia/runtime/package_mods.cpp index 8ceb95a..aeae890 100644 --- a/psprecomp/games/dissidia/runtime/package_mods.cpp +++ b/psprecomp/games/dissidia/runtime/package_mods.cpp @@ -67,7 +67,11 @@ void walk(const std::string& root, const std::string& rel, std::vectorpush_back(r); } } diff --git a/psprecomp/runtime/include/psp_tex_pack.h b/psprecomp/runtime/include/psp_tex_pack.h index 9629abb..4add64e 100644 --- a/psprecomp/runtime/include/psp_tex_pack.h +++ b/psprecomp/runtime/include/psp_tex_pack.h @@ -24,6 +24,11 @@ using PspTexPackDirFn = std::string (*)(); /// after psp_io_init). Without a provider the default is /mods/textures. void psp_texpack_set_dir_provider(PspTexPackDirFn fn); +/// More replacement folders (installed mod folders' textures/): their .png join the pack; the main pack wins on the same id. +/// Called once with the pack. Replacements only (dumps and textures.ini stay in the main pack). +using PspTexPackDirsFn = std::vector (*)(); +void psp_texpack_set_extra_dirs_provider(PspTexPackDirsFn fn); + /// True when any of dump / replacement (non-empty pack) / upscale is on. /// Cheap after the first call; when false ge_texture_bind computes no ids. bool psp_texpack_active(); diff --git a/psprecomp/runtime/src/psp_tex_pack.cpp b/psprecomp/runtime/src/psp_tex_pack.cpp index d1e4d59..5c0e2c5 100644 --- a/psprecomp/runtime/src/psp_tex_pack.cpp +++ b/psprecomp/runtime/src/psp_tex_pack.cpp @@ -22,6 +22,7 @@ namespace { PspTexPackDirFn g_provider = nullptr; +PspTexPackDirsFn g_extra_provider = nullptr; // ---- xxHash64 (stable across runs/platforms; little-endian word reads) ---- constexpr uint64_t P1 = 11400714785074694791ull, P2 = 14029467366897019727ull, @@ -70,7 +71,8 @@ struct State { int upscale = 0; // 2..4 int repl_filter = 0; std::string dir, dump_dir, index_path; - std::unordered_set pack; // ids with .png in the pack dir + std::unordered_set pack; // ids with .png in the pack dir (or an extra dir) + std::unordered_map extra_dir; // ids found only in an extra dir: that dir std::unordered_set bad; // replacement files that failed to load std::map seen; // sorted -> stable index file bool dirty = false; @@ -194,16 +196,27 @@ void init_once() { load_index(); std::fprintf(stderr, "[TEXPACK] dump on: %s (cap %zu)\n", g.dump_dir.c_str(), g.dump_max); } - if (want_replace && is_dir(g.dir)) { - if (DIR* d = opendir(g.dir.c_str())) { + std::vector extra = g_extra_provider ? g_extra_provider() : std::vector{}; + if (want_replace && (is_dir(g.dir) || !extra.empty())) { + auto scan = [](const std::string& dir, bool main) { + DIR* d = opendir(dir.c_str()); + if (!d) return; while (dirent* de = readdir(d)) { size_t n = std::strlen(de->d_name); if (n != 20 || std::strcmp(de->d_name + 16, ".png")) continue; std::string stem(de->d_name, 16); uint64_t id; - if (parse_hex16(stem.c_str(), &id)) g.pack.insert(id); + if (!parse_hex16(stem.c_str(), &id)) continue; + if (main) { g.pack.insert(id); g.extra_dir.erase(id); } + else if (g.pack.insert(id).second) g.extra_dir[id] = dir; } closedir(d); + }; + scan(g.dir, true); + for (auto& x : extra) { + while (x.size() > 1 && x.back() == '/') x.pop_back(); + scan(x, false); + std::fprintf(stderr, "[TEXPACK] mod folder pack %s\n", x.c_str()); } g.replace = true; std::fprintf(stderr, "[TEXPACK] replacement pack %s: %zu texture(s)%s\n", g.dir.c_str(), @@ -215,6 +228,7 @@ void init_once() { } // namespace void psp_texpack_set_dir_provider(PspTexPackDirFn fn) { g_provider = fn; } +void psp_texpack_set_extra_dirs_provider(PspTexPackDirsFn fn) { g_extra_provider = fn; } bool psp_texpack_active() { init_once(); @@ -469,7 +483,8 @@ bool psp_texpack_load_replacement(uint64_t id, std::vector& rgba, int& if (!g.replace || !g.pack.count(id) || g.bad.count(id)) return false; char name[40]; std::snprintf(name, sizeof name, "/%016llx.png", (unsigned long long)id); - const bool ok = load_png_cached(id, g.dir + name, rgba, w, h); + auto xd = g.extra_dir.find(id); + const bool ok = load_png_cached(id, (xd != g.extra_dir.end() ? xd->second : g.dir) + name, rgba, w, h); static const bool log_ids = std::getenv("PSPRECOMP_TEXPACK_LOG_IDS") != nullptr; // one line per id the first time it is bound if (ok && log_ids) { static std::set seen;