using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Necro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.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;
}
}
}
[BepInPlugin("com.you.necropolis.arcanistfix", "Arcanist Move Set Fallback", "0.2.1")]
public class ArcanistFix : BaseUnityPlugin
{
internal static ManualLogSource Log;
private void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
new Harmony("com.you.necropolis.arcanistfix").PatchAll();
Log.LogInfo((object)"Arcanist fix loaded");
}
}
[HarmonyPatch(typeof(Actor), "GetMoveSet")]
internal static class PatchGetMoveSet
{
private const string ArcanistBody = "arcanist";
private const string DonorBody = "brute";
private static bool inFallback;
private static ActorDef GetDef(Actor actor)
{
Traverse val = Traverse.Create((object)actor);
ActorDef result = null;
if (val.Field("actorDef").FieldExists())
{
result = val.Field("actorDef").GetValue<ActorDef>();
}
else if (val.Property("actorDef", (object[])null).PropertyExists())
{
result = val.Property("actorDef", (object[])null).GetValue<ActorDef>();
}
return result;
}
private static void Prefix(Actor __instance, string moveSet, ref Action<MoveSet> callback)
{
if (inFallback || callback == null)
{
return;
}
ActorDef def = GetDef(__instance);
if (def == null || def.moveSetBody != "arcanist")
{
return;
}
Action<MoveSet> original = callback;
callback = delegate(MoveSet found)
{
if ((Object)(object)found != (Object)null)
{
original(found);
return;
}
ArcanistFix.Log.LogInfo((object)("No '" + moveSet + "' for arcanist, using brute"));
string moveSetBody = def.moveSetBody;
inFallback = true;
try
{
def.moveSetBody = "brute";
AccessTools.Method(typeof(Actor), "GetMoveSet", (Type[])null, (Type[])null).Invoke(__instance, new object[2] { moveSet, original });
}
finally
{
def.moveSetBody = moveSetBody;
inFallback = false;
}
};
}
}