Skip to content

Decompiled Project Repair Cookbook

clericall edited this page Aug 13, 2026 · 1 revision

Decompiled Project Repair Cookbook

When you decompile a Unity IL2CPP game using tools like AssetRipper, the resulting project usually opens broken in the Unity Editor. Buttons and text components show as missing scripts, native plugin DLLs fail to load, and importing the full 4–50 GB asset folder takes hours or crashes the editor.

This cookbook contains practical recipes for fixing these decompiler issues using the Python and PowerShell scripts included in the tools/ directory.


Recipe 1: Fixing Broken uGUI References (remap-ugui.py)

The Problem

AssetRipper assigns one synthetic GUID per assembly (d3e719b59ab71ba3f6b398058c866280) instead of one per script file. Because Unity expects distinct GUIDs for Image, Text, Button, and CanvasScaler, every uGUI component across all your scenes shows as a missing script reference (m_Script: {fileID: ...}).

The Fix

Run remap-ugui.py against your project's Assets/ directory:

python tools/remap-ugui.py "C:\Path\To\UnityProject\Assets"

What It Does

  • Reads .unity scenes, .prefab files, and .asset files.
  • Matches each synthetic (fileID, synthetic GUID) pair against verified uGUI component signatures.
  • Rewrites the m_Script pointers to point to Unity's native uGUI package GUIDs.
  • Backs up modified files once to <file>.bak.
  • Is safe to re-run (idempotent).

Recipe 2: Repairing Native Plugin DLL Headers (fix-plugin-pe.ps1)

The Problem

AssetRipper often writes decompiled managed plugin DLLs with the IMAGE_FILE_DLL header bit cleared and the PE subsystem set to 3 (console) instead of 2 (GUI). This makes Windows DLLs look like standalone executable EXEs. Unity refuses to load them as managed assemblies, causing build errors about missing types.

The Fix

Run fix-plugin-pe.ps1 in PowerShell targeting your Unity project:

powershell -File tools/fix-plugin-pe.ps1 -ProjectPath "C:\Path\To\UnityProject"

What It Does

  • Scans Assets/ recursively for corrupt .dll files.
  • Backs up original DLLs to UnityProject-plugin-backup/.
  • Flips the IMAGE_FILE_DLL characteristic bit (0x2000).
  • Sets the PE subsystem to GUI (2).
  • Clears CLI native-entrypoint flags.
  • Prints a verification pass confirming Unity will accept the DLLs.

Recipe 3: Importing Small Scene Dependency Closures (measure-scenes.ps1 & import-group.ps1)

The Problem

A full decompiled export can be tens of gigabytes. Importing everything into Unity takes hours, fills up disk space, and imports thousands of assets you don't need for the target scenes.

The Fix

Calculate the exact dependency graph of your target scenes, and copy only the files those scenes actually reference.

Step 1: Scan GUIDs into a Map File

Scan your decompiled assets folder to generate a mapping file of guid=path:

Get-ChildItem -Path "C:\DecompiledExport\Assets" -Recurse -Filter *.meta | ForEach-Object {
    $g = (Get-Content $_.FullName | Select-String 'guid:\s*([0-9a-f]{32})').Matches.Groups[1].Value
    if ($g) { "$g=$($_.FullName -replace '\.meta$','')" }
} | Set-Content "C:\DecompiledExport\guid-map.txt"

Step 2: Calculate Scene Dependency Closures

Run measure-scenes.ps1 to calculate file lists and megabyte totals per scene:

powershell -File tools/measure-scenes.ps1 -Assets "C:\DecompiledExport\Assets" -GuidMap "C:\DecompiledExport\guid-map.txt"

Step 3: Merge Scenes into Groups

Run measure-groups.ps1 to union the scenes you plan to ship (e.g., Menu scenes):

powershell -File tools/measure-groups.ps1 -Assets "C:\DecompiledExport\Assets"

Step 4: Import Only the Measured Closure

Copy the measured group files into your clean, fresh Unity project:

powershell -File tools/import-group.ps1 -Group "A_menu" -Source "C:\DecompiledExport\Assets" -Dest "C:\CleanUnityProject\Assets" -SkipAnim

Note: -SkipAnim skips large .anim files to keep the import minimal.


Recipe 4: Local WebGL Brotli Server (serve-webgl.py)

The Problem

Unity WebGL builds output Brotli-compressed files (.wasm.br, .data.br, .framework.js.br). Running standard python -m http.server fails with browser decompression errors because Python doesn't attach Content-Encoding: br headers or correct MIME types.

The Fix

Run serve-webgl.py pointing to your WebGL build directory and a port:

python tools/serve-webgl.py "C:\Path\To\WebGLBuild" 8080

Open http://127.0.0.1:8080/ in your browser.

What It Does

  • Binds safely to 127.0.0.1.
  • Sends Content-Encoding: br for .br files.
  • Sets correct MIME types (application/wasm, application/javascript, application/octet-stream).

Recipe 5: Running Method Survival Censuses (measure-bodies.py & measure-owned.py)

To check how much compilable C# logic survived decompilation in a project:

Measure Overall Method Survival

python tools/measure-bodies.py "C:\DecompiledExport\Assets\Scripts"

Measure Game-Owned vs Third-Party Middleware Survival

python tools/measure-owned.py "C:\DecompiledExport\Assets\Scripts"

Both tools will exit with an error on bad directory paths and print clean percentages distinguishing empty/stub methods from live code.

Clone this wiki locally