Decompiled source of EveryFriendIsX v1.0.2

BepInEx/plugins/pauli-EveryFriendIsX/EveryFriendIsX.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Atomicrops.Game.Data;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SharedLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("EveryFriendIsX")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EveryFriendIsX")]
[assembly: AssemblyTitle("EveryFriendIsX")]
[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 Template
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "EveryFriendIsX";

		public const string PLUGIN_NAME = "EveryFriendIsX";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace EveryFriendIsX
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "pauli.plugin.EveryFriendIsX";

		public const string PLUGIN_NAME = "EveryFriendIsX";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("pauli.plugin.EveryFriendIsX", "EveryFriendIsX", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Log;

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin pauli.plugin.EveryFriendIsX is loaded!");
			Harmony val = new Harmony("pauli.plugin.EveryFriendIsX");
			val.PatchAll();
		}
	}
	[HarmonyPatch(typeof(FriendsCollection))]
	public static class AddMethodPatch
	{
		[HarmonyPatch("_add", new Type[]
		{
			typeof(FriendModel),
			typeof(bool),
			typeof(Vector2),
			typeof(AddParams_)
		})]
		private static void Prefix(ref FriendModel model)
		{
			string text = ReadChoiceFromFile();
			if (string.IsNullOrEmpty(text))
			{
				Plugin.Log.LogError((object)"Friend choice is empty or not found!");
				return;
			}
			string text2 = text;
			string text3 = text2;
			if (text3 == null)
			{
				return;
			}
			FriendDef val;
			switch (text3.Length)
			{
			default:
				return;
			case 8:
				switch (text3[0])
				{
				default:
					return;
				case 'A':
					if (text3 == "AlienPet")
					{
						model.Def = SingletonScriptableObject<FriendDefLoader>.I.AlienPet;
					}
					return;
				case 'F':
					break;
				}
				if (!(text3 == "Furryosa"))
				{
					return;
				}
				break;
			case 3:
			{
				char c = text3[0];
				if ((uint)c <= 98u)
				{
					if (c == 'R')
					{
						if (!(text3 == "Rue"))
						{
							return;
						}
						break;
					}
					if (c != 'b' || !(text3 == "bee"))
					{
						return;
					}
				}
				else
				{
					switch (c)
					{
					default:
						return;
					case 'p':
						if (!(text3 == "pig"))
						{
							return;
						}
						break;
					case 'c':
						if (!(text3 == "cow"))
						{
							return;
						}
						break;
					}
				}
				goto IL_0231;
			}
			case 11:
				switch (text3[0])
				{
				default:
					return;
				case 'c':
					if (!(text3 == "chickenweed"))
					{
						return;
					}
					break;
				case 'd':
					if (!(text3 == "dronerifler"))
					{
						return;
					}
					break;
				}
				goto IL_0231;
			case 6:
				switch (text3[0])
				{
				default:
					return;
				case 'B':
					if (!(text3 == "Borage"))
					{
						return;
					}
					break;
				case 'N':
					if (!(text3 == "Norman"))
					{
						return;
					}
					break;
				}
				break;
			case 10:
				if (!(text3 == "Waterchris"))
				{
					return;
				}
				break;
			case 12:
				if (!(text3 == "RandomSpouse"))
				{
					return;
				}
				break;
			case 4:
			case 5:
			case 7:
			case 9:
				return;
				IL_0231:
				val = FriendDefLoader.Get(text);
				if ((Object)(object)val != (Object)null)
				{
					model.Def = val;
				}
				else
				{
					Plugin.Log.LogError((object)("Could not fetch the '" + text + "' FriendDef!"));
				}
				return;
			}
			EligiblesCollection eligibles = SingletonScriptableObject<GameData>.I.Eligibles;
			if (eligibles != null)
			{
				FriendDef val2 = null;
				if (text == "RandomSpouse")
				{
					Dictionary<FriendDef, FriendModel> dictionary = eligibles._getall();
					List<FriendDef> list = new List<FriendDef>(dictionary.Keys);
					val2 = list[Random.Range(0, list.Count)];
				}
				else
				{
					foreach (FriendDef key in eligibles._getall().Keys)
					{
						if (key.Name == text)
						{
							val2 = key;
							break;
						}
					}
				}
				if ((Object)(object)val2 != (Object)null)
				{
					model.Def = val2;
				}
				else
				{
					Plugin.Log.LogError((object)("Could not find a matching FriendDef for the choice: " + text + "!"));
				}
			}
			else
			{
				Plugin.Log.LogError((object)"Eligibles collection is null!");
			}
		}

		private static string ReadChoiceFromFile()
		{
			string text = Path.Combine(Path.GetDirectoryName(typeof(AddMethodPatch).Assembly.Location), "friendchoice.txt");
			if (File.Exists(text))
			{
				string[] array = File.ReadAllLines(text);
				string[] array2 = array;
				foreach (string text2 in array2)
				{
					if (!text2.StartsWith("#") && !string.IsNullOrWhiteSpace(text2))
					{
						return text2.Trim();
					}
				}
			}
			else
			{
				Plugin.Log.LogError((object)("friendchoice.txt not found in " + text));
			}
			return null;
		}
	}
}