using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using NameColorizer;
using Photon.Pun;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Anti-Dexter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fc8178120ce35bbce231f327dcb6c5cb3cdc44e2")]
[assembly: AssemblyProduct("Anti-Dexter")]
[assembly: AssemblyTitle("Anti-Dexter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace AntiDexter
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Anti-Dexter";
public const string PLUGIN_NAME = "Anti-Dexter";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace AntiDexter.Patches
{
[HarmonyPatch(typeof(PhotonNetwork))]
internal class PhotonNetworkPatch
{
[HarmonyPatch("SetPlayerCustomProperties")]
[HarmonyPrefix]
private static void SetPlayerCustomPropertiesPatch()
{
try
{
if (PhotonNetwork.LocalPlayer != null)
{
string nickName = PhotonNetwork.LocalPlayer.NickName;
if (string.Equals(nickName, "Dexter", StringComparison.OrdinalIgnoreCase))
{
PhotonNetwork.LocalPlayer.NickName = "Mohamad";
ColoredNametagMod.logger.LogInfo((object)("检测到目标名称: " + nickName + ",已替换为: Mohamad"));
}
}
}
catch (Exception ex)
{
ColoredNametagMod.logger.LogError((object)("修改名称时发生错误: " + ex.Message));
}
}
}
[HarmonyPatch(typeof(PlayerAvatar))]
internal class PlayerAvatarPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPatch(PlayerAvatar __instance)
{
try
{
if (!((Object)(object)__instance.photonView != (Object)null))
{
return;
}
string nickName = __instance.photonView.Owner.NickName;
if (!string.Equals(nickName, "Dexter", StringComparison.OrdinalIgnoreCase))
{
return;
}
if ((Object)(object)__instance.worldSpaceUIPlayerName != (Object)null && (Object)(object)__instance.worldSpaceUIPlayerName.text != (Object)null)
{
((TMP_Text)__instance.worldSpaceUIPlayerName.text).text = "Mohamad";
ColoredNametagMod.logger.LogInfo((object)("方法1: 检测到目标名称: " + nickName + ",已替换为: Mohamad"));
return;
}
TextMeshPro[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<TextMeshPro>(true);
TextMeshPro[] array = componentsInChildren;
foreach (TextMeshPro val in array)
{
if (((TMP_Text)val).text.Contains(nickName))
{
((TMP_Text)val).text = ((TMP_Text)val).text.Replace(nickName, "Mohamad");
ColoredNametagMod.logger.LogInfo((object)("方法2: 检测到目标名称: " + nickName + ",已替换为: Mohamad"));
return;
}
}
FieldInfo field = typeof(PlayerAvatar).GetField("playerName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
object value = field.GetValue(__instance);
TextMeshPro val2 = (TextMeshPro)((value is TextMeshPro) ? value : null);
if (val2 != null)
{
((TMP_Text)val2).text = "Mohamad";
ColoredNametagMod.logger.LogInfo((object)("方法3: 检测到目标名称: " + nickName + ",已替换为: Mohamad"));
return;
}
}
ColoredNametagMod.logger.LogWarning((object)("无法找到合适的方法修改玩家名称: " + nickName));
}
catch (Exception ex)
{
ColoredNametagMod.logger.LogError((object)("修改名称时发生错误: " + ex.Message));
}
}
}
}
namespace NameColorizer
{
[BepInPlugin("zombieseatflesh7.ColoredNametags", "Anti-Dexter", "1.0.0")]
public class ColoredNametagMod : BaseUnityPlugin
{
[CompilerGenerated]
private static class <>O
{
public static Action<Action<WorldSpaceUIParent, PlayerAvatar>, WorldSpaceUIParent, PlayerAvatar> <0>__WorldSpaceUIParent_PlayerNameHook;
public static Action<Action<PlayerAvatarVisuals, int, Color>, PlayerAvatarVisuals, int, Color> <1>__PlayerAvatarVisuals_SetColorHook;
public static Manipulator <2>__SetPlayerNameTransparency;
}
public const string PLUGIN_GUID = "zombieseatflesh7.ColoredNametags";
public const string PLUGIN_NAME = "Anti-Dexter";
public const string PLUGIN_VERSION = "1.0.0";
internal static readonly ManualLogSource logger = Logger.CreateLogSource("Anti-Dexter");
private static string RGBToHex(Color color)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: 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)
int num = Mathf.RoundToInt(color.r * 255f);
int num2 = Mathf.RoundToInt(color.g * 255f);
int num3 = Mathf.RoundToInt(color.b * 255f);
return num.ToString("X2") + num2.ToString("X2") + num3.ToString("X2");
}
private static void WorldSpaceUIParent_PlayerNameHook(Action<WorldSpaceUIParent, PlayerAvatar> orig, WorldSpaceUIParent self, PlayerAvatar player)
{
orig(self, player);
UpdatePlayerNametagColor(player);
}
private static void PlayerAvatarVisuals_SetColorHook(Action<PlayerAvatarVisuals, int, Color> orig, PlayerAvatarVisuals self, int _colorIndex, Color _setColor)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
orig(self, _colorIndex, _setColor);
UpdatePlayerNametagColor(self.playerAvatar);
}
private static void UpdatePlayerNametagColor(PlayerAvatar player)
{
//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_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)player.worldSpaceUIPlayerName == (Object)null))
{
Color color = player.playerAvatarVisuals.color;
color.r += 0.666f;
color.g += 0.666f;
color.b += 0.666f;
color *= 1f / Mathf.Max(new float[3] { color.r, color.g, color.b });
string text = RGBToHex(color);
((TMP_Text)player.worldSpaceUIPlayerName.text).text = "<color=#" + text + ">" + player.playerName;
}
}
private void Awake()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Expected O, but got Unknown
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Expected O, but got Unknown
new Hook((MethodBase)AccessTools.Method(typeof(WorldSpaceUIParent), "PlayerName", (Type[])null, (Type[])null), (Delegate)new Action<Action<WorldSpaceUIParent, PlayerAvatar>, WorldSpaceUIParent, PlayerAvatar>(WorldSpaceUIParent_PlayerNameHook));
new Hook((MethodBase)AccessTools.Method(typeof(PlayerAvatarVisuals), "SetColor", (Type[])null, (Type[])null), (Delegate)new Action<Action<PlayerAvatarVisuals, int, Color>, PlayerAvatarVisuals, int, Color>(PlayerAvatarVisuals_SetColorHook));
MethodInfo? method = typeof(WorldSpaceUIPlayerName).GetMethod("Update", BindingFlags.Instance | BindingFlags.NonPublic);
object obj = <>O.<2>__SetPlayerNameTransparency;
if (obj == null)
{
Manipulator val = SetPlayerNameTransparency;
<>O.<2>__SetPlayerNameTransparency = val;
obj = (object)val;
}
new ILHook((MethodBase)method, (Manipulator)obj);
Harmony val2 = new Harmony("zombieseatflesh7.ColoredNametags");
val2.PatchAll();
logger.LogInfo((object)"Anti-Dexter v1.0.0 已加载!");
}
private static void SetPlayerNameTransparency(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il).Goto(0, (MoveType)0, false);
if (val.TryGotoNext(new Func<Instruction, bool>[2]
{
(Instruction i) => ILPatternMatchingExt.MatchLdcR4(i, 0.5f),
(Instruction i) => ILPatternMatchingExt.MatchNewobj<Color>(i)
}))
{
val.Remove();
val.Emit(OpCodes.Ldc_R4, 0.75f);
}
}
}
}