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 Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CircletDemister")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Azumatt")]
[assembly: AssemblyProduct("CircletDemister")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 CircletDemister
{
[HarmonyPatch(typeof(ZNetScene), "Awake")]
internal static class ZNetSceneAwakePatch
{
private static void Postfix(ZNetScene __instance)
{
CircletDemisterPlugin.DemisterParticleFf = __instance.GetPrefab("Demister").GetComponentInChildren<ParticleSystemForceField>();
CircletDemisterPlugin.DemisterParticleFf.endRange = 4f;
}
}
[HarmonyPatch(typeof(Humanoid), "EquipItem")]
internal static class PlayerEquipItemPatch
{
private static void Postfix(ref Humanoid __instance, ref bool __result, ItemData? item, bool triggerEquipEffects = true)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)Player.m_localPlayer == (Object)null) && ((Character)__instance).IsPlayer() && !Player.m_localPlayer.m_isLoading && !(((item != null) ? ((Object)item.m_dropPrefab).name : null) != "HelmetDverger") && (Object)(object)CircletDemisterPlugin.PlayerParticleFf == (Object)null)
{
CircletDemisterPlugin.PlayerParticleFf = Object.Instantiate<ParticleSystemForceField>(CircletDemisterPlugin.DemisterParticleFf, ((Character)__instance).GetHeadPoint(), Quaternion.identity, ((Component)__instance).transform);
}
}
}
[HarmonyPatch(typeof(Humanoid), "UnequipItem")]
internal static class PlayerUnequipItemPatch
{
private static void Postfix(ref Humanoid __instance, ItemData? item, bool triggerEquipEffects = true)
{
if (((Character)__instance).IsPlayer() && !(((item != null) ? ((Object)item.m_dropPrefab).name : null) != "HelmetDverger") && !((Object)(object)Player.m_localPlayer == (Object)null) && ((Character)__instance).IsPlayer() && !((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && !((Object)(object)CircletDemisterPlugin.PlayerParticleFf == (Object)null))
{
Demister.m_instances.Remove(((Component)CircletDemisterPlugin.PlayerParticleFf).GetComponent<Demister>());
Object.Destroy((Object)(object)((Component)CircletDemisterPlugin.PlayerParticleFf).gameObject);
CircletDemisterPlugin.PlayerParticleFf = null;
}
}
}
[BepInPlugin("Azumatt.CircletDemister", "CircletDemister", "1.0.2")]
public class CircletDemisterPlugin : BaseUnityPlugin
{
internal const string ModName = "CircletDemister";
internal const string ModVersion = "1.0.2";
internal const string Author = "Azumatt";
private const string ModGUID = "Azumatt.CircletDemister";
private static string ConfigFileName = "Azumatt.CircletDemister.cfg";
private static string ConfigFileFullPath;
internal static string ConnectionError;
private readonly Harmony _harmony = new Harmony("Azumatt.CircletDemister");
public static readonly ManualLogSource CircletDemisterLogger;
internal static ParticleSystemForceField? DemisterParticleFf;
internal static ParticleSystemForceField? PlayerParticleFf;
private static ConfigEntry<float> DemisterMaxRange { get; set; }
public void Awake()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
DemisterMaxRange = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "End Range", 3.5f, new ConfigDescription("The end range of the demister effect on the circlet. Capped to be weaker than the Mistlands Demister Orb (Wisp) that has a range of 6", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
DemisterMaxRange.SettingChanged += delegate
{
UpdateDemisterRange(null, null);
};
Assembly executingAssembly = Assembly.GetExecutingAssembly();
_harmony.PatchAll(executingAssembly);
SetupWatcher();
}
private void OnDestroy()
{
((BaseUnityPlugin)this).Config.Save();
try
{
if ((Object)(object)DemisterParticleFf != (Object)null)
{
Object.Destroy((Object)(object)DemisterParticleFf);
}
if ((Object)(object)PlayerParticleFf != (Object)null)
{
Object.Destroy((Object)(object)PlayerParticleFf);
}
}
catch
{
}
}
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
{
CircletDemisterLogger.LogDebug((object)"ReadConfigValues called");
((BaseUnityPlugin)this).Config.Reload();
}
catch
{
CircletDemisterLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
CircletDemisterLogger.LogError((object)"Please check your config entries for spelling and format!");
}
}
private void UpdateDemisterRange(object sender, EventArgs e)
{
if ((Object)(object)PlayerParticleFf != (Object)null)
{
PlayerParticleFf.endRange = DemisterMaxRange.Value;
}
}
static CircletDemisterPlugin()
{
string configPath = Paths.ConfigPath;
char directorySeparatorChar = Path.DirectorySeparatorChar;
ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
ConnectionError = "";
CircletDemisterLogger = Logger.CreateLogSource("CircletDemister");
DemisterParticleFf = null;
PlayerParticleFf = null;
DemisterMaxRange = null;
}
}
}