### Install gdsdecomp using Scoop on Windows Source: https://github.com/gdretools/gdsdecomp/blob/master/README.md This command installs the gdsdecomp tool using the Scoop package manager on Windows. It first adds the 'games' bucket to Scoop, which contains the gdsdecomp package, and then installs the package itself. Ensure Scoop is installed and configured before running these commands. ```shell scoop bucket add games scoop install gdsdecomp ``` -------------------------------- ### Run Decompilation Test Source: https://github.com/gdretools/gdsdecomp/blob/master/godot-mono-decomp/godot-mono-decomp-aot-test/README.md Example commands to run the compiled test program for decompiling a .NET assembly. It takes the assembly path and output directory as arguments, with optional reference paths. ```bash ./aot-test /path/to/your/assembly.dll ./output ./aot-test /path/to/your/assembly.dll ./output ./reference1 ./reference2 ``` -------------------------------- ### Install VTracer Python Package Source: https://github.com/gdretools/gdsdecomp/blob/master/external/vtracer/README.md This command installs the VTracer Python package using pip, the Python package installer. This makes VTracer's functionality available within Python environments, leveraging pyo3 for native extensions. Ensure Python and pip are installed. ```sh pip install vtracer ``` -------------------------------- ### Install VTracer via Cargo (Rust) Source: https://github.com/gdretools/gdsdecomp/blob/master/external/vtracer/README.md This command installs the VTracer program using the Rust package manager, Cargo. It requires a Rust toolchain to be installed on the system. This is a common method for installing Rust-based command-line tools. ```sh cargo install vtracer ``` -------------------------------- ### Basic VTracer Command-Line Usage Source: https://github.com/gdretools/gdsdecomp/blob/master/external/vtracer/README.md This is a fundamental example of using the VTracer command-line tool. It specifies an input raster image file and an output SVG vector graphics file. The tool will then process the input image and generate the vector output. ```sh ./vtracer --input input.jpg --output output.svg ``` -------------------------------- ### Glob Pattern Examples for File Inclusion/Exclusion Source: https://github.com/gdretools/gdsdecomp/blob/master/README.md This section explains how to use glob patterns for specifying files to include or exclude during project recovery. Patterns can be recursive, rooted to specific directories, or implicitly recursive. They only match files present in the project PCK/directory. ```bash - Recursive patterns can be specified with `**` - Example: `res://**/*.gdc` matches `res://main.gdc`, `res://scripts/script.gdc`, etc. - Globs should be rooted to `res://` or `user://` - Example: `res://*.gdc` will match all .gdc files in the root of the project, but not any of the subdirectories. - If not rooted, globs will be rooted to `res://` - Example: `addons/plugin/main.gdc` is equivalent to `res://addons/plugin/main.gdc` - As a special case, if the glob has a wildcard and does not contain a directory, it will be assumed to be a recursive pattern. - Example: `*.gdc` would be equivalent to `res://**/*.gdc` - Include/Exclude globs will only match files that are actually in the project PCK/dir, not any non-present resource source files. - Example: - A project contains the file `res://main.gdc`. `res://main.gd` is the source file of `res://main.gdc`, but is not included in the project PCK. - Performing project recovery with the include glob `res://main.gd` would not recover `res://main.gd`. - Performing project recovery with the include glob `res://main.gdc` would recover `res://main.gd` ``` -------------------------------- ### Convert RGBA Pixels to SVG (Python) Source: https://github.com/gdretools/gdsdecomp/blob/master/external/vtracer/vtracer/README.md This example demonstrates converting image data represented as RGBA pixel tuples into an SVG string. It utilizes the Pillow library (PIL) to open and process the image before passing the pixel data and image dimensions to VTracer's `convert_pixels_to_svg` function. ```python from PIL import Image import vtracer input_path = "/path/to/some_file.jpg" img = Image.open(input_path).convert('RGBA') pixels: list[tuple[int, int, int, int]] = list(img.getdata()) svg_str: str = vtracer.convert_pixels_to_svg(pixels, img.size) ``` -------------------------------- ### Command Line: PCK Creation with GDRE Tools Source: https://context7.com/gdretools/gdsdecomp/llms.txt Creates new PCK archives from specified project directories. Supports creating basic PCK files, PCK files with file filtering (include/exclude patterns), encrypted PCK files using a key, and embedding PCK data into an executable template. Requires the GDRE Tools executable. ```bash gdre_tools --headless \ --pck-create=./my_project \ --output=game.pck \ --pck-version=2 \ --pck-engine-version=4.3.0 gdre_tools --headless \ --pck-create=./my_project \ --output=game.pck \ --pck-version=2 \ --pck-engine-version=4.3.0 \ --include="res://**/*.gd" \ --include="res://**/*.tscn" \ --exclude="res://.import/**" gdre_tools --headless \ --pck-create=./my_project \ --output=game.pck \ --pck-version=2 \ --pck-engine-version=4.3.0 \ --key=000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F gdre_tools --headless \ --pck-create=./my_project \ --output=game_embedded.exe \ --pck-version=2 \ --pck-engine-version=4.3.0 \ --embed=godot_template.exe ``` -------------------------------- ### Convert Text Resource to Binary Source: https://context7.com/gdretools/gdsdecomp/llms.txt Converts a text-based resource file back into its binary format. This is the inverse operation of `--bin-to-txt`. The tool automatically determines the output format based on the input file. ```bash gdre_tools --headless \ --txt-to-bin=./resources/material.tres ``` -------------------------------- ### Batch Convert Resources to Text Source: https://context7.com/gdretools/gdsdecomp/llms.txt Performs a batch conversion of multiple resource files from binary to text format. It uses glob patterns to specify input files and outputs the converted text resources to a designated directory. This is efficient for converting entire directories of resources. ```bash gdre_tools --headless \ --bin-to-txt="./resources/**/*.res" \ --output=./text_resources ``` -------------------------------- ### GDScript: Convert Textures, Audio, and Binary Resources Source: https://context7.com/gdretools/gdsdecomp/llms.txt Provides functions to convert various Godot resource formats using the ImportExporter class. This includes converting textures to PNG, audio streams (oggstr, mp3str, sample) to their respective formats (ogg, mp3, wav), and binary resources to text. Errors are printed to the console if conversion fails. ```gdscript extends Node func convert_texture_to_png(texture_path: String, output_path: String) -> void: var exporter = ImportExporter.new() var err = exporter.convert_tex_to_png(texture_path, output_path, "") if err != OK: print("Conversion failed: ", err) else: print("Texture converted to: ", output_path) func convert_audio_stream(audio_path: String, output_dir: String) -> void: var exporter = ImportExporter.new() var err if audio_path.ends_with(".oggstr"): err = exporter.convert_oggstr_to_ogg(audio_path, output_dir, "") elif audio_path.ends_with(".mp3str"): err = exporter.convert_mp3str_to_mp3(audio_path, output_dir, "") elif audio_path.ends_with(".sample"): err = exporter.convert_sample_to_wav(audio_path, output_dir, "") if err != OK: print("Audio conversion failed: ", err) func convert_binary_to_text(resource_path: String, output_dir: String) -> void: var exporter = ImportExporter.new() var err = exporter.convert_res_bin_2_txt(resource_path, output_dir, "") if err != OK: print("Binary to text conversion failed: ", err) ``` -------------------------------- ### Command Line: Full Project Recovery with GDRE Tools Source: https://context7.com/gdretools/gdsdecomp/llms.txt Recovers a complete Godot project from compiled executables, PCK, or APK files. Supports encryption keys, filtering by file type, and forcing specific bytecode versions. Requires the GDRE Tools executable and the target file. ```bash gdre_tools --headless --recover=game.pck --output=./recovered_project gdre_tools --headless --recover=game.exe \ --key=000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F \ --output=./recovered_project gdre_tools --headless --recover=game.apk \ --scripts-only \ --key=000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F \ --output=./scripts_only gdre_tools --headless --recover=game.pck \ --include="res://**/*.gdc" \ --exclude="res://addons/**" \ --output=./filtered_recovery gdre_tools --headless --recover=game.pck \ --force-bytecode-version=4.3.0 \ --output=./recovered_project ``` -------------------------------- ### Standalone Project Recovery Command Source: https://github.com/gdretools/gdsdecomp/blob/master/README.md This command demonstrates how to run the gdsdecomp tool in headless mode for project recovery. It requires a compiled Godot executable and specifies the path to the standalone module and the resource to recover. ```bash $ bin/godot.linuxbsd.template_debug.x86_64.llvm --headless --path=modules/gdsdecomp/standalone --recover= ``` -------------------------------- ### Create or Modify PCK Archives using C++ API Source: https://context7.com/gdretools/gdsdecomp/llms.txt Illustrates how to create or modify PCK archives programmatically using the `PckCreator` class in C++. It covers configuring PCK parameters (version, encryption, watermark), creating a PCK from a directory with include/exclude filters, and embedding the PCK into an executable. ```cpp #include "utility/pck_creator.h" // Create new PCK Ref creator = memnew(PckCreator); // Configure PCK parameters creator->set_pack_version(2); // PCK format version (0, 1, 2) creator->set_ver_major(4); creator->set_ver_minor(3); creator->set_ver_rev(0); creator->set_encrypt(false); creator->set_watermark("MyGame v1.0"); // Create from directory with filters Vector include_filters; include_filters.push_back("res://**/*.gd"); include_filters.push_back("res://**/*.tscn"); Vector exclude_filters; exclude_filters.push_back("res://.import/**"); exclude_filters.push_back("res://temp/**"); Error err = creator->pck_create( "game.pck", // Output PCK path "./project_dir", // Source directory include_filters, // Files to include exclude_filters // Files to exclude ); if (err != OK) { print_line("PCK creation failed: " + creator->get_error_message()); return; } // Embed PCK into executable creator->set_embed(true); creator->set_exe_to_embed("godot_template.exe"); err = creator->pck_create("game_embedded.exe", "./project_dir", include_filters, exclude_filters); ``` -------------------------------- ### Compiling Godot with gdsdecomp Module Source: https://github.com/gdretools/gdsdecomp/blob/master/README.md Instructions for compiling the Godot engine from source with the gdsdecomp module. This involves cloning the repository into the modules subfolder and rebuilding Godot using scons. It also mentions the need for rustup and dotnet 9 sdk. ```bash Clone this repository into Godot's `modules` subfolder as `gdsdecomp`. Rebuild Godot engine as described in https://docs.godotengine.org/en/latest/development/compiling/index.html. You will also need [rustup](https://rustup.rs) and [dotnet 9 sdk](https://dotnet.microsoft.com/en-us/download/dotnet/9.0). ``` -------------------------------- ### Extract and Validate PCK Files using C++ API Source: https://context7.com/gdretools/gdsdecomp/llms.txt Demonstrates how to programmatically load, extract, and validate PCK archives using the `PckDumper` class in C++. It covers loading a PCK file, retrieving file information, extracting all files to a directory, and performing MD5 integrity checks. Error handling for loading and extraction is included. ```cpp #include "utility/pck_dumper.h" // Load and extract PCK Ref dumper = memnew(PckDumper); // Load PCK file Error err = dumper->load_pck("game.pck"); if (err != OK) { print_line("Failed to load PCK: " + itos(err)); return; } // Get file information PackedStringArray files = dumper->get_loaded_files(); int file_count = dumper->get_file_count(); String engine_version = dumper->get_engine_version(); print_line("Loaded " + itos(file_count) + " files"); print_line("Engine version: " + engine_version); // Extract all files to directory Vector files_to_extract; // Empty = extract all err = dumper->pck_dump_to_dir("./output", files_to_extract); if (err != OK) { print_line("Extraction failed: " + itos(err)); return; } // Verify file integrity err = dumper->check_md5_all_files(); if (err != OK) { if (dumper->had_encryption_error()) { print_line("Encryption error detected"); } print_line("MD5 check failed"); } dumper->clear_data(); ``` -------------------------------- ### Build Test Program with CMake Source: https://github.com/gdretools/gdsdecomp/blob/master/godot-mono-decomp/godot-mono-decomp-aot-test/README.md Commands to configure and build the C++ test program using CMake. It assumes the build environment is set up and the NativeAOT library is available. ```bash mkdir build cd build cmake .. make ``` -------------------------------- ### Convert Binary Scene to Text Resource Source: https://context7.com/gdretools/gdsdecomp/llms.txt Converts a binary resource file (e.g., a scene) into a human-readable text format. This is useful for inspecting or manually editing resource files. The output is directed to a specified directory. ```bash gdre_tools --headless \ --bin-to-txt=./scenes/level.scn \ --output=./scenes_text ``` -------------------------------- ### Command Line: PCK Extraction with GDRE Tools Source: https://context7.com/gdretools/gdsdecomp/llms.txt Extracts files from PCK, EXE, or APK archives without performing a full project recovery. Supports extraction using glob patterns, listing files without extraction, and handling encrypted PCK files. Requires the GDRE Tools executable and the target archive. ```bash gdre_tools --headless --extract=game.pck --output=./extracted gdre_tools --headless --extract=game.pck \ --include="res://**/*.png" \ --include="res://**/*.wav" \ --output=./assets_only gdre_tools --headless --list-files=game.pck gdre_tools --headless --extract=game.pck \ --key=000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F \ --skip-checksum-check \ --output=./extracted ``` -------------------------------- ### Patch PCK with Filtering and Encryption Source: https://context7.com/gdretools/gdsdecomp/llms.txt Enables advanced PCK patching by including filtering options (`--include`, `--exclude`) and specifying an encryption key. This allows for selective patching and securing the archive's contents. The `--key` argument requires a 32-byte key in hexadecimal format. ```bash gdre_tools --headless \ --pck-patch=original.pck \ --output=patched.pck \ --patch-file="/path/to/mod.gd=res://mods/mod.gd" \ --include="res://**" \ --exclude="res://.import/**" \ --key=000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F ``` -------------------------------- ### Combine PCK Patching with Translation Patching Source: https://context7.com/gdretools/gdsdecomp/llms.txt Integrates PCK file patching with translation file modification in a single operation. This command allows updating both game assets and translations simultaneously. It uses `--pck-patch` for general file patching and `--patch-translations` for localization updates. ```bash gdre_tools --headless \ --pck-patch=game.pck \ --output=patched_game.pck \ --patch-translations="./updated.csv=res://translations/strings.csv" ``` -------------------------------- ### Recover and Extract Textures from PCK Source: https://context7.com/gdretools/gdsdecomp/llms.txt Extracts files from a PCK archive and automatically converts textures to PNG format. The `--recover` option specifies the PCK file, `--output` indicates the extraction directory, and `--include` filters for specific file types. Textures (e.g., .stex) are automatically converted. ```bash gdre_tools --headless \ --recover=game.pck \ --output=./extracted \ --include="res://**/*.stex" ``` -------------------------------- ### Patch PCK and Embed into Executable Source: https://context7.com/gdretools/gdsdecomp/llms.txt Combines PCK patching with embedding the modified PCK into an executable file. This is useful for distributing game updates or custom builds. The `--embed` argument specifies the template executable to use. ```bash gdre_tools --headless \ --pck-patch=original.pck \ --output=patched_game.exe \ --patch-file="/path/to/fix.gd=res://scripts/bugfix.gd" \ --embed=game_template.exe ``` -------------------------------- ### Command Line: GDScript Compilation with GDRE Tools Source: https://context7.com/gdretools/gdsdecomp/llms.txt Compiles GDScript source code (.gd) files into bytecode format (.gdc). Supports compiling single files or multiple files using glob patterns. Allows specifying the target bytecode version and the commit hash for the bytecode. Requires the GDRE Tools executable. ```bash gdre_tools --headless \ --compile=./scripts/player.gd \ --bytecode=4.3.0 gdre_tools --headless \ --compile="./scripts/**/*.gd" \ --bytecode=4.3.0 \ --output=./compiled_scripts gdre_tools --headless \ --compile=./main.gd \ --bytecode=f3f05dc ``` -------------------------------- ### C++ API: Import and Export Resources Source: https://context7.com/gdretools/gdsdecomp/llms.txt This C++ snippet utilizes the ImportExporter class to convert imported resources back to their original formats during project recovery. It details loading import metadata, exporting all or specific imports, and retrieving a detailed recovery report. The report includes totals for processed, successful, and failed exports, as well as lists of decompiled and failed scripts. It also detects C# project presence. Dependencies include 'utility/import_exporter.h'. ```cpp #include "utility/import_exporter.h" // Create exporter Ref exporter = memnew(ImportExporter); // Load import metadata from project Error err = exporter->load_import_files("./extracted_project", 0); if (err != OK) { print_line("Failed to load import files"); return; } // Export all imports back to original formats Vector files_to_export; err = exporter->export_imports("./recovered_project", files_to_export); // Get detailed report Ref report = exporter->get_report(); Dictionary totals = report->get_totals(); print_line("Total files processed: " + String(totals["total"])); print_line("Successful exports: " + String(totals["success"])); print_line("Failed exports: " + String(totals["failed"])); // Get decompiled scripts Vector decompiled = report->get_decompiled_scripts(); Vector failed = report->get_failed_scripts(); // Check for special conditions if (report->is_mono_detected()) { print_line("C# project detected"); } // Print full report report->print_report(); String report_string = report->get_report_string(); ``` -------------------------------- ### GDScript API: Project Recovery Operations Source: https://context7.com/gdretools/gdsdecomp/llms.txt This GDScript code defines functions for automating project recovery. The `recover_project` function loads a PCK file, extracts its contents to a directory, and then exports imported resources back to their original formats using the ImportExporter. It provides feedback on the recovery process through a report. The `extract_scripts_only` function specifically extracts only GDScript files (.gdc and .gd) from a PCK. This snippet relies on `PckDumper` and `ImportExporter` classes. ```gdscript extends Node func recover_project(pck_path: String, output_dir: String) -> void: # Create dumper and load PCK var dumper = PckDumper.new() var err = dumper.load_pck(pck_path) if err != OK: print("Failed to load PCK: ", err) return # Extract files var files_to_extract = PackedStringArray() err = dumper.pck_dump_to_dir(output_dir, files_to_extract) if err != OK: print("Extraction failed: ", err) return # Export imports (convert resources) var exporter = ImportExporter.new() err = exporter.load_import_files(output_dir, 0) if err != OK: print("Failed to load imports: ", err) return err = exporter.export_imports(output_dir, []) if err != OK: print("Export failed: ", err) return # Get recovery report var report = exporter.get_report() var totals = report.get_totals() print("Recovery complete!") print("Files processed: ", totals["total"]) print("Successful: ", totals["success"]) print("Failed: ", totals["failed"]) # Print detailed report print(report.get_report_string()) func extract_scripts_only(pck_path: String, output_dir: String) -> void: var dumper = PckDumper.new() dumper.load_pck(pck_path) # Get all files and filter for scripts var all_files = dumper.get_loaded_files() var script_files = PackedStringArray() for file in all_files: if file.ends_with(".gdc") or file.ends_with(".gd"): script_files.append(file) dumper.pck_dump_to_dir(output_dir, script_files) ``` -------------------------------- ### Configure Native AOT Library Build with CMake Source: https://github.com/gdretools/gdsdecomp/blob/master/godot-mono-decomp/godot-mono-decomp-aot-test/CMakeLists.txt This snippet configures CMake to build a .NET NativeAOT library. It determines the library path based on the operating system and linking type (static or shared). It uses a custom command to execute 'dotnet publish' with specific build configurations. This is crucial for preparing the native library before compiling the main executable. ```cmake cmake_minimum_required(VERSION 3.16) project(godot-mono-decomp-aot-test) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) option(USE_STATIC_LINKING "Use static linking for the AOT library" OFF) set(DOTNET_RUNTIME "net9.0") if(USE_STATIC_LINKING) if(WIN32) set(AOT_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/../GodotMonoDecompNativeAOT/bin/Release/${DOTNET_RUNTIME}/osx-arm64/publish/GodotMonoDecompNativeAOT.lib") else() set(AOT_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/../GodotMonoDecompNativeAOT/bin/Release/${DOTNET_RUNTIME}/osx-arm64/publish/GodotMonoDecompNativeAOT.a") endif() else() if(WIN32) set(AOT_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/../GodotMonoDecompNativeAOT/bin/Release/${DOTNET_RUNTIME}/osx-arm64/publish/GodotMonoDecompNativeAOT.dll") elseif(APPLE) set(AOT_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/../GodotMonoDecompNativeAOT/bin/Release/${DOTNET_RUNTIME}/osx-arm64/publish/GodotMonoDecompNativeAOT.dylib") else() set(AOT_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/../GodotMonoDecompNativeAOT/bin/Release/net9.0/osx-arm64/publish/GodotMonoDecompNativeAOT.so") endif() endif() # Find the AOT library # Create executable with source files add_executable(aot-test main.cpp) if(USE_STATIC_LINKING) set(NATIVE_LIB_TYPE "Static") else() set(NATIVE_LIB_TYPE "Shared") endif() # specify that this is a custom target that builds the AOT_LIBRARY_PATH # Use add_custom_command to specify the output file add_custom_command( OUTPUT ${AOT_LIBRARY_PATH} COMMAND dotnet publish /p:NativeLib=${NATIVE_LIB_TYPE} --use-current-runtime --self-contained true -c Release WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/../GodotMonoDecompNativeAOT COMMENT "Building AOT library: ${AOT_LIBRARY_PATH}" ) # Create a custom target that depends on the custom command add_custom_target(dotnet-publish DEPENDS ${AOT_LIBRARY_PATH}) add_dependencies(aot-test dotnet-publish) # specify that dotnet-publish is the rule that builds the AOT_LIBRARY_PATH # Link with the AOT library statically target_link_libraries(aot-test ${AOT_LIBRARY_PATH}) # include include_directories(${CMAKE_SOURCE_DIR}/../GodotMonoDecompNativeAOT/include) # Set RPATH to find the library at runtime (for any remaining dynamic dependencies) set_target_properties(aot-test PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE INSTALL_RPATH "${CMAKE_SOURCE_DIR}/../GodotMonoDecompNativeAOT/bin/Release/${DOTNET_RUNTIME}/osx-arm64/publish" ) # Copy the AOT library to the build directory for testing (in case there are dynamic dependencies) add_custom_command(TARGET aot-test POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${AOT_LIBRARY_PATH} $ ) # if macos, do the relocation stuff if(APPLE) add_custom_command(TARGET aot-test POST_BUILD COMMAND install_name_tool -add_rpath @loader_path/.. $ ) endif() # Print information about the build message(STATUS "AOT Library Path: ${AOT_LIBRARY_PATH}") message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}") message(STATUS "Linking statically with NativeAOT library") ``` -------------------------------- ### Patch Multiple Files in PCK Archive Source: https://context7.com/gdretools/gdsdecomp/llms.txt Allows patching multiple files within a PCK archive simultaneously. Each file to be patched is specified using the `--patch-file` argument, mapping the local file path to its destination path inside the PCK. This is useful for applying several changes at once. ```bash gdre_tools --headless \ --pck-patch=original.pck \ --output=patched.pck \ --patch-file="/path/to/script1.gd=res://script1.gd" \ --patch-file="/path/to/scene.tscn=res://scenes/level.tscn" ``` -------------------------------- ### Command Line: GDScript Decompilation with GDRE Tools Source: https://context7.com/gdretools/gdsdecomp/llms.txt Decompiles compiled GDScript bytecode (.gdc) files into readable GDScript source code (.gd). Supports decompiling single files or multiple files using glob patterns. Allows specifying the bytecode version, using custom bytecode definitions loaded from JSON, and listing available bytecode versions. Requires the GDRE Tools executable. ```bash gdre_tools --headless \ --decompile=./scripts/player.gdc \ --bytecode=4.3.0 gdre_tools --headless \ --decompile="./scripts/**/*.gdc" \ --bytecode=f3f05dc \ --output=./decompiled_scripts gdre_tools --headless \ --decompile=./scripts/main.gdc \ --load-custom-bytecode=./custom_bytecode.json \ --output=./decompiled gdre_tools --headless --list-bytecode-versions gdre_tools --headless --dump-bytecode-versions=./bytecode_defs ``` -------------------------------- ### Convert Image to SVG (Python) Source: https://github.com/gdretools/gdsdecomp/blob/master/external/vtracer/vtracer/README.md Demonstrates basic image-to-SVG conversion using VTracer's Python binding. It shows default multicolor conversion and a faster single-color (binary) mode. Inputs are file paths for the input image and the output SVG. The function `convert_image_to_svg_py` is used. ```python import vtracer input_path = "/path/to/some_file.jpg" output_path = "/path/to/some_file.vtracer.jpg" # Minimal example: use all default values, generate a multicolor SVG vtracer.convert_image_to_svg_py(input_path, output_path) # Single-color example. Good for line art, and much faster than full color: vtracer.convert_image_to_svg_py(input_path, output_path, colormode='binary') ``` -------------------------------- ### Patch Single File in PCK Archive Source: https://context7.com/gdretools/gdsdecomp/llms.txt Modifies a single file within an existing PCK archive. This command requires the original PCK file, an output file name, and a mapping of the local file to its path within the PCK. It uses the `--headless` flag for non-interactive execution. ```bash gdre_tools --headless \ --pck-patch=original.pck \ --output=patched.pck \ --patch-file="/path/to/modified.gd=res://scripts/main.gd" ``` -------------------------------- ### gdsdecomp Command-Line Arguments Source: https://github.com/gdretools/gdsdecomp/blob/master/README.md These arguments are used to control the behavior of the gdsdecomp tool, specifying input files, output directories, and locales for translation patching. The --pck argument is mandatory for specifying the source translation PCK file. ```bash --pck= The PCK file with the source translations (if used in combination with --pck-patch, this can be omitted) --output= The output directory to save the patched translations to (optional if used in combination with --pck-patch) --locales= The locales to patch (comma-separated list, defaults to only newly-added locales) ``` -------------------------------- ### Python: Generate Bytecode Decompiler Classes Source: https://context7.com/gdretools/gdsdecomp/llms.txt A Python script that generates decompiler classes for new bytecode versions by reading version definitions from a JSON file. It iterates through defined versions, extracts commit hashes and bytecode numbers, and prints messages indicating the generation process. This script is intended to be run as `python bytecode_generator.py`. ```python #!/usr/bin/env python3 import json from pathlib import Path # Load bytecode version definitions with open('misc/bytecode_versions.json', 'r') as f: bytecode_versions = json.load(f) # Generate bytecode class files for version_info in bytecode_versions: commit_hash = version_info['commit'] bytecode_number = version_info['bytecode'] # Generate header and implementation # Files generated: bytecode/{commit_hash}.h and bytecode/{commit_hash}.cpp print(f"Generating bytecode version {bytecode_number} ({commit_hash})") # Run the generator # python bytecode_generator.py # This creates decompiler classes like: # - GDScriptDecomp_f3f05dc (for commit f3f05dc) # - GDScriptDecomp_4.3.0 (mapped from version string) ``` -------------------------------- ### C++ API: Decompile GDScript Bytecode Source: https://context7.com/gdretools/gdsdecomp/llms.txt This snippet demonstrates how to use the GDScriptDecomp class in C++ to decompile GDScript bytecode files. It covers creating a decompiler for a specific version, handling errors during decompilation, and retrieving the decompiled source code. It also shows how to decompile encrypted bytecode and list supported bytecode versions. Dependencies include the 'bytecode/bytecode_versions.h' header. ```cpp #include "bytecode/bytecode_versions.h" // Get decompiler for specific version Ref decomp = GDScriptDecomp::create_decomp_for_version("4.3.0"); if (decomp.is_null()) { print_line("Unsupported bytecode version"); return; } // Decompile file Error err = decomp->decompile_byte_code("res://scripts/player.gdc"); if (err != OK) { print_line("Decompilation failed: " + decomp->get_error_message()); return; } // Get decompiled source String source_code = decomp->get_script_text(); print_line("Decompiled script:\n" + source_code); // Decompile encrypted bytecode PackedByteArray encryption_key; encryption_key.resize(32); // ... fill key ... err = decomp->decompile_byte_code_encrypted("res://scripts/encrypted.gdc", encryption_key); // List all available bytecode versions Vector versions = GDScriptDecomp::get_bytecode_versions(); for (int i = 0; i < versions.size(); i++) { print_line("Supported version: " + versions[i]); } ``` -------------------------------- ### Patch Translations from CSV Source: https://context7.com/gdretools/gdsdecomp/llms.txt Modifies translation files within a PCK archive using a CSV file. The command maps a local CSV file containing new translations to the corresponding translation file path within the PCK. It requires the original PCK and an output path for the modified PCK. ```bash gdre_tools --headless \ --patch-translations="./new_translations.csv=res://translations/game.csv" \ --pck=game.pck \ --output=./patched_translations ``` -------------------------------- ### Advanced VTracer Conversion Options (Python) Source: https://github.com/gdretools/gdsdecomp/blob/master/external/vtracer/vtracer/README.md This snippet illustrates the extensive customization options available when converting images to SVG using VTracer's Python binding. It shows how to modify parameters like `colormode`, `hierarchical`, `mode`, and various quality/filtering settings to fine-tune the vectorization process. ```python import vtracer inp = "/path/to/input.jpg" out = "/path/to/output.svg" vtracer.convert_image_to_svg_py(inp, out, colormode = 'color', # ["color"] or "binary" hierarchical = 'stacked', # ["stacked"] or "cutout" mode = 'spline', # ["spline"] "polygon", or "none" filter_speckle = 4, # default: 4 color_precision = 6, # default: 6 layer_difference = 16, # default: 16 corner_threshold = 60, # default: 60 length_threshold = 4.0, # in [3.5, 10] default: 4.0 max_iterations = 10, # default: 10 splice_threshold = 45, # default: 45 path_precision = 3 # default: 8 ) ``` -------------------------------- ### Add VTracer as a Rust Library Dependency Source: https://github.com/gdretools/gdsdecomp/blob/master/external/vtracer/README.md This command adds the VTracer crate as a dependency to a Rust project. It uses Cargo, the Rust build system and package manager, to manage project dependencies. This allows developers to use VTracer's functionality within their Rust applications. ```sh cargo add vtracer ``` -------------------------------- ### Patch Specific Locales in Translations Source: https://context7.com/gdretools/gdsdecomp/llms.txt Allows patching translations for specific locales within a PCK archive. In addition to the translation CSV and PCK file, the `--locales` argument specifies which languages to update. This provides granular control over translation updates. ```bash gdre_tools --headless \ --patch-translations="./translations.csv=res://translations/main.csv" \ --pck=game.pck \ --output=./patched \ --locales=en,es,fr,de ``` -------------------------------- ### Convert Raw Image Bytes to SVG (Python) Source: https://github.com/gdretools/gdsdecomp/blob/master/external/vtracer/vtracer/README.md This snippet shows how to convert raw image bytes directly into an SVG string using VTracer's Python binding. This is useful when the image data is obtained from sources other than files, such as network requests. The function `convert_raw_image_to_svg` requires image bytes and the image format. ```python import vtracer input_img_bytes: bytes = get_bytes() # e.g. reading bytes from a file or a HTTP request body svg_str: str = vtracer.convert_raw_image_to_svg(input_img_bytes, img_format='jpg') ```