├── .gitignore ├── ComputeHash ├── ComputeHash.csproj ├── ComputeHash.sln ├── CryptoExtensions.cs ├── Program.cs └── Properties │ └── AssemblyInfo.cs ├── Example ├── Pluton │ ├── LoadOuts │ │ ├── admin.ini │ │ └── starter.ini │ ├── Plugins │ │ └── Example │ │ │ └── Example.py │ └── Pluton.cfg └── RustDedicated_Data │ ├── Core.cfg │ ├── DirectoryConfig.cfg │ └── Hashes.ini ├── LICENSE ├── Pluton.Patcher ├── DiffMatchPatch.cs ├── Pluton.Patcher.csproj ├── Pluton.Patcher.sln ├── Pluton.Patcher │ ├── FieldDefinitionExtensions.cs │ ├── MethodDefinitionExtensions.cs │ ├── Reflection │ │ ├── AssemblyPatcher.cs │ │ ├── MethodPatcher.cs │ │ ├── PatcherObject.cs │ │ └── TypePatcher.cs │ └── TypeDefinitionExtensions.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── icon.ico └── ref │ ├── ICSharpCode.AvalonEdit.dll │ ├── ICSharpCode.Decompiler.dll │ ├── ICSharpCode.NRefactory.CSharp.dll │ ├── ICSharpCode.NRefactory.VB.dll │ ├── ICSharpCode.NRefactory.dll │ ├── ICSharpCode.TreeView.dll │ ├── ILSpy.BamlDecompiler.Plugin.dll │ ├── ILSpy.exe │ ├── ILSpy.exe.config │ ├── Mono.Cecil.Pdb.dll │ ├── Mono.Cecil.dll │ └── Reflexil.Reflector.AIO.dll ├── Pluton ├── Bootstrap.cs ├── Config.cs ├── CoreConfig.cs ├── CountedInstance.cs ├── CryptoExtensions.cs ├── DataStore.cs ├── DirectoryConfig.cs ├── Documentation │ ├── DoqAttribute.cs │ └── DoqEnums.cs ├── Dump.cs ├── Events │ ├── AuthEvent.cs │ ├── BuildingEvent.cs │ ├── BuildingPartDemolishedEvent.cs │ ├── BuildingPartDestroyedEvent.cs │ ├── BuildingPartGradeChangeEvent.cs │ ├── ChatEvent.cs │ ├── ClientConsoleEvent.cs │ ├── CombatEntityHurtEvent.cs │ ├── CommandEvent.cs │ ├── CommandPermissionEvent.cs │ ├── ConsumeFuelEvent.cs │ ├── CorpseHurtEvent.cs │ ├── CorpseInitEvent.cs │ ├── CraftEvent.cs │ ├── DeathEvent.cs │ ├── DoorCodeEvent.cs │ ├── DoorUseEvent.cs │ ├── EntityLootEvent.cs │ ├── EventTriggeredEvent.cs │ ├── GatherEvent.cs │ ├── HammerEvent.cs │ ├── HurtEvent.cs │ ├── InventoryModEvent.cs │ ├── ItemConditionEvent.cs │ ├── ItemLootEvent.cs │ ├── ItemPickupEvent.cs │ ├── ItemRepairEvent.cs │ ├── ItemUsedEvent.cs │ ├── LandmineTriggerEvent.cs │ ├── LootEvent.cs │ ├── MetabolismDamageEvent.cs │ ├── MetabolismTickEvent.cs │ ├── NPCDeathEvent.cs │ ├── NPCHurtEvent.cs │ ├── PlayerClothingEvent.cs │ ├── PlayerDeathEvent.cs │ ├── PlayerHealthChangeEvent.cs │ ├── PlayerHurtEvent.cs │ ├── PlayerKickEvent.cs │ ├── PlayerLootEvent.cs │ ├── PlayerTakeRadsEvent.cs │ ├── PlayerTakedmgEvent.cs │ ├── RespawnEvent.cs │ ├── RocketShootEvent.cs │ ├── ServerConsoleEvent.cs │ ├── ShootEvent.cs │ ├── SyringeUseEvent.cs │ └── WeaponThrowEvent.cs ├── Find.cs ├── Hooks.cs ├── ISingleton.cs ├── IniParser.cs ├── Logger.cs ├── Objects │ ├── BuildingPart.cs │ ├── ChatCommands.cs │ ├── ConsoleCommands.cs │ ├── Entity.cs │ ├── Inv.cs │ ├── InvItem.cs │ ├── LoadOut.cs │ ├── LoadOutItem.cs │ ├── NPC.cs │ ├── OfflinePlayer.cs │ ├── Player.cs │ ├── PluginCommand.cs │ ├── PlutonUIComponents │ │ ├── BaseComponent.cs │ │ ├── Button.cs │ │ ├── IComponent.cs │ │ ├── Image.cs │ │ ├── NeedsCursor.cs │ │ ├── Outline.cs │ │ ├── RawImage.cs │ │ ├── RectTransform.cs │ │ └── Text.cs │ ├── PlutonUIEntity.cs │ ├── PlutonUIPanel.cs │ ├── Stats.cs │ └── Zone2D.cs ├── PluginLoaders │ ├── BasePlugin.cs │ ├── CSPlugin.cs │ ├── CSSPlugin.cs │ ├── CSScriptPluginLoader.cs │ ├── CSharpPlugin.cs │ ├── CSharpPluginLoader.cs │ ├── IPlugin.cs │ ├── IPluginLoader.cs │ ├── JSPlugin.cs │ ├── JSPluginLoader.cs │ ├── LUAPlugin.cs │ ├── LUAPluginLoader.cs │ ├── PHPPlugin.cs │ ├── PHPPluginLoader.cs │ ├── PYPlugin.cs │ ├── PYPluginLoader.cs │ ├── PluginLoader.cs │ └── PluginWatcher.cs ├── Pluton.cfg ├── Pluton.cs ├── Pluton.csproj ├── Pluton.sln ├── Properties │ └── AssemblyInfo.cs ├── ReflectionExtensions.cs ├── Serialize │ ├── ISerializable.cs │ ├── SerializedQuaternion.cs │ ├── SerializedVector3.cs │ ├── SerializedZone2D.cs │ └── UnityEngineExtensions.cs ├── Server.cs ├── Singleton.cs ├── SingletonEx.cs ├── Stopper.cs ├── StringExtensions.cs ├── TimedEvent.cs ├── Util.cs ├── World.cs ├── plugins.cs └── ref │ ├── IronPython.Deps.dll │ ├── Jint.dll │ ├── Mono.Cecil.dll │ ├── MoonSharp.Interpreter.dll │ ├── System.Reactive.dll │ ├── System.Threading.dll │ └── mcs.exe ├── README.md └── ref ├── .gitignore └── Put here rust dlls.txt /.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 | *.userprefs 9 | 10 | # Build results 11 | [Dd]ebug/ 12 | [Dd]ebugPublic/ 13 | [Rr]elease/ 14 | [Rr]eleases/ 15 | x64/ 16 | x86/ 17 | build/ 18 | bld/ 19 | [Bb]in/ 20 | [Oo]bj/ 21 | 22 | # Roslyn cache directories 23 | *.ide/ 24 | 25 | # MSTest test Results 26 | [Tt]est[Rr]esult*/ 27 | [Bb]uild[Ll]og.* 28 | 29 | #NUNIT 30 | *.VisualState.xml 31 | TestResult.xml 32 | 33 | # Build Results of an ATL Project 34 | [Dd]ebugPS/ 35 | [Rr]eleasePS/ 36 | dlldata.c 37 | 38 | *_i.c 39 | *_p.c 40 | *_i.h 41 | *.ilk 42 | *.meta 43 | *.obj 44 | *.pch 45 | *.pdb 46 | *.pgc 47 | *.pgd 48 | *.rsp 49 | *.sbr 50 | *.tlb 51 | *.tli 52 | *.tlh 53 | *.tmp 54 | *.tmp_proj 55 | *.log 56 | *.vspscc 57 | *.vssscc 58 | .builds 59 | *.pidb 60 | *.svclog 61 | *.scc 62 | 63 | # Chutzpah Test files 64 | _Chutzpah* 65 | 66 | # Visual C++ cache files 67 | ipch/ 68 | *.aps 69 | *.ncb 70 | *.opensdf 71 | *.sdf 72 | *.cachefile 73 | 74 | # Visual Studio profiler 75 | *.psess 76 | *.vsp 77 | *.vspx 78 | 79 | # TFS 2012 Local Workspace 80 | $tf/ 81 | 82 | # Guidance Automation Toolkit 83 | *.gpState 84 | 85 | # ReSharper is a .NET coding add-in 86 | _ReSharper*/ 87 | *.[Rr]e[Ss]harper 88 | *.DotSettings.user 89 | 90 | # JustCode is a .NET coding addin-in 91 | .JustCode 92 | 93 | # TeamCity is a build add-in 94 | _TeamCity* 95 | 96 | # DotCover is a Code Coverage Tool 97 | *.dotCover 98 | 99 | # NCrunch 100 | _NCrunch_* 101 | .*crunch*.local.xml 102 | 103 | # MightyMoose 104 | *.mm.* 105 | AutoTest.Net/ 106 | 107 | # Web workbench (sass) 108 | .sass-cache/ 109 | 110 | # Installshield output folder 111 | [Ee]xpress/ 112 | 113 | # DocProject is a documentation generator add-in 114 | DocProject/buildhelp/ 115 | DocProject/Help/*.HxT 116 | DocProject/Help/*.HxC 117 | DocProject/Help/*.hhc 118 | DocProject/Help/*.hhk 119 | DocProject/Help/*.hhp 120 | DocProject/Help/Html2 121 | DocProject/Help/html 122 | 123 | # Click-Once directory 124 | publish/ 125 | 126 | # Publish Web Output 127 | *.[Pp]ublish.xml 128 | *.azurePubxml 129 | # TODO: Comment the next line if you want to checkin your web deploy settings 130 | # but database connection strings (with potential passwords) will be unencrypted 131 | *.pubxml 132 | *.publishproj 133 | 134 | # NuGet Packages 135 | *.nupkg 136 | # The packages folder can be ignored because of Package Restore 137 | **/packages/* 138 | # except build/, which is used as an MSBuild target. 139 | !**/packages/build/ 140 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 141 | #!**/packages/repositories.config 142 | 143 | # Windows Azure Build Output 144 | csx/ 145 | *.build.csdef 146 | 147 | # Windows Store app package directory 148 | AppPackages/ 149 | 150 | # Others 151 | sql/ 152 | *.Cache 153 | ClientBin/ 154 | [Ss]tyle[Cc]op.* 155 | ~$* 156 | *~ 157 | *.dbmdl 158 | *.dbproj.schemaview 159 | *.pfx 160 | *.publishsettings 161 | node_modules/ 162 | 163 | # RIA/Silverlight projects 164 | Generated_Code/ 165 | 166 | # Backup & report files from converting an old project file 167 | # to a newer Visual Studio version. Backup files are not needed, 168 | # because we have git ;-) 169 | _UpgradeReport_Files/ 170 | Backup*/ 171 | UpgradeLog*.XML 172 | UpgradeLog*.htm 173 | 174 | # SQL Server files 175 | *.mdf 176 | *.ldf 177 | 178 | # Business Intelligence projects 179 | *.rdl.data 180 | *.bim.layout 181 | *.bim_*.settings 182 | 183 | # Microsoft Fakes 184 | FakesAssemblies/ 185 | -------------------------------------------------------------------------------- /ComputeHash/ComputeHash.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | {E6B9F03D-B020-4A3E-BA25-422F2A45B9CE} 7 | Exe 8 | ComputeHash 9 | ComputeHash 10 | v3.5 11 | False 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\Debug 18 | DEBUG; 19 | prompt 20 | 4 21 | x86 22 | true 23 | 24 | 25 | full 26 | true 27 | bin\Release 28 | prompt 29 | 4 30 | x86 31 | true 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ComputeHash/ComputeHash.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeHash", "ComputeHash.csproj", "{E6B9F03D-B020-4A3E-BA25-422F2A45B9CE}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|x86 = Debug|x86 9 | Release|x86 = Release|x86 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {E6B9F03D-B020-4A3E-BA25-422F2A45B9CE}.Debug|x86.ActiveCfg = Debug|x86 13 | {E6B9F03D-B020-4A3E-BA25-422F2A45B9CE}.Debug|x86.Build.0 = Debug|x86 14 | {E6B9F03D-B020-4A3E-BA25-422F2A45B9CE}.Release|x86.ActiveCfg = Release|x86 15 | {E6B9F03D-B020-4A3E-BA25-422F2A45B9CE}.Release|x86.Build.0 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(MonoDevelopProperties) = preSolution 18 | StartupItem = ComputeHash.csproj 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /ComputeHash/CryptoExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Security.Cryptography; 4 | 5 | namespace ComputeHash 6 | { 7 | public static class CryptoExtensions 8 | { 9 | public static string GetMD5Hash(this byte[] input) 10 | { 11 | using (MD5 md5hash = MD5.Create()) { 12 | return GetMD5Hash(md5hash, input); 13 | } 14 | } 15 | 16 | public static string GetMD5Hash(MD5 md5Hash, byte[] input) 17 | { 18 | byte[] data = md5Hash.ComputeHash(input); 19 | 20 | StringBuilder sBuilder = new StringBuilder(); 21 | 22 | for (int i = 0; i < data.Length; i++) 23 | sBuilder.Append(data[i].ToString("x2")); 24 | 25 | return sBuilder.ToString(); 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /ComputeHash/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace ComputeHash 5 | { 6 | class MainClass 7 | { 8 | public static void Main (string[] args) 9 | { 10 | string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Hashes.txt"); 11 | 12 | string[] lines; 13 | if (File.Exists(path)) 14 | lines = File.ReadAllLines(path); 15 | else 16 | lines = new string[]{}; 17 | 18 | foreach (string arg in args) { 19 | string hash = File.ReadAllBytes(arg).GetMD5Hash(); 20 | 21 | bool contains = false; 22 | foreach (string line in lines) { 23 | if (line.StartsWith("//")) 24 | continue; 25 | if (line.Equals(hash)) { 26 | contains = true; 27 | break; 28 | } 29 | } 30 | 31 | if (!contains) { 32 | File.AppendAllText(path, String.Format("// {0}\r\n{1}\r\n\r\n", Path.GetFileName(arg), hash)); 33 | Console.WriteLine("The file's hash has been successfully added to: " + path); 34 | } else { 35 | Console.WriteLine("The file's hash is already added to: " + path); 36 | } 37 | } 38 | Console.ReadKey(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ComputeHash/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle ("ComputeHash")] 8 | [assembly: AssemblyDescription ("")] 9 | [assembly: AssemblyConfiguration ("")] 10 | [assembly: AssemblyCompany ("")] 11 | [assembly: AssemblyProduct ("")] 12 | [assembly: AssemblyCopyright ("balu")] 13 | [assembly: AssemblyTrademark ("")] 14 | [assembly: AssemblyCulture ("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion ("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | 28 | -------------------------------------------------------------------------------- /Example/Pluton/LoadOuts/admin.ini: -------------------------------------------------------------------------------- 1 | [Def] 2 | itemCount=9 3 | ownerCanUse=True 4 | modCanUse=True 5 | normalCanUse=False 6 | 7 | [0] 8 | Name=5.56 Rifle Cartridge 9 | Amount=1000 10 | 11 | [1] 12 | Name=Bone Knife 13 | Amount=1 14 | 15 | [2] 16 | Name=Hammer 17 | Amount=1 18 | 19 | [3] 20 | Name=Bolt Action Rifle 21 | Amount=1 22 | 23 | [4] 24 | Name=Coffee Can Helmet 25 | Amount=1 26 | 27 | [5] 28 | Name=Leather Gloves 29 | Amount=1 30 | 31 | [6] 32 | Name=Burlap Trousers 33 | Amount=1 34 | 35 | [7] 36 | Name=Burlap Shirt 37 | Amount=1 38 | 39 | [8] 40 | Name=Burlap Shoes 41 | Amount=1 42 | 43 | -------------------------------------------------------------------------------- /Example/Pluton/LoadOuts/starter.ini: -------------------------------------------------------------------------------- 1 | [Def] 2 | itemCount=6 3 | ownerCanUse=True 4 | modCanUse=True 5 | normalCanUse=True 6 | 7 | [0] 8 | Name=Stone Hatchet 9 | Amount=1 10 | 11 | [1] 12 | Name=Torch 13 | Amount=1 14 | 15 | [2] 16 | Name=Bandage 17 | Amount=1 18 | 19 | [3] 20 | Name=Bandage 21 | Amount=1 22 | 23 | [4] 24 | Name=Sleeping Bag 25 | Amount=1 26 | 27 | [5] 28 | Name=Lantern 29 | Amount=1 30 | 31 | -------------------------------------------------------------------------------- /Example/Pluton/Plugins/Example/Example.py: -------------------------------------------------------------------------------- 1 | import clr 2 | import sys 3 | from System import String 4 | 5 | class Example: 6 | def On_PlayerConnected(self, player): 7 | for p in Server.ActivePlayers: 8 | if(p.Name != player.Name): 9 | p.Message(String.Format("{0} has joined the server!", player.Name)) 10 | 11 | def On_PlayerDisconnected(self, player): 12 | for p in Server.ActivePlayers: 13 | if(p.Name != player.Name): 14 | p.Message(String.Format("{0} has left the server!", player.Name)) 15 | -------------------------------------------------------------------------------- /Example/Pluton/Pluton.cfg: -------------------------------------------------------------------------------- 1 | [Config] 2 | 3 | ;;; is pluton Enabled? 4 | enabled=true 5 | 6 | ;;; will it display the pluton version upon login 7 | tellVersion = true 8 | 9 | ;;; How often the server will Save. (milliseconds) 10 | saveInterval = 180000 11 | 12 | ;;; how often should the server broadcast messages loop (millisecond) 13 | broadcastInterval = 600000 14 | 15 | ;;; when hitting a resource (tree, rock, body etc) how much extra loot should you get 16 | resourceGatherMultiplier= 1.0 17 | 18 | ;;; want to freeze time? change this to 12 for day, or 0 for night. LEAVE AT -1 TO NOT ENABLE IT 19 | permanentTime=-1 20 | 21 | ;;; the amount of realtime minutes it takes to pass 24 hours in game. has no effect if permanentTime is not -1 22 | timescale= 30 23 | 24 | ;;; crafting timescale. Instacraft: 100000.0 Halfcraft: 2.0 Quartercraft: 4.0 25 | craftTimescale=1.0 26 | 27 | [Logging] 28 | chatInConsole=true 29 | debugInConsole=true 30 | errorInConsole=true 31 | exceptionInConsole=true 32 | 33 | chatInLog=true 34 | debugInLog=true 35 | errorInLog=true 36 | exceptionInLog=true 37 | 38 | [Commands] 39 | enabled=true 40 | 41 | ;;; command to show the registered commands, /commands 42 | Commands=commands 43 | 44 | ;;; command to show a little description of registered commands, /whatdoes statsof 45 | Description=whatis 46 | 47 | ;;; commadn to show registered commands usage, /howto statsof 48 | Usage=howto 49 | ShowStatsOther=statsof 50 | ShowMyStats=mystats 51 | ShowLocation=whereami 52 | ShowOnlinePlayers=players 53 | Help=help 54 | 55 | [HelpMessage] 56 | help_string0=This is an empty help section 57 | 58 | [BroadcastMessages] 59 | msg0=This server is powered by Pluton, the new servermod! 60 | msg1=For more information visit our github repo: github.com/Notulp/Pluton or our forum: pluton-team.org (SOON) 61 | -------------------------------------------------------------------------------- /Example/RustDedicated_Data/Core.cfg: -------------------------------------------------------------------------------- 1 | ; enable / disable dll plugins 2 | [csharp] 3 | enabled=false 4 | checkHash=true 5 | 6 | ; enable / disable python plugins 7 | [python] 8 | enabled=true 9 | checkHash=false 10 | 11 | ; enable / disable javascript plugins 12 | [javascript] 13 | enabled=true 14 | checkHash=false 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Example/RustDedicated_Data/DirectoryConfig.cfg: -------------------------------------------------------------------------------- 1 | [Directories] 2 | ; usable shortcuts: 3 | ;; %root% -> PathToReleaseFolder* 4 | ;; %data% -> %root%\RustDedicated 5 | ;; %identity% -> %root%\server\identity* 6 | ;; %public% -> %identity%\Pluton 7 | 8 | Core=%data%\Core.cfg 9 | Pluton=%public%\Pluton.cfg 10 | Hashes=%data%\Hashes.ini 11 | 12 | -------------------------------------------------------------------------------- /Example/RustDedicated_Data/Hashes.ini: -------------------------------------------------------------------------------- 1 | // BuildDestroyModifier.py 2 | 94b5c6d4a0805a9108fd78b8515dc2e4 3 | // LegacyStructures.dll 4 | b065c9ae9d6c58845eafc613a3577491 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2015 Pluton Team 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 | 23 | -------------------------------------------------------------------------------- /Pluton.Patcher/Pluton.Patcher.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | {F0675A4B-9122-4F79-B676-9C908EF81C2E} 7 | Exe 8 | Pluton.Patcher 9 | Pluton.Patcher 10 | v4.5 11 | 8.0.30703 12 | 2.0 13 | icon.ico 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug 20 | DEBUG; 21 | prompt 22 | 4 23 | x86 24 | true 25 | 26 | 27 | none 28 | true 29 | bin\Release 30 | prompt 31 | 4 32 | x86 33 | true 34 | 35 | 36 | 37 | 38 | ref\ILSpy.exe 39 | 40 | 41 | ref\ICSharpCode.Decompiler.dll 42 | 43 | 44 | 45 | ref\Mono.Cecil.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /Pluton.Patcher/Pluton.Patcher.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pluton.Patcher", "Pluton.Patcher.csproj", "{F0675A4B-9122-4F79-B676-9C908EF81C2E}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|x86 = Debug|x86 9 | Release|x86 = Release|x86 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {F0675A4B-9122-4F79-B676-9C908EF81C2E}.Debug|x86.ActiveCfg = Debug|x86 13 | {F0675A4B-9122-4F79-B676-9C908EF81C2E}.Debug|x86.Build.0 = Debug|x86 14 | {F0675A4B-9122-4F79-B676-9C908EF81C2E}.Release|x86.ActiveCfg = Release|x86 15 | {F0675A4B-9122-4F79-B676-9C908EF81C2E}.Release|x86.Build.0 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(MonoDevelopProperties) = preSolution 18 | StartupItem = Pluton.Patcher.csproj 19 | Policies = $0 20 | $0.TextStylePolicy = $1 21 | $1.FileWidth = 120 22 | $1.inheritsSet = VisualStudio 23 | $1.inheritsScope = text/plain 24 | $1.scope = text/x-csharp 25 | $0.CSharpFormattingPolicy = $2 26 | $2.BeforeMethodDeclarationParentheses = False 27 | $2.BeforeMethodCallParentheses = False 28 | $2.BeforeConstructorDeclarationParentheses = False 29 | $2.BeforeIndexerDeclarationBracket = False 30 | $2.BeforeDelegateDeclarationParentheses = False 31 | $2.AfterDelegateDeclarationParameterComma = True 32 | $2.NewParentheses = False 33 | $2.SpacesBeforeBrackets = False 34 | $2.inheritsSet = Mono 35 | $2.inheritsScope = text/x-csharp 36 | $2.scope = text/x-csharp 37 | outputpath = build\bin 38 | EndGlobalSection 39 | EndGlobal 40 | -------------------------------------------------------------------------------- /Pluton.Patcher/Pluton.Patcher/FieldDefinitionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Mono.Cecil; 6 | 7 | namespace Pluton.Patcher 8 | { 9 | static class FieldDefinitionExtensions 10 | { 11 | public static FieldDefinition SetPublic(this FieldDefinition self, bool value) 12 | { 13 | if (self == null) { 14 | throw new ArgumentNullException("self"); 15 | } 16 | 17 | self.IsPublic = value; 18 | self.IsPrivate = !value; 19 | 20 | return self; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Pluton.Patcher/Pluton.Patcher/MethodDefinitionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Mono.Cecil; 6 | 7 | namespace Pluton.Patcher 8 | { 9 | static class MethodDefinitionExtensions 10 | { 11 | public static MethodDefinition SetPublic(this MethodDefinition self, bool value) 12 | { 13 | if (self == null) { 14 | throw new ArgumentNullException("self"); 15 | } 16 | 17 | self.IsPublic = value; 18 | self.IsPrivate = !value; 19 | 20 | return self; 21 | } 22 | 23 | public static string Print(this MethodDefinition self) 24 | { 25 | return self.PrintIL() + Environment.NewLine + self.PrintCSharp(); 26 | } 27 | 28 | public static string PrintIL(this MethodDefinition self) 29 | { 30 | try { 31 | var textoutput = new ICSharpCode.Decompiler.PlainTextOutput(); 32 | var options = new ICSharpCode.ILSpy.DecompilationOptions(); 33 | var lang = new ICSharpCode.ILSpy.ILLanguage(true); 34 | lang.DecompileMethod(self, textoutput, options); 35 | return textoutput.ToString(); 36 | } catch (Exception ex) { 37 | Console.ForegroundColor = ConsoleColor.Red; 38 | Console.WriteLine(ex.Message); 39 | Console.WriteLine(ex.StackTrace); 40 | Console.ForegroundColor = ConsoleColor.Gray; 41 | return ex.Message; 42 | } 43 | } 44 | 45 | public static string PrintCSharp(this MethodDefinition self) 46 | { 47 | try { 48 | var textoutput = new ICSharpCode.Decompiler.PlainTextOutput(); 49 | var options = new ICSharpCode.ILSpy.DecompilationOptions(); 50 | var lang = new ICSharpCode.ILSpy.CSharpLanguage(); 51 | lang.DecompileMethod(self, textoutput, options); 52 | return textoutput.ToString(); 53 | } catch (Exception ex) { 54 | Console.ForegroundColor = ConsoleColor.Red; 55 | Console.WriteLine(ex.Message); 56 | Console.WriteLine(ex.StackTrace); 57 | Console.ForegroundColor = ConsoleColor.Gray; 58 | return ex.Message; 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Pluton.Patcher/Pluton.Patcher/Reflection/AssemblyPatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Mono.Cecil; 3 | using Mono.Cecil.Cil; 4 | using System.Linq; 5 | using System.Collections.Generic; 6 | 7 | namespace Pluton.Patcher.Reflection 8 | { 9 | public class AssemblyPatcher : PatcherObject 10 | { 11 | internal AssemblyDefinition assemblyDefinition; 12 | internal ModuleDefinition mainModule; 13 | 14 | internal Mono.Collections.Generic.Collection Types { 15 | get { 16 | return mainModule.Types; 17 | } 18 | } 19 | 20 | public AssemblyPatcher(AssemblyDefinition assDef) 21 | { 22 | if (assDef == null) 23 | return; 24 | 25 | assemblyDefinition = assDef; 26 | mainModule = assemblyDefinition.MainModule; 27 | rootAssemblyPatcher = this; 28 | } 29 | 30 | public static AssemblyPatcher FromFile(string filename) 31 | { 32 | return new AssemblyPatcher(AssemblyDefinition.ReadAssembly(filename)); 33 | } 34 | 35 | public TypePatcher CreateType(string @namespace, string name) 36 | { 37 | TypeDefinition plutonClass = new TypeDefinition(@namespace, name, TypeAttributes.Public, mainModule.Import(typeof(Object))); 38 | mainModule.Types.Add(plutonClass); 39 | return GetType(name); 40 | } 41 | 42 | public TypePatcher GetType(string type) 43 | { 44 | var t = mainModule.GetType(type); 45 | if (t == null) return null; 46 | 47 | return new TypePatcher(this, t); 48 | } 49 | 50 | public TypePatcher GetType(Func, TypeDefinition> func) 51 | { 52 | return new TypePatcher(this, func.Invoke(mainModule.GetTypes())); 53 | } 54 | 55 | public MethodReference ImportMethod(MethodPatcher toImport) 56 | { 57 | return mainModule.Import(toImport.methodDefinition); 58 | } 59 | 60 | public void Write(string file) 61 | { 62 | assemblyDefinition.Write(file); 63 | } 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /Pluton.Patcher/Pluton.Patcher/Reflection/PatcherObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton.Patcher.Reflection 4 | { 5 | public class PatcherObject 6 | { 7 | protected PatcherObject parent; 8 | internal AssemblyPatcher rootAssemblyPatcher; 9 | 10 | public PatcherObject(){} 11 | 12 | public PatcherObject(PatcherObject prnt) 13 | { 14 | parent = prnt; 15 | } 16 | 17 | public T As () where T : PatcherObject 18 | { 19 | return (T)this; 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Pluton.Patcher/Pluton.Patcher/Reflection/TypePatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Mono.Cecil; 3 | using Mono.Cecil.Cil; 4 | using System.Linq; 5 | using System.Collections.Generic; 6 | 7 | namespace Pluton.Patcher.Reflection 8 | { 9 | public class TypePatcher : PatcherObject 10 | { 11 | internal TypeDefinition typeDefinition; 12 | 13 | public TypePatcher(PatcherObject prnt, TypeDefinition typDef) : base(prnt) 14 | { 15 | typeDefinition = typDef; 16 | rootAssemblyPatcher = prnt.rootAssemblyPatcher; 17 | } 18 | 19 | public MethodPatcher GetMethod(string method) 20 | { 21 | return new MethodPatcher(this, typeDefinition.GetMethod(method)); 22 | } 23 | 24 | public MethodPatcher GetMethod(Func, MethodDefinition> func) 25 | { 26 | return new MethodPatcher(this, func.Invoke(typeDefinition.GetMethods())); 27 | } 28 | 29 | public TypePatcher GetNestedType(string nestedType) 30 | { 31 | return new TypePatcher(this, typeDefinition.GetNestedType(nestedType)); 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Pluton.Patcher/Pluton.Patcher/TypeDefinitionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Mono.Cecil; 6 | 7 | namespace Pluton.Patcher 8 | { 9 | static class Empty 10 | { 11 | public static readonly T[] Array = new T [0]; 12 | } 13 | 14 | static class TypeDefinitionExtensions 15 | { 16 | public static IEnumerable GetConstructors(this TypeDefinition self) 17 | { 18 | if (self == null) { 19 | throw new ArgumentNullException("self"); 20 | } 21 | 22 | if (!self.HasMethods) { 23 | return Empty.Array; 24 | } 25 | 26 | return self.Methods.Where(method => method.IsConstructor); 27 | } 28 | 29 | public static MethodDefinition GetStaticConstructor(this TypeDefinition self) 30 | { 31 | if (self == null) { 32 | throw new ArgumentNullException("self"); 33 | } 34 | 35 | if (!self.HasMethods) { 36 | return null; 37 | } 38 | 39 | return self.GetConstructors().FirstOrDefault(ctor => ctor.IsStatic); 40 | } 41 | 42 | public static IEnumerable GetMethods(this TypeDefinition self) 43 | { 44 | if (self == null) { 45 | throw new ArgumentNullException("self"); 46 | } 47 | 48 | if (!self.HasMethods) { 49 | return Empty.Array; 50 | } 51 | 52 | return self.Methods.Where(method => !method.IsConstructor); 53 | } 54 | 55 | public static MethodDefinition GetMethod(this TypeDefinition self, String name) 56 | { 57 | if (self == null) { 58 | throw new ArgumentNullException("self"); 59 | } 60 | 61 | if (!self.HasMethods) { 62 | return null; 63 | } 64 | 65 | return self.Methods.FirstOrDefault(v => v.Name == name); 66 | } 67 | 68 | public static FieldDefinition GetField(this TypeDefinition self, String name) 69 | { 70 | if (self == null) { 71 | throw new ArgumentNullException("self"); 72 | } 73 | 74 | if (!self.HasFields) { 75 | return null; 76 | } 77 | 78 | return self.Fields.FirstOrDefault(v => v.Name == name); 79 | } 80 | 81 | public static PropertyDefinition GetProperty(this TypeDefinition self, String name) 82 | { 83 | if (self == null) { 84 | throw new ArgumentNullException("self"); 85 | } 86 | 87 | if (!self.HasProperties) { 88 | return null; 89 | } 90 | 91 | return self.Properties.FirstOrDefault(v => v.Name == name); 92 | } 93 | 94 | public static TypeDefinition GetNestedType(this TypeDefinition self, String name) 95 | { 96 | if (self == null) { 97 | throw new ArgumentNullException("self"); 98 | } 99 | 100 | if (!self.HasNestedTypes) { 101 | return null; 102 | } 103 | 104 | return self.NestedTypes.FirstOrDefault(v => v.Name == name); 105 | } 106 | } 107 | } -------------------------------------------------------------------------------- /Pluton.Patcher/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle ("Pluton.Patcher")] 8 | [assembly: AssemblyDescription ("")] 9 | [assembly: AssemblyConfiguration ("")] 10 | [assembly: AssemblyCompany ("")] 11 | [assembly: AssemblyProduct ("Pluton.Patcher")] 12 | [assembly: AssemblyCopyright ("Pluton team")] 13 | [assembly: AssemblyTrademark ("")] 14 | [assembly: AssemblyCulture ("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion ("1.1.5.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | 28 | -------------------------------------------------------------------------------- /Pluton.Patcher/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/icon.ico -------------------------------------------------------------------------------- /Pluton.Patcher/ref/ICSharpCode.AvalonEdit.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/ref/ICSharpCode.AvalonEdit.dll -------------------------------------------------------------------------------- /Pluton.Patcher/ref/ICSharpCode.Decompiler.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/ref/ICSharpCode.Decompiler.dll -------------------------------------------------------------------------------- /Pluton.Patcher/ref/ICSharpCode.NRefactory.CSharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/ref/ICSharpCode.NRefactory.CSharp.dll -------------------------------------------------------------------------------- /Pluton.Patcher/ref/ICSharpCode.NRefactory.VB.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/ref/ICSharpCode.NRefactory.VB.dll -------------------------------------------------------------------------------- /Pluton.Patcher/ref/ICSharpCode.NRefactory.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/ref/ICSharpCode.NRefactory.dll -------------------------------------------------------------------------------- /Pluton.Patcher/ref/ICSharpCode.TreeView.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/ref/ICSharpCode.TreeView.dll -------------------------------------------------------------------------------- /Pluton.Patcher/ref/ILSpy.BamlDecompiler.Plugin.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/ref/ILSpy.BamlDecompiler.Plugin.dll -------------------------------------------------------------------------------- /Pluton.Patcher/ref/ILSpy.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/ref/ILSpy.exe -------------------------------------------------------------------------------- /Pluton.Patcher/ref/ILSpy.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Pluton.Patcher/ref/Mono.Cecil.Pdb.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/ref/Mono.Cecil.Pdb.dll -------------------------------------------------------------------------------- /Pluton.Patcher/ref/Mono.Cecil.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/ref/Mono.Cecil.dll -------------------------------------------------------------------------------- /Pluton.Patcher/ref/Reflexil.Reflector.AIO.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton.Patcher/ref/Reflexil.Reflector.AIO.dll -------------------------------------------------------------------------------- /Pluton/Bootstrap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Timers; 4 | using UnityEngine; 5 | 6 | namespace Pluton 7 | { 8 | public class Bootstrap : MonoBehaviour 9 | { 10 | public static string Version { get; } = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); 11 | 12 | public static ServerTimers timers; 13 | 14 | public static bool PlutonLoaded = false; 15 | 16 | public static void AttachBootstrap() 17 | { 18 | try { 19 | Hooks.CreateOrUpdateSubjects(); 20 | 21 | System.Reflection.Assembly executingAssembly = System.Reflection.Assembly.GetExecutingAssembly(); 22 | Type[] types = executingAssembly.GetTypes(); 23 | for (int i = 0; i < types.Length; i++) { 24 | object[] customAttributes = types[i].GetCustomAttributes (typeof(ConsoleSystem.Factory), false); 25 | if (customAttributes != null && customAttributes.Length != 0) { 26 | ConsoleSystem.Factory factory = customAttributes[0] as ConsoleSystem.Factory; 27 | typeof(ConsoleSystem.Index).CallStaticMethod("BuildFields", types[i], factory); 28 | typeof(ConsoleSystem.Index).CallStaticMethod("BuildProperties", types[i], factory); 29 | typeof(ConsoleSystem.Index).CallStaticMethod("BuildFunctions", types[i], factory); 30 | } 31 | } 32 | 33 | DirectoryConfig.GetInstance(); 34 | CoreConfig.GetInstance(); 35 | Config.GetInstance(); 36 | 37 | if (!pluton.enabled) { 38 | Debug.Log("[Bootstrap] Pluton is disabled!"); 39 | return; 40 | } 41 | 42 | Init(); 43 | 44 | PlutonLoaded = true; 45 | Console.WriteLine("Pluton Loaded!"); 46 | } catch (Exception ex) { 47 | Debug.LogException(ex); 48 | Debug.Log("[Bootstarp] Error while loading Pluton!"); 49 | } 50 | } 51 | 52 | public static void SaveAll(object x = null) 53 | { 54 | try { 55 | Server.GetInstance().Save(); 56 | DataStore.GetInstance().Save(); 57 | Logger.LogDebug("[Bootstrap] Server saved successfully!"); 58 | } catch (Exception ex) { 59 | Logger.LogDebug("[Bootstrap] Failed to save the server!"); 60 | Logger.LogException(ex); 61 | } 62 | } 63 | 64 | public static void ReloadTimers() 65 | { 66 | if (timers != null) 67 | timers.Dispose(); 68 | 69 | var saver = Config.GetInstance().GetValue("Config", "saveInterval", "180000"); 70 | if (saver != null) { 71 | double save = Double.Parse(saver); 72 | 73 | timers = new ServerTimers(save); 74 | timers.Start(); 75 | } 76 | } 77 | 78 | public static void Init() 79 | { 80 | if (!Directory.Exists(Util.GetPublicFolder())) 81 | Directory.CreateDirectory(Util.GetPublicFolder()); 82 | 83 | Logger.Init(); 84 | CryptoExtensions.Init(); 85 | DataStore.GetInstance().Load(); 86 | Server.GetInstance(); 87 | 88 | LuaPluginLoader.GetInstance(); 89 | CSharpPluginLoader.GetInstance(); 90 | CSScriptPluginLoader.GetInstance(); 91 | JSPluginLoader.GetInstance(); 92 | PYPluginLoader.GetInstance(); 93 | 94 | InstallThreadedOutput(); 95 | 96 | ReloadTimers(); 97 | ConVar.Server.official = false; 98 | } 99 | 100 | public static void InstallThreadedOutput() 101 | { 102 | Application.logMessageReceivedThreaded += new Application.LogCallback(delegate(string condition, string stackTrace, LogType type) { 103 | Logger.ThreadedLogRecieved(condition, stackTrace, type); 104 | }); 105 | Application.logMessageReceived += new Application.LogCallback(delegate(string condition, string stackTrace, LogType type) { 106 | Logger.LogRecieved(condition, stackTrace, type); 107 | }); 108 | } 109 | 110 | public class ServerTimers 111 | { 112 | public readonly Timer _savetimer; 113 | 114 | public ServerTimers(double save) 115 | { 116 | _savetimer = new Timer(save); 117 | 118 | Debug.Log("Server timers started!"); 119 | _savetimer.Elapsed += new ElapsedEventHandler(this._savetimer_Elapsed); 120 | } 121 | 122 | public void Dispose() 123 | { 124 | Stop(); 125 | _savetimer.Dispose(); 126 | } 127 | 128 | public void Start() => _savetimer.Start(); 129 | 130 | public void Stop() => _savetimer.Stop(); 131 | 132 | private void _savetimer_Elapsed(object sender, ElapsedEventArgs e) => SaveAll(); 133 | } 134 | } 135 | } 136 | 137 | -------------------------------------------------------------------------------- /Pluton/Config.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using UnityEngine; 3 | 4 | namespace Pluton 5 | { 6 | public class Config : Singleton, ISingleton 7 | { 8 | public IniParser PlutonConfig; 9 | 10 | public void Initialize() 11 | { 12 | string ConfigPath = DirectoryConfig.GetInstance().GetConfigPath("Pluton"); 13 | 14 | if (File.Exists(ConfigPath)) { 15 | PlutonConfig = new IniParser(ConfigPath); 16 | Debug.Log("Config " + ConfigPath + " loaded!"); 17 | } else { 18 | Directory.CreateDirectory(Util.GetPublicFolder()); 19 | File.Create(ConfigPath).Close(); 20 | PlutonConfig = new IniParser(ConfigPath); 21 | Debug.Log("Config " + ConfigPath + " Created!"); 22 | Debug.Log("The config will be filled with the default values."); 23 | } 24 | pluton.enabled = GetBoolValue("Config", "enabled", true); 25 | } 26 | 27 | public bool CheckDependencies() 28 | { 29 | return SingletonEx.IsInitialzed(); 30 | } 31 | 32 | public string GetValue(string Section, string Setting, string defaultValue = "") 33 | { 34 | if (!PlutonConfig.ContainsSetting(Section, Setting)) { 35 | PlutonConfig.AddSetting(Section, Setting, defaultValue); 36 | PlutonConfig.Save(); 37 | } 38 | return PlutonConfig.GetSetting(Section, Setting, defaultValue); 39 | } 40 | 41 | public bool GetBoolValue(string Section, string Setting, bool defaultValue = false) 42 | { 43 | if (!PlutonConfig.ContainsSetting(Section, Setting)) { 44 | PlutonConfig.AddSetting(Section, Setting, defaultValue.ToString().ToLower()); 45 | PlutonConfig.Save(); 46 | } 47 | return PlutonConfig.GetBoolSetting(Section, Setting, defaultValue); 48 | } 49 | 50 | public void Reload() 51 | { 52 | string ConfigPath = DirectoryConfig.GetInstance().GetConfigPath("Pluton"); 53 | 54 | if (File.Exists(ConfigPath)) 55 | PlutonConfig = new IniParser(ConfigPath); 56 | } 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /Pluton/CoreConfig.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using UnityEngine; 3 | 4 | namespace Pluton 5 | { 6 | public class CoreConfig : Singleton, ISingleton 7 | { 8 | private IniParser ConfigFile; 9 | 10 | public void Initialize() 11 | { 12 | string ConfigPath = DirectoryConfig.GetInstance().GetConfigPath("Core"); 13 | 14 | if (File.Exists(ConfigPath)) { 15 | ConfigFile = new IniParser(ConfigPath); 16 | Debug.Log("Config " + ConfigPath + " loaded!"); 17 | } else { 18 | File.Create(ConfigPath).Close(); 19 | ConfigFile = new IniParser(ConfigPath); 20 | Debug.Log("Core config " + ConfigPath + " Created!"); 21 | Debug.Log("The config will be filled with the default values."); 22 | GenerateConfig(); 23 | ConfigFile.Save(); 24 | } 25 | } 26 | 27 | public bool CheckDependencies() 28 | { 29 | return SingletonEx.IsInitialzed(); 30 | } 31 | 32 | public void GenerateConfig() 33 | { 34 | ConfigFile.AddSetting("csharp", "enabled", "true"); 35 | ConfigFile.AddSetting("csharp", "checkHash", "true"); 36 | 37 | ConfigFile.AddSetting("csscript", "enabled", "true"); 38 | ConfigFile.AddSetting("csscript", "checkHash", "true"); 39 | 40 | ConfigFile.AddSetting("python", "enabled", "true"); 41 | ConfigFile.AddSetting("python", "checkHash", "false"); 42 | 43 | ConfigFile.AddSetting("javascript", "enabled", "true"); 44 | ConfigFile.AddSetting("javascript", "checkHash", "false"); 45 | 46 | ConfigFile.AddSetting("lua", "enabled", "true"); 47 | ConfigFile.AddSetting("lua", "checkHash", "false"); 48 | } 49 | 50 | public string GetValue(string Section, string Setting) 51 | { 52 | return ConfigFile.GetSetting(Section, Setting); 53 | } 54 | 55 | public bool GetBoolValue(string Section, string Setting) 56 | { 57 | return ConfigFile.GetBoolSetting(Section, Setting); 58 | } 59 | 60 | public void Reload() 61 | { 62 | string ConfigPath = DirectoryConfig.GetInstance().GetConfigPath("Core"); 63 | 64 | if (File.Exists(ConfigPath)) 65 | ConfigFile = new IniParser(ConfigPath); 66 | } 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /Pluton/CountedInstance.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Pluton 5 | { 6 | [Serializable] 7 | public class CountedInstance 8 | { 9 | [NonSerialized] 10 | public static Dictionary InstanceTypes = new Dictionary(); 11 | 12 | ~CountedInstance() 13 | { 14 | CountedInstance.RemoveCount(base.GetType()); 15 | } 16 | 17 | public CountedInstance() 18 | { 19 | CountedInstance.AddCount(base.GetType()); 20 | } 21 | 22 | static CountedInstance() 23 | { 24 | CountedInstance.InstanceTypes = new Dictionary(); 25 | } 26 | 27 | internal static void AddCount(Type type) 28 | { 29 | CountedInstance.Counts counts; 30 | if (CountedInstance.InstanceTypes.TryGetValue(type, out counts)) { 31 | counts.Created++; 32 | return; 33 | } 34 | CountedInstance.InstanceTypes.Add(type, new CountedInstance.Counts()); 35 | } 36 | 37 | internal static void RemoveCount(Type type) 38 | { 39 | CountedInstance.Counts counts; 40 | if (CountedInstance.InstanceTypes.TryGetValue(type, out counts)) { 41 | counts.Destroyed++; 42 | } 43 | } 44 | 45 | public static string InstanceReportText() 46 | { 47 | string text = ""; 48 | foreach (KeyValuePair current in CountedInstance.InstanceTypes) { 49 | object obj = text; 50 | text = String.Concat(new object[] { 51 | obj, 52 | current.Key.FullName, 53 | Environment.NewLine + "\tCurrently:\t", 54 | current.Value.Created - current.Value.Destroyed, 55 | Environment.NewLine + "\tCreated: \t", 56 | current.Value.Created, 57 | Environment.NewLine 58 | }); 59 | } 60 | return text; 61 | } 62 | 63 | [Serializable] 64 | public class Counts 65 | { 66 | public int Created = 1; 67 | public int Destroyed; 68 | } 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Pluton/CryptoExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using System.Linq; 5 | using System.Collections.Generic; 6 | using System.Security.Cryptography; 7 | 8 | namespace Pluton 9 | { 10 | public static class CryptoExtensions 11 | { 12 | private static List TrustedHashes; 13 | 14 | public static void Init() 15 | { 16 | TrustedHashes = new List(); 17 | string path = DirectoryConfig.GetInstance().GetConfigPath("Hashes"); 18 | if (!File.Exists(path)) 19 | File.AppendAllText(path, "// empty"); 20 | 21 | TrustedHashes = (from line in File.ReadAllLines(path) 22 | where !String.IsNullOrEmpty(line) && !line.StartsWith("//") 23 | select line).ToList(); 24 | } 25 | 26 | public static string GetMD5Hash(MD5 md5Hash, string input) 27 | { 28 | return GetMD5Hash(md5Hash, Encoding.UTF8.GetBytes(input)); 29 | } 30 | 31 | public static string GetMD5Hash(MD5 md5Hash, byte[] input) 32 | { 33 | byte[] data = md5Hash.ComputeHash(input); 34 | 35 | StringBuilder sBuilder = new StringBuilder(); 36 | 37 | for (int i = 0; i < data.Length; i++) 38 | sBuilder.Append(data[i].ToString("x2")); 39 | 40 | return sBuilder.ToString(); 41 | } 42 | 43 | public static bool VerifyMD5Hash(this string input) 44 | { 45 | using (MD5 md5Hash = MD5.Create()) { 46 | return TrustedHashes.Contains(GetMD5Hash(md5Hash, input)); 47 | } 48 | } 49 | 50 | public static bool VerifyMD5Hash(this byte[] input) 51 | { 52 | using (MD5 md5Hash = MD5.Create()) { 53 | return TrustedHashes.Contains(GetMD5Hash(md5Hash, input)); 54 | } 55 | } 56 | 57 | public static bool VerifyMD5Hash(this string input, string hash) 58 | { 59 | using (MD5 md5hash = MD5.Create()) { 60 | return VerifyMD5Hash(md5hash, input, hash); 61 | } 62 | } 63 | 64 | public static bool VerifyMD5Hash(this byte[] input, string hash) 65 | { 66 | using (MD5 md5hash = MD5.Create()) { 67 | return VerifyMD5Hash(md5hash, input, hash); 68 | } 69 | } 70 | 71 | public static bool VerifyMD5Hash(MD5 md5Hash, string input, string hash) 72 | { 73 | return VerifyMD5Hash(md5Hash, Encoding.UTF8.GetBytes(input), hash); 74 | } 75 | 76 | public static bool VerifyMD5Hash(MD5 md5Hash, byte[] input, string hash) 77 | { 78 | string hashOfInput = GetMD5Hash(md5Hash, input); 79 | 80 | StringComparer comparer = StringComparer.OrdinalIgnoreCase; 81 | 82 | if (0 == comparer.Compare(hashOfInput, hash)) 83 | return true; 84 | else 85 | return false; 86 | } 87 | } 88 | } 89 | 90 | -------------------------------------------------------------------------------- /Pluton/DirectoryConfig.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using UnityEngine; 3 | 4 | namespace Pluton 5 | { 6 | public class DirectoryConfig : Singleton, ISingleton 7 | { 8 | private IniParser DirConfig; 9 | 10 | public void Initialize() 11 | { 12 | string ConfigPath = Path.Combine(Util.GetServerFolder(), "DirectoryConfig.cfg"); 13 | 14 | if (File.Exists(ConfigPath)) { 15 | DirConfig = new IniParser(ConfigPath); 16 | Debug.Log("Config " + ConfigPath + " loaded!"); 17 | } else { 18 | char sc = Path.DirectorySeparatorChar; 19 | Directory.CreateDirectory(Util.GetPublicFolder()); 20 | File.Create(ConfigPath).Close(); 21 | DirConfig = new IniParser(ConfigPath); 22 | Debug.Log("Config " + ConfigPath + " Created!"); 23 | Debug.Log("The config will be filled with the default values."); 24 | DirConfig.AddSetting("Directories", "Core", "%data%" + sc + "Core.cfg"); 25 | DirConfig.AddSetting("Directories", "Pluton", "%public%" + sc + "Pluton.cfg"); 26 | DirConfig.AddSetting("Directories", "Hashes", "%data%" + sc + "Hashes.ini"); 27 | DirConfig.Save(); 28 | } 29 | } 30 | 31 | public bool CheckDependencies() 32 | { 33 | return true; 34 | } 35 | 36 | public string GetConfigPath(string config) 37 | { 38 | string path = DirConfig.GetSetting("Directories", config); 39 | 40 | if (path.StartsWith("%public%")) 41 | path = path.Replace("%public%", Util.GetPublicFolder()); 42 | 43 | if (path.StartsWith("%data%")) 44 | path = path.Replace("%data%", Util.GetServerFolder()); 45 | 46 | if (path.StartsWith("%root%")) 47 | path = path.Replace("%root%", Util.GetRootFolder()); 48 | 49 | if (path.StartsWith("%identity%")) 50 | path = path.Replace("%identity%", Util.GetIdentityFolder()); 51 | 52 | return path; 53 | } 54 | 55 | public void Reload() 56 | { 57 | string ConfigPath = Path.Combine(Util.GetServerFolder(), "DirectoryConfig.cfg"); 58 | 59 | if (File.Exists(ConfigPath)) 60 | DirConfig = new IniParser(ConfigPath); 61 | } 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /Pluton/Documentation/DoqAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Pluton.Documentation 5 | { 6 | public class DoqAttribute : Attribute 7 | { 8 | public object category; 9 | 10 | public object doqType; 11 | 12 | public string description = "none"; 13 | 14 | public Type[] args; 15 | 16 | public DoqAttribute(params Type[] Args){ 17 | args = Args; 18 | } 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Pluton/Documentation/DoqEnums.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton.Documentation 4 | { 5 | public enum DoqCategory 6 | { 7 | Pluton_Hooks, 8 | Pluton_Objects, 9 | Pluton_Events, 10 | Pluton_Libraries, 11 | Pluton_Libary_Methods 12 | } 13 | 14 | public enum DoqType 15 | { 16 | Class, 17 | Field, 18 | Enum, 19 | Hook, 20 | Method 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Pluton/Events/AuthEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Network; 3 | 4 | namespace Pluton.Events 5 | { 6 | public class AuthEvent : CountedInstance 7 | { 8 | public bool Approved; 9 | 10 | [Obsolete("AuthEvent.approved is obsolete and will be removed, please use AuthEvent.Approved", true)] 11 | public bool approved { 12 | get { return Approved; } 13 | set { Approved = value; } 14 | } 15 | 16 | public readonly Connection Connection; 17 | 18 | [Obsolete("AuthEvent.con is obsolete and will be removed, please use AuthEvent.Connection", true)] 19 | public Connection con { 20 | get { return Connection; } 21 | } 22 | 23 | public ulong GameID { 24 | get { return Connection.userid; } 25 | } 26 | 27 | public string IP { 28 | get { return Connection.ipaddress; } 29 | } 30 | 31 | public string Name { 32 | get { return Connection.username; } 33 | } 34 | 35 | public string OS { 36 | get { return Connection.os; } 37 | } 38 | 39 | public string Reason; 40 | 41 | [Obsolete("AuthEvent._reason is obsolete and will be removed, please use AuthEvent.Reason", true)] 42 | public string _reason { 43 | get { return Reason; } 44 | set { Reason = value; } 45 | } 46 | 47 | public AuthEvent(Connection connection) 48 | { 49 | Connection = connection; 50 | Approved = true; 51 | } 52 | 53 | public void Reject(string reason = "no reason") 54 | { 55 | Approved = false; 56 | Reason = reason; 57 | } 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /Pluton/Events/BuildingEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton.Events 4 | { 5 | public class BuildingEvent : CountedInstance 6 | { 7 | public BuildingPart BuildingPart; 8 | public readonly Player Builder; 9 | public readonly Construction Construction; 10 | public readonly Construction.Target Target; 11 | public bool NeedsValidPlacement; 12 | 13 | public string DestroyReason = String.Empty; 14 | public bool DoDestroy = false; 15 | 16 | public BuildingEvent(Construction construction, Construction.Target target, BuildingBlock bb, bool bNeedsValidPlacement) 17 | { 18 | Builder = Server.GetPlayer(target.player); 19 | BuildingPart = new BuildingPart(bb); 20 | Construction = construction; 21 | Target = target; 22 | NeedsValidPlacement = bNeedsValidPlacement; 23 | } 24 | 25 | public void Destroy(string reason = "Plugin blocks building!") 26 | { 27 | DoDestroy = true; 28 | DestroyReason = reason; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Pluton/Events/BuildingPartDemolishedEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class BuildingPartDemolishedEvent : CountedInstance 4 | { 5 | public readonly Player Player; 6 | public readonly BuildingPart BuildingPart; 7 | 8 | public BuildingPartDemolishedEvent(BuildingBlock bb, BasePlayer basePlayer) 9 | { 10 | BuildingPart = new BuildingPart(bb); 11 | Player = Server.GetPlayer(basePlayer); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Pluton/Events/BuildingPartDestroyedEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton.Events 4 | { 5 | public class BuildingPartDestroyedEvent : CountedInstance 6 | { 7 | public readonly BuildingPart BuildingPart; 8 | 9 | [Obsolete("BuildingPartDestroyedEvent.buildingPart is obsolete and will be removed, please use BuildingPartDestroyedEvent.BuildingPart", true)] 10 | public BuildingPart buildingPart { 11 | get { return BuildingPart; } 12 | } 13 | 14 | public readonly HitInfo Info; 15 | 16 | [Obsolete("BuildingPartDestroyedEvent._info is obsolete and will be removed, please use BuildingPartDestroyedEvent.Info", true)] 17 | public HitInfo _info { 18 | get { return Info; } 19 | } 20 | 21 | public readonly string HitBone; 22 | 23 | public BuildingPartDestroyedEvent(BuildingBlock bb, HitInfo info) 24 | { 25 | Info = info; 26 | BuildingPart = new BuildingPart(bb); 27 | string bonename = StringPool.Get(info.HitBone); 28 | HitBone = bonename == "" ? "unknown" : bonename; 29 | } 30 | 31 | public float[] DamageAmounts { 32 | get { 33 | return Info.damageTypes.types; 34 | } 35 | set { 36 | Info.damageTypes.types = value; 37 | } 38 | } 39 | 40 | public Rust.DamageType DamageType { 41 | get { return Info.damageTypes.GetMajorityDamageType(); } 42 | } 43 | 44 | public Entity Attacker { 45 | get { 46 | try { 47 | if (Info.Initiator != null) { 48 | BaseEntity ent = Info.Initiator; 49 | BasePlayer p = ent.GetComponent(); 50 | if (p != null) 51 | return Server.GetPlayer(p); 52 | 53 | BaseNPC n = ent.GetComponent(); 54 | if (n != null) 55 | return new NPC(n); 56 | 57 | return new Entity(ent); 58 | } 59 | return null; 60 | } catch (Exception ex) { 61 | Logger.LogWarning("[BPDestroyedEvent] Got an exception instead of the attacker."); 62 | Logger.LogException(ex); 63 | return null; 64 | } 65 | } 66 | } 67 | 68 | public InvItem Weapon { 69 | get { 70 | try { 71 | if (Info.Weapon == null) 72 | return null; 73 | uint itemUID = (uint)Info.Weapon.GetFieldValue("ownerItemUID"); 74 | 75 | BasePlayer ownerPlayer = Info.Weapon.ownerPlayer; 76 | if (ownerPlayer == null) { 77 | return null; 78 | } 79 | 80 | return new InvItem(ownerPlayer.inventory.FindItemUID(itemUID)); 81 | } catch (Exception ex) { 82 | Logger.LogWarning("[BPDestroyedEvent] Got an exception instead of the weapon."); 83 | Logger.LogException(ex); 84 | return null; 85 | } 86 | } 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /Pluton/Events/BuildingPartGradeChangeEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class BuildingPartGradeChangeEvent: CountedInstance 4 | { 5 | private BuildingGrade.Enum grade; 6 | 7 | public BuildingPart BuildingPart; 8 | public readonly Player Builder; 9 | 10 | public bool HasPrivilege; 11 | public bool Rotatable = true; 12 | public bool PayForUpgrade = true; 13 | 14 | public string DestroyReason = string.Empty; 15 | public bool DoDestroy = false; 16 | 17 | public BuildingPartGradeChangeEvent(BuildingBlock bb, BuildingGrade.Enum bgrade, BasePlayer player) 18 | { 19 | BuildingPart = new BuildingPart(bb); 20 | Builder = Server.GetPlayer(player); 21 | grade = bgrade; 22 | 23 | HasPrivilege = (bool)bb.CallMethod("CanChangeToGrade", bgrade, player); 24 | } 25 | 26 | public BuildingGrade.Enum Grade { 27 | get { return grade; } 28 | set { grade = value; } 29 | } 30 | 31 | public int GradeInt { 32 | get { return (int)grade; } 33 | set { grade = (BuildingGrade.Enum)value; } 34 | } 35 | 36 | public void Destroy(string reason = "Plugin blocks building!") 37 | { 38 | DoDestroy = true; 39 | DestroyReason = reason; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Pluton/Events/ChatEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton.Events 4 | { 5 | public class ChatEvent : CountedInstance 6 | { 7 | public readonly ConsoleSystem.Arg Arg; 8 | 9 | [Obsolete("ChatEvent._arg is obsolete and will be removed, please use ChatEvent.Arg", true)] 10 | public ConsoleSystem.Arg _arg { 11 | get { return Arg; } 12 | } 13 | 14 | public readonly string OriginalText; 15 | public readonly Player User; 16 | public string BroadcastName; 17 | public string FinalText; 18 | public string Reply; 19 | 20 | public ChatEvent(Player player, ConsoleSystem.Arg args) 21 | { 22 | User = player; 23 | Arg = args; 24 | if (args.connection != null) 25 | BroadcastName = args.connection.username; 26 | else 27 | BroadcastName = Server.server_message_name; 28 | OriginalText = args.ArgsStr.Substring(1, args.ArgsStr.Length - 2).Replace("\\", ""); 29 | FinalText = OriginalText.Replace('<', '[').Replace('>', ']'); 30 | Reply = "chat.say was executed"; 31 | } 32 | 33 | public void Cancel(string reply = "Your message was not sent") 34 | { 35 | FinalText = ""; 36 | Reply = reply; 37 | } 38 | 39 | public void ReplyWith(string msg) => Reply = msg; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /Pluton/Events/ClientConsoleEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Pluton.Events 5 | { 6 | public class ClientConsoleEvent : CountedInstance 7 | { 8 | public readonly ConsoleSystem.Arg Internal; 9 | public readonly Player User; 10 | 11 | public readonly string Cmd; 12 | 13 | [Obsolete("ClientConsoleEvent.cmd is obsolete and will be removed, please use ClientConsoleEvent.Cmd", true)] 14 | public string cmd { 15 | get { return Cmd; } 16 | } 17 | 18 | public readonly List Args; 19 | public string Reply; 20 | 21 | public ClientConsoleEvent(ConsoleSystem.Arg arg, string rconCmd) 22 | { 23 | Internal = arg; 24 | User = Server.GetPlayer((BasePlayer)arg.connection.player); 25 | Args = new List(); 26 | 27 | Reply = "Command not found!"; 28 | 29 | if (String.IsNullOrEmpty(rconCmd)) 30 | return; 31 | 32 | foreach (string str in rconCmd.Split(' ')) 33 | Args.Add(str); 34 | 35 | Cmd = Args[0]; 36 | Args.RemoveAt(0); 37 | } 38 | 39 | public void ReplyWith(string msg) => Reply = msg; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Pluton/Events/CombatEntityHurtEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class CombatEntityHurtEvent : HurtEvent 4 | { 5 | public readonly Entity Victim; 6 | 7 | public CombatEntityHurtEvent(BaseCombatEntity combatEnt, HitInfo info) 8 | : base(info) 9 | { 10 | var block = combatEnt.GetComponent(); 11 | 12 | if (block != null) 13 | Victim = new BuildingPart(block); 14 | else 15 | Victim = new Entity(combatEnt); 16 | } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Pluton/Events/CommandEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton.Events 4 | { 5 | public class CommandEvent : CountedInstance 6 | { 7 | 8 | public readonly string[] Args; 9 | 10 | [Obsolete("CommandEvent.args is obsolete and will be removed, please use CommandEvent.Args", true)] 11 | public string[] args { 12 | get { return Args; } 13 | } 14 | 15 | public readonly string Cmd; 16 | 17 | [Obsolete("CommandEvent.cmd is obsolete and will be removed, please use CommandEvent.Cmd", true)] 18 | public string cmd { 19 | get { return Cmd; } 20 | } 21 | 22 | public string[] QuotedArgs { 23 | get { 24 | return Util.GetInstance().GetQuotedArgs(Args); 25 | } 26 | } 27 | 28 | [Obsolete("CommandEvent.quotedArgs is obsolete and will be removed, please use CommandEvent.QuotedArgs", true)] 29 | public string[] quotedArgs { 30 | get { return QuotedArgs; } 31 | } 32 | 33 | public string Reply; 34 | 35 | public readonly Player User; 36 | 37 | public CommandEvent(Player player, string[] command) 38 | { 39 | User = player; 40 | Reply = String.Format("/{0} executed!", String.Join(" ", command)); 41 | Cmd = command[0]; 42 | Args = new string[command.Length - 1]; 43 | Array.Copy(command, 1, Args, 0, command.Length - 1); 44 | } 45 | 46 | public void ReplyWith(string msg) => Reply = msg; 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /Pluton/Events/CommandPermissionEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton.Events 4 | { 5 | public class CommandPermissionEvent : CommandEvent 6 | { 7 | public bool Blocked = false; 8 | 9 | [Obsolete("CommandPermissionEvent.blocked is obsolete and will be removed, please use CommandPermissionEvent.Blocked", true)] 10 | public bool blocked { 11 | get { return Blocked; } 12 | } 13 | 14 | public readonly ChatCommand ChatCommand; 15 | 16 | [Obsolete("CommandPermissionEvent.chatCommand is obsolete and will be removed, please use CommandPermissionEvent.ChatCommand", true)] 17 | public ChatCommand chatCommand { 18 | get { return ChatCommand; } 19 | } 20 | 21 | public CommandPermissionEvent(Player player, string[] command, ChatCommand chatCmd) 22 | : base(player, command) 23 | { 24 | ChatCommand = chatCmd; 25 | } 26 | 27 | public void BlockCommand(string reason) 28 | { 29 | Reply = reason; 30 | Blocked = true; 31 | } 32 | 33 | public string PluginName { 34 | get { return ChatCommand.plugin.Name; } 35 | } 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Pluton/Events/ConsumeFuelEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class ConsumeFuelEvent : CountedInstance 4 | { 5 | private BaseOven _baseOven; 6 | private InvItem _item; 7 | private ItemModBurnable _burn; 8 | 9 | public ConsumeFuelEvent(BaseOven bo, Item fuel, ItemModBurnable burn) 10 | { 11 | _baseOven = bo; 12 | _item = new InvItem(fuel); 13 | _burn = burn; 14 | } 15 | 16 | public BaseOven BaseOven { 17 | get { return _baseOven; } 18 | } 19 | 20 | public InvItem Item { 21 | get { return _item; } 22 | } 23 | 24 | public ItemModBurnable Burnable { 25 | get { return _burn; } 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Pluton/Events/CorpseHurtEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class CorpseHurtEvent : HurtEvent 4 | { 5 | public readonly BaseCorpse corpse; 6 | 7 | public CorpseHurtEvent(BaseCorpse c, HitInfo info) 8 | : base(info) 9 | { 10 | corpse = c; 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Pluton/Events/CorpseInitEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class CorpseInitEvent : CountedInstance 4 | { 5 | public readonly BaseCorpse Corpse; 6 | public readonly Entity Parent; 7 | 8 | public CorpseInitEvent(BaseCorpse c, BaseEntity p) 9 | { 10 | Corpse = c; 11 | Parent = new Entity(p); 12 | } 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Pluton/Events/CraftEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class CraftEvent : CountedInstance 4 | { 5 | /// 6 | /// The Player who started crafting. 7 | /// 8 | public Player Crafter; 9 | 10 | /// 11 | /// Item.Definition of the target item. 12 | /// 13 | public ItemDefinition Target; 14 | 15 | /// 16 | /// The ItemCrafter object. 17 | /// 18 | public ItemCrafter itemCrafter; 19 | 20 | /// 21 | /// The blueprint. 22 | /// 23 | public ItemBlueprint bluePrint; 24 | 25 | /// 26 | /// Amount of crafting item. 27 | /// 28 | public int Amount; 29 | 30 | /// 31 | /// Cancels teh event. 32 | /// 33 | public bool Cancel = false; 34 | 35 | /// 36 | /// Notify the Crafter about the action. 37 | /// 38 | public string cancelReason = System.String.Empty; 39 | 40 | public int SkinID; 41 | 42 | public CraftEvent(ItemCrafter self, ItemBlueprint bp, BasePlayer owner, ProtoBuf.Item.InstanceData instanceData, int amount, int skinid) 43 | { 44 | Crafter = Server.GetPlayer(owner); 45 | Target = bp.targetItem; 46 | itemCrafter = self; 47 | Amount = amount; 48 | bluePrint = bp; 49 | SkinID = skinid; 50 | } 51 | 52 | public void Stop(string reason = "A plugin stops you from crafting that!") 53 | { 54 | cancelReason = reason; 55 | Cancel = true; 56 | } 57 | 58 | /// 59 | /// Gets or sets the time needed to craft this item. NOTE: this is saved for each blueprint, so CraftTime /= 2; will make instacraft eventually. Be careful! 60 | /// 61 | /// The craft time. 62 | public float CraftTime { 63 | get { 64 | return bluePrint.time; 65 | } 66 | set { 67 | bluePrint.time = value; 68 | } 69 | } 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /Pluton/Events/DeathEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton.Events 4 | { 5 | public class DeathEvent : CountedInstance 6 | { 7 | public readonly HitInfo _info; 8 | public bool dropLoot = true; 9 | public readonly string HitBone; 10 | public bool Die = true; 11 | 12 | public DeathEvent(HitInfo info) 13 | { 14 | _info = info; 15 | string bonename = StringPool.Get(info.HitBone); 16 | HitBone = bonename == "" ? "unknown" : bonename; 17 | } 18 | 19 | /****************** 20 | * * 21 | * Generic 0 * 22 | * Hunger 1 * 23 | * Thirst 2 * 24 | * Cold 3 * 25 | * Drowned 4 * 26 | * Heat 5 * 27 | * Bleeding 6 * 28 | * Poison 7 * 29 | * Suicide 8 * 30 | * Bullet 9 * 31 | * Slash 10 * 32 | * Blunt 11 * 33 | * Fall 12 * 34 | * Radiation 13 * 35 | * Bite 14 * 36 | * Stab 15 * 37 | * * 38 | ******************/ 39 | 40 | public float[] DamageAmounts { 41 | get { 42 | return _info.damageTypes.types; 43 | } 44 | set { 45 | _info.damageTypes.types = value; 46 | } 47 | } 48 | 49 | public Rust.DamageType DamageType { 50 | get { return _info.damageTypes.GetMajorityDamageType(); } 51 | } 52 | 53 | public Entity Attacker { 54 | get { 55 | try { 56 | if (_info.Initiator != null) { 57 | BaseEntity ent = _info.Initiator; 58 | BasePlayer p = ent.GetComponent(); 59 | if (p != null) 60 | return Server.GetPlayer(p); 61 | 62 | BaseNPC n = ent.GetComponent(); 63 | if (n != null) 64 | return new NPC(n); 65 | 66 | return new Entity(ent); 67 | } 68 | return null; 69 | } catch (Exception ex) { 70 | Logger.LogWarning("[HurtEvent] Got an exception instead of the attacker."); 71 | Logger.LogException(ex); 72 | return null; 73 | } 74 | } 75 | } 76 | 77 | public InvItem Weapon { 78 | get { 79 | try { 80 | if (_info.Weapon == null) 81 | return null; 82 | uint itemUID = (uint)_info.Weapon.GetFieldValue("ownerItemUID"); 83 | 84 | BasePlayer ownerPlayer = _info.Weapon.ownerPlayer; 85 | if (ownerPlayer == null) { 86 | return null; 87 | } 88 | 89 | return new InvItem(ownerPlayer.inventory.FindItemUID(itemUID)); 90 | } catch (Exception ex) { 91 | Logger.LogWarning("[DeathEvent] Got an exception instead of the weapon."); 92 | Logger.LogException(ex); 93 | return null; 94 | } 95 | } 96 | } 97 | } 98 | } 99 | 100 | -------------------------------------------------------------------------------- /Pluton/Events/DoorCodeEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Pluton.Events 5 | { 6 | public class DoorCodeEvent : CountedInstance 7 | { 8 | public Player Player; 9 | public CodeLock codeLock; 10 | 11 | public bool allowed = true; 12 | public bool forceAllow = false; 13 | 14 | private string _entered; 15 | 16 | public string Code { 17 | get { 18 | return (string)codeLock.GetFieldValue("code"); 19 | } 20 | set { 21 | int code; 22 | if (value.Length == 4 && Int32.TryParse(value, out code)) { 23 | codeLock.SetFieldValue("code", code); 24 | } 25 | } 26 | } 27 | 28 | public string Entered { 29 | get { 30 | return _entered; 31 | } 32 | set { 33 | int code; 34 | if (value.Length == 4 && Int32.TryParse(value, out code)) { 35 | _entered = value; 36 | } 37 | } 38 | } 39 | 40 | public DoorCodeEvent(CodeLock doorLock, BasePlayer player, string entered) 41 | { 42 | codeLock = doorLock; 43 | _entered = entered; 44 | Player = Server.GetPlayer(player); 45 | } 46 | 47 | public void Allow() => forceAllow = true; 48 | 49 | public void ClearWhitelist() => codeLock.SetFieldValue("whitelistPlayers", new List()); 50 | 51 | public void Deny() => allowed = false; 52 | 53 | public bool IsCorrect() => _entered == Code; 54 | 55 | public void RemoveCode() 56 | { 57 | codeLock.SetFieldValue("code", ""); 58 | codeLock.SetFieldValue("hasCode", false); 59 | codeLock.SetFlag(BaseEntity.Flags.Locked, false); 60 | Allow(); 61 | } 62 | 63 | public void ResetLock() 64 | { 65 | codeLock.SetFieldValue("code", ""); 66 | codeLock.SetFieldValue("hasCode", false); 67 | codeLock.SetFlag(BaseEntity.Flags.Locked, false); 68 | codeLock.SetFieldValue("whitelistPlayers", new List()); 69 | } 70 | 71 | public void Whitelist() 72 | { 73 | List whitelist = new List(); 74 | whitelist = (List)codeLock.GetFieldValue("whitelistPlayers"); 75 | whitelist.Add(Player.GameID); 76 | codeLock.SetFieldValue("whitelistPlayers", whitelist); 77 | } 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /Pluton/Events/DoorUseEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class DoorUseEvent : CountedInstance 4 | { 5 | public bool Allow = true; // allow the player to open ( or try to open with a lock ) the door ? 6 | public bool Open; // is the player opening or closing the door ? 7 | public bool IgnoreLock = false; 8 | public Player Player; 9 | public Entity Door; 10 | 11 | public string DenyReason = ""; 12 | 13 | public DoorUseEvent(Entity door, Player player, bool open) 14 | { 15 | Door = door; 16 | Open = open; 17 | Player = player; 18 | } 19 | 20 | public void Deny(string reason = "") 21 | { 22 | Allow = false; 23 | DenyReason = reason; 24 | } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Pluton/Events/EntityLootEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class EntityLootEvent : LootEvent 4 | { 5 | public readonly Entity Target; 6 | 7 | public EntityLootEvent(PlayerLoot pl, Player looter, Entity looted) 8 | : base(pl, looter) 9 | { 10 | Target = looted; 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Pluton/Events/EventTriggeredEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class EventTriggeredEvent : CountedInstance 4 | { 5 | bool stopevent = false; 6 | GameObjectRef targetPrefab = null; 7 | 8 | public EventTriggeredEvent(TriggeredEventPrefab triggeredEventPrefab) 9 | { 10 | targetPrefab = triggeredEventPrefab.targetPrefab; 11 | } 12 | 13 | public bool Stop { 14 | get { return stopevent; } 15 | set { stopevent = value; } 16 | } 17 | 18 | public GameObjectRef PrefabRef { 19 | get { return targetPrefab; } 20 | set { targetPrefab = value; } 21 | } 22 | 23 | public string Prefab { 24 | get { return targetPrefab.resourcePath; } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Pluton/Events/GatherEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class GatherEvent : CountedInstance 4 | { 5 | private ResourceDispenser _resourceDispenser; 6 | private Player _gatherer; 7 | private Entity _resource; 8 | private ItemAmount _itemAmount; 9 | private int _amount; 10 | 11 | public GatherEvent(ResourceDispenser dispenser, BaseEntity from, BaseEntity to, ItemAmount itemAmt, int amount) 12 | { 13 | if (to is BasePlayer) { 14 | _gatherer = Server.GetPlayer((BasePlayer)to); 15 | _resource = new Entity(from); 16 | _resourceDispenser = dispenser; 17 | _itemAmount = itemAmt; 18 | _amount = (int)(amount * World.GetInstance().ResourceGatherMultiplier); 19 | } 20 | } 21 | 22 | public ResourceDispenser ResourceDispenser { 23 | get { return _resourceDispenser; } 24 | } 25 | 26 | public Player Gatherer { 27 | get { return _gatherer; } 28 | } 29 | 30 | public Entity Resource { 31 | get { return _resource; } 32 | } 33 | 34 | public ItemAmount ItemAmount { 35 | get { return _itemAmount; } 36 | } 37 | 38 | public int Amount { 39 | get { return _amount; } 40 | set { _amount = value; } 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Pluton/Events/HammerEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class HammerEvent : CountedInstance 4 | { 5 | public readonly HitInfo _info; 6 | public readonly string HitBone; 7 | public readonly BasePlayer basePlayer; 8 | 9 | public HammerEvent(HitInfo info, BasePlayer player) 10 | { 11 | _info = info; 12 | basePlayer = player; 13 | string bonename = StringPool.Get(info.HitBone); 14 | HitBone = bonename == "" ? "unknown" : bonename; 15 | } 16 | 17 | public Player Player { 18 | get { return Server.GetPlayer(basePlayer); } 19 | } 20 | 21 | public Entity Victim { 22 | get { 23 | BaseEntity ent = _info.HitEntity; 24 | BasePlayer p = ent.GetComponent(); 25 | if (p != null) 26 | return Server.GetPlayer(p); 27 | BaseNPC n = ent.GetComponent(); 28 | if (n != null) 29 | return new NPC(n); 30 | return new Entity(ent); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Pluton/Events/HurtEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton.Events 4 | { 5 | public class HurtEvent : CountedInstance 6 | { 7 | public readonly HitInfo _info; 8 | public readonly string HitBone; 9 | 10 | public HurtEvent(HitInfo info) 11 | { 12 | _info = info; 13 | string bonename = StringPool.Get(info.HitBone); 14 | HitBone = bonename == "" ? "unknown" : bonename; 15 | } 16 | 17 | /****************** 18 | * * 19 | * Generic 0 * 20 | * Hunger 1 * 21 | * Thirst 2 * 22 | * Cold 3 * 23 | * Drowned 4 * 24 | * Heat 5 * 25 | * Bleeding 6 * 26 | * Poison 7 * 27 | * Suicide 8 * 28 | * Bullet 9 * 29 | * Slash 10 * 30 | * Blunt 11 * 31 | * Fall 12 * 32 | * Radiation 13 * 33 | * Bite 14 * 34 | * Stab 15 * 35 | * * 36 | ******************/ 37 | 38 | public float[] DamageAmounts { 39 | get { 40 | return _info.damageTypes.types; 41 | } 42 | set { 43 | _info.damageTypes.types = value; 44 | } 45 | } 46 | 47 | public Rust.DamageType DamageType { 48 | get { return _info.damageTypes.GetMajorityDamageType(); } 49 | } 50 | 51 | public Entity Attacker { 52 | get { 53 | try { 54 | if (_info.Initiator != null) { 55 | BaseEntity ent = _info.Initiator; 56 | BasePlayer p = ent.GetComponent(); 57 | if (p != null) 58 | return Server.GetPlayer(p); 59 | 60 | BaseNPC n = ent.GetComponent(); 61 | if (n != null) 62 | return new NPC(n); 63 | 64 | return new Entity(ent); 65 | } 66 | return null; 67 | } catch (Exception ex) { 68 | Logger.LogWarning("[HurtEvent] Got an exception instead of the attacker."); 69 | Logger.LogException(ex); 70 | return null; 71 | } 72 | } 73 | } 74 | 75 | public InvItem Weapon { 76 | get { 77 | try { 78 | if (_info.Weapon == null) 79 | return null; 80 | 81 | return new InvItem(_info.Weapon.GetItem()); 82 | } catch (Exception ex) { 83 | Logger.LogWarning("[HurtEvent] Got an exception instead of the weapon."); 84 | Logger.LogException(ex); 85 | return null; 86 | } 87 | } 88 | } 89 | } 90 | } 91 | 92 | -------------------------------------------------------------------------------- /Pluton/Events/InventoryModEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class InventoryModEvent : CountedInstance 4 | { 5 | private InvItem _item; 6 | private ItemContainer _itemContainer; 7 | private Player _owner; 8 | private Entity _entity; 9 | 10 | public InventoryModEvent(ItemContainer ic, Item i) 11 | { 12 | _item = new InvItem(i); 13 | _itemContainer = ic; 14 | 15 | if (ic.entityOwner != null) 16 | _entity = new Entity(ic.entityOwner); 17 | if (ic.playerOwner != null) 18 | _owner = Server.GetPlayer(ic.playerOwner); 19 | } 20 | 21 | public InvItem Item { 22 | get { return _item; } 23 | } 24 | 25 | public ItemContainer ItemContainer { 26 | get { return _itemContainer; } 27 | } 28 | 29 | public Player Player { 30 | get { return _owner; } 31 | } 32 | 33 | public Entity Entity { 34 | get { return _entity; } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Pluton/Events/ItemConditionEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class ItemConditionEvent : CountedInstance 4 | { 5 | private InvItem _item; 6 | private float _amount; 7 | 8 | public Player Player; 9 | 10 | public ItemConditionEvent(Item item, float amount) 11 | { 12 | _item = new InvItem(item); 13 | _amount = amount; 14 | Player = Server.GetPlayer(item.GetOwnerPlayer()); 15 | } 16 | 17 | public InvItem Item { 18 | get { return _item; } 19 | } 20 | 21 | public float Amount { 22 | get { return _amount; } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Pluton/Events/ItemLootEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class ItemLootEvent : LootEvent 4 | { 5 | public readonly Item Target; 6 | 7 | public ItemLootEvent(PlayerLoot pl, Player looter, Item looted) 8 | : base(pl, looter) 9 | { 10 | Target = looted; 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Pluton/Events/ItemPickupEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class ItemPickupEvent : CountedInstance 4 | { 5 | private InvItem _item; 6 | private Player _player; 7 | private BaseEntity.RPCMessage _msg; 8 | private CollectibleEntity _entity; 9 | 10 | public ItemPickupEvent(CollectibleEntity ce, BaseEntity.RPCMessage msg, Item i) 11 | { 12 | _entity = ce; 13 | _msg = msg; 14 | _player = Server.GetPlayer(msg.player); 15 | _item = new InvItem(i); 16 | } 17 | 18 | public BaseEntity.RPCMessage RPCMessage { 19 | get { return _msg; } 20 | } 21 | 22 | public CollectibleEntity Entity { 23 | get { return _entity; } 24 | } 25 | 26 | public InvItem Item { 27 | get { return _item; } 28 | } 29 | 30 | public Player Player { 31 | get { return _player; } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Pluton/Events/ItemRepairEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class ItemRepairEvent : CountedInstance 4 | { 5 | private RepairBench _repairBench; 6 | private Player _player; 7 | private InvItem _item; 8 | private BaseEntity.RPCMessage _msg; 9 | 10 | public ItemRepairEvent(RepairBench repairBench, BaseEntity.RPCMessage msg) 11 | { 12 | _repairBench = repairBench; 13 | _player = Server.GetPlayer(msg.player); 14 | _item = new InvItem(repairBench.inventory.GetSlot(0)); 15 | _msg = msg; 16 | } 17 | 18 | public RepairBench RepairBench { 19 | get { return _repairBench; } 20 | } 21 | 22 | public Player Player { 23 | get { return _player; } 24 | } 25 | 26 | public InvItem Item { 27 | get { return _item; } 28 | } 29 | 30 | public BaseEntity.RPCMessage RPCMessage { 31 | get { return _msg; } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Pluton/Events/ItemUsedEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class ItemUsedEvent : CountedInstance 4 | { 5 | private InvItem _item; 6 | private int _amount; 7 | 8 | public ItemUsedEvent(Item item, int amountToConsume) 9 | { 10 | _item = new InvItem(item); 11 | _amount = amountToConsume; 12 | } 13 | 14 | public InvItem Item { 15 | get { return _item; } 16 | } 17 | 18 | public int Amount { 19 | get { return _amount; } 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Pluton/Events/LandmineTriggerEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class LandmineTriggerEvent 4 | { 5 | private Landmine _landmine; 6 | private Player _player; 7 | private bool _explode = true; 8 | 9 | public LandmineTriggerEvent(Landmine landmine, BasePlayer player) 10 | { 11 | _landmine = landmine; 12 | _player = Server.GetPlayer(player); 13 | } 14 | 15 | public Landmine Landmine { 16 | get { return _landmine; } 17 | } 18 | 19 | public Player Player { 20 | get { return _player; } 21 | } 22 | 23 | public bool Explode { 24 | get { return _explode; } 25 | } 26 | 27 | public void CancelExplosion() 28 | { 29 | _explode = false; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Pluton/Events/LootEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class LootEvent : CountedInstance 4 | { 5 | public bool Cancel = false; 6 | public string cancelReason = "A plugin stops you from looting that!"; 7 | public readonly Player Looter; 8 | public readonly PlayerLoot pLoot; 9 | 10 | public LootEvent(PlayerLoot pl, Player looter) 11 | { 12 | Looter = looter; 13 | pLoot = pl; 14 | } 15 | 16 | public void Stop(string reason = "A plugin stops you from looting that!") 17 | { 18 | cancelReason = reason; 19 | Cancel = true; 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Pluton/Events/MetabolismDamageEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton.Events 4 | { 5 | public class MetabolismDamageEvent : CountedInstance 6 | { 7 | public readonly Player Victim; 8 | 9 | public float HungerDamage = 0.0f; 10 | public float ThirstDamage = 0.0f; 11 | public float ColdDamage = 0.0f; 12 | public float HeatDamage = 0.0f; 13 | public float DrownedDamage = 0.0f; 14 | public float BleedingDamage = 0.0f; 15 | public float PoisonDamage = 0.0f; 16 | public float RadiationDamage = 0.0f; 17 | 18 | public MetabolismDamageEvent(BasePlayer player) 19 | { 20 | Victim = Server.GetPlayer(player); 21 | } 22 | 23 | public PlayerMetabolism metabolism 24 | { 25 | get 26 | { 27 | return Victim.basePlayer.metabolism; 28 | } 29 | } 30 | 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Pluton/Events/MetabolismTickEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton.Events 4 | { 5 | public class MetabolismTickEvent : CountedInstance 6 | { 7 | public readonly Player Victim; 8 | 9 | public float CurrentTemperature = 0.0f; 10 | public float FutureTemperature = 0.0f; 11 | 12 | public float debug = 0.0f; 13 | public float debug2 = 0.0f; 14 | 15 | public float CaloriesHealthChange = 0.0f; 16 | public float HydrationHealthChange = 0.0f; 17 | public float CaloriesChange = 0.0f; 18 | public float HydrationChange = 0.0f; 19 | public float HeartrateValue = 0.0f; 20 | public float OxygenValue = 0.0f; 21 | public float WetnessValue = 0.0f; 22 | public float BleedingValue = 0.0f; 23 | public float PoisonValue = 0.0f; 24 | public float RadiationValue = 0.0f; 25 | public bool PreventDamage = false; 26 | 27 | 28 | public MetabolismTickEvent(BasePlayer player) 29 | { 30 | Victim = Server.GetPlayer(player); 31 | } 32 | 33 | public PlayerMetabolism metabolism 34 | { 35 | get 36 | { 37 | return Victim.basePlayer.metabolism; 38 | } 39 | } 40 | 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Pluton/Events/NPCDeathEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class NPCDeathEvent : DeathEvent 4 | { 5 | public readonly NPC Victim; 6 | 7 | public NPCDeathEvent(NPC npc, HitInfo info) 8 | : base(info) 9 | { 10 | Victim = npc; 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Pluton/Events/NPCHurtEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class NPCHurtEvent : HurtEvent 4 | { 5 | public readonly NPC Victim; 6 | 7 | public NPCHurtEvent(NPC npc, HitInfo info) 8 | : base(info) 9 | { 10 | Victim = npc; 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Pluton/Events/PlayerClothingEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class PlayerClothingEvent : CountedInstance 4 | { 5 | private InvItem _item; 6 | private Player _player; 7 | 8 | public PlayerClothingEvent(PlayerInventory playerInventory, Item item) 9 | { 10 | _item = new InvItem(item); 11 | _player = Server.GetPlayer(playerInventory.GetComponent()); 12 | } 13 | 14 | public Player Player { 15 | get { return _player; } 16 | } 17 | 18 | public InvItem Item { 19 | get { return _item; } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Pluton/Events/PlayerDeathEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class PlayerDeathEvent : DeathEvent 4 | { 5 | public readonly Player Victim; 6 | 7 | public PlayerDeathEvent(Player player, HitInfo info) 8 | : base(info) 9 | { 10 | Victim = player; 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Pluton/Events/PlayerHealthChangeEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class PlayerHealthChangeEvent : CountedInstance 4 | { 5 | private float _oldh, _newh; 6 | private Player _pl; 7 | 8 | public PlayerHealthChangeEvent(BasePlayer p, float oldh, float newh) 9 | { 10 | _oldh = oldh; 11 | _newh = newh; 12 | _pl = new Player(p); 13 | } 14 | 15 | public Player Player 16 | { 17 | get { return _pl; } 18 | } 19 | 20 | public float OldHealth 21 | { 22 | get { return _oldh; } 23 | } 24 | 25 | public float NewHealth 26 | { 27 | get { return _newh; } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Pluton/Events/PlayerHurtEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class PlayerHurtEvent : HurtEvent 4 | { 5 | public readonly Player Victim; 6 | 7 | public PlayerHurtEvent(Player player, HitInfo info) 8 | : base(info) 9 | { 10 | Victim = player; 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Pluton/Events/PlayerKickEvent.cs: -------------------------------------------------------------------------------- 1 | using Network; 2 | 3 | namespace Pluton 4 | { 5 | public class PlayerKickEvent : CountedInstance 6 | { 7 | public bool Kick = false; 8 | public string Reason; 9 | 10 | public Connection Connection; 11 | 12 | public PlayerKickEvent(Connection connection, string reason) 13 | { 14 | Connection = connection; 15 | Reason = reason; 16 | } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Pluton/Events/PlayerLootEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class PlayerLootEvent : LootEvent 4 | { 5 | public readonly Player Target; 6 | 7 | public PlayerLootEvent(PlayerLoot pl, Player looter, Player looted) 8 | : base(pl, looter) 9 | { 10 | Target = looted; 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Pluton/Events/PlayerTakeRadsEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class PlayerTakeRadsEvent : CountedInstance 4 | { 5 | 6 | public readonly Player Victim; 7 | public readonly float RadAmount; 8 | public readonly float Current; 9 | public float Next; 10 | 11 | public PlayerTakeRadsEvent(Player p, float current, float amount) 12 | { 13 | RadAmount = amount; 14 | Current = current; 15 | float next = UnityEngine.Mathf.Clamp(amount, p.basePlayer.metabolism.radiation_level.min, p.basePlayer.metabolism.radiation_level.max); 16 | Next = next <= current ? current : next; 17 | Victim = p; 18 | } 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Pluton/Events/PlayerTakedmgEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class PlayerTakedmgEvent : CountedInstance 4 | { 5 | public readonly Player Victim; 6 | public float Amount; 7 | public Rust.DamageType Type; 8 | 9 | public PlayerTakedmgEvent(Player p, float amount, Rust.DamageType type) 10 | { 11 | Type = type; 12 | Amount = amount; 13 | Victim = p; 14 | } 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Pluton/Events/RespawnEvent.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Pluton.Events 4 | { 5 | public class RespawnEvent : CountedInstance 6 | { 7 | public bool GiveDefault; 8 | public bool ChangePos; 9 | public bool WakeUp; 10 | public float StartHealth = -1; 11 | public Vector3 SpawnPos; 12 | public Quaternion SpawnRot; 13 | public Player Player; 14 | 15 | public RespawnEvent(Player p, Vector3 pos, Quaternion quat) 16 | { 17 | SpawnPos = pos; 18 | SpawnRot = quat; 19 | WakeUp = false; 20 | ChangePos = false; 21 | GiveDefault = true; 22 | Player = p; 23 | } 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Pluton/Events/RocketShootEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class RocketShootEvent : CountedInstance 4 | { 5 | private BaseEntity.RPCMessage _msg; 6 | private BaseLauncher _launch; 7 | private Entity _entity; 8 | private Player _player; 9 | 10 | public RocketShootEvent(BaseLauncher baseLauncher, BaseEntity.RPCMessage msg, BaseEntity baseEntity) 11 | { 12 | _entity = new Entity(baseEntity); 13 | _player = Server.GetPlayer(msg.player); 14 | _msg = msg; 15 | _launch = baseLauncher; 16 | } 17 | 18 | public BaseLauncher BaseLauncher { 19 | get { return _launch; } 20 | } 21 | 22 | public Player Player { 23 | get { return _player; } 24 | } 25 | 26 | public Entity Entity { 27 | get { return _entity; } 28 | } 29 | 30 | public BaseEntity.RPCMessage RPCMessage { 31 | get { return _msg; } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Pluton/Events/ServerConsoleEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace Pluton.Events 6 | { 7 | public class ServerConsoleEvent : CountedInstance 8 | { 9 | public readonly ConsoleSystem.Arg _args; 10 | 11 | public readonly string cmd; 12 | public readonly List Args; 13 | 14 | public string Reply; 15 | 16 | public ServerConsoleEvent(ConsoleSystem.Arg args, string rconCmd) 17 | { 18 | if (String.IsNullOrEmpty(rconCmd)) 19 | return; 20 | 21 | _args = args; 22 | Args = args.Args != null ? args.Args.ToList() : new List(); 23 | cmd = rconCmd.Split(' ')[0]; 24 | Reply = "Command not found!"; 25 | } 26 | 27 | public void ReplyWith(string reply) 28 | { 29 | Reply = reply; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Pluton/Events/ShootEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class ShootEvent : CountedInstance 4 | { 5 | private BaseEntity.RPCMessage _rpcMessage; 6 | private BaseProjectile _projectile; 7 | private Player _player; 8 | 9 | public ShootEvent(BaseProjectile baseProjectile, BaseEntity.RPCMessage msg) 10 | { 11 | _player = Server.GetPlayer(msg.player); 12 | _rpcMessage = msg; 13 | _projectile = baseProjectile; 14 | } 15 | 16 | public BaseProjectile BaseProjectile { 17 | get { return _projectile; } 18 | } 19 | 20 | public Player Player { 21 | get { return _player; } 22 | } 23 | 24 | public BaseEntity.RPCMessage RPCMessage { 25 | get { return _rpcMessage; } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Pluton/Events/SyringeUseEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class SyringeUseEvent : CountedInstance 4 | { 5 | private Player _user; 6 | private Player _receiver; 7 | private SyringeWeapon _syringeWeapon; 8 | private bool _self; 9 | 10 | public SyringeUseEvent(SyringeWeapon sw, BaseEntity.RPCMessage msg, bool isSelf) 11 | { 12 | _syringeWeapon = sw; 13 | _user = Server.GetPlayer(sw.ownerPlayer); 14 | _self = isSelf; 15 | 16 | if (isSelf) 17 | _receiver = _user; 18 | else 19 | _receiver = new Player(BaseNetworkable.serverEntities.Find(msg.read.UInt32()) as BasePlayer); 20 | } 21 | 22 | public Player User { 23 | get { return _user; } 24 | } 25 | 26 | public Player Receiver { 27 | get { return _receiver; } 28 | } 29 | 30 | public SyringeWeapon Syringe { 31 | get { return _syringeWeapon; } 32 | } 33 | 34 | public bool IsSelfUsage() 35 | { 36 | return _self; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Pluton/Events/WeaponThrowEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton.Events 2 | { 3 | public class WeaponThrowEvent : CountedInstance 4 | { 5 | private ThrownWeapon _thrownWeapon; 6 | private BaseEntity.RPCMessage _msg; 7 | private Player _player; 8 | 9 | public WeaponThrowEvent(ThrownWeapon thrownWeapon, BaseEntity.RPCMessage msg) 10 | { 11 | _msg = msg; 12 | _thrownWeapon = thrownWeapon; 13 | _player = Server.GetPlayer(msg.player); 14 | } 15 | 16 | public BaseEntity.RPCMessage RPCMessage { 17 | get { return _msg; } 18 | } 19 | 20 | public ThrownWeapon Weapon { 21 | get { return _thrownWeapon; } 22 | } 23 | 24 | public Player Player { 25 | get { return _player; } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Pluton/ISingleton.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton 3 | { 4 | public interface ISingleton 5 | { 6 | bool CheckDependencies(); 7 | 8 | void Initialize(); 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Pluton/Objects/BuildingPart.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Runtime.Serialization; 4 | using UnityEngine; 5 | 6 | namespace Pluton 7 | { 8 | [Serializable] 9 | public class BuildingPart : Entity 10 | { 11 | [NonSerialized] 12 | private BuildingBlock _buildingBlock; 13 | 14 | SerializedVector3 position; 15 | 16 | [OnSerializing] 17 | void OnSerializing(StreamingContext context) 18 | { 19 | position = buildingBlock.transform.position.Serialize(); 20 | } 21 | 22 | public BuildingPart(BuildingBlock bb) : base(bb) 23 | { 24 | _buildingBlock = bb; 25 | } 26 | 27 | public Socket_Base FindSocket(string name) 28 | { 29 | return (from socket in _buildingBlock.blockDefinition.allSockets 30 | where socket.socketName == name 31 | select socket).First(); 32 | } 33 | 34 | public void Destroy() 35 | { 36 | buildingBlock.Kill(BaseNetworkable.DestroyMode.Gib); 37 | } 38 | 39 | public override bool IsBuildingPart() 40 | { 41 | return true; 42 | } 43 | 44 | public void Rotate() 45 | { 46 | var blockDefinition = buildingBlock.blockDefinition; 47 | if (!blockDefinition.canRotate) { 48 | return; 49 | } 50 | buildingBlock.transform.localRotation *= Quaternion.Euler(blockDefinition.rotationAmount); 51 | buildingBlock.ClientRPC(null, "UpdateConditionalModels", new object[0]); 52 | buildingBlock.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); 53 | } 54 | 55 | public BuildingBlock buildingBlock { 56 | get { 57 | if (_buildingBlock == null) { 58 | Vector3 v3pos = position.ToVector3(); 59 | _buildingBlock = (from bb in UnityEngine.Object.FindObjectsOfType() 60 | where this.Prefab == bb.LookupPrefabName() && 61 | v3pos == bb.transform.position 62 | select bb).FirstOrDefault(); 63 | } 64 | return _buildingBlock; 65 | } 66 | private set { 67 | _buildingBlock = value; 68 | } 69 | } 70 | 71 | public BuildingGrade.Enum Grade { 72 | get { 73 | return buildingBlock.grade; 74 | } 75 | set { 76 | buildingBlock.SetGrade(value); 77 | buildingBlock.SetHealthToMax(); 78 | buildingBlock.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); 79 | } 80 | } 81 | 82 | public float Health { 83 | get { 84 | return buildingBlock.health; 85 | } 86 | set { 87 | buildingBlock.health = value; 88 | } 89 | } 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /Pluton/Objects/ChatCommands.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace Pluton 6 | { 7 | public class ChatCommand 8 | { 9 | public delegate void CallbackDelegate(string[] args, Player player); 10 | 11 | public string _command; 12 | public string _description; 13 | public string _usage; 14 | public BasePlugin plugin; 15 | public CallbackDelegate callback; 16 | 17 | public ChatCommand setCallback(CallbackDelegate function) 18 | { 19 | callback = function; 20 | return this; 21 | } 22 | 23 | public ChatCommand setCallback(string function) 24 | { 25 | callback = new CallbackDelegate((cmd, player) => { 26 | plugin.Invoke(function, new[] { (object)cmd, player }); 27 | }); 28 | return this; 29 | } 30 | 31 | public ChatCommand setUsage(string usage) 32 | { 33 | _usage = usage; 34 | return this; 35 | } 36 | 37 | public ChatCommand setDescription(string description) 38 | { 39 | _description = description; 40 | return this; 41 | } 42 | 43 | public ChatCommand setCommand(string command) 44 | { 45 | _command = command; 46 | return this; 47 | } 48 | 49 | public ChatCommand(string command) 50 | { 51 | _command = command; 52 | } 53 | 54 | public ChatCommand() 55 | { 56 | _command = ""; 57 | } 58 | } 59 | 60 | public class ChatCommands 61 | { 62 | public BasePlugin plugin; 63 | 64 | public Dictionary Commands = new Dictionary(); 65 | 66 | public ChatCommands(BasePlugin pl) 67 | { 68 | plugin = pl; 69 | } 70 | 71 | public ChatCommand Register(string command) 72 | { 73 | if (String.IsNullOrEmpty(command)) 74 | return (ChatCommand)null; 75 | 76 | ChatCommand c = new ChatCommand(command); 77 | c.plugin = plugin; 78 | 79 | return Register(c); 80 | } 81 | 82 | public List RegisterWithMultipleNames(string[] commands, string callback, string usage, string description) 83 | { 84 | List chatCommands = new List(); 85 | foreach (string command in commands) { 86 | ChatCommand chatCommand = Register(command).setCallback(callback).setUsage(usage).setDescription(description); 87 | chatCommands.Add(chatCommand); 88 | } 89 | return chatCommands; 90 | } 91 | 92 | public ChatCommand Register(ChatCommand command) 93 | { 94 | Commands.Add(Commands.Count, command); 95 | return command; 96 | } 97 | 98 | public List getCommands() 99 | { 100 | return (from c in Commands.Values 101 | select c._command).ToList(); 102 | } 103 | 104 | public ChatCommand[] getChatCommands(string command) 105 | { 106 | return (from c in Commands.Values 107 | where c._command == command 108 | select c).ToArray(); 109 | } 110 | 111 | public string[] getDescriptions(string command) 112 | { 113 | return (from c in Commands.Values 114 | where c._command == command 115 | select c._description).ToArray(); 116 | } 117 | 118 | public string[] getUsages(string command) 119 | { 120 | return (from c in Commands.Values 121 | where c._command == command 122 | select c._usage).ToArray(); 123 | } 124 | } 125 | } 126 | 127 | -------------------------------------------------------------------------------- /Pluton/Objects/ConsoleCommands.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace Pluton 6 | { 7 | public class ConsoleCommand 8 | { 9 | public delegate void CallbackDelegate(string[] args); 10 | 11 | public string _command; 12 | public string _description; 13 | public string _usage; 14 | public BasePlugin plugin; 15 | public CallbackDelegate callback; 16 | 17 | public ConsoleCommand setCallback(CallbackDelegate function) 18 | { 19 | callback = function; 20 | return this; 21 | } 22 | 23 | public ConsoleCommand setCallback(string function) 24 | { 25 | callback = new CallbackDelegate(cmd => { 26 | try { 27 | plugin.Invoke(function, (object)cmd); 28 | } catch (Exception ex) { 29 | Logger.Log("there"); 30 | Logger.Log(ex.ToString()); 31 | } 32 | }); 33 | return this; 34 | } 35 | 36 | public ConsoleCommand setUsage(string usage) 37 | { 38 | _usage = usage; 39 | return this; 40 | } 41 | 42 | public ConsoleCommand setDescription(string description) 43 | { 44 | _description = description; 45 | return this; 46 | } 47 | 48 | public ConsoleCommand setCommand(string command) 49 | { 50 | _command = command; 51 | return this; 52 | } 53 | 54 | public ConsoleCommand(string command) 55 | { 56 | _command = command; 57 | } 58 | 59 | public ConsoleCommand() 60 | { 61 | _command = ""; 62 | } 63 | } 64 | 65 | public class ConsoleCommands 66 | { 67 | public BasePlugin plugin; 68 | 69 | public Dictionary Commands = new Dictionary(); 70 | 71 | public ConsoleCommands(BasePlugin pl) 72 | { 73 | plugin = pl; 74 | } 75 | 76 | public ConsoleCommand Register(string command) 77 | { 78 | if (String.IsNullOrEmpty(command)) 79 | return (ConsoleCommand)null; 80 | 81 | ConsoleCommand c = new ConsoleCommand(command); 82 | c.plugin = plugin; 83 | 84 | return Register(c); 85 | } 86 | 87 | public ConsoleCommand Register(ConsoleCommand command) 88 | { 89 | Commands.Add(Commands.Count, command); 90 | return command; 91 | } 92 | 93 | public List getCommands() 94 | { 95 | return (from c in Commands.Values 96 | select c._command).ToList(); 97 | } 98 | 99 | public ConsoleCommand[] getConsoleCommands(string command) 100 | { 101 | return (from c in Commands.Values 102 | where c._command == command 103 | select c).ToArray(); 104 | } 105 | 106 | public string[] getDescriptions(string command) 107 | { 108 | return (from c in Commands.Values 109 | where c._command == command 110 | select c._description).ToArray(); 111 | } 112 | 113 | public string[] getUsages(string command) 114 | { 115 | return (from c in Commands.Values 116 | where c._command == command 117 | select c._usage).ToArray(); 118 | } 119 | } 120 | } 121 | 122 | -------------------------------------------------------------------------------- /Pluton/Objects/Entity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace Pluton 5 | { 6 | [Serializable] 7 | public class Entity : CountedInstance 8 | { 9 | [NonSerialized] 10 | public readonly BaseEntity baseEntity; 11 | public readonly string Prefab; 12 | public readonly uint PrefabID; 13 | 14 | public Entity(BaseEntity ent) 15 | { 16 | baseEntity = ent; 17 | Prefab = baseEntity.LookupPrefabName(); 18 | PrefabID = baseEntity.prefabID; 19 | } 20 | 21 | public virtual void Kill() 22 | { 23 | baseEntity.Kill(BaseNetworkable.DestroyMode.Gib); 24 | } 25 | 26 | public virtual bool IsBuildingPart() 27 | { 28 | return false; 29 | } 30 | 31 | public virtual bool IsNPC() 32 | { 33 | return false; 34 | } 35 | 36 | public virtual bool IsPlayer() 37 | { 38 | return false; 39 | } 40 | 41 | public BuildingPart ToBuildingPart() 42 | { 43 | BuildingBlock b = baseEntity.GetComponent(); 44 | if (b == null) 45 | return null; 46 | return new BuildingPart(b); 47 | } 48 | 49 | public NPC ToNPC() 50 | { 51 | BaseNPC a = baseEntity.GetComponent(); 52 | if (a == null) 53 | return null; 54 | return new NPC(a); 55 | } 56 | 57 | public Player ToPlayer() 58 | { 59 | BasePlayer p = baseEntity.ToPlayer(); 60 | if (p == null) 61 | return null; 62 | return Server.GetPlayer(p); 63 | } 64 | 65 | public virtual Vector3 Location { 66 | get { 67 | return baseEntity.transform.position; 68 | } 69 | set { 70 | bool oldsync = baseEntity.syncPosition; 71 | baseEntity.transform.position = value; 72 | baseEntity.syncPosition = true; 73 | baseEntity.TransformChanged(); 74 | baseEntity.syncPosition = oldsync; 75 | } 76 | } 77 | 78 | public virtual string Name { 79 | get { 80 | return baseEntity.name == "player/player" ? (baseEntity as BasePlayer).displayName : baseEntity.name; 81 | } 82 | } 83 | 84 | public float X { 85 | get { 86 | return baseEntity.transform.position.x; 87 | } 88 | } 89 | 90 | public float Y { 91 | get { 92 | return baseEntity.transform.position.y; 93 | } 94 | } 95 | 96 | public float Z { 97 | get { 98 | return baseEntity.transform.position.z; 99 | } 100 | } 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /Pluton/Objects/Inv.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace Pluton 6 | { 7 | public class Inv : CountedInstance 8 | { 9 | 10 | public readonly PlayerInventory _inv; 11 | public readonly Player owner; 12 | 13 | public Inv(PlayerInventory inv) 14 | { 15 | _inv = inv; 16 | owner = Server.GetPlayer(inv.GetComponent()); 17 | } 18 | 19 | public bool Add(InvItem item) 20 | { 21 | ItemContainer con; 22 | if (item.containerPref == InvItem.ContainerPreference.Belt) 23 | con = InnerBelt; 24 | else if (item.containerPref == InvItem.ContainerPreference.Wear) 25 | con = InnerWear; 26 | else 27 | con = InnerMain; 28 | 29 | bool flag = _inv.GiveItem(item._item, con); 30 | if (!flag) { 31 | flag = _inv.GiveItem(item._item); 32 | } 33 | 34 | return flag; 35 | } 36 | 37 | public bool Add(InvItem item, ItemContainer con) 38 | { 39 | return _inv.GiveItem(item._item, con); 40 | } 41 | 42 | public bool Add(int itemID) 43 | { 44 | return Add(itemID, 1); 45 | } 46 | 47 | public bool Add(int itemID, int amount) 48 | { 49 | return Add(new InvItem(itemID, amount)); 50 | } 51 | 52 | public bool Add(string longNameOrShortNameOrPrefab, int amount) 53 | { 54 | return Add(new InvItem(longNameOrShortNameOrPrefab, amount)); 55 | } 56 | 57 | public void Notice(LoadOutItem loItem) 58 | { 59 | string msg = String.Format("{0} {1}", InvItem.GetItemID(loItem.Name), loItem.Amount); 60 | Notice(msg); 61 | } 62 | 63 | public void Notice(InvItem item) 64 | { 65 | string msg = String.Format("{0} {1}", item.ItemID, item.Quantity); 66 | Notice(msg); 67 | } 68 | 69 | public void Notice(string msg) 70 | { 71 | owner.basePlayer.Command("note.inv " + msg); 72 | } 73 | 74 | public ItemContainer InnerBelt { 75 | get { 76 | return _inv.containerBelt; 77 | } 78 | } 79 | 80 | public ItemContainer InnerMain { 81 | get { 82 | return _inv.containerMain; 83 | } 84 | } 85 | 86 | public ItemContainer InnerWear { 87 | get { 88 | return _inv.containerWear; 89 | } 90 | } 91 | 92 | public List AllItems() 93 | { 94 | return (from item in _inv.AllItems() 95 | select new InvItem(item)).ToList(); 96 | } 97 | 98 | public List BeltItems() 99 | { 100 | return (from item in _inv.containerBelt.itemList 101 | select new InvItem(item)).ToList(); 102 | } 103 | 104 | public List MainItems() 105 | { 106 | return (from item in _inv.containerMain.itemList 107 | select new InvItem(item)).ToList(); 108 | } 109 | 110 | public List WearItems() 111 | { 112 | return (from item in _inv.containerWear.itemList 113 | select new InvItem(item)).ToList(); 114 | } 115 | } 116 | } 117 | 118 | -------------------------------------------------------------------------------- /Pluton/Objects/LoadOutItem.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton 3 | { 4 | public class LoadOutItem : CountedInstance 5 | { 6 | public readonly int Amount; 7 | public readonly string Name; 8 | 9 | public LoadOutItem(string name) 10 | { 11 | Amount = 1; 12 | Name = name; 13 | } 14 | 15 | public LoadOutItem(string name, int amount) 16 | { 17 | Amount = amount; 18 | Name = name; 19 | } 20 | 21 | public InvItem invItem { 22 | get { 23 | return new InvItem(Name, Amount); 24 | } 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Pluton/Objects/NPC.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton 3 | { 4 | public class NPC : Entity 5 | { 6 | public readonly BaseNPC baseNPC; 7 | 8 | public NPC(BaseNPC npc) : base(npc) 9 | { 10 | baseNPC = npc; 11 | } 12 | 13 | public override void Kill() 14 | { 15 | var info = new HitInfo(); 16 | info.damageTypes.Add(Rust.DamageType.Suicide, 100f); 17 | info.Initiator = baseNPC as BaseEntity; 18 | baseNPC.Die(info); 19 | } 20 | 21 | public override bool IsNPC() 22 | { 23 | return true; 24 | } 25 | 26 | public uint ID { 27 | get { 28 | return baseNPC.net.ID; 29 | } 30 | } 31 | 32 | public float Health { 33 | get { 34 | return baseNPC.health; 35 | } 36 | set { 37 | baseNPC.health = value; 38 | } 39 | 40 | } 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Pluton/Objects/OfflinePlayer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton 4 | { 5 | [Serializable] 6 | public class OfflinePlayer : CountedInstance 7 | { 8 | public string Name; 9 | public string SteamID; 10 | public string IP; 11 | public string OS; 12 | public float X; 13 | public float Y; 14 | public float Z; 15 | public ulong totalTimeOnline; 16 | public bool Admin; 17 | 18 | // you shouldn't ever call this constructor manually 19 | public OfflinePlayer(Player player) 20 | { 21 | Name = player.Name; 22 | SteamID = player.SteamID; 23 | IP = player.IP; 24 | OS = player.OS; 25 | X = player.X; 26 | Y = player.Y; 27 | Z = player.Z; 28 | totalTimeOnline = (ulong)player.TimeOnline; 29 | Admin = player.Admin; 30 | } 31 | 32 | public static OfflinePlayer Get(ulong steamID) 33 | { 34 | OfflinePlayer op = Server.GetInstance().OfflinePlayers[steamID]; 35 | if (op == null) { 36 | Logger.LogDebug("[OfflinePlayer] Couldn't find OfflinePlayer: " + steamID.ToString()); 37 | return null; 38 | } 39 | return op; 40 | } 41 | 42 | public static OfflinePlayer Get(string steamID) 43 | { 44 | return Get(UInt64.Parse(steamID)); 45 | } 46 | 47 | public void Update(Player player) 48 | { 49 | if (Name != player.Name) { 50 | Logger.LogDebug("[OfflinePlayer] " + Name + " changed name to: " + player.Name); 51 | Name = player.Name; 52 | } 53 | IP = player.IP; 54 | OS = player.OS; 55 | X = player.X; 56 | Y = player.Y; 57 | Z = player.Z; 58 | Admin = player.Admin; 59 | totalTimeOnline += (ulong)player.TimeOnline; 60 | } 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Pluton/Objects/PluginCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace Pluton 6 | { 7 | public class PluginCommand 8 | { 9 | public string _command; 10 | public string _description; 11 | public string _usage; 12 | 13 | public PluginCommand(string command, string description, string usage) 14 | { 15 | _command = command; 16 | _usage = usage; 17 | _description = description; 18 | } 19 | 20 | public PluginCommand() 21 | { 22 | _command = ""; 23 | _usage = "_not specified_"; 24 | _description = "_not specified_"; 25 | } 26 | } 27 | 28 | public class PluginCommands 29 | { 30 | private static PluginCommands instance; 31 | 32 | public static Dictionary Commands = new Dictionary(); 33 | 34 | public static PluginCommands GetInstance() 35 | { 36 | if (instance == null) 37 | new PluginCommands(); 38 | return instance; 39 | } 40 | 41 | public void Init() 42 | { 43 | Commands.Clear(); 44 | if (Config.GetBoolValue("Commands", "enabled", true)) { 45 | RegisterCommand(GetPlutonCommand("ShowMyStats", "mystats"), GetPlutonCommand("ShowMyStats", "mystats"), "Shows your stat."); 46 | RegisterCommand(GetPlutonCommand("ShowStatsOther", "statsof"), GetPlutonCommand("ShowStatsOther", "statsof") + " \"\"", "Shows another player's stat."); 47 | RegisterCommand(GetPlutonCommand("ShowLocation", "whereami"), GetPlutonCommand("ShowLocation", "whereami"), "Shows where you are."); 48 | RegisterCommand(GetPlutonCommand("ShowOnlinePlayers", "players"), GetPlutonCommand("ShowOnlinePlayers", "players"), "Shows how many ppl are online."); 49 | RegisterCommand(GetPlutonCommand("Help", "help"), GetPlutonCommand("Help", "help"), "Shows the basic help message(s)."); 50 | RegisterCommand(GetPlutonCommand("Commands", "commands"), GetPlutonCommand("Commands", "commands"), "Shows the list of commands."); 51 | } 52 | PluginLoader.LoadCommands(); 53 | } 54 | 55 | public string GetPlutonCommand(string c, string defaultValue) 56 | { 57 | if (String.IsNullOrEmpty(c)) 58 | return ""; 59 | 60 | string c2 = Config.GetValue("Commands", c, defaultValue); 61 | 62 | if (c2 == null) 63 | return ""; 64 | 65 | return c2; 66 | } 67 | 68 | public void RegisterCommand(string command, string usage, string description) 69 | { 70 | if (String.IsNullOrEmpty(command)) 71 | return; 72 | PluginCommand c = new PluginCommand(); 73 | c._description = description; 74 | c._command = command; 75 | c._usage = usage; 76 | RegisterCommand(c); 77 | } 78 | 79 | public void RegisterCommand(PluginCommand command) 80 | { 81 | Commands.Add(Commands.Count, command); 82 | } 83 | 84 | public PluginCommands() 85 | { 86 | if (instance == null) 87 | instance = this; 88 | } 89 | 90 | public List getCommands() 91 | { 92 | return (from c in Commands.Values 93 | select c._command).ToList(); 94 | } 95 | 96 | public string[] getDescriptions(string command) 97 | { 98 | return (from c in Commands.Values 99 | where c._command == command 100 | select c._description).ToArray(); 101 | } 102 | 103 | public string[] getUsages(string command) 104 | { 105 | return (from c in Commands.Values 106 | where c._command == command 107 | select c._usage).ToArray(); 108 | } 109 | } 110 | } 111 | 112 | -------------------------------------------------------------------------------- /Pluton/Objects/PlutonUIComponents/BaseComponent.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton.PlutonUI 3 | { 4 | public class BaseComponent : CountedInstance, IComponent 5 | { 6 | public JSON.Value this[string key] { 7 | get { 8 | return _obj[key]; 9 | } 10 | set { 11 | _obj[key] = value; 12 | } 13 | } 14 | 15 | public float fadeIn { 16 | get { 17 | return _obj.GetFloat("fadeIn"); 18 | } 19 | set { 20 | if (_obj.ContainsKey("fadeIn")) 21 | _obj["fadeIn"] = new JSON.Value(value); 22 | else 23 | _obj.Add("fadeIn", new JSON.Value(value)); 24 | } 25 | } 26 | 27 | protected JSON.Object _obj = new JSON.Object(); 28 | 29 | public JSON.Object obj { 30 | get { 31 | return _obj; 32 | } 33 | set { 34 | _obj = value; 35 | } 36 | } 37 | 38 | public virtual string type { get { return ""; } } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Pluton/Objects/PlutonUIComponents/Button.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton.PlutonUI 3 | { 4 | public class Button : BaseComponent 5 | { 6 | public string close { 7 | get { 8 | return _obj.GetString("close"); 9 | } 10 | set { 11 | if (_obj.ContainsKey("close")) 12 | _obj["close"] = new JSON.Value(value); 13 | else 14 | _obj.Add("close", new JSON.Value(value)); 15 | } 16 | } 17 | 18 | public string command { 19 | get { 20 | return _obj.GetString("command"); 21 | } 22 | set { 23 | if (_obj.ContainsKey("command")) 24 | _obj["command"] = new JSON.Value(value); 25 | else 26 | _obj.Add("command", new JSON.Value(value)); 27 | } 28 | } 29 | 30 | public string color { 31 | get { 32 | return _obj.GetString("color", "1.0 1.0 1.0 1.0"); 33 | } 34 | set { 35 | if (_obj.ContainsKey("color")) 36 | _obj["color"] = new JSON.Value(value); 37 | else 38 | _obj.Add("color", new JSON.Value(value)); 39 | } 40 | } 41 | 42 | public string imagetype { 43 | get { 44 | return _obj.GetString("imagetype", "Simple"); 45 | } 46 | set { 47 | if (_obj.ContainsKey("imagetype")) 48 | _obj["imagetype"] = new JSON.Value(value); 49 | else 50 | _obj.Add("imagetype", new JSON.Value(value)); 51 | } 52 | } 53 | 54 | public string material { 55 | get { 56 | return _obj.GetString("material", "Assets/Icons/IconMaterial.mat"); 57 | } 58 | set { 59 | if (_obj.ContainsKey("material")) 60 | _obj["material"] = new JSON.Value(value); 61 | else 62 | _obj.Add("material", new JSON.Value(value)); 63 | } 64 | } 65 | 66 | public string sprite { 67 | get { 68 | return _obj.GetString("sprite", "Assets/Content/UI/UI.Background.Tile.psd"); 69 | } 70 | set { 71 | if (_obj.ContainsKey("sprite")) 72 | _obj["sprite"] = new JSON.Value(value); 73 | else 74 | _obj.Add("sprite", new JSON.Value(value)); 75 | } 76 | } 77 | 78 | public override string type { 79 | get { 80 | return "UnityEngine.UI.Button"; 81 | } 82 | } 83 | 84 | public Button() 85 | { 86 | this["type"] = new JSON.Value(type); 87 | } 88 | } 89 | } 90 | 91 | -------------------------------------------------------------------------------- /Pluton/Objects/PlutonUIComponents/IComponent.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton.PlutonUI 3 | { 4 | public interface IComponent 5 | { 6 | float fadeIn { get; } 7 | 8 | JSON.Object obj { get; } 9 | 10 | string type { get; } 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Pluton/Objects/PlutonUIComponents/Image.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton.PlutonUI 3 | { 4 | public class Image : BaseComponent 5 | { 6 | public string color { 7 | get { 8 | return _obj.GetString("color", "1.0 1.0 1.0 1.0"); 9 | } 10 | set { 11 | if (_obj.ContainsKey("color")) 12 | _obj["color"] = new JSON.Value(value); 13 | else 14 | _obj.Add("color", new JSON.Value(value)); 15 | } 16 | } 17 | 18 | public string imagetype { 19 | get { 20 | return _obj.GetString("imagetype", "Simple"); 21 | } 22 | set { 23 | if (_obj.ContainsKey("imagetype")) 24 | _obj["imagetype"] = new JSON.Value(value); 25 | else 26 | _obj.Add("imagetype", new JSON.Value(value)); 27 | } 28 | } 29 | 30 | public string material { 31 | get { 32 | return _obj.GetString("material", "Assets/Icons/IconMaterial.mat"); 33 | } 34 | set { 35 | if (_obj.ContainsKey("material")) 36 | _obj["material"] = new JSON.Value(value); 37 | else 38 | _obj.Add("material", new JSON.Value(value)); 39 | } 40 | } 41 | 42 | public string png { 43 | get { 44 | return _obj.GetString("png", "0"); 45 | } 46 | set { 47 | if (_obj.ContainsKey("png")) 48 | _obj["png"] = new JSON.Value(value); 49 | else 50 | _obj.Add("png", new JSON.Value(value)); 51 | } 52 | } 53 | 54 | public string sprite { 55 | get { 56 | return _obj.GetString("sprite", "Assets/Content/UI/UI.Background.Tile.psd"); 57 | } 58 | set { 59 | if (_obj.ContainsKey("sprite")) 60 | _obj["sprite"] = new JSON.Value(value); 61 | else 62 | _obj.Add("sprite", new JSON.Value(value)); 63 | } 64 | } 65 | 66 | public override string type { 67 | get { 68 | return "UnityEngine.UI.Image"; 69 | } 70 | } 71 | 72 | public Image() 73 | { 74 | this["type"] = new JSON.Value(type); 75 | } 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /Pluton/Objects/PlutonUIComponents/NeedsCursor.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton.PlutonUI 3 | { 4 | public class NeedsCursor : BaseComponent 5 | { 6 | public override string type { 7 | get { 8 | return "NeedsCursor"; 9 | } 10 | } 11 | 12 | public NeedsCursor() 13 | { 14 | this["type"] = new JSON.Value(type); 15 | } 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Pluton/Objects/PlutonUIComponents/Outline.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton.PlutonUI 3 | { 4 | public class Outline : BaseComponent 5 | { 6 | public string color { 7 | get { 8 | return _obj.GetString("color", "1.0 1.0 1.0 1.0"); 9 | } 10 | set { 11 | if (_obj.ContainsKey("color")) 12 | _obj["color"] = new JSON.Value(value); 13 | else 14 | _obj.Add("color", new JSON.Value(value)); 15 | } 16 | } 17 | 18 | public string distance { 19 | get { 20 | return _obj.GetString("distance", "1.0 -1.0"); 21 | } 22 | set { 23 | if (_obj.ContainsKey("distance")) 24 | _obj["distance"] = new JSON.Value(value); 25 | else 26 | _obj.Add("distance", new JSON.Value(value)); 27 | } 28 | } 29 | 30 | public override string type { 31 | get { 32 | return "UnityEngine.UI.Outline"; 33 | } 34 | } 35 | 36 | public bool useGraphicAlpha { 37 | get { 38 | return _obj.ContainsKey("useGraphicAlpha"); 39 | } 40 | set { 41 | if (_obj.ContainsKey("useGraphicAlpha") && !value) 42 | _obj.Remove("useGraphicAlpha"); 43 | else if (!_obj.ContainsKey("useGraphicAlpha") && value) 44 | _obj.Add("useGraphicAlpha", new JSON.Value(value)); 45 | } 46 | } 47 | 48 | public Outline() 49 | { 50 | this["type"] = new JSON.Value(type); 51 | } 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Pluton/Objects/PlutonUIComponents/RawImage.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton.PlutonUI 3 | { 4 | public class RawImage : BaseComponent 5 | { 6 | public string color { 7 | get { 8 | return _obj.GetString("color", "1.0 1.0 1.0 1.0"); 9 | } 10 | set { 11 | if (_obj.ContainsKey("color")) 12 | _obj["color"] = new JSON.Value(value); 13 | else 14 | _obj.Add("color", new JSON.Value(value)); 15 | } 16 | } 17 | 18 | public string material { 19 | get { 20 | return _obj.GetString("material"); 21 | } 22 | set { 23 | if (_obj.ContainsKey("material")) 24 | _obj["material"] = new JSON.Value(value); 25 | else 26 | _obj.Add("material", new JSON.Value(value)); 27 | } 28 | } 29 | 30 | public string png { 31 | get { 32 | return _obj.GetString("png"); 33 | } 34 | set { 35 | if (_obj.ContainsKey("png")) 36 | _obj["png"] = new JSON.Value(value); 37 | else 38 | _obj.Add("png", new JSON.Value(value)); 39 | } 40 | } 41 | 42 | public string sprite { 43 | get { 44 | return _obj.GetString("sprite", "Assets/Icons/rust.png"); 45 | } 46 | set { 47 | if (_obj.ContainsKey("sprite")) 48 | _obj["sprite"] = new JSON.Value(value); 49 | else 50 | _obj.Add("sprite", new JSON.Value(value)); 51 | } 52 | } 53 | 54 | public override string type { 55 | get { 56 | return "UnityEngine.UI.RawImage"; 57 | } 58 | } 59 | 60 | public string url { 61 | get { 62 | return _obj.GetString("url"); 63 | } 64 | set { 65 | if (_obj.ContainsKey("url")) 66 | _obj["url"] = new JSON.Value(value); 67 | else 68 | _obj.Add("url", new JSON.Value(value)); 69 | } 70 | } 71 | 72 | public RawImage() 73 | { 74 | this["type"] = new JSON.Value(type); 75 | } 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /Pluton/Objects/PlutonUIComponents/RectTransform.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton.PlutonUI 3 | { 4 | public class RectTransform : BaseComponent 5 | { 6 | public string anchormax { 7 | get { 8 | return _obj.GetString("anchormax", "1.0 1.0"); 9 | } 10 | set { 11 | if (_obj.ContainsKey("anchormax")) 12 | _obj["anchormax"] = new JSON.Value(value); 13 | else 14 | _obj.Add("anchormax", new JSON.Value(value)); 15 | } 16 | } 17 | 18 | public string anchormin { 19 | get { 20 | return _obj.GetString("anchormin", "0.0 0.0"); 21 | } 22 | set { 23 | if (_obj.ContainsKey("anchormin")) 24 | _obj["anchormin"] = new JSON.Value(value); 25 | else 26 | _obj.Add("anchormin", new JSON.Value(value)); 27 | } 28 | } 29 | 30 | public string offsetmax { 31 | get { 32 | return _obj.GetString("offsetmax", "1.0 1.0"); 33 | } 34 | set { 35 | if (_obj.ContainsKey("offsetmax")) 36 | _obj["offsetmax"] = new JSON.Value(value); 37 | else 38 | _obj.Add("offsetmax", new JSON.Value(value)); 39 | } 40 | } 41 | 42 | public string offsetmin { 43 | get { 44 | return _obj.GetString("offsetmin", "0.0 0.0"); 45 | } 46 | set { 47 | if (_obj.ContainsKey("offsetmin")) 48 | _obj["offsetmin"] = new JSON.Value(value); 49 | else 50 | _obj.Add("offsetmin", new JSON.Value(value)); 51 | } 52 | } 53 | 54 | public override string type { 55 | get { 56 | return "RectTransform"; 57 | } 58 | } 59 | 60 | public RectTransform() 61 | { 62 | this["type"] = new JSON.Value(type); 63 | } 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /Pluton/Objects/PlutonUIComponents/Text.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton.PlutonUI 3 | { 4 | public class Text : BaseComponent 5 | { 6 | public string align { 7 | get { 8 | return _obj.GetString("align", "UpperLeft"); 9 | } 10 | set { 11 | if (_obj.ContainsKey("align")) 12 | _obj["align"] = new JSON.Value(value); 13 | else 14 | _obj.Add("align", new JSON.Value(value)); 15 | } 16 | } 17 | 18 | public string color { 19 | get { 20 | return _obj.GetString("color", "1.0 1.0 1.0 1.0"); 21 | } 22 | set { 23 | if (_obj.ContainsKey("color")) 24 | _obj["color"] = new JSON.Value(value); 25 | else 26 | _obj.Add("color", new JSON.Value(value)); 27 | } 28 | } 29 | 30 | public string font { 31 | get { 32 | return _obj.GetString("font", "RobotoCondensed-Bold.ttf"); 33 | } 34 | set { 35 | if (_obj.ContainsKey("font")) 36 | _obj["font"] = new JSON.Value(value); 37 | else 38 | _obj.Add("font", new JSON.Value(value)); 39 | } 40 | } 41 | 42 | public int fontSize { 43 | get { 44 | return _obj.GetInt("fontSize", 14); 45 | } 46 | set { 47 | if (_obj.ContainsKey("fontSize")) 48 | _obj["fontSize"] = new JSON.Value(value); 49 | else 50 | _obj.Add("fontSize", new JSON.Value(value)); 51 | } 52 | } 53 | 54 | public string text { 55 | get { 56 | return _obj.GetString("text", "emptytext"); 57 | } 58 | set { 59 | if (_obj.ContainsKey("text")) 60 | _obj["text"] = new JSON.Value(value); 61 | else 62 | _obj.Add("text", new JSON.Value(value)); 63 | } 64 | } 65 | 66 | public override string type { 67 | get { 68 | return "UnityEngine.UI.Text"; 69 | } 70 | } 71 | 72 | public Text() 73 | { 74 | this["type"] = new JSON.Value(type); 75 | } 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /Pluton/Objects/PlutonUIEntity.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Pluton 4 | { 5 | public class PlutonUIEntity 6 | { 7 | public List connections; 8 | public JSON.Array panels = new JSON.Array(); 9 | 10 | public PlutonUIEntity(IEnumerable cons = null) 11 | { 12 | if (cons != null) 13 | connections = cons as List; 14 | } 15 | 16 | public PlutonUIEntity(Network.Connection con = null) 17 | { 18 | if (con != null) 19 | connections = new List() { con }; 20 | } 21 | 22 | public PlutonUIPanel AddPanel(string name = null, string parent = null, float? fadeout = null) 23 | { 24 | PlutonUIPanel panel = new PlutonUIPanel(name, parent, fadeout); 25 | panels.Add(panel.obj); 26 | return panel; 27 | } 28 | 29 | public JSON.Array CreateUI() 30 | { 31 | if (connections.Count == 0) 32 | return null; 33 | 34 | CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connections = connections }, null, "AddUI", new Facepunch.ObjectList?(new Facepunch.ObjectList(panels.ToString()))); 35 | return panels; 36 | } 37 | 38 | public void DestroyUI() 39 | { 40 | if (connections.Count == 0) 41 | return; 42 | foreach (var panel in panels) { 43 | CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connections = connections }, null, "DestroyPanel", new Facepunch.ObjectList?(new Facepunch.ObjectList(panel.Obj.GetString("name")))); 44 | } 45 | } 46 | 47 | public PlutonUIPanel GetPanel(string name) 48 | { 49 | for (int i = 0; i < panels.Length; i++) { 50 | if (panels[i].Obj.GetString(name) == name) { 51 | return new PlutonUIPanel() { obj = panels[i].Obj }; 52 | } 53 | } 54 | return null; 55 | } 56 | 57 | public bool RemovePanel(string name) 58 | { 59 | 60 | for (int i = 0; i < panels.Length; i++) { 61 | if (panels[i].Obj.GetString(name) == name) { 62 | panels.Remove(i); 63 | return true; 64 | } 65 | } 66 | return false; 67 | } 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /Pluton/Objects/PlutonUIPanel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton 4 | { 5 | public class PlutonUIPanel 6 | { 7 | public JSON.Object obj = new JSON.Object(); 8 | 9 | public JSON.Value this[string key] { 10 | get { 11 | return obj[key]; 12 | } 13 | set { 14 | obj[key] = value; 15 | } 16 | } 17 | 18 | public JSON.Array components { 19 | get { 20 | return obj.GetArray("components"); 21 | } 22 | set { 23 | if (obj.ContainsKey("components")) 24 | obj["components"] = new JSON.Value(value); 25 | else 26 | obj.Add("components", new JSON.Value(value)); 27 | } 28 | } 29 | 30 | public float fadeOut { 31 | get { 32 | return obj.GetFloat("fadeOut", 0f); 33 | } 34 | set { 35 | if (obj.ContainsKey("fadeOut")) 36 | obj["fadeOut"] = new JSON.Value(value); 37 | else 38 | obj.Add("fadeOut", new JSON.Value(value)); 39 | } 40 | } 41 | 42 | public string name { 43 | get { 44 | return obj.GetString("name", "PlutonUI Panel"); 45 | } 46 | set { 47 | if (obj.ContainsKey("name")) 48 | obj["name"] = new JSON.Value(value); 49 | else 50 | obj.Add("name", new JSON.Value(value)); 51 | } 52 | } 53 | 54 | public string parent { 55 | get { 56 | return obj.GetString("parent", "Overlay"); 57 | } 58 | set { 59 | if (obj.ContainsKey("parent")) 60 | obj["parent"] = new JSON.Value(value); 61 | else 62 | obj.Add("parent", new JSON.Value(value)); 63 | } 64 | } 65 | 66 | public PlutonUIPanel(string nam = null, string par = null, float? fade = null) 67 | { 68 | components = new JSON.Array(); 69 | if (nam != null) 70 | name = nam; 71 | if (par != null) 72 | parent = par; 73 | if (fade != null) 74 | fadeOut = (float)fade; 75 | } 76 | 77 | public PlutonUI.BaseComponent AddComponent(PlutonUI.BaseComponent comp) 78 | { 79 | components.Add(comp.obj); 80 | return comp; 81 | } 82 | 83 | public PlutonUI.BaseComponent AddComponent () where T : PlutonUI.BaseComponent 84 | { 85 | PlutonUI.BaseComponent t = Activator.CreateInstance(); 86 | components.Add(t.obj); 87 | return t; 88 | } 89 | 90 | public bool RemoveComponent(PlutonUI.BaseComponent comp) 91 | { 92 | for (int i = 0; i < components.Length; i++) { 93 | if (components[i].Obj == comp.obj) { 94 | components.Remove(i); 95 | return true; 96 | } 97 | } 98 | return false; 99 | } 100 | } 101 | } 102 | 103 | -------------------------------------------------------------------------------- /Pluton/Objects/Stats.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton 4 | { 5 | [Serializable] 6 | public class PlayerStats : CountedInstance 7 | { 8 | 9 | public uint Kills; 10 | public uint Deaths; 11 | 12 | public uint PlayerKills; 13 | public uint PlayerDeaths; 14 | 15 | public uint NPCKills; 16 | public uint NPCDeaths; 17 | 18 | public double TotalDamageTaken; 19 | public double TotalDamageDone; 20 | 21 | public double DamageToPlayers; 22 | public double DamageFromPlayers; 23 | 24 | public double DamageToNPCs; 25 | public double DamageFromNPCs; 26 | 27 | public double DamageToEntities; 28 | 29 | public double FallDamage; 30 | 31 | public PlayerStats(string steamid) 32 | { 33 | if (!Server.GetInstance().serverData.ContainsKey("PlayerStats", steamid)) { 34 | Kills = 0; 35 | Deaths = 0; 36 | PlayerKills = 0; 37 | PlayerDeaths = 0; 38 | NPCKills = 0; 39 | NPCDeaths = 0; 40 | TotalDamageTaken = 0; 41 | TotalDamageDone = 0; 42 | DamageToPlayers = 0; 43 | DamageFromPlayers = 0; 44 | DamageToNPCs = 0; 45 | DamageFromNPCs = 0; 46 | DamageToEntities = 0; 47 | FallDamage = 0; 48 | Server.GetInstance().serverData.Add("PlayerStats", steamid, this); 49 | } else { 50 | var stats = Server.GetInstance().serverData.Get("PlayerStats", steamid) as PlayerStats; 51 | Kills = stats.Kills; 52 | Deaths = stats.Deaths; 53 | PlayerKills = stats.PlayerKills; 54 | PlayerDeaths = stats.PlayerDeaths; 55 | NPCKills = stats.NPCKills; 56 | NPCDeaths = stats.NPCDeaths; 57 | TotalDamageTaken = stats.TotalDamageTaken; 58 | TotalDamageDone = stats.TotalDamageDone; 59 | DamageToPlayers = stats.DamageToPlayers; 60 | DamageFromPlayers = stats.DamageFromPlayers; 61 | DamageToNPCs = stats.DamageToNPCs; 62 | DamageFromNPCs = stats.DamageFromNPCs; 63 | DamageToEntities = stats.DamageToEntities; 64 | FallDamage = stats.FallDamage; 65 | } 66 | } 67 | 68 | public void AddKill(bool player, bool npc) 69 | { 70 | Kills++; 71 | if (player) 72 | PlayerKills++; 73 | else if (npc) 74 | NPCKills++; 75 | } 76 | 77 | public void AddDeath(bool player, bool npc) 78 | { 79 | Deaths++; 80 | if (player) 81 | PlayerDeaths++; 82 | else if (npc) 83 | NPCDeaths++; 84 | } 85 | 86 | public void AddDamageFrom(float dmgAmount, bool player, bool npc, bool fall) 87 | { 88 | TotalDamageTaken += (double)dmgAmount; 89 | if (player) 90 | DamageFromPlayers += (double)dmgAmount; 91 | else if (npc) 92 | DamageFromNPCs += (double)dmgAmount; 93 | else if (fall) 94 | FallDamage += (double)dmgAmount; 95 | } 96 | 97 | public void AddDamageTo(float dmgAmount, bool player, bool npc, bool entity) 98 | { 99 | TotalDamageDone += (double)dmgAmount; 100 | if (player) 101 | DamageToPlayers += (double)dmgAmount; 102 | else if (npc) 103 | DamageToNPCs += (double)dmgAmount; 104 | else if (entity) 105 | DamageToEntities += (double)dmgAmount; 106 | } 107 | } 108 | } 109 | 110 | -------------------------------------------------------------------------------- /Pluton/PluginLoaders/CSPlugin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using System.Linq; 5 | using System.Collections.Generic; 6 | 7 | namespace Pluton 8 | { 9 | /// 10 | /// C# plugin. 11 | /// 12 | public class CSPlugin : BasePlugin 13 | { 14 | public CSharpPlugin Engine; 15 | 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | /// Name. 20 | /// Code. 21 | /// Rootdir. 22 | public CSPlugin(string name, string code, DirectoryInfo rootdir) : base(name, rootdir) 23 | { 24 | Type = PluginType.CSharp; 25 | 26 | System.Threading.ThreadPool.QueueUserWorkItem( 27 | new System.Threading.WaitCallback(a => Load(code)), null); 28 | } 29 | 30 | /// 31 | /// Invoke the specified method and args. 32 | /// 33 | /// Method. 34 | /// Arguments. 35 | /// Func. 36 | public override object Invoke(string func, params object[] args) 37 | { 38 | try { 39 | if (State == PluginState.Loaded && Globals.Contains(func)) { 40 | object result = (object)null; 41 | 42 | using (new Stopper(Name, func)) { 43 | result = Engine.CallMethod(func, args); 44 | } 45 | return result; 46 | } else { 47 | Logger.LogWarning("[Plugin] Function: " + func + " not found in plugin: " + Name + ", or plugin is not loaded."); 48 | return null; 49 | } 50 | } catch (Exception ex) { 51 | string fileinfo = (String.Format("{0}<{1}>.{2}()", Name, Type, func) + Environment.NewLine); 52 | HasErrors = true; 53 | if (ex is TargetInvocationException) { 54 | LastError = FormatException(ex.InnerException); 55 | Logger.LogError(fileinfo + FormatException(ex.InnerException)); 56 | } else { 57 | LastError = FormatException(ex); 58 | Logger.LogError(fileinfo + FormatException(ex)); 59 | } 60 | return null; 61 | } 62 | } 63 | 64 | public override void Load(string code = "") 65 | { 66 | try { 67 | byte[] bin = File.ReadAllBytes(code); 68 | if (CoreConfig.GetInstance().GetBoolValue("csharp", "checkHash") && !bin.VerifyMD5Hash()) { 69 | Logger.LogDebug(String.Format("[Plugin] MD5Hash not found for: {0} [{1}]!", Name, Type)); 70 | State = PluginState.HashNotFound; 71 | return; 72 | } 73 | 74 | LoadReferences(); 75 | 76 | Assembly assembly = Assembly.Load(bin); 77 | Type classType = assembly.GetType(Name + "." + Name); 78 | if (classType == null || !classType.IsSubclassOf(typeof(CSharpPlugin)) || !classType.IsPublic || classType.IsAbstract) 79 | throw new TypeLoadException("Main module class not found:" + Name); 80 | 81 | Engine = (CSharpPlugin)Activator.CreateInstance(classType); 82 | 83 | Engine.Plugin = this; 84 | Engine.Commands = chatCommands; 85 | Engine.ServerConsoleCommands = consoleCommands; 86 | 87 | Globals = (from method in classType.GetMethods() 88 | select method.Name).ToList(); 89 | 90 | State = PluginState.Loaded; 91 | } catch (Exception ex) { 92 | Logger.LogException(ex); 93 | State = PluginState.FailedToLoad; 94 | } 95 | 96 | PluginLoader.GetInstance().OnPluginLoaded(this); 97 | } 98 | 99 | public void LoadReferences() 100 | { 101 | List dllpaths = GetRefDllPaths().ToList(); 102 | foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies()) { 103 | if (dllpaths.Contains(ass.FullName)) { 104 | dllpaths.Remove(ass.FullName); 105 | } 106 | } 107 | dllpaths.ForEach(path => { 108 | Assembly.LoadFile(path); 109 | }); 110 | } 111 | 112 | IEnumerable GetRefDllPaths() 113 | { 114 | string refpath = Path.Combine(RootDir.FullName, "References"); 115 | if (Directory.Exists(refpath)) { 116 | DirectoryInfo refdir = new DirectoryInfo(refpath); 117 | FileInfo[] files = refdir.GetFiles("*.dll"); 118 | foreach (FileInfo file in files) { 119 | yield return file.FullName; 120 | } 121 | } 122 | } 123 | } 124 | } 125 | 126 | -------------------------------------------------------------------------------- /Pluton/PluginLoaders/CSharpPlugin.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Pluton 3 | { 4 | /// 5 | /// C# engine. 6 | /// 7 | public class CSharpPlugin 8 | { 9 | /// 10 | /// Gets or sets the author. 11 | /// 12 | /// The author. 13 | public string Author { 14 | get { 15 | return Plugin.Author; 16 | } 17 | set { 18 | Plugin.Author = value; 19 | } 20 | } 21 | 22 | /// 23 | /// Gets or sets the about. 24 | /// 25 | /// The about. 26 | public string About { 27 | get { 28 | return Plugin.About; 29 | } 30 | set { 31 | Plugin.About = value; 32 | } 33 | } 34 | 35 | /// 36 | /// Gets or sets the version. 37 | /// 38 | /// The version. 39 | public string Version { 40 | get { 41 | return Plugin.Version; 42 | } 43 | set { 44 | Plugin.Version = value; 45 | } 46 | } 47 | 48 | /// 49 | /// The commands. 50 | /// 51 | public ChatCommands Commands; 52 | 53 | /// 54 | /// The data store. 55 | /// 56 | public DataStore DataStore { 57 | get { 58 | return DataStore.GetInstance(); 59 | } 60 | } 61 | 62 | /// 63 | /// The plugin. 64 | /// 65 | public BasePlugin Plugin; 66 | 67 | /// 68 | /// The util. 69 | /// 70 | public Util Util { 71 | get { 72 | return Util.GetInstance(); 73 | } 74 | } 75 | 76 | /// 77 | /// The server. 78 | /// 79 | public Server Server { 80 | get { 81 | return Server.GetInstance(); 82 | } 83 | } 84 | 85 | /// 86 | /// The server console commands. 87 | /// 88 | public ConsoleCommands ServerConsoleCommands; 89 | 90 | /// 91 | /// The web. 92 | /// 93 | public Web Web { 94 | get { 95 | return Web.GetInstance(); 96 | } 97 | } 98 | 99 | /// 100 | /// The world. 101 | /// 102 | public World World { 103 | get { 104 | return World.GetInstance(); 105 | } 106 | } 107 | 108 | /// 109 | /// Find instance for C# plugins. 110 | /// 111 | /// The find class. 112 | public Find Find { 113 | get { 114 | return Find.GetInstance(); 115 | } 116 | } 117 | 118 | /// 119 | /// A global storage that any plugin can easily access. 120 | /// 121 | public System.Collections.Generic.Dictionary GlobalData { 122 | get { 123 | return BasePlugin.GlobalData; 124 | } 125 | } 126 | 127 | public CSharpPlugin() 128 | { 129 | } 130 | } 131 | } 132 | 133 | -------------------------------------------------------------------------------- /Pluton/PluginLoaders/IPlugin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Pluton.Events; 3 | 4 | namespace Pluton 5 | { 6 | public interface IPlugin 7 | { 8 | string FormatException(Exception ex); 9 | 10 | object Invoke(string method, params object[] args); 11 | 12 | void Load(string code = ""); 13 | } 14 | 15 | public enum PluginState : sbyte 16 | { 17 | FailedToLoad = -1, 18 | NotLoaded = 0, 19 | Loaded = 1, 20 | HashNotFound = 2 21 | } 22 | 23 | public enum PluginType 24 | { 25 | Undefined, 26 | Python, 27 | JavaScript, 28 | CSharp, 29 | CSScript, 30 | Lua 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Pluton/PluginLoaders/IPluginLoader.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Pluton 4 | { 5 | public interface IPluginLoader 6 | { 7 | string GetExtension(); 8 | 9 | string GetSource(string path); 10 | 11 | string GetMainFilePath(string pluginname); 12 | 13 | string GetPluginDirectoryPath(string name); 14 | 15 | IEnumerable GetPluginNames(); 16 | 17 | void LoadPlugin(string name); 18 | 19 | void LoadPlugins(); 20 | 21 | void ReloadPlugin(string name); 22 | 23 | void ReloadPlugins(); 24 | 25 | void UnloadPlugin(string name); 26 | 27 | void UnloadPlugins(); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Pluton/PluginLoaders/JSPlugin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using Jint; 5 | using Jint.Expressions; 6 | 7 | namespace Pluton 8 | { 9 | public class JSPlugin : BasePlugin 10 | { 11 | public JintEngine Engine; 12 | public Jint.Expressions.Program Program; 13 | 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | /// Name. 18 | /// Code. 19 | /// Rootdir. 20 | public JSPlugin(string name, string code, DirectoryInfo rootdir) : base(name, rootdir) 21 | { 22 | Type = PluginType.JavaScript; 23 | 24 | if (CoreConfig.GetInstance().GetBoolValue("javascript", "checkHash") && !code.VerifyMD5Hash()) { 25 | Logger.LogDebug(String.Format("[Plugin] MD5Hash not found for: {0} [{1}]!", name, Type)); 26 | State = PluginState.HashNotFound; 27 | return; 28 | } 29 | 30 | System.Threading.ThreadPool.QueueUserWorkItem( 31 | new System.Threading.WaitCallback(a => Load(code)), null); 32 | } 33 | 34 | /// 35 | /// Invoke the specified method and args. 36 | /// 37 | /// Method. 38 | /// Arguments. 39 | /// Func. 40 | public override object Invoke(string func, params object[] args) 41 | { 42 | try { 43 | if (State == PluginState.Loaded && Globals.Contains(func)) { 44 | object result = (object)null; 45 | 46 | using (new Stopper(Name, func)) { 47 | result = Engine.CallFunction(func, args); 48 | } 49 | return result; 50 | } else { 51 | Logger.LogWarning("[Plugin] Function: " + func + " not found in plugin: " + Name + ", or plugin is not loaded."); 52 | return null; 53 | } 54 | } catch (Exception ex) { 55 | string fileinfo = (String.Format("{0}<{1}>.{2}()", Name, Type, func) + Environment.NewLine); 56 | Logger.LogError(fileinfo + FormatException(ex)); 57 | return null; 58 | } 59 | } 60 | 61 | public override void Load(string code = "") 62 | { 63 | 64 | try { 65 | Engine = new JintEngine(Options.Ecmascript5) 66 | .AllowClr(true); 67 | 68 | Engine.SetParameter("Commands", chatCommands) 69 | .SetParameter("DataStore", DataStore.GetInstance()) 70 | .SetParameter("Find", Find.GetInstance()) 71 | .SetParameter("GlobalData", GlobalData) 72 | .SetParameter("Plugin", this) 73 | .SetParameter("Server", Server.GetInstance()) 74 | .SetParameter("ServerConsoleCommands", consoleCommands) 75 | .SetParameter("Util", Util.GetInstance()) 76 | .SetParameter("Web", Web) 77 | .SetParameter("World", World.GetInstance()) 78 | .SetFunction("importClass", new importit(importClass)); 79 | Program = JintEngine.Compile(code, false); 80 | 81 | Globals = (from statement in Program.Statements 82 | where statement.GetType() == typeof(FunctionDeclarationStatement) 83 | select ((FunctionDeclarationStatement)statement).Name).ToList(); 84 | 85 | Engine.Run(Program); 86 | 87 | object author = GetGlobalObject("Author"); 88 | object about = GetGlobalObject("About"); 89 | object version = GetGlobalObject("Version"); 90 | Author = author == null ? "" : author.ToString(); 91 | About = about == null ? "" : about.ToString(); 92 | Version = version == null ? "" : version.ToString(); 93 | 94 | State = PluginState.Loaded; 95 | } catch (Exception ex) { 96 | Logger.LogException(ex); 97 | State = PluginState.FailedToLoad; 98 | PluginLoader.GetInstance().CurrentlyLoadingPlugins.Remove(Name); 99 | } 100 | 101 | PluginLoader.GetInstance().OnPluginLoaded(this); 102 | } 103 | 104 | public object GetGlobalObject(string identifier) 105 | { 106 | return Engine.Run(String.Format("return {0};", identifier)); 107 | } 108 | 109 | public delegate Jint.Native.JsInstance importit(string t); 110 | 111 | public Jint.Native.JsInstance importClass(string type) 112 | { 113 | Engine.SetParameter(type.Split('.').Last(), Util.GetInstance().TryFindReturnType(type)); 114 | return (Engine.Global as Jint.Native.JsDictionaryObject)[type.Split('.').Last()]; 115 | } 116 | } 117 | } 118 | 119 | -------------------------------------------------------------------------------- /Pluton/PluginLoaders/LUAPlugin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using MoonSharp.Interpreter; 4 | using MoonSharp.Interpreter.Interop; 5 | 6 | namespace Pluton 7 | { 8 | /// 9 | /// Lua plugin. 10 | /// 11 | public class LUAPlugin : BasePlugin 12 | { 13 | 14 | /// 15 | /// LUA Tables 16 | /// 17 | public Table Tables; 18 | public Script script; 19 | 20 | /// 21 | /// Initializes a new instance of the class. 22 | /// 23 | /// Name. 24 | /// Code. 25 | /// Rootdir. 26 | public LUAPlugin(string name, string code, DirectoryInfo rootdir) 27 | : base(name, rootdir) 28 | { 29 | Type = PluginType.Lua; 30 | 31 | if (CoreConfig.GetInstance().GetBoolValue("lua", "checkHash") && !code.VerifyMD5Hash()) 32 | { 33 | Logger.LogDebug(String.Format("[Plugin] MD5Hash not found for: {0} [{1}]!", name, Type)); 34 | State = PluginState.HashNotFound; 35 | PluginLoader.GetInstance().CurrentlyLoadingPlugins.Remove(Name); 36 | return; 37 | } 38 | 39 | System.Threading.ThreadPool.QueueUserWorkItem( 40 | new System.Threading.WaitCallback(a => Load(code)), null); 41 | } 42 | 43 | /// 44 | /// Invoke the specified method and args. 45 | /// 46 | /// Method. 47 | /// Arguments. 48 | /// Func. 49 | public override object Invoke(string func, params object[] args) 50 | { 51 | try 52 | { 53 | if (State == PluginState.Loaded && Globals.Contains(func)) 54 | { 55 | object result = (object)null; 56 | 57 | using (new Stopper(Name, func)) 58 | { 59 | result = script.Call(script.Globals[func], args); 60 | } 61 | return result; 62 | } 63 | else 64 | { 65 | Logger.LogWarning("[Plugin] Function: " + func + " not found in plugin: " + Name + ", or plugin is not loaded."); 66 | return null; 67 | } 68 | } 69 | catch (Exception ex) 70 | { 71 | string fileinfo = (String.Format("{0}<{1}>.{2}()", Name, Type, func) + Environment.NewLine); 72 | Logger.LogError(fileinfo + FormatException(ex)); 73 | return null; 74 | } 75 | } 76 | 77 | public override string FormatException(Exception ex) 78 | { 79 | return base.FormatException(ex) + 80 | (ex is ScriptRuntimeException ? Environment.NewLine + (ex as ScriptRuntimeException).DecoratedMessage : ""); 81 | } 82 | 83 | public override void Load(string code = "") 84 | { 85 | try 86 | { 87 | UserData.RegistrationPolicy = InteropRegistrationPolicy.Automatic; 88 | script = new Script(); 89 | script.Globals["Plugin"] = this; 90 | script.Globals["Util"] = Util.GetInstance(); 91 | script.Globals["Server"] = Server.GetInstance(); 92 | script.Globals["DataStore"] = DataStore.GetInstance(); 93 | script.Globals["Commands"] = chatCommands; 94 | script.Globals["GlobalData"] = GlobalData; 95 | script.Globals["ServerConsoleCommands"] = consoleCommands; 96 | script.Globals["Web"] = Web.GetInstance(); 97 | script.Globals["World"] = World.GetInstance(); 98 | script.DoString(code); 99 | 100 | Author = script.Globals.Get("Author").String; 101 | About = script.Globals.Get("About").String; 102 | Version = script.Globals.Get("Version").String; 103 | 104 | State = PluginState.Loaded; 105 | foreach (DynValue v in script.Globals.Keys) 106 | { 107 | Globals.Add(v.ToString().Replace("\"", "")); 108 | } 109 | Tables = script.Globals; 110 | } 111 | catch (Exception ex) 112 | { 113 | Logger.LogException(ex); 114 | State = PluginState.FailedToLoad; 115 | } 116 | 117 | PluginLoader.GetInstance().OnPluginLoaded(this); 118 | } 119 | } 120 | } 121 | 122 | -------------------------------------------------------------------------------- /Pluton/PluginLoaders/PHPPlugin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using PHP.Core; 4 | 5 | namespace Pluton.PluginLoaders 6 | { 7 | /// 8 | /// PHP plugin. 9 | /// 10 | public class PHPPlugin : BasePlugin 11 | { 12 | ScriptContext context; 13 | public PhpArray PHPGlobals; 14 | PhpObject Class; 15 | private DirectoryInfo rpath; 16 | 17 | /// 18 | /// Initializes a new instance of the class. 19 | /// 20 | /// Name. 21 | /// Code. 22 | /// Rootdir. 23 | public PHPPlugin(string name, string code, DirectoryInfo rootdir) 24 | : base(name, rootdir) 25 | { 26 | rpath = rootdir; 27 | Type = PluginType.PHP; 28 | 29 | if (CoreConfig.GetInstance().GetBoolValue("php", "checkHash") && !code.VerifyMD5Hash()) 30 | { 31 | Logger.LogDebug(String.Format("[Plugin] MD5Hash not found for: {0} [{1}]!", name, Type)); 32 | State = PluginState.HashNotFound; 33 | return; 34 | } 35 | 36 | System.Threading.ThreadPool.QueueUserWorkItem( 37 | new System.Threading.WaitCallback(a => Load(code)), null); 38 | } 39 | 40 | /// 41 | /// Invoke the specified method and args. 42 | /// 43 | /// Method. 44 | /// Arguments. 45 | /// Func. 46 | public override object Invoke(string func, params object[] args) 47 | { 48 | try 49 | { 50 | if (State == PluginState.Loaded && Globals.Contains(func)) 51 | { 52 | object result = (object)null; 53 | 54 | using (new Stopper(Name, func)) 55 | { 56 | var caller = new PhpCallback(Class, func); 57 | result = caller.Invoke(args); 58 | } 59 | return result; 60 | } 61 | else 62 | { 63 | Logger.LogWarning("[Plugin] Function: " + func + " not found in plugin: " + Name + ", or plugin is not loaded."); 64 | return null; 65 | } 66 | } 67 | catch (Exception ex) 68 | { 69 | string fileinfo = (String.Format("{0}<{1}>.{2}()", Name, Type, func) + Environment.NewLine); 70 | Logger.LogError(fileinfo + FormatException(ex)); 71 | return null; 72 | } 73 | } 74 | 75 | public override void Load(string code = "") 76 | { 77 | try 78 | { 79 | context = ScriptContext.CurrentContext; 80 | context.Include(rpath + "\\" + Name + ".php", true); 81 | Class = (PhpObject) context.NewObject(Name); 82 | PHPGlobals = context.GlobalVariables; 83 | context.GlobalVariables.Add("Commands", chatCommands); 84 | context.GlobalVariables.Add("DataStore", DataStore.GetInstance()); 85 | context.GlobalVariables.Add("Find", Find.GetInstance()); 86 | context.GlobalVariables.Add("GlobalData", GlobalData); 87 | context.GlobalVariables.Add("Plugin", this); 88 | context.GlobalVariables.Add("Server", Pluton.Server.GetInstance()); 89 | context.GlobalVariables.Add("ServerConsoleCommands", consoleCommands); 90 | context.GlobalVariables.Add("Util", Util.GetInstance()); 91 | context.GlobalVariables.Add("Web", Web.GetInstance()); 92 | context.GlobalVariables.Add("World", World.GetInstance()); 93 | foreach (var x in PHPGlobals) 94 | { 95 | Globals.Add(x.Key.ToString()); 96 | } 97 | 98 | State = PluginState.Loaded; 99 | } 100 | catch (Exception ex) 101 | { 102 | Logger.LogException(ex); 103 | State = PluginState.FailedToLoad; 104 | } 105 | 106 | PluginLoader.GetInstance().OnPluginLoaded(this); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Pluton/PluginLoaders/PluginWatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace Pluton 7 | { 8 | public class PluginWatcher : Singleton, ISingleton 9 | { 10 | public List Watchers = new List(); 11 | 12 | public PluginWatcher() 13 | { 14 | } 15 | 16 | public void AddWatcher(PluginType type, string filter) 17 | { 18 | foreach (PluginTypeWatcher watch in Watchers) 19 | if (watch.Type == type) 20 | return; 21 | 22 | PluginTypeWatcher watcher = new PluginTypeWatcher(type, filter); 23 | Watchers.Add(watcher); 24 | } 25 | 26 | public void Initialize() 27 | { 28 | } 29 | 30 | public bool CheckDependencies() 31 | { 32 | return true; 33 | } 34 | } 35 | 36 | public class PluginTypeWatcher : CountedInstance 37 | { 38 | public PluginType Type; 39 | 40 | public FileSystemWatcher Watcher; 41 | 42 | public PluginTypeWatcher(PluginType type, string filter) 43 | { 44 | Type = type; 45 | Watcher = new FileSystemWatcher(Path.Combine(Util.GetPublicFolder(), "Plugins"), "*" + filter); 46 | Watcher.EnableRaisingEvents = true; 47 | Watcher.IncludeSubdirectories = true; 48 | Watcher.Changed += OnPluginChanged; 49 | Watcher.Created += OnPluginCreated; 50 | 51 | } 52 | 53 | public override string ToString() 54 | { 55 | return String.Format("PluginTypeWatcher<{0}>", Type); 56 | } 57 | 58 | bool TryLoadPlugin(string name, PluginType type) 59 | { 60 | try { 61 | BasePlugin plugin = null; 62 | if (PluginLoader.GetInstance().Plugins.TryGetValue(name, out plugin)) 63 | PluginLoader.GetInstance().ReloadPlugin(plugin); 64 | else 65 | PluginLoader.GetInstance().LoadPlugin(name, type); 66 | 67 | return true; 68 | 69 | } catch (Exception ex) { 70 | Pluton.Logger.LogException(ex); 71 | return false; 72 | } 73 | } 74 | 75 | void OnPluginCreated(object sender, FileSystemEventArgs e) 76 | { 77 | string filename = Path.GetFileNameWithoutExtension(e.Name); 78 | string dir = Path.GetDirectoryName(e.FullPath).Split(Path.DirectorySeparatorChar).Last(); 79 | 80 | if (filename == dir) { 81 | if (!TryLoadPlugin(filename, Type)) { 82 | Pluton.Logger.Log(String.Format("[PluginWatcher] Couldn't load: {0}{3}{1}.{2}", dir, filename, Type, Path.DirectorySeparatorChar)); 83 | } 84 | } 85 | } 86 | 87 | void OnPluginChanged(object sender, FileSystemEventArgs e) 88 | { 89 | string filename = Path.GetFileNameWithoutExtension(e.Name); 90 | string dir = Path.GetDirectoryName(e.FullPath).Split(Path.DirectorySeparatorChar).Last(); 91 | 92 | string assumedPluginPathFromDir = Path.Combine(Path.Combine(Watcher.Path, dir), dir + Path.GetExtension(e.Name)); 93 | 94 | if (filename == dir) { 95 | if (File.Exists(e.FullPath)) { 96 | if (!TryLoadPlugin(filename, Type)) { 97 | Pluton.Logger.Log(String.Format("[PluginWatcher] Couldn't load: {0}{3}{1}.{2}", dir, filename, Type, Path.DirectorySeparatorChar)); 98 | } 99 | } 100 | } else if (File.Exists(assumedPluginPathFromDir)) { 101 | if (!TryLoadPlugin(dir, Type)) { 102 | Pluton.Logger.Log(String.Format("[PluginWatcher] Couldn't load: {0}{3}{1}.{2}", dir, filename, Type, Path.DirectorySeparatorChar)); 103 | } 104 | } 105 | } 106 | } 107 | } 108 | 109 | -------------------------------------------------------------------------------- /Pluton/Pluton.cfg: -------------------------------------------------------------------------------- 1 | [Config] 2 | 3 | ;;; is pluton Enabled? 4 | enabled=true 5 | 6 | ;;; How often the server will Save. (milliseconds) 7 | saveInterval=180000 8 | 9 | [Logging] 10 | chatInConsole=true 11 | debugInConsole=true 12 | errorInConsole=true 13 | exceptionInConsole=true 14 | 15 | chatInLog=true 16 | debugInLog=true 17 | errorInLog=true 18 | exceptionInLog=true 19 | -------------------------------------------------------------------------------- /Pluton/Pluton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Pluton 5 | { 6 | [ConsoleSystem.Factory("pluton")] 7 | public class pluton : ConsoleSystem 8 | { 9 | 10 | [ConsoleSystem.Admin, ConsoleSystem.Help("Helps to break basic functionality", "")] 11 | public static bool enabled; 12 | 13 | [ConsoleSystem.Admin, ConsoleSystem.Help("Measure perfomance of method calls.", "")] 14 | public static bool stopper; 15 | 16 | static pluton() 17 | { 18 | pluton.enabled = true; 19 | pluton.stopper = false; 20 | } 21 | 22 | public pluton() 23 | : base() 24 | { 25 | } 26 | 27 | [ConsoleSystem.Admin] 28 | public static void ban(ConsoleSystem.Arg arg) 29 | { 30 | Player player = Player.Find(arg.ArgsStr); 31 | if (player != null) { 32 | string nameFrom; 33 | if (arg.connection != null && arg.connection.username != null) 34 | nameFrom = arg.connection.username; 35 | else 36 | nameFrom = "RCON"; 37 | 38 | player.Ban("Banned by: " + nameFrom); 39 | Server.GetInstance().Broadcast(arg.ArgsStr + " is banned from the server by " + nameFrom + "!"); 40 | arg.ReplyWith(arg.ArgsStr + " is banned!"); 41 | } else { 42 | arg.ReplyWith("Couldn't find player: " + arg.ArgsStr); 43 | } 44 | } 45 | 46 | [ConsoleSystem.Admin] 47 | public static void kick(ConsoleSystem.Arg arg) 48 | { 49 | Player player = Player.Find(arg.ArgsStr); 50 | if (player != null) { 51 | string nameFrom; 52 | if (arg.connection != null && arg.connection.username != null) 53 | nameFrom = arg.connection.username; 54 | else 55 | nameFrom = "RCON"; 56 | 57 | player.Kick("Kicked by: " + nameFrom); 58 | Server.GetInstance().Broadcast(arg.ArgsStr + " is kicked from the server by " + nameFrom + "!"); 59 | arg.ReplyWith(arg.ArgsStr + " is kicked!"); 60 | } else { 61 | arg.ReplyWith("Couldn't find player: " + arg.ArgsStr); 62 | } 63 | } 64 | 65 | [ConsoleSystem.User, ConsoleSystem.Help("pluton.login ", "")] 66 | public static void login(ConsoleSystem.Arg arg) 67 | { 68 | if (arg.connection != null && arg.ArgsStr == rcon.password) { 69 | ServerUsers.Set(arg.connection.userid, ServerUsers.UserGroup.Moderator, arg.connection.username, "Console login!"); 70 | ServerUsers.Save(); 71 | arg.ReplyWith("You are a moderator now!"); 72 | } 73 | } 74 | 75 | [ConsoleSystem.Admin, ConsoleSystem.Help("pluton.reload ", "")] 76 | public static void reload(ConsoleSystem.Arg arg) 77 | { 78 | if (PluginLoader.GetInstance().Plugins.ContainsKey(arg.ArgsStr)) { 79 | PluginLoader.GetInstance().ReloadPlugin(arg.ArgsStr); 80 | arg.ReplyWith(String.Format("{0} plugin reloaded!", arg.ArgsStr)); 81 | } else if (arg.ArgsStr == "") { 82 | DirectoryConfig.GetInstance().Reload(); 83 | CoreConfig.GetInstance().Reload(); 84 | Config.GetInstance().Reload(); 85 | 86 | Server.GetInstance().LoadLoadouts(); 87 | 88 | if (Server.GetInstance().Loaded) 89 | Hooks.On_ServerInit(); 90 | 91 | PluginLoader.GetInstance().ReloadPlugins(); 92 | 93 | arg.ReplyWith("Pluton reloaded!"); 94 | 95 | var planes = (from plane in UnityEngine.Object.FindObjectsOfType() 96 | where plane.transform.position.x == 0f && plane.transform.position.z == 0f 97 | select plane).ToList(); 98 | planes.ForEach(p => p.SendMessage("KillMessage", UnityEngine.SendMessageOptions.DontRequireReceiver)); 99 | if (planes.Count != 0) { 100 | Pluton.Logger.LogWarning(String.Format("Destroyed {0} plane at Vector3.zero", planes.Count)); 101 | } 102 | } else { 103 | arg.ReplyWith(String.Format("Couldn't find plugin: {0}!", arg.ArgsStr)); 104 | } 105 | } 106 | 107 | [ConsoleSystem.Admin, ConsoleSystem.Help("Manually saves stats, server", "")] 108 | public static void saveall(ConsoleSystem.Arg arg) 109 | { 110 | Bootstrap.SaveAll(); 111 | arg.ReplyWith("Everything saved!"); 112 | } 113 | 114 | [ConsoleSystem.Admin, ConsoleSystem.Help("Prints some data to the server console.", "")] 115 | public static void status(ConsoleSystem.Arg arg) 116 | { 117 | UnityEngine.Debug.Log(CountedInstance.InstanceReportText()); 118 | arg.ReplyWith("Finished report!"); 119 | } 120 | } 121 | } 122 | 123 | -------------------------------------------------------------------------------- /Pluton/Pluton.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pluton", "Pluton.csproj", "{245F4330-51E8-4B2A-A5C6-45145A09EF52}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {245F4330-51E8-4B2A-A5C6-45145A09EF52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {245F4330-51E8-4B2A-A5C6-45145A09EF52}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {245F4330-51E8-4B2A-A5C6-45145A09EF52}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {245F4330-51E8-4B2A-A5C6-45145A09EF52}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(MonoDevelopProperties) = preSolution 18 | Policies = $0 19 | $0.TextStylePolicy = $1 20 | $1.FileWidth = 120 21 | $1.inheritsSet = VisualStudio 22 | $1.inheritsScope = text/plain 23 | $1.scope = text/x-csharp 24 | $0.CSharpFormattingPolicy = $2 25 | $2.IndentSwitchBody = True 26 | $2.BeforeMethodDeclarationParentheses = False 27 | $2.BeforeMethodCallParentheses = False 28 | $2.BeforeConstructorDeclarationParentheses = False 29 | $2.BeforeIndexerDeclarationBracket = False 30 | $2.BeforeDelegateDeclarationParentheses = False 31 | $2.AfterDelegateDeclarationParameterComma = True 32 | $2.NewParentheses = False 33 | $2.SpacesBeforeBrackets = False 34 | $2.inheritsSet = Mono 35 | $2.inheritsScope = text/x-csharp 36 | $2.scope = text/x-csharp 37 | $0.TextStylePolicy = $3 38 | $3.FileWidth = 120 39 | $3.inheritsSet = VisualStudio 40 | $3.inheritsScope = text/plain 41 | $3.scope = text/plain 42 | outputpath = build\bin 43 | EndGlobalSection 44 | EndGlobal 45 | -------------------------------------------------------------------------------- /Pluton/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | // Information about this assembly is defined by the following attributes. 4 | // Change them to the values specific to your project. 5 | 6 | [assembly: AssemblyTitle("Pluton")] 7 | [assembly: AssemblyDescription("A server mod for the active branch of the survival sandbox game Rust")] 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("Pluton")] 11 | [assembly: AssemblyCopyright("Pluton Team")] 12 | [assembly: AssemblyTrademark("")] 13 | [assembly: AssemblyCulture("")] 14 | 15 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 16 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 17 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 18 | 19 | [assembly: AssemblyVersion("1.2.13.*")] 20 | 21 | // The following attributes are used to specify the signing key for the assembly, 22 | // if desired. See the Mono documentation for more information about signing. 23 | 24 | //[assembly: AssemblyDelaySign(false)] 25 | //[assembly: AssemblyKeyFile("")] 26 | 27 | -------------------------------------------------------------------------------- /Pluton/Serialize/ISerializable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton 4 | { 5 | public interface ISerializable 6 | { 7 | object Deserialize(); 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /Pluton/Serialize/SerializedQuaternion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace Pluton 5 | { 6 | [Serializable] 7 | public struct SerializedQuaternion : ISerializable 8 | { 9 | public float x; 10 | public float y; 11 | public float z; 12 | public float w; 13 | 14 | public SerializedQuaternion(Quaternion q) 15 | { 16 | x = q.x; 17 | y = q.y; 18 | z = q.z; 19 | w = q.w; 20 | } 21 | 22 | public object Deserialize() 23 | { 24 | return new Quaternion(x, y, z, w); 25 | } 26 | 27 | public override bool Equals(object other) 28 | { 29 | if (!(other is SerializedQuaternion)) { 30 | return false; 31 | } 32 | SerializedQuaternion q = (SerializedQuaternion)other; 33 | return x.Equals (q.x) && y.Equals (q.y) && z.Equals (q.z) && w.Equals (q.w); 34 | } 35 | 36 | public override int GetHashCode() 37 | { 38 | return ToQuaternion().GetHashCode(); 39 | } 40 | 41 | public Quaternion ToQuaternion() 42 | { 43 | return new Quaternion(x, y, z, w); 44 | } 45 | 46 | public override string ToString() 47 | { 48 | return String.Format("({0:F1}, {1:F1}, {2:F1}, {3:F1})", new object[] { x, y, z, w }); 49 | } 50 | 51 | public static bool operator == (SerializedQuaternion lhs, SerializedQuaternion rhs) { 52 | return Quaternion.Dot (lhs.ToQuaternion(), rhs.ToQuaternion()) > 0.999999; 53 | } 54 | 55 | public static bool operator != (SerializedQuaternion lhs, SerializedQuaternion rhs) { 56 | return Quaternion.Dot (lhs.ToQuaternion(), rhs.ToQuaternion()) <= 0.999999; 57 | } 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /Pluton/Serialize/SerializedVector3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace Pluton 5 | { 6 | [Serializable] 7 | public struct SerializedVector3 : ISerializable 8 | { 9 | public float x; 10 | public float y; 11 | public float z; 12 | 13 | public SerializedVector3(Vector3 v3) 14 | { 15 | x = v3.x; 16 | y = v3.y; 17 | z = v3.z; 18 | } 19 | 20 | public object Deserialize() 21 | { 22 | return new Vector3(x, y, z); 23 | } 24 | 25 | public override bool Equals(object other) 26 | { 27 | if (!(other is SerializedVector3)) 28 | return false; 29 | 30 | SerializedVector3 v3 = (SerializedVector3)other; 31 | 32 | return x.Equals(v3.x) && y.Equals(v3.y) && z.Equals(v3.z); 33 | } 34 | 35 | public override int GetHashCode() 36 | { 37 | return ToVector3().GetHashCode(); 38 | } 39 | 40 | public Vector3 ToVector3() 41 | { 42 | return new Vector3(x, y, z); 43 | } 44 | 45 | public override string ToString() 46 | { 47 | return String.Format("({0:F1}, {1:F1}, {2:F1})", x, y, z); 48 | } 49 | 50 | public static bool operator == (SerializedVector3 lhs, SerializedVector3 rhs) { 51 | return Vector3.SqrMagnitude (lhs.ToVector3() - rhs.ToVector3()) < 9.999999E-11; 52 | } 53 | 54 | public static bool operator != (SerializedVector3 lhs, SerializedVector3 rhs) { 55 | return Vector3.SqrMagnitude (lhs.ToVector3() - rhs.ToVector3()) >= 9.999999E-11; 56 | } 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /Pluton/Serialize/SerializedZone2D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | namespace Pluton 7 | { 8 | [Serializable] 9 | public class SerializedZone2D 10 | { 11 | public string Name; 12 | public int[] Tris; 13 | public int TrisCount; 14 | public List Verts; 15 | 16 | public Zone2D ToZone2D() 17 | { 18 | try { 19 | GameObject obj = new GameObject(Name); 20 | var gobj = GameObject.Instantiate(obj, Vector3.zero, Quaternion.identity) as GameObject; 21 | var zone = gobj.AddComponent(); 22 | zone.Name = Name; 23 | zone.Tris = Tris; 24 | zone.TrisCount = TrisCount; 25 | zone.Verts = Verts.Select(x => x.ToVector3()).ToList(); 26 | Util.GetInstance().zones.Add(Name, zone); 27 | return zone; 28 | } catch (Exception ex) { 29 | Logger.LogException(ex); 30 | return null; 31 | } 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Pluton/Serialize/UnityEngineExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Pluton 4 | { 5 | public static class UnityEngineExtensions 6 | { 7 | public static SerializedVector3 Serialize(this Vector3 self) 8 | { 9 | return new SerializedVector3(self); 10 | } 11 | 12 | public static SerializedQuaternion Serialize(this Quaternion self) 13 | { 14 | return new SerializedQuaternion(self); 15 | } 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Pluton/Singleton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pluton 4 | { 5 | public abstract class Singleton : CountedInstance where T : ISingleton 6 | { 7 | internal static T Instance; 8 | 9 | public static T GetInstance() 10 | { 11 | return Singleton.Instance; 12 | } 13 | 14 | static Singleton() 15 | { 16 | Singleton.Instance = Activator.CreateInstance(); 17 | if (Singleton.Instance.CheckDependencies()) 18 | Singleton.Instance.Initialize(); 19 | else 20 | UnityEngine.Debug.LogWarning(String.Format("Couldn't initialite Singleton<{0}>, is one of it's dependencies missing?", Instance.GetType())); 21 | } 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Pluton/SingletonEx.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton 2 | { 3 | public static class SingletonEx 4 | { 5 | public static bool IsInitialzed() where T : ISingleton 6 | { 7 | return Singleton.GetInstance() != null; 8 | } 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Pluton/Stopper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace Pluton 5 | { 6 | public class Stopper : CountedInstance, IDisposable 7 | { 8 | readonly string Type; 9 | readonly string Method; 10 | readonly long WarnTimeMS; 11 | readonly Stopwatch stopper; 12 | 13 | public Stopper(string type, string method, float warnSecs = 0.1f) 14 | { 15 | if (!pluton.stopper) 16 | return; 17 | Type = type; 18 | Method = method; 19 | WarnTimeMS = (long)(warnSecs * 1000); 20 | stopper = Stopwatch.StartNew(); 21 | } 22 | 23 | void IDisposable.Dispose() 24 | { 25 | if (!pluton.stopper) 26 | return; 27 | 28 | if (stopper.ElapsedMilliseconds > WarnTimeMS) { 29 | Logger.LogWarning(String.Format("[{0}.{1}] Took: {2}s ({3}ms)", 30 | Type, 31 | Method, 32 | stopper.Elapsed.Seconds, 33 | stopper.ElapsedMilliseconds 34 | )); 35 | } 36 | } 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Pluton/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace Pluton 6 | { 7 | public static class StringExtensions 8 | { 9 | public static string BoldText(this string self) 10 | { 11 | return String.Format("{0}", self); 12 | } 13 | 14 | public static string ColorText(this string self, string color) 15 | { 16 | return String.Format("{1}", color, self); 17 | } 18 | 19 | public static string ItalicText(this string self) 20 | { 21 | return String.Format("{0}", self); 22 | } 23 | 24 | public static string JsonPretty(this string self, string indent = "\t") 25 | { 26 | return String.Join(Environment.NewLine, self.yieldPretty(indent).ToArray()).TrimStart('\n', '\r', ' ', '\t').Replace(":", ": "); 27 | } 28 | 29 | static IEnumerable yieldPretty(this string json, string indent) 30 | { 31 | int depth = 0; 32 | foreach (string line in json.Replace("{", "{\n").Replace("}", "\n}").Replace(",\"", ",\n\"").Replace("[", "[\n").Replace("]", "\n]").Replace("},{", "},\n{").Replace("],[", "],\n[").Split('\n')) { 33 | if (line.Contains("}") || line.Contains("]")) 34 | depth -= 1; 35 | 36 | yield return indent.Multiply(depth) + line; 37 | 38 | if (line.Contains("{") || line.Contains("[")) 39 | depth += 1; 40 | } 41 | } 42 | 43 | public static string Multiply(this string self, int multiply) 44 | { 45 | if (multiply < 0) 46 | throw new ArgumentOutOfRangeException("multiply", multiply, $"Can't multiply a string by x{multiply}"); 47 | 48 | string result = String.Empty; 49 | for (int i = 0; i < multiply; i++) 50 | result += self; 51 | return result; 52 | } 53 | 54 | public static string SetSize(this string self, int size) 55 | { 56 | return String.Format("{1}", size, self); 57 | } 58 | 59 | public static string SetSize(this string self, string size) 60 | { 61 | return String.Format("{1}", size, self); 62 | } 63 | 64 | public static string QuoteSafe(this string self) 65 | { 66 | self = self.Replace("\"", "\\\""); 67 | self = self.TrimEnd(new char[] { '\\' }); 68 | return "\"" + self + "\""; 69 | } 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /Pluton/TimedEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Pluton 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Timers; 6 | 7 | public class TimedEvent : CountedInstance 8 | { 9 | 10 | private Dictionary _args; 11 | private readonly string _name; 12 | private readonly Timer _timer; 13 | private long lastTick; 14 | private int _elapsedCount; 15 | 16 | public delegate void TimedEventFireDelegate(TimedEvent evt); 17 | 18 | public event TimedEventFireDelegate OnFire; 19 | 20 | public TimedEvent(string name, double interval) 21 | { 22 | this._name = name; 23 | this._timer = new Timer(); 24 | this._timer.Interval = interval; 25 | this._timer.Elapsed += new ElapsedEventHandler(this._timer_Elapsed); 26 | this._elapsedCount = 0; 27 | } 28 | 29 | public TimedEvent(string name, double interval, Dictionary args) 30 | : this(name, interval) 31 | { 32 | _args = args; 33 | } 34 | 35 | private void _timer_Elapsed(object sender, ElapsedEventArgs e) 36 | { 37 | if (this.OnFire != null) { 38 | this.OnFire(this); 39 | } 40 | 41 | this._elapsedCount += 1; 42 | this.lastTick = DateTime.UtcNow.Ticks; 43 | } 44 | 45 | public void Start() 46 | { 47 | this._timer.Start(); 48 | this.lastTick = DateTime.UtcNow.Ticks; 49 | } 50 | 51 | public void Stop() 52 | { 53 | this._timer.Stop(); 54 | } 55 | 56 | public void Kill() 57 | { 58 | this._timer.Stop(); 59 | this._timer.Dispose(); 60 | } 61 | 62 | public Dictionary Args { 63 | get { return this._args; } 64 | set { this._args = value; } 65 | } 66 | 67 | public double Interval { 68 | get { return this._timer.Interval; } 69 | set { this._timer.Interval = value; } 70 | } 71 | 72 | public string Name { 73 | get { return this._name; } 74 | } 75 | 76 | public double TimeLeft { 77 | get { return (this.Interval - ((DateTime.UtcNow.Ticks - this.lastTick) / 0x2710L)); } 78 | } 79 | 80 | public int ElapsedCount { 81 | get { return this._elapsedCount; } 82 | } 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /Pluton/plugins.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace Pluton 6 | { 7 | [ConsoleSystem.Factory("plugins")] 8 | public class plugins : ConsoleSystem 9 | { 10 | [ConsoleSystem.Admin, ConsoleSystem.Help("Prints out plugin statistics!")] 11 | public static void Loaded(ConsoleSystem.Arg args) 12 | { 13 | int count = PluginLoader.GetInstance().Plugins.Count; 14 | string result = String.Format("Loaded plugins({0}):" + Environment.NewLine, count); 15 | foreach (BasePlugin plugin in PluginLoader.GetInstance().Plugins.Values) { 16 | result += String.Format(" {0, -22} [{1, -10}], timers: {2, 8}, parallel: {3, 8}\r\n", plugin.Name, plugin.Type, plugin.Timers.Count + plugin.ParallelTimers.Count, plugin.ParallelTimers.Count); 17 | result += String.Format("Author: {0}, about: {1}, version: {2}" + Environment.NewLine + Environment.NewLine, plugin.Author, plugin.About, plugin.Version); 18 | } 19 | args.ReplyWith(result); 20 | } 21 | 22 | [ConsoleSystem.Admin, ConsoleSystem.Help("Prints out hooks statistics!")] 23 | public static void Hooks(ConsoleSystem.Arg args) 24 | { 25 | Dictionary> hooks = new Dictionary>(); 26 | PluginLoader.GetInstance().Plugins.Values.ToList().ForEach( 27 | p => p.Globals.ToList().ForEach( 28 | g => { 29 | if (g.StartsWith("On_")) 30 | AddPluginToHookListInDict(hooks, g, p.Name); 31 | })); 32 | 33 | string result = "The registered hooks are:" + Environment.NewLine; 34 | 35 | hooks.Keys.ToList().ForEach(k => { 36 | result += k + ": " + String.Join(", ", hooks[k].ToArray()) + Environment.NewLine; 37 | }); 38 | 39 | args.ReplyWith(result); 40 | } 41 | 42 | private static void AddPluginToHookListInDict(Dictionary> hooks, string key, string value) 43 | { 44 | if (hooks.ContainsKey(key)) 45 | hooks[key].Add(value); 46 | else 47 | hooks.Add(key, new List() { value } ); 48 | } 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /Pluton/ref/IronPython.Deps.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton/ref/IronPython.Deps.dll -------------------------------------------------------------------------------- /Pluton/ref/Jint.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton/ref/Jint.dll -------------------------------------------------------------------------------- /Pluton/ref/Mono.Cecil.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton/ref/Mono.Cecil.dll -------------------------------------------------------------------------------- /Pluton/ref/MoonSharp.Interpreter.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton/ref/MoonSharp.Interpreter.dll -------------------------------------------------------------------------------- /Pluton/ref/System.Reactive.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton/ref/System.Reactive.dll -------------------------------------------------------------------------------- /Pluton/ref/System.Threading.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton/ref/System.Threading.dll -------------------------------------------------------------------------------- /Pluton/ref/mcs.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Notulp/Pluton/7391a08d43d70efa81d68a71b41eb240b9304f9b/Pluton/ref/mcs.exe -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Pluton Icon 2 | 3 | Pluton 4 | ====== 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Pluton is a server mod for the active branch of the survival sandbox game Rust. By using our simple API, you can to easily change the gameplay drastically. 25 | 26 | * [Homepage](http://pluton.team) 27 | * [Forum](http://forum.pluton.team) 28 | * [Wiki](http://forum.pluton.team/wiki/index/) 29 | * [Binaries](http://dl.pluton.team) 30 | * [Compiling](http://forum.pluton.team/wiki/compiling/) 31 | * [FAQ](http://forum.pluton.team/wiki/faq/) 32 | 33 | 34 | Our sponsors: 35 | ------------ 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /ref/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | 3 | !.gitignore 4 | !Put here rust dlls.txt -------------------------------------------------------------------------------- /ref/Put here rust dlls.txt: -------------------------------------------------------------------------------- 1 | Assembly-CSharp.dll 2 | Assembly-CSharp-firstpass.dll 3 | Facepunch.Network.dll 4 | Facepunch.System.dll 5 | Facepunch.UnityEngine.dll 6 | Rust.Data.dll 7 | UnityEngine.dll --------------------------------------------------------------------------------