Appearance
Unity Integration
This guide describes how to integrate SARD Anti-Cheat into Unity games using the official C# wrapper.
Overview
SARD provides a secure client-side runtime that integrates seamlessly with Unity games via P/Invoke.
- Compatible with Mono and IL2CPP
- Windows x64 builds
- Automatic lifecycle management
- Secure session tokens for server validation
Downloads
Download the required files from the SARD CDN:
| File | Description |
|---|---|
SardIntegration.cs | C# P/Invoke wrapper |
SardInitializer.cs | Auto-initialization script |
armour.dll | Native dll (64-bit) |
SARDUpdater.exe | SARD Updater |
Folder Structure
Unity Project (Development)
Assets/
├── Plugins/
│ └── x86_64/
│ └── armour.dll
└── SARD/
├── SardIntegration.cs
└── SardInitializer.csBuilt Game (Production)
<GameFolder>/
├── YourGame.exe
├── YourGame_Data/
│ └── Plugins/
│ └── x86_64/
│ └── armour.dll
└── SARD/
└── SARDUpdater.exeInstallation
1. Create Folders
In your Unity project:
- Create
Assets/SARD/ - Create
Assets/Plugins/x86_64/
2. Add Files
| File | Location |
|---|---|
SardIntegration.cs | Assets/SARD/ |
SardInitializer.cs | Assets/SARD/ |
armour.dll | Assets/Plugins/x86_64/ |
Unity automatically includes DLLs from Assets/Plugins/x86_64/ in Windows x64 builds.
3. Build Your Game
Build normally from Unity (File > Build Settings > Build).
4. Add SARDUpdater
After building:
- Create a
SARDfolder next to your game executable - Place
SARDUpdater.exein the SARD folder
Initialization
SARD initializes automatically before any scene loads via SardInitializer.cs. Download the file from the SARD CDN and add it to your project - no manual initialization required.
The initializer:
- Runs before
Awake()orStart()via[RuntimeInitializeOnLoadMethod] - Sets the user ID using
SystemInfo.deviceUniqueIdentifier - Automatically finalizes on application quit
Checking Initialization Status
csharp
// Check if SARD initialized successfully
if (SardInitializer.IsInitialized)
{
Debug.Log("SARD is active");
}
else
{
Debug.LogError($"SARD failed: {SardInitializer.InitializationError}");
}
// Get the initialization return code
int code = SardInitializer.InitializationResult;Launching the Game
Players must launch the game through SARDUpdater:
powershell
cd <GameFolder>\SARD
.\SARDUpdater.exe -sardKey <YOUR-SARD-KEY> -sardGame "..\YourGame.exe"SARDUpdater handles:
- Runtime updates
- Driver installation
- Game launch with protection enabled
API Reference
SardIntegration (P/Invoke Wrapper)
SardInitialize
csharp
int result = SardIntegration.SardInitialize(armourPath, sessionId);Initializes the anti-cheat runtime. Called automatically by SardInitializer.cs.
| Parameter | Description |
|---|---|
armourPath | Path to armour.dll (or null for auto-detect) |
sessionId | Initial session ID (or null) |
SardFinalize
csharp
SardIntegration.SardFinalize();Shuts down the runtime. Called automatically on application quit.
SardSetUserId
csharp
SardIntegration.SardSetUserId(userId);Sets the player identifier. Call after successful initialization.
SardSetSessionId
csharp
SardIntegration.SardSetSessionId(sessionId);Updates the current session ID without changing user identity.
SardRelogin
csharp
SardIntegration.SardRelogin(userId, sessionId);Updates both player identity and session after account switch.
GetSecureSessionId
csharp
string secureSession = SardIntegration.GetSecureSessionId();Returns a cryptographically signed session token for server-side validation. Use this in HTTP headers to verify requests come from a protected client.
SardInitializer (High-Level API)
Properties
| Property | Type | Description |
|---|---|---|
IsInitialized | bool | true if SARD started successfully |
InitializationResult | int | Return code from SardInitialize() |
InitializationError | string | Error message if initialization failed |
Relogin
csharp
SardInitializer.Relogin(userId, sessionId);Safe wrapper for SardRelogin with null-checks and error handling.
GetSecureSessionId
csharp
string token = SardInitializer.GetSecureSessionId();Safe wrapper that returns null if SARD is not initialized.
Server Integration
Validating Requests
Attach the secure session to outgoing HTTP requests:
csharp
string sardSession = SardInitializer.GetSecureSessionId();
if (!string.IsNullOrEmpty(sardSession))
{
request.SetRequestHeader("X-SARD-Session", sardSession);
}Your server can validate this token with the SARD backend to ensure:
- The request comes from a protected game client
- The client has not been tampered with
- The session is currently valid
Return Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Runtime failed to load |
| 2 | Export not found |
| <0 | Internal error |
Integration Checklist
Development
- Add
SardIntegration.cstoAssets/SARD/ - Add
SardInitializer.cstoAssets/SARD/ - Add
armour.dlltoAssets/Plugins/x86_64/ - Test in editor (check console for
[SARD]logs) - Verify
SardInitializer.IsInitializedreturns expected value
Production
- Build game from Unity
- Create
SARD/folder next to game executable - Add
SARDUpdater.exetoSARD/folder - Test launch via SARDUpdater
- Verify secure session tokens are being sent to server
Troubleshooting
"SARD DLL not found"
- Ensure
armour.dllis inAssets/Plugins/x86_64/ - For built games, check
<GameName>_Data/Plugins/x86_64/
Initialization returns code 1
- The runtime failed to load. Ensure you're launching via SARDUpdater.
Initialization returns code 2
- Export not found. You may have an outdated
armour.dll.
GetSecureSessionId returns null
- Check
SardInitializer.IsInitializedfirst - Ensure the game was launched via SARDUpdater
Support
For integration assistance, contact SARD support.
