using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Mod for MineMogul game")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Magnet Tool Color")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d8d4abed-2e41-4c36-9b78-e56f3a641e8a")]
[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 MagnetToolColor;
internal static class ModInfo
{
public const string PLUGIN_GUID = "com.maxgerman.magnettoolcolor";
public const string PLUGIN_NAME = "Magnet Tool Color";
public const string PLUGIN_VERSION = "1.0.0";
public const string ASSEMBLY_VERSION = "1.0.0";
public const string FILE_VERSION = "1.0.0";
public const string INFORMATIONAL_VERSION = "1.0.0";
public const string HARMONY_ID = "com.maxgerman.magnettoolcolor";
public const string LOG_PREFIX = "[Magnet Tool Color] ";
public const string DISPLAY_NAME_SHORT = "MagnetToolColor";
public const string DISPLAY_NAME_LONG = "Magnet Tool Color";
internal const string Guid = "com.maxgerman.magnettoolcolor";
internal const string Name = "Magnet Tool Color";
internal const string Version = "1.0.0";
}
internal static class ModLog
{
private static readonly ManualLogSource _bepInExLogger = Logger.CreateLogSource("UI_Tweaks");
internal static void Log(string message, string tag = "")
{
_bepInExLogger.LogMessage((object)FormatMessage(message, tag));
}
internal static void Warn(string message, string tag = "")
{
_bepInExLogger.LogWarning((object)FormatMessage(message, tag));
}
internal static void Error(string message, string tag = "")
{
_bepInExLogger.LogError((object)FormatMessage(message, tag));
}
private static string FormatMessage(string message, string tag)
{
if (string.IsNullOrEmpty(tag))
{
return message;
}
return "[" + tag + "] " + message;
}
}
[BepInPlugin("com.maxgerman.magnettoolcolor", "Magnet Tool Color", "1.0.0")]
public class MagnetToolColor : BaseUnityPlugin
{
private ConfigEntry<string> colorConfig;
private Type toolMagnetType;
private TMP_Text modeLabel;
private TMP_Text currentModeText;
private Image image;
private Color targetColor;
private float nextSearchTime;
private bool uiFound;
private void Awake()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
colorConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Magnet Tool", "Color", "#2dcd2d", "Color applied to all Magnet Tool UI elements.");
targetColor = ParseColor(colorConfig.Value);
colorConfig.SettingChanged += OnColorChanged;
toolMagnetType = FindType("ToolMagnet");
if (toolMagnetType == null)
{
ModLog.Error("ToolMagnet type was not found.");
return;
}
ModLog.Log("Magnet Tool Color loaded.");
ModLog.Log("Configured color: " + ColorToHex(targetColor));
}
private void Update()
{
if (Time.unscaledTime >= nextSearchTime)
{
nextSearchTime = Time.unscaledTime + 0.5f;
FindMagnetUI();
}
ApplyTextColor(modeLabel);
ApplyTextColor(currentModeText);
ApplyImageColor(image);
}
private void OnColorChanged(object sender, EventArgs e)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
targetColor = ParseColor(colorConfig.Value);
ModLog.Log("Color changed to " + ColorToHex(targetColor));
ApplyTextColor(modeLabel);
ApplyTextColor(currentModeText);
ApplyImageColor(image);
}
private void FindMagnetUI()
{
if (uiFound && (Object)(object)modeLabel != (Object)null && (Object)(object)currentModeText != (Object)null)
{
return;
}
Component[] array = Object.FindObjectsByType<Component>((FindObjectsInactive)1, (FindObjectsSortMode)0);
foreach (Component val in array)
{
if ((Object)(object)val == (Object)null || toolMagnetType == null || ((object)val).GetType() != toolMagnetType)
{
continue;
}
GameObject gameObject = val.gameObject;
if ((Object)(object)gameObject == (Object)null)
{
continue;
}
Transform val2 = gameObject.transform.Find("ViewModel");
if ((Object)(object)val2 == (Object)null)
{
continue;
}
TMP_Text[] componentsInChildren = ((Component)val2).GetComponentsInChildren<TMP_Text>(true);
modeLabel = null;
currentModeText = null;
TMP_Text[] array2 = componentsInChildren;
foreach (TMP_Text val3 in array2)
{
if (!((Object)(object)val3 == (Object)null))
{
if (((Object)((Component)val3).gameObject).name == "ModeLabel")
{
modeLabel = val3;
}
if (((Object)((Component)val3).gameObject).name == "CurrentModeText")
{
currentModeText = val3;
}
}
}
Image[] componentsInChildren2 = ((Component)val2).GetComponentsInChildren<Image>(true);
image = null;
Image[] array3 = componentsInChildren2;
foreach (Image val4 in array3)
{
if (!((Object)(object)val4 == (Object)null) && ((Object)((Component)val4).gameObject).name == "Image")
{
image = val4;
}
}
if ((Object)(object)modeLabel != (Object)null && (Object)(object)currentModeText != (Object)null)
{
uiFound = true;
ModLog.Log("Magnet UI found.");
ModLog.Log("ModeLabel: " + ((Object)(object)modeLabel != (Object)null));
ModLog.Log("CurrentModeText: " + ((Object)(object)currentModeText != (Object)null));
ModLog.Log("Image: " + ((Object)(object)image != (Object)null));
ApplyTextColor(modeLabel);
ApplyTextColor(currentModeText);
ApplyImageColor(image);
break;
}
}
}
private void ApplyTextColor(TMP_Text text)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)text == (Object)null)
{
return;
}
((Graphic)text).color = targetColor;
text.enableVertexGradient = false;
TextMeshProUGUI val = (TextMeshProUGUI)(object)((text is TextMeshProUGUI) ? text : null);
if (val != null)
{
((TMP_Text)val).faceColor = Color32.op_Implicit(targetColor);
((TMP_Text)val).outlineColor = Color32.op_Implicit(Color.black);
}
Material fontMaterial = text.fontMaterial;
if (!((Object)(object)fontMaterial == (Object)null))
{
SetMaterialColor(fontMaterial, "_FaceColor", targetColor);
SetMaterialColor(fontMaterial, "_GlowColor", targetColor);
SetMaterialColor(fontMaterial, "_UnderlayColor", Color.clear);
if (fontMaterial.HasProperty("_GlowPower"))
{
fontMaterial.SetFloat("_GlowPower", 0f);
}
if (fontMaterial.HasProperty("_GlowOuter"))
{
fontMaterial.SetFloat("_GlowOuter", 0f);
}
if (fontMaterial.HasProperty("_GlowInner"))
{
fontMaterial.SetFloat("_GlowInner", 0f);
}
((Graphic)text).SetVerticesDirty();
((Graphic)text).SetMaterialDirty();
}
}
private void ApplyImageColor(Image img)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)img == (Object)null))
{
((Graphic)img).color = targetColor;
((Graphic)img).SetVerticesDirty();
((Graphic)img).SetMaterialDirty();
}
}
private void SetMaterialColor(Material material, string property, Color color)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
if (material.HasProperty(property))
{
material.SetColor(property, color);
}
}
private Type FindType(string typeName)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
try
{
Type type = assembly.GetType(typeName, throwOnError: false);
if (type != null)
{
return type;
}
}
catch
{
}
}
return null;
}
private Color ParseColor(string value)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
Color result = default(Color);
if (ColorUtility.TryParseHtmlString(value, ref result))
{
return result;
}
ModLog.Warn("Invalid color '" + value + "'. Using #FF8800.");
return new Color(1f, 0.533f, 0f, 1f);
}
private string ColorToHex(Color color)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
return "#" + ColorUtility.ToHtmlStringRGBA(color);
}
}