HideDress/SkinHide/SkinHidePlugin.cs

135 lines
4.9 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 HarmonyLib;
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-05-06 15:17:35 +08:00
namespace SkinHide
{
2022-08-17 10:12:05 +08:00
[BepInPlugin("com.kmyuhkyuk.SkinHide", "kmyuhkyuk-SkinHide", "1.2.3")]
2022-05-06 15:17:35 +08:00
public class SkinHidePlugin : BaseUnityPlugin
{
2022-07-16 02:51:13 +08:00
public static PlayerBody Player;
2022-05-06 15:17:35 +08:00
2022-07-16 02:51:13 +08:00
public static PlayerBody PlayerModelView;
2022-05-06 15:17:35 +08:00
2022-07-16 02:51:13 +08:00
public static List <PlayerBody> Bot = new List<PlayerBody>();
2022-05-27 05:14:50 +08:00
2022-07-16 03:24:49 +08:00
public enum Part
{
All,
Dress,
SkinDress
}
2022-05-06 15:17:35 +08:00
public static ConfigEntry<bool> KeyPlayerSkinHide { get; set; }
public static ConfigEntry<bool> KeyBotSkinHide { get; set; }
2022-07-16 03:24:49 +08:00
public static ConfigEntry<Part> KeyPlayerSkinHidePart { get; set; }
public static ConfigEntry<Part> KeyBotSkinHidePart { get; set; }
2022-07-16 02:51:13 +08:00
public static ConfigEntry<KeyboardShortcut> KBSPlayerSkinHide { get; set; }
public static ConfigEntry<KeyboardShortcut> KBSBotSkinHide { get; set; }
2022-05-27 05:14:50 +08:00
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-06 07:19:26 +08:00
KeyPlayerSkinHide = Config.Bind<bool>(SkinHideSettings, "玩家服装隐藏 Player Skin Hide", false);
KeyBotSkinHide = Config.Bind<bool>(SkinHideSettings, "Bot服装隐藏 Bot Skin Hide", false);
2022-07-16 02:51:13 +08:00
2022-08-06 07:19:26 +08:00
KeyPlayerSkinHidePart = Config.Bind<Part>(SkinHidePartSettings, "Player", Part.All);
KeyBotSkinHidePart = Config.Bind<Part>(SkinHidePartSettings, "Bot", Part.All);
2022-07-16 03:24:49 +08:00
2022-08-06 07:19:26 +08:00
KBSPlayerSkinHide = Config.Bind<KeyboardShortcut>(KBSSettings, "玩家服装隐藏快捷键 Player Skin Hide", KeyboardShortcut.Empty);
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-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-07-16 02:51:13 +08:00
if (KBSPlayerSkinHide.Value.IsDown())
2022-05-06 15:17:35 +08:00
{
2022-07-16 02:51:13 +08:00
KeyPlayerSkinHide.Value = !KeyPlayerSkinHide.Value;
2022-05-06 15:17:35 +08:00
}
2022-07-16 02:51:13 +08:00
if (KBSBotSkinHide.Value.IsDown())
2022-05-06 15:17:35 +08:00
{
2022-07-16 02:51:13 +08:00
KeyBotSkinHide.Value = !KeyBotSkinHide.Value;
}
2022-05-27 05:14:50 +08:00
2022-07-16 02:51:13 +08:00
//PlayerModelView Skin Hide
if (PlayerModelView != null)
{
2022-08-17 10:03:42 +08:00
Hide(PlayerModelView, KeyPlayerSkinHidePart.Value, 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-08-17 10:03:42 +08:00
Hide(Player, KeyPlayerSkinHidePart.Value, KeyPlayerSkinHide.Value);
2022-05-06 15:17:35 +08:00
}
2022-05-06 16:01:02 +08:00
//Bot Skin Hide
2022-07-16 03:10:31 +08:00
Bot.RemoveAll(x => x == null);
2022-07-16 02:51:13 +08:00
if (Bot.Count > 0)
2022-05-06 15:17:35 +08:00
{
2022-07-16 02:53:16 +08:00
foreach (PlayerBody bot in Bot)
2022-05-06 15:17:35 +08:00
{
2022-08-17 10:03:42 +08:00
Hide(bot, KeyBotSkinHidePart.Value, 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-07-22 13:40:32 +08:00
object slotviews = Traverse.Create(playerbody).Field("SlotViews").GetValue<object>();
2022-05-27 05:14:50 +08:00
2022-07-16 02:51:13 +08:00
IEnumerable<object> slotlist = (IEnumerable<object>)Traverse.Create(slotviews).Field("list_0").GetValue<object>();
2022-05-27 05:14:50 +08:00
2022-07-16 02:51:13 +08:00
Dress[] dresses = slotlist.Where(x => Traverse.Create(x).Field("Dresses").GetValue<Dress[]>() != null).SelectMany(x => Traverse.Create(x).Field("Dresses").GetValue<Dress[]>()).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-07-16 02:51:13 +08:00
MeshRenderer[] renderers = dress.SelectMany(x => x.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
}
}
}
}