Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>/` 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
`<mods>/<name>/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).
2 changes: 1 addition & 1 deletion psprecomp/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ lives entirely under `games/<id>/`:
| Artifact | Consumed by | Carries |
|----------|-------------|---------|
| `games/<id>/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/<id>/runtime/*.cpp` | runtime build via `-DPSPRECOMP_GAME=<id>` | 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/<id>/runtime/*.cpp` | runtime build via `-DPSPRECOMP_GAME=<id>` | 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: `<mods>/<folder>/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/<id>/tests/`, `games/<id>/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
Expand Down
17 changes: 17 additions & 0 deletions psprecomp/games/dissidia/docs/loose-file-mods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name>: 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).
Expand Down
61 changes: 58 additions & 3 deletions psprecomp/games/dissidia/runtime/hooks_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <iterator>
#include <string>
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>

// roster.cpp: in-flight data patches of the overlay blobs (extra roster slots).
Expand All @@ -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<std::string> dissidia_mod_roots();
extern uint32_t dissidia_model_budget_request(uint32_t bytes);
extern uint32_t dissidia_model_budget();

Expand Down Expand Up @@ -189,6 +191,48 @@ std::string mods_dir() {
return parent + "/mods";
}

// Installed mod folders: <mods>/<folder>/mod.json + <folder>/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 <mods> 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 <mods> 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<char>(f)), std::istreambuf_iterator<char>());
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<std::string> 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<std::string> out;
const std::string dir = mods_dir();
DIR* d = ::opendir(dir.c_str());
if (!d) return out;
std::vector<std::string> 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 <workdir>/voice_jp (loose
// files, scanned after the mods) and movies from <workdir>/movie_jp.
Expand Down Expand Up @@ -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<std::string> extra;
std::vector<std::string> 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()); }
Expand Down Expand Up @@ -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<std::string> 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<bool(std::vector<uint8_t>&)> edit) {
AssetPatch p;
Expand Down Expand Up @@ -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 <mods>/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 <mods>/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::string> {
std::vector<std::string> 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 <mods>/fx_shaders.
psp_fx_set_dir_provider([]() -> std::string { return mods_dir() + "/fx_shaders"; });
}
30 changes: 18 additions & 12 deletions psprecomp/games/dissidia/runtime/hooks_models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@
#include <cstring>
#include <filesystem>
#include <string>
#include <vector>

std::string dissidia_mods_dir();
std::vector<std::string> dissidia_mod_roots(); // hooks_io.cpp: installed mod folders that are on
uint32_t dissidia_model_budget_request(uint32_t bytes);

namespace {
Expand Down Expand Up @@ -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<std::string> 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<char>(std::tolower(static_cast<unsigned char>(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<uint64_t>(biggest, it->file_size(ec2));
for (const std::string& dir : dirs) { // <mods> 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<char>(std::tolower(static_cast<unsigned char>(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<uint64_t>(biggest, it->file_size(ec2));
}
}
ec.clear();
}
if (biggest > g_staging) {
const uint32_t b = dissidia_model_budget_request(static_cast<uint32_t>(std::min<uint64_t>(biggest, 0xFFFFFFFFull)));
Expand Down
6 changes: 5 additions & 1 deletion psprecomp/games/dissidia/runtime/package_mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ void walk(const std::string& root, const std::string& rel, std::vector<std::stri
if (::stat((root + "/" + r).c_str(), &st) != 0) continue;
t = S_ISDIR(st.st_mode) ? DT_DIR : S_ISREG(st.st_mode) ? DT_REG : DT_UNKNOWN;
}
if (t == DT_DIR) walk(root, r, out);
if (t == DT_DIR) {
struct stat ms; // an installed mod folder (hooks_io.cpp mod_roots): its install/ is a root of its own, when it is on
if (::stat((root + "/" + r + "/mod.json").c_str(), &ms) == 0) continue;
walk(root, r, out);
}
else if (t == DT_REG) out->push_back(r);
}
}
Expand Down
5 changes: 5 additions & 0 deletions psprecomp/runtime/include/psp_tex_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ using PspTexPackDirFn = std::string (*)();
/// after psp_io_init). Without a provider the default is <ms0 parent>/mods/textures.
void psp_texpack_set_dir_provider(PspTexPackDirFn fn);

/// More replacement folders (installed mod folders' textures/): their <id>.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<std::string> (*)();
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();
Expand Down
25 changes: 20 additions & 5 deletions psprecomp/runtime/src/psp_tex_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<uint64_t> pack; // ids with <id>.png in the pack dir
std::unordered_set<uint64_t> pack; // ids with <id>.png in the pack dir (or an extra dir)
std::unordered_map<uint64_t, std::string> extra_dir; // ids found only in an extra dir: that dir
std::unordered_set<uint64_t> bad; // replacement files that failed to load
std::map<uint64_t, Rec> seen; // sorted -> stable index file
bool dirty = false;
Expand Down Expand Up @@ -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<std::string> extra = g_extra_provider ? g_extra_provider() : std::vector<std::string>{};
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(),
Expand All @@ -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();
Expand Down Expand Up @@ -469,7 +483,8 @@ bool psp_texpack_load_replacement(uint64_t id, std::vector<uint8_t>& 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<uint64_t> seen;
Expand Down
Loading