C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Facepunch;
using Facepunch.Extend;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using UnityEngine.UI;
using Global = Rust.Global;
namespace Oxide.Plugins;
[Info("LSkins", "LAGZYA", "1.7.5")]
public class LSkins : RustPlugin {
#region Cfg
private const bool En = false;
private class DataPlayer {
[JsonProperty(En ? "List of favorite skins" : "Список избранных скинов")]
public Dictionary<string, Dictionary<ulong, ItemData.SkinInfo>> _izvSkins = new Dictionary<string, Dictionary<ulong, ItemData.SkinInfo>>();
[JsonProperty(En ? "List of default skins supplied" : "Список поставленных скинов по дефолту")]
public Dictionary<string, DefaultSkins> _defaultSkins = new Dictionary<string, DefaultSkins>();
}
private class DefaultSkins {
[JsonProperty(En ? "SkinID" : "СкинАйди")]
public ulong skinId;
[JsonProperty(En ? "Information about the skin" : "Информация о скине")]
public ItemData.SkinInfo SkinInfo;
}
private Dictionary<ulong, DataPlayer> _playerData = new Dictionary<ulong, DataPlayer>();
private static ConfigData Cfg {
get;
set;
}
private class ConfigData {
internal class MarketSystem {
[JsonProperty(En ? "Enabled(true = yes)" : "Включить?(true = да)")]
public bool IsEnabled = false;
[JsonProperty(En ? "How to pay?(Scrap, ServerRewards, Economics)" : "Чем платить?(Scrap, ServerRewards, Economics)")]
public string WhoMarket = "Scrap";
[JsonProperty(En ? "The price for opening the interface (If 0, then free)" : "Цена за открытие интерфейса(Если 0, то бесплатно)")]
public int costOpen = 10;
[JsonProperty(En ? "Price per change of one skin (If 0, then free)" : "Цена за смену одного скина(Если 0, то бесплатно)")]
public int costChange = 10;
}
internal class InterfaceSetting {
[JsonProperty(En ? "Background color of favorite skins" : "Цвет фона фаворитных скинов")]
public string favcolor = "#535150";
[JsonProperty(En ? "Background color of the main panel" : "Цвет фона основной панели")]
public string mainColor = "#535151";
[JsonProperty(En ? "The color of the forward arrow" : "Цвет стрелочки вперед")]
public string pageup = "#5c80ba";
[JsonProperty(En ? "The color of the back arrow" : "Цвет стрелочки назад")]
public string pagedown = "#5c80ba";
}
[JsonProperty(En ? "Add a skin to the cfg automatically?(true = yes)" : "Добавить в кфг автоматически скин?(true = да)")]
public bool IsApproved = false;
[JsonProperty(En ? "Add a hazmats to the cfg automatically?(true = yes)" : "Добавить в кфг автоматически хазматы?(true = да)")]
public bool IsHazmat = false;
[JsonProperty(En ? "Rights to use the skins system" : "Права для использование системы скинов.")]
public string canuse = "lskins.use";
[JsonProperty(En ? "Rights to use the skins approve" : "Права для использование подтвержденных скинов.")]
public string canuseapprove = "lskins.useapprove";
[JsonProperty(En ? "List of available commands" : "Список доступных команд")]
public List<string> Commands = new List<string>();
[JsonProperty(En ? "List of available commands for skins entity" : "Список доступных команд для изменения скина ентити")]
public List<string> EntCommands = new List<string>();
[JsonProperty(En ? "Install the skin automatically on items where there is already a skin?(true = yes)" : "Устанавилвать скин автоматически на предметы где уже есть скин?(true = да)")]
public bool SkinAuto = false;
[JsonProperty(En ? "Rights to use default skins" : "Права для использование скинов по дефолту")]
public string canusedefault = "lskins.usedefault";
[JsonProperty(En ? "Setting up payment for opening" : "Настройка оплаты за открытие")]
public MarketSystem Market = new MarketSystem();
[JsonProperty(En ? "Setting interface" : "Настройка интерфейса")]
public InterfaceSetting Interface = new InterfaceSetting();
[JsonProperty(En ? "Items with these skins cannot be exchanged." : "Предметы с этими скинами нельзя будет поменять.")]
public List<ulong> blackList = new List<ulong>();
[JsonProperty(En ? "Rights to use unique skins" : "Права для использование уникальных скинов")]
public Dictionary<string, List<ulong>> useSkins = new Dictionary<string, List<ulong>>();
public static ConfigData GetNewConf() {
var newConfig = new ConfigData {
Commands = new List<string>() {
"skins", "skin", "s"
}
, EntCommands = new List<string>() {
"se"
}
, useSkins = new Dictionary<string, List<ulong>>() {
["lskins.prem"]
= new List<ulong>() {
2668297561, 2649480126, 2599664731,
}
}
, blackList = new List<ulong>() {
12341234,
}
}
;
return newConfig;
}
}
class ItemData {
public class SkinInfo {
[JsonProperty(En ? "Enabled skin?(true = yes)" : "Включить скин?(true = да)")]
public bool IsEnabled = true;
[JsonProperty(En ? "Is this skin from the developers of rust or take it in a workshop?" : "Этот скин есть от разработчиков раста или принять в воркшопе??(true = да)")]
public bool IsApproved = true;
[JsonProperty(En ? "Name skin" : "Название скина")]
public string MarketName = "Warhead LR300";
}
public Dictionary<ulong, SkinInfo> _skinInfos = new Dictionary<ulong, SkinInfo>();
}
protected override void LoadDefaultConfig() {
Cfg = ConfigData.GetNewConf();
}
protected override void SaveConfig() {
Config.WriteObject(Cfg);
}
protected override void LoadConfig() {
base.LoadConfig();
try {
Cfg = Config.ReadObject<ConfigData>();
}
catch {
LoadDefaultConfig();
}
NextTick(SaveConfig);
}
#endregion
#region Interface
private static string Layer = "UiLSkins";
private static string Hud = "Hud";
private static string Overlay = "Overlay";
private static string _regular = "robotocondensed-regular.ttf";
private static string _blur = "assets/content/ui/uibackgroundblur.mat";
private static string _sharp = "assets/content/ui/ui.background.tile.psd";
private static string _radial = "assets/content/ui/ui.background.transparent.radial.psd";
private void LoadIzbranoeUI(BasePlayer player, string weapon, ulong itemId, int page, bool isentity = false) {
if (!_playerData.TryGetValue(player.userID, out var weapons)) return;
CuiHelper.DestroyUi(player, Layer + "-Izbranoe");
var cont = new CuiElementContainer();
cont.Add(new CuiPanel() {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = $"{201} {111}", OffsetMax = $"{571} {231}"
}
}
, "Overlay", Layer + "-Izbranoe");
if (!weapons._izvSkins.ContainsKey(weapon)) return;
var tSkinsList = weapons._izvSkins[weapon];
foreach (var keyValuePair in Cfg.useSkins.Where(keyValuePair => !permission.UserHasPermission(player.UserIDString, keyValuePair.Key))) {
keyValuePair.Value.ForEach(p => {
if (tSkinsList.ContainsKey(p)) {
tSkinsList.Remove(p);
}
}
);
}
for (var i = 0; i < 12; i++) {
if (tSkinsList.Count - 1 < i) continue;
cont.Add(new CuiElement() {
Parent = Layer + "-Izbranoe", Components = {
new CuiRawImageComponent() {
Png = GetImage(weapon + "_" + tSkinsList.ToList()[i].Key)
}
, new CuiRectTransformComponent() {
AnchorMin = $"0 0.5", AnchorMax = $"0 0.5", OffsetMin = $"{2 + i * 62 - Math.Floor((double)i / 6) * 6 * 62} {5 - Math.Floor((double)i / 6) * 62}", OffsetMax = $"{52 + i * 62 - Math.Floor((double)i / 6) * 6 * 62} {55 - Math.Floor((double)i / 6) * 62}"
}
}
}
);
var type = isentity ? "setskinent" : "setskin";
cont.Add(new CuiButton() {
Button = {
Color = "1 1 1 0", Command = $"uiskinmenu {type} {itemId} {tSkinsList.ToList()[i].Key}"
}
, Text = {
Text = ""
}
, RectTransform = {
AnchorMin = $"0 0.5", AnchorMax = $"0 0.5", OffsetMin = $"{2 + i * 62 - Math.Floor((double)i / 6) * 6 * 62} {5 - Math.Floor((double)i / 6) * 62}", OffsetMax = $"{52 + i * 62 - Math.Floor((double)i / 6) * 6 * 62} {55 - Math.Floor((double)i / 6) * 62}"
}
}
, Layer + "-Izbranoe", Layer + "-Izbranoe" + i);
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"{-5} {-10}", OffsetMax = $"{10} {5}"
}
, Button = {
Command = $"uiskinmenu setizbranoe {weapon} {tSkinsList.ToList()[i].Key} {page} {itemId}", Color = HexToRustFormat("#dead39"), Sprite = "assets/icons/favourite_servers.png",
}
, Text = {
Text = ""
}
}
, Layer + "-Izbranoe" + i);
if (!permission.UserHasPermission(player.UserIDString, Cfg.canusedefault)) continue;
if (_playerData.TryGetValue(player.userID, out weapons) && weapons._defaultSkins.ContainsKey(weapon) && weapons._defaultSkins[weapon].skinId == tSkinsList.ToList()[i].Key) {
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "1 0", AnchorMax = "1 0", OffsetMin = $"{-10} {0}", OffsetMax = $"{0} {10}"
}
, Button = {
Command = $"uiskinmenu setdefault {weapon} {tSkinsList.ToList()[i].Key} {page} {itemId}", Color = HexToRustFormat("#369f47"), Sprite = "assets/icons/power.png",
}
, Text = {
Text = ""
}
}
, Layer + "-Izbranoe" + i);
}
else {
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "1 0", AnchorMax = "1 0", OffsetMin = $"{-10} {0}", OffsetMax = $"{0} {10}"
}
, Button = {
Command = $"uiskinmenu setdefault {weapon} {tSkinsList.ToList()[i].Key} {page} {itemId}", Color = HexToRustFormat("#fb4f3b"), Sprite = "assets/icons/power.png",
}
, Text = {
Text = ""
}
}
, Layer + "-Izbranoe" + i);
}
}
CuiHelper.AddUi(player, cont);
}
private void LoadWearUI(BasePlayer player) {
CuiHelper.DestroyUi(player, Layer + "-Wear");
var cont = new CuiElementContainer();
cont.Add(new CuiPanel() {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = $"{-588} {115}", OffsetMax = $"{-215} {169}"
}
}
, "Overlay", Layer + "-Wear");
for (int i = 0; i < player.inventory.containerWear.capacity - 1; i++) {
var item = player.inventory.containerWear.GetSlot(i);
if (item == null) {
cont.Add(new CuiElement() {
Parent = Layer + "-Wear", Components = {
new CuiRawImageComponent() {
Png = GetImage($"LSKINGRID({Version})"), Color = "1 1 1 0.05"
}
, new CuiRectTransformComponent() {
AnchorMin = $"0 0", AnchorMax = $"0 0", OffsetMin = $"{0 + i * 54 - Math.Floor((double)i / 7) * 7 * 54} {0}", OffsetMax = $"{50 + i * 54 - Math.Floor((double)i / 7) * 7 * 54} {50}"
}
}
}
);
continue;
}
var onblacklist = Cfg.blackList.Contains(item.skin);
var shortname = item.info.shortname.Contains("hazmatsuit") ? "hazmatsuit" : item.info.shortname;
var skinsExsist = Interface.Oxide.DataFileSystem.ExistsDatafile($"LSkins/Skins/{shortname}");
if (!onblacklist && skinsExsist) {
cont.Add(new CuiButton() {
Button = {
Color = "0.65 0.65 0.65 0", Command = $"uiskinmenu weaponSelect {item.info.shortname} {item.uid}"
}
, Text = {
Text = ""
}
, RectTransform = {
AnchorMin = $"0 0", AnchorMax = $"0 0", OffsetMin = $"{0 + i * 54 - Math.Floor((double)i / 7) * 7 * 54} {0}", OffsetMax = $"{50 + i * 54 - Math.Floor((double)i / 7) * 7 * 54} {50}"
}
}
, Layer + "-Wear");
}
else {
cont.Add(new CuiElement() {
Parent = Layer + "-Wear", Components = {
new CuiRawImageComponent() {
Png = GetImage($"LSKINGRID({Version})"), Color = "1 1 1 0.05"
}
, new CuiRectTransformComponent() {
AnchorMin = $"0 0", AnchorMax = $"0 0", OffsetMin = $"{0 + i * 54 - Math.Floor((double)i / 7) * 7 * 54} {0}", OffsetMax = $"{50 + i * 54 - Math.Floor((double)i / 7) * 7 * 54} {50}"
}
}
}
);
}
}
CuiHelper.AddUi(player, cont);
}
private void LoadMainUI(BasePlayer player) {
CuiHelper.DestroyUi(player, Layer + "-Main");
var cont = new CuiElementContainer();
cont.Add(new CuiPanel() {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = $"{0.5} {0}", AnchorMax = $"{0.5} {0}", OffsetMin = $"{-200} {85}", OffsetMax = $"{180} {337}"
}
}
, "Overlay", Layer + "-Main");
for (int i = 0; i < player.inventory.containerMain.capacity; i++) {
var item = player.inventory.containerMain.GetSlot(i);
if (item == null) {
cont.Add(new CuiElement() {
Parent = Layer + "-Main", Components = {
new CuiRawImageComponent() {
Png = GetImage($"LSKINGRID({Version})"), Color = "1 1 1 0.05"
}
, new CuiRectTransformComponent() {
AnchorMin = $"0 1", AnchorMax = $"0 1", OffsetMin = $"{0 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {-60 - Math.Floor((double)i / 6) * 63.5}", OffsetMax = $"{60 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {0 - Math.Floor((double)i / 6) * 63.5}"
}
}
}
);
continue;
}
var onblacklist = Cfg.blackList.Contains(item.skin);
var shortname = item.info.shortname.Contains("hazmatsuit") ? "hazmatsuit" : item.info.shortname;
var skinsExsist = Interface.Oxide.DataFileSystem.ExistsDatafile($"LSkins/Skins/{shortname}");
if (!onblacklist && skinsExsist) {
cont.Add(new CuiButton() {
Button = {
Color = "0.65 0.65 0.65 0", Command = $"uiskinmenu weaponSelect {item.info.shortname} {item.uid}"
}
, Text = {
Text = ""
}
, RectTransform = {
AnchorMin = $"0 1", AnchorMax = $"0 1", OffsetMin = $"{0 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {-60 - Math.Floor((double)i / 6) * 63}", OffsetMax = $"{60 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {0 - Math.Floor((double)i / 6) * 63}"
}
}
, Layer + "-Main");
}
else {
cont.Add(new CuiElement() {
Parent = Layer + "-Main", Components = {
new CuiRawImageComponent() {
Png = GetImage($"LSKINGRID({Version})"), Color = "1 1 1 0.05"
}
, new CuiRectTransformComponent() {
AnchorMin = $"0 1", AnchorMax = $"0 1", OffsetMin = $"{0 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {-60 - Math.Floor((double)i / 6) * 63}", OffsetMax = $"{60 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {0 - Math.Floor((double)i / 6) * 63.5}"
}
}
}
);
}
}
CuiHelper.AddUi(player, cont);
}
private void LoadBeltUI(BasePlayer player) {
CuiHelper.DestroyUi(player, Layer + "-Belt");
var cont = new CuiElementContainer();
cont.Add(new CuiPanel() {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = $"{-200} {17}", OffsetMax = $"{180} {79}"
}
}
, "Overlay", Layer + "-Belt");
for (int i = 0; i < 6; i++) {
var item = player.inventory.containerBelt.GetSlot(i);
if (item == null) {
cont.Add(new CuiElement() {
Parent = Layer + "-Belt", Components = {
new CuiRawImageComponent() {
Png = GetImage($"LSKINGRID({Version})"), Color = "1 1 1 0.05"
}
, new CuiRectTransformComponent() {
AnchorMin = $"0 0", AnchorMax = $"0 0", OffsetMin = $"{0 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {0}", OffsetMax = $"{60 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {60}"
}
}
}
);
continue;
}
var onblacklist = Cfg.blackList.Contains(item.skin);
var shortname = item.info.shortname.Contains("hazmatsuit") ? "hazmatsuit" : item.info.shortname;
var skinsExsist = Interface.Oxide.DataFileSystem.ExistsDatafile($"LSkins/Skins/{shortname}");
if (!onblacklist && skinsExsist) {
cont.Add(new CuiButton() {
Button = {
Color = "0.65 0.65 0.65 0", Command = $"uiskinmenu weaponSelect {item.info.shortname} {item.uid}"
}
, Text = {
Text = ""
}
, RectTransform = {
AnchorMin = $"0 0", AnchorMax = $"0 0", OffsetMin = $"{0 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {0}", OffsetMax = $"{60 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {60}"
}
}
, Layer + "-Belt");
}
else {
cont.Add(new CuiElement() {
Parent = Layer + "-Belt", Components = {
new CuiRawImageComponent() {
Png = GetImage($"LSKINGRID({Version})"), Color = "1 1 1 0.05"
}
, new CuiRectTransformComponent() {
AnchorMin = $"0 0", AnchorMax = $"0 0", OffsetMin = $"{0 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {0}", OffsetMax = $"{60 + i * 64 - Math.Floor((double)i / 6) * 6 * 64} {60}"
}
}
}
);
}
}
CuiHelper.AddUi(player, cont);
}
[ConsoleCommand("uiskinmenu")]
private void ConsoleCommand(ConsoleSystem.Arg arg) {
var player = arg.Player();
if (player == null) return;
var sound1 = new Effect("assets/bundled/prefabs/fx/notice/loot.drag.grab.fx.prefab", player, 0, new Vector3(), new Vector3());
string weapon;
ulong skinId;
int page;
int itemId;
DataPlayer weapons;
string uid;
switch (arg.Args[0]) {
case "search" : EffectNetwork.Send(sound1, player.Connection);
LoadSkinsUI(player, arg.Args[1], 1, uint.Parse(arg.Args[2]), bool.Parse(arg.Args[3]), arg.Args[4]);
break;
case "page" : EffectNetwork.Send(sound1, player.Connection);
LoadSkinsUI(player, arg.Args[1], arg.Args[2].ToInt(), uint.Parse(arg.Args[3]), bool.Parse(arg.Args[4]));
LoadIzbranoeUI(player, arg.Args[1], uint.Parse(arg.Args[3]), arg.Args[2].ToInt(), bool.Parse(arg.Args[4]));
break;
case "weaponSelect" : EffectNetwork.Send(sound1, player.Connection);
LoadSkinsUI(player, arg.Args[1], 1, uint.Parse(arg.Args[2]));
LoadIzbranoeUI(player, arg.Args[1], uint.Parse(arg.Args[2]), 1);
break;
case "setizbranoe" : EffectNetwork.Send(sound1, player.Connection);
if (!_playerData.TryGetValue(player.userID, out weapons)) return;
weapon = arg.Args[1];
skinId = ulong.Parse(arg.Args[2]);
page = arg.Args[3].ToInt();
itemId = arg.Args[4].ToInt();
if (weapons._izvSkins.ContainsKey(weapon) && weapons._izvSkins[weapon].ContainsKey(skinId)) {
weapons._izvSkins[weapon].Remove(skinId);
}
else if (weapons._izvSkins.ContainsKey(weapon)) {
weapons._izvSkins[weapon].Add(skinId, _loadData[weapon][skinId]);
}
else {
weapons._izvSkins.Add(weapon, new Dictionary<ulong, ItemData.SkinInfo>() {
[skinId]
= _loadData[weapon][skinId]
}
);
}
LoadSkinsUI(player, weapon, page, (uint)itemId);
LoadIzbranoeUI(player, weapon, (uint)itemId, page);
break;
case "setdefault" : EffectNetwork.Send(sound1, player.Connection);
if (!_playerData.TryGetValue(player.userID, out weapons)) return;
weapon = arg.Args[1];
skinId = ulong.Parse(arg.Args[2]);
page = arg.Args[3].ToInt();
itemId = arg.Args[4].ToInt();
if (weapons._defaultSkins.ContainsKey(weapon) && weapons._defaultSkins[weapon].skinId == skinId) {
weapons._defaultSkins.Remove(weapon);
}
else if (weapons._defaultSkins.ContainsKey(weapon)) {
weapons._defaultSkins[weapon].skinId = skinId;
weapons._defaultSkins[weapon].SkinInfo = _loadData[weapon][skinId];
}
else {
weapons._defaultSkins.Add(weapon, new DefaultSkins() {
skinId = skinId, SkinInfo = _loadData[weapon][skinId]
}
);
}
LoadSkinsUI(player, weapon, page, (uint)itemId);
LoadIzbranoeUI(player, weapon, (uint)itemId, page);
break;
case "setskin" : EffectNetwork.Send(sound1, player.Connection);
if (Cfg.Market.IsEnabled && !permission.UserHasPermission(player.UserIDString, Cfg.canuse)) {
if (ChangeSkin(player) == false) {
return;
}
}
uid = arg.Args[1];
var item = player.inventory.FindItemByUID(new ItemId(ulong.Parse(uid)));
if (item.info.shortname.Contains("hazmatsuit")) {
var pos = item.position;
var container = item.GetRootContainer();
var uids = item.uid;
int amount = item.amount;
item.DoRemove();
item = ItemManager.CreateByName($"{_hazmats[ulong.Parse(arg.Args[2])]}");
item.uid = uids;
item.MoveToContainer(container, pos);
item.amount = amount;
item.MarkDirty();
player.SendNetworkUpdate();
return;
}
item.skin = ulong.Parse(arg.Args[2]);
var hend = item.GetHeldEntity();
if (hend != null) {
hend.skinID = ulong.Parse(arg.Args[2]);
hend.SendNetworkUpdate();
}
item.MarkDirty();
player.SendNetworkUpdate();
break;
case "setskinent" : EffectNetwork.Send(sound1, player.Connection);
if (Cfg.Market.IsEnabled && !permission.UserHasPermission(player.UserIDString, Cfg.canuse)) {
if (ChangeSkin(player) == false) {
return;
}
}
uint entid = uint.Parse(arg.Args[1]);
var ent = BaseEntity.serverEntities.Find(new NetworkableId(entid)) as BaseEntity;
if (ent != null) {
ent.skinID = ulong.Parse(arg.Args[2]);
ent.SendNetworkUpdate();
}
break;
case "close" : EffectNetwork.Send(sound1, player.Connection);
player.EndLooting();
break;
}
}
private void LoadSkinsUI(BasePlayer player, string weapon, int page, ulong itemId, bool isentity = false, string search = null) {
if (weapon.Contains("hazmatsuit")) weapon = "hazmatsuit";
var skinsList = _loadData.ContainsKey(weapon);
if (!skinsList) return;
if (!_playerData.TryGetValue(player.userID, out var weapons)) return;
CuiHelper.DestroyUi(player, Layer + "-Search");
var cont = new CuiElementContainer();
cont.Add(new CuiPanel() {
Image = {
ImageType = UnityEngine.UI.Image.Type.Filled, Png = "assets/standard assets/effects/imageeffects/textures/noise.png", Sprite = _sharp, Color = HexToRustFormat("#5351512C"), Material = "assets/icons/greyout.mat"
}
, RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-400} {-185}", OffsetMax = $"{-35} {115}"
}
}
, Layer, Layer + "-Search");
cont.Add(new CuiPanel() {
Image = {
ImageType = UnityEngine.UI.Image.Type.Filled, Png = "assets/standard assets/effects/imageeffects/textures/noise.png", Sprite = _sharp, Color = HexToRustFormat("#5351512C"), Material = "assets/icons/greyout.mat"
}
, RectTransform = {
AnchorMin = "1 0.5", AnchorMax = "1 0.5", OffsetMin = $"{4} {-150}", OffsetMax = $"{42} {150}"
}
}
, Layer + "-Search", Layer + "-Page");
var tSkinsList = _loadData[weapon].Where(p => permission.UserHasPermission(player.UserIDString, Cfg.canuseapprove) ? p.Value.IsApproved || !p.Value.IsApproved : !p.Value.IsApproved).ToDictionary(keyValuePair => keyValuePair.Key, keyValuePair => keyValuePair.Value);
if (Cfg.useSkins.Count >= 1) foreach (var keyValuePair in Cfg.useSkins.Where(keyValuePair => !permission.UserHasPermission(player.UserIDString, keyValuePair.Key))) {
keyValuePair.Value.ForEach(p => {
if (tSkinsList.ContainsKey(p)) {
tSkinsList.Remove(p);
}
}
);
}
if (0 < tSkinsList.Count - 12 * page) {
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-10} {5}", OffsetMax = $"{10} {143}"
}
, Button = {
Command = $"uiskinmenu page {weapon} {page + 1} {itemId} {isentity}", Color = HexToRustFormat($"{Cfg.Interface.pageup}c3")
}
, Text = {
Text = "»", Align = TextAnchor.MiddleCenter, FontSize = (int)(20)
}
}
, Layer + "-Page");
}
else {
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-10} {5}", OffsetMax = $"{10} {143}"
}
, Button = {
Command = $"", Color = HexToRustFormat($"{Cfg.Interface.pageup}c3")
}
, Text = {
Text = "»", Align = TextAnchor.MiddleCenter, FontSize = (int)(20), Color = "0.65 0.65 0.65 0.65"
}
}
, Layer + "-Page");
}
if (page > 1) {
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-10} {-137}", OffsetMax = $"{10} {-5}"
}
, Button = {
Command = $"uiskinmenu page {weapon} {page - 1} {itemId} {isentity}", Color = HexToRustFormat(Cfg.Interface.pagedown)
}
, Text = {
Text = "«", Align = TextAnchor.MiddleCenter, FontSize = (int)(20)
}
}
, Layer + "-Page");
}
else {
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-10} {-137}", OffsetMax = $"{10} {-5}"
}
, Button = {
Command = $"", Color = HexToRustFormat($"{Cfg.Interface.pagedown}c3")
}
, Text = {
Text = "«", Align = TextAnchor.MiddleCenter, FontSize = (int)(20), Color = "0.65 0.65 0.65 0.65"
}
}
, Layer + "-Page");
}
cont.Add(new CuiElement() {
Parent = Layer + "-Search", Components = {
new CuiImageComponent() {
ImageType = UnityEngine.UI.Image.Type.Filled, Png = "assets/standard assets/effects/imageeffects/textures/noise.png", Sprite = _sharp, Color = "0.25 0.25 0.25 0.3", Material = "assets/icons/greyout.mat"
}
, new CuiRectTransformComponent() {
AnchorMin = "0.7 1", AnchorMax = "0.7 1", OffsetMin = "-70 13", OffsetMax = "100 35"
}
}
}
);
cont.Add(new CuiElement() {
Parent = Layer + "-Search", Components = {
new CuiInputFieldComponent() {
NeedsKeyboard = false, Text = lang.GetMessage("LABLESEARCH", this, player.UserIDString), Align = TextAnchor.MiddleCenter, Command = $"uiskinmenu search {weapon} {itemId} {isentity} ", Color = "1 1 1 1", FontSize = 12
}
, new CuiRectTransformComponent() {
AnchorMin = "0.7 1", AnchorMax = "0.7 1", OffsetMin = "-70 13", OffsetMax = "100 35"
}
}
}
);
foreach (var skinItem in tSkinsList.Where(p => search == null ? p.Value != null : p.Value.MarketName.ToLower().Contains(search.ToLower()) || p.Key.ToString().Contains(search.ToLower())).Where(p => p.Value.IsEnabled).Select((i, t) => new {
A = i, B = t - (page - 1) * 12
}
).Skip((page - 1) * 12).Take(12)) {
cont.Add(new CuiElement() {
Parent = Layer + "-Search", Name = Layer + "-Search" + ".Player" + skinItem.B, Components = {
new CuiImageComponent() {
Color = "0.35 0.35 0.35 0.65"
}
, new CuiRectTransformComponent {
AnchorMin = $"0 0.5", AnchorMax = $"0 0.5", OffsetMin = $"{4 + skinItem.B * 90 - Math.Floor((double)skinItem.B / 4) * 4 * 90} {60 - Math.Floor((double)skinItem.B / 4) * 98}", OffsetMax = $"{90 + skinItem.B * 90 - Math.Floor((double)skinItem.B / 4) * 4 * 90} {143 - Math.Floor((double)skinItem.B / 4) * 98}"
}
}
}
);
cont.Add(new CuiElement() {
Parent = Layer + "-Search" + ".Player" + skinItem.B, Components = {
new CuiRawImageComponent() {
Png = GetImage(weapon + "_" + skinItem.A.Key)
}
, new CuiRectTransformComponent() {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-30 -30", OffsetMax = "30 30"
}
}
}
);
cont.Add(new CuiElement() {
Parent = Layer + "-Search" + ".Player" + skinItem.B, Components = {
new CuiTextComponent() {
Text = skinItem.A.Value.MarketName, Align = TextAnchor.MiddleCenter, Font = _regular, FontSize = 9
}
, new CuiRectTransformComponent() {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = $"{-40} {-15}", OffsetMax = $"{40} {0}"
}
}
}
);
var type = isentity ? "setskinent" : "setskin";
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-30} {-30}", OffsetMax = $"{30} {30}"
}
, Button = {
Command = $"uiskinmenu {type} {itemId} {skinItem.A.Key}", Color = "0 0 0 0"
}
, Text = {
Text = ""
}
}
, Layer + "-Search" + ".Player" + skinItem.B);
if (weapons!._izvSkins.ContainsKey(weapon) && weapons._izvSkins[weapon].ContainsKey(skinItem.A.Key)) {
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"{1} {-18}", OffsetMax = $"{18} {-1}"
}
, Button = {
Command = $"uiskinmenu setizbranoe {weapon} {skinItem.A.Key} {page} {itemId}", Color = HexToRustFormat("#dead39"), Sprite = "assets/icons/favourite_servers.png",
}
, Text = {
Text = ""
}
}
, Layer + "-Search" + ".Player" + skinItem.B);
}
else {
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"{1} {-18}", OffsetMax = $"{18} {-1}"
}
, Button = {
Command = $"uiskinmenu setizbranoe {weapon} {skinItem.A.Key} {page} {itemId}", Color = "1 1 1 1", Sprite = "assets/icons/favourite_servers.png",
}
, Text = {
Text = ""
}
}
, Layer + "-Search" + ".Player" + skinItem.B);
}
if (!permission.UserHasPermission(player.UserIDString, Cfg.canusedefault)) continue;
if (_playerData.TryGetValue(player.userID, out weapons) && weapons._defaultSkins.ContainsKey(weapon) && weapons._defaultSkins[weapon].skinId == skinItem.A.Key) {
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = $"{-16} {-16}", OffsetMax = $"{-5} {-5}"
}
, Button = {
Command = $"uiskinmenu setdefault {weapon} {skinItem.A.Key} {page} {itemId}", Color = HexToRustFormat("#369f47"), Sprite = "assets/icons/power.png",
}
, Text = {
Text = ""
}
}
, Layer + "-Search" + ".Player" + skinItem.B);
}
else {
cont.Add(new CuiButton() {
RectTransform = {
AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = $"{-16} {-16}", OffsetMax = $"{-5} {-5}"
}
, Button = {
Command = $"uiskinmenu setdefault {weapon} {skinItem.A.Key} {page} {itemId}", Color = HexToRustFormat("#fb4f3b"), Sprite = "assets/icons/power.png",
}
, Text = {
Text = ""
}
}
, Layer + "-Search" + ".Player" + skinItem.B);
}
}
CuiHelper.AddUi(player, cont);
}
#endregion
#region Hooks
private List<Item> GetAllPlayerItems(BasePlayer player) {
List<Item> items = Pool.Get<List<Item>>();
if (player.inventory.containerMain != null) {
items.AddRange(player.inventory.containerMain.itemList);
}
if (player.inventory.containerBelt != null) {
items.AddRange(player.inventory.containerBelt.itemList);
}
if (player.inventory.containerWear != null) {
items.AddRange(player.inventory.containerWear.itemList);
}
return items;
}
private bool ChangeSkin(BasePlayer player) {
if (player == null || player.IsDead()) return false;
if (Cfg.Market.costChange <= 0) return true;
switch (Cfg.Market.WhoMarket) {
case "Scrap" : {
var scrap = GetAllPlayerItems(player).FirstOrDefault(p => p.info.shortname == "scrap" && p.skin == 0 && p.amount >= Cfg.Market.costChange);
if (scrap == null) {
SendReply(player, lang.GetMessage("NEEDMORESCRAP", this, player.UserIDString));
return false;
}
if (scrap.amount == Cfg.Market.costChange) {
scrap.RemoveFromContainer();
scrap.RemoveFromWorld();
}
else {
scrap.amount = (int)(scrap.amount - Cfg.Market.costChange);
scrap.MarkDirty();
}
return true;
}
case "ServerRewards" : {
var checkPoint = ServerRewards?.Call("CheckPoints", player.userID);
if (checkPoint == null) {
return false;
}
if ((int)checkPoint < Cfg.Market.costChange) {
SendReply(player, lang.GetMessage("NEEDMOREMONEY", this, player.UserIDString));
return false;
}
else {
ServerRewards?.Call("TakePoints", player.userID, Cfg.Market.costChange);
}
return true;
}
case "Economics" : {
double checkPoint = (double)Economics?.Call("Balance", player.userID)!;
if (checkPoint <= 0) {
SendReply(player, lang.GetMessage("NEEDMOREMONEY", this, player.UserIDString));
return false;
}
if (checkPoint < Cfg.Market.costChange) {
SendReply(player, lang.GetMessage("NEEDMOREMONEY", this, player.UserIDString));
return false;
}
else {
Puts(checkPoint.ToString());
Economics?.Call("Withdraw", player.userID, (double)Cfg.Market.costChange);
}
return true;
}
default : return false;
}
}
private bool OpenPay(BasePlayer player) {
if (player == null || player.IsDead()) return false;
if (Cfg.Market.costOpen <= 0) return true;
switch (Cfg.Market.WhoMarket) {
case "Scrap" : {
var scrap = GetAllPlayerItems(player).FirstOrDefault(p => p.info.shortname == "scrap" && p.skin == 0 && p.amount >= Cfg.Market.costOpen);
if (scrap == null) {
SendReply(player, lang.GetMessage("NEEDMORESCRAP", this, player.UserIDString));
return false;
}
if (scrap.amount == Cfg.Market.costOpen) {
scrap.RemoveFromContainer();
scrap.RemoveFromWorld();
}
else {
scrap.amount = (int)(scrap.amount - Cfg.Market.costOpen);
scrap.MarkDirty();
}
return true;
}
case "ServerRewards" : {
var checkPoint = ServerRewards?.Call("CheckPoints", player.userID);
if (checkPoint == null) {
SendReply(player, lang.GetMessage("NEEDMOREMONEY", this, player.UserIDString));
return false;
}
if ((int)checkPoint < Cfg.Market.costOpen) {
SendReply(player, lang.GetMessage("NEEDMOREMONEY", this, player.UserIDString));
return false;
}
else {
ServerRewards?.Call("TakePoints", player.userID, Cfg.Market.costOpen);
}
return true;
}
case "Economics" : {
double checkPoint = (double)Economics?.Call("Balance", player.userID)!;
if (checkPoint <= 0) {
SendReply(player, lang.GetMessage("NEEDMOREMONEY", this, player.UserIDString));
return false;
}
if (checkPoint < Cfg.Market.costOpen) {
SendReply(player, lang.GetMessage("NEEDMOREMONEY", this, player.UserIDString));
return false;
}
else {
Economics?.Call("Withdraw", player.userID, (double)Cfg.Market.costOpen);
}
return true;
}
default : return false;
}
}
private void OnItemAddedToContainer(ItemContainer container, Item item) {
if (container == null || item == null) return;
if(Cfg == null) return;
if(permission == null) return;
string shortname = item.info.shortname;
if (item.info.shortname.Contains("hazmatsuit")) shortname = "hazmatsuit";
if (!_loadData.ContainsKey(shortname)) return;
if (item.skin != 0 && !Cfg.SkinAuto) return;
if (item.skin != 0 && Cfg.blackList.Contains(item.skin)) return;
var player = item.GetOwnerPlayer();
if (player == null) return;
if (!permission.UserHasPermission(player.UserIDString, Cfg.canusedefault)) return;
if (container != player.inventory.containerMain && container != player.inventory.containerBelt && container != player.inventory.containerWear) return;
if (!_playerData.TryGetValue(player.userID, out var playerData)) return;
if (!playerData._defaultSkins.TryGetValue(shortname, out var skinData)) return;
if (item.skin == skinData.skinId) return;
if (shortname.Contains("hazmatsuit")) {
if (item.info.shortname == _hazmats[skinData.skinId]) return;
var pos = item.position;
var uids = item.uid;
var amount = item.amount;
item.DoRemove();
item = ItemManager.CreateByName($"{_hazmats[skinData.skinId]}");
item.uid = uids;
item.amount = amount;
item.MoveToContainer(container, pos);
item.MarkDirty();
player.SendNetworkUpdate();
return;
}
item.skin = skinData.skinId;
var held = item.GetHeldEntity();
if (held == null) return;
held.skinID = skinData.skinId;
held.SendNetworkUpdate();
}
private void OnItemCraftFinished(ItemCraftTask task, Item item, ItemCrafter craft) {
if (craft == null || craft.owner == null) return;
string shortname = item.info.shortname;
if (item.info.shortname.Contains("hazmatsuit")) shortname = "hazmatsuit";
if (task.skinID != 0 && !Cfg.SkinAuto) return;
if (task.skinID != 0 && Cfg.blackList.Contains(ulong.Parse(task.skinID.ToString()))) return;
if (!permission.UserHasPermission(craft.owner.UserIDString, Cfg.canusedefault)) return;
if (!this._playerData.TryGetValue(craft.owner.userID, out var playerData)) return;
if (!playerData._defaultSkins.TryGetValue(shortname, out var skinData)) return;
if (item.skin == skinData.skinId) return;
if (shortname.Contains("hazmatsuit")) {
if (item.info.shortname == _hazmats[skinData.skinId]) return;
var pos = item.position;
var uids = item.uid;
var amount = item.amount;
item.DoRemove();
item = ItemManager.CreateByName($"{_hazmats[skinData.skinId]}");
item.uid = uids;
item.amount = amount;
craft.owner.GiveItem(item);
item.MarkDirty();
return;
}
item.skin = skinData.skinId;
var held = item.GetHeldEntity();
if (held == null) return;
held.skinID = skinData.skinId;
held.SendNetworkUpdate();
}
private object OnItemAction(Item item, string action, BasePlayer player) {
if (_openSkins.ContainsKey(player.userID)) return false;
return null;
}
private string _apiKey = "LSKINS-fch42341sad85wkasxksqq";
private Dictionary<string, Dictionary<ulong, ItemData.SkinInfo>> _loadData = new Dictionary<string, Dictionary<ulong, ItemData.SkinInfo>>();
private void LoadDataSkins() {
foreach (var cfgWeaponSkin in Interface.Oxide.DataFileSystem.GetFiles("LSkins/Skins/")) {
var text = cfgWeaponSkin.Remove(0, cfgWeaponSkin.IndexOf("/Skins/") + 7);
// ... [Code preview truncated due to length. Full source in attached file] ...