Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ jobs:
- name: Build release
run: |
. $HOME/.cargo/env
cargo build --release
cargo build -p s2binlib_binding --release

- name: Upload Linux artifact
uses: actions/upload-artifact@v4
with:
name: s2binlib-linux-x86_64
path: target/release/libs2binlib.a
path: |
target/release/libs2binlib.so
target/release/libs2binlib.a

build-windows:
name: Build Windows
Expand All @@ -50,14 +52,16 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: Build release
run: cargo build --release
run: cargo build -p s2binlib_binding --release

- name: Upload Windows artifacts
uses: actions/upload-artifact@v4
with:
name: s2binlib-windows-x86_64
path: |
target/release/s2binlib.dll
target/release/s2binlib.lib
target/release/s2binlib.pdb

create-release-package:
name: Create Release Package
Expand Down Expand Up @@ -100,8 +104,12 @@ jobs:
mkdir -p release/windows
mkdir -p release/include
cp artifacts/s2binlib-linux-x86_64/libs2binlib.a release/linux/
cp artifacts/s2binlib-linux-x86_64/libs2binlib.so release/linux/
cp artifacts/s2binlib-windows-x86_64/s2binlib.lib release/windows/
cp s2binlib.h release/include/
cp artifacts/s2binlib-windows-x86_64/s2binlib.dll release/windows/
cp artifacts/s2binlib-windows-x86_64/s2binlib.pdb release/windows/
cp headers/s2binlib001.h release/include/
cp headers/s2binlib_static.h release/include/

- name: Create release archives
run: |
Expand Down Expand Up @@ -142,7 +150,8 @@ jobs:
s2binlib-${{ steps.gitversion.outputs.semVer }}-linux-x86_64.tar.gz
s2binlib-${{ steps.gitversion.outputs.semVer }}-windows-x86_64.tar.gz
s2binlib-${{ steps.gitversion.outputs.semVer }}-all-platforms.tar.gz
s2binlib.h
headers/s2binlib001.h
headers/s2binlib_static.h
draft: false
prerelease: false
env:
Expand Down
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 58 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,79 @@ This is useful for debugging integration issues with the C API.

On windows, if you are seeing linking error like `"__imp_NtReadFile"`, you also need to link `kernel32.dll` and `ntdll.dll`.

## Example
## C API

Example code:
S2BinLib provides two C API styles:

```cpp
### 1. Global Singleton API (Recommended for simple use cases, static linking)

The global singleton API (`s2binlib.h`) provides a thread-safe, easy-to-use interface with all functions prefixed with `s2binlib_`:

```c
#include <s2binlib.h>

int main() {

// Initialize the lib, the game type is csgo for cs2
// Initialize the global instance (game type is "csgo" for CS2)
s2binlib_initialize("/home/csgo/cs2server/game", "csgo");

// If you are using metamod, relocate these modules because its modified
// If you are using metamod, relocate these modules because they're modified
GET_V_IFACE_ANY(GetServerFactory, g_pSource2Server, ISource2Server, SOURCE2SERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pEngineServer2, IVEngineServer2, SOURCE2ENGINETOSERVER_INTERFACE_VERSION);
s2binlib_set_module_base_from_pointer("server", g_pSource2Server);
s2binlib_set_module_base_from_pointer("engine2", g_pEngineServer2);

// pattern scan
// Pattern scan
void* result;
s2binlib_pattern_scan("server", "01 02 03 AA BB CC ? ? DD", &result);

// free after use, this will only release the file bytes in memory, dumped xref and other information will still be cached
// Find a vtable
void* vtable_addr;
s2binlib_find_vtable("server", "CBaseEntity", &vtable_addr);

// Free after use, this will only release the file bytes in memory
// Dumped xref and other information will still be cached
s2binlib_unload_all_binaries();

// Clean up the global instance
s2binlib_destroy();
}
```

**Features:**
- Thread-safe global singleton
- Simple API with no manual instance management
- All functions use snake_case naming with `s2binlib_` prefix
- Return values: 0 for success, negative for errors (-1: not initialized, -2: invalid parameter, -3: operation failed, -4: not found, -99: mutex error)

### 2. Object-Oriented API (For version control)

The object-oriented API (`s2binlib001.h`) allows multiple instances with explicit lifecycle control:

```cpp
#include <s2binlib001.h>

int main() {
// Create instance manually
void* s2binlib_ptr = s2binlib001_create();
S2BinLib001* s2binlib = (S2BinLib001*)s2binlib_ptr;

// Initialize through vtable
s2binlib->Initialize("/home/csgo/cs2server/game", "csgo");

// Use vtable methods
void* result;
s2binlib->PatternScan("server", "01 02 03 AA BB CC ? ? DD", &result);

// Destroy instance
s2binlib->Destroy();
}
```

### 3. Dynamic Loading
Or use the `CreateInterface` function for dynamic loading:

```cpp
// windows example
S2CreateInterfaceFn createInterface = (S2CreateInterfaceFn)GetProcAddress(hDll, "S2BinLib_CreateInterface");
auto s2binlib = createInterface(S2BINLIB_INTERFACE_NAME);
```
54 changes: 27 additions & 27 deletions dump/linux/networkvars.txt
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
CAttributeContainer::NetworkVar_m_Item [31]
StateChanged: [ 28 -> 157FF80 ]
StateChanged: [ 28 -> 157FF00 ]
CBaseAnimGraph::NetworkVar_m_RagdollPose [4]
StateChanged: [ 1 -> 114E660 ]
StateChanged: [ 1 -> 114E5E0 ]
CBaseAnimGraphController::NetworkVar_m_animGraphNetworkedVars [63]
StateChanged: [ 60 -> 112B140 ]
StateChanged: [ 60 -> 112B0C0 ]
CBaseModelEntity::NetworkVar_m_Collision [4]
StateChanged: [ 1 -> 114E8E0 ]
StateChanged: [ 1 -> 114E860 ]
CBaseModelEntity::NetworkVar_m_Glow [4]
StateChanged: [ 1 -> 114E7A0 ]
StateChanged: [ 1 -> 114E720 ]
CBasePlayerPawn::NetworkVar_m_skybox3d [4]
StateChanged: [ 1 -> 1313740 ]
StateChanged: [ 1 -> 13136C0 ]
CBodyComponentBaseAnimGraph::NetworkVar_m_animationController [35]
StateChanged: [ 28 -> 112D240 ]
StateChanged: [ 28 -> 112D1C0 ]
CBodyComponentPoint::NetworkVar_m_sceneNode [29]
StateChanged: [ 26 -> 940820 ]
CBodyComponentSkeletonInstance::NetworkVar_m_skeletonInstance [30]
StateChanged: [ 26 -> 9407E0 ]
CC4::NetworkVar_m_entitySpottedState [4]
StateChanged: [ 1 -> 1038860 ]
StateChanged: [ 1 -> 10387E0 ]
CCSGO_TeamPreviewCharacterPosition::NetworkVar_m_agentItem [31]
StateChanged: [ 28 -> FDC6C0 ]
StateChanged: [ 28 -> FDC640 ]
CCSGO_TeamPreviewCharacterPosition::NetworkVar_m_glovesItem [31]
StateChanged: [ 28 -> FDC580 ]
StateChanged: [ 28 -> FDC500 ]
CCSGO_TeamPreviewCharacterPosition::NetworkVar_m_weaponItem [31]
StateChanged: [ 28 -> FDC440 ]
StateChanged: [ 28 -> FDC3C0 ]
CCSGameRules::NetworkVar_m_RetakeRules [7]
StateChanged: [ 4 -> F3CBC0 ]
CCSPlayerController_ActionTrackingServices::NetworkVar_m_matchStats [5]
StateChanged: [ 1 -> 10F85C0 ]
StateChanged: [ 1 -> 10F8540 ]
CCSPlayerPawn::NetworkVar_m_EconGloves [31]
StateChanged: [ 28 -> 9B8A00 ]
CCSPlayerPawn::NetworkVar_m_entitySpottedState [4]
StateChanged: [ 1 -> 9B88C0 ]
CCSPlayer_ActionTrackingServices::NetworkVar_m_weaponPurchasesThisMatch [4]
StateChanged: [ 1 -> 1074AA0 ]
StateChanged: [ 1 -> 1074A20 ]
CCSPlayer_ActionTrackingServices::NetworkVar_m_weaponPurchasesThisRound [4]
StateChanged: [ 1 -> 1074A40 ]
StateChanged: [ 1 -> 10749C0 ]
CChicken::NetworkVar_m_AttributeManager [10]
StateChanged: [ 2 -> AEA1E0 ]
CCollisionProperty::NetworkVar_m_collisionAttribute [4]
StateChanged: [ 1 -> 1338680 ]
StateChanged: [ 1 -> 1338600 ]
CEconEntity::NetworkVar_m_AttributeManager [10]
StateChanged: [ 2 -> 15939A0 ]
StateChanged: [ 2 -> 1593920 ]
CEconItemView::NetworkVar_m_AttributeList [4]
StateChanged: [ 1 -> 15E4FE0 ]
StateChanged: [ 1 -> 15E4FA0 ]
CEconItemView::NetworkVar_m_NetworkedDynamicAttributes [4]
StateChanged: [ 1 -> 15E5080 ]
StateChanged: [ 1 -> 15E5040 ]
CEnvWind::NetworkVar_m_EnvWindShared [4]
StateChanged: [ 1 -> 135D780 ]
StateChanged: [ 1 -> 135D700 ]
CEnvWindController::NetworkVar_m_EnvWindShared [4]
StateChanged: [ 1 -> B7D040 ]
CFogController::NetworkVar_m_fog [4]
StateChanged: [ 1 -> B95400 ]
CGameSceneNode::NetworkVar_m_hParent [4]
StateChanged: [ 1 -> 11F0740 ]
StateChanged: [ 1 -> 11F06C0 ]
CHostage::NetworkVar_m_entitySpottedState [4]
StateChanged: [ 1 -> AFE8A0 ]
CHostage::NetworkVar_m_reuseTimer [4]
StateChanged: [ 1 -> AFE760 ]
CPlantedC4::NetworkVar_m_AttributeManager [10]
StateChanged: [ 2 -> 1038AE0 ]
StateChanged: [ 2 -> 1038A60 ]
CPlantedC4::NetworkVar_m_entitySpottedState [4]
StateChanged: [ 1 -> 10389A0 ]
StateChanged: [ 1 -> 1038920 ]
CPlayer_CameraServices::NetworkVar_m_PlayerFog [4]
StateChanged: [ 1 -> 1267980 ]
StateChanged: [ 1 -> 1267900 ]
CPlayer_CameraServices::NetworkVar_m_audio [4]
StateChanged: [ 1 -> 12679C0 ]
StateChanged: [ 1 -> 1267940 ]
CShatterGlassShardPhysics::NetworkVar_m_ShardDesc [5]
StateChanged: [ 1 -> BC8100 ]
CSkeletonInstance::NetworkVar_m_modelState [4]
StateChanged: [ 0 -> 129BA40 ]
StateChanged: [ 0 -> 129B9C0 ]
CSkyCamera::NetworkVar_m_skyboxData [4]
StateChanged: [ 1 -> 15025E0 ]
StateChanged: [ 1 -> 1502560 ]
CTriggerFan::NetworkVar_m_RampTimer [4]
StateChanged: [ 1 -> BB0820 ]
sky3dparams_t::NetworkVar_fog [4]
StateChanged: [ 1 -> 12E8D20 ]
StateChanged: [ 1 -> 12E8CA0 ]
6 changes: 3 additions & 3 deletions dump/linux/strings/client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ $hRh
--FD-
-0123456789
-2&Z
-4e6
-4p6
-5X5
-;-C-I-M-a-e-q-
-<nre!
Expand Down Expand Up @@ -5665,7 +5665,7 @@ JD<t
JM0L
JPQv
JS_!0
JY3H
JY3S
JZIX
J_R=I)
J`KL
Expand Down Expand Up @@ -9295,7 +9295,7 @@ kw.6#
k~Rz
l :%
l!;b
l&+3kH
l&+3vH
l&: q
l&rB6
l4Ot
Expand Down
2 changes: 1 addition & 1 deletion dump/linux/strings/engine2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,6 @@ $p?b
?Tf,
?Y?"/
?]"#A~
?`Q#
?q?4
?rJRTS\Rg>`H`CeIkHq7v4}4v4u7
?t)A
Expand All @@ -1512,6 +1511,7 @@ $p?b
@+8b
@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@/home/saml/dev/steam/thirdpartycode/nonredist/libyuv/libyuv/source/scale_uv.cc
@@XR(
@i-kuX
@l?O#m?
A!;I2
Expand Down
Loading