using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Magic Tweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Magic Tweaks")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d4029118-85db-4a09-adac-3f6abf34709f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MagicTweak;
[BepInPlugin("gaakrin.magictweaks", "Magic Tweaks", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony val = new Harmony("gaakrin.magictweaks");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Magic Tweaks loaded");
}
}
[HarmonyPatch(typeof(ObjectDB), "Awake")]
public static class ObjectDB_Awake_Patch
{
private static void Postfix(ObjectDB __instance)
{
try
{
GameObject itemPrefab = __instance.GetItemPrefab("StaffFireball");
GameObject itemPrefab2 = __instance.GetItemPrefab("StaffShield");
GameObject itemPrefab3 = __instance.GetItemPrefab("StaffRedTroll");
GameObject itemPrefab4 = __instance.GetItemPrefab("StaffSkeleton");
GameObject itemPrefab5 = __instance.GetItemPrefab("StaffIceShards");
if ((Object)(object)itemPrefab == (Object)null || (Object)(object)itemPrefab2 == (Object)null || (Object)(object)itemPrefab3 == (Object)null || (Object)(object)itemPrefab4 == (Object)null || (Object)(object)itemPrefab5 == (Object)null)
{
Debug.LogWarning((object)"[Magic Tweaks] One or more prefabs not found");
return;
}
ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
ItemDrop component2 = itemPrefab2.GetComponent<ItemDrop>();
ItemDrop component3 = itemPrefab3.GetComponent<ItemDrop>();
ItemDrop component4 = itemPrefab4.GetComponent<ItemDrop>();
ItemDrop component5 = itemPrefab5.GetComponent<ItemDrop>();
if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null || (Object)(object)component3 == (Object)null || (Object)(object)component4 == (Object)null || (Object)(object)component5 == (Object)null)
{
Debug.LogWarning((object)"[Magic Tweaks] One or more ItemDrop components missing");
return;
}
Attack val = component2.m_itemData.m_shared.m_attack.Clone();
Attack val2 = component2.m_itemData.m_shared.m_attack.Clone();
Attack val3 = component3.m_itemData.m_shared.m_attack.Clone();
val.m_damageMultiplier = 0f;
val.m_forceMultiplier = 0f;
val.m_staggerMultiplier = 0f;
val.m_attackHitNoise = 0f;
val2.m_damageMultiplier = 0f;
val2.m_forceMultiplier = 0f;
val2.m_staggerMultiplier = 0f;
val2.m_attackHitNoise = 0f;
val3.m_attackAnimation = component4.m_itemData.m_shared.m_attack.m_attackAnimation;
component.m_itemData.m_shared.m_secondaryAttack = val;
component5.m_itemData.m_shared.m_secondaryAttack = val2;
component4.m_itemData.m_shared.m_secondaryAttack = val3;
Debug.Log((object)"[Magic Tweaks] Secondary attacks applied");
}
catch (Exception ex)
{
Debug.LogError((object)ex);
}
}
}
[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
public static class Attack_OnAttackTrigger_Patch
{
[HarmonyPostfix]
public static void Postfix(Attack __instance)
{
Humanoid value = Traverse.Create((object)__instance).Field("m_character").GetValue<Humanoid>();
Player val = (Player)(object)((value is Player) ? value : null);
if ((Object)(object)val == (Object)null)
{
return;
}
ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon();
if (currentWeapon == null)
{
return;
}
Attack secondaryAttack = currentWeapon.m_shared.m_secondaryAttack;
if (secondaryAttack != null && !(__instance.m_attackAnimation != secondaryAttack.m_attackAnimation) && (currentWeapon.m_shared.m_name == "$item_stafffireball" || currentWeapon.m_shared.m_name == "$item_stafficeshards"))
{
int hashCode = "Staff_shield".GetHashCode();
StatusEffect statusEffect = ObjectDB.instance.GetStatusEffect(hashCode);
if (!((Object)(object)statusEffect == (Object)null))
{
((Character)val).GetSEMan().AddStatusEffect(statusEffect, true, 0, 0f);
}
}
}
}