• File: SkinMenu.cs
  • Full Path: /var/www/FileManager/Files/RUST PLUGINS/SkinMenu.cs
  • Date Modified: 04/29/2025 11:05 AM
  • File size: 81.37 KB
  • MIME-type: text/plain
  • Charset: utf-8
 
Open Back
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Libraries;
using Oxide.Core.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using UnityEngine;
using ConVar;
using Network;
using Random = UnityEngine.Random;
using System.Collections;

namespace Oxide.Plugins
{
    [Info("SkinMenu", "fermens", "0.1.1")]
    class SkinMenu : RustPlugin
    {
        #region Config
        private PluginConfig config;

        protected override void LoadDefaultConfig()
        {
            config = PluginConfig.DefaultConfig();
        }
        protected override void LoadConfig()
        {
            base.LoadConfig();
            config = Config.ReadObject<PluginConfig>();
        }
        protected override void SaveConfig()
        {
            Config.WriteObject(config);
        }

        enum elementbutton { weapon, construction, items, attire, tool };

        class BUTTON
        {
            [JsonProperty("Название")]
            public string name;

            [JsonProperty("Предметы")]
            public string[] items;
        }

        class settext
        {
            [JsonProperty("Текст")]
            public string text;

            [JsonProperty("Размер текста")]
            public string size;
        }

        class color
        {
            [JsonProperty("Цвет нажатой кнопки")]
            public string activecolor;

            [JsonProperty("Цвет кнопки")]
            public string buttoncolor;

            [JsonProperty("Цвет основного фона")]
            public string background;

            [JsonProperty("Цвет фона подменю")]
            public string backgroundmenu;

            [JsonProperty("Цвет фона скина")]
            public string backgroundskin;

            [JsonProperty("Цвет верхней панели")]
            public string backgroundup;

            [JsonProperty("Цвет нижней панели")]
            public string backgroundfoot;

            [JsonProperty("Цвет кнопок в ремонтном верстаке")]
            public string bench;
        }

        class text
        {
            [JsonProperty("Название вверху")]
            public settext title;

            [JsonProperty("Кнопка выхода")]
            public settext exit;

            [JsonProperty("Подсказка внизу")]
            public settext pint;

            [JsonProperty("Сообщение о успешной смене скина")]
            public settext done;

            [JsonProperty("Ремонтный верстак")]
            public bench bench;
        }

        class bench
        {
            [JsonProperty("Для выбора рандомного скина")]
            public settext random;

            [JsonProperty("Для выбора основного скина")]
            public settext main;

            [JsonProperty("Для открытия скин меню")]
            public settext menu;
        }

        class priv
        {
            [JsonProperty("Включить?")]
            public bool enable;

            [JsonProperty("Премишн")]
            public string permission;

            [JsonProperty("Сообщение")]
            public string message;
        }

        private class PluginConfig
        {
            [JsonProperty("1. STEAM APIKEY (https://steamcommunity.com/dev/apikey)")]
            public string APIKEY;

            [JsonProperty("2. Настройка текста")]
            public text text;

            [JsonProperty("3. Настройка цветов")]
            public color color;

            [JsonProperty("4. Категории")]
            public Dictionary<elementbutton, BUTTON> categorys;

            [JsonProperty("5. Список скинов")]
            public Dictionary<string, List<ulong>> skins;

            [JsonProperty("6. Доступ к скинам по привилегии")]
            public priv priv;

            [JsonProperty("7. Перекрашивать скин когда берут в руки?")]
            public bool paint;

            [JsonProperty("8. Возможность перекрашивать скин в ремонтном верстаке?")]
            public bool repairbench;

            public static PluginConfig DefaultConfig()
            {
                return new PluginConfig()
                {
                    APIKEY = "",
                    text = new text
                    {
                        bench = new bench
                        {
                            main = new settext { text = "ОСНОВНОЙ", size = "18" },
                            random = new settext { text = "РАНДОМ", size = "18" },
                            menu = new settext { text = "СКИН МЕНЮ", size = "18" }
                        },
                        done = new settext { text = "УСПЕШНО СМЕНИЛИ СКИН!", size = "30" },
                        exit = new settext { text = "ЗАКРЫТЬ", size = "26" },
                        pint = new settext { text = "Выбранный скин накладывается при крафте и в ремонтном верстаке при выборе основного скина, а так же перекрашивает предметы в инвентаре при выборе.", size = "12" },
                        title = new settext { text = "СКИН МЕНЮ", size = "26" }
                    },
                    color = new color
                    {
                        activecolor = "0 0.8 1 0.2588235",
                        buttoncolor = "1 1 1 0.2588235",
                        background = "0 0 0 0.9961886",
                        backgroundup = "0.7490196 0.7490196 0.7490196 0.1647059",
                        backgroundfoot = "0.7490196 0.7490196 0.7490196 0.1647059",
                        bench = "1 1 1 0.1176471",
                        backgroundmenu = "1 1 1 0.09772462",
                        backgroundskin = "1 1 1 0.254902"
                    },
                    categorys = new Dictionary<elementbutton, BUTTON>
                    {
                        { elementbutton.weapon, new BUTTON {  name = "Оружие", items = new string[] { "rifle.ak", "rifle.bolt", "lmg.m249", "rifle.m39", "bow.hunting", "knife.bone", "bone.club", "crossbow", "shotgun.double", "pistol.eoka", "grenade.f1", "longsword", "smg.mp5", "shotgun.pump", "pistol.semiauto", "salvaged.sword", "smg.thompson", "pistol.revolver", "rocket.launcher", "rifle.semiauto", "shotgun.waterpipe", "smg.2", "pistol.python", "rifle.lr300", "knife.combat" } } },
                        { elementbutton.construction, new BUTTON {  name = "Cтроительство", items = new string[] { "wall.frame.garagedoor", "door.double.hinged.toptier", "door.double.hinged.metal", "door.double.hinged.wood", "door.hinged.toptier", "door.hinged.metal", "door.hinged.wood", "barricade.concrete", "barricade.sandbags"} } },
                        { elementbutton.items, new BUTTON {  name ="Предметы", items = new string[] { "rug", "rug.bear", "table", "chair", "fridge", "vending.machine", "box.wooden.large", "target.reactive", "sleepingbag", "water.purifier", "box.wooden", "fun.guitar", "locker", "furnace" } } },
                        { elementbutton.attire, new BUTTON {  name ="Одежда", items = new string[] { "mask.bandana", "mask.balaclava", "hat.beenie", "burlap.shoes", "burlap.shirt", "burlap.trousers", "burlap.headwrap", "bucket.helmet", "hat.beenie", "hat.cap", "shirt.collared", "coffeecan.helmet", "deer.skull.mask", "attire.hide.skirt", "attire.hide.vest", "attire.hide.pants", "attire.hide.boots", "attire.hide.helterneck", "hoodie", "attire.hide.poncho", "burlap.gloves", "tshirt.long", "metal.plate.torso", "metal.facemask", "hat.miner", "pants", "roadsign.jacket", "roadsign.kilt", "riot.helmet", "jacket.snow", "pants.shorts", "shirt.tanktop", "tshirt", "jacket", "shoes.boots" } } },
                        { elementbutton.tool, new BUTTON {  name ="Инструменты",  items = new string[] { "rock", "hammer.salvaged", "icepick.salvaged", "explosive.satchel", "stonehatchet", "stone.pickaxe", "hammer", "hatchet", "pickaxe" } } }
                    },
                    skins = new Dictionary<string, List<ulong>>
                    {
                        { "rifle.ak", new List<ulong> { 0, 849047662, 887494035, 1359893925, 1202410378, 1372945520, 859845460, 1259716979, 1826520371, 1750654242, 809212871, 809190373, 1435827815, 1112904406, 1385673487, 1679665505, 924020531, 1349512142, 937864743, 1196676446, 875130056, 1915393587, 1174389582, 1583542371, 1102750231, 840477492, 1306351416, 885146172, 1137915903, 1245563496, 1349324364, 1929819581, 1092674304, 920472848, 1804885723, 928950425, 1448221547, 939180121, 940035827, 903882218, 1476966011, 1588206436, 1167207039, 889710179, 1362212220, 1265322092, 1364985829, 1599157678, 1575397458, 1886272847, 925720043, 1272989639, 1434027951, 908297014, 1213092632, 1428980348, 1983066869, 1457951707, 10137, 1338305091, 1118706219, 1539318940, 1760078043, 1161844853, 1522034435, 1120500163, 1685375084, 1549426268, 1907342157, 1870705926, 911726740, 1252554814, 895307805, 1352844155, 1746886322, 1288866247, 654502185, 934891737, 1175238674, 1539409946, 1372566409, 1277707212, 1396630285, 1076214414, 1882821847, 1850236015, 1230963555, 1539007965, 1088459232, 1129886223, 1124932043, 1467269924, 1659781652, 1402320927, 1324932956, 1140366289, 1159593268, 1309470544 } },
                        { "rifle.bolt", new List<ulong> { 0, 1852284996, 818403150, 1795984246, 1535660827, 1517933342, 1581664321, 897023403, 933509449, 1587273896, 875259050, 943036098, 840105253, 819149392, 972020573, 1592946955, 947954942, 1119629516, 1161165984 } },
                        { "knife.bone", new List<ulong> { 0, 808955868, 1277364396, 909612594, 945031477, 933322251 } },
                        { "bow.hunting", new List<ulong> { 0, 1729629485, 1729920243, 1729683309, 1734427277, 1747542198, 1759967280, 1773297889, 1788414884, 1793915047, 1846220912, 1876857585, 1883523860, 1885852817, 1926862937, 1974088369, 1984690140, 1988012822 } },
                        { "bone.club", new List<ulong> { 0, 1557788243, 810156739, 791109245, 888839261, 945026868 } },
                        { "lmg.m249", new List<ulong> { 0, 1707973294, 1719536313, 1712378771, 1831294069, 1992981006 } },
                        { "rifle.m39", new List<ulong> { 0, 1707880195, 1708343082, 1720530850, 1708365495, 1736532811 } },
                        { "crossbow", new List<ulong> { 0, 915855989, 1565444858, 874268567, 1961541693, 1772979668, 1242702498, 1390284445, 883141682, 818070371, 1349337546, 1181976746, 1291686117, 809964230, 1466387739, 1699027694, 1428614422, 1365706569, 1127389810, 1115959202, 1865294019, 1421675342, 1184318659, 1739935284, 1097642159, 1269230939, 1089558546, 1206661880, 1328219905, 1701173429, 856029421, 1766369967, 1559298697, 1367933148, 1408631840, 1810999666, 1383105648 } },
                        { "shotgun.double", new List<ulong> { 0, 916790605, 865019380, 1448142776, 1660175523, 1119662164, 1680595474, 1213074188, 1378519774, 948113632, 854987948, 1260964187, 1522902588, 860153737, 1414878365, 1295701369, 1408050439, 1174675399, 858957151, 1910558629, 1465627520, 1341524782, 1127266590, 1441939951, 1870693079, 1282137884, 1590495543, 1229950256, 1277558450, 1225880743, 1247696065, 1616108563, 1569952704 } },
                        { "pistol.eoka", new List<ulong> { 0, 1171935313, 856053892, 857750032, 898387222, 926184643, 1174673119, 1413731110 } },
                        { "grenade.f1", new List<ulong> { 0, 836745325, 936182773, 1163186435, 815252048 } },
                        { "furnace", new List<ulong> { 0, 1231071505, 1230386524, 1230680321, 1230539924, 1230975843, 1239083962, 1241065527, 1230272984, 1247357204, 1261530424, 1260546874, 1277183788, 1282172459, 1260305347, 1277616284, 1305743950, 1305332196, 1320779999, 1335260783, 1335598661, 1349367380, 1354714819, 1356581838, 1354629493, 1373663659, 1367939983, 1377346304, 1384844042, 1408433814, 1391109786, 1427551950, 1421455358, 1467078851, 1448350353, 1458047080, 1457061230, 1529559770, 1387619038, 1539436979, 1539005624, 1575177513, 1588458946, 1587226587, 1587959070, 1632040649, 1636919294, 1640730462, 1652555216, 1630511618, 1645019295, 1559242743, 1583218948, 1701971555, 1723387671, 1772650961, 1775718906, 1805182793, 1810979800, 1865321291, 1892656766, 1936112920, 1935093227, 1949401987, 1975322284, 1992130386 } },
                        { "longsword", new List<ulong> { 0, 1222939471, 825169057, 796733487, 831965423, 855009078, 825008040 } },
                        { "smg.mp5", new List<ulong> { 0, 1137434899, 1693898215, 904404578, 796679172, 833639834, 1637174724, 796687275, 1865099372, 911612956, 1673754411, 808554348, 892100306, 853438134, 800974015, 914624163, 1654499223, 1413917236, 1084800708, 1087199678 } },
                        { "shotgun.pump", new List<ulong> { 0, 1115399868, 1553603344, 964345579, 1153922437, 1269617539, 1666328139, 1094741003, 813631833, 813628651, 1760154042, 921253888, 1191938171, 1476013941, 1132569603, 1292063367, 1672954158, 1652348929, 850130444, 849997025, 1706897835, 731119713 } },
                        { "pistol.semiauto", new List<ulong> { 0, 902487409, 1720501333, 919535259, 883156158, 924018875, 937863988, 876007573, 1428766159, 1183693235, 1158943049, 863443112, 953126981, 910681058, 1811814491, 1105853708, 1167255900, 904356033, 893118140, 1121906926, 805925675, 1630961792, 954520976, 1113544521, 830255284, 899942580, 853927198, 1571099329, 950037016, 972059802, 830606037, 804337360, 1328323548, 798375117, 868298519, 1446715780, 908722214, 827533196, 975102848, 938007886, 1118707296, 936623315, 829983759, 1553005167, 1092676141, 935205778 } },
                        { "salvaged.sword", new List<ulong> { 0, 1568609421, 1587541456, 1915832963, 950134503, 1652800384, 1455468520, 1852787012, 828885909, 1442148142, 1442017029, 893871715, 969725237, 1366123054, 1239660381, 1154175800, 1283812544, 1535765451, 1212723513, 930557072, 1313755167, 825240467, 1624719255 } },
                        { "smg.thompson", new List<ulong> { 0, 561462394, 839819171, 1345464512, 1720001936, 1772377862 } },
                        { "pistol.revolver", new List<ulong> { 0, 910665268, 1901240954, 1192708586, 1235107237, 1265936882, 1141054826, 815532676, 1517889157, 937338314, 970737094, 1536482422, 873242795, 809865395, 809822151, 933056389, 1448503557, 1349358875, 1580859157, 809897611, 1346870567, 911828654, 1235996786, 1428863076, 950956238, 1787802800, 1435664860, 1161550991, 1309517474, 1408242038, 1447877728, 1099177489, 973871108, 1217455695, 887846629 } },
                        { "rocket.launcher", new List<ulong> { 0, 812737524, 813795591, 853494512, 875930670, 879708939, 926279011, 894679426, 1137393412, 1162978825, 1162085821, 1815384807, 1839729563, 1905848285, 1926503780, 1936188783 } },
                        { "rifle.semiauto", new List<ulong> { 0, 818613234, 828616457, 839302795, 840023839, 875259741, 900921542, 899564368, 922119054, 942919370, 959955205, 1099992405, 1112906123, 1113987623, 1135415770, 1129722099, 1168002579, 1170719113, 1182015913, 1193105339, 1098038362, 1195821858, 1240340535, 1279791283, 1291766032, 1298949573, 1300137383, 1300239738, 1217394290, 1310522106, 1313600286, 1359059068, 1385736095, 1395475969, 1429032578, 1448088345, 1446861251, 1517644801, 1522185915, 1566048269, 1576671137, 1616628843, 1621472496, 1652791742, 1772028068, 1788152335, 1814170373, 1819195444, 1818125194, 1863834018, 1876226129, 1936035303, 1933250593, 1966875478 } },
                        { "shotgun.waterpipe", new List<ulong> { 0, 633754963, 819137470, 661319648, 832764933, 907070012, 1147084675, 1168524895, 1181616781, 1205464046, 1219492103, 1234721165, 1209128595, 1274179291, 1250809355, 1320685736, 1421462560, 1693498234, 1851214164 } },
                        { "smg.2", new List<ulong> { 0, 1329096680, 820350952, 820402694, 866745136, 1081305198, 1128840196, 931547202, 1185311263, 1185311263, 816728172, 1839296742, 1805101270, 897099822, 892212957, 904964438, 1597038037, 1446184061, 1961720552, 1685722307, 1198145190, 1753609137, 1114032911, 1107572641, 854914986, 1523699528, 822943156, 970682025 } },
                        { "pistol.python", new List<ulong> { 0, 1214609010, 1215390635, 1217395562, 1216163401, 1228154190, 1223105431, 1235690536, 1258109891, 1265214612, 1290876678, 1296687971, 1305704747, 1277518447, 1328632407, 1335582211, 1342464644, 1364964220, 1377347733, 1356665596, 1373936691, 1418647979, 1435858834, 1435364672, 1455062983, 1445908611, 1457537882, 1461918011, 1421351634, 1529514494, 1362224646, 1563667918, 1406640269, 1605379554, 1624620555, 1672707813, 1752928667, 1796388607, 1812135451, 1839518047, 1864788236, 1914959779, 1917523660 } },
                        { "rifle.lr300", new List<ulong> { 0, 1621894466, 1741459108, 1535995784, 1239079767, 1569062511, 1173523145, 1553359638, 1553359638, 1174458060, 1604879931, 1225499752, 1725240606, 1883559335, 1419392688, 1700177871, 1612152593, 1578816958, 1660691287, 1173459827, 1644715625, 1177273104, 1264358358, 1953108368, 1671985039, 1652362426, 1308037543, 1779949198, 1635559091, 1787012455, 1176479716, 1481478360, 1967805281, 1282171260, 1203322875 } },
                        { "knife.combat", new List<ulong> { 0, 1702530691, 1706788762, 1707332381, 1715608877, 1719795241, 1706692846, 1730634130, 1739818618, 1910941833, 1952506333 } },
                        { "door.hinged.toptier", new List<ulong> { 0,  801831553, 801937986, 801889927, 804286931, 807729959, 809638761, 839925176, 869475498, 885928673, 911652483, 930478674, 933057923, 948938468, 1092678229, 1114020299, 1135412861, 1176460121, 1206145767, 1228341388, 1376526519, 1402412287, 1477263064, 1557857999, 1605324677, 1395469801, 1414795168, 1999927543 } },
                        { "door.hinged.metal", new List<ulong> { 0, 827190175, 832957536, 835119969, 849614068, 859864870, 836815358, 883741993, 897274189, 901194793, 915684869, 921076360, 917719889, 922419554, 934924536, 914869833, 928503162, 942658960, 948930384, 959898495, 961909886, 962391797, 1083653685, 1066783524, 1109694864, 1117884427, 1120339199, 1119310953, 1124738987, 1141051963, 1176406578, 1175547229, 1170684837, 950560231, 1211678957, 1213613030, 1227441654, 1239808532, 1260208160, 1281626747, 1290467327, 1294718018, 1309566989, 1306412169, 1313458951, 1321264697, 1328395850, 1328566466, 1342459239,  1356364616, 1356332123, 1362729705, 1354718926, 1362595551, 1390896848, 1380022034, 1383063240, 1401769919, 1412186246, 1415394917, 1412241247, 1435254318, 1438420454, 1443957299, 1447958101, 1466554259, 1457845730, 1448354224, 1447671986, 1523940330, 1524017223, 1514174191, 1539115581, 1205721755, 1565096963, 1576050073, 1587119000, 1587777999, 1595324955, 1617363766, 1653322594, 1680572723, 1687047599, 1707455661, 1727356485, 1733664175, 1747674239, 1759765099, 1772296521, 1780241717, 1795304359, 1812049396, 1839905607, 1845208821, 1852469574, 1852769999, 1870735722, 1886472768, 1926577314, 1933669766, 1952448742, 1974769574, 1984902763, 1992539569, 1999996993, 2009712630 } },
                        { "door.hinged.wood", new List<ulong> { 0, 809253752,804854812,804991715,847902281,838700836,923763807,950184212,1100873539,1100886818,1108316628,1127631900,1132144523,1131650209,1176899114,962427350,1260913194,1313604647,1320929144,1328425419,1362500013,1386052491,1402178300,1415059257,1428632857,1415496136,1269783329,1539681696,1605229872,1666630991,1733982448,1886617093,1759874635,1932460590,1932737376 } },
                        { "barricade.concrete", new List<ulong> { 0, 791070521, 828182621, 846663258, 924112225, 939333522 } },
                        { "barricade.sandbags", new List<ulong> { 0, 809144507 } },
                        { "tshirt", new List<ulong> { 0, 499455600, 495902079, 492471488, 489878758, 492781593, 490236659, 490948132, 492096219, 489329801, 490217825, 489687236, 504919781, 851890495, 1412895302 } },
                        { "shirt.tanktop", new List<ulong> { 0, 784578916 } },
                        { "rug.bear", new List<ulong> { 0, 870446546 } },
                        { "rug", new List<ulong> { 0, 871072156, 870851438, 907327964, 1114718055, 1225299046, 1461385713, 1637950966, 1740724608 } },
                        { "locker", new List<ulong> { 0, 879533969, 879343335, 881997061, 881411749, 1138218408, 1328242213, 1901223959, 1935027646 } },
                        { "table", new List<ulong> { 0, 872346354, 875258582, 909129983 } },
                        { "chair", new List<ulong> { 0, 871271807, 871339422, 875258235, 897656037, 1154498476, 1147170604, 1260443731 } },
                        { "fridge", new List<ulong> { 0, 864918396, 869398873, 873612402, 886416273, 1759824768, 1927006810, 1968311805 } },
                        { "vending.machine", new List<ulong> { 0, 861548229, 860916780, 862291005, 861029759, 862137836, 869474635, 871927557, 1161727529, 1335113551, 1373851317, 1780228760, 1927092059 } },
                        { "fun.guitar", new List<ulong> { 0, 809938266, 809801196, 826914904, 844914652 } },
                        { "box.wooden", new List<ulong> { 0, 787716105, 885103417, 889212734, 930694436, 1127078435, 1212709764, 1316294242, 1455068496, 1529745641, 1644263172, 1679876778, 1818868472, 1865304630, 2000024196 } },
                        { "water.purifier", new List<ulong> { 0, 786826476, 886677071, 1796826334 } },
                        { "sleepingbag", new List<ulong> { 0, 493375502, 494249390, 514146546, 535099192, 539536110, 548925163, 558861217, 795398514, 809186722, 834487561, 909889024, 919353105, 944993672, 1127084512, 1132190812, 1137518723, 1140342335, 1152883867, 1102195403, 1165339422, 1174407153, 1186393080, 1228238024, 1269426600, 1283724154, 1296042340, 1362261702, 1396600730, 1402402700, 1466734204, 1447956760, 1565127136, 1586749954, 1711044880, 1709890051, 1773435398, 1804347166, 1818779860, 1839630957, 1858936313, 1865305668, 1886931973, 1906188254, 1934818691, 1986734890, 1991418530, 2011695446 } },
                        { "target.reactive", new List<ulong> { 0, 791177585, 824001540 } },
                        { "box.wooden.large", new List<ulong> { 0, 798455489, 797422750, 810383121, 576569265, 813269955, 842083350, 854002617, 854718942, 878850459, 881249489, 851053322, 882223700, 890915277, 892062620, 904962497, 809975811, 928502682, 932160919, 942917320, 942678679, 969292267, 978112601, 1067191615, 1102266445, 1116497962, 1119263507, 1135412156, 1159589238, 1169231428, 1192724938, 1199632980, 1206100969, 1209454231, 1212838382, 1251062707, 1261541803, 1269932286, 1277330503, 1204070852, 1285113124, 1282838099, 1306240898, 1315566388, 1320924107, 1342462175, 1353721544, 1356773002, 1362394666, 1382429236, 1394363785, 1443958473, 1447962258, 1456233168, 1466559128, 1517816237, 1524018833, 1535990243, 1196352289, 1547157690, 1557427113, 1565532295, 1575872461, 1582501552, 1617361106, 1630549771, 1627583152, 1651859603, 1673157060, 1680678559, 1686299197, 1727351952, 1740339091, 1753777701, 1766238308, 1795321839, 1825978701, 1840296976, 1853539864, 1877231477, 1882223552, 1886917011, 1900496901, 1911972056, 1915836108, 1926650593, 1936186181, 1973015940, 2012513964 } },
                        { "wall.frame.garagedoor", new List<ulong> { 0, 1180981036, 1180968592, 1183127702, 1186351868, 1209586977, 1238292260, 1309406283, 1306203844, 1334974046, 1358030533, 1380090862, 1398568170, 1428456080, 1415079530, 1415167317, 1461027316, 1465843732, 1523814360, 1529742943, 1539143998, 1575268855, 1617613419, 1645407409, 1649777840, 1529558717, 1680120997, 1733848365, 1747024635, 1759641728, 1772483395, 1788350229, 1804915784, 1805270622, 1819106723, 1826250647, 1839473397, 1846000839, 1856195647, 1871289078, 1886876765, 1926583818, 1935858699, 1968391406, 1973756459, 2006000003, 2010495833 } },
                        { "door.double.hinged.wood", new List<ulong> { 0, 1876817741, 1882487559 } },
                        { "door.double.hinged.toptier", new List<ulong> { 0, 1874611109, 1911994581, 1925748582 } },
                        { "door.double.hinged.metal", new List<ulong> { 0, 1874961152, 1876575703, 1883500337, 1885983859, 1882782756, 1895120296, 1900646657, 1904509199, 1914299009, 1918077744, 1911036760, 1926125252, 1926973479, 1936126874 } },
                        { "shoes.boots", new List<ulong> { 0, 493534620, 493064563, 507940691, 513629119, 613481881, 784559403, 809586899, 838205144, 869090082, 882570089, 899942107, 919261524, 826587881, 944997041, 961096730, 920390242, 1084392788, 962503020, 1100926907, 1106548545, 1111680681, 1406796292, 1432967312, 1441308562, 1395755190, 1839313604, 1864539854, 1915955573, 1915397286, 1196740980, 1960694026, 1995685684, 2009426933 } },
                        { "jacket", new List<ulong> { 0, 505424331, 834233801, 1317555901 } },
                        { "pants.shorts", new List<ulong> { 0, 799006291, 794678401, 793871235, 818068257, 1412875829, 1416779855 } },
                        { "jacket.snow", new List<ulong> { 0, 530154777, 530159711, 839466039, 913227043 } },
                        { "riot.helmet", new List<ulong> { 0, 801095823, 849872204, 869709888, 869125904, 887283623, 911015530, 920983864, 930923611, 930563894, 937863435, 950182163, 1109466231, 1414953014, 1784490572, 1993881492 } },
                        { "roadsign.kilt", new List<ulong> { 0, 784577443, 794291485, 801837047, 818612271, 828173323, 865679836, 879861153, 892414125, 934742835, 944586866, 953123363, 934937654, 947949717, 950176525, 953112839, 1084396407, 1102986622, 1103687152, 1121447954, 1130405286, 1130610212, 1106569231, 1159599284, 1154469089, 1151205503, 1202976443, 974345761, 1251419748, 1248433379, 1269612137, 1342123902, 1332333384, 1349158079, 1353722661, 1349943069, 1380028657, 1400837602, 1388416860, 1441848470, 1442167045, 1442346890, 1438090382, 1539652650, 1539570583, 1558579257, 1737733590, 1759482713, 1797483140, 1779983158, 1740068457, 1723851847, 1865210905, 1894376712, 1906531526, 1915398061, 1944165903, 1974809731, 1986050287 } },
                        { "roadsign.jacket", new List<ulong> { 0, 784581113, 801873550, 818611894, 828175620, 865659101, 879861502, 892402754, 934744263, 932778217, 944577714, 953124938, 934926427, 947950933, 950173158, 953104456, 1084394793, 1102966153, 1098029034, 1121456497, 1130406273, 1130599258, 1119760089, 1159597292, 1154446174, 1151219812, 1202977830, 974336556, 1251431494, 1248434418, 1269597852, 1234957719, 1342125487, 1332334593, 1349163491, 1349940035, 1380025789, 1400828574, 1388417448, 1441844877, 1442162947, 1442341176, 1438089648, 1539651543, 1539573170, 1558586741, 1743991748, 1759481001, 1797481354, 1779981832, 1740065674, 1865210028, 1894379005, 1906530247, 1944167671, 1974808139, 1986047563 } },
                        { "pants", new List<ulong> { 0, 494003754, 490773561, 504687841, 798690647, 823154911, 889714798, 888360095, 909888619, 930559188, 939586076, 955615160, 961084105, 969289969, 975498827, 960252273, 1100930207, 1106596145, 1111673876, 1125254090, 1150816693, 1150763210, 1170988006, 1229552157, 1234956405, 1274163146, 1287193745, 1296612316, 1305364315, 1317553480, 1328753424, 1356749671, 1368418893, 1356324187, 1371313777, 1406835139, 1432965178, 1441311938, 1448346336, 1385326314, 1552705077, 1581822078, 1587846022, 1623181884, 1292094174, 1638743634, 1660293384, 1700938224, 1703218418, 1740505052, 1740563572, 1766646393, 1768737448, 1787243248, 1810590744, 1784474755, 1196747617, 1858308973, 1883629284, 1894589800, 1911973450, 1927127023, 1936132863, 1950854989, 1968533197, 1993902344, 1987863036, 1997534121 } },
                        { "hat.miner", new List<ulong> { 0, 788260164, 886318490, 886968007 } },
                        { "metal.facemask", new List<ulong> { 0, 784316334, 794837198, 792827436, 792079554, 792649975, 792905158, 799044333, 803894027, 800980236, 807821375, 816530945, 812933296, 828888629, 824898622, 821441043, 832021670, 832934294, 841012325, 835026584, 831923884, 881687672, 896211631, 895067146, 899001394, 901668040, 900645045, 907176719, 915572534, 924019464, 915693648, 943128194, 903628875, 971433920, 939788004, 932233099, 1092671728, 962694769, 1084823878, 1113983678, 1083628316, 1130407273, 1135160079, 1137533438, 1172409741, 1121237616, 1203888714, 1270065112, 1313529548, 1335769610, 1349988105, 1353724450, 1421829383, 1522955755, 1547874663, 1575391468, 1587225942, 1586135331, 1581351961, 1680454451, 1693643930, 1711049678, 1753711761, 1771714129, 1777973800, 1787201365, 1845950558, 1886184322, 1886920683, 1894591519, 1900843064, 1805321162, 1932619423, 1934943101, 1969741836, 1993775723, 2001712636, 2005707226 } },
                        { "metal.plate.torso", new List<ulong> { 0, 794169855, 799657859, 796728308, 797410767, 817022417, 823132085, 828888000, 832233112, 842577956, 798736321, 819160334, 895066686, 900807753, 924019814, 934627208, 944835223, 970700662, 1113984430, 1094522474, 1135168998, 1270065959, 1335770974, 1349989767, 1353723648, 1421841596, 1522963149, 1575392727, 1587225313, 1586132318, 1581353262, 1578628782, 1680452167, 1693641239, 1711048020, 1753699785, 1771804406, 1777967326, 1787198707, 1845931269, 1886179838, 1886922099, 1900842357, 1805322456, 1932615190, 1934946028, 1969743263, 1993774875, 2001706617, 2005709642 } },
                        { "tshirt.long", new List<ulong> { 0, 500940007, 492923278, 494178127, 493015260, 493860728, 492980527, 512107102, 534635471, 564242686, 566893368, 801204141, 808300545, 1416787006 } },
                        { "burlap.gloves", new List<ulong> { 0, 565678598, 610098458, 661317919, 816473273, 874488180, 883476299, 904961862, 961103399, 938394833, 921030333, 949616124, 1084390180, 962495909, 1100928373, 1111677889, 1106600389, 1296614997, 1368419860, 1394040487, 1406800025, 1432966221, 1448347837, 1395757825, 1552705918, 1623175153, 1839312425, 1864540635, 1865178625, 1915956499, 1727356926, 1196737780, 1960696487, 1993913813, 2009427605 } },
                        { "attire.hide.poncho", new List<ulong> { 0, 788732722, 825459163, 837191793, 833524594, 1269162578 } },
                        { "hoodie", new List<ulong> { 0, 1357519971, 492800372, 519147220, 539943199, 612956053, 619935833, 626133126, 661319427, 797128321, 803249256, 677636990, 889718910, 835836079, 895065994, 897890977, 914621940, 919353761, 926162531, 939604165, 904963081, 941172099, 954392337, 954947279, 961066582, 971807764, 959900137, 975500312, 959641236, 1100931254, 1106582025, 1111669350, 1150818496, 1150760640, 1170989053, 1209453497, 1234693807, 1274163900, 1282111884, 1296608954, 1305321596, 1317554978, 1328751626, 1356748246, 1368417352, 1356328924, 1373714814, 1371314541, 1408832378, 1432964453, 1448343881, 1385322661, 1552703337, 1564974974, 1581817010, 1587744366, 1623185000, 1292091712, 1638742127, 1660290744, 1700935391, 1703216433, 1740503746, 1740562395, 1766644324, 1768733505, 1787216403, 1810592176, 1784482745, 1196751864, 1858310941, 1883624383, 1894585931, 1911980598, 1927124747, 1936131747, 1950853975, 1968538819, 1993891915, 2000507925, 1997532879 } },
                        { "attire.hide.helterneck", new List<ulong> { 0, 798669794, 845019310 } },
                        { "attire.hide.boots", new List<ulong> { 0, 785347695, 837175591, 1230633097 } },
                        { "attire.hide.pants", new List<ulong> { 0, 837179220, 1269154354 } },
                        { "attire.hide.vest", new List<ulong> { 0, 878319804, 1269172413 } },
                        { "attire.hide.skirt", new List<ulong> { 0, 793180528, 831920129 } },
                        { "deer.skull.mask", new List<ulong> { 0, 784259585, 837166252, 882204381, 1935631950 } },
                        { "coffeecan.helmet", new List<ulong> { 0, 784910461, 806212029, 814098474, 843676357, 848645884, 854460770, 809816871, 914060966, 919595880, 891592450, 938020581, 948491992, 970583835, 955675586, 1104118217, 1121458604, 1129809202, 1130589746, 1174375607, 1154453278, 1151227603, 1202978872, 974321420, 1251411840, 1248435433, 1269589560, 1342122459, 1332335200, 1349166206, 1349946203, 1380023142, 1400824309, 1388417865, 1441850738, 1442169133, 1445131741, 1438088592, 1539650632, 1539575334, 1743856800, 1759479029, 1797478191, 1804649832, 1740061403, 1865208631, 1894381558, 1906527802, 1944168755, 1974807032, 1986043465 } },
                        { "shirt.collared", new List<ulong> { 0, 797241160, 802078252, 802073199, 801955689, 809704306, 819818852, 885078753 } },
                        { "hat.cap", new List<ulong> { 0, 495026469, 494030776, 890772638, 893188334, 1137628492, 1565217605, 1760269295 } },
                        { "hat.beenie", new List<ulong> { 0, 501159601, 519469651, 594202145 } },
                        { "bucket.helmet", new List<ulong> { 0, 564826303, 570784227, 784438982, 867605376, 831798567, 885450077, 889767601, 926313433, 964461549, 949889936, 1073904216, 1197730661 } },
                        { "burlap.headwrap", new List<ulong> { 0, 785890135, 861551572, 868014709, 896506958, 942098139, 822358002, 1691834772, 1694253807 } },
                        { "burlap.trousers", new List<ulong> { 0, 809968188, 921250017, 1127409880, 1145780081, 1323664071, 1354675665, 1380047706, 1394040054, 1438049211, 1755140135 } },
                        { "burlap.shirt", new List<ulong> { 0, 585386820, 654502725, 809909900, 849866944, 882451685, 926478499, 899941622, 1127407306, 1145786859, 1229561297, 1294812700, 1294811936, 1323654151, 1354670586, 1380044819, 1394039696, 1438049725, 1755124648 } },
                        { "burlap.shoes", new List<ulong> { 0, 790679533, 906443871 } },
                        { "mask.balaclava", new List<ulong> { 0, 502924129, 503161493, 506771831, 519942815, 507590678, 539536877, 539562549, 535666265, 613057784, 807719156, 813561728, 843976918, 851779943, 858156568, 856403207, 884484239, 1175131736, 1174877663 } },
                        { "mask.bandana", new List<ulong> { 0, 521069222, 903595865, 1185794212, 1323640876, 1438048628, 820870847, 1685873480, 1710737837 } },
                        { "pickaxe", new List<ulong> { 0, 832799172, 863455081, 859743520, 828884658, 904296143, 1083591199, 949859819, 1121521173, 1150813747, 1143157014, 1283807232, 1298797381, 1320093416, 1325483813, 1362736707, 1377987815, 1407877776, 1435220253, 1444912645, 1466675896, 1414450451, 1428399027, 1553326380, 1572401500, 1616992357, 1780027581, 1557509001, 1845184191, 1872098938, 1901442609, 1911366896, 1962080594, 1987871430 } },
                        { "hatchet", new List<ulong> { 0, 814630559, 816715928, 826402867, 824552943, 814713259, 825033005, 892263562, 910196839, 915910717, 924242197, 928879549, 912857899, 944497252, 953186726, 962959509, 950020589, 1082302323, 1092131816, 1076337199, 1095577423, 1108554409, 967413298, 1121515438, 1137482995, 1143274085, 1150815053, 1152712210, 1145547996, 1107210636, 1171956705, 1193102490, 1220880032, 1242774466, 1252014044, 1258108678, 1247701169, 1291775183, 1320099240, 1325481133, 1359120832, 1362737705, 1379766114, 1407875352, 1378023158, 1435214632, 1448232793, 1466664834, 1414446668, 1422179740, 1553321287, 1572398539, 1620492374, 1546404025, 1617000027, 1772892883, 1838326907, 1870596204, 1900587737, 1911293067, 1962083351, 1987865546 } },
                        { "hammer", new List<ulong> { 0, 822539548, 833423263, 938806184, 961294045, 1095969830, 1116103194, 1125995819, 1128710439, 1120977731, 1208606722, 1249500235, 1457914371, 1539336419, 1586965130, 1652017472, 1720644451, 1858261101, 1876980303, 1884786335, 1916000340 } },
                        { "stone.pickaxe", new List<ulong> { 0, 840380436, 837149011, 886904592, 1100085862, 1127557296, 1196675392, 1269582427, 1290539482, 1306179593, 1342118597, 1395460858, 1428446680, 1428014003, 1594886582, 1788447750, 1852292345, 1906588860, 1988077270 } },
                        { "stonehatchet", new List<ulong> { 0, 797445687, 854688691, 878257758, 887663210, 912599650, 955692135, 947950887, 1058431260, 1092741003, 1114895505, 1117098080, 1151551275, 1184754750, 1196674526, 1235107175, 1269563695, 1290344811, 1306176753, 1340282993, 1356232241, 1342121150, 1395467841, 1428438688, 1438048408, 1428010053, 1559244155, 1594996565, 1788439811, 1852290423, 1906590340, 1988082179 } },
                        { "explosive.satchel", new List<ulong> { 0, 855084816, 855256664, 860156815, 856333895, 908893157, 855113878, 1586074827, 1710383765, 1906259594, 1934132095, 1961769080 } },
                        { "icepick.salvaged", new List<ulong> { 0, 820810719, 844666224, 843454856, 911446362, 1121804393, 1124734833, 933760454, 1276627079 } },
                        { "hammer.salvaged", new List<ulong> { 0, 1176274440, 873519952, 862959564, 797728217 } },
                        { "rock", new List<ulong> { 0, 804791902, 807372963, 824904841, 834287924, 864277659, 843429299, 858285362, 933809748, 971411353, 1084822722, 1126754320, 1209361016, 1205671322, 1378500484, 1368454662, 1435229543, 1458528823, 1467090959, 1530140666, 1539197932, 1595910049, 1617334269, 1636101879, 1693063715, 1739062735, 1838926976, 1953527967 } },
                    },
                    priv = new priv
                    {
                        enable = false,
                        message = "<color=yellow>У вас нет доступа к этой команде!</color>",
                        permission = "skinmenu.use"
                    }, paint = true,
                    repairbench = false
                };
            }
        }
        #endregion

        #region ЗАГРУЗКА КАРТИНОК
        [PluginReference] Plugin ImageLibrary;
        public string GetImage(string shortname, ulong skin = 0)
        {
            
            if(skin == 0)
            {
                string url = $"https://www.rustedit.io/images/imagelibrary/{shortname}.png";
                return GetImagea(url, shortname);
            }
            return (string)ImageLibrary.Call("GetImage", shortname, skin);
        }

        private string GetImagea(string url, string fileName, ulong skin = 0)
        {
            if (ImageLibrary == null)
            {
                Puts("ImageLibrary no Loaded");
                return string.Empty;
            }
            var imageId = (string)ImageLibrary.CallHook("GetImage", fileName, skin);
            //Puts($"ImageLibrary Load {imageId}");
            if (imageId != "1226046096")
            {
                //Puts($"GetImage {url} {fileName}");
                return imageId;
            }
            ImageLibrary.Call("AddImage", url, fileName, skin);
            //Puts($"AddImage {url} {fileName}");
            return imageId;
        }
        public bool AddImage(string url, string shortname, ulong skin = 0) => (bool)ImageLibrary?.Call("AddImage", url, shortname, skin);
        public bool HasImage(string imageName, ulong imageId) => (bool)ImageLibrary?.Call("HasImage", imageName, imageId);

        const int MAXLOAD = 20;
        Dictionary<ulong, int> COUNTAMAXSAD = new Dictionary<ulong, int>();
        public void ADDIMAGE(string shortname, ulong skinID = 0)
        {
            if (skinID == 0) GetImage(shortname);
            else if (!HasImage(shortname, skinID))
            {
                webrequest.Enqueue("https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/", $"key={config.APIKEY}&itemcount=1&publishedfileids%5B0%5D={skinID}", (code, response) =>
                {
                    if (code != 200 || response == null)
                    {
                        if (COUNTAMAXSAD.ContainsKey(skinID)) COUNTAMAXSAD[skinID]++;
                        else COUNTAMAXSAD[skinID] = 0;
                        if (COUNTAMAXSAD[skinID] >= MAXLOAD) return;
                        timer.Once(10f, () => ADDIMAGE(shortname, skinID));
                        return;
                    }

                    SteampoweredResult sr = JsonConvert.DeserializeObject<SteampoweredResult>(response);
                    if (sr == null || !(sr is SteampoweredResult) || sr.response.result == 0 || sr.response.resultcount == 0)
                    {
                        PrintError($"Image failed to download! Error: Parse JSON response - Image Name: {shortname} - Image skinID: {skinID} - Response: {response}");
                        return;
                    }
                    SteampoweredResult.Response.PublishedFiled publishedfiled = sr.response.publishedfiledetails.FirstOrDefault();
                    AddImage(publishedfiled.preview_url, shortname, skinID);
                    if (COUNTAMAXSAD.ContainsKey(skinID)) COUNTAMAXSAD.Remove(skinID);

                }, this, RequestMethod.POST);
            }
        }
        #endregion

        #region КЕШ
        const float BUTTONADD = 0.198f;
        const float conststartx = 0.015f;
        const float conststarty = 0.955f;
        static string GUISkin = "";
        static string MAINGUI = "";
        const string ELEMENTBUTTONGUI = ",{\"name\":\"ELEMENTBUTTON.{num}\",\"parent\":\"SkinMenu\",\"components\":[{\"type\":\"UnityEngine.UI.Button\",\"color\":\"{color}\",\"command\":\"{button}\"},{\"type\":\"RectTransform\",\"anchormin\":\"{min} 0.87\",\"anchormax\":\"{max} 0.93\",\"offsetmax\":\"0 0\"}]},{\"name\":\"ELEMENTBUTTONTEXT\",\"parent\":\"ELEMENTBUTTON.{num}\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{text}\",\"fontSize\":20,\"align\":\"MiddleCenter\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]}";
        const string ELEMENTGUI = ",{\"name\":\"ELEMENTPANEL\",\"parent\":\"SKINBACKHROUND\",\"components\":[{\"type\":\"UnityEngine.UI.Button\",\"command\":\"{button}\",\"color\":\"{backgroundskin}\"},{\"type\":\"RectTransform\",\"anchormin\":\"{minx} {miny}\",\"anchormax\":\"{maxx} {maxy}\",\"offsetmax\":\"0 0\"}]},{\"name\":\"ELEMENTBUTT\",\"parent\":\"ELEMENTPANEL\",\"components\":[{\"type\":\"UnityEngine.UI.Button\",\"command\":\"{button}\",\"color\":\"1 1 1 0\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]},{\"name\":\"ELEMENT\",\"parent\":\"ELEMENTPANEL\",\"components\":[{\"type\":\"UnityEngine.UI.RawImage\",\"png\":\"{png}\",\"fadeIn\":0.5},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]}";
        const string BACKGROUNDGUI = "{\"name\":\"SKINBACKHROUND\",\"parent\":\"SkinMenu\",\"components\":[{\"type\":\"UnityEngine.UI.Image\",\"color\":\"{backgroundmenu}\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.01 0.07\",\"anchormax\":\"0.99 0.85\",\"offsetmax\":\"0 0\"}]},{\"name\":\"SKINBACKHROUNDHEADER\",\"parent\":\"SKINBACKHROUND\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{backfooter}\",\"fontSize\":{backfootersize},\"align\":\"MiddleCenter\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 0.05\",\"offsetmax\":\"0 0\"}]}";
        const string BUTTONGUI = ",{\"name\":\"BUTTONBACKS\",\"parent\":\"SKINBACKHROUND\",\"components\":[{\"type\":\"UnityEngine.UI.Button\",\"command\":\"{button}\",\"color\":\"{color}\"},{\"type\":\"RectTransform\",\"anchormin\":\"{min} 0.01\",\"anchormax\":\"{max} 0.06\",\"offsetmax\":\"0 0\"}]},{\"name\":\"BUTTONBACKSTEXT\",\"parent\":\"BUTTONBACKS\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{T}\",\"align\":\"MiddleCenter\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]}";

        class playerinfo
        {
            public Dictionary<string, ulong> skins;
            public elementbutton page;
        }

        static Dictionary<ulong, playerinfo> skinplayers = new Dictionary<ulong, playerinfo>();
        #endregion

        private object CanWearItem(PlayerInventory inventory, Item item, int targetSlot)
        {
            BasePlayer player = inventory.gameObject.ToBaseEntity() as BasePlayer;
            if (player == null) return null;
            CHANGEME(player, item);
            return null;
        }

        private void OnActiveItemChanged(BasePlayer player, Item oldItem, Item newItem)
        {
            CHANGEME(player, newItem);
        }

        private void CHANGEME(BasePlayer player, Item newItem)
        {
            if (newItem == null) return;
            string shortname = newItem.info.shortname;
            if (!config.skins.ContainsKey(shortname) || !config.skins[shortname].Contains(newItem.skin)) return;
            ulong skin = APISKIN(player, shortname);
            if (skin == newItem.skin) return;
            newItem.skin = skin;
            newItem.MarkDirty();
            BaseEntity heldEntity = newItem.GetHeldEntity();
            if ((UnityEngine.Object)heldEntity != (UnityEngine.Object)null)
            {
                heldEntity.skinID = skin;
                heldEntity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
            }
        }

        private void OnServerInitialized()
        {
            SaveConfig();

            if (string.IsNullOrEmpty(config.APIKEY))
            {
                Debug.LogError("УКАЖИТЕ APIKEY В КОНФИГЕ! [p.s. при создании можете указать любой домен]");
                return;
            }

            if (config.priv == null)
            {
                config.priv = new priv
                {
                    enable = false,
                    message = "<color=yellow>У вас нет доступа к этой команде!</color>",
                    permission = "skinmenu.use"
                };
            }

            if (!config.paint)
            {
                Unsubscribe(nameof(CanWearItem));
                Unsubscribe(nameof(OnActiveItemChanged));
            }

            if (!config.repairbench)
            {
                Unsubscribe(nameof(OnLootEntity));
                Unsubscribe(nameof(OnItemRemovedFromContainer));
                Unsubscribe(nameof(CanAcceptItem));
                Unsubscribe(nameof(OnPlayerLootEnd));
            }

            permission.RegisterPermission(config.priv.permission, this);

            AddImage("http://i.imgur.com/sZepiWv.png", "NONE");
            AddImage("http://i.imgur.com/lydxb0u.png", "LOADING");

            foreach (var z in config.categorys)
            {
                if (z.Value.items == null || z.Value.items.Length == 0) continue;
                foreach (var x in z.Value.items) ADDIMAGE(x);
            }

            foreach (var z in config.skins)
            {
                if (z.Value == null || z.Value.Count == 0) continue;
                foreach (var x in z.Value) ADDIMAGE(z.Key, x);
            }

            foreach (BasePlayer player in BasePlayer.activePlayerList)
            {
                InitPlayerSkin(player);
                INITPLAYER(player.userID);
            }

            MAINGUI = "[{\"name\":\"SkinMenu\",\"parent\":\"Overlay\",\"components\":[{\"type\":\"UnityEngine.UI.Image\",\"color\":\"{background}\",\"fadeIn\":0.5},{\"type\":\"NeedsCursor\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]},{\"name\":\"SKINHEADER\",\"parent\":\"SkinMenu\",\"components\":[{\"type\":\"UnityEngine.UI.Image\",\"color\":\"{backgroundup}\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0.95\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]},{\"name\":\"SKINHEADERTEXT\",\"parent\":\"SKINHEADER\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{header}\",\"fontSize\":{headersize},\"align\":\"MiddleCenter\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]},{\"name\":\"SKINCLOSE\",\"parent\":\"SkinMenu\",\"components\":[{\"type\":\"UnityEngine.UI.Button\",\"command\":\"skin.controll exit\",\"close\":\"SkinMenu\",\"color\":\"{backgroundfoot}\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 0.05\",\"offsetmax\":\"0 0\"}]},{\"name\":\"CLOSETEXT\",\"parent\":\"SKINCLOSE\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{closetext}\",\"fontSize\":{closetextsize},\"align\":\"MiddleCenter\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]}{main}]".Replace("{backgroundup}", config.color.backgroundup).Replace("{backgroundfoot}", config.color.backgroundfoot).Replace("{closetext}", config.text.exit.text).Replace("{closetextsize}", config.text.exit.size).Replace("{background}", config.color.background).Replace("{header}", config.text.title.text).Replace("{headersize}", config.text.title.size);
            GUISkin = "[{\"name\":\"SKINPANELMAIN\",\"parent\":\"Hud.Menu\",\"components\":[{\"type\":\"UnityEngine.UI.Image\",\"color\":\"1 1 1 0\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.5 0\",\"anchormax\":\"0.5 0\",\"offsetmax\":\"0 0\"}]},{\"name\":\"SKINPANEL\",\"parent\":\"SKINPANELMAIN\",\"components\":[{\"type\":\"UnityEngine.UI.Button\",\"command\":\"skin.controll main\",\"color\":\"{bench}\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.5 0\",\"anchormax\":\"0.5 0\",\"offsetmin\":\"303 72\",\"offsetmax\":\"410 98\"}]},{\"name\":\"SKINTEXT\",\"parent\":\"SKINPANEL\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{main}\",\"fontSize\":{mainsize},\"align\":\"MiddleCenter\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]},{\"name\":\"SKINPANEL\",\"parent\":\"SKINPANELMAIN\",\"components\":[{\"type\":\"UnityEngine.UI.Button\",\"command\":\"chat.say /skin\",\"color\":\"{bench}\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.5 0\",\"anchormax\":\"0.5 0\",\"offsetmin\":\"192 43\",\"offsetmax\":\"410 69\"}]},{\"name\":\"SKINTEXT\",\"parent\":\"SKINPANEL\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{menu}\",\"fontSize\":{menusize},\"align\":\"MiddleCenter\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]},{\"name\":\"SKINPANEL\",\"parent\":\"SKINPANELMAIN\",\"components\":[{\"type\":\"UnityEngine.UI.Button\",\"command\":\"skin.controll rand\",\"color\":\"{bench}\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.5 0\",\"anchormax\":\"0.5 0\",\"offsetmin\":\"192 72\",\"offsetmax\":\"301 98\"}]},{\"name\":\"SKINTEXT\",\"parent\":\"SKINPANEL\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{rand}\",\"fontSize\":{randsize},\"align\":\"MiddleCenter\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]}]".Replace("{menusize}", config.text.bench.menu.size).Replace("{menu}", config.text.bench.menu.text).Replace("{mainsize}", config.text.bench.main.size).Replace("{main}", config.text.bench.main.text).Replace("{randsize}", config.text.bench.random.size).Replace("{rand}", config.text.bench.random.text).Replace("{bench}", config.color.bench);
        }

        const string UIALERT = "[{\"name\":\"ALERT\",\"parent\":\"Overlay\",\"components\":[{\"type\":\"UnityEngine.UI.Image\",\"color\":\"0 0 0 0.7485173\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0.6\",\"anchormax\":\"1 0.7\",\"offsetmax\":\"0 0\"}]},{\"name\":\"TEXTALERT\",\"parent\":\"ALERT\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{text}\",\"fontSize\":{size},\"align\":\"MiddleCenter\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmax\":\"0 0\"}]},{\"name\":\"CuiElement\",\"parent\":\"Overlay\",\"components\":[{\"type\":\"RectTransform\",\"anchormin\":\"0.05208334 0.09259259\",\"anchormax\":\"0.1041667 0.1851852\",\"offsetmax\":\"0 0\"}]},{\"name\":\"CuiElement\",\"parent\":\"Overlay\",\"components\":[{\"type\":\"RectTransform\",\"anchormin\":\"0.05208334 0.09259259\",\"anchormax\":\"0.1041667 0.1851852\",\"offsetmax\":\"0 0\"}]}]";
        private void ALERTPLAYER(BasePlayer player, string text, string size)
        {
            CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "ALERT");
            CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", UIALERT.Replace("{size}", size).Replace("{text}", text));
            timer.Once(2f, () => CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "ALERT"));
        }

        private void INITPLAYER(ulong userid)
        {
            if (!skinplayers.ContainsKey(userid)) skinplayers.Add(userid, new playerinfo { skins = new Dictionary<string, ulong>(), page = elementbutton.weapon });
        }

        private void OnPlayerConnected(BasePlayer player)
        {
            InitPlayerSkin(player);
            INITPLAYER(player.userID);
        }

        #region SteampoweredAPI 
        private class SteampoweredResult
        {
            public Response response;
            public class Response
            {
                [JsonProperty("result")]
                public int result;

                [JsonProperty("resultcount")]
                public int resultcount;

                [JsonProperty("publishedfiledetails")]
                public List<PublishedFiled> publishedfiledetails;
                public class PublishedFiled
                {
                    [JsonProperty("publishedfileid")]
                    public ulong publishedfileid;

                    [JsonProperty("result")]
                    public int result;

                    [JsonProperty("creator")]
                    public string creator;

                    [JsonProperty("creator_app_id")]
                    public int creator_app_id;

                    [JsonProperty("consumer_app_id")]
                    public int consumer_app_id;

                    [JsonProperty("filename")]
                    public string filename;

                    [JsonProperty("file_size")]
                    public int file_size;

                    [JsonProperty("preview_url")]
                    public string preview_url;

                    [JsonProperty("hcontent_preview")]
                    public string hcontent_preview;

                    [JsonProperty("title")]
                    public string title;

                    [JsonProperty("description")]
                    public string description;

                    [JsonProperty("time_created")]
                    public int time_created;

                    [JsonProperty("time_updated")]
                    public int time_updated;

                    [JsonProperty("visibility")]
                    public int visibility;

                    [JsonProperty("banned")]
                    public int banned;

                    [JsonProperty("ban_reason")]
                    public string ban_reason;

                    [JsonProperty("subscriptions")]
                    public int subscriptions;

                    [JsonProperty("favorited")]
                    public int favorited;

                    [JsonProperty("lifetime_subscriptions")]
                    public int lifetime_subscriptions;

                    [JsonProperty("lifetime_favorited")]
                    public int lifetime_favorited;

                    [JsonProperty("views")]
                    public int views;

                    [JsonProperty("tags")]
                    public List<Tag> tags;
                    public class Tag
                    {
                        [JsonProperty("tag")]
                        public string tag;
                    }
                }
            }
        }
        #endregion


        const string GUICENTERBUT = ",{\"name\":\"PAGETEXT\",\"parent\":\"SKINBACKHROUND\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{text}\",\"fontSize\":16,\"align\":\"MiddleRight\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.4 0.01\",\"anchormax\":\"0.48 0.06\",\"offsetmax\":\"0 0\"}]}";
        static Dictionary<ulong, bool> opening = new Dictionary<ulong, bool>();
        const int MAXROW = 4;
        const int INROW = 10;

        bool HAVEACCES(string id)
        {
            if (!config.priv.enable) return true;
            if (permission.UserHasPermission(id, config.priv.permission)) return true;
            return false;
        }

        [ConsoleCommand("skin.add")]
        private void CONSOLECOMMANADD(ConsoleSystem.Arg arg)
        {
            if (!arg.IsAdmin) return;
            if (!arg.HasArgs() || arg.Args.Length < 2)
            {
                arg.ReplyWith("skin.add НАЗВАНИЕ_ПРЕДМЕТА ID_СКИНА [пример: skin.add rifle.ak 0]");
                return;
            }

            List<ulong> skins;
            string name = arg.Args[0];
            if(!config.skins.TryGetValue(name, out skins))
            {
                arg.ReplyWith($"Не нашли в конфиге предмет с названием {name}");
                return;
            }

            ulong skinid;
            if(!ulong.TryParse(arg.Args[1], out skinid))
            {
                arg.ReplyWith($"Это не ID скина {arg.Args[1]}!");
                return;
            }

            if (skins.Contains(skinid))
            {
                arg.ReplyWith($"Такой скин уже добавлен!");
                return;
            }

            skins.Add(skinid);
            ADDIMAGE(name, skinid);
            arg.ReplyWith($"Добавили скин {arg.Args[1]} для {name}. [сохранили конфиг]");
        }

        [ConsoleCommand("skin.remove")]
        private void CONSOLECOMMANREMOVE(ConsoleSystem.Arg arg)
        {
            if (!arg.IsAdmin) return;
            if (!arg.HasArgs() || arg.Args.Length < 2)
            {
                arg.ReplyWith("skin.remove НАЗВАНИЕ_ПРЕДМЕТА ID_СКИНА [пример: skin.remove rifle.ak 0]");
                return;
            }

            List<ulong> skins;
            string name = arg.Args[0];
            if (!config.skins.TryGetValue(name, out skins))
            {
                arg.ReplyWith($"Не нашли в конфиге предмет с названием {name}");
                return;
            }

            ulong skinid;
            if (!ulong.TryParse(arg.Args[1], out skinid))
            {
                arg.ReplyWith($"Это не ID скина {arg.Args[1]}!");
                return;
            }

            if (!skins.Contains(skinid))
            {
                arg.ReplyWith($"Нет такого скина в списке!");
                return;
            }

            skins.Remove(skinid);
            arg.ReplyWith($"Удалили скин {arg.Args[1]} у {name}. [сохранили конфиг]");
        }
         
        [ConsoleCommand("skin.list")]
        private void CONSOLECOMMANLIST(ConsoleSystem.Arg arg)
        {
            if (!arg.IsAdmin) return;
            if (!arg.HasArgs() || arg.Args.Length < 1)
            {
                arg.ReplyWith("skin.list НАЗВАНИЕ_ПРЕДМЕТА [пример: skin.list rifle.ak]");
                return;
            }

            List<ulong> skins;
            string name = arg.Args[0];
            if (!config.skins.TryGetValue(name, out skins))
            {
                arg.ReplyWith($"Не нашли в конфиге предмет с названием {name}");
                return;
            }

            if(skins.Count == 0)
            {
                arg.ReplyWith("Нет скинов.");
                return;
            }

            string skinlist = "";
            foreach(var z in skins)
            {
                if (z == 0) continue;
                string id = z.ToString();
                skinlist += $"{id} - https://steamcommunity.com/sharedfiles/filedetails/?id={id}\n";
            }

            arg.ReplyWith($"Список скинов для {name}\n{skinlist}");
        }

        [ConsoleCommand("skin.save")]
        private void CONSOLECOMMANSAVE(ConsoleSystem.Arg arg)
        {
            SaveConfig();
            Debug.Log("Конфиг успешно сохранен.");
        }

        private static IEnumerator PAINTING(Item[] items, string name, ulong skin)
        {
            foreach (Item item in items)
            {
                if (item.info.shortname == name)
                {
                    if (skin == item.skin) continue;
                    item.skin = skin;
                    item.MarkDirty();
                    BaseEntity heldEntity = item.GetHeldEntity();
                    if ((UnityEngine.Object)heldEntity != (UnityEngine.Object)null)
                    {
                        heldEntity.skinID = skin;
                        heldEntity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
                    }
                    yield return new WaitForEndOfFrame();
                }
            }
            yield break;
        }

        [ConsoleCommand("skin.controll")]
        private void CONSOLECOMMANDSKINMENU(ConsoleSystem.Arg arg)
        {
            if (!arg.HasArgs()) return;
            BasePlayer player = arg.Player();
            if (player == null) return;
            if (!HAVEACCES(player.UserIDString))
            {
                player.ChatMessage(config.priv.message);
                return;
            }
            if (config.repairbench)
            {
                if (arg.Args[0] == "rand")
                {
                    ChangeSkin(player, true);
                    return;
                }
                else if (arg.Args[0] == "main")
                {
                    ChangeSkin(player, false);
                    return;
                }
            }
            if (!opening.ContainsKey(player.userID)) return;
            INITPLAYER(player.userID);
            if (arg.Args.Length == 3)
            {
                if (arg.Args[0] == "show")
                {
                    string ITEMNAME = arg.Args[1];
                    if (!config.skins.ContainsKey(ITEMNAME)) return;
                    int PAGE;
                    if (!int.TryParse(arg.Args[2], out PAGE)) return;
                    opening[player.userID] = false;
                    if (!skinplayers[player.userID].skins.ContainsKey(ITEMNAME)) skinplayers[player.userID].skins.Add(ITEMNAME, 0UL);
                    CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "SKINBACKHROUND");
                    string ISTRING = "[" + BACKGROUNDGUI.Replace("{backgroundmenu}", config.color.backgroundmenu).Replace("{backfootersize}", "0").Replace("{backfooter}", "");
                    int i = 1;
                    float startx = conststartx;
                    float starty = conststarty;
                    foreach (var x in config.skins[ITEMNAME].Skip(PAGE * MAXROW * INROW).Take(MAXROW * INROW))
                    {
                        ISTRING += ELEMENTGUI.Replace("{backgroundskin}", config.color.backgroundskin).Replace("{button}", $"skin.controll choose {ITEMNAME} {x}").Replace("{maxy}", starty.ToString()).Replace("{miny}", (starty - 0.2f).ToString()).Replace("{maxx}", (startx + 0.088f).ToString()).Replace("{minx}", startx.ToString()).Replace("{png}", GetImage(ITEMNAME, x));
                        if (i % INROW == 0)
                        {
                            startx = conststartx;
                            starty -= 0.22f;
                        }
                        else startx += 0.098f;
                        i++;
                    }
                    float start = 0.485f;
                    for (int c = 0; c <= Math.Floor(config.skins[ITEMNAME].Count() / (MAXROW * INROW * 1f)); c++)
                    {
                        ISTRING += BUTTONGUI.Replace("{button}", PAGE == c ? "" : $"skin.controll show {ITEMNAME} {c}").Replace("{color}", PAGE == c ? config.color.activecolor : config.color.buttoncolor).Replace("{max}", (start + 0.02f).ToString()).Replace("{min}", start.ToString()).Replace("{T}", (c + 1).ToString());
                        start += 0.025f;
                    }
                    ISTRING += GUICENTERBUT.Replace("{text}", "СТРАНИЦЫ:");
                    CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", ISTRING + "]");
                }
                else if (arg.Args[0] == "choose")
                {
                    string ITEMNAME = arg.Args[1];
                    if (!config.skins.ContainsKey(ITEMNAME)) return;
                    ulong SKIN;
                    if (!ulong.TryParse(arg.Args[2], out SKIN) || !config.skins[ITEMNAME].Contains(SKIN)) return;
                    // Debug.Log(arg.Args[2]);
                    if (!skinplayers[player.userID].skins.ContainsKey(ITEMNAME)) skinplayers[player.userID].skins.Add(ITEMNAME, SKIN);
                    else skinplayers[player.userID].skins[ITEMNAME] = SKIN;
                    player.SendConsoleCommand($"skin.controll page {(int)skinplayers[player.userID].page}");
                    NextTick(() => ALERTPLAYER(player, config.text.done.text, config.text.done.size));
                    //ServerMgr.Instance.StartCoroutine(PAINTING(GetAllItem(player.inventory), ITEMNAME, SKIN));
                    EffectNetwork.Send(new Effect("assets/bundled/prefabs/fx/notice/loot.drag.grab.fx.prefab", player, 0, Vector3.up, Vector3.zero) { scale = 1f }, player.net.connection);
                }
            }
            else if (arg.Args.Length == 2)
            {
                if (arg.Args[0] == "page")
                {
                    int INTPARSE;
                    if (!int.TryParse(arg.Args[1], out INTPARSE) || INTPARSE < 0 || INTPARSE >= config.categorys.Count) return;
                    elementbutton page = (elementbutton)INTPARSE;
                    elementbutton lpage = skinplayers[player.userID].page;
                    if (page == lpage && opening[player.userID]) return;
                    opening[player.userID] = true;
                    string lastpage = ((int)lpage).ToString();
                    string activepage = ((int)page).ToString();
                    CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "SKINBACKHROUND");
                    string ISTRING = "[" + BACKGROUNDGUI.Replace("{backgroundmenu}", config.color.backgroundmenu).Replace("{backfootersize}", config.text.pint.size).Replace("{backfooter}", config.text.pint.text);
                    int i = 1;
                    float startx = conststartx;
                    float starty = conststarty;
                    foreach (var x in config.categorys[page].items)
                    {
                        if (!skinplayers[player.userID].skins.ContainsKey(x)) skinplayers[player.userID].skins.Add(x, 0UL);
                        ISTRING += ELEMENTGUI.Replace("{backgroundskin}", config.color.backgroundskin).Replace("{maxy}", starty.ToString()).Replace("{miny}", (starty - 0.2f).ToString()).Replace("{button}", $"skin.controll show {x} 0").Replace("{maxx}", (startx + 0.088f).ToString()).Replace("{minx}", startx.ToString()).Replace("{png}", GetImage(x, skinplayers[player.userID].skins[x]));
                        if (i % 10 == 0)
                        {
                            startx = conststartx;
                            starty -= 0.22f;
                        }
                        else startx += 0.098f;
                        i++;
                    }
                    if (page != lpage)
                    {
                        CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", $"ELEMENTBUTTON.{lastpage}");
                        CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", $"ELEMENTBUTTON.{INTPARSE}");
                        float start = 0.01f;
                        foreach (var z in config.categorys)
                        {
                            if (z.Key == lpage) ISTRING += ELEMENTBUTTONGUI.Replace("{num}", lastpage).Replace("{button}", $"skin.controll page {lastpage}").Replace("{text}", z.Value.name).Replace("{color}", config.color.buttoncolor).Replace("{min}", start.ToString()).Replace("{max}", (start + 0.188f).ToString());
                            else if (z.Key == page) ISTRING += ELEMENTBUTTONGUI.Replace("{num}", activepage).Replace("{button}", $"skin.controll page {activepage}").Replace("{text}", z.Value.name).Replace("{color}", config.color.activecolor).Replace("{min}", start.ToString()).Replace("{max}", (start + 0.188f).ToString());
                            start += BUTTONADD;
                        }
                    }
                    CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", ISTRING + "]");
                    skinplayers[player.userID].page = page;
                }
            }
            else if (arg.Args[0] == "exit")
            {
                if (opening.ContainsKey(player.userID)) opening.Remove(player.userID);
            }
        }

        private Item[] GetAllItem(PlayerInventory inventory)
        {
            List<Item> items = new List<Item>();
            foreach (ItemDefinition itemd in inventory.containerBelt.onlyAllowedItems)
            {
                try
                {
                    Item item = ItemManager.CreateByItemID(itemd.itemid, itemd.volume, 0);
                    items.Add(item);
                }
                catch (Exception ex) { }
            }
            foreach (ItemDefinition itemd in inventory.containerMain.onlyAllowedItems)
            {
                try
                {
                    Item item = ItemManager.CreateByItemID(itemd.itemid, itemd.volume, 0);
                    items.Add(item);
                }
                catch (Exception ex) { }
            }
            foreach (ItemDefinition itemd in inventory.containerWear.onlyAllowedItems)
            {
                try
                {
                    Item item = ItemManager.CreateByItemID(itemd.itemid, itemd.volume, 0);
                    items.Add(item);
                }
                catch (Exception ex) { }
            }
            inventory.baseEntity.ChatMessage($"{items.Count} Items");
            return items.ToArray();
        }

        [ChatCommand("skinid")]
        private void TESTCHATCOMMANDSKINMENU(BasePlayer player, string command, string[] args)
        {
            if (!player.IsAdmin) return;
            Item item = player.GetActiveItem();
            if (item == null) return;
            string text = item.skin.ToString();
            player.ChatMessage(text);
        }

        [ChatCommand("skin")]
        private void CHATCOMMANDSKINMENU(BasePlayer player, string command, string[] args)
        {
            if (!HAVEACCES(player.UserIDString))
            {
                player.ChatMessage(config.priv.message);
                return;
            }
            if (opening.ContainsKey(player.userID))
            {
                CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "SkinMenu");
                opening.Remove(player.userID);
                return;
            }
            else opening.Add(player.userID, true);

            INITPLAYER(player.userID);
            elementbutton page = skinplayers[player.userID].page;
            string ISTRING = "," + BACKGROUNDGUI.Replace("{backgroundmenu}", config.color.backgroundmenu).Replace("{backfootersize}", config.text.pint.size).Replace("{backfooter}", config.text.pint.text);
            float start = 0.01f;
            foreach (var z in config.categorys)
            {
                if (z.Key == page)
                {
                    int i = 1;
                    float startx = conststartx;
                    float starty = conststarty;
                    foreach (var x in z.Value.items)
                    {
                        if (!skinplayers[player.userID].skins.ContainsKey(x)) skinplayers[player.userID].skins.Add(x, 0UL);
                        ISTRING += ELEMENTGUI.Replace("{backgroundskin}", config.color.backgroundskin).Replace("{maxy}", starty.ToString()).Replace("{button}", $"skin.controll show {x} 0").Replace("{miny}", (starty - 0.2f).ToString()).Replace("{maxx}", (startx + 0.088f).ToString()).Replace("{minx}", startx.ToString()).Replace("{png}", GetImage(x, skinplayers[player.userID].skins[x]));
                        if (i % 10 == 0)
                        {
                            startx = conststartx;
                            starty -= 0.22f;
                        }
                        else startx += 0.098f;
                        i++;
                    }
                }
                string KEY = ((int)z.Key).ToString();
                ISTRING += ELEMENTBUTTONGUI.Replace("{num}", KEY).Replace("{button}", $"skin.controll page {KEY}").Replace("{text}", z.Value.name).Replace("{color}", z.Key == page ? config.color.activecolor : config.color.buttoncolor).Replace("{min}", start.ToString()).Replace("{max}", (start + 0.188f).ToString());
                start += BUTTONADD;
            }
            CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", MAINGUI.Replace("{main}", ISTRING));
        }

        private ulong APISKIN(BasePlayer player, string ITEMNAME)
        {
            playerinfo playerinfo;
            if (!skinplayers.TryGetValue(player.userID, out playerinfo)) return 0UL;
            ulong SKIN;
            if (!playerinfo.skins.TryGetValue(ITEMNAME, out SKIN)) return 0UL;
            return SKIN;
        }
        
        Dictionary<RepairBench, List<ulong>> openrepair = new Dictionary<RepairBench, List<ulong>>();
        private void OnLootEntity(BasePlayer player, BaseEntity entity)
        {
            if (entity is RepairBench)
            {
                if (!HAVEACCES(player.UserIDString)) return;
                RepairBench repairBench = entity.GetComponent<RepairBench>();
                if (repairBench.inventory.IsFull())
                {
                    if (!openrepair.ContainsKey(repairBench)) openrepair.Add(repairBench, new List<ulong> { player.userID });
                    else if (!openrepair[repairBench].Contains(player.userID)) openrepair[repairBench].Add(player.userID);

                    CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "SKINPANELMAIN");
                    CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", GUISkin);
                }
            }
        }

        void OnItemRemovedFromContainer(ItemContainer container, Item item)
        {
            if (container.entityOwner == null) return;
            if (container.entityOwner is RepairBench)
            {
                RepairBench repairBench = (RepairBench)container.entityOwner;
                if (!openrepair.ContainsKey(repairBench)) return;
                foreach (var z in openrepair[repairBench])
                {
                    BasePlayer player = BasePlayer.FindByID(z);
                    if (player == null) continue;
                    CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "SKINPANELMAIN");
                }
                openrepair.Remove(repairBench);
            }
        }

        private void CanAcceptItem(ItemContainer container, Item item)
        {
            if (container == null || item == null) return;
            if (container.entityOwner != null && container.entityOwner is RepairBench || item.parent != null && item.parent.entityOwner != null && item.parent.entityOwner is RepairBench)
            {
                RepairBench repairBench = (RepairBench)container.entityOwner ?? (RepairBench)item.parent.entityOwner;
                BasePlayer player = item.GetOwnerPlayer() ?? container.GetOwnerPlayer();
                if (player != null)
                {
                    NextTick(() =>
                    {
                        if (container == null || item == null) return;
                        if (!openrepair.ContainsKey(repairBench)) openrepair.Add(repairBench, new List<ulong>());
                        Item slot = repairBench.inventory.GetSlot(0);
                        if (slot != null)
                        {
                            if (!openrepair[repairBench].Contains(player.userID))
                            {
                                CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "SKINPANELMAIN");
                                CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", GUISkin);
                                openrepair[repairBench].Add(player.userID);
                            }
                        }
                    });
                }
            }
        }

        void OnPlayerLootEnd(PlayerLoot looter)
        {
            if (looter?.entitySource == null) return;
            if (!(looter.entitySource is RepairBench)) return;
            RepairBench repairBench = (RepairBench)looter.entitySource;
            BasePlayer player = looter.GetComponent<BasePlayer>();
            if (player == null) return;
            if (!HAVEACCES(player.UserIDString)) return;
            if (!openrepair.ContainsKey(repairBench)) openrepair.Add(repairBench, new List<ulong>());
            if (openrepair[repairBench].Contains(player.userID)) openrepair[repairBench].Remove(player.userID);
            CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "SKINPANELMAIN");
        }

        Dictionary<BasePlayer, DateTime> nextskinchange = new Dictionary<BasePlayer, DateTime>();
        private void ChangeSkin(BasePlayer player, bool rand)
        {
            foreach (var z in openrepair.Where(x => x.Value.Contains(player.userID)))
            {
                if (z.Key == null || z.Key.IsDestroyed) continue;
                Item slot = z.Key.inventory.GetSlot(0);
                if (slot == null) return;
                INITPLAYER(player.userID);
                ulong nextskin = 0UL;
                if (rand)
                {
                    List<ulong> skinlist;
                    if (!config.skins.TryGetValue(slot.info.shortname, out skinlist)) return;
                    nextskin = skinlist[Random.Range(0, skinlist.Count())];
                }
                else nextskin = APISKIN(player, slot.info.shortname);
                if (nextskin == slot.skin) return;
                DateTime time;
                if (nextskinchange.TryGetValue(player, out time) && DateTime.Now < time) return;
                nextskinchange[player] = DateTime.Now.AddSeconds(1f);
                slot.skin = nextskin;
                slot.MarkDirty();
                BaseEntity heldEntity = slot.GetHeldEntity();
                if ((UnityEngine.Object)heldEntity != (UnityEngine.Object)null)
                {
                    heldEntity.skinID = nextskin;
                    heldEntity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
                }
                if (!z.Key.skinchangeEffect.isValid) return;
                Effect.server.Run(z.Key.skinchangeEffect.resourcePath, z.Key, 0U, new Vector3(0.0f, 1.5f, 0.0f), Vector3.zero, (Connection)null, false);

            }
        }

        private void OnPlayerDisconnected(BasePlayer player, string reason)
        {
            Save(player);
            skinplayers.Remove(player.userID);
        }

        private void Save(BasePlayer player)
        {
            playerinfo playerinfo;
            if (!skinplayers.TryGetValue(player.userID, out playerinfo)) return;
            Interface.Oxide.DataFileSystem.WriteObject($"SKINS/{player.UserIDString}", playerinfo);
        }

        private void InitPlayerSkin(BasePlayer player)
        {
            if (!Interface.Oxide.DataFileSystem.ExistsDatafile($"SKINS/{player.UserIDString}")) return;
            playerinfo info = Interface.Oxide.DataFileSystem.ReadObject<playerinfo>($"SKINS/{player.UserIDString}");
            skinplayers[player.userID] = info;
        }

        private void Unload()
        {
            foreach (BasePlayer player in BasePlayer.activePlayerList) Save(player);
            skinplayers.Clear();
            openrepair.Clear();
            CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connections = Network.Net.sv.connections }, null, "DestroyUI", "SkinMenu");
            CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connections = Network.Net.sv.connections }, null, "DestroyUI", "SKINPANELMAIN");
            CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connections = Network.Net.sv.connections }, null, "DestroyUI", "ALERT");
            opening.Clear();
        }
    }
}