using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CellMenu;
using GTFO.API.Utilities;
using Gear;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SNetwork;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MeleeFriendlyFire")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MeleeFriendlyFire")]
[assembly: AssemblyTitle("MeleeFriendlyFire")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace MeleeFriendlyFire
{
internal static class CorePatches
{
private static readonly int MASK_PLAYER_SYNCED = (int)Math.Pow(2.0, LayerManager.LAYER_PLAYER_SYNCED);
private static readonly float DEFAULT_DAMAGE_MULTI = 0.125f;
private static bool enableMeleeFriendlyFire = false;
internal static void UpdateMasks()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Invalid comparison between Unknown and I4
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Invalid comparison between Unknown and I4
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
if ((int)ConfigManager.keybindHold.Value > 0)
{
enableMeleeFriendlyFire = Input.GetKey(ConfigManager.keybindHold.Value);
ConfigManager.keybindToggle.Value = (KeyCode)0;
}
else if ((int)ConfigManager.keybindToggle.Value > 0)
{
if (Input.GetKeyDown(ConfigManager.keybindToggle.Value))
{
enableMeleeFriendlyFire = !enableMeleeFriendlyFire;
string text = (enableMeleeFriendlyFire ? "ON" : "OFF");
Utils.SendLocalMessage("MeleeFriendlyFire " + text);
}
}
else
{
enableMeleeFriendlyFire = true;
}
if (enableMeleeFriendlyFire)
{
LayerManager.MASK_MELEE_ATTACK_TARGETS |= MASK_PLAYER_SYNCED;
LayerManager.MASK_MELEE_ATTACK_TARGETS_WITH_STATIC |= MASK_PLAYER_SYNCED;
}
else
{
LayerManager.MASK_MELEE_ATTACK_TARGETS &= ~MASK_PLAYER_SYNCED;
LayerManager.MASK_MELEE_ATTACK_TARGETS_WITH_STATIC &= ~MASK_PLAYER_SYNCED;
}
}
[HarmonyPatch(typeof(MeleeWeaponFirstPerson), "DoAttackDamage")]
[HarmonyPrefix]
private static void DoAttackDamage_Prefix(MeleeWeaponFirstPerson __instance, ref MeleeWeaponDamageData data)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
if (data.damageGO != null && CustomExtensions.IsInLayerMask(data.damageGO, LayerMask.op_Implicit(MASK_PLAYER_SYNCED)))
{
__instance.m_damageToDeal *= DEFAULT_DAMAGE_MULTI;
}
}
[HarmonyPatch(typeof(MeleeWeaponFirstPerson), "DoAttackDamage")]
[HarmonyPostfix]
private static void DoAttackDamage_Postfix(MeleeWeaponFirstPerson __instance, ref MeleeWeaponDamageData data)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
if (data.damageGO != null && CustomExtensions.IsInLayerMask(data.damageGO, LayerMask.op_Implicit(MASK_PLAYER_SYNCED)))
{
__instance.m_damageToDeal /= DEFAULT_DAMAGE_MULTI;
}
}
[HarmonyPatch(typeof(Dam_PlayerDamageBase), "ReceiveMeleeDamage")]
[HarmonyPrefix]
private static void ReceiveMeleeDamage_Prefix(Dam_PlayerDamageBase __instance, ref pFullDamageData data)
{
IReplicator val = default(IReplicator);
((pReplicator)(ref data.source.pRep)).TryGetID(ref val);
if (val.OwningPlayer != null && SNet.IsMaster)
{
((UFloat16)(ref data.damage)).Set(((UFloat16)(ref data.damage)).Get(((Dam_SyncedDamageBase)__instance).HealthMax) / DEFAULT_DAMAGE_MULTI * ConfigManager.damageMulti.Value, ((Dam_SyncedDamageBase)__instance).HealthMax);
}
}
}
internal static class GameLogPatches
{
[HarmonyPatch(typeof(Dam_PlayerDamageBase), "ReceiveMeleeDamage")]
[HarmonyPostfix]
private static void ReceiveMeleeDamage_Postfix(Dam_PlayerDamageBase __instance, ref pFullDamageData data)
{
if (ConfigManager.printBoppedMsg.Value)
{
IReplicator val = default(IReplicator);
((pReplicator)(ref data.source.pRep)).TryGetID(ref val);
if (val.OwningPlayer != null)
{
Utils.SendLocalMessage(PlayerNameExtentions.GetColoredName(val.OwningPlayer, (string)null) + " bopped " + PlayerNameExtentions.GetColoredName(__instance.Owner, (string)null));
}
}
}
}
internal static class PluginInfo
{
public const string GUID = "Andocas.MeleeFriendlyFire";
public const string NAME = "MeleeFriendlyFire";
public const string VERSION = "0.3.0";
}
[BepInPlugin("Andocas.MeleeFriendlyFire", "MeleeFriendlyFire", "0.3.0")]
internal class Plugin : BasePlugin
{
private class UnityPlugin : MonoBehaviour
{
private void Update()
{
CorePatches.UpdateMasks();
}
}
public override void Load()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
Utils.LogInfo("Andocas.MeleeFriendlyFire is loading...");
Harmony val = new Harmony("Andocas.MeleeFriendlyFire");
val.PatchAll(typeof(CorePatches));
val.PatchAll(typeof(GameLogPatches));
((BasePlugin)this).AddComponent<UnityPlugin>();
Utils.LogInfo("Andocas.MeleeFriendlyFire is loaded");
}
}
internal static class ConfigManager
{
private static ConfigFile configFile;
public static ConfigEntry<bool> printBoppedMsg;
public static ConfigEntry<float> damageMulti;
public static ConfigEntry<KeyCode> keybindHold;
public static ConfigEntry<KeyCode> keybindToggle;
static ConfigManager()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Expected O, but got Unknown
configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "MeleeFriendlyFire.cfg"), true);
printBoppedMsg = configFile.Bind<bool>("General", "Bopped message", true, "See a message like \"Player1 bopped Player2\" when someone is meleed.");
damageMulti = configFile.Bind<float>("Host Settings", "Damage multiplier", 0.125f, "Set the damage multiplier for all melee friendly fire in the lobby. (For one-tap, set to a large number like 99.)");
keybindToggle = configFile.Bind<KeyCode>("Keybinds", "Toggle", (KeyCode)0, "Toggle melee friendly fire on/off. (Overridden by \"Hold\" keybind.)");
keybindHold = configFile.Bind<KeyCode>("Keybinds", "Hold", (KeyCode)0, "Only enable melee friendly fire while this key is held down. (Overrides \"Toggle\" keybind.)");
LiveEditListener val = LiveEdit.CreateListener(Paths.ConfigPath, "MeleeFriendlyFire.cfg", false);
val.FileChanged += (LiveEditEventHandler)delegate
{
configFile.Reload();
};
}
}
internal static class Utils
{
private static readonly ManualLogSource logger = Logger.CreateLogSource("Andocas.MeleeFriendlyFire");
public static void LogInfo(object? o)
{
logger.LogInfo((object)GetMessage(o));
}
public static void LogError(object? o)
{
logger.LogError((object)GetMessage(o));
}
private static string GetMessage(object? o)
{
if (o == null)
{
return "No string representation for <null>";
}
return o.ToString() ?? $"No string representation for <{o.GetType()}>";
}
public static void SendLocalMessage(string text)
{
LogInfo("SendLocalMessage: " + text);
GuiManager.PlayerLayer.m_gameEventLog.AddLogItem(text, (eGameEventChatLogType)2);
CM_PageLoadout.Current.m_gameEventLog.AddLogItem(text, (eGameEventChatLogType)2);
}
}
}