Decompiled source of ShacoCoilHead v1.1.0

ShacoCoilHead.dll

Decompiled 6 months 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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ShacoCoilHead")]
[assembly: AssemblyDescription("Replaces Coil-Heads (SpringMen) models with that of Shaco from League of Legends.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShacoCoilHead")]
[assembly: AssemblyCopyright("Copyright © LukaS 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("21c80494-ee00-40e9-87c4-344a69cb0d70")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace ShacoCoilHead;

[BepInPlugin("LukaS.ShacoCoilHead", "Shaco Coil-Head", "1.1.0")]
public class ShacoCoilHeadMain : BaseUnityPlugin
{
	private const string modGUID = "LukaS.ShacoCoilHead";

	private const string modName = "Shaco Coil-Head";

	private const string modVersion = "1.1.0";

	private static readonly Harmony HarmonyInst = new Harmony("LukaS.ShacoCoilHead");

	public static ManualLogSource ModLog;

	private static readonly Dictionary<string, GameObject> Assets = new Dictionary<string, GameObject>();

	private void Awake()
	{
		ModLog = Logger.CreateLogSource("LukaS.ShacoCoilHead");
		if (LoadAssets())
		{
			HarmonyInst.PatchAll();
		}
	}

	private bool LoadAssets()
	{
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Expected O, but got Unknown
		string path = Path.Combine(Paths.BepInExRootPath, "plugins\\ShacoCoilHead\\Assets");
		if (!Directory.Exists(path))
		{
			ModLog.LogError((object)"ShacoCoilHead could not find the \\ShacoCoilHead\\Assets folder!");
			return false;
		}
		string[] invalidExtensions = new string[8] { ".dll", ".json", ".png", ".md", ".old", ".txt", ".exe", ".lem" };
		string[] array = (from file in Directory.GetFiles(path, "*", SearchOption.AllDirectories)
			where !invalidExtensions.Any((string ending) => file.EndsWith(ending, StringComparison.CurrentCultureIgnoreCase))
			select file).ToArray();
		string[] array2 = array;
		foreach (string text in array2)
		{
			ModLog.LogInfo((object)("Loading assets from file " + text + ":"));
			AssetBundle val = AssetBundle.LoadFromFile(text);
			string[] allAssetNames = val.GetAllAssetNames();
			foreach (string text2 in allAssetNames)
			{
				ModLog.LogInfo((object)("  Loading asset: " + text2));
				if (!Assets.ContainsKey(text2))
				{
					Assets.Add(text2, (GameObject)val.LoadAsset(text2));
				}
			}
		}
		return true;
	}

	public static GameObject GetObjFromAsset(string name)
	{
		if (Assets.ContainsKey(name))
		{
			return Assets[name];
		}
		ModLog.LogWarning((object)("Couldn't find asset " + name));
		return null;
	}
}
[HarmonyPatch(typeof(EnemyAI))]
internal class SpringManModelPatch
{
	[HarmonyPatch(typeof(EnemyAI), "Start")]
	[HarmonyPostfix]
	public static void ModelPatch(EnemyAI __instance)
	{
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		if (__instance is SpringManAI)
		{
			GameObject objFromAsset = ShacoCoilHeadMain.GetObjFromAsset("assets/shaco.prefab");
			if ((Object)(object)objFromAsset != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(objFromAsset);
				((Renderer)((Component)((Component)__instance).transform.Find("SpringManModel/Body")).gameObject.GetComponent<SkinnedMeshRenderer>()).enabled = false;
				((Renderer)((Component)((Component)__instance).transform.Find("SpringManModel/Head")).gameObject.GetComponent<MeshRenderer>()).enabled = false;
				val.transform.SetParent(((Component)__instance).transform.Find("SpringManModel"));
				val.transform.localPosition = Vector3.zero;
				val.transform.localRotation = Quaternion.identity;
				val.transform.localScale = Vector3.one;
				GameObject gameObject = ((Component)val.transform.Find("Shaco/Body")).gameObject;
				GameObject gameObject2 = ((Component)val.transform.Find("Shaco/AnimContainer/metarig")).gameObject;
				Transform val2 = ((Component)__instance).transform.Find("SpringManModel/AnimContainer");
				Transform val3 = val2.Find("metarig");
				gameObject2.transform.SetParent(val2);
				gameObject2.transform.SetSiblingIndex(0);
				gameObject2.transform.localPosition = new Vector3(0f, 1.8f, 0f);
				gameObject.GetComponent<SkinnedMeshRenderer>().rootBone = ((Component)gameObject2.transform.Find("spine")).transform;
				((Object)val3).name = "old_metarig";
			}
		}
	}
}