using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Agents;
using Il2CppInterop.Runtime.InteropTypes;
using Player;
using SNetwork;
using TheArchive.Core;
using TheArchive.Core.Attributes;
using TheArchive.Core.Attributes.Feature.Settings;
using TheArchive.Core.FeaturesAPI;
using TheArchive.Core.Localization;
using TheArchive.Interfaces;
using TheArchive.Loader;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Hikaria.ReverseFriendlyFire")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Hikaria.ReverseFriendlyFire")]
[assembly: AssemblyTitle("Hikaria.ReverseFriendlyFire")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Hikaria.ReverseFriendlyFire
{
[ArchiveModule("Hikaria.ReverseFriendlyFire", "ReverseFriendlyFire", "1.2.0")]
public class EntryPoint : IArchiveModule
{
public static EntryPoint Instance { get; private set; }
public bool ApplyHarmonyPatches => false;
public bool UsesLegacyPatches => false;
public ArchiveLegacyPatcher Patcher { get; set; }
public string ModuleGroup => "Reverse Friendly Fire";
public Dictionary<Language, string> ModuleGroupLanguages => new Dictionary<Language, string>
{
{
(Language)1,
"反伤"
},
{
(Language)0,
"Reverse Friendly Fire"
}
};
public void Init()
{
Instance = this;
Logs.LogMessage("OK");
}
public void OnSceneWasLoaded(int buildIndex, string sceneName)
{
}
public void OnLateUpdate()
{
}
public void OnExit()
{
}
}
internal static class Logs
{
private static IArchiveLogger _logger;
private static IArchiveLogger Logger => _logger ?? (_logger = LoaderWrapper.CreateLoggerInstance("Hikaria.ReverseFriendlyFire", ConsoleColor.White));
public static void LogDebug(object data)
{
Logger.Debug(data.ToString());
}
public static void LogError(object data)
{
Logger.Error(data.ToString());
}
public static void LogInfo(object data)
{
Logger.Info(data.ToString());
}
public static void LogMessage(object data)
{
Logger.Msg(ConsoleColor.White, data.ToString());
}
public static void LogWarning(object data)
{
Logger.Warning(data.ToString());
}
public static void LogNotice(object data)
{
Logger.Notice(data.ToString());
}
public static void LogSuccess(object data)
{
Logger.Success(data.ToString());
}
public static void LogException(Exception ex)
{
Logger.Exception(ex);
}
}
public static class PluginInfo
{
public const string GUID = "Hikaria.ReverseFriendlyFire";
public const string NAME = "ReverseFriendlyFire";
public const string VERSION = "1.2.0";
}
}
namespace Hikaria.ReverseFriendlyFire.Features
{
[EnableFeatureByDefault]
public class ReverseFriendlyFire : Feature
{
public class ReverseFriendlyFireSetting
{
[FSDisplayName("友伤倍率")]
[FSSlider(/*Could not decode attribute arguments.*/)]
public float FFMulti { get; set; }
[FSDisplayName("反伤倍率")]
[FSSlider(/*Could not decode attribute arguments.*/)]
public float ReverseFFMulti { get; set; } = 1f;
[FSDisplayName("反伤致死")]
public bool FFToDeath { get; set; } = true;
}
[ArchivePatch(/*Could not decode attribute arguments.*/)]
private class Dam_PlayerDamageLocal__ReceiveBulletDamage__Patch
{
private static void Prefix(ref pBulletDamageData data)
{
if (!SNet.IsMaster)
{
return;
}
PlayerAgent val;
if (IsSentryGunFire)
{
val = SentryGunOwner;
}
else
{
Agent val2 = default(Agent);
if (!((pAgent)(ref data.source)).TryGet(ref val2))
{
return;
}
val = ((Il2CppObjectBase)val2).Cast<PlayerAgent>();
}
float num = ((UFloat16)(ref data.damage)).Get(((Dam_SyncedDamageBase)val.Damage).HealthMax);
((UFloat16)(ref data.damage)).Set(num * Settings.FFMulti, ((Dam_SyncedDamageBase)val.Damage).HealthMax);
num = Math.Clamp(num * Settings.ReverseFFMulti, 0f, ((Dam_SyncedDamageBase)val.Damage).HealthMax);
float num2 = Math.Clamp(((Dam_SyncedDamageBase)val.Damage).Health - num, Settings.FFToDeath ? 0f : 0.001f, ((Dam_SyncedDamageBase)val.Damage).HealthMax);
((Dam_SyncedDamageBase)val.Damage).SendSetHealth(num2);
if (num2 == 0f && Settings.FFToDeath)
{
((Dam_SyncedDamageBase)val.Damage).SendSetDead(true);
}
}
}
[ArchivePatch(/*Could not decode attribute arguments.*/)]
private class Dam_PlayerDamageBase__ReceiveBulletDamage__Patch
{
private static void Prefix(ref pBulletDamageData data)
{
if (!SNet.IsMaster)
{
return;
}
PlayerAgent val;
if (IsSentryGunFire)
{
val = SentryGunOwner;
}
else
{
Agent val2 = default(Agent);
if (!((pAgent)(ref data.source)).TryGet(ref val2))
{
return;
}
val = ((Il2CppObjectBase)val2).Cast<PlayerAgent>();
}
float num = ((UFloat16)(ref data.damage)).Get(((Dam_SyncedDamageBase)val.Damage).HealthMax);
((UFloat16)(ref data.damage)).Set(num * Settings.FFMulti, ((Dam_SyncedDamageBase)val.Damage).HealthMax);
num = Math.Clamp(num * Settings.ReverseFFMulti, 0f, ((Dam_SyncedDamageBase)val.Damage).HealthMax);
float num2 = Math.Clamp(((Dam_SyncedDamageBase)val.Damage).Health - num, Settings.FFToDeath ? 0f : 0.001f, ((Dam_SyncedDamageBase)val.Damage).HealthMax);
((Dam_SyncedDamageBase)val.Damage).SendSetHealth(num2);
if (num2 == 0f && Settings.FFToDeath)
{
((Dam_SyncedDamageBase)val.Damage).SendSetDead(true);
}
}
}
[ArchivePatch(/*Could not decode attribute arguments.*/)]
private class SentryGunInstance_Firing_Bullets__FireBullet__Patch
{
private static void Prefix(SentryGunInstance_Firing_Bullets __instance)
{
if (SNet.IsMaster)
{
IsSentryGunFire = true;
SentryGunOwner = __instance.m_core.Owner;
}
}
private static void Postfix()
{
if (SNet.IsMaster)
{
IsSentryGunFire = false;
SentryGunOwner = null;
}
}
}
[ArchivePatch(/*Could not decode attribute arguments.*/)]
private class SentryGunInstance_Firing_Bullets__UpdateFireShotgunSemi__Patch
{
private static void Prefix(SentryGunInstance_Firing_Bullets __instance)
{
if (SNet.IsMaster)
{
IsSentryGunFire = true;
SentryGunOwner = __instance.m_core.Owner;
}
}
private static void Postfix()
{
if (SNet.IsMaster)
{
IsSentryGunFire = false;
SentryGunOwner = null;
}
}
}
private static PlayerAgent SentryGunOwner;
private static bool IsSentryGunFire;
public override string Name => "Reverse Friendly Fire";
public override bool InlineSettingsIntoParentMenu => true;
[FeatureConfig]
public static ReverseFriendlyFireSetting Settings { get; set; }
}
}