mirror of
https://github.com/TheBozos/DC_Recomp.git
synced 2026-12-01 21:33:18 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdfcd6447b | ||
|
|
4ef5cf6f0a | ||
|
|
4a7f5ad4a6 | ||
|
|
e72dc61db6 | ||
|
|
7f1f6c802b | ||
|
|
a592d8e3ee | ||
|
|
42920f3a57 | ||
|
|
f9ec4ddce0 | ||
|
|
9710186230 | ||
|
|
4207130f78 | ||
|
|
b1025e01b3 | ||
|
|
a2ff5405c2 | ||
|
|
b9025d3717 | ||
|
|
f003c2c4ef | ||
|
|
8e469b6e98 | ||
|
|
7f34ba411e | ||
|
|
ad72ef2486 | ||
|
|
d43b9afeeb | ||
|
|
4367975295 | ||
|
|
7d374fc209 |
No files matched your search
+1
-1
Submodule BozoEngine updated: 296ac6d2c2...8a4ac058b9.
@@ -1,5 +1,22 @@
|
||||
# Changelog
|
||||
|
||||
## [0.3.0] - 2026-11-09
|
||||
|
||||
### Added
|
||||
- Graphics page in the game's Options (controller): display mode, resolution, render scale and frame rate, applied at once and saved to `video.ini`.
|
||||
- Cheats: weapon level-up, reveal floor map, fish always bite, item spawner, fast-forward (hold ` or the touchpad, or lock it on), damage multiplier, one-hit kills, no damage taken and a key finder on the dungeon map.
|
||||
|
||||
### Changed
|
||||
- More of the game runs natively: the per-frame and loading-screen DMA transfers, the per-frame GS display swap and the startup GS sync-path calls are gone, and model, remake, shadow and cloth builds no longer reserve space for console packet data.
|
||||
- BozoEngine moves to its current main (8a4ac05), which adds the calls the Graphics page uses.
|
||||
|
||||
### Fixed
|
||||
- The game now reads `video.ini`: the launcher's display settings and the F2 Video tab apply (the game ignored them). `--fullscreen` still opens borderless over the monitor.
|
||||
|
||||
### Known limits
|
||||
- Gameplay testing covers Norune, Divine Beast Cave, Matataki, Georama, saving and loading; a complete story playthrough and full visual parity are unverified.
|
||||
- Linux and widescreen are not qualified.
|
||||
|
||||
## [0.2.0] - 2026-11-09
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -179,6 +179,12 @@ if(DC_ENGINE_TESTS)
|
||||
target_link_options(dc-cheat-tests PRIVATE -static)
|
||||
endif()
|
||||
add_test(NAME dc_native_cheats COMMAND dc-cheat-tests)
|
||||
add_executable(dc-cheat-extra-tests tests/dc_cheat_extra_tests.cpp)
|
||||
target_link_libraries(dc-cheat-extra-tests PRIVATE dc_cheats bozo_host)
|
||||
if(MINGW)
|
||||
target_link_options(dc-cheat-extra-tests PRIVATE -static)
|
||||
endif()
|
||||
add_test(NAME dc_native_cheat_extras COMMAND dc-cheat-extra-tests)
|
||||
add_executable(dc-ingame-cheat-menu-tests tests/dc_ingame_cheat_menu_tests.cpp)
|
||||
target_link_libraries(dc-ingame-cheat-menu-tests PRIVATE dc_ingame_cheats bozo_host)
|
||||
if(MINGW)
|
||||
|
||||
@@ -28,7 +28,7 @@ BozoEngine replaces the PS2Recomp fork completely; there is no emulation fallbac
|
||||
|
||||
## For players (Windows)
|
||||
|
||||
Download **`DC_Recomp-0.2.0-bozo.zip`** from [Releases](https://github.com/TheBozos/DC_Recomp/releases/latest),
|
||||
Download **`DC_Recomp-0.3.0-bozo.zip`** from [Releases](https://github.com/TheBozos/DC_Recomp/releases/latest),
|
||||
check its `.sha256`, and extract it to a writable folder such as `D:\Games\DC_Recomp_Bozo`.
|
||||
Open **DC Launcher.exe**, select your own USA disc image (`.iso` or `.bin`/`.cue`), click **Prepare the game**,
|
||||
then **Play**. Preparation runs locally with the bundled offline tools; no developer software is needed.
|
||||
@@ -41,7 +41,7 @@ The unsigned launcher may trigger Windows SmartScreen. Game files and generated
|
||||
Use the launcher's **Settings** for display options, logs, maintenance and updates. **F2** opens the game's
|
||||
settings. Saves, controls, video settings and cheats are stored in `%APPDATA%\DC_Recomp` and survive launcher
|
||||
updates. Existing development saves are kept separately; copy only the desired card files into that directory.
|
||||
The in-game pause menu includes **Cheats** and **Quit Game**. Updates offer a rebuild when the source changes.
|
||||
The in-game pause menu includes **Graphics**, **Cheats** and **Quit Game**. Updates offer a rebuild when the source changes.
|
||||
See [CHANGELOG.md](CHANGELOG.md) for release changes and the checked routes above for current coverage.
|
||||
|
||||
## Status
|
||||
@@ -62,7 +62,7 @@ A complete story playthrough and full visual parity remain unverified.
|
||||
| Travel to Matataki through “Go to Other Area” | ✅ |
|
||||
| Memory-card saving, loading and restart with saved progress | ✅ |
|
||||
| Native music and effects | ✅ |
|
||||
| Controller-operated Cheats and Quit Game inside Options; F2 settings remain available | ✅ |
|
||||
| Controller-operated Graphics, Cheats and Quit Game inside Options; F2 settings remain available | ✅ |
|
||||
| Georama and dungeon play on the current engine | ✅ |
|
||||
| New-game opening on the current engine | 🔧 |
|
||||
| Complete story, all companions, locations and effects | 🔧 |
|
||||
@@ -211,8 +211,10 @@ pacman -S --needed mingw-w64-ucrt-x86_64-{gcc,cmake,ninja,pkgconf,ffmpeg,libarch
|
||||
`--fullscreen` starts fullscreen; `--no-vsync` disables VSync for comparisons. The default is windowed
|
||||
with VSync enabled. **F8** captures a frame when a capture directory is configured.
|
||||
|
||||
The game's **Options** entry page offers **Game Options** (the original settings), **Cheats**, and
|
||||
**Quit Game**. Up/Down selects rows, Cross confirms and Circle goes back. Quit Game asks for confirmation,
|
||||
The game's **Options** entry page offers **Game Options** (the original settings), **Graphics**, **Cheats**, and
|
||||
**Quit Game**. Up/Down selects rows, Cross confirms and Circle goes back. **Graphics** sets the display mode,
|
||||
resolution, render scale and frame rate; **Apply and save** writes them to `video.ini` (shared with the launcher's
|
||||
Settings and **F2 → Video**). Quit Game asks for confirmation,
|
||||
with Cancel selected initially. Save through the game's normal save menu before quitting to keep progress;
|
||||
quitting does not autosave.
|
||||
|
||||
@@ -290,7 +292,7 @@ licences and corresponding toolchain sources, and audits the archives for game d
|
||||
```bash
|
||||
python tools/make_build_kit.py --out D:/dc_kit/kit
|
||||
scripts/bench_run.sh --alone 20 "release package" python tools/make_release.py \
|
||||
--version 0.2.0 --kit D:/dc_kit/kit --out D:/dc_release --with-sources
|
||||
--version 0.3.0 --kit D:/dc_kit/kit --out D:/dc_release --with-sources
|
||||
```
|
||||
|
||||
Only committed source is exported. Follow [the release checklist](docs/RELEASE_CHECKLIST.md) before publishing;
|
||||
|
||||
+125
-1
@@ -1140,7 +1140,7 @@ The allocation audit deliberately retains these different owners:
|
||||
| Shared primary arena and read/data subarenas | Real files, models, game objects and allocator cursor/bounds behavior |
|
||||
| Visibility descriptor/capacity/cursor | Native depth queries and per-frame reset of their logical request extent; its backing reserve is removed |
|
||||
| Visual MDT data address and size | `CreateVisual` `0x126770` passes the native builder's visual size to `CDataAlloc2::Alloc`, then advances game bookkeeping; the data address keys `g_mdtCopies` and visual fields |
|
||||
| Model/shadow/cloth allocation extents | The shared game allocation ABI still advances by these sizes. `modelAllocationQwords` and `clothCreateHook` retain legacy VIF-size formulas without serializing packets. Shrinking them requires migrating address identity, reuse/lifetime and live-animation/remake contracts together |
|
||||
| Model/shadow/cloth allocation extents | The shared game allocation ABI still advances by these sizes. Since the model-extent and cloth-extent migrations each build reserves one qword, keeping its own aligned address (see "Native model extent" and "Native cloth extent") |
|
||||
|
||||
The earlier snapshot/lifetime and original/native builder tests still pass. No generic allocator is replaced,
|
||||
and the model/cloth size ABI is not collapsed to zero or a shared dummy identity.
|
||||
@@ -1713,3 +1713,127 @@ methods and six changed-instruction guard rejections. **77/77 normal suites** an
|
||||
Runtime, production patches,
|
||||
the engine pin and saves are unchanged. Live DUN coverage remains **33/43** with
|
||||
497 unobserved sites globally; fixtures add no gameplay or visual qualification.
|
||||
|
||||
## Per-frame transfer retirement (2026-11-09)
|
||||
|
||||
`MGEndFrame`'s tail no longer waits, flushes or sends. The earlier frame-end pass kept one native SDK send per frame,
|
||||
an empty VIF1 transfer, to preserve its completion interrupt and callback. That completion has no consumer: the game's
|
||||
only `AddDmacHandler` call is in `sceSifInitCmd`, which BozoEngine answers natively, so no DMA-completion handler is
|
||||
ever installed. The `sceDmaSync` before it waits on the GIF channel (`gp-0x7434`, from `MGInit`), which never carries a
|
||||
transfer in this port. Three guarded patches retire `sceDmaSync` (`0x12d61c`), `FlushCache` (`0x12d678`) and
|
||||
`sceDmaSend` (`0x12d68c`); every delay slot was already a `nop`. The frame counter and its first-frame flag, the
|
||||
`sceDmaGetChan(1)` lookup stored at `gp-0x7438` and the double-buffer toggle stay.
|
||||
|
||||
- The `frame_submit` reference/adapted span now starts at `0x12d610`, covering the wait. 24 cases (counter overflow,
|
||||
buffer states, first frame): the published reference waits, flushes and sends once; the adapted tail makes no
|
||||
transfer, flush or wait and queues no completion. Frame counter, flag, channel handle and toggle match; all other
|
||||
guest RAM is unchanged.
|
||||
- **126/126** suites. The seven scripted routes end as before with identical cards and zero register/unknown accesses,
|
||||
VU0 calls or GIF submissions. VIF1 SDK submissions per route fall from 5,338–10,010 to **1,190** (1,571 on the
|
||||
Matataki route), and sync calls from 6,536–10,986 to 2,388–3,162. Captures match the previous build within 2 mean
|
||||
levels outside the two known fade frames.
|
||||
|
||||
Remaining transfer calls, about 1,190 per run, sit in the boot and loading paths: `main`'s four sends at mode changes
|
||||
(two upload VU1 microcode from `0x24f960`/`0x296680`, which nothing executes), `VSyncCallBack_Load`'s send and syncs,
|
||||
`EnterFixTexture`/`EnterFixTextureZ` and `StoreImage`.
|
||||
|
||||
### Boot and loading transfers (2026-11-09)
|
||||
|
||||
The rest follow the same reasoning:
|
||||
|
||||
- `VSyncCallBack_Load`, every vblank while loading: `sceDmaSync` of VIF1 (`0x154380`), `iFlushCache` (`0x15468c`),
|
||||
the empty VIF1 `sceDmaSend` (`0x1546a0`) and `sceDmaSync` of GIF (`0x15474c`) are retired. The `loading`
|
||||
reference/adapted span (96 cases) now requires the adapted callback to make no cache or transfer call and queue no
|
||||
completion, while its fade sprites match the reference's calls in order and all non-stack RAM matches.
|
||||
- `main`, at mode changes: four `FlushCache` / `sceDmaSend` / `sceGsSyncPath` triples (`0x141388`..`0x141638`) are
|
||||
retired, two of them the VU1 microcode uploads. `v0` is reloaded after each removed call.
|
||||
- `EnterFixTexture` / `EnterFixTextureZ` are replaced whole by native hooks, so their sends never run. `StoreImage` is
|
||||
reached only from `MGEndFrame`'s screenshot branch (`0x12d4e4`).
|
||||
|
||||
**126/126** suites. All seven routes now report **0 VIF0, 0 VIF1, 0 GIF submissions and 0 sync calls**, with the same
|
||||
ends, identical cards and zero register/unknown accesses and VU0 calls. A loading transition finishes slightly earlier
|
||||
(the Matataki route's frame 6,000 arrives where the previous build is still fading); later captures show the same views
|
||||
within about 3 mean levels.
|
||||
|
||||
### Per-frame display-buffer swap (2026-11-09)
|
||||
|
||||
`MGEndFrame` no longer calls `sceGsSetHalfOffset` (`0x12d5e8`), `FlushCache` (`0x12d5f4`) or `sceGsSwapDBuff`
|
||||
(`0x12d608`) every frame. `sceGsSetHalfOffset` only rewrites the draw record's XYOFFSET image, which the native
|
||||
renderer never reads; `sceGsSwapDBuff` writes nothing and only hands the records to `sceGsPutDispEnv` /
|
||||
`sceGsPutDrawEnv`, both no-ops in BozoEngine. The per-frame `sceDmaGetChan(1)` (`0x12d64c`) and its store
|
||||
(`0x12d654`) go too: `MGInit` already stored that VIF1 handle, and without the call the store would have written the
|
||||
frame counter left in `v0`. The buffer index toggle stays.
|
||||
|
||||
- The `frame_submit` span now starts at `0x12d5c0` (24 cases): the reference sets the half offset, swaps, waits,
|
||||
flushes twice, looks the channel up and sends; the adapted span does none of these, and all guest RAM matches, the
|
||||
channel handle included.
|
||||
- 126/126 suites; seven routes with the same ends, identical cards, and zero transfers or syncs. Matataki frames differ
|
||||
only by cloud drift after the earlier load (up to 3.8 mean levels).
|
||||
- A temporary per-name library-call count on the 9,000-frame Matataki route (not committed) shows
|
||||
`sceGsPutDispEnv` / `sceGsPutDrawEnv` going from 7,869 / 7,868 calls to none, and `sceDmaGetChan` from 7,874 to 6.
|
||||
The PS2 library calls left every frame are the controller (`scePad*`) and the sound driver's SIF commands. The
|
||||
GS-library calls left run at startup or mode changes: `sceGsSyncV` (86, in `CGamePad::Init`), `sceGsSyncPath` (9)
|
||||
and the `sceGsSetDef*` record setup.
|
||||
|
||||
### Startup GS calls: sceGsSyncPath retired, sceGsSyncV kept (2026-11-09)
|
||||
|
||||
`main`'s mode change no longer calls `sceGsSyncPath` (`0x141334`); it always answers "idle", and `v0` is reloaded
|
||||
right after. With it alone, the EE clock of the companion route (the title attract demo) matches the previous build at
|
||||
every logged frame and its captures are identical. 126/126 suites; all seven routes end as before with identical cards.
|
||||
|
||||
The 22 `sceGsSyncV` calls (`CGamePad::Init`, `main`, `SndBgmFadeOutStop`, `EditLoop`) are **kept**. BozoEngine's
|
||||
handler neither waits nor ends a frame, but these calls are still part of the boot timeline. Replacing them all with
|
||||
`v0 = 1` reached frame 0 about 36 fields later in EE time, and shifted the attract demo by one field from frame 120
|
||||
on. Restoring only `CGamePad::Init`'s waits put frame 0 back, but the attract demo still diverged: at frame 60 the
|
||||
previous build is inside `main`'s wait-for-odd-field loop (`0x141140`), which really does spin during boot until the
|
||||
loading screen's vsync callback ends a frame. Removing these calls would change behaviour for a few dozen free calls at
|
||||
startup, so they stay; the one-time `sceGsResetGraph` (field rate) and `sceGsSetDef*` record setup stay too.
|
||||
|
||||
## Model extents: who writes the VU data buffers (2026-11-09)
|
||||
|
||||
The model, remake and shadow builders still return the old VIF packet size (`modelAllocationQwords`), and the game
|
||||
reserves that much arena for a buffer nothing fills. Before replacing it with a native size, `DC_PROBE_EXTENTS=1`
|
||||
checks whether anything else uses those buffers. Each buffer is filled with a pattern when built (native builders write
|
||||
nothing there), and every 60 frames the buffers built in the last 600 frames are compared. A change is classified as
|
||||
**live** when the building visual still has its vtable, still points at this buffer and still has this size.
|
||||
|
||||
- The six gameplay routes (Matataki travel, Cheats + Quit, water, dungeon menu, save, reload) report 13–82 changed
|
||||
buffers each, and **none while their visual owned them**: every change is reuse after the scene or asset changed.
|
||||
- The attract-demo route reports 352 changed buffers, 8 classified live. Their new bytes are float vectors ending in
|
||||
1.0 and colour bytes: model data loaded at the demo's scene switches (frames 4,980, 6,120, 6,480, 7,020, 7,440),
|
||||
over buffers whose old visual records simply were not overwritten yet. No VIF command words appear.
|
||||
|
||||
No game code was found writing into a built VU data buffer that is still in use. `SetVuData`, the only original
|
||||
routine that wrote into one, is called only from the replaced `CreateVUdataFromMDT`. Cloth builds return a size before
|
||||
their buffer exists, so the probe does not cover cloth.
|
||||
|
||||
### Native model extent
|
||||
|
||||
Model, remake and shadow builds now reserve **one qword**; `modelAllocationQwords` and its VIF packet formula are
|
||||
gone. `CreateVisual` builds at the allocator's cursor, reserves the returned extent, adds it to the game's running
|
||||
total at `gp-0x7460` and calls `Align64`, so every build still gets its own 64-byte-aligned data address. That address
|
||||
keys the retained MDT copy, and double-buffered visuals keep their two distinct addresses at `+0x28`/`+0x2c`. Remakes
|
||||
reuse their buffer, and the raw `CVisualMDTVu1` draw's temporary allocation now takes one qword. Before, single builds
|
||||
reserved up to hundreds of kilobytes each (the probe saw 75,008- and 334,176-byte remake buffers).
|
||||
|
||||
- The builder fixture (1,064 cases) now requires the original to reserve its VIF size and the native build to reserve
|
||||
one qword, with its data address recorded and no console output written. 126/126 suites.
|
||||
- All seven routes end as before with identical cards and zero register/unknown accesses, VU0 calls, transfers and
|
||||
syncs. The attract-demo route is still frame-exact. Captures match within 3.6 mean levels outside the known fade
|
||||
frames. A scripted walk onto Divine Beast Cave B1 (map revealed through the Cheats page) renders the floor, Toan and
|
||||
HUD normally.
|
||||
|
||||
### Native cloth extent
|
||||
|
||||
Cloth `CreateVUData` (`0x13C5F0`) now also reserves **one qword**; `textureAllocationQwords` and its formula are gone.
|
||||
`CCloth::Initialize` stores the cursor as buffer 0 (`+0x24`), builds, records the size at `+0x1C`, reserves it with
|
||||
`Alloc`, takes buffer 1 with `Alloc64(size)` (`+0x28`) and builds again, so the two buffers keep distinct addresses.
|
||||
Its per-frame `DrawVu1` (`0x13C470`) is replaced by the native cloth draw, which never reads the size or either buffer:
|
||||
it draws from the simulation grid at `cloth + row*0x100 + column*0x10`. In the cloth code (`0x13B800`–`0x13E400`) only
|
||||
`Initialize` touches `+0x1C` (`0x13CC5C`–`0x13CC94`).
|
||||
|
||||
- The builder fixture's cloth case now requires the original to reserve its VIF size and the native build one qword.
|
||||
126/126 suites.
|
||||
- With `DC_NATIVE_STATS=1` the Matataki, water and attract-demo routes build cloth 20, 12 and 64 times. All seven
|
||||
routes end as before with identical cards and zero register/unknown accesses, VU0 calls, transfers and syncs; the
|
||||
attract-demo route is frame-exact, and captures match within 3.5 mean levels outside the known fade frames.
|
||||
+49
-3
@@ -1,12 +1,18 @@
|
||||
# Cheats and in-game options
|
||||
|
||||
Open the game's main menu, choose **Options**, then **Cheats**. The entry page also offers
|
||||
**Game Options** (the original settings) and **Quit Game**. Circle goes back; Circle on the entry page
|
||||
**Game Options** (the original settings), **Graphics** and **Quit Game**. Circle goes back; Circle on the entry page
|
||||
closes Options through the original fade/exit lifecycle. Quit Game defaults to Cancel and requires
|
||||
an explicit confirmation. It uses normal application shutdown and does not autosave.
|
||||
|
||||
The same cheat controls remain available in **F2 → Cheats**. Both interfaces share session settings.
|
||||
|
||||
**Graphics** sets the window from the controller: **Display** (windowed, fullscreen or borderless),
|
||||
**Resolution** (the window's or full-screen size; borderless uses the monitor's), **Render scale** (50% to 200% of
|
||||
the window's resolution for the 3D) and **Frame rate** (60 fps, or the monitor's refresh with the frames between the
|
||||
game's interpolated). Left/Right changes a row; **Apply and save** applies the choices at once and writes them to
|
||||
`video.ini`, the same file as the launcher's Settings and **F2 → Video**. Nothing is stored in the game's save.
|
||||
|
||||
| Control | Effect and limits |
|
||||
|---|---|
|
||||
| Infinite health | Keeps all party HP full and cancels queued loss |
|
||||
@@ -20,8 +26,17 @@ The same cheat controls remain available in **F2 → Cheats**. Both interfaces s
|
||||
| Movement speed | 50–200% horizontal player displacement before collision; leaves gravity unchanged |
|
||||
| Freeze time of day | Holds one shared time input for outdoor sky and lighting; game/story timers and menu fades continue |
|
||||
| Inventory size | One edit, 1–100 slots; refuses shrinkage that would hide an occupied entry or exceed capacity with active quantities |
|
||||
| Level up equipped weapon | Fills the equipped weapon's ABS to the game's own threshold; choose **Level up** in the weapon menu as usual. Refused for default weapons, the Serpent Sword and level 99 |
|
||||
| Reveal floor map | Marks every floor cell of the current dungeon floor explored, on arrival and when switched on; unopened chests, Atla and trap circles show too |
|
||||
| Fish always bite | A fish near the bait never leaves it, and a hooked fish stays hooked until you reel in; fish kinds, sizes and points are unchanged |
|
||||
| Spawn item / Spawn count / Give item | Gives up to 10 of a bag item, attachment or weapon through the game's own give-item routine, while there is room. Event, key and story items, default and story weapons are not offered |
|
||||
| Fast-forward speed / always on | 150–400% (default 300%). Hold **`** (the key below Esc) or a gamepad's **touchpad** / **Share** button, or lock it on. Sound is muted while fast |
|
||||
| Damage multiplier | 1–16× damage you deal to monsters, capped at the monster's remaining HP; immunities stay |
|
||||
| One-hit kills | Any hit that deals damage defeats the monster; immunities stay |
|
||||
| No damage taken | Monster attacks never land: no damage, knock-down, status or theft. Poison already active, traps and thirst still apply |
|
||||
| Key finder | The monster carrying the current floor's key blinks as a gold square on the dungeon map |
|
||||
|
||||
On the in-game list, Up/Down selects and scrolls through all 16 rows. Cross toggles on/off rows;
|
||||
On the in-game list, Up/Down selects and scrolls through all 28 rows. Cross toggles on/off rows;
|
||||
Left/Right sets them off/on. ATK, quantities and capacity use Left/Right ±1, L1/R1 ±10, L2/R2 ±100.
|
||||
Gilda uses ±1/100/1000; movement uses ±5%. Select the active slot (1–3, left to right on the HUD)
|
||||
before changing its quantity. Empty slots cannot create items. The row hint describes each control.
|
||||
@@ -32,7 +47,7 @@ may allow a larger quantity afterward; close and reopen Options to refresh the d
|
||||
Quantity requests retain the expected item ID, so changing the selected item before application
|
||||
cannot silently edit a different item. Resizing never deletes or moves items.
|
||||
|
||||
Toggles start off, ABS starts at 1× and movement starts at 100% on each launch. These settings are not
|
||||
Toggles start off, ABS and damage start at 1×, movement at 100% and fast-forward at 300% on each launch. These settings are not
|
||||
stored in saves. Restored resources and one-time inventory edits **are** included if the game saves
|
||||
afterward. Disabling a resource cheat restores normal depletion from its current value.
|
||||
|
||||
@@ -63,3 +78,34 @@ item requests; and observe the inputs reaching collision and both lighting rende
|
||||
transitions and the quit confirmation's default/cancel/one-shot behaviour. Native-window captures
|
||||
check layout and original settings access. Full retail combat and all movement/lighting situations
|
||||
remain part of manual gameplay testing.
|
||||
|
||||
### Level-up, map, fishing, spawner, fast-forward, combat and key finder
|
||||
|
||||
Hook points, all in the main program (the DUN overlay is reached through the main routines it calls, with
|
||||
return-address checks and the identity-matched DUN module):
|
||||
|
||||
- **Level-up**: a one-shot edit at the player's status tick. ABS (`WEAPON_HAVE+0x14`) is set to the compiled
|
||||
`GetWeaponMaxExp` (0x232080) result; the weapon menu's own flow then applies stat gains, attachment absorption,
|
||||
synthsphere counting, `level+1` and the ABS reset. A kill at full ABS never levels a weapon in the original either.
|
||||
- **Map**: `FlushCheckMask` (0x1C3C00, after the floor build clears it) and `checkMask` (0x1C39C0, walking updates)
|
||||
write the 20×20 explored grid (`CDungeonMap+0x8710`) and room flags for cells that have floor, on the two DUN map
|
||||
objects only (0x1DC4BE0, 0x1DD56F0); column 19, which no floor reaches, is left alone. The grid is not saved.
|
||||
- **Fishing**: `rand_check` (0x240050) gets probability 0 for the LeaveFood/LeaveHook rolls only, still drawing its
|
||||
`rand()`; `CFish::Step` (0x240480) holds a hooked fish's timer (state 8, `+0x58`) at 1. DC1 has no line break.
|
||||
- **Spawner**: the compiled `CheckItemGet` (0x1BDD40), `CheckWeaponRot` (0x1BDF90) and `GetItem` (0x1BE060) run on a
|
||||
copy of the hook's context with a sentinel return. Names come from the resident system messages (`SystemMes`,
|
||||
key = number + 100; a weapon's number from `ComItemInfo`, indexed id − 0x51). The allow-list excludes the 53
|
||||
event-flagged bag items (every floor gate key among them), unused IDs, the Synthsphere and default/story weapons.
|
||||
- **Fast-forward**: the frame pacer's cap is raised (the game's clock advances per frame); audio is not queued while
|
||||
fast. `PS2X_FRAME_CAP=0` runs are left unlimited.
|
||||
- **Damage dealt**: an instruction hook at 0x1DC3F4 (`subu v0,v0,s4` in `CMonstorUnit::CheckDmg`, a native site)
|
||||
scales the final damage before the original subtraction. Every player attack reaches monster HP there.
|
||||
- **Damage taken**: `CheckHitUser` (0x1B5920) answers "no hit" (-1) to DUN `BtCheckDamageProc` (return 0x1DBB0E0).
|
||||
- **Key finder**: after `CMonstorUnit::DrawMapSymbol` (0x1D7AA0, from DUN `MainDraw`), the live monster holding a
|
||||
gate key (`unit+i*400+0x1E470`; the floor's own key, `NowDngMap+0x464`, first) is located through its own virtual
|
||||
`GetPosition` and marked with the port's native `set2DSpriteC4` rectangle at the map's transform. No packet is built.
|
||||
|
||||
`dc_native_cheat_extras` checks each hook's decisions against recording stubs. A scripted dungeon run checked the
|
||||
page, map reveal, the key marker, level-up (Dagger ABS 27 → 32), spawning (two Fire), fast-forward (60 → 180 frames
|
||||
per second at 300%) and full HP with no damage taken. `DC_PROBE_CHEATS=1` logs applied level-ups and spawns.
|
||||
Fishing and the damage multiplier still need play-testing in a fishing spot and in combat.
|
||||
@@ -16,6 +16,20 @@
|
||||
0x0012d574 0x0c0411a6 0x00000000 # retire console free-time percentage print
|
||||
# Native SDK submissions do not use the console channel's tag-transfer bit.
|
||||
# Remove those byte read/modify/write operations at their original callers.
|
||||
# main, at mode changes: four flush / sceDmaSend / sceGsSyncPath triples. Two upload VU1 microcode (0x296680,
|
||||
# 0x24f960) that nothing executes; the others send nothing a native consumer reads. v0 is reloaded after each.
|
||||
0x00141388 0x0c045168 0x00000000 # main: no FlushCache
|
||||
0x0014139c 0x0c0431be 0x00000000 # main: no sceDmaSend
|
||||
0x001413ac 0x0c044be6 0x00000000 # main: no sceGsSyncPath wait
|
||||
0x001413b8 0x0c045168 0x00000000 # main: no FlushCache
|
||||
0x001413cc 0x0c0431be 0x00000000 # main: no sceDmaSend
|
||||
0x001413dc 0x0c044be6 0x00000000 # main: no sceGsSyncPath wait
|
||||
0x001415e4 0x0c045168 0x00000000 # main: no FlushCache
|
||||
0x001415f8 0x0c0431be 0x00000000 # main: no VU1 microcode upload (0x296680)
|
||||
0x00141608 0x0c044be6 0x00000000 # main: no sceGsSyncPath wait
|
||||
0x00141614 0x0c045168 0x00000000 # main: no FlushCache
|
||||
0x00141628 0x0c0431be 0x00000000 # main: no VU1 microcode upload (0x24f960)
|
||||
0x00141638 0x0c044be6 0x00000000 # main: no sceGsSyncPath wait
|
||||
0x0014165c 0x90a40000 0x24040000 # main: channel byte read
|
||||
0x00141670 0xa0a20000 0x00000000 # main: channel byte store
|
||||
0x0012d43c 0x90a40000 0x24040000 # MGEndFrame: channel byte read
|
||||
@@ -56,9 +70,22 @@
|
||||
# Retain frame pacing, native visibility and the later native completion callback.
|
||||
0x0012d1dc 0x8f848bd4 0x0804b49a # continue directly at native visibility 0x12d268
|
||||
0x0012d1e0 0x70002e28 0x70002e28 # guard retained delay slot: a1 = 0 (caller-volatile)
|
||||
# The retained SDK send acknowledges completed native work; it reads no packet.
|
||||
0x0012d680 0x8f828bd4 0x00000000 # no packet-object lookup before completion
|
||||
0x0012d688 0x8c450004 0x24050000 # pass no packet/source pointer; retain channel/IRQ semantics
|
||||
# The per-frame transfer tail. The game installs no DMA-completion handler (its only AddDmacHandler is in
|
||||
# sceSifInitCmd, answered natively), so nothing consumes a VIF1 completion; the GIF channel it waits on
|
||||
# never carries a transfer. The frame counter, the channel lookup and the buffer toggle stay.
|
||||
# MGEndFrame's display-buffer swap. sceGsSetHalfOffset only rewrites the draw record's XYOFFSET image, which the
|
||||
# native renderer never reads; sceGsSwapDBuff only passes the records to sceGsPutDispEnv / sceGsPutDrawEnv, which
|
||||
# are no-ops natively. The buffer index toggle below stays.
|
||||
0x0012d5e8 0x0c044f92 0x00000000 # no sceGsSetHalfOffset
|
||||
0x0012d5f4 0x0c045168 0x00000000 # no FlushCache
|
||||
0x0012d608 0x0c044ba8 0x00000000 # no sceGsSwapDBuff
|
||||
0x0012d61c 0x0c043316 0x00000000 # no sceDmaSync of the (always idle) GIF channel
|
||||
0x0012d64c 0x0c0430ea 0x00000000 # no sceDmaGetChan(1): MGInit already stored the same VIF1 handle
|
||||
0x0012d654 0xaf828bc8 0x00000000 # ... so v0 (here the frame counter) is not stored over it
|
||||
0x0012d680 0x8f828bd4 0x00000000 # no packet-object lookup
|
||||
0x0012d688 0x8c450004 0x24050000 # no packet/source pointer
|
||||
0x0012d678 0x0c045168 0x00000000 # no FlushCache before a transfer
|
||||
0x0012d68c 0x0c0431be 0x00000000 # no sceDmaSend: nothing to transfer, nothing waiting on its completion
|
||||
# CVisualMDTVu1 raw draw: retain selected buffer metadata, temporary allocation
|
||||
# extent, all native draw arguments/results, and the post-draw buffer restore.
|
||||
# Its native draw reads MDT assets, so copying console VIF output is unused.
|
||||
@@ -80,6 +107,12 @@
|
||||
0x00154664 0x3c0201d0 0x080551a2 # skip packet End/Terminate to cache call 0x154688
|
||||
0x00154668 0x2444b370 0x00000000 # no unused packet pointer in delay slot
|
||||
0x0015469c 0x8c25b374 0x24050000 # completion has no packet source
|
||||
# Loading callback, every vblank while loading: the same transfer tail as MGEndFrame. No DMA-completion handler
|
||||
# exists and no transfer is ever outstanding, so nothing waits, flushes or sends.
|
||||
0x00154380 0x0c043316 0x00000000 # no sceDmaSync of VIF1
|
||||
0x0015468c 0x0c045174 0x00000000 # no iFlushCache before a transfer
|
||||
0x001546a0 0x0c0431be 0x00000000 # no sceDmaSend of VIF1
|
||||
0x0015474c 0x0c043316 0x00000000 # no sceDmaSync of GIF
|
||||
0x001546c4 0x8f828bc0 0x080551cb # skip half-offset/display/cache setup to buffer toggle 0x15472c
|
||||
0x001546c8 0x10400005 0x00000000 # discard obsolete environment-selection branch
|
||||
# TexAnime: native texture copies require no leading/trailing TEXFLUSH packets.
|
||||
@@ -350,3 +383,5 @@
|
||||
0x00223760 0x8f848bd4 0x24040000 # null packet argument; DrawNewFileTemplete__Fiii
|
||||
0x002237f0 0x8f848bd4 0x24040000 # null packet argument; DrawNewFileTemplete__Fiii
|
||||
0x00223858 0x8f848bd4 0x24040000 # null packet argument; DrawNewFileTemplete__Fiii
|
||||
# main's mode change: sceGsSyncPath always answers idle; v0 is reloaded right after.
|
||||
0x00141334 0x0c044be6 0x00000000 # main: no sceGsSyncPath
|
||||
+309
-5
@@ -7,15 +7,24 @@
|
||||
#include <atomic>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <bit>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace dc::cheats
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::array<std::atomic<bool>, 5> options{};
|
||||
std::array<std::atomic<bool>, 11> options{};
|
||||
std::atomic<int> damageRate{1};
|
||||
std::atomic<int> fastRate{300};
|
||||
std::atomic<bool> fastHeld{false};
|
||||
std::atomic<int> currentAttack{-1}, pendingAttack{-1};
|
||||
std::atomic<int> absRate{1},moveRate{100},currentGilda{-1},pendingGilda{-1};
|
||||
std::atomic<int> currentSize{-1},minimumSize{1},pendingSize{-1};
|
||||
@@ -27,6 +36,38 @@ namespace dc::cheats
|
||||
bozo::port::InstructionHandler priorInstruction=nullptr;
|
||||
RecompiledFunction moveCheck=nullptr,sky=nullptr,light=nullptr;
|
||||
constexpr uint32_t kMoveCheck=0x14A680u,kSky=0x187F90u,kLight=0x188D50u,kAbsGain=0x1DF2A0u;
|
||||
// Fishing (town only): every fish decision is rand_check(p) (0x240050, one rand() per call); a hooked fish
|
||||
// escapes only when its action timer (+0x58) runs out in state 8 (+0x50). DC1 has no line break.
|
||||
RecompiledFunction randCheck=nullptr,fishStep=nullptr;
|
||||
constexpr uint32_t kRandCheck=0x240050u,kFishStep=0x240480u;
|
||||
constexpr uint32_t kLeaveFood=0x2403FCu,kLeaveHook=0x24044Cu; // rand_check's return addresses in LeaveFood/LeaveHook
|
||||
// Dungeon floor maps: the two CDungeonMap objects of DUN's .bss (main floor, sub-map), each with a 20 x 20
|
||||
// explored grid (+0x8710, ints, index x + z * 20), 16 room-visited flags (+0x8) and the cell table (+0x9C50,
|
||||
// 16-byte records, part -1: no floor). FlushCheckMask clears them as a floor is built; checkMask marks them as
|
||||
// the player walks; only DrawMiniMap reads them (not saved).
|
||||
RecompiledFunction checkMask=nullptr,flushMask=nullptr;
|
||||
constexpr uint32_t kCheckMask=0x1C39C0u,kFlushMask=0x1C3C00u,kDunResident=0x1DB7450u;
|
||||
constexpr uint32_t kMapMain=0x01DC4BE0u,kMapSub=0x01DD56F0u;
|
||||
// Calling compiled game routines from a hook: GetWeaponMaxExp, CheckItemGet, CheckWeaponRot, GetItem.
|
||||
RecompiledFunction maxExp=nullptr,checkItemGet=nullptr,checkWeaponRot=nullptr,getItem=nullptr;
|
||||
constexpr uint32_t kMaxExp=0x232080u,kCheckItemGet=0x1BDD40u,kCheckWeaponRot=0x1BDF90u,kGetItem=0x1BE060u;
|
||||
constexpr uint32_t kReturnSentinel=0x00080000u; // not code: a routine's jr ra lands here
|
||||
std::atomic<bool> pendingLevel{false};
|
||||
std::atomic<uint32_t> pendingSpawn{0}; // id | count << 16
|
||||
std::mutex spawnMutex;
|
||||
std::vector<SpawnItem> spawnList;
|
||||
bool spawnListBuilt=false;
|
||||
// Combat: every player attack (melee, shots, magic, bombs, thrown items) reaches a monster's HP at one
|
||||
// instruction of CMonstorUnit::CheckDmg, 0x1DC3F4 subu v0,v0,s4 (v0 HP, s4 the final damage, s5 the unit).
|
||||
// The player is hit only where DUN's BtCheckDamageProc asks CheckHitUser (0x1B5920; returns to 0x1DBB0E0).
|
||||
constexpr uint32_t kMonsterHp=0x1DC3F4u,kCheckHitUser=0x1B5920u,kHitUserReturn=0x1DBB0E0u;
|
||||
RecompiledFunction checkHitUser=nullptr;
|
||||
// Key finder: SetKey gives a floor's key to one live monster (unit = gp-0x6320, 16 slots of 400 bytes: state
|
||||
// +0x1E3D0 (-1 none), HP +0x1E3F4, item +0x1E470 (s16, -1 none)). DUN MainDraw calls DrawMapSymbol (0x1D7AA0,
|
||||
// returning to 0x1DB0348) to put monster icons on the map; the marker is drawn after it.
|
||||
constexpr uint32_t kMapSymbols=0x1D7AA0u,kMapSymbolsReturn=0x1DB0348u,kColourRect=0x15E120u;
|
||||
RecompiledFunction mapSymbols=nullptr,colourRect=nullptr;
|
||||
uint32_t markerBlink=0;
|
||||
RecompiledFunction addLife = nullptr, setLife = nullptr, addDrink = nullptr, step = nullptr, wear = nullptr;
|
||||
constexpr uint32_t kAddLife = 0x001BE710u, kSetLife = 0x001BE900u, kAddDrink = 0x001BE510u,
|
||||
kStep = 0x001BEA50u, kWear = 0x001B5D90u;
|
||||
@@ -60,6 +101,9 @@ namespace dc::cheats
|
||||
return read<int16_t>(ram,record)>0 ? record : 0;
|
||||
}
|
||||
void weaponAttack(uint8_t *ram,uint32_t status);
|
||||
void levelUp(uint8_t *ram,uint32_t s,const R5900Context *ctx,Runtime *rt);
|
||||
void spawn(uint8_t *ram,uint32_t s,const R5900Context *ctx,Runtime *rt);
|
||||
void buildSpawnList(const uint8_t *ram);
|
||||
// GetItem and GetNowItemNum count active quantities as bag occupancy.
|
||||
// The backing array has 103 entries; ordinary capacity is at most 100.
|
||||
int occupied(const uint8_t *ram,uint32_t s,int excludedSlot=-1)
|
||||
@@ -94,7 +138,7 @@ namespace dc::cheats
|
||||
for(int i=0;i<3;++i){const auto a=item(ram,s,i);currentItems[i].store(
|
||||
a.id<0?0:uint64_t(a.id)|(uint64_t(a.quantity)<<16)|(uint64_t(a.maximum)<<32),std::memory_order_relaxed);}
|
||||
}
|
||||
void editPlayer(uint8_t *ram,uint32_t s)
|
||||
void editPlayer(uint8_t *ram,uint32_t s,const R5900Context *ctx=nullptr,Runtime *rt=nullptr)
|
||||
{
|
||||
const int size=pendingSize.exchange(-1,std::memory_order_relaxed);
|
||||
const int gold=pendingGilda.exchange(-1,std::memory_order_relaxed);
|
||||
@@ -104,15 +148,147 @@ namespace dc::cheats
|
||||
if(request && a.id==int(request&65535) && a.maximum>0)
|
||||
write<int16_t>(ram,s+0x4368+i*2,static_cast<int16_t>(std::clamp(int(request>>16),1,a.maximum)));}
|
||||
weaponAttack(ram,s);
|
||||
if(s){levelUp(ram,s,ctx,rt);spawn(ram,s,ctx,rt);buildSpawnList(ram);}
|
||||
publishPlayer(ram,s);
|
||||
}
|
||||
// Runs a compiled routine on a copy of the hook's context (its own frame below the current stack, its return to
|
||||
// a sentinel). -1 when it did not return there (a routine that blocks or switches threads is never called so).
|
||||
bool callGameDone(RecompiledFunction routine,uint8_t *ram,const R5900Context *ctx,Runtime *rt,
|
||||
std::initializer_list<uint32_t> args,int32_t *result=nullptr)
|
||||
{
|
||||
if(!routine || !ctx || !rt)return false;
|
||||
R5900Context call=*ctx;
|
||||
int reg=4;
|
||||
for(const uint32_t a:args)call.r[reg++].ud[0]=uint64_t(int64_t(int32_t(a)));
|
||||
call.r[31].ud[0]=kReturnSentinel;
|
||||
call.leaving=false;
|
||||
routine(ram,&call,rt);
|
||||
if(call.pc!=kReturnSentinel || call.leaving)return false;
|
||||
if(result)*result=getRegS32(&call,2);
|
||||
return true;
|
||||
}
|
||||
int32_t callGame(RecompiledFunction routine,uint8_t *ram,const R5900Context *ctx,Runtime *rt,
|
||||
std::initializer_list<uint32_t> args)
|
||||
{
|
||||
int32_t result=-1;
|
||||
return callGameDone(routine,ram,ctx,rt,args,&result)?result:-1;
|
||||
}
|
||||
// DC_PROBE_CHEATS=1: the one-shot edits that call game routines, as they are applied.
|
||||
bool probe(){static const bool on=std::getenv("DC_PROBE_CHEATS")!=nullptr;return on;}
|
||||
bool defaultWeapon(int id){return id==0x101 || id==0x12B || id==0x13A || id==0x14B || id==0x15B || id==0x16B;}
|
||||
void levelUp(uint8_t *ram,uint32_t s,const R5900Context *ctx,Runtime *rt)
|
||||
{
|
||||
if(!rt || !pendingLevel.exchange(false,std::memory_order_relaxed))return;
|
||||
const uint32_t w=equippedWeapon(ram,s);
|
||||
if(!w)return;
|
||||
const int id=read<int16_t>(ram,w),level=read<int16_t>(ram,w+2);
|
||||
// The game's own refusals: default weapons earn no ABS, the Serpent Sword waits for a story flag, 99 is
|
||||
// the last level.
|
||||
if(defaultWeapon(id) || id==0x10C || level>=99)return;
|
||||
const int32_t needed=callGame(maxExp,ram,ctx,rt,{w});
|
||||
const int before=read<int16_t>(ram,w+0x14);
|
||||
if(needed>0 && needed<=999 && before<needed)write<int16_t>(ram,w+0x14,int16_t(needed));
|
||||
if(probe())std::fprintf(stderr,"[dc:cheats] level-up: weapon 0x%x level %d ABS %d -> %d (needed %d)\n",id,level,before,
|
||||
read<int16_t>(ram,w+0x14),needed);
|
||||
}
|
||||
// The game's text: 16-bit codes (0xFD21.. 'A'.., 0xFD3B.. 'a'.., 0xFD6F.. '0'.., 0xFF02 space, 0xFF01 end).
|
||||
std::string gameText(const uint8_t *ram,int key)
|
||||
{
|
||||
const uint32_t buffer=read<uint32_t>(ram,0x2A2528u)&0x1FFFFFFu; // SystemMes, resident all session
|
||||
if(!buffer || buffer>0x1F00000u)return {};
|
||||
const int count=read<int16_t>(ram,buffer);
|
||||
if(count<=0 || count>4000)return {};
|
||||
for(int i=0;i<count;++i)
|
||||
{
|
||||
if(read<int16_t>(ram,buffer+4+4*uint32_t(i))!=key)continue;
|
||||
uint32_t at=buffer+2*uint32_t(count+read<int16_t>(ram,buffer+6+4*uint32_t(i))+1);
|
||||
std::string text;
|
||||
for(int n=0;n<40 && at<0x1FFFFFEu;++n,at+=2)
|
||||
{
|
||||
const uint16_t c=read<uint16_t>(ram,at);
|
||||
if(c==0xFF01)break;
|
||||
if(c>=0xFD21 && c<=0xFD3A)text+=char('A'+c-0xFD21);
|
||||
else if(c>=0xFD3B && c<=0xFD54)text+=char('a'+c-0xFD3B);
|
||||
else if(c>=0xFD6F && c<=0xFD78)text+=char('0'+c-0xFD6F);
|
||||
else if(c==0xFF02)text+=' ';
|
||||
else if(c==0xFD55)text+='\'';
|
||||
else if(c==0xFD5D)text+='-';
|
||||
else if(c==0xFD6D)text+='.';
|
||||
else if(c==0xFD5B)text+='&';
|
||||
else if(c==0xFD61)text+='(';
|
||||
else if(c==0xFD62)text+=')';
|
||||
else return {}; // an argument or a mark: not a plain item name
|
||||
}
|
||||
return text;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
// What the spawner offers: no event/key/story item (they satisfy doors and NPCs out of order), no default or
|
||||
// story weapon, no unused ID.
|
||||
bool spawnable(int id)
|
||||
{
|
||||
if(id>=0x84 && id<=0x100)
|
||||
return (id<=0x8D) || (id>=0x91 && id<=0x9B) || (id>=0x9F && id<=0xB7) || (id>=0xBA && id<=0xC1) ||
|
||||
id==0xC5 || id==0xC7 || (id>=0xF5 && id<=0xF7);
|
||||
if(id>=0x51 && id<=0x83)
|
||||
return (id<=0x55) || (id>=0x5B && id<=0x6B) || (id>=0x6F && id<=0x78);
|
||||
if(id>=0x102 && id<=0x177)
|
||||
{
|
||||
constexpr int excluded[]={0x10B,0x10C,0x115,0x116,0x117,0x118,0x129,0x12A,0x12B,0x13A,0x146,0x14A,0x14B,
|
||||
0x156,0x15A,0x15B,0x166,0x169,0x16A,0x16B};
|
||||
return std::find(std::begin(excluded),std::end(excluded),id)==std::end(excluded);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void buildSpawnList(const uint8_t *ram)
|
||||
{
|
||||
if(spawnListBuilt)return;
|
||||
std::vector<SpawnItem> list;
|
||||
for(int id=0x51;id<=0x177;++id)
|
||||
{
|
||||
if(!spawnable(id))continue;
|
||||
// System message id + 100: a bag item's or an attachment's number is its id; a weapon's is ComItemInfo's
|
||||
// (8-byte entries indexed id - 0x51, the number at +6; 0 = unused).
|
||||
const int number=id<=0x100 ? id : read<int16_t>(ram,0x27DE50u+uint32_t(id-0x51)*8+6);
|
||||
if(number<=0)continue;
|
||||
const int key=number+100;
|
||||
const std::string name=gameText(ram,key);
|
||||
if(name.empty())continue;
|
||||
SpawnItem item;item.id=id;std::snprintf(item.name,sizeof(item.name),"%s",name.c_str());
|
||||
list.push_back(item);
|
||||
}
|
||||
if(list.empty())return; // the messages are not loaded yet
|
||||
std::lock_guard lock(spawnMutex);
|
||||
spawnList=std::move(list);spawnListBuilt=true;
|
||||
}
|
||||
void spawn(uint8_t *ram,uint32_t s,const R5900Context *ctx,Runtime *rt)
|
||||
{
|
||||
if(!rt)return;
|
||||
const uint32_t request=pendingSpawn.exchange(0,std::memory_order_relaxed);
|
||||
const int id=int(request&0xFFFF),count=std::clamp(int(request>>16),1,10);
|
||||
if(!request || !validStatus(s) || !spawnable(id))return;
|
||||
int given=0;
|
||||
for(int n=0;n<count;++n,++given)
|
||||
{
|
||||
if(id>=0x101)
|
||||
{
|
||||
// A weapon goes to its owner, who must have joined (+5: party size), with room left in slots 0..9.
|
||||
const int owner=read<int8_t>(ram,0x275A7Eu+uint32_t(id)*0x4C);
|
||||
if(owner<0 || owner>=read<int8_t>(ram,s+5) || callGame(checkWeaponRot,ram,ctx,rt,{s,uint32_t(id)})>=9)break;
|
||||
}
|
||||
else if(callGame(checkItemGet,ram,ctx,rt,{s,uint32_t(id)})!=0)break; // bag or attachments full
|
||||
// a2 = 1: a stat sphere (0x5B..0x5E) gives its +1 bonus, as when one is found.
|
||||
if(callGame(getItem,ram,ctx,rt,{s,uint32_t(id),1u})<0)break;
|
||||
}
|
||||
if(probe())std::fprintf(stderr,"[dc:cheats] spawn: item 0x%x, %d of %d given\n",id,given,count);
|
||||
}
|
||||
void moveHook(uint8_t *ram,R5900Context *ctx,Runtime *rt)
|
||||
{
|
||||
const uint32_t caller=getRegU32(ctx,31);
|
||||
const bool town=caller==0x16A9C0u;
|
||||
const bool dungeon=(caller==0x1DB39F4u || caller==0x1DB3EA0u || caller==0x1DB5C10u) && rt->functions.generated(0x1DB7450u);
|
||||
if(town || dungeon){
|
||||
editPlayer(ram,playerStatus(ram,ctx));
|
||||
editPlayer(ram,playerStatus(ram,ctx),ctx,rt);
|
||||
const int rate=movementPercent();
|
||||
const int64_t p=bozo::GuestMemory::flatOffset(getRegU32(ctx,5),12);
|
||||
if(rate!=100 && p>0 && p<=bozo::kFlatScratchpadOffset-12){
|
||||
@@ -134,6 +310,99 @@ namespace dc::cheats
|
||||
if(!haveHeldTime && std::isfinite(time) && time>=0 && time<=12){heldTime=time;haveHeldTime=true;}
|
||||
if(haveHeldTime)ctx->fu[12]=std::bit_cast<uint32_t>(heldTime);
|
||||
}
|
||||
void randCheckHook(uint8_t *r,R5900Context *c,Runtime *rt)
|
||||
{
|
||||
// A fish near the bait never decides to leave it: p = 0 for the two Leave rolls only. The call still draws
|
||||
// its rand(), so the shared sequence advances as it would; the Find/Eat/Bite odds (bait affinity) stay.
|
||||
const uint32_t from=getRegU32(c,31);
|
||||
if(enabled(Cheat::FishingHelper) && (from==kLeaveFood || from==kLeaveHook))c->fu[12]=0;
|
||||
randCheck(r,c,rt);
|
||||
}
|
||||
void fishStepHook(uint8_t *r,R5900Context *c,Runtime *rt)
|
||||
{
|
||||
// A hooked fish (state 8) stays hooked until the button is pressed: its timer never runs out.
|
||||
const int64_t fish=bozo::GuestMemory::flatOffset(getRegU32(c,4),0x60);
|
||||
if(enabled(Cheat::FishingHelper) && fish>=0 && fish<=bozo::kFlatScratchpadOffset-0x60 &&
|
||||
read<int32_t>(r,uint32_t(fish)+0x50)==8 && read<int32_t>(r,uint32_t(fish)+0x58)<1)
|
||||
write<int32_t>(r,uint32_t(fish)+0x58,1);
|
||||
fishStep(r,c,rt);
|
||||
}
|
||||
void revealFloor(uint8_t *r,uint32_t map)
|
||||
{
|
||||
if(map!=kMapMain && map!=kMapSub)return;
|
||||
// Every cell with floor, except column x = 19: SetUnderLoad fills it, but no floor reaches it.
|
||||
for(uint32_t i=0;i<400;++i)
|
||||
if(i%20!=19 && read<int32_t>(r,map+0x9C50+i*16)!=-1)write<int32_t>(r,map+0x8710+i*4,1);
|
||||
const int rooms=std::clamp(read<int32_t>(r,map+0xB650),0,16);
|
||||
for(int i=0;i<rooms;++i)
|
||||
if(read<int32_t>(r,map+0xB558+i*16)!=0)write<int32_t>(r,map+0x8+i*4,1);
|
||||
}
|
||||
void flushMaskHook(uint8_t *r,R5900Context *c,Runtime *rt)
|
||||
{
|
||||
// On arrival: after the floor build clears the grid (the three DUN floor-build call sites only).
|
||||
const uint32_t from=getRegU32(c,31),map=getRegU32(c,4);
|
||||
flushMask(r,c,rt);
|
||||
if(enabled(Cheat::RevealFloorMap) && !c->leaving && c->pc==from &&
|
||||
(from==0x1DB8A1Cu || from==0x1DB913Cu || from==0x1DB91FCu) && rt->functions.generated(kDunResident))
|
||||
revealFloor(r,map);
|
||||
}
|
||||
void checkMaskHook(uint8_t *r,R5900Context *c,Runtime *rt)
|
||||
{
|
||||
// Switched on mid-floor: at MoveChara's next walking update (it only ever adds explored cells).
|
||||
if(enabled(Cheat::RevealFloorMap) && getRegU32(c,31)==0x1DB159Cu && rt->functions.generated(kDunResident))
|
||||
revealFloor(r,getRegU32(c,4));
|
||||
checkMask(r,c,rt);
|
||||
}
|
||||
void checkHitUserHook(uint8_t *r,R5900Context *c,Runtime *rt)
|
||||
{
|
||||
// No damage taken: the hit test answers "no hit" (-1) to the player's hit routine, before its damage,
|
||||
// knock-down, status and theft effects.
|
||||
if(enabled(Cheat::NoDamageTaken) && getRegU32(c,31)==kHitUserReturn && rt->functions.generated(kDunResident))
|
||||
{setReturnS32(c,-1);c->pc=getRegU32(c,31);return;}
|
||||
checkHitUser(r,c,rt);
|
||||
}
|
||||
bool gateKey(int item){return item==0xC3 || item==0xC4 || item==0xC6 || (item>=0xC9 && item<=0xCE);}
|
||||
void mapSymbolsHook(uint8_t *r,R5900Context *c,Runtime *rt)
|
||||
{
|
||||
const uint32_t from=getRegU32(c,31);
|
||||
mapSymbols(r,c,rt);
|
||||
if(!enabled(Cheat::KeyFinder) || from!=kMapSymbolsReturn || c->pc!=from || !rt->functions.generated(kDunResident) ||
|
||||
!colourRect)return;
|
||||
const uint32_t gp=getRegU32(c,28),unit=read<uint32_t>(r,(gp-0x6320u)&0x1FFFFFFu)&0x1FFFFFFu;
|
||||
const uint32_t map=read<uint32_t>(r,(gp-0x6338u)&0x1FFFFFFu)&0x1FFFFFFu;
|
||||
if(!unit || unit>0x1F00000u)return;
|
||||
const int wanted=map && map<0x1F00000u ? read<int32_t>(r,map+0x464) : -1;
|
||||
int holder=-1;
|
||||
for(int i=0;i<16;++i){
|
||||
const uint32_t slot=unit+uint32_t(i)*400;
|
||||
const int item=read<int16_t>(r,slot+0x1E470);
|
||||
if(read<int32_t>(r,slot+0x1E3D0)==-1 || read<int32_t>(r,slot+0x1E3F4)<=0 || !gateKey(item))continue;
|
||||
if(holder<0 || item==wanted)holder=i; // dungeon 1 places three keys: the floor's own wins
|
||||
}
|
||||
if(holder<0)return;
|
||||
// Scratch guest memory below the stack, as the routine's own frame would use: position, rectangles.
|
||||
const uint32_t scratch=(getRegU32(c,29)-0x200u)&~15u;
|
||||
const uint32_t character=unit+uint32_t(holder)*0x3510+0x1FCD0u;
|
||||
// Its position through its own virtual GetPosition (vtable at +0xA0, slot +0xA0), as DrawMapSymbol asks.
|
||||
const uint32_t table=read<uint32_t>(r,(character+0xA0)&0x1FFFFFFu)&0x1FFFFFFu;
|
||||
const uint32_t getPosition=table?read<uint32_t>(r,(table+0xA0)&0x1FFFFFFu):0u;
|
||||
RecompiledFunction locate=rt->functions.override(getPosition);if(!locate)locate=rt->functions.generated(getPosition);
|
||||
if(!locate || !callGameDone(locate,r,c,rt,{character,scratch}))return;
|
||||
const float scale=read<float>(r,(gp-0x7F80u)&0x1FFFFFFu),x=read<float>(r,scratch),z=read<float>(r,scratch+8);
|
||||
if(!std::isfinite(x) || !std::isfinite(z) || !std::isfinite(scale))return;
|
||||
// A solid gold square, 10 x 10 around the holder's 8 x 8 icon position, blinking: drawn by the port's native
|
||||
// colour-rectangle routine (set2DSpriteC4), like the game's own map rectangles.
|
||||
const int32_t rect[4]={int32_t(scale*x)+384-1,int32_t(scale*z)+68-1,10,10};
|
||||
// spRGBA: the bytes R, G, B, A (255, 200, 32), alpha 0x80 = 1.0 then 0: blinking.
|
||||
const uint32_t gold=((++markerBlink/15)%2?0x80u:0x00u)<<24|0x0020C8FFu; // on and off: unlike the static exit tile
|
||||
std::memcpy(r+scratch+0x20,rect,16);
|
||||
for(uint32_t k=0;k<4;++k)write<uint32_t>(r,scratch+0x30+k*4,gold);
|
||||
R5900Context draw=*c;
|
||||
draw.r[4].ud[0]=0;draw.r[5].ud[0]=scratch+0x20;
|
||||
for(int k=0;k<4;++k)draw.r[6+k].ud[0]=scratch+0x30+uint32_t(k)*4;
|
||||
draw.r[31].ud[0]=kReturnSentinel;draw.pc=kColourRect;
|
||||
colourRect(r,&draw,rt);
|
||||
}
|
||||
void skyHook(uint8_t *r,R5900Context *c,Runtime *rt){timeInput(c);sky(r,c,rt);}
|
||||
void lightHook(uint8_t *r,R5900Context *c,Runtime *rt){timeInput(c);light(r,c,rt);}
|
||||
bool instruction(uint8_t *r,R5900Context *c,Runtime *rt,uint32_t pc)
|
||||
@@ -148,6 +417,18 @@ namespace dc::cheats
|
||||
c->r[7].ud[0]=uint64_t(std::min(int64_t(reward)*rate,int64_t(32767)));
|
||||
return false; // execute the original lh v1,0x14(s3)
|
||||
}
|
||||
if(pc==kMonsterHp){
|
||||
// Scales the final damage just before the original subtraction; immunities (0 damage) stay. Capped at
|
||||
// the HP left (or the original damage, if higher), so the damage number stays the game's own range.
|
||||
const int64_t damage=getRegS32(c,20),hp=getRegS32(c,2);
|
||||
if(damage>0){
|
||||
int64_t scaled=damage;
|
||||
if(enabled(Cheat::OneHitKills))scaled=std::max(damage,hp);
|
||||
else if(damageMultiplier()>1)scaled=std::min(damage*damageMultiplier(),std::max(damage,hp));
|
||||
c->r[20].ud[0]=uint64_t(scaled);
|
||||
}
|
||||
return false; // execute the original subu v0,v0,s4
|
||||
}
|
||||
return priorInstruction && priorInstruction(r,c,rt,pc);
|
||||
}
|
||||
void weaponAttack(uint8_t *ram,uint32_t status)
|
||||
@@ -236,7 +517,7 @@ namespace dc::cheats
|
||||
// The weapon menu ticks a preview copy of CUserStatus. Queue edits
|
||||
// until the real player is ticking again, rather than consuming
|
||||
// the request on a temporary preview/inventory allocation.
|
||||
if (!player || player==status) editPlayer(ram,player);
|
||||
if (!player || player==status) editPlayer(ram,player,ctx,runtime);
|
||||
else
|
||||
{
|
||||
const uint32_t weapon=equippedWeapon(ram,player);
|
||||
@@ -275,6 +556,12 @@ namespace dc::cheats
|
||||
void requestWeaponAttack(int value) { pendingAttack.store(std::clamp(value,0,999),std::memory_order_relaxed); }
|
||||
int absMultiplier(){return absRate.load(std::memory_order_relaxed);}
|
||||
void setAbsMultiplier(int v){absRate.store(std::clamp(v,1,16),std::memory_order_relaxed);}
|
||||
int fastForwardPercent(){return fastRate.load(std::memory_order_relaxed);}
|
||||
void setFastForwardPercent(int v){fastRate.store(std::clamp(v,150,400),std::memory_order_relaxed);}
|
||||
void setFastForwardHeld(bool held){fastHeld.store(held,std::memory_order_relaxed);}
|
||||
int gameSpeedPercent(){return fastHeld.load(std::memory_order_relaxed) || enabled(Cheat::FastForwardLock) ? fastForwardPercent() : 100;}
|
||||
int damageMultiplier(){return damageRate.load(std::memory_order_relaxed);}
|
||||
void setDamageMultiplier(int v){damageRate.store(std::clamp(v,1,16),std::memory_order_relaxed);}
|
||||
int movementPercent(){return moveRate.load(std::memory_order_relaxed);}
|
||||
void setMovementPercent(int v){moveRate.store(std::clamp(v,50,200),std::memory_order_relaxed);}
|
||||
int gilda(){return currentGilda.load(std::memory_order_relaxed);}
|
||||
@@ -290,7 +577,11 @@ namespace dc::cheats
|
||||
const auto a=activeConsumable(slot);if(a.id<0 || a.maximum<1)return;
|
||||
pendingItems[slot].store(uint64_t(a.id)|(uint64_t(std::clamp(quantity,1,a.maximum))<<16),std::memory_order_relaxed);
|
||||
}
|
||||
void refreshPlayer(const uint8_t *r,const R5900Context *c){publishPlayer(r,playerStatus(r,c));}
|
||||
void requestWeaponLevelUp(){pendingLevel.store(true,std::memory_order_relaxed);}
|
||||
int spawnItemCount(){std::lock_guard lock(spawnMutex);return int(spawnList.size());}
|
||||
SpawnItem spawnItem(int index){std::lock_guard lock(spawnMutex);return index>=0 && index<int(spawnList.size())?spawnList[size_t(index)]:SpawnItem{};}
|
||||
void requestSpawn(int id,int count){if(spawnable(id))pendingSpawn.store(uint32_t(id)|uint32_t(std::clamp(count,1,10))<<16,std::memory_order_relaxed);}
|
||||
void refreshPlayer(const uint8_t *r,const R5900Context *c){publishPlayer(r,playerStatus(r,c));buildSpawnList(r);}
|
||||
void applyPlayerEdits(uint8_t *r,const R5900Context *c){editPlayer(r,playerStatus(r,c));}
|
||||
void install(Runtime &runtime, bozo::port::Registry ®istry)
|
||||
{
|
||||
@@ -307,6 +598,19 @@ namespace dc::cheats
|
||||
if(moveCheck)registry.registerFunction(kMoveCheck,moveHook);
|
||||
if(sky)registry.registerFunction(kSky,skyHook);
|
||||
if(light)registry.registerFunction(kLight,lightHook);
|
||||
randCheck=runtime.functions.generated(kRandCheck);fishStep=runtime.functions.generated(kFishStep);
|
||||
if(randCheck)registry.registerFunction(kRandCheck,randCheckHook);
|
||||
if(fishStep)registry.registerFunction(kFishStep,fishStepHook);
|
||||
checkMask=runtime.functions.generated(kCheckMask);flushMask=runtime.functions.generated(kFlushMask);
|
||||
if(checkMask)registry.registerFunction(kCheckMask,checkMaskHook);
|
||||
if(flushMask)registry.registerFunction(kFlushMask,flushMaskHook);
|
||||
maxExp=runtime.functions.generated(kMaxExp);checkItemGet=runtime.functions.generated(kCheckItemGet);
|
||||
checkWeaponRot=runtime.functions.generated(kCheckWeaponRot);getItem=runtime.functions.generated(kGetItem);
|
||||
checkHitUser=runtime.functions.generated(kCheckHitUser);
|
||||
if(checkHitUser)registry.registerFunction(kCheckHitUser,checkHitUserHook);
|
||||
mapSymbols=registry.find(kMapSymbols);if(!mapSymbols)mapSymbols=runtime.functions.generated(kMapSymbols);
|
||||
colourRect=registry.find(kColourRect); // the port's native rectangle drawing (dc_native), installed first
|
||||
if(mapSymbols)registry.registerFunction(kMapSymbols,mapSymbolsHook);
|
||||
priorInstruction=registry.instructionHandler();registry.nativeGraphics(instruction);
|
||||
}
|
||||
}
|
||||
+19
-1
@@ -8,13 +8,21 @@ namespace bozo::port { class Registry; }
|
||||
|
||||
namespace dc::cheats
|
||||
{
|
||||
enum class Cheat { InfiniteHealth, InfiniteWeaponDurability, InfiniteThirst, InfiniteStamina, FreezeTimeOfDay };
|
||||
enum class Cheat { InfiniteHealth, InfiniteWeaponDurability, InfiniteThirst, InfiniteStamina, FreezeTimeOfDay, FastForwardLock, FishingHelper, RevealFloorMap, OneHitKills, NoDamageTaken, KeyFinder };
|
||||
bool enabled(Cheat cheat);
|
||||
void setEnabled(Cheat cheat, bool on);
|
||||
// Fast-forward: while held (the window's ` key or a gamepad's touchpad / Share button) or locked on, the frame
|
||||
// cap is raised to this percentage of the normal rate and the sound is muted. Game logic runs per frame.
|
||||
int fastForwardPercent();
|
||||
void setFastForwardPercent(int value); // 150..400
|
||||
void setFastForwardHeld(bool held); // window input, sampled once a frame
|
||||
int gameSpeedPercent(); // 100, or fastForwardPercent() while held or locked
|
||||
int equippedWeaponAttack(); // game-thread snapshot; -1 when no weapon is equipped
|
||||
void requestWeaponAttack(int value); // one edit, applied on the game thread
|
||||
int absMultiplier();
|
||||
void setAbsMultiplier(int value); // 1..16, positive combat rewards only
|
||||
int damageMultiplier();
|
||||
void setDamageMultiplier(int value); // 1..16, damage the party deals to monsters
|
||||
int movementPercent();
|
||||
void setMovementPercent(int value); // 50..200, horizontal movement before collision
|
||||
int gilda();
|
||||
@@ -25,6 +33,16 @@ namespace dc::cheats
|
||||
struct Consumable { int id=-1, quantity=0, maximum=0; };
|
||||
Consumable activeConsumable(int slot);
|
||||
void requestConsumableQuantity(int slot,int quantity);
|
||||
// Weapon level-up: fills the equipped weapon's ABS to the game's own threshold (GetWeaponMaxExp); the player then
|
||||
// levels it up in the weapon menu as usual. Refused for default weapons, the Serpent Sword and level 99.
|
||||
void requestWeaponLevelUp();
|
||||
// Item spawner: the bag items, attachments and weapons the game's GetItem may give without touching story
|
||||
// progress (event/key items, default and story weapons, unused IDs excluded), with their names read from the
|
||||
// game's resident system messages. Empty until the game has loaded them.
|
||||
struct SpawnItem { int id = 0; char name[32] = {}; };
|
||||
int spawnItemCount();
|
||||
SpawnItem spawnItem(int index);
|
||||
void requestSpawn(int id, int count); // count 1..10; stops at the first refusal (bag/attachment/weapon full)
|
||||
// Authoritative player state only. Called on the game thread at Options
|
||||
// entry/exit and gameplay updates, never against inventory preview copies.
|
||||
void refreshPlayer(const uint8_t *ram,const R5900Context *ctx);
|
||||
|
||||
@@ -32,6 +32,10 @@ namespace dc::cheats
|
||||
ImGui::TextWrapped("Applies when gameplay resumes. The edited ATK is included when you save your game.");
|
||||
ImGui::Separator();
|
||||
int abs=absMultiplier();if(ImGui::SliderInt("Weapon ABS multiplier",&abs,1,16,"%dx"))setAbsMultiplier(abs);
|
||||
int damage=damageMultiplier();if(ImGui::SliderInt("Damage multiplier",&damage,1,16,"%dx"))setDamageMultiplier(damage);
|
||||
toggle("One-hit kills", Cheat::OneHitKills, "Any hit that deals damage defeats the monster; immunities still apply.");
|
||||
toggle("No damage taken", Cheat::NoDamageTaken, "Monster attacks never land: no damage, knock-down or theft.");
|
||||
toggle("Key finder", Cheat::KeyFinder, "The monster carrying the floor's key blinks gold on the map.");
|
||||
int speed=movementPercent();if(ImGui::SliderInt("Movement speed",&speed,50,200,"%d%%"))setMovementPercent(speed);
|
||||
toggle("Freeze time of day",Cheat::FreezeTimeOfDay,"Holds sky and lighting; game timers continue.");
|
||||
static int gold=1000;
|
||||
@@ -50,7 +54,34 @@ namespace dc::cheats
|
||||
ImGui::BeginDisabled(inventorySize()<0);if(ImGui::Button("Apply inventory size"))requestInventorySize(capacity);ImGui::EndDisabled();
|
||||
ImGui::TextWrapped("Inventory edits apply when gameplay resumes and are included in game saves. Existing items are never discarded by resizing.");
|
||||
ImGui::Separator();
|
||||
ImGui::TextWrapped("Cheats reset each launch: toggles off, ABS 1x, movement 100%.");
|
||||
ImGui::BeginDisabled(current < 0);
|
||||
if (ImGui::Button("Level up equipped weapon")) requestWeaponLevelUp();
|
||||
ImGui::EndDisabled();
|
||||
ImGui::TextDisabled("Fills its ABS; choose Level up in the weapon menu. Not for default weapons.");
|
||||
toggle("Reveal floor map", Cheat::RevealFloorMap, "Shows the whole dungeon floor on the map, chests and Atla included.");
|
||||
toggle("Fish always bite", Cheat::FishingHelper, "Fish near the bait take it and stay hooked until you reel in.");
|
||||
static int spawn = 0, spawnCount = 1;
|
||||
const int items = spawnItemCount();
|
||||
if (items)
|
||||
{
|
||||
spawn = std::clamp(spawn, 0, items - 1);
|
||||
if (ImGui::BeginCombo("Spawn item", spawnItem(spawn).name))
|
||||
{
|
||||
for (int i = 0; i < items; ++i)
|
||||
if (ImGui::Selectable(spawnItem(i).name, i == spawn)) spawn = i;
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
ImGui::SliderInt("Spawn count", &spawnCount, 1, 10);
|
||||
if (ImGui::Button("Give item")) requestSpawn(spawnItem(spawn).id, spawnCount);
|
||||
ImGui::TextDisabled("Given when gameplay resumes, while there is room. Story and key items are excluded.");
|
||||
}
|
||||
else ImGui::TextDisabled("Item names appear once the game has loaded its messages.");
|
||||
ImGui::Separator();
|
||||
int fast = fastForwardPercent();
|
||||
if (ImGui::SliderInt("Fast-forward speed", &fast, 150, 400, "%d%%")) setFastForwardPercent(fast / 50 * 50);
|
||||
toggle("Fast-forward always on", Cheat::FastForwardLock, "Or hold ` (below Esc) or the gamepad's touchpad. Sound is muted.");
|
||||
ImGui::Separator();
|
||||
ImGui::TextWrapped("Cheats reset each launch: toggles off, ABS 1x, movement 100%, fast-forward 300%.");
|
||||
});
|
||||
}
|
||||
}
|
||||
+164
-17
@@ -4,12 +4,15 @@
|
||||
#include "dc_cheats.h"
|
||||
#include "bozo/port.h"
|
||||
#include "bozo/runtime.h"
|
||||
#include "bozo/app/video_settings.h"
|
||||
#include "bozo/render/renderer.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@@ -23,21 +26,48 @@ constexpr uint32_t kPhase=0x1da8a50,kFade=0x1da8a54,kLoaded=0x1da8ac4,kPad=0x1cb
|
||||
constexpr uint32_t kUp=0x1000,kDown=0x4000,kLeft=0x8000,kRight=0x2000,kCross=0x40,kCircle=0x20;
|
||||
constexpr uint32_t kL1=4,kR1=8,kL2=1,kR2=2;
|
||||
constexpr float identity[16]={1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
|
||||
enum class Page { Root, Game, Cheats, Quit };
|
||||
enum class Page { Root, Game, Graphics, Cheats, Quit };
|
||||
struct Menu {
|
||||
bool active=false,queued=false;
|
||||
Page page=Page::Root;
|
||||
int root=0,row=0,attack=0,quitChoice=0,gold=0,slot=0,quantity=1,capacity=50;
|
||||
int root=0,row=0,attack=0,quitChoice=0,gold=0,slot=0,quantity=1,capacity=50,spawn=0,spawnCount=1;
|
||||
uint32_t held=0,ticks=0;
|
||||
std::shared_ptr<const bozo::render::Texture> font;
|
||||
// Graphics: the window's settings as edited on the page, posted to the window's thread by its Apply row.
|
||||
int graphicsRow=0;
|
||||
bozo::app::video::Settings graphics;
|
||||
const char *graphicsStatus="";
|
||||
} menu;
|
||||
constexpr int rootCount=4;
|
||||
const char *const rootLabels[rootCount]={"Game Options","Graphics","Cheats","Quit Game"};
|
||||
enum GraphicsRow { Display, Resolution, RenderScale, FrameRate, ApplyGraphics, GraphicsRowEnd };
|
||||
constexpr float renderScales[]={0.5f,0.75f,1.f,1.5f,2.f};
|
||||
RecompiledFunction originalInit=nullptr,originalExit=nullptr,originalKey=nullptr,originalDraw=nullptr;
|
||||
RecompiledFunction originalHelp=nullptr,originalMessage=nullptr;
|
||||
constexpr uint32_t kHelp=0x217A60,kMessage=0x153310;
|
||||
constexpr int rowCount=16;
|
||||
// Rows 0..15 as before; then the level-up, map, fishing, spawner and fast-forward rows.
|
||||
enum Row { LevelUp=16, RevealMap, FishBite, SpawnItem, SpawnCount, GiveItem, FastSpeed, FastLock, DamageRate, OneHit,
|
||||
NoDamage, KeyFinder, RowEnd };
|
||||
constexpr int rowCount=RowEnd;
|
||||
// The toggle rows and the cheat each switches.
|
||||
bool toggleRow(int row,Cheat &cheat)
|
||||
{
|
||||
if(row<4){cheat=static_cast<Cheat>(row);return true;}
|
||||
if(row==13){cheat=Cheat::FreezeTimeOfDay;return true;}
|
||||
if(row==RevealMap){cheat=Cheat::RevealFloorMap;return true;}
|
||||
if(row==FishBite){cheat=Cheat::FishingHelper;return true;}
|
||||
if(row==FastLock){cheat=Cheat::FastForwardLock;return true;}
|
||||
if(row==OneHit){cheat=Cheat::OneHitKills;return true;}
|
||||
if(row==NoDamage){cheat=Cheat::NoDamageTaken;return true;}
|
||||
if(row==KeyFinder){cheat=Cheat::KeyFinder;return true;}
|
||||
return false;
|
||||
}
|
||||
void (*prepareScene)()=nullptr;
|
||||
uint64_t fontVersion=0;
|
||||
std::atomic<bool> quitRequested{false};
|
||||
std::atomic<bozo::app::video::Shared (*)()> videoShared{nullptr};
|
||||
std::atomic<void (*)(const bozo::app::video::Settings &,bool)> videoPost{nullptr};
|
||||
bozo::app::video::Shared windowSettings(){const auto f=videoShared.load(std::memory_order_acquire);return f?f():bozo::app::video::Shared{};}
|
||||
template<class T> T read(const uint8_t *r,uint32_t at){T v;std::memcpy(&v,r+at,sizeof(v));return v;}
|
||||
template<class T> void write(uint8_t *r,uint32_t at,T v){std::memcpy(r+at,&v,sizeof(v));}
|
||||
void done(R5900Context *c){setReturnS32(c,0);c->pc=getRegU32(c,31);}
|
||||
@@ -96,16 +126,92 @@ void text(std::vector<bozo::render::Vertex> &v,std::string_view s,float x,float
|
||||
x+=8*scale;
|
||||
}
|
||||
}
|
||||
namespace video=bozo::app::video;
|
||||
bool sameGraphics(const video::Settings &a,const video::Settings &b)
|
||||
{
|
||||
return a.mode==b.mode && a.width==b.width && a.height==b.height && std::abs(a.renderScale-b.renderScale)<0.01f &&
|
||||
a.frameRate==b.frameRate;
|
||||
}
|
||||
int renderScaleIndex(float scale)
|
||||
{
|
||||
int best=2;
|
||||
for(int i=0;i<int(std::size(renderScales));++i)if(std::abs(renderScales[i]-scale)<std::abs(renderScales[best]-scale))best=i;
|
||||
return best;
|
||||
}
|
||||
std::string graphicsValue(int row,const video::Settings &g,const video::Shared &shared)
|
||||
{
|
||||
char text[64]="";
|
||||
if(row==Display)return g.mode==video::WindowMode::Fullscreen?"Fullscreen":g.mode==video::WindowMode::Borderless?"Borderless":"Windowed";
|
||||
if(row==Resolution){
|
||||
if(g.mode==video::WindowMode::Borderless)std::snprintf(text,sizeof(text),"%dx%d monitor",shared.monitor.first,shared.monitor.second);
|
||||
else std::snprintf(text,sizeof(text),"%dx%d",g.width,g.height);
|
||||
}
|
||||
if(row==RenderScale)std::snprintf(text,sizeof(text),"%d%%",int(std::lround(g.renderScale*100)));
|
||||
if(row==FrameRate){
|
||||
// DC's font has no parentheses (they draw as braces).
|
||||
if(g.frameRate==0)return "60 fps";
|
||||
if(g.frameRate<0)std::snprintf(text,sizeof(text),"Monitor %d Hz",shared.monitorRefresh);
|
||||
else std::snprintf(text,sizeof(text),"%d fps",g.frameRate);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
// Left/Right on a graphics row: the next choice that way.
|
||||
void stepGraphics(int row,int way,const video::Shared &shared)
|
||||
{
|
||||
auto &g=menu.graphics;
|
||||
if(row==Display)g.mode=static_cast<video::WindowMode>((int(g.mode)+3+way)%3);
|
||||
else if(row==Resolution && g.mode!=video::WindowMode::Borderless && !shared.resolutions.empty()){
|
||||
const auto &sizes=shared.resolutions;const int n=int(sizes.size());
|
||||
int at=-1;for(int i=0;i<n;++i)if(sizes[i]==std::pair{g.width,g.height})at=i;
|
||||
at=at<0?(way>0?0:n-1):std::clamp(at+way,0,n-1);
|
||||
g.width=sizes[at].first;g.height=sizes[at].second;
|
||||
}else if(row==RenderScale)g.renderScale=renderScales[std::clamp(renderScaleIndex(g.renderScale)+way,0,int(std::size(renderScales))-1)];
|
||||
else if(row==FrameRate){
|
||||
std::vector<int> rates={0,-1};
|
||||
if(shared.applied.frameRate>0)rates.push_back(shared.applied.frameRate);
|
||||
int at=0;for(int i=0;i<int(rates.size());++i)if(rates[i]==g.frameRate)at=i;
|
||||
g.frameRate=rates[(at+int(rates.size())+way)%int(rates.size())];
|
||||
}
|
||||
menu.graphicsStatus="";
|
||||
}
|
||||
void drawGraphics(std::vector<bozo::render::Vertex> &v,uint32_t white,uint32_t gold,uint32_t dim)
|
||||
{
|
||||
const video::Shared shared=windowSettings();
|
||||
if(!shared.open){
|
||||
text(v,"Window settings are not",156,170,1.25f,white);text(v,"available in this run.",156,200,1.25f,white);
|
||||
text(v,"O: Back",292,352,1,white);return;
|
||||
}
|
||||
const char *labels[]={"Display","Resolution","Render scale","Frame rate","Apply and save"};
|
||||
for(int i=0;i<GraphicsRowEnd;++i){
|
||||
const float y=120.f+i*34+(i==ApplyGraphics?12:0);
|
||||
const bool locked=i==Resolution && menu.graphics.mode==video::WindowMode::Borderless;
|
||||
const auto c=i==menu.graphicsRow?gold:locked?dim:white;
|
||||
text(v,labels[i],140,y,1.25f,c);if(i==menu.graphicsRow)text(v,">",120,y,1.25f,c);
|
||||
if(i==ApplyGraphics)continue;
|
||||
std::string value=graphicsValue(i,menu.graphics,shared);
|
||||
if(i==menu.graphicsRow && !locked)value="< "+value+" >";
|
||||
text(v,value,526-float(value.size())*10,y,1.25f,c);
|
||||
}
|
||||
const std::string now="Now: "+graphicsValue(Display,shared.applied,shared)+", "+graphicsValue(Resolution,shared.applied,shared)+
|
||||
", "+graphicsValue(RenderScale,shared.applied,shared)+", "+graphicsValue(FrameRate,shared.applied,shared);
|
||||
text(v,now,320-float(now.size())*3.6f,312,0.9f,dim);
|
||||
const char *help=menu.graphicsRow==Display?"L/R: Window, full screen or borderless":
|
||||
menu.graphicsRow==Resolution?(menu.graphics.mode==video::WindowMode::Borderless?"Borderless uses the monitor size":"L/R: Window or full-screen size"):
|
||||
menu.graphicsRow==RenderScale?"L/R: 3D resolution against the window":
|
||||
menu.graphicsRow==FrameRate?"L/R: Monitor smooths between frames":"X: Apply now and keep for next launch";
|
||||
if(*menu.graphicsStatus)help=menu.graphicsStatus;
|
||||
else if(!sameGraphics(menu.graphics,shared.applied) && menu.graphicsRow!=ApplyGraphics)help="Not applied yet: choose Apply and save";
|
||||
text(v,help,320-float(std::strlen(help))*4,354,1,white);
|
||||
}
|
||||
void drawPage(int alpha)
|
||||
{
|
||||
if(prepareScene)prepareScene();panel(alpha);
|
||||
std::vector<bozo::render::Vertex> v;
|
||||
const uint32_t white=colour(0x808080,alpha),gold=colour(0x207080,alpha),dim=colour(0x484848,alpha);
|
||||
const auto heading=menu.page==Page::Root?"OPTIONS":menu.page==Page::Quit?"QUIT GAME?":"CHEATS";
|
||||
text(v,heading,menu.page==Page::Root?264.f:menu.page==Page::Quit?240.f:272.f,76,2,gold);
|
||||
const auto heading=menu.page==Page::Root?"OPTIONS":menu.page==Page::Quit?"QUIT GAME?":menu.page==Page::Graphics?"GRAPHICS":"CHEATS";
|
||||
text(v,heading,320-float(std::strlen(heading))*8,76,2,gold);
|
||||
if(menu.page==Page::Root){
|
||||
const char *labels[]={"Game Options","Cheats","Quit Game"};
|
||||
for(int i=0;i<3;++i){const float y=150.f+i*44;const auto c=i==menu.root?gold:white;text(v,labels[i],164,y,1.5f,c);if(i==menu.root)text(v,">",132,y,1.5f,c);}
|
||||
for(int i=0;i<rootCount;++i){const float y=136.f+i*44;const auto c=i==menu.root?gold:white;text(v,rootLabels[i],164,y,1.5f,c);if(i==menu.root)text(v,">",132,y,1.5f,c);}
|
||||
text(v,"D-pad: Select X: Open O: Back",120,352,1,white);
|
||||
}else if(menu.page==Page::Quit){
|
||||
text(v,"Close the game?",200,150,1.5f,white);
|
||||
@@ -113,37 +219,55 @@ void drawPage(int alpha)
|
||||
const char *labels[]={"Cancel","Quit Game"};
|
||||
for(int i=0;i<2;++i){const float y=240.f+i*38;const auto c=i==menu.quitChoice?gold:white;text(v,labels[i],204,y,1.5f,c);if(i==menu.quitChoice)text(v,">",172,y,1.5f,c);}
|
||||
text(v,"X: Confirm O: Cancel",164,352,1,white);
|
||||
}else if(menu.page==Page::Graphics){
|
||||
drawGraphics(v,white,gold,dim);
|
||||
}else{
|
||||
const char *labels[]={"Infinite health","Weapon durability","Infinite thirst","Combo stamina",
|
||||
"Equipped weapon ATK","Apply weapon ATK","Weapon ABS multiplier","Gilda","Apply Gilda",
|
||||
"Active consumable slot","Consumable quantity","Apply quantity","Movement speed","Freeze time of day",
|
||||
"Inventory size","Apply inventory size"};
|
||||
"Inventory size","Apply inventory size","Level up equipped weapon","Reveal floor map","Fish always bite",
|
||||
"Spawn item","Spawn count","Give item","Fast-forward speed","Fast-forward always on","Damage multiplier",
|
||||
"One-hit kills","No damage taken","Key finder"};
|
||||
const int first=std::max(0,menu.row-5);
|
||||
for(int i=first;i<std::min(first+6,rowCount);++i){
|
||||
const float y=126.f+(i-first)*34;const auto c=i==menu.row?gold:white;
|
||||
text(v,labels[i],128,y,1.25f,c);if(i==menu.row)text(v,">",108,y,1.25f,c);
|
||||
std::string value;
|
||||
if(i<4)value=enabled(static_cast<Cheat>(i))?"ON":"OFF";
|
||||
if(Cheat cheat;toggleRow(i,cheat))value=enabled(cheat)?"ON":"OFF";
|
||||
if(i==4)value=equippedWeaponAttack()<0?"---":std::to_string(menu.attack);
|
||||
if(i==6)value=std::to_string(absMultiplier())+"x";
|
||||
if(i==7)value=gilda()<0?"---":std::to_string(menu.gold);
|
||||
if(i==9)value=std::to_string(menu.slot+1);
|
||||
if(i==10)value=activeConsumable(menu.slot).id<0?"---":std::to_string(menu.quantity);
|
||||
if(i==12)value=std::to_string(movementPercent())+"%";
|
||||
if(i==13)value=enabled(Cheat::FreezeTimeOfDay)?"ON":"OFF";
|
||||
if(i==14)value=inventorySize()<0?"---":std::to_string(menu.capacity);
|
||||
if(i==SpawnItem)value=spawnItemCount()?spawnItem(menu.spawn).name:"---";
|
||||
if(i==SpawnCount)value=std::to_string(menu.spawnCount);
|
||||
if(i==FastSpeed)value=std::to_string(fastForwardPercent())+"%";
|
||||
if(i==DamageRate)value=std::to_string(damageMultiplier())+"x";
|
||||
text(v,value,526-float(value.size())*10,y,1.25f,c);
|
||||
}
|
||||
char count[32];std::snprintf(count,sizeof(count),"%d/%d",menu.row+1,rowCount);text(v,count,470,88,1,dim);
|
||||
const char *help="L/R: 1 L1/R1: 10 L2/R2: 100 O: Back";
|
||||
if(menu.row<4 || menu.row==13)help="X: Toggle Left/Right: Set O: Back";
|
||||
if(Cheat cheat;toggleRow(menu.row,cheat))
|
||||
help=menu.row==RevealMap?"X: Toggle Whole floor shown on the map":menu.row==FishBite?"X: Toggle Fish bite and stay hooked":
|
||||
menu.row==FastLock?"X: Toggle Sound is muted while fast":
|
||||
menu.row==OneHit?"X: Toggle Any hit that deals damage kills":
|
||||
menu.row==NoDamage?"X: Toggle Monster attacks never land":
|
||||
menu.row==KeyFinder?"X: Toggle Key holder blinks gold on the map":"X: Toggle Left/Right: Set O: Back";
|
||||
else if(menu.row==6)help="L/R: 1x Positive combat ABS O: Back";
|
||||
else if(menu.row==7)help="L/R: 1 L1/R1: 100 L2/R2: 1000";
|
||||
else if(menu.row==9)help="L/R: Choose one of the three HUD slots";
|
||||
else if(menu.row==12)help="L/R: 5% Collision stays enabled";
|
||||
else if(menu.row==14)help="1-100 slots; occupied items are protected";
|
||||
else if(menu.row==5 || menu.row==8 || menu.row==11 || menu.row==15)help="X: Apply when play resumes O: Back";
|
||||
if((menu.row==4 || menu.row==5) && equippedWeaponAttack()<0)help="No weapon equipped O: Back";
|
||||
else if(menu.row==LevelUp)help="X: Fill ABS; level up in the weapon menu";
|
||||
else if(menu.row==SpawnItem)help=spawnItemCount()?"L/R: 1 L1/R1: 10 Story items excluded":"Item names load with the game";
|
||||
else if(menu.row==SpawnCount)help="L/R: 1 Each one takes a bag slot";
|
||||
else if(menu.row==GiveItem)help="X: Give when play resumes O: Back";
|
||||
else if(menu.row==FastSpeed)help="L/R: 50% Hold ` or the touchpad";
|
||||
else if(menu.row==DamageRate)help="L/R: 1x Damage you deal to monsters";
|
||||
if((menu.row==4 || menu.row==5 || menu.row==LevelUp) && equippedWeaponAttack()<0)help="No weapon equipped O: Back";
|
||||
if((menu.row==10 || menu.row==11) && activeConsumable(menu.slot).id<0)help="Equip a consumable in this HUD slot first";
|
||||
if(menu.queued)help="Edit queued; close Options to apply";
|
||||
text(v,help,112,354,1,white);
|
||||
@@ -177,7 +301,7 @@ void key(uint8_t *r,R5900Context *c,Runtime *rt)
|
||||
return;
|
||||
}
|
||||
if(pressed&kCircle){
|
||||
if(menu.page==Page::Cheats || menu.page==Page::Quit){menu.page=Page::Root;menu.held=menu.ticks=0;done(c);}
|
||||
if(menu.page==Page::Cheats || menu.page==Page::Graphics || menu.page==Page::Quit){menu.page=Page::Root;menu.held=menu.ticks=0;done(c);}
|
||||
else {
|
||||
// The original Circle boundary starts this fade. Do not also run
|
||||
// hidden Game Options navigation if Circle and a direction coincide.
|
||||
@@ -186,8 +310,22 @@ void key(uint8_t *r,R5900Context *c,Runtime *rt)
|
||||
return;
|
||||
}
|
||||
if(menu.page==Page::Root){
|
||||
if(pressed&kUp)menu.root=(menu.root+2)%3;else if(pressed&kDown)menu.root=(menu.root+1)%3;
|
||||
if(pressed&kCross){menu.page=menu.root==0?Page::Game:menu.root==1?Page::Cheats:Page::Quit;menu.quitChoice=0;menu.held=menu.ticks=0;menu.attack=std::max(0,equippedWeaponAttack());menu.gold=std::max(0,gilda());menu.capacity=std::clamp(inventorySize(),1,100);menu.quantity=std::max(1,activeConsumable(menu.slot).quantity);menu.queued=false;}
|
||||
if(pressed&kUp)menu.root=(menu.root+rootCount-1)%rootCount;else if(pressed&kDown)menu.root=(menu.root+1)%rootCount;
|
||||
if(pressed&kCross){menu.page=menu.root==0?Page::Game:menu.root==1?Page::Graphics:menu.root==2?Page::Cheats:Page::Quit;
|
||||
menu.graphics=windowSettings().applied;menu.graphicsRow=0;menu.graphicsStatus="";menu.quitChoice=0;menu.held=menu.ticks=0;menu.attack=std::max(0,equippedWeaponAttack());menu.gold=std::max(0,gilda());menu.capacity=std::clamp(inventorySize(),1,100);menu.quantity=std::max(1,activeConsumable(menu.slot).quantity);menu.queued=false;}
|
||||
}else if(menu.page==Page::Graphics){
|
||||
const video::Shared shared=windowSettings();
|
||||
if(shared.open){
|
||||
if(pressed&kUp)menu.graphicsRow=(menu.graphicsRow+GraphicsRowEnd-1)%GraphicsRowEnd;
|
||||
else if(pressed&kDown)menu.graphicsRow=(menu.graphicsRow+1)%GraphicsRowEnd;
|
||||
if(menu.graphicsRow!=ApplyGraphics && (pressed&(kLeft|kRight)))stepGraphics(menu.graphicsRow,(pressed&kRight)?1:-1,shared);
|
||||
if(menu.graphicsRow==ApplyGraphics && (pressed&kCross)){
|
||||
// Borderless keeps the window size it returns to.
|
||||
video::Settings next=menu.graphics;
|
||||
if(next.mode==video::WindowMode::Borderless){next.width=shared.applied.width;next.height=shared.applied.height;}
|
||||
if(const auto post=videoPost.load(std::memory_order_acquire))post(next,true);menu.graphics=next;menu.graphicsStatus="Applied and saved";
|
||||
}
|
||||
}
|
||||
}else if(menu.page==Page::Quit){
|
||||
if(pressed&(kUp|kDown|kLeft|kRight))menu.quitChoice^=1;
|
||||
if(pressed&kCross){if(menu.quitChoice)quitRequested.store(true,std::memory_order_relaxed);else menu.page=Page::Root;}
|
||||
@@ -196,8 +334,7 @@ void key(uint8_t *r,R5900Context *c,Runtime *rt)
|
||||
int delta=0;if(pressed&kLeft)--delta;if(pressed&kRight)++delta;
|
||||
if(pressed&kL1)delta-=10;if(pressed&kR1)delta+=10;if(pressed&kL2)delta-=100;if(pressed&kR2)delta+=100;
|
||||
if(delta)menu.queued=false;
|
||||
if(menu.row<4 || menu.row==13){
|
||||
const auto cheat=menu.row==13?Cheat::FreezeTimeOfDay:static_cast<Cheat>(menu.row);
|
||||
if(Cheat cheat;toggleRow(menu.row,cheat)){
|
||||
if(pressed&kCross)setEnabled(cheat,!enabled(cheat));else if(pressed&kLeft)setEnabled(cheat,false);else if(pressed&kRight)setEnabled(cheat,true);
|
||||
}else if(menu.row==4 && equippedWeaponAttack()>=0)menu.attack=std::clamp(menu.attack+delta,0,999);
|
||||
else if(menu.row==5 && equippedWeaponAttack()>=0 && (pressed&kCross)){requestWeaponAttack(menu.attack);menu.queued=true;}
|
||||
@@ -212,6 +349,14 @@ void key(uint8_t *r,R5900Context *c,Runtime *rt)
|
||||
else if(menu.row==12 && delta)setMovementPercent(movementPercent()+(delta>0?5:-5));
|
||||
else if(menu.row==14 && inventorySize()>=0)menu.capacity=std::clamp(menu.capacity+delta,std::min(100,minimumInventorySize()),100);
|
||||
else if(menu.row==15 && inventorySize()>=0 && (pressed&kCross)){requestInventorySize(menu.capacity);menu.queued=true;}
|
||||
else if(menu.row==LevelUp && equippedWeaponAttack()>=0 && (pressed&kCross)){requestWeaponLevelUp();menu.queued=true;}
|
||||
else if(menu.row==SpawnItem && delta && spawnItemCount()){
|
||||
const int n=spawnItemCount(),step=std::clamp(delta,-10,10);menu.spawn=((menu.spawn+step)%n+n)%n;
|
||||
}
|
||||
else if(menu.row==SpawnCount && delta)menu.spawnCount=std::clamp(menu.spawnCount+(delta>0?1:-1),1,10);
|
||||
else if(menu.row==GiveItem && spawnItemCount() && (pressed&kCross)){requestSpawn(spawnItem(menu.spawn).id,menu.spawnCount);menu.queued=true;}
|
||||
else if(menu.row==FastSpeed && delta)setFastForwardPercent(fastForwardPercent()+(delta>0?50:-50));
|
||||
else if(menu.row==DamageRate && delta)setDamageMultiplier(damageMultiplier()+delta);
|
||||
|
||||
}
|
||||
done(c);
|
||||
@@ -250,4 +395,6 @@ void installIngameMenu(Runtime &rt,bozo::port::Registry ®istry,void (*prepare
|
||||
registry.registerFunction(kInit,init);registry.registerFunction(kExit,exit);registry.registerFunction(kKey,key);registry.registerFunction(kDraw,draw);
|
||||
}
|
||||
bool takeIngameQuitRequest(){return quitRequested.exchange(false,std::memory_order_relaxed);}
|
||||
void setGraphicsAccess(bozo::app::video::Shared (*shared)(),void (*post)(const bozo::app::video::Settings &,bool))
|
||||
{videoPost.store(post,std::memory_order_release);videoShared.store(shared,std::memory_order_release);}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "bozo/app/video_settings.h"
|
||||
struct Runtime;
|
||||
namespace bozo::port { class Registry; }
|
||||
namespace dc::cheats {
|
||||
@@ -6,4 +7,7 @@ namespace dc::cheats {
|
||||
// returning to gameplay. Native pages share the existing cheat controls.
|
||||
void installIngameMenu(Runtime &, bozo::port::Registry &, void (*prepareScene)() = nullptr);
|
||||
bool takeIngameQuitRequest(); // consumed at the application's frame boundary
|
||||
// The windowed build, before the game thread starts: the window's settings for the Graphics page (without them,
|
||||
// as headless, the page says they are unavailable).
|
||||
void setGraphicsAccess(bozo::app::video::Shared (*shared)(), void (*post)(const bozo::app::video::Settings &, bool));
|
||||
}
|
||||
+42
-1
@@ -22,12 +22,36 @@
|
||||
#include "bozo/app/audio_device.h"
|
||||
#include "bozo/app/device_pad.h"
|
||||
#include "bozo/app/window.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#endif
|
||||
namespace dc
|
||||
{
|
||||
void installAudio(bozo::libs::Libraries &);
|
||||
void install(Runtime &, bozo::port::Registry &);
|
||||
} // namespace dc
|
||||
#ifdef DC_WITH_WINDOW
|
||||
namespace
|
||||
{
|
||||
// The fast-forward hold: the ` key (by position, below Esc), or a gamepad's touchpad / Share (MISC1) button. None
|
||||
// of them is in the default PS2 bindings. SDL releases the keys when the window loses the keyboard.
|
||||
bool fastForwardHeld()
|
||||
{
|
||||
bool held = false;
|
||||
if (const bool *keys = SDL_GetKeyboardState(nullptr))
|
||||
held = keys[SDL_SCANCODE_GRAVE];
|
||||
int count = 0;
|
||||
if (SDL_JoystickID *ids = SDL_GetGamepads(&count))
|
||||
{
|
||||
for (int i = 0; i < count && !held; ++i)
|
||||
if (SDL_Gamepad *pad = SDL_GetGamepadFromID(ids[i]))
|
||||
held = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_TOUCHPAD) ||
|
||||
SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_MISC1);
|
||||
SDL_free(ids);
|
||||
}
|
||||
return held;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
bozo::host::FreeOptions options;
|
||||
@@ -132,9 +156,17 @@ int main(int argc, char **argv)
|
||||
module("dun", dun_function_table, dun_function_count, dun_resume_table, dun_resume_count);
|
||||
bozo::app::FramePacer pacer;
|
||||
pacer.setPaced(window);
|
||||
const uint32_t normalCap = pacer.cap(); // 60, or PS2X_FRAME_CAP (0: unlimited, left alone)
|
||||
host.onFrame = [&](uint64_t f, const R5900Context *ctx)
|
||||
{
|
||||
if (dc::cheats::takeIngameQuitRequest()) host.requestStop();
|
||||
#ifdef DC_WITH_WINDOW
|
||||
if (window)
|
||||
dc::cheats::setFastForwardHeld(fastForwardHeld());
|
||||
#endif
|
||||
// Fast-forward raises the cap: the game's logic and clock advance per frame, so it simply runs more of them.
|
||||
if (normalCap)
|
||||
pacer.setCap(normalCap * static_cast<uint32_t>(dc::cheats::gameSpeedPercent()) / 100u);
|
||||
pacer.frameEnd();
|
||||
if (f % 60 == 0)
|
||||
std::printf("[dc] frame=%llu pc=%x cycles=%llu\n", (unsigned long long)f, ctx->pc,
|
||||
@@ -160,7 +192,9 @@ int main(int argc, char **argv)
|
||||
if (recording.isOpen())
|
||||
recording.write(pcm, count);
|
||||
#ifdef DC_WITH_WINDOW
|
||||
if (window)
|
||||
// Muted while fast-forwarding: sound made faster than real time would overflow the device's queue and be
|
||||
// dropped in bursts. A WAV recording keeps every sample.
|
||||
if (window && dc::cheats::gameSpeedPercent() == 100)
|
||||
audio.push(pcm, count);
|
||||
#endif
|
||||
};
|
||||
@@ -199,6 +233,13 @@ int main(int argc, char **argv)
|
||||
if (window)
|
||||
{
|
||||
dc::cheats::registerMenu();
|
||||
// video.ini (the launcher's Settings, the F2 Video tab and the in-game Graphics page) over the defaults, and the
|
||||
// environment over the file; --fullscreen keeps its meaning, the monitor as it is.
|
||||
bozo::app::video::loadAtStartup(windowOptions.width, windowOptions.height);
|
||||
if (windowOptions.fullscreen)
|
||||
bozo::app::video::edited().mode = bozo::app::video::WindowMode::Borderless;
|
||||
windowOptions.videoSettings = true;
|
||||
dc::cheats::setGraphicsAccess(&bozo::app::video::shared, &bozo::app::video::post);
|
||||
bozo::app::Game game;
|
||||
game.run = run;
|
||||
game.stop = [&] { host.requestStop(); };
|
||||
|
||||
+75
-41
@@ -89,6 +89,68 @@ namespace dc::native
|
||||
constexpr uint32_t kTextureManager = 0x01C75870u; // the CTextureManager every MDT material's texture is in
|
||||
uint64_t g_nativeModelBuilds = 0, g_nativeModelRemakes = 0, g_nativeShadowBuilds = 0, g_nativeClothBuilds = 0;
|
||||
uint64_t g_retiredModelBytes = 0;
|
||||
// DC_PROBE_EXTENTS=1 (diagnosis): every model, remake, shadow and cloth buffer is filled with a pattern when
|
||||
// built (the native builders write nothing there and nothing should read it); every 60 frames the buffers
|
||||
// built in the last 600 frames are checked, and any byte something else changed is reported once per buffer.
|
||||
uint32_t extentWord(const uint8_t *rdram, uint32_t address)
|
||||
{
|
||||
uint32_t value;
|
||||
std::memcpy(&value, rdram + (address & 0x1FFFFFFu), 4);
|
||||
return value;
|
||||
}
|
||||
struct ExtentCanary { uint32_t data = 0, bytes = 0, visual = 0, vtable = 0; uint64_t frame = 0; const char *kind = ""; bool reported = false; };
|
||||
std::vector<ExtentCanary> g_extentCanaries;
|
||||
uint64_t g_extentFrame = 0, g_extentChecked = 0, g_extentChanged = 0, g_extentLive = 0;
|
||||
const uint8_t *g_extentRam = nullptr; // guest RAM, from the first build
|
||||
bool extentProbe() { static const bool on = std::getenv("DC_PROBE_EXTENTS") != nullptr; return on; }
|
||||
uint8_t extentPattern(uint32_t address) { return static_cast<uint8_t>(0xC5u ^ (address >> 4)); }
|
||||
void extentFill(uint8_t *rdram, uint32_t data, uint32_t bytes, const char *kind, uint32_t visual)
|
||||
{
|
||||
if (!extentProbe() || bytes == 0u || bytes > 0x400000u) return;
|
||||
g_extentRam = rdram;
|
||||
for (uint32_t i = 0; i < bytes; ++i) rdram[(data + i) & 0x1FFFFFFu] = extentPattern(data + i);
|
||||
// A rebuild of the same buffer starts its watch again.
|
||||
std::erase_if(g_extentCanaries, [&](const ExtentCanary &c) { return c.data == data; });
|
||||
g_extentCanaries.push_back({data, bytes, visual, extentWord(rdram, visual + 8u), g_extentFrame, kind});
|
||||
}
|
||||
void extentCheck(const uint8_t *rdram)
|
||||
{
|
||||
if (!extentProbe()) return;
|
||||
++g_extentFrame;
|
||||
if (g_extentFrame % 60u != 0u) return;
|
||||
std::erase_if(g_extentCanaries, [](const ExtentCanary &c) { return g_extentFrame - c.frame > 600u; });
|
||||
for (auto &c : g_extentCanaries)
|
||||
{
|
||||
++g_extentChecked;
|
||||
if (c.reported) continue;
|
||||
for (uint32_t i = 0; i < c.bytes; ++i)
|
||||
if (rdram[(c.data + i) & 0x1FFFFFFu] != extentPattern(c.data + i))
|
||||
{
|
||||
c.reported = true;
|
||||
++g_extentChanged;
|
||||
// Live: the visual still has its vtable and still points at this buffer with this size.
|
||||
const bool live = extentWord(rdram, c.visual + 8u) == c.vtable && extentWord(rdram, c.visual + 0x18u) == c.data &&
|
||||
extentWord(rdram, c.visual + 0x1Cu) * 16u == c.bytes;
|
||||
if (live) ++g_extentLive;
|
||||
if (live)
|
||||
{
|
||||
const uint32_t at = (c.data + (i & ~15u)) & 0x1FFFFFFu;
|
||||
std::fprintf(stderr, "[dc:extent] new bytes at +0x%x: %08x %08x %08x %08x; visual +0x18 %08x +0x1c %08x\n",
|
||||
i & ~15u, extentWord(rdram, at), extentWord(rdram, at + 4u), extentWord(rdram, at + 8u),
|
||||
extentWord(rdram, at + 12u), extentWord(rdram, c.visual + 0x18u), extentWord(rdram, c.visual + 0x1Cu));
|
||||
}
|
||||
std::fprintf(stderr, "[dc:extent] %s buffer %08x (%u bytes, visual %08x, built frame %llu): byte +0x%x changed by frame %llu, %s\n",
|
||||
c.kind, c.data, c.bytes, c.visual, static_cast<unsigned long long>(c.frame), i,
|
||||
static_cast<unsigned long long>(g_extentFrame), live ? "VISUAL STILL OWNS IT" : "visual gone or moved");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (g_extentFrame % 600u == 0u)
|
||||
std::fprintf(stderr, "[dc:extent] frame %llu: %zu buffers watched, %llu checks, %llu changed, %llu while their visual owned them\n",
|
||||
static_cast<unsigned long long>(g_extentFrame), g_extentCanaries.size(),
|
||||
static_cast<unsigned long long>(g_extentChecked), static_cast<unsigned long long>(g_extentChanged),
|
||||
static_cast<unsigned long long>(g_extentLive));
|
||||
}
|
||||
uint64_t g_group = 0;
|
||||
|
||||
struct Stats
|
||||
@@ -305,44 +367,11 @@ namespace dc::native
|
||||
}
|
||||
return model;
|
||||
}
|
||||
// The caller still advances its shared arena by this extent. Preserve that ABI while
|
||||
// retiring every byte of VIF/material/vertex serialization into the supplied buffer.
|
||||
uint32_t textureAllocationQwords(bozo::libs::Guest &guest, uint32_t record, uint32_t gp)
|
||||
{
|
||||
uint64_t textureMode = 0;
|
||||
if (record) std::memcpy(&textureMode, guest.in(record + 0x30u, 8), 8);
|
||||
if (!textureMode) std::memcpy(&textureMode, guest.in(gp - 0x7420u, 8), 8);
|
||||
return textureMode ? 4u : 3u;
|
||||
}
|
||||
uint32_t modelAllocationQwords(const MdtDescription &model, bool shadow, bool remake,
|
||||
bozo::libs::Guest &guest, const uint8_t *ram, uint32_t mdt, uint32_t gp)
|
||||
{
|
||||
uint64_t qwords = 0;
|
||||
for (const auto &primitive : model.primitives)
|
||||
{
|
||||
++qwords;
|
||||
if (shadow)
|
||||
{
|
||||
const uint32_t triangles = primitive.count / 3u;
|
||||
qwords += triangles * 6ull + ((triangles + 9u) / 10u) * 3ull;
|
||||
continue;
|
||||
}
|
||||
if (primitive.material != -1)
|
||||
qwords += 5u + (remake ? 4u : textureAllocationQwords(guest, boundRecord(ram, mdt + model.materials +
|
||||
static_cast<uint32_t>(primitive.material) * 0x60u + 0x34u), gp));
|
||||
const uint32_t limit = model.stride == 4u ? 33u : 54u;
|
||||
uint32_t remaining = primitive.count;
|
||||
while (remaining)
|
||||
{
|
||||
const uint32_t vertices = std::min(remaining, limit);
|
||||
qwords += vertices * model.stride + 4u;
|
||||
remaining -= vertices;
|
||||
if (primitive.kind == 4u && remaining) remaining += 2u;
|
||||
}
|
||||
}
|
||||
if (qwords > 0x1ffffffu / 16u) throw std::runtime_error("native model: allocation extent too large");
|
||||
return static_cast<uint32_t>(qwords);
|
||||
}
|
||||
// The extent a model, remake or shadow build reserves in the game's arena: one qword. CreateVisual allocates it
|
||||
// at the data address it passed (and Align64 follows), so every build keeps a distinct, aligned address, the key
|
||||
// of its retained MDT. The old VIF packet size reserved space nothing fills: DC_PROBE_EXTENTS found no game
|
||||
// code writing into a live buffer (docs/BOZO_MIGRATION.md, "Model extents").
|
||||
constexpr uint32_t kNativeModelQwords = 1u;
|
||||
void noteMdt(const uint8_t *rdram, uint32_t data, uint32_t mdt, bool bind, const MdtDescription &model)
|
||||
{
|
||||
const uint32_t size = model.size;
|
||||
@@ -382,13 +411,14 @@ namespace dc::native
|
||||
bozo::libs::Guest guest(*runtime, ctx);
|
||||
const uint32_t visual = getRegU32(ctx, 4), data = getRegU32(ctx, 5), mdt = getRegU32(ctx, 6);
|
||||
const auto model = describeMdt(guest, mdt, shadow);
|
||||
const uint32_t qwords = modelAllocationQwords(model, shadow, remake, guest, rdram, mdt, getRegU32(ctx, 28));
|
||||
const uint32_t qwords = kNativeModelQwords;
|
||||
guest.in(visual + 0x18u, 8);
|
||||
noteMdt(rdram, data, mdt, !remake && !shadow, model);
|
||||
guest.write32(visual + 0x18u, data);
|
||||
guest.write32(visual + 0x1cu, qwords);
|
||||
++(shadow ? g_nativeShadowBuilds : remake ? g_nativeModelRemakes : g_nativeModelBuilds);
|
||||
g_retiredModelBytes += qwords * 16ull;
|
||||
extentFill(rdram, data, qwords * 16u, shadow ? "shadow" : remake ? "remake" : "model", visual);
|
||||
setReturnS32(ctx, static_cast<int32_t>(qwords));
|
||||
ctx->pc = getRegU32(ctx, 31);
|
||||
}
|
||||
@@ -1842,8 +1872,10 @@ namespace dc::native
|
||||
const int32_t columns = static_cast<int32_t>(guest.read32(cloth + 0x30u));
|
||||
if (rows < 0 || rows > 16 || columns < 0 || columns > 16)
|
||||
throw std::runtime_error("native cloth: grid outside simulation storage");
|
||||
const uint32_t qwords = 6u + textureAllocationQwords(guest, textureRecord(ram, cloth + 0x94u), getRegU32(ctx, 28)) +
|
||||
static_cast<uint32_t>(std::max(0, rows - 1)) * (4u + static_cast<uint32_t>(columns) * 6u);
|
||||
// One qword, as for models: CCloth::Initialize reserves it for buffer 0 and takes buffer 1 with Alloc64, so the
|
||||
// two stay distinct; its per-frame DrawVu1 (native) never uses the size, and the native draw reads the
|
||||
// simulation grid, not either buffer.
|
||||
const uint32_t qwords = kNativeModelQwords;
|
||||
++g_nativeClothBuilds;
|
||||
g_retiredModelBytes += qwords * 16ull;
|
||||
setReturnS32(ctx, static_cast<int32_t>(qwords));
|
||||
@@ -4801,6 +4833,8 @@ namespace dc::native
|
||||
return;
|
||||
bozo::render::Renderer &renderer = bozo::render::Renderer::instance();
|
||||
++g_publishedFrames;
|
||||
if (g_extentRam)
|
||||
extentCheck(g_extentRam);
|
||||
static uint32_t s_frames = 0;
|
||||
static const bool s_reportStats = [] {
|
||||
const char *value = std::getenv("DC_NATIVE_STATS");
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
// The level-up, map, fishing, spawner and fast-forward cheats. Each wrapped original is a recording stub, so the hooks'
|
||||
// own decisions are checked exactly: what they pass on, what they write, and what they refuse.
|
||||
#include "../runtime/dc_cheats.h"
|
||||
#include "bozo/port.h"
|
||||
#include "bozo/runtime.h"
|
||||
#include <bit>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace {
|
||||
constexpr uint32_t user=0x400000,gp=0x300000,stack=0x700000,link=0x123450;
|
||||
constexpr uint32_t mapMain=0x01DC4BE0,mapSub=0x01DD56F0,fish=0x500000,messages=0x600000;
|
||||
int failures=0;
|
||||
void check(bool ok,const char *what){if(!ok){++failures;std::printf("FAIL %s\n",what);}}
|
||||
template<class T> T read(uint8_t *r,uint32_t p){T n;std::memcpy(&n,r+p,sizeof(n));return n;}
|
||||
template<class T> void write(uint8_t *r,uint32_t p,T n){std::memcpy(r+p,&n,sizeof(n));}
|
||||
void ret(R5900Context *c,int32_t v){c->r[2].ud[0]=uint64_t(int64_t(v));c->pc=c->r[31].uw[0];}
|
||||
|
||||
// The recording stubs.
|
||||
float seenProbability=-1;int stepCalls=0,maxExpCalls=0,itemChecks=0,weaponChecks=0,gives=0,checkResult=0,rotResult=0;
|
||||
std::vector<int> given;
|
||||
void randCheck(uint8_t *,R5900Context *c,Runtime *){seenProbability=std::bit_cast<float>(c->fu[12]);ret(c,0);}
|
||||
void fishStep(uint8_t *,R5900Context *c,Runtime *){++stepCalls;ret(c,0);}
|
||||
void checkMask(uint8_t *,R5900Context *c,Runtime *){ret(c,0);}
|
||||
void flushMask(uint8_t *r,R5900Context *c,Runtime *){
|
||||
const uint32_t m=c->r[4].uw[0];for(uint32_t i=0;i<400;++i)write<int32_t>(r,m+0x8710+i*4,0);ret(c,0);}
|
||||
void maxExp(uint8_t *,R5900Context *c,Runtime *){++maxExpCalls;ret(c,40);}
|
||||
void checkItemGet(uint8_t *,R5900Context *c,Runtime *){++itemChecks;ret(c,checkResult);}
|
||||
void checkWeaponRot(uint8_t *,R5900Context *c,Runtime *){++weaponChecks;ret(c,rotResult);}
|
||||
void getItem(uint8_t *,R5900Context *c,Runtime *){++gives;given.push_back(c->r[5].sw[0]);ret(c,0);}
|
||||
void plain(uint8_t *,R5900Context *c,Runtime *){ret(c,0);}
|
||||
int hitTests=0,symbolCalls=0,sprites=0;int32_t spriteRect[4]={};uint32_t spriteColour[4]={};
|
||||
void checkHitUser(uint8_t *,R5900Context *c,Runtime *){++hitTests;ret(c,3);}
|
||||
void mapSymbols(uint8_t *,R5900Context *c,Runtime *){++symbolCalls;ret(c,0);}
|
||||
void getPosition(uint8_t *r,R5900Context *c,Runtime *){ // (x, y, z) = (1000, 0, -200)
|
||||
const uint32_t out=c->r[5].uw[0];write<float>(r,out,1000);write<float>(r,out+4,0);write<float>(r,out+8,-200);ret(c,0);}
|
||||
void colourRect(uint8_t *r,R5900Context *c,Runtime *){
|
||||
++sprites;std::memcpy(spriteRect,r+c->r[5].uw[0],16);
|
||||
for(int i=0;i<4;++i)spriteColour[i]=read<uint32_t>(r,c->r[6+i].uw[0]);c->pc=c->r[31].uw[0];}
|
||||
|
||||
R5900Context at(uint32_t pc,uint32_t a0,uint32_t from=link)
|
||||
{R5900Context c;c.pc=pc;c.r[4].uw[0]=a0;c.r[28].uw[0]=gp;c.r[29].uw[0]=stack;c.r[31].uw[0]=from;return c;}
|
||||
void call(Runtime &rt,bozo::port::Registry ®,R5900Context &c)
|
||||
{const uint32_t back=c.r[31].uw[0];reg.find(c.pc)(rt.memory.ram(),&c,&rt);check(c.pc==back && !c.leaving,"hook returns to its caller");}
|
||||
|
||||
// The game's message table: n, then (key, offset) pairs, then the 16-bit text.
|
||||
void messageTable(uint8_t *r,const std::vector<std::pair<int,std::string>> &entries)
|
||||
{
|
||||
const int n=int(entries.size());write<int16_t>(r,messages,int16_t(n));
|
||||
int16_t offset=int16_t(n+1);std::vector<uint16_t> text; // text starts at u16 index 2n + 2 = n + (n + 1) + 1
|
||||
for(int i=0;i<n;++i){
|
||||
write<int16_t>(r,messages+4+4*i,int16_t(entries[size_t(i)].first));write<int16_t>(r,messages+6+4*i,offset);
|
||||
for(char ch:entries[size_t(i)].second)
|
||||
text.push_back(ch==' '?0xFF02:ch>='a'?uint16_t(0xFD3B+ch-'a'):ch>='A'?uint16_t(0xFD21+ch-'A'):uint16_t(0xFD6F+ch-'0'));
|
||||
text.push_back(0xFF01);offset=int16_t(n+1+int(text.size()));
|
||||
}
|
||||
for(size_t i=0;i<text.size();++i)write<uint16_t>(r,messages+2*uint32_t(2*n+2)+2*uint32_t(i),text[i]);
|
||||
write<uint32_t>(r,0x2A2528,messages);
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
using namespace dc::cheats;
|
||||
// Sorted by address: the resource routines install() requires, then the wrapped originals.
|
||||
const BozoFunctionEntry table[]={
|
||||
{0x1B5920,checkHitUser},
|
||||
{0x1B5D90,plain},{0x1BDD40,checkItemGet},{0x1BDF90,checkWeaponRot},{0x1BE060,getItem},{0x1BE510,plain},
|
||||
{0x1BE710,plain},{0x1BE900,plain},{0x1BEA50,plain},{0x1C39C0,checkMask},{0x1C3C00,flushMask},{0x1D7AA0,mapSymbols},
|
||||
{0x200000,getPosition},{0x232080,maxExp},{0x240050,randCheck},{0x240480,fishStep}};
|
||||
const BozoFunctionEntry withDun[]={{0x1B5920,checkHitUser},
|
||||
{0x1B5D90,plain},{0x1BDD40,checkItemGet},{0x1BDF90,checkWeaponRot},{0x1BE060,getItem},{0x1BE510,plain},
|
||||
{0x1BE710,plain},{0x1BE900,plain},{0x1BEA50,plain},{0x1C39C0,checkMask},{0x1C3C00,flushMask},{0x1D7AA0,mapSymbols},
|
||||
{0x200000,getPosition},{0x232080,maxExp},{0x240050,randCheck},{0x240480,fishStep}};
|
||||
auto rt=std::make_unique<Runtime>();rt->functions.setGenerated(table,std::size(table));
|
||||
bozo::port::Registry reg;install(*rt,reg);auto *r=rt->memory.ram();
|
||||
|
||||
// Fishing: the Leave rolls only, and only when on.
|
||||
auto roll=[&](uint32_t from){auto c=at(0x240050,fish,from);c.fu[12]=std::bit_cast<uint32_t>(0.1f);call(*rt,reg,c);return seenProbability;};
|
||||
check(roll(0x2403FC)==0.1f && roll(0x24044C)==0.1f,"fishing off: the Leave rolls keep their odds");
|
||||
setEnabled(Cheat::FishingHelper,true);
|
||||
check(roll(0x2403FC)==0 && roll(0x24044C)==0,"fishing on: a fish near the bait never leaves it");
|
||||
check(roll(0x24022C)==0.1f && roll(0x2402F0)==0.1f && roll(0x2403B0)==0.1f,"fishing on: Find/Eat/Bite odds unchanged");
|
||||
write<int32_t>(r,fish+0x50,8);write<int32_t>(r,fish+0x58,0);
|
||||
{auto c=at(0x240480,fish);call(*rt,reg,c);}
|
||||
check(read<int32_t>(r,fish+0x58)==1 && read<int32_t>(r,fish+0x50)==8 && stepCalls==1,"a hooked fish keeps its timer; Step still runs");
|
||||
write<int32_t>(r,fish+0x50,7);write<int32_t>(r,fish+0x58,0);
|
||||
{auto c=at(0x240480,fish);call(*rt,reg,c);}
|
||||
check(read<int32_t>(r,fish+0x58)==0,"a nibbling fish's timer is not touched");
|
||||
setEnabled(Cheat::FishingHelper,false);
|
||||
write<int32_t>(r,fish+0x50,8);write<int32_t>(r,fish+0x58,0);
|
||||
{auto c=at(0x240480,fish);call(*rt,reg,c);}
|
||||
check(read<int32_t>(r,fish+0x58)==0,"fishing off: the hooked fish's timer runs out as before");
|
||||
|
||||
// Map: floor cells (part != -1) except column 19, two rooms.
|
||||
auto layout=[&](uint32_t m){
|
||||
for(uint32_t i=0;i<400;++i){write<int32_t>(r,m+0x9C50+i*16,(i%3==0 || i%20==19)?2:-1);write<int32_t>(r,m+0x8710+i*4,0);}
|
||||
for(uint32_t i=0;i<16;++i){write<int32_t>(r,m+8+i*4,0);write<int32_t>(r,m+0xB558+i*16,i<2?1:0);}
|
||||
write<int32_t>(r,m+0xB650,3);};
|
||||
auto revealed=[&](uint32_t m){
|
||||
for(uint32_t i=0;i<400;++i){const bool want=i%20!=19 && i%3==0;if((read<int32_t>(r,m+0x8710+i*4)==1)!=want)return false;}
|
||||
return read<int32_t>(r,m+8)==1 && read<int32_t>(r,m+12)==1 && read<int32_t>(r,m+16)==0;};
|
||||
layout(mapMain);setEnabled(Cheat::RevealFloorMap,true);
|
||||
{auto c=at(0x1C39C0,mapMain,0x1DB159C);call(*rt,reg,c);}
|
||||
check(read<int32_t>(r,mapMain+0x8710)==0,"no reveal while the DUN overlay is not resident");
|
||||
auto dun=std::make_unique<Runtime>();dun->functions.setGenerated(withDun,std::size(withDun));
|
||||
bozo::port::Registry dunReg;dunReg.registerFunction(0x15E120,colourRect);install(*dun,dunReg);auto *d=dun->memory.ram();
|
||||
// The DUN overlay resident: its module registered with identity bytes in place, as the game loads it.
|
||||
const std::vector<uint8_t> identity{0x44,0x55,0x4E,0x21};std::memcpy(d+0x1DABD00,identity.data(),identity.size());
|
||||
const BozoFunctionEntry dunModule[]={{0x1DB7450,plain}};
|
||||
dun->functions.addModule(0x1DABD00,0x1F00000,d+0x1DABD00,identity,dunModule,1,nullptr,0);
|
||||
std::swap(r,d);std::swap(rt,dun);
|
||||
layout(mapMain);{auto c=at(0x1C39C0,mapMain,0x1DB159C);call(*rt,dunReg,c);}
|
||||
check(revealed(mapMain),"walking update: every floor cell explored, column 19 and empty cells left alone");
|
||||
layout(mapMain);{auto c=at(0x1C39C0,mapMain,0x1DB1000);call(*rt,dunReg,c);}
|
||||
check(read<int32_t>(r,mapMain+0x8710)==0,"another caller of checkMask is not revealed");
|
||||
layout(mapSub);{auto c=at(0x1C3C00,mapSub,0x1DB913C);call(*rt,dunReg,c);}
|
||||
check(revealed(mapSub),"floor build: the sub-map is revealed after FlushCheckMask clears it");
|
||||
layout(0x500000);{auto c=at(0x1C39C0,0x500000,0x1DB159C);call(*rt,dunReg,c);}
|
||||
check(read<int32_t>(r,0x500000+0x8710)==0,"only the two real map objects are written");
|
||||
setEnabled(Cheat::RevealFloorMap,false);layout(mapMain);{auto c=at(0x1C3C00,mapMain,0x1DB8A1C);call(*rt,dunReg,c);}
|
||||
check(read<int32_t>(r,mapMain+0x8710)==0,"map off: the floor stays unexplored");
|
||||
|
||||
// The player (gp-0x6388) with character 0's equipped weapon in slot 0.
|
||||
std::memset(r+user,0,0x8C00);write<uint32_t>(r,gp-0x6388,user);write<int8_t>(r,user+5,2);
|
||||
const uint32_t weapon=user+0x450C;write<int16_t>(r,weapon,0x103);write<int16_t>(r,weapon+2,3);write<int16_t>(r,weapon+0x14,7);
|
||||
auto tick=[&]{auto c=at(0x1BEA50,user);call(*rt,dunReg,c);};
|
||||
requestWeaponLevelUp();tick();
|
||||
check(read<int16_t>(r,weapon+0x14)==40 && maxExpCalls==1,"level-up: ABS filled to the game's own threshold");
|
||||
write<int16_t>(r,weapon+0x14,7);tick();check(read<int16_t>(r,weapon+0x14)==7,"level-up request is used once");
|
||||
write<int16_t>(r,weapon,0x101);requestWeaponLevelUp();tick();check(read<int16_t>(r,weapon+0x14)==7,"default weapon refused");
|
||||
write<int16_t>(r,weapon,0x10C);requestWeaponLevelUp();tick();check(read<int16_t>(r,weapon+0x14)==7,"Serpent Sword refused");
|
||||
write<int16_t>(r,weapon,0x103);write<int16_t>(r,weapon+2,99);requestWeaponLevelUp();tick();
|
||||
check(read<int16_t>(r,weapon+0x14)==7,"level 99 refused");
|
||||
|
||||
// Spawner: names from the message table; bag items and attachments by id + 100, weapons through ComItemInfo
|
||||
// (indexed id - 0x51).
|
||||
write<int16_t>(r,0x27DE50+(0x103-0x51)*8+6,3);
|
||||
messageTable(r,{{0x91+100,"Bread"},{0xC3+100,"Drans Crest"},{0x5B+100,"Attack"},{3+100,"Baselard"}});
|
||||
tick();
|
||||
bool bread=false,crest=false,sphere=false,blade=false;
|
||||
for(int i=0;i<spawnItemCount();++i){const auto it=spawnItem(i);const std::string n=it.name;
|
||||
bread|=it.id==0x91 && n=="Bread";crest|=it.id==0xC3;sphere|=it.id==0x5B && n=="Attack";blade|=it.id==0x103 && n=="Baselard";}
|
||||
check(bread && sphere && blade && spawnItemCount()==3,"spawner lists named items with their game names");
|
||||
check(!crest,"spawner never offers a key or story item");
|
||||
requestSpawn(0x91,3);tick();check(gives==3 && given[0]==0x91 && itemChecks==3,"three units given through GetItem");
|
||||
checkResult=1;gives=0;requestSpawn(0x91,3);tick();check(gives==0,"a full bag refuses without entering the overflow path");
|
||||
checkResult=0;gives=0;requestSpawn(0xC3,1);tick();check(gives==0,"a key item request is ignored");
|
||||
write<int8_t>(r,0x275A7E + 0x103*0x4C,1);rotResult=3;gives=0;requestSpawn(0x103,1);tick();
|
||||
check(gives==1 && weaponChecks==1,"a weapon goes to its joined owner");
|
||||
write<int8_t>(r,0x275A7E + 0x103*0x4C,4);gives=0;requestSpawn(0x103,1);tick();check(gives==0,"a weapon for a character not yet joined is refused");
|
||||
write<int8_t>(r,0x275A7E + 0x103*0x4C,1);rotResult=9;gives=0;requestSpawn(0x103,1);tick();check(gives==0,"a full weapon list is refused");
|
||||
|
||||
// Damage dealt: the instruction before the game's own subtraction (v0 HP, s4 damage).
|
||||
auto hit=[&](int damage,int hp){R5900Context c;c.r[20].ud[0]=uint64_t(int64_t(damage));c.r[2].ud[0]=uint64_t(int64_t(hp));
|
||||
const bool handled=dunReg.instructionHandler()(r,&c,rt.get(),0x1DC3F4);check(!handled,"the original subtraction still runs");
|
||||
return int(c.r[20].sw[0]);};
|
||||
check(hit(30,100)==30,"damage unchanged at 1x");
|
||||
setDamageMultiplier(2);check(hit(30,100)==60,"2x doubles the damage");
|
||||
setDamageMultiplier(16);check(hit(30,100)==100,"scaled damage is capped at the HP left");
|
||||
check(hit(300,100)==300,"a hit already above the HP keeps its own damage");
|
||||
check(hit(0,100)==0,"an immune hit (0 damage) stays immune");
|
||||
setDamageMultiplier(1);setEnabled(Cheat::OneHitKills,true);check(hit(1,250)==250 && hit(0,250)==0,"one-hit kills, immunities kept");
|
||||
setEnabled(Cheat::OneHitKills,false);
|
||||
|
||||
// Damage taken: only BtCheckDamageProc's hit test, only in the dungeon.
|
||||
auto test=[&](uint32_t from){auto c=at(0x1B5920,0x480000,from);call(*rt,dunReg,c);return c.r[2].sw[0];};
|
||||
check(test(0x1DBB0E0)==3 && hitTests==1,"no-damage off: the hit test runs");
|
||||
setEnabled(Cheat::NoDamageTaken,true);
|
||||
check(test(0x1DBB0E0)==-1 && hitTests==1,"no-damage on: the player's hit test answers no hit");
|
||||
check(test(0x1DBC000)==3 && hitTests==2,"other hit tests are untouched");
|
||||
setEnabled(Cheat::NoDamageTaken,false);
|
||||
|
||||
// Key finder: unit at 0x800000 with slot 5 holding the floor's key (0xC9) and slot 2 another key (0xC4).
|
||||
const uint32_t unit=0x800000,floorMap=0x480000;
|
||||
std::memset(r+unit,0,0x80000);write<uint32_t>(r,gp-0x6320,unit);write<uint32_t>(r,gp-0x6338,floorMap);
|
||||
write<int32_t>(r,floorMap+0x464,0xC9);write<float>(r,gp-0x7F80,0.1f);
|
||||
for(uint32_t i=0;i<16;++i){write<int32_t>(r,unit+i*400+0x1E3D0,1);write<int32_t>(r,unit+i*400+0x1E3F4,10);write<int16_t>(r,unit+i*400+0x1E470,-1);}
|
||||
write<int16_t>(r,unit+5*400+0x1E470,0xC9);write<int16_t>(r,unit+2*400+0x1E470,0xC4);
|
||||
for(uint32_t i=0;i<16;++i){const uint32_t character=unit+i*0x3510+0x1FCD0;write<uint32_t>(r,character+0xA0,0x460000);}
|
||||
write<uint32_t>(r,0x460000+0xA0,0x200000); // the vtable's GetPosition
|
||||
auto symbols=[&]{auto c=at(0x1D7AA0,unit,0x1DB0348);call(*rt,dunReg,c);};
|
||||
symbols();check(sprites==0 && symbolCalls==1,"key finder off: only the game's icons");
|
||||
setEnabled(Cheat::KeyFinder,true);symbols();
|
||||
check(sprites==1 && spriteRect[0]==100+384-1 && spriteRect[1]==-20+68-1 && spriteRect[2]==10 && spriteRect[3]==10,
|
||||
"the marker sits on the holder at the game's map transform");
|
||||
check((spriteColour[0]&0xFFFFFF)==0x20C8FF && spriteColour[0]==spriteColour[3],"a gold square");
|
||||
write<int32_t>(r,unit+5*400+0x1E3F4,0);symbols();check(sprites==2,"the other key holder is marked once the floor's is gone");
|
||||
write<int32_t>(r,unit+2*400+0x1E3D0,-1);symbols();check(sprites==2,"no live holder: no marker");
|
||||
setEnabled(Cheat::KeyFinder,false);
|
||||
|
||||
// Fast-forward.
|
||||
check(gameSpeedPercent()==100,"normal speed by default");
|
||||
setFastForwardHeld(true);check(gameSpeedPercent()==300,"held: the fast-forward speed (300% by default)");
|
||||
setFastForwardPercent(1000);check(gameSpeedPercent()==400,"fast-forward speed capped at 400%");
|
||||
setFastForwardHeld(false);check(gameSpeedPercent()==100,"released: normal speed");
|
||||
setEnabled(Cheat::FastForwardLock,true);check(gameSpeedPercent()==400,"locked on without holding");
|
||||
setEnabled(Cheat::FastForwardLock,false);setFastForwardPercent(300);
|
||||
std::printf("Extra cheats: %d failures\n",failures);return failures?1:0;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ namespace
|
||||
NativePort port{libs, this};
|
||||
Observer observer{libs};
|
||||
RecompiledFunction end = nullptr, terminate = nullptr, channel = nullptr;
|
||||
int packetCalls = 0, syncCalls = 0, flushCalls = 0, sendCalls = 0;
|
||||
int packetCalls = 0, syncCalls = 0, flushCalls = 0, sendCalls = 0, dmaSyncCalls = 0, gsCalls = 0, channelCalls = 0;
|
||||
uint32_t sentChannel = 0, sentSource = 0;
|
||||
Machine()
|
||||
{
|
||||
@@ -60,7 +60,7 @@ namespace
|
||||
end = rt.functions.generated(0x120de0); terminate = rt.functions.generated(0x120c28);
|
||||
channel = rt.functions.generated(0x10c3a8);
|
||||
if (!end || !terminate || !channel) throw std::runtime_error("missing original SDK helper");
|
||||
for (uint32_t pc : {0x120de0u,0x120c28u,0x112f98u,0x104698u,0x113f40u,0x10c3a8u,0x1145a0u,0x10c6f8u})
|
||||
for (uint32_t pc : {0x120de0u,0x120c28u,0x112f98u,0x104698u,0x113f40u,0x10c3a8u,0x1145a0u,0x10c6f8u,0x10cc58u,0x113e48u,0x112ea0u})
|
||||
rt.functions.setOverride(pc, sdk);
|
||||
libs.attach(dispatcher); rt.port = &port; dispatcher.kernel().setObserver(&observer);
|
||||
auto &old = libs.io.channels[1];
|
||||
@@ -82,7 +82,13 @@ namespace
|
||||
++m.syncCalls;
|
||||
m.libs.find("sceGsSyncPath")->handler(m.libs, guest);
|
||||
}
|
||||
else if (pc == 0x10c3a8) m.channel(ram, ctx, rt);
|
||||
else if (pc == 0x10c3a8) { ++m.channelCalls; m.channel(ram, ctx, rt); }
|
||||
else if (pc == 0x113e48 || pc == 0x112ea0) ++m.gsCalls; // sceGsSetHalfOffset / sceGsSwapDBuff
|
||||
else if (pc == 0x10cc58)
|
||||
{
|
||||
++m.dmaSyncCalls;
|
||||
m.libs.find("sceDmaSync")->handler(m.libs, guest);
|
||||
}
|
||||
else if (pc == 0x1145a0) { ++m.flushCalls; guest.ret(0); } // coherent native RAM, no cache device
|
||||
else if (pc == 0x10c6f8)
|
||||
{
|
||||
@@ -140,39 +146,41 @@ int main()
|
||||
}
|
||||
std::printf("DC frame close: %d reference/adapted cases, %d failures\n", cases, failures);
|
||||
#else
|
||||
// The per-frame transfer tail: the published reference waits on the GIF channel, flushes and sends an empty VIF1
|
||||
// transfer; the adapted tail does none of it. The game installs no DMA-completion handler, so no completion is
|
||||
// owed. Frame counter, its first-frame flag, channel lookup and buffer toggle must match.
|
||||
for (uint32_t count : {0u,1u,0x7fffffffu,0xffffffffu})
|
||||
for (uint32_t frame : {0u,1u,0xffffffffu})
|
||||
for (bool masked : {false,true})
|
||||
for (bool first : {false,true})
|
||||
{
|
||||
++cases; Machine reference, native;
|
||||
reference.setup(0, false, count, frame, false); native.setup(0, false, count, frame, true);
|
||||
for (Machine *m : {&reference, &native})
|
||||
{
|
||||
m->dispatcher.kernel().addHandler(true, 1, 0x123400, -1, 0, 0, 0);
|
||||
m->dispatcher.kernel().causeEnable(true, 1, !masked);
|
||||
auto *r = m->dispatcher.runtime().memory.ram();
|
||||
r[gp - 0x73a8] = first ? 0 : 1;
|
||||
word(r, gp - 0x7434, 0x1000a000); // the GIF and VIF1 channel handles MGInit stored
|
||||
word(r, gp - 0x7438, 0x10009000);
|
||||
}
|
||||
reference.run(DC_FRAME_REFERENCE[0].function);
|
||||
auto *ram = native.dispatcher.runtime().memory.ram();
|
||||
const auto *ref = reference.dispatcher.runtime().memory.ram();
|
||||
std::vector<uint8_t> expected(ram, ram + bozo::kFlatScratchpadOffset);
|
||||
for (uint32_t address : {gp - 0x73ac, gp - 0x7438, gp - 0x7440}) word(expected.data(), address, word(ref, address));
|
||||
expected[gp - 0x73a8] = ref[gp - 0x73a8];
|
||||
native.run(DC_FRAME_NATIVE[0].function);
|
||||
check(reference.flushCalls == 1 && native.flushCalls == 1 && reference.sendCalls == 1 && native.sendCalls == 1,
|
||||
"native completion and surrounding retained SDK call occur exactly once");
|
||||
check(reference.sentChannel == 0x10009000 && native.sentChannel == reference.sentChannel &&
|
||||
reference.sentSource == output && native.sentSource == 0, "same native channel completion no longer needs a packet source");
|
||||
check(native.libs.io.nativeSubmissions[1] == 1 && reference.libs.io.nativeSubmissions[1] == 1 &&
|
||||
native.libs.io.nativeCompleted[1] && reference.libs.io.nativeCompleted[1], "native completion state matches published reference");
|
||||
check(reference.dispatcher.kernel().handlerQueued() == !masked && native.dispatcher.kernel().handlerQueued() == !masked,
|
||||
"completion callback delivery respects its original mask");
|
||||
if (masked)
|
||||
{
|
||||
reference.dispatcher.kernel().causeEnable(true, 1, true); native.dispatcher.kernel().causeEnable(true, 1, true);
|
||||
check(reference.dispatcher.kernel().handlerQueued() && native.dispatcher.kernel().handlerQueued(),
|
||||
"masked completion survives until callback enable");
|
||||
}
|
||||
check(reference.gsCalls == 2 && reference.dmaSyncCalls == 1 && reference.flushCalls == 2 &&
|
||||
reference.channelCalls == 1 && reference.sendCalls == 1,
|
||||
"published reference sets the half offset, swaps, waits, flushes twice, looks the channel up and sends");
|
||||
check(word(ref, gp - 0x7438) == 0x10009000, "the reference's lookup returns the handle MGInit stored");
|
||||
check(native.gsCalls == 0 && native.channelCalls == 0 && native.dmaSyncCalls == 0 && native.flushCalls == 0 && native.sendCalls == 0 &&
|
||||
native.libs.io.nativeSubmissions[1] == 0 && native.libs.io.nativeSynchronizations == 0,
|
||||
"adapted tail makes no transfer, flush or wait");
|
||||
check(reference.sentChannel == 0x10009000 && reference.sentSource == output,
|
||||
"the reference sent the old packet on the VIF1 channel");
|
||||
check(!native.dispatcher.kernel().handlerQueued(), "no completion callback is queued");
|
||||
check(std::memcmp(ram, expected.data(), expected.size()) == 0,
|
||||
"frame counter, channel handle and buffer toggle match; ALL other guest RAM stays unchanged");
|
||||
"frame counter, its flag, channel handle and buffer toggle match; ALL other guest RAM stays unchanged");
|
||||
reference.checkRetiredBank(); native.checkRetiredBank();
|
||||
}
|
||||
std::printf("DC frame submit: %d reference/adapted cases, %d failures\n", cases, failures);
|
||||
|
||||
@@ -9,7 +9,15 @@
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace video=bozo::app::video;
|
||||
namespace {
|
||||
int postCalls=0;video::Settings posted;bool postedSave=false;
|
||||
video::Shared fakeWindow(){
|
||||
video::Shared s;s.open=true;s.applied.width=1280;s.applied.height=960;s.applied.mode=video::WindowMode::Windowed;
|
||||
s.applied.renderScale=1.f;s.applied.frameRate=0;s.resolutions={{1280,960},{1920,1080}};s.monitor={2560,1440};s.monitorRefresh=144;
|
||||
return s;
|
||||
}
|
||||
void fakePost(const video::Settings &settings,bool save){++postCalls;posted=settings;postedSave=save;}
|
||||
constexpr uint32_t initPc=0x21e4d0,exitPc=0x21e780,keyPc=0x21e9b0,drawPc=0x21f2b0;
|
||||
constexpr uint32_t phase=0x1da8a50,fade=0x1da8a54,loaded=0x1da8ac4,pad=0x1cbc540;
|
||||
constexpr uint32_t user=0x400000,gp=0x300000,weapon=user+0x450c,record=0x1c76968,pixels=0x500000;
|
||||
@@ -67,7 +75,7 @@ int main(){
|
||||
check(initCalls==1 && read<int32_t>(r,phase)==0,"original loading and opening fade complete");
|
||||
check(drawCalls==0 && sceneCalls>0,"native page owns drawing after flushing scene work");
|
||||
const auto frame=bozo::render::Renderer::instance().published();check(frame && frame->batches.size()>=2,"root page submits board and owned font geometry");
|
||||
tap(*rt,p,0x4000);tap(*rt,p,0x40); // Root -> Cheats
|
||||
tap(*rt,p,0x4000);tap(*rt,p,0x4000);tap(*rt,p,0x40); // Root -> Graphics -> Cheats
|
||||
for(int i=0;i<4;++i){tap(*rt,p,0x40);check(dc::cheats::enabled(static_cast<dc::cheats::Cheat>(i)),"each cheat is controllable through the in-game page");if(i<3)tap(*rt,p,0x4000);}
|
||||
tap(*rt,p,0x4000); // ATK row
|
||||
tap(*rt,p,0x2000);tap(*rt,p,8);tap(*rt,p,2);tap(*rt,p,0x8000); // 30+1+10+100-1 = 140
|
||||
@@ -92,7 +100,7 @@ int main(){
|
||||
tap(*rt,p,0x4000);tap(*rt,p,2);tap(*rt,p,0x4000);tap(*rt,p,0x40);step(*rt,p);
|
||||
check(read<int8_t>(r,user+0x4360)==100,"inventory size is controller accessible and capped at 100");
|
||||
draw(*rt,p);const auto scrolled=bozo::render::Renderer::instance().published();check(scrolled && scrolled->batches.size()>=2,"last scroll page draws native text and board");
|
||||
tap(*rt,p,0x20);tap(*rt,p,0x1000);tap(*rt,p,0x40); // back -> Game Options
|
||||
tap(*rt,p,0x20);tap(*rt,p,0x1000);tap(*rt,p,0x1000);tap(*rt,p,0x40); // back -> Game Options
|
||||
const int beforeDraw=drawCalls;draw(*rt,p);check(drawCalls==beforeDraw+1,"original Game Options drawing remains available");
|
||||
tap(*rt,p,0x2000);check(read<int32_t>(r,0x1da8a64)==1,"Game Options input reaches its original handler");
|
||||
tap(*rt,p,0x20);check(read<int32_t>(r,phase)==0,"back from Game Options returns to root without closing");
|
||||
@@ -107,6 +115,24 @@ int main(){
|
||||
tap(*rt,p,0x40);tap(*rt,p,0x4000);tap(*rt,p,0x40);
|
||||
check(dc::cheats::takeIngameQuitRequest() && !dc::cheats::takeIngameQuitRequest(),"explicit Quit Game confirmation produces one shutdown request");
|
||||
call(*rt,p,exitPc);
|
||||
// Graphics: without the window (headless) the page only explains; with it, Apply posts the edited settings once.
|
||||
call(*rt,p,initPc);finishFade(*rt,p);tap(*rt,p,0x4000);tap(*rt,p,0x40); // Root -> Graphics
|
||||
tap(*rt,p,0x2000);tap(*rt,p,0x4000);tap(*rt,p,0x4000);tap(*rt,p,0x4000);tap(*rt,p,0x4000);tap(*rt,p,0x40);
|
||||
draw(*rt,p);const auto unavailable=bozo::render::Renderer::instance().published();
|
||||
check(postCalls==0 && unavailable && unavailable->batches.size()>=2,"Graphics without a window draws its notice and posts nothing");
|
||||
tap(*rt,p,0x20);check(read<int32_t>(r,phase)==0,"back from Graphics returns to root without closing");
|
||||
dc::cheats::setGraphicsAccess(fakeWindow,fakePost);tap(*rt,p,0x40); // Root (still on Graphics) -> Graphics
|
||||
tap(*rt,p,0x2000);tap(*rt,p,0x4000);tap(*rt,p,0x2000);tap(*rt,p,0x4000);tap(*rt,p,0x2000);tap(*rt,p,0x4000);tap(*rt,p,0x2000);
|
||||
check(postCalls==0,"Graphics edits wait for Apply");
|
||||
draw(*rt,p);const auto graphics=bozo::render::Renderer::instance().published();check(graphics && graphics->batches.size()>=2,"Graphics page draws native text and board");
|
||||
tap(*rt,p,0x4000);tap(*rt,p,0x40);
|
||||
check(postCalls==1 && postedSave && posted.mode==video::WindowMode::Fullscreen && posted.width==1920 && posted.height==1080 &&
|
||||
posted.renderScale==1.5f && posted.frameRate==-1,"Apply posts mode, size, render scale and frame rate once, saved");
|
||||
tap(*rt,p,0x4000);tap(*rt,p,0x2000);tap(*rt,p,0x4000);tap(*rt,p,0x2000); // Display -> Borderless; its size row is locked
|
||||
tap(*rt,p,0x4000);tap(*rt,p,0x4000);tap(*rt,p,0x4000);tap(*rt,p,0x40);
|
||||
check(postCalls==2 && posted.mode==video::WindowMode::Borderless && posted.width==1280 && posted.height==960,
|
||||
"Borderless keeps the window size it returns to");
|
||||
const int exitsBefore=exitCalls;tap(*rt,p,0x20);tap(*rt,p,0x20);finishFade(*rt,p);check(exitCalls==exitsBefore+1,"Options still closes after Graphics");
|
||||
std::memset(r+record+8,0,32);call(*rt,p,initPc);finishFade(*rt,p);const int fallback=drawCalls;draw(*rt,p);
|
||||
check(drawCalls==fallback+1,"missing font falls back to original Options without trapping input");
|
||||
for(int i=0;i<4;++i)dc::cheats::setEnabled(static_cast<dc::cheats::Cheat>(i),false);
|
||||
|
||||
@@ -200,23 +200,22 @@ int main()
|
||||
check(ref->packetCalls == (submitted ? 4 : 0) && native->packetCalls == 0,
|
||||
"only reference resets/ends/terminates, including End's now-visible nested terminate");
|
||||
check(ref->consoleCalls == (p.ended ? 0 : 3) && native->consoleCalls == 0, "adapted callback skips console half-offset/cache/swap setup");
|
||||
// The published reference still waits, flushes and sends; the adapted callback makes no transfer (the
|
||||
// game installs no DMA-completion handler). Its fade sprites must be the same calls, in order.
|
||||
auto sprites = [](const std::vector<Event> &all) {
|
||||
std::vector<Event> only;
|
||||
for (const auto &e : all) if (e.pc == 0x15c310) only.push_back(e);
|
||||
return only;
|
||||
};
|
||||
const int expectedSyncs = p.ended ? 0 : p.countdown == 0 ? 2 : 1;
|
||||
check(ref->events == native->events && ref->syncCalls == expectedSyncs && ref->syncCalls == native->syncCalls,
|
||||
"fade/sprite inputs, completion/cache/sync arguments and ordering match");
|
||||
check(ref->sendCalls == submitted && native->sendCalls == submitted &&
|
||||
(!submitted || (ref->sentChannel == native->sentChannel && ref->sentSource == output && native->sentSource == 0)),
|
||||
"same native completion count/channel without a packet source");
|
||||
check(ref->libs.io.nativeSubmissions[1] == submitted && native->libs.io.nativeSubmissions[1] == submitted &&
|
||||
ref->libs.io.nativeCompleted[1] == submitted && native->libs.io.nativeCompleted[1] == submitted,
|
||||
"native completion ownership matches");
|
||||
const bool queued = submitted && !masked;
|
||||
check(ref->dispatcher.kernel().handlerQueued() == queued && native->dispatcher.kernel().handlerQueued() == queued,
|
||||
"completion IRQ respects callback mask");
|
||||
if (submitted && masked)
|
||||
{
|
||||
ref->dispatcher.kernel().causeEnable(true, 1, true); native->dispatcher.kernel().causeEnable(true, 1, true);
|
||||
check(ref->dispatcher.kernel().handlerQueued() && native->dispatcher.kernel().handlerQueued(), "masked completion survives until enabled");
|
||||
}
|
||||
check(sprites(ref->events) == sprites(native->events), "fade/sprite inputs and ordering match");
|
||||
check(ref->syncCalls == expectedSyncs && native->syncCalls == 0, "only the reference waits on a channel");
|
||||
check(ref->sendCalls == submitted && (!submitted || ref->sentSource == output) && native->sendCalls == 0,
|
||||
"only the reference sends");
|
||||
check(native->events.size() == sprites(native->events).size(), "adapted callback makes no cache or transfer call");
|
||||
check(ref->libs.io.nativeSubmissions[1] == submitted && native->libs.io.nativeSubmissions[1] == 0,
|
||||
"no native submission from the adapted callback");
|
||||
check(!native->dispatcher.kernel().handlerQueued(), "no completion callback queued");
|
||||
check(adapted.fcr31 == original.fcr31, "fade float status matches published reference");
|
||||
check(std::memcmp(ram, expectedRam.data(), stack - 0x1000) == 0 &&
|
||||
std::memcmp(ram + stack, expectedRam.data() + stack, expectedRam.size() - stack) == 0,
|
||||
|
||||
@@ -64,14 +64,18 @@ namespace
|
||||
std::memset(ram + output, 0xa5, 0x20000);
|
||||
auto native = context(); native.pc = pc;
|
||||
registry.find(pc)(ram, &native, &rt);
|
||||
check(native.r[2].uw[0] == expectedSize, "native allocation extent matches original compiled builder");
|
||||
check(word(ram, visual + 0x1c) == expectedVisualSize, "visual size bookkeeping matches original");
|
||||
// The native extent is one qword: CreateVisual reserves it at the data address and aligns to 64 bytes, so each
|
||||
// build keeps a distinct address. The original's VIF packet size is no longer reserved.
|
||||
check(expectedSize > 1u && expectedVisualSize == expectedSize, "the original reserves its VIF packet size");
|
||||
check(native.r[2].uw[0] == 1u, "native allocation extent is one qword");
|
||||
check(word(ram, visual + 0x1c) == 1u && word(ram, visual + 0x18) == output,
|
||||
"visual records its data address and the native extent");
|
||||
check(native.pc == 0x123450 && native.r[29].uw[0] == 0x700000, "native builder preserves return and stack");
|
||||
check(std::all_of(ram + output, ram + output + 0x20000, [](uint8_t v) { return v == 0xa5; }),
|
||||
"native builder never serializes the console output");
|
||||
native = context(0x12000000); native.pc = pc;
|
||||
registry.find(pc)(ram, &native, &rt);
|
||||
check(native.r[2].uw[0] == expectedSize, "obsolete output address is never dereferenced");
|
||||
check(native.r[2].uw[0] == 1u, "obsolete output address is never dereferenced");
|
||||
}
|
||||
}
|
||||
int main()
|
||||
@@ -115,7 +119,8 @@ int main()
|
||||
auto native = context(0x12000000); native.pc = 0x13c5f0;
|
||||
registry.find(0x13c5f0)(ram, &native, rt.get());
|
||||
++cases;
|
||||
check(native.r[2].uw[0] == original.r[2].uw[0], "cloth allocation extent matches original compiled builder");
|
||||
check(original.r[2].uw[0] > 1u && native.r[2].uw[0] == 1u,
|
||||
"the original reserves its VIF size; native cloth reserves one qword");
|
||||
check(std::memcmp(ram, beforeCloth.data(), beforeCloth.size()) == 0, "cloth builder leaves all guest RAM unchanged");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ base, end, helpers = {
|
||||
'water': (0x160f20, 0x1610fc, [0x161100, 0x1281b0, 0x1607e0]),
|
||||
'effect': (0x163480, 0x1638ec, [0x1312d0, 0x12e990, 0x1110b0, 0x12e740, 0x15d4b0]),
|
||||
'frame_close': (0x12d1dc, 0x12d268, [0x120de0, 0x120c28, 0x112f98, 0x104698, 0x113f40]),
|
||||
'frame_submit': (0x12d63c, 0x12d6a8, [0x10c3a8, 0x1145a0, 0x10c6f8]),
|
||||
'frame_submit': (0x12d5c0, 0x12d6a8, [0x113e48, 0x112ea0, 0x10cc58, 0x10c3a8, 0x1145a0, 0x10c6f8]),
|
||||
'frame_draw': (0x12ed80, 0x12edec, [0x120c28, 0x120f78]),
|
||||
'frame_member': (0x12a110, 0x12a18c, [0x120c28, 0x120f78]),
|
||||
'mdt_draw': (0x1360e0, 0x136200, [0x127900, 0x1033b0, 0x135000]),
|
||||
@@ -91,9 +91,9 @@ target.with_suffix('.native.externals').write_text(target.with_suffix('.external
|
||||
selected = [line for line in patches.read_text().splitlines()
|
||||
if line.split('#')[0].strip() and span_start <= int(line.split()[0], 16) < end]
|
||||
expected = {'frame_close': 2, 'frame_draw': 0, 'frame_member': 0, 'mdt_draw': 2,
|
||||
'message': 3, 'edit_state': 2, 'menu_state': 2, 'loading': 9, 'fire': 6, 'language': 2, 'fishing': 9,
|
||||
'message': 3, 'edit_state': 2, 'menu_state': 2, 'loading': 13, 'fire': 6, 'language': 2, 'fishing': 9,
|
||||
'debug_font': 14, 'packet_init': 2, 'begin_frame': 5, 'resident_chain': 2, 'loading_init': 2,
|
||||
'packet_reserve': 2, 'buffer_clear': 4, 'packet_handle': 1, 'packet_get': 1}.get(kind, 4)
|
||||
'packet_reserve': 2, 'buffer_clear': 4, 'packet_handle': 1, 'packet_get': 1, 'frame_submit': 12}.get(kind, 4)
|
||||
handle_sites = {int(line.split()[0], 16) for line in selected
|
||||
if int(line.split()[0], 16) != 0x12e280
|
||||
and int(line.split()[1], 16) & 0xffe0ffff == 0x8f808bd4
|
||||
|
||||
@@ -5,7 +5,7 @@ if sys.argv[1]=='--overrides':
|
||||
addresses=set()
|
||||
for path in (root/'runtime').glob('dc_*.cpp'):
|
||||
addresses.update(int(x,16) for x in re.findall(r'0x([0-9a-fA-F]+)',path.read_text()))
|
||||
native_sites=(0x12C19C,0x15434C,0x12D268,0x1AB290,0x13DFA8,0x13DFF0,0x13E314,0x13E420,0x1DF2A0) # guarded port boundaries
|
||||
native_sites=(0x12C19C,0x15434C,0x12D268,0x1AB290,0x13DFA8,0x13DFF0,0x13E314,0x13E420,0x1DF2A0,0x1DC3F4) # guarded port boundaries
|
||||
out.write_text(''.join(f'override 0x{x:x}\n' for x in sorted(addresses) if 0x100000 <= x < 0x245300 and x not in native_sites)
|
||||
+ ''.join(f'native 0x{x:x}\n' for x in native_sites))
|
||||
sys.exit(0)
|
||||
|
||||
Reference in new issue
Block a user