Skip to main content
The Crimsonland project includes 40+ analysis and utility scripts to support reverse engineering, parity verification, and development workflows.

Build Automation (Just)

The project uses just as a command runner. All common tasks are defined in justfile.

Common Commands

just --list              # Show all available commands
just check               # Run full verification suite
just test                # Run pytest
just test-cov            # Run pytest with coverage reports
just extract             # Extract PAQ archives to filesystem
just docs-build          # Build documentation site
See justfile for 50+ available commands.

Testing Tools

pytest

Primary test runner:
uv run pytest                    # Run all tests
uv run pytest tests/test_*.py    # Run specific test file
uv run pytest -k "pattern"       # Run tests matching pattern
uv run pytest --cov-report=html  # Generate HTML coverage report
See Testing Guide for detailed usage.

Syrupy (Snapshot Testing)

Captures and verifies complex data structures:
uv run pytest --snapshot-update  # Update snapshots after intentional changes

Code Quality Tools

Ruff (Linter)

Fast Python linter:
uv run ruff check .              # Check all files
uv run ruff check --fix .        # Auto-fix safe issues
uv run ruff check --fix --show-fixes .  # Show what was fixed
Configuration in pyproject.toml:
  • Line length: 120
  • Enabled rules: B007, B017, B023, B904, COM812, I001, PGH003, PT017, RUF012, RUF100, S113, S607, TRY004, UP035

ty (Type Checker)

Fast Python type checker:
uv run ty check src tests        # Check source and tests
just ty                          # Shorthand for above
just ty-tests                    # Check tests only

import-linter

Enforces architectural boundaries:
uv run lint-imports              # Validate import contracts
Contracts defined in pyproject.toml:
  • grim must not import crimson
  • Perk implementations isolated from selection logic
Structural code search and transformation:
sg scan                          # Run configured rules
sg test                          # Test ast-grep rules
sg run -p 'pattern' -r 'fix' src  # Apply transformation
For Zig code:
sg run -c sgconfig.local.yml -l zig -p '_PATTERN' -r '$FIX' crimson-zig/src

prek (Pre-commit Hooks)

Manages git hooks:
prek install -c prek.toml -t pre-commit -t pre-push  # Install hooks
prek run --stage pre-commit      # Run pre-commit checks manually
prek run --stage pre-push        # Run pre-push checks manually

Asset Tools

PAQ Archive Extraction

Extract original game archives:
just extract                     # Extract to artifacts/assets/
uv run crimson extract <src> <dst>  # Custom paths
JAZ textures are automatically converted to PNG with alpha.

Atlas Tools

Sprite atlas analysis:
just atlas-scan                  # Scan and generate usage map
just atlas-export-all            # Export all frames
just atlas-export <image> <grid> # Export specific atlas

Font Samples

Generate font rendering samples:
just font-sample                 # View font samples
uv run crimson view fonts        # Same as above

Analysis Scripts (40+)

Located in scripts/, these tools support reverse engineering and analysis.

Ghidra Tools

# Unix only
just ghidra-exe                # Analyze crimsonland.exe
just ghidra-grim               # Analyze grim.dll
just ghidra-sync               # Sync name/type maps
Scripts in analysis/ghidra/scripts/:
  • ApplyNameMap.java - Apply name mappings
  • ApplyDataMap.java - Apply data structure layouts
  • ExportAll.java - Export decompiles

Frida Tools (Windows)

Runtime instrumentation for capturing native behavior:
just frida-gameplay-state-capture    # Capture state snapshots
just frida-gameplay-diff-capture     # Differential capture
Captures go to $CRIMSON_FRIDA_DIR (default: C:\share\frida).

Frida Import/Reduce (Unix)

Import Windows captures to Unix for analysis:
just frida-copy-share            # Copy from /mnt/c/share/frida
just frida-import-raw            # Import to analysis/frida/raw/
just frida-reduce                # Generate summaries
just game-over-panel-reduce      # Reduce panel trace
just panel-state-resolution-reduce  # Reduce resolution sweep
just demo-trial-validate         # Validate trial overlay
just demo-idle-summarize         # Summarize idle threshold

Code Analysis Scripts

just entrypoint-trace            # Trace call graph from entrypoint
just function-hotspots           # Identify frequently called functions
just dat-hotspots                # Analyze data access patterns
just schema-inventory            # Inventory data schemas
just save-status                 # Analyze save file structure
just weapon-table                # Extract weapon table
just spawn-templates             # Generate spawn templates

Duplication Detection

just dup-report                  # Generate code duplication report
just dup-report out=<file> min=<lines>  # Custom output and threshold
Uses pylint with R0801 rule (duplicate-code).

Documentation Tools

Zensical (Docs Site Generator)

uv tool install zensical         # Install globally
zensical serve                   # Serve docs locally
just docs-build                  # Build static site
just docs-check                  # Validate docs structure
just docs-zensical-fix           # Auto-fix formatting issues

Documentation Validation

uv run scripts/check_docs.py     # Validate docs structure and links

Replay Tools

Replay analysis and verification:
uv run crimson replay list                   # List replay files
uv run crimson replay play <file>            # Play back replay
uv run crimson replay verify <file>          # Verify determinism
uv run crimson replay verify-checkpoints <file>  # Compare to sidecar
uv run crimson replay benchmark <file>       # Benchmark throughput
uv run crimson replay render <file>          # Render to video

Debugging Tools

WinDbg (Windows)

Debugger for native binary:
just windbg-server               # Start WinDbg server
just windbg-client               # Connect WinDbg client
just windbg-tail                 # Tail WinDbg log (Unix)
Logs saved to game directory for offline analysis.

PE Analysis (Unix)

Portable Executable metadata:
just pe-info                     # Show PE metadata
just pe-info target=grim.dll     # Analyze DLL
just pe-imports                  # Show import table
Uses rabin2 from radare2.

Zig Tools

For Zig runtime development:
just zig-build                   # Build Zig project
just zig-run                     # Run Zig binary
just zig-test                    # Run Zig tests
just zig-wasm                    # Build WebAssembly
just check-zig                   # Full Zig verification

Utility Scripts

Select utility scripts in scripts/:
ScriptPurpose
atlas_scan.pyScan sprite atlases for usage
atlas_export.pyExport atlas frames to PNG
check_docs.pyValidate documentation structure
extract_weapon_table.pyExtract weapon stats to table
gen_spawn_templates.pyGenerate creature spawn templates
entrypoint_trace.pyTrace call graph from entrypoints
function_hotspots.pyIdentify hot functions
dat_hotspots.pyAnalyze data access patterns
schema_inventory.pyInventory data structures
save_status.pyAnalyze save file structure
zensical_fix_md.pyAuto-fix Markdown formatting

Tool Installation Summary

All Python tools are installed via uv sync:
uv sync                      # Install everything
Includes:
  • pytest, ruff, ty, import-linter
  • syrupy, pytest-mock, pytest-cov
  • Frida analysis scripts (Unix)

Next Steps

Testing Guide

Learn how to run and write tests

Verification Process

Complete verification workflow

Parity Workflow

Understand parity-first development

Code Style

Follow project coding standards

Build docs developers (and LLMs) love