using System;
using System.Diagnostics;
using System.IO;
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 JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("NoWeaponDust")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Azumatt")]
[assembly: AssemblyProduct("NoWeaponDust")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
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;
}
}
}
namespace NoWeaponDust
{
[BepInPlugin("Azumatt.NoWeaponDust", "NoWeaponDust", "1.0.1")]
public class NoWeaponDustPlugin : BaseUnityPlugin
{
public enum Toggle
{
On = 1,
Off = 0
}
private class ConfigurationManagerAttributes
{
[UsedImplicitly]
public int? Order;
[UsedImplicitly]
public bool? Browsable;
[UsedImplicitly]
public string? Category;
[UsedImplicitly]
public Action<ConfigEntryBase>? CustomDrawer;
}
internal const string ModName = "NoWeaponDust";
internal const string ModVersion = "1.0.1";
internal const string Author = "Azumatt";
private const string ModGUID = "Azumatt.NoWeaponDust";
private static string ConfigFileName = "Azumatt.NoWeaponDust.cfg";
private static string ConfigFileFullPath;
internal static string ConnectionError;
private readonly Harmony _harmony = new Harmony("Azumatt.NoWeaponDust");
public static readonly ManualLogSource NoWeaponDustLogger;
internal static ConfigEntry<Toggle> RemoveTriggerEffects;
internal static ConfigEntry<Toggle> RemoveHitTerrainEffects;
internal static ConfigEntry<Toggle> RemoveHitEffects;
internal static ConfigEntry<Toggle> RemoveStartEffects;
public void Awake()
{
RemoveTriggerEffects = config("1 - General", "RemoveTriggerEffects", Toggle.On, "If on, this will remove the dust effect from weapons (On Trigger). If off, it will not.");
RemoveHitTerrainEffects = config("1 - General", "RemoveHitTerrainEffects", Toggle.Off, "If on, this will remove the dust effect from weapons (On Hit Terrain). If off, it will not.");
RemoveHitEffects = config("1 - General", "RemoveHitEffects", Toggle.Off, "If on, this will remove the dust effect from weapons (On Hit). If off, it will not.");
RemoveStartEffects = config("1 - General", "RemoveStartEffects", Toggle.Off, "If on, this will remove the dust effect from weapons (On Start). If off, it will not.");
Assembly executingAssembly = Assembly.GetExecutingAssembly();
_harmony.PatchAll(executingAssembly);
SetupWatcher();
}
private void OnDestroy()
{
((BaseUnityPlugin)this).Config.Save();
}
private void SetupWatcher()
{
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
fileSystemWatcher.Changed += ReadConfigValues;
fileSystemWatcher.Created += ReadConfigValues;
fileSystemWatcher.Renamed += ReadConfigValues;
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
fileSystemWatcher.EnableRaisingEvents = true;
}
private void ReadConfigValues(object sender, FileSystemEventArgs e)
{
if (!File.Exists(ConfigFileFullPath))
{
return;
}
try
{
NoWeaponDustLogger.LogDebug((object)"ReadConfigValues called");
((BaseUnityPlugin)this).Config.Reload();
}
catch
{
NoWeaponDustLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
NoWeaponDustLogger.LogError((object)"Please check your config entries for spelling and format!");
}
}
internal static void DisableEffectBasedOnConfig(EffectList effectList, Toggle shouldDisable)
{
if (effectList == null)
{
return;
}
EffectData[] effectPrefabs = effectList.m_effectPrefabs;
foreach (EffectData val in effectPrefabs)
{
if (!((Object)(object)val.m_prefab == (Object)null) && (((Object)val.m_prefab).name.Contains("vfx_") || ((Object)val.m_prefab).name.StartsWith("fx_")))
{
val.m_enabled = shouldDisable == Toggle.Off;
}
}
}
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 NoWeaponDustPlugin()
{
string configPath = Paths.ConfigPath;
char directorySeparatorChar = Path.DirectorySeparatorChar;
ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
ConnectionError = "";
NoWeaponDustLogger = Logger.CreateLogSource("NoWeaponDust");
RemoveTriggerEffects = null;
RemoveHitTerrainEffects = null;
RemoveHitEffects = null;
RemoveStartEffects = null;
}
}
[HarmonyPatch(typeof(Attack), "DoAreaAttack")]
internal static class AttackDoAreaAttackPatch
{
private static void Prefix(Attack __instance)
{
if (((Character)__instance.m_character).IsPlayer())
{
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_hitTerrainEffect, NoWeaponDustPlugin.RemoveHitTerrainEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_weapon.m_shared.m_hitTerrainEffect, NoWeaponDustPlugin.RemoveHitTerrainEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_hitEffect, NoWeaponDustPlugin.RemoveHitEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_weapon.m_shared.m_hitEffect, NoWeaponDustPlugin.RemoveHitEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_triggerEffect, NoWeaponDustPlugin.RemoveTriggerEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_weapon.m_shared.m_triggerEffect, NoWeaponDustPlugin.RemoveTriggerEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_startEffect, NoWeaponDustPlugin.RemoveStartEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_weapon.m_shared.m_startEffect, NoWeaponDustPlugin.RemoveStartEffects.Value);
}
}
}
[HarmonyPatch(typeof(Attack), "DoNonAttack")]
internal static class AttackDoNonAttackPatch
{
private static void Prefix(Attack __instance)
{
if (((Character)__instance.m_character).IsPlayer())
{
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_triggerEffect, NoWeaponDustPlugin.RemoveTriggerEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_weapon.m_shared.m_triggerEffect, NoWeaponDustPlugin.RemoveTriggerEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_startEffect, NoWeaponDustPlugin.RemoveStartEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_weapon.m_shared.m_startEffect, NoWeaponDustPlugin.RemoveStartEffects.Value);
}
}
}
[HarmonyPatch(typeof(Attack), "DoMeleeAttack")]
internal static class AttackOnAttackTriggerPatch
{
private static void Prefix(Attack __instance)
{
if (((Character)__instance.m_character).IsPlayer())
{
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_hitTerrainEffect, NoWeaponDustPlugin.RemoveHitTerrainEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_weapon.m_shared.m_hitTerrainEffect, NoWeaponDustPlugin.RemoveHitTerrainEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_hitEffect, NoWeaponDustPlugin.RemoveHitEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_weapon.m_shared.m_hitEffect, NoWeaponDustPlugin.RemoveHitEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_triggerEffect, NoWeaponDustPlugin.RemoveTriggerEffects.Value);
NoWeaponDustPlugin.DisableEffectBasedOnConfig(__instance.m_weapon.m_shared.m_triggerEffect, NoWeaponDustPlugin.RemoveTriggerEffects.Value);
}
}
}
}