HideDress/SkinHide/SkinHidePlugin.cs

206 lines
7.5 KiB
C#
Raw Normal View History

2022-05-06 15:17:35 +08:00
using BepInEx;
using BepInEx.Configuration;
2023-01-13 18:22:27 +08:00
using System;
2022-07-16 02:51:13 +08:00
using System.Linq;
2023-01-13 18:22:27 +08:00
using System.Diagnostics;
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;
2023-02-01 19:33:52 +08:00
using EFT.InventoryLogic;
2022-05-06 15:17:35 +08:00
namespace SkinHide
{
2022-11-07 11:03:15 +08:00
[BepInPlugin("com.kmyuhkyuk.SkinHide", "kmyuhkyuk-SkinHide", "1.2.7")]
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
2023-02-27 12:33:56 +08:00
internal static List<PlayerBody> BotList = 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;
2023-01-14 00:30:56 +08:00
internal static Version GameVersion { get; private set; }
2023-01-05 08:49:34 +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
2023-01-13 18:22:27 +08:00
FileVersionInfo exeInfo = Process.GetCurrentProcess().MainModule.FileVersionInfo;
GameVersion = new Version(exeInfo.FileMajorPart, exeInfo.ProductMinorPart, exeInfo.ProductBuildPart, exeInfo.FilePrivatePart);
2022-11-21 23:02:45 +08:00
const string skinHideSettings = "Skin Hide Settings";
const string skinHidePartSettings = "隐藏部分设置 Skin Hide Part Settings";
const 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();
2023-02-27 12:33:56 +08:00
new PlayerInitPatch().Enable();
new PlayerEndPatch().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
2023-02-27 07:42:12 +08:00
if (PlayerModelView != null)
2022-10-15 13:05:00 +08:00
{
2023-02-27 07:42:12 +08:00
if (SettingsDatas.KeyPlayerSkinHide.Value)
{
Hide(PlayerModelView, SettingsDatas.KeyPlayerSkinHidePart.Value, true);
2022-10-15 13:05:00 +08:00
2023-02-27 07:42:12 +08:00
PMVHideCache = true;
}
else if (!SettingsDatas.KeyPlayerSkinHide.Value && PMVHideCache)
{
Hide(PlayerModelView, Part.All, false);
2022-10-15 13:05:00 +08:00
2023-02-27 07:42:12 +08:00
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-05-06 16:01:02 +08:00
//Bot Skin Hide
2023-02-27 12:33:56 +08:00
if (BotList.Count > 0)
2022-10-15 13:05:00 +08:00
{
2023-02-27 07:42:12 +08:00
if (SettingsDatas.KeyBotSkinHide.Value)
2022-10-15 13:05:00 +08:00
{
2023-02-27 12:33:56 +08:00
foreach (PlayerBody bot in BotList)
2023-02-27 07:42:12 +08:00
{
Hide(bot, SettingsDatas.KeyBotSkinHidePart.Value, true);
}
2022-10-15 13:05:00 +08:00
2023-02-27 07:42:12 +08:00
BotHideCache = true;
2022-05-06 15:17:35 +08:00
}
2023-02-27 07:42:12 +08:00
else if (!SettingsDatas.KeyBotSkinHide.Value && BotHideCache)
{
2023-02-27 12:33:56 +08:00
foreach (PlayerBody bot in BotList)
2023-02-27 07:42:12 +08:00
{
Hide(bot, Part.All, false);
}
2022-10-15 13:05:00 +08:00
2023-02-27 07:42:12 +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
2023-02-01 19:33:52 +08:00
IEnumerable<Dress> dresses = slotList.SelectMany(x => ReflectionDatas.RefDresses.GetValue(x)).Where(x => x != null);
2022-10-15 15:53:31 +08:00
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
}
}