using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Movement;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DBR")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("Optical Persistence")]
[assembly: AssemblyTitle("OpticalPersistence")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 OpticalPersistence
{
[MycoMod(/*Could not decode attribute arguments.*/)]
[BepInPlugin("DBR.OpticalPersistence", "OpticalPersistence", "1.4.0")]
public class OpticalPersistence : BaseUnityPlugin
{
[HarmonyPatch(typeof(ShieldProjector), "OnBeforeTakeDamage")]
public static class OpticalPersistencePatch
{
[HarmonyPrefix]
public static bool Prefix(ShieldProjector __instance, ref DamageData data)
{
if (__instance.Data.aggroDuration < __instance.Data.aggroCooldown || Time.time - LastAggroTime.Invoke(__instance) < __instance.Data.aggroDuration)
{
return true;
}
float num = 1f - __instance.Data.aggroDamageResistance * 0.5f;
data.damage *= num;
return false;
}
}
[HarmonyPatch(typeof(ShieldProjector), "Update")]
public static class UpdatePatch
{
[HarmonyPostfix]
public static void Postfix(ShieldProjector __instance)
{
if (__instance.Data.aggroDuration > 0f && __instance.Data.aggroDuration > __instance.Data.aggroCooldown)
{
bool flag = IsAggroing(__instance);
if (flag && !hasAggroed)
{
hasAggroed = true;
((Gun)__instance).Player.RemoveStackDisplay((object)typeof(OpticalPersistence));
}
else if (!flag && hasAggroed)
{
hasAggroed = false;
((Gun)__instance).Player.UpdateStackDisplay((object)typeof(OpticalPersistence), "Optical Persistence", PersistenceIcon, 1, 0f);
}
}
}
}
[HarmonyPatch(typeof(ShieldProjector), "OnUpgradesEnabled")]
public static class OpticalAttractionDisplayEnablePatch
{
[HarmonyPostfix]
public static void Postfix(ShieldProjector __instance)
{
if (__instance.Data.aggroDuration > __instance.Data.aggroCooldown && !IsAggroing(__instance))
{
((Gun)__instance).Player.UpdateStackDisplay((object)typeof(OpticalPersistence), "Optical Persistence", PersistenceIcon, 1, 0f);
}
}
}
[HarmonyPatch(typeof(ShieldProjector), "OnUpgradesDisabled")]
public static class OpticalAttractionDisplayDisablePatch
{
[HarmonyPostfix]
public static void Postfix()
{
Player.LocalPlayer.RemoveStackDisplay((object)typeof(OpticalPersistence));
}
}
public const string PLUGIN_GUID = "DBR.OpticalPersistence";
public const string PLUGIN_NAME = "OpticalPersistence";
public const string PLUGIN_VERSION = "1.4.0";
internal static Sprite PersistenceIcon;
internal static ManualLogSource Logger;
private static readonly FieldRef<ShieldProjector, float> LastAggroTime = AccessTools.FieldRefAccess<ShieldProjector, float>("lastAggroTime");
private static bool hasAggroed = false;
private void Awake()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin DBR.OpticalPersistence is loaded");
Harmony val = new Harmony("DBR.OpticalPersistence");
try
{
val.PatchAll();
}
catch (Exception ex)
{
Logger.LogError((object)("Error applying patches: " + ex.Message));
}
PersistenceIcon = LoadExternalIcon("persistence.png", (BaseUnityPlugin)(object)this);
}
public static bool IsAggroing(ShieldProjector instance)
{
return Time.time - LastAggroTime.Invoke(instance) < instance.Data.aggroDuration;
}
internal static Sprite LoadExternalIcon(string iconName, BaseUnityPlugin pluginInstance)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
string path = Path.Combine(Path.GetDirectoryName(pluginInstance.Info.Location), iconName);
if (!File.Exists(path))
{
return null;
}
try
{
byte[] array = File.ReadAllBytes(path);
Texture2D val = new Texture2D(2, 2);
ImageConversion.LoadImage(val, array);
return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
}
catch (Exception ex)
{
Logger.LogError((object)("Icon Load Failed: " + ex.Message));
return null;
}
}
}
}