Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of NoTreeDust v1.0.0
NoTreeDust.dll
Decompiled a year agousing System; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("NoTreeDust")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Azumatt")] [assembly: AssemblyProduct("NoTreeDust")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")] [assembly: AssemblyFileVersion("1.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace NoTreeDust { [BepInPlugin("Azumatt.NoTreeDust", "NoTreeDust", "1.0.0")] public class NoTreeDustPlugin : BaseUnityPlugin { public enum Toggle { On = 1, Off = 0 } internal const string ModName = "NoTreeDust"; internal const string ModVersion = "1.0.0"; internal const string Author = "Azumatt"; private const string ModGUID = "Azumatt.NoTreeDust"; private static string ConfigFileName = "Azumatt.NoTreeDust.cfg"; private static string ConfigFileFullPath; internal static string ConnectionError; private readonly Harmony _harmony = new Harmony("Azumatt.NoTreeDust"); public static readonly ManualLogSource NoTreeDustLogger; private FileSystemWatcher _watcher; private readonly object _reloadLock = new object(); private DateTime _lastConfigReloadTime; private const long RELOAD_DELAY = 10000000L; private const string VfxKeyword = "vfx"; public static ConfigEntry<Toggle> DestroyedEffectsEnabled; public static ConfigEntry<Toggle> HitEffectsEnabled; public static ConfigEntry<Toggle> RespawnEffectsEnabled; public void Awake() { bool saveOnConfigSet = ((BaseUnityPlugin)this).Config.SaveOnConfigSet; ((BaseUnityPlugin)this).Config.SaveOnConfigSet = false; DestroyedEffectsEnabled = config("1 - General", "Destroy Effects", Toggle.Off, "Enable/Disable destroy effects on the trees"); HitEffectsEnabled = config("1 - General", "Hit Effects", Toggle.Off, "Enable/Disable hit effects on the trees"); RespawnEffectsEnabled = config("1 - General", "Respawn Effects", Toggle.Off, "Enable/Disable respawn effects on the trees"); DestroyedEffectsEnabled.SettingChanged += delegate { UpdateAllDestroyedEffects(); }; HitEffectsEnabled.SettingChanged += delegate { UpdateAllHitEffects(); }; RespawnEffectsEnabled.SettingChanged += delegate { UpdateAllRespawnEffects(); }; Assembly executingAssembly = Assembly.GetExecutingAssembly(); _harmony.PatchAll(executingAssembly); SetupWatcher(); ((BaseUnityPlugin)this).Config.Save(); if (saveOnConfigSet) { ((BaseUnityPlugin)this).Config.SaveOnConfigSet = saveOnConfigSet; } } private void OnDestroy() { SaveWithRespectToConfigSet(); _watcher?.Dispose(); } private void SetupWatcher() { _watcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName); _watcher.Changed += ReadConfigValues; _watcher.Created += ReadConfigValues; _watcher.Renamed += ReadConfigValues; _watcher.IncludeSubdirectories = true; _watcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; _watcher.EnableRaisingEvents = true; } private void ReadConfigValues(object sender, FileSystemEventArgs e) { DateTime now = DateTime.Now; if (now.Ticks - _lastConfigReloadTime.Ticks < 10000000) { return; } lock (_reloadLock) { if (!File.Exists(ConfigFileFullPath)) { NoTreeDustLogger.LogWarning((object)"Config file does not exist. Skipping reload."); return; } try { NoTreeDustLogger.LogDebug((object)"Reloading configuration..."); SaveWithRespectToConfigSet(reload: true); NoTreeDustLogger.LogInfo((object)"Configuration reload complete."); } catch (Exception ex) { NoTreeDustLogger.LogError((object)("Error reloading configuration: " + ex.Message)); } } _lastConfigReloadTime = now; } private void SaveWithRespectToConfigSet(bool reload = false) { bool saveOnConfigSet = ((BaseUnityPlugin)this).Config.SaveOnConfigSet; ((BaseUnityPlugin)this).Config.SaveOnConfigSet = false; if (reload) { ((BaseUnityPlugin)this).Config.Reload(); } ((BaseUnityPlugin)this).Config.Save(); if (saveOnConfigSet) { ((BaseUnityPlugin)this).Config.SaveOnConfigSet = saveOnConfigSet; } } private static void UpdateAllDestroyedEffects() { bool isEnabled = DestroyedEffectsEnabled.Value.IsOn(); TreeBase[] array = Resources.FindObjectsOfTypeAll<TreeBase>(); for (int i = 0; i < array.Length; i++) { UpdateEffectList(array[i].m_destroyedEffect.m_effectPrefabs, isEnabled); } TreeLog[] array2 = Resources.FindObjectsOfTypeAll<TreeLog>(); for (int i = 0; i < array2.Length; i++) { UpdateEffectList(array2[i].m_destroyedEffect.m_effectPrefabs, isEnabled); } foreach (Destructible item in from x in Resources.FindObjectsOfTypeAll<Destructible>() where (int)x.m_destructibleType == 2 select x) { UpdateEffectList(item.m_destroyedEffect.m_effectPrefabs, isEnabled); } } private static void UpdateAllHitEffects() { bool isEnabled = HitEffectsEnabled.Value.IsOn(); TreeBase[] array = Resources.FindObjectsOfTypeAll<TreeBase>(); for (int i = 0; i < array.Length; i++) { UpdateEffectList(array[i].m_hitEffect.m_effectPrefabs, isEnabled); } TreeLog[] array2 = Resources.FindObjectsOfTypeAll<TreeLog>(); for (int i = 0; i < array2.Length; i++) { UpdateEffectList(array2[i].m_hitEffect.m_effectPrefabs, isEnabled); } foreach (Destructible item in from x in Resources.FindObjectsOfTypeAll<Destructible>() where (int)x.m_destructibleType == 2 select x) { UpdateEffectList(item.m_hitEffect.m_effectPrefabs, isEnabled); } } private static void UpdateAllRespawnEffects() { bool isEnabled = RespawnEffectsEnabled.Value.IsOn(); TreeBase[] array = Resources.FindObjectsOfTypeAll<TreeBase>(); for (int i = 0; i < array.Length; i++) { UpdateEffectList(array[i].m_respawnEffect.m_effectPrefabs, isEnabled); } } internal static void UpdateEffectList(EffectData[] effects, bool isEnabled) { if (effects == null) { return; } foreach (EffectData val in effects) { if (val != null && (Object)(object)val.m_prefab != (Object)null && ((Object)val.m_prefab).name.Contains("vfx")) { val.m_enabled = isEnabled; } } } private ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description) { return ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, description); } private ConfigEntry<T> config<T>(string group, string name, T value, string description) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>())); } static NoTreeDustPlugin() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName; ConnectionError = ""; NoTreeDustLogger = Logger.CreateLogSource("NoTreeDust"); DestroyedEffectsEnabled = null; HitEffectsEnabled = null; RespawnEffectsEnabled = null; } } public static class ToggleExtensions { public static bool IsOn(this NoTreeDustPlugin.Toggle value) { return value == NoTreeDustPlugin.Toggle.On; } public static bool IsOff(this NoTreeDustPlugin.Toggle value) { return value == NoTreeDustPlugin.Toggle.Off; } } [HarmonyPatch(typeof(ZNetScene), "Awake")] internal static class ZNetSceneAwakePatch { [HarmonyPriority(0)] private static void Postfix(ZNetScene __instance) { //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Invalid comparison between Unknown and I4 NoTreeDustPlugin.NoTreeDustLogger.LogDebug((object)"ZNetScene Awake Postfix, turning off tree dust"); TreeBase val = default(TreeBase); TreeLog val2 = default(TreeLog); Destructible val3 = default(Destructible); foreach (GameObject prefab in __instance.m_prefabs) { if (prefab.TryGetComponent<TreeBase>(ref val)) { NoTreeDustPlugin.UpdateEffectList(val.m_destroyedEffect.m_effectPrefabs, NoTreeDustPlugin.DestroyedEffectsEnabled.Value.IsOn()); NoTreeDustPlugin.UpdateEffectList(val.m_hitEffect.m_effectPrefabs, NoTreeDustPlugin.HitEffectsEnabled.Value.IsOn()); NoTreeDustPlugin.UpdateEffectList(val.m_respawnEffect.m_effectPrefabs, NoTreeDustPlugin.RespawnEffectsEnabled.Value.IsOn()); } if (prefab.TryGetComponent<TreeLog>(ref val2)) { NoTreeDustPlugin.UpdateEffectList(val2.m_destroyedEffect.m_effectPrefabs, NoTreeDustPlugin.DestroyedEffectsEnabled.Value.IsOn()); NoTreeDustPlugin.UpdateEffectList(val2.m_hitEffect.m_effectPrefabs, NoTreeDustPlugin.HitEffectsEnabled.Value.IsOn()); } if (prefab.TryGetComponent<Destructible>(ref val3) && (int)val3.m_destructibleType == 2) { NoTreeDustPlugin.UpdateEffectList(val3.m_destroyedEffect.m_effectPrefabs, NoTreeDustPlugin.DestroyedEffectsEnabled.Value.IsOn()); NoTreeDustPlugin.UpdateEffectList(val3.m_hitEffect.m_effectPrefabs, NoTreeDustPlugin.HitEffectsEnabled.Value.IsOn()); } } } } }