using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.AI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Erenshor-PvP-Mod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Erenshor-PvP-Mod")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a13976a9-69d8-401e-95e2-fbd13a04556e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ErenshorPVPMode;
[BepInPlugin("com.Reckss.pvpmode", "Erenshor PvP Mode", "1.0.1")]
public class PvPModePlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(Character), "DamageMe")]
private static class Patch_DamageMe
{
private static bool Prefix(Character __instance, ref bool _fromPlayer)
{
if (!Instance.modEnabled.Value)
{
return true;
}
SimPlayer component = ((Component)__instance).GetComponent<SimPlayer>();
if ((Object)(object)component != (Object)null)
{
if ((Object)(object)GameData.SimPlayerGrouping != (Object)null && GameData.SimPlayerGrouping.IsSimInPlayerGroup(component))
{
return false;
}
_fromPlayer = false;
}
return true;
}
private static void Postfix(Character __instance, int __result)
{
if (__result <= 0 || !Instance.modEnabled.Value)
{
return;
}
SimPlayer component = ((Component)__instance).GetComponent<SimPlayer>();
if ((Object)(object)component == (Object)null || ((Object)(object)GameData.SimPlayerGrouping != (Object)null && GameData.SimPlayerGrouping.IsSimInPlayerGroup(component)))
{
return;
}
NPC component2 = ((Component)component).GetComponent<NPC>();
if (!((Object)(object)component2 == (Object)null) && !component2.SummonedByPlayer)
{
Character myself = GameData.PlayerControl.Myself;
component2.AggroOn(myself);
if (inCombat.Add(component))
{
((MonoBehaviour)Instance).StartCoroutine(Instance.SimCombatLoop(component, myself));
}
}
}
}
[HarmonyPatch(typeof(Character), "MagicDamageMe")]
private static class Patch_MagicDamageMe
{
private static bool Prefix(Character __instance, ref bool _fromPlayer)
{
if (!Instance.modEnabled.Value)
{
return true;
}
SimPlayer component = ((Component)__instance).GetComponent<SimPlayer>();
if ((Object)(object)component != (Object)null)
{
if ((Object)(object)GameData.SimPlayerGrouping != (Object)null && GameData.SimPlayerGrouping.IsSimInPlayerGroup(component))
{
return false;
}
_fromPlayer = false;
}
return true;
}
private static void Postfix(Character __instance, int __result)
{
if (__result <= 0 || !Instance.modEnabled.Value)
{
return;
}
SimPlayer component = ((Component)__instance).GetComponent<SimPlayer>();
if ((Object)(object)component == (Object)null || ((Object)(object)GameData.SimPlayerGrouping != (Object)null && GameData.SimPlayerGrouping.IsSimInPlayerGroup(component)))
{
return;
}
NPC component2 = ((Component)component).GetComponent<NPC>();
if (!((Object)(object)component2 == (Object)null) && !component2.SummonedByPlayer)
{
Character myself = GameData.PlayerControl.Myself;
component2.AggroOn(myself);
if (inCombat.Add(component))
{
((MonoBehaviour)Instance).StartCoroutine(Instance.SimCombatLoop(component, myself));
}
}
}
}
[HarmonyPatch(typeof(SimPlayer), "Update")]
private static class Patch_SimPlayer_Update
{
private static bool Prefix(SimPlayer __instance)
{
if (Instance.modEnabled.Value && inCombat.Contains(__instance))
{
return false;
}
return true;
}
}
[CompilerGenerated]
private sealed class <SimCombatLoop>d__7 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public SimPlayer sim;
public Character threat;
public PvPModePlugin <>4__this;
private Character <charComp>5__1;
private NPC <npc>5__2;
private NavMeshAgent <agent>5__3;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SimCombatLoop>d__7(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<charComp>5__1 = null;
<npc>5__2 = null;
<agent>5__3 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Expected O, but got Unknown
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<charComp>5__1 = ((Component)sim).GetComponent<Character>();
<npc>5__2 = ((Component)sim).GetComponent<NPC>();
<agent>5__3 = ((Component)sim).GetComponent<NavMeshAgent>();
if ((Object)(object)<charComp>5__1 == (Object)null || (Object)(object)<npc>5__2 == (Object)null)
{
return false;
}
break;
case 1:
<>1__state = -1;
break;
}
if (inCombat.Contains(sim) && <charComp>5__1.MyStats.CurrentHP > 0 && threat.MyStats.CurrentHP > 0 && <>4__this.modEnabled.Value)
{
<npc>5__2.AggroOn(threat);
if ((Object)(object)<agent>5__3 != (Object)null && ((Behaviour)<agent>5__3).enabled)
{
<agent>5__3.SetDestination(((Component)threat).transform.position);
}
<>2__current = (object)new WaitForSeconds(0.2f);
<>1__state = 1;
return true;
}
inCombat.Remove(sim);
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
internal static PvPModePlugin Instance;
private ConfigEntry<bool> modEnabled;
private static readonly HashSet<SimPlayer> inCombat = new HashSet<SimPlayer>();
private void Awake()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
Instance = this;
modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Toggle PvP mode (F5)");
Harmony val = new Harmony("com.Reckss.pvpmode");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)("PvP Mode loaded. Currently " + (modEnabled.Value ? "Enabled" : "Disabled") + "."));
}
private void Update()
{
if (Input.GetKeyDown((KeyCode)286))
{
modEnabled.Value = !modEnabled.Value;
string text = "PvP Mode " + (modEnabled.Value ? "Enabled" : "Disabled");
((BaseUnityPlugin)this).Logger.LogInfo((object)text);
UpdateSocialLog.LogAdd(text, "yellow");
}
}
[IteratorStateMachine(typeof(<SimCombatLoop>d__7))]
private IEnumerator SimCombatLoop(SimPlayer sim, Character threat)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SimCombatLoop>d__7(0)
{
<>4__this = this,
sim = sim,
threat = threat
};
}
}