C#:
// Reference: Facepunch.Sqlite
using CompanionServer;
using ConVar;
//using Facepunch.Sqlite;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Database;
using Oxide.Core.Plugins;
using Oxide.Core.SQLite.Libraries;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.Networking;
///Скачано с дискорд сервера Rust Edit [PRO+]
///discord.gg/9vyTXsJyKR
namespace Oxide.Plugins {
[Info("Game Mode Manager", "discord.gg/9vyTXsJyKR", "1.1.3")]
[Description("The core and backbone plugin of both Scrim and Recoil Training Ground minigames.")]
public class GameModeManager : RustPlugin {
[PluginReference]
Plugin ZoneManager, InventoryLoadout;
private static GameModeManager _instance;
public const string PermissionAdmin = "gamemodemanager.admin";
public const string PermissionVanishBypass = "gamemodemanager.vanish.bypass";
public const string PermissionIgnore = "gamemodemanager.ignore";
private readonly string _databasePath = $"{Interface.Oxide.DataDirectory}//{MainFolderName}//{nameof(GameModeManager).ToLower()}.db";
private readonly string _globalStatisticsTableName = "Global_Statistics";
public Configuration PluginConfig;
private DynamicConfigFile _dataManager;
private PluginData _pluginData;
public const string MainFolderName = "GameModes";
public LobbyData LobbyToEdit;
public HashSet<ulong> TeleportingPlayers = new HashSet<ulong>();
public List<BasePlayer> TransportedPlayers = new List<BasePlayer>();
public ImageManagerBehaviour ImageManager;
private const float TextRefreshRate = 2f;
private readonly Regex _steamAvatarRegex = new Regex(@"(?<=<avatarMedium>[\w\W]+)https://.+\.jpg(?=[\w\W]+<\/avatarMedium>)", RegexOptions.Compiled);
private Core.Database.Connection _statisticsDatabaseConnection;
// = new Database();
SQLite Sqlite = Interface.GetMod().GetLibrary<SQLite>();
private readonly Dictionary<ulong, Timer> _freezeTimers = new Dictionary<ulong, Timer>();
public Dictionary<ulong, string> PlayersAvatarUrls = new Dictionary<ulong, string>();
public Dictionary<ulong, string> PlayerSearch = new Dictionary<ulong, string>();
public Dictionary<ulong, List<SelectablePlayer>> PlayerSearchResults = new Dictionary<ulong, List<SelectablePlayer>>();
public Dictionary<ulong, PlayerPageIndex> PlayerPageIndexes = new Dictionary<ulong, PlayerPageIndex>();
public Dictionary<int, Lobby> Lobbies {
get;
set;
}
= new Dictionary<int, Lobby>();
#region Classes
#region Config
public class Configuration {
[JsonProperty(PropertyName = "Use Better Chat")]
public bool UseBetterChat {
get;
set;
}
[JsonProperty(PropertyName = "Chat command to leave the arena")]
public string ArenaLeaveCommand {
get;
set;
}
= "Leave";
[JsonProperty(PropertyName = "Chat command to show lobby pause menu")]
public string ShowLobbyPauseMenuCommand {
get;
set;
}
= "Menu";
[JsonProperty(PropertyName = "Up Arrow Icon")]
public string UpArrow {
get;
set;
}
= "https://i.ibb.co/f1QCfNG/up.png";
[JsonProperty(PropertyName = "Down Arrow Icon")]
public string DownArrow {
get;
set;
}
= "https://i.ibb.co/ZzkvpWX/down.png";
[JsonProperty(PropertyName = "Left Arrow Icon")]
public string LeftArrow {
get;
set;
}
= "https://i.ibb.co/Tr09rGF/left.png";
[JsonProperty(PropertyName = "Right Arrow Icon")]
public string RightArrow {
get;
set;
}
= "https://i.ibb.co/CvjHK1Z/right.png";
[JsonProperty(PropertyName = "Search Button Icon")]
public string SearchButton {
get;
set;
}
= "https://i.ibb.co/TL0J5s7/arrow-forward.png";
[JsonProperty(PropertyName = "Check Mark Icon")]
public string Checked {
get;
set;
}
= "https://i.ibb.co/CPCK3cs/check.png";
[JsonProperty(PropertyName = "Clear Input Icon")]
public string Clear {
get;
set;
}
= "https://i.ibb.co/Qm3zRY6/clear.png";
[JsonProperty(PropertyName = "Close Button Icon")]
public string Close {
get;
set;
}
= "https://i.ibb.co/fQnDjW6/close.png";
[JsonProperty(PropertyName = "Search Icon")]
public string Search {
get;
set;
}
= "https://i.ibb.co/LtzyY5F/search.png";
[JsonProperty(PropertyName = "Info Icon")]
public string Info {
get;
set;
}
= "https://i.ibb.co/1dFT9RL/info.png";
[JsonProperty(PropertyName = "VIP Locked Icon")]
public string VipLocked {
get;
set;
}
= "https://i.ibb.co/fr0YhNY/vip-locked.png";
[JsonProperty(PropertyName = "Locked Icon")]
public string Locked {
get;
set;
}
= "https://i.ibb.co/pWh2Gh8/locked.png";
[JsonProperty(PropertyName = "UnLocked Icon")]
public string UnLocked {
get;
set;
}
= "https://i.ibb.co/QCMYJvq/unlocked.png";
[JsonProperty(PropertyName = "Match Leader Icon")]
public string MatchLeader {
get;
set;
}
= "https://i.ibb.co/jHQmGT8/crown.png";
}
#endregion Config
#region Data
public class PluginData {
[JsonProperty(PropertyName = "Lobbies")]
public HashSet<LobbyData> Lobbies {
get;
set;
}
= new HashSet<LobbyData>();
}
public class LobbyData {
[JsonProperty(PropertyName = "Lobby - Name", Order = 1)]
public string Name {
get;
set;
}
[JsonProperty(PropertyName = "Lobby - Zone ID", Order = 2)]
public string ZoneId {
get;
set;
}
[JsonProperty(PropertyName = "Lobby - ID", Order = 3)]
public int Id {
get;
set;
}
[JsonProperty(PropertyName = "Lobby - Main - Enabled", Order = 4)]
public bool IsMain {
get;
set;
}
[JsonProperty(PropertyName = "Lobby - Loadout", Order = 5)]
public string LoadoutName {
get;
set;
}
[JsonProperty(PropertyName = "Whitelist Mode - Enabled", Order = 6)]
public bool RestrictAccess {
get;
set;
}
[JsonProperty(PropertyName = "Whitelisted Players", Order = 7)]
public HashSet<ulong> AllowedPlayers {
get;
set;
}
= new HashSet<ulong>();
[JsonProperty(PropertyName = "Banned Players", Order = 8)]
public HashSet<ulong> BannedPlayers {
get;
set;
}
= new HashSet<ulong>();
[JsonProperty(PropertyName = "Spawn Points", Order = 9)]
public HashSet<LobbySpawnData> SpawnLocations {
get;
set;
}
= new HashSet<LobbySpawnData>();
public override bool Equals(object obj) {
var match = obj as LobbyData;
if (match == null) {
return false;
}
return match.Id == Id;
}
public override int GetHashCode() {
return Id.GetHashCode();
}
}
public class ArenaData {
[JsonProperty(PropertyName = "Arena - Name", Order = 1)]
public string Name {
get;
set;
}
[JsonProperty(PropertyName = "Arena - ID", Order = 2)]
public int Id {
get;
set;
}
[JsonProperty(PropertyName = "Arena - Enabled", Order = 3)]
public bool IsEnabled {
get;
set;
}
[JsonProperty(PropertyName = "Arena - Zone ID", Order = 4)]
public string ZoneId {
get;
set;
}
[JsonProperty(PropertyName = "Arena - Lobby ID", Order = 5)]
public int LobbyId {
get;
set;
}
[JsonProperty(PropertyName = "Match - Type", Order = 6)]
public MatchType MatchType {
get;
set;
}
[JsonProperty(PropertyName = "Match - Capacity", Order = 7)]
public int Capacity {
get;
set;
}
[JsonProperty(PropertyName = "Entrance Point - Enabled", Order = 12)]
public bool IsEntranceTriggerActive {
get;
set;
}
[JsonProperty(PropertyName = "Entrance Point - Radius", Order = 13)]
public float EntranceTriggerRadius {
get;
set;
}
[JsonProperty(PropertyName = "Entrance Point - Physically Enter - Enabled", Order = 14)]
public bool AccessThroughLobbyOnly {
get;
set;
}
[JsonProperty(PropertyName = "Entrance Point - Text Visibility Range", Order = 15)]
public float EntrancePointTextVisibilityRange {
get;
set;
}
= 100f;
[JsonProperty(PropertyName = "Entrance Point - Location", Order = 18)]
public Vector3 EntranceLocation {
get;
set;
}
[JsonProperty(PropertyName = "Whitelist Mode - Enabled", Order = 27)]
public bool RestrictAccess {
get;
set;
}
[JsonProperty(PropertyName = "Whitelisted Players", Order = 28)]
public HashSet<ulong> AllowedPlayers {
get;
set;
}
= new HashSet<ulong>();
[JsonProperty(PropertyName = "Banned Players", Order = 29)]
public HashSet<ulong> BannedPlayers {
get;
set;
}
= new HashSet<ulong>();
}
public abstract class BaseSpawnData {
[JsonProperty(PropertyName = "Spawn - Enabled", Order = 3)]
public bool IsEnabled {
get;
set;
}
[JsonProperty(PropertyName = "Spawn - Name", Order = 4)]
public string Name {
get;
set;
}
[JsonProperty(PropertyName = "Spawn - Location", Order = 5)]
public Vector3 SpawnPoint {
get;
set;
}
[JsonProperty(PropertyName = "Spawn - Radius", Order = 6)]
public float Radius {
get;
set;
}
[JsonProperty(PropertyName = "Spawn - Chance", Order = 7)]
public int SpawnChance {
get;
set;
}
}
public class LobbySpawnData : BaseSpawnData {
public override bool Equals(object obj) {
var match = obj as LobbySpawnData;
if (match == null) {
return false;
}
return match.Name.Equals(Name, StringComparison.OrdinalIgnoreCase);
}
public override int GetHashCode() {
return Name.ToLower().GetHashCode();
}
}
#endregion Data
#region Behaviours
public class ArenaBehaviour : MonoBehaviour {
private bool _isInitialized;
public Arena Arena {
get;
set;
}
float _updateTime = 0.5f;
public static ArenaBehaviour CreateEntrance(string name, Vector3 entranceLocation, float triggerRadius, bool isTriggerActive) {
var sphereObject = new GameObject(name);
sphereObject.transform.position = entranceLocation;
sphereObject.gameObject.layer = (int)Rust.Layer.Reserved2;
if (isTriggerActive) {
var sphereCollider = sphereObject.AddComponent<SphereCollider>();
sphereCollider.radius = triggerRadius;
sphereCollider.isTrigger = true;
}
return sphereObject.AddComponent<ArenaBehaviour>();
}
public void Initialize(Arena arena) {
Arena = arena;
if (Arena == null) return;
InvokeHandler.InvokeRepeating(this, UpdateText, UnityEngine.Random.Range(0.1f, 2f), TextRefreshRate);
if (!Arena.Data.IsEnabled) return;
_isInitialized = true;
}
public void Update() {
if (!_isInitialized) {
return;
}
_updateTime -= UnityEngine.Time.deltaTime;
if (_updateTime <= 0) {
_updateTime = 0.5f;
Arena?.TimerTick();
}
}
public void DoDestroy() {
Destroy(this);
}
private void OnDestroy() {
InvokeHandler.CancelInvoke(this, UpdateText);
}
private void OnTriggerEnter(Collider collider) {
if (!_isInitialized || !Arena.Data.IsEntranceTriggerActive || collider == null || collider.gameObject == null) return;
var player = collider.gameObject.ToBaseEntity()?.ToPlayer();
if (player == null) return;
if (player.isMounted) return;
if (_instance.TeleportingPlayers.Contains(player.userID)) return;
Interface.CallHook(nameof(IAdvancedLobby.HandleJoinArena), player, Arena.Data.Id);
}
private void OnTriggerExit(Collider collider) {
if (!_isInitialized || !Arena.Data.IsEntranceTriggerActive || collider == null || collider.gameObject == null) return;
var player = collider.gameObject.ToBaseEntity()?.ToPlayer();
if (player == null) return;
if (player.isMounted) return;
Ui.ClearAllMenus(player);
}
private void UpdateText() {
var position = Vector3.up * 2 + Arena.Data.EntranceLocation;
var formattedText = Arena.GetEntranceText();
_instance.UpdateInGameText(formattedText, position, Arena.Data.EntrancePointTextVisibilityRange);
}
}
public class ImageManagerBehaviour : MonoBehaviour {
private readonly Dictionary<string, string> _images = new Dictionary<string, string>();
public string GetImage(string key) {
var imageId = string.Empty;
if (_images.TryGetValue(key, out imageId)) {
return imageId;
}
return null;
}
public IEnumerator DownloadImage(string key, string url) {
var www = UnityWebRequest.Get(url);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError) {
_instance.PrintError($"Image failed to download! Error: {www.error} - Image URL: {url}");
www.Dispose();
yield break;
}
var texture = new Texture2D(2, 2);
texture.LoadImage(www.downloadHandler.data);
if (texture != null) {
byte[] bytes = texture.EncodeToPNG();
DestroyImmediate(texture);
StoreByteArray(key, bytes);
}
www.Dispose();
}
private void StoreByteArray(string key, byte[] bytes) {
if (bytes != null) {
_images[key] = FileStorage.server.Store(bytes, FileStorage.Type.png, CommunityEntity.ServerInstance.net.ID).ToString();
}
}
}
#endregion Behaviours
public static class Ui {
public static float GetX(float amount, int width = 1920) => amount / width;
public static float GetY(float amount, int height = 1080) => amount / height;
public static float GetMinX(float left, int width = 1920) => left / width;
public static float GetMaxX(float right, int width = 1920) => 1 - right / width;
public static float GetMinY(float bottom, int height = 1080) => bottom / height;
public static float GetMaxY(float top, int height = 1080) => 1 - top / height;
public static string GetMin(float left, float bottom, int width = 1920, int height = 1080) => $"{GetMinX(left, width)} {GetMinY(bottom, height)}";
public static string GetMax(float right, float top, int width = 1920, int height = 1080) => $"{GetMaxX(right, width)} {GetMaxY(top, height)}";
public static string GetVerticalMin(float left, float bottom, int order, float amount, int width = 1920, int height = 1080) => $"{GetMinX(left, width)} {GetMinY(bottom, height) - GetY(amount, height) * order}";
public static string GetVerticalMax(float right, float top, int order, float amount, int width = 1920, int height = 1080) => $"{GetMaxX(right, width)} {GetMaxY(top, height) - GetY(amount, height) * order}";
public static string GetHorizontalMin(float left, float bottom, int order, float amount, int width = 1920, int height = 1080) => $"{GetMinX(left, width) + GetX(amount, width) * order} {GetMinY(bottom, height)}";
public static string GetHorizontalMax(float right, float top, int order, float amount, int width = 1920, int height = 1080) => $"{GetMaxX(right, width) + GetX(amount, width) * order} {GetMaxY(top, height)}";
public static string GetGridMin(float left, float bottom, int order, float xAmount, float yAmount, int columnCount, int rowCount, int width = 1920, int height = 1080) {
if (columnCount > 0) {
return $"{GetMinX(left, width) + GetX(xAmount, width) * (order % columnCount)} {GetMinY(bottom, height) - GetY(yAmount, height) * (order / columnCount)}";
}
if (rowCount > 0) {
return $"{GetMinX(left, width) + GetX(xAmount, width) * (order % rowCount)} {GetMinY(bottom, height) - GetY(yAmount, height) * (order / rowCount)}";
}
return $"{GetMinX(left, width) + GetX(xAmount, width) * order} {GetMinY(bottom, height) - GetY(yAmount, height) * order}";
}
public static string GetGridMax(float right, float top, int order, float xAmount, float yAmount, int columnCount, int rowCount, int width = 1920, int height = 1080) {
if (columnCount > 0) {
return $"{GetMaxX(right, width) + GetX(xAmount, width) * (order % columnCount)} {GetMaxY(top, height) - GetY(yAmount, height) * (order / columnCount)}";
}
if (rowCount > 0) {
return $"{GetMaxX(right, width) + GetX(xAmount, width) * (order % rowCount)} {GetMaxY(top, height) - GetY(yAmount, height) * (order / rowCount)}";
}
return $"{GetMaxX(right, width) + GetX(xAmount, width) * order} {GetMaxY(top, height) - GetY(yAmount, height) * order}";
}
public static CuiElementContainer Container(Panels panel, string color, string min, string max, bool useBlur = true, bool useCursor = true, Panels parent = Panels.Overlay) {
CuiElementContainer container = new CuiElementContainer() {
{
new CuiPanel {
Image = {
Color = color, Material = useBlur ? "assets/content/ui/uibackgroundblur.mat" : "Assets/Icons/IconMaterial.mat"
}
, RectTransform = {
AnchorMin = min, AnchorMax = max
}
, CursorEnabled = useCursor
}
, new CuiElement().Parent = parent == Panels.HudMenu ? "Hud.Menu" : parent.ToString(), panel.ToString()
}
}
;
return container;
}
public static void Panel(ref CuiElementContainer container, Panels panel, string color, string min, string max, bool cursor = false) {
container.Add(new CuiPanel {
Image = {
Color = color
}
, RectTransform = {
AnchorMin = min, AnchorMax = max
}
, CursorEnabled = cursor
}
, panel.ToString());
}
public static void Panel(ref CuiElementContainer container, Panels panel, string color, string text, string min, string max, int size, string textMin = null, string textMax = null, string font = "RobotoCondensed-Regular.ttf", string textColor = "1.0 1.0 1.0 1.0", TextAnchor align = TextAnchor.MiddleCenter, bool cursor = false) {
var name = CuiHelper.GetGuid();
var cuiElement = new CuiElement {
Name = name, Parent = panel.ToString(), FadeOut = 0
}
;
cuiElement.Components.Add(new CuiImageComponent {
Color = color
}
);
cuiElement.Components.Add(new CuiRectTransformComponent {
AnchorMin = min, AnchorMax = max
}
);
if (cursor) cuiElement.Components.Add(new CuiNeedsCursorComponent());
container.Add(cuiElement);
var textName = CuiHelper.GetGuid();
container.Add(new CuiElement {
Name = textName, Parent = panel.ToString(), FadeOut = 0, Components = {
new CuiTextComponent {
Color = textColor, FontSize = (int)(size * 0.7f), Align = align, Text = text, Font = font
}
, new CuiRectTransformComponent {
AnchorMin = textMin ?? min, AnchorMax = textMax ?? max
}
}
}
);
}
public static void Label(ref CuiElementContainer container, Panels panel, string text, int size, string min, string max, bool isBold = true, string color = "1.0 1.0 1.0 1.0", TextAnchor align = TextAnchor.MiddleCenter, float fadeIn = 0) {
container.Add(new CuiLabel {
Text = {
FadeIn = fadeIn, Color = color, FontSize = (int)(size * 0.7f), Align = align, Text = text, Font = isBold ? "RobotoCondensed-Bold.ttf" : "RobotoCondensed-Regular.ttf"
}
, RectTransform = {
AnchorMin = min, AnchorMax = max
}
}
, panel.ToString());
}
public static void OutlineLabel(ref CuiElementContainer container, Panels panel, string text, int size, string min, string max, string font = Fonts.RobotoCondensedRegular, string color = "1.0 1.0 1.0 1.0", TextAnchor align = TextAnchor.MiddleCenter, float fadeIn = 0, string outlineDistance = "1 1", string outlineColor = "0 0 0 1.0") {
CuiElement textElement = new CuiElement {
Name = CuiHelper.GetGuid(), Parent = panel.ToString(), FadeOut = fadeIn, Components = {
new CuiTextComponent {
Text = text, FontSize = (int)(size * 0.7f), Align = align, FadeIn = fadeIn, Font = font, Color = color
}
, new CuiOutlineComponent {
Distance = outlineDistance, Color = outlineColor
}
, new CuiRectTransformComponent {
AnchorMin = min, AnchorMax = max
}
}
}
;
container.Add(textElement);
}
public static void Label(ref CuiElementContainer container, Panels panel, string text, int size, string min, string max, string font = "RobotoCondensed-Regular.ttf", string color = "1.0 1.0 1.0 1.0", TextAnchor align = TextAnchor.MiddleCenter) {
container.Add(new CuiLabel {
Text = {
Color = color, FontSize = (int)(size * 0.7f), Align = align, Text = text, Font = font
}
, RectTransform = {
AnchorMin = min, AnchorMax = max
}
}
, panel.ToString());
}
public static void Input(ref CuiElementContainer container, Panels panel, string text, int size, string min, string max, string command = null, string font = "RobotoCondensed-Regular.ttf", string color = "1.0 1.0 1.0 1.0", int charsLimit = 100, bool isPassword = false, TextAnchor align = TextAnchor.MiddleLeft) {
var name = CuiHelper.GetGuid();
container.Add(new CuiElement {
Name = name, Parent = panel.ToString(), FadeOut = 0, Components = {
new CuiInputFieldComponent {
Color = color, FontSize = (int)(size * 0.7f), Align = align, Text = text, Font = font, CharsLimit = charsLimit, Command = command, IsPassword = isPassword
}
, new CuiRectTransformComponent {
AnchorMin = min, AnchorMax = max
}
}
}
);
}
public static void Button(ref CuiElementContainer container, Panels panel, string color, string text, int size, string min, string max, string command, bool isBold = true, string textColor = "1.0 1.0 1.0 1.0", TextAnchor align = TextAnchor.MiddleCenter) {
container.Add(new CuiButton {
Button = {
Color = color, Command = command, FadeIn = 0f
}
, RectTransform = {
AnchorMin = min, AnchorMax = max
}
, Text = {
Color = textColor, Text = text, FontSize = (int)(size * 0.7f), Font = isBold ? "RobotoCondensed-Bold.ttf" : "RobotoCondensed-Regular.ttf", Align = align
}
}
, panel.ToString());
}
public static void Button(ref CuiElementContainer container, Panels panel, string color, string text, int size, string min, string max, string command, string textMin = null, string textMax = null, bool isBold = true, string textColor = "1.0 1.0 1.0 1.0", TextAnchor align = TextAnchor.MiddleCenter) {
var parent = container.Add(new CuiButton {
Button = {
Color = color, Command = command, FadeIn = 0f
}
, RectTransform = {
AnchorMin = min, AnchorMax = max
}
, Text = {
Color = textColor, Text = null, FontSize = (int)(size * 0.7f), Font = isBold ? "RobotoCondensed-Bold.ttf" : "RobotoCondensed-Regular.ttf", Align = align
}
}
, panel.ToString());
var textName = CuiHelper.GetGuid();
container.Add(new CuiElement {
Name = textName, Parent = parent, FadeOut = 0, Components = {
new CuiTextComponent {
Color = textColor, FontSize = (int)(size * 0.7f), Align = align, Text = text, Font = isBold ? "RobotoCondensed-Bold.ttf" : "RobotoCondensed-Regular.ttf",
}
, new CuiRectTransformComponent {
AnchorMin = textMin ?? min, AnchorMax = textMax ?? max
}
}
}
);
}
public static void ImageButton(ref CuiElementContainer container, Panels panel, string color, string image, string min, string max, string command, string imageMin = null, string imageMax = null, bool isUrl = false) {
var name = CuiHelper.GetGuid();
container.Add(new CuiElement {
Name = name, Parent = panel.ToString(), FadeOut = 0, Components = {
new CuiButtonComponent {
Color = color, Command = command, FadeIn = 0f
}
, new CuiRectTransformComponent {
AnchorMin = min, AnchorMax = max
}
}
}
);
if (!string.IsNullOrWhiteSpace(image)) {
var rawImage = new CuiRawImageComponent {
Color = "1.0 1.0 1.0 1.0", FadeIn = 0f
}
;
if (isUrl) {
rawImage.Url = image;
}
else {
rawImage.Png = image;
}
container.Add(new CuiElement {
Parent = name, FadeOut = 0, Components = {
rawImage, new CuiRectTransformComponent {
AnchorMin = string.IsNullOrWhiteSpace(imageMin) ? "0.0 0.0" : imageMin, AnchorMax = string.IsNullOrWhiteSpace(imageMax) ? "1.0 1.0" : imageMax
}
}
}
);
}
}
public static void Image(ref CuiElementContainer container, Panels panel, string image, string min, string max, bool isUrl = false, string color = "1 1 1 1") {
var rawImage = new CuiRawImageComponent {
Color = color, FadeIn = 0f
}
;
if (isUrl) {
rawImage.Url = image;
}
else {
rawImage.Png = image;
}
container.Add(new CuiElement {
Components = {
rawImage, new CuiRectTransformComponent {
AnchorMin = min, AnchorMax = max
}
,
}
, FadeOut = 0f, Parent = panel.ToString()
}
);
}
public static string Color(string hexColor, float alpha = 1) {
if (hexColor.StartsWith("#")) hexColor = hexColor.Substring(1);
var red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
var green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
var blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
return $"{(double)red / 255} {(double)green / 255} {(double)blue / 255} {alpha}";
}
public class ColorCode {
public const string Black = "#000000", White = "#FFFFFF";
public const string Green = "#018447", Red = "#B1231E", Blue = "#3C7DB3", ButtonBlack = "#141414", EerieBlack = "#282726", Gray = "#424242", ShadowBlack = "#0F0F14", TextGray = "#B3B3B3", DarkBlue = "#0A325A", QueenBlue = "#33689A", MayaBlue = "#81C7F8", Gainsboro = "#DCDCDC", Xanthic = "#EEEE04";
}
public static void ClearAllMenus(BasePlayer player) {
_instance.UnfreezePlayer(player.userID);
foreach (var name in Enum.GetNames(typeof(Panels))) {
CuiHelper.DestroyUi(player, name);
}
}
public enum Panels {
Overall, Overlay, Hud, HudMenu, Under, Fullscreen, TeamDeathmatchJoin, ArenaList, PauseMenu, LoadoutMenu, SwitchTeamMenu, LeaderboardMenu, ControlMenu, QuickMenu, InGameInfo, MatchPlayers, Recoil, RecoilImage
}
public enum MenuTab {
PauseMenu, Loadout, SwitchTeam, Leaderboard, Control
}
public enum ControlMenuTab {
General, Players, Kits, Privacy
}
public class Fonts {
public const string DroidSansMono = "DroidSansMono.ttf";
public const string PermanentMarker = "PermanentMarker.ttf";
public const string RobotoCondensedBold = "RobotoCondensed-Bold.ttf";
public const string RobotoCondensedRegular = "RobotoCondensed-Regular.ttf";
}
}
public class Lobby {
public LobbyData Data {
get;
set;
}
= new LobbyData();
public Zone Zone {
get;
set;
}
= new Zone();
public HashSet<LobbyPlayer> ActivePlayers {
get;
set;
}
= new HashSet<LobbyPlayer>();
public Vector3 GetRandomSpawnLocation() {
var validSpawnPoints = Data.SpawnLocations.Where(x => x.IsEnabled).ToList();
if (!validSpawnPoints.Any()) {
return Zone.Location;
}
var tryCount = 0;
var randomChance = UnityEngine.Random.Range(0.1f, 100);
var spawnPoint = validSpawnPoints.Where(x => x.SpawnChance >= randomChance).ToList().GetRandom();
Vector2? randomPos = null;
if (spawnPoint.Radius > 0) {
while (tryCount < 20) {
randomPos = UnityEngine.Random.insideUnitCircle * spawnPoint.Radius;
var entities = Facepunch.Pool.GetList<BaseEntity>();
Vis.Entities(randomPos.Value, 10, entities, LayerMask.GetMask("Construction", "Deployable"));
var count = entities.Count;
Facepunch.Pool.FreeList(ref entities);
if (count == 0) {
break;
}
randomPos = null;
tryCount++;
}
}
else {
randomPos = Vector2.zero;
}
return randomPos.HasValue ? new Vector3(spawnPoint.SpawnPoint.x + randomPos.Value.x, spawnPoint.SpawnPoint.y, spawnPoint.SpawnPoint.z + randomPos.Value.y) : Vector3.zero;
}
}
public class LobbyPlayer {
private readonly BasePlayer _player;
public BasePlayer Player => _player;
public LobbyPlayer(BasePlayer basePlayer) {
_player = basePlayer;
}
public override bool Equals(object obj) {
var lobbyPlayer = obj as LobbyPlayer;
if (lobbyPlayer == null) {
return false;
}
return lobbyPlayer.Player.userID == Player.userID;
}
public override int GetHashCode() {
return _player.userID.GetHashCode();
}
}
public abstract class Arena {
protected Arena(Lobby lobby, ArenaData arenaData) {
Lobby = lobby;
Data = arenaData;
}
public Lobby Lobby {
get;
private set;
}
public virtual ArenaData Data {
get;
set;
}
public Zone Zone {
get;
set;
}
= new Zone();
public virtual Match Match {
get;
set;
}
public ArenaBehaviour Behaviour {
get;
set;
}
public virtual string GetEntranceText() {
return string.Empty;
}
public virtual void TimerTick() {
}
}
public abstract class Match {
protected Match(Arena arena) {
_id = Guid.NewGuid();
Arena = arena;
}
private readonly Guid _id;
public Guid Id => _id;
public virtual Arena Arena {
get;
private set;
}
public bool IsCountDownActivated {
get;
set;
}
public bool IsCountDownEnabled {
get;
set;
}
= true;
public bool IsStarted {
get;
set;
}
public bool WillAutoStart {
get;
set;
}
= false;
public virtual HashSet<MatchPlayer> Players {
get;
set;
}
= new HashSet<MatchPlayer>();
public bool AllowIndividualKit {
get;
set;
}
public bool RestrictAccess {
get;
set;
}
public HashSet<SelectablePlayer> AllowedPlayers {
get;
set;
}
= new HashSet<SelectablePlayer>();
public HashSet<SelectablePlayer> BannedPlayers {
get;
set;
}
= new HashSet<SelectablePlayer>();
public override bool Equals(object obj) {
var match = obj as Match;
if (match == null) {
return false;
}
return match.Id == Id;
}
public override int GetHashCode() {
return _id.GetHashCode();
}
}
public class MatchPlayer {
public MatchPlayer(BasePlayer player, Match match) {
Player = player;
_playerId = player.userID;
PlayerName = player.displayName;
Match = match;
Statistics = new PlayerStatistics(player);
AllowPlaying = true;
}
private readonly ulong _playerId;
public ulong PlayerId => _playerId;
public string PlayerName {
get;
set;
}
public BasePlayer Player {
get;
private set;
}
public virtual Match Match {
get;
private set;
}
public bool IsMatchLeader {
get;
set;
}
public bool AllowPlaying {
get;
set;
}
public PlayerStatistics Statistics {
get;
set;
}
public string BlueTeamSelectedLoadoutName {
get;
set;
}
= string.Empty;
public string RedTeamSelectedLoadoutName {
get;
set;
}
= string.Empty;
public HashSet<string> IndividualItems {
get;
set;
}
= new HashSet<string>();
public void Reset() {
AllowPlaying = true;
ResetMetabolism();
}
public void ResetMetabolism() {
_instance.ResetPlayer(Player);
}
public void ResetStats() {
Statistics.Reset();
}
public void ClearInventory() {
_instance.InventoryStrip(Player);
}
public override bool Equals(object obj) {
var matchPlayer = obj as MatchPlayer;
if (matchPlayer == null) {
return false;
}
return matchPlayer.PlayerId == PlayerId;
}
public override int GetHashCode() {
return _playerId.GetHashCode();
}
}
public class PlayerStatistics {
public PlayerStatistics(BasePlayer player) {
Player = player;
}
public BasePlayer Player {
get;
}
public int Kills {
get;
set;
}
public int Deaths {
get;
set;
}
public float DamagesDone {
get;
set;
}
public int Score => Kills - Deaths;
public virtual void Reset() {
Kills = 0;
Deaths = 0;
DamagesDone = 0;
}
}
public enum MatchType {
Scrim = 10, TrainingGround = 20
}
public enum ListType {
Leaderboard = 0, Match = 10, Search = 20, Ban = 30, Allow = 40
}
public class Zone {
public string Name {
get;
set;
}
public float Radius {
get;
set;
}
public float Radiation {
get;
set;
}
public float Comfort {
get;
set;
}
public float Temperature {
get;
set;
}
public Vector3 Location {
get;
set;
}
public Vector3 Size {
get;
set;
}
public Vector3 Rotation {
get;
set;
}
public string Id {
get;
set;
}
public string EnterMessage {
get;
set;
}
public string LeaveMessage {
get;
set;
}
public string Permission {
get;
set;
}
public string EjectSpawns {
get;
set;
}
}
public class PlayerRank : PlayerStatistics {
public PlayerRank(BasePlayer player) : base(player) {
}
public int Rank {
get;
set;
}
}
public class SelectablePlayer {
public SelectablePlayer(ulong playerId, string playerName) {
_playerId = playerId;
PlayerName = playerName;
}
private readonly ulong _playerId;
public ulong PlayerId => _playerId;
public string PlayerName {
get;
set;
}
public bool IsSelected {
get;
set;
}
public override bool Equals(object obj) {
var player = obj as SelectablePlayer;
if (player == null) {
return false;
}
return player.PlayerId == PlayerId;
}
public override int GetHashCode() {
return _playerId.GetHashCode();
}
}
public class PlayerPageIndex {
public int LeaderboardIndex {
get;
set;
}
public int SearchIndex {
get;
set;
}
public int MatchIndex {
get;
set;
}
public int BanIndex {
get;
set;
}
public int AllowIndex {
get;
set;
}
}
public class ArenaDetail {
public int ArenaId {
get;
set;
}
public string Name {
get;
set;
}
public MatchType MatchType {
get;
set;
}
public int BlueTeam {
get;
set;
}
public int RedTeam {
get;
set;
}
public int Capacity {
get;
set;
}
public bool IsVip {
get;
set;
}
public bool IsRestricted {
get;
set;
}
}
public class TextTagHelper {
const string TextColorRemovalPattern = @"(?<=(<color=.*>))(.*)(?=(<\/color>))";
const string TextS
// ... [Code preview truncated due to length. Full source in attached file] ...