2022-05-06 15:17:35 +08:00
using BepInEx ;
using BepInEx.Configuration ;
using UnityEngine ;
using SkinHide.Patches ;
2022-05-27 05:14:50 +08:00
using EFT ;
2022-05-06 15:17:35 +08:00
using EFT.Visual ;
using System.Collections.Generic ;
namespace SkinHide
{
2022-05-27 05:14:50 +08:00
[BepInPlugin("com.kmyuhkyuk.SkinHide", "kmyuhkyuk-SkinHide", "1.1.0")]
2022-05-06 15:17:35 +08:00
public class SkinHidePlugin : BaseUnityPlugin
{
public static GameObject Player ;
public static GameObject PlayerModelView ;
public SkinDress [ ] PlayerMVSkinDress ;
public Dress [ ] PlayerMVDress ;
public SkinDress [ ] PlayerSkinDress ;
public Dress [ ] PlayerDress ;
public HashSet < GameObject > PlayerSkinGameObject = new HashSet < GameObject > ( ) ;
2022-05-27 05:14:50 +08:00
public HashSet < GameObject > PlayerDressGameObject = new HashSet < GameObject > ( ) ;
2022-05-06 15:17:35 +08:00
2022-05-27 05:14:50 +08:00
public static List < GameObject > Bot = new List < GameObject > ( ) ;
2022-05-06 15:17:35 +08:00
2022-05-06 15:35:30 +08:00
public HashSet < GameObject > BotSkinGameObject = new HashSet < GameObject > ( ) ;
2022-05-27 05:14:50 +08:00
public HashSet < GameObject > BotDressGameObject = new HashSet < GameObject > ( ) ;
2022-05-06 15:17:35 +08:00
public static ConfigEntry < bool > KeyPlayerSkinHide { get ; set ; }
public static ConfigEntry < bool > KeyBotSkinHide { get ; set ; }
2022-05-27 05:14:50 +08:00
public static ConfigEntry < bool > KeyBotSkinHideShutDown { get ; set ; }
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" ;
KeyPlayerSkinHide = Config . Bind < bool > ( SkinHide , "玩家服装隐藏 Player Skin Hide" , false ) ;
KeyBotSkinHide = Config . Bind < bool > ( SkinHide , "Bot服装隐藏 Bot Skin Hide" , false ) ;
KeyBotSkinHideShutDown = Config . Bind < bool > ( SkinHide , "Bot服装隐藏功能关闭 Bot Skin Hide Function Shut Down" , false , "Many Bot corpse will cause lag, turn the switch off Bot Skin Scan." ) ;
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
{
//PlayerModelView Skin Hide
2022-05-06 15:17:35 +08:00
if ( PlayerModelView ! = null & & KeyPlayerSkinHide . Value )
{
2022-05-06 16:01:02 +08:00
//Get PlayerModelView all SkinDress and Dress
2022-05-06 15:17:35 +08:00
PlayerMVSkinDress = PlayerModelView . GetComponentsInChildren < SkinDress > ( ) ;
PlayerMVDress = PlayerModelView . GetComponentsInChildren < Dress > ( ) ;
2022-05-06 16:03:23 +08:00
//False SkinDress and Dress GameObject
2022-05-06 15:17:35 +08:00
if ( PlayerMVSkinDress ! = null )
{
foreach ( SkinDress skindress in PlayerMVSkinDress )
{
skindress . gameObject . SetActive ( false ) ;
}
}
if ( PlayerMVDress ! = null )
{
foreach ( Dress dress in PlayerMVDress )
{
dress . gameObject . SetActive ( false ) ;
}
}
}
2022-05-06 16:01:02 +08:00
//Player Skin Hide
2022-05-06 15:17:35 +08:00
if ( Player ! = null )
{
2022-05-06 16:01:02 +08:00
//Get Player all SkinDress and Dress
2022-05-27 05:14:50 +08:00
PlayerSkinDress = Player . transform . Find ( "Player/Mesh" ) . gameObject . GetComponentsInChildren < SkinDress > ( ) ;
PlayerDress = Player . transform . Find ( "Player/Root_Joint" ) . gameObject . GetComponentsInChildren < Dress > ( ) ;
2022-05-06 15:17:35 +08:00
2022-05-27 05:14:50 +08:00
//False SkinDress GameObject
2022-05-06 15:17:35 +08:00
if ( PlayerSkinDress ! = null )
{
foreach ( SkinDress skindress in PlayerSkinDress )
{
PlayerSkinGameObject . Add ( skindress . gameObject ) ;
}
}
if ( PlayerDress ! = null )
{
foreach ( Dress dress in PlayerDress )
{
2022-05-27 05:14:50 +08:00
PlayerDressGameObject . Add ( dress . gameObject ) ;
2022-05-06 15:17:35 +08:00
}
}
2022-05-27 05:14:50 +08:00
//Hide Dress GameObject
if ( PlayerDressGameObject ! = null )
{
List < GameObject > Loot = new List < GameObject > ( ) ;
foreach ( GameObject dress in PlayerDressGameObject )
{
MeshRenderer [ ] MeshRenderer = dress . GetComponentsInChildren < MeshRenderer > ( ) ;
//Loot False Hide
if ( dress ! = null & & dress . GetComponentInParent < GamePlayerOwner > ( ) ! = null )
{
foreach ( MeshRenderer mesh in MeshRenderer )
{
mesh . enabled = ! KeyPlayerSkinHide . Value ;
}
}
else
{
foreach ( MeshRenderer mesh in MeshRenderer )
{
mesh . enabled = true ;
}
Loot . Add ( dress ) ;
}
}
2022-05-27 05:54:47 +08:00
//Loot from List Remove
2022-05-27 05:14:50 +08:00
if ( Loot ! = null )
{
PlayerDressGameObject . ExceptWith ( Loot ) ;
}
}
//False or true SkinDress and Dress GameObject
2022-05-06 15:17:35 +08:00
if ( PlayerSkinGameObject ! = null )
{
2022-05-27 05:14:50 +08:00
List < GameObject > Loot = new List < GameObject > ( ) ;
2022-05-06 15:17:35 +08:00
foreach ( GameObject skin in PlayerSkinGameObject )
{
2022-05-27 05:14:50 +08:00
if ( skin ! = null & & skin . GetComponentInParent < GamePlayerOwner > ( ) ! = null )
{
skin . SetActive ( ! KeyPlayerSkinHide . Value ) ;
}
else
{
skin . SetActive ( true ) ;
Loot . Add ( skin ) ;
}
}
2022-05-27 05:21:50 +08:00
//Loot from List Remove
2022-05-27 05:14:50 +08:00
if ( Loot ! = null )
{
PlayerSkinGameObject . ExceptWith ( Loot ) ;
2022-05-06 15:17:35 +08:00
}
}
}
else
{
2022-05-06 16:01:02 +08:00
//Quit Raid Clear GameObject List
2022-05-06 15:17:35 +08:00
PlayerSkinGameObject . Clear ( ) ;
2022-05-27 05:14:50 +08:00
PlayerDressGameObject . Clear ( ) ;
2022-05-06 15:17:35 +08:00
}
2022-05-06 16:01:02 +08:00
//Clear List null Bot
2022-05-06 15:17:35 +08:00
Bot . RemoveAll ( x = > x = = null ) ;
2022-05-06 16:01:02 +08:00
//Bot Skin Hide
2022-05-27 05:14:50 +08:00
if ( Bot ! = null & & ! KeyBotSkinHideShutDown . Value )
2022-05-06 15:17:35 +08:00
{
2022-05-06 16:01:02 +08:00
//Get Bot all SkinDress and Dress
2022-05-06 15:17:35 +08:00
foreach ( GameObject bot in Bot )
{
2022-05-27 05:14:50 +08:00
SkinDress [ ] botskindress = bot . transform . Find ( "Player/Mesh" ) . gameObject . GetComponentsInChildren < SkinDress > ( ) ;
2022-05-06 15:17:35 +08:00
2022-05-27 05:14:50 +08:00
foreach ( SkinDress skinDress in botskindress )
{
BotSkinGameObject . Add ( skinDress . gameObject ) ;
}
Dress [ ] botDress = bot . transform . Find ( "Player/Root_Joint" ) . gameObject . GetComponentsInChildren < Dress > ( ) ;
foreach ( Dress Dress in botDress )
2022-05-06 15:17:35 +08:00
{
2022-05-27 05:14:50 +08:00
BotDressGameObject . Add ( Dress . gameObject ) ;
2022-05-06 15:17:35 +08:00
}
}
2022-05-27 05:14:50 +08:00
//Hide Dress GameObject
if ( BotDressGameObject ! = null )
2022-05-06 15:17:35 +08:00
{
2022-05-27 05:14:50 +08:00
List < GameObject > Loot = new List < GameObject > ( ) ;
foreach ( GameObject botdress in BotDressGameObject )
2022-05-06 15:17:35 +08:00
{
2022-05-27 05:14:50 +08:00
MeshRenderer [ ] MeshRenderer = botdress . GetComponentsInChildren < MeshRenderer > ( ) ;
//Loot False Hide
if ( botdress . GetComponentInParent < BotOwner > ( ) ! = null )
{
foreach ( MeshRenderer botmesh in MeshRenderer )
{
botmesh . enabled = ! KeyBotSkinHide . Value ;
}
}
else
{
foreach ( MeshRenderer botmesh in MeshRenderer )
{
botmesh . enabled = true ;
}
Loot . Add ( botdress ) ;
}
}
2022-05-27 05:21:50 +08:00
//Loot from List Remove
2022-05-27 05:14:50 +08:00
if ( Loot ! = null )
{
BotDressGameObject . ExceptWith ( Loot ) ;
2022-05-06 15:17:35 +08:00
}
}
2022-05-27 05:14:50 +08:00
//False or true SkinDress GameObject
2022-05-06 15:17:35 +08:00
if ( BotSkinGameObject ! = null )
{
2022-05-27 05:14:50 +08:00
List < GameObject > Loot = new List < GameObject > ( ) ;
2022-05-06 15:17:35 +08:00
foreach ( GameObject botskin in BotSkinGameObject )
{
2022-05-27 05:14:50 +08:00
if ( botskin . GetComponentInParent < BotOwner > ( ) ! = null )
{
botskin . SetActive ( ! KeyBotSkinHide . Value ) ;
}
else
{
botskin . SetActive ( true ) ;
Loot . Add ( botskin ) ;
}
}
2022-05-27 05:21:50 +08:00
//Loot from List Remove
2022-05-27 05:14:50 +08:00
if ( Loot ! = null )
{
BotSkinGameObject . ExceptWith ( Loot ) ;
2022-05-06 15:17:35 +08:00
}
}
}
else
{
2022-05-06 16:01:02 +08:00
//Quit Raid Clear GameObject List
2022-05-06 15:17:35 +08:00
BotSkinGameObject . Clear ( ) ;
2022-05-27 05:14:50 +08:00
BotDressGameObject . Clear ( ) ;
2022-05-06 15:17:35 +08:00
}
}
}
}