using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using ItemRarityColors;
using ItemRarityColors.Helpers;
using ItemRarityColors.Integration;
using ItemRarityColors.Patches;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
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(ModMain), "ItemRarityColors", "1.0.0", "Generic", null)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ItemRarityColors")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1250855253d79686f4ebe376bc05942bd130e3c9")]
[assembly: AssemblyProduct("ItemRarityColors")]
[assembly: AssemblyTitle("ItemRarityColors")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ItemRarityColors
{
public sealed class ModMain : MelonMod
{
public override void OnInitializeMelon()
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
Preferences.Init();
Log.Debug("ItemRarityColors: initializing...");
try
{
Harmony.DEBUG = Preferences.EnableDebugLogs?.Value ?? false;
}
catch
{
}
Harmony val = new Harmony("ItemRarityColors.Integration");
val.CreateClassProcessor(typeof(ADVRIntegration.IntegrationPatches.ModLoader_Initialize_PostfixPatch)).Patch();
val.CreateClassProcessor(typeof(ADVRIntegration.IntegrationPatches.SettingsMod_OnApplyClick_PostfixPatch)).Patch();
val.CreateClassProcessor(typeof(ADVRIntegration.IntegrationPatches.GameHandler_Awake_PostfixPatch)).Patch();
ADVRIntegration.EvaluateAndApply();
DiagnosticsPatches.Apply();
}
}
}
namespace ItemRarityColors.Patches
{
internal static class DiagnosticsPatches
{
[HarmonyPatch(typeof(ItemUpgrade), "GetLocalizedName")]
private static class ItemUpgrade_GetLocalizedName_PostfixPatch
{
[HarmonyPostfix]
private static void Postfix(ItemUpgrade __instance, ref string __result)
{
try
{
MelonPreferences_Entry<bool>? enableDebugLogs = Preferences.EnableDebugLogs;
if (enableDebugLogs != null && enableDebugLogs.Value && string.IsNullOrEmpty(__result))
{
string text = __instance?.rolledItem?.id ?? "<null>";
MelonLogger.Msg("ItemRarityColors: GetLocalizedName -> empty (rolledItem.id=" + text + ")");
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(ItemUpgrade), "GetLocalizedDesc")]
private static class ItemUpgrade_GetLocalizedDesc_PostfixPatch
{
[HarmonyPostfix]
private static void Postfix(ItemUpgrade __instance, ref string __result)
{
try
{
MelonPreferences_Entry<bool>? enableDebugLogs = Preferences.EnableDebugLogs;
if (enableDebugLogs != null && enableDebugLogs.Value && string.IsNullOrEmpty(__result))
{
string text = __instance?.rolledItem?.id ?? "<null>";
MelonLogger.Msg("ItemRarityColors: GetLocalizedDesc -> empty (rolledItem.id=" + text + ")");
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(ItemCreator), "CreateItemMesh")]
private static class ItemCreator_CreateItemMesh_PostfixPatch
{
[HarmonyPostfix]
private static void Postfix(ItemCreator __instance)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
try
{
MelonPreferences_Entry<bool>? enableDebugLogs = Preferences.EnableDebugLogs;
if (enableDebugLogs != null && enableDebugLogs.Value)
{
Sprite val = __instance?.sprite;
object obj;
if (!((Object)(object)val != (Object)null))
{
obj = "sprite=<null>";
}
else
{
string name = ((Object)val).name;
Rect rect = val.rect;
object arg = ((Rect)(ref rect)).width;
rect = val.rect;
obj = $"sprite={name} ({arg}x{((Rect)(ref rect)).height})";
}
string text = (string)obj;
MelonLogger.Msg("ItemRarityColors: CreateItemMesh -> " + text);
}
}
catch
{
}
}
}
private static Harmony _harmony;
private const string HarmonyId = "ItemRarityColors.Diagnostics";
private static bool _applied;
public static void Apply()
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Expected O, but got Unknown
if (_applied)
{
return;
}
try
{
MelonPreferences_Entry<bool>? enableDebugLogs = Preferences.EnableDebugLogs;
if (enableDebugLogs != null && enableDebugLogs.Value)
{
if (_harmony == null)
{
_harmony = new Harmony("ItemRarityColors.Diagnostics");
}
_harmony.CreateClassProcessor(typeof(ItemUpgrade_GetLocalizedName_PostfixPatch)).Patch();
_harmony.CreateClassProcessor(typeof(ItemUpgrade_GetLocalizedDesc_PostfixPatch)).Patch();
_harmony.CreateClassProcessor(typeof(ItemCreator_CreateItemMesh_PostfixPatch)).Patch();
_applied = true;
MelonLogger.Msg("ItemRarityColors: Diagnostics patches applied (debug enabled).");
}
}
catch (Exception ex)
{
MelonLogger.Warning("ItemRarityColors: Failed to apply diagnostics patches: " + ex.Message);
}
}
}
internal static class RarityTintPatches
{
[HarmonyPatch(typeof(ItemCreator), "UpdateItemMesh")]
private static class ItemCreator_UpdateItemMesh_PostfixPatch
{
[HarmonyPostfix]
private static void Postfix(ItemCreator __instance)
{
try
{
ItemUpgrade componentInParent = ((Component)__instance).GetComponentInParent<ItemUpgrade>();
if ((Object)(object)componentInParent == (Object)null || componentInParent.rolledItem == null)
{
MelonPreferences_Entry<bool>? enableDebugLogs = Preferences.EnableDebugLogs;
if (enableDebugLogs != null && enableDebugLogs.Value)
{
MelonLogger.Msg("ItemRarityColors: Skip tint - upgrade or rolledItem null (creator=" + ((__instance != null) ? ((Object)__instance).name : null) + ")");
}
return;
}
int tier = componentInParent.rolledItem.tier;
MelonPreferences_Entry<bool>? enableDebugLogs2 = Preferences.EnableDebugLogs;
if (enableDebugLogs2 != null && enableDebugLogs2.Value)
{
Texture2D texture = __instance._texture;
string arg = (((Object)(object)texture != (Object)null) ? $"tex={((Texture)texture).width}x{((Texture)texture).height}" : "tex=null");
MelonLogger.Msg($"ItemRarityColors: UpdateItemMesh postfix (creator={((Object)__instance).name}, tier={tier}, {arg})");
}
ApplyEdgeOnlyTint(__instance, tier);
}
catch (Exception arg2)
{
MelonLogger.Warning($"ItemRarityColors: ItemCreator.UpdateItemMesh postfix failed: {arg2}");
}
}
}
[HarmonyPatch(typeof(ItemUpgrade), "GenerateItem")]
private static class ItemUpgrade_GenerateItem_PostfixPatch
{
[HarmonyPostfix]
private static void Postfix(ItemUpgrade __instance)
{
try
{
ItemCreator val = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponentInChildren<ItemCreator>() : null);
MelonPreferences_Entry<bool>? enableDebugLogs = Preferences.EnableDebugLogs;
if (enableDebugLogs != null && enableDebugLogs.Value)
{
string text = __instance?.rolledItem?.id ?? "<null>";
string text2 = __instance?.rolledItem?.name ?? "<null>";
MelonLogger.Msg("ItemRarityColors: GenerateItem postfix (rolledItem.id=" + text + ", name=" + text2 + ")");
}
if ((Object)(object)val != (Object)null && __instance.rolledItem != null)
{
ApplyEdgeOnlyTint(val, __instance.rolledItem.tier);
}
}
catch (Exception arg)
{
MelonLogger.Warning($"ItemRarityColors: ItemUpgrade.GenerateItem postfix failed: {arg}");
}
}
}
private static Harmony _harmony;
private static bool _applied;
private const string HarmonyId = "ItemRarityColors.RarityTint";
public static bool IsApplied => _applied;
public static void Apply()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
if (_applied)
{
return;
}
try
{
if (_harmony == null)
{
_harmony = new Harmony("ItemRarityColors.RarityTint");
}
List<MethodInfo> list = _harmony.CreateClassProcessor(typeof(ItemCreator_UpdateItemMesh_PostfixPatch)).Patch();
List<MethodInfo> list2 = _harmony.CreateClassProcessor(typeof(ItemUpgrade_GenerateItem_PostfixPatch)).Patch();
_applied = true;
Log.Debug($"ItemRarityColors: Rarity edge-tint patches applied. (ItemCreator.UpdateItemMesh: {list?.Count ?? 0} methods, ItemUpgrade.GenerateItem: {list2?.Count ?? 0} methods)");
}
catch (Exception arg)
{
MelonLogger.Error($"ItemRarityColors: Failed to apply RarityTintPatches: {arg}");
}
}
public static void Remove()
{
if (!_applied)
{
return;
}
try
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchAll("ItemRarityColors.RarityTint");
}
_applied = false;
Log.Debug("ItemRarityColors: Rarity edge-tint patches removed.");
}
catch (Exception ex)
{
MelonLogger.Warning("ItemRarityColors: Failed to remove RarityTintPatches: " + ex.Message);
}
}
private static void ApplyEdgeOnlyTint(ItemCreator itemCreator, int tier)
{
//IL_032b: Unknown result type (might be due to invalid IL or missing references)
//IL_0330: Unknown result type (might be due to invalid IL or missing references)
//IL_0333: Unknown result type (might be due to invalid IL or missing references)
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
//IL_0339: Unknown result type (might be due to invalid IL or missing references)
//IL_0343: Expected O, but got Unknown
//IL_034a: Unknown result type (might be due to invalid IL or missing references)
//IL_0359: Unknown result type (might be due to invalid IL or missing references)
//IL_0368: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_0392: Unknown result type (might be due to invalid IL or missing references)
//IL_039f: Unknown result type (might be due to invalid IL or missing references)
//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
//IL_056a: Unknown result type (might be due to invalid IL or missing references)
//IL_056f: Unknown result type (might be due to invalid IL or missing references)
//IL_0573: Unknown result type (might be due to invalid IL or missing references)
//IL_0581: Unknown result type (might be due to invalid IL or missing references)
//IL_0700: Unknown result type (might be due to invalid IL or missing references)
//IL_0705: Unknown result type (might be due to invalid IL or missing references)
//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
//IL_0722: Unknown result type (might be due to invalid IL or missing references)
//IL_0717: Unknown result type (might be due to invalid IL or missing references)
//IL_05ed: Unknown result type (might be due to invalid IL or missing references)
//IL_05e2: Unknown result type (might be due to invalid IL or missing references)
//IL_0729: Expected O, but got Unknown
//IL_072b: Unknown result type (might be due to invalid IL or missing references)
//IL_073a: Unknown result type (might be due to invalid IL or missing references)
//IL_0749: Unknown result type (might be due to invalid IL or missing references)
//IL_0758: Unknown result type (might be due to invalid IL or missing references)
//IL_05f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0775: Unknown result type (might be due to invalid IL or missing references)
//IL_0782: Unknown result type (might be due to invalid IL or missing references)
//IL_078f: Unknown result type (might be due to invalid IL or missing references)
//IL_079c: Unknown result type (might be due to invalid IL or missing references)
//IL_07bc: Unknown result type (might be due to invalid IL or missing references)
//IL_060a: Unknown result type (might be due to invalid IL or missing references)
//IL_05ff: Unknown result type (might be due to invalid IL or missing references)
//IL_060f: Unknown result type (might be due to invalid IL or missing references)
//IL_0611: Unknown result type (might be due to invalid IL or missing references)
//IL_061d: Unknown result type (might be due to invalid IL or missing references)
//IL_062b: Unknown result type (might be due to invalid IL or missing references)
//IL_0632: Unknown result type (might be due to invalid IL or missing references)
//IL_0666: Unknown result type (might be due to invalid IL or missing references)
//IL_0670: Unknown result type (might be due to invalid IL or missing references)
//IL_067a: Unknown result type (might be due to invalid IL or missing references)
//IL_07f6: Unknown result type (might be due to invalid IL or missing references)
//IL_07fb: Unknown result type (might be due to invalid IL or missing references)
//IL_07fc: Unknown result type (might be due to invalid IL or missing references)
try
{
MeshRenderer val = (((Object)(object)itemCreator.overrideMeshFilter != (Object)null) ? ((Component)itemCreator.overrideMeshFilter).GetComponent<MeshRenderer>() : ((Component)itemCreator).GetComponent<MeshRenderer>());
if ((Object)(object)val == (Object)null)
{
MelonPreferences_Entry<bool>? enableDebugLogs = Preferences.EnableDebugLogs;
if (enableDebugLogs != null && enableDebugLogs.Value)
{
MelonLogger.Msg("ItemRarityColors: No MeshRenderer found; abort tint.");
}
return;
}
Material material = ((Renderer)val).material;
if ((Object)(object)material == (Object)null)
{
MelonPreferences_Entry<bool>? enableDebugLogs2 = Preferences.EnableDebugLogs;
if (enableDebugLogs2 != null && enableDebugLogs2.Value)
{
MelonLogger.Msg("ItemRarityColors: Face material null; abort tint.");
}
return;
}
if ((Object)(object)itemCreator._texture == (Object)null)
{
MelonPreferences_Entry<bool>? enableDebugLogs3 = Preferences.EnableDebugLogs;
if (enableDebugLogs3 != null && enableDebugLogs3.Value)
{
MelonLogger.Msg("ItemRarityColors: _texture is null; abort tint.");
}
return;
}
Color32[] pixels = itemCreator._texture.GetPixels32();
int num = 0;
for (int i = 0; i < pixels.Length; i++)
{
if (pixels[i].a > 0)
{
num++;
}
}
if (num <= 0)
{
MelonPreferences_Entry<bool>? enableDebugLogs4 = Preferences.EnableDebugLogs;
if (enableDebugLogs4 != null && enableDebugLogs4.Value)
{
MelonLogger.Msg("ItemRarityColors: Texture has no filled pixels; skip tint.");
}
return;
}
MeshFilter val2 = (((Object)(object)itemCreator.overrideMeshFilter != (Object)null) ? itemCreator.overrideMeshFilter : ((Component)itemCreator).GetComponent<MeshFilter>());
if ((Object)(object)val2 == (Object)null || (Object)(object)val2.mesh == (Object)null)
{
return;
}
Mesh mesh = val2.mesh;
int subMeshCount = mesh.subMeshCount;
int[] triangles = mesh.triangles;
if (triangles == null || triangles.Length == 0)
{
return;
}
if (subMeshCount >= 2)
{
Material[] materials = ((Renderer)val).materials;
if (((materials != null) ? materials.Length : 0) >= 2)
{
MelonPreferences_Entry<bool>? enableDebugLogs5 = Preferences.EnableDebugLogs;
if (enableDebugLogs5 != null && enableDebugLogs5.Value)
{
MelonLogger.Msg("ItemRarityColors: Mesh already split into submeshes; skipping reapply.");
}
return;
}
}
int num2 = num * 4;
int num3 = num2 * 3;
if (num3 > triangles.Length)
{
num3 = triangles.Length;
}
if (num3 <= 0)
{
MelonPreferences_Entry<bool>? enableDebugLogs6 = Preferences.EnableDebugLogs;
if (enableDebugLogs6 != null && enableDebugLogs6.Value)
{
MelonLogger.Msg("ItemRarityColors: Computed faceIdxCount=0; skip tint.");
}
return;
}
MelonPreferences_Entry<bool>? enableDebugLogs7 = Preferences.EnableDebugLogs;
if (enableDebugLogs7 != null && enableDebugLogs7.Value)
{
MelonLogger.Msg($"ItemRarityColors: Mesh split prep (verts={mesh.vertexCount}, tris={triangles.Length / 3}, filled={num}, faceIdx={num3}, tier={tier})");
}
int[] array = new int[num3];
Array.Copy(triangles, 0, array, 0, num3);
int num4 = triangles.Length - num3;
int[] array2 = new int[Math.Max(num4, 0)];
if (num4 > 0)
{
Array.Copy(triangles, num3, array2, 0, num4);
}
mesh.subMeshCount = 2;
mesh.SetTriangles(array, 0);
mesh.SetTriangles(array2, 1);
Color colorForTier = RarityColors.GetColorForTier(tier);
Material val3 = new Material(material)
{
color = colorForTier
};
TrySetColor(val3, "_BaseColor", colorForTier);
TrySetColor(val3, "_Color", colorForTier);
TrySetColor(val3, "_Tint", colorForTier);
if (val3.HasProperty("_EmissionColor"))
{
Color val4 = default(Color);
((Color)(ref val4))..ctor(colorForTier.r * 0.5f, colorForTier.g * 0.5f, colorForTier.b * 0.5f, colorForTier.a);
val3.EnableKeyword("_EMISSION");
val3.SetColor("_EmissionColor", val4);
}
((Renderer)val).materials = (Material[])(object)new Material[2] { material, val3 };
MelonPreferences_Entry<bool>? enableDebugLogs8 = Preferences.EnableDebugLogs;
if (enableDebugLogs8 != null && enableDebugLogs8.Value)
{
Material[] materials2 = ((Renderer)val).materials;
object obj;
if (materials2.Length == 0)
{
obj = "n/a";
}
else
{
Material obj2 = materials2[0];
if (obj2 == null)
{
obj = null;
}
else
{
Shader shader = obj2.shader;
obj = ((shader != null) ? ((Object)shader).name : null);
}
if (obj == null)
{
obj = "<null>";
}
}
string text = (string)obj;
object obj3;
if (materials2.Length <= 1)
{
obj3 = "n/a";
}
else
{
Material obj4 = materials2[1];
if (obj4 == null)
{
obj3 = null;
}
else
{
Shader shader2 = obj4.shader;
obj3 = ((shader2 != null) ? ((Object)shader2).name : null);
}
if (obj3 == null)
{
obj3 = "<null>";
}
}
string text2 = (string)obj3;
int num5 = array.Length / 3;
int num6 = array2.Length / 3;
MelonLogger.Msg($"ItemRarityColors: Mesh split done (submeshes=2, faceTris={num5}, edgeTris={num6}, m0={text}, m1={text2})");
}
try
{
List<Vector3> list = new List<Vector3>(mesh.vertices);
List<Vector3> list2 = new List<Vector3>();
mesh.GetNormals(list2);
if (list2.Count != list.Count)
{
mesh.RecalculateNormals();
list2.Clear();
mesh.GetNormals(list2);
}
List<Vector2> list3 = new List<Vector2>();
mesh.GetUVs(0, list3);
if (list3.Count != list.Count)
{
list3 = new List<Vector2>(mesh.uv);
}
int[] array3 = array;
if (array3 == null || array3.Length == 0)
{
return;
}
Bounds bounds = mesh.bounds;
float y = ((Bounds)(ref bounds)).center.y;
float z = ((Bounds)(ref bounds)).center.z;
Dictionary<int, int> dictionary = new Dictionary<int, int>(1024);
int[] array4 = new int[array3.Length];
Vector3 item2 = default(Vector3);
for (int j = 0; j < array3.Length; j++)
{
int num7 = array3[j];
if (!dictionary.TryGetValue(num7, out var value))
{
Vector3 val5 = list[num7];
Vector3 val6 = ((list2.Count > num7) ? list2[num7] : Vector3.right);
Vector2 item = ((list3.Count > num7) ? list3[num7] : Vector2.zero);
float num8 = val5.y - y;
float num9 = val5.z - z;
((Vector3)(ref item2))..ctor(val5.x - val6.x * 0.0005f, y + num8 * 1.03f, z + num9 * 1.03f);
value = list.Count;
list.Add(item2);
list2.Add(val6);
list3.Add(item);
dictionary[num7] = value;
}
array4[j] = value;
}
mesh.SetVertices(list);
mesh.SetNormals(list2);
mesh.SetUVs(0, list3);
mesh.subMeshCount = 3;
mesh.SetTriangles(array, 0);
mesh.SetTriangles(array2, 1);
mesh.SetTriangles(array4, 2);
mesh.RecalculateBounds();
Color colorForTier2 = RarityColors.GetColorForTier(tier);
Material[] materials3 = ((Renderer)val).materials;
Material val7 = ((materials3.Length >= 2) ? new Material(materials3[1]) : new Material(material));
val7.color = colorForTier2;
TrySetColor(val7, "_BaseColor", colorForTier2);
TrySetColor(val7, "_Color", colorForTier2);
TrySetColor(val7, "_Tint", colorForTier2);
if (val7.HasProperty("_EmissionColor"))
{
Color val8 = default(Color);
((Color)(ref val8))..ctor(colorForTier2.r * 0.5f, colorForTier2.g * 0.5f, colorForTier2.b * 0.5f, colorForTier2.a);
val7.EnableKeyword("_EMISSION");
val7.SetColor("_EmissionColor", val8);
}
if (materials3.Length < 3)
{
((Renderer)val).materials = (Material[])(object)new Material[3]
{
(materials3.Length != 0) ? materials3[0] : material,
(Material)((materials3.Length > 1) ? ((object)materials3[1]) : ((object)new Material(material)
{
color = colorForTier2
})),
val7
};
}
else
{
materials3[2] = val7;
((Renderer)val).materials = materials3;
}
MelonPreferences_Entry<bool>? enableDebugLogs9 = Preferences.EnableDebugLogs;
if (enableDebugLogs9 != null && enableDebugLogs9.Value)
{
MelonLogger.Msg($"ItemRarityColors: Added Y/Z rim overlay (overlayTris={array4.Length / 3}).");
}
}
catch (Exception ex)
{
MelonLogger.Warning("ItemRarityColors: Failed adding rim overlay: " + ex.Message);
}
}
catch (Exception arg)
{
MelonLogger.Warning($"ItemRarityColors: Failed to apply edge-only tint: {arg}");
}
}
private static void TrySetColor(Material m, string name, Color value)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
try
{
if (m.HasProperty(name))
{
m.SetColor(name, value);
}
}
catch
{
}
}
}
}
namespace ItemRarityColors.Integration
{
internal static class ADVRIntegration
{
internal static class IntegrationPatches
{
[HarmonyPatch(typeof(ModLoader), "Initialize")]
internal static class ModLoader_Initialize_PostfixPatch
{
[HarmonyPostfix]
private static void Postfix(ModLoader __instance)
{
AppendPseudoMod(__instance);
}
}
[HarmonyPatch(typeof(SettingsMod), "OnApplyClick")]
internal static class SettingsMod_OnApplyClick_PostfixPatch
{
[HarmonyPostfix]
private static void Postfix()
{
EvaluateAndApply();
}
}
[HarmonyPatch(typeof(GameHandler), "Awake")]
internal static class GameHandler_Awake_PostfixPatch
{
[HarmonyPostfix]
private static void Postfix()
{
EvaluateAndApply();
}
}
}
private const string OurModId = "ItemRarityColors";
public static void EvaluateAndApply()
{
try
{
bool managerEnabledFlag = GetManagerEnabledFlag("ItemRarityColors");
MelonLogger.Msg($"ItemRarityColors: EvaluateAndApply -> enabled={managerEnabledFlag}");
if (managerEnabledFlag && !RarityTintPatches.IsApplied)
{
RarityTintPatches.Apply();
}
else if (!managerEnabledFlag && RarityTintPatches.IsApplied)
{
RarityTintPatches.Remove();
}
}
catch (Exception ex)
{
MelonLogger.Warning("ItemRarityColors: Enablement evaluation failed: " + ex.Message);
}
}
private static bool GetManagerEnabledFlag(string modId)
{
try
{
if ((Object)(object)GameHandler.INSTANCE == (Object)null)
{
return false;
}
return ES3.Load<bool>("mod_enabled_" + modId, false, GameHandler.INSTANCE.e3Settings);
}
catch
{
return false;
}
}
private static string GetGameVersionOrFallback()
{
try
{
return GameHandler.GetGameVersionString();
}
catch
{
return "unknown";
}
}
private static void AppendPseudoMod(ModLoader __instance)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: 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)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Expected O, but got Unknown
try
{
if (!((Object)(object)__instance == (Object)null))
{
Mod[] array = __instance.loadedMods ?? Array.Empty<Mod>();
if (!array.Any((Mod m) => string.Equals(m.modId, "ItemRarityColors", StringComparison.OrdinalIgnoreCase)))
{
Mod val = new Mod
{
modId = "ItemRarityColors",
modName = "Item Rarity Colors",
modDesc = "Tint item edges by rarity (MelonLoader mod).",
modVersion = GetGameVersionOrFallback()
};
Mod[] array2 = (Mod[])(object)new Mod[array.Length + 1];
Array.Copy(array, array2, array.Length);
array2[array.Length] = val;
__instance.loadedMods = array2;
MelonLogger.Msg("ItemRarityColors: Added pseudo-mod entry to in-game mod list.");
}
}
}
catch (Exception ex)
{
MelonLogger.Warning("ItemRarityColors: Failed to append ItemRarityColors to mod list: " + ex.Message);
}
}
}
}
namespace ItemRarityColors.Helpers
{
internal static class Log
{
internal static void Debug(string message)
{
MelonPreferences_Entry<bool>? enableDebugLogs = Preferences.EnableDebugLogs;
if (enableDebugLogs == null || enableDebugLogs.Value)
{
MelonLogger.Msg(message);
}
}
}
internal static class Preferences
{
internal static MelonPreferences_Category? Category { get; private set; }
internal static MelonPreferences_Entry<bool>? EnableDebugLogs { get; private set; }
internal static void Init()
{
if (Category == null)
{
Category = MelonPreferences.CreateCategory("ItemRarityColors", "Item Rarity Colors");
}
if (EnableDebugLogs == null)
{
EnableDebugLogs = Category.CreateEntry<bool>("EnableDebugLogs", true, "Enable Debug Logs", (string)null, false, false, (ValueValidator)null, (string)null);
}
}
}
internal static class RarityColors
{
public static Color GetColorForTier(int tier)
{
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
return (Color)(tier switch
{
3 => new Color(1f, 0.25f, 0.25f, 1f),
2 => new Color(0.3f, 0.9f, 0.3f, 1f),
_ => new Color(1f, 1f, 1f, 1f),
});
}
}
}