Decompiled source of FpsProtector v1.0.3

FPSProtector.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FPSProtector")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FPSProtector")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("22648583-abaa-4c2a-b94d-a7c56c4dd87b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ZNetSceneNREFix;

[BepInPlugin("com.shaya.nrefix", "FPSProtector", "1.0.3")]
public class NREFixPlugin : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("com.shaya.fpsprotector");

	private void Awake()
	{
		harmony.PatchAll();
		Debug.Log((object)"FPSProtector v1.0.3 loaded safely via Finalizer. Shielding framerate from missing prefabs and ghost objects.");
	}
}
[HarmonyPatch(typeof(ZNetScene), "RemoveObjects")]
public class ZNetScene_RemoveObjects_SafePatch
{
	private static Exception Finalizer(Exception __exception)
	{
		return null;
	}
}
[HarmonyPatch(typeof(ZNetScene), "CreateObject")]
public class ZNetScene_CreateObject_Patch
{
	private static readonly HashSet<int> missingHashes = new HashSet<int>();

	private static bool Prefix(ZNetScene __instance, ref GameObject __result, ZDO zdo)
	{
		int prefab = zdo.GetPrefab();
		if (prefab == 0)
		{
			return true;
		}
		if (missingHashes.Contains(prefab))
		{
			__result = null;
			return false;
		}
		if ((Object)(object)__instance.GetPrefab(prefab) == (Object)null)
		{
			missingHashes.Add(prefab);
			Debug.LogWarning((object)$"[FPSProtector] Prefab hash {prefab} is missing. Blacklisting to protect FPS.");
			__result = null;
			return false;
		}
		return true;
	}
}