├── .gitignore ├── LICENSE ├── README.md ├── Rocket.Unturned.LICENSE ├── Rocket.Unturned.Launcher ├── Program.cs └── Rocket.Unturned.Launcher.csproj ├── Rocket.Unturned.Module ├── HttpRequestMessageFactoryCreatePatch.cs ├── Module │ ├── English.dat │ ├── Icon.png │ └── Rocket.Unturned.module ├── Rocket.Unturned.Module.csproj ├── RocketInitializer.cs ├── RocketUnturnedModule.cs └── runtimelibs │ ├── System.Configuration.Install.dll │ ├── System.Drawing.dll │ ├── System.IO.Compression.dll │ ├── System.Net.Http.dll │ ├── System.Net.Primitives.dll │ ├── System.Runtime.Serialization.dll │ ├── System.Runtime.dll │ ├── System.Web.dll │ ├── System.Xml.Linq.dll │ └── netstandard.dll ├── Rocket.Unturned.sln ├── Rocket.Unturned.sln.DotSettings ├── Rocket.Unturned ├── Commands │ ├── CommandAdmin.cs │ ├── CommandBroadcast.cs │ ├── CommandCompass.cs │ ├── CommandEffect.cs │ ├── CommandExit.cs │ ├── CommandHeal.cs │ ├── CommandHome.cs │ ├── CommandInvestigate.cs │ ├── CommandItem.cs │ ├── CommandMore.cs │ ├── CommandTp.cs │ ├── CommandTphere.cs │ ├── CommandUnadmin.cs │ ├── CommandVehicle.cs │ ├── RocketUnturnedCommandProvider.cs │ ├── VanillaCommand.cs │ └── VanillaCommandProvider.cs ├── Console │ ├── UnturnedConsolePipe.cs │ └── UnturnedConsoleWriter.cs ├── Permissions │ └── UnturnedAdminPermissionChecker.cs ├── Player │ ├── Events │ │ ├── UnturnedPlayerChatEvent.cs │ │ ├── UnturnedPlayerDamagedEvent.cs │ │ ├── UnturnedPlayerDeadEvent.cs │ │ ├── UnturnedPlayerDeathEvent.cs │ │ ├── UnturnedPlayerPreConnectEvent.cs │ │ ├── UnturnedPlayerUpdateBleedingEvent.cs │ │ ├── UnturnedPlayerUpdateBrokenEvent.cs │ │ ├── UnturnedPlayerUpdateExperienceEvent.cs │ │ ├── UnturnedPlayerUpdateFoodEvent.cs │ │ ├── UnturnedPlayerUpdateGestureEvent.cs │ │ ├── UnturnedPlayerUpdateHealthEvent.cs │ │ ├── UnturnedPlayerUpdateLifeEvent.cs │ │ ├── UnturnedPlayerUpdateStanceEvent.cs │ │ ├── UnturnedPlayerUpdateStatEvent.cs │ │ ├── UnturnedPlayerUpdateVirusEvent.cs │ │ └── UnturnedPlayerUpdateWaterEvent.cs │ ├── PreConnectUnturnedPlayer.cs │ ├── UnturnedIdentity.cs │ ├── UnturnedPlayer.cs │ ├── UnturnedPlayerEntity.cs │ ├── UnturnedPlayerManager.cs │ └── UnturnedUser.cs ├── Properties │ └── ServiceConfigurator.cs ├── Rocket.Unturned.csproj ├── RocketUnturnedHost.cs └── Utils │ └── AutomaticSaveWatchdog.cs └── lib ├── Assembly-CSharp-firstpass.dll └── Assembly-CSharp.dll /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | bld/ 16 | [Bb]in/ 17 | [Oo]bj/ 18 | .vs/ 19 | 20 | UnityEngine.dll 21 | UnityEngine.CoreModule.dll 22 | 23 | # Roslyn cache directories 24 | *.ide/ 25 | 26 | # MSTest test Results 27 | [Tt]est[Rr]esult*/ 28 | [Bb]uild[Ll]og.* 29 | 30 | #NUNIT 31 | *.VisualState.xml 32 | TestResult.xml 33 | 34 | # Build Results of an ATL Project 35 | [Dd]ebugPS/ 36 | [Rr]eleasePS/ 37 | dlldata.c 38 | 39 | *_i.c 40 | *_p.c 41 | *_i.h 42 | *.ilk 43 | *.meta 44 | *.obj 45 | *.pch 46 | *.pdb 47 | *.pgc 48 | *.pgd 49 | *.rsp 50 | *.sbr 51 | *.tlb 52 | *.tli 53 | *.tlh 54 | *.tmp 55 | *.tmp_proj 56 | *.log 57 | *.vspscc 58 | *.vssscc 59 | .builds 60 | *.pidb 61 | *.svclog 62 | *.scc 63 | 64 | # Chutzpah Test files 65 | _Chutzpah* 66 | 67 | # Visual C++ cache files 68 | ipch/ 69 | *.aps 70 | *.ncb 71 | *.opensdf 72 | *.sdf 73 | *.cachefile 74 | 75 | # Visual Studio profiler 76 | *.psess 77 | *.vsp 78 | *.vspx 79 | 80 | # TFS 2012 Local Workspace 81 | $tf/ 82 | 83 | # Guidance Automation Toolkit 84 | *.gpState 85 | 86 | # ReSharper is a .NET coding add-in 87 | _ReSharper*/ 88 | *.[Rr]e[Ss]harper 89 | *.DotSettings.user 90 | 91 | # JustCode is a .NET coding addin-in 92 | .JustCode 93 | 94 | # TeamCity is a build add-in 95 | _TeamCity* 96 | 97 | # DotCover is a Code Coverage Tool 98 | *.dotCover 99 | 100 | # NCrunch 101 | _NCrunch_* 102 | .*crunch*.local.xml 103 | 104 | # MightyMoose 105 | *.mm.* 106 | AutoTest.Net/ 107 | 108 | # Web workbench (sass) 109 | .sass-cache/ 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.[Pp]ublish.xml 129 | *.azurePubxml 130 | ## TODO: Comment the next line if you want to checkin your 131 | ## web deploy settings but do note that will include unencrypted 132 | ## passwords 133 | #*.pubxml 134 | 135 | # NuGet Packages Directory 136 | packages/* 137 | ## TODO: If the tool you use requires repositories.config 138 | ## uncomment the next line 139 | #!packages/repositories.config 140 | 141 | # Enable "build/" folder in the NuGet Packages folder since 142 | # NuGet packages use it for MSBuild targets. 143 | # This line needs to be after the ignore of the build folder 144 | # (and the packages folder if the line above has been uncommented) 145 | !packages/build/ 146 | 147 | # Windows Azure Build Output 148 | csx/ 149 | *.build.csdef 150 | 151 | # Windows Store app package directory 152 | AppPackages/ 153 | 154 | # Others 155 | sql/ 156 | *.Cache 157 | ClientBin/ 158 | [Ss]tyle[Cc]op.* 159 | ~$* 160 | *~ 161 | *.dbmdl 162 | *.dbproj.schemaview 163 | *.pfx 164 | *.publishsettings 165 | node_modules/ 166 | 167 | # RIA/Silverlight projects 168 | Generated_Code/ 169 | 170 | # Backup & report files from converting an old project file 171 | # to a newer Visual Studio version. Backup files are not needed, 172 | # because we have git ;-) 173 | _UpgradeReport_Files/ 174 | Backup*/ 175 | UpgradeLog*.XML 176 | UpgradeLog*.htm 177 | 178 | # SQL Server files 179 | *.mdf 180 | *.ldf 181 | 182 | # Business Intelligence projects 183 | *.rdl.data 184 | *.bim.layout 185 | *.bim_*.settings 186 | 187 | # Microsoft Fakes 188 | FakesAssemblies/ 189 | 190 | # LightSwitch generated files 191 | GeneratedArtifacts/ 192 | _Pvt_Extensions/ 193 | ModelManifest.xml 194 | 195 | # IntelliJ Rider 196 | .idea/ 197 | /Rocket.Unturned/lib/net461 198 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Sven Mawby 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | We, Sven Mawby "fr34kyn01535" and Enes Sadık Özbek "Trojaner" stopped maintaining RocketMod. 2 | 3 | Read [our message](https://github.com/RocketMod/Rocket/blob/master/Farewell.md) for more information. 4 | -------------------------------------------------------------------------------- /Rocket.Unturned.LICENSE: -------------------------------------------------------------------------------- 1 | Unturned 3 is property of Smartly Dressed Games. 2 | You are not allowed to change, mix or redistribute Unturned 3 3 | unless permission is explicitly given by Smartly Dressed Games. 4 | Copyright (C) | Smartly Dressed Games | Nelson Sexton 5 | 6 | -------------------------------------------------------------------------------------- 7 | 8 | Rocket.Unturned is licensed under MIT. 9 | 10 | Copyright (C) | RocketMod | Sven Mawby 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a copy 13 | of this software and associated documentation files (the "Software"), to deal 14 | in the Software without restriction, including without limitation the rights 15 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 | copies of the Software, and to permit persons to whom the Software is 17 | furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in all 20 | copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | SOFTWARE. 29 | -------------------------------------------------------------------------------- /Rocket.Unturned.Launcher/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Rocket.Unturned.Launcher 7 | { 8 | internal class RocketLauncher 9 | { 10 | public static bool IsLinux 11 | { 12 | get 13 | { 14 | int p = (int)Environment.OSVersion.Platform; 15 | return (p == 4) || (p == 6) || (p == 128); 16 | } 17 | } 18 | 19 | private static TextReader consoleReader; 20 | private static string instanceName; 21 | 22 | public static void Main(string[] args) 23 | { 24 | instanceName = args.Length > 0 ? args[0] : "Rocket"; 25 | 26 | string executableName = ""; 27 | if (args.Length > 1) 28 | { 29 | executableName = args[1]; 30 | } 31 | else 32 | { 33 | foreach (string s in new[] { "Unturned_Headless.x86_64", "Unturned_Headless.x86", "Unturned.x86_64", "Unturned.x86", "Unturned.exe" }) 34 | if (File.Exists(s)) 35 | { 36 | executableName = s; 37 | break; 38 | } 39 | } 40 | 41 | if (string.IsNullOrEmpty(executableName)) 42 | throw new FileNotFoundException("Could not locate Unturned executable"); 43 | 44 | 45 | string arguments = "-nographics -batchmode -silent-crashes -logfile 'Servers/" 46 | + instanceName 47 | + "/unturned.log' +secureserver/" 48 | + instanceName; 49 | 50 | var startInfo = new ProcessStartInfo(executableName, arguments) 51 | { 52 | RedirectStandardOutput = true, 53 | RedirectStandardInput = false, 54 | UseShellExecute = false, 55 | }; 56 | 57 | if (IsLinux) 58 | { 59 | var currentDir = Path.GetFullPath(Environment.CurrentDirectory); 60 | var lib64Dir = Path.Combine(currentDir, "lib64"); 61 | 62 | startInfo.Environment.Add("LD_LIBRARY_PATH", lib64Dir); 63 | } 64 | 65 | string consoleOutput = instanceName + ".console"; 66 | 67 | FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(".", consoleOutput); 68 | fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName; 69 | fileSystemWatcher.Changed += fileSystemWatcher_Changed; 70 | consoleReader = new StreamReader(new FileStream(consoleOutput, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite)); 71 | fileSystemWatcher.EnableRaisingEvents = true; 72 | 73 | Console.WriteLine($@"Starting Unturned via: {executableName} {arguments}"); 74 | Process p = new Process 75 | { 76 | StartInfo = startInfo 77 | }; 78 | 79 | p.Start(); 80 | p.WaitForExit(); 81 | } 82 | 83 | private static void fileSystemWatcher_Changed(object sender, FileSystemEventArgs e) 84 | { 85 | if (Path.GetFileName(e.FullPath).Equals(instanceName + ".console", StringComparison.OrdinalIgnoreCase)) 86 | return; 87 | 88 | if (e.ChangeType != WatcherChangeTypes.Changed) 89 | return; 90 | 91 | string newline = consoleReader.ReadToEnd(); 92 | if (!string.IsNullOrEmpty(newline)) 93 | Console.Write(newline); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Rocket.Unturned.Launcher/Rocket.Unturned.Launcher.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | RocketLauncher 5 | netcoreapp2.2; net461 6 | 7 | 0.0.0.0 8 | 9 | 0.0.0.0 10 | 11 | 0.0.0.0 12 | Exe 13 | 14 | 15 | -------------------------------------------------------------------------------- /Rocket.Unturned.Module/HttpRequestMessageFactoryCreatePatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Harmony; 3 | using NuGet.Protocol; 4 | using System.Net.Http; 5 | 6 | namespace Rocket.Unturned.Module 7 | { 8 | [HarmonyPatch(typeof(HttpRequestMessageFactory))] 9 | [HarmonyPatch(nameof(HttpRequestMessageFactory.Create))] 10 | [HarmonyPatch(new[] { typeof(HttpMethod), typeof(string), typeof(HttpRequestMessageConfiguration) })] 11 | public class HttpRequestMessageFactoryCreatePatchString 12 | { 13 | [HarmonyPrefix] 14 | public static void Create(HttpMethod method, ref string requestUri, HttpRequestMessageConfiguration configuration) 15 | { 16 | #if DEBUG 17 | System.Console.WriteLine("HttpRequestMessageFactory: Creating from string: " + requestUri); 18 | #endif 19 | requestUri = requestUri.Replace("https://", "http://"); 20 | } 21 | } 22 | 23 | [HarmonyPatch(typeof(HttpRequestMessageFactory))] 24 | [HarmonyPatch(nameof(HttpRequestMessageFactory.Create))] 25 | [HarmonyPatch(new[] { typeof(HttpMethod), typeof(Uri), typeof(HttpRequestMessageConfiguration) })] 26 | public class HttpRequestMessageFactoryCreatePatchUri 27 | { 28 | [HarmonyPrefix] 29 | public static void Create(HttpMethod method, ref Uri requestUri, HttpRequestMessageConfiguration configuration) 30 | { 31 | #if DEBUG 32 | System.Console.WriteLine("HttpRequestMessageFactory: Creating from URI: " + requestUri); 33 | #endif 34 | requestUri = new Uri(requestUri.ToString().Replace("https://", "http://")); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Rocket.Unturned.Module/Module/English.dat: -------------------------------------------------------------------------------- 1 | Name RocketMod for Unturned 2 | Description RocketMod is a free modular plugin framework for various game servers. -------------------------------------------------------------------------------- /Rocket.Unturned.Module/Module/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/Rocket.Unturned.Module/Module/Icon.png -------------------------------------------------------------------------------- /Rocket.Unturned.Module/Module/Rocket.Unturned.module: -------------------------------------------------------------------------------- 1 | { 2 | "Name": "Rocket.Unturned", 3 | "Version": "0.0.0.0", 4 | "Assemblies": 5 | [ 6 | { 7 | "Path": "/Rocket.Unturned.Module.dll", 8 | "Role": "Server" 9 | } 10 | ], 11 | "Dependencies": 12 | [ 13 | { 14 | "Name": "Framework", 15 | "Version": "3.17.4.0" 16 | }, 17 | { 18 | "Name": "Unturned", 19 | "Version": "3.17.4.0" 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /Rocket.Unturned.Module/Rocket.Unturned.Module.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Rocket.Unturned.Module 5 | net461 6 | 7 | 0.0.0.0 8 | 9 | 0.0.0.0 10 | 11 | 0.0.0.0 12 | 13 | 0.0.0.0 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | false 23 | 24 | 25 | true 26 | 27 | 28 | 29 | NUGET_BOOTSTRAP 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | All 39 | 40 | 41 | 42 | 43 | 44 | ..\lib\Assembly-CSharp.dll 45 | false 46 | 47 | 48 | ..\lib\Assembly-CSharp-firstpass.dll 49 | false 50 | 51 | 52 | ..\lib\UnityEngine.dll 53 | false 54 | 55 | 56 | ..\lib\UnityEngine.CoreModule.dll 57 | false 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /Rocket.Unturned.Module/RocketInitializer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Runtime.CompilerServices; 4 | using System.Threading.Tasks; 5 | using SDG.Unturned; 6 | using UnityEngine; 7 | 8 | namespace Rocket.Unturned.Module 9 | { 10 | public class RocketInitializer 11 | { 12 | [MethodImpl(MethodImplOptions.NoInlining)] 13 | public static void Initialize() 14 | { 15 | #if NUGET_BOOTSTRAP 16 | string rocketDirectory = Path.GetFullPath($"Servers/{Dedicator.serverID}/Rocket/"); 17 | if (!Directory.Exists(rocketDirectory)) 18 | { 19 | Directory.CreateDirectory(rocketDirectory); 20 | } 21 | 22 | Debug.Log("Bootstrapping RocketMod for Unturned, this might take a while..."); 23 | 24 | var logger = new UnityLoggerAdapter(); 25 | var bootrapper = new RocketDynamicBootstrapper(); 26 | 27 | bootrapper.Bootstrap(rocketDirectory, 28 | new List { "Rocket.Unturned" }, 29 | false, 30 | RocketDynamicBootstrapper.DefaultNugetRepository, 31 | logger); 32 | 33 | #else 34 | var runtime = new Runtime(); 35 | runtime.InitAsync().GetAwaiter().GetResult(); 36 | #endif 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Rocket.Unturned.Module/RocketUnturnedModule.cs: -------------------------------------------------------------------------------- 1 | using NuGet.Common; 2 | using SDG.Framework.Modules; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Net; 7 | using System.Net.Security; 8 | using System.Reflection; 9 | using System.Security.Cryptography.X509Certificates; 10 | using System.Text.RegularExpressions; 11 | using System.Threading.Tasks; 12 | using Harmony; 13 | using Debug = UnityEngine.Debug; 14 | 15 | namespace Rocket.Unturned.Module 16 | { 17 | public class RocketUnturnedModule : IModuleNexus 18 | { 19 | private const string HarmonyInstanceId = "net.rocketmod.unturned.module"; 20 | private readonly Dictionary loadedAssemblies = new Dictionary(); 21 | private HarmonyInstance harmonyInstance; 22 | 23 | public void initialize() 24 | { 25 | var selfAssembly = typeof(RocketUnturnedModule).Assembly; 26 | 27 | harmonyInstance = HarmonyInstance.Create(HarmonyInstanceId); 28 | harmonyInstance.PatchAll(selfAssembly); 29 | 30 | InstallNewtonsoftJson(); 31 | InstallTlsWorkaround(); 32 | InstallAssemblyResolver(); 33 | 34 | var assemblyLocation = selfAssembly.Location; 35 | var assemblyDirectory = Path.GetDirectoryName(assemblyLocation); 36 | 37 | foreach (var file in Directory.GetFiles(assemblyDirectory)) 38 | { 39 | if (file.EndsWith(".dll")) 40 | { 41 | LoadAssembly(file); 42 | } 43 | } 44 | 45 | RocketInitializer.Initialize(); 46 | } 47 | 48 | private void InstallNewtonsoftJson() 49 | { 50 | string managedDir = Path.GetDirectoryName(typeof(IModuleNexus).Assembly.Location); 51 | string rocketDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 52 | 53 | string unturnedNewtonsoftFile = Path.GetFullPath(Path.Combine(managedDir, "Newtonsoft.Json.dll")); 54 | string newtonsoftBackupFile = unturnedNewtonsoftFile + ".bak"; 55 | string rocketNewtonsoftFile = Path.GetFullPath(Path.Combine(rocketDir, "Newtonsoft.Json.dll")); 56 | 57 | const string runtimeSerialization = "System.Runtime.Serialization.dll"; 58 | var unturnedRuntimeSerialization = Path.GetFullPath(Path.Combine(managedDir, runtimeSerialization)); 59 | var rocketRuntimeSerialization = Path.GetFullPath(Path.Combine(rocketDir, runtimeSerialization)); 60 | 61 | const string xmlLinq = "System.Xml.Linq.dll"; 62 | var unturnedXmlLinq = Path.GetFullPath(Path.Combine(managedDir, xmlLinq)); 63 | var rocketXmlLinq = Path.GetFullPath(Path.Combine(rocketDir, xmlLinq)); 64 | 65 | // Copy Libraries of Newtonsoft.Json 66 | 67 | if (!File.Exists(unturnedRuntimeSerialization)) 68 | { 69 | File.Copy(rocketRuntimeSerialization, unturnedRuntimeSerialization); 70 | } 71 | 72 | if (!File.Exists(unturnedXmlLinq)) 73 | { 74 | File.Copy(rocketXmlLinq, unturnedXmlLinq); 75 | } 76 | 77 | // Copy Newtonsoft.Json 78 | AssemblyName asm = AssemblyName.GetAssemblyName(unturnedNewtonsoftFile); 79 | GetVersionIndependentName(asm.FullName, out var version); 80 | if (version.StartsWith("7.", StringComparison.OrdinalIgnoreCase)) 81 | { 82 | if (File.Exists(newtonsoftBackupFile)) 83 | { 84 | File.Delete(newtonsoftBackupFile); 85 | } 86 | 87 | File.Move(unturnedNewtonsoftFile, newtonsoftBackupFile); 88 | File.Copy(rocketNewtonsoftFile, unturnedNewtonsoftFile); 89 | } 90 | } 91 | 92 | private void InstallAssemblyResolver() 93 | { 94 | AppDomain.CurrentDomain.AssemblyResolve += delegate (object sender, ResolveEventArgs args) 95 | { 96 | var name = GetVersionIndependentName(args.Name, out _); 97 | 98 | if (loadedAssemblies.ContainsKey(name)) 99 | { 100 | return loadedAssemblies[name]; 101 | } 102 | 103 | return null; 104 | }; 105 | } 106 | 107 | public void shutdown() 108 | { 109 | harmonyInstance.UnpatchAll(HarmonyInstanceId); 110 | } 111 | 112 | private void InstallTlsWorkaround() 113 | { 114 | //http://answers.unity.com/answers/1089592/view.html 115 | ServicePointManager.ServerCertificateValidationCallback = CertificateValidationWorkaroundCallback; 116 | } 117 | 118 | private bool CertificateValidationWorkaroundCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 119 | { 120 | bool isOk = true; 121 | // If there are errors in the certificate chain, look at each error to determine the cause. 122 | if (sslPolicyErrors != SslPolicyErrors.None) 123 | { 124 | foreach (X509ChainStatus chainStatus in chain.ChainStatus) 125 | { 126 | if (chainStatus.Status != X509ChainStatusFlags.RevocationStatusUnknown) 127 | { 128 | chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain; 129 | chain.ChainPolicy.RevocationMode = X509RevocationMode.Online; 130 | chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0); 131 | chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags; 132 | bool chainIsValid = chain.Build((X509Certificate2)certificate); 133 | if (!chainIsValid) 134 | { 135 | isOk = false; 136 | } 137 | } 138 | } 139 | } 140 | return isOk; 141 | } 142 | 143 | 144 | private static readonly Regex versionRegex = new Regex("Version=(?.+?), ", RegexOptions.Compiled); 145 | 146 | protected static string GetVersionIndependentName(string fullAssemblyName, out string extractedVersion) 147 | { 148 | var match = versionRegex.Match(fullAssemblyName); 149 | extractedVersion = match.Groups[1].Value; 150 | return versionRegex.Replace(fullAssemblyName, ""); 151 | } 152 | 153 | public void LoadAssembly(string dllName) 154 | { 155 | //Load the dll from the same directory as this assembly 156 | var selfLocation = typeof(RocketUnturnedModule).Assembly.Location; 157 | var currentPath = Path.GetDirectoryName(selfLocation) ?? ""; 158 | var dllFullPath = Path.GetFullPath(Path.Combine(currentPath, dllName)); 159 | 160 | if (string.Equals(selfLocation, dllFullPath, StringComparison.OrdinalIgnoreCase)) 161 | { 162 | return; 163 | } 164 | 165 | var data = File.ReadAllBytes(dllFullPath); 166 | var asm = Assembly.Load(data); 167 | 168 | var name = GetVersionIndependentName(asm.FullName, out _); 169 | 170 | if (loadedAssemblies.ContainsKey(name)) 171 | { 172 | return; 173 | } 174 | 175 | loadedAssemblies.Add(name, asm); 176 | } 177 | } 178 | 179 | public class UnityLoggerAdapter : LoggerBase 180 | { 181 | public override void Log(ILogMessage message) 182 | { 183 | Debug.Log($"[{message.Level}] [NuGet] {message.Message}"); 184 | } 185 | 186 | public override async Task LogAsync(ILogMessage message) 187 | { 188 | Log(message); 189 | } 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /Rocket.Unturned.Module/runtimelibs/System.Configuration.Install.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/Rocket.Unturned.Module/runtimelibs/System.Configuration.Install.dll -------------------------------------------------------------------------------- /Rocket.Unturned.Module/runtimelibs/System.Drawing.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/Rocket.Unturned.Module/runtimelibs/System.Drawing.dll -------------------------------------------------------------------------------- /Rocket.Unturned.Module/runtimelibs/System.IO.Compression.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/Rocket.Unturned.Module/runtimelibs/System.IO.Compression.dll -------------------------------------------------------------------------------- /Rocket.Unturned.Module/runtimelibs/System.Net.Http.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/Rocket.Unturned.Module/runtimelibs/System.Net.Http.dll -------------------------------------------------------------------------------- /Rocket.Unturned.Module/runtimelibs/System.Net.Primitives.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/Rocket.Unturned.Module/runtimelibs/System.Net.Primitives.dll -------------------------------------------------------------------------------- /Rocket.Unturned.Module/runtimelibs/System.Runtime.Serialization.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/Rocket.Unturned.Module/runtimelibs/System.Runtime.Serialization.dll -------------------------------------------------------------------------------- /Rocket.Unturned.Module/runtimelibs/System.Runtime.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/Rocket.Unturned.Module/runtimelibs/System.Runtime.dll -------------------------------------------------------------------------------- /Rocket.Unturned.Module/runtimelibs/System.Web.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/Rocket.Unturned.Module/runtimelibs/System.Web.dll -------------------------------------------------------------------------------- /Rocket.Unturned.Module/runtimelibs/System.Xml.Linq.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/Rocket.Unturned.Module/runtimelibs/System.Xml.Linq.dll -------------------------------------------------------------------------------- /Rocket.Unturned.Module/runtimelibs/netstandard.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/Rocket.Unturned.Module/runtimelibs/netstandard.dll -------------------------------------------------------------------------------- /Rocket.Unturned.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26403.3 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rocket.Unturned", "Rocket.Unturned\Rocket.Unturned.csproj", "{BADB74F6-90C0-40AF-865D-27795B50C469}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rocket.Unturned.Launcher", "Rocket.Unturned.Launcher\Rocket.Unturned.Launcher.csproj", "{0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rocket.Unturned.Module", "Rocket.Unturned.Module\Rocket.Unturned.Module.csproj", "{B0A590B8-539B-4B5F-80CF-33E51823E845}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Debug|x64 = Debug|x64 16 | Debug|x86 = Debug|x86 17 | Local|Any CPU = Local|Any CPU 18 | Local|x64 = Local|x64 19 | Local|x86 = Local|x86 20 | Release|Any CPU = Release|Any CPU 21 | Release|x64 = Release|x64 22 | Release|x86 = Release|x86 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Debug|x64.ActiveCfg = Debug|Any CPU 28 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Debug|x64.Build.0 = Debug|Any CPU 29 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Debug|x86.ActiveCfg = Debug|Any CPU 30 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Debug|x86.Build.0 = Debug|Any CPU 31 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Local|Any CPU.ActiveCfg = Release|Any CPU 32 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Local|Any CPU.Build.0 = Release|Any CPU 33 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Local|x64.ActiveCfg = Release|Any CPU 34 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Local|x64.Build.0 = Release|Any CPU 35 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Local|x86.ActiveCfg = Release|Any CPU 36 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Local|x86.Build.0 = Release|Any CPU 37 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Release|x64.ActiveCfg = Release|Any CPU 40 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Release|x64.Build.0 = Release|Any CPU 41 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Release|x86.ActiveCfg = Release|Any CPU 42 | {BADB74F6-90C0-40AF-865D-27795B50C469}.Release|x86.Build.0 = Release|Any CPU 43 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Debug|x64.ActiveCfg = Debug|Any CPU 46 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Debug|x64.Build.0 = Debug|Any CPU 47 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Debug|x86.ActiveCfg = Debug|Any CPU 48 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Debug|x86.Build.0 = Debug|Any CPU 49 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Local|Any CPU.ActiveCfg = Release|Any CPU 50 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Local|Any CPU.Build.0 = Release|Any CPU 51 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Local|x64.ActiveCfg = Release|Any CPU 52 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Local|x64.Build.0 = Release|Any CPU 53 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Local|x86.ActiveCfg = Release|Any CPU 54 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Local|x86.Build.0 = Release|Any CPU 55 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Release|Any CPU.ActiveCfg = Release|Any CPU 56 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Release|Any CPU.Build.0 = Release|Any CPU 57 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Release|x64.ActiveCfg = Release|Any CPU 58 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Release|x64.Build.0 = Release|Any CPU 59 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Release|x86.ActiveCfg = Release|Any CPU 60 | {0F68CF17-C7C9-41BF-8F76-4DAF1D5146B4}.Release|x86.Build.0 = Release|Any CPU 61 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 62 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Debug|Any CPU.Build.0 = Debug|Any CPU 63 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Debug|x64.ActiveCfg = Debug|Any CPU 64 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Debug|x64.Build.0 = Debug|Any CPU 65 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Debug|x86.ActiveCfg = Debug|Any CPU 66 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Debug|x86.Build.0 = Debug|Any CPU 67 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Local|Any CPU.ActiveCfg = Debug|Any CPU 68 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Local|Any CPU.Build.0 = Debug|Any CPU 69 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Local|x64.ActiveCfg = Debug|Any CPU 70 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Local|x64.Build.0 = Debug|Any CPU 71 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Local|x86.ActiveCfg = Debug|Any CPU 72 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Local|x86.Build.0 = Debug|Any CPU 73 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Release|Any CPU.ActiveCfg = Release|Any CPU 74 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Release|Any CPU.Build.0 = Release|Any CPU 75 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Release|x64.ActiveCfg = Release|Any CPU 76 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Release|x64.Build.0 = Release|Any CPU 77 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Release|x86.ActiveCfg = Release|Any CPU 78 | {B0A590B8-539B-4B5F-80CF-33E51823E845}.Release|x86.Build.0 = Release|Any CPU 79 | EndGlobalSection 80 | GlobalSection(SolutionProperties) = preSolution 81 | HideSolutionNode = FALSE 82 | EndGlobalSection 83 | GlobalSection(ExtensibilityGlobals) = postSolution 84 | EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.2\lib\NET35 85 | SolutionGuid = {0FCCF378-BF24-4185-8167-E38D22C58912} 86 | EndGlobalSection 87 | EndGlobal 88 | -------------------------------------------------------------------------------- /Rocket.Unturned.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | DO_NOT_SHOW 3 | ERROR 4 | ERROR 5 | HINT 6 | DO_NOT_SHOW 7 | ERROR 8 | SUGGESTION 9 | ERROR 10 | SUGGESTION 11 | WARNING 12 | WARNING 13 | WARNING 14 | WARNING 15 | WARNING 16 | DO_NOT_SHOW 17 | DO_NOT_SHOW 18 | DO_NOT_SHOW 19 | WARNING 20 | CRLF 21 | ExpressionBody 22 | True 23 | ExpressionBody 24 | True 25 | False 26 | True 27 | True 28 | True 29 | 30 | TOGETHER_SAME_LINE 31 | True 32 | True 33 | True 34 | True 35 | True 36 | True 37 | True 38 | True 39 | 1 40 | 1 41 | 42 | 43 | 44 | EXPANDED 45 | NEVER 46 | ALWAYS 47 | ALWAYS 48 | ALWAYS 49 | 50 | 51 | True 52 | False 53 | True 54 | True 55 | CHOP_IF_LONG 56 | CHOP_IF_LONG 57 | WRAP_IF_LONG 58 | CHOP_ALWAYS 59 | WRAP_IF_LONG 60 | WRAP_IF_LONG 61 | CHOP_ALWAYS 62 | False 63 | UseExplicitType 64 | UseExplicitType 65 | UseExplicitType 66 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 67 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 68 | C:\Users\fr34kyn01535\AppData\Local\JetBrains\Transient\ReSharperPlatformVs15\v11_de26377b\SolutionCaches 69 | True 70 | C:\Users\fr34kyn01535\GitHub\Rocket.Unturned\Rocket.Unturned.sln.DotSettings 71 | 72 | True 73 | 1 74 | LIVE_MONITOR 75 | LIVE_MONITOR 76 | DO_NOTHING 77 | LIVE_MONITOR 78 | LIVE_MONITOR 79 | LIVE_MONITOR 80 | LIVE_MONITOR 81 | LIVE_MONITOR 82 | LIVE_MONITOR 83 | LIVE_MONITOR 84 | LIVE_MONITOR 85 | DO_NOTHING 86 | LIVE_MONITOR 87 | True 88 | True 89 | True 90 | True 91 | True 92 | True 93 | True 94 | True 95 | True 96 | True -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandAdmin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Rocket.API.Commands; 4 | using Rocket.API.Player; 5 | using Rocket.API.User; 6 | using Rocket.Core.Commands; 7 | using Rocket.Core.Player; 8 | using Rocket.Core.User; 9 | using Rocket.Unturned.Player; 10 | 11 | namespace Rocket.Unturned.Commands 12 | { 13 | public class CommandAdmin : ICommand 14 | { 15 | public async Task ExecuteAsync(ICommandContext context) 16 | { 17 | if(context.Parameters.Length != 1) 18 | throw new CommandWrongUsageException(); 19 | 20 | IPlayer target = await context.Parameters.GetAsync(0); 21 | 22 | if (target.IsOnline && target is UnturnedPlayer uPlayer && !uPlayer.IsAdmin) 23 | { 24 | uPlayer.SetAdmin(true); 25 | return; 26 | } 27 | 28 | await context.User.SendMessageAsync($"Could not admin {target.User.DisplayName}." , ConsoleColor.Red); 29 | } 30 | 31 | public bool SupportsUser(IUser user) => true; 32 | 33 | public string Name => "Admin"; 34 | public string Summary => "Gives admin to a player."; 35 | public string Description => null; 36 | public string Syntax => ""; 37 | public IChildCommand[] ChildCommands => null; 38 | public string[] Aliases => null; 39 | } 40 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandBroadcast.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using System.Drawing; 3 | using Rocket.API.Commands; 4 | using Rocket.API.Player; 5 | using Rocket.API.User; 6 | using Rocket.Core.Commands; 7 | using Rocket.Unturned.Player; 8 | 9 | namespace Rocket.Unturned.Commands 10 | { 11 | public class CommandBroadcast : ICommand 12 | { 13 | public bool SupportsUser(IUser user) => user is UnturnedUser; 14 | 15 | public async Task ExecuteAsync(ICommandContext context) 16 | { 17 | if (!(context.Container.Resolve("unturned") is UnturnedPlayerManager playerManager)) 18 | return; 19 | 20 | string colorName = await context.Parameters.GetAsync(0); 21 | 22 | Color? color = playerManager.GetColorFromName(colorName); 23 | 24 | int i = 1; 25 | if (color == null) i = 0; 26 | string message = await context.Parameters.GetAsync(i); 27 | 28 | if (message == null) 29 | throw new CommandWrongUsageException(); 30 | 31 | await playerManager.BroadcastAsync(null, message, color ?? Color.Green); 32 | } 33 | 34 | public string Name => "Broadcast"; 35 | public string Summary => "Broadcasts a message."; 36 | public string Description => null; 37 | public string Permission => "Rocket.Unturned.Broadcast"; 38 | public string Syntax => "[color] "; 39 | public IChildCommand[] ChildCommands => null; 40 | public string[] Aliases => null; 41 | } 42 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandCompass.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API; 2 | using Rocket.API.Commands; 3 | using Rocket.API.Player; 4 | using Rocket.API.User; 5 | using Rocket.Core.Commands; 6 | using Rocket.Core.I18N; 7 | using Rocket.Unturned.Player; 8 | using System.Threading.Tasks; 9 | 10 | namespace Rocket.Unturned.Commands 11 | { 12 | public class CommandCompass : ICommand 13 | { 14 | public bool SupportsUser(IUser user) => user is UnturnedUser; 15 | 16 | public async Task ExecuteAsync(ICommandContext context) 17 | { 18 | UnturnedUser user = (UnturnedUser)context.User; 19 | 20 | var translations = ((RocketUnturnedHost)context.Container.Resolve()).ModuleTranslations; 21 | 22 | var player = ((UnturnedUser)context.User).Player; 23 | float currentDirection = player.Entity.Rotation; 24 | 25 | string targetDirection = context.Parameters.Length > 0 ? await context.Parameters.GetAsync(0) : null; 26 | 27 | if (targetDirection != null) 28 | { 29 | switch (targetDirection.ToLowerInvariant()) 30 | { 31 | case "north": 32 | currentDirection = 0; 33 | break; 34 | case "east": 35 | currentDirection = 90; 36 | break; 37 | case "south": 38 | currentDirection = 180; 39 | break; 40 | case "west": 41 | currentDirection = 270; 42 | break; 43 | default: 44 | throw new CommandWrongUsageException(); 45 | } 46 | 47 | player.Entity.Teleport(player.Entity.Position, currentDirection); 48 | } 49 | 50 | string directionName = "Unknown"; 51 | 52 | if (currentDirection > 30 && currentDirection < 60) 53 | { 54 | directionName = await translations.GetAsync("command_compass_northeast"); 55 | } 56 | else if (currentDirection > 60 && currentDirection < 120) 57 | { 58 | directionName = await translations.GetAsync("command_compass_east"); 59 | } 60 | else if (currentDirection > 120 && currentDirection < 150) 61 | { 62 | directionName = await translations.GetAsync("command_compass_southeast"); 63 | } 64 | else if (currentDirection > 150 && currentDirection < 210) 65 | { 66 | directionName = await translations.GetAsync("command_compass_south"); 67 | } 68 | else if (currentDirection > 210 && currentDirection < 240) 69 | { 70 | directionName = await translations.GetAsync("command_compass_southwest"); 71 | } 72 | else if (currentDirection > 240 && currentDirection < 300) 73 | { 74 | directionName = await translations.GetAsync("command_compass_west"); 75 | } 76 | else if (currentDirection > 300 && currentDirection < 330) 77 | { 78 | directionName = await translations.GetAsync("command_compass_northwest"); 79 | } 80 | else if (currentDirection > 330 || currentDirection < 30) 81 | { 82 | directionName = await translations.GetAsync("command_compass_north"); 83 | } 84 | 85 | await user.SendLocalizedMessageAsync(translations, "command_compass_facing_private", null, directionName); 86 | } 87 | 88 | public string Name => "Compass"; 89 | public string Summary => "Shows the direction you are facing."; 90 | public string Description => null; 91 | public string Permission => "Rocket.Unturned.Compass"; 92 | public string Syntax => "[direction]"; 93 | public IChildCommand[] ChildCommands => null; 94 | public string[] Aliases => null; 95 | } 96 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Rocket.API.Commands; 4 | using Rocket.API.Player; 5 | using Rocket.API.User; 6 | using Rocket.Core.Commands; 7 | using Rocket.Unturned.Player; 8 | 9 | namespace Rocket.Unturned.Commands 10 | { 11 | public class CommandEffect : ICommand 12 | { 13 | public bool SupportsUser(IUser user) => user is UnturnedUser; 14 | 15 | public async Task ExecuteAsync(ICommandContext context) 16 | { 17 | if(context.Parameters.Length != 1) 18 | throw new CommandWrongUsageException(); 19 | 20 | ushort id = await context.Parameters.GetAsync(0); 21 | 22 | var player = ((UnturnedUser)context.User).Player; 23 | player.TriggerEffect(id); 24 | } 25 | 26 | public string Name => "Effect"; 27 | public string Summary => "Triggers an effect at your position."; 28 | public string Description => null; 29 | public string Permission => "Rocket.Unturned.Effect"; 30 | public string Syntax => ""; 31 | public IChildCommand[] ChildCommands => null; 32 | public string[] Aliases => null; 33 | } 34 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandExit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Rocket.API.Commands; 4 | using Rocket.API.Player; 5 | using Rocket.API.User; 6 | using Rocket.Unturned.Player; 7 | 8 | namespace Rocket.Unturned.Commands 9 | { 10 | public class CommandExit : ICommand 11 | { 12 | public bool SupportsUser(IUser user) => user is UnturnedUser; 13 | 14 | public async Task ExecuteAsync(ICommandContext context) 15 | { 16 | var playerManager = context.Container.Resolve(); 17 | await playerManager.KickAsync(context.User, context.User, "Exit"); 18 | } 19 | 20 | public string Name => "Exit"; 21 | public string Summary => "Exits the game without cooldown."; 22 | public string Description => null; 23 | public string Permission => "Rocket.Unturned.Exit"; 24 | public string Syntax => ""; 25 | public IChildCommand[] ChildCommands => null; 26 | public string[] Aliases => null; 27 | } 28 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandHeal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Rocket.API; 4 | using Rocket.API.Commands; 5 | using Rocket.API.I18N; 6 | using Rocket.API.Permissions; 7 | using Rocket.API.Player; 8 | using Rocket.API.User; 9 | using Rocket.Core.I18N; 10 | using Rocket.Core.Player; 11 | using Rocket.Core.User; 12 | using Rocket.Unturned.Player; 13 | 14 | namespace Rocket.Unturned.Commands 15 | { 16 | public class CommandHeal : ICommand 17 | { 18 | public bool SupportsUser(IUser user) => user is UnturnedUser; 19 | 20 | public async Task ExecuteAsync(ICommandContext context) 21 | { 22 | IPermissionChecker permissions = context.Container.Resolve(); 23 | ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve()).ModuleTranslations; 24 | 25 | IPlayer target; 26 | if (await permissions.CheckPermissionAsync(context.User, Permission + ".Others") == PermissionResult.Grant 27 | && context.Parameters.Length >= 1) 28 | target = await context.Parameters.GetAsync(0); 29 | else 30 | target = ((UnturnedUser)context.User).Player; 31 | 32 | if (!(target is UnturnedPlayer uPlayer)) 33 | { 34 | await context.User.SendMessageAsync($"Could not heal {target.User.DisplayName}", ConsoleColor.Red); 35 | return; 36 | } 37 | 38 | uPlayer.Entity.Heal(100); 39 | uPlayer.Entity.Bleeding = false; 40 | uPlayer.Entity.Broken = false; 41 | uPlayer.Entity.Infection = 0; 42 | uPlayer.Entity.Hunger = 0; 43 | uPlayer.Entity.Thirst = 0; 44 | 45 | if (target == context.User) 46 | { 47 | await context.User.SendLocalizedMessageAsync(translations, "command_heal_success"); 48 | return; 49 | } 50 | 51 | await context.User.SendLocalizedMessageAsync(translations, "command_heal_success_me", null, target.User.DisplayName); 52 | await target.User.SendLocalizedMessageAsync(translations, "command_heal_success_other", null, context.User.DisplayName); 53 | } 54 | 55 | public string Name => "Heal"; 56 | public string Summary => "Heals yourself or somebody else."; 57 | public string Description => null; 58 | public string Permission => "Rocket.Unturned.Heal"; 59 | public string Syntax => "[player]"; 60 | public IChildCommand[] ChildCommands => null; 61 | public string[] Aliases => null; 62 | } 63 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandHome.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Rocket.API; 4 | using Rocket.API.Commands; 5 | using Rocket.API.I18N; 6 | using Rocket.API.User; 7 | using Rocket.Core.Commands; 8 | using Rocket.UnityEngine.Extensions; 9 | using Rocket.Unturned.Player; 10 | using SDG.Unturned; 11 | using UnityEngine; 12 | 13 | namespace Rocket.Unturned.Commands 14 | { 15 | public class CommandHome : ICommand 16 | { 17 | public bool SupportsUser(IUser user) => user is UnturnedUser; 18 | 19 | public async Task ExecuteAsync(ICommandContext context) 20 | { 21 | UnturnedPlayer player = ((UnturnedUser)context.User).Player; 22 | 23 | ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve()).ModuleTranslations; 24 | 25 | if (!BarricadeManager.tryGetBed(player.CSteamID, out Vector3 pos, out byte rot)) 26 | { 27 | throw new CommandWrongUsageException(await translations.GetAsync("command_bed_no_bed_found_private")); 28 | } 29 | 30 | if (player.Entity.Stance == EPlayerStance.DRIVING || player.Entity.Stance == EPlayerStance.SITTING) 31 | { 32 | throw new CommandWrongUsageException(await translations.GetAsync("command_generic_teleport_while_driving_error")); 33 | } 34 | 35 | player.Entity.Teleport(pos.ToSystemVector(), rot); 36 | } 37 | 38 | public string Name => "Home"; 39 | public string Summary => "Teleports you to your last bed."; 40 | public string Description => null; 41 | public string Permission => "Rocket.Unturned.Home"; 42 | public string Syntax => ""; 43 | public IChildCommand[] ChildCommands => null; 44 | public string[] Aliases => null; 45 | } 46 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandInvestigate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Rocket.API; 4 | using Rocket.API.Commands; 5 | using Rocket.API.I18N; 6 | using Rocket.API.Player; 7 | using Rocket.API.User; 8 | using Rocket.Core.Commands; 9 | using Rocket.Core.User; 10 | using Rocket.Unturned.Player; 11 | using SDG.Unturned; 12 | 13 | namespace Rocket.Unturned.Commands 14 | { 15 | public class CommandInvestigate : ICommand 16 | { 17 | public bool SupportsUser(IUser user) => user is UnturnedUser; 18 | 19 | public async Task ExecuteAsync(ICommandContext context) 20 | { 21 | ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve()).ModuleTranslations; 22 | 23 | if (context.Parameters.Length != 1) 24 | { 25 | throw new CommandWrongUsageException(); 26 | } 27 | 28 | UnturnedPlayer target = (UnturnedPlayer) await context.Parameters.GetAsync(0); 29 | 30 | SteamPlayer otherPlayer = target.SteamPlayer; 31 | await context.User.SendMessageAsync(await translations.GetAsync("command_investigate_private", otherPlayer.playerID.characterName, otherPlayer.playerID.steamID.ToString())); 32 | } 33 | 34 | public string Name => "Investigate"; 35 | public string Summary => "Shows you the SteamID64 of a player."; 36 | public string Description => null; 37 | public string Permission => "Rocket.Unturned.Investigate"; 38 | public string Syntax => ""; 39 | public IChildCommand[] ChildCommands => null; 40 | public string[] Aliases => null; 41 | } 42 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Rocket.API; 6 | using Rocket.API.Commands; 7 | using Rocket.API.I18N; 8 | using Rocket.API.User; 9 | using Rocket.Core.Commands; 10 | using Rocket.Core.I18N; 11 | using Rocket.Unturned.Player; 12 | using SDG.Unturned; 13 | 14 | namespace Rocket.Unturned.Commands 15 | { 16 | public class CommandItem : ICommand 17 | { 18 | public bool SupportsUser(IUser user) => user is UnturnedUser; 19 | 20 | public async Task ExecuteAsync(ICommandContext context) 21 | { 22 | ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve()).ModuleTranslations; 23 | 24 | UnturnedPlayer player = ((UnturnedUser)context.User).Player; 25 | if (context.Parameters.Length != 1 && context.Parameters.Length != 2) 26 | throw new CommandWrongUsageException(); 27 | 28 | byte amount = 1; 29 | 30 | string itemString = await context.Parameters.GetAsync(0); 31 | 32 | if (!ushort.TryParse(itemString, out ushort id)) 33 | { 34 | List sortedAssets = new List(Assets.find(EAssetType.ITEM).Cast()); 35 | ItemAsset asset = sortedAssets.Where(i => i.itemName != null) 36 | .OrderBy(i => i.itemName.Length) 37 | .FirstOrDefault(i => i.itemName.ToLower().Contains(itemString.ToLower())); 38 | 39 | if (asset != null) id = asset.id; 40 | if (string.IsNullOrEmpty(itemString.Trim()) || id == 0) 41 | throw new CommandWrongUsageException(); 42 | } 43 | 44 | Asset a = Assets.find(EAssetType.ITEM, id); 45 | 46 | if(a == null) 47 | throw new CommandWrongUsageException(); 48 | 49 | if (context.Parameters.Length == 2) 50 | amount = await context.Parameters.GetAsync(1); 51 | 52 | string assetName = ((ItemAsset)a).itemName; 53 | 54 | await context.User.SendLocalizedMessageAsync(translations, player.GiveItem(id, amount) ? "command_i_giving_private" : "command_i_giving_failed_private", 55 | null, amount, assetName, id); 56 | } 57 | 58 | public string Name => "Item"; 59 | public string Summary => "Gives yourself an item."; 60 | public string Description => null; 61 | public string Permission => "Rocket.Unturned.Item"; 62 | public string Syntax => "[item id or name]"; 63 | public IChildCommand[] ChildCommands => null; 64 | public string[] Aliases => new[] { "I" }; 65 | } 66 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandMore.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Rocket.API; 4 | using Rocket.API.Commands; 5 | using Rocket.API.I18N; 6 | using Rocket.API.User; 7 | using Rocket.Core.Commands; 8 | using Rocket.Core.I18N; 9 | using Rocket.Unturned.Player; 10 | 11 | namespace Rocket.Unturned.Commands 12 | { 13 | public class CommandMore : ICommand 14 | { 15 | public bool SupportsUser(IUser user) => user is UnturnedUser; 16 | 17 | public async Task ExecuteAsync(ICommandContext context) 18 | { 19 | ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve()).ModuleTranslations; 20 | 21 | if(context.Parameters.Length != 1) 22 | throw new CommandWrongUsageException(); 23 | 24 | byte amount = await context.Parameters.GetAsync(0); 25 | 26 | UnturnedPlayer player = ((UnturnedUser)context.User).Player; 27 | ushort itemId = player.NativePlayer.equipment.itemID; 28 | 29 | if (itemId == 0) 30 | { 31 | await context.User.SendLocalizedMessageAsync(translations, "command_more_dequipped"); 32 | return; 33 | } 34 | 35 | await context.User.SendLocalizedMessageAsync(translations, "command_more_give", null, amount, itemId); 36 | player.GiveItem(itemId, amount); 37 | } 38 | 39 | public string Name => "More"; 40 | public string Summary => "Gives more of an item that you have in your hands."; 41 | public string Description => null; 42 | public string Permission => "Rocket.Unturned.More"; 43 | public string Syntax => ""; 44 | public IChildCommand[] ChildCommands => null; 45 | public string[] Aliases => null; 46 | } 47 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandTp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Threading.Tasks; 4 | using Rocket.API; 5 | using Rocket.API.Commands; 6 | using Rocket.API.I18N; 7 | using Rocket.API.Player; 8 | using Rocket.API.User; 9 | using Rocket.Core.Commands; 10 | using Rocket.Core.I18N; 11 | using Rocket.UnityEngine.Extensions; 12 | using Rocket.Unturned.Player; 13 | using SDG.Unturned; 14 | using UnityEngine; 15 | 16 | namespace Rocket.Unturned.Commands 17 | { 18 | public class CommandTp : ICommand 19 | { 20 | public bool SupportsUser(IUser user) => user is UnturnedUser; 21 | public async Task ExecuteAsync(ICommandContext context) 22 | { 23 | ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve()).ModuleTranslations; 24 | 25 | UnturnedPlayer player = ((UnturnedUser)context.User).Player; 26 | 27 | if (context.Parameters.Length != 1 && context.Parameters.Length != 3) 28 | throw new CommandWrongUsageException(); 29 | 30 | if (player.Entity.Stance == EPlayerStance.DRIVING || player.Entity.Stance == EPlayerStance.SITTING) 31 | throw new CommandWrongUsageException( 32 | await translations.GetAsync("command_generic_teleport_while_driving_error")); 33 | 34 | float? x = null; 35 | float? y = null; 36 | float? z = null; 37 | 38 | if (context.Parameters.Length == 3) 39 | { 40 | x = await context.Parameters.GetAsync(0); 41 | y = await context.Parameters.GetAsync(1); 42 | z = await context.Parameters.GetAsync(2); 43 | } 44 | 45 | if (x != null) 46 | { 47 | player.Entity.Teleport(new System.Numerics.Vector3((float)x, (float)y, (float)z)); 48 | await context.User.SendLocalizedMessageAsync(translations, "command_tp_teleport_private", null, (float)x + "," + (float)y + "," + (float)z); 49 | return; 50 | } 51 | 52 | if (await context.Parameters.GetAsync(0) is UnturnedPlayer otherplayer && otherplayer != player) 53 | { 54 | player.Entity.Teleport(otherplayer); 55 | await context.User.SendLocalizedMessageAsync(translations, "command_tp_teleport_private", null, otherplayer.CharacterName); 56 | return; 57 | } 58 | 59 | Node item = LevelNodes.nodes.FirstOrDefault(n => n.type == ENodeType.LOCATION && ((LocationNode)n).name.ToLower().Contains((context.Parameters.GetAsync(0).GetAwaiter().GetResult()).ToLower())); 60 | if (item != null) 61 | { 62 | Vector3 c = item.point + new Vector3(0f, 0.5f, 0f); 63 | player.Entity.Teleport(c.ToSystemVector()); 64 | await context.User.SendLocalizedMessageAsync(translations, "command_tp_teleport_private", null, ((LocationNode)item).name); 65 | return; 66 | } 67 | 68 | await context.User.SendLocalizedMessageAsync(translations, "command_tp_failed_find_destination"); 69 | } 70 | 71 | public string Name => "Tp"; 72 | public string Summary => "Teleports you to another player or location."; 73 | public string Description => null; 74 | public string Permission => "Rocket.Unturned.Tp"; 75 | public string Syntax => ""; 76 | public IChildCommand[] ChildCommands => null; 77 | public string[] Aliases => null; 78 | } 79 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandTphere.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Rocket.API; 4 | using Rocket.API.Commands; 5 | using Rocket.API.I18N; 6 | using Rocket.API.Player; 7 | using Rocket.API.User; 8 | using Rocket.Core.Commands; 9 | using Rocket.Core.I18N; 10 | using Rocket.Unturned.Player; 11 | 12 | namespace Rocket.Unturned.Commands 13 | { 14 | public class CommandTphere : ICommand 15 | { 16 | public bool SupportsUser(IUser user) => user is UnturnedUser; 17 | 18 | public async Task ExecuteAsync(ICommandContext context) 19 | { 20 | ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve()).ModuleTranslations; 21 | 22 | UnturnedPlayer player = ((UnturnedUser)context.User).Player; 23 | 24 | if (context.Parameters.Length != 1) 25 | { 26 | throw new CommandWrongUsageException(); 27 | } 28 | 29 | UnturnedPlayer otherPlayer = (UnturnedPlayer) await context.Parameters.GetAsync(0); 30 | 31 | if (otherPlayer.IsInVehicle) 32 | { 33 | await context.User.SendLocalizedMessageAsync(translations, "command_tphere_vehicle"); 34 | return; 35 | } 36 | 37 | otherPlayer.Entity.Teleport(player); 38 | await context.User.SendLocalizedMessageAsync(translations, "command_tphere_teleport_from_private", null, otherPlayer.CharacterName); 39 | await otherPlayer.User.SendLocalizedMessageAsync(translations, "command_tphere_teleport_to_private", null, player.CharacterName); 40 | } 41 | 42 | public string Name => "Tphere"; 43 | public string Summary => "Teleports another player to you."; 44 | public string Description => null; 45 | public string Permission => "Rocket.Unturned.Tphere"; 46 | public string Syntax => ""; 47 | public IChildCommand[] ChildCommands => null; 48 | public string[] Aliases => null; 49 | } 50 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandUnadmin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.Design; 3 | using System.Threading.Tasks; 4 | using Rocket.API.Commands; 5 | using Rocket.API.Player; 6 | using Rocket.API.User; 7 | using Rocket.Core.Commands; 8 | using Rocket.Core.Player; 9 | using Rocket.Core.User; 10 | using Rocket.Unturned.Player; 11 | 12 | namespace Rocket.Unturned.Commands 13 | { 14 | public class CommandUnadmin : ICommand 15 | { 16 | public bool SupportsUser(IUser user) => true; 17 | 18 | public async Task ExecuteAsync(ICommandContext context) 19 | { 20 | if (context.Parameters.Length != 1) 21 | throw new CommandWrongUsageException(); 22 | 23 | IPlayer targetUser = await context.Parameters.GetAsync(0); 24 | 25 | if (targetUser is UnturnedPlayer uPlayer && uPlayer.IsAdmin) 26 | { 27 | uPlayer.SetAdmin(false); 28 | return; 29 | } 30 | 31 | await context.User.SendMessageAsync($"Could not unadmin {targetUser.User.DisplayName}.", ConsoleColor.Red); 32 | } 33 | 34 | public string Name => "Unadmin"; 35 | public string Summary => "Removes admin from a player."; 36 | public string Description => null; 37 | public string Permission => "Rocket.Unturned.Unadmin"; 38 | public string Syntax => ""; 39 | public IChildCommand[] ChildCommands => null; 40 | public string[] Aliases => null; 41 | } 42 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/CommandVehicle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Rocket.API; 4 | using Rocket.API.Commands; 5 | using Rocket.API.I18N; 6 | using Rocket.API.User; 7 | using Rocket.Core.Commands; 8 | using Rocket.Core.I18N; 9 | using Rocket.Unturned.Player; 10 | using SDG.Unturned; 11 | using UnityEngine; 12 | 13 | namespace Rocket.Unturned.Commands 14 | { 15 | public class CommandVehicle : ICommand 16 | { 17 | public bool SupportsUser(IUser user) => user is UnturnedUser; 18 | 19 | public async Task ExecuteAsync(ICommandContext context) 20 | { 21 | ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve()).ModuleTranslations; 22 | 23 | UnturnedPlayer player = ((UnturnedUser)context.User).Player; 24 | 25 | if (context.Parameters.Length != 1) 26 | { 27 | throw new CommandWrongUsageException(); 28 | } 29 | 30 | string param = await context.Parameters.GetAsync(0); 31 | 32 | if (!ushort.TryParse(param, out ushort id)) 33 | { 34 | bool found = false; 35 | Asset[] assets = SDG.Unturned.Assets.find(EAssetType.VEHICLE); 36 | foreach (VehicleAsset ia in assets) 37 | { 38 | if (ia?.vehicleName == null || !ia.vehicleName.ToLower().Contains(param.ToLower())) 39 | continue; 40 | 41 | id = ia.id; 42 | found = true; 43 | break; 44 | } 45 | 46 | if (!found) 47 | throw new CommandWrongUsageException(); 48 | } 49 | 50 | Asset a = Assets.find(EAssetType.VEHICLE, id); 51 | string assetName = ((VehicleAsset)a).vehicleName; 52 | 53 | await context.User.SendLocalizedMessageAsync(translations, VehicleTool.giveVehicle(player.NativePlayer, id) 54 | ? "command_v_giving_private" 55 | : "command_v_giving_failed_private", null, assetName, id); 56 | } 57 | 58 | public string Name => "Vehicle"; 59 | public string Summary => "Gives yourself a vehicle."; 60 | public string Description => null; 61 | public string Permission => "Rocket.Unturned.Vehicle"; 62 | public string Syntax => ""; 63 | public IChildCommand[] ChildCommands => null; 64 | public string[] Aliases => new [] { "V" }; 65 | } 66 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/RocketUnturnedCommandProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Rocket.API; 6 | using Rocket.API.Commands; 7 | using Rocket.Core.DependencyInjection; 8 | using Rocket.Core.Extensions; 9 | 10 | namespace Rocket.Unturned.Commands 11 | { 12 | public class RocketUnturnedCommandProvider : ICommandProvider 13 | { 14 | private readonly IHost rocketUnturned; 15 | 16 | public RocketUnturnedCommandProvider(IHost rocketUnturned) 17 | { 18 | this.rocketUnturned = rocketUnturned; 19 | } 20 | 21 | public ILifecycleObject GetOwner(ICommand command) => rocketUnturned; 22 | public async Task InitAsync() 23 | { 24 | var types = (typeof(RocketUnturnedCommandProvider).Assembly.FindTypes()) 25 | .Where(c => c.GetCustomAttributes(typeof(DontAutoRegisterAttribute), true).Length == 0) 26 | .Where(c => !typeof(IChildCommand).IsAssignableFrom(c)); 27 | 28 | List list = new List(); 29 | foreach (Type type in types) 30 | list.Add((ICommand)Activator.CreateInstance(type, new object[0])); 31 | Commands = list; 32 | } 33 | 34 | public IEnumerable Commands { get; private set; } 35 | public string ServiceName => "Rocket.Unturned"; 36 | } 37 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/VanillaCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Rocket.API.Commands; 6 | using Rocket.API.User; 7 | using Rocket.Core.DependencyInjection; 8 | using Rocket.Unturned.Player; 9 | using SDG.Unturned; 10 | using Steamworks; 11 | 12 | namespace Rocket.Unturned.Commands 13 | { 14 | [DontAutoRegister] 15 | public class VanillaCommand : ICommand 16 | { 17 | public Command NativeCommand { get; } 18 | 19 | public VanillaCommand(Command nativeCommand) 20 | { 21 | NativeCommand = nativeCommand; 22 | } 23 | 24 | public bool SupportsUser(IUser user) => true; 25 | 26 | public async Task ExecuteAsync(ICommandContext context) 27 | { 28 | CSteamID id = CSteamID.Nil; 29 | switch (context.User) 30 | { 31 | case UnturnedUser user: 32 | id = user.Player.NativePlayer.channel.owner.playerID.steamID; 33 | break; 34 | case IConsole _: 35 | id = CSteamID.Nil; 36 | break; 37 | 38 | default: 39 | throw new NotSupportedException(); 40 | } 41 | 42 | Commander.commands.FirstOrDefault(c => c.command == Name)?.check(id, Name, string.Join("/", context.Parameters.ToArray())); 43 | } 44 | 45 | public string Name => NativeCommand.command; 46 | public string Summary => NativeCommand.help; 47 | public string Description => null; 48 | public string Permission => "Unturned." + Name; 49 | public string Syntax => NativeCommand.info.Replace(Name, "").Trim(); 50 | public IChildCommand[] ChildCommands => null; 51 | public string[] Aliases => null; 52 | } 53 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Commands/VanillaCommandProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using Rocket.API; 4 | using Rocket.API.Commands; 5 | using Rocket.Core.ServiceProxies; 6 | using SDG.Unturned; 7 | 8 | namespace Rocket.Unturned.Commands 9 | { 10 | [ServicePriority(Priority = ServicePriority.Low)] //any other command provider should override it 11 | public class VanillaCommandProvider : ICommandProvider 12 | { 13 | private readonly IHost rocketUnturned; 14 | 15 | public VanillaCommandProvider(IHost rocketUnturned) 16 | { 17 | this.rocketUnturned = rocketUnturned; 18 | } 19 | 20 | private List commands; 21 | 22 | public ILifecycleObject GetOwner(ICommand command) => rocketUnturned; 23 | 24 | public async Task InitAsync() 25 | { 26 | 27 | } 28 | 29 | public void Init() 30 | { 31 | 32 | } 33 | 34 | public IEnumerable Commands 35 | { 36 | get 37 | { 38 | if (commands != null && commands.Count != 0) 39 | return commands; 40 | 41 | commands = new List(); 42 | 43 | foreach (var cmd in Commander.commands) 44 | commands.Add(new VanillaCommand(cmd)); 45 | 46 | return commands; 47 | } 48 | } 49 | 50 | public string ServiceName => "Unturned"; 51 | } 52 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Console/UnturnedConsolePipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading; 4 | using Rocket.Core.Logging; 5 | using SDG.Unturned; 6 | using UnityEngine; 7 | using ILogger = Rocket.API.Logging.ILogger; 8 | 9 | namespace Rocket.Unturned.Console 10 | { 11 | public class UnturnedConsolePipe : MonoBehaviour 12 | { 13 | public ILogger Logger { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Rocket.Unturned/Console/UnturnedConsoleWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | namespace Rocket.Unturned.Console 6 | { 7 | public class UnturnedConsoleWriter : TextWriter 8 | { 9 | private readonly TextWriter consoleOutput; 10 | private readonly TextWriter consoleError; 11 | 12 | private readonly StreamWriter streamWriter; 13 | 14 | public UnturnedConsoleWriter(StreamWriter streamWriter) 15 | { 16 | this.streamWriter = streamWriter; 17 | consoleOutput = System.Console.Out; 18 | consoleError = System.Console.Error; 19 | 20 | System.Console.SetOut(this); 21 | System.Console.SetError(this); 22 | } 23 | 24 | public override Encoding Encoding => consoleOutput.Encoding; 25 | public override IFormatProvider FormatProvider => consoleOutput.FormatProvider; 26 | 27 | public override string NewLine 28 | { 29 | get => consoleOutput.NewLine; 30 | set => consoleOutput.NewLine = value; 31 | } 32 | 33 | public override void Close() 34 | { 35 | consoleOutput.Close(); 36 | streamWriter.Close(); 37 | } 38 | 39 | public override void Flush() 40 | { 41 | consoleOutput.Flush(); 42 | streamWriter.Flush(); 43 | } 44 | 45 | public override void Write(double value) 46 | { 47 | consoleOutput.Write(value); 48 | streamWriter.Write(value); 49 | } 50 | 51 | public override void Write(string value) 52 | { 53 | consoleOutput.Write(value); 54 | streamWriter.Write(value); 55 | } 56 | 57 | public override void Write(object value) 58 | { 59 | consoleOutput.Write(value); 60 | streamWriter.Write(value); 61 | } 62 | 63 | public override void Write(decimal value) 64 | { 65 | consoleOutput.Write(value); 66 | streamWriter.Write(value); 67 | } 68 | 69 | public override void Write(float value) 70 | { 71 | consoleOutput.Write(value); 72 | streamWriter.Write(value); 73 | } 74 | 75 | public override void Write(bool value) 76 | { 77 | consoleOutput.Write(value); 78 | streamWriter.Write(value); 79 | } 80 | 81 | public override void Write(int value) 82 | { 83 | consoleOutput.Write(value); 84 | streamWriter.Write(value); 85 | } 86 | 87 | public override void Write(uint value) 88 | { 89 | consoleOutput.Write(value); 90 | streamWriter.Write(value); 91 | } 92 | 93 | public override void Write(ulong value) 94 | { 95 | consoleOutput.Write(value); 96 | streamWriter.Write(value); 97 | } 98 | 99 | public override void Write(long value) 100 | { 101 | consoleOutput.Write(value); 102 | streamWriter.Write(value); 103 | } 104 | 105 | public override void Write(char[] buffer) 106 | { 107 | consoleOutput.Write(buffer); 108 | streamWriter.Write(buffer); 109 | } 110 | 111 | public override void Write(char value) 112 | { 113 | consoleOutput.Write(value); 114 | streamWriter.Write(value); 115 | } 116 | 117 | public override void Write(string format, params object[] arg) 118 | { 119 | consoleOutput.Write(format, arg); 120 | streamWriter.Write(format, arg); 121 | } 122 | 123 | public override void Write(string format, object arg0) 124 | { 125 | consoleOutput.Write(format, arg0); 126 | streamWriter.Write(format, arg0); 127 | } 128 | 129 | public override void Write(string format, object arg0, object arg1) 130 | { 131 | consoleOutput.Write(format, arg0, arg1); 132 | streamWriter.Write(format, arg0, arg1); 133 | } 134 | 135 | public override void Write(char[] buffer, int index, int count) 136 | { 137 | consoleOutput.Write(buffer, index, count); 138 | streamWriter.Write(buffer, index, count); 139 | } 140 | 141 | public override void Write(string format, object arg0, object arg1, object arg2) 142 | { 143 | consoleOutput.Write(format, arg0, arg1, arg2); 144 | streamWriter.Write(format, arg0, arg1, arg2); 145 | } 146 | 147 | public override void WriteLine() 148 | { 149 | consoleOutput.WriteLine(); 150 | streamWriter.WriteLine(); 151 | } 152 | 153 | public override void WriteLine(double value) 154 | { 155 | consoleOutput.WriteLine(value); 156 | streamWriter.WriteLine(value); 157 | } 158 | 159 | public override void WriteLine(decimal value) 160 | { 161 | consoleOutput.WriteLine(value); 162 | streamWriter.WriteLine(value); 163 | } 164 | 165 | public override void WriteLine(string value) 166 | { 167 | consoleOutput.WriteLine(value); 168 | streamWriter.WriteLine(value); 169 | } 170 | 171 | public override void WriteLine(object value) 172 | { 173 | consoleOutput.WriteLine(value); 174 | streamWriter.WriteLine(value); 175 | } 176 | 177 | public override void WriteLine(float value) 178 | { 179 | consoleOutput.WriteLine(value); 180 | streamWriter.WriteLine(value); 181 | } 182 | 183 | public override void WriteLine(bool value) 184 | { 185 | consoleOutput.WriteLine(value); 186 | streamWriter.WriteLine(value); 187 | } 188 | 189 | public override void WriteLine(uint value) 190 | { 191 | consoleOutput.WriteLine(value); 192 | streamWriter.WriteLine(value); 193 | } 194 | 195 | public override void WriteLine(long value) 196 | { 197 | consoleOutput.WriteLine(value); 198 | streamWriter.WriteLine(value); 199 | } 200 | 201 | public override void WriteLine(ulong value) 202 | { 203 | consoleOutput.WriteLine(value); 204 | streamWriter.WriteLine(value); 205 | } 206 | 207 | public override void WriteLine(int value) 208 | { 209 | consoleOutput.WriteLine(value); 210 | streamWriter.WriteLine(value); 211 | } 212 | 213 | public override void WriteLine(char[] buffer) 214 | { 215 | consoleOutput.WriteLine(buffer); 216 | streamWriter.WriteLine(buffer); 217 | } 218 | 219 | public override void WriteLine(char value) 220 | { 221 | consoleOutput.WriteLine(value); 222 | streamWriter.WriteLine(value); 223 | } 224 | 225 | public override void WriteLine(string format, params object[] arg) 226 | { 227 | consoleOutput.WriteLine(format, arg); 228 | streamWriter.WriteLine(format, arg); 229 | } 230 | 231 | public override void WriteLine(string format, object arg0) 232 | { 233 | consoleOutput.WriteLine(format, arg0); 234 | streamWriter.WriteLine(format, arg0); 235 | } 236 | 237 | public override void WriteLine(string format, object arg0, object arg1) 238 | { 239 | consoleOutput.WriteLine(format, arg0, arg1); 240 | streamWriter.WriteLine(format, arg0, arg1); 241 | } 242 | 243 | public override void WriteLine(char[] buffer, int index, int count) 244 | { 245 | consoleOutput.WriteLine(buffer, index, count); 246 | streamWriter.WriteLine(buffer, index, count); 247 | } 248 | 249 | public override void WriteLine(string format, object arg0, object arg1, object arg2) 250 | { 251 | consoleOutput.WriteLine(format, arg0, arg1, arg2); 252 | streamWriter.WriteLine(format, arg0, arg1, arg2); 253 | } 254 | 255 | protected override void Dispose(bool disposing) 256 | { 257 | if (disposing) 258 | { 259 | System.Console.SetOut(consoleOutput); 260 | System.Console.SetError(consoleError); 261 | } 262 | } 263 | } 264 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Permissions/UnturnedAdminPermissionChecker.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Rocket.API.Permissions; 3 | using Rocket.Core.ServiceProxies; 4 | using Rocket.Unturned.Player; 5 | 6 | namespace Rocket.Unturned.Permissions 7 | { 8 | [ServicePriority(Priority = ServicePriority.Lowest)] 9 | public class UnturnedAdminPermissionChecker : IPermissionChecker 10 | { 11 | public bool SupportsTarget(IPermissionActor target) 12 | { 13 | if (target is UnturnedUser user) 14 | return user.Player.IsAdmin; 15 | 16 | return false; 17 | } 18 | 19 | public Task CheckPermissionAsync(IPermissionActor target, string permission) => Task.FromResult(PermissionResult.Grant); 20 | 21 | public string ServiceName { get; } = "Unturned Admin Checker"; 22 | } 23 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerChatEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.API.User; 4 | using Rocket.Core.Player.Events; 5 | using Rocket.Core.User.Events; 6 | using SDG.Unturned; 7 | using UnityEngine; 8 | 9 | namespace Rocket.Unturned.Player.Events 10 | { 11 | public class UnturnedPlayerChatEvent : PlayerChatEvent 12 | { 13 | public UnturnedPlayer UnturnedPlayer { get; } 14 | public EChatMode Mode { get; } 15 | public Color Color { get; set; } 16 | public bool IsRichText { get; set; } 17 | 18 | public UnturnedPlayerChatEvent(UnturnedPlayer unturnedPlayer, EChatMode mode, Color color, bool isRichText, string message, 19 | bool cancelled) : base(unturnedPlayer, message, EventExecutionTargetContext.Sync) 20 | { 21 | UnturnedPlayer = unturnedPlayer; 22 | Mode = mode; 23 | Color = color; 24 | IsRichText = isRichText; 25 | IsCancelled = cancelled; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerDamagedEvent.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using Rocket.API.Commands; 3 | using Rocket.API.Eventing; 4 | using Rocket.API.Player; 5 | using Rocket.API.User; 6 | using Rocket.Core.Player.Events; 7 | using SDG.Unturned; 8 | using Vector3 = System.Numerics.Vector3; 9 | 10 | namespace Rocket.Unturned.Player.Events 11 | { 12 | public class UnturnedPlayerDamagedEvent : PlayerDamageEvent 13 | { 14 | public EDeathCause DeathCause { get; set; } 15 | public ELimb Limb { get; set; } 16 | public Vector3 Direction { get; set; } 17 | public float Times { get; set; } 18 | 19 | public UnturnedPlayerDamagedEvent(IPlayer player, EDeathCause deathCause, ELimb limb, IUser damageDealer, Vector3 direction, float damage, float times) : base(player, damage, damageDealer) 20 | { 21 | DeathCause = deathCause; 22 | Limb = limb; 23 | Direction = direction; 24 | Damage = damage; 25 | Times = times; 26 | } 27 | public UnturnedPlayerDamagedEvent(IPlayer player, EDeathCause deathCause, ELimb limb, IUser damageDealer, Vector3 direction, float damage, float times, bool global = true) : base(player, damage, damageDealer, global) 28 | { 29 | DeathCause = deathCause; 30 | Limb = limb; 31 | Direction = direction; 32 | Damage = damage; 33 | Times = times; 34 | } 35 | public UnturnedPlayerDamagedEvent(IPlayer player, EDeathCause deathCause, ELimb limb, IUser damageDealer, Vector3 direction, float damage, float times, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, damage, damageDealer, executionTarget, global) 36 | { 37 | DeathCause = deathCause; 38 | Limb = limb; 39 | Direction = direction; 40 | Damage = damage; 41 | Times = times; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerDeadEvent.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using Rocket.API.Eventing; 3 | using Rocket.API.Player; 4 | using Rocket.Core.Player.Events; 5 | 6 | namespace Rocket.Unturned.Player.Events 7 | { 8 | public class UnturnedPlayerDeadEvent : PlayerEvent 9 | { 10 | public System.Numerics.Vector3 Position { get; } 11 | 12 | public UnturnedPlayerDeadEvent(IPlayer player, Vector3 position) : base(player) 13 | { 14 | Position = position; 15 | } 16 | public UnturnedPlayerDeadEvent(IPlayer player, Vector3 position, bool global = true) : base(player, global) 17 | { 18 | Position = position; 19 | } 20 | 21 | public UnturnedPlayerDeadEvent(IPlayer player, System.Numerics.Vector3 position, 22 | EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, 23 | bool global = true) : base(player, executionTarget, global) 24 | { 25 | Position = position; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerDeathEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Entities; 2 | using Rocket.API.Eventing; 3 | using Rocket.API.Player; 4 | using Rocket.Core.Player.Events; 5 | using SDG.Unturned; 6 | 7 | namespace Rocket.Unturned.Player.Events 8 | { 9 | public class UnturnedPlayerDeathEvent : PlayerDeathEvent 10 | { 11 | public ELimb Limb { get; } 12 | public EDeathCause DeathCause { get; } 13 | 14 | public UnturnedPlayerDeathEvent(IPlayer player, ELimb limb, EDeathCause deathCause, IEntity killer = null) : base(player, killer) 15 | { 16 | Limb = limb; 17 | DeathCause = deathCause; 18 | } 19 | public UnturnedPlayerDeathEvent(IPlayer player, ELimb limb, EDeathCause deathCause, IEntity killer = null, bool global = true) : base(player, killer, global) 20 | { 21 | Limb = limb; 22 | DeathCause = deathCause; 23 | } 24 | public UnturnedPlayerDeathEvent(IPlayer player, ELimb limb, EDeathCause deathCause, IEntity killer = null, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, killer, executionTarget, global) 25 | { 26 | Limb = limb; 27 | DeathCause = deathCause; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerPreConnectEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.Core.Player.Events; 3 | using SDG.Unturned; 4 | using Steamworks; 5 | 6 | namespace Rocket.Unturned.Player.Events 7 | { 8 | public class UnturnedPlayerPreConnectEvent : PlayerPreConnectEvent 9 | { 10 | public ValidateAuthTicketResponse_t SteamworksAuthResponse { get; } 11 | 12 | public SteamPending PendingPlayer { get; } 13 | 14 | public ESteamRejection? UnturnedRejectionReason { get; set; } 15 | 16 | public override string RejectionReason => UnturnedRejectionReason?.ToString(); 17 | 18 | public UnturnedPlayerPreConnectEvent(PreConnectUnturnedPlayer player, ValidateAuthTicketResponse_t steamworksAuthResponse) : base(player) 19 | { 20 | SteamworksAuthResponse = steamworksAuthResponse; 21 | PendingPlayer = player.PendingPlayer; 22 | } 23 | public UnturnedPlayerPreConnectEvent(PreConnectUnturnedPlayer player, ValidateAuthTicketResponse_t steamworksAuthResponse, bool global = true) : base(player, global) 24 | { 25 | SteamworksAuthResponse = steamworksAuthResponse; 26 | PendingPlayer = player.PendingPlayer; 27 | } 28 | public UnturnedPlayerPreConnectEvent(PreConnectUnturnedPlayer player, ValidateAuthTicketResponse_t steamworksAuthResponse, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 29 | { 30 | SteamworksAuthResponse = steamworksAuthResponse; 31 | PendingPlayer = player.PendingPlayer; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerUpdateBleedingEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.Core.Player.Events; 4 | 5 | namespace Rocket.Unturned.Player.Events 6 | { 7 | public class UnturnedPlayerUpdateBleedingEvent : PlayerEvent 8 | { 9 | public bool IsBleeding { get; } 10 | public UnturnedPlayerUpdateBleedingEvent(IPlayer player, bool isBleeding) : base(player) 11 | { 12 | IsBleeding = isBleeding; 13 | } 14 | public UnturnedPlayerUpdateBleedingEvent(IPlayer player, bool isBleeding, bool global = true) : base(player, global) 15 | { 16 | IsBleeding = isBleeding; 17 | } 18 | public UnturnedPlayerUpdateBleedingEvent(IPlayer player, bool isBleeding, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 19 | { 20 | IsBleeding = isBleeding; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerUpdateBrokenEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.Core.Player.Events; 4 | 5 | namespace Rocket.Unturned.Player.Events 6 | { 7 | public class UnturnedPlayerUpdateBrokenEvent : PlayerEvent 8 | { 9 | public bool IsBroken { get; } 10 | public UnturnedPlayerUpdateBrokenEvent(IPlayer player, bool isBroken) : base(player) 11 | { 12 | IsBroken = isBroken; 13 | } 14 | public UnturnedPlayerUpdateBrokenEvent(IPlayer player, bool isBroken, bool global = true) : base(player, global) 15 | { 16 | IsBroken = isBroken; 17 | } 18 | public UnturnedPlayerUpdateBrokenEvent(IPlayer player, bool isBroken, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 19 | { 20 | IsBroken = isBroken; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerUpdateExperienceEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.Core.Player.Events; 4 | 5 | namespace Rocket.Unturned.Player.Events 6 | { 7 | public class UnturnedPlayerUpdateExperienceEvent : PlayerEvent 8 | { 9 | public uint Experience { get; } 10 | public UnturnedPlayerUpdateExperienceEvent(IPlayer player, uint experience) : base(player) 11 | { 12 | Experience = experience; 13 | } 14 | public UnturnedPlayerUpdateExperienceEvent(IPlayer player, uint experience, bool global = true) : base(player, global) 15 | { 16 | Experience = experience; 17 | } 18 | public UnturnedPlayerUpdateExperienceEvent(IPlayer player, uint experience, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 19 | { 20 | Experience = experience; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerUpdateFoodEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.Core.Player.Events; 4 | 5 | namespace Rocket.Unturned.Player.Events 6 | { 7 | public class UnturnedPlayerUpdateFoodEvent : PlayerEvent 8 | { 9 | public byte Food { get; } 10 | public UnturnedPlayerUpdateFoodEvent(IPlayer player, byte food) : base(player) 11 | { 12 | Food = food; 13 | } 14 | public UnturnedPlayerUpdateFoodEvent(IPlayer player, byte food, bool global = true) : base(player, global) 15 | { 16 | Food = food; 17 | } 18 | public UnturnedPlayerUpdateFoodEvent(IPlayer player, byte food, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 19 | { 20 | Food = food; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerUpdateGestureEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.Core.Player.Events; 4 | using SDG.Unturned; 5 | 6 | namespace Rocket.Unturned.Player.Events 7 | { 8 | public class UnturnedPlayerUpdateGestureEvent : PlayerEvent 9 | { 10 | public EPlayerGesture Gesture { get; } 11 | public UnturnedPlayerUpdateGestureEvent(IPlayer player, EPlayerGesture gesture) : base(player) 12 | { 13 | Gesture = gesture; 14 | } 15 | public UnturnedPlayerUpdateGestureEvent(IPlayer player, EPlayerGesture gesture, bool global = true) : base(player, global) 16 | { 17 | Gesture = gesture; 18 | } 19 | public UnturnedPlayerUpdateGestureEvent(IPlayer player, EPlayerGesture gesture, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 20 | { 21 | Gesture = gesture; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerUpdateHealthEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.Core.Player.Events; 4 | 5 | namespace Rocket.Unturned.Player.Events 6 | { 7 | public class UnturnedPlayerUpdateHealthEvent : PlayerEvent 8 | { 9 | public byte Health { get; } 10 | public UnturnedPlayerUpdateHealthEvent(IPlayer player, byte health) : base(player) 11 | { 12 | Health = health; 13 | } 14 | public UnturnedPlayerUpdateHealthEvent(IPlayer player, byte health, bool global = true) : base(player, global) 15 | { 16 | Health = health; 17 | } 18 | public UnturnedPlayerUpdateHealthEvent(IPlayer player, byte health, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 19 | { 20 | Health = health; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerUpdateLifeEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.Core.Player.Events; 4 | 5 | namespace Rocket.Unturned.Player.Events 6 | { 7 | public class UnturnedPlayerUpdateLifeEvent : PlayerEvent 8 | { 9 | public byte Life { get; } 10 | public UnturnedPlayerUpdateLifeEvent(IPlayer player, byte life) : base(player) 11 | { 12 | Life = life; 13 | } 14 | public UnturnedPlayerUpdateLifeEvent(IPlayer player, byte life, bool global = true) : base(player, global) 15 | { 16 | Life = life; 17 | } 18 | public UnturnedPlayerUpdateLifeEvent(IPlayer player, byte life, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 19 | { 20 | Life = life; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerUpdateStanceEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.Core.Player.Events; 4 | using SDG.Unturned; 5 | 6 | namespace Rocket.Unturned.Player.Events 7 | { 8 | public class UnturnedPlayerUpdateStanceEvent : PlayerEvent 9 | { 10 | public EPlayerStance Stance { get; } 11 | public UnturnedPlayerUpdateStanceEvent(IPlayer player, EPlayerStance stance) : base(player) 12 | { 13 | Stance = stance; 14 | } 15 | public UnturnedPlayerUpdateStanceEvent(IPlayer player, EPlayerStance stance, bool global = true) : base(player, global) 16 | { 17 | Stance = stance; 18 | } 19 | public UnturnedPlayerUpdateStanceEvent(IPlayer player, EPlayerStance stance, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 20 | { 21 | Stance = stance; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerUpdateStatEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.Core.Player.Events; 4 | using SDG.Unturned; 5 | 6 | namespace Rocket.Unturned.Player.Events 7 | { 8 | public class UnturnedPlayerUpdateStatEvent : PlayerEvent 9 | { 10 | public EPlayerStat Stat { get; } 11 | public UnturnedPlayerUpdateStatEvent(IPlayer player, EPlayerStat stat) : base(player) 12 | { 13 | Stat = stat; 14 | } 15 | public UnturnedPlayerUpdateStatEvent(IPlayer player, EPlayerStat stat, bool global = true) : base(player, global) 16 | { 17 | Stat = stat; 18 | } 19 | public UnturnedPlayerUpdateStatEvent(IPlayer player, EPlayerStat stat, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 20 | { 21 | Stat = stat; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerUpdateVirusEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.Core.Player.Events; 4 | 5 | namespace Rocket.Unturned.Player.Events 6 | { 7 | public class UnturnedPlayerUpdateVirusEvent : PlayerEvent 8 | { 9 | public byte Virus { get; } 10 | public UnturnedPlayerUpdateVirusEvent(IPlayer player, byte virus) : base(player) 11 | { 12 | Virus = virus; 13 | } 14 | public UnturnedPlayerUpdateVirusEvent(IPlayer player, byte virus, bool global = true) : base(player, global) 15 | { 16 | Virus = virus; 17 | } 18 | public UnturnedPlayerUpdateVirusEvent(IPlayer player, byte virus, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 19 | { 20 | Virus = virus; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/Events/UnturnedPlayerUpdateWaterEvent.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.Eventing; 2 | using Rocket.API.Player; 3 | using Rocket.Core.Player.Events; 4 | 5 | namespace Rocket.Unturned.Player.Events 6 | { 7 | public class UnturnedPlayerUpdateWaterEvent : PlayerEvent 8 | { 9 | public byte Water { get; } 10 | public UnturnedPlayerUpdateWaterEvent(IPlayer player, byte water) : base(player) 11 | { 12 | Water = water; 13 | } 14 | public UnturnedPlayerUpdateWaterEvent(IPlayer player, byte water, bool global = true) : base(player, global) 15 | { 16 | Water = water; 17 | } 18 | public UnturnedPlayerUpdateWaterEvent(IPlayer player, byte water, EventExecutionTargetContext executionTarget = EventExecutionTargetContext.Sync, bool global = true) : base(player, executionTarget, global) 19 | { 20 | Water = water; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/PreConnectUnturnedPlayer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Rocket.API.DependencyInjection; 3 | using SDG.Unturned; 4 | using Steamworks; 5 | 6 | namespace Rocket.Unturned.Player 7 | { 8 | public class PreConnectUnturnedPlayer : UnturnedPlayer 9 | { 10 | public SteamPending PendingPlayer { get; } 11 | 12 | public PreConnectUnturnedPlayer(IDependencyContainer container, SteamPending pendingPlayer, UnturnedPlayerManager manager) : base(container, pendingPlayer.playerID.steamID, manager) 13 | { 14 | PendingPlayer = pendingPlayer; 15 | } 16 | 17 | public override bool IsOnline => false; 18 | 19 | public override string ToString(string format, IFormatProvider formatProvider) 20 | { 21 | string f = format; 22 | if (f != null && PendingPlayer != null) 23 | { 24 | string[] subFormats = f.Split(':'); 25 | 26 | f = subFormats[0]; 27 | string subFormat = subFormats.Length > 1 ? subFormats[1] : null; 28 | 29 | if (f.Equals("nick", StringComparison.OrdinalIgnoreCase) 30 | || f.Equals("nickname", StringComparison.OrdinalIgnoreCase)) 31 | { 32 | return PendingPlayer.playerID.nickName.ToString(formatProvider); 33 | } 34 | 35 | if (f.Equals("playername", StringComparison.OrdinalIgnoreCase)) 36 | { 37 | return PendingPlayer.playerID.playerName.ToString(formatProvider); 38 | } 39 | 40 | if (f.Equals("charachtername", StringComparison.OrdinalIgnoreCase)) 41 | { 42 | return PendingPlayer.playerID.characterName.ToString(formatProvider); 43 | } 44 | 45 | if (f.Equals("group", StringComparison.OrdinalIgnoreCase) 46 | || f.Equals("groupname", StringComparison.OrdinalIgnoreCase)) 47 | { 48 | var gid = PendingPlayer.playerID.@group; 49 | if (gid == CSteamID.Nil) 50 | return "no group"; 51 | 52 | GroupInfo group = GroupManager.getGroupInfo(gid); 53 | return group.name.ToString(formatProvider); 54 | } 55 | 56 | 57 | if (f.Equals("groupid", StringComparison.OrdinalIgnoreCase)) 58 | { 59 | var gid = PendingPlayer.playerID.@group; 60 | if (gid == CSteamID.Nil) 61 | return "no group"; 62 | 63 | return gid.m_SteamID.ToString(subFormat, formatProvider); 64 | } 65 | } 66 | 67 | return base.ToString(format, formatProvider); 68 | } 69 | 70 | public override int GetHashCode() 71 | { 72 | return User.Id.GetHashCode(); 73 | } 74 | 75 | public override bool Equals(object o) 76 | { 77 | if (!(o is PreConnectUnturnedPlayer uPlayer)) 78 | return false; 79 | 80 | return uPlayer.GetHashCode() == GetHashCode(); 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/UnturnedIdentity.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API.User; 2 | 3 | namespace Rocket.Unturned.Player { 4 | public class UnturnedIdentity : IIdentity 5 | { 6 | public UnturnedIdentity(ulong id) 7 | { 8 | Id = id.ToString(); 9 | } 10 | 11 | public string Id { get; } 12 | public string IdentityType => "Unturned"; 13 | } 14 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/UnturnedPlayer.cs: -------------------------------------------------------------------------------- 1 | using SDG.Unturned; 2 | using Steamworks; 3 | using System; 4 | using System.Linq; 5 | using Rocket.API.DependencyInjection; 6 | using Rocket.Core.Player; 7 | using Rocket.API.User; 8 | 9 | namespace Rocket.Unturned.Player 10 | { 11 | public class UnturnedPlayer : BasePlayer 12 | { 13 | public override int GetHashCode() 14 | { 15 | return User.Id.GetHashCode(); 16 | } 17 | 18 | public override bool Equals(object o) 19 | { 20 | if (!(o is UnturnedPlayer uPlayer)) 21 | return false; 22 | 23 | return uPlayer.GetHashCode() == GetHashCode(); 24 | } 25 | 26 | 27 | public SDG.Unturned.Player NativePlayer => PlayerTool.getPlayer(CSteamID); 28 | 29 | public SteamPlayer SteamPlayer => NativePlayer?.channel?.owner; 30 | 31 | public string DisplayName => CharacterName; 32 | 33 | public bool IsAdmin => NativePlayer.channel.owner.isAdmin; 34 | 35 | public CSteamID CSteamID { get; } 36 | 37 | private readonly UnturnedPlayerManager manager; 38 | 39 | private readonly IDependencyContainer container; 40 | 41 | public UnturnedPlayer(IDependencyContainer container, SteamPlayer player, UnturnedPlayerManager manager) : this(container, player.playerID.steamID, manager) 42 | { 43 | 44 | } 45 | 46 | public UnturnedPlayer(IDependencyContainer container, CSteamID cSteamID, UnturnedPlayerManager manager) : base(container, manager) 47 | { 48 | this.container = container; 49 | this.manager = manager; 50 | CSteamID = cSteamID; 51 | } 52 | 53 | public float Ping => NativePlayer.channel.owner.ping; 54 | 55 | public override UnturnedUser User 56 | { 57 | get 58 | { 59 | return (UnturnedUser)container.Resolve().GetUserAsync(CSteamID.ToString()).Result; 60 | } 61 | } 62 | 63 | public bool Equals(UnturnedPlayer p) 64 | { 65 | if (p == null) return false; 66 | 67 | return CSteamID.ToString() == p.CSteamID.ToString(); 68 | } 69 | 70 | public T GetComponent() => (T)(object)NativePlayer.GetComponent(typeof(T)); 71 | 72 | public void TriggerEffect(ushort effectID) 73 | { 74 | EffectManager.instance.channel.send("tellEffectPoint", CSteamID, ESteamPacket.UPDATE_UNRELIABLE_BUFFER, 75 | effectID, NativePlayer.transform.position); 76 | } 77 | 78 | public string RemoteAddress 79 | { 80 | get 81 | { 82 | SteamGameServerNetworking.GetP2PSessionState(CSteamID, out P2PSessionState_t state); 83 | return Parser.getIPFromUInt32(state.m_nRemoteIP); 84 | } 85 | } 86 | 87 | public void MaximizeSkills() 88 | { 89 | PlayerSkills skills = NativePlayer.skills; 90 | 91 | foreach (Skill skill in skills.skills.SelectMany(s => s)) skill.level = skill.max; 92 | 93 | skills.askSkills(NativePlayer.channel.owner.playerID.steamID); 94 | } 95 | 96 | public string SteamGroupName 97 | { 98 | get 99 | { 100 | { 101 | FriendsGroupID_t id; 102 | id.m_FriendsGroupID = (short)SteamGroupID.m_SteamID; 103 | return SteamFriends.GetFriendsGroupName(id); 104 | } 105 | } 106 | } 107 | 108 | public int SteamGroupMembersCount 109 | { 110 | get 111 | { 112 | FriendsGroupID_t id; 113 | id.m_FriendsGroupID = (short)SteamGroupID.m_SteamID; 114 | return SteamFriends.GetFriendsGroupMembersCount(id); 115 | } 116 | } 117 | 118 | public PlayerInventory Inventory => NativePlayer.inventory; 119 | 120 | public bool GiveItem(ushort itemId, byte amount) => ItemTool.tryForceGiveItem(NativePlayer, itemId, amount); 121 | 122 | public bool GiveItem(Item item) => NativePlayer.inventory.tryAddItem(item, false); 123 | 124 | public bool GiveVehicle(ushort vehicleId) => VehicleTool.giveVehicle(NativePlayer, vehicleId); 125 | 126 | public CSteamID SteamGroupID => NativePlayer.channel.owner.playerID.group; 127 | 128 | public void SetAdmin(bool isAdmin) 129 | { 130 | SetAdmin(isAdmin, null); 131 | } 132 | 133 | public void SetAdmin(bool isAdmin, UnturnedPlayer issuer) 134 | { 135 | if (isAdmin) 136 | SteamAdminlist.admin(CSteamID, issuer?.CSteamID ?? new CSteamID(0)); 137 | else 138 | SteamAdminlist.unadmin(NativePlayer.channel.owner.playerID.steamID); 139 | } 140 | 141 | public string CharacterName => NativePlayer.channel.owner.playerID.characterName; 142 | 143 | public string SteamName => NativePlayer.channel.owner.playerID.playerName; 144 | 145 | public bool IsPro => NativePlayer.channel.owner.isPro; 146 | 147 | public InteractableVehicle CurrentVehicle => NativePlayer.movement.getVehicle(); 148 | 149 | public bool IsInVehicle => CurrentVehicle != null; 150 | 151 | public override UnturnedPlayerEntity Entity => new UnturnedPlayerEntity(this); 152 | 153 | public override bool IsOnline => Provider.clients.Any(c => c.playerID.steamID == CSteamID); 154 | 155 | public override DateTime SessionConnectTime => DateTime.Now; 156 | 157 | public override DateTime? SessionDisconnectTime => null; 158 | 159 | public override string ToString(string format, IFormatProvider formatProvider) 160 | { 161 | if (format != null && SteamPlayer != null) 162 | { 163 | string[] subFormats = format.Split(':'); 164 | 165 | format = subFormats[0]; 166 | string subFormat = subFormats.Length > 1 ? subFormats[1] : null; 167 | 168 | if (format.Equals("nick", StringComparison.OrdinalIgnoreCase) 169 | || format.Equals("nickname", StringComparison.OrdinalIgnoreCase)) 170 | { 171 | return SteamPlayer.playerID.nickName.ToString(formatProvider); 172 | } 173 | 174 | if (format.Equals("playername", StringComparison.OrdinalIgnoreCase)) 175 | { 176 | return SteamPlayer.playerID.playerName.ToString(formatProvider); 177 | } 178 | 179 | if (format.Equals("charactername", StringComparison.OrdinalIgnoreCase)) 180 | { 181 | return SteamPlayer.playerID.characterName.ToString(formatProvider); 182 | } 183 | 184 | if (format.Equals("group", StringComparison.OrdinalIgnoreCase) 185 | || format.Equals("groupname", StringComparison.OrdinalIgnoreCase)) 186 | { 187 | var gid = SteamPlayer.playerID.@group; 188 | if (gid == CSteamID.Nil) 189 | return "no group"; 190 | 191 | GroupInfo group = GroupManager.getGroupInfo(gid); 192 | return group.name.ToString(formatProvider); 193 | } 194 | 195 | 196 | if (format.Equals("groupid", StringComparison.OrdinalIgnoreCase)) 197 | { 198 | var gid = SteamPlayer.playerID.@group; 199 | if (gid == CSteamID.Nil) 200 | return "no group"; 201 | 202 | return gid.m_SteamID.ToString(subFormat, formatProvider); 203 | } 204 | } 205 | 206 | return base.ToString(format, formatProvider); 207 | } 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /Rocket.Unturned/Player/UnturnedPlayerEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Numerics; 4 | using System.Threading.Tasks; 5 | using Rocket.API.Entities; 6 | using Rocket.API.Player; 7 | using Rocket.API.User; 8 | using Rocket.UnityEngine.Extensions; 9 | using SDG.Unturned; 10 | using Steamworks; 11 | using Vector3 = UnityEngine.Vector3; 12 | 13 | namespace Rocket.Unturned.Player { 14 | public class UnturnedPlayerEntity : IPlayerEntity, ILivingEntity 15 | { 16 | public UnturnedPlayerEntity(UnturnedPlayer unturnedPlayer) 17 | { 18 | Player = unturnedPlayer; 19 | } 20 | 21 | public System.Numerics.Vector3 Position => Player.NativePlayer?.transform?.position.ToSystemVector() ?? throw new PlayerNotOnlineException(); 22 | 23 | public async Task TeleportAsync(System.Numerics.Vector3 position, float rotation) 24 | { 25 | return Teleport(position, rotation); 26 | } 27 | 28 | public string EntityTypeName => "Player"; 29 | 30 | 31 | public EPlayerStance Stance => Player.NativePlayer.stance.stance; 32 | 33 | public float Rotation => Player.NativePlayer.transform.rotation.eulerAngles.y; 34 | 35 | public byte Stamina => Player.NativePlayer.life.stamina; 36 | 37 | public byte Infection 38 | { 39 | get => Player.NativePlayer.life.virus; 40 | set 41 | { 42 | Player.NativePlayer.life.askDisinfect(100); 43 | Player.NativePlayer.life.askInfect(value); 44 | } 45 | } 46 | 47 | public bool Teleport(string nodeName) 48 | { 49 | Node node = LevelNodes.nodes.FirstOrDefault(n 50 | => n.type == ENodeType.LOCATION 51 | && ((LocationNode)n).name.ToLower().Contains(nodeName)); 52 | if (node != null) 53 | { 54 | Vector3 c = node.point + new Vector3(0f, 0.5f, 0f); 55 | Player.NativePlayer.sendTeleport(c, MeasurementTool.angleToByte(Rotation)); 56 | return true; 57 | } 58 | 59 | return false; 60 | } 61 | 62 | 63 | public uint Experience 64 | { 65 | get => Player.NativePlayer.skills.experience; 66 | set 67 | { 68 | Player.NativePlayer.skills.channel.send("tellExperience", ESteamCall.SERVER, ESteamPacket.UPDATE_RELIABLE_BUFFER, 69 | value); 70 | Player.NativePlayer.skills.channel.send("tellExperience", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, 71 | value); 72 | } 73 | } 74 | 75 | public int Reputation 76 | { 77 | get => Player.NativePlayer.skills.reputation; 78 | set => Player.NativePlayer.skills.askRep(value); 79 | } 80 | 81 | public Task KillAsync() => throw new NotImplementedException(); 82 | 83 | public Task KillAsync(IEntity killer) => throw new NotImplementedException(); 84 | 85 | public Task KillAsync(IUser killer) => throw new NotImplementedException(); 86 | 87 | public double MaxHealth { get; } = 100; 88 | 89 | public double Health 90 | { 91 | get { return Player.NativePlayer.life.health; } 92 | set 93 | { 94 | if (value > 255) 95 | { 96 | value = 255; 97 | } 98 | 99 | byte healthToSet = (byte) value; 100 | byte amountToHeal = (byte)(Player.NativePlayer.life.health - healthToSet); 101 | 102 | Player.NativePlayer.life.askHeal(amountToHeal, false, false); 103 | } 104 | } 105 | 106 | 107 | public byte Hunger 108 | { 109 | get => Player.NativePlayer.life.food; 110 | set 111 | { 112 | Player.NativePlayer.life.askEat(100); 113 | Player.NativePlayer.life.askStarve(value); 114 | } 115 | } 116 | 117 | public byte Thirst 118 | { 119 | get => Player.NativePlayer.life.water; 120 | set 121 | { 122 | Player.NativePlayer.life.askDrink(100); 123 | Player.NativePlayer.life.askDehydrate(value); 124 | } 125 | } 126 | 127 | public bool Broken 128 | { 129 | get => Player.NativePlayer.life.isBroken; 130 | set 131 | { 132 | Player.NativePlayer.life.tellBroken(Provider.server, value); 133 | Player.NativePlayer.life.channel.send("tellBroken", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, value); 134 | } 135 | } 136 | 137 | public bool Bleeding 138 | { 139 | get => Player.NativePlayer.life.isBleeding; 140 | set 141 | { 142 | Player.NativePlayer.life.tellBleeding(Provider.server, value); 143 | Player.NativePlayer.life.channel.send("tellBleeding", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, value); 144 | } 145 | } 146 | 147 | public bool Dead => Player.NativePlayer.life.isDead; 148 | 149 | public void Heal(byte amount) 150 | { 151 | Heal(amount, null, null); 152 | } 153 | 154 | public void Heal(byte amount, bool? bleeding, bool? broken) 155 | { 156 | Player.NativePlayer.life.askHeal(amount, bleeding ?? Player.NativePlayer.life.isBleeding, broken ?? Player.NativePlayer.life.isBroken); 157 | } 158 | 159 | public void Suicide() 160 | { 161 | Player.NativePlayer.life.askSuicide(Player.CSteamID); 162 | } 163 | 164 | public EPlayerKill Damage(byte amount, Vector3 direction, EDeathCause cause, ELimb limb, CSteamID damageDealer) 165 | { 166 | Player.NativePlayer.life.askDamage(amount, direction, cause, limb, damageDealer, out EPlayerKill playerKill); 167 | return playerKill; 168 | } 169 | 170 | public EPlayerKill Damage(byte amount, System.Numerics.Vector3 direction, EDeathCause cause, ELimb limb, CSteamID damageDealer) 171 | { 172 | return Damage(amount, direction.ToUnityVector(), cause, limb, damageDealer); 173 | } 174 | 175 | public void Teleport(UnturnedPlayer target) 176 | { 177 | var targetPos = target.Entity.Position; 178 | var rotation = target.Entity.Rotation; 179 | 180 | Teleport(targetPos, MeasurementTool.angleToByte(rotation)); 181 | } 182 | 183 | public bool Teleport(System.Numerics.Vector3 position, float rotation) 184 | { 185 | if (EnableVanish) 186 | { 187 | Player.NativePlayer.channel.send("askTeleport", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, position, MeasurementTool.angleToByte(rotation)); 188 | Player.NativePlayer.channel.send("askTeleport", ESteamCall.NOT_OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new Vector3(position.X, position.Y + 1337, position.Z), MeasurementTool.angleToByte(rotation)); 189 | Player.NativePlayer.channel.send("askTeleport", ESteamCall.SERVER, ESteamPacket.UPDATE_RELIABLE_BUFFER, position, MeasurementTool.angleToByte(rotation)); 190 | } 191 | else 192 | { 193 | Player.NativePlayer.channel.send("askTeleport", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, position.ToUnityVector(), MeasurementTool.angleToByte(Rotation)); 194 | } 195 | return true; 196 | } 197 | 198 | public bool EnableVanish { get; set; } = false; 199 | 200 | public bool Teleport(System.Numerics.Vector3 position) 201 | { 202 | return Teleport(position, Rotation); 203 | } 204 | 205 | public UnturnedPlayer Player { get; } 206 | } 207 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Player/UnturnedPlayerManager.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API; 2 | using Rocket.API.Commands; 3 | using Rocket.API.DependencyInjection; 4 | using Rocket.API.Eventing; 5 | using Rocket.API.Player; 6 | using Rocket.API.User; 7 | using Rocket.Core.Player.Events; 8 | using Rocket.Core.User.Events; 9 | using SDG.Unturned; 10 | using Steamworks; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Linq; 14 | using System.Threading.Tasks; 15 | using Rocket.Core.Logging; 16 | using Rocket.Core.Player; 17 | using Color = UnityEngine.Color; 18 | using ILogger = Rocket.API.Logging.ILogger; 19 | 20 | namespace Rocket.Unturned.Player 21 | { 22 | public class UnturnedPlayerManager : IPlayerManager 23 | { 24 | private readonly IHost host; 25 | private readonly IEventBus eventManager; 26 | private readonly IDependencyContainer container; 27 | private readonly ILogger logger; 28 | 29 | public UnturnedPlayerManager(IHost host, IEventBus @eventManager, 30 | IDependencyContainer container, ILogger logger) 31 | { 32 | this.host = host; 33 | this.eventManager = eventManager; 34 | this.container = container; 35 | this.logger = logger; 36 | } 37 | 38 | public async Task KickAsync(IUser user, IUser kickedBy = null, string reason = null) 39 | { 40 | var target = ((UnturnedUser)user).Player; 41 | 42 | PlayerKickEvent @event = new PlayerKickEvent(target, kickedBy, reason, true); 43 | eventManager.Emit(host, @event); 44 | if (@event.IsCancelled) 45 | return false; 46 | 47 | if (target.IsOnline) 48 | Provider.kick(target.CSteamID, reason ?? string.Empty); 49 | return true; 50 | } 51 | 52 | public async Task BanAsync(IUser user, IUser bannedBy = null, string reason = null, TimeSpan? duration = null) 53 | { 54 | UserBanEvent @event = new UserBanEvent(user, bannedBy, reason, duration, true); 55 | eventManager.Emit(host, @event); 56 | if (@event.IsCancelled) 57 | return false; 58 | 59 | var callerId = (bannedBy is UnturnedUser up) ? up.CSteamID : CSteamID.Nil; 60 | 61 | //if (user.IsOnline) 62 | //{ 63 | // SteamBlacklist.ban(player.CSteamID, 0, callerId, reason, (uint)(duration?.TotalSeconds ?? uint.MaxValue)); 64 | // return true; 65 | //} 66 | 67 | var steamId = new CSteamID(ulong.Parse(user.Id)); 68 | SteamBlacklist.ban(steamId, 0, callerId, reason ?? string.Empty, (uint)(duration?.TotalSeconds ?? uint.MaxValue)); 69 | 70 | var target = ((UnturnedUser)user).Player; 71 | 72 | if (target.IsOnline) 73 | Provider.kick(steamId, reason ?? string.Empty); 74 | 75 | return true; 76 | } 77 | 78 | public async Task UnbanAsync(IUser target, IUser bannedBy = null) 79 | { 80 | UserUnbanEvent @event = new UserUnbanEvent(target, bannedBy); 81 | eventManager.Emit(host, @event); 82 | if (@event.IsCancelled) 83 | return false; 84 | 85 | var steamId = new CSteamID(ulong.Parse(target.Id)); 86 | return SteamBlacklist.unban(steamId); 87 | } 88 | 89 | public async Task SendMessageAsync(IUser sender, IUser receiver, string message, System.Drawing.Color? color = null, 90 | params object[] arguments) 91 | { 92 | var uColor = color == null 93 | ? Color.white 94 | : new Color((1f / 255f) * color.Value.R, (1f / 255f) * color.Value.G, (1f / 255f) * color.Value.B, (1f / 100f) * color.Value.A); 95 | 96 | if (receiver is IConsole console) 97 | { 98 | console.WriteLine(message, color, arguments); 99 | return; 100 | } 101 | 102 | if (!(receiver is UnturnedUser unturnedUser)) 103 | throw new Exception("Could not cast " + receiver.GetType().FullName + " to UnturnedUser!"); 104 | 105 | ChatManager.say(unturnedUser.CSteamID, message, uColor, true); 106 | } 107 | 108 | public async Task BroadcastAsync(IUser sender, IEnumerable receivers, string message, System.Drawing.Color? color = null, 109 | params object[] arguments) 110 | { 111 | var wrappedMessage = WrapMessage(string.Format(message, arguments)); 112 | foreach (IUser user in receivers) 113 | foreach (var line in wrappedMessage) 114 | await user.UserManager.SendMessageAsync(sender, user, line, color); 115 | } 116 | 117 | public async Task BroadcastAsync(IUser sender, string message, System.Drawing.Color? color = null, 118 | params object[] arguments) 119 | { 120 | await BroadcastAsync(sender, Players.Select(d => d.User), message, color, arguments); 121 | logger.LogInformation("[Broadcast] " + message); 122 | } 123 | 124 | public async Task GetUserAsync(string idOrName) 125 | { 126 | var player = (UnturnedPlayer) await GetPlayerAsync(idOrName); 127 | 128 | if(player == null) 129 | { 130 | throw new PlayerNotFoundException(idOrName); 131 | } 132 | 133 | return new UnturnedUser(player.Container, player.SteamPlayer); 134 | } 135 | 136 | public System.Drawing.Color? GetColorFromName(string colorName) 137 | { 138 | switch (colorName.Trim().ToLower()) 139 | { 140 | case "black": return System.Drawing.Color.Black; 141 | case "blue": return System.Drawing.Color.Blue; 142 | case "cyan": return System.Drawing.Color.Cyan; 143 | case "gray": return System.Drawing.Color.Gray; 144 | case "green": return System.Drawing.Color.Green; 145 | case "grey": return System.Drawing.Color.Gray; 146 | case "magenta": return System.Drawing.Color.Magenta; 147 | case "red": return System.Drawing.Color.Red; 148 | case "white": return System.Drawing.Color.White; 149 | case "yellow": return System.Drawing.Color.Yellow; 150 | case "rocket": return GetColorFromRGB(90, 206, 205); 151 | } 152 | 153 | return GetColorFromHex(colorName); 154 | } 155 | 156 | public System.Drawing.Color? GetColorFromHex(string hexString) 157 | { 158 | hexString = hexString.Replace("#", ""); 159 | if (hexString.Length == 3) 160 | { // #99f 161 | hexString = hexString.Insert(1, System.Convert.ToString(hexString[0])); // #999f 162 | hexString = hexString.Insert(3, System.Convert.ToString(hexString[2])); // #9999f 163 | hexString = hexString.Insert(5, System.Convert.ToString(hexString[4])); // #9999ff 164 | } 165 | 166 | if (hexString.Length != 6 || !int.TryParse(hexString, System.Globalization.NumberStyles.HexNumber, null, out int argb)) 167 | { 168 | return null; 169 | } 170 | byte r = (byte)((argb >> 16) & 0xff); 171 | byte g = (byte)((argb >> 8) & 0xff); 172 | byte b = (byte)(argb & 0xff); 173 | return GetColorFromRGB(r, g, b); 174 | } 175 | 176 | public System.Drawing.Color GetColorFromRGB(byte R, byte G, byte B) 177 | { 178 | return GetColorFromRGB(R, G, B, 100); 179 | } 180 | 181 | public System.Drawing.Color GetColorFromRGB(byte R, byte G, byte B, short A) 182 | { 183 | return System.Drawing.Color.FromArgb(A, R, G, B); 184 | } 185 | 186 | public IPlayer GetPlayer(string nameOrId) 187 | { 188 | SteamPlayer player; 189 | 190 | if (ulong.TryParse(nameOrId, out var id)) 191 | player = PlayerTool.getSteamPlayer(new CSteamID(id)); 192 | else 193 | player = PlayerTool.getSteamPlayer(nameOrId); 194 | 195 | if (player == null) 196 | throw new PlayerNotFoundException(nameOrId); 197 | 198 | return new UnturnedPlayer(container, player, this); 199 | } 200 | 201 | 202 | 203 | public PreConnectUnturnedPlayer GetPendingPlayer(string uniqueID) 204 | { 205 | return PendingPlayers.FirstOrDefault(c => c.User.Id.Equals(uniqueID)); 206 | } 207 | 208 | public PreConnectUnturnedPlayer GetPendingPlayerByName(string displayName) 209 | { 210 | return PendingPlayers.FirstOrDefault(c => c.User.DisplayName.Equals(displayName, StringComparison.OrdinalIgnoreCase)); 211 | } 212 | 213 | public async Task> GetPlayersAsync() => Players; 214 | 215 | public async Task GetPlayerAsync(string nameOrId) 216 | { 217 | SteamPlayer player = null; 218 | 219 | if (ulong.TryParse(nameOrId, out var id)) 220 | player = PlayerTool.getSteamPlayer(new CSteamID(id)); 221 | 222 | if(player == null) 223 | player = PlayerTool.getSteamPlayer(nameOrId); 224 | 225 | if (player == null) 226 | throw new PlayerNotFoundException(nameOrId); 227 | 228 | return new UnturnedPlayer(container, player, this); 229 | } 230 | 231 | public async Task GetPlayerByNameAsync(string name) 232 | { 233 | SteamPlayer player = PlayerTool.getSteamPlayer(name); 234 | if (player == null) 235 | throw new PlayerNameNotFoundException(name); 236 | 237 | return new UnturnedPlayer(container, player, this); 238 | } 239 | 240 | public async Task GetPlayerByIdAsync(string id) 241 | { 242 | var player = PlayerTool.getSteamPlayer(ulong.Parse(id)); 243 | if (player == null) 244 | throw new PlayerIdNotFoundException(id); 245 | 246 | return new UnturnedPlayer(container, player, this); 247 | } 248 | 249 | public bool TryGetOnlinePlayer(string nameOrId, out IPlayer output) 250 | { 251 | output = null; 252 | try 253 | { 254 | output = GetPlayerAsync(nameOrId).GetAwaiter().GetResult(); 255 | return true; 256 | } 257 | catch (Exception) 258 | { 259 | return false; 260 | } 261 | } 262 | 263 | public bool TryGetOnlinePlayerById(string id, out IPlayer output) 264 | { 265 | output = null; 266 | try 267 | { 268 | output = GetPlayerByIdAsync(id).GetAwaiter().GetResult(); 269 | return true; 270 | } 271 | catch (Exception) 272 | { 273 | return false; 274 | } 275 | } 276 | 277 | public bool TryGetOnlinePlayerByName(string displayName, out IPlayer output) 278 | { 279 | output = null; 280 | try 281 | { 282 | output = GetPlayerByNameAsync(displayName).GetAwaiter().GetResult(); 283 | return true; 284 | } 285 | catch (Exception) 286 | { 287 | return false; 288 | } 289 | } 290 | 291 | /// 292 | /// Online players which succesfully joined the server. 293 | /// 294 | public IEnumerable Players => 295 | Provider.clients.Select(c => (IPlayer)new UnturnedPlayer(container, c, this)); 296 | 297 | /// 298 | /// Players which are not authenticated and have not joined yet. 299 | /// 300 | public IEnumerable PendingPlayers => Provider.pending.Select(c => new PreConnectUnturnedPlayer(container, c, this)); 301 | public string ServiceName => "Unturned"; 302 | 303 | public async Task GetIdentity(string id) => new UnturnedIdentity(ulong.Parse(id)); 304 | 305 | protected static List WrapMessage(string text) 306 | { 307 | if (text.Length == 0) return new List(); 308 | string[] words = text.Split(' '); 309 | List lines = new List(); 310 | string currentLine = ""; 311 | int maxLength = 90; 312 | foreach (string currentWord in words) 313 | { 314 | if (currentLine.Length > maxLength || currentLine.Length + currentWord.Length > maxLength) 315 | { 316 | lines.Add(currentLine); 317 | currentLine = ""; 318 | } 319 | 320 | if (currentLine.Length > 0) 321 | currentLine += " " + currentWord; 322 | else 323 | currentLine += currentWord; 324 | } 325 | 326 | if (currentLine.Length > 0) 327 | lines.Add(currentLine); 328 | return lines; 329 | } 330 | } 331 | } 332 | -------------------------------------------------------------------------------- /Rocket.Unturned/Player/UnturnedUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Rocket.API.DependencyInjection; 4 | using Rocket.API.Player; 5 | using Rocket.API.User; 6 | using SDG.Unturned; 7 | using Steamworks; 8 | 9 | namespace Rocket.Unturned.Player 10 | { 11 | public class UnturnedUser : IPlayerUser 12 | { 13 | public IDependencyContainer Container { get; } 14 | 15 | public string Id { get; } 16 | public CSteamID CSteamID { get; } 17 | 18 | private IPlayerManager playerManager; 19 | 20 | public UnturnedUser(IDependencyContainer container, SteamPlayer player) : this(container, player.playerID.steamID) 21 | { 22 | } 23 | 24 | public UnturnedUser(IDependencyContainer container, SteamPending player) : this(container, player.playerID.steamID) 25 | { 26 | } 27 | 28 | public UnturnedUser(IDependencyContainer container, CSteamID id) 29 | { 30 | Id = id.ToString(); 31 | CSteamID = id; 32 | Container = container; 33 | UserManager = playerManager = container.Resolve(); 34 | } 35 | 36 | public UnturnedPlayer Player => (UnturnedPlayer)playerManager.GetPlayerByIdAsync(Id).GetAwaiter().GetResult(); 37 | 38 | public DateTime? LastSeen { get; } 39 | 40 | public IUserManager UserManager { get; } 41 | 42 | public string UserName => Player.SteamName; 43 | 44 | public string DisplayName => Player.DisplayName; 45 | 46 | public List Identities { get; } = new List(); 47 | 48 | public string UserType => "Unturned"; 49 | 50 | 51 | public override int GetHashCode() 52 | { 53 | return CSteamID.GetHashCode(); 54 | } 55 | 56 | public override bool Equals(object o) 57 | { 58 | if (!(o is UnturnedUser uPlayer)) 59 | return false; 60 | 61 | return uPlayer.GetHashCode() == GetHashCode(); 62 | } 63 | 64 | IPlayer IPlayerUser.Player => Player; 65 | } 66 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Properties/ServiceConfigurator.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API; 2 | using Rocket.API.Commands; 3 | using Rocket.API.DependencyInjection; 4 | using Rocket.API.Permissions; 5 | using Rocket.API.Player; 6 | using Rocket.API.User; 7 | using Rocket.Core.User; 8 | using Rocket.Unturned.Commands; 9 | using Rocket.Unturned.Permissions; 10 | using Rocket.Unturned.Player; 11 | 12 | namespace Rocket.Unturned.Properties 13 | { 14 | public class ServiceConfigurator : IServiceConfigurator 15 | { 16 | public void ConfigureServices(IDependencyContainer container) 17 | { 18 | container.AddSingleton(null, "unturned", "host"); 19 | container.AddSingleton(null, "host", "unturned"); 20 | var mgr = container.Resolve("unturned"); 21 | 22 | container.AddSingleton(mgr, null, "host", "unturned"); 23 | container.AddSingleton("stdconsole"); 24 | 25 | container.AddSingleton("unturned_commands"); 26 | container.AddSingleton("rocket_unturned_commands"); 27 | 28 | container.AddSingleton("unturned_admins"); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Rocket.Unturned.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | netstandard2.0 4 | Rocket.Unturned 5 | RocketMod .NET Game Server Plugin Framework Unturned implementation 6 | Rocket.Unturned 7 | Library 8 | true 9 | 0.0.0.0 10 | 0.0.0.0 11 | 0.0.0.0 12 | 0.0.0.0 13 | $(AssemblyName) 14 | true 15 | RocketMod Rocket Unturned Plugin Framework 16 | https://github.com/RocketMod/Rocket.Unturned/blob/master/LICENSE 17 | https://rocketmod.net/ 18 | Sven Mawby<fr34kyn01535@bam.yt>, Enes Sadık Özbek <esozbek.me> 19 | Sven Mawby<fr34kyn01535@bam.yt> 20 | Sven Mawby <fr34kyn01535@bam.yt>, Enes Sadık Özbek <esozbek.me> 21 | RocketMod 22 | Sven Mawby <fr34kyn01535@bam.yt> 23 | true 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | ..\lib\UnityEngine.CoreModule.dll 33 | false 34 | 35 | 36 | ..\lib\UnityEngine.dll 37 | false 38 | 39 | 40 | ..\lib\Assembly-CSharp.dll 41 | false 42 | 43 | 44 | ..\lib\Assembly-CSharp-firstpass.dll 45 | false 46 | 47 | 48 | -------------------------------------------------------------------------------- /Rocket.Unturned/RocketUnturnedHost.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API; 2 | using Rocket.API.Commands; 3 | using Rocket.API.DependencyInjection; 4 | using Rocket.API.Eventing; 5 | using Rocket.API.I18N; 6 | using Rocket.API.Plugins; 7 | using Rocket.API.User; 8 | using Rocket.Core.Commands.Events; 9 | using Rocket.Core.Configuration; 10 | using Rocket.Core.Implementation.Events; 11 | using Rocket.Core.Logging; 12 | using Rocket.Core.Player.Events; 13 | using Rocket.Core.User; 14 | using Rocket.UnityEngine.Extensions; 15 | using Rocket.Unturned.Console; 16 | using Rocket.Unturned.Player; 17 | using Rocket.Unturned.Player.Events; 18 | using Rocket.Unturned.Utils; 19 | using SDG.Unturned; 20 | using Steamworks; 21 | using System; 22 | using System.Collections.Generic; 23 | using System.Diagnostics; 24 | using System.IO; 25 | using System.Linq; 26 | using System.Net; 27 | using System.Net.Security; 28 | using System.Security.Cryptography.X509Certificates; 29 | using System.Threading.Tasks; 30 | using UnityEngine; 31 | using ILogger = Rocket.API.Logging.ILogger; 32 | using Object = UnityEngine.Object; 33 | using Version = System.Version; 34 | 35 | namespace Rocket.Unturned 36 | { 37 | public class RocketUnturnedHost : IHost 38 | { 39 | public RocketUnturnedHost(IDependencyContainer container) 40 | { 41 | string rocketDirectory = $"Servers/{Dedicator.serverID}/Rocket/"; 42 | if (!Directory.Exists(rocketDirectory)) 43 | Directory.CreateDirectory(rocketDirectory); 44 | 45 | Directory.SetCurrentDirectory(rocketDirectory); 46 | Console = new StdConsole(container); 47 | } 48 | 49 | private GameObject rocketGameObject; 50 | private ILogger logger; 51 | private UnturnedPlayerManager playerManager; 52 | private IEventBus eventManager; 53 | private IDependencyContainer container; 54 | internal ITranslationCollection ModuleTranslations { get; private set; } 55 | private IRuntime runtime; 56 | public bool IsAlive => true; 57 | public ushort ServerPort => Provider.port; 58 | public IConsole Console { get; set; } 59 | public string GameName => "Unturned"; 60 | 61 | public async Task InitAsync(IRuntime runtime) 62 | { 63 | InstallTlsWorkaround(); 64 | BaseLogger.SkipTypeFromLogging(typeof(UnturnedPlayerManager)); 65 | 66 | this.runtime = runtime; 67 | rocketGameObject = new GameObject(); 68 | Object.DontDestroyOnLoad(rocketGameObject); 69 | 70 | container = runtime.Container; 71 | eventManager = container.Resolve(); 72 | playerManager = (UnturnedPlayerManager)container.Resolve("host"); 73 | ModuleTranslations = container.Resolve(); 74 | 75 | logger = container.Resolve(); 76 | logger.LogInformation("Loading Rocket Unturned Implementation..."); 77 | 78 | container.AddSingleton(); 79 | container.Resolve().Start(); 80 | await LoadTranslations(); 81 | 82 | Provider.onServerHosted += OnServerHosted; 83 | 84 | if (Environment.OSVersion.Platform == PlatformID.Unix 85 | || Environment.OSVersion.Platform == PlatformID.MacOSX) 86 | { 87 | rocketGameObject.SetActive(false); // deactivate object so it doesn't run Awake until all properties were set 88 | var console = rocketGameObject.AddComponent(); 89 | console.Logger = logger; 90 | rocketGameObject.SetActive(true); // reactivate object 91 | } 92 | 93 | SteamChannel.onTriggerSend += TriggerSend; 94 | Provider.onCheckValid += OnCheckValid; 95 | Provider.onServerConnected += OnPlayerConnected; 96 | Provider.onServerDisconnected += OnPlayerDisconnected; 97 | DamageTool.playerDamaged += OnPlayerDamaged; 98 | Provider.onServerShutdown += OnServerShutdown; 99 | ChatManager.onChatted += (SteamPlayer player, EChatMode mode, ref Color color, ref bool isRich, string message, 100 | ref bool isVisible) => 101 | { 102 | UnturnedPlayer p = (UnturnedPlayer)playerManager.GetPlayerByIdAsync(player.playerID.steamID.m_SteamID.ToString()).GetAwaiter().GetResult(); 103 | UnturnedPlayerChatEvent @event = new UnturnedPlayerChatEvent(p, mode, color, isRich, message, !isVisible); 104 | eventManager.Emit(this, @event); 105 | color = @event.Color; 106 | isRich = @event.IsRichText; 107 | isVisible = !@event.IsCancelled; 108 | }; 109 | 110 | CommandWindow.onCommandWindowOutputted += (text, color) => logger.LogNative(text?.ToString()); 111 | } 112 | 113 | private void InstallTlsWorkaround() 114 | { 115 | //http://answers.unity.com/answers/1089592/view.html 116 | ServicePointManager.ServerCertificateValidationCallback = CertificateValidationWorkaroundCallback; 117 | } 118 | 119 | public bool CertificateValidationWorkaroundCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 120 | { 121 | bool isOk = true; 122 | // If there are errors in the certificate chain, look at each error to determine the cause. 123 | if (sslPolicyErrors != SslPolicyErrors.None) 124 | { 125 | foreach (X509ChainStatus chainStatus in chain.ChainStatus) 126 | { 127 | if (chainStatus.Status != X509ChainStatusFlags.RevocationStatusUnknown) 128 | { 129 | chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain; 130 | chain.ChainPolicy.RevocationMode = X509RevocationMode.Online; 131 | chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0); 132 | chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags; 133 | bool chainIsValid = chain.Build((X509Certificate2)certificate); 134 | if (!chainIsValid) 135 | { 136 | isOk = false; 137 | } 138 | } 139 | } 140 | } 141 | return isOk; 142 | } 143 | 144 | private void OnServerShutdown() 145 | { 146 | var shutdownTask = Task.Run(async () => 147 | { 148 | await Task.Yield(); 149 | await runtime.ShutdownAsync(); 150 | }); 151 | 152 | shutdownTask.GetAwaiter().GetResult(); 153 | } 154 | 155 | private void OnPlayerDamaged(SDG.Unturned.Player uPlayer, ref EDeathCause cause, ref ELimb limb, ref CSteamID killerId, ref global::UnityEngine.Vector3 direction, ref float damage, ref float times, ref bool canDamage) 156 | { 157 | if (uPlayer == null) 158 | { 159 | return; 160 | } 161 | 162 | playerManager.TryGetOnlinePlayerById(uPlayer.channel.owner.playerID.steamID.ToString(), out var player); 163 | playerManager.TryGetOnlinePlayerById(killerId.m_SteamID.ToString(), out var killer); 164 | 165 | UnturnedPlayerDamagedEvent damageEvent = 166 | new UnturnedPlayerDamagedEvent(player, cause, limb, killer?.User, direction.ToSystemVector(), damage, times) 167 | { 168 | IsCancelled = !canDamage 169 | }; 170 | 171 | eventManager.Emit(this, damageEvent); 172 | cause = damageEvent.DeathCause; 173 | limb = damageEvent.Limb; 174 | killerId = damageEvent.DamageDealer != null ? new CSteamID(ulong.Parse(damageEvent.DamageDealer.Id)) : CSteamID.Nil; 175 | direction = damageEvent.Direction.ToUnityVector(); 176 | damage = (float)damageEvent.Damage; 177 | times = damageEvent.Times; 178 | canDamage = !damageEvent.IsCancelled; 179 | } 180 | 181 | private async Task LoadTranslations() 182 | { 183 | var context = new ConfigurationContext(this); 184 | context.ConfigurationName += "Translations"; 185 | 186 | await ModuleTranslations.LoadAsync(context, 187 | new Dictionary 188 | { 189 | { "command_compass_facing_private","You are facing {0}"}, 190 | { "command_compass_north","N"}, 191 | { "command_compass_east","E"}, 192 | { "command_compass_south","S"}, 193 | { "command_compass_west","W"}, 194 | { "command_compass_northwest","NW"}, 195 | { "command_compass_northeast","NE"}, 196 | { "command_compass_southwest","SW"}, 197 | { "command_compass_southeast","SE"}, 198 | { "command_heal_success_me","{0} was successfully healed"}, 199 | { "command_heal_success_other","You were healed by {0}"}, 200 | { "command_heal_success","You were healed"}, 201 | { "command_bed_no_bed_found_private","You do not have a bed to teleport to."}, 202 | { "command_i_giving_private","Giving you item {0}x {1} ({2})"}, 203 | { "command_i_giving_failed_private","Failed giving you item {0}x {1} ({2})"}, 204 | { "command_more_dequipped", "No item being held in hands." }, 205 | { "command_more_give", "Giving {0} of item: {1}." }, 206 | { "command_generic_teleport_while_driving_error","You cannot teleport while driving or riding in a vehicle."}, 207 | { "command_tp_failed_find_destination","Failed to find destination"}, 208 | { "command_tphere_vehicle", "The player you are trying to teleport is in a vehicle"}, 209 | { "command_tphere_teleport_from_private","Teleported {0} to you"}, 210 | { "command_tphere_teleport_to_private","You were teleported to {0}"}, 211 | { "command_v_giving_private","Giving you a {0} ({1})"}, 212 | { "command_v_giving_failed_private","Failed giving you a {0} ({1})"}, 213 | }); 214 | } 215 | 216 | private void OnPlayerConnected(CSteamID steamid) 217 | { 218 | var player = playerManager.GetPlayerByIdAsync(steamid.ToString()).GetAwaiter().GetResult(); 219 | PlayerConnectedEvent @event = new PlayerConnectedEvent(player); 220 | eventManager.Emit(this, @event); 221 | } 222 | 223 | private void OnPlayerDisconnected(CSteamID steamid) 224 | { 225 | var player = playerManager.GetPlayerByIdAsync(steamid.ToString()).GetAwaiter().GetResult(); 226 | PlayerDisconnectedEvent @event = new PlayerDisconnectedEvent(player, null); 227 | eventManager.Emit(this, @event); 228 | } 229 | 230 | private void OnCheckValid(ValidateAuthTicketResponse_t callback, ref bool isValid) 231 | { 232 | var pendingPlayer = Provider.pending.FirstOrDefault(c => c.playerID.steamID.Equals(callback.m_SteamID)); 233 | if (pendingPlayer == null) return; 234 | 235 | PreConnectUnturnedPlayer player = new PreConnectUnturnedPlayer(container, pendingPlayer, playerManager); 236 | UnturnedPlayerPreConnectEvent @event = new UnturnedPlayerPreConnectEvent(player, callback); 237 | eventManager.Emit(this, @event); 238 | 239 | if (@event.UnturnedRejectionReason != null) 240 | { 241 | Provider.reject(callback.m_SteamID, @event.UnturnedRejectionReason.Value); 242 | isValid = false; 243 | return; 244 | } 245 | 246 | if (@event.IsCancelled) 247 | { 248 | Provider.reject(callback.m_SteamID, ESteamRejection.PLUGIN); 249 | isValid = false; 250 | return; 251 | } 252 | 253 | isValid = true; 254 | } 255 | 256 | private void OnServerHosted() 257 | { 258 | ICommandHandler cmdHandler = container.Resolve(); 259 | 260 | ChatManager.onCheckPermissions += (SteamPlayer player, string commandLine, ref bool shouldExecuteCommand, ref bool shouldList) => 261 | { 262 | if (commandLine.StartsWith("/")) 263 | { 264 | commandLine = commandLine.Substring(1); 265 | var caller = playerManager.GetPlayer(player.playerID.steamID.ToString()); 266 | var playerExecutionEvent = new PreCommandExecutionEvent(caller.User, commandLine); 267 | eventManager.Emit(this, playerExecutionEvent); 268 | 269 | var commandTask = Task.Run(async () => 270 | { 271 | await Task.Yield(); 272 | 273 | bool success = await cmdHandler.HandleCommandAsync(caller.User, commandLine, "/"); 274 | if (!success) 275 | await caller.User.SendMessageAsync("Command not found", ConsoleColor.Red); 276 | }); 277 | commandTask.GetAwaiter().GetResult(); 278 | 279 | shouldList = false; 280 | } 281 | 282 | shouldExecuteCommand = false; 283 | }; 284 | 285 | CommandWindow.onCommandWindowInputted += (string commandline, ref bool shouldExecuteCommand) => 286 | { 287 | shouldExecuteCommand = false; 288 | 289 | if (commandline.StartsWith("/")) 290 | commandline = commandline.Substring(1); 291 | 292 | var consoleExecutionEvent = new PreCommandExecutionEvent(Console, commandline); 293 | eventManager.Emit(this, consoleExecutionEvent); 294 | 295 | var commandTask = Task.Run(async () => 296 | { 297 | await Task.Yield(); 298 | 299 | bool success = await cmdHandler.HandleCommandAsync(Console, commandline, ""); 300 | if (!success) 301 | await Console.SendMessageAsync("Command not found", ConsoleColor.Red); 302 | }); 303 | 304 | commandTask.GetAwaiter().GetResult(); 305 | }; 306 | 307 | eventManager.Emit(this, new ImplementationReadyEvent(this)); 308 | 309 | var pluginManager = container.Resolve(); 310 | var task = Task.Run(async () => 311 | { 312 | await Task.Yield(); 313 | await pluginManager.InitAsync(); 314 | }); 315 | 316 | task.GetAwaiter().GetResult(); 317 | 318 | } 319 | 320 | internal void TriggerSend(SteamPlayer player, string method, ESteamCall steamCall, ESteamPacket steamPacket, params object[] data) 321 | { 322 | try 323 | { 324 | if (player == null 325 | || player.player == null 326 | || player.playerID.steamID == CSteamID.Nil 327 | || player.player.transform == null 328 | || data == null) return; 329 | 330 | UnturnedPlayer unturnedPlayer = 331 | (UnturnedPlayer)playerManager.GetPlayer(player.playerID.steamID.ToString()); 332 | 333 | if (method.StartsWith("tellWear")) 334 | { 335 | //PlayerWearEvent method.Replace("tellWear", ""), (ushort)data[0], data.Count() > 1 ? (byte?)data[1] : null) 336 | return; 337 | } 338 | 339 | IEvent @event = null; 340 | switch (method) 341 | { 342 | case "tellBleeding": 343 | @event = new UnturnedPlayerUpdateBleedingEvent(unturnedPlayer, (bool)data[0]); 344 | break; 345 | case "tellBroken": 346 | @event = new UnturnedPlayerUpdateBrokenEvent(unturnedPlayer, (bool)data[0]); 347 | break; 348 | case "tellLife": 349 | @event = new UnturnedPlayerUpdateLifeEvent(unturnedPlayer, (byte)data[0]); 350 | break; 351 | case "tellFood": 352 | @event = new UnturnedPlayerUpdateFoodEvent(unturnedPlayer, (byte)data[0]); 353 | break; 354 | case "tellHealth": 355 | @event = new UnturnedPlayerUpdateHealthEvent(unturnedPlayer, (byte)data[0]); 356 | break; 357 | case "tellVirus": 358 | @event = new UnturnedPlayerUpdateVirusEvent(unturnedPlayer, (byte)data[0]); 359 | break; 360 | case "tellWater": 361 | @event = new UnturnedPlayerUpdateWaterEvent(unturnedPlayer, (byte)data[0]); 362 | break; 363 | case "tellStance": 364 | @event = new UnturnedPlayerUpdateStanceEvent(unturnedPlayer, (EPlayerStance)(byte)data[0]); 365 | break; 366 | case "tellGesture": 367 | @event = new UnturnedPlayerUpdateGestureEvent(unturnedPlayer, (EPlayerGesture)(byte)data[0]); 368 | break; 369 | case "tellStat": 370 | @event = new UnturnedPlayerUpdateStatEvent(unturnedPlayer, (EPlayerStat)(byte)data[0]); 371 | break; 372 | case "tellExperience": 373 | @event = new UnturnedPlayerUpdateExperienceEvent(unturnedPlayer, (uint)data[0]); 374 | break; 375 | case "tellRevive": 376 | @event = new PlayerRespawnEvent(unturnedPlayer); 377 | break; 378 | case "tellDead": 379 | @event = new UnturnedPlayerDeadEvent(unturnedPlayer, ((global::UnityEngine.Vector3)data[0]).ToSystemVector()); 380 | break; 381 | case "tellDeath": 382 | { 383 | var deathCause = (EDeathCause)(byte)data[0]; 384 | var limb = (ELimb)(byte)data[1]; 385 | var killerId = data[2].ToString(); 386 | 387 | playerManager.TryGetOnlinePlayerById(killerId, out var killer); 388 | 389 | @event = new UnturnedPlayerDeathEvent(unturnedPlayer, limb, deathCause, (killer as UnturnedPlayer)?.Entity); 390 | break; 391 | } 392 | } 393 | 394 | if (@event != null) 395 | eventManager.Emit(this, @event); 396 | } 397 | catch (Exception ex) 398 | { 399 | logger.LogError("Failed to receive packet \"" + method + "\"", ex); 400 | } 401 | } 402 | 403 | public async Task ShutdownAsync() 404 | { 405 | Provider.shutdown(); 406 | } 407 | 408 | public async Task ReloadAsync() { } 409 | public Version HostVersion => new Version(FileVersionInfo.GetVersionInfo(GetType().Assembly.Location).FileVersion); 410 | public Version GameVersion => new Version(Provider.APP_VERSION); 411 | public string ServerName => Provider.serverName; 412 | 413 | public string InstanceId => Provider.serverID; 414 | public string WorkingDirectory => Directory.GetCurrentDirectory(); 415 | public string ConfigurationName => Name; 416 | public string Name => "Rocket.Unturned"; 417 | } 418 | } -------------------------------------------------------------------------------- /Rocket.Unturned/Utils/AutomaticSaveWatchdog.cs: -------------------------------------------------------------------------------- 1 | using Rocket.API; 2 | using Rocket.API.Logging; 3 | using Rocket.API.Scheduling; 4 | using Rocket.Core.Logging; 5 | using SDG.Unturned; 6 | using System; 7 | 8 | namespace Rocket.Unturned.Utils 9 | { 10 | public class AutomaticSaveWatchdog 11 | { 12 | private readonly IHost host; 13 | private readonly ILogger logger; 14 | private readonly ITaskScheduler scheduler; 15 | private int saveInterval = 30; 16 | 17 | public AutomaticSaveWatchdog(IHost host, ILogger logger, ITaskScheduler scheduler) 18 | { 19 | this.host = host; 20 | this.logger = logger; 21 | this.scheduler = scheduler; 22 | } 23 | 24 | public void Start() 25 | { 26 | bool autoSaveEnabled = true; //U.Settings.Instance.AutomaticSave.Enabled; 27 | 28 | // ReSharper disable once ConditionIsAlwaysTrueOrFalse 29 | // ReSharper disable once HeuristicUnreachableCode 30 | 31 | if (!autoSaveEnabled) 32 | return; 33 | 34 | int i = 300; //;U.Settings.Instance.AutomaticSave.Interval; 35 | 36 | if (i >= saveInterval) 37 | saveInterval = i; 38 | else 39 | logger.LogError("AutomaticSave interval must be at least 30 seconds, changed to 30 seconds."); 40 | 41 | logger.LogInformation("This server will automatically save every {0} seconds.", saveInterval); 42 | 43 | var period = TimeSpan.FromSeconds(saveInterval); 44 | scheduler.SchedulePeriodically(host, RunSave, "Automatic Save", period, period); 45 | } 46 | 47 | private void RunSave() 48 | { 49 | if (!Level.isInitialized) 50 | { 51 | return; 52 | } 53 | 54 | if (Level.info == null) 55 | { 56 | return; 57 | } 58 | 59 | logger.LogInformation("Saving server"); 60 | SaveManager.save(); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /lib/Assembly-CSharp-firstpass.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/lib/Assembly-CSharp-firstpass.dll -------------------------------------------------------------------------------- /lib/Assembly-CSharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketMod/Rocket.Unturned/5b684f782678c740006c844a79d17a36d2babefe/lib/Assembly-CSharp.dll --------------------------------------------------------------------------------