Decompiled source of NoMoreTrash v1.0.1

NoMoreTrashMono.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using NoMoreTrashMono;
using ScheduleOne.DevUtilities;
using ScheduleOne.Trash;
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(NoMoreTrash), "NoMoreTrash", "1.0.1", "Voidane", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: AssemblyTitle("NoMoreTrash")]
[assembly: AssemblyDescription("Destroys all trash in the world that the config is set to.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NoMoreTrashMono")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("be82ea52-085c-4e40-923b-e451789032ea")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace NoMoreTrashMono;

public class ConfigData
{
	public static MelonPreferences_Category clearTrash;

	public static MelonPreferences_Entry<bool> soilbag;

	public static MelonPreferences_Entry<bool> soilbag2;

	public static MelonPreferences_Entry<bool> seedvial;

	public static MelonPreferences_Entry<bool> cuke;

	public static MelonPreferences_Entry<bool> pgr;

	public static MelonPreferences_Entry<bool> speedgrow;

	public static MelonPreferences_Entry<bool> fertilizer;

	public static MelonPreferences_Entry<bool> plantscrap;

	public static MelonPreferences_Entry<bool> trashbag;

	public static MelonPreferences_Entry<bool> soilbag3;

	public static MelonPreferences_Entry<bool> cigarette;

	public static MelonPreferences_Entry<bool> usedcigarette;

	public static MelonPreferences_Entry<bool> cigarettebox;

	public static MelonPreferences_Entry<bool> coffeecup;

	public static MelonPreferences_Entry<bool> crushedcuke;

	public static MelonPreferences_Entry<bool> glassbottle;

	public static MelonPreferences_Entry<bool> litter1;

	public static MelonPreferences_Entry<bool> waterbottle;

	public static MelonPreferences_Entry<bool> energydrink;

	public static MelonPreferences_Entry<bool> flumedicine;

	public static MelonPreferences_Entry<bool> gasoline;

	public static MelonPreferences_Entry<bool> mouthwash;

	public static MelonPreferences_Entry<bool> motoroil;

	public static MelonPreferences_Entry<bool> iodine;

	public static MelonPreferences_Entry<bool> bong;

	public static MelonPreferences_Entry<bool> syringe;

	public static MelonPreferences_Entry<bool> pipe;

	public static MelonPreferences_Entry<bool> chemicaljug;

	public static MelonPreferences_Entry<bool> m1911mag;

	public static MelonPreferences_Entry<bool> revolvercylinder;

	public static MelonPreferences_Entry<bool> acid;

	public static MelonPreferences_Entry<bool> addy;

	public static MelonPreferences_Entry<bool> phosphorus;

	public Dictionary<string, bool> TrashItems;

	public static ConfigData Instance;

	public ConfigData()
	{
		Instance = this;
		clearTrash = MelonPreferences.CreateCategory("NoMoreTrash-clearTrash", "ClearTrash");
		soilbag = clearTrash.CreateEntry<bool>("soilbag", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		soilbag2 = clearTrash.CreateEntry<bool>("soilbag2", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		seedvial = clearTrash.CreateEntry<bool>("seedvial", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		cuke = clearTrash.CreateEntry<bool>("cuke", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		pgr = clearTrash.CreateEntry<bool>("pgr", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		speedgrow = clearTrash.CreateEntry<bool>("speedgrow", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		fertilizer = clearTrash.CreateEntry<bool>("fertilizer", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		plantscrap = clearTrash.CreateEntry<bool>("plantscrap", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		trashbag = clearTrash.CreateEntry<bool>("trashbag", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		soilbag3 = clearTrash.CreateEntry<bool>("soilbag3", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		cigarette = clearTrash.CreateEntry<bool>("cigarette", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		usedcigarette = clearTrash.CreateEntry<bool>("usedcigarette", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		cigarettebox = clearTrash.CreateEntry<bool>("cigarettebox", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		coffeecup = clearTrash.CreateEntry<bool>("coffeecup", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		crushedcuke = clearTrash.CreateEntry<bool>("crushedcuke", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		glassbottle = clearTrash.CreateEntry<bool>("glassbottle", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		litter1 = clearTrash.CreateEntry<bool>("litter1", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		waterbottle = clearTrash.CreateEntry<bool>("waterbottle", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		energydrink = clearTrash.CreateEntry<bool>("energydrink", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		flumedicine = clearTrash.CreateEntry<bool>("flumedicine", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		gasoline = clearTrash.CreateEntry<bool>("gasoline", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		mouthwash = clearTrash.CreateEntry<bool>("mouthwash", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		motoroil = clearTrash.CreateEntry<bool>("motoroil", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		iodine = clearTrash.CreateEntry<bool>("iodine", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		bong = clearTrash.CreateEntry<bool>("bong", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		syringe = clearTrash.CreateEntry<bool>("syringe", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		pipe = clearTrash.CreateEntry<bool>("pipe", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		chemicaljug = clearTrash.CreateEntry<bool>("chemicaljug", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		m1911mag = clearTrash.CreateEntry<bool>("m1911mag", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		revolvercylinder = clearTrash.CreateEntry<bool>("revolvercylinder", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		acid = clearTrash.CreateEntry<bool>("acid", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		addy = clearTrash.CreateEntry<bool>("addy", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		phosphorus = clearTrash.CreateEntry<bool>("phosphorus", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		clearTrash.SetFilePath("UserData/NoTrashMod.cfg");
		clearTrash.SaveToFile(true);
		InitializeTrashDictionary();
	}

	private void InitializeTrashDictionary()
	{
		TrashItems = new Dictionary<string, bool>
		{
			{ "soilbag", soilbag.Value },
			{ "soilbag2", soilbag2.Value },
			{ "seedvial", seedvial.Value },
			{ "cuke", cuke.Value },
			{ "pgr", pgr.Value },
			{ "speedgrow", speedgrow.Value },
			{ "fertilizer", fertilizer.Value },
			{ "plantscrap", plantscrap.Value },
			{ "trashbag", trashbag.Value },
			{ "soilbag3", soilbag3.Value },
			{ "cigarette", cigarette.Value },
			{ "usedcigarette", usedcigarette.Value },
			{ "cigarettebox", cigarettebox.Value },
			{ "coffeecup", coffeecup.Value },
			{ "crushedcuke", crushedcuke.Value },
			{ "glassbottle", glassbottle.Value },
			{ "litter1", litter1.Value },
			{ "waterbottle", waterbottle.Value },
			{ "energydrink", energydrink.Value },
			{ "flumedicine", flumedicine.Value },
			{ "gasoline", gasoline.Value },
			{ "mouthwash", mouthwash.Value },
			{ "motoroil", motoroil.Value },
			{ "iodine", iodine.Value },
			{ "bong", bong.Value },
			{ "syringe", syringe.Value },
			{ "pipe", pipe.Value },
			{ "chemicaljug", chemicaljug.Value },
			{ "m1911mag", m1911mag.Value },
			{ "revolvercylinder", revolvercylinder.Value },
			{ "acid", acid.Value },
			{ "addy", addy.Value },
			{ "phosphorus", phosphorus.Value }
		};
	}
}
public class NoMoreTrash : MelonMod
{
	[HarmonyPatch(typeof(TrashItem), "Start")]
	public static class Patch_TrashItem_Destroying
	{
		[HarmonyPostfix]
		public static void Postfix(TrashItem __instance)
		{
			if (((Object)((Component)((Component)__instance).transform.parent).gameObject).name.Contains("_Temp"))
			{
				if (!configData.TrashItems.TryGetValue(__instance.ID, out var value))
				{
					MelonLogger.Error("could not find: " + __instance.ID + " in config");
					MelonLogger.Error("This might be a new or custom item that needs to added to the config!");
					MelonLogger.Error("Report here: discord.gg/XB7ruKtJje");
				}
				if (value)
				{
					__instance.DestroyTrash();
				}
			}
		}
	}

	public static TrashManager trashManager;

	public static ConfigData configData;

	private const string versionCurrent = "1.0.1";

	private const string versionMostUpToDateURL = "https://raw.githubusercontent.com/Voidane/NoMoreTrash/refs/heads/Mono/NoMoreTrashMono/Version.txt";

	private const string githubBranchURL = "https://github.com/Voidane/NoMoreTrash/tree/Mono";

	private const string nexusOrThunderURL = "https://www.nexusmods.com/schedule1/mods/221?tab=files or thunderstore link";

	private string versionUpdate = null;

	public override void OnInitializeMelon()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		MelonLogger.Msg("===========================================");
		MelonLogger.Msg("Initializing No Trash Mod (MONO) 1.0.1");
		MelonLogger.Msg("Discord: discord.gg/XB7ruKtJje");
		configData = new ConfigData();
		new Harmony("com.voidane.nomoretrashmono").PatchAll();
		CheckForUpdates();
	}

	private async void CheckForUpdates()
	{
		try
		{
			HttpClient client = new HttpClient();
			try
			{
				versionUpdate = (await client.GetStringAsync("https://raw.githubusercontent.com/Voidane/NoMoreTrash/refs/heads/Mono/NoMoreTrashMono/Version.txt")).Trim();
			}
			finally
			{
				((IDisposable)client)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Exception e = ex;
			MelonLogger.Msg("Could not fetch most up to date version " + e.Message);
		}
		if ("1.0.1" != versionUpdate)
		{
			MelonLogger.Msg("New Update for no trash mod (MONO)! https://www.nexusmods.com/schedule1/mods/221?tab=files or thunderstore link, Current: 1.0.1, Update: " + versionUpdate);
		}
		MelonLogger.Msg("Has been initialized...");
		MelonLogger.Msg("===========================================");
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		if (!(sceneName == "Main"))
		{
			return;
		}
		MelonLogger.Msg("Main scene loaded!");
		MelonCoroutines.Start(WaitOnSceneLoad(null, "Managers", 20f, delegate(Transform managers)
		{
			MelonCoroutines.Start(WaitOnSceneLoad(managers, "@Trash", 5f, delegate(Transform tm)
			{
				TrashManager val = default(TrashManager);
				if (((Component)tm).TryGetComponent<TrashManager>(ref val))
				{
					trashManager = NetworkSingleton<TrashManager>.Instance;
				}
			}));
		}));
	}

	private IEnumerator WaitOnSceneLoad(Transform parent, string name, float timeoutLimit, Action<Transform> onComplete)
	{
		Transform target = null;
		float timeOutCounter = 0f;
		MelonLogger.Msg("Looking for " + name + " inside of " + (((Object)(object)parent == (Object)null) ? "Hierarchy" : ((Object)((Component)parent).gameObject).name));
		while ((Object)(object)target == (Object)null && timeOutCounter < timeoutLimit)
		{
			target = (((Object)(object)parent == (Object)null) ? GameObject.Find(name).transform : parent.Find(name));
			if ((Object)(object)target == (Object)null)
			{
				timeOutCounter += 0.5f;
				yield return (object)new WaitForSeconds(0.5f);
			}
		}
		if ((Object)(object)target != (Object)null)
		{
			onComplete?.Invoke(target);
		}
		else
		{
			MelonLogger.Error("Failed to find target object within timeout period!");
			onComplete?.Invoke(null);
		}
		yield return target;
	}
}