using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
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("RemoveRaidIcon")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RemoveRaidIcon")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("67f40cdf-9038-4a7d-b7a1-fdc9567f1a85")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.1", FrameworkDisplayName = ".NET Framework 4.6.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ValphPvPTweaks
{
internal class CircularQueue<T> : Queue<T>
{
private int capacity;
public CircularQueue(int capacity)
: base(capacity)
{
this.capacity = capacity;
}
public new void Enqueue(T item)
{
if (this.Count() >= capacity)
{
Dequeue();
}
base.Enqueue(item);
}
}
internal class Constants
{
internal const string InCombatZdoKey = "VPT_PlayerInCombat";
internal const string CharacterDeadRpc = "VPT_CharacterDeadRpc";
}
public static class Extensions
{
public static bool InCombat(this Player player)
{
return (Object)(object)((Character)player).m_nview != (Object)null && ((Character)player).m_nview.IsValid() && ((Character)player).m_nview.GetZDO().GetBool("VPT_PlayerInCombat", false);
}
public static ZDO GetZdo(this ZNetPeer peer)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return ZDOMan.instance.GetZDO(peer.m_characterID);
}
public static bool InCombat(this ZNetPeer peer)
{
ZDO zdo = peer.GetZdo();
return zdo != null && zdo.GetBool("VPT_PlayerInCombat", false);
}
}
[BepInPlugin("pvptweaks.valph", "valPHPvPTweaks", "1.5.1")]
[BepInProcess("valheim.exe")]
public class valphpvptweaks : BaseUnityPlugin
{
[HarmonyPatch(typeof(Minimap), "UpdateEventPin")]
private class Minimap_UpdateEventPin_Patch
{
private static void Postfix(Minimap __instance, ref PinData ___m_randEventAreaPin, ref PinData ___m_randEventPin)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Invalid comparison between Unknown and I4
if (___m_randEventAreaPin != null && (int)___m_randEventAreaPin.m_type == 13)
{
__instance.RemovePin(___m_randEventAreaPin);
__instance.RemovePin(___m_randEventPin);
}
}
}
[HarmonyPatch(typeof(Chat), "SendText")]
public class HideShoutPing
{
private static void Prefix(ref Vector3 __state)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
{
__state = ((Character)Player.m_localPlayer).m_head.position;
((Character)Player.m_localPlayer).m_head.position = default(Vector3);
}
}
private static void Postfix(Vector3 __state)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
{
((Character)Player.m_localPlayer).m_head.position = __state;
}
}
}
[HarmonyPatch(typeof(Character))]
private class CharacterPatch
{
[HarmonyPrefix]
[HarmonyPatch("ApplyDamage")]
private static void ApplyDamagePrefix(Character __instance, HitData hit)
{
if (!((Object)(object)__instance == (Object)(object)Player.m_localPlayer))
{
return;
}
Character attacker = hit.GetAttacker();
if (Object.op_Implicit((Object)(object)attacker) && attacker.IsPlayer())
{
Player val = (Player)(object)((attacker is Player) ? attacker : null);
if ((Object)(object)val != (Object)null)
{
string playerName = val.GetPlayerName();
float bodyArmor = ((Character)val).GetBodyArmor();
float stamina = val.GetStamina();
valphLogger.LogInfo((object)$"Hit by {playerName} | Hit Damage: {hit.GetTotalDamage()}");
}
}
recentHitQueue.Enqueue(hit);
}
}
[HarmonyPatch(typeof(Player), "CreateTombStone")]
private static class PatchItemLoss
{
[HarmonyPriority(700)]
private static void Prefix(Player __instance, out Dictionary<ItemData, bool> __state)
{
List<ItemData> list = new List<ItemData>();
List<ItemData> list2 = new List<ItemData>();
__state = new Dictionary<ItemData, bool>();
foreach (ItemData item in ((Humanoid)__instance).m_inventory.m_inventory)
{
string text = ((item.m_gridPos.y == 0) ? "hotbar" : "inventory");
bool equipped = item.m_equipped;
if (isPvpDeath() && text == "hotbar")
{
__state.Add(item, item.m_equipped);
}
else if (equipped && isPvpDeath())
{
__state.Add(item, item.m_equipped);
}
else
{
list.Add(item);
}
}
((Humanoid)__instance).m_inventory.m_inventory = list;
}
[HarmonyPriority(100)]
private static void Postfix(Player __instance, Dictionary<ItemData, bool> __state)
{
foreach (KeyValuePair<ItemData, bool> item in __state)
{
((Humanoid)__instance).m_inventory.m_inventory.Add(item.Key);
if (item.Value)
{
((Humanoid)__instance).EquipItem(item.Key, false);
}
}
((Humanoid)__instance).m_inventory.Changed();
}
}
[HarmonyPatch(typeof(Skills), "OnDeath")]
private static class SkillsOnDeathPatch
{
private static bool Prefix(Skills __instance)
{
return !isPvpDeath();
}
}
[HarmonyPatch(typeof(Terminal), "updateBinds")]
public static class Patch_Bind_Command
{
public static bool Prefix()
{
return false;
}
}
private static CircularQueue<HitData> recentHitQueue = new CircularQueue<HitData>(3);
private static List<string> typeEnums = new List<string>();
private const string ModName = "valPHPvPTweaks";
public static readonly ManualLogSource valphLogger = Logger.CreateLogSource("valPHPvPTweaks");
private void Awake()
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
foreach (int value in Enum.GetValues(typeof(ItemType)))
{
typeEnums.Add(Enum.GetName(typeof(ItemType), value));
}
Harmony val = new Harmony("valPHPvPTweaks");
val.PatchAll();
}
private static bool isPvpDeath()
{
foreach (HitData item in recentHitQueue)
{
Character attacker = item.GetAttacker();
if (Object.op_Implicit((Object)(object)attacker) && attacker.IsPlayer())
{
Player val = (Player)(object)((attacker is Player) ? attacker : null);
if ((Object)(object)val != (Object)null)
{
string playerName = val.GetPlayerName();
return true;
}
}
}
return false;
}
}
}
namespace ValphPvPTweaks.statuseffect
{
[HarmonyPatch]
internal class Patches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(Player), "OnSpawned")]
private static void Player_OnSpawned(Player __instance)
{
((Component)__instance).gameObject.AddComponent<PlayerCombatHandler>();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(ObjectDB), "Awake")]
private static void ObjectDB_Awake(ObjectDB __instance)
{
__instance.m_StatusEffects.Add((StatusEffect)(object)SE_Combat.Create());
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Game), "Start")]
private static void Game_Start()
{
StatusEffect statusEffect = ObjectDB.instance.GetStatusEffect(StringExtensionMethods.GetStableHashCode("SE_Combat"));
statusEffect.m_icon = ((Component)InventoryGui.instance.m_pvp).GetComponent<ToggleImage>().m_onImage;
}
}
internal class PlayerCombatHandler : MonoBehaviour
{
private const string EnterCombatRpc = "EnterCombatRpc";
private Player _player;
private void Awake()
{
_player = ((Component)this).GetComponent<Player>();
((Character)_player).m_onDamaged = (Action<float, Character>)Delegate.Combine(((Character)_player).m_onDamaged, new Action<float, Character>(OnDamaged));
if ((Object)(object)((Character)_player).m_nview != (Object)null && ((Character)_player).m_nview.IsValid())
{
((Character)_player).m_nview.Register("EnterCombatRpc", (Action<long>)OnEnteredPvpMode);
}
}
private void OnDamaged(float damage, Character character)
{
if (!(damage <= 0f) && !((Object)(object)character == (Object)null) && character.IsPlayer())
{
OnEnteredPvpMode(0L);
character.m_nview.InvokeRPC("EnterCombatRpc", Array.Empty<object>());
}
}
private void OnEnteredPvpMode(long obj)
{
((Character)_player).GetSEMan().AddStatusEffect(StringExtensionMethods.GetStableHashCode("SE_Combat"), true, 0, 0f);
}
public static void EnterCombat(Character character)
{
if ((Object)(object)character != (Object)null && (Object)(object)character.m_nview != (Object)null && character.m_nview.IsValid())
{
character.m_nview.InvokeRPC("EnterCombatRpc", Array.Empty<object>());
}
}
}
internal class SE_Combat : SE_Stats
{
public const string Name = "SE_Combat";
public override bool CanAdd(Character character)
{
return character.IsPlayer();
}
public override void Setup(Character character)
{
((SE_Stats)this).Setup(character);
base.m_healthRegenMultiplier = 1f;
((StatusEffect)this).m_ttl = 120f;
ZNetView nview = ((StatusEffect)this).m_character.m_nview;
if (nview != null)
{
ZDO zDO = nview.GetZDO();
if (zDO != null)
{
zDO.Set("VPT_PlayerInCombat", true);
}
}
}
public override void Stop()
{
((StatusEffect)this).Stop();
if (Game.instance.IsShuttingDown())
{
return;
}
ZNetView nview = ((StatusEffect)this).m_character.m_nview;
if (nview != null)
{
ZDO zDO = nview.GetZDO();
if (zDO != null)
{
zDO.Set("VPT_PlayerInCombat", false);
}
}
}
public static SE_Combat Create()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
SE_Combat sE_Combat = ScriptableObject.CreateInstance<SE_Combat>();
((Object)sE_Combat).name = "SE_Combat";
((StatusEffect)sE_Combat).m_name = "Battle";
((StatusEffect)sE_Combat).m_startMessage = "Combat has begun!";
((StatusEffect)sE_Combat).m_startMessageType = (MessageType)2;
((StatusEffect)sE_Combat).m_stopMessage = "Combat has begun";
((StatusEffect)sE_Combat).m_stopMessageType = (MessageType)1;
return sE_Combat;
}
}
}