using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("CoinPiercerWallbang")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CoinPiercerWallbang")]
[assembly: AssemblyTitle("CoinPiercerWallbang")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 CoinPiercerWallbang
{
[BepInPlugin("DestinedSnow.CoinPiercerwallbangConfig", "CoinPiercer Wallbang", "1.1.0")]
[BepInProcess("ULTRAKILL.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static BoolValueChangeEventDelegate <>9__12_0;
public static BoolValueChangeEventDelegate <>9__12_1;
public static BoolValueChangeEventDelegate <>9__12_2;
internal void <Awake>b__12_0(BoolValueChangeEvent data)
{
CoinWallbang.Value = data.value;
}
internal void <Awake>b__12_1(BoolValueChangeEvent data)
{
DirectWallbang.Value = data.value;
}
internal void <Awake>b__12_2(BoolValueChangeEvent data)
{
InstantCharge.Value = data.value;
}
}
public const string ModGuid = "DestinedSnow.CoinPiercerwallbangConfig";
public const string ModName = "CoinPiercer Wallbang";
public const string ModVersion = "1.1.0";
internal static ManualLogSource Log;
public static PluginConfigurator PluginConfigInstance;
public static BoolField CoinWallbangField;
public static BoolField DirectWallbangField;
public static BoolField InstantChargeField;
internal static ConfigEntry<bool> CoinWallbang;
internal static ConfigEntry<bool> DirectWallbang;
internal static ConfigEntry<bool> InstantCharge;
private Harmony harmony;
private void Awake()
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Expected O, but got Unknown
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Expected O, but got Unknown
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Expected O, but got Unknown
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Expected O, but got Unknown
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Expected O, but got Unknown
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_0230: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Expected O, but got Unknown
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_0282: Unknown result type (might be due to invalid IL or missing references)
//IL_0288: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
CoinWallbang = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CoinWallbang", true, (ConfigDescription)null);
DirectWallbang = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DirectWallbang", true, (ConfigDescription)null);
InstantCharge = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "InstantCharge", true, (ConfigDescription)null);
harmony = new Harmony("DestinedSnow.CoinPiercerwallbangConfig");
harmony.PatchAll();
if (AccessTools.Field(typeof(Revolver), "chargingPierce") == null)
{
Log.LogError((object)"Revolver.chargingPierce not found.");
}
if (AccessTools.Field(typeof(Revolver), "pierceShotCharge") == null)
{
Log.LogError((object)"Revolver.pierceShotCharge not found.");
}
if (AccessTools.Method(typeof(Coin), "CheckEnemyObstruction", (Type[])null, (Type[])null) == null)
{
Log.LogError((object)"Coin.CheckEnemyObstruction not found.");
}
if (AccessTools.Field(typeof(PhysicsCastResult), "distance") == null)
{
Log.LogError((object)"PhysicsCastResult.distance not found.");
}
PluginConfigInstance = PluginConfigurator.Create("Coin Piercer Wallbang", "Coin Piercer Wallbang Config");
string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
string iconWithURL = "file:///" + Path.Combine(directoryName, "icon.png").Replace("\\", "/");
PluginConfigInstance.SetIconWithURL(iconWithURL);
CoinWallbangField = new BoolField(PluginConfigInstance.rootPanel, "Coin Wallbang", "coin_wallbang", CoinWallbang.Value);
BoolField coinWallbangField = CoinWallbangField;
object obj = <>c.<>9__12_0;
if (obj == null)
{
BoolValueChangeEventDelegate val = delegate(BoolValueChangeEvent data)
{
CoinWallbang.Value = data.value;
};
<>c.<>9__12_0 = val;
obj = (object)val;
}
coinWallbangField.onValueChange += (BoolValueChangeEventDelegate)obj;
DirectWallbangField = new BoolField(PluginConfigInstance.rootPanel, "Direct Piercer Wallbang", "direct_wallbang", DirectWallbang.Value);
BoolField directWallbangField = DirectWallbangField;
object obj2 = <>c.<>9__12_1;
if (obj2 == null)
{
BoolValueChangeEventDelegate val2 = delegate(BoolValueChangeEvent data)
{
DirectWallbang.Value = data.value;
};
<>c.<>9__12_1 = val2;
obj2 = (object)val2;
}
directWallbangField.onValueChange += (BoolValueChangeEventDelegate)obj2;
InstantChargeField = new BoolField(PluginConfigInstance.rootPanel, "Instant Charged Piercer", "instant_charge", InstantCharge.Value);
BoolField instantChargeField = InstantChargeField;
object obj3 = <>c.<>9__12_2;
if (obj3 == null)
{
BoolValueChangeEventDelegate val3 = delegate(BoolValueChangeEvent data)
{
InstantCharge.Value = data.value;
};
<>c.<>9__12_2 = val3;
obj3 = (object)val3;
}
instantChargeField.onValueChange += (BoolValueChangeEventDelegate)obj3;
Log.LogInfo((object)"CoinPiercer Wallbang 1.1.0 loaded.");
}
private void OnDestroy()
{
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
}
internal static bool IsChargedPiercer(RevolverBeam beam)
{
if ((Object)(object)beam == (Object)null)
{
return false;
}
if (beam.gunVariation != 0)
{
return false;
}
int num = (beam.strongAlt ? 6 : 3);
return beam.hitAmount >= num;
}
}
[HarmonyPatch(typeof(Coin), "CheckEnemyObstruction")]
internal static class CoinCheckEnemyObstructionPatch
{
private static bool Prefix(Coin __instance, ref bool __result)
{
if (!Plugin.CoinWallbang.Value)
{
return true;
}
try
{
GameObject value = Traverse.Create((object)__instance).Field("altBeam").GetValue<GameObject>();
if ((Object)(object)value == (Object)null)
{
return true;
}
RevolverBeam component = value.GetComponent<RevolverBeam>();
if ((Object)(object)component == (Object)null)
{
return true;
}
if (!Plugin.IsChargedPiercer(component))
{
return true;
}
__result = true;
return false;
}
catch (Exception arg)
{
Plugin.Log.LogWarning((object)$"CoinCheckEnemyObstructionPatch error: {arg}");
return true;
}
}
}
[HarmonyPatch(typeof(RevolverBeam), "Shoot")]
internal static class BeamDistancePatch
{
private static float ModifyDistance(float distance, RevolverBeam beam)
{
if (!Plugin.DirectWallbang.Value)
{
return distance;
}
if (Plugin.IsChargedPiercer(beam))
{
return 10000f;
}
return distance;
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
FieldInfo distanceField = AccessTools.Field(typeof(PhysicsCastResult), "distance");
MethodInfo modifyMethod = AccessTools.Method(typeof(BeamDistancePatch), "ModifyDistance", (Type[])null, (Type[])null);
int replacements = 0;
foreach (CodeInstruction code in instructions)
{
yield return code;
if (code.opcode == OpCodes.Ldfld && object.Equals(code.operand, distanceField))
{
replacements++;
yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
yield return new CodeInstruction(OpCodes.Call, (object)modifyMethod);
}
}
if (replacements == 0)
{
Plugin.Log.LogError((object)"BeamDistancePatch failed: target instruction not found.");
}
}
}
[HarmonyPatch(typeof(Revolver), "Update")]
internal static class InstantChargePatch
{
private static void Prefix(Revolver __instance)
{
if (Plugin.InstantCharge.Value && __instance.gunVariation == 0)
{
Traverse val = Traverse.Create((object)__instance);
bool value = val.Field("chargingPierce").GetValue<bool>();
float value2 = val.Field("pierceShotCharge").GetValue<float>();
if (value && !(value2 >= 100f))
{
val.Field("pierceShotCharge").SetValue((object)100f);
}
}
}
}
}