Decompiled source of RadianceShovel v1.0.0

BepInEx/plugins/RadianceShovel/RadianceShovel.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("RadianceShovel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RadianceShovel")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3dd80a6a-2d66-490e-9553-122a4218e403")]
[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 RadianceShovel;

[BepInPlugin("fenixlegend.RadianceShovel", "Radiance Shovel", "1.0.0")]
public class RadianceShovel : BaseUnityPlugin
{
	public static ManualLogSource logger;

	public static AssetBundle bundle;

	public static GameObject radiancePrefab;

	public static bool isLoaded;

	public static RadianceShovelConfig config;

	private void Awake()
	{
		logger = ((BaseUnityPlugin)this).Logger;
		config = new RadianceShovelConfig(((BaseUnityPlugin)this).Config);
		LoadBundle();
		Harmony.CreateAndPatchAll(typeof(ShovelPatch), (string)null);
		logger.LogInfo((object)"bad mod was loaded");
	}

	private void LoadBundle()
	{
		try
		{
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "radiance");
			if (!File.Exists(text))
			{
				logger.LogError((object)"ab not found syka");
				return;
			}
			bundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)bundle == (Object)null)
			{
				logger.LogError((object)"ab fail");
				return;
			}
			radiancePrefab = bundle.LoadAsset<GameObject>("radianceShovel");
			if ((Object)(object)radiancePrefab == (Object)null)
			{
				logger.LogError((object)"eblan a gde ab");
				return;
			}
			isLoaded = true;
			logger.LogInfo((object)"all ok bro");
		}
		catch (Exception ex)
		{
			logger.LogError((object)("error ab " + ex.Message));
		}
	}
}
public class RadianceShovelConfig
{
	public ConfigEntry<bool> UseOriginalPosition { get; private set; }

	public ConfigEntry<float> ScaleX { get; private set; }

	public ConfigEntry<float> ScaleY { get; private set; }

	public ConfigEntry<float> ScaleZ { get; private set; }

	public ConfigEntry<float> PositionX { get; private set; }

	public ConfigEntry<float> PositionY { get; private set; }

	public ConfigEntry<float> PositionZ { get; private set; }

	public ConfigEntry<float> RotationX { get; private set; }

	public ConfigEntry<float> RotationY { get; private set; }

	public ConfigEntry<float> RotationZ { get; private set; }

	public ConfigEntry<float> GlowIntensity { get; private set; }

	public ConfigEntry<float> GlowRange { get; private set; }

	public ConfigEntry<string> GlowColor { get; private set; }

	public ConfigEntry<bool> ApplyHandRotation { get; private set; }

	public ConfigEntry<float> HandRotationX { get; private set; }

	public ConfigEntry<float> HandRotationY { get; private set; }

	public ConfigEntry<float> HandRotationZ { get; private set; }

	public event Action OnConfigChanged;

	public RadianceShovelConfig(ConfigFile config)
	{
		GlowIntensity = config.Bind<float>("Glow", "Intensity", 30f, "Glow light intensity");
		GlowRange = config.Bind<float>("Glow", "Range", 8f, "Glow light range");
		GlowColor = config.Bind<string>("Glow", "Color", "#FFD700", "Glow color (HEX format)");
		ApplyHandRotation = config.Bind<bool>("Hand", "ApplyRotation", true, "Enable hand rotation");
		HandRotationX = config.Bind<float>("Hand", "RotationX", 0f, "Hand rotation X (degrees)");
		HandRotationY = config.Bind<float>("Hand", "RotationY", 0f, "Hand rotation Y (degrees)");
		HandRotationZ = config.Bind<float>("Hand", "RotationZ", 0f, "Hand rotation Z (degrees)");
		UseOriginalPosition = config.Bind<bool>("Mesh", "UseOriginalPosition", false, "Copy position/rotation from original shovel");
		ScaleX = config.Bind<float>("Mesh", "ScaleX", 100f, "Scale X");
		ScaleY = config.Bind<float>("Mesh", "ScaleY", 100f, "Scale Y");
		ScaleZ = config.Bind<float>("Mesh", "ScaleZ", 100f, "Scale Z");
		PositionX = config.Bind<float>("Mesh", "PositionX", -0.2f, "Position X");
		PositionY = config.Bind<float>("Mesh", "PositionY", -0.1f, "Position Y");
		PositionZ = config.Bind<float>("Mesh", "PositionZ", -1.05f, "Position Z");
		RotationX = config.Bind<float>("Mesh", "RotationX", 0f, "Rotation X");
		RotationY = config.Bind<float>("Mesh", "RotationY", 1f, "Rotation Y");
		RotationZ = config.Bind<float>("Mesh", "RotationZ", 22f, "Rotation Z");
		UseOriginalPosition.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		ScaleX.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		ScaleY.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		ScaleZ.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		PositionX.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		PositionY.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		PositionZ.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		RotationX.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		RotationY.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		RotationZ.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		GlowIntensity.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		GlowRange.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		GlowColor.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		ApplyHandRotation.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		HandRotationX.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		HandRotationY.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
		HandRotationZ.SettingChanged += delegate
		{
			this.OnConfigChanged?.Invoke();
		};
	}
}
[HarmonyPatch]
public class ShovelPatch
{
	private static List<Transform> modifiedHands = new List<Transform>();

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Shovel), "Start")]
	private static void ReplaceShovelMesh(Shovel __instance)
	{
		if (!RadianceShovel.isLoaded)
		{
			return;
		}
		try
		{
			ReplaceMeshInChildren(((Component)__instance).gameObject);
		}
		catch (Exception ex)
		{
			RadianceShovel.logger.LogError((object)("Error: " + ex.Message));
		}
	}

	private static void ReplaceMeshInChildren(GameObject obj)
	{
		MeshFilter component = obj.GetComponent<MeshFilter>();
		MeshRenderer component2 = obj.GetComponent<MeshRenderer>();
		if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
		{
			ReplaceMesh(component, component2);
			return;
		}
		for (int i = 0; i < obj.transform.childCount; i++)
		{
			ReplaceMeshInChildren(((Component)obj.transform.GetChild(i)).gameObject);
		}
	}

	private static void ReplaceMesh(MeshFilter filter, MeshRenderer renderer)
	{
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e0: Expected O, but got Unknown
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0415: Unknown result type (might be due to invalid IL or missing references)
		//IL_041f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Expected O, but got Unknown
		//IL_036e: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Expected O, but got Unknown
		//IL_0306: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)RadianceShovel.radiancePrefab == (Object)null)
		{
			return;
		}
		MeshFilter component = RadianceShovel.radiancePrefab.GetComponent<MeshFilter>();
		MeshRenderer component2 = RadianceShovel.radiancePrefab.GetComponent<MeshRenderer>();
		if ((Object)(object)component == (Object)null || (Object)(object)component.mesh == (Object)null)
		{
			RadianceShovel.logger.LogError((object)"Prefab has no mesh!");
			return;
		}
		string obj = (((Object)(object)((Component)filter).transform.parent != (Object)null) ? ((Object)((Component)filter).transform.parent).name : "");
		string name = ((Object)((Component)filter).gameObject).name;
		if (!obj.ToLower().Contains("shovel") && !name.ToLower().Contains("shovel"))
		{
			return;
		}
		RadianceShovelConfig config = RadianceShovel.config;
		filter.mesh = component.mesh;
		if (config.UseOriginalPosition.Value)
		{
			Vector3 localPosition = ((Component)filter).transform.localPosition;
			Quaternion localRotation = ((Component)filter).transform.localRotation;
			((Component)filter).gameObject.transform.localPosition = localPosition;
			((Component)filter).gameObject.transform.localRotation = localRotation;
			((Component)filter).gameObject.transform.localScale = new Vector3(config.ScaleX.Value, config.ScaleY.Value, config.ScaleZ.Value);
		}
		else
		{
			((Component)filter).gameObject.transform.localPosition = new Vector3(config.PositionX.Value, config.PositionY.Value, config.PositionZ.Value);
			((Component)filter).gameObject.transform.localRotation = Quaternion.Euler(config.RotationX.Value, config.RotationY.Value, config.RotationZ.Value);
			((Component)filter).gameObject.transform.localScale = new Vector3(config.ScaleX.Value, config.ScaleY.Value, config.ScaleZ.Value);
		}
		Transform val = FindHand(((Component)filter).transform);
		if ((Object)(object)val != (Object)null && ((Object)val).name == "hand.R" && !modifiedHands.Contains(val) && config.ApplyHandRotation.Value)
		{
			val.localRotation = Quaternion.Euler(config.HandRotationX.Value, config.HandRotationY.Value, config.HandRotationZ.Value);
			modifiedHands.Add(val);
		}
		if ((Object)(object)component2 != (Object)null && ((Renderer)component2).materials != null)
		{
			Material[] array = (Material[])(object)new Material[((Renderer)component2).materials.Length];
			for (int i = 0; i < ((Renderer)component2).materials.Length; i++)
			{
				if ((Object)(object)((Renderer)component2).materials[i] != (Object)null)
				{
					array[i] = new Material(((Renderer)component2).materials[i]);
					if ((Object)(object)array[i].shader == (Object)null || ((Object)array[i].shader).name == "Hidden/InternalErrorShader")
					{
						array[i].shader = Shader.Find("Standard");
						array[i].color = GetColorFromHex(config.GlowColor.Value);
						array[i].EnableKeyword("_EMISSION");
						array[i].SetColor("_EmissionColor", GetColorFromHex(config.GlowColor.Value) * 5f);
					}
				}
				else
				{
					array[i] = new Material(Shader.Find("Standard"));
					array[i].color = GetColorFromHex(config.GlowColor.Value);
					array[i].EnableKeyword("_EMISSION");
					array[i].SetColor("_EmissionColor", GetColorFromHex(config.GlowColor.Value) * 5f);
				}
			}
			((Renderer)renderer).materials = array;
		}
		else
		{
			Material val2 = new Material(Shader.Find("Standard"));
			val2.color = GetColorFromHex(config.GlowColor.Value);
			val2.EnableKeyword("_EMISSION");
			val2.SetColor("_EmissionColor", GetColorFromHex(config.GlowColor.Value) * 5f);
			((Renderer)renderer).material = val2;
		}
		((Renderer)renderer).enabled = true;
		AddGlowEffect(((Component)filter).gameObject);
	}

	private static Transform FindHand(Transform start)
	{
		Transform val = start;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name == "hand.R")
			{
				return val;
			}
			val = val.parent;
		}
		return null;
	}

	private static void AddGlowEffect(GameObject obj)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)obj.GetComponent<Light>() == (Object)null)
		{
			RadianceShovelConfig config = RadianceShovel.config;
			Light obj2 = obj.AddComponent<Light>();
			obj2.type = (LightType)2;
			obj2.color = GetColorFromHex(config.GlowColor.Value);
			obj2.intensity = config.GlowIntensity.Value;
			obj2.range = config.GlowRange.Value;
		}
	}

	private static Color GetColorFromHex(string hex)
	{
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		if (hex.StartsWith("#"))
		{
			hex = hex.Substring(1);
		}
		if (hex.Length == 6)
		{
			float num = (float)int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber) / 255f;
			float num2 = (float)int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber) / 255f;
			float num3 = (float)int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber) / 255f;
			return new Color(num, num2, num3);
		}
		return new Color(1f, 0.85f, 0.4f);
	}
}