Decompiled source of RankTitleSwapper v1.1.2

plugins/RankTitleSwapper/RankTitleSwapper.dll

Decompiled 2 weeks 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 BepInEx;
using UltraTweaker;
using UltraTweaker.SettingUI;
using UltraTweaker.SettingUI.UIElements;
using UltraTweaker.SettingUI.UIElements.Impl;
using UltraTweaker.Subsettings;
using UltraTweaker.Subsettings.Impl;
using UltraTweaker.Tweaks;
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: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace RankTitleSwapper;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("waffle.ultrakill.rts", "RankTitleSwapper", "1.1.0")]
public class Core : BaseUnityPlugin
{
	public const string Name = "RankTitleSwapper";

	public const string GUID = "waffle.ultrakill.rts";

	public const string Version = "1.1.0";

	public void Start()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		SettingUIHandler.Pages.Add("waffle.ultrakill.rts.main", new Page("GENERAL", "RANKTITLESWAPPER"));
		UltraTweaker.AddAssembly(Assembly.GetExecutingAssembly());
	}
}
[TweakMetadata("Swap Rank Titles", "waffle.ultrakill.rts.rank_title_swapper", "Replace rank titles with ones of your choice.", "waffle.ultrakill.rts.main", 0, null, true, false)]
public class TitleTweak : Tweak
{
	private static string _modPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

	private static string _titlePath = Path.Combine(_modPath, "Titles");

	private List<Sprite> _default;

	private List<Sprite> _edited;

	public List<string> Paths
	{
		get
		{
			string[] files = Directory.GetFiles(_titlePath);
			for (int i = 0; i < files.Length; i++)
			{
				files[i] = files[i].Split(new char[1] { Path.DirectorySeparatorChar }).Last();
			}
			return files.ToList();
		}
	}

	public TitleTweak()
	{
		//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_00a4: Expected O, but got Unknown
		//IL_00a4: Expected O, but got Unknown
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Expected O, but got Unknown
		//IL_00c0: 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)
		//IL_00da: Expected O, but got Unknown
		//IL_00da: Expected O, but got Unknown
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Expected O, but got Unknown
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Expected O, but got Unknown
		//IL_0110: Expected O, but got Unknown
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Expected O, but got Unknown
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Expected O, but got Unknown
		//IL_0146: Expected O, but got Unknown
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Expected O, but got Unknown
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Expected O, but got Unknown
		//IL_017c: Expected O, but got Unknown
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Expected O, but got Unknown
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Expected O, but got Unknown
		//IL_01b2: Expected O, but got Unknown
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Expected O, but got Unknown
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Expected O, but got Unknown
		//IL_01e8: Expected O, but got Unknown
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Expected O, but got Unknown
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Expected O, but got Unknown
		//IL_021e: Expected O, but got Unknown
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Expected O, but got Unknown
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Expected O, but got Unknown
		//IL_0254: Expected O, but got Unknown
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Expected O, but got Unknown
		string text = _titlePath;
		if (text.Contains("AppData\\Roaming"))
		{
			text = text.Substring(text.IndexOf("AppData\\Roaming") + "AppData\\Roaming".Length);
			text = "%appdata%\\" + text;
		}
		else if (text.Contains(PathUtils.GameDirectory()))
		{
			text = text.Replace(PathUtils.GameDirectory(), "ULTRAKILL");
		}
		base.Subsettings = new Dictionary<string, Subsetting>
		{
			{
				"path",
				(Subsetting)new CommentSubsetting((Tweak)(object)this, new Metadata("Path", "path", text), (SubsettingUIElement)new CommentSubsettingElement(), (Action)OpenFolder, "OPEN")
			},
			{
				"ranku",
				(Subsetting)new StringSubsetting((Tweak)(object)this, new Metadata("ULTRAKILL", "ranku", "ULTRAKILL style rank."), (SubsettingUIElement)new DropdownStringSubsettingElement(Paths), "RankU.png")
			},
			{
				"ranksss",
				(Subsetting)new StringSubsetting((Tweak)(object)this, new Metadata("SSShitstorm", "ranksss", "SSShitstorm style rank."), (SubsettingUIElement)new DropdownStringSubsettingElement(Paths), "RankSSS.png")
			},
			{
				"rankss",
				(Subsetting)new StringSubsetting((Tweak)(object)this, new Metadata("SSadistic", "rankss", "SSadistic style rank."), (SubsettingUIElement)new DropdownStringSubsettingElement(Paths), "RankSS.png")
			},
			{
				"ranks",
				(Subsetting)new StringSubsetting((Tweak)(object)this, new Metadata("Supreme", "ranks", "Supreme style rank."), (SubsettingUIElement)new DropdownStringSubsettingElement(Paths), "RankS.png")
			},
			{
				"ranka",
				(Subsetting)new StringSubsetting((Tweak)(object)this, new Metadata("Anarchic", "ranka", "Anarchic style rank."), (SubsettingUIElement)new DropdownStringSubsettingElement(Paths), "RankA.png")
			},
			{
				"rankb",
				(Subsetting)new StringSubsetting((Tweak)(object)this, new Metadata("Brutal", "rankb", "Brutal style rank."), (SubsettingUIElement)new DropdownStringSubsettingElement(Paths), "RankB.png")
			},
			{
				"rankc",
				(Subsetting)new StringSubsetting((Tweak)(object)this, new Metadata("Chaotic", "rankc", "Chaotic style rank."), (SubsettingUIElement)new DropdownStringSubsettingElement(Paths), "RankC.png")
			},
			{
				"rankd",
				(Subsetting)new StringSubsetting((Tweak)(object)this, new Metadata("Destructive", "rankd", "Destructive style rank."), (SubsettingUIElement)new DropdownStringSubsettingElement(Paths), "RankD.png")
			}
		};
	}

	private void OpenFolder()
	{
		ProcessStartInfo startInfo = new ProcessStartInfo
		{
			Arguments = _titlePath,
			FileName = "explorer.exe"
		};
		Process.Start(startInfo);
	}

	public override void OnTweakEnabled()
	{
		((Tweak)this).OnTweakEnabled();
		SetValues();
		SetStyleHud(_edited);
	}

	public override void OnTweakDisabled()
	{
		((Tweak)this).OnTweakDisabled();
		SetStyleHud(_default);
	}

	public override void OnSceneLoad(Scene scene, LoadSceneMode mode)
	{
		_default = MonoSingleton<StyleHUD>.Instance?.ranks.Select((StyleRank x) => x.sprite).ToList();
		SetStyleHud(_edited);
	}

	public override void OnSubsettingUpdate()
	{
		SetValues();
		SetStyleHud(_edited);
	}

	public static bool TryLoadPNG(string fileName, out Sprite sprite)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		string text = Path.Combine(_titlePath, fileName);
		Debug.Log((object)("Loading " + text));
		if (File.Exists(text))
		{
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, File.ReadAllBytes(text));
			sprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			return true;
		}
		sprite = null;
		return false;
	}

	public void SetValues()
	{
		if (_default == null)
		{
			_default = MonoSingleton<StyleHUD>.Instance?.ranks.Select((StyleRank x) => x.sprite).ToList() ?? null;
		}
		if (_default != null)
		{
			_edited = _default.ToList();
			TitleTweak instance = Tweak.GetInstance<TitleTweak>();
			if (TryLoadPNG(((Tweak)instance).Subsettings["rankd"].GetValue<string>(), out var sprite))
			{
				_edited[0] = sprite;
			}
			if (TryLoadPNG(((Tweak)instance).Subsettings["rankc"].GetValue<string>(), out var sprite2))
			{
				_edited[1] = sprite2;
			}
			if (TryLoadPNG(((Tweak)instance).Subsettings["rankb"].GetValue<string>(), out var sprite3))
			{
				_edited[2] = sprite3;
			}
			if (TryLoadPNG(((Tweak)instance).Subsettings["ranka"].GetValue<string>(), out var sprite4))
			{
				_edited[3] = sprite4;
			}
			if (TryLoadPNG(((Tweak)instance).Subsettings["ranks"].GetValue<string>(), out var sprite5))
			{
				_edited[4] = sprite5;
			}
			if (TryLoadPNG(((Tweak)instance).Subsettings["rankss"].GetValue<string>(), out var sprite6))
			{
				_edited[5] = sprite6;
			}
			if (TryLoadPNG(((Tweak)instance).Subsettings["ranksss"].GetValue<string>(), out var sprite7))
			{
				_edited[6] = sprite7;
			}
			if (TryLoadPNG(((Tweak)instance).Subsettings["ranku"].GetValue<string>(), out var sprite8))
			{
				_edited[7] = sprite8;
			}
		}
	}

	public void SetStyleHud(List<Sprite> sprites)
	{
		if (sprites == null)
		{
			Debug.LogWarning((object)"Null list, returning.");
			return;
		}
		if ((Object)(object)MonoSingleton<StyleHUD>.Instance == (Object)null)
		{
			Debug.LogWarning((object)"Null StyleHUD, returning.");
			return;
		}
		for (int i = 0; i < MonoSingleton<StyleHUD>.Instance.ranks.Count; i++)
		{
			MonoSingleton<StyleHUD>.Instance.ranks[i].sprite = sprites[i];
		}
		MonoSingleton<StyleHUD>.Instance.rankImage.sprite = sprites[MonoSingleton<StyleHUD>.Instance.rankIndex];
	}
}