using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Agents;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using Enemies;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Kain_Core.Handlers;
using Kain_Core.Patches;
using Kain_Core.Utils;
using Player;
using SNetwork;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Kain_Core")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Kain_Core")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("040a0a8b-216d-42c9-a9bf-ed843674b750")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Kain_Core
{
[BepInPlugin("Kain.Core", "Kain_Core", "1.0.1")]
internal class EntryPoint : BasePlugin
{
internal static EntryPoint Instance;
public override void Load()
{
Instance = this;
ClassInjector.RegisterTypeInIl2Cpp<WeaponAutoAim>();
Patch.RegisterPatch<WeaponAutoAim_Patch>();
Patch.RegisterPatch<MeleeSelfHeal_Patch>();
Logs.LogMessage("OK");
}
}
internal static class Logs
{
public static void LogDebug(object data)
{
((BasePlugin)EntryPoint.Instance).Log.LogDebug(data);
}
public static void LogError(object data)
{
((BasePlugin)EntryPoint.Instance).Log.LogError(data);
}
public static void LogFatal(object data)
{
((BasePlugin)EntryPoint.Instance).Log.LogFatal(data);
}
public static void LogInfo(object data)
{
((BasePlugin)EntryPoint.Instance).Log.LogInfo(data);
}
public static void LogMessage(object data)
{
((BasePlugin)EntryPoint.Instance).Log.LogMessage(data);
}
public static void LogWarning(object data)
{
((BasePlugin)EntryPoint.Instance).Log.LogWarning(data);
}
}
internal class WeaponAutoAim_Patch : Patch
{
private static readonly Dictionary<uint, WeaponAutoAim> AutoAimsInstances = new Dictionary<uint, WeaponAutoAim>();
public override string Name => "WeaponAutoAim";
public override void Execute()
{
PatchMethod<Weapon>("CastWeaponRay", new Type[4]
{
typeof(Transform),
typeof(WeaponHitData).MakeByRefType(),
typeof(Vector3),
typeof(int)
}, PatchType.Prefix);
PatchMethod<BulletWeapon>("OnWield", PatchType.Postfix);
PatchMethod<BulletWeapon>("OnUnWield", PatchType.Prefix);
PatchMethod<BulletWeapon>("Update", PatchType.Postfix);
}
public static void Weapon__CastWeaponRay__Prefix(ref WeaponHitData weaponRayData)
{
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)weaponRayData.owner != (Object)null) || !InputMapper.GetButtonKeyMouse((InputAction)7, (eFocusState)4))
{
return;
}
ArchetypeDataBlock archetypeData = weaponRayData.owner.Inventory.WieldedItem.ArchetypeData;
if (archetypeData == null || ((GameDataBlockBase<ArchetypeDataBlock>)(object)archetypeData).persistentID < 2000 || ((GameDataBlockBase<ArchetypeDataBlock>)(object)archetypeData).persistentID > 3000)
{
return;
}
if (!AutoAimsInstances.TryGetValue(((GameDataBlockBase<ArchetypeDataBlock>)(object)archetypeData).persistentID, out var value))
{
value = ((Component)weaponRayData.owner.Inventory.WieldedItem).GetComponent<WeaponAutoAim>();
if ((Object)(object)value == (Object)null)
{
return;
}
AutoAimsInstances.Add(((GameDataBlockBase<ArchetypeDataBlock>)(object)archetypeData).persistentID, value);
}
if ((Object)(object)value.m_Target != (Object)null)
{
WeaponHitData obj = weaponRayData;
Vector3 val = ((Agent)value.m_Target).AimTarget.position - weaponRayData.owner.FPSCamera.Position;
obj.fireDir = ((Vector3)(ref val)).normalized;
}
}
public static void BulletWeapon__Update__Postfix(BulletWeapon __instance)
{
if (((GameDataBlockBase<ArchetypeDataBlock>)(object)((ItemEquippable)__instance).ArchetypeData).persistentID >= 2500 && ((GameDataBlockBase<ArchetypeDataBlock>)(object)((ItemEquippable)__instance).ArchetypeData).persistentID <= 3000)
{
((Item)__instance).Owner.Inventory.DoReload();
}
}
public static void BulletWeapon__OnWield__Postfix(BulletWeapon __instance)
{
if (((GameDataBlockBase<ArchetypeDataBlock>)(object)((ItemEquippable)__instance).ArchetypeData).persistentID >= 2000 && ((GameDataBlockBase<ArchetypeDataBlock>)(object)((ItemEquippable)__instance).ArchetypeData).persistentID <= 3000 && IsWeaponOwner(__instance))
{
WeaponAutoAim weaponAutoAim = ((Component)__instance).gameObject.GetComponent<WeaponAutoAim>();
if ((Object)(object)weaponAutoAim == (Object)null)
{
weaponAutoAim = ((Component)__instance).gameObject.AddComponent<WeaponAutoAim>();
}
if ((Object)(object)weaponAutoAim.m_Owner == (Object)null)
{
weaponAutoAim.m_BulletWeapon = __instance;
weaponAutoAim.m_Owner = ((Item)__instance).Owner;
weaponAutoAim.m_PlayerCamera = ((Component)((Item)__instance).Owner.FPSCamera).gameObject.GetComponent<Camera>();
weaponAutoAim.SetupReticle();
}
((Behaviour)weaponAutoAim).enabled = true;
}
}
public static void BulletWeapon__OnUnWield__Prefix(BulletWeapon __instance)
{
if (((GameDataBlockBase<ArchetypeDataBlock>)(object)((ItemEquippable)__instance).ArchetypeData).persistentID >= 2000 && ((GameDataBlockBase<ArchetypeDataBlock>)(object)((ItemEquippable)__instance).ArchetypeData).persistentID <= 3000 && IsWeaponOwner(__instance))
{
WeaponAutoAim component = ((Component)__instance).gameObject.GetComponent<WeaponAutoAim>();
if ((Object)(object)component != (Object)null)
{
((GuiLayerComp)component.m_Reticle).AnimateScale(0f, 0f);
component.m_HasTarget = false;
component.m_Target = null;
((Behaviour)component).enabled = false;
}
}
}
private static bool IsWeaponOwner(BulletWeapon weapon)
{
return ((Item)weapon).Owner.Owner.IsLocal;
}
}
public static class PluginInfo
{
public const string PLUGIN_NAME = "Kain_Core";
public const string PLUGIN_GUID = "Kain.Core";
public const string PLUGIN_VERSION = "1.0.1";
public const string PLUGIN_INTERNAL_VERSION = "10001";
public const string PLUGIN_CONTRIBUTORS = "Kain, Localia, mccad, Hikaria";
}
}
namespace Kain_Core.Utils
{
public abstract class Patch
{
[Flags]
public enum PatchType : byte
{
Prefix = 1,
Postfix = 2,
Both = 3
}
private protected static readonly Dictionary<Type, Patch> RegisteredPatches = new Dictionary<Type, Patch>();
private protected static Harmony s_Harmony;
protected internal Harmony Harmony { get; set; }
public virtual bool Enabled => true;
public abstract string Name { get; }
public virtual void Initialize()
{
}
public abstract void Execute();
public void PatchConstructor<TClass>(PatchType patchType, string prefixMethodName = null, string postfixMethodName = null) where TClass : class
{
PatchConstructor<TClass>(null, patchType, prefixMethodName, postfixMethodName);
}
public void PatchConstructor<TClass>(Type[] parameters, PatchType patchType, string prefixMethodName = null, string postfixMethodName = null) where TClass : class
{
ConstructorInfo methodBase = AccessTools.Constructor(typeof(TClass), parameters, false);
PatchMethod<TClass>(methodBase, patchType, prefixMethodName, postfixMethodName);
}
public void PatchMethod<TClass>(string methodName, PatchType patchType, Type[] generics = null, string prefixMethodName = null, string postfixMethodName = null) where TClass : class
{
PatchMethod<TClass>(methodName, null, patchType, generics, prefixMethodName, postfixMethodName);
}
public void PatchMethod<TClass>(string methodName, Type[] parameters, PatchType patchType, Type[] generics = null, string prefixMethodName = null, string postfixMethodName = null) where TClass : class
{
MethodInfo methodBase = AccessTools.Method(typeof(TClass), methodName, parameters, generics);
PatchMethod<TClass>(methodBase, patchType, prefixMethodName, postfixMethodName);
}
public void PatchMethod<TClass>(MethodBase methodBase, PatchType patchType, string prefixMethodName = null, string postfixMethodName = null) where TClass : class
{
PatchMethod(typeof(TClass), methodBase, patchType, prefixMethodName, postfixMethodName);
}
public void PatchMethod(Type classType, string methodName, PatchType patchType, Type[] generics = null, string prefixMethodName = null, string postfixMethodName = null)
{
PatchMethod(classType, methodName, null, patchType, generics, prefixMethodName, postfixMethodName);
}
public void PatchMethod(Type classType, string methodName, Type[] parameters, PatchType patchType, Type[] generics = null, string prefixMethodName = null, string postfixMethodName = null)
{
MethodInfo methodBase = AccessTools.Method(classType, methodName, parameters, generics);
PatchMethod(classType, methodBase, patchType, prefixMethodName, postfixMethodName);
}
public void PatchMethod(Type classType, MethodBase methodBase, PatchType patchType, string prefixMethodName = null, string postfixMethodName = null)
{
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Expected O, but got Unknown
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Expected O, but got Unknown
//IL_00ef: Expected O, but got Unknown
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Expected O, but got Unknown
string text = classType.Name.Replace("`", "__");
string arg = methodBase.ToString();
string text2 = (methodBase.IsConstructor ? "ctor" : methodBase.Name);
MethodInfo methodInfo = null;
MethodInfo methodInfo2 = null;
if ((int)(patchType & PatchType.Prefix) > 0)
{
try
{
methodInfo2 = AccessTools.Method(GetType(), prefixMethodName ?? (text + "__" + text2 + "__Prefix"), (Type[])null, (Type[])null);
}
catch (Exception arg2)
{
Logs.LogError($"未能获得 ({arg}) 的前缀补丁方法: {arg2}");
}
}
if ((int)(patchType & PatchType.Postfix) > 0)
{
try
{
methodInfo = AccessTools.Method(GetType(), postfixMethodName ?? (text + "__" + text2 + "__Postfix"), (Type[])null, (Type[])null);
}
catch (Exception arg3)
{
Logs.LogError($"未能获得 ({arg}) 的后缀补丁方法: {arg3}");
}
}
try
{
if (methodInfo2 != null && methodInfo != null)
{
Harmony.Patch(methodBase, new HarmonyMethod(methodInfo2), new HarmonyMethod(methodInfo), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
else if (methodInfo2 != null)
{
Harmony.Patch(methodBase, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
else if (methodInfo != null)
{
Harmony.Patch(methodBase, (HarmonyMethod)null, new HarmonyMethod(methodInfo), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
catch (Exception arg4)
{
Logs.LogError($"无法为 {arg} 方法打补丁: {arg4}");
}
}
public static void RegisterPatch<T>() where T : Patch, new()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
if (s_Harmony == null)
{
s_Harmony = new Harmony("Kain.Core");
}
if (RegisteredPatches.ContainsKey(typeof(T)))
{
Logs.LogError($"忽略重复补丁: {typeof(T).Name}");
return;
}
T val = new T
{
Harmony = s_Harmony
};
val.Initialize();
if (val.Enabled)
{
Logs.LogMessage($"正在应用补丁: {val.Name}");
val.Execute();
}
RegisteredPatches[typeof(T)] = val;
}
}
}
namespace Kain_Core.Patches
{
internal class MeleeSelfHeal_Patch : Patch
{
public override string Name => "MeleeSelfHeal";
public override void Execute()
{
PatchMethod<Dam_EnemyDamageBase>("ReceiveMeleeDamage", PatchType.Postfix);
}
private static void Dam_EnemyDamageBase__ReceiveMeleeDamage__Postfix(Dam_EnemyDamageBase __instance, pFullDamageData data)
{
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
IReplicator val = default(IReplicator);
if (!SNet.IsMaster || ((Agent)__instance.Owner).Alive || !((pReplicator)(ref data.source.pRep)).TryGetID(ref val))
{
return;
}
int num = val.OwningPlayer.PlayerSlotIndex();
PlayerAgent val2 = default(PlayerAgent);
if (PlayerManager.TryGetPlayerAgent(ref num, ref val2) && !(((Dam_SyncedDamageBase)val2.Damage).Health <= 0f))
{
_ = ((Dam_SyncedDamageBase)val2.Damage).Health;
float num2 = (float)Math.Min((double)((Dam_SyncedDamageBase)val2.Damage).Health + (double)((Dam_SyncedDamageBase)val2.Damage).HealthMax * 0.05, ((Dam_SyncedDamageBase)val2.Damage).HealthMax);
pSetHealthData val3 = default(pSetHealthData);
((SFloat16)(ref val3.health)).Set(num2, ((Dam_SyncedDamageBase)val2.Damage).HealthMax);
if (val2.Owner.IsLocal)
{
((Dam_SyncedDamageBase)val2.Damage).ReceiveSetHealth(val3);
}
((Dam_SyncedDamageBase)val2.Damage).SendSetHealth(num2);
}
}
}
}
namespace Kain_Core.Handlers
{
internal class WeaponAutoAim : MonoBehaviour
{
public GameObject m_ReticleHolder;
public CrosshairHitIndicator m_Reticle;
public EnemyAgent m_Target;
public Camera m_PlayerCamera;
public float m_DetectionTick;
public bool m_HasTarget;
public BulletWeapon m_BulletWeapon;
public PlayerAgent m_Owner;
public Color m_TargetedColor = new Color(1.2f, 0.3f, 0.1f, 1f);
public Color m_UnTargetedColor = new Color(0.3f, 0.1f, 0.1f, 1f);
public Color m_PassiveDetection = new Color(0.5f, 0.5f, 0.5f, 0.5f);
public Vector3 m_TargetedEulerAngles = new Vector3(0f, 0f, 45f);
public WeaponAutoAim(IntPtr value)
: base(value)
{
}//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
public void Setup()
{
}
public void SetupReticle()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
m_ReticleHolder = new GameObject();
m_ReticleHolder.transform.SetParent(((GuiLayer)GuiManager.CrosshairLayer).CanvasTrans);
m_Reticle = Object.Instantiate<CrosshairHitIndicator>(GuiManager.CrosshairLayer.m_hitIndicatorFriendly, m_ReticleHolder.transform);
((Object)m_Reticle).name = "SmartPistol_AutoAimIndicator";
((Component)m_Reticle).transform.localScale = Vector3.zero;
SetVFX(m_TargetedColor, m_TargetedEulerAngles);
((Component)m_Reticle).transform.localEulerAngles = m_TargetedEulerAngles;
}
public void Update()
{
UpdateColor();
UpdateDetection();
}
public void UpdateDetection()
{
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)m_Target != (Object)null)
{
m_ReticleHolder.transform.position = m_PlayerCamera.WorldToScreenPoint(((Agent)m_Target).AimTarget.position);
if (!m_HasTarget)
{
((Component)m_Reticle).transform.localScale = Vector3.one * 2f;
((Component)m_Reticle).transform.localEulerAngles = m_TargetedEulerAngles;
((GuiLayerComp)m_Reticle).AnimateScale(1.5f, 0.13f);
m_HasTarget = true;
}
}
else
{
Transform transform = ((Component)m_Reticle).transform;
transform.localEulerAngles += new Vector3(0f, 0f, 5f);
}
if (m_HasTarget && (Object)(object)m_Target == (Object)null)
{
((GuiLayerComp)m_Reticle).AnimateScale(0f, 0.5f);
m_HasTarget = false;
}
if (m_DetectionTick < Time.time)
{
m_Target = SentryGunInstance_Detection.CheckForTargetLegacy(((ItemEquippable)m_BulletWeapon).ArchetypeData, ((Component)m_BulletWeapon).transform);
m_DetectionTick = Time.time + 0.25f;
}
}
public void UpdateColor()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
if (m_HasTarget)
{
m_Reticle.m_hitColor = m_TargetedColor;
}
else
{
m_Reticle.m_hitColor = m_UnTargetedColor;
}
if (!InputMapper.GetButtonKeyMouse((InputAction)7, (eFocusState)4) || ((ItemEquippable)m_BulletWeapon).GetCurrentClip() <= 0)
{
m_ReticleHolder.transform.localScale = Vector3.one * 0.5f;
Transform transform = m_ReticleHolder.transform;
transform.localEulerAngles += new Vector3(0f, 0f, 2f);
m_Reticle.m_hitColor = m_PassiveDetection;
}
else
{
m_ReticleHolder.transform.localScale = Vector3.one;
m_ReticleHolder.transform.localEulerAngles = Vector3.zero;
}
m_Reticle.UpdateColorsWithAlphaMul(m_Reticle.m_hitColor.a);
}
public void SetVFX(Color color, Vector3 euler)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
((Component)m_Reticle).transform.localEulerAngles = euler;
m_Reticle.m_hitColor = color;
m_Reticle.UpdateColorsWithAlphaMul(1f);
}
}
}