using BepInEx; using BepInEx.Configuration; using System.Linq; using System.Collections.Generic; using UnityEngine; using EFT; using EFT.Visual; using SkinHide.Patches; using SkinHide.Utils; using System; using EFT.UI.DragAndDrop; namespace SkinHide { [BepInPlugin("com.kmyuhkyuk.SkinHide", "kmyuhkyuk-SkinHide", "1.2.6")] public class SkinHidePlugin : BaseUnityPlugin { internal static PlayerBody Player; internal static PlayerBody PlayerModelView; internal static List Bot = new List(); private readonly SettingsData SettingsDatas = new SettingsData(); private readonly ReflectionData ReflectionDatas = new ReflectionData(); private bool PMVHideCache; private bool PlayerHideCache; private bool BotHideCache; public enum Part { All, Dress, SkinDress } private void Start() { Logger.LogInfo("Loaded: kmyuhkyuk-SkinHide"); string skinHideSettings = "Skin Hide Settings"; string skinHidePartSettings = "隐藏部分设置 Skin Hide Part Settings"; string kbsSettings = "快捷键设置 Keyboard Shortcut Settings"; SettingsDatas.KeyPlayerSkinHide = Config.Bind(skinHideSettings, "玩家服装隐藏 Player Skin Hide", false); SettingsDatas.KeyBotSkinHide = Config.Bind(skinHideSettings, "Bot服装隐藏 Bot Skin Hide", false); SettingsDatas.KeyPlayerSkinHidePart = Config.Bind(skinHidePartSettings, "Player", Part.All); SettingsDatas.KeyBotSkinHidePart = Config.Bind(skinHidePartSettings, "Bot", Part.All); SettingsDatas.KBSPlayerSkinHide = Config.Bind(kbsSettings, "玩家服装隐藏快捷键 Player Skin Hide", KeyboardShortcut.Empty); SettingsDatas.KBSBotSkinHide = Config.Bind(kbsSettings, "Bot服装隐藏快捷键 Bot Skin Hide", KeyboardShortcut.Empty); new PlayerModelViewPatch().Enable(); new PlayerPatch().Enable(); ReflectionDatas.RefSlotViews = RefHelp.FieldRef.Create("SlotViews"); ReflectionDatas.RefSlotList = RefHelp.FieldRef>.Create(ReflectionDatas.RefSlotViews.FieldType, "list_0"); ReflectionDatas.RefDresses = RefHelp.FieldRef.Create(ReflectionDatas.RefSlotList.FieldType.GetGenericArguments()[0], "Dresses"); ReflectionDatas.RefRenderers = RefHelp.FieldRef.Create("Renderers"); } void Update() { if (SettingsDatas.KBSPlayerSkinHide.Value.IsDown()) { SettingsDatas.KeyPlayerSkinHide.Value = !SettingsDatas.KeyPlayerSkinHide.Value; } if (SettingsDatas.KBSBotSkinHide.Value.IsDown()) { SettingsDatas.KeyBotSkinHide.Value = !SettingsDatas.KeyBotSkinHide.Value; } //PlayerModelView Skin Hide if (PlayerModelView != null && SettingsDatas.KeyPlayerSkinHide.Value) { Hide(PlayerModelView, SettingsDatas.KeyPlayerSkinHidePart.Value, true); PMVHideCache = true; } else if (PlayerModelView != null && !SettingsDatas.KeyPlayerSkinHide.Value && PMVHideCache) { Hide(PlayerModelView, Part.All, false); PMVHideCache = false; } //Player Skin Hide if (Player != null) { if (SettingsDatas.KeyPlayerSkinHide.Value) { Hide(Player, SettingsDatas.KeyPlayerSkinHidePart.Value, true); PlayerHideCache = true; } else if (!SettingsDatas.KeyPlayerSkinHide.Value && PlayerHideCache) { Hide(Player, Part.All, false); PlayerHideCache = false; } } else { Bot.Clear(); } //Bot Skin Hide if (Bot.Count > 0 && SettingsDatas.KeyBotSkinHide.Value) { foreach (PlayerBody bot in Bot) { Hide(bot, SettingsDatas.KeyBotSkinHidePart.Value, true); } BotHideCache = true; } else if (Bot.Count > 0 && !SettingsDatas.KeyBotSkinHide.Value && BotHideCache) { foreach (PlayerBody bot in Bot) { Hide(bot, Part.All, false); } BotHideCache = false; } } void Hide(PlayerBody playerbody, Part part, bool hide) { object slotViews = ReflectionDatas.RefSlotViews.GetValue(playerbody); IEnumerable slotList = ReflectionDatas.RefSlotList.GetValue(slotViews); List dresses = new List(); foreach (object slot in slotList) { Dress[] dres = ReflectionDatas.RefDresses.GetValue(slot); if (dres != null) { foreach (Dress dr in dres) { dresses.Add(dr); } } } IEnumerable dress = dresses.Where(x => x.GetType() == typeof(Dress)); IEnumerable renDress = dress.SelectMany(x => ReflectionDatas.RefRenderers.GetValue(x)); IEnumerable skinDress = dresses.Where(x => x.GetType() == typeof(SkinDress) || x.GetType() == typeof(ArmBandView)).Select(x => x.gameObject); switch (part) { case Part.All: foreach (GameObject gameobject in skinDress) { gameobject.SetActive(!hide); } foreach (MeshRenderer renderer in renDress) { renderer.enabled = !hide; } break; case Part.Dress: foreach (MeshRenderer renderer in renDress) { renderer.enabled = !hide; } break; case Part.SkinDress: foreach (GameObject gameobject in skinDress) { gameobject.SetActive(!hide); } break; } } public class SettingsData { public ConfigEntry KeyPlayerSkinHide; public ConfigEntry KeyBotSkinHide; public ConfigEntry KeyPlayerSkinHidePart; public ConfigEntry KeyBotSkinHidePart; public ConfigEntry KBSPlayerSkinHide; public ConfigEntry KBSBotSkinHide; } public class ReflectionData { public RefHelp.FieldRef RefSlotViews; public RefHelp.FieldRef> RefSlotList; public RefHelp.FieldRef RefDresses; public RefHelp.FieldRef RefRenderers; } } }