Decompiled source of TheBenedictBus v1.0.1

CruiserSkin.dll

Decompiled 12 hours ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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("iSHAK")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("iSHAK")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("61bf0656-343b-4d77-bb0d-9a0214ffaea2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CruiserSkin;

internal class Patch
{
	private static Texture2D main;

	private static Texture2D destroyed;

	public static ManualLogSource log;

	[HarmonyPatch(typeof(VehicleController), "Start")]
	[HarmonyPrefix]
	private static void StartPatch(VehicleController __instance)
	{
		main = Plugin.defaults[0];
		destroyed = Plugin.destroyeds[0];
		Transform[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Transform>();
		foreach (Transform val in componentsInChildren)
		{
			if (((Object)val).name.Contains("MainBody") || ((Object)val).name == "CarHoodMesh" || ((Object)val).name == "MelanieRVFloor1(Clone)")
			{
				((Renderer)((Component)val).GetComponent<MeshRenderer>()).materials[0].mainTexture = (Texture)(object)main;
			}
			else if (((Object)val).name == "DoorRightContainer" || ((Object)val).name == "DoorLeftContainer")
			{
				((Renderer)((Component)val).GetComponentInChildren<MeshRenderer>()).materials[0].mainTexture = (Texture)(object)main;
			}
			else if (((Object)val).name == "BackDoorMesh")
			{
				((Renderer)((Component)val).GetComponent<SkinnedMeshRenderer>()).materials[0].mainTexture = (Texture)(object)main;
			}
		}
	}

	[HarmonyPatch(typeof(VehicleController), "DestroyCar")]
	[HarmonyPostfix]
	private static void DestroyCarPatch(VehicleController __instance)
	{
		Transform[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Transform>();
		foreach (Transform val in componentsInChildren)
		{
			if (((Object)val).name.Contains("MainBody") || ((Object)val).name == "CarHoodMesh")
			{
				((Renderer)((Component)val).GetComponent<MeshRenderer>()).materials[0].mainTexture = (Texture)(object)destroyed;
			}
			else if (((Object)val).name == "DoorRightContainer" || ((Object)val).name == "DoorLeftContainer")
			{
				((Renderer)((Component)val).GetComponentInChildren<MeshRenderer>()).materials[0].mainTexture = (Texture)(object)destroyed;
			}
			else if (((Object)val).name == "BackDoorMesh")
			{
				((Renderer)((Component)val).GetComponent<SkinnedMeshRenderer>()).materials[0].mainTexture = (Texture)(object)destroyed;
			}
		}
	}
}
[BepInPlugin("EffMapis.CruiserSkin", "CruiserSkin", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
	public static List<Texture2D> defaults = new List<Texture2D>();

	public static List<Texture2D> destroyeds = new List<Texture2D>();

	private void Awake()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		initSkins(Paths.PluginPath);
		Patch.log = ((BaseUnityPlugin)this).Logger;
		if (defaults.Count > 0)
		{
			new Harmony("CruiserSkin").PatchAll(typeof(Patch));
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"CruiserSkin is loaded!");
	}

	private void initSkins(string path)
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Expected O, but got Unknown
		string[] directories = Directory.GetDirectories(path);
		foreach (string path2 in directories)
		{
			initSkins(path2);
		}
		string[] files = Directory.GetFiles(path);
		foreach (string text in files)
		{
			if (text.EndsWith("cruiser.png"))
			{
				Texture2D val = new Texture2D(2, 2);
				ImageConversion.LoadImage(val, File.ReadAllBytes(text));
				defaults.Add(val);
			}
			else if (text.EndsWith("cruiser_destroyed.png"))
			{
				Texture2D val2 = new Texture2D(2, 2);
				ImageConversion.LoadImage(val2, File.ReadAllBytes(text));
				destroyeds.Add(val2);
			}
		}
	}
}