using System;
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 LethalNetworkAPI;
using LethalNetworkAPI.Utils;
using Unity.Netcode;
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 LNetworkVariable<int> skinSet = LNetworkVariable<int>.Connect("CS.Skin", 0, (LNetworkVariableWritePerms)0, (Action<int, int>)null);
[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" || ((Object)val).name == "DriverSeatContainer" || ((Object)val).name == "CabinWindowContainer")
{
((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;
}
else if (((Object)val).name == "Wheels")
{
MeshRenderer[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer val2 in componentsInChildren2)
{
((Renderer)val2).materials[0].mainTexture = (Texture)(object)destroyed;
}
}
}
}
[HarmonyPatch(typeof(RoundManager), "LoadNewLevel")]
[HarmonyPostfix]
private static void LoadNewLevel(RoundManager __instance, ref int randomSeed, ref SelectableLevel newLevel)
{
VehicleController val = Object.FindObjectOfType<VehicleController>();
if ((Object)(object)val != (Object)null)
{
if (((NetworkBehaviour)__instance).IsServer && LNetworkUtils.IsHostOrServer)
{
skinSet.Value = Random.Range(0, Plugin.defaults.Count);
}
setSkin(val);
}
}
private static void setSkin(VehicleController vc)
{
main = Plugin.defaults[skinSet.Value];
destroyed = Plugin.destroyeds[skinSet.Value];
Plugin.logger.LogInfo((object)("skin value is setted to " + skinSet.Value));
Transform[] componentsInChildren = ((Component)vc).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)main;
}
else if (((Object)val).name == "DoorRightContainer" || ((Object)val).name == "DoorLeftContainer" || ((Object)val).name == "DriverSeatContainer" || ((Object)val).name == "CabinWindowContainer")
{
((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;
}
else if (((Object)val).name == "Wheels")
{
MeshRenderer[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer val2 in componentsInChildren2)
{
((Renderer)val2).materials[0].mainTexture = (Texture)(object)main;
}
}
}
}
}
[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>();
public static ManualLogSource logger;
private void Awake()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
logger = ((BaseUnityPlugin)this).Logger;
initSkins(Paths.PluginPath);
if (defaults.Count > 0)
{
new Harmony("CruiserSkin").PatchAll(typeof(Patch));
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"CruiserSkin is loaded!");
}
private void initSkins(string path)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Expected O, but got Unknown
string[] directories = Directory.GetDirectories(path);
foreach (string path2 in directories)
{
initSkins(path2);
}
string[] files = Directory.GetFiles(path);
string[] array = files;
foreach (string text in array)
{
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);
}
}
}
}