HideDress/SkinHide/SkinHidePlugin.cs

156 lines
5.8 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-11 04:31:32 +08:00
[BepInPlugin("com.kmyuhkyuk.SkinHide", "kmyuhkyuk-SkinHide", "1.2.5")]
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-13 10:14:01 +08:00
private readonly SettingsData settingsdata = new SettingsData();
2022-08-31 23:12:17 +08:00
2022-10-13 10:14:01 +08:00
private readonly ReflectionData reflectiondata = new ReflectionData();
2022-10-11 04:31:32 +08:00
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-08-06 07:19:26 +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-08-31 23:12:17 +08:00
settingsdata.KeyPlayerSkinHide = Config.Bind<bool>(SkinHideSettings, "玩家服装隐藏 Player Skin Hide", false);
settingsdata.KeyBotSkinHide = Config.Bind<bool>(SkinHideSettings, "Bot服装隐藏 Bot Skin Hide", false);
2022-07-16 02:51:13 +08:00
2022-08-31 23:12:17 +08:00
settingsdata.KeyPlayerSkinHidePart = Config.Bind<Part>(SkinHidePartSettings, "Player", Part.All);
settingsdata.KeyBotSkinHidePart = Config.Bind<Part>(SkinHidePartSettings, "Bot", Part.All);
2022-07-16 03:24:49 +08:00
2022-08-31 23:12:17 +08:00
settingsdata.KBSPlayerSkinHide = Config.Bind<KeyboardShortcut>(KBSSettings, "玩家服装隐藏快捷键 Player Skin Hide", KeyboardShortcut.Empty);
settingsdata.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
reflectiondata.RefSlotViews = RefHelp.FieldRef<PlayerBody, object>.Create("SlotViews");
reflectiondata.RefSlotList = RefHelp.FieldRef<object, IEnumerable<object>>.Create(reflectiondata.RefSlotViews.FieldType, "list_0");
reflectiondata.RefDresses = RefHelp.FieldRef<object, Dress[]>.Create(reflectiondata.RefSlotList.FieldType.GetGenericArguments()[0], "Dresses");
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-08-31 23:12:17 +08:00
if (settingsdata.KBSPlayerSkinHide.Value.IsDown())
2022-05-06 15:17:35 +08:00
{
2022-08-31 23:12:17 +08:00
settingsdata.KeyPlayerSkinHide.Value = !settingsdata.KeyPlayerSkinHide.Value;
2022-05-06 15:17:35 +08:00
}
2022-08-31 23:12:17 +08:00
if (settingsdata.KBSBotSkinHide.Value.IsDown())
2022-05-06 15:17:35 +08:00
{
2022-08-31 23:12:17 +08:00
settingsdata.KeyBotSkinHide.Value = !settingsdata.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
if (PlayerModelView != null)
{
2022-10-12 11:12:03 +08:00
Hide(PlayerModelView, settingsdata.KeyPlayerSkinHidePart.Value, settingsdata.KeyPlayerSkinHide.Value);
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-12 11:12:03 +08:00
Hide(Player, settingsdata.KeyPlayerSkinHidePart.Value, settingsdata.KeyPlayerSkinHide.Value);
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-07-16 02:51:13 +08:00
if (Bot.Count > 0)
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-12 11:12:03 +08:00
Hide(bot, settingsdata.KeyBotSkinHidePart.Value, settingsdata.KeyBotSkinHide.Value);
2022-05-06 15:17:35 +08:00
}
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-11 04:31:32 +08:00
object slotviews = reflectiondata.RefSlotViews.GetValue(playerbody);
2022-05-27 05:14:50 +08:00
2022-10-11 04:31:32 +08:00
IEnumerable<object> slotlist = reflectiondata.RefSlotList.GetValue(slotviews);
2022-05-27 05:14:50 +08:00
2022-10-11 04:31:32 +08:00
Dress[] dresses = slotlist.Where(x => reflectiondata.RefDresses.GetValue(x) != null).SelectMany(x => reflectiondata.RefDresses.GetValue(x)).ToArray();
2022-05-06 15:17:35 +08:00
2022-07-16 02:51:13 +08:00
GameObject[] dress = dresses.Where(x => x.GetType() == typeof(Dress)).Select(x => x.gameObject).ToArray();
2022-05-27 05:14:50 +08:00
2022-10-12 11:12:03 +08:00
MeshRenderer[] renderers = dress.SelectMany(x => x.gameObject.GetComponentsInChildren<MeshRenderer>()).ToArray();
2022-05-27 05:14:50 +08:00
2022-07-16 02:51:13 +08:00
GameObject[] skindress = dresses.Where(x => x.GetType() == typeof(SkinDress) || x.GetType() == typeof(ArmBandView)).Select(x => x.gameObject).ToArray();
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:
foreach (GameObject gameobject in skindress)
{
gameobject.SetActive(!hide);
}
foreach (MeshRenderer renderer in renderers)
{
renderer.enabled = !hide;
}
break;
case Part.Dress:
foreach (MeshRenderer renderer in renderers)
{
renderer.enabled = !hide;
}
break;
case Part.SkinDress:
foreach (GameObject gameobject in skindress)
{
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-05-06 15:17:35 +08:00
}
}