Complete SC5/SV5 round-trip serialization and editor support in ObjectEditor - #261
Merged
Merged
Conversation
Co-authored-by: LeftofZen <7483209+LeftofZen@users.noreply.github.com>
Co-authored-by: LeftofZen <7483209+LeftofZen@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
LeftofZen
September 2, 2026 07:24
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
There are a couple of correctness issues in newly added save logic (file extension selection and packed-object header/count consistency) that can produce malformed or mis-typed output files.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR completes SC5/SV5 (S5) map-file round-trip support across the Dat serializer and the ObjectEditor UI, aiming for byte-identical load -> save output while also enabling in-editor modifications (notably tile elements and required objects).
Changes:
- Adds packed-object read/write support that preserves original encoded chunk bytes for byte-identical round-tripping.
- Implements tile-element serialization (
TileElement.Write) and updatesS5File.Write()to emit edited tile elements when present. - Enables SCV5 Save/Save As in the editor and adds regression tests asserting byte-identical output for SC5/SV5.
File summaries
| File | Description |
|---|---|
| Tests/SCV5SerializationTests.cs | Adds round-trip tests for SC5/SV5 asserting byte-identical load -> save. |
| Gui/Views/MainWindow.axaml | Switches the TileElement editor template to a PropertyGrid-based editor. |
| Gui/ViewModels/Loco/SCV5ViewModel.cs | Enables Save/Save As for SCV5 files and wires saving through S5File.Write(). |
| Dat/Types/SCV5/TileElement.cs | Preserves the raw type byte and adds Write() for tile-element serialization. |
| Dat/Types/SCV5/ScenarioOptions.cs | Fixes LandDistributionPatterns to the correct array shape. |
| Dat/Types/SCV5/S5File.cs | Implements packed-object chunk round-tripping, correct save-variant writing, and tile-element emission. |
| Dat/Types/SCV5/GameStateSave1.cs | Fixes Orders array sizing to kMaxOrders. |
| Dat/Types/S5Header.cs | Makes S5Header an ILocoStruct to support nested struct serialization paths. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
82
to
+86
| // packed | ||
| ReadOnlySpan<byte> packed = []; | ||
| byte[] packed = []; | ||
| if (Header.NumPackedObjects != 0) | ||
| { | ||
| // todo: add data here | ||
| // todo: copy ObjectManager::writePackedObjects | ||
| //packed = WritePackedObjects(); | ||
| packed = WritePackedObjects(); |
Comment on lines
+245
to
+246
| static byte[] SerializeTileElements(IEnumerable<TileElement> tileElements) | ||
| => tileElements.SelectMany(x => x.Write()).ToArray(); |
Comment on lines
315
to
+319
| public override void Save() | ||
| => Logger.LogWarning("Save is not currently implemented"); | ||
| { | ||
| var savePath = CurrentFile.FileLocation == FileLocation.Local | ||
| ? CurrentFile.FileName | ||
| : Path.Combine(EditorContext.Settings.DownloadFolder, Path.ChangeExtension($"{CurrentFile.DisplayName}-{CurrentFile.Id}", ".sv5")); |
| public const uint8_t FLAG_LAST = 1 << 7; | ||
|
|
||
| public ElementType Type { get; set; } | ||
| public uint8_t TypeByte { get; set; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This updates the partial SC5/SV5 implementation to support reliable load/save round-tripping for OpenLoco map files, including packed object chunks and tile-element data. It also fills key S5 structure gaps and wires map-file editing paths needed by the editor UI.
S5 binary model + serializer parity
S5Header + ObjectHeader + encoded payload).TileElement.Write) and switched save logic to emit edited tile elements when available.GameStateSave1/GameStateSave2).S5 structure correctness fixes
ScenarioOptions.LandDistributionPatternsto the correct array shape.Orderssizing tokMaxOrders.S5Headerserializable as a nested loco struct to support chunk-based object serialization paths.Editor behavior
Regression coverage
load -> saveyields byte-identical output.