using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace PeakGlitchPack;
public static class PluginInfo
{
public const string PLUGIN_GUID = "com.peakglitchpack.ropeandemote";
public const string PLUGIN_NAME = "PeakGlitchPack";
public const string PLUGIN_VERSION = "1.4.0";
}
[BepInPlugin("com.peakglitchpack.ropeandemote", "PeakGlitchPack", "1.4.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
internal static ConfigEntry<bool> EnableAlwaysStore;
internal static ConfigEntry<bool> EnableEmoteAnywhere;
private Harmony _harmony;
private void Awake()
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
EnableAlwaysStore = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableAlwaysStore", true, "Pocket items that normally cannot be stored, including cacti. Cacti still stick when held.");
EnableEmoteAnywhere = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableEmoteAnywhere", true, "Emote while climbing.");
try
{
_harmony = new Harmony("com.peakglitchpack.ropeandemote");
_harmony.PatchAll(typeof(Plugin).Assembly);
Log.LogInfo((object)"PeakGlitchPack v1.4.0 loaded.");
}
catch (Exception ex)
{
Log.LogError((object)("Failed to load: " + ex));
}
}
private void OnDestroy()
{
if (_harmony != null)
{
_harmony.UnpatchSelf();
}
}
}
[HarmonyPatch]
public static class CanPocketAlwaysTrue
{
private static IEnumerable<MethodBase> TargetMethods()
{
Type item = AccessTools.TypeByName("Item");
if (item != null)
{
MethodInfo m = AccessTools.Method(item, "Interact", (Type[])null, (Type[])null);
if (m != null)
{
yield return m;
}
m = AccessTools.Method(item, "RequestPickup", (Type[])null, (Type[])null);
if (m != null)
{
yield return m;
}
}
Type items = AccessTools.TypeByName("CharacterItems");
if (items != null)
{
MethodInfo m2 = AccessTools.Method(items, "EquipSlot", (Type[])null, (Type[])null);
if (m2 != null)
{
yield return m2;
}
}
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
foreach (CodeInstruction inst in instructions)
{
FieldInfo field = inst.operand as FieldInfo;
if (inst.opcode == OpCodes.Ldfld && field != null && field.Name == "canPocket")
{
yield return new CodeInstruction(OpCodes.Pop, (object)null);
yield return new CodeInstruction(OpCodes.Ldc_I4_1, (object)null);
}
else
{
yield return inst;
}
}
}
}
[HarmonyPatch]
public static class DoSwitching_AllowPocketSticky
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("CharacterItems");
return (!(type == null)) ? AccessTools.Method(type, "DoSwitching", (Type[])null, (Type[])null) : null;
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
foreach (CodeInstruction inst in instructions)
{
FieldInfo field = inst.operand as FieldInfo;
if (inst.opcode == OpCodes.Ldfld && field != null && field.Name == "currentStickyItem")
{
yield return new CodeInstruction(OpCodes.Pop, (object)null);
yield return new CodeInstruction(OpCodes.Ldnull, (object)null);
}
else
{
yield return inst;
}
}
}
}
[HarmonyPatch]
public static class EquipSlot_UnstickThenPocket
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("CharacterItems");
return (!(type == null)) ? AccessTools.Method(type, "EquipSlot", (Type[])null, (Type[])null) : null;
}
private static void Prefix(object __instance)
{
if (Plugin.EnableAlwaysStore == null || !Plugin.EnableAlwaysStore.Value)
{
return;
}
try
{
FieldInfo fieldInfo = AccessTools.Field(__instance.GetType(), "character");
if (fieldInfo == null)
{
return;
}
object value = fieldInfo.GetValue(__instance);
if (value == null)
{
return;
}
FieldInfo fieldInfo2 = AccessTools.Field(value.GetType(), "data");
if (fieldInfo2 == null)
{
return;
}
object value2 = fieldInfo2.GetValue(value);
if (value2 == null)
{
return;
}
FieldInfo fieldInfo3 = AccessTools.Field(value2.GetType(), "currentStickyItem");
if (fieldInfo3 == null)
{
return;
}
object value3 = fieldInfo3.GetValue(value2);
if (value3 != null)
{
MethodInfo methodInfo = AccessTools.Method(value3.GetType(), "Unstick", (Type[])null, (Type[])null);
if (methodInfo != null)
{
methodInfo.Invoke(value3, null);
}
fieldInfo3.SetValue(value2, null);
}
}
catch
{
}
}
}
[HarmonyPatch]
public static class EmoteAnywhereTranspiler
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("GUIManager");
return (!(type == null)) ? AccessTools.Method(type, "UpdateEmoteWheel", (Type[])null, (Type[])null) : null;
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
foreach (CodeInstruction inst in instructions)
{
FieldInfo field = inst.operand as FieldInfo;
if (inst.opcode == OpCodes.Ldfld && field != null && field.Name == "isClimbing")
{
yield return new CodeInstruction(OpCodes.Pop, (object)null);
yield return new CodeInstruction(OpCodes.Ldc_I4_0, (object)null);
}
else
{
yield return inst;
}
}
}
}