diff --git a/psprecomp/games/dissidia/docs/README.md b/psprecomp/games/dissidia/docs/README.md index 5c900a0..728c916 100644 --- a/psprecomp/games/dissidia/docs/README.md +++ b/psprecomp/games/dissidia/docs/README.md @@ -32,6 +32,7 @@ Short guides next to the tools, and the full reference here: - [spawned-objects.md](spawned-objects.md): the `wpnp` table and the objects `hold_prop` / `summon_object` spawn (Gilgamesh's swords, Yuna's aeons). - [effects.md](effects.md): how the game draws effects (placement, timing, colour and blending, every component), and corrections to the FEP notes. - [audio.md](audio.md): extra BGM tracks, voice banks. +- [related-projects.md](related-projects.md): other Dissidia 012 projects (VCKing101's port, DissidiaDecompProject, RecompLauncher), credited, and what is worth taking from them. - [recomp-status.md](recomp-status.md): how the native build came together (October 2026), and soak-test findings. Historical. - [character-lighting.md](character-lighting.md): live key and rim lighting on character bodies in the native build (`body.lighting`). - [spring-bones.md](spring-bones.md): how the game swings capes, hair, skirts and weapon chains, and giving a mod character a physics cape. diff --git a/psprecomp/games/dissidia/docs/native-build.md b/psprecomp/games/dissidia/docs/native-build.md index ede824c..09ee5ec 100644 --- a/psprecomp/games/dissidia/docs/native-build.md +++ b/psprecomp/games/dissidia/docs/native-build.md @@ -132,3 +132,29 @@ axes, so in battle the original runs on a square-gate version of the stick with (`PSPRECOMP_ANALOG_DPAD_ZONE`, default 0.35 of travel; `PSPRECOMP_ANALOG_8WAY=0` turns it off). `PSPRECOMP_ANALOG_FULL=0` restores the original 8-way behaviour, `PSPRECOMP_ANALOG_DEADZONE` (default 0.20 of travel) sets the radial dead zone, `PSPRECOMP_ANALOG_LOG=` logs raw / game / replacement vectors. + +Walking direction: the stick vector above is not what steers a walk. The walker's input (`ovl_battle FUN_08B38A0C`, on the world map +and for the player's fighter in battle) builds its step from the four walk bits only, so even with the changes above every walk went one +of eight ways (found by VCKing101, [related-projects.md](related-projects.md)). `input.cpp` turns that step to the stick's own direction +just before the game applies the camera to it, for the hardware pad's walker with the stick past the dead zone; when the walk starts, the +walk speed and everything after it stay the game's. On the world map and in battle; never while the pads are fed by the game's online +exchange or a replay. A saved battle replay stores just the 8-way bits, so a fight steered by the stick can play back a little +differently; `PSPRECOMP_ANALOG_WALK_BATTLE=0` keeps battle 8-way (and replays exact). `PSPRECOMP_ANALOG_WALK=0` turns it all off, +`PSPRECOMP_ANALOG_WALK_LOG=` logs n replaced steps, `PSPRECOMP_ANALOG_WALK_OUTLOG=` the walk's world-space output. +Measured 18-19 November 2026: on the prologue field (debug socket `A` pushes of 0.4 s, walker position at `+0x110`) 15, -15 and 30 +degrees of stick turned the walk by 14.8, 15.0 and 30.2 degrees against a straight push, where the 8-way walk jumps by 20 to 45. In +battle (battle_test, Squall, stage 12, stick 0 then 15 degrees) the walk's world direction turned 15.6 degrees and the fighter moved +along it to within 1 to 3 degrees a frame (more while the body turns); with the 8-way walk it stayed on one direction for 0, 15 and -15. +Comparing world headings between separate battle runs does not work: the lock-on camera orbits the opponent, and the dummy stands +somewhere else each run. + +Camera follow dead zone: the world map's free camera (`ovl_battle FUN_08B3F7F4`) turns toward the walker's facing by up to 0.05 rad a +frame with no dead zone. With the walk at the stick's own angle, a push a few degrees off straight up then turns the camera, the +camera-relative walk turns with it, and the camera spins (VCKing101's measurement; here with `PSPRECOMP_CAM_UNLOCK_HOLD=0` and no +zone, a 15 degree push turned the walk 186 degrees in 1.75 s). `input.cpp` moves the follow's atan2 result (`FUN_089A457C`, only the +call on the walker's facing) so the follow does not turn within `PSPRECOMP_ANALOG_FOLLOW_ZONE` degrees, ramps up to the cap over half the zone, and is +the game's beyond that; only while the walker's last step was the analogue one. Default 180: the camera does not follow a walk with +the stick at all, since the right stick turns it (asked for 19 November 2026: the left stick also swung the camera left and right); +22.5 is VCKing101's zone, 0 the game's follow. Walking with the D-pad keeps the game's follow. With it the same push walked straight. Normally `camera.cpp`'s hold camera is active on the world map too (no lock-on target): +it keeps the view and turns the stick by the game camera's turn, which already hides the spin; the zone covers the cases without it +(`PSPRECOMP_CAM_UNLOCK_HOLD=0`, `PSPRECOMP_CAM_FREE=0`). `PSPRECOMP_ANALOG_FOLLOW_LOG=` logs reduced follow turns. diff --git a/psprecomp/games/dissidia/docs/related-projects.md b/psprecomp/games/dissidia/docs/related-projects.md new file mode 100644 index 0000000..e219af1 --- /dev/null +++ b/psprecomp/games/dissidia/docs/related-projects.md @@ -0,0 +1,136 @@ +# Related projects: what we can learn from them + +Surveyed 18 November 2026. Three other Dissidia 012 projects, what they have that this project does not, and what is +worth taking. Addresses in their notes are for the USA release (ULUS10566), but the main executable and the overlays +load at the same addresses as ours, so they can be used directly (checked: their `0x08872138` is our +`FUN_08872138`, the pad dead-zone routine; their `0x0889F234` is our BGM playback `FUN_0889F234`). + +## Credits and licences + +- **[VCKing101/Dissidia012-pc](https://github.com/VCKing101/Dissidia012-pc)**, by VCKing101. A native port built + on [PortableKit](https://github.com/TeamGDB/PortableKit), plus a matching decompilation. MIT licence (copyright + 2026 VCKing101) for its port code, tools and docs. Its `NOTICE.md` says the MIT licence does **not** cover the + decompiled C in `src/`, `include/` and `port/decomp/`. So: research facts and designs from its docs can be + used with credit. Code from `port/host/` or `tools/` may be copied only with the MIT notice kept. Do not copy the + decompiled C. Write our own from their notes. +- **[RocherBrockas/DissidiaDecompProject](https://github.com/RocherBrockas/DissidiaDecompProject)**, by Pierre + Brossy. An early decompilation setup (splat, Ghidra scripts, a `PACKAGE.BIN` extractor, per-format notes). MIT. + Some format notes in it are credited to Sky Noxt. +- **[RecompLauncher](https://recomplauncher.com/game/dissidia012-pc)**: a launcher that lists recomps from their + GitHub repos, installs them, and runs their setup from the player's disc image. VCKing101's port is listed there. + +Anything added to this project from these sources must name the source in the commit message and in the doc or code +comment it lands in. Use a link to the repo and the file it came from. + +## Worth taking, most useful first + +### 1. Analogue walking: the direction is still 8-way (bug in ours) + +**Done** for the world map and battle (18-19 November 2026, `runtime/input.cpp`, [native-build.md](native-build.md)); battle replays +may play back a little differently. The camera follow dead zone below is done too (same file). + +Source: [docs/port/analog-movement.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/analog-movement.md). + +Our `input.cpp` replaces the stick vector that `FUN_08872138` writes. Their notes show that **nothing in the walk +reads that vector**. The walker's input is `ovl_battle 0x08B38A0C`, called once a frame from `0x08B36D2C` with +`(out, walker, pad, camera)`. It builds a camera-space step from the four "walk" bits only (+-1 on x and z), so every +walk direction is one of eight. Lowering the per-axis dead zone (`PSPRECOMP_ANALOG_DPAD_ZONE`) changes when a bit +appears, not the angle. This applies on the world map, and in battle too: the fighter under the player's pad calls the +same function. + +Their fix: override `0x08B38A0C` and, when the walk bits come from the stick (the "move with analog stick" option, pad +table B at `0x08B7F380`), use the real stick direction in camera space. Set the walker's direction flags at +`walker+0x5B0` as the 8-way bits would be (each axis within 67.5 degrees). Leave the rest as the game does it. The walk +speed stays the same, because the output is a unit direction. + +Two cautions from them: +- **Replays.** A battle replay records only the 8-way bits (`0x08889628` -> `0x088CA680`, 15 bits a frame). Analogue + steering in battle makes a saved replay play back differently. They keep battle 8-way by default. Netplay is safe + if both machines are fed the same bytes. +- **World map camera follow.** The free camera's follow (`ovl_battle 0x08B3F7F4`, the end at `0x08B3FAA4..0x08B3FC08`) + turns toward the walker's facing by up to 0.05 rad per frame, with no dead zone. With true angles, a push slightly + off straight up makes the camera turn and the walker veer. They added a 22.5 degree dead zone to the follow. + +### 2. Online battles: replacing the game's per-frame exchange + +Source: [docs/port/communication-mode.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/communication-mode.md) +(sections 4 and 11 onward) and [online-next.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/online-next.md) section 5. + +Our multiplayer runs the game's own lock-step over our ad-hoc emulation. Their notes on that lock-step: +- All of it is one function, the role-0 handler `0x0890D664` (frame pump `0x088EC010 -> 0x0890E794 -> 0x08907F14 -> + 0x0890C5BC`). Spectators use `0x0890DF58`. +- It sends a 16-bit word a frame: 12 buttons plus 4 stick-direction bits. So online fighters get only the 8-way stick + and no right stick. Input delay is 0 to 2 frames, it grows and never shrinks, and the battle freezes on every + late frame past about 100 ms round trip. After 900 waiting frames the session ends. +- Packet: 0x24 bytes, the last 8 pad words, a desync hash every 10 frames (`0x0890CD90`; the hash callback is battle + `0x08B136D4`). +- Both machines simulate both fighters and both cameras from the two pads, so full analogue input can go in the raw + pads' injected samples (`+0x40..+0x4F`) as long as both machines inject the same bytes. + +They replaced `0x0890D664` during battles with their own UDP lock-step: full analogue, both right sticks (bytes 10 and +11 of the sample), a set input delay, redundancy, and the game's own check value compared every 10 frames. They then +added **rollback**. Their measurements: dirty-page snapshots are about 2 MiB a frame, and 2 to 3 frames of rollback on +top of 1 frame of delay covers about 100 to 130 ms without a stall. This is the main gap in our +[multiplayer.md](multiplayer.md) ("input delay or rollback for high latency" is listed there as missing). + +### 3. Japanese voices: story scene scripts + +Source: [docs/port/japanese-voices.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/japanese-voices.md), "Story scenes". + +Our `jp_audio.py` swaps audio files only. They found that **302 voiced story scenes** (`talkevent/*.evex`, ARC +archives) have different scripts on the English and Japanese discs. 55 have other voice lists and 247 have other +waits, because each line waits a fixed time tuned to its own recording. With English scripts and Japanese audio, lines +get cut off or the wrong line plays (their example: Vaan and Terra, 012 Chapter 2, `up02_103`). Their fix is to read +each of those scenes as the Japanese disc has it, keeping the English text. The English game knows every script +command of the Japanese scripts except `0x157` and `0x162`. They also keep the English movie picture with the +Japanese sound, where we swap the whole PMF. + +Their trick for pairing files without names: the `PACKAGE_INFO.BIN` hash is CRC-32/BZIP2, which is linear. Two names +of the same length that differ only in `jp`/`en` differ by a constant that depends only on how many characters follow, +so `hash XOR delta(n)` finds the English twin of every Japanese file (6,222 of 6,354 sound files pair one to one). + +### 4. Features we do not have + +| Feature | Their doc | Notes for us | +| --- | --- | --- | +| BGM picker on the loading screen (series left/right, track wheel up/down) and music mods in MP3/Ogg/Opus/FLAC/WAV/BRSTM with loop points, no disc change | [bgm-playlist-design.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/bgm-playlist-design.md), [mod-folder.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/mod-folder.md) | Ours needs AT3 encoding and a `main.bin` rewrite ([audio.md](audio.md)). Their facts: the table object `*0x089D6C30` has room for 256 rows; DLC rows are added at run time by `0x0889F040`; the selector is battle `0x08AF8CA4`, struct at loading screen `+0x6AC`. | +| Local split-screen versus (1v1 and party), each player with a controller and camera | [local-versus.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/local-versus.md) | Large job (one game drawn twice). Their notes on player 2's input path also serve netplay. | +| Cheats page: built-in cheats plus PPSSPP CWCheat files (`PSP/Cheats/ULUS10566.ini`) | [cheats.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/cheats.md) | Their CWCheat engine is in PortableKit (MIT). | +| Button prompts drawn as Xbox / PlayStation / Nintendo / keyboard, following the controller in use | [button-prompts.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/button-prompts.md) | Also changes the prompts inside hint text. | +| L/R on the triggers option; per-player controller choice; one key each for dodge, dash, EX Mode, summon and assists | [keyboard-controls.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/keyboard-controls.md), [controller-picker.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/controller-picker.md) | Small. | +| Save, message and keyboard dialogs drawn in the game's own menu style with its sounds | [native-dialogs.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/native-dialogs.md) | Cosmetic. | +| Listing on RecompLauncher | [recomplauncher.json](https://github.com/VCKing101/Dissidia012-pc/blob/main/recomplauncher.json) | Needs a portable zip and a no-window `--prepare --game {game}` step; the manifest describes the ISO check, an ini settings file, and the save, mod and log folders. | + +### 5. Event names + +Source: [docs/research/moveset-format.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/research/moveset-format.md), section 6. + +They list all 125 ranged and 56 keyed event handlers. Compared with the names in `tools/charmod_objx.py`, these codes +have names there and not here (uses / fighters in brackets): +- Ranged: `0x3C brave_regen` (Gabranth), `0x51 armor` (Kain, Chaos), `0x17 swing_reset` (Sephiroth, Bartz, Firion), + `0x6B sound_ramp`, `0x1A actionable_ex` (Feral Chaos). +- Unused by any retail move, but working handlers that new moves could use: `0x0D freeze_state`, `0x0E hold_target`, + `0x41 break_lock_ons`, `0x44 tint`, `0x4E shape_off`, plus camera paths `0x5C`/`0x6F` (partly understood). +- Keyed: `0x17 cart_effect` (Laguna, Squall). + +Check each in the game code before adding it to the table: their codes are the event type, ours are +`(arg count << 8) | type`. + +### 6. Smaller facts + +- `PACKAGE_INFO.BIN` is read into a fixed buffer of `0x20F8C` bytes (`0x08871938`), room for only 210 more records + ([japanese-voices.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/japanese-voices.md)). +- The pad manager object map (`0x08C15B90`), its three pad arrays, the remap tables and the injected / replay / + network input paths: [research/pad-module.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/research/pad-module.md). +- `DES4` files are stage geometry: collision meshes, transforms of breakable objects, EX core positions and fighter + start and end positions (Sky Noxt, in DissidiaDecompProject `Extract/des4/README.md`). + +## Already covered here + +- The text cipher (DissidiaDecompProject `Tools/MiscTools`): our `tools/mess_text.py` already reads and writes it, + including the OFF4 layout. +- The `PACKAGE.BIN` extractor and builder: `tools/package_extract.py` and the loose-file layer do more. +- Right-stick camera, analogue dead zone, 60+ fps, HD textures, Discord status, Japanese voices, internet play, + cloud saves: all here already. Our frame rates (up to 240) and character modding go further than theirs. +- Their quit crash (a descriptor pool destroyed before sets were freed from it) does not apply. Our Vulkan code + never frees single descriptor sets. diff --git a/psprecomp/games/dissidia/docs/steamdeck.md b/psprecomp/games/dissidia/docs/steamdeck.md index b0d9b75..c718e41 100644 --- a/psprecomp/games/dissidia/docs/steamdeck.md +++ b/psprecomp/games/dissidia/docs/steamdeck.md @@ -296,9 +296,10 @@ Input to any of the buttons above if you want them. stick then does nothing in menus), `PSPRECOMP_RSTICK_DEADZONE=0.3` widens the dead zone. Environment variables set in Steam's Launch Options as `PSPRECOMP_CAM_SENS=1.5 %command%` do not work here (the entry is a script, `%command%` is the script); export them in `play.sh` above the `exec` line instead. -* Movement is fully analogue: the game itself only has 8 stick directions (a 78% per-axis dead zone); the port - replaces that with a radial dead zone (`PSPRECOMP_ANALOG_DEADZONE`, default 0.20) so any angle works. - `PSPRECOMP_ANALOG_FULL=0` brings back the original 8-way movement. The Deck's sticks have a hardware dead zone +* Movement: the game itself only has 8 stick directions (a 78% per-axis dead zone). The port uses a radial dead zone + (`PSPRECOMP_ANALOG_DEADZONE`, default 0.20) and walks and fights in the stick's own direction + (`PSPRECOMP_ANALOG_WALK_BATTLE=0` keeps battle 8-way, which saved battle replays need to play back exactly; + `PSPRECOMP_ANALOG_WALK=0` the 8 ways everywhere, `PSPRECOMP_ANALOG_FULL=0` the original stick code). The Deck's sticks have a hardware dead zone of their own plus Steam Input's; if drift is a problem raise the radial one. * `PSPRECOMP_GAMECONTROLLERDB=/path/gamecontrollerdb.txt` (or `run.sh --gamecontrollerdb FILE`, or just drop the file in the work directory as `gamecontrollerdb.txt`) loads extra SDL mappings for pads SDL diff --git a/psprecomp/games/dissidia/runtime/input.cpp b/psprecomp/games/dissidia/runtime/input.cpp index 27fa127..51b1002 100644 --- a/psprecomp/games/dissidia/runtime/input.cpp +++ b/psprecomp/games/dissidia/runtime/input.cpp @@ -22,10 +22,36 @@ // // PSPRECOMP_ANALOG_FULL=0 restores the original 8-way behaviour. PSPRECOMP_ANALOG_LOG= logs n stick // updates (raw, game vector, replacement). +// +// Walking direction. The vector above is not what steers a walk: the walker's input, ovl_battle FUN_08B38A0C +// (a0 = out, a1 = walker, a2 = its pad, a3 = camera; called each frame from FUN_08B36D2C on the world map and for the +// player's fighter in battle), asks the pad for the four logical walk bits and builds a camera-space step from them +// (sp+0x40: x = +-1, z = +-1, or y with walker+0x5B1 bit 0x20), then turns it by the inverted camera matrix +// (FUN_0885EA88 .. FUN_089A3F40) or copies it (FUN_089A3BC8, walker+0x5B1 bit 0x40) and normalises it. So every walk goes +// one of eight ways whatever the stick says. Found by VCKing101 (https://github.com/VCKing101/Dissidia012-pc, +// docs/port/analog-movement.md, MIT); this is our own code from those notes. +// Fix: while FUN_08B38A0C runs for the LogicalPad of raw[0] (the hardware pad) with the stick pushed, the first of FUN_0885EA88 / FUN_089A3BC8 +// called from its frame rewrites the step at sp+0x40 to the stick's own direction (the pad's +0x20 vector, the radial +// one written above). Everything after it (camera, normalisation, walker+0x5B0 flags from the 8-way bits) is the game's. +// The walk still starts when the game sees a walk bit. On the world map and in battle (never while the pads are fed by +// the online exchange or a replay). A saved battle replay records just the 8-way bits, so a fight steered by the stick +// can play back a little differently. PSPRECOMP_ANALOG_WALK=0 turns it off, PSPRECOMP_ANALOG_WALK_BATTLE=0 keeps battle +// 8-way, PSPRECOMP_ANALOG_WALK_LOG= logs n replaced steps, PSPRECOMP_ANALOG_WALK_OUTLOG= the walk's world output. +// +// Camera follow. The world map's free camera (ovl_battle FUN_08B3F7F4: a0 = yaw block, yaw at +8; a1 = camera, owner at +248) +// turns its yaw toward the walker's facing (owner+0x90, through the atan2 FUN_089A457C) by up to the row's cap (0.05 rad) a frame, +// with no dead zone. With the 8-way walk a push near straight up walked straight up; with the stick's own angle the facing is a few +// degrees off, the camera turns, the camera-relative walk turns with it and the camera spins (VCKing101 measured 172 deg/s for a +// 15 degree push, docs/port/analog-movement.md section 7). Fix, as theirs: while the follow runs for the walker whose last walk step +// was ours, its atan2 result is moved so that the angle it turns toward is 0 within PSPRECOMP_ANALOG_FOLLOW_ZONE degrees of straight +// ahead, rises to the cap over a ramp of half the zone, and is the game's beyond that. Default 180: the camera does not follow the +// analogue walk at all (the right stick turns it; walking with the D-pad keeps the game's follow). 22.5 is VCKing101's zone (straight +// back, the sides and diagonals turn as in the game), 0 the game's follow. #include "psp_game_module.h" #include "recomp.h" #include "hle/psp_hle.h" +#include #include #include #include @@ -112,8 +138,135 @@ void dissidia_stick_process(uint8_t* rdram, recomp_context* ctx) { wrf(out, ox); wrf(out + 4, oy); wrf(out + 8, 0.f); wrf(out + 12, w); } +// ---- walking direction (see the top of the file) ---- +constexpr uint32_t WALK_INPUT = 0x08B38A0Cu; // ovl_battle +constexpr uint32_t CAM_MATRIX = 0x0885EA88u; // first call after the step is built (camera path) +constexpr uint32_t VEC_COPY = 0x089A3BC8u; // first call after the step is built (no-camera path) +constexpr uint32_t WALK_FRAME = 336u; // FUN_08B38A0C's stack frame; the step is at sp+0x40 +constexpr uint32_t LOGICAL_PAD_VT = 0x089C96E8u, PAD_MGR = 0x08C15B90u, BATTLE_OBJ = 0x089D6A10u; +FuncPtr g_orig_walk = nullptr, g_orig_cam_matrix = nullptr, g_orig_vec_copy = nullptr; +bool g_walk_battle = true; +int g_walk_log = 0; +uint32_t g_walk_sp = 0, g_walk_walker = 0; // set only while an eligible FUN_08B38A0C runs +float g_walk_dx = 0.f, g_walk_dy = 0.f; +uint32_t g_last_walker = 0; // walker of the last FUN_08B38A0C call, and whether its step was ours +bool g_last_walk_analog = false; + +uint32_t rdw(uint32_t a) { uint32_t v; std::memcpy(&v, g_ram + (a & 0x07FFFFFFu), 4); return v; } + +bool walk_eligible(uint32_t pad) { + if (!pad || rdw(pad + 0x34u) != LOGICAL_PAD_VT) return false; // a CPU brain's or the null pad: the game's way + if ((rdw(pad + 0x44u) & 1u) || !rdw(pad + 0x4Cu)) return false; // disabled, or no action map + if (rdw(PAD_MGR + 0x264u) & 3u) return false; // replay playback / muted + const uint32_t src = rdw(pad + 0x40u); + if (src != PAD_MGR) return false; // only the pad read from the hardware (raw[0]): not a CPU's + if (rdw(src + 0x50u) == 1u) return false; // raw[0] fed by the online exchange or a replay + const uint32_t bo = rdw(BATTLE_OBJ); + const bool battle = bo && (rdw(bo + 0x38u) || rdw(bo + 0x3Cu)); // the world map's battle object has no fighters + if (battle && !g_walk_battle) return false; + return rdf(pad + 0x2Cu) > 0.f; // stick past the radial dead zone +} + +// PSPRECOMP_ANALOG_WALK_OUTLOG=: the walk's world-space output for the hardware pad's walker, hook on or off (diagnostics). +int g_out_log = 0; +void walk_log_out(uint32_t pad, uint32_t out) { + if (g_out_log <= 0 || !pad || rdw(pad + 0x40u) != PAD_MGR) return; + const float x = rdf(out), z = rdf(out + 8); + if (x == 0.f && z == 0.f) return; + g_out_log--; + std::fprintf(stderr, "[WALKOUT] walker=%08X out=(%.3f,%.3f) heading %.1f analog=%d\n", g_last_walker, x, z, + std::atan2(x, z) * 57.29578f, (int)g_last_walk_analog); +} + +void walk_input_hook(uint8_t* rdram, recomp_context* ctx) { + const uint32_t pad = static_cast(ctx->r[6]); + const uint32_t out_vec = static_cast(ctx->r[4]); + g_last_walker = static_cast(ctx->r[5]); + g_last_walk_analog = false; + if (!walk_eligible(pad)) { g_orig_walk(rdram, ctx); walk_log_out(pad, out_vec); return; } + const uint32_t prev_sp = g_walk_sp, prev_walker = g_walk_walker; + const float pdx = g_walk_dx, pdy = g_walk_dy; + g_walk_sp = static_cast(ctx->r[29]) - WALK_FRAME; + g_walk_walker = static_cast(ctx->r[5]); + g_walk_dx = rdf(pad + 0x20u); g_walk_dy = rdf(pad + 0x24u); + g_orig_walk(rdram, ctx); + g_walk_sp = prev_sp; g_walk_walker = prev_walker; g_walk_dx = pdx; g_walk_dy = pdy; + walk_log_out(pad, out_vec); +} + +// Called at the first of FUN_0885EA88 / FUN_089A3BC8 from the walk's own frame: the step is complete at sp+0x40. +void walk_replace_step(const recomp_context* ctx) { + if (!g_walk_sp || static_cast(ctx->r[29]) != g_walk_sp) return; + const uint32_t v = g_walk_sp + 0x40u; + const float x = rdf(v), y = rdf(v + 4), z = rdf(v + 8); + if (x == 0.f && y == 0.f && z == 0.f) return; // not walking this frame + const bool vertical = (g_ram[(g_walk_walker + 0x5B1u) & 0x07FFFFFFu] & 0x20u) != 0; + const float nx = g_walk_dx, nf = g_walk_dy; // stick: x right, y down = towards the camera + if (g_walk_log > 0) { + g_walk_log--; + std::fprintf(stderr, "[WALK] walker=%08X step (%.0f,%.0f,%.0f) -> (%.3f,%.3f,%.3f) stick angle %.1f\n", g_walk_walker, x, y, z, + nx, vertical ? -nf : 0.f, vertical ? 0.f : nf, std::atan2(nx, -nf) * 57.29578f); + } + wrf(v, nx); + if (vertical) { wrf(v + 4, -nf); wrf(v + 8, 0.f); } else { wrf(v + 4, 0.f); wrf(v + 8, nf); } + g_walk_sp = 0; // once per walk call + g_last_walk_analog = true; +} + +// ---- camera follow dead zone ---- +constexpr uint32_t FREE_CAM_INPUT = 0x08B3F7F4u; // ovl_battle +constexpr uint32_t ATAN2 = 0x089A457Cu; // f0 = atan2(f12, f13) +FuncPtr g_orig_free_input = nullptr, g_orig_atan2 = nullptr; +float g_follow_zone = 180.f * 0.017453293f; // default: no follow at all (the right stick turns the camera) +uint32_t g_follow_owner = 0, g_follow_yaw = 0; // set while FUN_08B3F7F4 runs for that walker +int g_follow_log = 0; + +void free_input_hook(uint8_t* rdram, recomp_context* ctx) { + const uint32_t yaw_blk = static_cast(ctx->r[4]), cam = static_cast(ctx->r[5]); + const uint32_t owner = cam ? rdw(cam + 248u) : 0; + if (!owner || owner != g_last_walker || !g_last_walk_analog) { g_orig_free_input(rdram, ctx); return; } + g_follow_owner = owner; g_follow_yaw = yaw_blk; + g_orig_free_input(rdram, ctx); + g_follow_owner = 0; g_follow_yaw = 0; +} + +float wrap_pi(float a) { + const float two_pi = 6.2831853f; + while (a > 3.14159265f) a -= two_pi; + while (a <= -3.14159265f) a += two_pi; + return a; +} + +void atan2_hook(uint8_t* rdram, recomp_context* ctx) { + if (!g_follow_owner) { g_orig_atan2(rdram, ctx); return; } + // Only the follow's own call: atan2(-facing.x, -facing.z) of the owner. + const float a = ctx->f[12], b = ctx->f[13]; + const bool follow = a == -rdf(g_follow_owner + 0x90u) && b == -rdf(g_follow_owner + 0x98u); + g_orig_atan2(rdram, ctx); + if (!follow) return; + const float yaw = rdf(g_follow_yaw + 8u), target = ctx->f[0]; + const float diff = wrap_pi(target - yaw), ad = std::fabs(diff); + float cap = rdf(static_cast(ctx->r[18]) + 32u); // the follow's per-frame cap (read the same way right after this call) + if (!(cap > 0.f && cap < 1.f)) cap = 0.05f; + const float ramp = std::max(g_follow_zone * 0.5f, cap); + float fed = diff; + if (ad <= g_follow_zone) fed = 0.f; + else if (ad < g_follow_zone + ramp) fed = std::copysign(cap * (ad - g_follow_zone) / ramp, diff); + if (g_follow_log > 0 && fed != diff) { + g_follow_log--; + std::fprintf(stderr, "[FOLLOW] yaw %.1f target %.1f diff %.2f -> %.2f deg (cap %.2f)\n", yaw * 57.29578f, target * 57.29578f, + diff * 57.29578f, fed * 57.29578f, cap * 57.29578f); + } + ctx->f[0] = yaw + fed; +} + +void cam_matrix_hook(uint8_t* rdram, recomp_context* ctx) { walk_replace_step(ctx); g_orig_cam_matrix(rdram, ctx); } +void vec_copy_hook(uint8_t* rdram, recomp_context* ctx) { walk_replace_step(ctx); g_orig_vec_copy(rdram, ctx); } + } // namespace +extern FuncPtr ovl_battle_lookup(uint32_t vaddr); + void dissidia_input_install(uint8_t* rdram) { const char* e = std::getenv("PSPRECOMP_ANALOG_FULL"); if (e && e[0] == '0') { std::fprintf(stderr, "[INPUT] analogue stick: original 8-way processing (PSPRECOMP_ANALOG_FULL=0)\n"); return; } @@ -129,4 +282,29 @@ void dissidia_input_install(uint8_t* rdram) { if (!g_orig) { std::fprintf(stderr, "[INPUT] stick hook NOT installed\n"); return; } psp_dispatch_register(STICK_PROCESS, dissidia_stick_process); std::fprintf(stderr, "[INPUT] continuous analogue stick direction (dead zone %.2f)\n", g_dz); + + if ((e = std::getenv("PSPRECOMP_ANALOG_WALK")) && e[0] == '0') { std::fprintf(stderr, "[INPUT] walking: original 8 ways\n"); return; } + if ((e = std::getenv("PSPRECOMP_ANALOG_WALK_BATTLE"))) g_walk_battle = e[0] != '0'; + if ((e = std::getenv("PSPRECOMP_ANALOG_WALK_LOG"))) g_walk_log = std::atoi(e); + if ((e = std::getenv("PSPRECOMP_ANALOG_WALK_OUTLOG"))) g_out_log = std::atoi(e); + g_orig_walk = ovl_battle_lookup(WALK_INPUT); + g_orig_cam_matrix = psp_dispatch_probe_lookup(CAM_MATRIX); + g_orig_vec_copy = psp_dispatch_probe_lookup(VEC_COPY); + if (!g_orig_walk || !g_orig_cam_matrix || !g_orig_vec_copy) { std::fprintf(stderr, "[INPUT] walk hook NOT installed\n"); return; } + psp_dispatch_register(WALK_INPUT, walk_input_hook); + psp_dispatch_register(CAM_MATRIX, cam_matrix_hook); + psp_dispatch_register(VEC_COPY, vec_copy_hook); + std::fprintf(stderr, "[INPUT] analogue walking direction (world map%s)\n", g_walk_battle ? " and battle" : ""); + + if ((e = std::getenv("PSPRECOMP_ANALOG_FOLLOW_ZONE"))) g_follow_zone = static_cast(std::atof(e)) * 0.017453293f; + if (g_follow_zone > 180.f * 0.017453293f) g_follow_zone = 180.f * 0.017453293f; + if ((e = std::getenv("PSPRECOMP_ANALOG_FOLLOW_LOG"))) g_follow_log = std::atoi(e); + if (g_follow_zone <= 0.f) return; + g_orig_free_input = ovl_battle_lookup(FREE_CAM_INPUT); + g_orig_atan2 = psp_dispatch_probe_lookup(ATAN2); + if (!g_orig_free_input || !g_orig_atan2) { std::fprintf(stderr, "[INPUT] camera follow zone NOT installed\n"); return; } + psp_dispatch_register(FREE_CAM_INPUT, free_input_hook); + psp_dispatch_register(ATAN2, atan2_hook); + if (g_follow_zone >= 3.14159f) std::fprintf(stderr, "[INPUT] world map camera does not follow the analogue walk (right stick turns it)\n"); + else std::fprintf(stderr, "[INPUT] camera follow dead zone %.1f deg for the analogue walk\n", g_follow_zone * 57.29578f); } diff --git a/psprecomp/runtime/src/psp_env_options.inc b/psprecomp/runtime/src/psp_env_options.inc index e195704..a46cdfa 100644 --- a/psprecomp/runtime/src/psp_env_options.inc +++ b/psprecomp/runtime/src/psp_env_options.inc @@ -61,6 +61,9 @@ const EnvOpt k_env_opts[] = { {"ANALOG_8WAY", EC_INPUT, 'k', "", "In battle, run the game's original stick code on a square-gate stick for eight even sectors."}, {"ANALOG_DEADZONE", EC_INPUT, 'c', "0.1|0.15|0.3", "Left stick dead zone, as a fraction of full travel (default 0.20)."}, {"ANALOG_DPAD_ZONE", EC_INPUT, 'c', "0.25|0.45|0.55", "Stick travel at which a direction counts as a D-pad press in battle (default 0.35)."}, + {"ANALOG_WALK", EC_INPUT, 'k', "", "Move in the stick's own direction on the world map and in battle. Off: one of eight ways, as on the PSP."}, + {"ANALOG_WALK_BATTLE", EC_INPUT, 'k', "", "In battle too. Off: fighters move one of eight ways (saved battle replays then play back exactly)."}, + {"ANALOG_FOLLOW_ZONE", EC_INPUT, 'c', "0|22.5|60", "World map camera: degrees either side of straight ahead in which it does not turn after a walk with the stick (default 180 = never, the right stick turns it; 0 = the game's follow)."}, {"RSTICK_DPAD", EC_INPUT, 'k', "", "Right stick presses the D-pad (menus, selecting). Off: it does nothing."}, {"RSTICK_DEADZONE", EC_INPUT, 'c', "0.1|0.3|0.4", "Right stick dead zone, as a fraction of full travel (default 0.20)."}, {"ARROWS_DPAD_ONLY", EC_INPUT, 'e', "", "Keyboard arrow keys press only the D-pad, not the left stick as well."}, @@ -224,6 +227,8 @@ const EnvOpt k_env_opts[] = { {"STAGE_LOG", EC_LOG_GAME, 'e', "", "Log the stage id as stages load."}, {"FEP_LOG_SKIN", EC_LOG_GAME, 'e', "", "With the effect-draw log: also log skinned draws."}, {"ANALOG_LOG", EC_LOG_GAME, 'c', "50|500", "Log this many stick samples."}, + {"ANALOG_WALK_LOG", EC_LOG_GAME, 'c', "20|200", "Log this many walk steps turned to the stick's direction."}, + {"ANALOG_FOLLOW_LOG", EC_LOG_GAME, 'c', "20|200", "Log this many world map camera follow turns reduced by the dead zone."}, {"PAD_LOG", EC_LOG_GAME, 'e', "", "Log pad connects and button mapping."}, {"CTRL_LOG", EC_LOG_GAME, 'e', "", "Log which game code polls the pad."}, {"TOUCH_LOG", EC_LOG_GAME, 'e', "", "Log touch input."},