|
1 | 1 | # Reference Replacement Mod |
2 | 2 |
|
3 | | -A ResoniteModLoader plugin that replicates the built-in Asset Optimization workflow for bulk reference swapping. It scans a slot hierarchy, finds every `ISyncRef` that currently points to a selected source `IWorldElement`, and rewrites the reference to a replacement target inside a single undo batch. |
| 3 | +A [ResoniteModLoader](https://github.com/resonite-modding-group/ResoniteModLoader) mod for [Resonite](https://resonite.com/) that mirrors the Asset Optimization workflow to bulk swap every matching `ISyncRef` inside a single undo batch. |
4 | 4 |
|
5 | 5 | ## Features |
6 | | -- Dev Tool context-menu entry so you can open the dialog directly from the inspector/dash (“Reference Replacement…”). |
7 | | -- Modal UI in userspace with reference pickers for the process root slot plus source/target references. |
8 | | -- Dry-run analysis button that reports how many matches (and incompatibilities) were discovered before you commit the change. |
9 | | -- Replacement button that writes every compatible `ISyncRef` inside one undo batch for clean rollback. |
10 | | -- Skips refs whose target type is incompatible with the requested replacement and reports how many were skipped. |
| 6 | +- Dev Tool context-menu entry (**Reference Replacement…**) to open the dialog from any inspected slot. |
| 7 | +- Userspace dialog with pickers for process root, source reference, and replacement target. |
| 8 | +- Analyze button that previews compatible vs incompatible hits before committing. |
| 9 | +- Replace button that writes every compatible reference atomically for clean undo support. |
| 10 | +- Automatic skip counters so incompatible targets are reported instead of silently failing. |
11 | 11 |
|
12 | | -## Building |
13 | | -1. Install the .NET 9 SDK. |
14 | | -2. Point the build at your Resonite installation by passing a property when invoking any `dotnet` command: |
15 | | - ```bash |
16 | | - dotnet build ReferenceReplacement.sln \ |
17 | | - -p:ResoniteAssembliesDir="/absolute/path/to/Resonite" |
18 | | - ``` |
19 | | - The property must contain the folder with `FrooxEngine.dll`, `Elements.Core.dll`, `rml_libs/0Harmony.dll`, and `Libraries/ResoniteModLoader.dll`. The repo never stores those binaries. |
20 | | -3. (Optional) Set `CopyToMods=true` to copy the built DLL into `$(ResoniteAssembliesDir)/rml_mods` after each build. |
21 | | -4. (Optional) To enable hot reload during local development, place `ResoniteHotReloadLib.dll` (and its companion `ResoniteHotReloadLibCore.dll`) under `$(ResoniteAssembliesDir)/rml_libs` and build with `-p:EnableResoniteHotReloadLib=true`. Leave the property unset (default) if the extra assemblies are not available. |
22 | | - |
23 | | -### Hot Reload (Optional) |
24 | | -- Builds compiled with `-p:EnableResoniteHotReloadLib=true` register the mod with [ResoniteHotReloadLib](https://github.com/Nytra/ResoniteHotReloadLib), enabling the Dev Tool’s **Hot Reload Mods** panel to reload it without restarting Resonite. |
25 | | -- Keep the property unset for CI or clean machines: the mod skips referencing the library entirely, so contributors without the DLL can still build and test normally. |
26 | | - |
27 | | -## Usage |
28 | | -1. Equip the Dev Tool, target any slot, and open its context menu (default `T`). |
29 | | -2. Choose **Reference Replacement…** to spawn the dialog in userspace. |
30 | | -3. Use the three reference fields to pick: |
31 | | - - Process root (slot): the slot whose subtree should be scanned. |
32 | | - - Source reference: any slot, component, or other `IWorldElement` you wish to replace. |
33 | | - - Replacement reference: the new `IWorldElement` all matching `ISyncRef`s should target. |
34 | | -4. Press **Analyze** to preview counts. Press **Replace** to run the swap inside a single undo batch. |
35 | | -5. Close the dialog when finished. |
| 12 | +## Installation |
| 13 | +1. Install [ResoniteModLoader](https://github.com/resonite-modding-group/ResoniteModLoader). |
| 14 | +2. Download the latest `ReferenceReplacement.dll` from this repo’s Releases page and place it in the `rml_mods` folder inside your Resonite install (e.g., `C:\Program Files (x86)\Steam\steamapps\common\Resonite\rml_mods`). Create the folder if it does not exist. |
| 15 | +3. Launch Resonite and confirm the mod loads via the in-game logs if desired. |
36 | 16 |
|
37 | | -## Design Summary |
38 | | -- **Entry point:** A Harmony postfix on `DevTool.GenerateMenuItems` adds the context menu button and funnels requests to a singleton dialog manager so only one window per user exists. |
39 | | -- **UI layer:** A dedicated `ReferenceReplacementDialog` controller builds the Asset Optimization style panel with reusable `ReferenceProxy` fields, local-only button events, and status readouts. |
40 | | -- **Scanning:** `ReferenceScanner` walks the process root, every child slot, and every component’s sync members. It recursively descends through `ISyncRef`, `SyncRefList`, `SyncRefDictionary`, and other enumerable sync containers, capturing every reference that matches the selected source. Paths are tracked for reporting and debugging. |
41 | | -- **Safety:** Before applying changes, the dialog verifies that root/source/replacement live in the same world and that the source differs from the replacement. Replacement happens within an undo batch (`UndoManagerExtensions.BeginUndoBatch/EndUndoBatch`) so the user can revert in one step, and every incompatible reference is skipped with a counter in the status panel. |
42 | | - |
43 | | -## Repository Layout |
44 | | -``` |
45 | | -ReferenceReplacementMod/ |
46 | | -├── ReferenceReplacement.sln |
47 | | -├── README.md |
48 | | -└── src/ReferenceReplacement/ |
49 | | - ├── ReferenceReplacement.csproj |
50 | | - ├── ReferenceReplacementMod.cs |
51 | | - ├── Logic/ReferenceScanner.cs |
52 | | - ├── Patching/DevToolMenuPatch.cs |
53 | | - └── UI/ |
54 | | - ├── ReferenceReplacementDialogManager.cs |
55 | | - └── ReferenceReplacementDialog.cs |
56 | | -``` |
| 17 | +## Build & Hot Reload |
| 18 | +1. Install the .NET 9 SDK. |
| 19 | +2. `dotnet build ReferenceReplacement.sln` auto-detects `Resonite` next to the repo, the default Steam Windows path, then the default Steam Linux path. If the game lives elsewhere, pass `-p:ResoniteAssembliesDir="/absolute/path/to/Resonite"` so the build can find `FrooxEngine.dll`, `Elements.Core.dll`, `Libraries/ResoniteModLoader.dll`, and `rml_libs/0Harmony.dll`. |
| 20 | +3. Set `CopyToMods=true` when invoking `dotnet build` to copy the compiled DLL into `$(ResoniteAssembliesDir)/rml_mods` after each build. |
| 21 | +4. Drop `ResoniteHotReloadLib.dll` (and `ResoniteHotReloadLibCore.dll`) into `$(ResoniteAssembliesDir)/rml_libs` and build with `-p:EnableResoniteHotReloadLib=true` if you want the Dev Tool’s **Hot Reload Mods** panel to reload this mod without restarting Resonite. Leave the property unset on machines without the DLL. |
0 commit comments