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 BeltSkins;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Players;
using MelonLoader;
using MelonLoader.Utils;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "BeltSkins", "1.2.5", "ERROR", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 255, 0, 0)]
[assembly: MelonAuthorColor(255, 255, 0, 0)]
[assembly: AssemblyTitle("BeltSkins")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BeltSkins")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: VerifyLoaderVersion(0, 6, 2, true)]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b10c94a1-8a40-4701-bc5b-98eabb44dfea")]
[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 BeltSkins;
public class Main : MelonMod
{
[HarmonyPatch(typeof(PlayerController), "Initialize", new Type[] { typeof(Player) })]
public static class PlayerInit
{
private static void Postfix(ref PlayerController __instance, ref Player player)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
ApplyBeltTexture(((Component)__instance).gameObject, (int)__instance.controllerType == 1, player.Data.GeneralData.BattlePoints);
}
}
public static void ApplyBeltTexture(GameObject player, bool isLocal, int playerBP)
{
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Expected O, but got Unknown
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
MelonLogger.Msg("Player BP: " + playerBP);
Texture2D val = null;
string beltColor = GetBeltColor(playerBP);
Texture2D val2;
Texture2D val3;
Texture2D val4;
if (isLocal)
{
val2 = LoadTexture("/Main.png");
val3 = LoadTexture("/Mat.png");
val4 = LoadTexture("/Normal.png");
}
else
{
val = LoadTexture("/" + beltColor + "/Main_Tint.png");
val2 = (((Object)(object)val != (Object)null) ? val : LoadTexture("/" + beltColor + "/Main.png"));
val3 = LoadTexture("/" + beltColor + "/Mat.png");
val4 = LoadTexture("/" + beltColor + "/Normal.png");
}
if ((Object)(object)val2 == (Object)null && !isLocal)
{
MelonLogger.Msg($"No main texture found for {beltColor} belt ({playerBP} BP), skipping belt texture application.");
return;
}
MelonLogger.Msg($"Attempting to skin {beltColor} belt ({playerBP} BP)");
try
{
Renderer component = ((Component)player.transform.Find("Visuals/Belt")).GetComponent<Renderer>();
MaterialPropertyBlock val5 = new MaterialPropertyBlock();
val5.Clear();
if ((Object)(object)val2 != (Object)null)
{
if (isLocal)
{
val5.SetColor("_ColorB", Color.white);
val5.SetColor("_FadeColor", Color.white);
}
val5.SetTexture("_Color_Map", (Texture)(object)val2);
}
if ((Object)(object)val3 != (Object)null)
{
val5.SetTexture("_Metal_Map", (Texture)(object)val3);
}
if ((Object)(object)val4 != (Object)null)
{
val5.SetTexture("_Normal_Map", (Texture)(object)val4);
}
component.SetPropertyBlock(val5);
}
catch (Exception ex)
{
MelonLogger.Error("Failed to apply texture to player: " + ex.Message);
}
}
public static string GetBeltColor(int playerBP)
{
Dictionary<int, string> dictionary = new Dictionary<int, string>
{
{ 156, "Black" },
{ 96, "Red" },
{ 54, "Blue" },
{ 30, "Green" },
{ 12, "Yellow" },
{ 0, "White" }
};
foreach (KeyValuePair<int, string> item in dictionary)
{
if (playerBP >= item.Key)
{
return item.Value;
}
}
return "White";
}
private static Texture2D LoadTexture(string fileName)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
string path = MelonEnvironment.UserDataDirectory + "/Skins/Player/Belt" + fileName;
if (!File.Exists(path))
{
MelonLogger.Warning("Texture file not found: " + fileName);
return null;
}
byte[] array = File.ReadAllBytes(path);
Texture2D val = new Texture2D(2, 2);
if (!ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
{
MelonLogger.Warning("Failed to load texture from file: " + fileName);
return null;
}
return val;
}
}