Decompiled source of AllyNames v1.1.1

AllyNames.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using R2API.Utils;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AllyNames")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AllyNames")]
[assembly: AssemblyTitle("AllyNames")]
[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 AllyNames
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("SwagWizards.AllyNames", "AllyNames", "1.1.1")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class AllyNames : BaseUnityPlugin
	{
		public const string PluginGUID = "SwagWizards.AllyNames";

		public const string PluginAuthor = "SwagWizards";

		public const string PluginName = "AllyNames";

		public const string PluginVersion = "1.1.1";

		public const bool LogDebug = false;

		public static AllyNames instance;

		public static Dictionary<uint, string> savedTokens = new Dictionary<uint, string>();

		public static Dictionary<NetworkInstanceId, int> empathyCoresNameIndexes = new Dictionary<NetworkInstanceId, int>();

		private List<string> addedTokens;

		private static ConfigFile namesConfigFile { get; set; }

		public void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			InitConfig();
			NamesList.BuildNamesByBodyName();
			AddTokens();
			CharacterBody.Start += new hook_Start(CharacterBody_Start);
			CharacterMaster.OnBodyDeath += new hook_OnBodyDeath(CharacterMaster_OnBodyDeath);
		}

		public void OnDestroy()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			CharacterBody.Start -= new hook_Start(CharacterBody_Start);
			CharacterMaster.OnBodyDeath -= new hook_OnBodyDeath(CharacterMaster_OnBodyDeath);
		}

		private void CharacterBody_Start(orig_Start orig, CharacterBody self)
		{
			orig.Invoke(self);
			OnCharacterBodySpawned(self);
		}

		private void CharacterMaster_OnBodyDeath(orig_OnBodyDeath orig, CharacterMaster self, CharacterBody body)
		{
			//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_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)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			BodyIndex bodyIndex = body.bodyIndex;
			BodyIndex val = BodyCatalog.FindBodyIndex("RoboBallRedBuddyBody");
			BodyIndex val2 = BodyCatalog.FindBodyIndex("RoboBallGreenBuddyBody");
			if (bodyIndex == val || bodyIndex == val2)
			{
				OnEmpathyCoreDeath(val, val2, self);
			}
			orig.Invoke(self, body);
		}

		private void OnCharacterBodySpawned(CharacterBody characterBody)
		{
			CharacterMaster master = characterBody.master;
			string randomNameForCharacterMaster = NamesList.GetRandomNameForCharacterMaster(master, characterBody);
			if (!(randomNameForCharacterMaster == ""))
			{
				characterBody.baseNameToken = randomNameForCharacterMaster;
			}
		}

		private void AddTokens()
		{
			addedTokens = new List<string>();
			foreach (NamesByBodyIndex namesByBodyIndex in NamesList.namesByBodyIndexes)
			{
				foreach (string key in namesByBodyIndex.names.Keys)
				{
					if (!addedTokens.Contains(key))
					{
						string text = namesByBodyIndex.names[key];
						LanguageAPI.Add(key, text);
						addedTokens.Add(key);
						bool flag = false;
					}
				}
			}
		}

		private void OnEmpathyCoreDeath(BodyIndex redBodyIndex, BodyIndex greenBodyIndex, CharacterMaster characterMaster)
		{
			//IL_002c: 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)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			MinionOwnership minionOwnership = characterMaster.minionOwnership;
			if ((Object)(object)minionOwnership == (Object)null)
			{
				return;
			}
			MinionGroup group = characterMaster.minionOwnership.group;
			NetworkInstanceId ownerMasterId = characterMaster.minionOwnership.ownerMasterId;
			if (group == null)
			{
				return;
			}
			bool flag = false;
			MinionOwnership[] members = group._members;
			foreach (MinionOwnership val in members)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				CharacterMaster component = ((Component)val).GetComponent<CharacterMaster>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.networkIdentity == (Object)(object)characterMaster.networkIdentity))
				{
					CharacterBody body = component.GetBody();
					if (!((Object)(object)body == (Object)null) && (body.bodyIndex == redBodyIndex || body.bodyIndex == greenBodyIndex))
					{
						flag = true;
						break;
					}
				}
			}
			if (!flag)
			{
				empathyCoresNameIndexes.Remove(ownerMasterId);
			}
		}

		private void InitConfig()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			namesConfigFile = new ConfigFile(Paths.ConfigPath + "\\AllyNames.cfg", true);
			NamesList.InitConfig();
		}
	}
	internal static class Log
	{
		internal static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void LogDebug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void LogError(object data)
		{
			_logSource.LogError(data);
		}

		internal static void LogFatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void LogInfo(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void LogMessage(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void LogWarning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	public struct NamesByBodyIndex
	{
		public Dictionary<string, string> names;

		public string bodyIndex { get; }

		public string[] additionalCategories { get; }

		public NamesByBodyIndex(string bodyIndex, string[] additionalCategories, Dictionary<string, string> names)
		{
			this.bodyIndex = bodyIndex;
			this.additionalCategories = additionalCategories;
			this.names = names;
		}
	}
	public struct ConfigBodyIndex
	{
		public ConfigEntry<string> configEntry { get; set; }

		public string bodyIndex { get; }

		public string realName { get; }

		public string categories { get; }

		public string names { get; }

		public ConfigBodyIndex(string bodyIndex, string realName, string categories, string names)
		{
			this.bodyIndex = bodyIndex;
			this.realName = realName;
			this.categories = categories;
			this.names = names;
			configEntry = ((BaseUnityPlugin)AllyNames.instance).Config.Bind<string>("Categories and names by Body Index", bodyIndex, "[" + categories + "][" + names + "]", realName + ". Format: \"[Category1,Category2,...][Name1,Name2,Name3,...]\"");
		}
	}
	public struct ConfigCategory
	{
		public ConfigEntry<string> configEntry { get; set; }

		public string category { get; }

		public string names { get; }

		public ConfigCategory(string category, string names)
		{
			this.category = category;
			this.names = names;
			configEntry = ((BaseUnityPlugin)AllyNames.instance).Config.Bind<string>("Custom Categories", category, names, "Format: \"Name1,Name2,Name3,...\"");
		}
	}
	public class NamesList
	{
		public static Xoroshiro128Plus rng = new Xoroshiro128Plus(0uL);

		public static List<NamesByBodyIndex> namesByBodyIndexes = new List<NamesByBodyIndex>();

		public static ConfigCategory[] configCategories;

		public static ConfigBodyIndex[] configBodyIndexes;

		public static void BuildNamesByBodyName()
		{
			Dictionary<string, string[]> dictionary = new Dictionary<string, string[]>();
			ConfigCategory[] array = configCategories;
			for (int i = 0; i < array.Length; i++)
			{
				ConfigCategory configCategory = array[i];
				string[] value = configCategory.configEntry.Value.Split(new string[1] { "," }, StringSplitOptions.RemoveEmptyEntries);
				dictionary.Add(configCategory.category, value);
			}
			ConfigBodyIndex[] array2 = configBodyIndexes;
			for (int j = 0; j < array2.Length; j++)
			{
				ConfigBodyIndex configBodyIndex = array2[j];
				string text = "|_ALLY_NAMES_SEPARATOR_|";
				string value2 = configBodyIndex.configEntry.Value;
				value2 = value2.Replace("][", text);
				value2 = value2.Replace("]", "").Replace("[", "");
				string[] array3 = value2.Split(new string[1] { text }, StringSplitOptions.None);
				string text2 = "";
				string[] array4 = new string[0];
				if (array3.Length >= 1)
				{
					text2 = array3[0];
					array4 = text2.Split(new string[1] { "," }, StringSplitOptions.RemoveEmptyEntries);
				}
				string text3 = "";
				string[] array5 = new string[0];
				if (array3.Length >= 2)
				{
					text3 = array3[1];
					array5 = text3.Split(new string[1] { "," }, StringSplitOptions.RemoveEmptyEntries);
				}
				string bodyIndex = configBodyIndex.bodyIndex + "Body";
				Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
				string[] array6 = array5;
				foreach (string text4 in array6)
				{
					string key = TurnNameIntoToken(text4);
					if (!dictionary2.ContainsKey(key))
					{
						dictionary2.Add(key, text4);
					}
				}
				string[] array7 = array4;
				foreach (string key2 in array7)
				{
					string[] array8 = dictionary[key2];
					foreach (string text5 in array8)
					{
						string key3 = TurnNameIntoToken(text5);
						if (!dictionary2.ContainsKey(key3))
						{
							dictionary2.Add(key3, text5);
						}
					}
				}
				NamesByBodyIndex item = new NamesByBodyIndex(bodyIndex, array4, dictionary2);
				namesByBodyIndexes.Add(item);
			}
		}

		public static string TurnNameIntoToken(string name)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (char c in name)
			{
				if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
				{
					stringBuilder.Append(c);
				}
			}
			string text = stringBuilder.ToString();
			string text2 = text.ToUpper();
			return "ALLYNAMES_" + text2;
		}

		public static string GetRandomNameForCharacterMaster(CharacterMaster characterMaster, CharacterBody characterBody)
		{
			//IL_001e: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)characterMaster == (Object)null) && !((Object)(object)characterMaster.networkIdentity == (Object)null))
			{
				_ = characterMaster.networkIdentity.netId;
				if (0 == 0)
				{
					NetworkInstanceId netId = characterMaster.networkIdentity.netId;
					uint value = ((NetworkInstanceId)(ref netId)).Value;
					if (AllyNames.savedTokens.ContainsKey(value))
					{
						bool flag = false;
						return AllyNames.savedTokens[value];
					}
					BodyIndex bodyIndex = characterBody.bodyIndex;
					string bodyName = BodyCatalog.GetBodyName(bodyIndex);
					int num = -1;
					bool flag2 = false;
					if (bodyName == "RoboBallRedBuddyBody" || bodyName == "RoboBallGreenBuddyBody")
					{
						int num2 = CheckForEmpathyCoresSync(characterMaster, bodyName);
						if (num2 != -1)
						{
							num = num2;
						}
						else
						{
							flag2 = true;
						}
					}
					Dictionary<string, string> dictionary = new Dictionary<string, string>();
					bool flag3 = false;
					foreach (NamesByBodyIndex namesByBodyIndex in namesByBodyIndexes)
					{
						if (namesByBodyIndex.bodyIndex == bodyName)
						{
							dictionary = namesByBodyIndex.names;
							flag3 = true;
							break;
						}
					}
					if (!flag3)
					{
						return "";
					}
					if (dictionary.Count == 0)
					{
						return "";
					}
					rng.ResetSeed((ulong)value);
					int num3 = ((num != -1) ? num : rng.RangeInt(0, dictionary.Count));
					string key = dictionary.ElementAt(num3).Key;
					bool flag4 = false;
					AllyNames.savedTokens.Add(value, key);
					if (flag2)
					{
						AllyNames.empathyCoresNameIndexes.Add(characterMaster.minionOwnership.ownerMasterId, num3);
					}
					return key;
				}
			}
			return "";
		}

		private static int CheckForEmpathyCoresSync(CharacterMaster characterMaster, string bodyName)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			int result = -1;
			NetworkInstanceId ownerMasterId = characterMaster.minionOwnership.ownerMasterId;
			if (AllyNames.empathyCoresNameIndexes.ContainsKey(ownerMasterId))
			{
				result = AllyNames.empathyCoresNameIndexes[ownerMasterId];
			}
			return result;
		}

		public static void InitConfig()
		{
			configCategories = new ConfigCategory[8]
			{
				new ConfigCategory("Default", "Christopher,Joseph,Andrew,Ryan,Brandon,Jason,Justin,Sarah,William,Jonathan,Stephanie,Brian,Nicole,Anthony,Heather,Elizabeth,Duncan,Paul,Jeffrey,Ben,Javid,Nick,Steve,Gabriel,Jaime,Sean,Steven,Alejandro,Devon,Hugh,Rick,Reza,Mansoor,Hariz,Orso,Aleks,Jean-luc"),
				new ConfigCategory("Drones", ".jpeg,Michael,Microwave,New Folder (1),Hotdog.com,Buddy,32-bit,.png,Child 2.0,Ampie 3,Beep,Bolt,The Killer ^_^,1001000 1001001,V1,V2,Bee,Beep jr.,Updog,Foo,Bar,Hello World,Null,Access violation,Nova,Bigweld,Robots (2005),Q5U4EX7YY2E9N,Java,she risk on my of til i rain 2,Dronathan,Zip bomb,Killshare,notavirus.exe"),
				new ConfigCategory("Void", "Void Guy"),
				new ConfigCategory("CustomCategory1", ""),
				new ConfigCategory("CustomCategory2", ""),
				new ConfigCategory("CustomCategory3", ""),
				new ConfigCategory("CustomCategory4", ""),
				new ConfigCategory("CustomCategory5", "")
			};
			configBodyIndexes = new ConfigBodyIndex[21]
			{
				new ConfigBodyIndex("Turret1", "Gunner Turret", "Default,Drones", "Useless,Flightless Drone"),
				new ConfigBodyIndex("Drone1", "Gunner Drone", "Default,Drones", ""),
				new ConfigBodyIndex("Drone2", "Healing Drone", "Default,Drones", ":3"),
				new ConfigBodyIndex("MissileDrone", "Missiles Drone", "Default,Drones", ""),
				new ConfigBodyIndex("EquipmentDrone", "Equipment Drone", "Default,Drones", "Fart"),
				new ConfigBodyIndex("FlameDrone", "Incinerator Drone", "Default,Drones", "I'M KILLING YOU,I'M KILLING YOU!,MY PROGRAMMING IS JUST 'GET THAT FUCKING GUY RIGHT NOW"),
				new ConfigBodyIndex("EmergencyDrone", "Emergency Drone", "Default,Drones", ""),
				new ConfigBodyIndex("BackupDrone", "Back-Up Strike Drone", "Default,Drones", ""),
				new ConfigBodyIndex("EngiTurret", "Engineer Turret", "Default,Drones", "pew pew,*shoots you*"),
				new ConfigBodyIndex("EngiWalkerTurret", "Engineer Mobile Turret", "Default,Drones", "woooshhhphewww,*lasers you*"),
				new ConfigBodyIndex("MegaDrone", "TC-280 Prototype", "Default", "DESTRUCTION,APOCALYPSE,ARMAGEDDON,BAD INVESTMENT,I <3 VOID SEED,*DIES*,STAR DREAM"),
				new ConfigBodyIndex("DroneCommander", "Col. Droneman", "Default", "Col. Beep Boop"),
				new ConfigBodyIndex("BeetleGuardAlly", "Beetle Guard", "Default", "Sir Dies-A-Lot"),
				new ConfigBodyIndex("SquidTurret", "Squid Polyp", "Default", "Agent 3,Agent 4,Free Scrap,Scrap Me"),
				new ConfigBodyIndex("RoboBallRedBuddy", "Quiet Probe", "", "DO YOU LOVE THEM TOO,RED AND LONELY,COLD,Orso"),
				new ConfigBodyIndex("RoboBallGreenBuddy", "Delighted Probe", "", "YES I LOVE YOU TOO,GREEN AND LONELY,BOLD,Aleks"),
				new ConfigBodyIndex("MinorConstructOnKill", "Alpha Construct", "Default", "Triangle"),
				new ConfigBodyIndex("TitanGold", "Aurelionite", "Default", "Big Boy,The Guardian"),
				new ConfigBodyIndex("NullifierAlly", "Void Reaver", "Default,Void", "the crap"),
				new ConfigBodyIndex("VoidJailerAlly", "Void Jailer", "Default,Void", "the lober"),
				new ConfigBodyIndex("VoidMegaCrabAlly", "Void Devastator", "Default,Void", "the cooler crap")
			};
		}
	}
}