Skip to content

Conversation

@bobtista
Copy link

@bobtista bobtista commented Dec 11, 2025

Adds JSON chunk format support for converting SCB <->JSON. This implementation integrates directly into the game engine's existing DataChunk system rather than being a standalone tool.

Tested round trip for GeneralsMD on SkirmishScripts.scb and MultiplayerScripts.scb, byte for byte identical

TODO:
[ ] Replicate to Generals

@bobtista bobtista force-pushed the bobtista/data-chunk-json-converter branch 4 times, most recently from 5d53a71 to ebe3cd5 Compare December 12, 2025 14:46
@bobtista bobtista marked this pull request as ready for review December 12, 2025 14:47
Copy link

@Skyaero42 Skyaero42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the purpose of this conversion tool? When would somebody use it?

It feels very AI-ish, barely any comments and large methods with hundreds of lines of code.

{
initMemoryManager();

const char* gameDir = "C:\\Program Files\\EA Games\\Command and Conquer Generals Zero Hour\\Command and Conquer Generals Zero Hour";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded gamedir

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Updated to use our registry lookup, also added the gamedir as an optional command line arg

return true;
}

int main(int argc, char* argv[])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lacking any comments on how to use this tool and what it does

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add comments. I generally get asked to remove them, overcompensated this time

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a couple of comments, can add more where helpful

@bobtista
Copy link
Author

bobtista commented Dec 16, 2025

Whats the purpose of this conversion tool? When would somebody use it?

It feels very AI-ish, barely any comments and large methods with hundreds of lines of code.

"This will allow us to edit and revision AI scripts in plain text."

And yes, I very much used Claude on this one, particularly when going from having round trip go from "This is logically the same" to "This is byte for byte identical." Also getting the initial build to compile (needed to include/stub a lot of stuff to keep it living in the game code), and getting it to run without issue (needed to use the debugger and step line by line to find issues). There was a lot of "here's the diff output, explain the likely causes and propose 3 fixes explaining the tradeoffs of each" over and over - it's a grind for sure, but manually getting byte for byte would have taken forever. My goal was to get the tool to work first, which it does, provably so. From here, I'm happy to refactor and improve it however is best.

@bobtista bobtista force-pushed the bobtista/data-chunk-json-converter branch from 223f08b to 5b4a27f Compare December 16, 2025 15:30
@bobtista bobtista marked this pull request as draft January 4, 2026 07:26
@bobtista bobtista force-pushed the bobtista/data-chunk-json-converter branch 7 times, most recently from fe39a9e to e364ebe Compare January 5, 2026 01:40
@bobtista bobtista force-pushed the bobtista/data-chunk-json-converter branch from 6a25b9b to 2fdf9ce Compare January 7, 2026 04:42
@bobtista
Copy link
Author

bobtista commented Jan 7, 2026

Here is the standalone version https://github.com/bobtista/GeneralsGameCode/pull/new/bobtista/data-chunk-json-converter-standalone which I know is not the direction we're going in, but it works and may be useful some day.

I'm also thinking we can get 100% automatic syncing on changes (those that wouldn't break existing scbs anyway), by combining the binary and json conversions with templating. We should also be able to get the names instead of numbers when there's mapping in the code, while still keeping things synced. For the key names though, this mapping doesn't exist yet. The binary writer just outputs their values, but we could make the JSON way more readable if we add the field name. We'd make a one time change like

chunkWriter.writeInt(pCondition->m_conditionType);
  to:
chunkWriter.writeInt("conditionType", pCondition->m_conditionType);

Right now we have ~25 of them, and this would be a one time change - in the future if we for some reason add another, we'd just add another line like this with the name as a param. This just makes the json output more human readable.

@bobtista bobtista force-pushed the bobtista/data-chunk-json-converter branch from be48b3b to 5418a61 Compare January 8, 2026 01:53
bobtista and others added 4 commits January 7, 2026 20:58
Add writeEnumAsInt() method to ChunkOutputStream interface that writes
int values to binary but string names to JSON _items array.

Enum types converted:
- COMPARISON: LESS_THAN, LESS_EQUAL, EQUAL, GREATER_EQUAL, GREATER, NOT_EQUAL
- RELATION: ENEMIES, NEUTRAL, ALLIES
- AI_MOOD: SLEEP, PASSIVE, NORMAL, ALERT, AGGRESSIVE
- RADAR_EVENT_TYPE: INVALID, CONSTRUCTION, UPGRADE, etc.
- BUILDABLE: Yes, Only_AI, No, Ignore_Prerequisites
- SURFACES_ALLOWED: LAND, WATER, CLIFF
- SHAKE_INTENSITY: SUBTLE, NORMAL, STRONG, SEVERE, EXTREME
- LEFT_OR_RIGHT: LEFT, RIGHT

Roundtrip tested: SCB -> JSON -> SCB produces byte-identical output.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@bobtista
Copy link
Author

bobtista commented Jan 8, 2026

Ok, here's the latest - this is all 100% byte identical round trip, and inherits any changes automatically from the game. The json output is pretty readable for anyone familiar with scripting - would love feedback at this point, can share the json of skirmish or multiplayer scb files.

Script: "USA Base Expansion Check"

  • Runs on: normal and hard difficulty (not easy)
  • isOneShot: true (runs once, then disables)
  • delayEvaluationSeconds: 7 (waits 7 seconds before checking)

Conditions (OrCondition groups are OR'd, multiple groups are AND'd):

"condition": "PLAYER_HAS_CREDITS"
"_items": ["INT", 7000, "COMPARISON", "GREATER_EQUAL", "SIDE", ""]
→ has ≥ 7000 credits

"condition": "PLAYER_HAS_OBJECT_COMPARISON"
"_items": ["SIDE", "", "COMPARISON", "LESS_EQUAL", "INT", 3, "OBJECT_TYPE", "Supply Lines - Buildings"]
→ has ≤ 3 "Supply Lines - Buildings"

"condition": "COUNTER"
"_items": ["COUNTER", "_ESCALATION", "COMPARISON", "GREATER_EQUAL", "INT", 25]
→ Counter _ESCALATION is ≥ 25

Actions (when conditions pass):

"action": "ENABLE_SCRIPT"
"_items": ["SCRIPT", "USA Base Expand Start-B"]
→ Enable script "USA Base Expand Start-B"

"action": "SET_MILLISECOND_TIMER"
"_items": ["COUNTER", "USA Build Expansion Timer-B", "REAL", 15.0]
→ Set timer "USA Build Expansion Timer-B" to 15 seconds

"action": "CALL_SUBROUTINE"
"_items": ["SCRIPT_SUBROUTINE", "USA Base Expand Start - N"]
→ Call subroutine "USA Base Expand Start - N"

An actual snippet of the json for example:

"_children": [
                      {
                        "_items": [
                          "INT",
                          12000,
                          0.0,
                          "",
                          "COMPARISON",
                          3,
                          0.0,
                          "",
                          "SIDE",
                          0,
                          0.0,
                          "<This Player>"
                        ],
                        "condition": "PLAYER_HAS_CREDITS",
                        "label": "Condition",
                        "version": 4
                      },

@bobtista
Copy link
Author

made an MVP, going to use it and iterate and add QOL improvements based on feedback, but it's another large change - will close this for now and make a new one later

@bobtista bobtista closed this Jan 13, 2026
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.

Implement SCB to plain text to SCB compiler

2 participants