using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Peak.Afflictions;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace KickBecomeBones;
[BepInPlugin("com.kickbecomebonesfix.plugin", "KickBecomeBonesFix", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal class Notice
{
internal string Text;
internal float ShownAt;
internal Color TextColor;
}
internal class NoticeRenderer : MonoBehaviour
{
private Font _font;
private GUIStyle _style;
private void EnsureStyle()
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Expected O, but got Unknown
if (_style != null)
{
return;
}
if ((Object)(object)_font == (Object)null)
{
try
{
_font = Font.CreateDynamicFontFromOSFont(new string[4] { "Microsoft YaHei", "SimHei", "Noto Sans CJK SC", "Arial" }, 20);
}
catch (Exception ex)
{
Log.LogError((object)("Dynamic font creation failed: " + ex.Message));
_font = null;
}
}
_style = new GUIStyle(GUI.skin.label);
_style.fontSize = 20;
_style.fontStyle = (FontStyle)1;
_style.alignment = (TextAnchor)4;
_style.wordWrap = false;
if ((Object)(object)_font != (Object)null)
{
_style.font = _font;
}
}
private void OnGUI()
{
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
List<Notice> notices = Plugin.notices;
if (notices.Count == 0)
{
return;
}
float time = Time.time;
for (int num = notices.Count - 1; num >= 0; num--)
{
if (time - notices[num].ShownAt > 6f)
{
notices.RemoveAt(num);
}
}
if (notices.Count == 0)
{
return;
}
try
{
EnsureStyle();
}
catch (Exception ex)
{
Log.LogError((object)("Notice style setup failed: " + ex.Message));
return;
}
float num2 = 680f;
float num3 = 32f;
float num4 = (float)Screen.height * 0.74f;
Rect val = default(Rect);
foreach (Notice item in notices)
{
float num5 = 1f;
float num6 = time - item.ShownAt;
if (num6 > 5f)
{
num5 = 1f - (num6 - 5f);
}
((Rect)(ref val))..ctor(((float)Screen.width - num2) / 2f, num4, num2, num3);
Color color = GUI.color;
GUI.color = new Color(0.02f, 0.02f, 0.05f, 0.66f * num5);
GUI.DrawTexture(val, (Texture)(object)Texture2D.whiteTexture);
GUI.color = new Color(item.TextColor.r, item.TextColor.g, item.TextColor.b, num5);
GUI.Label(val, item.Text, _style);
GUI.color = color;
num4 -= num3 + 4f;
}
}
}
[HarmonyPatch(typeof(CharacterGrabbing), "RPCA_Kick")]
internal static class KillKickerPatch
{
[HarmonyPostfix]
internal static void RPCA_KickPostfix(CharacterGrabbing __instance, PhotonMessageInfo info)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
if (!PhotonNetwork.IsMasterClient)
{
return;
}
try
{
KillKicker(GetCharacterFromInfo(info));
}
catch (Exception ex)
{
Log.LogError((object)("KillKickerPatch error: " + ex));
}
}
}
[HarmonyPatch(typeof(CharacterGrabbing), "RPCA_KickImpact")]
internal static class KickImpactPatch
{
[HarmonyPostfix]
internal static void RPCA_KickImpactPostfix(CharacterGrabbing __instance, Vector3 position, PhotonMessageInfo info)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Unknown result type (might be due to invalid IL or missing references)
Character val = null;
Character val2 = null;
List<Character> list = new List<Character>();
try
{
val = GetCharacterFromInfo(info);
val2 = Character.localCharacter;
for (int i = 0; i < Character.AllCharacters.Count; i++)
{
Character val3 = Character.AllCharacters[i];
if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val3 == (Object)(object)val) && GetCharacterDistance(val3, position) < 10f)
{
list.Add(val3);
}
}
}
catch (Exception ex)
{
Log.LogError((object)("KickImpactPatch detection error: " + ex));
return;
}
bool flag = (Object)(object)val2 != (Object)null && list.Contains(val2);
bool flag2 = (Object)(object)val2 != (Object)null && (Object)(object)val == (Object)(object)val2;
try
{
ArmShield(list);
}
catch (Exception ex)
{
Log.LogError((object)("KickImpactPatch shield error: " + ex));
}
try
{
if (flag2)
{
string text = "";
for (int i = 0; i < list.Count; i++)
{
if (i > 0)
{
text += "、";
}
text += GetCharacterDisplayName(list[i]);
}
if (text.Length == 0)
{
text = "玩家";
}
ShowNotice("你踢了 " + text + "!惩罚:变成骷髅", new Color(1f, 0.55f, 0.55f));
}
else if (flag)
{
string text2 = GetCharacterDisplayName(val);
if (text2 == "未知玩家" && info.Sender != null)
{
text2 = info.Sender.NickName;
}
ShowNotice("检测到 " + text2 + " 的踢击!", new Color(1f, 0.85f, 0.4f));
ShowNotice("已施加强化牛奶保护(20 秒无敌),对方已变成骷髅", new Color(0.85f, 1f, 0.85f));
}
}
catch (Exception ex)
{
Log.LogError((object)("KickImpactPatch notice error: " + ex));
}
try
{
if (PhotonNetwork.IsMasterClient)
{
for (int i = 0; i < list.Count; i++)
{
ApplyMilk(list[i]);
}
}
else if (flag)
{
KillKicker(val);
ApplyMilk(val2);
}
}
catch (Exception ex)
{
Log.LogError((object)("KickImpactPatch milk/kill error: " + ex));
}
}
}
[HarmonyPatch(typeof(Character), "Fall", new Type[]
{
typeof(float),
typeof(float)
})]
internal static class ShieldFallSenderPatch
{
[HarmonyPrefix]
internal static bool Prefix(Character __instance)
{
return !IsShielded(__instance);
}
}
[HarmonyPatch(typeof(Character), "AddForceAtPosition", new Type[]
{
typeof(Vector3),
typeof(Vector3),
typeof(float)
})]
internal static class ShieldForceSenderPatch
{
[HarmonyPrefix]
internal static bool Prefix(Character __instance)
{
return !IsShielded(__instance);
}
}
[HarmonyPatch(typeof(Character), "RPCA_AddForceAtPosition", new Type[]
{
typeof(Vector3),
typeof(Vector3),
typeof(float),
typeof(PhotonMessageInfo)
})]
internal static class ShieldForceReceiverPatch
{
[HarmonyPrefix]
internal static bool Prefix(Character __instance, Vector3 force, Vector3 point, float radius, PhotonMessageInfo info)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
return ShieldForcePrefix(__instance, force, point, radius);
}
}
[HarmonyPatch(typeof(Character), "RPCA_AddForceAtPosition", new Type[]
{
typeof(Vector3),
typeof(Vector3),
typeof(float)
})]
internal static class ShieldForceReceiverPatchNoInfo
{
[HarmonyPrefix]
internal static bool Prefix(Character __instance, Vector3 force, Vector3 point, float radius)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
return ShieldForcePrefix(__instance, force, point, radius);
}
}
[HarmonyPatch(typeof(Character), "RPCA_Fall", new Type[]
{
typeof(float),
typeof(float),
typeof(PhotonMessageInfo)
})]
internal static class ShieldFallReceiverPatch
{
[HarmonyPrefix]
internal static bool Prefix(Character __instance, float seconds, float shake, PhotonMessageInfo info)
{
return !IsShielded(__instance);
}
}
[HarmonyPatch(typeof(Character), "RPCA_Fall", new Type[]
{
typeof(float),
typeof(float)
})]
internal static class ShieldFallReceiverPatchNoInfo
{
[HarmonyPrefix]
internal static bool Prefix(Character __instance, float seconds, float shake)
{
return !IsShielded(__instance);
}
}
public const string Id = "com.kickbecomebonesfix.plugin";
public const string Name = "KickBecomeBonesFix";
public const string Version = "1.0.0";
internal static readonly ManualLogSource Log = Logger.CreateLogSource("KickBecomeBonesFix");
internal static Plugin instance;
internal static float shieldUntil = 0f;
internal static readonly List<Character> shieldedCharacters = new List<Character>();
internal static bool forceNegationSent = false;
internal static readonly List<Notice> notices = new List<Notice>();
internal static NoticeRenderer renderer;
private void Awake()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
instance = this;
Log.LogInfo((object)"KickBecomeBonesFix 1.0.0 loading.");
Harmony harmony = new Harmony("com.kickbecomebonesfix.plugin");
TryPatch(harmony, typeof(KillKickerPatch));
TryPatch(harmony, typeof(KickImpactPatch));
TryPatch(harmony, typeof(ShieldFallSenderPatch));
TryPatch(harmony, typeof(ShieldForceSenderPatch));
TryPatch(harmony, typeof(ShieldForceReceiverPatch));
TryPatch(harmony, typeof(ShieldForceReceiverPatchNoInfo));
TryPatch(harmony, typeof(ShieldFallReceiverPatch));
TryPatch(harmony, typeof(ShieldFallReceiverPatchNoInfo));
Log.LogInfo((object)"KickBecomeBonesFix 1.0.0 ready. Kickers die; kicked players stay in place; kick notices on screen.");
}
internal static void TryPatch(Harmony harmony, Type type)
{
try
{
harmony.PatchAll(type);
Log.LogInfo((object)("Patched " + type.Name + " OK."));
}
catch (Exception ex)
{
Log.LogError((object)("Failed to patch " + type.Name + ": " + ex.Message));
}
}
internal static void ShowNotice(string text, Color color)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
Notice notice = new Notice();
notice.Text = text;
notice.ShownAt = Time.time;
notice.TextColor = color;
notices.Add(notice);
Log.LogInfo((object)("[踢击提示] " + text));
EnsureRenderer();
}
internal static void EnsureRenderer()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
if ((Object)(object)renderer != (Object)null)
{
return;
}
try
{
GameObject val = new GameObject("KickBecomeBonesNoticeRenderer");
Object.DontDestroyOnLoad((Object)(object)val);
renderer = val.AddComponent<NoticeRenderer>();
Log.LogInfo((object)"Notice renderer created.");
}
catch (Exception ex)
{
Log.LogError((object)("Notice renderer creation failed: " + ex.Message));
}
}
internal static bool IsShielded(Character c)
{
return (Object)(object)c != (Object)null && Time.time < shieldUntil && shieldedCharacters.Contains(c);
}
internal static Character GetCharacterFromInfo(PhotonMessageInfo info)
{
Player sender = info.Sender;
if (sender == null)
{
return null;
}
for (int i = 0; i < Character.AllCharacters.Count; i++)
{
Character val = Character.AllCharacters[i];
if ((Object)(object)val == (Object)null || val.refs == null)
{
continue;
}
PhotonView view = val.refs.view;
if (!((Object)(object)view == (Object)null))
{
Player controller = view.Controller;
if (controller != null && ((object)controller).Equals((object?)sender))
{
return val;
}
}
}
return null;
}
internal static float GetCharacterDistance(Character c, Vector3 pos)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = c.Center - pos;
return ((Vector3)(ref val)).magnitude;
}
internal static string GetCharacterDisplayName(Character c)
{
if ((Object)(object)c == (Object)null)
{
return "未知玩家";
}
try
{
string characterName = c.characterName;
if (!string.IsNullOrEmpty(characterName))
{
return characterName;
}
}
catch
{
}
return "未知玩家";
}
internal static void KillKicker(Character kicker)
{
if (!((Object)(object)kicker == (Object)null) && kicker.refs != null && !((Object)(object)kicker.refs.view == (Object)null) && !kicker.data.dead)
{
kicker.refs.view.RPC("RPCA_Die", (RpcTarget)0, new object[0]);
}
}
internal static void ApplyMilk(Character c)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
if (!((Object)(object)c == (Object)null) && c.refs != null && !((Object)(object)c.refs.afflictions == (Object)null))
{
Affliction_Invincibility val = new Affliction_Invincibility();
((Affliction)val).totalTime = 20f;
c.refs.afflictions.AddAffliction((Affliction)(object)val, false);
}
}
internal static void ArmShield(List<Character> victims)
{
if (victims.Count != 0)
{
shieldUntil = Time.time + 2f;
shieldedCharacters.Clear();
shieldedCharacters.AddRange(victims);
forceNegationSent = false;
Character localCharacter = Character.localCharacter;
if ((Object)(object)localCharacter != (Object)null && shieldedCharacters.Contains(localCharacter) && (Object)(object)instance != (Object)null)
{
((MonoBehaviour)instance).StartCoroutine(UnFallRoutine(localCharacter));
}
}
}
internal static IEnumerator UnFallRoutine(Character local)
{
yield return (object)new WaitForSeconds(0.3f);
SendUnFall(local);
yield return (object)new WaitForSeconds(0.8f);
SendUnFall(local);
}
internal static void SendUnFall(Character c)
{
if (!((Object)(object)c == (Object)null) && c.refs != null && !((Object)(object)c.refs.view == (Object)null))
{
c.refs.view.RPC("RPCA_UnFall", (RpcTarget)0, new object[0]);
}
}
internal static bool ShieldForcePrefix(Character __instance, Vector3 force, Vector3 point, float radius)
{
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
if (!IsShielded(__instance))
{
return true;
}
Character localCharacter = Character.localCharacter;
if ((Object)(object)localCharacter == (Object)(object)__instance && !forceNegationSent)
{
forceNegationSent = true;
if (__instance.refs != null && (Object)(object)__instance.refs.view != (Object)null)
{
try
{
__instance.refs.view.RPC("RPCA_AddForceAtPosition", (RpcTarget)0, new object[3]
{
-force,
point,
radius
});
}
catch (Exception ex)
{
Log.LogError((object)("Force negation broadcast failed: " + ex.Message));
}
}
}
return false;
}
}