using System; using UnityEngine; namespace SARD { public static class SardInitializer { public static bool IsInitialized { get; private set; } public static int InitializationResult { get; private set; } = -1; public static string InitializationError { get; private set; } [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] private static void Initialize() { Application.quitting += Finalize; TryInitialize(); } /// /// Attempt to initialize SARD. Can be called multiple times — /// if already initialized, returns true immediately. /// public static bool TryInitialize() { if (IsInitialized) return true; Debug.Log("[SARD] SardInitializer starting..."); try { string userId = "marita"; int result = SardIntegration.SardInitialize(null, null); InitializationResult = result; if (result == 0) { IsInitialized = true; InitializationError = null; Debug.Log("[SARD] Anti-Cheat initialized successfully"); try { SardIntegration.SardSetUserId(userId); Debug.Log($"[SARD] UserId set: {userId}"); } catch (EntryPointNotFoundException) { Debug.LogWarning("[SARD] sardSetUserId not available in this armour.dll version — skipping"); } return true; } else { IsInitialized = false; InitializationError = $"Initialization returned code: {result}"; Debug.LogWarning($"[SARD] {InitializationError}"); return false; } } catch (DllNotFoundException e) { IsInitialized = false; InitializationError = $"SARD DLL not found: {e.Message}"; Debug.LogError($"[SARD] {InitializationError}"); return false; } catch (EntryPointNotFoundException e) { IsInitialized = false; InitializationError = $"Entry point missing in armour.dll: {e.Message}"; Debug.LogError($"[SARD] {InitializationError}"); return false; } catch (Exception e) { IsInitialized = false; InitializationError = $"Initialization failed: {e.Message}"; Debug.LogError($"[SARD] {InitializationError}"); return false; } } /// /// Call on application quit to clean up SARD resources. /// public static void Finalize() { if (!IsInitialized) return; try { SardIntegration.SardFinalize(); Debug.Log("[SARD] Anti-Cheat finalized"); } catch (Exception e) { Debug.LogError($"[SARD] Finalization error: {e.Message}"); } } public static void Relogin(string userId, string sessionId) { if (!IsInitialized) { Debug.LogWarning("[SARD] Cannot relogin - not initialized"); return; } try { SardIntegration.SardRelogin(userId, sessionId); Debug.Log($"[SARD] Relogin completed for user: {userId}"); } catch (Exception e) { Debug.LogError($"[SARD] Relogin failed: {e.Message}"); } } public static string GetSecureSessionId() { if (!IsInitialized) { Debug.LogWarning("[SARD] Cannot get secure session - not initialized"); return null; } try { return SardIntegration.GetSecureSessionId(); } catch (Exception e) { Debug.LogError($"[SARD] GetSecureSessionId failed: {e.Message}"); return null; } } } }