Source2Gen is a tool designed to generate SDKs for Source 2 games.
Example SDKs generated with this tool can be found at neverlosecc/source2sdk.
- Extracts SDK definitions from Source 2 binaries with minimal effort
- Supports multiple Source 2 games (full list below)
- Emits C++23, C23, or IDA-compatible C headers
- Cross-platform: Windows and Linux
Launch source2gen-loader.exe
:
source2gen-loader.exe
The loader will attempt to automatically detect the game path.
To specify the game directory manually:
source2gen-loader.exe --game-path "C:\\Games\\CS2"
Additional arguments can be passed directly to source2gen via the loader, for example:
source2gen-loader.exe --game-path "C:\\Games\\CS2" --emit-language c
Run the provided wrapper script:
./scripts/run.sh "$HOME/.steam/steam/steamapps/cs2/" [options]
Generated SDKs will appear under the ./sdk
directory.
For manual or debugging use, invoke directly:
LD_LIBRARY_PATH=$HOME/.steam/steam/steamapps/cs2/game/bin/linuxsteamrt64/:$HOME/.steam/steam/steamapps/cs2/game/csgo/bin/linuxsteamrt64/ \
./build/source2gen
Note: Linux support is experimental. Expect issues, incomplete output, or errors. Contributions to improve Linux support are encouraged.
By default, the SDK contains dummy implementations for certain types, located in sdk-static
It is recommended to replace these dummy implementations with actual implementations specific to your needs.
Language | Minimum Language Standard |
---|---|
cpp |
C++23 |
c |
C23 |
c-ida |
C (single file: sdk/ida.h ) |
- In IDA, navigate to File -> Load File -> Parse C Header File...
- Select
sdk/ida.h
- Wait for compilation to complete (this may take some time)
All defined types will then be available under Local Types in IDA.
Note
The IDA support was tested on IDA Pro 9.1, all the "older" versions of IDA might not proceed the output well, feel free to open the issues in case you run into any issues though.
Some entities are omitted or replaced with dummy implementations in the generated SDK due to technical limitations:
- Overlapping fields: when multiple fields occupy the same memory location
- Misaligned fields: fields whose type alignment requirements prevent correct in-structure offset placement
- Misaligned types: class/struct types where padding would be needed beyond the original size to meet alignment rules
- Entities using C++ templates
Some of these limitations might be addressed in future versions using compiler-specific extensions.
Windows
- Visual Studio 2019 or newer (build inside the "Developer Command Prompt")
- CMake
- Conan
Linux
- g++-13 or newer
- CMake
- Conan
git clone --recurse-submodules https://github.com/neverlosecc/source2gen.git
Supported games:
CS2
(default), SBOX
, ARTIFACT2
, ARTIFACT1
, DOTA2
, UNDERLORDS
, DESKJOB
, DEADLOCK
, HL_ALYX
, THE_LAB_ROBOT_REPAIR
Example build targeting DEADLOCK:
conan build -o "game=DEADLOCK" --build=missing .
Replace DEADLOCK
with the chosen target.
Run unit tests (Linux):
LD_LIBRARY_PATH=$HOME/.steam/steam/steamapps/cs2/game/bin/linuxsteamrt64/:$HOME/.steam/steam/steamapps/cs2/game/csgo/bin/linuxsteamrt64/ \
./build/Release/bin/source2gen-test
Test whether the generated SDK compiles:
./scripts/test-cpp.sh ~/games/cs2/
Implements the codegen::IGenerator
interface, designed to be language-agnostic. Notable considerations:
- Namespaces and module information are encoded into identifiers to avoid conflicts
- Enumerator names include the enum name prefix to minimize name collisions
- Classes are emitted as
struct
in C/C++ - Uses of
struct
,union
,enum
types are prefixed with the "struct", "union", "enum" keyword respectively (seecodegen::TypeCategory
) - Static fields are omitted for C output (the only currently known use case of C is to generate IDA headers)
Implemented as a wrapper on top of the C generator:
- Sets options
--no-static-assertions
and--no-static-members
- Performs postprocessing:
- Merges all generated files into a single header (
sdk/ida.h
) - Removes system includes
- Merges all generated files into a single header (
Special thanks to project contributors:
- es3n1n
- cpz
- Cre3per (Linux support)
- Soufiw
- anarh1st47
- praydog (author of the original Source2Gen tool)
If you have contributed and are not listed here, please submit a pull request.
- Conan - C and C++ package manager
- CMake - Build system
- ValveFileVDF - VDF file parser
- argparse - C++ argument parser
- Abseil - Common C++ libraries from Google
- GoogleTest - Testing framework