Decompiled source of CrimeTweaker v1.0.3

plugins/CrimeTweaker.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine.UIElements;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CrimeTweaker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+19cc7f8b43c994d1fab6c7a8a15ba34e3aa75061")]
[assembly: AssemblyProduct("CrimeTweaker")]
[assembly: AssemblyTitle("CrimeTweaker")]
[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 CrimeTweaker
{
	[BepInPlugin("IngoH.HardTime.CrimeTweaker", "CrimeTweaker", "1.0.2")]
	[HarmonyPatch]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "IngoH.HardTime.CrimeTweaker";

		public const string PluginName = "CrimeTweaker";

		public const string PluginVer = "1.0.2";

		internal static ManualLogSource Log;

		internal static readonly Harmony Harmony = new Harmony("IngoH.HardTime.CrimeTweaker");

		internal static string PluginPath;

		internal static ConfigEntry<float> OverallCrimeModifier;

		internal static ConfigEntry<float> StarCrimeModifier;

		internal static ConfigEntry<float> AICrimeModifier;

		internal static List<ConfigEntry<float>> PerCrimeModifiers = new List<ConfigEntry<float>>();

		internal static List<string> Crimes = new List<string>(29)
		{
			"insubordination", "conspiracy", "possession", "vandalism", "escaping", "theft", "fornication", "arson", "assault", "assault with a weapon",
			"grievious bodily harm", "attempted murder", "murder", "serial murder", "terrorism", "trespassing", "trading", "freeloading (unused)", "urination/defecation", "tardiness (unused)",
			"truancy", "sleeping", "graffiti (partially unused)", "shoplifting (unused)", "snacking", "reckless driving", "discharging a firearm", "animal abuse", "impersonation"
		};

		private void Awake()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			PluginPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			OverallCrimeModifier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "OverallCrimeModifier", 100f, new ConfigDescription("Changes the overall percent chance of crimes being witnessed.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1E+09f), Array.Empty<object>()));
			StarCrimeModifier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "StarCrimeModifier", 100f, new ConfigDescription("Changes the percent chance of the player being witnessed committing a crime.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1E+09f), Array.Empty<object>()));
			AICrimeModifier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "AICrimeModifier", 100f, new ConfigDescription("Changes the percent chance of AI being witnessed committing a crime.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1E+09f), Array.Empty<object>()));
			foreach (string crime in Crimes)
			{
				PerCrimeModifiers.Add(((BaseUnityPlugin)this).Config.Bind<float>("General", StringUtilsExtensions.ToPascalCase(crime) + "CrimeModifier", 100f, new ConfigDescription("Changes the percent chance of " + crime + " being witnessed.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1E+09f), Array.Empty<object>())));
			}
		}

		private void OnEnable()
		{
			Harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded CrimeTweaker!");
		}

		private void OnDisable()
		{
			Harmony.UnpatchSelf();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Unloaded CrimeTweaker!");
		}

		[HarmonyPatch(typeof(DFOGOCNBECG), "DOLDKPGLHBL")]
		[HarmonyPrefix]
		public static bool DFOGOCNBECG_DOLDKPGLHBL(DFOGOCNBECG __instance, int LMCLGBPJKFM, int NFCNFEIIFMA, int DEGGCDHLFBC, int MKEBAFANECN, ref int KPJANCMHICM)
		{
			double prob = 1.0 / (double)(1 + KPJANCMHICM);
			prob = AdjustProb(__instance, LMCLGBPJKFM, NFCNFEIIFMA, DEGGCDHLFBC, MKEBAFANECN, prob);
			KPJANCMHICM = (int)(1.0 / prob) - 1;
			if ((double)KPJANCMHICM > 1000000.0)
			{
				return false;
			}
			return true;
		}

		private static double AdjustProb(DFOGOCNBECG culprit, int warrant, int victim, int witness, int variable, double prob)
		{
			if (warrant > 0 && warrant <= Crimes.Count)
			{
				Log.LogDebug((object)$"{Characters.c[culprit.GOOKPABIPBC].name} was spotted doing {Crimes[warrant - 1]}! Normal prob: {prob * 100.0}%");
			}
			prob *= (double)(OverallCrimeModifier.Value / 100f);
			prob = ((culprit.GOOKPABIPBC != Characters.star) ? (prob * (double)(AICrimeModifier.Value / 100f)) : (prob * (double)(StarCrimeModifier.Value / 100f)));
			if (warrant > 0 && warrant <= Crimes.Count)
			{
				prob *= (double)(PerCrimeModifiers[warrant - 1].Value / 100f);
			}
			if (prob > 0.9999)
			{
				prob = 1.0;
			}
			if (prob < 0.0001)
			{
				prob = 0.0;
			}
			if (warrant > 0 && warrant <= Crimes.Count)
			{
				Log.LogDebug((object)$"Adjusted prob: {prob * 100.0}%");
			}
			return prob;
		}
	}
}