Skip to content

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:

FileDescription
SardIntegration.csC# P/Invoke wrapper
SardInitializer.csAuto-initialization script
armour.dllNative dll (64-bit)
SARDUpdater.exeSARD Updater

Folder Structure

Unity Project (Development)

Assets/
├── Plugins/
│   └── x86_64/
│       └── armour.dll
└── SARD/
    ├── SardIntegration.cs
    └── SardInitializer.cs

Built Game (Production)

<GameFolder>/
├── YourGame.exe
├── YourGame_Data/
│   └── Plugins/
│       └── x86_64/
│           └── armour.dll
└── SARD/
    └── SARDUpdater.exe

Installation

1. Create Folders

In your Unity project:

  • Create Assets/SARD/
  • Create Assets/Plugins/x86_64/

2. Add Files

FileLocation
SardIntegration.csAssets/SARD/
SardInitializer.csAssets/SARD/
armour.dllAssets/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:

  1. Create a SARD folder next to your game executable
  2. Place SARDUpdater.exe in 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() or Start() 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.

ParameterDescription
armourPathPath to armour.dll (or null for auto-detect)
sessionIdInitial 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

PropertyTypeDescription
IsInitializedbooltrue if SARD started successfully
InitializationResultintReturn code from SardInitialize()
InitializationErrorstringError 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

CodeMeaning
0Success
1Runtime failed to load
2Export not found
<0Internal error

Integration Checklist

Development

  • Add SardIntegration.cs to Assets/SARD/
  • Add SardInitializer.cs to Assets/SARD/
  • Add armour.dll to Assets/Plugins/x86_64/
  • Test in editor (check console for [SARD] logs)
  • Verify SardInitializer.IsInitialized returns expected value

Production

  • Build game from Unity
  • Create SARD/ folder next to game executable
  • Add SARDUpdater.exe to SARD/ folder
  • Test launch via SARDUpdater
  • Verify secure session tokens are being sent to server

Troubleshooting

"SARD DLL not found"

  • Ensure armour.dll is in Assets/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.IsInitialized first
  • Ensure the game was launched via SARDUpdater

Support

For integration assistance, contact SARD support.