Decompiled source of NoPolice v1.0.0

NoPolice.dll

Decompiled 8 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using MelonLoader;
using Microsoft.CodeAnalysis;
using NoPolice;
using NoPolice.Patches;
using NoPolice.Utils;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "NoPolice", "1.0.0", "HazDS", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NoPolice")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NoPolice")]
[assembly: AssemblyTitle("NoPolice")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NoPolice
{
	public class Core : MelonMod
	{
		private Harmony _harmony;

		private int _patchedCount;

		public override void OnInitializeMelon()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			_harmony = new Harmony("com.nopolice.patches");
			_patchedCount = 0;
			PatchLawActivitySettings();
			PatchLawManager();
			PatchPoliceStation();
			PatchPoliceOfficer();
			MelonLogger.Msg(string.Format("{0} v{1} loaded! ({2} patches applied)", "NoPolice", "1.0.0", _patchedCount));
		}

		private void PatchLawActivitySettings()
		{
			Type type = CrossCompat.FindType("ScheduleOne.Law.LawActivitySettings");
			if (type == null)
			{
				MelonLogger.Error("Failed to find LawActivitySettings type");
			}
			else
			{
				PatchMethod(type, "Evaluate", "Evaluate_Prefix");
			}
		}

		private void PatchLawManager()
		{
			Type type = CrossCompat.FindType("ScheduleOne.Law.LawManager");
			if (type == null)
			{
				MelonLogger.Error("Failed to find LawManager type");
			}
			else
			{
				PatchMethod(type, "PoliceCalled", "PoliceCalled_Prefix");
			}
		}

		private void PatchPoliceStation()
		{
			Type type = CrossCompat.FindType("ScheduleOne.Map.PoliceStation");
			if (type == null)
			{
				MelonLogger.Error("Failed to find PoliceStation type");
			}
			else
			{
				PatchMethod(type, "Dispatch", "Dispatch_Prefix");
			}
		}

		private void PatchPoliceOfficer()
		{
			Type type = CrossCompat.FindType("ScheduleOne.Police.PoliceOfficer");
			if (type == null)
			{
				MelonLogger.Error("Failed to find PoliceOfficer type");
				return;
			}
			PatchMethod(type, "BeginFootPursuit_Networked", "BeginFootPursuit_Prefix");
			PatchMethod(type, "BeginVehiclePursuit_Networked", "BeginVehiclePursuit_Prefix");
			PatchMethod(type, "BeginBodySearch_Networked", "BeginBodySearch_Prefix");
			PatchMethod(type, "CheckNewInvestigation", "CheckNewInvestigation_Prefix");
		}

		private void PatchMethod(Type targetType, string methodName, string prefixMethodName)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			try
			{
				MethodInfo method = targetType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method == null)
				{
					MelonLogger.Warning("Method not found: " + targetType.Name + "." + methodName);
					return;
				}
				MethodInfo method2 = typeof(PolicePatches).GetMethod(prefixMethodName, BindingFlags.Static | BindingFlags.Public);
				if (method2 == null)
				{
					MelonLogger.Error("Prefix method not found: " + prefixMethodName);
					return;
				}
				_harmony.Patch((MethodBase)method, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_patchedCount++;
			}
			catch (Exception ex)
			{
				MelonLogger.Error("Failed to patch " + targetType.Name + "." + methodName + ": " + ex.Message);
				MelonLogger.Error("Stack trace: " + ex.StackTrace);
			}
		}
	}
}
namespace NoPolice.Utils
{
	public static class Constants
	{
		public static class Game
		{
			public const string GAME_STUDIO = "TVGS";

			public const string GAME_NAME = "Schedule I";
		}

		public const string MOD_NAME = "NoPolice";

		public const string MOD_VERSION = "1.0.0";

		public const string MOD_AUTHOR = "HazDS";

		public const string HARMONY_ID = "com.nopolice.patches";
	}
	public static class CrossCompat
	{
		public static Type FindType(string fullName)
		{
			string name = (fullName.StartsWith("ScheduleOne") ? ("Il2Cpp" + fullName) : fullName);
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				Type type = assembly.GetType(fullName) ?? assembly.GetType(name);
				if (type != null)
				{
					return type;
				}
			}
			return null;
		}
	}
}
namespace NoPolice.Patches
{
	public static class PolicePatches
	{
		public static bool Evaluate_Prefix()
		{
			return false;
		}

		public static bool PoliceCalled_Prefix()
		{
			return false;
		}

		public static bool Dispatch_Prefix()
		{
			return false;
		}

		public static bool BeginFootPursuit_Prefix()
		{
			return false;
		}

		public static bool BeginVehiclePursuit_Prefix()
		{
			return false;
		}

		public static bool BeginBodySearch_Prefix()
		{
			return false;
		}

		public static bool CheckNewInvestigation_Prefix()
		{
			return false;
		}
	}
}