Decompiled source of PortablePals v0.0.2

PortablePals.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using AllTameable.DNA;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CLLC;
using CreatureLevelControl;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using PortablePals;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PortablePals")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PortablePals")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("db3f13a2-a323-4902-ad30-87a28b8836b6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CLLC
{
	[HarmonyPatch(typeof(CreatureLevelControl), "PatchSize")]
	public class CLLC_Patches
	{
		private static bool Prefix(CreatureLevelControl __instance, EnemyLevelData originalData, out Vector3 __state)
		{
			//IL_000f: 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)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)originalData).gameObject;
			__state = gameObject.transform.localScale;
			TimedScaleAndFreeze timedScaleAndFreeze = default(TimedScaleAndFreeze);
			if ((((Object)(object)gameObject != (Object)null) & gameObject.TryGetComponent<TimedScaleAndFreeze>(ref timedScaleAndFreeze)) && timedScaleAndFreeze.CLLC_Scale != 1f)
			{
				DBG.blogDebug("Already Scaled by CLLC");
				__state = Vector3.zero;
				return false;
			}
			return true;
		}

		private static void Postfix(CreatureLevelControl __instance, EnemyLevelData originalData, Vector3 __state)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (!(__state == Vector3.zero))
			{
				GameObject gameObject = ((Component)originalData).gameObject;
				TimedScaleAndFreeze tsf = default(TimedScaleAndFreeze);
				if ((Object)(object)gameObject != (Object)null && gameObject.TryGetComponent<TimedScaleAndFreeze>(ref tsf))
				{
					float scale = gameObject.transform.localScale.x / __state.x;
					DBG.blogDebug("In CLLC Patch with scale=" + scale);
					CatchPal.checkScales(gameObject, isCLLC: true, tsf, scale);
				}
			}
		}
	}
}
namespace PortablePals
{
	internal class CatchPal
	{
		public static string releaseZDOKey = "PP_Release";

		public static float tsf_startScale = 0.1f;

		public static float tsf_startTime = 0.6f;

		public static float tsf_duration = 1.1f;

		public static GameObject Staging;

		public const int maxCatchDist = 15;

		public static Vector3 throwforce = new Vector3(-50f, 450f, 200f);

		public static ForceMode forceMode = (ForceMode)0;

		public static Vector3 throwLoc = new Vector3(0.4f, 0.9f, -0.04f);

		public static int catcherHash = StringExtensionMethods.GetStableHashCode("PP_Catcher");

		[HarmonyPatch(typeof(Character), "Awake")]
		[HarmonyPostfix]
		private static void RegisterRPCs(Character __instance)
		{
			ZNetView nview = __instance.m_nview;
			nview.Register<ZDOID>("RPC_RequestCatch", (Action<long, ZDOID>)RPC_RequestCatch);
			nview.Register<ZDOID, ZDOID>("RPC_CatchEffect", (Action<long, ZDOID, ZDOID>)RPC_CatchEffect);
			if (nview.GetZDO() != null && nview.GetZDO().GetBool(releaseZDOKey, false))
			{
				DBG.blogDebug("Has Release ZDO");
				ReleaseCreatureEffect(__instance);
				nview.GetZDO().Set(releaseZDOKey, false);
			}
		}

		public static int attemptCatch(Player plr, ItemData item)
		{
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			if (((Character)plr).InAttack())
			{
				DBG.blogDebug("In Attack");
				return 0;
			}
			if (item.m_customData.TryGetValue("PP_Prefab", out var value) && (value ?? "") != "")
			{
				ReleaseCreature(plr, item);
				if (item.m_shared.m_useDurability)
				{
					float maxDurability = item.GetMaxDurability();
					if (item.m_durability > maxDurability)
					{
						item.m_durability = maxDurability;
					}
					item.m_durability -= 1f;
				}
				return 1;
			}
			item.m_shared.m_movementModifier = -0.05f;
			if (float.TryParse(GeneralExtensions.GetValueSafe<string, string>(item.m_customData, "PP_LastCatch"), out var result))
			{
				float num = Math.Abs(result - Time.time);
				if (num < 0.3f)
				{
					DBG.blogDebug("Catch already in Progress");
					return 0;
				}
				if (num < Plugin.cooldown.Value)
				{
					DBG.blogDebug("In Cooldown:" + result);
					((Character)plr).Message((MessageType)2, "Item in cooldown, try again in " + (int)(Plugin.cooldown.Value - num + 1f) + "s", 0, (Sprite)null);
					return 0;
				}
			}
			Character val = null;
			GameObject val2 = null;
			plr.FindHoverObject(ref val2, ref val);
			if ((Object)(object)val != (Object)null)
			{
				if (Vector3.Distance(((Character)plr).m_eye.position, ((Component)val).transform.position) < 15f)
				{
					DBG.blogDebug("hovering=" + val.m_name);
					if (CatchCreature(plr, item, val))
					{
						return 2;
					}
					DBG.blogDebug("Failed to attempt catch=" + ((Object)val).name);
					return 0;
				}
				DBG.blogDebug("to far away from=" + ((Object)val).name);
				return 0;
			}
			DBG.blogDebug("no creature to catch");
			return 0;
		}

		private static bool CatchCreature(Player plr, ItemData item, Character hovCreature)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			if (!hovCreature.m_nview.IsValid() || !hovCreature.IsTamed())
			{
				return false;
			}
			item.m_shared.m_movementModifier = -0.9f;
			ZDO zDO = hovCreature.m_nview.GetZDO();
			long @long = zDO.GetLong(catcherHash, 0L);
			DBG.blogDebug("Catcher uid=" + @long);
			ZDOID zDOID = zDO.GetZDOID("PP_Catcher");
			if (((ZDOID)(ref zDOID)).UserID != 0)
			{
				DBG.blogDebug("Already has Catcher ZDOID");
				if (Time.time - zDO.GetFloat("PP_CatcherTime", 0f) < 5f)
				{
					return false;
				}
				DBG.blogDebug("Time has passed, attempting Catch");
			}
			if (@long != 0)
			{
				DBG.blogDebug("Already has Catcher");
			}
			Utils2.addOrUpdateCustomData(item.m_customData, "PP_LastCatch", Time.time.ToString());
			DBG.blogDebug("Set lastCatch to: " + Time.time);
			zDO.Set("PP_Catcher", ((Character)plr).m_nview.GetZDO().m_uid);
			zDO.Set("PP_CatcherTime", Time.time);
			DBG.blogDebug("Set ZDOID");
			ZDOID zDOID2 = zDO.GetZDOID("PP_Catcher");
			ZDOID uid = zDO.m_uid;
			DBG.blogDebug("found ZDOID");
			GameObject val = ZNetScene.instance.FindInstance(zDOID2);
			DBG.blogDebug("got go");
			DBG.blogDebug("go name=" + ((Object)val).name);
			hovCreature.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_RequestCatch", new object[1] { uid });
			((MonoBehaviour)hovCreature).StartCoroutine(CatchUpdate(hovCreature));
			return true;
		}

		private static bool SaveCreatureToItem(Player plr, Character hovCreature)
		{
			if (!hovCreature.m_nview.IsValid() || !hovCreature.IsTamed())
			{
				return false;
			}
			ItemData rightItem = ((Humanoid)plr).m_rightItem;
			if (rightItem == null || !((Object)rightItem.m_dropPrefab).name.Contains("PalStone"))
			{
				return false;
			}
			Dictionary<string, string> customData = rightItem.m_customData;
			Utils2.addOrUpdateCustomData(customData, "PP_Prefab", hovCreature.m_nview.GetPrefabName());
			Utils2.addOrUpdateCustomData(customData, "PP_Name", hovCreature.m_nview.GetZDO().GetString(StringExtensionMethods.GetStableHashCode("TamedName"), ""));
			Utils2.addOrUpdateCustomData(customData, "PP_Lvl", hovCreature.m_level.ToString());
			Utils2.addOrUpdateCustomData(customData, "PP_Health", hovCreature.GetHealth().ToString());
			float num = (float)hovCreature.m_nview.GetZDO().GetLong(ZDOVars.s_tameLastFeeding, 0L) / 10000000f;
			Utils2.addOrUpdateCustomData(customData, "PP_LastFed", ((int)(ZNet.instance.m_netTime - (double)num)).ToString());
			Humanoid val = (Humanoid)(object)((hovCreature is Humanoid) ? hovCreature : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				Utils2.addOrUpdateCustomData(customData, "PP_Seed", val.m_seed.ToString());
			}
			DBG.blogDebug("Health=" + hovCreature.GetHealth());
			if (Plugin.hasCLLC)
			{
				Utils2.addOrUpdateCustomData(customData, "PP_CLLC", CLLC.CLLC_getInfusion(hovCreature) + "," + CLLC.CLLC_getEffect(hovCreature));
			}
			if (Plugin.hasAT)
			{
				Utils2.addOrUpdateCustomData(customData, "PP_DNA", AllTame_API.GetDNA(hovCreature));
			}
			Tameable tamable = hovCreature.m_baseAI.m_tamable;
			if ((Object)(object)tamable != (Object)null && tamable.HaveSaddle())
			{
				DBG.blogDebug("Has Saddle");
				Utils2.addOrUpdateCustomData(customData, "PP_Saddle", "true");
			}
			else
			{
				Utils2.addOrUpdateCustomData(customData, "PP_Saddle", "false");
			}
			return true;
		}

		private static void ReleaseCreatureEffect(Character character)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			DBG.blogDebug("Releasing Creature Effect");
			GameObject gameObject = ((Component)character).gameObject;
			TimedScaleAndFreeze timedScaleAndFreeze = gameObject.AddComponent<TimedScaleAndFreeze>();
			timedScaleAndFreeze.ZNetDestroy = false;
			timedScaleAndFreeze.startScale = tsf_startScale;
			timedScaleAndFreeze.startimeScale = tsf_startTime;
			timedScaleAndFreeze.duration = tsf_duration;
			timedScaleAndFreeze.roughness = 0.02f;
			timedScaleAndFreeze.breakChild = -1;
			ZNetView nview = character.m_nview;
			if (Object.op_Implicit((Object)(object)nview) && nview.IsValid())
			{
				timedScaleAndFreeze.ogScale = nview.GetZDO().GetVec3("PP_Scale", Vector3.one);
			}
			else
			{
				DBG.blogWarning("Failed to grab zdo scale for " + ((Object)character).name);
				timedScaleAndFreeze.ogScale = gameObject.transform.localScale;
			}
			((Component)character).transform.localScale = timedScaleAndFreeze.ogScale * tsf_startScale;
			if (!Object.op_Implicit((Object)(object)gameObject))
			{
				DBG.blogWarning("Failed to release " + ((Object)character).name);
				return;
			}
			VisEquipment component = gameObject.GetComponent<VisEquipment>();
			if (Plugin.hasAT)
			{
				AllTame_API.setDNAHash(gameObject, nview);
			}
			if ((Object)(object)component != (Object)null)
			{
				DBG.blogDebug("has visequ");
				((Component)component.m_rightHand).gameObject.SetActive(false);
				((Component)component.m_leftHand).gameObject.SetActive(false);
				((Behaviour)component).enabled = false;
				Humanoid val = (Humanoid)(object)((character is Humanoid) ? character : null);
				if ((Object)(object)val != (Object)null)
				{
					val.GiveDefaultItems();
				}
			}
			else
			{
				DBG.blogDebug("no visequ");
			}
			gameObject.SetActive(true);
			((Behaviour)character).enabled = false;
		}

		public static void checkScales(GameObject go, bool isCLLC, TimedScaleAndFreeze tsf, float scale)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			if (scale == 1f || scale > 5f || Math.Abs(tsf.DNA_Scale - scale) < 0.001f || Math.Abs(tsf.CLLC_Scale - scale) < 0.001f)
			{
				DBG.blogDebug("Seems like duplicate Scale=" + scale);
				Transform transform = go.transform;
				transform.localScale /= scale;
			}
			else if (isCLLC)
			{
				if (tsf.CLLC_Scale != 1f)
				{
					DBG.blogDebug("Postfix Already Scaled by CLLC ");
					return;
				}
				tsf.CLLC_Scale = scale;
				DBG.blogDebug("CLLC Scale Modified by " + scale + ": lvl=" + go.GetComponent<Character>().GetLevel() + ": tamed=" + go.GetComponent<Character>().m_tamed);
				tsf.exteriorScale *= scale;
			}
			else if (tsf.DNA_Scale != 1f)
			{
				DBG.blogDebug("Postfix Already Scaled by DNA ");
			}
			else
			{
				DBG.blogDebug("DNA Scale Modified by " + scale);
				tsf.DNA_Scale = scale;
				tsf.exteriorScale *= scale;
			}
		}

		private static bool ReleaseCreature(Player plr, ItemData item)
		{
			//IL_0050: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_054a: Unknown result type (might be due to invalid IL or missing references)
			//IL_056b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0570: Unknown result type (might be due to invalid IL or missing references)
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_0583: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0603: Unknown result type (might be due to invalid IL or missing references)
			//IL_062a: Unknown result type (might be due to invalid IL or missing references)
			//IL_066b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0670: Unknown result type (might be due to invalid IL or missing references)
			//IL_067d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0682: Unknown result type (might be due to invalid IL or missing references)
			DBG.blogDebug("Releasing Creature local");
			Dictionary<string, string> customData = item.m_customData;
			customData.TryGetValue("PP_Prefab", out var value);
			GameObject prefab = ZNetScene.instance.GetPrefab(StringExtensionMethods.GetStableHashCode(value));
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				return true;
			}
			Vector3 val = ((Component)plr).transform.position + ((Component)plr).transform.rotation * throwLoc;
			Vector3 localScale = prefab.transform.localScale;
			Vector3 val2 = localScale;
			DBG.blogDebug("StartScale=" + ((object)(Vector3)(ref val2)).ToString());
			GameObject val3 = Object.Instantiate<GameObject>(prefab, val, Quaternion.Euler(0f, (float)Random.Range(0, 360), 0f));
			val2 = val3.transform.localScale;
			DBG.blogDebug("Scale=" + ((object)(Vector3)(ref val2)).ToString());
			val3.transform.localScale = localScale;
			val2 = val3.transform.localScale;
			DBG.blogDebug("locaScale post Set Scale=" + ((object)(Vector3)(ref val2)).ToString());
			DBG.blogDebug("Created Creature");
			Character component = val3.GetComponent<Character>();
			component.m_nview.GetZDO().Set(releaseZDOKey, true);
			if (customData.TryGetValue("PP_Saddle", out var value2) && value2 == "true")
			{
				DBG.blogDebug("Attempting Saddle");
				component.m_nview.GetZDO().Set(ZDOVars.s_haveSaddleHash, true);
				if ((Object)(object)component.m_baseAI != (Object)null && (Object)(object)component.m_baseAI.m_tamable != (Object)null)
				{
					DBG.blogDebug("Attempting Set Saddle");
					component.m_baseAI.m_tamable.SetSaddle(true);
				}
			}
			Humanoid val4 = (Humanoid)(object)((component is Humanoid) ? component : null);
			if (Object.op_Implicit((Object)(object)val4) && int.TryParse(GeneralExtensions.GetValueSafe<string, string>(customData, "PP_Seed"), out var result))
			{
				val4.m_seed = result;
				component.m_nview.GetZDO().Set(ZDOVars.s_seed, result, true);
				DBG.blogDebug("Set Seed");
			}
			component.SetTamed(true);
			val2 = val3.transform.localScale;
			DBG.blogDebug("locaScale post Set Tame=" + ((object)(Vector3)(ref val2)).ToString());
			if (customData.TryGetValue("PP_Name", out var value3) && value3 != "")
			{
				val3.GetComponent<Tameable>().SetText(value3);
			}
			else
			{
				DBG.blogDebug("No Specific Name");
			}
			if (Plugin.hasCLLC && customData.TryGetValue("PP_CLLC", out var value4))
			{
				string[] array = value4.Split(new char[1] { ',' });
				CLLC.SetInfusionCreature(component, array[0]);
				if (array.Length > 1)
				{
					CLLC.SetExtraEffectCreature(component, array[1]);
				}
			}
			bool flag = false;
			if (int.TryParse(GeneralExtensions.GetValueSafe<string, string>(customData, "PP_Lvl"), out var result2))
			{
				component.SetLevel(result2);
			}
			else
			{
				flag = true;
				DBG.blogDebug("Failed to get lvl");
			}
			val2 = val3.transform.localScale;
			DBG.blogDebug("localScale post set lvl Set=" + ((object)(Vector3)(ref val2)).ToString());
			if (flag || !component.IsTamed())
			{
				DBG.blogDebug("Error Occured, Destryoing Creature");
				Object.Destroy((Object)(object)val3);
			}
			val3.SetActive(true);
			val2 = val3.transform.localScale;
			DBG.blogDebug("localScale pre DNA Set=" + ((object)(Vector3)(ref val2)).ToString());
			component.m_nview.GetZDO().Set("PP_Scale", val3.transform.localScale);
			if (Plugin.hasAT && long.TryParse(GeneralExtensions.GetValueSafe<string, string>(customData, "PP_DNA"), out var result3))
			{
				AllTame_API.setDNA(val3, result3);
			}
			if (customData.TryGetValue("PP_Health", out var value5))
			{
				DBG.blogDebug("Attempting Health");
				float.TryParse(value5, out var result4);
				if (result4 > 0f)
				{
					component.SetHealth(result4);
					DBG.blogDebug("Health Read=" + component.GetHealth());
				}
			}
			if (customData.TryGetValue("PP_LastFed", out var value6))
			{
				DBG.blogDebug("Attempting LastFed");
				float.TryParse(value6, out var result5);
				if (result5 != 0f)
				{
					long num = Math.Max(ZNet.instance.GetTime().Ticks - Convert.ToInt64(result5 * 10000000f), 0L);
					DBG.blogDebug("lastFed =" + result5 + ", ticks=" + num);
					component.m_nview.GetZDO().Set(ZDOVars.s_tameLastFeeding, num);
				}
			}
			val2 = val3.transform.localScale;
			DBG.blogDebug("localScale post DNA Set=" + ((object)(Vector3)(ref val2)).ToString());
			localScale = val3.transform.localScale;
			ReleaseCreatureEffect(component);
			val3.GetComponent<TimedScaleAndFreeze>().ogScale = localScale;
			float num2 = Math.Min(val3.GetComponent<Rigidbody>().mass, 110f) - 10f;
			DBG.blogDebug("mass is " + num2);
			val2 = new Vector3(throwforce.x, throwforce.y - 100f * num2 / 110f, throwforce.z + 220f * num2 / 110f);
			DBG.blogDebug("throw is " + ((object)(Vector3)(ref val2)).ToString());
			val3.GetComponent<Rigidbody>().AddForce(((Component)plr).transform.rotation * new Vector3(throwforce.x, throwforce.y - 100f * num2 / 110f, throwforce.z + 220f * num2 / 110f) * (num2 + 10f), forceMode);
			DBG.blogDebug("Added Force to " + value);
			Utils2.addOrUpdateCustomData(((Humanoid)plr).RightItem.m_customData, "PP_Prefab", "");
			return true;
		}

		private static void RPC_RequestCatch(long uid, ZDOID creature)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = ZNetScene.instance.FindInstance(creature);
			ZLog.Log((object)("Player " + uid + " wants to catch " + ((Object)val).name + " im: " + ZDOMan.GetSessionID()));
			ZNetView nview = val.GetComponent<Character>().m_nview;
			if (nview.IsOwner())
			{
				nview.GetZDO().SetOwner(uid);
				ZLog.Log((object)("  Setting Owner to " + uid));
			}
			else if (nview.GetZDO().GetOwner() == uid)
			{
				ZLog.Log((object)"  but they are already the owner PP");
			}
			else
			{
				ZLog.Log((object)"  but neither I nor the requesting player are the owners PP");
			}
		}

		private static IEnumerator CatchUpdate(Character creature)
		{
			yield return (object)new WaitForSeconds(0.1f);
			CatchUpdate_Repeat(creature);
		}

		private static IEnumerator regainControl(Player plr, float time)
		{
			yield return (object)new WaitForSeconds(time);
			regainControl_Repeat(plr, repeat: true);
		}

		private static void regainControl_Repeat(Player plr, bool repeat = false)
		{
			ItemData rightItem = ((Humanoid)plr).RightItem;
			if (rightItem == null || !((Object)rightItem.m_dropPrefab).name.Contains("PalStone"))
			{
				DBG.blogDebug("Invalid Item to regain control from");
				return;
			}
			DBG.blogDebug("Forcing Movement");
			((Character)plr).m_animator.CrossFade("Base Layer.Movement", 0.25f, 0);
			if (rightItem.m_shared.m_movementModifier + 0.2f >= -0.05f)
			{
				DBG.blogDebug("Regained control");
				rightItem.m_shared.m_movementModifier = -0.05f;
				return;
			}
			DBG.blogDebug("decreasing movement penalty");
			SharedData shared = rightItem.m_shared;
			shared.m_movementModifier += 0.2f;
			if (repeat)
			{
				((MonoBehaviour)plr).StartCoroutine(regainControl(plr, 0.1f));
			}
		}

		private static void CatchUpdate_Repeat(Character creature)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			ZNetView nview = creature.m_nview;
			if (!nview.IsValid())
			{
				return;
			}
			ZDOID zDOID = nview.GetZDO().GetZDOID("PP_Catcher");
			long userID = ((ZDOID)(ref zDOID)).UserID;
			long owner = nview.GetZDO().GetOwner();
			DBG.blogDebug("found UID=" + userID);
			DBG.blogDebug("owner=" + owner);
			if (userID == owner)
			{
				ZLog.Log((object)"I can finally Catch");
				if (SaveCreatureToItem(Player.m_localPlayer, creature))
				{
					creature.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_CatchEffect", new object[2]
					{
						nview.GetZDO().m_uid,
						zDOID
					});
				}
				else
				{
					DBG.blogWarning("Failed to save creature data to Item");
				}
				((MonoBehaviour)Player.m_localPlayer).StartCoroutine(regainControl(Player.m_localPlayer, 1.1f));
			}
			else
			{
				regainControl_Repeat(Player.m_localPlayer);
				ZLog.Log((object)"Im still not the owner");
				((MonoBehaviour)creature).StartCoroutine(CatchUpdate(creature));
			}
		}

		private static void RPC_CatchEffect(long uid, ZDOID creature, ZDOID catcher)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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)
			//IL_0045: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = ZNetScene.instance.FindInstance(creature);
			Character component = val.GetComponent<Character>();
			GameObject val2 = ZNetScene.instance.FindInstance(catcher);
			if (component.m_nview.IsValid())
			{
				GameObject val3 = new GameObject("holder");
				val3.SetActive(false);
				val3.transform.position = ((Component)component).transform.position;
				((Component)component).transform.parent = val3.transform;
				val3.AddComponent<TimedColor>();
				TimedDestruction val4 = val3.AddComponent<TimedDestruction>();
				val4.Trigger(2f);
				TimedScaleAndFreeze timedScaleAndFreeze = ((Component)component).gameObject.AddComponent<TimedScaleAndFreeze>().SetRB(((Component)component).GetComponent<Rigidbody>());
				Vector3 endPos = val2.transform.position + val2.transform.rotation * new Vector3(0.288f, 1.8141f, 0.91f);
				timedScaleAndFreeze.SetEndPos(endPos);
				timedScaleAndFreeze.startScale = 1f;
				timedScaleAndFreeze.endScale = 0.01f;
				timedScaleAndFreeze.startimeMove = 0.3f;
				timedScaleAndFreeze.startimeScale = 0f;
				timedScaleAndFreeze.roughness = 0f;
				timedScaleAndFreeze.breakChild = -1;
				timedScaleAndFreeze.setFinalScale = false;
				val3.SetActive(true);
			}
		}
	}
	internal class Patches
	{
		[HarmonyPatch(typeof(InventoryGui), "CanRepair")]
		public static class FixMaxRepairLevel
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				bool skipped = false;
				foreach (CodeInstruction instruction in instructions)
				{
					if (!skipped && instruction.opcode == OpCodes.Ldc_I4_4)
					{
						skipped = true;
						yield return new CodeInstruction(OpCodes.Ldc_I4_8, (object)null);
					}
					else
					{
						yield return instruction;
					}
				}
			}
		}

		public static string catch_anim = "emote_point";

		public static string release_anim = "knife_stab";

		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		[HarmonyPostfix]
		private static void AddItems(ObjectDB __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name == "main")
			{
				PrefabManager.addPortablePalStone();
			}
		}

		[HarmonyPatch(typeof(Attack), "Start")]
		[HarmonyPrefix]
		private static bool Attack_Start(Attack __instance, Humanoid character, ZSyncAnimation zanim, ItemData weapon, ref float timeSinceLastAttack)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			if (weapon == null)
			{
				return true;
			}
			if ((Object)(object)weapon.m_dropPrefab == (Object)null || !((Object)weapon.m_dropPrefab).name.Contains("PalStone"))
			{
				return true;
			}
			if (Math.Abs(Time.time - weapon.m_lastAttackTime) < 1.1f)
			{
				DBG.blogDebug("too soon");
				return false;
			}
			weapon.m_shared.m_movementModifier = -0.05f;
			DBG.blogDebug("inPalStoneAttackAwake");
			int num = CatchPal.attemptCatch((Player)character, weapon);
			if (((Character)character).IsPlayer() && num <= 0)
			{
				weapon.m_lastAttackTime = Time.time;
				((Character)character).m_attack = true;
				return false;
			}
			if (num == 2)
			{
				__instance.m_attackAnimation = catch_anim;
				__instance.m_attackChainLevels = 1;
				zanim.SetSpeed(4f);
				zanim.m_animator.speed = 3f;
			}
			else
			{
				__instance.m_attackAnimation = release_anim;
				__instance.m_attackChainLevels = 3;
				zanim.SetSpeed(0.5f);
				zanim.m_animator.speed = 0.5f;
			}
			weapon.m_lastAttackTime = Time.time;
			DBG.blogDebug("animation=" + __instance.m_attackAnimation);
			return true;
		}

		[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(bool),
			typeof(float)
		})]
		[HarmonyPostfix]
		private static void Postfix(ItemData item, bool crafting, int qualityLevel, ref string __result)
		{
			if (Object.op_Implicit((Object)(object)item.m_dropPrefab) && ((Object)item.m_dropPrefab).name.Contains("PalStone"))
			{
				__result = Build_PalStone_Description(item, crafting, qualityLevel);
			}
		}

		private static string Build_PalStone_Description(ItemData item, bool crafting, int quality)
		{
			Player localPlayer = Player.m_localPlayer;
			string text = "\n";
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(item.m_shared.m_description);
			stringBuilder.Append("\n");
			if (item.m_crafterID != 0)
			{
				stringBuilder.AppendFormat("\n$item_crafter: <color=orange>{0}</color>", CensorShittyWords.FilterUGC(item.m_crafterName, (UGCType)2, (string)null, item.m_crafterID));
			}
			if (item.m_shared.m_useDurability)
			{
				if (crafting)
				{
					float maxDurability = item.GetMaxDurability(quality);
					stringBuilder.AppendFormat("\n$item_durability: <color=orange>{0}</color>", maxDurability);
				}
				else
				{
					float maxDurability2 = item.GetMaxDurability(quality);
					float durability = item.m_durability;
					stringBuilder.AppendFormat("\n$item_durability: <color=orange>{0}%</color> <color=yellow>({1}/{2})</color>", (item.GetDurabilityPercentage() * 100f).ToString("0"), durability.ToString("0"), maxDurability2.ToString("0"));
				}
				if (item.m_shared.m_canBeReparied && !crafting)
				{
					Recipe recipe = ObjectDB.instance.GetRecipe(item);
					if ((Object)(object)recipe != (Object)null)
					{
						int minStationLevel = recipe.m_minStationLevel;
						stringBuilder.AppendFormat("\n$item_repairlevel: <color=orange>{0}</color>", minStationLevel.ToString());
					}
				}
			}
			Dictionary<string, string> customData = item.m_customData;
			if (!customData.TryGetValue("PP_Prefab", out var value) || (value ?? "") == "")
			{
				text += "<color=red>Empty</color>\n<color=yellow>Use on tamed creature to store within.</color>\n";
				stringBuilder.Append(text);
				localPlayer.AppendEquipmentModifierTooltips(item, stringBuilder);
				return stringBuilder.ToString();
			}
			text = text + "Stored Creature: <color=green>" + value + "</color>\n";
			if (customData.TryGetValue("PP_Name", out var value2) && (value2 ?? "") != "")
			{
				text = text + "Name: <color=orange>" + value2 + "</color>\n";
			}
			text = text + "Level: <color=orange>" + GeneralExtensions.GetValueSafe<string, string>(customData, "PP_Lvl") + "</color>\n";
			if (Plugin.hasCLLC)
			{
				string[] array = GeneralExtensions.GetValueSafe<string, string>(customData, "PP_CLLC").Split(new char[1] { ',' });
				if ((array[0] ?? "") != "" && array[0] != "None")
				{
					text = text + "Infusion: <color=orange>" + array[0] + "</color>\n";
				}
				if (array.Length > 1 && array[1] + "None" != "" && array[1] != "None")
				{
					text = text + "Effect: <color=orange>" + array[1] + "</color>\n";
				}
			}
			if (customData.TryGetValue("PP_Saddle", out var value3) && value3 == "true")
			{
				text += "- <color=orange>Equipped with Saddle</color>\n";
			}
			stringBuilder.Append(text);
			localPlayer.AppendEquipmentModifierTooltips(item, stringBuilder);
			return stringBuilder.ToString();
		}
	}
	internal class AllTame_API
	{
		[HarmonyPatch(typeof(DNA), "setTraits")]
		public class AT_DNA_Patches
		{
			private static void Prefix(DNA __instance, out Vector3 __state)
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				__state = ((Component)__instance).gameObject.transform.localScale;
			}

			private static void Postfix(DNA __instance, Vector3 __state)
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				GameObject gameObject = ((Component)__instance).gameObject;
				TimedScaleAndFreeze tsf = default(TimedScaleAndFreeze);
				if ((Object)(object)gameObject != (Object)null && gameObject.TryGetComponent<TimedScaleAndFreeze>(ref tsf))
				{
					float scale = gameObject.transform.localScale.x / __state.x;
					DBG.blogDebug("In setTraits Patch with scale=" + scale);
					CatchPal.checkScales(gameObject, isCLLC: false, tsf, scale);
				}
			}
		}

		public static string GetDNA(Character character)
		{
			DNA component = ((Component)character).GetComponent<DNA>();
			if ((Object)(object)component == (Object)null)
			{
				return "";
			}
			return component.DNA_hash.ToString();
		}

		public static void setDNAHash(GameObject go, ZNetView znv)
		{
			DNA component = go.GetComponent<DNA>();
			if (Object.op_Implicit((Object)(object)component))
			{
				DBG.blogDebug("DNA hash=" + component.DNA_hash);
				component.DNA_hash = znv.GetZDO().GetLong("AT_DNA", 0L);
				DBG.blogDebug("DNA hash2=" + component.DNA_hash);
				component.ParseMSG();
			}
		}

		public static void setDNA(GameObject go, long dna_hash)
		{
			DNA val = default(DNA);
			if (go.TryGetComponent<DNA>(ref val))
			{
				val.DNA_hash = dna_hash;
				val.ParseMSG();
				val.restoreColor();
				val.setAttributes();
				val.SetZDO();
				DBG.blogDebug("PP hash=" + dna_hash);
			}
			else
			{
				DBG.blogDebug("No DNA");
			}
		}
	}
	internal class CLLC
	{
		public static void SetInfusionCreature(Character character, string infusion)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (!Enum.TryParse<CreatureInfusion>(infusion, out CreatureInfusion result))
			{
				DBG.blogDebug("Failed to parse infusion from string " + infusion);
			}
			else
			{
				API.SetInfusionCreature(character, result);
			}
		}

		public static void SetExtraEffectCreature(Character character, string effect)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (!Enum.TryParse<CreatureExtraEffect>(effect, out CreatureExtraEffect result))
			{
				DBG.blogDebug("Failed to parse extra effect from string " + effect);
			}
			else
			{
				API.SetExtraEffectCreature(character, result);
			}
		}

		public static string CLLC_getInfusion(Character character)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			CreatureInfusion infusionCreature = API.GetInfusionCreature(character);
			return ((object)(CreatureInfusion)(ref infusionCreature)).ToString();
		}

		public static string CLLC_getEffect(Character character)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			CreatureExtraEffect extraEffectCreature = API.GetExtraEffectCreature(character);
			return ((object)(CreatureExtraEffect)(ref extraEffectCreature)).ToString();
		}
	}
	public static class DBG
	{
		public static void cprt(string s)
		{
			Console.instance.Print(s);
		}

		public static void InfoTL(string s)
		{
			((Character)Player.m_localPlayer).Message((MessageType)1, s, 0, (Sprite)null);
		}

		public static void InfoCT(string s)
		{
			((Character)Player.m_localPlayer).Message((MessageType)2, s, 0, (Sprite)null);
		}

		public static void blogInfo(object o)
		{
			Plugin.logger.LogInfo(o);
		}

		public static void blogWarning(object o)
		{
			Plugin.logger.LogWarning(o);
		}

		public static void blogDebug(object o)
		{
			if (Plugin.debugout.Value)
			{
				Plugin.logger.LogWarning(o);
			}
		}

		public static void tryblogDebug(object o, object o_backup)
		{
			try
			{
				if (Plugin.debugout.Value)
				{
					Plugin.logger.LogWarning(o);
				}
			}
			catch
			{
				Plugin.logger.LogWarning(o_backup);
			}
		}
	}
	[BepInPlugin("meldurson.valheim.PortablePals", "PortablePals", "0.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigEntry<int> nexusID;

		public static ConfigEntry<string> cfg;

		public static ConfigEntry<int> durability;

		public static ConfigEntry<bool> repairable;

		public static ConfigEntry<string> recipe;

		public static ConfigEntry<string> craftingStation;

		public static ConfigEntry<float> cooldown;

		public static ConfigEntry<bool> debugout;

		public static string assetPath = "Assets/PortablePals/";

		public static ManualLogSource logger;

		public static GameObject Root;

		public static PrefabManager prefabManager;

		public const string CLLCGUID = "org.bepinex.plugins.creaturelevelcontrol";

		public const string AllTameableGUID = "meldurson.valheim.AllTameable";

		public static bool hasCLLC = false;

		public static bool hasAT = false;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ZNetScene), "Shutdown")]
		private static void Postfix()
		{
			DBG.blogInfo("Reseting PortablePals");
		}

		private void Awake()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			logger = ((BaseUnityPlugin)this).Logger;
			recipe = ((BaseUnityPlugin)this).Config.Bind<string>("2: Crafting", "Crafting Recipe", "YmirRemains:2,Crystal:5,BlackCore:2,Obsidian:3", new ConfigDescription("What is the recipe for craft, separate amount with : and different items with ,", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			craftingStation = ((BaseUnityPlugin)this).Config.Bind<string>("2: Crafting", "Crafting Station", "piece_workbench:5", new ConfigDescription("What is the required Crafting Station and Level, separated by a : such as WorkBench:5 would be lvl 5 Workbench (vanilla stations are: piece_workbench, forge, piece_cauldron, piece_stonecutter, piece_artisanstation, blackforge, piece_magetable", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			durability = ((BaseUnityPlugin)this).Config.Bind<int>("2: Crafting", "Durability", 10, new ConfigDescription("Durability of PalStone, 0 is indestuctable", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			repairable = ((BaseUnityPlugin)this).Config.Bind<bool>("2: Crafting", "Repairable", true, new ConfigDescription("If durability is used, can stone be repaired?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			cooldown = ((BaseUnityPlugin)this).Config.Bind<float>("2: Crafting", "Cooldown", 60f, new ConfigDescription("Cooldown between uses in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			debugout = ((BaseUnityPlugin)this).Config.Bind<bool>("1: General", "Debug Output", false, "Determines if debug is output to bepinex log");
			Root = new GameObject("PortablePals Root");
			Object.DontDestroyOnLoad((Object)(object)Root);
			CatchPal.Staging = new GameObject("Staging Area");
			CatchPal.Staging.transform.SetParent(Root.transform);
			CatchPal.Staging.SetActive(false);
			if (Chainloader.PluginInfos.ContainsKey("org.bepinex.plugins.creaturelevelcontrol"))
			{
				DBG.blogDebug("Has CLLC");
				hasCLLC = true;
			}
			if (Chainloader.PluginInfos.ContainsKey("meldurson.valheim.AllTameable"))
			{
				DBG.blogDebug("Has AllTameable");
				hasAT = true;
			}
			PerformPatches();
			prefabManager = Root.AddComponent<PrefabManager>();
			DBG.blogInfo("PortablePals Loaded");
			PrefabManager.OnVanillaPrefabsAvailable += PrefabManager.ItemReg;
		}

		private static void LoadTamelists()
		{
		}

		public void PerformPatches()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("meldurson.valheim.PortablePals");
			DBG.blogInfo("Patching Select");
			val.PatchAll(typeof(Patches));
			val.PatchAll(typeof(CatchPal));
			if (hasCLLC)
			{
				val.PatchAll(typeof(CLLC_Patches));
				DBG.blogDebug("Patched CLLCPatches");
			}
			if (hasAT)
			{
				val.PatchAll(typeof(AllTame_API.AT_DNA_Patches));
				DBG.blogDebug("Patched ATPatches");
			}
			IEnumerable<MethodBase> patchedMethods = val.GetPatchedMethods();
			val.PatchAll(typeof(Patches.FixMaxRepairLevel));
			foreach (MethodBase item in patchedMethods)
			{
				DBG.blogDebug(item.ReflectedType?.ToString() + ":" + item.Name + " is patched");
			}
		}
	}
	public class TimedScaleAndFreeze : MonoBehaviour
	{
		public float roughness = 0.05f;

		public float startimeScale = 1f;

		public float startimeMove = 0.4f;

		private float lastTimeScale = 0f;

		private float lastTimeMove = 0f;

		public float duration = 1f;

		public int breakChild = 0;

		public float startScale = 0.01f;

		public float endScale = 1f;

		public float maxMovePercent = 0.1f;

		public Vector3 endLoc = Vector3.zero;

		private float timeMulti;

		public Vector3 ogScale;

		private float endTime;

		public bool ZNetDestroy = true;

		private bool childOfZnet = false;

		private bool firstUpdate = true;

		public float CLLC_Scale = 1f;

		public float DNA_Scale = 1f;

		public bool setFinalScale = true;

		private Vector3 previousScale;

		public Vector3 exteriorScale = Vector3.one;

		public Rigidbody rb;

		private RigidbodyConstraints constraints = (RigidbodyConstraints)0;

		public ZNetView m_nview;

		private void Start()
		{
			//IL_00b6: 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)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m_nview == (Object)null)
			{
				m_nview = ((Component)this).GetComponent<ZNetView>();
			}
			if ((Object)(object)m_nview == (Object)null)
			{
				m_nview = ((Component)this).GetComponentInParent<ZNetView>();
				childOfZnet = true;
			}
			lastTimeScale = Time.time + startimeScale;
			startimeScale = lastTimeScale;
			lastTimeMove = Time.time + startimeMove;
			startimeMove = lastTimeMove;
			DBG.blogDebug("Start Time Scale =" + startimeScale);
			timeMulti = (endScale - startScale) / duration;
			_ = ogScale;
			if (ogScale == Vector3.zero)
			{
				ogScale = ((Component)this).transform.localScale;
			}
			Vector3 val = ogScale;
			DBG.blogDebug("ogScale =" + ((object)(Vector3)(ref val)).ToString());
			((Component)this).transform.localScale = ogScale * startScale;
			previousScale = ((Component)this).transform.localScale;
			endTime = startimeScale + duration;
		}

		private void Update()
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			float time = Time.time;
			Vector3 val;
			if (time > endTime)
			{
				if (setFinalScale)
				{
					((Component)this).transform.localScale = Vector3.Scale(exteriorScale, ogScale);
					val = ((Component)this).transform.localScale;
					DBG.blogDebug("finalScale=" + ((object)(Vector3)(ref val)).ToString());
				}
				removeSelf();
				return;
			}
			if (time - lastTimeScale > roughness)
			{
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(((Component)this).transform.localScale.x / previousScale.x, ((Component)this).transform.localScale.y / previousScale.y, ((Component)this).transform.localScale.z / previousScale.z);
				if (((Vector3)(ref val2)).magnitude < 5f)
				{
					exteriorScale = Vector3.Scale(exteriorScale, val2);
				}
				else
				{
					val = val2;
					string? text = ((object)(Vector3)(ref val)).ToString();
					val = ((Component)this).transform.localScale;
					DBG.blogDebug("scaler Scale too high =" + text + ", scale=" + ((object)(Vector3)(ref val)).ToString());
				}
				if (((Component)this).transform.localScale.x / previousScale.x != 1f)
				{
					val = exteriorScale;
					string? text2 = ((object)(Vector3)(ref val)).ToString();
					val = ((Component)this).transform.localScale;
					DBG.blogDebug("exterior Scale =" + text2 + ", scale=" + ((object)(Vector3)(ref val)).ToString());
				}
				((Component)this).transform.localScale = Vector3.Scale(exteriorScale, ogScale) * (startScale + timeMulti * (time - startimeScale));
				previousScale = ((Component)this).transform.localScale;
				lastTimeScale = time;
				if (firstUpdate)
				{
					Character component = ((Component)this).gameObject.GetComponent<Character>();
					if ((Object)(object)component != (Object)null && !((Behaviour)component).enabled)
					{
						((Behaviour)component).enabled = true;
					}
					firstUpdate = false;
				}
			}
			if (time - lastTimeMove > roughness && endLoc != Vector3.zero)
			{
				if (endLoc != Vector3.zero)
				{
					((Component)this).transform.position = Vector3.MoveTowards(((Component)this).transform.position, endLoc, maxMovePercent * Vector3.Distance(((Component)this).transform.position, endLoc));
				}
				lastTimeMove = time;
			}
		}

		public void SetEndPos(Vector3 location)
		{
			//IL_0002: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			endLoc = location;
			Vector3 val = endLoc;
			DBG.blogDebug("End loc =" + ((object)(Vector3)(ref val)).ToString());
		}

		public TimedScaleAndFreeze SetRB(Rigidbody freeze_rb)
		{
			//IL_000f: 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)
			rb = freeze_rb;
			constraints = rb.constraints;
			rb.constraints = (RigidbodyConstraints)126;
			return this;
		}

		public void removeSelf()
		{
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				VisEquipment componentInChildren = ((Component)this).gameObject.GetComponentInChildren<VisEquipment>();
				if ((Object)(object)componentInChildren != (Object)null && !((Behaviour)componentInChildren).enabled)
				{
					((Behaviour)componentInChildren).enabled = true;
					((Component)componentInChildren.m_rightHand).gameObject.SetActive(true);
					((Component)componentInChildren.m_leftHand).gameObject.SetActive(true);
					Humanoid component = ((Component)this).gameObject.GetComponent<Humanoid>();
					if ((Object)(object)component != (Object)null)
					{
						component.EquipItem(component.RightItem, true);
						DBG.blogDebug("Equipped right Item:" + ((object)component.RightItem).ToString());
					}
				}
			}
			catch
			{
				DBG.blogWarning("Failed VisEquip");
			}
			try
			{
				if (breakChild >= 0 && breakChild < ((Component)this).transform.childCount)
				{
					DBG.blogDebug("Breaking Child " + ((Object)((Component)this).gameObject).name);
					Transform child = ((Component)this).transform.GetChild(breakChild);
					if (Object.op_Implicit((Object)(object)child))
					{
						child.parent = null;
						if ((Object)(object)rb != (Object)null)
						{
							rb.constraints = constraints;
						}
					}
				}
			}
			catch
			{
				DBG.blogWarning("Failed Break Child");
			}
			try
			{
				ZNetView component2 = ((Component)this).gameObject.GetComponent<ZNetView>();
				if ((Object)(object)component2 != (Object)null && component2.IsValid() && component2.GetZDO().GetBool(CatchPal.releaseZDOKey, false))
				{
					DBG.blogDebug("Removing Release ZDO");
					component2.GetZDO().Set(CatchPal.releaseZDOKey, false);
				}
			}
			catch
			{
				DBG.blogWarning("Failed reset releaseZDO");
			}
			DestroyNow();
		}

		public void DestroyNow()
		{
			if (!ZNetDestroy)
			{
				DBG.blogDebug("Destroying tsf component in " + ((Object)((Component)this).gameObject).name);
				Object.Destroy((Object)(object)this);
			}
			else if (Object.op_Implicit((Object)(object)m_nview))
			{
				if (m_nview.IsValid())
				{
					if (!m_nview.HasOwner())
					{
						m_nview.ClaimOwnership();
					}
					if (m_nview.IsOwner())
					{
						DBG.blogDebug("Destroying Znet in " + ((Object)((Component)this).gameObject).name);
						ZNetScene.instance.Destroy(((Component)this).gameObject);
					}
				}
			}
			else
			{
				DBG.blogDebug("Not Owner, waiting for owner to destroy " + ((Object)((Component)this).gameObject).name);
			}
		}
	}
	public class TimedColor : MonoBehaviour
	{
		public float roughness = 0.01f;

		public float startime = 0f;

		private float lastTime = 0f;

		public float duration = 0.7f;

		public int breakChild = 0;

		public Color endColorMulti = new Color(25f, 25f, 25f);

		private Color colMulti;

		private float endTime;

		private List<Material> materials = new List<Material>();

		private int actualCyles = 0;

		private bool hasEnded = false;

		public Rigidbody rb;

		private void Start()
		{
			//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)
			lastTime = Time.time + startime;
			startime = lastTime;
			DBG.blogDebug("Start Color time =" + startime);
			int num = (int)(duration / Math.Max(roughness, 1f / 59f));
			DBG.blogDebug("Expected num cycles=" + num);
			colMulti = new Color(Mathf.Pow(endColorMulti.r, 1f / (float)num), Mathf.Pow(endColorMulti.g, 1f / (float)num), Mathf.Pow(endColorMulti.b, 1f / (float)num));
			endTime = startime + duration;
			Renderer[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<Renderer>();
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				DBG.blogDebug("material added: " + ((Object)val.material).name);
				materials.Add(val.material);
			}
		}

		private void Update()
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			if (hasEnded)
			{
				return;
			}
			float time = Time.time;
			if (time > endTime)
			{
				DBG.blogDebug("ActualCycles =" + actualCyles);
				hasEnded = true;
			}
			else
			{
				if (!(time - lastTime > roughness))
				{
					return;
				}
				actualCyles++;
				foreach (Material material in materials)
				{
					Color color = material.color;
					material.color = new Color(color.r * colMulti.r, color.g * colMulti.g, color.b * colMulti.b);
				}
				lastTime = time;
			}
		}
	}
	public class PrefabManager : MonoBehaviour
	{
		public GameObject Root;

		private static AssetBundle PP_Assets;

		private void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			Root = new GameObject("PrefabList");
			Root.transform.SetParent(Plugin.Root.transform);
			Root.SetActive(false);
			PP_Assets = AssetUtils.LoadAssetBundleFromResources("portablepals", Assembly.GetExecutingAssembly());
		}

		public static AssetBundle getAssetBundle()
		{
			return PP_Assets;
		}

		public static void ItemReg()
		{
			DBG.blogDebug("ItemReg");
			addPortablePalStone();
			PrefabManager.OnVanillaPrefabsAvailable -= ItemReg;
		}

		public static void ItemRegFromServer()
		{
			addPortablePalStone();
		}

		private static ItemConfig makePalStoneRecipe()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			ItemConfig val = new ItemConfig();
			string[] array = Plugin.recipe.Value.Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(new char[1] { ':' });
				if (array2.Length == 2 && int.TryParse(array2[1], out var result))
				{
					val.AddRequirement(new RequirementConfig(array2[0], result, 0, false));
				}
				else
				{
					val.AddRequirement(new RequirementConfig(array2[0], 1, 0, false));
				}
			}
			string[] array3 = Plugin.craftingStation.Value.Split(new char[1] { ':' });
			if (array3.Length == 2 && int.TryParse(array3[1], out var result2))
			{
				val.CraftingStation = array3[0];
				val.MinStationLevel = result2;
				val.RepairStation = array3[0];
			}
			else
			{
				val.CraftingStation = array3[0];
				val.RepairStation = array3[0];
				val.MinStationLevel = 5;
			}
			return val;
		}

		public static void addPortablePalStone()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			CustomItem val = ItemManager.Instance.GetItem("PalStone");
			if (val == null)
			{
				DBG.blogDebug("Adding recipe for Pal Stone");
				GameObject val2 = PP_Assets.LoadAsset<GameObject>(Plugin.assetPath + "Palstone.prefab");
				DBG.blogDebug("Loaded from assets");
				val = new CustomItem(val2, true, makePalStoneRecipe());
				ItemManager.Instance.AddItem(val);
			}
			ItemDrop itemDrop = val.ItemDrop;
			ItemData itemData = itemDrop.m_itemData;
			if (Plugin.durability.Value > 0)
			{
				itemData.m_shared.m_maxDurability = Plugin.durability.Value;
				itemData.m_shared.m_useDurability = true;
			}
			else
			{
				itemData.m_shared.m_useDurability = false;
			}
			if (Plugin.repairable.Value)
			{
				itemData.m_shared.m_canBeReparied = true;
			}
			else
			{
				itemData.m_shared.m_canBeReparied = false;
			}
			itemData.m_shared.m_attachOverride = (ItemType)19;
		}
	}
	public static class Utils2
	{
		private const BindingFlags bindingFlags = BindingFlags.Public;

		public static T GetCopyOf<T>(this Component comp, T other) where T : Component
		{
			Type type = ((object)comp).GetType();
			if (type != ((object)other).GetType())
			{
				return default(T);
			}
			List<Type> list = new List<Type>();
			Type baseType = type.BaseType;
			while (baseType != null && !(baseType == typeof(MonoBehaviour)))
			{
				list.Add(baseType);
				baseType = baseType.BaseType;
			}
			IEnumerable<PropertyInfo> enumerable = type.GetProperties(BindingFlags.Public);
			foreach (Type item in list)
			{
				enumerable = enumerable.Concat(item.GetProperties(BindingFlags.Public));
			}
			enumerable = from property in enumerable
				where !(type == typeof(Rigidbody)) || !(property.Name == "inertiaTensor")
				where !property.CustomAttributes.Any((CustomAttributeData attribute) => attribute.AttributeType == typeof(ObsoleteAttribute))
				select property;
			foreach (PropertyInfo pinfo in enumerable)
			{
				if (pinfo.CanWrite && !enumerable.Any((PropertyInfo e) => e.Name == $"shared{char.ToUpper(pinfo.Name[0])}{pinfo.Name.Substring(1)}"))
				{
					try
					{
						pinfo.SetValue(comp, pinfo.GetValue(other, null), null);
					}
					catch
					{
					}
				}
			}
			IEnumerable<FieldInfo> enumerable2 = type.GetFields(BindingFlags.Public);
			foreach (FieldInfo finfo in enumerable2)
			{
				foreach (Type item2 in list)
				{
					if (!enumerable2.Any((FieldInfo e) => e.Name == $"shared{char.ToUpper(finfo.Name[0])}{finfo.Name.Substring(1)}"))
					{
						enumerable2 = enumerable2.Concat(item2.GetFields(BindingFlags.Public));
					}
				}
			}
			foreach (FieldInfo item3 in enumerable2)
			{
				item3.SetValue(comp, item3.GetValue(other));
			}
			enumerable2 = enumerable2.Where((FieldInfo field) => field.CustomAttributes.Any((CustomAttributeData attribute) => attribute.AttributeType == typeof(ObsoleteAttribute)));
			foreach (FieldInfo item4 in enumerable2)
			{
				item4.SetValue(comp, item4.GetValue(other));
			}
			return (T)(object)((comp is T) ? comp : null);
		}

		public static T AddComponent<T>(this GameObject go, T toAdd) where T : Component
		{
			return go.AddComponent(((object)toAdd).GetType()).GetCopyOf(toAdd);
		}

		public static T CopyBroComponet<T, TU>(this Component comp, TU other) where T : Component
		{
			Type baseType = ((object)comp).GetType().BaseType;
			IEnumerable<FieldInfo> fields = baseType.GetFields(BindingFlags.Public);
			foreach (FieldInfo item in fields)
			{
				item.SetValue(comp, item.GetValue(other));
				DBG.blogWarning(item?.ToString() + " , " + item.GetType()?.ToString() + " , " + item.Name);
			}
			return (T)(object)((comp is T) ? comp : null);
		}

		public static void addOrUpdateCustomData(Dictionary<string, string> dic, string key, string newValue)
		{
			if (dic.ContainsKey(key))
			{
				dic[key] = newValue;
				return;
			}
			DBG.blogDebug("Added " + key + " to dictionary");
			dic.Add(key, newValue);
		}
	}
}