Decompiled source of Size2Fix v1.0.0

Size2Fix.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
using Steamworks.Data;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Size2Fix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Fixes bug that made the size 2 fish uncatchable.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Size2Fix")]
[assembly: AssemblyTitle("Size2Fix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Size2Fix
{
	[BepInPlugin("com.earthlingOnFire.Size2Fix", "Size 2 Fix", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch]
		public static class Patches
		{
			private static Vector3 fishSize2 = new Vector3(1.2f, 1.2f, 1.2f);

			private static Vector3 sharkSize2 = new Vector3(0.8f, 0.8f, 0.8f);

			private static Vector3 dopeSize2 = new Vector3(0.8f, 0.8f, 0.8f);

			private static Vector3 fishWorldSize2 = new Vector3(2f, 2f, 2f);

			[HarmonyPostfix]
			[HarmonyPatch(typeof(LeaderboardController), "GetFishScores")]
			private static async void LeaderboardController_GetFishScores_Postfix(Task<LeaderboardEntry[]> __result, LeaderboardType type)
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				LeaderboardEntry[] leaderboard = await __result;
				if (leaderboard == null || !hasCaughtSize2.Value)
				{
					return;
				}
				Friend user = new Friend(SteamClient.SteamId);
				int userIndex = -1;
				int targetIndex = -1;
				for (int i = 0; i < leaderboard.Length; i++)
				{
					LeaderboardEntry entry = leaderboard[i];
					if (entry.Score == 1 && targetIndex == -1)
					{
						targetIndex = i;
					}
					if (((Friend)(ref entry.User)).IsMe)
					{
						userIndex = i;
						if (entry.Score == 2)
						{
							return;
						}
					}
					entry = default(LeaderboardEntry);
				}
				if (targetIndex != -1)
				{
					if (userIndex != -1)
					{
						Friend otherUser = leaderboard[targetIndex].User;
						leaderboard[userIndex].User = otherUser;
					}
					else
					{
						targetIndex = 2;
					}
					leaderboard[targetIndex].User = user;
					leaderboard[targetIndex].Score = 2;
					leaderboard[targetIndex].GlobalRank = 3;
				}
			}

			private static bool RollTheDice()
			{
				int num = Random.Range(0, 100);
				if (num < probability)
				{
					return true;
				}
				return false;
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(FishBait), "CatchFish")]
			private static void FishBait_CatchFish_Prefix(FishBait __instance, out bool __state)
			{
				BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
				FieldInfo field = typeof(FishBait).GetField("returnToRod", bindingAttr);
				if (!(bool)field.GetValue(__instance))
				{
					__state = true;
				}
				else
				{
					__state = false;
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(FishBait), "CatchFish")]
			private static void FishBait_CatchFish_Postfix(FishBait __instance, bool __state)
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: 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_0072: 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_0097: Unknown result type (might be due to invalid IL or missing references)
				if (__state && RollTheDice())
				{
					BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
					FieldInfo field = typeof(FishBait).GetField("spawnedFish", bindingAttr);
					GameObject gameObject = ((Component)(Transform)field.GetValue(__instance)).gameObject;
					((Object)gameObject).name = ((Object)gameObject).name + " (size 2)";
					Vector3 localScale = gameObject.transform.localScale;
					Vector3 localScale2 = default(Vector3);
					((Vector3)(ref localScale2))..ctor(localScale.x * 2f, localScale.y * 2f, localScale.z * 2f);
					gameObject.transform.localScale = localScale2;
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(FishBait), "ReturnAnim")]
			private static bool FishBait_ReturnAnim_Prefix(FishBait __instance)
			{
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Expected O, but got Unknown
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Expected O, but got Unknown
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Expected O, but got Unknown
				//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: Expected O, but got Unknown
				//IL_0251: Unknown result type (might be due to invalid IL or missing references)
				//IL_0256: Unknown result type (might be due to invalid IL or missing references)
				//IL_0284: 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_0276: Unknown result type (might be due to invalid IL or missing references)
				//IL_027b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0297: Unknown result type (might be due to invalid IL or missing references)
				if (__instance.flyProgress >= 1f)
				{
					BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
					FieldInfo field = typeof(FishBait).GetField("spawnedFish", bindingAttr);
					GameObject gameObject = ((Component)(Transform)field.GetValue(__instance)).gameObject;
					FieldInfo field2 = typeof(FishBait).GetField("sourceWeapon", bindingAttr);
					FishingRodWeapon val = (FishingRodWeapon)field2.GetValue(__instance);
					FieldInfo field3 = typeof(FishingRodWeapon).GetField("animator", bindingAttr);
					Animator val2 = (Animator)field3.GetValue(val);
					FieldInfo field4 = typeof(FishingRodWeapon).GetField("hookedFishe", bindingAttr);
					FishDescriptor val3 = (FishDescriptor)field4.GetValue(val);
					MethodInfo method = typeof(FishingRodWeapon).GetMethod("ResetFishing", bindingAttr);
					FieldInfo field5 = typeof(FishingRodWeapon).GetField("fishPickupTemplate", bindingAttr);
					ItemIdentifier val4 = (ItemIdentifier)field5.GetValue(val);
					__instance.flyProgress = 1f;
					val2.SetTrigger(Animator.StringToHash("Idle"));
					MonoSingleton<FishingHUD>.Instance.ShowFishCaught(true, val3.fish);
					GameObject val5 = FishingRodWeapon.CreateFishPickup(val4, val3.fish, true, true);
					method.Invoke(val, null);
					val.pullSound.Stop();
					Object.Destroy((Object)(object)gameObject.gameObject);
					try
					{
						MonoSingleton<LeaderboardController>.Instance.SubmitFishSize(SteamController.FishSizeMulti);
					}
					catch
					{
					}
					if (((Object)gameObject).name.Contains("size 2"))
					{
						GameObject val6 = GameObject.Find("FishingCanvas/Fish Caught/Fish Size Text");
						Text component = val6.GetComponent<Text>();
						component.text = "SIZE: 2";
						hasCaughtSize2.Value = true;
						GameObject val7 = null;
						for (int i = 0; i < val5.transform.childCount; i++)
						{
							GameObject gameObject2 = ((Component)val5.transform.GetChild(i)).gameObject;
							if (((Object)gameObject2).name != "Dummy Object")
							{
								val7 = gameObject2;
								break;
							}
						}
						((Object)val7).name = ((Object)val7).name + " (size 2)";
						ItemIdentifier componentInParent = val7.GetComponentInParent<ItemIdentifier>();
						if (((Object)val7).name.Contains("Dope"))
						{
							componentInParent.putDownScale = dopeSize2;
						}
						else if (((Object)val7).name.Contains("Shark"))
						{
							componentInParent.putDownScale = sharkSize2;
						}
						else
						{
							componentInParent.putDownScale = fishSize2;
						}
						val5.transform.localScale = componentInParent.putDownScale;
						GameObject val8 = GameObject.Find("Fish Scores");
						FishLeaderboard obj2 = default(FishLeaderboard);
						if ((Object)(object)val8 != (Object)null && val8.TryGetComponent<FishLeaderboard>(ref obj2))
						{
							MethodInfo method2 = typeof(FishLeaderboard).GetMethod("Fetch", bindingAttr);
							method2.Invoke(obj2, null);
						}
						return false;
					}
					GameObject val9 = GameObject.Find("FishingCanvas/Fish Caught/Fish Size Text");
					Text component2 = val9.GetComponent<Text>();
					component2.text = "SIZE: 1";
				}
				return true;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(Punch), "ForceHold")]
			private static void Punch_ForceHold_Postfix(Punch __instance)
			{
				ItemIdentifier heldItem = __instance.heldItem;
				if (((Component)heldItem).transform.childCount <= 0)
				{
					return;
				}
				Transform child = ((Component)heldItem).transform.GetChild(0);
				if (((Object)child).name.Contains("Cooked Fish"))
				{
					GameObject val = GameObject.Find("FishingCanvas/Fish Caught/Fish Size Text");
					Text component = val.GetComponent<Text>();
					if (((Object)child).name.Contains("size 2"))
					{
						component.text = "SIZE: 2";
					}
					else
					{
						component.text = "SIZE: 1";
					}
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(Punch), "ResetHeldItemPosition")]
			private static void Punch_ResetHeldItemPosition_Postfix(Punch __instance)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				ItemIdentifier heldItem = __instance.heldItem;
				if (((Component)heldItem).transform.childCount > 0 && ((Object)((Component)heldItem).transform.GetChild(0)).name.Contains("size 2"))
				{
					((Component)heldItem).transform.localScale = heldItem.putDownScale;
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(Punch), "ForceThrow")]
			private static void Punch_ForceThrow_Prefix(out ItemIdentifier __state, Punch __instance)
			{
				ItemIdentifier heldItem = __instance.heldItem;
				__state = null;
				if (Object.op_Implicit((Object)(object)heldItem) && ((Component)heldItem).transform.childCount > 0 && ((Object)((Component)heldItem).transform.GetChild(0)).name.Contains("size 2"))
				{
					__state = heldItem;
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(Punch), "ForceThrow")]
			private static void Punch_ForceThrow_Postfix(ItemIdentifier __state)
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)__state))
				{
					((Component)__state).transform.localScale = fishWorldSize2;
				}
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
			[HarmonyPatch(/*Could not decode attribute arguments.*/)]
			private static Transform MonoBehaviourTransform(Component instance)
			{
				return instance.transform;
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(FishCooker), "OnTriggerEnter")]
			private static bool FishCooker_OnTriggerEnter_Prefix(Collider other, bool ___unusable, TimeSince ___timeSinceLastError, ItemIdentifier ___fishPickupTemplate, FishObject ___cookedFish, FishObject ___failedFish, GameObject ___cookedSound, GameObject ___cookedParticles, FishCooker __instance)
			{
				//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)
				//IL_0064: 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_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: 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_00c7: 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_0190: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c2: 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_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_01df: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_027e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0283: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_024a: Unknown result type (might be due to invalid IL or missing references)
				Vector3 putDownScale = ___fishPickupTemplate.putDownScale;
				bool flag = false;
				for (int i = 0; i < ((Component)other).transform.childCount; i++)
				{
					GameObject gameObject = ((Component)((Component)other).transform.GetChild(i)).gameObject;
					if (((Object)gameObject).name.Contains("size 2"))
					{
						putDownScale = fishSize2;
						flag = true;
						break;
					}
				}
				bool flag2 = ___unusable;
				TimeSince val = ___timeSinceLastError;
				ItemIdentifier val2 = Object.Instantiate<ItemIdentifier>(___fishPickupTemplate);
				val2.putDownScale = putDownScale;
				FishObjectReference val3 = default(FishObjectReference);
				if (!((Component)other).TryGetComponent<FishObjectReference>(ref val3))
				{
					return false;
				}
				if (flag2)
				{
					if (TimeSince.op_Implicit(val) > 2f)
					{
						val = TimeSince.op_Implicit(0f);
						MonoSingleton<HudMessageReceiver>.Instance.SendHudMessage("Too small for this fish.\n:^(", "", "", 0, false);
					}
				}
				else if (!((Object)(object)val3.fishObject == (Object)(object)___cookedFish) && !((Object)(object)val3.fishObject == (Object)(object)___failedFish))
				{
					_ = MonoSingleton<FishManager>.Instance.recognizedFishes[___cookedFish];
					GameObject val4 = FishingRodWeapon.CreateFishPickup(val2, val3.fishObject.canBeCooked ? ___cookedFish : ___failedFish, false, false);
					if (!val3.fishObject.canBeCooked)
					{
						MonoSingleton<HudMessageReceiver>.Instance.SendHudMessage("Cooking failed.", "", "", 0, false);
					}
					val4.transform.SetPositionAndRotation(MonoBehaviourTransform((Component)(object)__instance).position, Quaternion.identity);
					Rigidbody component = val4.GetComponent<Rigidbody>();
					Vector3 val5 = ((Component)MonoSingleton<NewMovement>.Instance).transform.position - MonoBehaviourTransform((Component)(object)__instance).position;
					component.velocity = ((Vector3)(ref val5)).normalized * 18f + Vector3.up * 10f;
					if (flag)
					{
						for (int j = 0; j < val4.transform.childCount; j++)
						{
							GameObject gameObject2 = ((Component)val4.transform.GetChild(j)).gameObject;
							if (((Object)gameObject2).name != "Dummy Object")
							{
								((Object)gameObject2).name = ((Object)gameObject2).name + " (size 2)";
								val4.transform.localScale = fishWorldSize2;
								break;
							}
						}
					}
					Object.Instantiate<GameObject>(___cookedSound, MonoBehaviourTransform((Component)(object)__instance).position, Quaternion.identity);
					if (Object.op_Implicit((Object)(object)___cookedParticles))
					{
						Object.Instantiate<GameObject>(___cookedParticles, MonoBehaviourTransform((Component)(object)__instance).position, Quaternion.identity);
					}
					Object.Destroy((Object)(object)((Component)val3).gameObject);
				}
				return false;
			}
		}

		public const string PLUGIN_GUID = "com.earthlingOnFire.Size2Fix";

		public const string PLUGIN_NAME = "Size 2 Fix";

		public const string PLUGIN_VERSION = "1.0.0";

		internal static Plugin plugin;

		internal static ConfigFile config;

		internal static ConfigEntry<bool> hasCaughtSize2;

		internal static int probability;

		private void Awake()
		{
			plugin = this;
			config = ((BaseUnityPlugin)this).Config;
			SetUpConfig();
		}

		private void SetUpConfig()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			probability = config.Bind<int>("General", "Probability", 10, new ConfigDescription("Probability of a fish's size being 2.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())).Value;
			hasCaughtSize2 = config.Bind<bool>("General", "Has Caught Size 2", false, new ConfigDescription("Whether or not a size 2 fish has been caught yet. Will be set to \"true\" when a fish of size 2 is caught.", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { true, false }), Array.Empty<object>()));
		}

		private void Start()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("com.earthlingOnFire.Size2Fix").PatchAll();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Size2Fix";

		public const string PLUGIN_NAME = "Size2Fix";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}