Skip to content

Fix ACE.Adapter conversion bugs and add round-trip tests - #4551

Merged
Mag-nus merged 1 commit into
ACEmulator:masterfrom
Mag-nus:adapter-roundtrip-tests
Nov 24, 2026
Merged

Mag-nus merged 1 commit into
ACEmulator:masterfrom
Mag-nus:adapter-roundtrip-tests

Conversation

@Mag-nus

@Mag-nus Mag-nus commented Nov 24, 2026

Copy link
Copy Markdown
Member

Fix ACE.Adapter conversion bugs and add round-trip tests

The problem

ACE.Adapter converts world content between ACE's database models and the Lifestoned and GDLE JSON formats. The Developer commands /import-json, /export-json and /export-json-folders use it. Every converter ends in catch { return false; }, so when one fails the command reports only "Failed to convert", with no reason.

Converting content out and back in again loses or changes data in several places:

  • Weenies with some, but not all, attributes or max vitals fail to export. The export read all six attributes and all three max vitals with FirstOrDefault(...).InitLevel and no null check. A missing one threw a NullReferenceException, and the whole weenie failed. Doors and chests that carry only MaxHealth are typical.
  • Emote item details are dropped on export when the action has no destination. Give, TakeItems and InqOwnsItems actions name an item without a DestinationType. The export only wrote the item's WCID, stack size, palette and shade when a destination was set, but the import reads them whenever they are present.
  • Double values are cut to float precision. The GDLE models typed FloatStat.Value, EmoteAction.FMin/FMax/Percent and Skill.LastUsed as float, while ACE stores all of them as double. A value of 0.1 comes back as 0.10000000149. For InqFloatStat emotes this can flip a boundary check: EmoteManager tests stat >= MinDbl, so a property of exactly 0.1 fails a minimum that was 0.1 before the round trip.
  • Duplicate DID keys import as duplicate rows. Every other stat list skips a key that is already present. DIDs only did so when correctForEnumShift was true.
  • Bool recipe requirements lose their message on export. The import reads BoolRequirement.Message; the export never wrote it.
  • Recipe mods with no typed rows are dropped on export. A mod's GDLE slot was taken from its first typed row, so a mod with only Health/Stamina/Mana/DataId/InstanceId had no slot and was skipped. The import creates exactly that kind of mod, so a recipe could change just by being imported and exported again.

The fix

  • Attributes and vitals (LifestonedConverter): two helpers, ToAttribute and ToVital, find each row once and return null when it is absent. The import already skips null entries, so an absent attribute comes back absent instead of as a zero row. This also replaces 27 list searches per weenie with 9.
  • Emote items (LifestonedConverter): item details are exported when WeenieClassId or DestinationType is set.
  • Precision (FloatStat, EmoteAction, Skill, LifestonedConverter): the four model properties are now double/double?, and the casts to float on export are removed. JSON numbers carry no type, so existing files load unchanged. No code outside ACE.Adapter uses these properties.
  • Duplicate DIDs (LifestonedConverter): the correctForEnumShift == false path skips a key that is already present, like the other path and every other stat list.
  • Bool requirement message (GDLEConverter): exported.
  • Untyped recipe mods (GDLEConverter): a mod with no typed rows takes the first free slot for its ExecutesOnSuccess value (0-3 on success, 4-7 on failure). Mods with typed rows are placed first, so an untyped mod cannot take a slot a typed mod needs.

One behaviour change in the export: a weenie with attributes but no vitals used to export health, stamina and mana objects full of zeros. It now leaves them out. Importing the JSON gives the same result as before, because AttributeSet creates default vitals when they are absent. That default, which gives such a weenie three zero-valued vital rows on import, is unchanged here. Changing it would alter how existing Lifestoned files import.

Tests

New project Source/ACE.Adapter.Tests (MSTest, no database or dat files needed, about 200 ms):

  • Round-trip sweep (RoundTripTests): for each of the six converter pairs that exist in both directions (Weenie, Quest, Recipe, CookBook, combined recipe, landblock), the test fills an object by reflection with a distinctive non-default value in every field. It then converts the object to the external format and back, and compares the two field by field. Each pair runs twice, with every bool seeded true and then false, so a dropped flag can't hide behind its default. Doubles are seeded as N+0.1, so any narrowing to float shows up.
  • Swallowed exceptions: the harness records any exception a converter catches and discards, with its file and line, and fails the test on it.
  • Expected differences: each test lists what its round trip is allowed to lose, with a reason, for example database keys, computed columns, or members the external format doesn't have. Any other difference fails.
  • Probes (ProbeTests): one targeted test per fix above, plus a full JSON round trip through TryConvertACEWeenieToLSDJSON and LifestonedLoader. Two further probes cover landblock GUID reassignment and the exception recorder itself.

Results:

  • All 23 tests pass with the fixes.
  • Against the unmodified converters, 15 of them fail.
  • To check that the sweep catches regressions, two field copies were temporarily removed from the converters (Quest.MaxSolves and emote Probability). The sweep caught both.
  • The solution builds with 0 warnings and 0 errors.
  • ACE.Server.Tests, ACE.Database.Tests and ACE.DatLoader.Tests were not re-run; this PR doesn't change any code they test.
  • Not tested: /import-json and /export-json against a live server and world database.

Other changes

  • ACE.sln: adds ACE.Adapter.Tests.
  • AppVeyor/AppVeyorTestScript.bat: runs ACE.Adapter.Tests.
  • ACE.DatLoader.Tests.csproj: references Appveyor.TestLogger, like the other test projects. This only takes effect once DatLoader tests are added to the CI script, which this PR doesn't do, because they need retail dat files.

Files

  • Source/ACE.Adapter/GDLE/GDLEConverter.cs
  • Source/ACE.Adapter/GDLE/Models/EmoteAction.cs
  • Source/ACE.Adapter/GDLE/Models/FloatStat.cs
  • Source/ACE.Adapter/GDLE/Models/Skill.cs
  • Source/ACE.Adapter/Lifestoned/LifestonedConverter.cs
  • Source/ACE.Adapter.Tests/ (new)
  • Source/ACE.DatLoader.Tests/ACE.DatLoader.Tests.csproj
  • Source/ACE.sln
  • AppVeyor/AppVeyorTestScript.bat

🤖 Generated with Claude Code

Converting content out to Lifestoned/GDLE JSON and back lost or changed
data in six places:

- Weenie export threw NullReferenceException, and failed the whole
  weenie, when any attribute or max vital was missing. Each is now looked
  up once and left null when absent; import already skips nulls.
- Emote item details were exported only when DestinationType was set.
  They are now exported when WeenieClassId is set too.
- FloatStat.Value, EmoteAction.FMin/FMax/Percent and Skill.LastUsed were
  float in the GDLE models but double in ACE. They are now double and the
  narrowing casts are gone.
- Duplicate DID keys imported as duplicate rows when correctForEnumShift
  was false.
- Bool recipe requirement messages were not exported.
- Recipe mods with no typed rows had no slot and were dropped on export.
  They now take the first free slot for their ExecutesOnSuccess value,
  after mods with typed rows are placed.

Adds ACE.Adapter.Tests: a reflection-driven round-trip sweep over the six
two-way converter pairs, run with bools seeded true and false, plus one
probe per fix and a JSON round trip. 23 tests pass; 15 fail against the
unfixed converters. Adds the project to ACE.sln and the AppVeyor test
script, and references Appveyor.TestLogger from ACE.DatLoader.Tests like
the other test projects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mag-nus
Mag-nus merged commit 742fd66 into ACEmulator:master Nov 24, 2026
2 checks passed
@Mag-nus
Mag-nus deleted the adapter-roundtrip-tests branch November 24, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants