SetResolutionPatch.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. using EFT.CameraControl;
  2. using HarmonyLib;
  3. namespace PerformanceScope
  4. {
  5. /// <summary>
  6. /// 覆盖游戏传入的镜内分辨率参数。游戏自身 Init() 调用
  7. /// <c>SetResolution(OpticFinalResolution)</c>(初值 1024)时,prefix 会直接改成目标值,
  8. /// 从而避免先建 1024 再重建造成的闪烁。
  9. /// Overrides the scope resolution argument passed by the game. When the game's own Init() calls
  10. /// <c>SetResolution(OpticFinalResolution)</c> (initial value 1024), the prefix replaces it with the target value,
  11. /// avoiding the flicker caused by creating 1024 first and then rebuilding.
  12. /// </summary>
  13. [HarmonyPatch(typeof(OpticCameraManager), nameof(OpticCameraManager.SetResolution))]
  14. internal static class SetResolutionPatch
  15. {
  16. // HarmonyWrapSafe:prefix 抛异常时包裹并跳过原方法而非中断游戏 Init 流程。
  17. // HarmonyWrapSafe: if the prefix throws, wrap it and skip the original method instead of aborting the game's Init flow.
  18. [HarmonyWrapSafe]
  19. [HarmonyPrefix]
  20. private static void Prefix(ref int resolution)
  21. {
  22. OpticResolutionService service = OpticResolutionService.Instance;
  23. if (service == null)
  24. {
  25. // 插件尚未初始化完成,保持游戏原值透传。
  26. // The plugin has not finished initializing; pass the game's original value through.
  27. return;
  28. }
  29. resolution = service.ComputeTarget();
  30. }
  31. }
  32. }