Decompiled source of CreatureGenetics v0.0.1

CreatureGenetics.dll

Decompiled 13 hours ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CreatureGenetics;
using CreatureGenetics.RPC;
using CreatureLevelControl;
using HarmonyLib;
using JetBrains.Annotations;
using LocalizationManager;
using Microsoft.CodeAnalysis;
using MonsterModifiers;
using MonsterModifiers.Custom_Components;
using Patches;
using ServerSync;
using StarLevelSystem;
using StarLevelSystem.Data;
using StarLevelSystem.common;
using StarLevelSystem.modules;
using StarLevelSystem.modules.Health;
using StarLevelSystem.modules.Sizes;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.ObjectPool;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Callbacks;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LetMeTameYou")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyProduct("LetMeTameYou")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: Guid("d8b8b522-7ea7-41eb-a21a-d076e3ab8dc5")]
[assembly: ComVisible(false)]
[assembly: AssemblyCompany("")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Patches
{
	internal class BetterRiding
	{
		public static void removeGrowupPatch()
		{
			MethodInfo method = AccessTools.Method(typeof(Growup), "GrowUpdate", (Type[])null, (Type[])null);
			Utils.RemovePatch(method, isPrefix: true, new string[1] { "Yggdrah.BetterRiding/Prefix" });
		}

		public static void InheritOwnership(Character childChar, Character adultChar)
		{
			if ((Object)(object)childChar == (Object)null || (Object)(object)adultChar == (Object)null || (Object)(object)childChar.m_nview == (Object)null || (Object)(object)adultChar.m_nview == (Object)null || !childChar.m_nview.IsValid() || !adultChar.m_nview.IsValid())
			{
				return;
			}
			ZDO zDO = childChar.m_nview.GetZDO();
			ZDO zDO2 = adultChar.m_nview.GetZDO();
			if (zDO != null && zDO2 != null)
			{
				long num = zDO.GetLong("playerID", 0L);
				string text = zDO.GetString("ownerName", "");
				if (num != 0)
				{
					zDO2.Set("playerID", num);
					zDO2.Set("ownerName", text);
					DBG.blogDebug($"[BetterRiding] Ownership transferred to grown creature: {text} ({num})");
				}
			}
		}
	}
	public class CLLC
	{
		public enum Effect_CLLC
		{
			None,
			Aggressive,
			Quick,
			Regenerating,
			Curious,
			Splitting,
			Armored
		}

		public enum Infusion_CLLC
		{
			None,
			Lightning,
			Fire,
			Frost,
			Poison,
			Chaos,
			Spirit
		}

		private static bool SetCLLCData(Character character, string key, string val)
		{
			if (Object.op_Implicit((Object)(object)character.m_nview))
			{
				return true;
			}
			ItemDrop component = ((Component)character).gameObject.GetComponent<ItemDrop>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				DBG.blogDebug("No item Drop");
				return true;
			}
			Utils.addOrUpdateCustomData(component.m_itemData.m_customData, key, val);
			DBG.blogDebug("Added " + key + " to ItemDrop, skipping set creature with " + key + ": " + val);
			return false;
		}

		private static Effect_CLLC TryGetExtraEffect(Character thisChar)
		{
			if (Object.op_Implicit((Object)(object)thisChar.m_nview))
			{
				return GetExtraEffectCreature(thisChar);
			}
			string value = ((Component)thisChar).gameObject.GetComponent<ItemDrop>().m_itemData.m_customData["ExtraEffect"];
			if (!Enum.TryParse<Effect_CLLC>(value, out var result))
			{
				result = Effect_CLLC.None;
			}
			return result;
		}

		private static Infusion_CLLC TryGetInfusion(Character thisChar)
		{
			if (Object.op_Implicit((Object)(object)thisChar.m_nview))
			{
				return GetInfusionCreature(thisChar);
			}
			string value = ((Component)thisChar).gameObject.GetComponent<ItemDrop>().m_itemData.m_customData["Infusion"];
			if (!Enum.TryParse<Infusion_CLLC>(value, out var result))
			{
				result = Infusion_CLLC.None;
			}
			return result;
		}

		public static int inheritValue(int mom_val, int dad_val)
		{
			if (mom_val != 0 || dad_val != 0)
			{
				int num = Random.Range(0, 100);
				if (num > 60)
				{
					DBG.blogDebugExtra("IsDadVal");
					return dad_val;
				}
				if (num > 20)
				{
					DBG.blogDebugExtra("IsMomVal");
					return mom_val;
				}
				DBG.blogDebugExtra("IsNoVal");
			}
			return 0;
		}

		public static bool SetInfusionExtraEffect(GameObject go, Genetics motherGenes, bool isEgg)
		{
			DBG.blogDebug("In infusion effect combine");
			Character component = ((Component)motherGenes).GetComponent<Character>();
			Genetics.GeneticPkg partnerPkg = motherGenes.partnerPkg;
			bool flag = false;
			bool flag2 = false;
			if (API.IsExtraEffectEnabled())
			{
				flag2 = true;
			}
			else
			{
				DBG.blogDebug("NoExtraEffectEnabled");
			}
			if (API.IsInfusionEnabled())
			{
				flag = true;
			}
			else
			{
				DBG.blogDebug("NoinfusionEnabled");
			}
			if (!flag && !flag2)
			{
				DBG.blogDebug("SkippingCLLC");
				return false;
			}
			Effect_CLLC extraEffectCreature = GetExtraEffectCreature(component);
			Infusion_CLLC infusionCreature = GetInfusionCreature(component);
			int level = component.GetLevel();
			int lvl = partnerPkg.lvl;
			Effect_CLLC effect = partnerPkg.effect;
			Infusion_CLLC infusion = partnerPkg.infusion;
			Character component2;
			if (isEgg)
			{
				DBG.blogDebug("Set Infusion/Effect of Egg");
				GameObject val = Object.Instantiate<GameObject>(go.GetComponent<EggGrow>().m_grownPrefab, global::CreatureGenetics.CreatureGenetics.Root.transform);
				component2 = val.GetComponent<Character>();
				DBG.blogDebug("Clone Char of Egg=" + Object.op_Implicit((Object)(object)component2));
				ZNetView component3 = ((Component)component2).GetComponent<ZNetView>();
				if (!component3.IsValid() || !component3.IsOwner())
				{
					((Component)component2).gameObject.AddComponent<ItemDrop>();
				}
			}
			else
			{
				component2 = go.GetComponent<Character>();
			}
			component2.m_level = Mathf.RoundToInt((float)((level + lvl) / 2));
			Effect_CLLC effect_CLLC = Effect_CLLC.None;
			Infusion_CLLC infusion_CLLC = Infusion_CLLC.None;
			int num = -1;
			int num2 = -1;
			if (global::CreatureGenetics.CreatureGenetics.allowEffectsMutation.Value)
			{
				if (flag2 && (float)Random.Range(0, 100) < global::CreatureGenetics.CreatureGenetics.MutationChanceEffects.Value)
				{
					num2 = 0;
				}
				if (flag && (float)Random.Range(0, 100) < global::CreatureGenetics.CreatureGenetics.MutationChanceEffects.Value)
				{
					num = 0;
				}
				for (int i = 0; i < 25; i++)
				{
					if (num2 != 0 && num != 0)
					{
						break;
					}
					DBG.blogDebug("i=" + i);
					if (num2 == 0)
					{
						API.SetExtraEffectCreature(component2);
						Effect_CLLC effect_CLLC2 = TryGetExtraEffect(component2);
						if (effect_CLLC2 != extraEffectCreature && effect_CLLC2 != effect && effect_CLLC2 != Effect_CLLC.None)
						{
							DBG.blogDebug("Effect(" + i + ")=" + effect_CLLC2);
							DBG.blogDebug("Has Mutation in Effect");
							effect_CLLC = effect_CLLC2;
							num2 = 1;
						}
					}
					if (num == 0)
					{
						API.SetInfusionCreature(component2);
						Infusion_CLLC infusion_CLLC2 = TryGetInfusion(component2);
						if (infusion_CLLC2 != infusionCreature && infusion_CLLC2 != infusion && infusion_CLLC2 != Infusion_CLLC.None)
						{
							DBG.blogDebug("Infusion(" + i + ")=" + infusion_CLLC2);
							DBG.blogDebug("Has Mutation in Infusion");
							infusion_CLLC = infusion_CLLC2;
							num = 1;
						}
					}
				}
			}
			if (num2 < 0)
			{
				DBG.blogDebug("inherit Effect");
				effect_CLLC = (Effect_CLLC)inheritValue((int)extraEffectCreature, (int)effect);
			}
			if (num < 0)
			{
				DBG.blogDebug("inherit Infusion");
				infusion_CLLC = (Infusion_CLLC)inheritValue((int)infusionCreature, (int)infusion);
			}
			if (!isEgg)
			{
				SetExtraEffectCreature(component2, effect_CLLC);
				SetInfusionCreature(component2, infusion_CLLC);
			}
			else
			{
				DBG.blogDebug("Effect=" + effect_CLLC);
				DBG.blogDebug("Infusion=" + infusion_CLLC);
				ItemDrop component4 = go.GetComponent<ItemDrop>();
				ItemData itemData = component4.m_itemData;
				Utils.addOrUpdateCustomData(itemData.m_customData, "ExtraEffect", effect_CLLC.ToString());
				Utils.addOrUpdateCustomData(itemData.m_customData, "Infusion", infusion_CLLC.ToString());
				if ((int)effect_CLLC + (int)infusion_CLLC > 0)
				{
					return true;
				}
			}
			return false;
		}

		public static Effect_CLLC iDropGetEff(ItemDrop iDrop)
		{
			Effect_CLLC result = Effect_CLLC.None;
			if (!Object.op_Implicit((Object)(object)iDrop))
			{
				return result;
			}
			DBG.blogDebug("Has iDrop");
			if (iDrop.m_itemData.m_customData.TryGetValue("ExtraEffect", out var value))
			{
				DBG.blogDebug("Custom Value=" + value);
				if (Enum.TryParse<Effect_CLLC>(value, out var result2))
				{
					DBG.blogDebug("GotEffect=" + result2);
					result = result2;
				}
			}
			return result;
		}

		public static Infusion_CLLC iDropGetInf(ItemDrop iDrop)
		{
			Infusion_CLLC result = Infusion_CLLC.None;
			if (!Object.op_Implicit((Object)(object)iDrop))
			{
				return result;
			}
			if (iDrop.m_itemData.m_customData.TryGetValue("Infusion", out var value))
			{
				DBG.blogDebug("Custom Value=" + value);
				if (Enum.TryParse<Infusion_CLLC>(value, out var result2))
				{
					DBG.blogDebug("GotInfusion=" + result2);
					result = result2;
				}
			}
			return result;
		}

		public static Infusion_CLLC GetInfusionCreature(Character character)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected I4, but got Unknown
			return (Infusion_CLLC)API.GetInfusionCreature(character);
		}

		public static Effect_CLLC GetExtraEffectCreature(Character character)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected I4, but got Unknown
			return (Effect_CLLC)API.GetExtraEffectCreature(character);
		}

		public static void SetInfusionCreature(Character character, Infusion_CLLC infusion)
		{
			API.SetInfusionCreature(character, (CreatureInfusion)infusion);
		}

		public static void SetExtraEffectCreature(Character character, Effect_CLLC infusion)
		{
			API.SetExtraEffectCreature(character, (CreatureExtraEffect)infusion);
		}

		public static bool CheckCLLC()
		{
			try
			{
				return API.IsEnabled();
			}
			catch
			{
				return false;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(API), "SetExtraEffectCreature", new Type[]
		{
			typeof(Character),
			typeof(CreatureExtraEffect)
		})]
		private unsafe static bool Prefix_API_SetExtraEffect(Character character, CreatureExtraEffect effect)
		{
			return SetCLLCData(character, "ExtraEffect", ((object)(*(CreatureExtraEffect*)(&effect))/*cast due to .constrained prefix*/).ToString());
		}

		[HarmonyPatch(typeof(API), "SetInfusionCreature", new Type[]
		{
			typeof(Character),
			typeof(CreatureInfusion)
		})]
		[HarmonyPrefix]
		private unsafe static bool Prefix_API_SetInfusionCreature(Character character, CreatureInfusion infusion)
		{
			return SetCLLCData(character, "Infusion", ((object)(*(CreatureInfusion*)(&infusion))/*cast due to .constrained prefix*/).ToString());
		}
	}
	public class MonMod_CG
	{
		public enum CG_MonsterModifierTypes
		{
			StaminaSiphon,
			EitrSiphon,
			ShieldBreaker,
			FoodDrain,
			IgnoreArmor,
			PoisonDeath,
			FrostDeath,
			FireDeath,
			PersonalShield,
			ShieldDome,
			SoulEater,
			RemoveStatusEffect,
			StaggerImmune,
			FireInfused,
			PoisonInfused,
			FrostInfused,
			LightningInfused,
			ElementalImmunity,
			PhysicalImmunity,
			FastMovement,
			FastAttackSpeed,
			DistantDetection
		}

		public static string CreateChildModifiers(string mom_Mod, string dad_Mod, int level)
		{
			if (level <= 1)
			{
				return "";
			}
			string text = string.Empty;
			if (!string.IsNullOrEmpty(mom_Mod))
			{
				text = text + mom_Mod + (mom_Mod.EndsWith(",") ? "" : ",");
			}
			if (!string.IsNullOrEmpty(dad_Mod))
			{
				text += dad_Mod;
			}
			DBG.blogDebug("combinedstring=" + text);
			text = text.TrimEnd(',', ' ');
			List<string> combinedList = text.Split(new char[1] { ',' }).ToList();
			List<string> list = combinedList.Distinct().ToList();
			int num = combinedList.Count - list.Count;
			int num2 = 0;
			foreach (string item in list)
			{
				num2 += (item.Contains("Immunity") ? 1 : 0);
			}
			DBG.blogDebug("immunityCount=" + num2);
			if (num2 > 3)
			{
				DBG.blogDebug("All Immunities, adding one dupe");
				num++;
			}
			combinedList.Remove("");
			DBG.blogDebug("count=" + combinedList.Count + "dups:=" + num);
			if (combinedList.Count - num < level - 1)
			{
				addNewMonMod(ref combinedList, level + num);
			}
			int num3 = 0;
			if (global::CreatureGenetics.CreatureGenetics.allowEffectsMutation.Value && (float)Random.Range(0, 100) < global::CreatureGenetics.CreatureGenetics.MutationChanceEffects.Value)
			{
				num3 = 1;
				addNewMonMod(ref combinedList, level + num, mutation: true);
			}
			int num4 = combinedList.Count;
			int i = num3;
			while (i < level - 1 + num)
			{
				int index = Random.Range(i, num4);
				string value = combinedList[i];
				combinedList[i] = combinedList[index];
				combinedList[index] = value;
				if (num2 > 3 && combinedList[i].Contains("Immunity"))
				{
					DBG.blogDebug("Immunity string(" + i + ")=" + string.Join(",", combinedList.ToArray()));
					int num5 = combinedList.RemoveAll((string x) => x == combinedList[i]);
					num -= num5;
					num4 -= num5;
					num2--;
				}
				DBG.blogDebug("shuffled string(" + i + ":count:" + num4 + ")=" + string.Join(",", combinedList.ToArray()));
				int num6 = i + 1;
				i = num6;
			}
			list = combinedList.Distinct().ToList();
			DBG.blogDebug("distinct string=" + string.Join(",", list.ToArray()));
			string text2 = string.Join(",", list.Take(level - 1).ToArray());
			DBG.blogDebug("cutsring=" + text2);
			return text2;
		}

		private static List<string> internal_RollModifiers(int amount)
		{
			List<string> list = new List<string>();
			try
			{
				MethodInfo method = typeof(ModifierUtils).GetMethod("RollRandomModifiers", BindingFlags.Static | BindingFlags.Public);
				object obj = method.Invoke(null, new object[1] { amount });
				foreach (object item in (IEnumerable)obj)
				{
					list.Add(item.ToString());
				}
			}
			catch (Exception ex)
			{
				DBG.blogDebug("Roll Mon Mod Error: " + ex.Message);
			}
			return list;
		}

		private static void addNewMonMod(ref List<string> combinedList, int level, bool mutation = false)
		{
			bool flag = false;
			if (mutation)
			{
				DBG.blogDebug("mutation combindlist=" + string.Join(",", combinedList.ToArray()));
				for (int i = 0; i < 5; i++)
				{
					if (!mutation)
					{
						break;
					}
					List<string> list = internal_RollModifiers(7);
					foreach (string item in list)
					{
						DBG.blogDebug("typeM=" + item);
						if (!combinedList.Contains(item.ToString()))
						{
							combinedList.Insert(0, item.ToString());
							mutation = false;
							break;
						}
					}
				}
				if (!mutation)
				{
					DBG.blogDebug("Mutation in MonMod: added " + combinedList[0]);
				}
				else
				{
					DBG.blogDebug("Failed Mutation in MonMod");
				}
			}
			for (int j = 0; j < 15; j++)
			{
				DBG.blogDebug("(" + j + ") combindlist=" + string.Join(",", combinedList.ToArray()));
				if (combinedList.Count >= level - 1)
				{
					flag = true;
					DBG.blogDebug("filledlist");
					break;
				}
				List<string> list2 = internal_RollModifiers(level - combinedList.Count - 1);
				foreach (string item2 in list2)
				{
					DBG.blogDebug("type=" + item2);
					if (!combinedList.Contains(item2.ToString()))
					{
						combinedList.Add(item2.ToString());
					}
				}
			}
			if (!flag)
			{
				combinedList = internal_RollModifiers(level - 1);
				DBG.blogDebug("backup combindlist=" + string.Join(",", combinedList.ToArray()));
			}
		}

		public static void SetModifiers(Character character, string MonMod)
		{
			MonsterModifier val = default(MonsterModifier);
			if (((Component)character).TryGetComponent<MonsterModifier>(ref val))
			{
				if (Object.op_Implicit((Object)(object)val.character))
				{
					DBG.blogDebug("MonMod has started");
				}
				character.m_nview.GetZDO().Set("modifiers", MonMod);
				DBG.blogDebug("MonMod has been set");
				DBG.blogDebug("MonMod is:" + character.m_nview.GetZDO().GetString("modifiers", string.Empty));
			}
			else
			{
				DBG.blogDebug("No Mon Mod");
			}
		}

		public static string getModifiers(Character character)
		{
			string text = "";
			MonsterModifier val = default(MonsterModifier);
			if (((Component)character).TryGetComponent<MonsterModifier>(ref val))
			{
				text = string.Join(",", val.Modifiers);
				DBG.blogDebug("got modifiers from component: " + text);
			}
			else
			{
				text = character.m_nview.GetZDO().GetString("modifiers", string.Empty) ?? "";
				DBG.blogDebug("got modifiers from zdo: " + text);
			}
			return text;
		}
	}
	public class SLS_CG
	{
		public enum ModifierType
		{
			Major,
			Minor,
			Boss
		}

		public static string getModifiers(Character character)
		{
			Dictionary<string, int> creaturesModifiers = API.GetCreaturesModifiers(character);
			DBG.blogDebug("SLS found " + creaturesModifiers.Count + " modifiers:");
			string text = "";
			foreach (KeyValuePair<string, int> item in creaturesModifiers)
			{
				DBG.blogDebugExtra("SLS Modifier=" + item.Key + ":" + item.Value);
				if (item.Key == "None")
				{
					DBG.blogDebugExtra("SLS skip Modifier: " + item.Key);
					continue;
				}
				text = text + item.Key + ":" + item.Value + ",";
			}
			if (text.Length > 1)
			{
				text.Trim(',', ' ');
			}
			DBG.blogDebug("SLS_Modifiers=" + text);
			return text;
		}

		public static void SetModifiers(Character character, string SLS_Str)
		{
			if ((SLS_Str ?? "") == "")
			{
				DBG.blogDebug("No Modifiers to set, skipping");
				return;
			}
			List<string> list = SLS_Str.Split(new char[1] { ',' }).ToList();
			for (int i = 0; i < list.Count; i++)
			{
				string[] array = list[i].Split(new char[1] { ':' });
				if (array.Length < 2)
				{
					array = new string[2]
					{
						array[0],
						"0"
					};
				}
				if (!int.TryParse(array[1], out var result))
				{
					DBG.blogDebug("Value not valid int:" + array[1]);
					result = 0;
				}
				DBG.blogDebug("Attempting to add sls mod:" + string.Join(",", array));
				API.AddModifierToTargetCreature(character, array[0], result, i == list.Count - 1);
				DBG.blogDebug("Added sls mod:" + string.Join(",", array));
				DBG.blogDebug("current Modifiers=" + getModifiers(character));
			}
		}

		public static string CreateChildModifiers(string mom_SLS, string dad_SLS, int level)
		{
			if (level <= 1)
			{
				return "";
			}
			string text = string.Empty;
			int[] array = new int[3];
			int[] array2 = new int[3];
			if (!string.IsNullOrEmpty(mom_SLS))
			{
				text = text + mom_SLS + (mom_SLS.EndsWith(",") ? "" : ",");
				array[0] = mom_SLS.Count((char x) => x == '0');
				array[1] = mom_SLS.Count((char x) => x == '1');
				array[2] = mom_SLS.Count((char x) => x == '2');
				Array.Copy(array, array2, array.Length);
			}
			if (!string.IsNullOrEmpty(dad_SLS))
			{
				text += dad_SLS;
				array[0] = Math.Max(array[0], dad_SLS.Count((char x) => x == '0'));
				array[1] = Math.Max(array[1], dad_SLS.Count((char x) => x == '1'));
				array[2] = Math.Max(array[2], dad_SLS.Count((char x) => x == '2'));
				array2[0] = Math.Min(array2[0], dad_SLS.Count((char x) => x == '0'));
				array2[1] = Math.Min(array2[1], dad_SLS.Count((char x) => x == '1'));
				array2[2] = Math.Min(array2[2], dad_SLS.Count((char x) => x == '2'));
			}
			else
			{
				array2 = new int[3];
			}
			DBG.blogDebug("SLS: All Possible Modifiers=" + text);
			int[] values = new int[3]
			{
				Math.Max(ValConfig.MaxMajorModifiersPerCreature.Value, array[0]),
				Math.Max(ValConfig.MaxMinorModifiersPerCreature.Value, array[1]),
				Math.Max(ValConfig.MaxBossModifiersPerBoss.Value, array[2])
			};
			DBG.blogDebugExtra("currentParentMods=" + string.Join(",", array));
			DBG.blogDebugExtra("minParentMods=" + string.Join(",", array2));
			DBG.blogDebugExtra("maxMods=" + string.Join(",", values));
			text = text.TrimEnd(',', ' ');
			List<string> list = text.Split(new char[1] { ',' }).ToList();
			list.Remove("");
			int count = list.Count;
			string[][] array3 = new string[3][]
			{
				list.Where((string x) => x.Contains("0")).Distinct().ToArray(),
				list.Where((string x) => x.Contains("1")).Distinct().ToArray(),
				list.Where((string x) => x.Contains("2")).Distinct().ToArray()
			};
			DBG.blogDebugExtra("Major modsMatrix[0]=" + string.Join(",", array3[0]));
			DBG.blogDebugExtra("Minor modsMatrix[1]=" + string.Join(",", array3[1]));
			DBG.blogDebugExtra("Boss modsMatrix[2]=" + string.Join(",", array3[2]));
			List<string> newMods = new List<string>();
			int num = ((array[2] <= 0) ? 1 : 2);
			int num2 = Random.Range(0, num - 1);
			bool flag = global::CreatureGenetics.CreatureGenetics.allowEffectsMutation.Value && (float)Random.Range(0, 100) < global::CreatureGenetics.CreatureGenetics.MutationChanceEffects.Value;
			if (flag)
			{
				ModifierType modifierType = (ModifierType)num2;
				DBG.blogDebug("Has add mutation of type=" + modifierType);
				array2[num2] = array[num2];
			}
			for (int num3 = 0; num3 < 3; num3++)
			{
				ModifierType modifierType;
				if (array[num3] == 0)
				{
					modifierType = (ModifierType)num3;
					DBG.blogDebugExtra("none of type=" + modifierType);
					continue;
				}
				count = array3[num3].Length;
				if (count > array2[num3])
				{
					modifierType = (ModifierType)num3;
					DBG.blogDebugExtra("shuffle list of type=" + modifierType);
					for (int num4 = 0; num4 < count; num4++)
					{
						int num5 = Random.Range(num4, count);
						ref string reference = ref array3[num3][num4];
						ref string reference2 = ref array3[num3][num5];
						string text2 = array3[num3][num5];
						string text3 = array3[num3][num4];
						reference = text2;
						reference2 = text3;
					}
					DBG.blogDebugExtra("shuffled list is=" + string.Join(",", array3[num3]));
				}
				else
				{
					modifierType = (ModifierType)num3;
					DBG.blogDebugExtra("did not shuffle list of type=" + modifierType);
				}
				count = array[num3];
				modifierType = (ModifierType)num3;
				DBG.blogDebugExtra("count of " + modifierType.ToString() + "=" + count);
				for (int num6 = 0; num6 < count; num6++)
				{
					if (num6 < array2[num3])
					{
						DBG.blogDebugExtra("Adding 100%: " + array3[num3][num6]);
						newMods.Add(array3[num3][num6]);
					}
					else if (Random.Range(0, 100) < 100 - 25 / (array[num3] - num6))
					{
						DBG.blogDebugExtra("Adding chance: " + array3[num3][num6]);
						newMods.Add(array3[num3][num6]);
					}
					else
					{
						DBG.blogDebugExtra("Failed chance: " + array3[num3][num6]);
					}
				}
			}
			if (newMods.Count > 0 && global::CreatureGenetics.CreatureGenetics.allowEffectsMutation.Value && (float)Random.Range(0, 100) < global::CreatureGenetics.CreatureGenetics.MutationChanceEffects.Value)
			{
				int num7 = 0;
				DBG.blogDebug("Has change mutation");
				if (newMods.Count > 1)
				{
					num7 = Random.Range(0, newMods.Count - 1);
				}
				DBG.blogDebugExtra("Changing: " + newMods[num7]);
				mutateSLS(ref newMods, num7, ref text);
				DBG.blogDebugExtra("Updated Modifier List:" + text);
			}
			if (flag)
			{
				ModifierType modifierType = (ModifierType)num2;
				DBG.blogDebug("Adding mutation of type: " + modifierType);
				addNewSLS(ref newMods, num2, text);
			}
			ShuffleClass.Shuffle<string>((IList<string>)newMods, false);
			return string.Join(",", newMods.ToArray());
		}

		private static void mutateSLS(ref List<string> newMods, int mutateNum, ref string combinedList)
		{
			char c = newMods[mutateNum].Trim(',', ' ').Last();
			int num = 1;
			switch (c)
			{
			case '0':
				num = 0;
				break;
			case '2':
				num = 2;
				break;
			}
			List<string> possibleModifiers = API.GetPossibleModifiers(num);
			ShuffleClass.Shuffle<string>((IList<string>)possibleModifiers, false);
			foreach (string item in possibleModifiers)
			{
				DBG.blogDebugExtra("Attempting to change effect:" + item);
				if (!combinedList.Contains(item))
				{
					DBG.blogDebug("Changed effect from:" + newMods[mutateNum] + " to :" + item);
					newMods[mutateNum] = item + ":" + num;
					combinedList = combinedList + "," + item + ":" + num;
					break;
				}
			}
		}

		private static void addNewSLS(ref List<string> newMods, int mutateType, string combinedList)
		{
			List<string> possibleModifiers = API.GetPossibleModifiers(mutateType);
			ShuffleClass.Shuffle<string>((IList<string>)possibleModifiers, false);
			foreach (string item in possibleModifiers)
			{
				DBG.blogDebugExtra("Attempting to add effect:" + item);
				if (!combinedList.Contains(item))
				{
					DBG.blogDebug("Added effect:" + item);
					newMods.Add(item + ":" + mutateType);
					break;
				}
			}
		}

		public static void copyColorEggCache(Character childChar, Character adultChar)
		{
			try
			{
				CharacterCacheEntry andSetLocalCache = CompositeLazyCache.GetAndSetLocalCache(childChar, 0, (Dictionary<string, ModifierType>)null, (List<string>)null, false);
				ColorDef colorization = Colorization.DetermineCharacterColorization(adultChar, childChar.m_level - 1);
				andSetLocalCache.Colorization = colorization;
				ColorDef colorization2 = andSetLocalCache.Colorization;
				DBG.blogDebugExtra("EggGrow Child Character color set to:" + colorization2.Hue + "," + colorization2.Saturation + "," + colorization2.Value + "," + colorization2.IsEmissive);
			}
			catch
			{
				DBG.blogDebugExtra("EggGrow Child Character color FAILED");
			}
		}

		public static int inheritValue(int mom_val, int dad_val)
		{
			if (mom_val != 0 || dad_val != 0)
			{
				int num = Random.Range(0, 100);
				if (num > 60)
				{
					DBG.blogDebugExtra("IsDadVal");
					return dad_val;
				}
				if (num > 20)
				{
					DBG.blogDebugExtra("IsMomVal");
					return mom_val;
				}
				DBG.blogDebugExtra("IsNoVal");
			}
			return 0;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(HealthModifications), "ApplyHealthModifications")]
		private static void Postfix_ApplyHealthModifications(Character chara)
		{
			try
			{
				Genetics genetics = default(Genetics);
				if (global::CreatureGenetics.CreatureGenetics.useDNATraits.Value && Object.op_Implicit((Object)(object)chara) && ((Component)chara).gameObject.TryGetComponent<Genetics>(ref genetics))
				{
					float num = chara.GetHealth() / chara.GetMaxHealth();
					float maxHealth = chara.GetMaxHealth();
					float num2 = Math.Max((float)genetics.Health / 128f, 0.1f);
					DBG.blogDebug("SLS: CurrentHealth:" + chara.GetHealth() + ", MaxHealth: " + maxHealth + ",DNA Multi: " + num2);
					float num3 = maxHealth * num2;
					chara.SetMaxHealth(num3);
					DBG.blogDebug("SLS: NewMaxHealth:" + chara.GetMaxHealth());
					if (num < 1f)
					{
						chara.SetHealth(num3 * num);
					}
					else
					{
						chara.Heal(num3, true);
					}
				}
			}
			catch
			{
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SetChildLevel), "SetupChildCharacter")]
		private static void Prefix_SetupChildCharacter(Character chara, ref Procreation proc)
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			CharacterCacheEntry andSetLocalCache = CompositeLazyCache.GetAndSetLocalCache(chara, 0, (Dictionary<string, ModifierType>)null, (List<string>)null, false);
			CharacterCacheEntry cacheEntry = CompositeLazyCache.GetCacheEntry(proc.m_character);
			andSetLocalCache.Colorization = cacheEntry.Colorization;
			ColorDef colorization = andSetLocalCache.Colorization;
			DBG.blogDebugExtra("Child Character color set to:" + colorization.Hue + "," + colorization.Saturation + "," + colorization.Value + "," + colorization.IsEmissive);
			proc = new Procreation();
			proc.m_character = chara;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Colorization), "ApplyLevelVisual")]
		private static void Postfix_ApplyLevelVisual(Character charc)
		{
			try
			{
				Genetics genetics = default(Genetics);
				if (global::CreatureGenetics.CreatureGenetics.useDNAColor.Value && Object.op_Implicit((Object)(object)charc) && ((Component)charc).gameObject.TryGetComponent<Genetics>(ref genetics))
				{
					DBG.blogDebugExtra("Set SLS Level Render");
					genetics.postLevelEffect = true;
					genetics.setCompleteColor(postLevel: true);
				}
			}
			catch
			{
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SizeModifications), "SetSizeModification")]
		private static bool Prefix_ApplySizeNew(GameObject obj, ZNetView zview, CharacterCacheEntry characterCache, bool update = false, float bonus = 0f)
		{
			//IL_000c: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Vector3 vec = zview.m_zdo.GetVec3(DataObjects.SLS_SIZE, Vector3.zero);
			DBG.blogDebugExtra("SLS PreSize=" + obj.transform.localScale.x + ", zdo=" + vec.x);
			return true;
		}

		[HarmonyPatch(typeof(SizeModifications), "SetSizeModification")]
		[HarmonyPostfix]
		private unsafe static void Postfix_ApplySizeNew(GameObject obj, ZNetView zview, CharacterCacheEntry characterCache)
		{
			//IL_000c: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			Vector3 vec = zview.m_zdo.GetVec3(DataObjects.SLS_SIZE, Vector3.zero);
			DBG.blogDebugExtra("SLS PostSize=" + obj.transform.localScale.x + ", zdo=" + vec.x);
			Genetics genetics = default(Genetics);
			if (!obj.TryGetComponent<Genetics>(ref genetics) || genetics.lateSetInit)
			{
				return;
			}
			DBG.blogDebugExtra("Genetics Size=" + genetics.Size);
			bool flag = characterCache.CreatureModifiers.ContainsKey("Big");
			if (flag)
			{
				DBG.blogDebugExtra("Has Big=" + obj.transform.localScale.x);
			}
			else
			{
				DBG.blogDebugExtra("No Big=" + obj.transform.localScale.x);
			}
			if (genetics.sls_sizes.Count > 0)
			{
				int num = 0;
				foreach (float[] sls_size in genetics.sls_sizes)
				{
					num++;
				}
				float[] array = genetics.sls_sizes[genetics.sls_sizes.Count - 1];
				float num2 = array[0];
				bool flag2 = array[1] != 0f;
				DBG.blogDebugExtra("last size=" + num2);
				if (flag || !flag2)
				{
					DBG.blogDebugExtra("Should Update size");
					genetics.sls_sizes.Add(new float[2]
					{
						vec.x,
						flag ? 1 : 0
					});
					genetics.sls_size = vec.x;
				}
				else
				{
					DBG.blogDebugExtra("Should not update size");
					((Vector3)(ref vec))..ctor(num2, num2, num2);
				}
				foreach (float[] sls_size2 in genetics.sls_sizes)
				{
					DBG.blogDebugExtra("post-size " + num + ": " + sls_size2[0] + sls_size2[1]);
					num++;
				}
			}
			else
			{
				genetics.sls_sizes.Add(new float[2]
				{
					vec.x,
					flag ? 1 : 0
				});
				genetics.sls_size = vec.x;
			}
			int num3 = (int)Mathf.Clamp((float)genetics.Size, (float)global::CreatureGenetics.CreatureGenetics.sizeMin256, (float)global::CreatureGenetics.CreatureGenetics.sizeMax256);
			DBG.blogDebugExtra("clampsize=" + num3);
			Vector3 val = vec * ((float)(num3 * num3) / 130000f + (float)num3 / 200f + 0.25f);
			Vector3 val2 = val;
			DBG.blogDebug("NewSize Post SLS=" + ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString());
			obj.transform.localScale = val;
		}
	}
}
namespace CreatureGenetics
{
	internal class GeneticsPatches
	{
		[HarmonyPatch(typeof(Procreation), "Procreate")]
		public static class InterceptProcreationFindMates
		{
			private static int CheckMates(int result, Procreation _proc)
			{
				DBG.blogDebug($"in CheckMates for:{((Object)_proc).name} with existing mate {result}");
				string key = ((Object)_proc).name.Replace("(Clone)", "");
				if (!CreatureGenetics.customGeneticsList.TryGetValue(key, out var value))
				{
					return result;
				}
				return GetGeneticInst(result, _proc, value, procOnly: true);
			}

			private static int AddMates(int result, Procreation _proc)
			{
				DBG.blogDebug($"in AddMates for:{((Object)_proc).name} with existing mate {result}");
				GameObject myPrefab = _proc.m_myPrefab;
				bool num = myPrefab == null || !Object.op_Implicit((Object)(object)myPrefab);
				myPrefab = _proc.m_offspringPrefab;
				if (num | (myPrefab == null || !Object.op_Implicit((Object)(object)myPrefab)))
				{
					DBG.blogDebug("Init Proc Prefabs");
					InitProcPrefabs(_proc);
				}
				CreatureGenetics.GeneticsConfig geneticsConfig = SetUpProcPrefabs(_proc);
				if (geneticsConfig == null)
				{
					return result;
				}
				return GetGeneticInst(result, _proc, geneticsConfig);
			}

			private static GameObject OnCreateChild(GameObject child, Procreation _proc)
			{
				DBG.blogDebug("in create child");
				Character component = child.GetComponent<Character>();
				Character component2 = ((Component)_proc).gameObject.GetComponent<Character>();
				EggGrow component3 = child.GetComponent<EggGrow>();
				if (!Object.op_Implicit((Object)(object)component) && !Object.op_Implicit((Object)(object)component3))
				{
					DBG.blogWarning("Procreation, No Child");
					return child;
				}
				if (!Object.op_Implicit((Object)(object)component2))
				{
					DBG.blogWarning("No Parent, setting tame and level manually");
					if (Object.op_Implicit((Object)(object)component))
					{
						component.SetTamed(true);
						component.SetLevel(1);
					}
					if (Object.op_Implicit((Object)(object)component3))
					{
						child.GetComponent<ItemDrop>().SetQuality(0);
					}
					return child;
				}
				Genetics genetics = default(Genetics);
				if (!child.gameObject.TryGetComponent<Genetics>(ref genetics))
				{
					DBG.blogDebug("Adding Genes");
					genetics = child.gameObject.AddComponent<Genetics>();
				}
				DBG.blogDebug("Attempting Custom Procreation");
				genetics.SetCreature(component2);
				DBG.blogDebug("Finsihed Custom Procreation");
				return child;
			}

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				MethodInfo procreationHook = AccessTools.DeclaredMethod(typeof(InterceptProcreationFindMates), "OnCreateChild", (Type[])null, (Type[])null);
				MethodInfo addMatesHook = AccessTools.DeclaredMethod(typeof(InterceptProcreationFindMates), "AddMates", (Type[])null, (Type[])null);
				MethodInfo checkMatesHook = AccessTools.DeclaredMethod(typeof(InterceptProcreationFindMates), "CheckMates", (Type[])null, (Type[])null);
				MethodInfo instantiator = typeof(Object).GetMethods().First((MethodInfo m) => m.Name == "Instantiate" && m.GetParameters().Length == 3 && m.GetParameters()[1].ParameterType == typeof(Vector3) && m.GetParameters()[2].ParameterType == typeof(Quaternion) && m.ContainsGenericParameters).MakeGenericMethod(typeof(GameObject));
				MethodInfo getNrOfInstances = typeof(SpawnSystem).GetMethods().First((MethodInfo m) => m.Name == "GetNrOfInstances" && m.GetParameters().Length == 5);
				List<CodeInstruction> codes = new List<CodeInstruction>(instructions);
				bool setCheckMates = false;
				bool setAddMates = true;
				bool setProcHook = true;
				for (int i = 0; i < codes.Count; i++)
				{
					if (CodeInstructionExtensions.Calls(codes[i], getNrOfInstances))
					{
						if (setAddMates && i + 1 < codes.Count && codes[i + 1].opcode.Name.StartsWith("ldarg"))
						{
							CodeInstruction stloc = codes[i + 1];
							yield return codes[i];
							yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
							yield return new CodeInstruction(OpCodes.Call, (object)addMatesHook);
							yield return stloc;
							setCheckMates = true;
							setAddMates = false;
							i++;
							continue;
						}
						if (setCheckMates && i + 2 < codes.Count && codes[i + 1].opcode.Name.StartsWith("stloc") && codes[i + 2].opcode.Name.StartsWith("ldarg"))
						{
							CodeInstruction stloc2 = codes[i + 1];
							yield return codes[i];
							yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
							yield return new CodeInstruction(OpCodes.Call, (object)checkMatesHook);
							yield return stloc2;
							setCheckMates = false;
							i++;
							continue;
						}
					}
					else if (setProcHook && codes[i].opcode == OpCodes.Call && CodeInstructionExtensions.OperandIs(codes[i], (MemberInfo)instantiator))
					{
						yield return codes[i];
						yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
						yield return new CodeInstruction(OpCodes.Call, (object)procreationHook);
						i++;
						setProcHook = false;
					}
					yield return codes[i];
				}
			}
		}

		[HarmonyPatch(typeof(EggGrow), "GrowUpdate")]
		public static class InterceptEggGrowup
		{
			private static GameObject OnEggGrowup(GameObject adult, EggGrow growup)
			{
				DBG.blogDebug("inEggGrowup");
				try
				{
					DBG.blogDebug("EggGrow adult=" + ((Object)adult).name);
					Character component = adult.GetComponent<Character>();
					ItemDrop component2 = ((Component)growup).GetComponent<ItemDrop>();
					if (!Object.op_Implicit((Object)(object)component))
					{
						DBG.blogWarning("Growup, No Adult");
						return adult;
					}
					component.SetTamed(growup.m_tamed);
					if (CreatureGenetics.useSLS)
					{
						DBG.blogDebug("Has SLS, Reducing Quality");
						ItemData itemData = component2.m_itemData;
						itemData.m_quality--;
					}
					component.SetLevel(component2.m_itemData.m_quality + 1);
					DBG.blogDebug("set lvl=" + component.m_level + ", egg+1=" + (component2.m_itemData.m_quality + 1));
					DBG.blogDebug("Attempting custom Growup");
					Genetics genetics = default(Genetics);
					if (!((Component)growup).gameObject.TryGetComponent<Genetics>(ref genetics))
					{
						DBG.blogDebug("Adding Genetics to Growup");
						genetics = ((Component)growup).gameObject.AddComponent<Genetics>();
					}
					Growup val = default(Growup);
					if (CreatureGenetics.useSLS && ((Component)component).TryGetComponent<Growup>(ref val))
					{
						Character component3 = val.m_grownPrefab.GetComponent<Character>();
						if ((Object)(object)component3 != (Object)null)
						{
							DBG.blogDebug("Attempting to grab data from full adult:" + ((Object)component3).name);
							SLS_CG.copyColorEggCache(component, component3);
						}
					}
					genetics.SetGrow(component);
				}
				catch (Exception o)
				{
					adult.GetComponent<Character>().SetTamed(true);
					DBG.blogWarning(o);
				}
				return adult;
			}

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				MethodInfo growupHook = AccessTools.DeclaredMethod(typeof(InterceptEggGrowup), "OnEggGrowup", (Type[])null, (Type[])null);
				MethodInfo instantiator = typeof(Object).GetMethods().First((MethodInfo m) => m.Name == "Instantiate" && m.GetParameters().Length == 3 && m.GetParameters()[1].ParameterType == typeof(Vector3) && m.GetParameters()[2].ParameterType == typeof(Quaternion) && m.ContainsGenericParameters).MakeGenericMethod(typeof(GameObject));
				foreach (CodeInstruction instruction in instructions)
				{
					yield return instruction;
					if (instruction.opcode == OpCodes.Call && CodeInstructionExtensions.OperandIs(instruction, (MemberInfo)instantiator))
					{
						yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
						yield return new CodeInstruction(OpCodes.Call, (object)growupHook);
					}
				}
			}
		}

		[HarmonyPatch(typeof(Growup), "GrowUpdate")]
		public static class InterceptGrowup
		{
			private static GameObject OnGrowup(GameObject adult, Growup growup)
			{
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0100: Unknown result type (might be due to invalid IL or missing references)
				DBG.blogDebug("inOnGrowup");
				try
				{
					DBG.blogDebug("adult=" + ((Object)adult).name);
					Character component = adult.GetComponent<Character>();
					Character component2 = ((Component)growup).gameObject.GetComponent<Character>();
					if (!Object.op_Implicit((Object)(object)component))
					{
						DBG.blogWarning("Growup, No Adult");
						return adult;
					}
					if (!Object.op_Implicit((Object)(object)component2))
					{
						DBG.blogWarning("No Growup, setting tame and level manually");
						component.SetTamed(true);
						component.SetLevel(1);
						return adult;
					}
					component.SetTamed(component2.IsTamed());
					component.SetLevel(component2.GetLevel());
					DBG.blogDebug("Attempting custom Growup");
					Genetics genetics = default(Genetics);
					if (!((Component)component2).gameObject.TryGetComponent<Genetics>(ref genetics))
					{
						genetics = ((Component)component2).gameObject.AddComponent<Genetics>();
					}
					if (CreatureGenetics.hasYBR)
					{
						BetterRiding.InheritOwnership(component2, component);
					}
					genetics.SetGrow(component);
					DBG.blogDebug("current size4=" + ((Component)component).transform.localScale.x);
				}
				catch (Exception o)
				{
					adult.GetComponent<Character>().SetTamed(true);
					DBG.blogWarning(o);
				}
				return adult;
			}

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				MethodInfo growupHook = AccessTools.DeclaredMethod(typeof(InterceptGrowup), "OnGrowup", (Type[])null, (Type[])null);
				MethodInfo instantiator = typeof(Object).GetMethods().First((MethodInfo m) => m.Name == "Instantiate" && m.GetParameters().Length == 3 && m.GetParameters()[1].ParameterType == typeof(Vector3) && m.GetParameters()[2].ParameterType == typeof(Quaternion) && m.ContainsGenericParameters).MakeGenericMethod(typeof(GameObject));
				foreach (CodeInstruction instruction in instructions)
				{
					yield return instruction;
					if (instruction.opcode == OpCodes.Call && CodeInstructionExtensions.OperandIs(instruction, (MemberInfo)instantiator))
					{
						yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
						yield return new CodeInstruction(OpCodes.Call, (object)growupHook);
					}
				}
			}
		}

		private static float[,] InfluenceMatrix;

		private void Awake()
		{
			InitInfluenceMatrix();
		}

		public static void InitInfluenceMatrix()
		{
			InfluenceMatrix = new float[6, 6]
			{
				{ 0f, 0f, -0.15f, 0.15f, -0.05f, 0.35f },
				{ 0f, 0f, -0.05f, -0.25f, 0.2f, 0.05f },
				{ -0.15f, -0.05f, 0f, 0f, 0.05f, 0.2f },
				{ 0.15f, -0.25f, 0f, 0f, 0.35f, -0.1f },
				{ -0.05f, 0.2f, 0.05f, 0.35f, 0f, 0f },
				{ 0.35f, 0.05f, 0.2f, -0.05f, 0f, 0f }
			};
		}

		public static float[,] getInfluenceMatrix()
		{
			if (InfluenceMatrix == null)
			{
				InitInfluenceMatrix();
			}
			return InfluenceMatrix;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Character), "Awake")]
		private static void PostfixCharacterAwake(Character __instance)
		{
			try
			{
				Genetics genetics = default(Genetics);
				if (!((Component)__instance).gameObject.TryGetComponent<Genetics>(ref genetics) && ((object)__instance).GetType() != typeof(Player))
				{
					genetics = ((Component)__instance).gameObject.AddComponent<Genetics>();
				}
				genetics.modifySpeed();
			}
			catch
			{
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "SetLevel")]
		private static void Prefix(Character __instance, ref int level)
		{
			if (Object.op_Implicit((Object)(object)((Component)__instance).gameObject.GetComponent<Genetics>()))
			{
				level = ((Component)__instance).gameObject.GetComponent<Genetics>().GetLevel(level);
				DBG.blogDebug("genetics level is " + level);
			}
		}

		public static GameObject addProcPrefToList(CreatureGenetics.GeneticsConfig genCfg, string PrefName, bool mate = true, string startPref = "", int depth = 0)
		{
			DBG.blogDebugExtra("LOOP:" + PrefName + "," + startPref + ",depth=" + depth);
			if (depth > 5)
			{
				DBG.blogDebug("Max depth reached with: " + PrefName);
				return null;
			}
			if (startPref != "")
			{
				if (PrefName == startPref)
				{
					DBG.blogDebugExtra("Finished loop starting at: " + PrefName);
					return null;
				}
			}
			else
			{
				startPref = PrefName;
			}
			string text = PrefName;
			if (!text.Contains("(Clone)"))
			{
				text += "(Clone)";
			}
			if (mate)
			{
				if (!genCfg.mateNames.Contains(text))
				{
					genCfg.mateNames.Add(text);
				}
				if (!genCfg.allProcPrefabs.Contains(text))
				{
					genCfg.allProcPrefabs.Add(text);
				}
				return null;
			}
			GameObject prefab = ZNetScene.instance.GetPrefab(PrefName);
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				DBG.blogWarning("Could not find Prefab: " + text);
				return null;
			}
			List<string> allProcPrefabs = genCfg.allProcPrefabs;
			if (Object.op_Implicit((Object)(object)prefab.GetComponent<BaseAI>()))
			{
				if (!allProcPrefabs.Contains(text))
				{
					DBG.blogDebug("parent added " + text + " to alloffspring of " + genCfg.PrefabName);
					allProcPrefabs.Add(text);
				}
			}
			else if (!genCfg.ProcEggPrefabs.Contains(text))
			{
				DBG.blogDebug("base added egg " + text + " to alloffspring of " + genCfg.PrefabName);
				genCfg.ProcEggPrefabs.Add(text);
			}
			Procreation component = prefab.GetComponent<Procreation>();
			GameObject val = null;
			bool flag = false;
			bool flag2 = true;
			if (Object.op_Implicit((Object)(object)component))
			{
				flag = true;
				string text2 = "";
				if (Object.op_Implicit((Object)(object)component.m_offspringPrefab))
				{
					text2 = ((Object)component.m_offspringPrefab).name;
					flag2 = Object.op_Implicit((Object)(object)component.m_offspringPrefab.GetComponent<BaseAI>());
					val = component.m_offspringPrefab;
				}
				else if (Object.op_Implicit((Object)(object)component.m_offspring))
				{
					text2 = ((Object)component.m_offspring).name;
					flag2 = Object.op_Implicit((Object)(object)component.m_offspring.GetComponent<BaseAI>());
					val = component.m_offspring;
				}
				else
				{
					DBG.blogDebug("did not find offspring adding Mini" + ((Object)prefab).name);
					text2 = "Mini" + ((Object)prefab).name;
				}
				GameObject val2 = addProcPrefToList(genCfg, text2, mate: false, startPref, depth + 1);
				if ((Object)(object)val == (Object)null && (Object)(object)val2 != (Object)null)
				{
					val = val2;
				}
			}
			Growup component2 = prefab.GetComponent<Growup>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				flag = true;
				if (Object.op_Implicit((Object)(object)component2.m_grownPrefab))
				{
					addProcPrefToList(genCfg, ((Object)component2.m_grownPrefab).name, mate: false, startPref, depth + 1);
				}
				else
				{
					DBG.blogDebug("did not find growup");
				}
			}
			EggGrow component3 = prefab.GetComponent<EggGrow>();
			if (Object.op_Implicit((Object)(object)component3))
			{
				flag = true;
				if (Object.op_Implicit((Object)(object)component3.m_grownPrefab))
				{
					addProcPrefToList(genCfg, ((Object)component3.m_grownPrefab).name, mate: false, startPref, depth + 1);
				}
				else
				{
					DBG.blogDebug("did not find eggGrowup");
				}
			}
			if (flag && (Object)(object)val == (Object)null)
			{
				val = prefab;
			}
			if (startPref == "" && !flag)
			{
				if (Object.op_Implicit((Object)(object)ZNetScene.instance.GetPrefab(PrefName + "Egg_LMTY")))
				{
					addProcPrefToList(genCfg, PrefName + "Egg_LMTY", mate: false, startPref, depth + 1);
				}
				DBG.blogDebug("did not find Offspring/GrowUp/EggGrow, adding Mini" + ((Object)prefab).name);
				string text3 = "Mini" + ((Object)prefab).name + "(Clone)";
				GameObject val3 = addProcPrefToList(genCfg, "Mini" + ((Object)prefab).name, mate: false, startPref, depth + 1);
				if ((Object)(object)val == (Object)null && (Object)(object)val3 != (Object)null)
				{
					val = val3;
				}
			}
			return val;
		}

		public static CreatureGenetics.GeneticsConfig SetUpProcPrefabs(Procreation _proc)
		{
			string text = ((Object)_proc).name.Replace("(Clone)", "");
			if (!CreatureGenetics.customGeneticsList.TryGetValue(text, out var value))
			{
				return null;
			}
			string text2 = "";
			bool flag = false;
			if (Object.op_Implicit((Object)(object)_proc.m_offspringPrefab))
			{
				text2 = ((Object)_proc.m_offspringPrefab).name;
				flag = (Object)(object)_proc.m_offspringPrefab.GetComponent<BaseAI>() == (Object)null;
			}
			else if (Object.op_Implicit((Object)(object)_proc.m_offspring))
			{
				text2 = ((Object)_proc.m_offspring).name;
				flag = (Object)(object)_proc.m_offspring.GetComponent<BaseAI>() == (Object)null;
			}
			else
			{
				DBG.blogDebug("did not find offspring");
			}
			text2 += "(Clone)";
			DBG.blogDebug("set up offspring name=" + text2);
			if (flag)
			{
				DBG.blogDebug("isEgg=" + text2);
				if (!value.ProcEggPrefabs.Contains(text2))
				{
					value.ProcEggPrefabs.Add(text2);
				}
			}
			else if (!value.allProcPrefabs.Contains(text2))
			{
				DBG.blogDebug("notEgg=" + text2);
				value.allProcPrefabs.Add(text2);
			}
			if (value.allProcPrefabs.Count + value.ProcEggPrefabs.Count > 1)
			{
				DBG.blogDebug("ProcPrefabs already init for: " + text);
				return value;
			}
			DBG.blogDebug("Pre allProcPref for: " + text + ": " + string.Join(",", value.allProcPrefabs));
			DBG.blogDebug("Pre ProcEggPrefabs for: " + text + ": " + string.Join(",", value.ProcEggPrefabs));
			if (value.ListofRandomOffspring.Count() != 0)
			{
				foreach (CreatureGenetics.specificMates item in value.ListofRandomOffspring)
				{
					addProcPrefToList(value, item.prefabName);
					foreach (CreatureGenetics.chanceOffspring item2 in item.possibleOffspring)
					{
						GameObject val = addProcPrefToList(value, item2.prefabName, mate: false);
						if ((Object)(object)val != (Object)null)
						{
							DBG.blogDebug("chanceOff.offspring: " + item.prefabName + ": " + ((Object)val).name + ", " + item2.prefabName);
							item2.offspring = val;
						}
					}
				}
				DBG.blogDebug("SetUp allProcPref for: " + text + ": " + string.Join(",", value.allProcPrefabs));
				DBG.blogDebug("SetUp mateNames for: " + text + ": " + string.Join(",", value.mateNames));
				DBG.blogDebug("SetUp eggs for: " + text + ": " + string.Join(",", value.ProcEggPrefabs));
			}
			return value;
		}

		public static void InitProcPrefabs(Procreation _proc)
		{
			string text = (((Object)(object)_proc.m_offspring != (Object)null) ? ((Object)_proc.m_offspring).name : "");
			_proc.m_offspringPrefab = ZNetScene.instance.GetPrefab(text);
			int prefab = _proc.m_nview.GetZDO().GetPrefab();
			_proc.m_myPrefab = ZNetScene.instance.GetPrefab(prefab);
			GameObject myPrefab = _proc.m_myPrefab;
			if (myPrefab == null || !Object.op_Implicit((Object)(object)myPrefab))
			{
				DBG.blogDebug("m_myPrefab is still Null, trying again for " + ((Object)_proc).name);
				string text2 = ((Object)_proc).name.Replace("(Clone)", "");
				DBG.blogDebug("proc_name=" + text2);
				if ((Object)(object)ZNetScene.instance.GetPrefab(text2) == (Object)null)
				{
					DBG.blogDebug("proc_name failed");
				}
				else
				{
					_proc.m_myPrefab = ZNetScene.instance.GetPrefab(text2);
				}
				myPrefab = _proc.m_myPrefab;
				if (myPrefab == null || !Object.op_Implicit((Object)(object)myPrefab))
				{
					DBG.blogDebug("m_myPrefab backup failed");
				}
				else
				{
					DBG.blogDebug("m_myPrefab backup success");
				}
			}
			myPrefab = _proc.m_offspringPrefab;
			if (myPrefab == null || !Object.op_Implicit((Object)(object)myPrefab))
			{
				DBG.blogDebug("Failed m_offspringPrefab=" + text);
				_proc.m_offspringPrefab = _proc.m_offspring;
				myPrefab = _proc.m_offspringPrefab;
				if (myPrefab == null || !Object.op_Implicit((Object)(object)myPrefab))
				{
					DBG.blogDebug("m_offspringPrefab backup failed :" + ((Object)(object)_proc.m_offspringPrefab == (Object)null));
				}
				else
				{
					DBG.blogDebug("m_offspringPrefab backup success");
				}
			}
		}

		[HarmonyPatch(typeof(Procreation), "ResetPregnancy")]
		[HarmonyPostfix]
		private static void PostfixResetPregnancy(Procreation __instance)
		{
			Genetics genetics = default(Genetics);
			if (((Component)__instance).TryGetComponent<Genetics>(ref genetics))
			{
				genetics.CheckOffspringReady();
			}
		}

		[HarmonyPatch(typeof(Procreation), "MakePregnant")]
		[HarmonyPostfix]
		private static void PostfixMakePregnant(Procreation __instance)
		{
			Genetics genetics = default(Genetics);
			if (((Component)__instance).TryGetComponent<Genetics>(ref genetics))
			{
				initRandomOffspring(__instance);
				genetics.ResetOffspring();
			}
		}

		private static void initRandomOffspring(Procreation _proc)
		{
			string key = ((Object)_proc).name.Replace("(Clone)", "");
			if (CreatureGenetics.customGeneticsList.TryGetValue(key, out var value) && value.allProcPrefabs.Count == 0 && value.ProcEggPrefabs.Count == 0 && value.ListofRandomOffspring.Count != 0)
			{
				SetUpProcPrefabs(_proc);
			}
		}

		private static int GetGeneticInst(int result, Procreation _proc, CreatureGenetics.GeneticsConfig genCfg, bool procOnly = false)
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			if (genCfg == null)
			{
				return result;
			}
			DBG.blogDebug($"Starting Genetic find for {((Object)_proc).name}, starting number {result}");
			string text = "";
			if (!procOnly)
			{
				if (Object.op_Implicit((Object)(object)_proc.m_offspringPrefab))
				{
					text = ((Object)_proc.m_offspringPrefab).name;
				}
				else if (Object.op_Implicit((Object)(object)_proc.m_offspring))
				{
					text = ((Object)_proc.m_offspring).name;
				}
			}
			else if (!genCfg.canMateWithSelf)
			{
				DBG.blogDebug("Cannot Mate with same prefab, " + result + " removed from total nearby");
				result = 1;
			}
			ZNetScene instance = ZNetScene.instance;
			Vector3 position = ((Component)_proc).transform.position;
			float totalCheckRange = _proc.m_totalCheckRange;
			if (procOnly)
			{
				result += MassGetNrOfCreatures(genCfg.mateNames, position, totalCheckRange, procreationOnly: true);
			}
			else
			{
				result += MassGetNrOfCreatures(genCfg.allProcPrefabs, position, totalCheckRange);
				result += MassGetNrOfItems(genCfg.ProcEggPrefabs, position, totalCheckRange);
			}
			DBG.blogDebug($"Final Result for {((Object)_proc).name} is {result}");
			return result;
		}

		public static int MassGetNrOfCreatures(List<string> prefNames, Vector3 center, float maxRange, bool procreationOnly = false)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			List<BaseAI> allInstances = BaseAI.GetAllInstances();
			int num = 0;
			foreach (BaseAI item in allInstances)
			{
				try
				{
					if (prefNames.Contains(((Object)((Component)item).gameObject).name) && (!(maxRange > 0f) || !(Vector3.Distance(center, ((Component)item).transform.position) > maxRange)))
					{
						if (!procreationOnly)
						{
							goto IL_008e;
						}
						Procreation component = ((Component)item).GetComponent<Procreation>();
						if (!Object.op_Implicit((Object)(object)component) || component.ReadyForProcreation())
						{
							goto IL_008e;
						}
					}
					goto end_IL_001f;
					IL_008e:
					num++;
					DBG.blogDebug("Added 1 of " + ((Object)((Component)item).gameObject).name + "to instnum");
					end_IL_001f:;
				}
				catch
				{
					DBG.blogDebug("Failed to find mate of " + ((Object)((Component)item).gameObject).name + " to instnum");
				}
			}
			return num;
		}

		public static int MassGetNrOfItems(List<string> prefNames, Vector3 center, float maxRange)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			GameObject[] array = GameObject.FindGameObjectsWithTag("spawned");
			int num = 0;
			GameObject[] array2 = array;
			foreach (GameObject val in array2)
			{
				if (prefNames.Contains(((Object)val.gameObject).name) && (!(maxRange > 0f) || !(Vector3.Distance(center, val.transform.position) > maxRange)))
				{
					DBG.blogDebug("Added 1 of " + ((Object)val.gameObject).name + "to instnum");
					num++;
				}
			}
			return num;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")]
		private static void PostfixGenerateDroplist(CharacterDrop __instance, ref List<KeyValuePair<GameObject, int>> __result)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Invalid comparison between Unknown and I4
			try
			{
				Genetics genetics = default(Genetics);
				if (!((Component)__instance).gameObject.TryGetComponent<Genetics>(ref genetics))
				{
					return;
				}
				float num = 0.6f + (float)genetics.Drops * CreatureGenetics.DropMultiplier;
				DBG.blogDebug("Pre drop multi" + num);
				ItemDrop val = default(ItemDrop);
				for (int i = 0; i < __result.Count; i++)
				{
					DBG.blogDebug("Pre drop" + ((Object)__result[i].Key).name + ", amt:" + __result[i].Value);
					if (!__result[i].Key.TryGetComponent<ItemDrop>(ref val) || (int)val.m_itemData.m_shared.m_itemType != 13)
					{
						float num2 = (float)__result[i].Value * num;
						int value = Mathf.FloorToInt(num2) + ((Random.value <= num2 % 1f) ? 1 : 0);
						DBG.blogDebug("amtFlt:" + num2 + ", newAmt:" + value);
						__result[i] = new KeyValuePair<GameObject, int>(__result[i].Key, value);
					}
				}
				for (int j = 0; j < __result.Count; j++)
				{
					DBG.blogDebug("drop Post" + ((Object)__result[j].Key).name + ", amt:" + __result[j].Value);
				}
			}
			catch
			{
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Character), "SetupMaxHealth")]
		private static void PostfixCharacterSetupMaxHealth(Character __instance)
		{
			try
			{
				Genetics genetics = default(Genetics);
				if (!CreatureGenetics.useSLS && ((Component)__instance).gameObject.TryGetComponent<Genetics>(ref genetics))
				{
					genetics.OGMaxHealth = Math.Max(__instance.GetMaxHealth(), genetics.OGMaxHealth);
					DBG.blogDebug("thisGenetics.OGMaxHealth: " + genetics.OGMaxHealth);
					__instance.SetMaxHealth(__instance.GetMaxHealth() * Math.Max((float)genetics.Health / 128f, 0.1f));
					DBG.blogDebug("__instance.GetMaxHealth(): " + __instance.GetMaxHealth());
				}
			}
			catch
			{
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "Damage")]
		private static void PrefixChracterDamage(Character __instance, ref HitData hit)
		{
			try
			{
				Genetics genetics = default(Genetics);
				if (((Component)__instance).gameObject.TryGetComponent<Genetics>(ref genetics))
				{
					hit.ApplyModifier(387f / ((float)genetics.Armor + 64f) - 1.01f);
				}
			}
			catch
			{
			}
		}

		private static void ChangeEquipmentColor(Humanoid chr)
		{
			try
			{
				Genetics genetics = default(Genetics);
				if (CreatureGenetics.useDNAColor.Value && ((Component)chr).gameObject.TryGetComponent<Genetics>(ref genetics) && !genetics.hasSetupEquipment && !genetics.lateSetInit)
				{
					genetics.hasSetupEquipment = genetics.setCompleteColor();
					DBG.blogDebug("SetupEquipment=" + genetics.hasSetupEquipment);
				}
			}
			catch
			{
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Humanoid), "SetupVisEquipment")]
		private static void PostfixHumanoidSetupVisEquipment(Humanoid __instance)
		{
			ChangeEquipmentColor(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Humanoid), "SetupEquipment")]
		private static void PostfixHumanoidSetupEquipment(Humanoid __instance)
		{
			ChangeEquipmentColor(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(LevelEffects), "SetupLevelVisualization")]
		private static void Postfix_SetupLevelVisualization(LevelEffects __instance, int level)
		{
			if (CreatureGenetics.useSLS)
			{
				DBG.blogDebug("Skipping Level Render as SLS");
				return;
			}
			try
			{
				Genetics genetics = default(Genetics);
				if (CreatureGenetics.useDNAColor.Value && Object.op_Implicit((Object)(object)__instance.m_character) && ((Component)__instance.m_character).gameObject.TryGetComponent<Genetics>(ref genetics))
				{
					DBG.blogDebug("Set Level Render");
					Renderer mainRender = __instance.m_mainRender;
					genetics.postLevelEffect = true;
					genetics.setCompleteColor(postLevel: true, mainRender);
					genetics.levelRender = __instance.m_mainRender;
				}
			}
			catch
			{
			}
		}
	}
	internal class DNAPatches
	{
	}
	public class Genetics : MonoBehaviour
	{
		[Serializable]
		public class OriginalData : ICloneable
		{
			public float acceleration { get; set; } = 1f;

			public float swimAcceleration { get; set; } = 1f;

			public float runSpeed { get; set; } = 1f;

			public float runTurnSpeed { get; set; } = 1f;

			public float flyFastSpeed { get; set; } = 1f;

			public float flyTurnSpeed { get; set; } = 1f;

			public float swimSpeed { get; set; } = 1f;

			public float swimTurnSpeed { get; set; } = 1f;

			public float prefSize { get; set; } = 1f;

			public bool filled { get; set; } = false;

			public object Clone()
			{
				return MemberwiseClone();
			}
		}

		[Serializable]
		public class TraitPkg : ICloneable
		{
			public long Speed { get; set; } = 128L;

			public long Health { get; set; } = 128L;

			public long Armor { get; set; } = 128L;

			public long Size { get; set; } = 128L;

			public object Clone()
			{
				return MemberwiseClone();
			}
		}

		[Serializable]
		public class GeneticPkg : ICloneable
		{
			public int id { get; set; } = 0;

			public string prefabName { get; set; } = "";

			public int lvl { get; set; } = 1;

			public CLLC.Effect_CLLC effect { get; set; } = CLLC.Effect_CLLC.None;

			public CLLC.Infusion_CLLC infusion { get; set; } = CLLC.Infusion_CLLC.None;

			public string MonMod { get; set; } = "";

			public string SLS { get; set; } = "";

			public byte[] DNA { get; set; } = new byte[10];

			public object Clone()
			{
				return MemberwiseClone();
			}
		}

		private const string ZDOkey = "CG_DNA";

		private const int NumDNAFactors = 10;

		private int traitOffset = 4;

		private static byte[] baseDNA;

		private static float initDelay;

		private ZNetView m_nview;

		public Character chr;

		public long R = 128L;

		public long G = 128L;

		public long B = 128L;

		public float OGMaxHealth = -1f;

		public long Health = 128L;

		public long Speed = 128L;

		public long Armor = 128L;

		public long Size = 128L;

		public long Productivity = 0L;

		public long Drops = 0L;

		public bool isWild = true;

		public byte[] DNA_Strand = null;

		public bool lateSetInit = false;

		public string HoverText = "";

		private OriginalData ogData = new OriginalData();

		private bool modifiedSpeed = false;

		public Renderer[] Renderers = (Renderer[])(object)new Renderer[0];

		private Dictionary<string, Color> baseColorTbl = new Dictionary<string, Color>();

		private Color baseColor = Color.white;

		private bool firstColor = true;

		private Color colorMulti = Color.white;

		public Renderer levelRender;

		public bool hasSetupEquipment = false;

		public bool postLevelEffect = false;

		public bool hueShifted = false;

		public GeneticPkg thisPkg;

		public GeneticPkg partnerPkg;

		public GeneticPkg offspringPkg;

		private int level = 1;

		private bool newLevel = false;

		public string savedOffspring = "";

		private int dad_lvl = 0;

		public string dad_info = "";

		public float sls_size = 0f;

		public List<float[]> sls_sizes = new List<float[]>();

		public bool delay_Size = false;

		private void Awake()
		{
			m_nview = ((Component)this).gameObject.GetComponent<ZNetView>();
			if (!m_nview.IsValid())
			{
				return;
			}
			chr = ((Component)this).gameObject.GetComponent<Character>();
			getOGData();
			SetDNA();
			if (Object.op_Implicit((Object)(object)((Component)this).GetComponentInParent<EggGrow>()))
			{
				ItemDrop component = ((Component)this).gameObject.GetComponent<ItemDrop>();
				if (Object.op_Implicit((Object)(object)component))
				{
					ItemData itemData = component.m_itemData;
					if (!itemData.m_customData.TryGetValue("Infusion", out var value))
					{
						value = "None";
					}
					if (!itemData.m_customData.TryGetValue("ExtraEffect", out var value2))
					{
						value2 = "None";
					}
					if (value != "None" || value2 != "None")
					{
						itemData.m_shared.m_maxStackSize = 1;
					}
					int quality = GetLevel(component.m_itemData.m_quality);
					DBG.blogDebug("Setting Quality to " + quality);
					component.SetQuality(quality);
				}
			}
			if (CreatureGenetics.useSLS)
			{
				lateSetInit = true;
				((MonoBehaviour)this).Invoke("lateSLSInit", 0.2f);
			}
		}

		public int GetLevel(int oldLevel)
		{
			if (newLevel)
			{
				return level;
			}
			return oldLevel;
		}

		public void checkInit()
		{
			DBG.blogDebug("Late Checking Init for " + ((Object)((Component)this).gameObject).name);
			if (!lateSetInit)
			{
				DBG.blogDebug("Already Solved, skipping");
				return;
			}
			lateSetInit = false;
			if (DNA_Strand == null)
			{
				DNA_Strand = m_nview.GetZDO().GetByteArray("CG_DNA", (byte[])null);
				if (DNA_Strand == null && (Object)(object)chr != (Object)null)
				{
					DBG.blogDebug("Performing Backup Init, with random dna");
					SetRandomDNA();
				}
				else
				{
					DBG.blogDebug("Performing Backup Init, dna=" + string.Join(",", DNA_Strand));
					ParseMSG();
				}
			}
			setAttributes();
			SetZDO();
		}

		public void finalSizeDelay()
		{
			DBG.blogDebug("Delay size=" + delay_Size);
			if (delay_Size)
			{
				delay_Size = false;
				setTraits(onlysize: true);
			}
		}

		public void lateSLSInit()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			DBG.blogDebug("In SLS Late Init for " + ((Object)((Component)this).gameObject).name);
			float x = ((Component)this).transform.localScale.x;
			DBG.blogDebugExtra("Starting Size=" + x);
			ZDO zDO = m_nview.GetZDO();
			Vector3 vec = zDO.GetVec3("SLS_SIZE", Vector3.zero);
			checkInit();
			int num = (int)Mathf.Clamp((float)Size, (float)CreatureGenetics.sizeMin256, (float)CreatureGenetics.sizeMax256);
			Transform transform = ((Component)this).transform;
			transform.localScale *= (float)(num * num) / 130000f + (float)num / 200f + 0.25f;
			DBG.blogDebugExtra("New size=" + ((object)((Component)this).transform.localScale/*cast due to .constrained prefix*/).ToString());
		}

		public void SetGrow(Character adultchar)
		{
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			DBG.blogDebug("inSetGrow");
			bool flag = (Object)(object)chr == (Object)null;
			ItemDrop component = ((Component)this).gameObject.GetComponent<ItemDrop>();
			string text = (flag ? Utils.iDropGetCustData(component, "CG_DNA") : "");
			if (CreatureGenetics.useCLLC)
			{
				CLLC.Effect_CLLC infusion;
				CLLC.Infusion_CLLC infusion2;
				if (flag)
				{
					DBG.blogDebug("No Char");
					infusion = CLLC.iDropGetEff(component);
					infusion2 = CLLC.iDropGetInf(component);
				}
				else
				{
					DBG.blogDebug("Has Char");
					infusion2 = CLLC.GetInfusionCreature(chr);
					infusion = CLLC.GetExtraEffectCreature(chr);
				}
				CLLC.SetInfusionCreature(adultchar, infusion2);
				CLLC.SetExtraEffectCreature(adultchar, infusion);
			}
			if (CreatureGenetics.useSLS)
			{
				string sLS_Str;
				if (flag)
				{
					DBG.blogDebug("No Char");
					sLS_Str = Utils.iDropGetCustData(component, "CG_SLS");
				}
				else
				{
					sLS_Str = SLS_CG.getModifiers(chr);
				}
				SLS_CG.SetModifiers(adultchar, sLS_Str);
				float x = ((Component)adultchar).transform.localScale.x;
				DBG.blogDebugExtra("Default Size1=" + x);
				ZDO zDO = adultchar.m_nview.GetZDO();
				DBG.blogDebugExtra("sls_size11: " + zDO.GetFloat("SLS_SIZE", 0f));
			}
			if (CreatureGenetics.useMonMod)
			{
				string monMod;
				if (flag)
				{
					DBG.blogDebug("No Char");
					monMod = Utils.iDropGetCustData(component, "CG_MonMod");
				}
				else
				{
					monMod = MonMod_CG.getModifiers(chr);
				}
				MonMod_CG.SetModifiers(adultchar, monMod);
			}
			DBG.blogDebugExtra("current size2=" + ((Component)adultchar).transform.localScale.x);
			if (!CreatureGenetics.useDNA)
			{
				return;
			}
			Genetics genetics = default(Genetics);
			if (!((Component)adultchar).gameObject.TryGetComponent<Genetics>(ref genetics))
			{
				DBG.blogDebugExtra("Adding adult Genes");
				genetics = ((Component)adultchar).gameObject.AddComponent<Genetics>();
			}
			byte[] array = null;
			if (text != "")
			{
				array = Convert.FromBase64String(text);
				DBG.blogDebug("Setting DNA from iDrop");
				DNA_Strand = array;
			}
			else
			{
				DNA_Strand = m_nview.GetZDO().GetByteArray("CG_DNA", (byte[])null);
				if (DNA_Strand == null)
				{
					SetRandomDNA();
					SetZDO();
				}
			}
			genetics.DNA_Strand = DNA_Strand;
			genetics.restoreColor();
			genetics.ParseMSG();
			genetics.setAttributes();
			genetics.SetZDO();
		}

		public static string iDropGetDNA(ItemDrop iDrop)
		{
			string result = "";
			if (Object.op_Implicit((Object)(object)iDrop) && CreatureGenetics.useDNA && iDrop.m_itemData.m_customData.TryGetValue("CG_DNA", out var value))
			{
				result = value;
				DBG.blogDebug("got DNA from iDrop");
			}
			return result;
		}

		public void SetDNA()
		{
			if (!CreatureGenetics.useDNA)
			{
				return;
			}
			if (DNA_Strand == null)
			{
				DNA_Strand = m_nview.GetZDO().GetByteArray("CG_DNA", (byte[])null);
				if (DNA_Strand != null)
				{
					DBG.blogDebugExtra("grabbed dna hash: " + string.Join(",", DNA_Strand));
				}
				else
				{
					DBG.blogDebug("DNA strand is null");
					if (Object.op_Implicit((Object)(object)((Component)this).gameObject.GetComponent<Growup>()))
					{
						DBG.blogDebug("is child, skipping init");
						if (!lateSetInit)
						{
							lateSetInit = true;
							((MonoBehaviour)this).Invoke("checkInit", initDelay);
						}
						return;
					}
					if (Object.op_Implicit((Object)(object)((Component)this).gameObject.GetComponent<EggGrow>()))
					{
						DBG.blogDebug("is egg, skipping init");
						return;
					}
					DBG.blogDebug("is adult, making random DNA");
				}
			}
			else
			{
				DBG.blogDebug("has DNA: " + string.Join(",", DNA_Strand));
			}
			ParseMSG();
			if (CreatureGenetics.useSLS)
			{
				DBG.blogDebug("is SLS, skipping init");
				if (!lateSetInit && (Object)(object)chr != (Object)null)
				{
					lateSetInit = true;
					((MonoBehaviour)this).Invoke("checkInit", initDelay);
				}
			}
			else
			{
				setAttributes();
				SetZDO();
			}
		}

		public void SetZDO()
		{
			if (DNA_Strand == null)
			{
				DNA_Strand = new byte[10];
			}
			DNA_Strand[0] = (byte)Math.Min(R, 255L);
			DNA_Strand[1] = (byte)Math.Min(G, 255L);
			DNA_Strand[2] = (byte)Math.Min(B, 255L);
			DNA_Strand[3] = Convert.ToByte(isWild);
			DNA_Strand[4] = (byte)Health;
			DNA_Strand[5] = (byte)Speed;
			DNA_Strand[6] = (byte)Armor;
			DNA_Strand[7] = (byte)Size;
			DNA_Strand[8] = (byte)Productivity;
			DNA_Strand[9] = (byte)Math.Max(0L, Drops);
			m_nview.GetZDO().Set("CG_DNA", DNA_Strand);
		}

		public void ParseMSG()
		{
			if (DNA_Strand == null)
			{
				Character val = default(Character);
				if (((Component)this).gameObject.TryGetComponent<Character>(ref val))
				{
					if (!val.m_tamed)
					{
						DBG.blogDebug("is not tamed");
						OGMaxHealth = val.GetMaxHealth();
						SetRandomDNA();
					}
					else if (!lateSetInit)
					{
						DBG.blogDebug("is tamed but no DNA");
						lateSetInit = true;
						((MonoBehaviour)this).Invoke("checkInit", initDelay);
					}
				}
			}
			else if (DNA_Strand.Length > 10)
			{
				DNA_Strand = new byte[10];
				SetRandomDNA();
			}
			else
			{
				DBG.blogDebug(((Object)((Component)this).gameObject).name + " DNA_Strand=" + string.Join(",", DNA_Strand));
				R = DNA_Strand[0];
				G = DNA_Strand[1];
				B = DNA_Strand[2];
				isWild = DNA_Strand[3] == 1;
				Health = DNA_Strand[4];
				Speed = DNA_Strand[5];
				Armor = DNA_Strand[6];
				Size = DNA_Strand[7];
				Productivity = DNA_Strand[8];
				Drops = DNA_Strand[9];
			}
		}

		private void SetRandomDNA()
		{
			GaussianGenerator gaussianGenerator = new GaussianGenerator();
			float dNAVarianceMod = CreatureGenetics.DNAVarianceMod;
			R = (long)gaussianGenerator.NextDouble(128.0, 13f * dNAVarianceMod);
			G = (long)gaussianGenerator.NextDouble(128.0, 13f * dNAVarianceMod);
			B = (long)gaussianGenerator.NextDouble(128.0, 13f * dNAVarianceMod);
			float[] array = new float[4]
			{
				6f * dNAVarianceMod,
				2f * dNAVarianceMod,
				-2f * dNAVarianceMod,
				-6f * dNAVarianceMod
			};
			ShuffleClass.Shuffle<float>((IList<float>)array, false);
			Health = (long)gaussianGenerator.NextDouble(128f + array[0], 13f * dNAVarianceMod);
			Speed = (long)gaussianGenerator.NextDouble(128f + array[1], 13f * dNAVarianceMod);
			Armor = (long)gaussianGenerator.NextDouble(128f + array[2], 13f * dNAVarianceMod);
			Size = (long)gaussianGenerator.NextDouble(128f + array[3], 13f * dNAVarianceMod);
			Productivity = Math.Max((long)gaussianGenerator.NextDouble(CreatureGenetics.centerProd, 13f * dNAVarianceMod), 0L);
			Drops = Math.Max((long)gaussianGenerator.NextDouble(CreatureGenetics.centerDrop, 13f * dNAVarianceMod), 0L);
		}

		public void setAttributes()
		{
			DBG.blogDebug("setting attributes");
			if (!Object.op_Implicit((Object)(object)chr))
			{
				SetZDO();
				return;
			}
			HoverText = "";
			if (CreatureGenetics.useDNAColor.Value)
			{
				Transform val = ((Component)this).transform.Find("Visual");
				if (Object.op_Implicit((Object)(object)val) && (postLevelEffect || (!Object.op_Implicit((Object)(object)((Component)val).GetComponent<LevelEffects>()) && !CreatureGenetics.useSLS)))
				{
					DBG.blogDebug("Setting Color: " + (lateSetInit ? "Late" : "On Time"));
					setCompleteColor(postLevel: true);
				}
			}
			if (CreatureGenetics.useDNATraits.Value)
			{
				setTraits();
			}
		}

		public bool setCompleteColor(bool postLevel = false, Renderer overwriteRender = null)
		{
			if (lateSetInit)
			{
				DBG.blogDebugExtra("too early to init");
				return false;
			}
			DBG.blogDebug("Colors=" + R + "," + G + "," + B);
			Transform val = ((Component)this).transform.Find("Visual");
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			bool value = CreatureGenetics.onlyDNABrightness.Value;
			Renderer[] renderers = Renderers;
			foreach (Renderer val2 in renderers)
			{
				int count = Regex.Matches(((Object)val2.material).name, "Instance").Count;
				if (count > 1)
				{
					setSingleColor(val2.material, postLevel, value);
				}
			}
			IEnumerable<Renderer> enumerable = ((Component)val).GetComponentsInChildren<Renderer>().Except(Renderers);
			if (Object.op_Implicit((Object)(object)overwriteRender) & !enumerable.Contains(overwriteRender))
			{
				enumerable.Append(overwriteRender);
			}
			foreach (Renderer item in enumerable)
			{
				setSingleColor(item.material, postLevel, value);
			}
			Renderers = Renderers.Concat(enumerable).ToArray();
			return true;
		}

		public void setSingleColor(Material mat, bool postLevel = false, bool onlyBright = false)
		{
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			if (!mat.HasProperty("_Color"))
			{
				return;
			}
			if (firstColor)
			{
				firstColor = false;
				if (onlyBright)
				{
					colorMulti = new Color((float)(R * R) / 63773f + (float)R / 172f, (float)(R * R) / 63773f + (float)R / 172f, (float)(R * R) / 63773f + (float)R / 172f);
				}
				else
				{
					colorMulti = new Color((float)(R * R) / 63773f + (float)R / 172f, (float)(G * G) / 63773f + (float)G / 172f, (float)(B * B) / 63773f + (float)B / 172f);
				}
			}
			string text = ((Object)mat).name.Replace(" (Instance)", "").Replace("(Clone)", "");
			Color val;
			if (baseColorTbl.TryGetValue(text, out var value))
			{
				if (checkSimilarity(mat.color, value))
				{
					return;
				}
				val = value;
			}
			else
			{
				baseColorTbl.Add(text, mat.color);
				val = mat.color;
				DBG.blogDebug("New Color for " + text + ":" + ((object)Unsafe.As<Color, Color>(ref colorMulti)/*cast due to .constrained prefix*/).ToString());
			}
			if (!hueShifted && mat.HasProperty("_Hue"))
			{
				float num = mat.GetFloat("_Hue");
				if (num != 0f)
				{
					colorMulti = Utils.ShiftHue(colorMulti, 0f - mat.GetFloat("_Hue"));
					hueShifted = true;
				}
			}
			Color color = val * colorMulti;
			mat.color = color;
		}

		public bool checkSimilarity(Color thisColor, Color baseColor)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			Color val = baseColor * colorMulti;
			if (object.Equals(thisColor, val))
			{
				return true;
			}
			return false;
		}

		public void restoreColor()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if (CreatureGenetics.useDNAColor.Value)
			{
				Renderer[] renderers = Renderers;
				Color color = default(Color);
				foreach (Renderer val in renderers)
				{
					Material material = val.material;
					((Color)(ref color))..ctor(baseColor.r, baseColor.g, baseColor.b, material.color.a);
					material.color = color;
				}
				Renderers = (Renderer[])(object)new Renderer[0];
			}
		}

		public void setTraits(bool onlysize = false)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			DBG.blogDebug("setting traits for " + ((Object)((Component)this).gameObject).name);
			int num = (int)Mathf.Clamp((float)Size, (float)CreatureGenetics.sizeMin256, (float)CreatureGenetics.sizeMax256);
			Transform transform = ((Component)chr).transform;
			transform.localScale *= (float)(num * num) / 130000f + (float)num / 200f + 0.25f;
			if (onlysize)
			{
				return;
			}
			Transform val = ((Component)this).transform.Find("Visual");
			if (Object.op_Implicit((Object)(object)val))
			{
				LODGroup component = ((Component)val).GetComponent<LODGroup>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.size *= Mathf.Max((float)(num * num / 17150 - num / 52) + 2.5f, 1f);
				}
			}
			if (!getOGData())
			{
				DBG.blogWarning("Could not get OG Data");
				return;
			}
			chr.SetupMaxHealth();
			modifySpeed();
			setProcreationTime();
		}

		public void setProcreationTime()
		{
			Procreation component = ((Component)this).gameObject.GetComponent<Procreation>();
			if (Object.op_Implicit((Object)(object)component))
			{
				float num = (component.m_updateInterval /= 0.6f + (float)Productivity * CreatureGenetics.ProdMultiplier);
				((MonoBehaviour)this).InvokeRepeating("Procreate", Random.Range(num, num * 1.5f), num);
				DBG.blogDebug("New Procreation Time=" + num);
			}
		}

		public bool getOGData()
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)chr))
			{
				return false;
			}
			if (!ogData.filled)
			{
				ogData.acceleration = chr.m_acceleration;
				ogData.flyFastSpeed = chr.m_flyFastSpeed;
				ogData.flyTurnSpeed = chr.m_flyTurnSpeed;
				ogData.runSpeed = chr.m_runSpeed;
				ogData.runTurnSpeed = chr.m_runTurnSpeed;
				ogData.swimAcceleration = chr.m_swimAcceleration;
				ogData.swimSpeed = chr.m_swimSpeed;
				ogData.swimTurnSpeed = chr.m_swimTurnSpeed;
				ogData.prefSize = ((Component)chr).transform.localScale.x;
				ogData.filled = true;
			}
			return true;
		}

		public void modifySpeed()
		{
			if (!modifiedSpeed || !Object.op_Implicit((Object)(object)chr))
			{
				modifiedSpeed = true;
				float num = (float)Speed / 128f;
				if (num < 0.01f)
				{
					num = 0.01f;
				}
				DBG.blogDebug("Speed=" + Speed + ", speedMulti=" + num);
				Character obj = chr;
				obj.m_acceleration *= num;
				Character obj2 = chr;
				obj2.m_flyFastSpeed *= num;
				Character obj3 = chr;
				obj3.m_flyTurnSpeed *= num;
				Character obj4 = chr;
				obj4.m_runSpeed *= num;
				Character obj5 = chr;
				obj5.m_runTurnSpeed *= num;
				Character obj6 = chr;
				obj6.m_swimAcceleration *= num;
				Character obj7 = chr;
				obj7.m_swimSpeed *= num;
				Character obj8 = chr;
				obj8.m_swimTurnSpeed *= num;
			}
		}

		public void forceSetDNA()
		{
			DNA_Strand = m_nview.GetZDO().GetByteArray("CG_DNA", (byte[])null);
			if (DNA_Strand == null || DNA_Strand[4] == 1)
			{
				DBG.blogDebugExtra("Set Random DNA");
				SetRandomDNA();
				SetZDO();
			}
		}

		public GeneticPkg getGeneticPkg()
		{
			if (thisPkg != null)
			{
				DBG.blogDebugExtra("already has pkg=" + thisPkg.prefabName);
				return thisPkg;
			}
			DBG.blogDebugExtra("making new pkg for=" + ((Object)((Component)this).gameObject).name);
			thisPkg = new GeneticPkg();
			thisPkg.id = ((Object)m_nview).GetInstanceID();
			thisPkg.DNA = DNA_Strand;
			Character component = ((Component)this).gameObject.GetComponent<Character>();
			thisPkg.prefabName = ((Object)component).name.Replace("(Clone)", "");
			thisPkg.lvl = component.GetLevel();
			if (CreatureGenetics.useCLLC)
			{
				thisPkg.effect = CLLC.GetExtraEffectCreature(component);
				thisPkg.infusion = CLLC.GetInfusionCreature(component);
			}
			if (CreatureGenetics.useSLS)
			{
				thisPkg.SLS = SLS_CG.getModifiers(component);
			}
			if (CreatureGenetics.useMonMod)
			{
				thisPkg.MonMod = MonMod_CG.getModifiers(component);
			}
			return thisPkg;
		}

		public void CheckOffspringReady()
		{
			DBG.blogDebug("checking offspring ready");
			if (partnerPkg == null)
			{
				SetOffspring();
				return;
			}
			if (savedOffspring == "")
			{
				savedOffspring = m_nview.GetZDO().GetString("OffspringName", "");
				if (savedOffspring == "")
				{
					SetOffspring();
					return;
				}
				DBG.blogDebug("Grabbed savedOffspring from zdo: " + savedOffspring);
			}
			Procreation component = ((Component)this).gameObject.GetComponent<Procreation>();
			if ((Object)(object)component == (Object)null)
			{
				DBG.blogWarning("Does not have procreation");
				return;
			}
			GameObject offspringPrefab = component.m_offspringPrefab;
			if (((offspringPrefab != null) ? ((Object)offspringPrefab).name : null) != savedOffspring)
			{
				DBG.blogDebug("savedOffspring=" + savedOffspring + ", offspringpref=" + ((offspringPrefab != null) ? ((Object)offspringPrefab).name : null));
				GameObject prefab = ZNetScene.instance.GetPrefab(savedOffspring);
				if ((Object)(object)prefab == (Object)null)
				{
					ResetOffspring();
				}
				else
				{
					component.m_offspringPrefab = prefab;
				}
			}
		}

		public void ResetOffspring()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			m_nview.GetZDO().Set("CG_Partner", ZDOID.None);
			partnerPkg = null;
			SetOffspring();
		}

		public void SetOffspring()
		{
			GetPartners();
			string prefabName = Utils.GetPrefabName(((Object)((Component)this).gameObject).name);
			if (!CreatureGenetics.customGeneticsList.TryGetValue(prefabName, out var value) || partnerPkg == null)
			{
				return;
			}
			DBG.blogDebugExtra("partnerPkg.prefabName=" + partnerPkg.prefabName);
			foreach (CreatureGenetics.specificMates item in value.ListofRandomOffspring)
			{
				DBG.blogDebugExtra("specmates.prefabName=" + item.prefabName);
			}
			CreatureGenetics.specificMates specificMates = value.ListofRandomOffspring.Find((CreatureGenetics.specificMates x) => x.prefabName == partnerPkg.prefabName);
			if (specificMates == null)
			{
				DBG.blogDebug("Could not find specmate=" + partnerPkg.prefabName);
			}
			else
			{
				Procreation val = default(Procreation);
				if (!((Component)this).gameObject.TryGetComponent<Procreation>(ref val))
				{
					return;
				}
				float num = Random.Range(0f, 100f);
				if (specificMates.possibleOffspring.Count == 0)
				{
					Procreation val2 = null;
					if (num > 50f)
					{
						DBG.blogDebugExtra("Getting PrefabProc from " + partnerPkg.prefabName);
						val2 = ZNetScene.instance.GetPrefab(partnerPkg.prefabName).GetComponent<Procreation>();
						DBG.blogDebugExtra("Getting PrefabProc from " + prefabName);
					}
					else
					{
						if ((Object)(object)value.baseOffspring != (Object)null)
						{
							DBG.blogDebugExtra("customGenes.baseOffspring " + ((Object)value.baseOffspring).name);
							val.m_offspring = value.baseOffspring;
							val.m_offspringPrefab = value.baseOffspring;
							DBG.blogDebugExtra("exiting prefab " + ((Object)val.m_offspring).name);
							val.m_nview.GetZDO().Set("OffspringName", ((Object)val.m_offspring).name);
							savedOffspring = ((Object)val.m_offspring).name;
							return;
						}
						val2 = ZNetScene.instance.GetPrefab(prefabName).GetComponent<Procreation>();
					}
					if ((Object)(object)val2 == (Object)null)
					{
						DBG.blogDebug("PrefabProc is null");
					}
					if ((Object)(object)val2.m_offspring != (Object)null)
					{
						val.m_offspring = val2.m_offspring;
						val.m_offspringPrefab = val2.m_offspring;
					}
					else if ((Object)(object)val2.m_offspringPrefab != (Object)null)
					{
						val.m_offspring = val2.m_offspringPrefab;
						val.m_offspringPrefab = val2.m_offspringPrefab;
					}
					if (num < 50f)
					{
						DBG.blogDebugExtra("Setting baseOffspring=" + (object)val.m_offspring);
						value.baseOffspring = val.m_offspring;
					}
					DBG.blogDebugExtra("exiting prefab " + ((Object)val.m_offspring).name);
					val.m_nview.GetZDO().Set("OffspringName", ((Object)val.m_offspring).name);
					savedOffspring = ((Object)val.m_offspring).name;
					return;
				}
				float num2 = 0f;
				DBG.blogDebugExtra("Determining chance for offspring of " + specificMates.prefabName);
				foreach (CreatureGenetics.chanceOffspring item2 in specificMates.possibleOffspring)
				{
					num2 += item2.chance;
					DBG.blogDebugExtra("currentchance=" + num2 + ", rndm=" + num);
					if (!(num2 >= num))
					{
						continue;
					}
					DBG.blogDebugExtra("finalchance=" + num2 + ", rndm=" + num);
					if ((Object)(object)item2.offspring == (Object)null)
					{
						DBG.blogDebugExtra("grabbing new prefab=" + item2.prefabName);
						item2.offspring = ZNetScene.instance.GetPrefab(item2.prefabName);
						if ((Object)(object)item2.offspring == (Object)null)
						{
							DBG.blogWarning("could not find prefab with name=" + item2.prefabName);
						}
					}
					val.m_offspring = item2.offspring;
					val.m_offspringPrefab = item2.offspring;
					DBG.blogDebug("proc.m_offspring=" + ((Object)val.m_offspring).name);
					val.m_nview.GetZDO().Set("OffspringName", ((Object)val.m_offspring).name);
					savedOffspring = ((Object)val.m_offspring).name;
					return;
				}
				DBG.blogDebug("Did not get chance offspring of " + specificMates.prefabName);
				if ((Object)(object)value.baseOffspring != (Object)null)
				{
					DBG.blogDebugExtra("customGenes.baseOffspring " + ((Object)value.baseOffspring).name);
					val.m_offspring = value.baseOffspring;
					val.m_offspringPrefab = value.baseOffspring;
					DBG.blogDebugExtra("exiting prefab " + ((Object)val.m_offspring).name);
					val.m_nview.GetZDO().Set("OffspringName", ((Object)val.m_offspring).name);
					savedOffspring = ((Object)val.m_offspring).name;
					return;
				}
				Procreation component = ZNetScene.instance.GetPrefab(prefabName).GetComponent<Procreation>();
				if ((Object)(object)component == (Object)null)
				{
					DBG.blogDebug("baseProc is null");
				}
				if ((Object)(object)component.m_offspring != (Object)null)
				{
					val.m_offspring = component.m_offspring;
					val.m_offspringPrefab = component.m_offspring;
				}
				else if ((Object)(object)component.m_offspringPrefab != (Object)null)
				{
					val.m_offspring = component.m_offspringPrefab;
					val.m_offspringPrefab = component.m_offspringPrefab;
				}
				value.baseOffspring = val.m_offspring;
				val.m_nview.GetZDO().Set("OffspringName", ((Object)val.m_offspring).name);
				savedOffspring = ((Object)val.m_offspring).name;
				DBG.blogDebug("exiting baseProc " + ((Object)val.m_offspring).name);
			}
		}

		public unsafe void GetPartners()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			if (partnerPkg != null)
			{
				return;
			}
			ZDOID zDOID = m_nview.GetZDO().GetZDOID("CG_Partner");
			if (zDOID != ZDOID.None)
			{
				ZDOID val = zDOID;
				DBG.blogDebugExtra("Found partner zdoid=" + ((object)(*(ZDOID*)(&val))/*cast due to .constrained prefix*/).ToString());
				GameObject val2 = ZNetScene.instance.FindInstance(zDOID);
				Genetics genetics = default(Genetics);
				if ((Object)(object)val2 != (Object)null && val2.TryGetComponent<Genetics>(ref genetics))
				{
					string name = ((Object)val2).name;
					val = zDOID;
					DBG.blogDebug("Found partner instance=" + name + ":" + ((object)(*(ZDOID*)(&val))/*cast due to .constrained prefix*/).ToString());
					DBG.blogDebugExtra("partnerGenes=" + genetics.savedOffspring);
					partnerPkg = genetics.getGeneticPkg();
					return;
				}
			}
			else
			{
				DBG.blogDebugExtra("No partner ZDOID found for=" + ((Object)m_nview).name);
			}
			string prefabName = Utils.GetPrefabName(((Object)((Component)this).gameObject).name);
			List<string> list = new List<string>();
			if (CreatureGenetics.customGeneticsList.TryGetValue(prefabName, out var value))
			{
				if (value.mateNames.Count == 0 && value.canMateWithSelf)
				{
					value.mateNames.Add(((Object)((Component)this).gameObject).name);
				}
				list = value.mateNames;
			}
			else
			{
				list.Add(((Object)((Component)this).gameObject).name);
			}
			Character val3 = null;
			float num = 999999f;
			List<Character> allCharacters = Character.GetAllCharacters();
			GameObject gameObject = ((Component)this).gameObject;
			DBG.blogDebug("Finding closest mate");
			bool flag = false;
			Tameable val4 = default(Tameable);
			foreach (Character item in allCharacters)
			{
				bool flag2 = false;
				if ((Object)(object)((Component)item).gameObject == (Object)(object)gameObject || !((Component)item).GetComponent<ZNetView>().IsValid() || !list.Contains(((Object)item).name) || !((Component)item).TryGetComponent<Tameable>(ref val4))
				{
					continue;
				}
				if (val4.IsHungry())
				{
					flag2 = true;
				}
				DBG.blogDebugExtra("Not skipping " + ((Object)item).name);
				float num2 = Vector3.Distance(((Component)item).transform.position, ((Component)this).transform.position);
				if ((flag && !flag2) || num2 < num)
				{
					DBG.blogDebugExtra("character with name go:" + ((Object)((Component)item).gameObject).name + " is " + Vector3.Distance(((Component)item).transform.position, ((Component)this).transform.position) + "m away");
					val3 = item;
					num = num2;
					flag = flag2;
					if (flag2)
					{
						DBG.blogDebugExtra(((Object)item).name + "is nearest mate even though hungry");
					}
				}
			}
			if ((Object)(object)val3 != (Object)null)
			{
				DBG.blogDebug("Partner with name go:" + ((Object)((Component)val3).gameObject).name + " is " + Vector3.Distance(((Component)val3).transform.position, ((Component)this).transform.position) + "m away");
				partnerPkg = ((Component)val3).GetComponent<Genetics>().getGeneticPkg();
				m_nview.GetZDO().Set("CG_Partner", val3.m_nview.GetZDO().m_uid);
			}
			else
			{
				DBG.blogDebug("Could not find partner");
				partnerPkg = new GeneticPkg();
				partnerPkg.DNA = baseDNA.ToArray();
				partnerPkg.lvl = ((Component)this).gameObject.GetComponent<Character>().GetLevel();
			}
		}

		public static int GetNewLvl(int lvl, int lvl2)
		{
			if (CreatureGenetics.allowLvlMutation.Value && Random.Range(0f, 100f) < CreatureGenetics.MutationChanceLvl.Value)
			{
				DBG.blogDebug("Has Mutation in Level");
				int num = Mathf.Max(Mathf.Min(lvl, lvl2) - 1, 1);
				int num2 = Mathf.Max(lvl, lvl2) + 1;
				DBG.blogDebugExtra("min=" + num + ", max=" + num2);
				int num3 = Mathf.Min(100, Random.Range(0, 100) + 10);
				DBG.blogDebugExtra("level_min=" + num + ", rndm=" + num3 + ", float=" + ((float)num + (float)num3 * ((float)num2 - (float)num) / 100f));
				lvl = num + Mathf.RoundToInt((float)(num3 * (num2 - num)) / 100f);
				if (CreatureGenetics.MaxMutationLvl.Value > 0 && lvl > CreatureGenetics.MaxMutationLvl.Value)
				{
					lvl = CreatureGenetics.MaxMutationLvl.Value;
				}
			}
			else if (Random.Range(0, 100) > 50)
			{
				DBG.blogDebugExtra("IsDadLvl");
				lvl = lvl2;
			}
			return lvl;
		}

		public byte[][] makeMinMaxDNA()
		{
			byte[][] array = new byte[10][];
			byte[] dNA = partnerPkg.DNA;
			DBG.blogDebugExtra("DNA_Strand.lrngth=" + DNA_Strand.Length);
			DBG.blogDebugExtra("minmaxDNA.lrngth=" + array.Length);
			for (int i = 0; i < array.Length; i++)
			{
				if (DNA_Strand[i] < dNA[i])
				{
					array[i] = new byte[2]
					{
						DNA_Strand[i],
						dNA[i]
					};
				}
				else
				{
					array[i] = new byte[2]
					{
						dNA[i],
						DNA_Strand[i]
					};
				}
				DBG.blogDebugExtra("minmaxDNA[" + i + "]=" + string.Join(",", array[i]));
			}
			DBG.blogDebugExtra("minmaxDNA.completed");
			return array;
		}

		public float[] calcPropMultiplier(int traitNum, ref byte[] newDNA, byte[][] MinMaxDNA)
		{
			float[,] influenceMatrix = GeneticsPatches.getInfluenceMatrix();
			float num = 1f;
			float num2 = 1f;
			float num3 = 127.5f;
			for (int i = 0; i < 10 - traitOffset; i++)
			{
				num3 = i switch
				{
					4 => CreatureGenetics.centerProd, 
					5 => CreatureGenetics.centerDrop, 
					_ => 127.5f, 
				};
				num *= influenceMatrix[traitNum, i] / 127.5f * ((float)(int)MinMaxDNA[i + traitOffset][0] - num3) + 1f;
				DBG.blogDebugExtra("minMulti " + i + "=" + num + ",minTrait=" + MinMaxDNA[i + traitOffset][0] + ",center=" + num3);
				num2 *= influenceMatrix[traitNum, i] / 127.5f * ((float)(int)MinMaxDNA[i + traitOffset][1] - num3) + 1f;