HideDress/SkinHide/SkinHidePlugin.cs

207 lines
7.2 KiB
C#
Raw Normal View History

2022-05-06 15:17:35 +08:00
using BepInEx;
using BepInEx.Configuration;
2022-07-16 02:51:13 +08:00
using System.Linq;
2022-05-28 22:35:48 +08:00
using System.Collections.Generic;
2022-05-06 15:17:35 +08:00
using UnityEngine;
2022-05-27 05:14:50 +08:00
using EFT;
2022-05-06 15:17:35 +08:00
using EFT.Visual;
2022-05-28 22:35:48 +08:00
using SkinHide.Patches;
2022-10-11 04:31:32 +08:00
using SkinHide.Utils;
2022-05-06 15:17:35 +08:00
namespace SkinHide
{
2022-10-15 13:09:46 +08:00
[BepInPlugin("com.kmyuhkyuk.SkinHide", "kmyuhkyuk-SkinHide", "1.2.6")]
2022-05-06 15:17:35 +08:00
public class SkinHidePlugin : BaseUnityPlugin
{
2022-10-11 04:31:32 +08:00
internal static PlayerBody Player;
2022-05-06 15:17:35 +08:00
2022-10-11 04:31:32 +08:00
internal static PlayerBody PlayerModelView;
2022-05-06 15:17:35 +08:00
2022-10-11 04:31:32 +08:00
internal static List<PlayerBody> Bot = new List<PlayerBody>();
2022-05-27 05:14:50 +08:00
2022-10-17 22:34:46 +08:00
private readonly SettingsData SettingsDatas = new SettingsData();
2022-08-31 23:12:17 +08:00
2022-10-17 22:34:46 +08:00
private readonly ReflectionData ReflectionDatas = new ReflectionData();
2022-10-11 04:31:32 +08:00
2022-10-15 13:05:00 +08:00
private bool PMVHideCache;
private bool PlayerHideCache;
private bool BotHideCache;
2022-07-16 03:24:49 +08:00
public enum Part
{
All,
Dress,
SkinDress
}
2022-05-06 15:17:35 +08:00
private void Start()
{
Logger.LogInfo("Loaded: kmyuhkyuk-SkinHide");
2022-05-27 05:14:50 +08:00
2022-10-17 22:34:46 +08:00
string skinHideSettings = "Skin Hide Settings";
string skinHidePartSettings = "隐藏部分设置 Skin Hide Part Settings";
string kbsSettings = "快捷键设置 Keyboard Shortcut Settings";
2022-07-16 02:51:13 +08:00
2022-10-17 22:34:46 +08:00
SettingsDatas.KeyPlayerSkinHide = Config.Bind<bool>(skinHideSettings, "玩家服装隐藏 Player Skin Hide", false);
SettingsDatas.KeyBotSkinHide = Config.Bind<bool>(skinHideSettings, "Bot服装隐藏 Bot Skin Hide", false);
2022-07-16 02:51:13 +08:00
2022-10-17 22:34:46 +08:00
SettingsDatas.KeyPlayerSkinHidePart = Config.Bind<Part>(skinHidePartSettings, "Player", Part.All);
SettingsDatas.KeyBotSkinHidePart = Config.Bind<Part>(skinHidePartSettings, "Bot", Part.All);
2022-07-16 03:24:49 +08:00
2022-10-17 22:34:46 +08:00
SettingsDatas.KBSPlayerSkinHide = Config.Bind<KeyboardShortcut>(kbsSettings, "玩家服装隐藏快捷键 Player Skin Hide", KeyboardShortcut.Empty);
SettingsDatas.KBSBotSkinHide = Config.Bind<KeyboardShortcut>(kbsSettings, "Bot服装隐藏快捷键 Bot Skin Hide", KeyboardShortcut.Empty);
2022-05-06 15:17:35 +08:00
new PlayerModelViewPatch().Enable();
2022-08-17 10:03:42 +08:00
new PlayerPatch().Enable();
2022-10-11 04:31:32 +08:00
2022-10-26 10:27:36 +08:00
ReflectionDatas.RefSlotViews = RefHelp.FieldRef<PlayerBody, object>.Create("SlotViews");
ReflectionDatas.RefSlotList = RefHelp.FieldRef<object, IEnumerable<object>>.Create(ReflectionDatas.RefSlotViews.FieldType, "list_0");
ReflectionDatas.RefDresses = RefHelp.FieldRef<object, Dress[]>.Create(ReflectionDatas.RefSlotList.FieldType.GetGenericArguments()[0], "Dresses");
2022-10-26 10:28:01 +08:00
ReflectionDatas.RefRenderers = RefHelp.FieldRef<Dress, Renderer[]>.Create("Renderers");
2022-05-06 15:17:35 +08:00
}
2022-07-16 17:14:19 +08:00
2022-05-06 15:17:35 +08:00
void Update()
2022-05-06 16:01:02 +08:00
{
2022-10-17 22:34:46 +08:00
if (SettingsDatas.KBSPlayerSkinHide.Value.IsDown())
2022-05-06 15:17:35 +08:00
{
2022-10-17 22:34:46 +08:00
SettingsDatas.KeyPlayerSkinHide.Value = !SettingsDatas.KeyPlayerSkinHide.Value;
2022-05-06 15:17:35 +08:00
}
2022-10-17 22:34:46 +08:00
if (SettingsDatas.KBSBotSkinHide.Value.IsDown())
2022-05-06 15:17:35 +08:00
{
2022-10-17 22:34:46 +08:00
SettingsDatas.KeyBotSkinHide.Value = !SettingsDatas.KeyBotSkinHide.Value;
2022-07-16 02:51:13 +08:00
}
2022-05-27 05:14:50 +08:00
2022-07-16 02:51:13 +08:00
//PlayerModelView Skin Hide
2022-10-17 22:34:46 +08:00
if (PlayerModelView != null && SettingsDatas.KeyPlayerSkinHide.Value)
2022-10-15 13:05:00 +08:00
{
2022-10-17 22:34:46 +08:00
Hide(PlayerModelView, SettingsDatas.KeyPlayerSkinHidePart.Value, true);
2022-10-15 13:05:00 +08:00
PMVHideCache = true;
}
2022-10-17 22:34:46 +08:00
else if (PlayerModelView != null && !SettingsDatas.KeyPlayerSkinHide.Value && PMVHideCache)
2022-07-16 02:51:13 +08:00
{
2022-10-15 13:05:00 +08:00
Hide(PlayerModelView, Part.All, false);
PMVHideCache = false;
2022-05-06 15:17:35 +08:00
}
2022-07-16 02:51:13 +08:00
//Player Skin Hide
if (Player != null)
2022-05-06 15:17:35 +08:00
{
2022-10-17 22:34:46 +08:00
if (SettingsDatas.KeyPlayerSkinHide.Value)
2022-10-15 13:05:00 +08:00
{
2022-10-17 22:34:46 +08:00
Hide(Player, SettingsDatas.KeyPlayerSkinHidePart.Value, true);
2022-10-15 13:05:00 +08:00
PlayerHideCache = true;
}
2022-10-17 22:34:46 +08:00
else if (!SettingsDatas.KeyPlayerSkinHide.Value && PlayerHideCache)
2022-10-15 13:05:00 +08:00
{
Hide(Player, Part.All, false);
PlayerHideCache = false;
}
2022-05-06 15:17:35 +08:00
}
2022-08-25 19:28:17 +08:00
else
{
Bot.Clear();
}
2022-05-06 15:17:35 +08:00
2022-05-06 16:01:02 +08:00
//Bot Skin Hide
2022-10-17 22:34:46 +08:00
if (Bot.Count > 0 && SettingsDatas.KeyBotSkinHide.Value)
2022-10-15 13:05:00 +08:00
{
foreach (PlayerBody bot in Bot)
{
2022-10-17 22:34:46 +08:00
Hide(bot, SettingsDatas.KeyBotSkinHidePart.Value, true);
2022-10-15 13:05:00 +08:00
}
BotHideCache = true;
}
2022-10-17 22:34:46 +08:00
else if (Bot.Count > 0 && !SettingsDatas.KeyBotSkinHide.Value && BotHideCache)
2022-05-06 15:17:35 +08:00
{
2022-10-12 11:12:03 +08:00
foreach (PlayerBody bot in Bot)
2022-05-06 15:17:35 +08:00
{
2022-10-15 13:05:00 +08:00
Hide(bot, Part.All, false);
2022-05-06 15:17:35 +08:00
}
2022-10-15 13:05:00 +08:00
BotHideCache = false;
2022-07-16 02:51:13 +08:00
}
}
2022-05-27 05:14:50 +08:00
2022-08-17 10:03:42 +08:00
void Hide(PlayerBody playerbody, Part part, bool hide)
2022-07-16 02:51:13 +08:00
{
2022-10-17 22:34:46 +08:00
object slotViews = ReflectionDatas.RefSlotViews.GetValue(playerbody);
2022-05-27 05:14:50 +08:00
2022-10-17 22:34:46 +08:00
IEnumerable<object> slotList = ReflectionDatas.RefSlotList.GetValue(slotViews);
2022-05-27 05:14:50 +08:00
2022-10-15 15:53:31 +08:00
List<Dress> dresses = new List<Dress>();
2022-05-06 15:17:35 +08:00
2022-10-17 22:34:46 +08:00
foreach (object slot in slotList)
2022-10-15 15:53:31 +08:00
{
2022-10-17 22:34:46 +08:00
Dress[] dres = ReflectionDatas.RefDresses.GetValue(slot);
2022-10-15 15:53:31 +08:00
if (dres != null)
{
foreach (Dress dr in dres)
{
dresses.Add(dr);
}
}
}
IEnumerable<Dress> dress = dresses.Where(x => x.GetType() == typeof(Dress));
2022-05-27 05:14:50 +08:00
2022-10-17 22:34:46 +08:00
IEnumerable<Renderer> renDress = dress.SelectMany(x => ReflectionDatas.RefRenderers.GetValue(x));
2022-05-27 05:14:50 +08:00
2022-10-17 22:34:46 +08:00
IEnumerable<GameObject> skinDress = dresses.Where(x => x.GetType() == typeof(SkinDress) || x.GetType() == typeof(ArmBandView)).Select(x => x.gameObject);
2022-05-27 05:14:50 +08:00
2022-07-16 03:24:49 +08:00
switch (part)
2022-05-06 15:17:35 +08:00
{
2022-07-16 03:24:49 +08:00
case Part.All:
2022-10-17 22:34:46 +08:00
foreach (GameObject gameobject in skinDress)
2022-07-16 03:24:49 +08:00
{
gameobject.SetActive(!hide);
}
2022-10-17 22:34:46 +08:00
foreach (MeshRenderer renderer in renDress)
2022-07-16 03:24:49 +08:00
{
renderer.enabled = !hide;
}
break;
case Part.Dress:
2022-10-17 22:34:46 +08:00
foreach (MeshRenderer renderer in renDress)
2022-07-16 03:24:49 +08:00
{
renderer.enabled = !hide;
}
break;
case Part.SkinDress:
2022-10-17 22:34:46 +08:00
foreach (GameObject gameobject in skinDress)
2022-07-16 03:24:49 +08:00
{
gameobject.SetActive(!hide);
}
break;
2022-05-06 15:17:35 +08:00
}
}
2022-08-31 23:12:17 +08:00
public class SettingsData
{
public ConfigEntry<bool> KeyPlayerSkinHide;
public ConfigEntry<bool> KeyBotSkinHide;
public ConfigEntry<Part> KeyPlayerSkinHidePart;
public ConfigEntry<Part> KeyBotSkinHidePart;
public ConfigEntry<KeyboardShortcut> KBSPlayerSkinHide;
public ConfigEntry<KeyboardShortcut> KBSBotSkinHide;
}
2022-10-11 04:31:32 +08:00
public class ReflectionData
{
public RefHelp.FieldRef<PlayerBody, object> RefSlotViews;
public RefHelp.FieldRef<object, IEnumerable<object>> RefSlotList;
public RefHelp.FieldRef<object, Dress[]> RefDresses;
2022-10-15 15:53:31 +08:00
public RefHelp.FieldRef<Dress, Renderer[]> RefRenderers;
2022-10-11 04:31:32 +08:00
}
2022-05-06 15:17:35 +08:00
}
}