diff --git a/AdvancedCosmetics.sln b/AdvancedCosmetics.sln new file mode 100644 index 0000000..67d09a2 --- /dev/null +++ b/AdvancedCosmetics.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31005.135 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedCosmetics", "AdvancedCosmetics\AdvancedCosmetics.csproj", "{8BFDD083-265C-451F-B378-86664E84334A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8BFDD083-265C-451F-B378-86664E84334A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8BFDD083-265C-451F-B378-86664E84334A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8BFDD083-265C-451F-B378-86664E84334A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8BFDD083-265C-451F-B378-86664E84334A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9EEEB2D1-1123-45F5-B1DC-33F55283B62F} + EndGlobalSection +EndGlobal diff --git a/AdvancedCosmetics/AdvancedCosmetics.cs b/AdvancedCosmetics/AdvancedCosmetics.cs new file mode 100644 index 0000000..1aeda3f --- /dev/null +++ b/AdvancedCosmetics/AdvancedCosmetics.cs @@ -0,0 +1,75 @@ +using AdvancedCosmetics.Models; +using Rocket.API.Collections; +using Rocket.Core.Logging; +using Rocket.Core.Plugins; +using Rocket.Unturned.Chat; +using Rocket.Unturned.Permissions; +using SDG.Provider; +using SDG.Unturned; +using Steamworks; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using Logger = Rocket.Core.Logging.Logger; + +namespace AdvancedCosmetics +{ + public class AdvancedCosmetics : RocketPlugin + { + public static AdvancedCosmetics Instance { get; private set; } + public Color MessageColor { get; private set; } + public List EconInfos { get; private set;} + public Dictionary Cosmetics { get; set; } + protected override void Load() + { + Instance = this; + MessageColor = UnturnedChat.GetColorFromName(Configuration.Instance.MessageColor, Color.green); + Cosmetics = new Dictionary(); + var dir = System.IO.Directory.GetParent(System.IO.Directory.GetParent(System.IO.Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).FullName).FullName).FullName + @"\EconInfo.json"; + EconInfos = Newtonsoft.Json.JsonConvert.DeserializeObject>(File.ReadAllText(dir)); + UnturnedPermissions.OnJoinRequested += UnturnedPermissions_OnJoinRequested; + Logger.Log($"{Name} {Assembly.GetName().Version} has been loaded"); + } + + protected override void Unload() + { + UnturnedPermissions.OnJoinRequested -= UnturnedPermissions_OnJoinRequested; + Logger.Log($"{Name} {Assembly.GetName().Version} has been unloaded"); + } + + public override TranslationList DefaultTranslations => new TranslationList + { + { "NotSetUp", "You didnt setup any custom cosmetic yet !" }, + { "RemovedCos", "Sucssesfully removed your custom cosmetics !"}, + { "AddCos", "Sucssesfully added a {0} to your cosmetics !"}, + { "NotFound", "Cosmetic with the id or name {0} not found !"} + }; + + private void UnturnedPermissions_OnJoinRequested(Steamworks.CSteamID player, ref SDG.Unturned.ESteamRejection? rejectionReason) + { + var pending = Provider.pending.FirstOrDefault(x => x.playerID.steamID == player); + if (pending != null && Cosmetics.ContainsKey(player)) + { + var cosmetics = Cosmetics[player]; + if(cosmetics != null) + { + pending.backpackItem = cosmetics.Backpack; + pending.glassesItem = cosmetics.Glass; + pending.hatItem = cosmetics.Hat; + pending.maskItem = cosmetics.Mask; + pending.pantsItem = cosmetics.Pants; + pending.shirtItem = cosmetics.Shirt; + pending.vestItem = cosmetics.Vest; + if(cosmetics.Skins != null) + { + pending.skinItems = cosmetics.Skins.ToArray(); + } + } + } + } + } +} diff --git a/AdvancedCosmetics/AdvancedCosmetics.csproj b/AdvancedCosmetics/AdvancedCosmetics.csproj new file mode 100644 index 0000000..b50da60 --- /dev/null +++ b/AdvancedCosmetics/AdvancedCosmetics.csproj @@ -0,0 +1,78 @@ + + + + + Debug + AnyCPU + {8BFDD083-265C-451F-B378-86664E84334A} + Library + Properties + AdvancedCosmetics + AdvancedCosmetics + v4.6.1 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\VirtualGarage\bin\Debug\Assembly-CSharp.dll + + + ..\..\VirtualGarage\bin\Debug\Assembly-CSharp-firstpass.dll + + + False + ..\..\VirtualGarage\bin\Debug\Newtonsoft.Json.dll + + + ..\..\VirtualGarage\bin\Debug\Rocket.API.dll + + + ..\..\VirtualGarage\bin\Debug\Rocket.Core.dll + + + ..\..\VirtualGarage\bin\Debug\Rocket.Unturned.dll + + + + + + + + + + + ..\..\VirtualGarage\bin\Debug\UnityEngine.dll + + + ..\..\VirtualGarage\bin\Debug\UnityEngine.CoreModule.dll + + + + + + + + + + + + + \ No newline at end of file diff --git a/AdvancedCosmetics/Commands/CustomCosmeticCommand.cs b/AdvancedCosmetics/Commands/CustomCosmeticCommand.cs new file mode 100644 index 0000000..6f255d5 --- /dev/null +++ b/AdvancedCosmetics/Commands/CustomCosmeticCommand.cs @@ -0,0 +1,107 @@ +using Rocket.API; +using Rocket.Unturned.Chat; +using Rocket.Unturned.Player; +using SDG.Provider; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AdvancedCosmetics.Commands +{ + public class CustomCosmeticCommand : IRocketCommand + { + public AllowedCaller AllowedCaller => AllowedCaller.Player; + + public string Name => "customcosmetic"; + + public string Help => "A command to get a custom cosmetic"; + + public string Syntax => "/customcosmetic | /customcosmetic "; + + public List Aliases => new List(); + + public List Permissions => new List(); + + public void Execute(IRocketPlayer caller, string[] command) + { + var player = (UnturnedPlayer)caller; + if(command.Length < 1) + { + UnturnedChat.Say(player, "Correct Usage: " + Syntax, AdvancedCosmetics.Instance.MessageColor); + } + else if(int.TryParse(command[0], out int SkinId)) + { + if(AdvancedCosmetics.Instance.EconInfos.FirstOrDefault(x => x.itemdefid == SkinId) != null) + { + AddCosmetic(player, AdvancedCosmetics.Instance.EconInfos.FirstOrDefault(x => x.itemdefid == SkinId)); + } + else + { + UnturnedChat.Say(player, AdvancedCosmetics.Instance.Translate("NotFound", SkinId), AdvancedCosmetics.Instance.MessageColor); + } + } + else + { + var skin = command[0]; + if(AdvancedCosmetics.Instance.EconInfos.FirstOrDefault(x => x.name.Contains(skin)) != null) + { + AddCosmetic(player, AdvancedCosmetics.Instance.EconInfos.FirstOrDefault(x => x.name.Contains(skin))); + } + else + { + UnturnedChat.Say(player, AdvancedCosmetics.Instance.Translate("NotFound", command[0]), AdvancedCosmetics.Instance.MessageColor); + } + } + } + + public void AddCosmetic(UnturnedPlayer player, UnturnedEconInfo info) + { + if (!AdvancedCosmetics.Instance.Cosmetics.ContainsKey(player.CSteamID)) + { + AdvancedCosmetics.Instance.Cosmetics.Add(player.CSteamID, new Models.Cosmetic()); + } + + var cosmetics = AdvancedCosmetics.Instance.Cosmetics[player.CSteamID]; + var tipo = info.type.ToLower(); + if (tipo.Contains("backpack")) + { + cosmetics.Backpack = info.itemdefid; + } + else if (tipo.Contains("glasses")) + { + cosmetics.Glass = info.itemdefid; + } + else if (tipo.Contains("hat")) + { + cosmetics.Hat = info.itemdefid; + } + else if (tipo.Contains("mask")) + { + cosmetics.Mask = info.itemdefid; + } + else if (tipo.Contains("pants")) + { + cosmetics.Pants = info.itemdefid; + } + else if (tipo.Contains("shirt")) + { + cosmetics.Shirt = info.itemdefid; + } + else if (tipo.Contains("vest")) + { + cosmetics.Vest = info.itemdefid; + } + else if(tipo.Contains("skin")) + { + if(cosmetics.Skins == null) + { + cosmetics.Skins = new List(); + } + cosmetics.Skins.Add(info.itemdefid); + } + UnturnedChat.Say(player, AdvancedCosmetics.Instance.Translate("AddCos", info.name), AdvancedCosmetics.Instance.MessageColor); + } + } +} diff --git a/AdvancedCosmetics/Commands/RemoveCustomCosmeticsCommand.cs b/AdvancedCosmetics/Commands/RemoveCustomCosmeticsCommand.cs new file mode 100644 index 0000000..3013772 --- /dev/null +++ b/AdvancedCosmetics/Commands/RemoveCustomCosmeticsCommand.cs @@ -0,0 +1,43 @@ +using Rocket.API; +using Rocket.Unturned.Chat; +using Rocket.Unturned.Player; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AdvancedCosmetics.Commands +{ + public class RemoveCustomCosmeticsCommand : IRocketCommand + { + public AllowedCaller AllowedCaller => AllowedCaller.Player; + + public string Name => "removecustomcosmetics"; + + public string Help => "A command to remove the custom cosmetics"; + + public string Syntax => "/removecustomcosmetics"; + + public List Aliases => new List + { + "removecosmetics", + }; + + public List Permissions => new List(); + + public void Execute(IRocketPlayer caller, string[] command) + { + var player = (UnturnedPlayer)caller; + if (AdvancedCosmetics.Instance.Cosmetics.ContainsKey(player.CSteamID)) + { + AdvancedCosmetics.Instance.Cosmetics.Remove(player.CSteamID); + UnturnedChat.Say(player, AdvancedCosmetics.Instance.Translate("RemovedCos"), AdvancedCosmetics.Instance.MessageColor); + } + else + { + UnturnedChat.Say(player, AdvancedCosmetics.Instance.Translate("NotSetUp"), AdvancedCosmetics.Instance.MessageColor); + } + } + } +} diff --git a/AdvancedCosmetics/Configuration.cs b/AdvancedCosmetics/Configuration.cs new file mode 100644 index 0000000..ccc32a5 --- /dev/null +++ b/AdvancedCosmetics/Configuration.cs @@ -0,0 +1,18 @@ +using Rocket.API; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AdvancedCosmetics +{ + public class Configuration : IRocketPluginConfiguration + { + public string MessageColor; + public void LoadDefaults() + { + MessageColor = "magenta"; + } + } +} diff --git a/AdvancedCosmetics/Models/Cosmetic.cs b/AdvancedCosmetics/Models/Cosmetic.cs new file mode 100644 index 0000000..9aa46e7 --- /dev/null +++ b/AdvancedCosmetics/Models/Cosmetic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AdvancedCosmetics.Models +{ + public class Cosmetic + { + public int Backpack { get; set; } + public int Glass { get; set; } + public int Hat { get; set; } + public int Mask { get; set; } + public int Pants { get; set; } + public int Shirt { get; set; } + public int Vest { get; set; } + public List Skins { get; set; } + } +} diff --git a/AdvancedCosmetics/Properties/AssemblyInfo.cs b/AdvancedCosmetics/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d616ec2 --- /dev/null +++ b/AdvancedCosmetics/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// La información general de un ensamblado se controla mediante el siguiente +// conjunto de atributos. Cambie estos valores de atributo para modificar la información +// asociada con un ensamblado. +[assembly: AssemblyTitle("AdvancedCosmetics")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("AdvancedCosmetics")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles +// para los componentes COM. Si es necesario obtener acceso a un tipo en este ensamblado desde +// COM, establezca el atributo ComVisible en true en este tipo. +[assembly: ComVisible(false)] + +// El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM. +[assembly: Guid("8bfdd083-265c-451f-b378-86664e84334a")] + +// La información de versión de un ensamblado consta de los cuatro valores siguientes: +// +// Versión principal +// Versión secundaria +// Número de compilación +// Revisión +// +// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión +// utilizando el carácter "*", como se muestra a continuación: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0")] +[assembly: AssemblyFileVersion("1.0.0")]