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 BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
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("ReforgeUniques")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ReforgeUniques")]
[assembly: AssemblyTitle("ReforgeUniques")]
[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 ReforgeUniques
{
[BepInPlugin("com.fizzy.reforgeuniques", "ReforgeUniques", "1.0.0")]
public class ReforgeUniques : BaseUnityPlugin
{
public static ConfigEntry<int> uniqueRerollCost;
private void Awake()
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
((ConfigEntry<bool>)AccessTools.Field(typeof(Chainloader), "ConfigHideBepInExGOs").GetValue(null)).Value = true;
uniqueRerollCost = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Uniques reforge cost", 15, new ConfigDescription("How many coins should reforging a unique spell cost", (AcceptableValueBase)null, Array.Empty<object>()));
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"ReforgeUniques has been loaded");
}
}
[HarmonyPatch]
public static class PatchUniques
{
[HarmonyPrefix]
[HarmonyPatch(typeof(UIReroll), "_Reroll")]
private static bool PrefixReroll(UIReroll __instance)
{
MethodInfo method = typeof(UIReroll).GetMethod("CheckCost", BindingFlags.Instance | BindingFlags.NonPublic);
int num = (int)typeof(UIReroll).GetMethod("GetCost", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(__instance, null);
if (PlayerMgr.Inst.CoinCount <= num)
{
method?.Invoke(__instance, null);
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(UIReroll), "GetCost")]
private static bool PrefixGetCost(UIReroll __instance, ref int __result)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Invalid comparison between Unknown and I4
MethodInfo methodInfo = AccessTools.PropertyGetter(typeof(UIReroll), "SelectedUIRS");
UIReroll_Spell val = (UIReroll_Spell)methodInfo.Invoke(__instance, null);
SpellConfig val2 = SpellConfig.dic[val.SpellID];
if ((int)val2.dropType == 4)
{
__result = ReforgeUniques.uniqueRerollCost.Value;
return false;
}
return true;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(SlotData), "GetAdditionalInfo")]
public static IEnumerable<CodeInstruction> TranspilerAddInfo(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
bool flag = false;
for (int i = 0; i < list.Count - 5; i++)
{
if (list[i].opcode == OpCodes.Ldstr && (string)list[i].operand == "◆\u00a0\u200a" && list[i + 1].opcode == OpCodes.Ldc_I4 && (int)list[i + 1].operand == 1002707)
{
list[i + 1].operand = 1002705;
flag = true;
break;
}
}
if (!flag)
{
Debug.Log((object)"Failed to find the target pattern in GetAdditionalInfo method");
}
return list;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIReroll), "_Reroll")]
public static IEnumerable<CodeInstruction> TranspilerReroll(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
bool flag = false;
for (int i = 0; i < list.Count - 5; i++)
{
if (list[i].opcode == OpCodes.Ldarg_0 && list[i + 1].opcode == OpCodes.Call && list[i + 1].operand.ToString().Contains("SelectedSpellCfg") && list[i + 2].opcode == OpCodes.Ldfld && list[i + 2].operand.ToString().Contains("dropType") && list[i + 3].opcode == OpCodes.Ldc_I4_4)
{
for (int j = i; j <= i + 5; j++)
{
list[j].opcode = OpCodes.Nop;
list[j].operand = null;
}
flag = true;
break;
}
}
if (!flag)
{
Debug.LogWarning((object)"Failed to find the target pattern in _Reroll method");
}
return list;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(BattleMgr), "ProcessPlayerEnterDoorAfterEffects")]
[HarmonyPatch(typeof(PlayerItemController), "PotionUse")]
private static IEnumerable<CodeInstruction> TranspilerEnterDoor(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
bool flag = false;
for (int i = 0; i < list.Count - 3; i++)
{
if ((list[i].opcode == OpCodes.Ldloc_3 || list[i].opcode == OpCodes.Ldloc_S) && list[i + 1].opcode == OpCodes.Ldfld && ((FieldInfo)list[i + 1].operand).Name == "dropType" && list[i + 2].opcode == OpCodes.Ldc_I4_4 && list[i + 3].opcode == OpCodes.Beq)
{
for (int j = i; j < i + 4; j++)
{
list[j].opcode = OpCodes.Nop;
list[j].operand = null;
}
flag = true;
break;
}
}
if (!flag)
{
Debug.LogWarning((object)"Failed to find the Special dropType check in ProcessPlayerEnterDoorAfterEffects or PotionUse");
}
return list;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIReroll), "CheckCost")]
private static IEnumerable<CodeInstruction> TranspilerCheckCost(IEnumerable<CodeInstruction> instructions)
{
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
bool flag = false;
for (int i = 0; i < list.Count - 5; i++)
{
if (list[i].opcode == OpCodes.Ldarg_0 && list[i + 1].opcode == OpCodes.Call && ((MethodInfo)list[i + 1].operand).Name == "get_SelectedSpellCfg" && list[i + 2].opcode == OpCodes.Ldfld && ((FieldInfo)list[i + 2].operand).Name == "dropType" && list[i + 3].opcode == OpCodes.Ldc_I4_4)
{
CodeInstruction val = new CodeInstruction(OpCodes.Br_S, list[i + 4].operand);
val.labels.AddRange(list[i].labels);
list[i] = val;
flag = true;
break;
}
}
if (!flag)
{
Debug.LogWarning((object)"Failed to find the Special spell check pattern in CheckCost");
}
return list;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIRelic_RestartKey), "CreateLevelFinish")]
private static IEnumerable<CodeInstruction> TranspilerRerollKey(IEnumerable<CodeInstruction> instructions)
{
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
bool flag = false;
for (int i = 0; i < list.Count - 8; i++)
{
if (list[i].opcode == OpCodes.Ldsfld && ((FieldInfo)list[i].operand).Name == "dic" && list[i + 1].opcode == OpCodes.Ldarg_0 && list[i + 2].opcode == OpCodes.Ldfld && (((FieldInfo)list[i + 2].operand).Name == "wandSpellIDs" || ((FieldInfo)list[i + 2].operand).Name == "bagSpellIDs") && list[i + 3].opcode == OpCodes.Ldloc_S && list[i + 4].opcode == OpCodes.Callvirt && ((MethodInfo)list[i + 4].operand).Name == "get_Item" && list[i + 5].opcode == OpCodes.Callvirt && ((MethodInfo)list[i + 5].operand).Name == "get_Item" && list[i + 6].opcode == OpCodes.Ldfld && ((FieldInfo)list[i + 6].operand).Name == "dropType" && list[i + 7].opcode == OpCodes.Ldc_I4_4)
{
CodeInstruction val = new CodeInstruction(OpCodes.Br_S, list[i + 8].operand);
val.labels.AddRange(list[i].labels);
list[i] = val;
flag = true;
}
}
if (!flag)
{
Debug.LogWarning((object)"Failed to find either of the Special spell check patterns in CreateLevelFinish");
}
return list;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "ReforgeUniques";
public const string PLUGIN_NAME = "ReforgeUniques";
public const string PLUGIN_VERSION = "1.0.0";
}
}