Decompiled source of LoadingSpriteAdditions v1.1.0

LoadingSpriteAdditions.dll

Decompiled 21 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HG.Reflection;
using LoadingScreenFix;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI.MainMenu;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
using RoR2.UI.MainMenu;
using RoR2BepInExPack.GameAssetPathsBetter;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
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: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LoadingSpriteAdditions")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+59372444030c122b523de78c546705b95410f99c")]
[assembly: AssemblyProduct("LoadingSpriteAdditions")]
[assembly: AssemblyTitle("LoadingSpriteAdditions")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 LoadingSpriteAdditions
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("kina.LoadingSpriteAdditions", "LoadingSpriteAdditions", "1.1.0")]
	public class LoadingSpriteAdditions : BaseUnityPlugin
	{
		public enum spriteType
		{
			rorr,
			disabled
		}

		private const string PluginGUID = "kina.LoadingSpriteAdditions";

		private const string PluginAuthor = "kina";

		private const string PluginName = "LoadingSpriteAdditions";

		private const string PluginVersion = "1.1.0";

		private static LoadingSpriteAdditions instance;

		private AssetBundle loadingSpritesBundle;

		private string[] loadingSpriteNames = new string[28]
		{
			"Huntress", "Enforcer", "Bandit", "BanditWhip", "HAND", "HANDRun", "Engi", "Miner", "Acrid", "Merc",
			"CHEF", "Pilot", "Arti", "ArtiFlame", "Drifter", "DrifterRun", "Sniper", "Robomando", "AcolyteTribeScout", "AcolyteTribeArcher",
			"AcolyteTribeHunter", "Nemmando", "NemmandoGun", "Nemmerc", "Technician", "MULE", "Captain", "REX"
		};

		private string[] disabledByDefault = new string[2] { "CHEF", "Acrid" };

		private ConfigEntry<bool> onlyCurrentSurv;

		private ConfigEntry<string> customBodyDict;

		private Dictionary<string, string> configBodyMatch = new Dictionary<string, string>();

		private ConfigEntry<string> blacklistBodies;

		private List<string> blacklistBodiesList = new List<string>();

		private ConfigEntry<float> ponchoChance;

		private Dictionary<string, SimpleSpriteAnimation> spriteAnimations = new Dictionary<string, SimpleSpriteAnimation>();

		private static PickRandomObjectOnAwake pickRandomInGame;

		private Dictionary<string, string> hardcoded = new Dictionary<string, string>
		{
			{ "Croco", "Acrid" },
			{ "DroneTech", "Pilot" },
			{ "Mage", "Arti" },
			{ "NemCommando", "Nemmando" },
			{ "HANDOverclocked", "Hand" },
			{ "SniperClassic", "Sniper" },
			{ "Treebot", "REX" }
		};

		private static bool ROOInstalled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		public void Awake()
		{
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Expected O, but got Unknown
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Expected O, but got Unknown
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Expected O, but got Unknown
			instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			loadingSpritesBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "loadingspritebundle"));
			try
			{
				ConfigEntry<bool> val = ((BaseUnityPlugin)instance).Config.Bind<bool>("LSA - Replacements", "Executioner", true, "whether to replace Executioner on the loading screen .,,.");
				if (ROOInstalled)
				{
					ROOSupport.AddConfig(val);
				}
				if (val.Value)
				{
					for (int i = 0; i < LoadingScreenFix.instance._spriteAnimations.Count; i++)
					{
						if (!(((Object)LoadingScreenFix.instance._spriteAnimations[i]).name != "ssaExecutionerWalk"))
						{
							LoadingScreenFix.instance._spriteAnimations[i] = loadingSpritesBundle.LoadAsset<SimpleSpriteAnimation>("ExecutionerWalk");
						}
					}
				}
			}
			catch (Exception data)
			{
				Log.Warning("error while trying to replace exe loading sprite ,.., ");
				Log.Warning(data);
			}
			ponchoChance = ((BaseUnityPlugin)this).Config.Bind<float>("LSA - Misc", "poncho chance,..,", 1f, "addition of .,,. poncho chance .,, .,. 1 = 1% ,..,,.,.,..,");
			if (ROOInstalled)
			{
				ROOSupport.AddConfig(ponchoChance);
			}
			if ((float)Random.Range(0, 100) <= ponchoChance.Value)
			{
				LoadingScreenFix.AddSpriteAnimation(loadingSpritesBundle.LoadAsset<SimpleSpriteAnimation>("ssaFalseSonPoncho"));
			}
			onlyCurrentSurv = ((BaseUnityPlugin)this).Config.Bind<bool>("LSA - Misc", "only pick currently playing survivor,..,", true, "makes LSA only pick your current survivor sprite .,,. goes random if it cant find it,.,..,");
			if (ROOInstalled)
			{
				ROOSupport.AddConfig(onlyCurrentSurv);
			}
			customBodyDict = ((BaseUnityPlugin)this).Config.Bind<string>("LSA - Misc", "currentply playing survivor overrides,..,", "DroneTechBody,Pilot,RailgunnerBody,Sniper,ToolbotBody,HAND", "overrides for if you want a specific body to have a sprte ,.,.");
			if (ROOInstalled)
			{
				ROOSupport.AddConfig(customBodyDict);
			}
			CreateBodyMatchDict();
			customBodyDict.SettingChanged += delegate
			{
				CreateBodyMatchDict();
			};
			blacklistBodies = ((BaseUnityPlugin)this).Config.Bind<string>("LSA - Misc", "blacklist bodies for currently playing override,..,", "", "if you think like ,. huntress rorr sprite is chuddy or something and want random on her,.,. eg \"HuntressBody,CommandoBody\" ,.,.");
			if (ROOInstalled)
			{
				ROOSupport.AddConfig(blacklistBodies);
			}
			CreateBlacklist();
			blacklistBodies.SettingChanged += delegate
			{
				CreateBlacklist();
			};
			string[] array = loadingSpriteNames;
			foreach (string text in array)
			{
				spriteType spriteType = spriteType.rorr;
				if (disabledByDefault.Contains(text))
				{
					spriteType = spriteType.disabled;
				}
				ConfigEntry<spriteType> val2 = ((BaseUnityPlugin)this).Config.Bind<spriteType>("LSA - Sprites", text ?? "", spriteType, "whether " + text + " should show up as a loading screen icon .,,");
				if (ROOInstalled)
				{
					ROOSupport.AddConfig(val2);
				}
				if (val2.Value == spriteType.rorr)
				{
					try
					{
						SimpleSpriteAnimation val3 = loadingSpritesBundle.LoadAsset<SimpleSpriteAnimation>("ssa" + text);
						LoadingScreenFix.AddSpriteAnimation(val3);
					}
					catch (Exception data2)
					{
						Log.Error("failed while trying to add " + text + " !!!");
						Log.Error(data2);
					}
				}
			}
			AddSpriteReplacement("CommandoWalk");
			AddSpriteReplacement("DroneHover");
			AddSpriteReplacement("GolemWalk");
			AddSpriteReplacement("LemurianWalk");
			AddSpriteReplacement("LoaderWalk");
			AddSpriteReplacement("ChildWalk");
			AsyncOperationHandle<GameObject> val4 = Addressables.LoadAssetAsync<GameObject>((object)RoR2_Base_UI.MiniScene_prefab);
			val4.Completed += delegate(AsyncOperationHandle<GameObject> handle)
			{
				pickRandomInGame = handle.Result.gameObject.GetComponent<PickRandomObjectOnAwake>();
			};
			PickRandomObjectOnAwake.OnEnable += new hook_OnEnable(ReplaceNewSillies);
			MainMenuController.Start += new hook_Start(UnhookNewSillies);
			PickRandomObjectOnAwake.OnEnable += new hook_OnEnable(PickRandomObjectOnAwakeOnOnEnable);
		}

		private void AddSpriteReplacement(string ssaName, string customPrefabName = "")
		{
			string text = ((customPrefabName != "") ? customPrefabName : ssaName);
			ConfigEntry<bool> val = ((BaseUnityPlugin)instance).Config.Bind<bool>("LSA - Replacements", text.Replace("Walk", "").Replace("Hover", "") ?? "", true, "whether to replace " + text.Replace("Walk", "").Replace("Hover", "") + " on the loading screen .,,.");
			if (ROOInstalled)
			{
				ROOSupport.AddConfig(val);
			}
			if (val.Value)
			{
				spriteAnimations.Add(ssaName, loadingSpritesBundle.LoadAsset<SimpleSpriteAnimation>(text));
			}
		}

		private void UnhookNewSillies(orig_Start orig, MainMenuController self)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			orig.Invoke(self);
			PickRandomObjectOnAwake.OnEnable -= new hook_OnEnable(ReplaceNewSillies);
			MainMenuController.Start -= new hook_Start(UnhookNewSillies);
			ReplaceSilliesOnRandom(pickRandomInGame);
		}

		private void ReplaceNewSillies(orig_OnEnable orig, PickRandomObjectOnAwake self)
		{
			if (((Object)((Component)self).gameObject).name != "MiniScene")
			{
				orig.Invoke(self);
				return;
			}
			ReplaceSilliesOnRandom(self);
			orig.Invoke(self);
		}

		private void ReplaceSilliesOnRandom(PickRandomObjectOnAwake pickRandom)
		{
			GameObject[] objectsToSelect = pickRandom.ObjectsToSelect;
			foreach (GameObject val in objectsToSelect)
			{
				if (spriteAnimations.TryGetValue(((Object)val).name, out var value))
				{
					((Component)val.transform.GetChild(0)).gameObject.GetComponent<SimpleSpriteAnimator>().animation = value;
					((Component)val.transform.GetChild(0)).gameObject.GetComponent<Image>().sprite = value.frames[0].sprite;
				}
			}
		}

		private void PickRandomObjectOnAwakeOnOnEnable(orig_OnEnable orig, PickRandomObjectOnAwake self)
		{
			orig.Invoke(self);
			if (!onlyCurrentSurv.Value || !Object.op_Implicit((Object)(object)Run.instance))
			{
				return;
			}
			CharacterMaster cachedMaster = LocalUserManager.GetFirstLocalUser().cachedMaster;
			CharacterBody body = cachedMaster.GetBody();
			string name = ((Object)cachedMaster.bodyPrefab).name;
			if (Object.op_Implicit((Object)(object)body))
			{
				name = ((Object)body).name;
			}
			name = NameCorrector(name);
			List<int> list = new List<int>();
			for (int i = 0; i < self.ObjectsToSelect.Length; i++)
			{
				string name2 = ((Object)self.ObjectsToSelect[i]).name;
				self.ObjectsToSelect[i].SetActive(false);
				if (name2.Contains(name, StringComparison.CurrentCultureIgnoreCase) && (!name2.Contains("nem", StringComparison.CurrentCultureIgnoreCase) || name.Contains("nem", StringComparison.CurrentCultureIgnoreCase)))
				{
					list.Add(i);
				}
			}
			if (list.Count == 0)
			{
				self.ObjectsToSelect[Random.Range(0, self.ObjectsToSelect.Length)].SetActive(true);
			}
			else
			{
				self.ObjectsToSelect[list[Random.Range(0, list.Count)]].SetActive(true);
			}
		}

		private void CreateBlacklist()
		{
			blacklistBodiesList = new List<string>();
			string[] array = blacklistBodies.Value.Split(',');
			if (array.Length != 0)
			{
				string[] array2 = array;
				foreach (string item in array2)
				{
					blacklistBodiesList.Add(item);
				}
			}
		}

		private void CreateBodyMatchDict()
		{
			configBodyMatch = new Dictionary<string, string>();
			string[] array = customBodyDict.Value.Split(',');
			if (array.Length != 0 && array.Length % 2 == 0)
			{
				for (int i = 0; i < array.Length; i += 2)
				{
					configBodyMatch.Add(array[i], array[i + 1]);
				}
			}
		}

		public string NameCorrector(string survName)
		{
			string text = survName.Replace("(Clone)", "");
			if (configBodyMatch.TryGetValue(text, out var value))
			{
				return value;
			}
			if (blacklistBodiesList.Contains(survName))
			{
				return "null";
			}
			text = text.Replace("Body", "").Replace(" ", "").Replace("2", "");
			if (text.Contains("Drone") && survName != "DroneTechBody")
			{
				return "Drone";
			}
			return hardcoded.GetValueOrDefault(text, text);
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

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

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

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

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

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

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	internal static class ROOSupport
	{
		internal static void AddConfig(ConfigEntry<LoadingSpriteAdditions.spriteType> configEntry)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)configEntry));
		}

		internal static void AddConfig(ConfigEntry<bool> configEntry)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(configEntry));
		}

		internal static void AddConfig(ConfigEntry<string> configEntry)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(configEntry));
		}

		internal static void AddConfig(ConfigEntry<float> configEntry)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new SliderOption(configEntry, new SliderConfig
			{
				min = 0f,
				max = 100f
			}));
		}
	}
	public static class Utils
	{
		public static void SliderConfig(float min, float max, ConfigEntry<float> config)
		{
			//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)
			//IL_000d: 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_0021: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			StepSliderConfig val = new StepSliderConfig
			{
				max = max,
				min = min,
				FormatString = "{0:0}"
			};
			StepSliderOption val2 = new StepSliderOption(config, val);
			ModSettingsManager.AddOption((BaseOption)(object)val2);
		}

		public static void SliderConfig(int min, int max, ConfigEntry<int> config)
		{
			//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)
			//IL_000d: 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_0020: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			IntSliderConfig val = new IntSliderConfig
			{
				max = max,
				min = min,
				formatString = "{0:0}"
			};
			IntSliderOption val2 = new IntSliderOption(config, val);
			ModSettingsManager.AddOption((BaseOption)(object)val2);
		}

		public static void CheckboxConfig(ConfigEntry<bool> config, bool restartRequired = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			CheckBoxConfig val = new CheckBoxConfig();
			((BaseOptionConfig)val).restartRequired = restartRequired;
			CheckBoxOption val2 = new CheckBoxOption(config, val);
			ModSettingsManager.AddOption((BaseOption)(object)val2);
		}

		public static void StringConfig(ConfigEntry<string> config)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			InputFieldConfig val = new InputFieldConfig();
			StringInputFieldOption val2 = new StringInputFieldOption(config, val);
			ModSettingsManager.AddOption((BaseOption)(object)val2);
		}

		public static void KeyboardConfig(ConfigEntry<KeyboardShortcut> config)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			KeyBindConfig val = new KeyBindConfig();
			KeyBindOption val2 = new KeyBindOption(config, val);
			ModSettingsManager.AddOption((BaseOption)(object)val2);
		}
	}
}