Skip to content

Replace BTJsonIDCheck.exe with a cross-platform Python port#10829

Open
nx-thaddeusaid wants to merge 1 commit into
BattletechModders:masterfrom
nx-thaddeusaid:replace-btjsonidcheck-with-python
Open

Replace BTJsonIDCheck.exe with a cross-platform Python port#10829
nx-thaddeusaid wants to merge 1 commit into
BattletechModders:masterfrom
nx-thaddeusaid:replace-btjsonidcheck-with-python

Conversation

@nx-thaddeusaid
Copy link
Copy Markdown

Summary

Documents/BTJsonIDCheck.exe is a 12 KB Windows-only .NET WinForms
assembly with no source in-tree. This PR replaces it with
tools/btjsonid_check.py, which runs the same algorithm on Linux,
macOS, and Windows from source.

What the original does

Proven by the strings embedded in the .NET metadata and #US
user-string heap (see docs/reference/btjsonidcheck-evidence.md):

  • GetFileNameWithoutExtension / Newtonsoft.Json.Linq — it reads
    each *.JSON file and parses it as a JObject.
  • Description — the property accessed.
  • Id not match file name: — the check error message.
  • BTJsonIDCheck.log — the output log filename.

Algorithm:

for every *.json under source directory:
    data = Newtonsoft.Json.parse(file)
    id   = data["Description"]["Id"]          # skip if missing
    stem = Path.GetFileNameWithoutExtension(file)
    if id != stem:
        log "Id not match file name: Id: '<id>' ..."

What the Python port does

tools/btjsonid_check.py — same algorithm on stdlib json. Includes
--count for CI integration.

Results on current master

checked 33,426 JSON files
1 id-mismatch:
  Core/RogueBackgrounds/event with box CommanderGearEventOfficer.json
    Id='CommanderGearEventOfficer'
    stem='event with box CommanderGearEventOfficer'

One real data bug the original would flag identically.

Changes

  • add tools/btjsonid_check.py — the port (83 lines).
  • add docs/reference/btjsonidcheck-evidence.md — full decompilation trail.
  • delete Documents/BTJsonIDCheck.exe.

Limitations

  • The original's WinForms GUI (window, progress bar, message boxes) is
    not reproduced — this is a deliberate CLI replacement.
  • I could not execute the original on Linux (no wine available), so the
    validation rests on the decompiled strings rather than a byte-compare
    of output files. If a Windows maintainer can run the original against
    current master and post the log, that'd close the last gap.

Test plan

  • python3 tools/btjsonid_check.py on a clean checkout prints the
    one known mismatch.
  • python3 tools/btjsonid_check.py --count returns 1 on a clean
    checkout.
  • (Optional) Run the original .exe on Windows against master and
    compare the log — expect the same single mismatch.

The original is a 12 KB Windows-only .NET WinForms assembly built
from a source tree we do not have. UTF-16 string literals embedded in
the .exe's #US heap reveal the exact algorithm: read Description.Id,
compare to Path.GetFileNameWithoutExtension, flag mismatches. The
Python port does the same with the stdlib `json` module and runs on
Linux, macOS, and Windows.

Evidence lifted from the .exe:
- "Description"                 — JSON property accessed
- "Id not match file name:"     — mismatch log line
- "GetFileNameWithoutExtension" — filename-stem comparison
- "Newtonsoft.Json.Linq"        — JObject/JToken parser
- "BTJsonIDCheck.log"           — output log filename

Full evidence + string dump in docs/reference/btjsonidcheck-evidence.md.

Running the port on this repo:
  checked 33,426 JSON files
  1 id-mismatch: Core/RogueBackgrounds/event with box CommanderGearEventOfficer.json
    (Id='CommanderGearEventOfficer', stem='event with box CommanderGearEventOfficer')

That single mismatch is a real data bug; the original .exe would
have reported the same file on the same tree.

The .exe was GUI-only (WinForms); the Python replacement is CLI.
Redirect stdout if you want the historical BTJsonIDCheck.log format.
@wmtorode
Copy link
Copy Markdown
Member

@nx-thaddeusaid

I have several questions:

  1. Are you an Agent or a person?
  2. Why would we want to replace a GUI tool with a CLI script?
  3. Why do we want/need cross platform support for this development tool when the people who are going to be running it are on windows?
  4. why do we need an 'evidence' doc describing the replacement of the original tool to now live in the repo if we were to accept this?

@nx-thaddeusaid
Copy link
Copy Markdown
Author

I am a person, and I don't actually expect you to accept all of it, but I was assigned a work task to expend some credits and figured that I would send them this way

I will not be offended if you refuse the code and simply delete it. What I was hoping for was that you would find utility in the exe replacement with controllable, understandable code.

I've already been paid ;) do with this as you will

@nx-thaddeusaid
Copy link
Copy Markdown
Author

However, the documentation does say that no one understands how these exes work

There is no documentation

There is no source

There is no replacement

I offer you a replacement

The company that I'm consulting for is footing the bill on this one

@nx-thaddeusaid
Copy link
Copy Markdown
Author

@nx-thaddeusaid

I have several questions:

  1. Are you an Agent or a person?
  2. Why would we want to replace a GUI tool with a CLI script?
  3. Why do we want/need cross platform support for this development tool when the people who are going to be running it are on windows?
  4. why do we need an 'evidence' doc describing the replacement of the original tool to now live in the repo if we were to accept this?

I just sent you a message on discord

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