Decompiled source of The GoldenPan v1.0.0

goldenPan.dll

Decompiled a month ago
using System;
using System.Collections;
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 GoldenPanMod;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections;
using MelonLoader;
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(GoldenPan), "GoldenPan", "1.0.0", "Wake", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("oldenPan")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("goldenPan")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a1f65a20-123d-4eeb-bd8b-0fed1540911f")]
[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 GoldenPanMod;

public class GoldenPan : MelonMod
{
	private GameObject fryingPan;

	private HashSet<GameObject> goldenizedObjects;

	private Coroutine checkCoroutine;

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg("GoldenPanMod loaded!");
		goldenizedObjects = new HashSet<GameObject>();
		MelonCoroutines.Start(FindAndModifyFryingPan());
	}

	private IEnumerator FindAndModifyFryingPan()
	{
		int retryCount = 0;
		while ((Object)(object)fryingPan == (Object)null && retryCount < 1000)
		{
			fryingPan = GameObject.Find("FryingPan [0]");
			if ((Object)(object)fryingPan != (Object)null)
			{
				MelonLogger.Msg("Frying pan found!");
				MeshCollider meshCollider2 = fryingPan.GetComponent<MeshCollider>();
				if ((Object)(object)meshCollider2 == (Object)null)
				{
					meshCollider2 = fryingPan.AddComponent<MeshCollider>();
					meshCollider2.convex = true;
					MelonLogger.Msg("MeshCollider added to the frying pan.");
				}
				Renderer[] fryPanRenderers = Il2CppArrayBase<Renderer>.op_Implicit(fryingPan.GetComponentsInChildren<Renderer>());
				if (fryPanRenderers.Length != 0)
				{
					ApplyGoldTextureToAll(fryPanRenderers);
				}
				checkCoroutine = (Coroutine)MelonCoroutines.Start(CheckNearbyObjects());
				yield break;
			}
			MelonLogger.Msg("Frying pan not found, retrying...");
			retryCount++;
			yield return (object)new WaitForSeconds(1f);
		}
		if ((Object)(object)fryingPan == (Object)null)
		{
			MelonLogger.Error("Failed to find frying pan after multiple attempts.");
		}
	}

	private IEnumerator CheckNearbyObjects()
	{
		float checkRadius = 0.2f;
		int layerMask = 1 << LayerMask.NameToLayer("Default");
		while (true)
		{
			Collider[] nearbyColliders = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(fryingPan.transform.position, checkRadius, layerMask));
			Collider[] array = nearbyColliders;
			foreach (Collider collider in array)
			{
				GameObject objWithRenderer = FindRendererObject(((Component)collider).gameObject);
				if (!((Object)(object)objWithRenderer == (Object)null) && !goldenizedObjects.Contains(objWithRenderer))
				{
					ApplyGoldTextureRecursively(objWithRenderer);
					goldenizedObjects.Add(objWithRenderer);
					MelonLogger.Msg("Applied gold texture to: " + ((Object)objWithRenderer).name);
				}
			}
			yield return (object)new WaitForSeconds(0.5f);
		}
	}

	private GameObject FindRendererObject(GameObject obj)
	{
		if ((Object)(object)obj == (Object)null)
		{
			MelonLogger.Msg("Object is null, skipping...");
			return null;
		}
		GameObject val = null;
		Transform val2 = obj.transform;
		while ((Object)(object)val2 != (Object)null)
		{
			if ((Object)(object)((Component)val2).GetComponent<Renderer>() != (Object)null)
			{
				val = ((Component)val2).gameObject;
				break;
			}
			val2 = val2.parent;
		}
		if ((Object)(object)val == (Object)null)
		{
			val = FindRendererInChildren(obj);
		}
		if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent<Transform>() != (Object)null)
		{
			return val;
		}
		MelonLogger.Msg("Skipping invalid object " + ((Object)obj).name + ". No valid Transform component found.");
		return null;
	}

	private GameObject FindRendererInChildren(GameObject obj)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		if ((Object)(object)obj == (Object)null)
		{
			MelonLogger.Msg("Object is null in children search, skipping...");
			return null;
		}
		IEnumerator enumerator = obj.transform.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				Transform val = (Transform)enumerator.Current;
				if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).GetComponent<Renderer>() != (Object)null)
				{
					return ((Component)val).gameObject;
				}
				GameObject val2 = FindRendererInChildren(((Component)val).gameObject);
				if ((Object)(object)val2 != (Object)null)
				{
					return val2;
				}
			}
		}
		finally
		{
			if (enumerator is IDisposable disposable)
			{
				disposable.Dispose();
			}
		}
		return null;
	}

	private void ApplyGoldTextureRecursively(GameObject obj)
	{
		if ((Object)(object)obj == (Object)null || (Object)(object)obj.GetComponent<Renderer>() == (Object)null)
		{
			MelonLogger.Msg("Skipping invalid object " + ((Object)obj).name + ". No Renderer component found.");
			return;
		}
		Renderer[] array = Il2CppArrayBase<Renderer>.op_Implicit(obj.GetComponentsInChildren<Renderer>(true));
		if (array.Length != 0)
		{
			ApplyGoldTextureToAll(array);
		}
		IEnumerator enumerator = obj.transform.GetEnumerator();
		while (enumerator.MoveNext())
		{
			Object current = enumerator.Current;
			Transform val = (Transform)(object)((current is Transform) ? current : null);
			if ((Object)(object)val != (Object)null)
			{
				ApplyGoldTextureRecursively(((Component)val).gameObject);
			}
		}
	}

	public void ApplyGoldTextureToAll(Renderer[] renderers)
	{
		Texture2D val = LoadGoldTextureFromFile();
		if ((Object)(object)val != (Object)null)
		{
			foreach (Renderer val2 in renderers)
			{
				if ((Object)(object)val2 == (Object)null || (Object)(object)val2.material == (Object)null)
				{
					continue;
				}
				foreach (Material item in (Il2CppArrayBase<Material>)(object)val2.materials)
				{
					item.mainTexture = (Texture)(object)val;
				}
			}
		}
		else
		{
			MelonLogger.Error("Failed to load or apply gold texture.");
		}
	}

	public Texture2D LoadGoldTextureFromFile()
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		string directoryName = Path.GetDirectoryName(Application.dataPath);
		string text = Path.Combine(directoryName, "Textures", "GoldTexture.jpg");
		if (!File.Exists(text))
		{
			MelonLogger.Error("Texture file not found at: " + text);
			return null;
		}
		byte[] array = File.ReadAllBytes(text);
		Texture2D val = new Texture2D(2, 2);
		if (!ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
		{
			MelonLogger.Error("Failed to load texture image.");
			return null;
		}
		return val;
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		if (checkCoroutine != null)
		{
			MelonCoroutines.Stop((object)checkCoroutine);
			checkCoroutine = null;
		}
		MelonCoroutines.Start(FindAndModifyFryingPan());
	}
}