Decompiled source of GiantChibi v1.0.1

BepInEx/plugins/GiantChibi/GiantChibi.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using LC_API.BundleAPI;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("GiantChibi")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A mod for Lethal Company which replaces the Forest giant with Chibidoki")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("GiantChibi")]
[assembly: AssemblyTitle("GiantChibi")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace GiantChibi;

public class ChibiModel : MonoBehaviour
{
	private ForestGiantAI controller;

	public void Start()
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)"[MonAmiral] Replacing the Forest Giant model.");
		controller = ((Component)this).GetComponentInChildren<ForestGiantAI>();
		((Component)this).GetComponentInChildren<LODGroup>().enabled = false;
		SkinnedMeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<SkinnedMeshRenderer>();
		GameObject val = null;
		try
		{
			GameObject loadedAsset = BundleLoader.GetLoadedAsset<GameObject>("assets/GiantChibi/ChibiGiant.fbx");
			Texture loadedAsset2 = BundleLoader.GetLoadedAsset<Texture>("assets/GiantChibi/Chibmin_ALB.png");
			Material val2 = new Material(((Renderer)componentsInChildren[0]).material);
			val2.SetTexture("_BaseColorMap", loadedAsset2);
			val2.SetTexture("_BumpMap", (Texture)null);
			val = Object.Instantiate<GameObject>(loadedAsset, ((Component)this).transform);
			val.transform.position = Vector3.zero;
			val.transform.rotation = Quaternion.identity;
			SkinnedMeshRenderer[] componentsInChildren2 = val.GetComponentsInChildren<SkinnedMeshRenderer>();
			foreach (SkinnedMeshRenderer obj in componentsInChildren2)
			{
				((Component)obj).gameObject.layer = ((Component)componentsInChildren[0]).gameObject.layer;
				((Renderer)obj).material = val2;
			}
			Transform boneToParent = val.transform.Find("metarig");
			Transform newParent = ((Component)this).transform.Find("FGiantModelContainer").Find("AnimContainer").Find("metarig");
			ParentBoneRecursively(boneToParent, newParent);
			componentsInChildren2 = componentsInChildren;
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				((Component)componentsInChildren2[i]).gameObject.SetActive(false);
			}
		}
		catch (Exception ex)
		{
			Debug.LogException(ex);
			if (Object.op_Implicit((Object)(object)val))
			{
				Object.Destroy((Object)(object)val);
				Object.Destroy((Object)(object)this);
			}
		}
	}

	public void Update()
	{
	}

	private void ParentBoneRecursively(Transform boneToParent, Transform newParent)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		boneToParent.parent = newParent;
		boneToParent.localPosition = Vector3.zero;
		boneToParent.localRotation = Quaternion.identity;
		for (int num = boneToParent.childCount - 1; num >= 0; num--)
		{
			Transform child = boneToParent.GetChild(num);
			Transform val = newParent.Find(((Object)child).name);
			if (Object.op_Implicit((Object)(object)val))
			{
				ParentBoneRecursively(child, val);
			}
		}
	}
}
[BepInPlugin("GiantChibi", "GiantChibi", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInProcess("Lethal Company.exe")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ForestGiantAI))]
	internal class ForestGiantAIPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPatch(ref PlayerControllerB __instance)
		{
			((Component)__instance).gameObject.AddComponent<ChibiModel>();
		}
	}

	public static Harmony _harmony;

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		_harmony = new Harmony("GiantChibi");
		_harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"GiantChibi loaded");
		BundleLoader.LoadAssetBundle(GetAssemblyFullPath("giantchibi"), true);
	}

	private static string GetAssemblyFullPath(string additionalPath)
	{
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		return Path.GetFullPath((additionalPath != null) ? Path.Combine(directoryName, ".\\" + additionalPath) : directoryName);
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "GiantChibi";

	public const string PLUGIN_NAME = "GiantChibi";

	public const string PLUGIN_VERSION = "1.0.1";
}