Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Check the protobuf schemas against the client's own, and fix the fields that differ - #405

Open
kcid9660 wants to merge 2 commits into
STFC-Mod:devfrom
kcid9660:pr/proto-schemas
Open

kcid9660 wants to merge 2 commits into
STFC-Mod:devfrom
kcid9660:pr/proto-schemas

Conversation

@kcid9660

@kcid9660 kcid9660 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

What changed and why

The schemas in src/mod/game/proto are written by hand. A field declared with the wrong type does not fail to decode: it reads as 0 or as a garbled value, as #400 found for ten fields. The client carries its real schemas, so this reads them and compares.

1. Dump the client's schemas ([config] dump_proto_schemas, default off)

Once each time the setting turns on, the mod writes community_patch_proto_schemas.binpb, a standard FileDescriptorSet with every file after its imports. On the current client it holds 256 files (231 KB).

The client cannot build most of its own descriptors. Its build strips members Google.Protobuf's reflection looks up by name, so descriptor.proto's initializer throws (DescriptorValidationException: google.protobuf.FileDescriptorSet.file: Property File not found). Every game schema imports it through extensions.proto, so every XxxReflection.Descriptor throws in turn. The dump therefore reads each schema where its initializer decodes it, before anything can fail: while the dump runs, a hook on System.Convert.FromBase64CharPtr keeps any decoded buffer that parses as a FileDescriptorProto. (FromBase64String itself is inlined into most callers in this build.) Outside the dump the hook only calls the original. The initializers still fail afterwards, which the log reports once per class; the game never uses those classes.

  • il2cpp: AllClasses() and StaticProperty() for scans by shape, in their own unit (scan.cc) so binaries that never scan import nothing new.
  • The IL2CPP exception report now appends inner exceptions, since a TypeInitializationException names no cause.
  • [patches] protoschemahooks switches the hook off.

2. Compare (zig build check-proto -Dgame-schemas=<file>)

compare-proto (reusing select_proto.zig's reader) matches every checked-in message to the client's by csharp_namespace (or package) and name, and each field by number. It fails on a type or cardinality difference and lists renamed or missing fields. Map entries are matched by key and value, not by their generated entry name.

3. Fix what it found (965 messages compared, game build of 2026-11-28)

Field Was Client Effect of the old type
DeployedFleet.battleWon bool google.protobuf.BoolValue read false on every journal; battle_won came only from initiator_wins
ServiceResponse.serverTime, .error fields 3, 6 fields 2, 3 both misread; only entityGroups is read today
UserProfile.ftueStage, UserTemplateHeader.level int32 sfixed32 read 0
UserProfile.level, .levelLastAwarded fixed32 sfixed32 same wire, sign only
Instance.status, .maintenance int32, int64 sint32, sint64 read doubled (zigzag)
ContentItem.level, Resource.amountOld uint32 fixed32 read 0
EventModel.ranks singular repeated kept only the last rank
ActiveMission.activeObjective MissionObjective ActiveObjective decoded as the wrong message
ActionSpec.behaviours ActionBehaviours int32 (flags) same wire
BridgeCrewOfficer.slotIndex, JournalGalacticAnomalyData.systemBuffs values int64 int32 same wire

userId and serverVersion are dropped from ServiceResponse; the client's schema has neither. battle_won now takes the wire value and still falls back to the side's own result, so no journal loses a true it had before.

After the fixes, check-proto reports no type or cardinality mismatches.

Validation

  • Windows, Zig 0.16: zig build install mods build-tests test-mod test-sync test-il2cpp test-codegen -Dtarget=x86_64-windows-msvc -Doptimize=ReleaseFast; scripts/check-il2cpp-dump.py reports 221 bindings, 0 problems.
  • In game (Windows, ReleaseFast): the dump wrote 256 files; check-proto against it fails before the fixes (15 mismatches) and passes after them.
  • The dump loads with standard tools once two client quirks are allowed for: the options file is registered as extensions.proto but 241 files import it as digit_extensions/extensions.proto, and resource.proto and store_offers.proto both declare a top-level Resource in the empty package (C# namespaces keep them apart).
  • Not built for macOS locally (no SDK here); CI covers it.
  • Based on 1071b75, one before Allow armada speedups by right clicking #404: dev at cc4a106 does not build yet (SemaphoreButtonListener has no Interactable), so build-win and build-mac on this PR will fail for that reason until it is fixed.

Settings and platforms

  • New: [config] dump_proto_schemas = false (developer diagnostic) and [patches] protoschemahooks = true.
  • No new server call or game-side action. The hook only observes while the dump runs.
  • For sync sites: battle journals can now carry battle_won: true from the wire where the side's result said otherwise; ServiceResponse decodes server_time and error from the right fields.

🤖 Generated with Claude Code

The schemas in src/mod/game/proto are written by hand, and a field declared
with the wrong type does not fail: it decodes as 0 or a garbled value (STFC-Mod#400
fixed ten of them). The client carries the real ones, so read them.

- [config] dump_proto_schemas: once each time it turns on, the frame tick finds
  every generated XxxReflection.Descriptor, reads FileDescriptor.SerializedData
  and writes community_patch_proto_schemas.binpb, a FileDescriptorSet with each
  file after its imports. Sync sites can decode raw reports with it too.
- zig build check-proto -Dgame-schemas=<file>: compare-proto checks every
  checked-in message against the client's by field number and fails on a type
  or cardinality mismatch; renamed and missing fields are reported only.
- il2cpp: AllClasses() and StaticProperty() for scans by shape, in their own
  unit so binaries that never scan import nothing new.
Compared with the client's own schemas (dump_proto_schemas + check-proto,
game build of 2026-11-28), 965 messages, these fields differed:

- DeployedFleet.battleWon: bool -> google.protobuf.BoolValue. It read false on
  every journal; battle_won now takes the wire value, still falling back to
  the side's own result.
- ServiceResponse: serverTime is field 2 and error field 3 (were 3 and 6);
  userId and serverVersion are not in the client's schema.
- UserProfile.level, levelLastAwarded: fixed32 -> sfixed32 (same wire);
  ftueStage: int32 -> sfixed32. UserTemplateHeader.level: int32 -> sfixed32.
- Instance.status, maintenance: int32/int64 -> sint32/sint64 (zigzag).
- ContentItem.level, Resource.amountOld: uint32 -> fixed32.
- EventModel.ranks: repeated. ActiveMission.activeObjective: ActiveObjective.
- ActionSpec.behaviours: int32 flags. BridgeCrewOfficer.slotIndex and
  JournalGalacticAnomalyData.systemBuffs values: int32 (same wire).

check-proto now reports no type or cardinality mismatches.
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.

1 participant