using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BardsTheftMod.Patches;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("BardsTheftMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Allows you to pickup Pre-Built Items from a time long past")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BardsTheftMod")]
[assembly: AssemblyTitle("BardsTheftMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 BardsTheftMod
{
[BepInPlugin("BardicNick.BardsTheftMod", "Bard's Theft Mod", "0.2.0")]
public class BardsTheftMod : BaseUnityPlugin
{
private static Harmony _harmony = new Harmony("BardsTheftMod");
public void Awake()
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin BardsTheftMod is loading!");
MethodInfo method = typeof(PreBuiltMachine).GetMethod("BuildMe");
MethodInfo method2 = typeof(BuildMePatch).GetMethod("Transpiler");
_harmony.Patch((MethodBase)method, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null);
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "BardsTheftMod";
public const string PLUGIN_NAME = "BardsTheftMod";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace BardsTheftMod.Patches
{
[HarmonyPatch(typeof(PreBuiltMachine), "BuildMe")]
public static class BuildMePatch
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator ilGenerator)
{
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Expected O, but got Unknown
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Expected O, but got Unknown
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Expected O, but got Unknown
ManualLogSource val = Logger.CreateLogSource("BardsTheftModFtCow | PreBuiltMachine.BuildMe() Transpiler");
val.LogInfo((object)"Starting Enumeration...");
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count - 1; i++)
{
if (list[i].opcode == OpCodes.Call && list[i - 1].opcode == OpCodes.Brfalse && list[i - 2].opcode == OpCodes.Ldfld && list[i - 3].opcode == OpCodes.Ldarg_0 && list[i - 2].operand.Equals(AccessTools.Field(typeof(PreBuiltMachine), "protectionStatus")))
{
val.LogInfo((object)$"Found location at {i}! Injecting...");
val.LogInfo((object)"Adding Ldarg_0:null...");
list.Insert(i, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
val.LogInfo((object)"Adding Ldc_I4_0:null...");
list.Insert(i + 1, new CodeInstruction(OpCodes.Ldc_I4_0, (object)null));
val.LogInfo((object)"Adding Stfld:ProtectionStatus.None...");
list.Insert(i + 2, new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(PreBuiltMachine), "protectionStatus")));
val.LogInfo((object)"Code injected!");
}
}
val.LogInfo((object)"Done!");
Logger.Sources.Remove((ILogSource)(object)val);
return list;
}
}
}