HideDress/SkinHide/SkinHidePlugin.cs

104 lines
3.6 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;
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-07-16 02:51:13 +08:00
[BepInPlugin("com.kmyuhkyuk.SkinHide", "kmyuhkyuk-SkinHide", "1.2.0")]
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-05-06 15:17:35 +08:00
public static ConfigEntry<bool> KeyPlayerSkinHide { get; set; }
public static ConfigEntry<bool> KeyBotSkinHide { 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
string SkinHide = "Skin Hide";
2022-07-16 02:51:13 +08:00
string KBS = "Keyboard Shortcut";
2022-05-27 05:14:50 +08:00
KeyPlayerSkinHide = Config.Bind<bool>(SkinHide, "玩家服装隐藏 Player Skin Hide", false);
KeyBotSkinHide = Config.Bind<bool>(SkinHide, "Bot服装隐藏 Bot Skin Hide", false);
2022-07-16 02:51:13 +08:00
KBSPlayerSkinHide = Config.Bind<KeyboardShortcut>(KBS, "玩家服装隐藏快捷键 Player Skin Hide", new KeyboardShortcut());
KBSBotSkinHide = Config.Bind<KeyboardShortcut>(KBS, "Bot服装隐藏快捷键 Bot Skin Hide", new KeyboardShortcut());
2022-05-06 15:17:35 +08:00
new PlayerModelViewPatch().Enable();
new GamePlayerOwnerPatch().Enable();
new BotOwnerPatch().Enable();
}
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)
{
Hide(PlayerModelView, 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-07-16 02:51:13 +08:00
Hide(Player, KeyPlayerSkinHide.Value);
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-07-16 02:51:13 +08:00
foreach (PlayerBody body in Bot)
2022-05-06 15:17:35 +08:00
{
2022-07-16 02:52:30 +08:00
Hide(body, 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-07-16 02:51:13 +08:00
void Hide(PlayerBody playerbody, bool hide)
{
object slotviews = playerbody.SlotViews;
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 02:51:13 +08:00
foreach (GameObject gameobject in skindress)
{
gameobject.SetActive(!hide);
2022-05-06 15:17:35 +08:00
}
2022-07-16 02:51:13 +08:00
foreach (MeshRenderer renderer in renderers)
2022-05-06 15:17:35 +08:00
{
2022-07-16 02:51:13 +08:00
renderer.enabled = !hide;
2022-05-06 15:17:35 +08:00
}
}
}
}