Иконка ресурса

FREE Skinner : 1.5.6 1.5.6

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
/* Copyright (C) Whispers88 - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * Written by Whispers88 rustafarian.server@gmail.com, February 2023
 */
using Network;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Libraries.Covalence;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Networking;
namespace Oxide.Plugins {
    /*ПЛАГИН БЫЛ ПОФИКШЕН С ПОМОЩЬЮ ПРОГРАММЫ СКАЧАНОЙ С https://discord.gg/dNGbxafuJn */
    [Info("Skinner", "https://discord.gg/dNGbxafuJn", "1.5.6")]
    [Description("Brings automation and ease to skinning items")]
    public class Skinner : CovalencePlugin {
        static Skinner skinner;
        private DynamicConfigFile _defaultSkins;
        private DynamicConfigFile _defaultSkins2;
        private DynamicConfigFile _defaultSkins3;
        private const string permdefault = "skinner.default";
        private const string permitems = "skinner.items";
        private const string permcraft = "skinner.craft";
        private const string permskininv = "skinner.skininv";
        private const string permskincon = "skinner.skincon";
        private const string permbypassauth = "skinner.bypassauth";
        private const string permimport = "skinner.import";
        private const string permskinbase = "skinner.skinbase";
        private const string permskinall = "skinner.skinall";
        private static List<string> _registeredhooks = new List<string> {
            "OnLootEntityEnd"
        }
        ;
        //, "CanStackItem" };//, "OnMaxStackable" };
        private Dictionary<ulong, Dictionary<string, CachedSkin>> _playerDefaultSkins = new Dictionary<ulong, Dictionary<string, CachedSkin>>();
        private Dictionary<ulong, Dictionary<string, CachedSkin>> _playerDefaultSkins2 = new Dictionary<ulong, Dictionary<string, CachedSkin>>();
        private Dictionary<ulong, Dictionary<string, CachedSkin>> _playerDefaultSkins3 = new Dictionary<ulong, Dictionary<string, CachedSkin>>();
        private Dictionary<ulong, int> _playerSelectedSet = new Dictionary<ulong, int>();
        private List<string> permissions = new List<string>() {
            permdefault, permcraft, permitems, permbypassauth, permskincon, permskininv, permimport, permskinbase, permskinall
        }
        ;
        private Dictionary<ulong, CoolDowns> _playercooldowns = new Dictionary<ulong, CoolDowns>();
        public class CoolDowns {
            public float skin = 30f;
            public float skinitem = 30f;
            public float skincraft = 30f;
            public float skincon = 30f;
            public float skininv = 30f;
            public float skinbase = 60f;
            public float skinall = 60f;
        }
#region Init
        private void OnServerInitialized() {
            skinner = this;
            foreach (string perm in permissions) permission.RegisterPermission(perm, this);
            foreach (string perm in config.Cooldowns.Keys) permission.RegisterPermission($"skinner.{perm}", this);
            AddCovalenceCommand(config.cmdsskin, "SkinCMD");
            AddCovalenceCommand(config.cmdsskincraft, "DefaultSkinsCMD");
            AddCovalenceCommand(config.cmdsskinitems, "SkinItemCMD");
            AddCovalenceCommand(config.cmdsskininv, "SkinInvCMD");
            AddCovalenceCommand(config.cmdsskincon, "SkinConCMD");
            AddCovalenceCommand(config.cmdskinimport, "SkinImportCMD");
            AddCovalenceCommand(config.cmdcollectionimport, "SkinImportCollection");
            AddCovalenceCommand(config.cmdskinbase, "SkinBaseCMD");
            AddCovalenceCommand(config.cmdskinallitems, "SkinAllItemsCMD");
            AddCovalenceCommand(new[] {
                "sbNextPage"
            }
            , "SBNextPageCMD");
            AddCovalenceCommand(new[] {
                "sbBackPage"
            }
            , "SBBackPageCMD");
            AddCovalenceCommand(new[] {
                "searchCMD"
            }
            , "SearchCMD");
            AddCovalenceCommand(new[] {
                "setSelectCMD", "skinset", "ss"
            }
            , "SetSelectCMD");
            //Convert Old Skins Config
            foreach (var oldskin in config.Importedskins) {
                if (!config.ImportedSkinList.ContainsKey(oldskin.Key)) config.ImportedSkinList.Add(oldskin.Key, new ImportedItem());
            }
            config.Importedskins.Clear();
            foreach (var skin in config.ImportedSkinList) {
                if (string.IsNullOrEmpty(skin.Value?.itemDisplayname ?? string.Empty) || string.IsNullOrEmpty(skin.Value?.itemShortname ?? string.Empty)) {
                    if (!_WorkshopSkinIDCollectionList.Contains(skin.Key.ToString())) _WorkshopSkinIDCollectionList.Add(skin.Key.ToString());
                }
            }
            //GetSkins();
            if (getCollectionscouroutine != null) {
                Puts("getcollections already running!!");
            }
            else {
                getCollectionscouroutine = GetCollectionSkinIDS();
                ServerMgr.Instance.StartCoroutine(getCollectionscouroutine);
            }
        }
        private void Loaded() {
            _defaultSkins = Interface.Oxide.DataFileSystem.GetFile("DefaultCraftSkins");
            _defaultSkins2 = Interface.Oxide.DataFileSystem.GetFile("DefaultCraftSkins2");
            _defaultSkins3 = Interface.Oxide.DataFileSystem.GetFile("DefaultCraftSkins3");
            LoadData();
        }
        private void Unload() {
            SaveData();
            foreach (var player in _viewingcon) {
                BaseEntity baseEntity = player.inventory.loot?.entitySource ?? null;
                if (baseEntity != null) {
                    BoxController boxController;
                    if (baseEntity.TryGetComponent<BoxController>(out boxController)) {
                        UnityEngine.GameObject.Destroy(boxController);
                    }
                }
            }
            foreach (var player in BasePlayer.activePlayerList) {
                CuiHelper.DestroyUi(player, "SkinPageUI");
                CuiHelper.DestroyUi(player, "SkinSearchUI");
                CuiHelper.DestroyUi(player, "SkinSetsSelectUI");
                SpraycanController spraycanController;
                if (player.TryGetComponent<SpraycanController>(out spraycanController)) {
                    UnityEngine.GameObject.Destroy(spraycanController);
                }
            }
            if (getCollectionscouroutine != null) ServerMgr.Instance.StopCoroutine(getCollectionscouroutine);
            if (getSteamWorkshopSkinData != null) ServerMgr.Instance.StopCoroutine(getSteamWorkshopSkinData);
        }
        public class CachedSkin {
            public string shortname = string.Empty;
            public string displayName = string.Empty;
            public ulong skinid = 0;
            public bool redirect = false;
            public string redirectshortname = string.Empty;
            public ItemCategory category;
        }
        private Dictionary<string, List<CachedSkin>> _skinsCache = new Dictionary<string, List<CachedSkin>>();
        private Dictionary<string, string> _redirectSkins = new Dictionary<string, string>();
        private Dictionary<string, CachedSkin> _defaultskins = new Dictionary<string, CachedSkin>();
        private void GetSkins() {
            if ((Steamworks.SteamInventory.Definitions?.Length ?? 0) == 0) {
                Puts("Waiting for Steamworks to update skin item definitions");
                Steamworks.SteamInventory.OnDefinitionsUpdated += GetSkins;
                return;
            }
            int sk = 0;
            Puts("Steamworks Updated, Updating Skins");
            Steamworks.SteamInventory.OnDefinitionsUpdated -= GetSkins;
            if (_skinsCache.Count < 1) {
                foreach (ItemDefinition itemDef in ItemManager.GetItemDefinitions()) {
                    List<CachedSkin> skins = new List<CachedSkin>() {
                        new CachedSkin() {
                            skinid = 0uL, shortname = itemDef.shortname
                        }
                    }
                    ;
                    foreach (var skin in ItemSkinDirectory.ForItem(itemDef)) {
                        if (config.blacklistedskins.Contains((ulong)skin.id)) continue;
                        if (skin.id == 0) continue;
                        CachedSkin cachedSkin = new CachedSkin {
                            skinid = Convert.ToUInt64(skin.id), shortname = itemDef.shortname, displayName = skin.invItem?.displayName?.english ?? itemDef.displayName.english
                        }
                        ;
                        ItemSkin itemSkin = skin.invItem as ItemSkin;
                        if (itemSkin != null && itemSkin.Redirect != null) {
                            cachedSkin.redirect = true;
                            cachedSkin.redirectshortname = itemSkin.Redirect.shortname;
                            if (!_redirectSkins.ContainsKey(cachedSkin.redirectshortname)) _redirectSkins.Add(cachedSkin.redirectshortname, itemDef.shortname);
                        }
                        skins.Add(cachedSkin);
                    }
                    if (skins.Count > 1) {
                        _skinsCache.Add(itemDef.shortname, skins);
                    }
                }
                foreach (Steamworks.InventoryDef item in Steamworks.SteamInventory.Definitions) {
                    string shortname = item.GetProperty("itemshortname") == "lr300.item" ? "rifle.lr300" : item.GetProperty("itemshortname");
                    if (string.IsNullOrEmpty(shortname) || item.Id < 100) continue;
                    ulong skinid;
                    if (config.blacklistedskins.Contains((ulong)item.Id)) continue;
                    if (!ulong.TryParse(item.GetProperty("workshopid"), out skinid)) {
                        skinid = (ulong)item.Id;
                    }
                    if (skinid < 100000) continue;
                    List<CachedSkin> skins;
                    if (_skinsCache.TryGetValue(shortname, out skins)) {
                        if (skins.Where(x => x.skinid == skinid || x.skinid == (ulong)item.Id).Count() > 0) continue;
                        skins.Add(new CachedSkin {
                            skinid = Convert.ToUInt64(skinid), shortname = shortname, displayName = item.Name
                        }
                        );
                    }
                    else {
                        _skinsCache.Add(shortname, new List<CachedSkin>() {
                            new CachedSkin {
                                skinid = 0, shortname = shortname
                            }
                            , new CachedSkin {
                                skinid = Convert.ToUInt64(skinid), shortname = shortname, displayName = item.Name
                            }
                        }
                        );
                    }
                }
            }
            foreach (var whitelistSkin in config.ImportedSkinList) {
                ItemDefinition itemdef = ItemManager.FindItemDefinition(whitelistSkin.Value.itemShortname);
                if (itemdef == null) {
                    Puts($"Could not find item definition for {whitelistSkin.Value.itemShortname} {whitelistSkin.Key}");
                    continue;
                }
                List<CachedSkin> skins2;
                if (_skinsCache.TryGetValue(itemdef.shortname, out skins2)) {
                    bool skip = false;
                    foreach (var a in skins2) {
                        if (a.skinid == whitelistSkin.Key) {
                            skip = true;
                            break;
                        }
                    }
                    if (!skip) skins2.Add(new CachedSkin {
                        skinid = whitelistSkin.Key, shortname = itemdef.shortname, displayName = whitelistSkin.Value.itemDisplayname
                    }
                    );
                }
                else {
                    Puts($"No default skins for {whitelistSkin.Value.itemShortname} trying to apply custom skin{whitelistSkin.Key}");
                    _skinsCache.Add(itemdef.shortname, new List<CachedSkin>() {
                        new CachedSkin() {
                            shortname = itemdef.shortname, displayName = whitelistSkin.Value.itemDisplayname, skinid = whitelistSkin.Key
                        }
                    }
                    );
                }
            }
            foreach (var item2 in _skinsCache.ToList()) {
                if (_redirectSkins.ContainsKey(item2.Key)) continue;
                int skinsamt = item2.Value.Count;
                sk += skinsamt;
                if (skinsamt == 1) {
                    _skinsCache.Remove(item2.Key);
                    continue;
                }
                ItemDefinition itemdef = ItemManager.FindItemDefinition(item2.Key);
                if (itemdef == null || itemdef?.Blueprint == null) {
                    _skinsCache.Remove(item2.Key);
                    continue;
                }
                //if (!itemdef.Blueprint.userCraftable)
                //    continue;
                if (!_defaultskins.ContainsKey(item2.Key)) _defaultskins.Add(item2.Key, new CachedSkin() {
                    shortname = item2.Key, category = itemdef.category
                }
                );
            }
            SaveConfig();
            //Re-order to look nice
            _defaultskins = _defaultskins.OrderBy(key => key.Value.category).ToDictionary(x => x.Key, x => x.Value);
            Puts($"{sk} skins were indexed, Skin indexing complete");
            if (!config.sprayCanOveride) Unsubscribe("OnActiveItemChanged");
        }
#endregion Init
#region Configuration
        private Configuration config;
        public class Configuration {
            [JsonProperty("Skin Commands (skin items in you inventory")]
            public string[] cmdsskin = new[] {
                "skin", "s"
            }
            ;
            [JsonProperty("Skin Items Commands (skin items you have already placed")]
            public string[] cmdsskinitems = new[] {
                "skinitem", "si"
            }
            ;
            [JsonProperty("Set default items to be skinned")]
            public string[] cmdsskincraft = new[] {
                "skincraft", "sc"
            }
            ;
            [JsonProperty("Automatically set all items in you inventory to your default skins")]
            public string[] cmdsskininv = new[] {
                "skininv", "sinv"
            }
            ;
            [JsonProperty("Automatically set all items a container to your default skins")]
            public string[] cmdsskincon = new[] {
                "skincon", "scon"
            }
            ;
            [JsonProperty("Automatically skin all deployables in your base")]
            public string[] cmdskinbase = new[] {
                "skinbase", "skinbuilding"
            }
            ;
            [JsonProperty("Automatically skin all items in your base")]
            public string[] cmdskinallitems = new[] {
                "skinall", "sa"
            }
            ;
            [JsonProperty("Import Custom Skins")]
            public string[] cmdskinimport = new[] {
                "skinimport", "sip"
            }
            ;
            [JsonProperty("Import Workshop Collection Command")]
            public string[] cmdcollectionimport = new[] {
                "colimport", "cip"
            }
            ;
            [JsonProperty("Custom Page Change UI Positon 'min x, min y', 'max x', max y'")]
            public string[] uiposition = new[] {
                "0.66 0.05", "0.82 0.1"
            }
            ;
            [JsonProperty("Custom Searchbar UI Positon 'min x, min y', 'max x', max y'")]
            public string[] uisearchposition = new[] {
                "0.70 0.88", "0.82 0.91"
            }
            ;
            [JsonProperty("Custom Set Selection UI Positon 'min x, min y', 'max x', max y'")]
            public string[] uisetsposition = new[] {
                "0.70 0.845", "0.93 0.875"
            }
            ;
            [JsonProperty("Apply names of skins to skinned items")]
            public bool applySkinNames = true;
            [JsonProperty("Add Search Bar UI")]
            public bool searchbar = true;
            [JsonProperty("Override spraycan behaviour")]
            public bool sprayCanOveride = false;
            [JsonProperty("Use spraycan effect when holding spraycan and skinning deployables")]
            public bool sprayCanEffect = true;
            [JsonProperty("Blacklisted Skins (skinID)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<ulong> blacklistedskins = new List<ulong>();
            [JsonProperty("Import Skin collections (steam workshop ID)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<ulong> skinCollectionIDs = new List<ulong>();
            [JsonProperty("Command based cooldowns ('permission' : 'command' seconds")]
            public Dictionary<string, CoolDowns> Cooldowns = new Dictionary<string, CoolDowns>() {
                {
                    "Default30CD", new CoolDowns()
                }
            }
            ;
            [JsonProperty("Imported Skins List", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<ulong, ImportedItem> ImportedSkinList = new Dictionary<ulong, ImportedItem>();
            [JsonProperty("Imported Skins (skinid : 'shortnamestring', skinid2 : 'shortnamestring2'", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<ulong, string> Importedskins = new Dictionary<ulong, string>() {
                {
                    861142659, "vending.machine"
                }
            }
            ;
            public string ToJson() => JsonConvert.SerializeObject(this);
            public Dictionary<string, object> ToDictionary() => JsonConvert.DeserializeObject<Dictionary<string, object>>(ToJson());
        }
        public class ImportedItem {
            public string itemShortname = string.Empty;
            public string itemDisplayname = string.Empty;
        }
        protected override void LoadDefaultConfig() => config = new Configuration();
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                config = Config.ReadObject<Configuration>();
                if (config == null) {
                    throw new JsonException();
                }
                if (!config.ToDictionary().Keys.SequenceEqual(Config.ToDictionary(x => x.Key, x => x.Value).Keys)) {
                    Puts("Configuration appears to be outdated; updating and saving");
                    SaveConfig();
                }
            }
            catch {
                Puts($"Configuration file {Name}.json is invalid; using defaults");
                LoadDefaultConfig();
            }
        }
        protected override void SaveConfig() {
            Puts($"Configuration changes saved to {Name}.json");
            Config.WriteObject(config, true);
        }
#endregion Configuration
#region Data
        private void LoadData() {
            try {
                _playerDefaultSkins = _defaultSkins.ReadObject<Dictionary<ulong, Dictionary<string, CachedSkin>>>();
            }
            catch {
                _playerDefaultSkins = new Dictionary<ulong, Dictionary<string, CachedSkin>>();
            }
            try {
                _playerDefaultSkins2 = _defaultSkins2.ReadObject<Dictionary<ulong, Dictionary<string, CachedSkin>>>();
            }
            catch {
                _playerDefaultSkins2 = new Dictionary<ulong, Dictionary<string, CachedSkin>>();
            }
            try {
                _playerDefaultSkins3 = _defaultSkins3.ReadObject<Dictionary<ulong, Dictionary<string, CachedSkin>>>();
            }
            catch {
                _playerDefaultSkins3 = new Dictionary<ulong, Dictionary<string, CachedSkin>>();
            }
        }
        private void SaveData() {
            _defaultSkins.WriteObject(_playerDefaultSkins);
            _defaultSkins2.WriteObject(_playerDefaultSkins2);
            _defaultSkins3.WriteObject(_playerDefaultSkins3);
        }
#endregion Data
#region Localization
        protected override void LoadDefaultMessages() {
            lang.RegisterMessages(new Dictionary<string, string> {
                ["NoPerms"]
                = "You don't have permissions to use this command", ["NoBuildingAuth"] = "You must have building auth to use this", ["NoObjectsFound"] = "No object found", ["NoSkins"] = "No skins available", ["ImportSkinArgs"] = "Bad args, Required input skinid", ["ImportCollectionArgs"] = "Bad args, Required input collectionID", ["SkinIDError"] = "Cannot parse skinid {0}", ["NoShortname"] = "No item found for shortname : {0}", ["DuplicateSkin"] = "Duplicate Skin ID for : {0} {1}", ["SkinImported2"] = "Skin {0} has been imported and saved", ["CollectionImported2"] = "Steam Skin Collection {0} has been imported and saved", ["CommandCooldown"] = "You can not use this command for another {0}", ["CompletedInvSkin"] = "All items in your inventory have been set to your default skins", ["CompletedConSkin"] = "All items in {0} have been set to your default skins", ["CompletedBuildingSkin"] = "All {0} in your base have been set to your default skins", ["CompletedAllSkin"] = "All {0} items in your base have been set to your default skins", ["SkinSetSelected"] = "Skin set {0} selected", ["SkinSetSelectedArgs"] = "Bad args, Required input set No.1, 2 or 3"
            }
            , this);
        }
#endregion Localization
#region Commands
        private void SkinImportCMD(IPlayer iplayer, string command, string[] args) {
            BasePlayer player = iplayer.Object as BasePlayer;
            if (player != null) {
                if (!HasPerm(player.UserIDString, permimport)) {
                    ChatMessage(iplayer, "NoPerms");
                    return;
                }
            }
            else if (!iplayer.IsServer) return;
            if (args.Length < 1) {
                ChatMessage(iplayer, "ImportSkinArgs");
                return;
            }
            ulong skinid = 0ul;
            if (!ulong.TryParse(args[0], out skinid)) {
                ChatMessage(iplayer, "ImportSkinArgs", args[0]);
                return;
            }
            _WorkshopSkinIDCollectionList.Add(skinid.ToString());
            if (getSteamWorkshopSkinData != null) {
                Puts("getSteamWorkshopSkinData already running!!");
            }
            else {
                getSteamWorkshopSkinData = GetSteamWorkshopSkinData();
                ServerMgr.Instance.StartCoroutine(getSteamWorkshopSkinData);
            }
            ChatMessage(iplayer, "SkinImported2", args[0]);
        }
        private void SkinImportCollection(IPlayer iplayer, string command, string[] args) {
            BasePlayer player = iplayer.Object as BasePlayer;
            if (player != null) {
                if (!HasPerm(player.UserIDString, permimport)) {
                    ChatMessage(iplayer, "NoPerms");
                    return;
                }
            }
            else if (!iplayer.IsServer) return;
            if (args.Length < 1) {
                ChatMessage(iplayer, "ImportCollectionArgs");
                return;
            }
            ulong collectionid = 0ul;
            if (!ulong.TryParse(args[0], out collectionid)) {
                ChatMessage(iplayer, "ImportCollectionArgs", args[0]);
                return;
            }
            config.skinCollectionIDs.Add(collectionid);
            if (getCollectionscouroutine != null) {
                Puts("getcollections already running!!");
            }
            else {
                getCollectionscouroutine = GetCollectionSkinIDS();
                ServerMgr.Instance.StartCoroutine(getCollectionscouroutine);
            }
            ChatMessage(iplayer, "CollectionImported2", args[0]);
        }
        private void SkinCMD(IPlayer iplayer, string command, string[] args) {
            BasePlayer player = iplayer.Object as BasePlayer;
            if (player == null) return;
            player.EndLooting();
            if (!HasPerm(player.UserIDString, permdefault)) {
                ChatMessage(iplayer, "NoPerms");
                return;
            }
            //Check for cooldown
            float cdtime = 0;
            //Find shortest cd perm
            foreach (var cdperm in config.Cooldowns) {
                if (!HasPerm(player.UserIDString, $"skinner.{cdperm.Key}")) continue;
                if (cdtime == 0) cdtime = cdperm.Value.skin;
                else if (cdtime > cdperm.Value.skin) cdtime = cdperm.Value.skin;
            }
            if (cdtime > 0) {
                CoolDowns coolDowns;
                if (!_playercooldowns.TryGetValue(player.userID, out coolDowns)) _playercooldowns.Add(player.userID, new CoolDowns() {
                    skin = Time.time
                }
                );
                else {
                    if (coolDowns.skin + cdtime > Time.time) {
                        ChatMessage(iplayer, "CommandCooldown", TimeSpan.FromSeconds(coolDowns.skin + cdtime - Time.time).ToString("hh' hrs 'mm' mins 'ss' secs'"));
                        return;
                    }
                    coolDowns.skin = Time.time;
                }
            }
            StorageContainer storageContainer = CreateStorageCon(player);
            BoxController boxController;
            if (!storageContainer.TryGetComponent<BoxController>(out boxController)) {
                storageContainer.Kill();
                return;
            }
            boxController.StartItemSkin();
            if (!_viewingcon.Contains(player)) _viewingcon.Add(player);
            if (_viewingcon.Count == 1) SubscribeToHooks();
            timer.Once(0.3f, () => {
                StartLooting(player, storageContainer);
            }
            );
        }
        private void DefaultSkinsCMD(IPlayer iplayer, string command, string[] args) {
            BasePlayer player = iplayer.Object as BasePlayer;
            if (player == null) return;
            if (!HasPerm(player.UserIDString, permcraft)) {
                ChatMessage(iplayer, "NoPerms");
                return;
            }
            //Check for cooldown
            float cdtime = 0;
            //Find shortest cd perm
            foreach (var cdperm in config.Cooldowns) {
                if (!HasPerm(player.UserIDString, $"skinner.{cdperm.Key}")) continue;
                if (cdtime == 0) cdtime = cdperm.Value.skincraft;
                else if (cdtime > cdperm.Value.skincraft) cdtime = cdperm.Value.skincraft;
            }
            if (cdtime > 0) {
                CoolDowns coolDowns;
                if (!_playercooldowns.TryGetValue(player.userID, out coolDowns)) _playercooldowns.Add(player.userID, new CoolDowns() {
                    skincraft = Time.time
                }
                );
                else {
                    if (coolDowns.skincraft + cdtime > Time.time) {
                        ChatMessage(iplayer, "CommandCooldown", TimeSpan.FromSeconds(coolDowns.skincraft + cdtime - Time.time).ToString("hh' hrs 'mm' mins 'ss' secs'"));
                        return;
                    }
                    coolDowns.skincraft = Time.time;
                }
            }
            if (!_playerDefaultSkins.ContainsKey(player.userID)) _playerDefaultSkins.Add(player.userID, new Dictionary<string, CachedSkin>());
            StorageContainer storageContainer = CreateStorageCon(player);
            BoxController boxController;
            if (!storageContainer.TryGetComponent<BoxController>(out boxController)) {
                storageContainer.Kill();
                return;
            }
            boxController.GetDefaultSkins();
            if (!_viewingcon.Contains(player)) _viewingcon.Add(player);
            if (_viewingcon.Count == 1) SubscribeToHooks();
            timer.Once(0.3f, () => {
                StartLooting(player, storageContainer);
            }
            );
        }
        private static int Layermask = LayerMask.GetMask("Deployed", "Construction");
        private void SkinItemCMD(IPlayer iplayer, string command, string[] args) {
            BasePlayer player = iplayer.Object as BasePlayer;
            if (player == null) return;
            if (!HasPerm(player.UserIDString, permitems)) {
                ChatMessage(iplayer, "NoPerms");
                return;
            }
            if (!player.CanBuild() && !HasPerm(player.UserIDString, permbypassauth)) {
                ChatMessage(iplayer, "NoBuildingAuth");
                return;
            }
            RaycastHit raycastHit;
            if (!Physics.Raycast(player.eyes.HeadRay(), out raycastHit, 5f, Layermask)) {
                ChatMessage(iplayer, "NoObjectsFound");
                return;
            }
            BaseCombatEntity entity = raycastHit.GetEntity() as BaseCombatEntity;
            if (entity == null || entity?.pickup.itemTarget == null) {
                ChatMessage(iplayer, "NoObjectsFound");
                return;
            }
            if (!_skinsCache.ContainsKey(entity.pickup.itemTarget.shortname)) {
                ChatMessage(iplayer, "NoSkins");
                return;
            }
            //Check for cooldown
            float cdtime = 0;
            //Find shortest cd perm
            foreach (var cdperm in config.Cooldowns) {
                if (!HasPerm(player.UserIDString, $"skinner.{cdperm.Key}")) continue;
                if (cdtime == 0) cdtime = cdperm.Value.skinitem;
                else if (cdtime > cdperm.Value.skinitem) cdtime = cdperm.Value.skinitem;
            }
            if (cdtime > 0) {
                CoolDowns coolDowns;
                if (!_playercooldowns.TryGetValue(player.userID, out coolDowns)) _playercooldowns.Add(player.userID, new CoolDowns() {
                    skinitem = Time.time
                }
                );
                else {
                    if (coolDowns.skinitem + cdtime > Time.time) {
                        ChatMessage(iplayer, "CommandCooldown", TimeSpan.FromSeconds(coolDowns.skinitem + cdtime - Time.time).ToString("hh' hrs 'mm' mins 'ss' secs'"));
                        return;
                    }
                    coolDowns.skinitem = Time.time;
                }
            }
            StorageContainer storageContainer = CreateStorageCon(player);
            BoxController boxController;
            if (!storageContainer.TryGetComponent<BoxController>(out boxController)) {
                storageContainer.Kill();
                return;
            }
            boxController.SkinDeplyoables(entity);
            if (!_viewingcon.Contains(player)) _viewingcon.Add(player);
            if (_viewingcon.Count == 1) SubscribeToHooks();
            timer.Once(0.3f, () => {
                StartLooting(player, storageContainer);
            }
            );
        }
        private void SkinInvCMD(IPlayer iplayer, string command, string[] args) {
            BasePlayer player = iplayer.Object as BasePlayer;
            if (player == null) return;
            player.EndLooting();
            if (!HasPerm(player.UserIDString, permskininv)) {
                ChatMessage(iplayer, "NoPerms");
                return;
            }
            Dictionary<string, CachedSkin> cachedskins = GetCachedSkins(player);
            if (cachedskins.Count < 1) return;
            if (player.inventory == null) return;
            //Check for cooldown
            float cdtime = 0;
            //Find shortest cd perm
            foreach (var cdperm in config.Cooldowns) {
                if (!HasPerm(player.UserIDString, $"skinner.{cdperm.Key}")) continue;
                if (cdtime == 0) cdtime = cdperm.Value.skininv;
                else if (cdtime > cdperm.Value.skininv) cdtime = cdperm.Value.skininv;
            }
            if (cdtime > 0) {
                CoolDowns coolDowns;
                if (!_playercooldowns.TryGetValue(player.userID, out coolDowns)) _playercooldowns.Add(player.userID, new CoolDowns() {
                    skininv = Time.time
                }
                );
                else {
                    if (coolDowns.skininv + cdtime > Time.time) {
                        ChatMessage(iplayer, "CommandCooldown", TimeSpan.FromSeconds(coolDowns.skininv + cdtime - Time.time).ToString("hh' hrs 'mm' mins 'ss' secs'"));
                        return;
                    }
                    coolDowns.skininv = Time.time;
                }
            }
            List<Item> itemstoSkin = new List<Item>();
            foreach(Item item in Enumerable.Concat(player.inventory.containerMain?.itemList ?? Enumerable.Empty<Item>(), Enumerable.Concat(player.inventory.containerBelt?.itemList ?? Enumerable.Empty<Item>(), player.inventory.containerWear?.itemList ?? Enumerable.Empty<Item>()))) {
                if(item.IsBackpack()) {
                    if(item.contents.itemList.Count > 0) {
                        itemstoSkin.AddRange(item.contents.itemList);
                    }
                }
                itemstoSkin.Add(item);
            }
            foreach (Item item in itemstoSkin) {
                if (item == null) continue;
                CachedSkin cachedSkin;
                if (cachedskins.TryGetValue(item.info.shortname, out cachedSkin)) {
                    //skip blacklisted skin
                    if (config.blacklistedskins.Contains(item.skin)) continue;
                    if (cachedSkin.redirect) continue;
                    item.skin = cachedSkin.skinid;
                    BaseEntity held = item.GetHeldEntity();
                    if (held != null) {
                        held.skinID = cachedSkin.skinid;
                        held.SendNetworkUpdate();
                    }
                }
            }
            player.inventory.containerWear.MarkDirty();
            player.inventory.containerBelt.MarkDirty();
            player.SendNetworkUpdateImmediate();
            ChatMessage(iplayer, "CompletedInvSkin");
        }
        private void SkinConCMD(IPlayer iplayer, string command, string[] args) {
            BasePlayer player = iplayer.Object as BasePlayer;
            if (player == null) return;
            player.EndLooting();
            if (!HasPerm(player.UserIDString, permskincon)) {
                ChatMessage(iplayer, "NoPerms");
                return;
            }
            if (!player.IsBuildingAuthed() && !HasPerm(player.UserIDString, permbypassauth)) {
                ChatMessage(iplayer, "NoBuildingAuth");
                return;
            }
            Dictionary<string, CachedSkin> cachedskins = GetCachedSkins(player);
            if (cachedskins.Count < 1) return;
            RaycastHit raycastHit;
            if (!Physics.Raycast(player.eyes.HeadRay(), out raycastHit, 5f, Layermask)) {
                ChatMessage(iplayer, "NoObjectsFound");
                return;
            }
            StorageContainer storage = raycastHit.GetEntity() as StorageContainer;
            if (storage == null || storage?.inventory == null) {
                ChatMessage(iplayer, "NoObjectsFound");
                return;
            }
            //Check for cooldown
            float cdtime = 0;
            //Find shortest cd perm
            foreach (var cdperm in config.Cooldowns) {
                if (!HasPerm(player.UserIDString, $"skinner.{cdperm.Key}")) continue;
                if (cdtime == 0) cdtime = cdperm.Value.skincon;
                else if (cdtime > cdperm.Value.skincon) cdtime = cdperm.Value.skincon;
            }
            if (cdtime > 0) {
                CoolDowns coolDowns;
                if (!_playercooldowns.TryGetValue(player.userID, out coolDowns)) _playercooldowns.Add(player.userID, new CoolDowns() {
                    skincon = Time.time
                }
                );
                else {
                    if (coolDowns.skincon + cdtime > Time.time) {
                        ChatMessage(iplayer, "CommandCooldown", TimeSpan.FromSeconds(coolDowns.skincon + cdtime - Time.time).ToString("hh' hrs 'mm' mins 'ss' secs'"));
                        return;
                    }
                    coolDowns.skincon = Time.time;
                }
            }
            foreach (Item item in storage.inventory.itemList) {
                if (item == null) continue;
                CachedSkin cachedSkin;
                if (cachedskins.TryGetValue(item.info.shortname, out cachedSkin)) {
                    //skip blacklisted skin
                    if (config.blacklistedskins.Contains(item.skin)) continue;
                    if (cachedSkin.redirect) continue;
                    item.skin = cachedSkin.skinid;
                    BaseEntity held = item.GetHeldEntity();
                    if (held != null) {
                        held.skinID = cachedSkin.skinid;
                        held.SendNetworkUpdate();
                    }
                }
            }
            storage.SendNetworkUpdateImmediate();
            ChatMessage(iplayer, "CompletedConSkin", storage.ShortPrefabName);
        }
        private void SkinBaseCMD(IPlayer iplayer, string command, string[] args) {
            BasePlayer player = iplayer.Object as BasePlayer;
            if (player == null) return;
            if (!HasPerm(player.UserIDString, permskinbase)) {
                ChatMessage(iplayer, "NoPerms");
                return;
            }
            Dictionary<string, CachedSkin> cachedskins = GetCachedSkins(player);
            if (cachedskins.Count < 1) return;
            if (!player.IsBuildingAuthed() && !HasPerm(player.UserIDString, permbypassauth)) {
                ChatMessage(iplayer, "NoBuildingAuth");
                return;
            }
            BuildingPrivlidge buildingPrivlidge = player.GetBuildingPrivilege();
            if (buildingPrivlidge == null) {
                ChatMessage(iplayer, "NoBuildingAuth");
                return;
            }
            BuildingManager.Building buildingManager = buildingPrivlidge.GetBuilding();
            if (buildingManager == null) {
                ChatMessage(iplayer, "NoBuildingAuth");
                return;
            }
            //Check for cooldown
            float cdtime = 0;
            //Find shortest cd perm
            foreach (var cdperm in config.Cooldowns) {
                if (!HasPerm(player.UserIDString, $"skinner.{cdperm.Key}")) continue;
                if (cdtime == 0) cdtime = cdperm.Value.skinbase;
                else if (cdtime > cdperm.Value.skinbase) cdtime = cdperm.Value.skinbase;
            }
            if (cdtime > 0) {
                CoolDowns coolDowns;
                if (!_playercooldowns.TryGetValue(player.userID, out coolDowns)) _playercooldowns.Add(player.userID, new CoolDowns() {
                    skinbase = Time.time
                }
                );
                else {
                    if (coolDowns.skinbase + cdtime > Time.time) {
                        ChatMessage(iplayer, "CommandCooldown", TimeSpan.FromSeconds(coolDowns.skinbase + cdtime - Time.time).ToString("hh' hrs 'mm' mins 'ss' secs'"));
                        return;
                    }
                    coolDowns.skinbase = Time.time;
                }
            }
            string skinned = "all deplyoables";
            if (args.Length > 0) {
                skinned = $"{args[0]}s";
            }
            foreach (var decayent in buildingManager.decayEntities) {
                BaseCombatEntity baseCombatEntity = decayent?.GetEntity() as BaseCombatEntity;
                if (baseCombatEntity == null || baseCombatEntity.pickup.itemTarget == null) continue;
                CachedSkin cachedSkin;
                if (args.Length > 0) {
                    if (!baseCombatEntity.pickup.itemTarget.shortname.Contains(args[0])) continue;
                }
                if (cachedskins.TryGetValue(baseCombatEntity.pickup.itemTarget.shortname, out cachedSkin)) {
                    if (baseCombatEntity.skinID == cachedSkin.skinid) continue;
                    baseCombatEntity.skinID = cachedSkin.skinid;
                    if (baseCombatEntity.skinID == 0uL || baseCombatEntity.skinID < 100000) {
                        SendNetworkUpdate(baseCombatEntity, player);
                    }
                    else baseCombatEntity.SendNetworkUpdateImmediate();
                }
            }
            ChatMessage(iplayer, "CompletedBuildingSkin", skinned);
        }
        private Dictionary<string, CachedSkin> GetCachedSkins(BasePlayer player) {
            IPlayer iplayer = player.IPlayer;
            int set = 1;
            Dictionary<string, CachedSkin> cachedskins = new Dictionary<string, CachedSkin>();
            if (_playerSelectedSet.TryGetValue(player.userID, out set)) {
                if (set == 2) {
                    if (!_playerDefaultSkins2.TryGetValue(player.userID, out cachedskins)) {
                        _playerDefaultSkins2[player.userID] = new Dictionary<string, CachedSkin>();
                        ChatMessage(iplayer, "NoDefaultSkins");
                        return _playerDefaultSkins2[player.userID];
                    }
                    return cachedskins;
                }
                if (set == 3) {
                    if (!_playerDefaultSkins3.TryGetValue(player.userID, out cachedskins)) {
                        _playerDefaultSkins3[player.userID] = new Dictionary<string, CachedSkin>();
                        ChatMessage(iplayer, "NoDefaultSkins");
                        return _playerDefaultSkins3[player.userID];
                    }
                    return cachedskins;
                }
            }
            if (!_playerDefaultSkins.TryGetValue(player.userID, out cachedskins)) {
                ChatMessage(iplayer, "NoDefaultSkins");
                _playerDefaultSkins[player.userID] = new Dictionary<string, CachedSkin>();
                return _playerDefaultSkins[player.userID];
            }
            return cachedskins;
        }
        private void SkinAllItemsCMD(IPlayer iplayer, string command, string[] args) {
            BasePlayer player = iplayer.Object as BasePlayer;
            if (player == null) return;
            if (!HasPerm(player.UserIDString, permskinall)) {
                ChatMessage(iplayer, "NoPerms");
                return;
            }
            Dictionary<string, CachedSkin> cachedskins = GetCachedSkins(player);
            if (cachedskins.Count < 1) return;
            if (!player.IsBuildingAuthed() && !HasPerm(player.UserIDString, permbypassauth)) {
                ChatMessage(iplayer, "NoBuildingAuth");
                return;
            }
            BuildingPrivlidge buildingPrivlidge = player.GetBuildingPrivilege();
            if (buildingPrivlidge == null) {
                ChatMessage(iplayer, "NoBuildingAuth");
                return;
            }
            BuildingManager.Building buildingManager = buildingPrivlidge.GetBuilding();
            if (buildingManager == null) {
                ChatMessage(iplayer, "NoBuildingAuth");
                return;
            }
            //Check for cooldown
            float cdtime = 0;
            //Find shortest cd perm
            foreach (var cdperm in config.Cooldowns) {
                if (!HasPerm(player.UserIDString, $"skinner.{cdperm.Key}")) continue;
                if (cdtime == 0) cdtime = cdperm.Value.skinall;
                else if (cdtime > cdperm.Value.skinall) cdtime = cdperm.Value.skinall;
            }
            if (cdtime > 0) {
                CoolDowns coolDowns;
                if (!_playercooldowns.TryGetValue(player.userID, out coolDowns)) _playercooldowns.Add(player.userID, new CoolDowns() {
                    skinall = Time.time
                }
                );
                else {
                    if (coolDowns.skinall + cdtime > Time.time) {
                        ChatMessage(iplayer, "CommandCooldown", TimeSpan.FromSeconds(coolDowns.skinall + cdtime - Time.time).ToString("hh' hrs 'mm' mins 'ss' secs'"));
                        return;
                    }
                    coolDowns.skinall = Time.time;
                }
            }
            string skinned = "items";
            ItemDefinition itemdef = null;
            if (args.Length > 0) {
                itemdef = ItemManager.FindItemDefinition(args[0]);
                if (itemdef == null) {
                    ChatMessage(iplayer, "NoShortname", args[0]);
                    return;
                }
                skinned = itemdef.shortname;
            }
            foreach (var decayent in buildingManager.decayEntities) {
                StorageContainer storageContainer = decayent?.GetEntity() as StorageContainer;
                if (storageContainer == null) continue;
                foreach (var item in storageContainer.inventory.itemList) {
                    if (itemdef != null) {
                        if (item.info.shortname != itemdef.shortname) continue;
                    }
                    //skip blacklisted skin
                    if (config.blacklistedskins.Contains(item.skin)) continue;
                    CachedSkin cachedSkin;
                    if (cachedskins.TryGetValue(item.info.shortname, out cachedSkin)) {
                        if (item.skin == cachedSkin.skinid) continue;
                        item.skin = cachedSkin.skinid;
                        var held = item.GetHeldEntity();
                        if (held != null) {
                            held.skinID = cachedSkin.skinid;
                            held.SendNetworkUpdate();
                        }
                    }
                }
            }
            ChatMessage(iplayer, "CompletedAllSkin", skinned);
        }
        private void SBNextPageCMD(IPlayer iplayer, string command, string[] args) {
            BasePlayer player = iplayer.Object as BasePlayer;
            if (player == null) return;
            if (!_viewingcon.Contains(player)) return;
            StorageContainer storagecontainer = player.inventory.loot.entitySource as StorageContainer;
            if (storagecontainer == null) return;
            BoxController boxController;
            if (!storagecon
// ... [Code preview truncated due to length. Full source in attached file] ...

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху