Decompiled source of GokuWhisk v1.0.0

GokuWhisk.dll

Decompiled 8 months ago
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.Configuration;
using BepInEx.Logging;
using GokuWhisk.Core;
using GokuWhisk.Patches;
using GokuWhisk.Scripts;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("GokuWhisk")]
[assembly: AssemblyDescription("A mod for Content Warning that replaces the Whisk enemy with Goku")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GokuWhisk")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5f4bc14-7c3d-4caa-9959-835163e210dc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GokuWhisk.Scripts
{
	internal class GokuController : MonoBehaviour
	{
		private Transform EnemyPositionTransform { get; set; }

		private GameObject BaseGokuObject { get; set; }

		private Vector3 PositionOffset { get; set; }

		private Quaternion RotationOffset { get; set; }

		public void Start()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			EnemyPositionTransform = ((Component)this).gameObject.transform.Find("RigCreator").Find("Rig").Find("ToolkitBoys_Hammer")
				.Find("Armature")
				.Find("Hip");
			PositionOffset = new Vector3(-0.2f, -1.6f, -0.2f);
			RotationOffset = Quaternion.Euler(344f, 0f, 0f);
			HideWhiskModel();
			CreateGokuModel();
			FixGokuMaterials();
		}

		public void Update()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			BaseGokuObject.transform.position = EnemyPositionTransform.position + PositionOffset;
			BaseGokuObject.transform.rotation = EnemyPositionTransform.rotation * RotationOffset;
		}

		private void HideWhiskModel()
		{
			Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
		}

		private void CreateGokuModel()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			GameObject asset = Assets.GetAsset<GameObject>("baseGokuPrefab");
			BaseGokuObject = Object.Instantiate<GameObject>(asset, EnemyPositionTransform);
			BaseGokuObject.transform.localScale = Vector3.one * 2.5f;
			((Object)BaseGokuObject).name = "Base Goku";
		}

		private void FixGokuMaterials()
		{
			Renderer componentInChildren = BaseGokuObject.GetComponentInChildren<Renderer>();
			Material[] materials = componentInChildren.materials;
			Material sharedMaterial = ((Component)this).GetComponentInChildren<Renderer>().sharedMaterial;
			sharedMaterial.GetPropertyNames((MaterialPropertyType)4).ToList().ForEach(delegate(string s)
			{
				Logger.LogInfo(s);
			});
			materials[0] = sharedMaterial;
			materials[1] = sharedMaterial;
			materials[2] = sharedMaterial;
			materials[0].mainTexture = (Texture)(object)Assets.GetAsset<Texture2D>("baseGokuClothesTexture");
			materials[1].mainTexture = (Texture)(object)Assets.GetAsset<Texture2D>("baseGokuFaceTexture");
			materials[2].mainTexture = (Texture)(object)Assets.GetAsset<Texture2D>("baseGokuHandsTexture");
			componentInChildren.materials = materials;
		}
	}
}
namespace GokuWhisk.Patches
{
	[HarmonyPatch]
	internal class ContentEventPatches
	{
		public static string[] GOKU_COMMENTS = new string[8] { "GOKU!!!", "IS THAT GOKU??", "my favorite arc is the android cell saga", "what is goku doing here?", "i recognize that guy", "LMAO goku", "KAMEHAMEHA!", "if he uses the spirit bomb its over for those guys" };

		[HarmonyPatch(typeof(ToolkitWhiskContentEvent), "GenerateComment")]
		[HarmonyPostfix]
		public static void GenerateComment(ref Comment __result)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			int num = Random.Range(0, GOKU_COMMENTS.Length);
			__result = new Comment(GOKU_COMMENTS[num]);
		}
	}
	[HarmonyPatch]
	internal class EnemyPatches
	{
		[HarmonyPatch(typeof(Bot_ToolkitBoy), "Start")]
		[HarmonyPostfix]
		public static void CreateGokuModel(Bot_ToolkitBoy __instance)
		{
			((Component)((Component)__instance).gameObject.transform.parent).gameObject.AddComponent<GokuController>();
		}
	}
}
namespace GokuWhisk.Core
{
	internal static class Assets
	{
		public static AssetBundle AssetBundle { get; private set; }

		private static Dictionary<string, Object> AssetList { get; set; }

		private static string AssemblyName => Assembly.GetExecutingAssembly().FullName.Split(new char[1] { ',' })[0];

		public static void PopulateAssets()
		{
			if ((Object)(object)AssetBundle != (Object)null)
			{
				Logger.LogWarning("Attempted to load the asset bundle but the bundle was not null!");
				return;
			}
			string name = AssemblyName + ".Bundle.gokuwhisk";
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name))
			{
				AssetBundle = AssetBundle.LoadFromStream(stream);
			}
			if ((Object)(object)AssetBundle == (Object)null)
			{
				Logger.LogError("Asset bundle at " + AssemblyName + ".gokuwhisk failed to load!");
			}
			AssetList = new Dictionary<string, Object>();
			Object[] array = AssetBundle.LoadAllAssets();
			foreach (Object val in array)
			{
				AssetList.Add(val.name, val);
			}
		}

		public static T GetAsset<T>(string name) where T : Object
		{
			if (!AssetList.TryGetValue(name, out var value))
			{
				Logger.LogError("Attempted to load asset of name " + name + " but no asset of that name exists!");
				return default(T);
			}
			T val = (T)(object)((value is T) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError("Attempted to load an asset of type " + typeof(T).Name + " but asset of name " + name + " does not match this type!");
				return default(T);
			}
			return val;
		}
	}
	internal static class Logger
	{
		public static void LogInfo(object message)
		{
			GokuWhiskBase.LogSource.LogInfo(message);
		}

		public static void LogWarning(object message)
		{
			GokuWhiskBase.LogSource.LogWarning(message);
		}

		public static void LogError(object message)
		{
			GokuWhiskBase.LogSource.LogError(message);
		}
	}
	[BepInPlugin("Vulf.GokuWhisk", "Goku Whisk", "1.0.0")]
	public class GokuWhiskBase : BaseUnityPlugin
	{
		private static GokuWhiskBase _instance;

		private readonly Harmony Harmony = new Harmony("Vulf.GokuWhisk");

		internal static GokuWhiskBase Instance
		{
			get
			{
				return _instance;
			}
			set
			{
				if ((Object)(object)_instance == (Object)null)
				{
					_instance = value;
				}
				else
				{
					Object.Destroy((Object)(object)value);
				}
			}
		}

		public static ManualLogSource LogSource => ((BaseUnityPlugin)Instance).Logger;

		public static ConfigFile ModConfig => ((BaseUnityPlugin)Instance).Config;

		public void Awake()
		{
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Populating assets...");
			Assets.PopulateAssets();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Hey it's me! Goku!");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Your files look pretty strong! I'm gonna patch them!");
			Harmony.PatchAll(typeof(GokuWhiskBase));
			Harmony.PatchAll(typeof(ContentEventPatches));
			Harmony.PatchAll(typeof(EnemyPatches));
		}
	}
	internal class PluginInfo
	{
		public const string GUID = "Vulf.GokuWhisk";

		public const string NAME = "Goku Whisk";

		public const string VERSION = "1.0.0";

		public const string ASSET_BUNDLE_NAME = "gokuwhisk";
	}
}