Decompiled source of BreedingTweaks v1.1.0

plugins/BreedingTweaks.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BreedingTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BreedingTweaks")]
[assembly: AssemblyCopyright("Copyright \ufffd  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
namespace BreedingTweaks;

[BepInPlugin("BreedingTweaks", "BreedingTweaks", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class BreedingTweaks : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Procreation), "Awake")]
	public class Procreation_Awake_Patch
	{
		private static void Postfix(Procreation __instance, ref int ___m_maxCreatures)
		{
			if (Configs.TryGetCustomCreatureCount(Utils.GetPrefabName(((Component)__instance).gameObject), out var count))
			{
				___m_maxCreatures = count;
			}
			else if (Configs.MaxCreaturesCount.Value != 4)
			{
				___m_maxCreatures = Configs.MaxCreaturesCount.Value;
			}
		}
	}

	[HarmonyPatch(typeof(Procreation), "Procreate")]
	public class Procreation_Procreate_Patch
	{
		private static int storedMinOffspringLevel;

		private static void Prefix(Character ___m_character, ref int ___m_minOffspringLevel)
		{
			if (Configs.ChanceForOneLevelHigher.Value != 0)
			{
				storedMinOffspringLevel = ___m_minOffspringLevel;
				int level = ___m_character.GetLevel();
				if (level < Configs.MaxCreatureLevel.Value && Random.Range(0f, 1f) <= (float)Configs.ChanceForOneLevelHigher.Value / 100f)
				{
					___m_minOffspringLevel = level + 1;
				}
			}
		}

		private static void Postfix(ref int ___m_minOffspringLevel)
		{
			if (Configs.ChanceForOneLevelHigher.Value != 0)
			{
				___m_minOffspringLevel = storedMinOffspringLevel;
			}
		}
	}

	public const string PluginGUID = "BreedingTweaks";

	public const string PluginName = "BreedingTweaks";

	public const string PluginVersion = "1.1.0";

	private static Harmony harmony;

	private void Awake()
	{
		Configs.SetupConfigs(((BaseUnityPlugin)this).Config);
		harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "BreedingTweaks");
	}

	private void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}
}
public static class Configs
{
	public static ConfigEntry<int> ChanceForOneLevelHigher;

	public static ConfigEntry<int> MaxCreatureLevel;

	public static ConfigEntry<int> MaxCreaturesCount;

	public static ConfigEntry<string> CustomCreatureCounts;

	public static ConfigurationManagerAttributes IsAdminOnly = new ConfigurationManagerAttributes
	{
		IsAdminOnly = true
	};

	public static void SetupConfigs(ConfigFile config)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Expected O, but got Unknown
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Expected O, but got Unknown
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Expected O, but got Unknown
		ChanceForOneLevelHigher = config.Bind<int>("General", GenerateConfigKey("ChanceForOneLevelHigher", "%"), 10, new ConfigDescription("Determines the chance that newborn offspring will be one level higher than its parent.\nVanilla default value: 0%.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), new object[1] { IsAdminOnly }));
		MaxCreatureLevel = config.Bind<int>("General", GenerateConfigKey("MaxCreatureLevel"), 3, new ConfigDescription("Determines the maximum level of newborn offspring.\nVanilla default value: 3 (2 stars).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 20), new object[1] { IsAdminOnly }));
		MaxCreaturesCount = config.Bind<int>("General", GenerateConfigKey("MaxCreaturesCount"), 8, new ConfigDescription("Determines the maximum number of creatures per cubic space.\nA cubic space means within 10 meters of the creature. Before procreating, it counts nearby creatures and will not procreate if the count meets or exceeds this limit (e.g. 8 nearby creatures with a limit of 8).\nVanilla default value: 4.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 40), new object[1] { IsAdminOnly }));
		CustomCreatureCounts = config.Bind<string>("General", GenerateConfigKey("CustomCreatureCounts"), string.Empty, new ConfigDescription("Sets maximum nearby creature counts for specific creature prefabs.\n\nUsage: prefab_name:count,prefab_name:count\nExample: Wolf:7,Boar:3\n\n- Listed prefabs override Max Creatures Count.\n- Unlisted prefabs use Max Creatures Count.\n- Leave empty to use the global limit for all creatures.\n- Use prefab names, not translated names (case-insensitive).\n- Use whole numbers from 2 to 40.\n- Separate entries with commas.\n- Invalid entries are ignored; first valid entry wins.\n- Applies on spawn or load; reload the world for existing creatures.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true,
			Order = -1,
			CustomDrawer = TextAreaDrawer
		} }));
	}

	public static bool TryGetCustomCreatureCount(string prefabName, out int count)
	{
		string[] array = CustomCreatureCounts.Value.Split(new char[1] { ',' });
		for (int i = 0; i < array.Length; i++)
		{
			string[] array2 = array[i].Split(new char[1] { ':' });
			if (array2.Length == 2 && string.Equals(array2[0].Trim(), prefabName, StringComparison.OrdinalIgnoreCase) && int.TryParse(array2[1].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out count) && count >= 2 && count <= 40)
			{
				return true;
			}
		}
		count = 0;
		return false;
	}

	public static string GenerateConfigKey(string key)
	{
		return GenerateConfigKey(key, null);
	}

	public static string GenerateConfigKey(string key, string unit)
	{
		key = string.Concat(key.Select((char x) => (!char.IsUpper(x)) ? x.ToString() : (" " + x))).TrimStart(new char[1] { ' ' });
		if (!string.IsNullOrEmpty(unit))
		{
			key += $" ({unit})";
		}
		return key;
	}

	private static void TextAreaDrawer(ConfigEntryBase entry)
	{
		entry.BoxedValue = GUILayout.TextArea((string)entry.BoxedValue, (GUILayoutOption[])(object)new GUILayoutOption[3]
		{
			GUILayout.ExpandWidth(true),
			GUILayout.ExpandHeight(true),
			GUILayout.MinHeight(80f)
		});
	}

	public static ConfigurationManagerAttributes SetOrder(int order, bool isAdminOnly = true)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		return new ConfigurationManagerAttributes
		{
			Order = order,
			IsAdminOnly = isAdminOnly
		};
	}
}