OZero Security
API 参考

API 参考

OZeroSecurity SDK 中所有公共类和方法的完整参考。除非另有说明,所有类都位于 OZeroSDK.Security 命名空间中。

OZeroSecurityManager OZeroSDK.Security

管理所有活动安全模块和安全事件的全局管理器。即使场景切换它也会保持存在,并且可以通过 Instance 属性进行访问。SDK 会在应用启动时自动创建,因此您无需直接进行实例化。

特性

姓名 类型 解释
Instance OZeroSecurityManager 静态单例访问器。返回活动实例。

方法

void RegisterUserCallback(DelegateSecurityViolation callback)

当项目代码需要接收安全事件时注册回调。OZero 的内置响应会在独立流程中继续执行,因此注册或移除这个回调不会关闭 SDK 的保护行为。回调会收到 OZeroSecurityEvent,其中包含检测区域、公共中止代码、消息键、诊断消息以及应用是否即将关闭。

void UnregisterUserCallback(DelegateSecurityViolation callback)

删除先前注册的用户回调。请务必从 OnDisableOnDestroy 调用它,以避免内存泄漏。

void RegisterUserPolicyActionCallback(Action<OZeroPolicyActionEvent> callback)

Registers a callback for server-issued policy actions delivered by the Pro device policy heartbeat. Use this for portal policies such as Callback responses. It is separate from local security detection callbacks.

void UnregisterUserPolicyActionCallback(Action<OZeroPolicyActionEvent> callback)

Removes a previously registered policy action callback. Register in OnEnable and unregister in OnDisable when using a scene object.

void RegisterUserActivationStateCallback(Action<OZeroUserActivationStateEvent> callback)

注册用于接收面向用户的 activation 或 DRM 状态变化的回调。使用 OZero-managed Steam DRM 和默认 Managed Verification UI 时,SDK 已经显示需要联网、重试、timeout 和阻止状态;只有自定义 UI、telemetry 或游戏专用 session gate 需要时才注册。

void UnregisterUserActivationStateCallback(Action<OZeroUserActivationStateEvent> callback)

移除先前注册的 activation 状态回调。在场景对象中使用时,请在 OnEnable 注册并在 OnDisable 解除。

void RegisterUserManagedVerificationStateCallback(Action<OZeroUserManagedVerificationStateEvent> callback)

Registers a callback for the shared OZero Managed Verification state used by Pro Build Integrity and Steam DRM. The default SDK UI handles these states automatically when enabled; use this callback only for custom UI, custom telemetry, or game-specific session gates.

void UnregisterUserManagedVerificationStateCallback(Action<OZeroUserManagedVerificationStateEvent> callback)

Removes a previously registered managed verification state callback. Register in OnEnable and unregister in OnDisable when using a scene object.

void RegisterUserManagedVerificationTextProvider(IOZeroUserManagedVerificationTextProvider provider)

Replaces individual built-in verification UI strings at runtime. Use JSON files under Assets/OZeroSDK/Resources/OZeroLocalization for normal localization, and use this provider only when text must be supplied dynamically.

void UnregisterUserManagedVerificationTextProvider(IOZeroUserManagedVerificationTextProvider provider)

Removes a previously registered managed verification text provider.

bool RequestBuildAttestationRetry()

Retries SDK-managed Build Integrity attestation after an online-required or retry-timeout state. The default Managed Verification UI calls this automatically. If your own game server validates OZA tokens, retry your own login or session-refresh request instead.

bool RequestSteamActivationRetry()

重试由 OZero 服务器托管的 Steam Activation / DRM 验证。默认 Managed Verification UI 会在 SDK 内部调用匹配的 retry 流程。只有在有意替换默认 UI 的自定义 UI 中才从游戏代码调用它;如果由你的游戏服务器执行 Steam 验证,请改为重试你自己的登录或会话请求。

代表

delegate void DelegateSecurityViolation(OZeroSecurityEvent evt)

这是 RegisterUserCallback 使用的回调签名。当需要警告 UI、自有服务器日志或短保存步骤时,请查看 evt.Typeevt.AbortCodeHexevt.MessageKeyevt.Messageevt.WillAbort。如果 evt.WillAbort 为 true,应用已经计划关闭,请避免耗时操作。

例子

using OZeroSDK.Security;
using UnityEngine;

public class MySecurityListener : MonoBehaviour
{
    void OnEnable()
        => OZeroSecurityManager.Instance.RegisterUserCallback(OnThreat);

    void OnDisable()
        => OZeroSecurityManager.Instance.UnregisterUserCallback(OnThreat);

    void OnThreat(OZeroSecurityEvent evt)
        => Debug.Log(
            $"Threat={evt.Type}, Code={evt.AbortCodeHex}, Message={evt.Message}");
}

OZeroSecurityEvent class

传递给 RegisterUserCallback 的面向客户公开的违规事件。它仅公开稳定且安全的诊断信息,而不是内部检测详情。

姓名 类型 解释
TypeModulationType引发违规的安全模块。
AbortCodeOZeroAbortCode稳定的公共中止代码类别。
AbortCodeValueint适合在服务器日志中使用的数字代码值。
AbortCodeHexstring0x0C 这样的十六进制字符串。
MessageKeystring可用于本地化和 analytics 分组的稳定英文消息键。
Messagestring可向客户公开的安全英文诊断消息。
WillAbortbool如果当前响应策略计划在回调返回后或宽限时间结束后终止应用程序,则为 true。

OZeroPolicyActionEvent class

Server policy callback payload passed to RegisterUserPolicyActionCallback. These events are issued by the customer portal policy system and delivered on the Unity main thread through the Pro device policy heartbeat.

姓名 类型 解释
ModulestringPolicy module such as variant, injection, or physics.
ActionIdstringUnique delivery id. The SDK uses it to avoid duplicate dispatch and acknowledge delivery.
PolicyIdstringCustomer portal policy id when available.
ReasonstringReason configured by the policy or generated from the matched evidence.
ScoreintRisk score at the time the policy matched.
EventCountintNumber of events that contributed to the policy match.
WindowMinutesintPolicy evaluation window in minutes.
IssuedAtUnixMslongServer UTC epoch milliseconds when the action was issued.
ExpiresAtUnixMslongServer UTC epoch milliseconds when the pending action expires if it is not acknowledged.

Policy callback example

Use this when a Customer Portal security policy is configured as Callback. The SDK delivers the policy action to the game, and your game decides how to notify, restrict, or move the user.

using OZeroSDK.Security;
using UnityEngine;

public sealed class OZeroPolicyListener : MonoBehaviour
{
    private void OnEnable()
        => OZeroSecurityManager.Instance.RegisterUserPolicyActionCallback(OnPolicyAction);

    private void OnDisable()
        => OZeroSecurityManager.Instance.UnregisterUserPolicyActionCallback(OnPolicyAction);

    private void OnPolicyAction(OZeroPolicyActionEvent evt)
    {
        Debug.LogWarning($"Policy={evt.PolicyId}, Module={evt.Module}, Score={evt.Score}, Reason={evt.Reason}");

        if (evt.Score >= 80)
        {
            ShowSecurityNotice(evt.Reason);
            DisableRankedMatchmaking();
        }
    }
}

OZeroUserActivationStateEvent class

User-facing activation or DRM state payload passed to RegisterUserActivationStateCallback. Steam Activation / DRM uses it to tell the game whether cached offline play is still allowed or online revalidation is required.

姓名 类型 解释
ProviderstringActivation provider such as steam.
StatestringStable state such as valid, revalidated, online_required, outage_fail_open, or rejected.
ReasonstringReason code such as steam_activation_revalidate_unavailable or steam_activation_cache_expired.
ActionstringPortal policy action value associated with this state when available.
OfflineAllowedboolTrue when the current cached token or grace policy allows offline play.
OnlineRequiredboolTrue when the game should ask the user to reconnect before allowing the protected session.
ExpiresAtUnixMslongUTC epoch milliseconds when the activation token expires.
GraceUntilUnixMslongUTC epoch milliseconds when the offline grace window ends.
OutageFailOpenUntilUnixMslongUTC epoch milliseconds for temporary server-outage fail-open handling.

Activation 状态回调使用条件

OZero-managed Steam DRM 与默认 Managed Verification UI 一起使用时,不需要 activation callback 代码;SDK 会向玩家显示需要联网、重试、timeout 和阻止状态。只有在有意替换默认 UI、添加自己的 session gate,或运行客户游戏服务器验证流程时才注册此回调。不要把 Steam Web API Key 或 OZero Server API Key 放入客户端。

OZeroUserManagedVerificationStateEvent class

传递给 RegisterUserManagedVerificationStateCallback 的面向用户 managed verification payload。Build Integrity 和 Steam DRM 都使用此事件,但默认 Managed Verification UI 会自动消费它。只有自定义 UI、自定义 telemetry 或游戏专用 session gate 需要时,才在游戏代码中处理。

姓名 类型 解释
ProviderOZeroManagedVerificationProviderSource module: BuildIntegrity or SteamDrm.
StateOZeroUserManagedVerificationStateCurrent state such as Checking, Allowed, Warning, OnlineRequired, RetryTimedOut, Blocked, or StandardFallback.
ReasonstringStable reason code suitable for custom UI text, analytics, or customer support logs.
VerdictstringServer verdict when available, such as allow, warn, block, or fallback.
CanRetryboolTrue when a Retry action is meaningful for the current provider and state.
TimestampUnixMslongUTC epoch milliseconds when the state was raised.

Managed verification 回调使用条件

managedVerificationUiPolicy 使用 OZero 内置对话框时,SDK 已经处理 Build Integrity 和 Steam DRM 的 managed-verification UI、重试和 timeout 状态。只有在 Custom UI / Callback Only、额外 telemetry 或游戏专用 session gate 中才注册 RegisterUserManagedVerificationStateCallback。在自定义 UI 模式下,请调用与 Provider 匹配的 retry 方法;在客户游戏服务器模式下,请重试自己的登录或会话请求。

OZeroManagedVerificationUiPolicy enum

决定 SDK 如何向玩家显示来自 Build Integrity 和 Steam DRM 的 managed verification 状态。两个 Built-In policy 都需要 TextMeshPro、TMP Essential Resources 和 optional OZero Built-In TMP Dialog package。若缺少这些条件仍选择 Built-In policy,build preflight 会停止 player build。请在 Window > OZero Security > Check Setup 中点击对应错误项的 Import Package 进行修复。

解释
CustomCallbackOnlySDK 只触发 RegisterUserManagedVerificationStateCallback 状态。仅在游戏自行实现 UI、重试按钮、timeout 处理和 session gate 时使用。
BuiltInBlockingDialog使用 OZero 内置阻止型对话框。对于在线重新验证期间应暂停或阻止受保护会话的正式版本,这是推荐默认值。
BuiltInNonBlockingDialog使用 OZero 内置非阻止型提示。只有在引导玩家重试或查看警告时,游戏仍可安全继续的情况下才使用。

OZeroManagedVerificationTimeoutAction enum

当在线必需或重试状态未在配置的超时时间内解决时,决定内置 managed verification UI 的处理方式。

解释
KeepDialogtimeout 后继续显示对话框。仅在希望玩家持续手动重试的流程中选择。
BlockSessiontimeout 后阻止受保护会话。在线验证必须成功但应用仍需保持打开时,这是推荐默认值。
AbortApplicationtimeout 后终止应用。仅在发布策略要求未解决的验证失败必须立即退出时使用。
InvokeCallbackOnly不执行内置阻止或退出行为,只触发 callback。用于完全自定义的会话控制。

ModulationType enum

标识哪个安全模块发出了警报。通过 OZeroSecurityEvent.Type 传递。

解释
MemoryModulation 以可疑方式访问的安全类型变量
SpeedHack 检测到速度黑客或时间操纵
TimeHack 检测系统时钟异常(倒流、NTP 不匹配)
Injection 检测内存注入工具(Frida等)或非法DLL
PhysicsHack 检测到不可能的位置变化(由 OZeroPhysicsHackDetector 触发 — 必须将组件直接附加到玩家对象并进行初始化)
DeviceBindingModulation 保存数据是从与其绑定的设备不同的设备加载的
InstallSource 应用安装自非授权商店
BuildIntegrity 程序集哈希不匹配、已连接调试器或平台检查失败
EnvironmentModulation 检测模拟器或异常运行环境
SteamAntiPiracy 当 Steam 所有权或票证验证失败时发生。

OZeroBootstrapper OZeroSDK.Security

负责初始化 SDK 的自动启动入口点。您不需要在项目代码中直接调用。它根据 Unity 启动流程加载安全设置,并在游戏开始前准备好激活的检测器。

无公共 API — 不要在调用方实例化、继承或引用此类型。唯一支持的集成表面是 OZeroSecurityConfig 资产。

OZeroSecurityConfigRuntime OZeroSDK.Security

在玩家运行时读取和验证受保护的构建设置的配置加载程序。验证打包的设置,准备内存中的 OZeroSecurityConfig 运行设置,并在验证失败时应用配置的威胁响应策略。

特性

姓名 类型 解释
Current OZeroSecurityConfig 通过读取玩家构建中包含的受保护设置而创建的设置快照。首次访问时调用 EnsureLoaded()

方法

static void EnsureLoaded()

可以安全重复调用的加载器。第一次调用验证并加载打包设置,后续调用重用相同的设置快照。失败处理遵循配置的响应策略。

这种类型是内部加载器。请将 OZeroSecurityConfig 和 Unity 编辑器窗口视为支持的集成表面。

OZero Secure Variables OZeroSDK.Security

可替代常规数字、字符串和向量类型的加密类型。值存储在受保护的内存区域中,并支持大多数算术运算符和隐式转换。只需更改类型名称即可应用于现有代码。

支持类型

替代类型
OZeroSV_Intint
OZeroSV_Int64long
OZeroSV_UIntuint
OZeroSV_UInt64ulong
OZeroSV_Shortshort
OZeroSV_UShortushort
OZeroSV_Bytebyte
OZeroSV_Floatfloat
OZeroSV_Doubledouble
OZeroSV_Decimaldecimal
OZeroSV_Boolbool
OZeroSV_Stringstring
OZeroSV_Vector2Vector2
OZeroSV_Vector3Vector3
OZeroSV_Bufferbyte[]

支持的运算符

数字类型(Int、Int64、UInt、UInt64、Short、UShort、Byte、Float、Double、Decimal)支持算术(+ - * / %)、比较(== != < > <= >=)、复合赋值 (+= -= *= /=)、递增/递减 (++ --) 运算符以及与基本类型的隐式转换。Vector2·Vector3 支持算术和等式运算符,而 Bool 仅支持等式运算符。字符串支持 ==!=+。Buffer 可以通过索引运算符直接访问字节数组。

Secure Types 旨在减少受支持的基本运算中的重复分配。但是,根据字符串/缓冲区转换、日志记录、装箱、LINQ 和用户代码模式,可能会发生 GC 分配,因此在应用于每帧大量更新之前,请进行性能分析。

OZeroSafePlayerPrefs OZeroSDK.Security

可以像 Unity 的 PlayerPrefs 一样使用的加密存储。由于密钥名称和值均受到保护,因此即使直接打开 Windows 注册表或 iOS 配置文件,也很难读取原始值。

方法

static void SetInt(string key, int value)
static int GetInt(string key, int defaultValue = 0)
static void SetFloat(string key, float value)
static float GetFloat(string key, float defaultValue = 0f)
static void SetString(string key, string value)
static string GetString(string key, string defaultValue = "")
static void SetInt64(string key, long value)
static long GetInt64(string key, long defaultValue = 0L)
static void SetDouble(string key, double value)
static double GetDouble(string key, double defaultValue = 0.0)
static void SetBool(string key, bool value)
static bool GetBool(string key, bool defaultValue = false)
static int IncrementInt(string key, int defaultValue = 0)
static bool HasKey(string key)
static void DeleteKey(string key)
static void DeleteAll()
static void Save()
static void Initialize(string newPassword = "", string newSalt = "") // obsolete compatibility no-op

提供常见的 PlayerPrefs 风格方法,并额外提供 Int64DoubleBoolIncrementInt 辅助方法。已有的 plain PlayerPrefs 值不会自动迁移;请从今后需要保护的 key 开始使用 OZeroSafePlayerPrefs

使用 OZeroSafePlayerPrefs 写入的数据与标准 PlayerPrefs 不兼容。在两者之间切换将使现有数据无法读取。

OZeroSV_File OZeroSDK.Security

使用内部加密逻辑保护文件的读写。由于不使用设备绑定密钥,因此即使像 Steam 云存档那样需要在多台设备上读取同一个存档文件,也可以使用。如果故意篡改文件,读取时的完整性检查将会失败并抛出 InvalidDataException

加密文件会以 SDK 内部格式保存。请不要直接解析文件结构或特定偏移位置,读写都应始终通过 OZeroSV_File API 处理。

方法

static void WriteAllText(string path, string contents)

加密 contents 并保存到 path。父文件夹不会自动创建,必要时请先调用 Directory.CreateDirectory

static string ReadAllText(string path)

读取 path 指定的文件,验证完整性后返回解密后的字符串。如果文件被篡改,将抛出 InvalidDataException

static void WriteAllBytes(string path, byte[] bytes)

加密数据并安全保存到 path

static byte[] ReadAllBytes(string path)

读取 path 指定的文件。在读取时验证文件的完整性,并检测是否发生篡改。

static string DecryptBytesToText(byte[] encryptedData)

解密已经加载到内存中的加密字节缓冲区。适用于远程下载或自定义存储后端,无法将文件路径传给 ReadAllText 的情况。

示例代码

using OZeroSDK.Security;

string path = Application.persistentDataPath + "/save.json";
string json = JsonUtility.ToJson(saveData);

// Write (encrypts automatically)
OZeroSV_File.WriteAllText(path, json);

// Read (decrypts + integrity check)
try
{
    string loaded = OZeroSV_File.ReadAllText(path);
    saveData = JsonUtility.FromJson<SaveData>(loaded);
}
catch (System.IO.InvalidDataException)
{
    // File was tampered — handle accordingly
    Debug.LogError("Save file integrity check failed.");
}

OZeroBuildIntegrityValidator OZeroSDK.Security

处理构建篡改、调试器/计时异常、平台原生完整性检查以及可选的 Pro 服务器验证的验证器。当 OZeroSecurityConfig 中启用构建完整性时,由 SDK 自动创建。

检查项目

测试 解释
Assembly / Manifest在支持的构建目标上验证生成的完整性清单和托管程序集状态。
Debugger / Timing检测附加的调试器、异常定时间隔、靠近断点的延迟,并抑制常见的焦点丢失误报。
Platform Native启用后,执行特定于平台的检查,例如 Android 包/签名、iOS 越狱和桌面运行时状态等。
Pro Attestation如果开启了 Pro 服务器验证,本地检查通过后会向服务器请求验证令牌。如果没有自己的游戏服务器,OZero 服务器也可以一同返回允许/警告/阻断的结果。

公共属性

姓名 类型 解释
InstanceOZeroBuildIntegrityValidator当前验证器实例(如果创建了模块)。
LastValidationResultbool?这些是最新的本地验证结果。在第一次验证之前,它是 null
IsValidatingbool如果验证正在运行,则为 true。
IsIntegrityVerifiedbool如果最近激活的本地检查通过,则为 true。
AttestationTokenOZeroBuildAttestationToken这是最新的 Pro 证明令牌。在服务器证明成功或失败之前为空,并且令牌包含用于重用跟踪的唯一 ID。

事件和方法

UnityEvent OnValidationPassed { get; }

当所有启用的本地检查通过时调用。

UnityEvent OnValidationFailed { get; }

当启用的本地检查或 Pro 证明拒绝构建时调用。

UnityEvent OnAttestationPassed { get; }

当 Pro 服务器证明成功并且在 AttestationToken 中收到有效令牌时调用。

void Validate()

开始手动验证。对于一般项目,建议使用仪表板的启动/定期验证设置。

OZeroBuildAttestationToken

Pro attestation 的结果。将 AttestToken 发送到游戏服务器,并在登录、PvP、排行榜或货币流程使用前调用 IsValid(nowMillis) 确认有效性。

bool IsExpired(long nowMillis)

超过服务器颁发的过期时间后返回 true。

bool IsValid(long nowMillis)

令牌成功签发且尚未过期时返回 true。

OZeroSpeedHackDetector OZeroSDK.Security

使用五个独立的检测信号检测速度黑客和时间操纵。仅在信号相互确认时才报告威胁,从而减少误报。

检测信号

信号 解释
TimeScale 检查游戏的时间流逝是否异常改变
API Clock 比较平台时间与原生参考时间以检测较大差异
Thread Drift 观察 Unity 运行时时间与原生参考时间的流逝差异
Time Backward 检测设备时间异常倒退的情况
NTP 可选 — 与可靠的外部时间参考进行交叉检查(需要网络)

检测通过带有 ModulationType.SpeedHackModulationType.TimeHackOZeroSecurityManager 回调进行。设置在 OZeroSecurityConfig 中。

OZeroWatchdog OZeroSDK.Security

用于可信长时间加载工作的公共 helper。在同步工作可能合理地阻塞 Unity 主线程超过发布版 deadline 时,有限延后原生 Watchdog heartbeat deadline。

方法

OZeroWatchdog.OZeroLoadingGraceScope BeginLoadingGrace(int maxGraceMs = 60000)

开始一个受限的 loading grace scope。可信加载工作完成后,请立即调用返回 scope 的 End() 或 dispose 它。支持嵌套 scope;最后一个 scope 结束后会恢复正常 Watchdog timing。

void OZeroLoadingGraceScope.End()

手动结束此 loading grace scope。Dispose() 会调用相同逻辑,因此 using 块和显式 End() 等效。

void RunWithLoadingGrace(Action work, int maxGraceMs = 60000)

用于同步加载工作的便捷 wrapper。它创建 loading grace scope,执行 work,并通过 using 块安全结束 scope。

示例

using OZeroSDK.Security;
using UnityEngine.SceneManagement;

public void LoadLargeScene()
{
    using (OZeroWatchdog.BeginLoadingGrace(60000))
    {
        SceneManager.LoadScene("Battle", LoadSceneMode.Single);
    }
}
此 API 只会延后 Watchdog deadline;它不会关闭其他保护模块,也不会公开原生 heartbeat。请仅用于可信加载边界,不要作为 keep-alive 机制使用。

OZeroInjectionDetector OZeroSDK.Security

检查正在运行的游戏是否附加了可疑模块,或者是否存在挂钩或调试器痕迹。定期检查在可能的情况下会使用稍微变动的检查时间,使简单的绕过尝试变得更加困难。

检测目标

Runtime module 意外的运行时模块或涉嫌挂钩的信号
Debugger 涉嫌调试器或跟踪工具连接的信号
Memory map 异常的运行时内存或模块状态信号
Illegal DLL 加载到进程中的未授权托管程序集信号(Windows/Unity 编辑器)

检测通过带有 ModulationType.InjectionOZeroSecurityManager 回调进行。

OZeroSteamAntiPiracy OZeroSDK.Security

Steam Anti-Piracy 的运行时控制 API。大多数项目只需在 Config Dashboard 中设置;如果游戏提供自己的策略 UI 或 QA 开关,可以通过这个静态 API 临时覆盖本地检测动作。

此 API 适用于在 QA 构建中临时切换到观察模式,或者在游戏内的管理员菜单中恢复为默认设置。在单独应用 Pro 服务器策略的项目中,门户的策略可能会优先,因此请将实际阻断策略与门户设置一起确认。

OZeroSteamDetectionAction

解释
Off不应用本地 Steam Anti-Piracy 响应。仅用于受控排查情况。
Observe只记录诊断信息,并允许游戏继续运行。
Callback触发 OZeroSecurityManager 回调,让游戏能够显示 UI、记录日志或自行处理。仅靠此选项不会自动终止应用程序,实际是否终止取决于 Global Threat Response 设置和项目的回调处理方式。
Block将违规视为阻断策略。实际应用是否终止遵循 Global Threat Response 设置。

方法

static void SetDetectionActionOverride(OZeroSteamDetectionAction action)

在运行时覆盖本地 Steam Anti-Piracy 检测动作。适用于 QA 构建中临时降级为 Observe,或让操作员从管理员菜单中选择特定操作。

static void ClearDetectionActionOverride()

清除运行时覆盖的操作,恢复为在 OZeroSecurityConfig 或 Pro 门户中设置的基本操作。

示例

using OZeroSDK.Security;

// QA session: observe Steam violations without blocking gameplay.
OZeroSteamAntiPiracy.SetDetectionActionOverride(
    OZeroSteamDetectionAction.Observe);

// Restore the dashboard/server policy.
OZeroSteamAntiPiracy.ClearDetectionActionOverride();

最近验证结果

OZeroSteamAntiPiracyValidator.Instance.GetLastResult()

返回最近一次 Steam 验证快照,包括 reported AppID、BuildID、SteamID、服务器验证状态、soft signal 和 native score 字段。可用于调试 UI 或 QA 报告,但不要作为唯一的游戏权限判断依据。

OZeroInstallSourceValidator OZeroSDK.Security

Android 安装来源验证器。启用 Install Source 后组件会自动创建。客户代码通常读取最近结果,用于支持 UI、诊断日志或按商店分流处理。

方法和事件

event Action<InstallSourceResult> OnInstallSourceDetected

安装来源确认完成后调用。

InstallSourceResult GetLastResult()

返回最近一次检查的缓存结果。

InstallSourceResult GetAndroidInstallationSource()

必要时先进行初始化,然后返回 Android 安装来源结果。

InstallSourceResult

DetectedSource解析后的安装来源,类型是 AndroidInstallSource enum。
RawInstallerPackageAndroid PackageManager 返回的原始 installer package name。
IsAuthorized如果本地配置以及启用时的 Pro 服务器策略允许该安装来源,则为 true。
ServerVerified仅限 Pro。如果服务器验证调用已完成,则为 true。
ServerAuthorized仅限 Pro。当 ServerVerified 为 true 时的服务器端授权状态。

AndroidInstallSource

InstallSourceResult.DetectedSource 返回的准确 enum 值。manual 中的商店名称只是便于阅读的显示名;代码中请与下面这些 enum 名称比较。

解释
GooglePlayStore从 Google Play Store 安装。
SamsungGalaxyStore从 Samsung Galaxy Store 安装。
AmazonAppstore从 Amazon Appstore 安装。
HuaweiAppGallery从 Huawei AppGallery 安装。
OneStore从 ONE Store 安装。
XiaomiGetApps从 Xiaomi GetApps 安装。
OppoAppMarket从 OPPO App Market 安装。
VivoAppStore从 Vivo App Store 安装。
Custom原始 installer package 与 customAuthorizedPackages 匹配。
ADBAndroid 返回空 installer package,通常出现在 ADB 或 sideload 方式安装时。
DetectionFailed由于 JNI 或平台 API 不可用,installer 查询本身失败。这与 ADB 不同。
UnknownAndroid 返回了 package name,但它既不在内置列表中,也不在自定义允许列表中。
Editor在 Unity Editor 中运行时返回。
NotApplicable在不适用 Android 安装来源概念的平台上返回。

OZeroDeviceBindingDetector OZeroSDK.Security

用于绑定到设备的存档槽和客服重置流程的辅助 API。启用 Device Binding 后,验证器会自动启动。只有在需要把云存档、账号存档槽等数据绑定到当前设备时,才需要直接调用下面的 token 方法。

方法

void Initialize()

准备本地设备指纹,然后进行注册或验证。普通项目中通常会在 SDK 启动时自动调用。

string BindToSaveSlot(string saveSlotKey)

创建一个将存档槽 key 与当前设备关联的令牌。请将令牌保存在存档元数据或服务器记录中,不要放入玩家可编辑的存档正文。

bool ValidateSaveSlot(string saveSlotKey, string storedToken)

检查已保存的存档槽令牌是否与当前设备匹配。如果不匹配,SDK 会触发配置好的 Device Binding 违规响应。

string GetCurrentFingerprintHash()

返回当前设备指纹 hash 的调试/演示用辅助方法。不要在正式游戏代码中显示、上传或保存这个值。

void ClearStoredFingerprint(string authorizationToken = "")

清除保存在此设备上的指纹。在非 Editor 构建中,需要传入服务器发放的 Reset Token,并且只应在合法的客服重置流程中使用。

示例

using OZeroSDK.Security;

var detector = OZeroDeviceBindingDetector.Instance;
string slotKey = "account:1234:slot:main";

string token = detector.BindToSaveSlot(slotKey);
// Store token next to your save metadata.

bool ok = detector.ValidateSaveSlot(slotKey, token);

OZeroSecurityConfig ScriptableObject

包含 OZero 安全模块默认设置的 Unity ScriptableObject 资产。当您在 Config Dashboard 或 Inspector 中更改值时,构建时它将被包含作为玩家的保护设置。当需要在代码中检查当前设置时,请使用 OZeroSecurityConfig.Instance

字段

字段会分组到 ResponseIntegrity 等嵌套设置类中。下表汇总了代码中经常查看或集成时经常调整的字段;完整 Inspector 设置表请参考 manual。默认值以代码中保存的序列化初始值为准。如果发布构建中运行时值会被强制改写,则用 * 标记。

字段 类型 默认 解释
- 顶部 -
developerSecret string "" 用于保护 OZeroSV_FileOZeroSafePlayerPrefs 数据的项目级 secret。首次发布前请在 Config Dashboard 中使用 Generate Secure Secret 生成,发布后不要更改。更改后,新版本将无法解密现有受保护数据。
enableLog bool true 启用 SDK 调试日志。它对开发/QA 排查原因有帮助,但发布构建的日志暴露策略需要单独确认。
enableFailureDiagnostics bool false 将安全失败诊断文件写入 Application.persistentDataPath。仅在 QA 或客户支持调查期间启用,确认后请再次关闭。
- 回复 -
response.forceQuitOnDetection bool true 决定确认威胁时应用是否自动退出。QA 期间可以关闭并只观察事件,但发布构建应根据项目策略明确选择。
response.fatalCallbackGraceSeconds float 10 威胁检测后,游戏侧安全回调 UI 可以向玩家显示提示的最长时间(秒)。只有明确需要立即退出时才设置为 0
— Managed Verification UI —
managedVerificationUiPolicy (Pro) OZeroManagedVerificationUiPolicy BuiltInBlockingDialog 选择 OZero Managed Build Integrity 和 Steam DRM 状态的用户界面流程。内置模式让 SDK 处理 nonce/attest、managed session verification、联网提示、重试和 timeout UI。只有替换 SDK 对话框时才使用 Custom UI / Callback Only。
managedVerificationDialogPrefabResourcePath (Pro) string "" 复制并自定义的 OZero Managed Verification UI prefab 的 Resources 路径。留空则使用 SDK 默认 prefab。
managedVerificationRetryTimeoutSeconds (Pro) int 15 玩家点击 Retry 后,报告 retry-timeout 前等待的最大秒数。
managedVerificationOnlineRequiredTimeoutSeconds (Pro) int 120 保持在线必需状态并应用配置的 timeout action 前等待的最大秒数。
managedVerificationTimeoutAction (Pro) OZeroManagedVerificationTimeoutAction BlockSession 选择 timeout 时是保持对话框、阻止受保护会话、终止应用,还是仅调用 callback。
autoRetryManagedVerificationWhenNetworkRestored (Pro) bool false 网络连接恢复后自动重试 managed verification。仅在无需玩家明确操作也可以安全重试的游戏流程中启用。
managedVerificationLanguageCode (Pro) string auto 内置 UI 字符串使用的语言代码。auto 会跟随 Application.systemLanguage
managedVerificationFallbackLanguageCode (Pro) string en 选定 JSON 资源缺失时使用的 fallback 语言。自定义资源使用 ozero_ui_text_{code}.json 格式。
- 完整性 -
integrity.useIntegrity bool true 用于启用 Build Integrity 模块的主开关。
integrity.validateOnStartup bool true Start() 运行时执行完整的完整性检查。
integrity.periodicCheckInterval float 300 定期重新验证运行之间的时间间隔(秒)。代码默认值为 300,设置为 0 或更小会禁用定期检查。
integrity.checkAssemblyHash bool true 针对 OZeroAssemblyManifest 编译的程序集的 SHA-256/公钥令牌验证。
integrity.checkDebugger bool true 检测附加的托管调试器、Unity 调试构建标志、CPU 时序异常。
integrity.checkPlatformNative bool true 运行特定于平台的本机检查(Root、越狱、APK 签名、Authenticode 等)。
integrity.failIfManifestMissing bool false* 将 manifest 丢失或加载失败视为违规。*在非 development 的 player build 中,无论序列化值如何都会强制为 true
integrity.failIfAssemblyHashBlobMissing bool false* 将生成的程序集哈希 blob 丢失视为违规。*在非 development 的 player build 中会强制为 true
integrity.requireManifestSignature bool false* 要求 manifest 具有有效签名。请在 Window → OZero Security → Config & Dashboard 中使用 Generate Key Pair 生成密钥。*在发布 player build 中会强制为 true
integrity.il2cppHashGlobalGameManagers bool false 在 Windows IL2CPP 文件哈希中包含 globalgamemanagers。Standard 和 Strict 预设会开启此项。
integrity.il2cppHashSharedAssets bool false 在 Windows IL2CPP 文件哈希中包含 sharedassets* 文件。Standard 和 Strict 预设会开启此项。
integrity.il2cppHashSceneFiles bool false 在 Windows IL2CPP 文件哈希中包含 level* 等 Unity 场景文件。Standard 和 Strict 预设会开启此项。
integrity.blockEmulator bool true (Android) 将模拟器检测视为完整性违规。
integrity.checkIntegrityWithServer (Pro) bool false 开启 Pro 的 nonce → attest 流程。与 OZero Managed 和默认 Managed Verification UI 一起使用时,SDK 会在无需游戏代码的情况下提交构建完整性证据、请求 managed session 判定,并处理面向用户的 retry/timeout 状态。
integrity.attestationVerificationMode (Pro) enum CustomerGameServer 选择由客户游戏服务器最终验证 OZA 令牌,或由 OZero Managed verification 通过 SDK 管理会话流程返回判定。
integrity.attestationNetworkPolicy (Pro) enum BestEffort 选择离线或重新验证失败时继续本地保护,还是报告需要联网重试的状态。默认 Managed Verification UI 模式会自动显示此状态。
— Install Source (Android) —
installSource.useInstallSource bool true Install Source验证主开关。
installSource.allowGooglePlayStore bool true 允许从 Google Play 安装(您还可以切换 Galaxy Store、Amazon Appstore、AppGallery、OneStore 等的各个商店标志)。
installSource.enableServerSync (Pro) bool false 本地检测后调用 /v1/install-source/verify,让 Pro 服务器应用托管 allowlist 并记录审计数据。
installSource.allowDetectionFailed bool false Android installer 查询本身失败时仍允许启动。除非有经过测试的设备级原因,发布构建中请保持关闭。
installSource.allowUnknownSources bool false 允许不在内置列表、也不在 customAuthorizedPackages 中的 installer package。
— Steam Anti-Piracy —
steamAntiPiracy.useSteamAntiPiracy bool false Steam 启动、权限、DLC 和发布 hygiene 检查的 master switch。
steamAntiPiracy.detectionAction OZeroSteamDetectionAction Callback Steam 验证失败时使用的本地响应。Pro 策略可能覆盖该值。
steamAntiPiracy.checkSteamDrmWithServer (Pro) bool false 启用基于服务器证据的 Steam DRM 验证。与 OZero Managed 和默认 Managed Verification UI 一起使用时,SDK 会处理 Steam ticket 提交、activation token cache、需要联网 UI、重试和 timeout 状态。
steamAntiPiracy.steamDrmVerificationMode (Pro) enum OZero Managed 选择由 OZero 托管验证,或由客户游戏服务器负责验证。与默认 Managed Verification UI 搭配时,OZero Managed 是无需自有后端的集成路径。
steamAntiPiracy.steamDrmNetworkPolicy (Pro) enum Best Effort 控制需要 Steam DRM 再验证但客户端无法连接服务器时的处理方式。默认 Managed Verification UI 模式会自动显示需要联网和重试流程。
— Device Binding —
deviceBinding.useDeviceBinding bool true 在 SDK 启动时开启 Device Binding 验证。
deviceBinding.hardwareChangeTolerance int (0–3) 1 决定设备指纹中的多少项发生变化时仍视为同一设备。
deviceBinding.enableServerSync (Pro) bool false 仅限 Pro。通过 /v1/device/register/v1/device/verify 注册并验证设备指纹。网络失败本身不会阻止游戏,但服务器明确拒绝时会成为 Device Binding 违规。
deviceBinding.maxDevices (Pro) int 0 显示一个许可证可注册设备数量的参考值。实际运营上限以服务器许可证记录或 Customer Portal 策略为准。
— 速度黑客 —
speedHack.useSpeedHack bool true 速度黑客检测器主开关。
speedHack.checkInterval float 1.0 检查间隔(秒)。过小或过大的值都会自动限制在安全范围内。
speedHack.requiredDetections int 3 判定为违规之前所需的连续可疑样本数。过小或过大的值都会自动限制在安全范围内。
speedHack.detectSlowHack bool false 同时检测慢速时间篡改。为减少游戏中正常慢动作的误报,默认关闭。
speedHack.useWebTimeValidation bool true 启用与外部端点的基于 HTTPS HEAD 的游戏时间交叉验证。
speedHack.webTimeUrls[] string[] [] 用于 Web 时间交叉验证的 HTTPS 地址列表。请设置两个以上由您管理或信任的地址。如果列表为空,Web 时间验证将没有可用地址。
speedHack.minSuccessfulEndpoints int 2 一次 web-time 检查回合要被视为成功,webTimeUrls 中至少有多少个地址必须返回有效 Date 标头。
speedHack.maxConsecutiveFailures int 6 web-time 检查回合连续失败达到此次数后,执行 onWebTimeUnavailable 策略。
speedHack.onWebTimeUnavailable WebTimeUnavailablePolicy WarnOnly 多次无法确认 Web/服务器时间时的策略。WarnOnly 只记录日志并继续运行。Strict 会在反复失败后触发 SpeedHack 事件。Silent 不记录日志,仅应保留给特殊测试。
speedHack.enableRemoteSpeedHackConfig bool false Pro 服务器功能。启用后,/v1/speedhack-config 可以在无需重新构建客户端的情况下覆盖部分 Speed & Time Hack 阈值。需要有效的 Pro 许可证和服务器 URL。
speedHack.remoteSpeedHackConfigInterval float 300 重新拉取 /v1/speedhack-config 的间隔。0 表示只在启动时拉取一次。
speedHack.remoteSpeedHackConfigJitterPercent float 20 让 Pro 远程设置请求不要在大量设备上重叠,而是在设定刷新周期附近分散调用的比例。限制在 075
speedHack.enableSignedServerTime bool false Pro 服务器功能。Pro 激活可用时,优先使用签名的 /v1/time 作为可信时间源。连续失败后会回退到已配置的 web-time endpoint。
— PhysicsHack —
physicsHack.useGlobalPhysicsHackbooltrue所有 OZeroPhysicsHackDetector 组件的全局开关。每个对象的移动阈值仍保留在各自组件的 Inspector 中。
physicsHack.enableServerTelemetry (Pro)boolfalse仅限 Pro,默认关闭。只有项目明确同意且当前许可证具备权限时,才会发送一般安全事件与详细 PhysicsHack telemetry。关闭后将停止发送新的 telemetry;服务器策略不能在没有本地同意的情况下启用传输。
physicsHack.telemetryThrottlePerMinute (Pro)int30此客户端每分钟可发送的 PhysicsHack telemetry 数量。0 表示不限制;如果 detector 调整不当,可能过度调用服务器,因此不建议使用。
— 注入 —
injection.useInjection bool true Injection & Hooking 的总开关。玩家构建会按配置的响应策略处理;开发构建使用以警告和诊断为主的流程;编辑器中通常不执行此检测。
injection.injectionWhitelistEntries OZeroInjectionWhitelistEntry[] empty 注册到 Injection Detector 的本地可信模块列表。它不是 Pro 专用,所有 tier 都可以使用。只添加随游戏一起分发,或通过 QA、诊断文件、Pro telemetry、OZero 支持团队确认过的模块。

WebTimeUnavailablePolicy

配置的 web-time 地址连续失败 maxConsecutiveFailures 个回合后应用的策略。它决定临时网络问题只记录日志,还是上报为安全回调。

解释
WarnOnly默认值。只留下警告日志,游戏继续运行。对于也需要离线运行的游戏,这是最安全的选择。
Strict反复失败后触发 SpeedHack 回调。网络质量较差时也可能出现 web-time 失败,因此请先在实际服务地区的网络环境中测试。
Silent不记录日志,也不触发回调。仅用于短期兼容性测试,不建议用于发布构建。
developerSecret 必须在首次发布前设置,之后不得更改。更改后,新版本将无法解密现有保存数据(PlayerPrefs 和文件)。

OZeroLicenseConfig OZeroSDK.Security.License

Resources/OZeroLicenseConfig 加载的 ScriptableObject。选择许可证层级,并保存 Plus/Pro 许可证密钥与 Pro 运行时服务器设置。如果资产不存在或密钥为空,则其运行方式与 Standard 相同。

字段

字段 类型 解释
tierOZeroLicenseTierStandard 以完全离线方式运行。Plus 激活项目绑定的原生变体。Pro 包含 Plus 并启用基于服务器的运行时功能。
licenseKeystring为项目签发的 Plus/Pro 许可证密钥。Plus 用它确认项目专用 Native Variant,Pro 还会在运行时激活和服务器功能中使用它。如果为空,则其运行方式与 Standard 相同。
serverBaseUrlstringPro 运行时服务器 Base URL。用于激活、遥测、signed time、attestation 和服务器策略调用。Standard 和 Plus 运行时不会调用此 URL。
serverPublicKeyHexstringPro 专用服务器签名公钥。请复制客户门户 > Server Key 中的 Active publicKey。Pro 运行时用它验证 signed activation、time、attestation 和 offline policy token。Plus Variant manifest 使用 SDK 内置的 OZero Variant signing key,而不是此字段。
previousServerPublicKeyHexstring仅在 Pro 服务器密钥轮换宽限期使用的旧签名公钥。通常请留空。
tokenTtlSecondsintPro 运行时离线缓存保留时间。过期后,Pro 服务器功能会保持关闭,直到再次激活成功。
offlineProPolicyModeOZeroOfflineProPolicyMode决定设备离线时如何使用已签名的 Pro 门户阻止策略。
activationTimeoutSecondsfloatPro 运行时激活超时时间。如果激活未在该时间内完成,游戏会使用可用的 Pro 缓存,或按 Standard/serverless 方式继续启动。
enableLogbool通过 OZeroSecLog 输出许可证流程的诊断日志。配置 Plus/Pro 时尤其有用。
enableDevicePolicyHeartbeatbool仅限 Pro。定期检查当前设备是否仍处于允许状态。
devicePolicyHeartbeatIntervalfloatPro 设备策略检查的基础间隔。默认 300 秒;0 会关闭周期检查。
devicePolicyHeartbeatJitterPercentfloat让多个设备不要同时检查设备策略,而是在设定周期附近分散确认时间的比例。限制在 075
enableSecurityLevelCheckbool仅限 Pro。允许服务器验证构建是否声明了预期的安全级别。
declaredSecurityLevelOZeroDeclaredSecurityLevel此构建向服务器声明的安全等级。
failOnSecurityLevelRejectbool为 true 时,如果服务器明确拒绝声明的安全等级或配置 hash,会执行配置的强响应。
securityLevelCheckIntervalfloat服务器安全等级重新检查间隔。0 表示只在启动时检查一次。
securityLevelCheckJitterPercentfloat让多个设备不要同时重新检查安全等级,而是在设定周期附近分散确认时间的比例。限制在 075

OZeroDeclaredSecurityLevel

启用安全等级验证时发送给 Pro 服务器的 enum。服务器会确认该值是否满足许可证配置的最低等级。

解释
Low原型或开发构建等级。仅在服务器策略明确允许低保护声明时使用。
Standard默认值,也是普通受保护正式游戏构建推荐使用的声明。
Strict最高保护声明。只有在 QA 确认项目能在 strict 策略下正常运行后才使用。

OZeroOfflineProPolicyMode

这个 enum 决定 Pro 门户下发设备、版本、国家等阻止策略后,玩家临时离线时 SDK 如何处理。第一次使用时建议保持默认值 ApplyCachedBlockPolicies

解释
ApplyCachedBlockPolicies推荐值。离线时也会继续应用最后一次收到的已签名阻止策略,适合大多数正式运营游戏。
RequireFreshPolicy如果无法确认有效期内的新策略,就不使用 Pro 保护。只适合始终在线、不能接受旧策略的游戏。
IgnoreCachedBlockPolicies离线时忽略缓存的阻止策略。主要用于测试或特殊迁移场景,不建议用于正式构建。

特性

static OZeroLicenseConfig RuntimeInstance { get; }

从 Resources 加载运行时设置。如果为 null,请按照与 Standard 相同的方式处理。

bool IsServerlessMode { get; }

对于 Standard、Plus 或空许可证密钥,它为 true。仅当需要 Pro 激活时才为 false。

bool IsVariantTier { get; }

在 Plus 和 Pro 中为 true。用于识别可执行 Native Variant 验证的等级;是否存在 private Variant 会根据已导入的签名清单自动判断。

OZeroLicenseRuntime OZeroSDK.Security.License

读取当前许可证状态的运行时 API。它在应用启动时自动初始化,因此大多数项目只需读取状态或调用 HasCapability 即可。

特性

姓名 类型 解释
EntitlementOZeroLicenseEntitlement当前已激活的 Pro 权限信息。在 Standard 模式下为 null。
HasEntitlementbool如果当前存在 Pro 激活信息,则为 true。
IsServerlessbool如果 SDK 在没有 Pro 服务器功能的情况下运行,则为 true。
Initializedbool许可证运行时的首次启动处理完成后为 true。
IsProDowngradedbool在 Pro 激活失败或过期后,如果 SDK 静默作为 Standard 继续执行,则为 true。
DowngradeReasonstring这是最近一次自动降级(切换回基本保护)的诊断原因。
DeviceIdProviderFunc<string>您可以选择更改用于激活的 device id。如果您的项目需要使用自己的标识符,请在初始化前设置。

方法

static Task Initialize()

多次调用也是安全的启动方法。通常由 SDK 自动调用,在自定义引导中可以在读取许可证状态之前等待。

static bool HasCapability(string cap)

返回当前激活信息中是否具有 telemetrysigned_timeattestation 等功能权限。在 Standard 中为 false。

Standard 和 Plus 不需要运行时激活。即使 Pro 无法激活,游戏玩法也将以 Standard 功能继续运行,仅有 Pro 专有功能不可用。

许可证服务器运行时调用

Pro 功能使用 /v1 下的 HTTPS JSON API。大多数调用由 SDK 自动执行。拥有自己游戏服务器的团队可以通过 /v1/validate 验证 OZA 令牌,并在结账或发放货币等重要操作中使用 consumeToken=true 来防止重复使用相同的令牌。没有自己服务器的团队可以使用 OZero 服务器的允许/警告/阻断结果。

端点 用途
POST /v1/activate在当前设备上激活 Pro 许可证,并更新本地激活信息。
GET /v1/time启用后,提供用于 Speed & Time Hack 验证的签名服务器时间。
POST /v1/attest在通过启用的完整性检查后,颁发包含唯一令牌 ID 的 Pro 构建证明令牌。nonce 绑定到提交的构建证据和应用标识信息。
POST /v1/validate在游戏服务器中验证 OZA 令牌。对于排名、支付、货币发放等重要的一次性操作,可以使用 consumeToken=true 来阻止重复使用同一个令牌。
POST /v1/managed-session对于没有自己后端的团队,OZero 会验证 Pro OZA 令牌并返回允许/警告/阻断判定以及短会话。SDK 会在会话过期前尝试自动重新验证,并且会阻止重复使用相同令牌的流程。
POST /v1/telemetry当 Pro 遥测权限激活时,将安全事件发送到服务器。

POST /v1/activate contract

这是 Unity SDK 启用 Pro 许可证时发送的基础请求契约。服务器 schema 可以接收额外的原生验证字段,但当前 SDK 的基础激活请求会发送下面这些字段。

字段类型必填解释
licenseKeystringyes/v1/activate 使用的 Pro 许可证密钥。服务器会验证密钥格式、状态、层级、到期时间和设备容量。
deviceIdstringyes设备标识。需要时可以通过 OZeroLicenseRuntime.DeviceIdProvider 自定义。
sdkVersionstringyes客户端 SDK 版本。
platformenum stringyesUnity 运行平台。服务器只接受允许的平台注册值。
appIdentifierstringoptionalUnity 应用标识符。只有非空时才会发送。
companyNamestringoptionalUnity PlayerSettings 中的公司名。只有非空时才会发送。
productNamestringoptionalUnity PlayerSettings 中的产品名。只有非空时才会发送。
webglOriginstringoptionalWebGL 构建中检测到的 origin。只有存在值时才会发送。
字段类型解释
activatedbool激活是否成功。正常响应为 true。
tierstring服务器确认的许可证等级。
capabilitiesstring[]该许可证可使用的功能列表。
serverFeaturesEnabledboolPro 服务器功能是否可用。
signedTokenstring服务器签名的激活 token。之后用于 Pro 服务器功能验证。
keyIdstring签名密钥标识符,用于 token 验证密钥轮换。
expiresAtnumber激活信息的过期时间。
serverUnreachablePosturestring服务器暂时不可达时如何看待缓存的策略。
失败响应是带有 codemessage 的 JSON。常见代码包括 BAD_JSONBAD_REQUESTLICENSE_NOT_FOUNDLICENSE_PENDINGLICENSE_SUSPENDEDLICENSE_REVOKEDLICENSE_EXPIREDDEVICE_BLOCKEDACTIVATION_LIMITSERVER_NOT_CONFIGUREDSIGN_FAILED。SDK 会区分明确的许可证/设备/identity 拒绝与临时网络失败。
网络故障、维护或许可证过期不会立即中断游戏玩法。SDK 将保持基本保护功能,并在下一个可激活的时刻重试 Pro 功能。

OZeroAbortCode 和事件消息

当 OZero 确认安全威胁时,会创建 OZeroSecurityEvent,并传递给 SDK 内置响应流程以及项目注册的回调。事件包含 ModulationType、稳定的公共 OZeroAbortCodeMessageKey、安全英文 MessageWillAbort

Abort Code和消息表

代码 OZeroAbortCode ModulationType MessageKey 信息
0x01MemoryModulationMemoryModulationmemory_modulationProtected memory value changed unexpectedly.
0x02InjectionInjectioninjectionUnexpected module, hook, or runtime injection signal detected.
0x0ABuildIntegrityBuildIntegritybuild_integrityBuild integrity validation failed.
0x0CSpeedOrTimeHackSpeedHackspeed_hackSuspicious time scale or execution speed change detected.
0x0CSpeedOrTimeHackTimeHacktime_hackSystem clock or trusted time anomaly detected.
0x0EDeviceOrInstallPolicyDeviceBindingModulationdevice_bindingDevice binding policy rejected the current device.
0x0EDeviceOrInstallPolicyInstallSourceinstall_sourceApplication install source is not trusted.
0x0FPhysicsHackPhysicsHackphysics_hackAbnormal physics behavior exceeded the configured policy.
0x10EnvironmentModulationEnvironmentModulationenvironment_modulationUnsupported or unsafe runtime environment detected.
0x13SteamAntiPiracySteamAntiPiracysteam_antipiracySteam ownership or ticket validation failed.

创建日志或多语言 UI 时,请使用 OZeroAbortCodeMessageKey 作为参考值。 Message 使用开发人员可以理解的安全表达式,因此可以直接显示在开发人员屏幕或 QA 日志上而没有问题。

处理运行时的安全事件

默认情况下,OZero 会根据 Config Dashboard 的 Response 设置关闭应用,或只留下日志。如果需要显示自己的警告画面、发送服务器日志,或在关闭前保存少量数据,请使用 OZeroSecurityManager.RegisterUserCallback 注册处理程序。

如果 evt.WillAbort 为 true,当前响应策略会在回调流程结束后关闭应用。请只执行 analytics flush 或最终保存这类短操作。回调是事件上报和清理处理的连接点,不是取消 OZero 安全响应的方式。

using OZeroSDK.Security;

void OnEnable()
{
    OZeroSecurityManager.Instance.RegisterUserCallback(OnHack);
}

void OnHack(OZeroSecurityEvent evt)
{
    Debug.LogWarning(
        $"OZero: {evt.Type} {evt.AbortCodeHex} {evt.MessageKey} - {evt.Message}");

    if (evt.WillAbort)
    {
        // Last chance to flush your own analytics or save state.
    }

    Analytics.FlushSync();
}

Injection Detector API OZeroSDK.Security

Injection Detector silenced -> Add to Whitelist workflow
流程:首次检测 -> 添加信任模块条目 -> 您可以在后续扫描中允许该模块处理。

用于把模块注册为 Injection 检查中的可信模块的 API。适用于随游戏一起分发的 overlay、录制工具、运营插件或合作伙伴模块等正常模块,但这些模块可能会被检测命中。HashHex 是该模块文件的 SHA-256 hash,SignerHex 是模块签名证书的 SHA-256 hash。不要猜测这些值,只注册从实际分发文件或诊断结果中确认的值。

数据结构 — OZeroInjectionWhitelistEntry

[Serializable]
public class OZeroInjectionWhitelistEntry
{
    // SHA-256 of the matched module file. Lowercase 64-char hex. Required.
    public string HashHex { get; set; }

    // SHA-256 of the module's signing certificate. Lowercase 64-char hex.
    // Empty ("") means "match by hash only" (only mode for Android .so / Linux ELF).
    public string SignerHex { get; set; }

    // Module file format hint — "pe" | "macho" | "so". Defaults to "so".
    public string Type { get; set; }

    // Optional human-readable note (UI / audit only — never sent to native).
    public string Comment { get; set; }
}

在 Unity 中注册本地可信模块条目时使用的数据结构。HashHex 是必填的 64 字符 SHA-256 文件 hash,SignerHex 是可选的 64 字符 signer fingerprint。Typepemachoso 之一,用于表示模块格式;Comment 是给运营人员看的备注。

运行时 API — OZeroDispatch

// Returns true when trusted-module policy support is available.
public static bool HasInjectionV3 { get; }

// Replace trusted module entries atomically. Pass null/empty to clear.
// Returns false when the runtime support is unavailable.
public static bool RegisterInjectionWhitelistHash(OZeroInjectionWhitelistEntry[] entries);

// Trusted-module aware scan. Returns true when a relevant runtime signal is observed.
// Output fields are diagnostic context for your review and may be empty.
public static bool DetectAssemblyInjectionV3(
    out bool   silencedByWhitelist,
    out string hashHex,
    out string signerHex,
    out string matchedModulePath);

用于在运行时将可信模块列表传递给原生检查器,或确认当前平台是否支持此功能。多数项目只需要 Config Dashboard 中的 Injection 设置。如果必须从代码直接调用,请在分发文件确定后只注册必要条目,并在 QA 日志中确认注册前后的结果。

配置 — OZeroSecurityConfig.InjectionSettings

// Preferred local trusted-module surface in the Injection settings.
public OZeroInjectionWhitelistEntry[] InjectionWhitelistEntries { get; }

InjectionWhitelistEntries 是 Injection 设置中的本地可信模块列表。它不是为了大范围允许客户 PC 上偶然安装的程序,而是用于注册开发商随游戏一起分发并确认正常工作的模块。这个本地列表所有 tier 都可以使用;Pro 客户可以通过客户门户的服务器管理 whitelist 在运营中更新同类策略。