C#:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Libraries;
using System.Text;
using System.Linq;
using System.IO;
using Network;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oxide.Core.Configuration;
using Oxide.Game.Rust.Cui;
using UnityEngine.Networking;
using UnityEngine;
namespace Oxide.Plugins
{
[Info(CPluginInfo.Title, CPluginInfo.Author, "1.21.41")]
[Description("Moscow.ovh rust store")]
public class RustStore : RustPlugin
{
private static class CPluginInfo
{
internal const string Name = "RustStore";
internal const string Author = "Bombardir, Moscow.OVH";
internal const string Title = "RustStore";
}
private static class CLog
{
public static void File(string text, string title = "info")
{
Instance.LogToFile(title, text, Instance);
}
public static void LogErrorWithFile(string text)
{
Error(text);
File(text, "errors");
}
public static void Debug(string format, params object[] args)
{
UnityEngine.Debug.Log($"[{CPluginInfo.Name}] {string.Format(format, args)}");
}
public static void Error(string format, params object[] args)
{
UnityEngine.Debug.LogError($"[{CPluginInfo.Name}] {string.Format(format, args)}");
}
public static void Warning(string format, params object[] args)
{
UnityEngine.Debug.LogWarning($"[{CPluginInfo.Name}] {string.Format(format, args)}");
}
public static void Debug(string format)
{
UnityEngine.Debug.Log($"[{CPluginInfo.Name}] {format}");
}
public static void Error(string format)
{
UnityEngine.Debug.LogError($"[{CPluginInfo.Name}] {format}");
}
public static void Warning(string format)
{
UnityEngine.Debug.LogWarning($"[{CPluginInfo.Name}] {format}");
}
}
public class CQueueImageCache
{
public delegate void OnDownloadCompleteHandler(string id);
private class QueueItem
{
internal readonly string ImageUrl;
internal event OnDownloadCompleteHandler OnDownloadComplete;
internal UnityWebRequest Www;
internal QueueItem(string imageUrl, OnDownloadCompleteHandler action)
{
ImageUrl = imageUrl;
if (action != null)
{
OnDownloadComplete += action;
}
}
internal void Invoke(string id)
{
OnDownloadComplete?.Invoke(id);
}
}
public int MaxActiveDownloads = 1;
private readonly HashSet<QueueItem> _activeDownloads = new HashSet<QueueItem>();
private readonly Queue<QueueItem> _queueList = new Queue<QueueItem>();
private readonly Dictionary<string, string> _cachedImages = new Dictionary<string, string>();
public void CacheImage(string imageUrl, OnDownloadCompleteHandler onDownloadComplete = null)
{
var itemCopy = _queueList.FirstOrDefault(item => item.ImageUrl == imageUrl) ??
_activeDownloads.FirstOrDefault(item => item.ImageUrl == imageUrl);
// Check if already queueing or downloading image
if (itemCopy != null)
{
if (onDownloadComplete != null)
{
itemCopy.OnDownloadComplete += onDownloadComplete;
}
return;
}
_queueList.Enqueue(new QueueItem(imageUrl, onDownloadComplete));
NextQueue();
}
public bool GetCachedImage(string url, out string id) => _cachedImages.TryGetValue(url, out id);
private void NextQueue()
{
// Check if we can start download of next image
if (_queueList.Count == 0 || _activeDownloads.Count >= MaxActiveDownloads)
{
return;
}
Rust.Global.Runner.StartCoroutine(WaitForRequest(_queueList.Dequeue()));
}
private static void PostImageError(string error, string url)
{
var data = StoreApi.ImagaErrorData;
var msg = $"Url: '{url}', Error: {error}";
data["message"] = msg;
CLog.Error("Не удалось скачать изображение: " + msg);
CStoreApi.PostRequest(data);
}
private IEnumerator WaitForRequest(QueueItem queueItem)
{
// Starting download
_activeDownloads.Add(queueItem);
var imageUrl = queueItem.ImageUrl;
var www = UnityWebRequestTexture.GetTexture(imageUrl);
queueItem.Www = www;
yield return www.Send();
_activeDownloads.Remove(queueItem);
// Check that image downloaded successfully
if (!string.IsNullOrEmpty(www.error))
{
PostImageError(www.error, imageUrl);
queueItem.Invoke(null);
NextQueue();
yield break;
}
// Check that data is image
var tex = DownloadHandlerTexture.GetContent(www);
if (tex == null || tex.height == 8 && tex.width == 8 && tex.name == string.Empty && tex.anisoLevel == 1)
{
PostImageError("Неправильный формат изображения", imageUrl);
queueItem.Invoke(null);
NextQueue();
yield break;
}
// Store image on server
var bytes = www.downloadHandler.data;
var id = FileStorage.server.Store(bytes, FileStorage.Type.png, 0);
if (FileStorage.server.Get(id, FileStorage.Type.png, 0) == null)
{
PostImageError("Ошибка при сохранении изображения в базу сервера", imageUrl);
queueItem.Invoke(null);
NextQueue();
yield break;
}
var idStr = id.ToString();
_cachedImages[imageUrl] = idStr;
// Calling callback
queueItem.Invoke(idStr);
NextQueue();
}
public void Dispose()
{
foreach (var obj in _activeDownloads)
{
obj.Www.Dispose();
}
_activeDownloads.Clear();
_cachedImages.Clear();
_queueList.Clear();
}
}
public enum EItemType
{
Blueprint = 5,
GameItem = 2,
Commands = 1
}
public class CStoreCache
{
private float _lastTimeGivingAll;
public bool IsGivingAll() => UnityEngine.Time.realtimeSinceStartup - _lastTimeGivingAll <= 30;
public void MarkGivingAll()
{
_lastTimeGivingAll = UnityEngine.Time.realtimeSinceStartup;
}
public void MarkGivedAll()
{
_lastTimeGivingAll = 0;
}
public readonly Dictionary<string, CItemJson> CachedCart = new Dictionary<string, CItemJson>();
}
public class CJsonResponse
{
private const string SuccessResp = "success";
public string rawResponse;
public string message = "empty";
public string status = "empty";
public JToken data;
public bool isSuccess() => status == SuccessResp;
public bool isFailure() => status != SuccessResp;
}
public class CRawStoreItem
{
public string pid;
public string queueID;
public string icon;
public virtual void MarkGived()
{
}
}
public class CStoreItem<T> : CRawStoreItem
{
public T data;
}
public class CItemJson : CStoreItem<JToken>
{
private float lastTimeGived;
public EItemType type;
public bool isGived() => lastTimeGived > 0;
public override void MarkGived() => lastTimeGived = UnityEngine.Time.realtimeSinceStartup;
public bool CanBeRemoved() => UnityEngine.Time.realtimeSinceStartup - lastTimeGived > 30;
}
public class CAutoItemJson : CStoreItem<string[]>
{
public string steamID;
}
public class UberItem
{
public readonly string Shortname;
public readonly ulong SkinId;
public UberItem(string shortname, ulong skinId)
{
Shortname = shortname;
SkinId = skinId;
}
}
public class CWwwRequests
{
private readonly List<UnityWebRequest> _activeRequests = new List<UnityWebRequest>();
public void Request(string url, Dictionary<string, string> data = null,
Action<string, string> onRequestComplete = null)
{
Rust.Global.Runner.StartCoroutine(WaitForRequest(url, data, onRequestComplete));
}
private IEnumerator WaitForRequest(string url, Dictionary<string, string> data = null,
Action<string, string> onRequestComplete = null)
{
var www = data == null ? UnityWebRequest.Get(url) : UnityWebRequest.Post(url, data);
_activeRequests.Add(www);
yield return www.Send();
onRequestComplete?.Invoke(www.downloadHandler.text, www.error);
_activeRequests.Remove(www);
}
public void Dispose()
{
foreach (var www in _activeRequests)
{
try
{
www.Dispose();
}
catch
{
// ignored
}
}
}
}
public class CStoreConfig
{
private readonly Dictionary<string, string> _messages = new Dictionary<string, string>()
{
["GIVE.MIND"] = "Ваш персонаж должен быть в сознании",
["GIVE.CUPBOARD.OTHER"] = "Вы не можете получить товар в зоне чужого шкафа",
["GIVE.CUPBOARD.OWNER"] = "Вы должны находится в зоне своего шкафа, чтобы получить товар",
["STORE.UNAVAILABLE"] = "Магазин временно недоступен",
["STORE.ERROR"] = "Что-то пошло не так...",
["STORE.OFFLINE"] = "Магазин выключен",
["STORE.RELOAD"] = "Магазин обновляется, повторите попытку позднее",
["ITEM.BLOCKED"] = "Предмет заблокирован",
["ITEM.ALREADYGIVED"] = "Предмет уже был выдан",
["ITEMS.EMPTY"] = "Товары отсутствуют",
["ITEMS.GIVE"] = "Ожидайте, ваши товары выдаются",
["ITEMS.GIVEN"] = "Все товары успешно выданы",
["IMAGE.LOADING"] = "Изображение\nзагружается",
["IMAGE.MISSED"] = "Изображения\nнет",
["SLOTS.RELEASE"] = "Освободите <b>{SLOTS}<\b>",
["SLOTS.DECLENSION1"] = "слот!",
["SLOTS.DECLENSION2"] = "слота!",
["SLOTS.DECLENSION3"] = "слотов!",
["STORE.NOSTEAM.SYNTAX"] = "Ошибка синтаксиса: /store login \"TOKEN\"",
["STORE.NOSTEAM.TOKEN.INVALID"] = "Вы ввели неправильный токен",
["STORE.NOSTEAM.TOKEN.EXPIRED"] = "Введенный токен устарел",
["STORE.NOSTEAM.REGISTERED"] = "Пользователь с таким steamid уже зарегистрирован",
["STORE.NOSTEAM.SUCCESS"] =
"Авторизация прошла успешно, теперь вы можете пользоваться корзиной в течение часа"
};
[JsonProperty("Включить SSL (шифрование трафика)")]
public bool EnableSsl = false;
[JsonProperty("номер магазина")] public string StoreId = "0";
[JsonProperty("номер сервера")] public string ServerId = "0";
[JsonProperty("ключ сервера")] public string ApiKey = "key";
[JsonProperty("выдача в один слот")] public bool StackItemsInOneSLot = false;
[JsonProperty("модификатор прочности раскаленных предметов")]
public float UberModifier = 1f;
[JsonProperty("иконка корзины")] public string CustomStoreIcon = "";
[JsonProperty("позиция иконки по вертикали (0.0 - 1.0)")]
public float IconPosY = 0.005f;
[JsonProperty("высота иконки (0.0 - 1.0)")]
public float IconHeight = 0.045f;
[JsonProperty("позиция иконки по горизонтали (0.0 - 1.0)")]
public float IconPosX = 0.005f;
[JsonProperty("ширина иконки (0.0 - 1.0)")]
public float IconWidth = 0.025f;
[JsonProperty("показывать иконку магазина")]
public bool ShowIcon = true;
[JsonProperty("включить англоязычную версию GUI")]
public bool UseEnglishImages = false;
[JsonProperty("выдача только в зоне своих шкафов")]
public bool OnlyCupboardGive = false;
[JsonProperty("запрет выдачи в зоне чужих шкафов")]
public bool BanOtherCupboardGive = true;
private DynamicConfigFile configSource;
public void InitializeMessages()
{
Lang.RegisterMessages(_messages, Instance);
}
public void Save()
{
configSource.WriteObject(this);
}
public static CStoreConfig Parse(DynamicConfigFile pluginConfig)
{
CStoreConfig output = null;
// Parsing config
try
{
output = pluginConfig.ReadObject<CStoreConfig>();
}
catch
{
// ignored
}
if (output == null)
{
pluginConfig.Save($"{pluginConfig.Filename}.jsonError");
output = new CStoreConfig();
CLog.Error("Файл конфигурации \"{0}\" содержит ошибку и был заменен на стандартный.\n" +
"Ошибочный файл конфигурации сохранен под названием \"{0}.jsonError\"", CPluginInfo.Name);
}
output.configSource = pluginConfig;
if (output.UberModifier > 5)
{
output.UberModifier = 5;
CLog.Error("Модификатор прочности раскаленных предметов не может быть больше 5.");
}
if (output.UberModifier <= 0)
{
output.UberModifier = 1;
CLog.Error("Модификатор прочности раскаленных предметов не может быть меньше 0.");
}
pluginConfig.WriteObject(output);
return output;
}
}
public class CGameItemJson
{
public string itemName;
public int quantity;
public bool block;
}
public class CStoreApi
{
public const string ItemBlueprint = "http://static.moscow.ovh/images/games/rust/icons/blueprintbase.png";
public const string ItemIconBaseUrl = "http://static.moscow.ovh/images/games/rust/icons/{0}.png";
public const string MainPanelUrl = "http://static.moscow.ovh/store/gui/rust/store_modal.png";
public const string ButtonsUrl = "http://static.moscow.ovh/store/gui/rust/store_buttons.png";
public const string ErrorUrl = "http://static.moscow.ovh/store/gui/rust/store_error.png";
public const string InfoUrl = "http://static.moscow.ovh/store/gui/rust/store_empty.png";
private const string ApiUrl = "https://store-api.moscow.ovh/index.php";
private const string ApiNoSslUrl = "http://store-api.moscow.ovh/index.php";
private static string _baseUrl = ApiUrl;
public readonly Dictionary<string, string> InitData = new Dictionary<string, string>()
{
["modules"] = "servers",
["action"] = "checkAuth"
};
public readonly Dictionary<string, string> GetItemsData = new Dictionary<string, string>()
{
["modules"] = "queue",
["action"] = "get"
};
public readonly Dictionary<string, string> GiveItemData = new Dictionary<string, string>()
{
["modules"] = "queue",
["action"] = "give"
};
public readonly Dictionary<string, string> ImagaErrorData = new Dictionary<string, string>()
{
["modules"] = "customError",
["action"] = "storeImg"
};
public readonly Dictionary<string, string> NoSteamLoginData = new Dictionary<string, string>()
{
["modules"] = "auth",
["action"] = "setData"
};
public readonly Dictionary<string, string> AutoCommandsData = new Dictionary<string, string>()
{
["modules"] = "queue",
["action"] = "autoActivate"
};
public readonly Dictionary<string, string> ChangeGlobalDiscount = new Dictionary<string, string>()
{
["modules"] = "config",
["action"] = "changeDiscount"
};
public readonly Dictionary<string, string> ChangeProductDiscount = new Dictionary<string, string>()
{
["modules"] = "config",
["action"] = "changeProductDiscount"
};
public readonly Dictionary<string, string> ChangeUserBalance = new Dictionary<string, string>()
{
["modules"] = "users",
["action"] = "changeUserBalance",
["type"] = "give"
};
public readonly Dictionary<string, string> GetUserData = new Dictionary<string, string>()
{
["modules"] = "users",
["action"] = "getData"
};
public readonly Dictionary<string, string> purchaseUserProduct = new Dictionary<string, string>()
{
["modules"] = "product",
["action"] = "purchase"
};
public CStoreApi(string storeId, string serverId, string serverKey)
{
var dictArray = new[]
{
InitData, GetItemsData, GiveItemData, ImagaErrorData, NoSteamLoginData, AutoCommandsData,
ChangeGlobalDiscount, ChangeProductDiscount, ChangeUserBalance, GetUserData, purchaseUserProduct
};
foreach (var dict in dictArray)
{
dict["storeID"] = storeId;
dict["serverID"] = serverId;
dict["serverKey"] = serverKey;
}
}
public static void DisableSsl()
{
_baseUrl = ApiNoSslUrl;
}
public static void EnableSsl()
{
_baseUrl = ApiUrl;
}
public static void PostRequest(Dictionary<string, string> data, Action<CJsonResponse> response = null)
{
WwwRequests.Request(_baseUrl, data, (res, error) =>
{
if (!string.IsNullOrEmpty(error) || string.IsNullOrEmpty(res))
{
CLog.LogErrorWithFile($"Ошибка запроса: {error}, Ответ: {res}");
response?.Invoke(
new CJsonResponse {rawResponse = res, status = "RequestError", message = error});
return;
}
CJsonResponse converted = null;
try
{
var settings = new JsonSerializerSettings
{
StringEscapeHandling = StringEscapeHandling.EscapeHtml
};
converted = JsonConvert.DeserializeObject<CJsonResponse>(res, settings);
}
catch
{
// ignored
}
if (converted == null)
{
CLog.LogErrorWithFile($"Ошибка обработки JSON запроса: {res}");
response?.Invoke(new CJsonResponse {rawResponse = res, status = "JsonError", message = res});
return;
}
converted.rawResponse = res;
if (converted.isFailure())
{
if (converted.message == "invalidStoreAuth" || converted.message == "invalidServerAuth")
{
CLog.LogErrorWithFile(
"Ошибка авторизации, убедитесь что вы настроили конфигурацию магазина в файле \"oxide/config/RustStore.json\".\n" +
"Данные для авторизации можно найти в магазине во вкладке серверы/установка.");
return;
}
CLog.LogErrorWithFile(converted.message);
response?.Invoke(converted);
return;
}
response?.Invoke(converted);
});
}
}
public class CGuiComponents
{
public const string MainPanelName = CPluginInfo.Name + "MainPanel";
public const string ModalPanelName = CPluginInfo.Name + "ModalPanel";
public const string ShopButtonName = CPluginInfo.Name + "ShopButton";
public const string ItemPatternName = CPluginInfo.Name + "ItemPattern";
public string MainPattern = @"[
{
""parent"": ""Overlay"",
""name"": """ + MainPanelName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""close"": """ + MainPanelName + @""",
""command"": ""closestore"",
""color"": ""0 0 0 0"",
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
},
{
""type"":""NeedsCursor""
}
]
},
{
""parent"": """ + MainPanelName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Image"",
""color"": ""0 0 0 0.3"",
""fadeIn"": ""0.4""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},
{
""parent"": """ + MainPanelName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""color"": ""0 0 0 0""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},
{
""parent"": """ + MainPanelName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""close"": """ + MainPanelName + @""",
""color"": ""1 1 1 0""
},
{
""type"":""RectTransform"",
""anchormin"": ""0.87 0.847"",
""anchormax"": ""0.892 0.883""
}
]
}]";
public string InfoPattern = @"[
{
""name"": """ + ModalPanelName + @""",
""parent"": """ + MainPanelName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.RawImage"",
""sprite"": ""assets/content/textures/generic/fulltransparent.tga"",
""png"": ""[PNG]"",
""fadeIn"": ""0.4""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},
{
""name"": """ + ModalPanelName + @""",
""parent"": """ + MainPanelName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Text"",
""text"":""{0}"",
""fontSize"":48,
""align"": ""MiddleCenter"",
""fadeIn"": ""0.4""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},
{
""parent"": """ + MainPanelName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""close"": """ + MainPanelName + @""",
""color"": ""1 1 1 0""
},
{
""type"":""RectTransform"",
""anchormin"": ""0.87 0.847"",
""anchormax"": ""0.892 0.883""
}
]
}
]";
public string ButtonPattern = @"[
{
""parent"": ""Overlay"",
""name"": """ + ShopButtonName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""sprite"": ""assets/icons/loot.png"",
""close"": """ + MainPanelName + @""",
""color"": ""1 1 1 0.2"",
""command"": ""store.opencart 0""
},
{
""type"":""RectTransform"",
""anchormin"": ""{X_POS} {Y_POS}"",
""anchormax"": ""{X_POS_POST} {Y_POS_POST}""
}
]
}
]";
public string CustomButtonPattern = @"[
{
""parent"": ""Overlay"",
""name"": """ + ShopButtonName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""close"": """ + MainPanelName + @""",
""color"": ""0 0 0 0"",
""command"": ""store.opencart 0""
},
{
""type"":""RectTransform"",
""anchormin"": ""{X_POS} {Y_POS}"",
""anchormax"": ""{X_POS_POST} {Y_POS_POST}""
}
]
},
{
""parent"": """ + ShopButtonName + @""",
""name"": ""ShopButtonImage"",
""components"":
[
{
""type"":""UnityEngine.UI.RawImage"",
""sprite"": ""assets/content/textures/generic/fulltransparent.tga"",
""png"": ""{PNG}""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
}
]";
public string ErrorPattern = @"[
{
""name"": """ + ModalPanelName + @""",
""parent"": """ + MainPanelName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.RawImage"",
""sprite"": ""assets/content/textures/generic/fulltransparent.tga"",
""png"": ""[PNG]"",
""fadeIn"": ""0.4""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},
{
""name"": """ + ModalPanelName + @""",
""parent"": """ + MainPanelName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Text"",
""text"":""{0}"",
""fontSize"":48,
""align"": ""MiddleCenter""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},
{
""parent"": """ + MainPanelName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""close"": """ + MainPanelName + @""",
""color"": ""1 1 1 0""
},
{
""type"":""RectTransform"",
""anchormin"": ""0.87 0.847"",
""anchormax"": ""0.892 0.883""
}
]
}
]";
public string ItemPatternParent = @"
{
""parent"": """ + MainPanelName + @""",
""name"": """ + ItemPatternName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Image"",
""color"": ""0 0 0 0""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},
";
public string ItemPattern = @"
{
""parent"": """ + ItemPatternName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Text"",
""text"":""{4}"",
""fontSize"":16,
""align"": ""LowerRight"",
""color"":""1 1 1 0.2"",
""fadeIN"": ""0.4""
},
{
""type"":""RectTransform"",
""anchormin"": ""{5}"",
""anchormax"": ""{6}""
}
]
},
{
""name"":""{NAME}"",
""parent"": """ + ItemPatternName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""command"":""store.giveitem {3}"",
""close"":""" + ItemPatternName + @""",
""color"": ""0 0 0 0"",
""fadeIN"": ""0.4""
},
{
""type"":""RectTransform"",
""anchormin"": ""{0}"",
""anchormax"": ""{1}""
}
]
},";
public string ItemPatternText = @"
{
""name"":""{NAME}.icon"",
""parent"": ""{NAME}"",
""components"":
[
{
""type"":""UnityEngine.UI.Text"",
""text"":""{TEXT}"",
""fontSize"":16,
""align"": ""MiddleCenter"",
""color"":""1 1 1 0.2"",
""fadeIN"": ""0.4""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},";
public string ItemPatternBlueprintImage = @"
{
""parent"": ""{NAME}"",
""components"":
[
{
""type"":""UnityEngine.UI.RawImage"",
""sprite"": ""assets/content/textures/generic/fulltransparent.tga"",
""png"": ""[PNG]"",
""fadeIn"": ""0.4""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},";
public string ItemPatternImage = @"
{
""name"":""{NAME}.icon"",
""parent"": ""{NAME}"",
""components"":
[
{
""type"":""UnityEngine.UI.RawImage"",
""sprite"": ""assets/content/textures/generic/fulltransparent.tga"",
""png"": ""{PNG}"",
""fadeIn"": ""0.4""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},";
public string NextPrevPattern = @"
{
""parent"": """ + ItemPatternName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.RawImage"",
""sprite"": ""assets/content/textures/generic/fulltransparent.tga"",
""png"": ""[PNG]"",
""fadeIn"": ""0.4""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},
{
""parent"": """ + ItemPatternName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""color"": ""0 0 0 0""
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
}
]
},
{
""parent"": """ + ItemPatternName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""command"":""store.giveitemall"",
""color"": ""1 1 1 0""
},
{
""type"":""RectTransform"",
""anchormin"": ""0.87 0.847"",
""anchormax"": ""0.892 0.883""
}
]
},
{
""parent"": """ + ItemPatternName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""close"":""ItemPattern"",
""color"": ""1 1 1 0"",
},
{
""type"":""RectTransform"",
""anchormin"": ""0.5125 0.1665"",
""anchormax"": ""0.8625 0.256""
}
]
},
{
""parent"": """ + ItemPatternName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""close"":""ItemPattern"",
""command"":""store.refreshcart {0}"",
""color"": ""1 1 1 0"",
},
{
""type"":""RectTransform"",
""anchormin"": ""0.5125 0.30"",
""anchormax"": ""0.675 0.389""
}
]
},
{
""parent"": """ + ItemPatternName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
"" "":""" + ItemPatternName + @""",
""command"":""store.refreshcart {1}"",
""color"": ""1 1 1 0"",
},
{
""type"":""RectTransform"",
""anchormin"": ""0.7 0.30"",
""anchormax"": ""0.8625 0.389""
}
]
},
{
""parent"": """ + MainPanelName + @""",
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""close"": """ + MainPanelName + @""",
""command"": ""closestore"",
""color"": ""1 1 1 0""
},
{
""type"":""RectTransform"",
""anchormin"": ""0.87 0.847"",
""anchormax"": ""0.892 0.883""
}
]
},";
}
public static class CGui
{
public static void CreateGlobal(string json)
=> CommunityEntity.ServerInstance.ClientRPCEx(new SendInfo(Net.sv.connections), null, "AddUI", json);
public static void DestroyGlobal(string name)
=> CommunityEntity.ServerInstance.ClientRPCEx(new SendInfo(Net.sv.connections), null, "DestroyUI",
name);
public static void Create(Connection con, string text)
=>
CommunityEntity.ServerInstance.ClientRPCEx(new SendInfo {connection = con}, null, "AddUI",
text);
public static void Destroy(Connection con, string name)
=>
CommunityEntity.ServerInstance.ClientRPCEx(new SendInfo {connection = con}, null, "DestroyUI",
name);
}
public static void AddLog(BasePlayer player, string text)
{
if (Logs[player.userID].Count >= 4)
{
Logs[player.userID].RemoveAt(0);
}
Logs[player.userID].Add(text);
}
public static class CConsoleComands
{
public static bool StoreOpen(ConsoleSystem.Arg arg)
{
var player = (BasePlayer) arg.Connection?.player;
if (player == null)
{
return false;
}
OpenStore(player);
return true;
}
public static bool StoreRefresh(ConsoleSystem.Arg arg)
{
var player = (BasePlayer) arg.Connection?.player;
if (player == null)
{
return false;
}
ShowCart(player, arg.GetInt(0));
return true;
}
public static bool StoreGiveall(ConsoleSystem.Arg arg)
{
var player = (BasePlayer) arg.Connection?.player;
if (player == null)
{
return false;
}
//SendInfoMessage(player, GetLangMessage(player.UserIDString, "ITEMS.GIVE"));
GiveAllStoreItems(player);
return true;
}
public static bool StoreGive(ConsoleSystem.Arg arg)
{
var player = (BasePlayer) arg.Connection?.player;
if (player == null)
{
return false;
}
GiveStoreItem(player, arg.GetString(0),
() =>
{
CuiHelper.DestroyUi(player, CGuiComponents.MainPanelName + arg.GetInt(1) + "D");
CuiHelper.AddUi(player, new CuiElementContainer
{
{
new CuiButton
{
RectTransform = {AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"},
Button = {Color = "0.4627 0.49 0.27 0.8"},
Text = {Text = "УСПЕШНО\n" +
"ПОЛУЧЕНО", Align = TextAnchor.MiddleCenter, FontSize = 22, Color = "0.929 0.882 0.847 0.4"}
},
CGuiComponents.MainPanelName + arg.GetInt(1), CGuiComponents.MainPanelName + arg.GetInt(1) + "D"
}
});
DrawLogs(player);
},
(error) =>
{
string er = "ОШИБКА\nПОЛУЧЕНИЯ";
if (error.Contains("освободите"))
{
er = "НЕ\nХВАТАЕТ\n" +
"МЕСТА";
AddLog(player, $"<size=15>Вам не хватает места ({error.Replace("sadasd", "")})</size>");
}
if (error.Contains("шкаф"))
{
er = "ЧУЖОЙ\nШКАФ";
AddLog(player, "Вы находитесь в зоне чужого шкафа");
}
CuiHelper.DestroyUi(player, CGuiComponents.MainPanelName + arg.GetInt(1) + "D");
CuiHelper.AddUi(player, new CuiElementContainer
{
{
new CuiButton
{
RectTransform = {AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"},
Button = {Color = "0.549 0.270 0.215 0.8"},
Text = {Text = er, Align = TextAnchor.MiddleCenter, FontSize = 22, Color = "0.929 0.882 0.847 0.4"}
},
CGuiComponents.MainPanelName + arg.GetInt(1), CGuiComponents.MainPanelName + arg.GetInt(1) + "D"
}
});
DrawLogs(player);
});
return true;
}
public static bool StoreConnect(ConsoleSystem.Arg arg)
{
if (!arg.IsAdmin)
{
return false;
}
var storeNumber = arg.GetString(0);
if (string.IsNullOrEmpty(storeNumber))
{
arg.ReplyWith("Не указан номер магазина");
return true;
}
var serverNumver = arg.GetString(1);
if (string.IsNullOrEmpty(serverNumver))
{
arg.ReplyWith("Не указан номер сервера");
return true;
}
var serverKey = arg.GetString(2);
if (string.IsNullOrEmpty(s
// ... [Code preview truncated due to length. Full source in attached file] ...