Skip to content
bitsfdbPublic

About

Decompiler and compiler for Rocket League's UnrealScript bytecode

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

tauscript

tauscript is a decompiler and compiler for the UnrealScript bytecode in Rocket League's cooked packages. It turns the compiled functions and states in TAGame.upk, ProjectX.upk, Engine.upk and the other script packages into readable source, and it compiles edited source back into a working package.

Rocket League ships no .uc source files. Its scripts exist only as compiled bytecode inside encrypted, compressed .upk packages, and the engine uses its own variant of the Unreal Engine 3 token set. tauscript handles every part of that: it decrypts and decompresses the package, decodes Rocket League's opcode layout and prints UnrealScript-style source. Going the other way, it compiles that source, rebuilds the package and re-encrypts the header.

Features

  • Exact round trips. Decompiling a function and compiling the output gives back the original bytecode byte for byte. This holds for every function in every script package in the game (see Verification).
  • Self-checking decompiler. Each node in the syntax tree is compiled again as soon as it is printed. If the readable form would not reproduce the original bytes, the decompiler prints that node in an explicit fallback syntax instead, so the output always compiles back exactly.
  • Package writer. compile replaces only the functions you edit and leaves the rest of the package unchanged. Saving a package with no edits reproduces the original file byte for byte.
  • Automatic name and import tables. New name literals and references to objects in other packages are added to the package's name and import tables when you compile, and the encrypted header grows to fit them.
  • Opcode reference. docs/opcode_map.md lists all 88 expression tokens, 37 dynamic-array sub-operations, 48 primitive casts and 205 native functions, with signatures and how often each one is used in the game.

Requirements

  • Python 3.8 or later
  • The cryptography package
  • A Rocket League installation (the Epic Games or Steam version)
pip install -r requirements.txt

Locating the game files

tauscript reads packages from the game's TAGame/CookedPCConsole directory. It uses the first of these that applies:

  1. The --game PATH option
  2. The RL_COOKED environment variable
  3. The default Windows install locations:
    • C:\Program Files\Epic Games\rocketleague\TAGame\CookedPCConsole
    • C:\Program Files (x86)\Steam\steamapps\common\rocketleague\TAGame\CookedPCConsole

--game is a global option, so it goes before the command:

python tas.py --game "D:\Games\rocketleague\TAGame\CookedPCConsole" decompile Car_TA.SetLoadout

Usage

python tas.py decompile Car_TA.SetLoadout              # print one function
python tas.py decompile Car_TA -o Car_TA.tas           # every function and state in a class
python tas.py decompile --package TAGame -o out/       # a whole package, one .tas file per class
python tas.py disasm Car_TA.SetLoadout                 # raw token tree with memory and disk offsets
python tas.py compile edited.tas -o patched/           # write patched package copies to patched/
python tas.py verify TAGame [--limit N] [--detailed]   # decompile and recompile every function, compare bytes
python tas.py opcodes -o docs/                         # regenerate opcode_map.md and opcode_map.json

Function and class names are not case-sensitive. A path is Class.Function, Class.State, Class.State.Function, or a bare class name to select every function and state in that class.

Editing a function

  1. Decompile the function, or a whole class, to a .tas file:

    python tas.py decompile Car_TA.SetLoadout -o SetLoadout.tas
    
    // final simulated SetLoadout(out ClientLoadoutData Data)
    // flags=0x420103 mem=242 disk=186
    function Car_TA.SetLoadout
    {
        LogInternal(((((((string(self) @ string(GetFuncName())) @ "bLoadoutSet=(") $ string(bLoadoutSet)) $ ")") @ "string(Data)=(") $ string(Data)) $ ")", 'JoinMatch', _);
        bLoadoutSet = true;
        Loadout.__EventAssetLoaded__Delegate += #InstanceDelegate('HandleAssetLoaded');
        Loadout.__EventAllAssetsLoaded__Delegate += #InstanceDelegate('HandleAllAssetsLoaded');
        rv(Loadout.LoadClientLoadout(Data));
        return;
    }
    
  2. Edit the body. The comment lines above function describe the original declaration and are ignored by the compiler. Control flow is written with labels and goto, as the decompiler prints it, and you can use any identifier as a label name.

  3. Compile it into a separate output directory:

    python tas.py compile SetLoadout.tas -o patched/
    

    The compiler writes a complete copy of each package that contains an edited function (here patched/TAGame.upk). It will not write into the game directory. Back up the original package, then copy the new one into place yourself.

A .tas file can contain any number of function Class.Name { ... } and state Class.Name { ... } blocks, from any number of packages. Only the functions and states in the file are replaced.

The .tas language

The decompiler prints UnrealScript-style source with a few additions. These additions are needed to describe bytecode exactly, because the bytecode holds details that ordinary UnrealScript source does not.

Construct Syntax
Statements x = y; return e; return; return implicit; stop; goto L_0040; ifnot (cond) goto L_0040; L_0040:
Iteration foreach Expr until L_0040; iternext; iterpop;
Switch cases case (expr) next L_0040; case default; (the switch itself is written in fallback form)
Default values of optional parameters defaultparm(expr);, one per optional parameter, at the top of the function
Variables Local, Member, default.Member
Member access obj.Field, obj.Func(a, b), obj?.Field (Rocket League's context flag), obj.@Pkg.Class.Field (explicit property)
Arrays arr[i], arr.Length, and other operations as #DynArray.AddItem(arr, _, [item]) and similar
Calls Func(a, _, c) (_ skips an optional argument), virtual Func(), global.Func(), @Class.Func(args) (explicit final call)
Operators Infix, prefix and postfix operators, with overloads resolved from operand types: a + b, !x, i++, s $ t, a && b
Casts int(x) float(x) string(x) byte(x) bool(x) name(x) vector(x) rotator(x) qword(x) sqword(x), and class casts such as Car_TA(x)
Literals 5, 5b (byte), 5i (forced 32-bit int), 5q and -5s (qword, sqword), 1.5, asfloat(0x7fc00000), "str", u"wide", 'Name', 'Name'#3, vect(x, y, z), rot(p, y, r), true, None, self
Object references Class'Path.To.Object' or @Path.To.Object (@#123 is a raw package index)
Events Obj.__EventX__Delegate += Handler; and -= Handler;
Conditional (c) ? a : b
Rvalue wrapper Rocket League wraps some reads through an object in an extra token. The compiler adds it where the game does. rv(x) forces it and raw(x) suppresses it
Fallback form #TokenName(operands...) for any token, with operands in the layout defined in opcodes.py, and #Native<index>(args...) for any native function

Fallback form

When the readable form of a node would not compile back to identical bytes, the decompiler prints that node as #TokenName(...). This form maps one to one onto the bytecode and always round-trips. Depending on the package, between about 1% and 9% of nodes are printed this way (see the table below). You can edit fallback nodes like any other code or replace them with readable code.

Names and imports

  • A name literal ('Foo') or call name that is not in the package's name table is appended to it.
  • A reference to an object in another package that this package does not import yet gets an import entry. Existing package, class and outer entries are reused. For example, calling GetPhysicsName() from TAGame adds only the Engine.Actor.GetPhysicsName entry.

Documentation

Document Contents
docs/package-format.md Package layout: summary, encryption, compressed chunks, name, import and export tables, function exports, and how packages are written
docs/bytecode.md Bytecode format and how Rocket League's differs from stock Unreal Engine 3
docs/decompiler.md How the decompiler works
docs/compiler.md How the compiler works
docs/opcode_map.md Every token, dynamic-array operation, primitive cast and native function, with usage counts

Decryption keys

Rocket League encrypts part of each package header with AES-256. The key is in keys.py:

PACKAGE_KEY = c7df6b13252acc7147bb51c98ad7e34b7fe500b77fa5fab293e2f24e6b17e779
Property Value
Cipher AES-256, ECB mode, no padding
Encrypted region From NameOffset in the package summary to the start of the trailing garbage block, rounded up to a multiple of 16 bytes
Contents The name, import and export tables and the compressed chunk table
Packages Every script package (Core, Engine, GFxUI, AkAudio, IpDrv, OnlineSubsystemEOS, OnlineSubsystemSteamworks, ProjectX, TAGame)

The package data that follows the header is split into zlib-compressed chunks. These are not encrypted. Their locations are listed in the chunk table inside the encrypted header.

How packages are written

When compile saves a package:

  • An edited function that fits in its original slot is written in place. A larger one is appended to the end of the package data, and its export entry is updated to point to the new location.
  • Only the compressed chunks that contain changed data are recompressed. All other chunks are copied unchanged.
  • When names or imports are added, the header grows to fit them. The writer updates the name and import counts, the table offsets, the last generation entry, the serial offset of every export, the chunk table and TotalHeaderSize. The trailing garbage block keeps its size.
  • The header is encrypted again with the same key.

Limitations

  • The compiler cannot add new properties, local variables or parameters. Edited code can only use variables that the function or its class already declares.
  • Only functions and states with bytecode can be edited. Class default properties and other non-script data are not decompiled.
  • tauscript is tested against the current PC build of Rocket League. A game update that changes the package format or the opcode table may require changes to tauscript.

Verification

verify decompiles every function in a package, compiles the output again and compares the result with the original bytecode and its in-memory size. By default it prints only mismatches and a summary. --detailed prints one line per function as it is checked, with its node count, how many nodes were printed in fallback form and its size on disk. The current results, also recorded in docs/verify_results.txt:

Package Byte-exact functions Nodes in fallback form
Core 581 / 581 1.5%
Engine 4,795 / 4,795 5.5%
GFxUI 179 / 179 0.6%
AkAudio 101 / 101 3.6%
IpDrv 853 / 853 6.3%
OnlineSubsystemEOS 523 / 523 7.3%
OnlineSubsystemSteamworks 528 / 528 9.2%
ProjectX 4,185 / 4,185 7.7%
TAGame 17,780 / 17,780 9.0%
Total 29,525 / 29,525

After a game update

Most game updates leave the script packages unchanged or change only a few functions. After an update:

  1. Run python tas.py verify <Package> for each script package. If every function still round-trips, tauscript fully supports the new build.
  2. Run python tas.py opcodes -o docs/ and compare the new opcode map with the old one. Any new or changed token shows up there.
  3. Recompile your .tas files against the updated game. Decompile each function you replace again and compare it with the version your edit was based on, so you don't overwrite changes Psyonix made to it.

Project layout

File Purpose
tas.py Command-line interface
keys.py Package decryption key
upk.py Package reader and writer: header encryption, zlib chunks, name, import and export tables
opcodes.py Token and dynamic-array operation layouts for Rocket League's bytecode
bytecode.py Exact bytecode decoder and encoder
model.py Symbol model across packages: classes, properties and their types, functions, native functions
lexer.py Tokenizer for .tas source
compiler.py Parser, scope and type resolution, and assembler with automatic jump offsets and labels
decompiler.py Self-checking source printer
patcher.py Compiles .tas files into export data and writes packages
opmap.py Opcode map generator
docs/ Opcode map and verification results

Disclaimer

tauscript is an independent project. It is not affiliated with, endorsed by or supported by Psyonix or Epic Games. Rocket League and its game files are the property of their respective owners. This repository contains no game files, and tauscript reads them only from your own installation. Modifying game files may break the game or violate its terms of service. Back up any files you change.

About

Decompiler and compiler for Rocket League's UnrealScript bytecode

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages