Decompiled source of Earth Everywhere v1.0.1

Mods/RumbleEarthEverywhere.dll

Decompiled a month ago
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using MelonLoader;
using RumbleEarthEverywhere;
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(EarthEverywhere), "Earth Everywhere", "1.0.0", "Teddy", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: AssemblyTitle("RumbleEarthEverywhere")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RumbleEarthEverywhere")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ae38683d-afde-4532-a26c-13c0c5d0b170")]
[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 RumbleEarthEverywhere;

public class EarthEverywhere : MelonMod
{
	private const float retryInterval = 5f;

	private const int maxRetries = 5;

	private readonly List<string> objectNames = new List<string> { "Col_paths", "Col_bridge", "Col_Stair", "Col_paths_metal", "Step", "Floor", "Col_howard floor", "Col_howard floor_metal" };

	private string currentScene;

	private bool sceneChanged;

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg("EarthEverywhere mod loaded!");
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		currentScene = sceneName;
		sceneChanged = true;
	}

	public override void OnFixedUpdate()
	{
		if (!(currentScene != "Gym") && sceneChanged)
		{
			sceneChanged = false;
			MelonLogger.Msg("Gym scene detected. Applying changes...");
			MelonCoroutines.Start(ChangeLayerWithRetry(objectNames, "CombatFloor"));
		}
	}

	private IEnumerator ChangeLayerWithRetry(List<string> objectNames, string layerName)
	{
		int newLayer = LayerMask.NameToLayer(layerName);
		if (newLayer == -1)
		{
			MelonLogger.Warning("Layer '" + layerName + "' does not exist.");
			yield break;
		}
		HashSet<string> remainingObjects = new HashSet<string>(objectNames);
		int retryCount = 0;
		while (remainingObjects.Count > 0 && retryCount < 5)
		{
			foreach (string objectName in new List<string>(remainingObjects))
			{
				GameObject targetObject = GameObject.Find(objectName);
				if ((Object)(object)targetObject != (Object)null)
				{
					int oldLayer = targetObject.layer;
					targetObject.layer = newLayer;
					MelonLogger.Msg($"Changed layer of '{objectName}' from {oldLayer} to {newLayer} ('{layerName}').");
					remainingObjects.Remove(objectName);
				}
				else
				{
					MelonLogger.Warning($"GameObject with name '{objectName}' not found. Retrying in {5f} seconds...");
				}
			}
			if (remainingObjects.Count > 0)
			{
				retryCount++;
				yield return (object)new WaitForSeconds(5f);
			}
		}
		if (remainingObjects.Count <= 0)
		{
			yield break;
		}
		foreach (string objectName2 in remainingObjects)
		{
			MelonLogger.Error($"Failed to find and change layer of GameObject '{objectName2}' after {5} retries.");
		}
	}
}