├── .gitignore ├── 3rdPartyLicenses ├── CODE_OF_CONDUCT.md ├── Images └── PB_logo.ico ├── LICENSE ├── Libraries ├── I18N.West.dll ├── I18N.dll ├── Newtonsoft.Json.dll └── UnityEngine.dll ├── PointBlank.sln ├── PointBlank ├── API │ ├── Collections │ │ ├── ConfigurationList.cs │ │ └── TranslationList.cs │ ├── Commands │ │ ├── EAllowedCaller.cs │ │ ├── EAllowedServerState.cs │ │ ├── ECommandRunError.cs │ │ ├── PointBlankCommand.cs │ │ ├── PointBlankCommandEvents.cs │ │ └── PointBlankCommandManager.cs │ ├── DataManagment │ │ ├── ConfData.cs │ │ ├── EDataType.cs │ │ ├── ESQLDataType.cs │ │ ├── JsonData.cs │ │ ├── SQLData.cs │ │ ├── UniversalData.cs │ │ ├── WebsiteData.cs │ │ └── XMLData.cs │ ├── Detour │ │ ├── DetourAttribute.cs │ │ └── DetourManager.cs │ ├── Discord │ │ ├── DiscordAPI.cs │ │ ├── DiscordClient.cs │ │ ├── DiscordWebhook.cs │ │ ├── EDiscordHttpCodes.cs │ │ └── EDiscordJsonCodes.cs │ ├── Extension │ │ └── PointBlankExtensionAttribute.cs │ ├── Groups │ │ ├── PointBlankGroup.cs │ │ ├── PointBlankGroupEvents.cs │ │ └── PointBlankGroupManager.cs │ ├── IPC │ │ ├── EIPCType.cs │ │ ├── IPCEvents.cs │ │ └── IPCManager.cs │ ├── Implements │ │ ├── NetFramework.cs │ │ ├── PointBlank.cs │ │ └── UnityEngine.cs │ ├── Interfaces │ │ ├── IConfigurable.cs │ │ └── ITranslatable.cs │ ├── Player │ │ ├── PointBlankPlayer.cs │ │ ├── PointBlankPlayerComponent.cs │ │ └── PointBlankPlayerEvents.cs │ ├── Plugins │ │ ├── PointBlankPlugin.cs │ │ ├── PointBlankPluginEvents.cs │ │ └── PointBlankPluginManager.cs │ ├── PointBlankConsole.cs │ ├── PointBlankLogging.cs │ ├── PointBlankReflect.cs │ ├── PointBlankTools.cs │ ├── Server │ │ └── PointBlankServer.cs │ ├── Services │ │ ├── PointBlankService.cs │ │ ├── PointBlankServiceEvents.cs │ │ └── PointBlankServiceManager.cs │ ├── Storage │ │ ├── Compressions │ │ │ ├── GZip.cs │ │ │ └── Huffman.cs │ │ ├── ECompression.cs │ │ └── PointBlankStorage.cs │ └── Tasks │ │ └── PointBlankTask.cs ├── Enviroment.cs ├── Framework │ ├── Configurations │ │ └── PointBlankConfigurations.cs │ ├── InterfaceManager.cs │ ├── Objects │ │ └── RuntimeObject.cs │ ├── Permissions │ │ └── Ring │ │ │ ├── RingPermission.cs │ │ │ ├── RingPermissionAttribute.cs │ │ │ └── RingPermissionRing.cs │ ├── ServiceManager.cs │ ├── Translations │ │ └── ServiceTranslations.cs │ └── Wrappers │ │ └── ServiceWrapper.cs ├── PointBlank.cs ├── PointBlank.csproj ├── PointBlank.csproj.DotSettings ├── PointBlankInfo.cs ├── Properties │ └── AssemblyInfo.cs └── Services │ ├── CommandManager │ ├── CommandManager.cs │ └── CommandWrapper.cs │ ├── DetourManager │ ├── DetourManager.cs │ ├── DetourWrapper.cs │ └── RedirectionHelper.cs │ ├── GroupManager │ └── GroupManager.cs │ ├── IPCManager │ └── IPCManager.cs │ ├── PluginManager │ ├── PluginConfiguration.cs │ ├── PluginManager.cs │ └── PluginWrapper.cs │ ├── TaskManager │ └── TaskManager.cs │ └── UpdateChecker │ └── UpdateChecker.cs ├── PointBlankSecurity ├── API │ ├── License │ │ └── LicenseVerifier.cs │ └── Security │ │ ├── EHashType.cs │ │ └── Hashing.cs ├── PointBlankSecurity.csproj └── Properties │ └── AssemblyInfo.cs └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs -------------------------------------------------------------------------------- /3rdPartyLicenses: -------------------------------------------------------------------------------- 1 | PointBlank uses 3rd party software and API in order to keep functionality. 2 | The required legal notices of the used codes are reproduced below as we are obligated to provide such notices: 3 | 4 | - Steamworks.NET: 5 | ############################################################################################################### 6 | Copyright (c) 2015 Riley Labrecque 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | ############################################################################################################### 26 | 27 | -Json.NET: 28 | ############################################################################################################### 29 | Copyright (c) 2007 James Newton-King 30 | 31 | Permission is hereby granted, free of charge, to any person obtaining a copy of this 32 | software and associated documentation files (the "Software"), to deal in the Software 33 | without restriction, including without limitation the rights to use, copy, modify, 34 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 35 | permit persons to whom the Software is furnished to do so, subject to the following 36 | conditions: 37 | 38 | The above copyright notice and this permission notice shall be included in all copies 39 | or substantial portions of the Software. 40 | 41 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 42 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 43 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 44 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 45 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 46 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 47 | ############################################################################################################### 48 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at eliteinfinity1337@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /Images/PB_logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PointBlankMod/PointBlank/6bada801330bb6fb5808981b608096f8a9b79dcc/Images/PB_logo.ico -------------------------------------------------------------------------------- /Libraries/I18N.West.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PointBlankMod/PointBlank/6bada801330bb6fb5808981b608096f8a9b79dcc/Libraries/I18N.West.dll -------------------------------------------------------------------------------- /Libraries/I18N.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PointBlankMod/PointBlank/6bada801330bb6fb5808981b608096f8a9b79dcc/Libraries/I18N.dll -------------------------------------------------------------------------------- /Libraries/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PointBlankMod/PointBlank/6bada801330bb6fb5808981b608096f8a9b79dcc/Libraries/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /Libraries/UnityEngine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PointBlankMod/PointBlank/6bada801330bb6fb5808981b608096f8a9b79dcc/Libraries/UnityEngine.dll -------------------------------------------------------------------------------- /PointBlank.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26430.16 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PointBlank", "PointBlank\PointBlank.csproj", "{1C15ECF9-39AF-4D7E-9493-47FF754514BA}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PointBlankSecurity", "PointBlankSecurity\PointBlankSecurity.csproj", "{1D66EA7A-036C-4C75-AF4A-1D89F7DE91A4}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1C15ECF9-39AF-4D7E-9493-47FF754514BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {1C15ECF9-39AF-4D7E-9493-47FF754514BA}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {1C15ECF9-39AF-4D7E-9493-47FF754514BA}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {1C15ECF9-39AF-4D7E-9493-47FF754514BA}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {1D66EA7A-036C-4C75-AF4A-1D89F7DE91A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {1D66EA7A-036C-4C75-AF4A-1D89F7DE91A4}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {1D66EA7A-036C-4C75-AF4A-1D89F7DE91A4}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {1D66EA7A-036C-4C75-AF4A-1D89F7DE91A4}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /PointBlank/API/Collections/TranslationList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Reflection; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Security.Permissions; 9 | using PointBlank.Framework.Permissions.Ring; 10 | 11 | namespace PointBlank.API.Collections 12 | { 13 | /// 14 | /// Custom collection for tranlsations 15 | /// 16 | [RingPermission(SecurityAction.Demand, ring = RingPermissionRing.None)] 17 | public class TranslationList : ICollection 18 | { 19 | #region Properties 20 | /// 21 | /// The list of transaltions 22 | /// 23 | protected Dictionary Translations { get; private set; } 24 | 25 | /// 26 | /// Gets/Sets the translation text using the key provided 27 | /// 28 | /// The key to find the translation 29 | /// The translation text 30 | public string this[string key] 31 | { 32 | get => Translations[key]; 33 | set => Translations[key] = value; 34 | } 35 | 36 | /// 37 | /// Gets/Sets the translation KeyValuePair using the index provided 38 | /// 39 | /// The index to find the translation 40 | /// The translation KeyValuePair 41 | public KeyValuePair this[int index] 42 | { 43 | get => Translations.ElementAt(index); 44 | set => Translations[Translations.ElementAt(index).Key] = value.Value; 45 | } 46 | 47 | /// 48 | /// Returns the amount of items in the translation list 49 | /// 50 | public int Count => Translations.Count; 51 | 52 | public object SyncRoot => throw new NotImplementedException(); 53 | 54 | public bool IsSynchronized => throw new NotImplementedException(); 55 | #endregion 56 | 57 | /// 58 | /// Custom collection for tranlsations 59 | /// 60 | public TranslationList() 61 | { 62 | StackTrace stack = new StackTrace(false); 63 | if (stack.FrameCount <= 0) 64 | { 65 | Translations = new Dictionary(); 66 | return; 67 | } 68 | MethodBase jumpMethod = stack.GetFrame(1).GetMethod(); 69 | 70 | if (!Memory.TranslationCollection.ContainsKey(jumpMethod)) 71 | { 72 | Translations = new Dictionary(); 73 | Memory.TranslationCollection.Add(jumpMethod, this); 74 | return; 75 | } 76 | Translations = Memory.TranslationCollection[jumpMethod].Translations; 77 | } 78 | 79 | #region Collection Functions 80 | /// 81 | /// Adds a translation entry using the key and value 82 | /// 83 | /// Key to save it as 84 | /// Value of the text 85 | public void Add(string key, string value) 86 | { 87 | if (!Translations.ContainsKey(key)) 88 | Translations.Add(key, value); 89 | } 90 | /// 91 | /// Adds a translation entry using the KeyValuePair 92 | /// 93 | /// The KeyValuePair to extract the data from 94 | public void Add(KeyValuePair kvp) => this.Add(kvp.Key, kvp.Value); 95 | 96 | /// 97 | /// Removes a translation entry using the key 98 | /// 99 | /// Key of translation entry 100 | public void Remove(string key) 101 | { 102 | if (Translations.ContainsKey(key)) 103 | Translations.Remove(key); 104 | } 105 | /// 106 | /// Removes a translation entry using the index 107 | /// 108 | /// Index of the entry 109 | public void RemoveAt(int index) => this.Remove(this[index].Key); 110 | 111 | /// 112 | /// Adds a range of translations using the KeyValuePair list 113 | /// 114 | /// The list of translations to add 115 | public void AddRange(IEnumerable> list) 116 | { 117 | foreach (KeyValuePair x in list) 118 | this.Add(x.Key, x.Value); 119 | } 120 | /// 121 | /// Adds a range of translations using the Translation list 122 | /// 123 | /// The list of translations to add 124 | public void AddRange(TranslationList list) 125 | { 126 | for (int i = 0; i < list.Count; i++) 127 | this.Add(list[i]); 128 | } 129 | 130 | /// 131 | /// Does the translation key exist 132 | /// 133 | /// The key of the translation 134 | /// If the translation key exists 135 | public bool ContainsKey(string key) => Translations.ContainsKey(key); 136 | 137 | /// 138 | /// Gets the enumerator and returns it 139 | /// 140 | /// Enumerator for translation list 141 | IEnumerator IEnumerable.GetEnumerator() => Translations.GetEnumerator(); 142 | 143 | /// 144 | /// Copies the KeyValuePairs to the array 145 | /// 146 | /// Copy destination 147 | /// Start from index 148 | public void CopyTo(Array array, int index) 149 | { 150 | for (int i = 0; i < (this.Count - index); i++) 151 | array.SetValue(this[index + i], i); 152 | } 153 | #endregion 154 | 155 | #region SubClasses 156 | private static class Memory 157 | { 158 | public static Dictionary TranslationCollection = new Dictionary(); 159 | } 160 | #endregion 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /PointBlank/API/Commands/EAllowedCaller.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Commands 7 | { 8 | /// 9 | /// The allowed caller 10 | /// 11 | public enum EAllowedCaller 12 | { 13 | SERVER, 14 | PLAYER, 15 | BOTH 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /PointBlank/API/Commands/EAllowedServerState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Commands 7 | { 8 | /// 9 | /// The server state 10 | /// 11 | public enum EAllowedServerState 12 | { 13 | RUNNING, 14 | LOADING, 15 | BOTH 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /PointBlank/API/Commands/ECommandRunError.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Commands 7 | { 8 | /// 9 | /// Error codes for executing a command 10 | /// 11 | public enum ECommandRunError 12 | { 13 | NONE, 14 | COMMAND_NOT_EXIST, 15 | NO_PERMISSION, 16 | SERVER_RUNNING, 17 | SERVER_LOADING, 18 | NOT_CONSOLE, 19 | NOT_PLAYER, 20 | ARGUMENT_COUNT, 21 | COOLDOWN, 22 | NO_EXECUTE, 23 | EXCEPTION 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /PointBlank/API/Commands/PointBlankCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.API.Plugins; 6 | using PointBlank.API.Player; 7 | using CM = PointBlank.Services.CommandManager.CommandManager; 8 | 9 | namespace PointBlank.API.Commands 10 | { 11 | /// 12 | /// Custom command class 13 | /// 14 | public abstract class PointBlankCommand 15 | { 16 | #region Properties 17 | /// 18 | /// The command instance 19 | /// 20 | public static PointBlankCommand Instance { get; internal set; } 21 | 22 | /// 23 | /// The commands used to execute this command 24 | /// 25 | public string[] Commands => CM.Commands.FirstOrDefault(a => a.CommandClass == this).Commands; 26 | 27 | /// 28 | /// The permissions needed to execute the command 29 | /// 30 | public string Permission => CM.Commands.FirstOrDefault(a => a.CommandClass == this).Permission; 31 | 32 | /// 33 | /// The cooldown needed to execute the command 34 | /// 35 | public int Cooldown => CM.Commands.FirstOrDefault(a => a.CommandClass == this).Cooldown; 36 | 37 | /// 38 | /// Is the command enabled 39 | /// 40 | public bool Enabled => CM.Commands.FirstOrDefault(a => a.CommandClass == this).Enabled; 41 | #endregion 42 | 43 | #region Abstract Properties 44 | /// 45 | /// If the player types any of the commands into the console it will run this command 46 | /// 47 | public abstract string[] DefaultCommands { get; } 48 | 49 | /// 50 | /// The translation key for the command help message 51 | /// 52 | public abstract string Help { get; } 53 | 54 | /// 55 | /// The translation key for the command usage message 56 | /// 57 | public abstract string Usage { get; } 58 | 59 | /// 60 | /// The permission needed to run the command 61 | /// 62 | public abstract string DefaultPermission { get; } 63 | #endregion 64 | 65 | #region Virtual Properties 66 | /// 67 | /// The minimum amount of parameters required for the command 68 | /// 69 | public virtual int MinimumParams => 0; 70 | 71 | /// 72 | /// The default cooldown(-1 to not override cooldown) 73 | /// 74 | public virtual int DefaultCooldown => -1; 75 | 76 | /// 77 | /// At what state is the command allowed to be executed 78 | /// 79 | public virtual EAllowedServerState AllowedServerState => EAllowedServerState.BOTH; 80 | 81 | /// 82 | /// Who can execute the command 83 | /// 84 | public virtual EAllowedCaller AllowedCaller => EAllowedCaller.BOTH; 85 | #endregion 86 | 87 | #region Abstract Functions 88 | /// 89 | /// Called when the player executes the command 90 | /// 91 | /// The arguments the player inputted 92 | /// The player executing the command 93 | public abstract void Execute(PointBlankPlayer executor, string[] args); 94 | #endregion 95 | 96 | public PointBlankCommand() 97 | { 98 | Instance = this; 99 | } 100 | 101 | #region Functions 102 | /// 103 | /// Translates a key and data to text depending on the translation 104 | /// 105 | /// The key of the translation 106 | /// The data to modify the translation 107 | /// The translated text 108 | public string Translate(string key, params object[] data) => PointBlankPlugin.GetInstance(this).Translate(key, data); 109 | 110 | /// 111 | /// Easy to use configuration value extractor 112 | /// 113 | /// The configuration value type 114 | /// The key of the configuration value 115 | /// The configuration value with specified type 116 | public T Configure(string key) => PointBlankPlugin.GetInstance(this).Configure(key); 117 | #endregion 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /PointBlank/API/Commands/PointBlankCommandEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Commands 7 | { 8 | /// 9 | /// Class for command events 10 | /// 11 | public static class PointBlankCommandEvents 12 | { 13 | #region Handlers 14 | /// 15 | /// Handler for command enable/disable 16 | /// 17 | /// The affected command 18 | public delegate void CommandStatusChangedHandler(PointBlankCommand command); 19 | 20 | /// 21 | /// Handler for command calls 22 | /// 23 | /// The affected command 24 | /// The arguments passed 25 | /// Should the command be executed 26 | /// The user that executed the command(null if it was the server) 27 | public delegate void CommandCalledHandler(PointBlankCommand command, string[] args, Player.PointBlankPlayer executor, ref bool allowExecute); 28 | #endregion 29 | 30 | #region Events 31 | /// 32 | /// Called when a command is enabled 33 | /// 34 | public static event CommandStatusChangedHandler OnCommandEnabled; 35 | /// 36 | /// Called when a command is disabled 37 | /// 38 | public static event CommandStatusChangedHandler OnCommandDisabled; 39 | 40 | /// 41 | /// Called when a command is executed 42 | /// 43 | public static event CommandCalledHandler OnCommandExecuted; 44 | #endregion 45 | 46 | #region Functions 47 | internal static void RunCommandEnable(PointBlankCommand command) 48 | { 49 | OnCommandEnabled?.Invoke(command); 50 | } 51 | internal static void RunCommandDisable(PointBlankCommand command) 52 | { 53 | OnCommandDisabled?.Invoke(command); 54 | } 55 | 56 | internal static void RunCommandExecute(PointBlankCommand command, string[] args, Player.PointBlankPlayer executor, ref bool allowExecute) 57 | { 58 | OnCommandExecuted?.Invoke(command, args, executor, ref allowExecute); 59 | } 60 | #endregion 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /PointBlank/API/Commands/PointBlankCommandManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.Services.CommandManager; 6 | using CM = PointBlank.Services.CommandManager.CommandManager; 7 | 8 | namespace PointBlank.API.Commands 9 | { 10 | /// 11 | /// All functions for managing commands 12 | /// 13 | public static class PointBlankCommandManager 14 | { 15 | #region Properties 16 | /// 17 | /// List of commands 18 | /// 19 | public static PointBlankCommand[] Commands => CM.Commands.Select(a => a.CommandClass).ToArray(); 20 | #endregion 21 | 22 | #region Functions 23 | /// 24 | /// Gets a command using a class 25 | /// 26 | /// The class to get the command with 27 | /// The command 28 | public static T GetCommand() where T : PointBlankCommand => (T)Commands.FirstOrDefault(a => a.GetType() == typeof(T)); 29 | 30 | /// 31 | /// Gets a command based on type 32 | /// 33 | /// The type to find the command by 34 | /// The command 35 | public static PointBlankCommand GetCommand(Type Class) => Commands.FirstOrDefault(a => a.GetType() == Class); 36 | 37 | /// 38 | /// Enables a command 39 | /// 40 | /// The command to enable 41 | public static void EnableCommand(PointBlankCommand command) 42 | { 43 | CommandWrapper wrapper = CM.Commands.FirstOrDefault(a => a.CommandClass == command); 44 | 45 | wrapper?.Enable(); 46 | } 47 | 48 | /// 49 | /// Disables a command 50 | /// 51 | /// The command to disable 52 | public static void DisableCommand(PointBlankCommand command) 53 | { 54 | CommandWrapper wrapper = CM.Commands.FirstOrDefault(a => a.CommandClass == command); 55 | 56 | wrapper?.Disable(); 57 | } 58 | 59 | /// 60 | /// Emulates command execution 61 | /// 62 | /// The command to execute 63 | public static ECommandRunError ExecuteCommand(string command, Player.PointBlankPlayer executor) 64 | { 65 | CM cmd = (CM)Enviroment.services["CommandManager.CommandManager"].ServiceClass; 66 | 67 | return cmd.ExecuteCommand(command, executor); 68 | } 69 | #endregion 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /PointBlank/API/DataManagment/EDataType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Security.Permissions; 6 | using PointBlank.Framework.Permissions.Ring; 7 | 8 | namespace PointBlank.API.DataManagment 9 | { 10 | [RingPermission(SecurityAction.Demand, ring = RingPermissionRing.None)] 11 | public enum EDataType 12 | { 13 | JSON, 14 | XML, 15 | //CONF, // Not done yet 16 | UNKNOWN 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /PointBlank/API/DataManagment/ESQLDataType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Security.Permissions; 6 | using PointBlank.Framework.Permissions.Ring; 7 | 8 | namespace PointBlank.API.DataManagment 9 | { 10 | [RingPermission(SecurityAction.Demand, ring = RingPermissionRing.None)] 11 | public enum ESQLDataType 12 | { 13 | INT, 14 | TINYINT, 15 | SMALLINT, 16 | MEDIUMINT, 17 | BIGINT, 18 | FLOAT_10_2, 19 | FLOAT_10_10, 20 | FLOAT_10_20, 21 | FLOAT_10_24, 22 | FLOAT_32_2, 23 | FLOAT_32_10, 24 | FLOAT_32_20, 25 | FLOAT_32_24, 26 | FLOAT_64_2, 27 | FLOAT_64_10, 28 | FLOAT_64_20, 29 | FLOAT_64_24, 30 | FLOAT_128_2, 31 | FLOAT_128_10, 32 | FLOAT_128_20, 33 | FLOAT_128_24, 34 | FLOAT_255_2, 35 | FLOAT_255_10, 36 | FLOAT_255_20, 37 | FLOAT_255_24, 38 | DOUBLE_16_4, 39 | DOUBLE_16_10, 40 | DOUBLE_16_20, 41 | DOUBLE_16_30, 42 | DOUBLE_16_40, 43 | DOUBLE_16_50, 44 | DOUBLE_16_53, 45 | DOUBLE_32_4, 46 | DOUBLE_32_10, 47 | DOUBLE_32_20, 48 | DOUBLE_32_30, 49 | DOUBLE_32_40, 50 | DOUBLE_32_50, 51 | DOUBLE_32_53, 52 | DOUBLE_64_4, 53 | DOUBLE_64_10, 54 | DOUBLE_64_20, 55 | DOUBLE_64_30, 56 | DOUBLE_64_40, 57 | DOUBLE_64_50, 58 | DOUBLE_64_53, 59 | DOUBLE_128_4, 60 | DOUBLE_128_10, 61 | DOUBLE_128_20, 62 | DOUBLE_128_30, 63 | DOUBLE_128_40, 64 | DOUBLE_128_50, 65 | DOUBLE_128_53, 66 | DOUBLE_255_4, 67 | DOUBLE_255_10, 68 | DOUBLE_255_20, 69 | DOUBLE_255_30, 70 | DOUBLE_255_40, 71 | DOUBLE_255_50, 72 | DOUBLE_255_53, 73 | DECIMAL_16_16, 74 | DECIMAL_16_32, 75 | DECIMAL_16_64, 76 | DECIMAL_16_128, 77 | DECIMAL_16_255, 78 | DECIMAL_32_16, 79 | DECIMAL_32_32, 80 | DECIMAL_32_64, 81 | DECIMAL_32_128, 82 | DECIMAL_32_255, 83 | DECIMAL_64_16, 84 | DECIMAL_64_32, 85 | DECIMAL_64_64, 86 | DECIMAL_64_128, 87 | DECIMAL_64_255, 88 | DECIMAL_128_16, 89 | DECIMAL_128_32, 90 | DECIMAL_128_64, 91 | DECIMAL_128_128, 92 | DECIMAL_128_255, 93 | DECIMAL_255_16, 94 | DECIMAL_255_32, 95 | DECIMAL_255_64, 96 | DECIMAL_255_128, 97 | DECIMAL_255_255, 98 | DATE, 99 | DATETIME, 100 | TIMESTAMP, 101 | TIME, 102 | CHAR_16, 103 | CHAR_32, 104 | CHAR_64, 105 | CHAR_128, 106 | CHAR_255, 107 | VARCHAR_16, 108 | VARCHAR_32, 109 | VARCHAR_64, 110 | VARCHAR_128, 111 | VARCHAR_255, 112 | TEXT, 113 | TINYTEXT, 114 | MEDIUMTEXT, 115 | LONGTEXT, 116 | ENUM 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /PointBlank/API/DataManagment/JsonData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Collections.Generic; 4 | using System.Security.Permissions; 5 | using System.Linq; 6 | using System.Text; 7 | using Newtonsoft.Json; 8 | using Newtonsoft.Json.Linq; 9 | using PointBlank.Framework.Permissions.Ring; 10 | 11 | namespace PointBlank.API.DataManagment 12 | { 13 | /// 14 | /// JSON data managment 15 | /// 16 | [RingPermission(SecurityAction.Demand, ring = RingPermissionRing.None)] 17 | public class JsonData 18 | { 19 | #region Properties 20 | /// 21 | /// Path to JSON file 22 | /// 23 | public string Path { get; private set; } 24 | /// 25 | /// JSON document 26 | /// 27 | public JObject Document { get; private set; } 28 | /// 29 | /// The XML document root node 30 | /// 31 | //public JArray RootNode { get; private set; } 32 | 33 | /// 34 | /// Was the JSON just created 35 | /// 36 | public bool CreatedNew { get; private set; } 37 | #endregion 38 | 39 | /// 40 | /// JSON data managment 41 | /// 42 | /// The path to json file 43 | internal JsonData(string path) 44 | { 45 | this.Path = path; // Set the path 46 | this.CreatedNew = !File.Exists(path); // Check if we have to create the file 47 | 48 | Reload(); // Run the reload 49 | } 50 | 51 | /// 52 | /// JSON data managment 53 | /// 54 | /// The json document 55 | internal JsonData(JObject doc, string path) 56 | { 57 | this.Path = path; // Set the path 58 | this.CreatedNew = !File.Exists(path); // Check if we have to create the file 59 | this.Document = doc; // Set the doc 60 | } 61 | 62 | #region Static Functions 63 | /// 64 | /// Checks if the file is JSON 65 | /// 66 | /// The path to the file 67 | /// If the file is JSON 68 | public static bool CheckFile(string filepath) 69 | { 70 | if (!File.Exists(filepath)) 71 | return false; 72 | 73 | try 74 | { 75 | JObject.Parse(File.ReadAllText(filepath)); // Try to parse 76 | 77 | return true; // Parse successful, file valid 78 | } 79 | #pragma warning disable CS0168 // Variable is declared but never used 80 | catch (Exception ex) 81 | #pragma warning restore CS0168 // Variable is declared but never used 82 | { 83 | return false; // Failed to validate 84 | } 85 | } 86 | 87 | /// 88 | /// Serializes a class instance into a JSON 89 | /// 90 | /// The instance of the class 91 | /// The JSON string 92 | public static string Serialize(object instance) => JsonConvert.SerializeObject(instance); // Serialize the object 93 | 94 | /// 95 | /// Serializes a class into a JSON 96 | /// 97 | /// The class to serialize 98 | /// The JSON string 99 | public static string Serialize() 100 | { 101 | return JsonConvert.SerializeObject(Activator.CreateInstance()); // Instentate the class and serialize the instance 102 | } 103 | 104 | /// 105 | /// Deserializes JSON into an instance of a class 106 | /// 107 | /// The JSON 108 | /// The type to deserialize to 109 | /// Instance of the deserialized file 110 | public static object Deserialize(string json, Type type) => JsonConvert.DeserializeObject(json, type); // Deserialize the file 111 | 112 | /// 113 | /// Deserialize JSON into an instance of a class 114 | /// 115 | /// The class 116 | /// The JSON 117 | /// Instance of the class deserialized from JSON 118 | public static T Deserialize(string json) => JsonConvert.DeserializeObject(json); // Deserialize the JSON 119 | #endregion 120 | 121 | #region Public Functions 122 | /// 123 | /// Reloads the JSON file 124 | /// 125 | public void Reload() => Document = CreatedNew ? new JObject() : JObject.Parse(File.ReadAllText(Path)); 126 | 127 | /// 128 | /// Saves the JSON file 129 | /// 130 | internal void Save() => File.WriteAllText(Path, Document.ToString(Formatting.Indented)); // Write the file 131 | 132 | /// 133 | /// Verifies the document and adds missing information specified in information 134 | /// 135 | /// The information to check from 136 | public void Verify(Dictionary information) 137 | { 138 | foreach(string key in information.Keys) 139 | if (!CheckKey(key)) 140 | Document.Add(key, information[key]); 141 | } 142 | 143 | /// 144 | /// Adds a name + value to an array 145 | /// 146 | /// The array to add to 147 | /// The name/key 148 | /// The value 149 | public void AddToArray(JArray array, string name, object value) 150 | { 151 | array.Add(new JObject( 152 | new JProperty(name, value) 153 | )); 154 | } 155 | 156 | /// 157 | /// Checks if the key exists in the document 158 | /// 159 | /// The key you want to check 160 | /// If it exists in the document 161 | public bool CheckKey(string key) => (Document[key] != null && Document[key].Type != JTokenType.Null); 162 | #endregion 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /PointBlank/API/DataManagment/UniversalData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Security.Permissions; 7 | using PointBlank.Framework.Permissions.Ring; 8 | using Newtonsoft.Json; 9 | using Newtonsoft.Json.Linq; 10 | using PointBlank.API; 11 | using PointBlank.Framework; 12 | using PT = System.IO.Path; 13 | 14 | namespace PointBlank.API.DataManagment 15 | { 16 | /// 17 | /// Universal data managment 18 | /// 19 | [RingPermission(SecurityAction.Demand, ring = RingPermissionRing.None)] 20 | public class UniversalData 21 | { 22 | #region Properties 23 | /// 24 | /// The path to the file(if linked to file) 25 | /// 26 | public string Path { get; private set; } 27 | /// 28 | /// The type of data that was inputted(SQL, XML, JSON) 29 | /// 30 | public EDataType DataType { get; private set; } 31 | 32 | /// 33 | /// The XML data(if the file is a XML) 34 | /// 35 | public XMLData XML { get; private set; } 36 | /// 37 | /// The JSON data(if the file is a JSON) 38 | /// 39 | public JsonData JSON { get; private set; } 40 | /// 41 | /// The CONF data(if the file is a CONF) 42 | /// 43 | //public ConfData CONF { get; private set; } 44 | 45 | /// 46 | /// Check if a new file was created 47 | /// 48 | public bool CreatedNew { get; private set; } 49 | #endregion 50 | 51 | /// 52 | /// Universal data managment 53 | /// 54 | /// The path to the data file 55 | public UniversalData(string path, EDataType DefaultDataType = EDataType.JSON) 56 | { 57 | this.Path = path + ".dat"; // Set the path 58 | this.CreatedNew = !File.Exists(Path); // Check if the file has to be created 59 | 60 | if (!Directory.Exists(PT.GetDirectoryName(Path))) 61 | Directory.CreateDirectory(PT.GetDirectoryName(Path)); 62 | if (CreatedNew) 63 | { 64 | DataType = DefaultDataType; // Set the data type 65 | 66 | switch (DefaultDataType) 67 | { 68 | case EDataType.JSON: 69 | JSON = new JsonData(Path); // Create the JSON file 70 | break; 71 | case EDataType.XML: 72 | XML = new XMLData(Path); // Create the XML file 73 | break; 74 | } 75 | 76 | return; // No need to continue 77 | } 78 | 79 | if (XMLData.CheckFile(Path)) 80 | { 81 | DataType = EDataType.XML; // An XML file 82 | XML = new XMLData(Path); 83 | } 84 | else if (JsonData.CheckFile(Path)) 85 | { 86 | DataType = EDataType.JSON; // A JSON file 87 | JSON = new JsonData(Path); 88 | } 89 | else 90 | { 91 | DataType = EDataType.UNKNOWN; // Unknown type/corrupted file 92 | } 93 | } 94 | 95 | #region Public Functions 96 | /// 97 | /// Gets the data in the format of your choosing 98 | /// 99 | /// The format of the data 100 | /// The data in the format you chose 101 | public object GetData(EDataType ExtractType) 102 | { 103 | if (DataType == EDataType.UNKNOWN || ExtractType == EDataType.UNKNOWN) // Unknown data type error 104 | return null; 105 | 106 | switch (DataType) 107 | { 108 | case EDataType.JSON: 109 | if (ExtractType == EDataType.XML) 110 | return JSONToXML(); // Convert the JSON to XML 111 | return JSON; // Return the JSON 112 | case EDataType.XML: 113 | if (ExtractType == EDataType.JSON) 114 | return XMLToJSON(); // Convert the XML to JSON 115 | return XML; // Return the XML 116 | } 117 | 118 | return null; 119 | } 120 | 121 | /// 122 | /// Saves the data depending on the format the server chose 123 | /// 124 | public void Save() 125 | { 126 | /*switch ((EDataType)Enviroment.FrameworkConfig[typeof(PointBlank)].Configurations["ConfigFormat"]) 127 | { 128 | case EDataType.JSON: 129 | if (DataType == EDataType.XML || XML != null) 130 | XMLToJSON(); // Convert to JSON 131 | 132 | JSON.Save(); // Save the JSON 133 | break; 134 | case EDataType.XML: 135 | if (DataType == EDataType.JSON || JSON != null) 136 | JSONToXML(); // Convert to XML 137 | 138 | XML.Save(); // Save the XML 139 | break; 140 | }*/ 141 | JSON.Save(); 142 | } 143 | #endregion 144 | 145 | #region Converter Functions 146 | private XMLData JSONToXML() 147 | { 148 | XMLData tmpXML = new XMLData(JsonConvert.DeserializeXmlNode(JSON.Document.ToString(), "Data"), Path); // Deserialize the JSON to XML 149 | 150 | if(XML == null) 151 | { 152 | XML = tmpXML; // If the XML is null just set the tmpXML to it 153 | return XML; 154 | } 155 | 156 | XML.Merge(tmpXML.Document); // Merge the XMLs 157 | 158 | return XML; 159 | } 160 | 161 | private JsonData XMLToJSON() 162 | { 163 | string sJson = JsonConvert.SerializeXmlNode(XML.Document, Formatting.None, true); // Deserialize the XML to JSON 164 | JsonData tmpJSON = null; 165 | 166 | if (!string.IsNullOrEmpty(sJson) && sJson != "null") 167 | tmpJSON = new JsonData(JObject.Parse(sJson), Path); // Parse the JSON 168 | else 169 | tmpJSON = new JsonData(Path); // Create a new JSON 170 | if(JSON == null) 171 | { 172 | JSON = tmpJSON; // If the JSON is null just set the tmpJSON to it 173 | return JSON; 174 | } 175 | 176 | JSON.Document.Merge(tmpJSON); // Merge both JSONs 177 | 178 | return JSON; 179 | } 180 | #endregion 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /PointBlank/API/Detour/DetourAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace PointBlank.API.Detour 8 | { 9 | /// 10 | /// Used to detour a specific function 11 | /// 12 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 13 | public class DetourAttribute : Attribute 14 | { 15 | #region Properties 16 | /// 17 | /// The class that contains the method 18 | /// 19 | public Type Class { get; private set; } 20 | /// 21 | /// The name of the method 22 | /// 23 | public string MethodName { get; private set; } 24 | /// 25 | /// The methodinfo of the method 26 | /// 27 | public MethodInfo Method { get; private set; } 28 | /// 29 | /// The flags to find the method 30 | /// 31 | public BindingFlags Flags { get; private set; } 32 | /// 33 | /// Was the method found 34 | /// 35 | public bool MethodFound { get; private set; } 36 | #endregion 37 | 38 | /// 39 | /// Used to detour a specific function 40 | /// 41 | /// The class containing the method 42 | /// The name of the method to replace 43 | /// The flags of the method to replace 44 | public DetourAttribute(Type tClass, string method, BindingFlags flags, int index = 0) 45 | { 46 | // Set the variables 47 | Class = tClass; 48 | MethodName = method; 49 | Flags = flags; 50 | 51 | try 52 | { 53 | Method = Class.GetMethods(flags).Where(a => a.Name == method).ToArray()[index]; 54 | MethodFound = true; 55 | } 56 | catch (Exception ex) 57 | { 58 | PointBlankLogging.LogError("Method not found! " + MethodName + " in class " + Class.FullName, ex, false, false); 59 | MethodFound = false; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /PointBlank/API/Detour/DetourManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Security.Permissions; 8 | using PointBlank.Framework.Permissions.Ring; 9 | using PointBlank.Services.DetourManager; 10 | using DM = PointBlank.Services.DetourManager.DetourManager; 11 | 12 | namespace PointBlank.API.Detour 13 | { 14 | /// 15 | /// Contains function for managing detours 16 | /// 17 | [RingPermission(SecurityAction.Demand, ring = RingPermissionRing.None)] 18 | public static class DetourManager 19 | { 20 | #region Public Functions 21 | /// 22 | /// Calls the original method that was detoured 23 | /// 24 | /// The original method 25 | /// The instance for the method(null if static) 26 | /// The arguments for the method 27 | /// The value that the original function returns 28 | public static object CallOriginal(MethodInfo method, object instance = null, params object[] args) 29 | { 30 | // Set the variables 31 | DetourWrapper wrapper = DM.Detours.First(a => a.Value.Original == method).Value; 32 | 33 | // Do the checks 34 | if (wrapper == null) 35 | throw new Exception("The detour specified was not found!"); 36 | 37 | return wrapper.CallOriginal(args, instance); 38 | } 39 | 40 | /// 41 | /// Calls the original method that was detoured 42 | /// 43 | /// The instance for the method(null if static) 44 | /// The arguments for the method 45 | /// The value tahat the original function returns 46 | public static object CallOriginal(object instance = null, params object[] args) 47 | { 48 | StackTrace trace = new StackTrace(false); 49 | 50 | if (trace.FrameCount < 1) 51 | throw new Exception("Invalid trace back to the original method! Please provide the methodinfo instead!"); 52 | 53 | MethodBase modded = trace.GetFrame(1).GetMethod(); 54 | MethodInfo original = null; 55 | 56 | if (!Attribute.IsDefined(modded, typeof(DetourAttribute))) 57 | modded = trace.GetFrame(2).GetMethod(); 58 | DetourAttribute att = (DetourAttribute)Attribute.GetCustomAttribute(modded, typeof(DetourAttribute)); 59 | 60 | if (att == null) 61 | throw new Exception("This method can only be called from an overwritten method!"); 62 | if (!att.MethodFound) 63 | throw new Exception("The original method was never found!"); 64 | original = att.Method; 65 | 66 | DetourWrapper wrapper = DM.Detours.First(a => a.Value.Original == original).Value; 67 | 68 | if (wrapper == null) 69 | throw new Exception("The detour specified was not found!"); 70 | 71 | return wrapper.CallOriginal(args, instance); 72 | } 73 | 74 | /// 75 | /// Enables the detour of a method(WARNING: The method needs to have been detoured atleast once!) 76 | /// 77 | /// The original method that was detoured 78 | /// If the detour was enabled successfully 79 | public static bool EnableDetour(MethodInfo method) 80 | { 81 | // Set the variables 82 | DetourWrapper wrapper = DM.Detours.First(a => a.Value.Original == method).Value; 83 | 84 | // Do the checks 85 | if (wrapper == null) 86 | return false; 87 | 88 | return wrapper.Detour(); 89 | } 90 | 91 | /// 92 | /// Disables the detour of a method(WARNING: The method needs to have been detoured atleast once!) 93 | /// 94 | /// The original method that was detoured 95 | /// If the detour was disabled successfully 96 | public static bool DisableDetour(MethodInfo method) 97 | { 98 | // Set the variables 99 | DetourWrapper wrapper = DM.Detours.First(a => a.Value.Original == method).Value; 100 | 101 | // Do the checks 102 | if (wrapper == null) 103 | return false; 104 | 105 | return wrapper.Revert(); 106 | } 107 | #endregion 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /PointBlank/API/Discord/DiscordClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Net.Security; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using Newtonsoft.Json.Linq; 9 | 10 | namespace PointBlank.API.Discord 11 | { 12 | /// 13 | /// Used for interacting with discord via the https code 14 | /// 15 | public class DiscordClient : WebClient 16 | { 17 | #region Properties 18 | /// 19 | /// The current URL of the website 20 | /// 21 | public Uri URL { get; private set; } 22 | 23 | /// 24 | /// The last http code received 25 | /// 26 | public EDiscordHttpCodes LastHTTPCode { get; private set; } 27 | /// 28 | /// The last json code received 29 | /// 30 | public EDiscordJsonCodes LastJSONCode { get; private set; } 31 | #endregion 32 | 33 | public DiscordClient() 34 | { 35 | base.Headers[HttpRequestHeader.ContentType] = "application/json"; 36 | } 37 | 38 | #region Private Functions 39 | private void ParseJsonCode(string response) 40 | { 41 | JObject obj = JObject.Parse(response); 42 | 43 | if(obj["code"] != null) 44 | { 45 | LastJSONCode = (EDiscordJsonCodes)(int)(obj["code"]); 46 | return; 47 | } 48 | LastJSONCode = 0; 49 | } 50 | #endregion 51 | 52 | #region Override Functions 53 | protected override WebRequest GetWebRequest(Uri address) 54 | { 55 | ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(PointBlank.ValidateCertificate); 56 | 57 | WebRequest request = base.GetWebRequest(address); 58 | 59 | return request; 60 | } 61 | 62 | protected override WebResponse GetWebResponse(WebRequest request) 63 | { 64 | WebResponse response = null; 65 | 66 | try 67 | { 68 | response = base.GetWebResponse(request); 69 | 70 | LastHTTPCode = (EDiscordHttpCodes)((HttpWebResponse)response).StatusCode; 71 | if(LastHTTPCode != EDiscordHttpCodes.NO_CONTENT) 72 | using (StreamReader reader = new StreamReader(((HttpWebResponse)response).GetResponseStream())) 73 | ParseJsonCode(reader.ReadToEnd()); 74 | } 75 | catch (WebException ex) 76 | { 77 | LastHTTPCode = (EDiscordHttpCodes)((HttpWebResponse)ex.Response).StatusCode; 78 | if (LastHTTPCode != EDiscordHttpCodes.NO_CONTENT) 79 | using (StreamReader reader = new StreamReader(((HttpWebResponse)response).GetResponseStream())) 80 | ParseJsonCode(reader.ReadToEnd()); 81 | } 82 | URL = response.ResponseUri; 83 | 84 | return response; 85 | } 86 | 87 | protected override void OnUploadStringCompleted(UploadStringCompletedEventArgs e) 88 | { 89 | if(e.Error != null) 90 | { 91 | 92 | LastHTTPCode = (EDiscordHttpCodes)((HttpWebResponse)((WebException)e.Error).Response).StatusCode; 93 | if (LastHTTPCode == EDiscordHttpCodes.NO_CONTENT) return; 94 | using (StreamReader reader = new StreamReader(((HttpWebResponse)((WebException)e.Error).Response).GetResponseStream())) 95 | ParseJsonCode(reader.ReadToEnd()); 96 | return; 97 | } 98 | 99 | base.OnUploadStringCompleted(e); 100 | } 101 | #endregion 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /PointBlank/API/Discord/DiscordWebhook.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using Newtonsoft.Json; 7 | using Newtonsoft.Json.Linq; 8 | 9 | namespace PointBlank.API.Discord 10 | { 11 | /// 12 | /// Used for interacting with discord webhooks 13 | /// 14 | public class DiscordWebhook : IDisposable 15 | { 16 | #region Variables 17 | private Queue QueuedMessages = new Queue(); 18 | #endregion 19 | 20 | #region Properties 21 | /// 22 | /// The webhook URL for interaction with discord 23 | /// 24 | public Uri URL { get; private set; } 25 | /// 26 | /// The name of the webhook(it will be displayed when sending messages) 27 | /// 28 | public string Name { get; set; } 29 | /// 30 | /// The avatar image URL for the webhook 31 | /// 32 | public string Avatar { get; set; } 33 | 34 | /// 35 | /// The client responsible for interacting with discord 36 | /// 37 | public DiscordClient Client { get; private set; } 38 | /// 39 | /// The amount of messages you can send before time reset 40 | /// 41 | public int Limit { get; private set; } 42 | /// 43 | /// The time until the limit resets 44 | /// 45 | public DateTime LastLimit { get; private set; } 46 | #endregion 47 | 48 | /// 49 | /// Creates and instance of the discord webhook 50 | /// 51 | /// The URL of the discord webhook 52 | /// The name of the discord webhook(can be changed later) 53 | public DiscordWebhook(Uri URL, string Name = "Unturned Server", string Avatar = null) 54 | { 55 | // Set the variables 56 | this.URL = URL; 57 | this.Name = Name; 58 | this.Avatar = Avatar; 59 | 60 | // Setup the variables 61 | Client = new DiscordClient(); 62 | LastLimit = DateTime.Now; 63 | } 64 | 65 | #region Public Functions 66 | /// 67 | /// Sends the generated message to the discord webhook 68 | /// 69 | /// The generated message to send 70 | /// Should sending be asynced 71 | /// Was the message sent successfully 72 | public bool Send(JObject message, bool Async = true) 73 | { 74 | if (message == null) 75 | return false; 76 | if ((DateTime.Now - LastLimit).TotalMilliseconds < 0) 77 | { 78 | QueuedMessages.Enqueue(message); 79 | return false; 80 | } 81 | JObject obj = new JObject {{"username", Name}}; 82 | 83 | if (!string.IsNullOrEmpty(Avatar)) 84 | obj.Add("avatar_url", Avatar); 85 | obj.Add("tts", false); 86 | obj.Add("embeds", new JArray() { message }); 87 | 88 | FlushQueue(Async); 89 | if (Async) 90 | Client.UploadStringAsync(URL, obj.ToString(Formatting.None)); 91 | else 92 | Client.UploadString(URL.AbsoluteUri, obj.ToString(Formatting.None)); 93 | 94 | if (int.Parse(Client.ResponseHeaders["X-RateLimit-Remaining"]) < 1) 95 | LastLimit = PointBlankTools.FromUnixTime(long.Parse(Client.ResponseHeaders["X-RateLimit-Reset"])); 96 | return Client.LastHTTPCode == EDiscordHttpCodes.OK && Client.LastHTTPCode == EDiscordHttpCodes.NO_CONTENT; 97 | } 98 | 99 | /// 100 | /// Sends the text message to the discord webhook 101 | /// 102 | /// The text message to send 103 | /// Should sending be asynced 104 | /// Was the message sent successfully 105 | public bool Send(string message, bool Async = true) 106 | { 107 | if (message == null) 108 | return false; 109 | if ((DateTime.Now - LastLimit).TotalMilliseconds < 0) 110 | { 111 | QueuedMessages.Enqueue(message); 112 | return false; 113 | } 114 | JObject obj = new JObject {{"username", Name}}; 115 | 116 | if (!string.IsNullOrEmpty(Avatar)) 117 | obj.Add("avatar_url", Avatar); 118 | obj.Add("tts", false); 119 | obj.Add("embeds", new JArray() { message }); 120 | 121 | FlushQueue(Async); 122 | if (Async) 123 | Client.UploadStringAsync(URL, obj.ToString(Formatting.None)); 124 | else 125 | Client.UploadString(URL.AbsoluteUri, obj.ToString(Formatting.None)); 126 | 127 | if (int.Parse(Client.ResponseHeaders["X-RateLimit-Remaining"]) < 1) 128 | LastLimit = PointBlankTools.FromUnixTime(long.Parse(Client.ResponseHeaders["X-RateLimit-Reset"])); 129 | return Client.LastHTTPCode == EDiscordHttpCodes.OK && Client.LastHTTPCode == EDiscordHttpCodes.NO_CONTENT; 130 | } 131 | 132 | /// 133 | /// Sends all the messages stuck in queue to discord 134 | /// 135 | /// Should sending be asynced 136 | public void FlushQueue(bool Async = true) 137 | { 138 | while(QueuedMessages.Count > 0) 139 | { 140 | object msg = QueuedMessages.Dequeue(); 141 | bool result = true; 142 | if (msg is string) 143 | result = Send((string)msg, Async); 144 | else if (msg is JObject) 145 | result = Send((JObject)msg, Async); 146 | 147 | if(!result && Client.LastHTTPCode == EDiscordHttpCodes.TOO_MANY_REQUESTS) 148 | break; 149 | } 150 | } 151 | 152 | /// 153 | /// Called to dispose the webhook 154 | /// 155 | public void Dispose() 156 | { 157 | Client.Dispose(); 158 | } 159 | #endregion 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /PointBlank/API/Discord/EDiscordHttpCodes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Discord 7 | { 8 | /// 9 | /// List of discord http response codes 10 | /// 11 | public enum EDiscordHttpCodes 12 | { 13 | OK = 200, 14 | CREATED = 201, 15 | NO_CONTENT = 204, 16 | NOT_MODIFIED = 304, 17 | BAD_REQUEST = 400, 18 | UNAUTHORIZED = 401, 19 | FORBIDDEN = 403, 20 | NOT_FOUND = 404, 21 | METHOD_NOT_ALLOWED = 405, 22 | TOO_MANY_REQUESTS = 429, 23 | GATEWAY_UNAVAILABLE = 502, 24 | SERVER_ERROR = 503 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /PointBlank/API/Discord/EDiscordJsonCodes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Discord 7 | { 8 | /// 9 | /// Lists of JSON codes sent by discord 10 | /// 11 | public enum EDiscordJsonCodes 12 | { 13 | UNKNOWN_ACCOUNT = 10001, 14 | UNKNOWN_APPLICATION = 10002, 15 | UNKNOWN_CHANNEL = 10003, 16 | UNKNOWN_GUILD = 10004, 17 | UNKNOWN_INTEGRATION = 10005, 18 | UNKNOWN_INVITE = 10006, 19 | UNKNOWN_MEMBER = 10007, 20 | UNKNOWN_MESSAGE = 10008, 21 | UNKNOWN_OVERWRITE = 10009, 22 | UNKNOWN_PROVIDER = 10010, 23 | UNKNOWN_ROLE = 10011, 24 | UNKNOWN_TOKEN = 10012, 25 | UNKNOWN_USER = 10013, 26 | UNKNOWN_EMOJI = 10014, 27 | BOTS_CANNOT_USE_ENDPOINT = 20001, 28 | ONLY_BOTS_CAN_USE_ENPOINT = 20002, 29 | MAX_NUMBER_OF_GUILDS = 30001, 30 | MAX_NUMBER_OF_FRIENDS = 30002, 31 | MAX_NUMBER_OF_PINS = 30003, 32 | MAX_NUMBER_OF_GUILD_ROLES = 30005, 33 | TOO_MANY_REACTIONS = 30010, 34 | UNAUTHORIZED = 40001, 35 | MISSING_ACCESS = 50001, 36 | INVALID_ACCOUNT_TYPE = 50002, 37 | CANNOT_EXECUTE_ON_DM = 50003, 38 | EMBEDED_DISABLED = 50004, 39 | CANNOT_EDIT_MESSAGE = 50005, 40 | CANNOT_SEND_EMPTY = 50006, 41 | CANNOT_SEND_TO_USER = 50007, 42 | CANNOT_SEND_TO_VOICE = 50008, 43 | VERIFICATION_TOO_HIGH = 50009, 44 | OAUTH2_NO_BOT = 50010, 45 | OAUTH2_LIMIT = 50011, 46 | OAUTH2_INVALID = 50012, 47 | MISSING_PERMISSIONS = 50013, 48 | INVALID_TOKEN = 50014, 49 | NOTE_TOO_LONG = 50015, 50 | TOO_FEW_OR_TOO_MANY_MESSAGES_TO_DELETE = 50016, 51 | INVALID_PIN_CHANNEL = 50019, 52 | CANNOT_EXECUTE_ON_SYSTEM_MESSAGE = 50021, 53 | MESSAGE_TOO_OLD = 50034, 54 | INVITE_BOT_FAIL = 50036, 55 | REACTION_BLOCKED = 90001 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /PointBlank/API/Extension/PointBlankExtensionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Extension 7 | { 8 | /// 9 | /// Used for defining extension for the PointBlank project. Must be added to the assembly of any extension that implements a modding API to any unity game 10 | /// 11 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] 12 | public class PointBlankExtensionAttribute : Attribute 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /PointBlank/API/Groups/PointBlankGroupEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Groups 7 | { 8 | /// 9 | /// List of events for groups 10 | /// 11 | public static class PointBlankGroupEvents 12 | { 13 | #region Handlers 14 | /// 15 | /// Handler for all group events such as OnGroupAdded and OnGroupRemoved 16 | /// 17 | /// The group that the event affects 18 | public delegate void GroupEventHandler(PointBlankGroup group); 19 | 20 | /// 21 | /// Handler for group permission events 22 | /// 23 | /// The affected permission 24 | /// The affected group's instance 25 | public delegate void PermissionEventHandler(PointBlankGroup instance, string permission); 26 | /// 27 | /// Handler for inherited groups events 28 | /// 29 | /// The affected group 30 | /// The affected group's instance 31 | public delegate void InheritEventHandler(PointBlankGroup instance, PointBlankGroup group); 32 | 33 | /// 34 | /// Handler for group prefix events 35 | /// 36 | /// The affected prefix 37 | /// The affected group's instance 38 | public delegate void PrefixEventHandler(PointBlankGroup instance, string prefix); 39 | /// 40 | /// Handler for the group suffix events 41 | /// 42 | /// The affected suffix 43 | /// The affected group's instance 44 | public delegate void SuffixEventHandler(PointBlankGroup instance, string suffix); 45 | #endregion 46 | 47 | #region Events 48 | /// 49 | /// Called when a group is added to the server 50 | /// 51 | public static event GroupEventHandler OnGroupAdded; 52 | /// 53 | /// Called when a group is removed from the server 54 | /// 55 | public static event GroupEventHandler OnGroupRemoved; 56 | 57 | /// 58 | /// Called when a permission is added 59 | /// 60 | public static event PermissionEventHandler OnPermissionAdded; 61 | /// 62 | /// Called when a permission is removed 63 | /// 64 | public static event PermissionEventHandler OnPermissionRemoved; 65 | 66 | /// 67 | /// Called when an inherit is added 68 | /// 69 | public static event InheritEventHandler OnInheritAdded; 70 | /// 71 | /// Called when an inherit is removed 72 | /// 73 | public static event InheritEventHandler OnInheritRemoved; 74 | 75 | /// 76 | /// Called when a prefix is added 77 | /// 78 | public static event PrefixEventHandler OnPrefixAdded; 79 | /// 80 | /// Called when a prefix is removed 81 | /// 82 | public static event PrefixEventHandler OnPrefixRemoved; 83 | 84 | /// 85 | /// Called when a suffix is added 86 | /// 87 | public static event SuffixEventHandler OnSuffixAdded; 88 | /// 89 | /// Called when a suffix is removed 90 | /// 91 | public static event SuffixEventHandler OnSuffixRemoved; 92 | #endregion 93 | 94 | #region Functions 95 | internal static void RunGroupAdded(PointBlankGroup g) => OnGroupAdded?.Invoke(g); 96 | internal static void RunGroupRemoved(PointBlankGroup g) => OnGroupRemoved?.Invoke(g); 97 | 98 | internal static void RunPermissionAdded(PointBlankGroup instance, string permission) => OnPermissionAdded?.Invoke(instance, permission); 99 | internal static void RunPermissionRemoved(PointBlankGroup instance, string permission) => OnPermissionRemoved?.Invoke(instance, permission); 100 | 101 | internal static void RunPrefixAdded(PointBlankGroup instance, string prefix) => OnPrefixAdded?.Invoke(instance, prefix); 102 | internal static void RunPrefixRemoved(PointBlankGroup instance, string prefix) => OnPrefixRemoved?.Invoke(instance, prefix); 103 | 104 | internal static void RunSuffixAdded(PointBlankGroup instance, string suffix) => OnSuffixAdded?.Invoke(instance, suffix); 105 | internal static void RunSuffixRemoved(PointBlankGroup instance, string suffix) => OnSuffixRemoved?.Invoke(instance, suffix); 106 | 107 | internal static void RunInheritAdded(PointBlankGroup instance, PointBlankGroup group) => OnInheritAdded?.Invoke(instance, @group); 108 | internal static void RunInheritRemoved(PointBlankGroup instance, PointBlankGroup group) => OnInheritRemoved?.Invoke(instance, @group); 109 | 110 | #endregion 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /PointBlank/API/Groups/PointBlankGroupManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | using PointBlank.API.Services; 7 | using GM = PointBlank.Services.GroupManager.GroupManager; 8 | 9 | namespace PointBlank.API.Groups 10 | { 11 | /// 12 | /// Used for managing server groups 13 | /// 14 | public static class PointBlankGroupManager 15 | { 16 | #region Variables 17 | private static Dictionary _Groups = new Dictionary(); 18 | #endregion 19 | 20 | #region Properties 21 | /// 22 | /// Array of groups in the server 23 | /// 24 | public static PointBlankGroup[] Groups => _Groups.Values.ToArray(); 25 | 26 | /// 27 | /// Is the group manager loaded(this is for events) 28 | /// 29 | public static bool Loaded { get; set; } = false; 30 | #endregion 31 | 32 | #region Public Functions 33 | /// 34 | /// Adds a group to the server groups 35 | /// 36 | /// The group instance to add 37 | public static void AddGroup(PointBlankGroup group) 38 | { 39 | if (_Groups.ContainsKey(group.ID)) 40 | return; 41 | _Groups.Add(group.ID, group); 42 | 43 | if (Loaded) 44 | PointBlankGroupEvents.RunGroupAdded(group); 45 | } 46 | /// 47 | /// Creates and adds a group to the server group 48 | /// 49 | /// The group ID 50 | /// The group name 51 | /// The command cooldown for the group 52 | public static void AddGroup(string ID, string Name, bool isDefault, int Cooldown, Color color) 53 | { 54 | if (_Groups.ContainsKey(ID)) 55 | return; 56 | PointBlankGroup group = new PointBlankGroup(ID, Name, isDefault, Cooldown, color); 57 | 58 | _Groups.Add(ID, group); 59 | 60 | if (Loaded) 61 | PointBlankGroupEvents.RunGroupAdded(group); 62 | } 63 | 64 | /// 65 | /// Removes a group from the server 66 | /// 67 | /// The group to remove 68 | public static void RemoveGroup(PointBlankGroup group) 69 | { 70 | if (!_Groups.ContainsValue(group)) 71 | return; 72 | _Groups.Remove(group.ID); 73 | 74 | if (Loaded) 75 | PointBlankGroupEvents.RunGroupRemoved(group); 76 | } 77 | /// 78 | /// Removes a group from the server 79 | /// 80 | /// The ID of the group 81 | public static void RemoveGroup(string ID) 82 | { 83 | if (!_Groups.ContainsKey(ID)) 84 | return; 85 | PointBlankGroup group = _Groups[ID]; 86 | 87 | _Groups.Remove(ID); 88 | 89 | if (Loaded) 90 | PointBlankGroupEvents.RunGroupRemoved(group); 91 | } 92 | 93 | /// 94 | /// Find a server group and returns it 95 | /// 96 | /// The ID of the group 97 | /// The group instance 98 | public static PointBlankGroup Find(string ID) => Groups.FirstOrDefault(a => a.ID == ID); 99 | 100 | /// 101 | /// Tries to find the group by ID and returns it 102 | /// 103 | /// The group ID to look for 104 | /// The group instance 105 | /// If the group was found 106 | public static bool TryFindGroup(string ID, out PointBlankGroup group) 107 | { 108 | PointBlankGroup g = Find(ID); 109 | 110 | group = g; 111 | return g != null; 112 | } 113 | 114 | /// 115 | /// Reloads the groups 116 | /// 117 | public static void Reload() 118 | { 119 | GM gm = (GM)PointBlankServiceManager.GetService("GroupManager.GroupManager"); 120 | 121 | gm.GroupConfig.Reload(); 122 | gm.LoadGroups(); 123 | } 124 | #endregion 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /PointBlank/API/IPC/EIPCType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.IPC 7 | { 8 | /// 9 | /// The types of IPC you can use 10 | /// 11 | public enum EIPCType 12 | { 13 | FILE, 14 | CONSOLE 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /PointBlank/API/IPC/IPCEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.IPC 7 | { 8 | /// 9 | /// Events for the inter-process communication library 10 | /// 11 | public static class IPCEvents 12 | { 13 | #region Handlers 14 | /// 15 | /// Handles all key list based events 16 | /// 17 | /// The affected key 18 | public delegate void KeyListChangedHandler(string key); 19 | 20 | /// 21 | /// Handles all key value changes 22 | /// 23 | /// The affected key 24 | /// The new value of the key 25 | public delegate void KeyValueChangedHandler(string key, string value); 26 | #endregion 27 | 28 | #region Events 29 | /// 30 | /// Called when a key is added 31 | /// 32 | public static event KeyListChangedHandler OnKeyAdded; 33 | /// 34 | /// Called when a key is removed 35 | /// 36 | public static event KeyListChangedHandler OnKeyRemoved; 37 | 38 | /// 39 | /// Called when a key value is changed 40 | /// 41 | public static event KeyValueChangedHandler OnKeyValueChanged; 42 | #endregion 43 | 44 | #region Functions 45 | internal static void RunKeyAdded(string key) => OnKeyAdded?.Invoke(key); 46 | internal static void RunKeyRemoved(string key) => OnKeyRemoved?.Invoke(key); 47 | 48 | internal static void RunKeyValueChanged(string key, string value) => OnKeyValueChanged?.Invoke(key, value); 49 | #endregion 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /PointBlank/API/IPC/IPCManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using IPCM = PointBlank.Services.IPCManager.IPCManager; 6 | 7 | namespace PointBlank.API.IPC 8 | { 9 | /// 10 | /// Inter-process communication library 11 | /// 12 | public static class IPCManager 13 | { 14 | #region Properties 15 | /// 16 | /// List of all Inter-Process communication keys 17 | /// 18 | public static string[] IPCKeys => IPCM.IPC.Keys.ToArray(); 19 | 20 | /// 21 | /// The current method used for IPC 22 | /// 23 | public static EIPCType IPCType { get; set; } = EIPCType.CONSOLE; 24 | #endregion 25 | 26 | #region Functions 27 | /// 28 | /// Adds a key to the IPC 29 | /// 30 | /// The key to add 31 | /// The default value of the key 32 | public static void AddKey(string key, string value) 33 | { 34 | if (IPCM.IPC.ContainsKey(key)) 35 | return; 36 | 37 | IPCM.IPC.Add(key, value); 38 | IPCEvents.RunKeyAdded(key); 39 | } 40 | /// 41 | /// Removes a key from the IPC 42 | /// 43 | /// The key to remove 44 | public static void RemoveKey(string key) 45 | { 46 | if (!IPCM.IPC.ContainsKey(key)) 47 | return; 48 | 49 | IPCM.IPC.Remove(key); 50 | IPCEvents.RunKeyRemoved(key); 51 | } 52 | 53 | /// 54 | /// Changes a key's value 55 | /// 56 | /// The key to change 57 | /// The new value of the key 58 | public static void SetValue(string key, string value) 59 | { 60 | if (!IPCM.IPC.ContainsKey(key)) 61 | return; 62 | 63 | IPCM.IPC[key] = value; 64 | IPCEvents.RunKeyValueChanged(key, value); 65 | } 66 | /// 67 | /// Gets the value of an IPC key 68 | /// 69 | /// The key to get the value from 70 | public static string GetValue(string key) 71 | { 72 | if (!IPCM.IPC.ContainsKey(key)) 73 | return null; 74 | 75 | return IPCM.IPC[key]; 76 | } 77 | #endregion 78 | 79 | #region Event Functions 80 | /// 81 | /// This is an event! You call this every time something is printed into the console! 82 | /// WARNING: Do not hook to the console output as it will cause issues! 83 | /// 84 | /// The printed text 85 | public static void HookOutput(string text) => IPCM.OnOutput(text); 86 | #endregion 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /PointBlank/API/Implements/NetFramework.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using PointBlank.API; 8 | 9 | namespace PointBlank.API.Implements 10 | { 11 | /// 12 | /// Contains .net framework functions that were removed or were added after version 3.5 13 | /// 14 | public static class NetFramework 15 | { 16 | /// 17 | /// The .net 3.5 implementation of the HasFlag function found in .net 4.0+ 18 | /// 19 | /// The flag to compare 20 | /// The flag to compare it to 21 | /// If the input flag contains the matching flag 22 | public static bool HasFlag(this Enum input, Enum matchTo) => (Convert.ToUInt32(input) & Convert.ToUInt32(matchTo)) != 0; 23 | 24 | /// 25 | /// Copies from one stream to another 26 | /// 27 | /// The source stream to copy from 28 | /// The destination stream to copy to 29 | public static void CopyTo(this Stream source, Stream destination) 30 | { 31 | byte[] bytes = new byte[4096]; 32 | int count; 33 | 34 | while ((count = source.Read(bytes, 0, bytes.Length)) != 0) 35 | destination.Write(bytes, 0, count); 36 | } 37 | 38 | #region Lists 39 | /// 40 | /// Uses a for loop on any list 41 | /// 42 | /// The list type 43 | /// The list the loop is running through 44 | /// The list function that gets run 45 | public static void For(this IEnumerable list, Action action) 46 | { 47 | for(int i = 0; i < list.Count(); i++) 48 | action(i, list.ElementAt(i)); 49 | } 50 | 51 | /// 52 | /// Uses a foreach loop on any list 53 | /// 54 | /// The list type 55 | /// The list the loop is running through 56 | /// The list function that gets run 57 | public static void ForEach(this IEnumerable list, Action action) 58 | { 59 | foreach (T obj in list) 60 | action(obj); 61 | } 62 | #endregion 63 | 64 | #region Reflection 65 | /// 66 | /// Gets the value and assigns the type of the value 67 | /// 68 | /// The type of the value 69 | /// The FieldInfo instance of the field 70 | /// The instance of the object(null if static) 71 | /// The value with assigned type 72 | public static T GetValue(this FieldInfo field, object instance) => (T)field.GetValue(instance); 73 | 74 | /// 75 | /// Runs a method and returns a value 76 | /// 77 | /// The value type 78 | /// The method to run 79 | /// The instance of the class(null if static) 80 | /// The parameters of the method 81 | /// The value the method returns 82 | public static T RunMethod(this MethodInfo method, object instance, params object[] parameters) => 83 | (T)method.Invoke(instance, parameters); 84 | /// 85 | /// Runs a method 86 | /// 87 | /// The method to run 88 | /// The instance of the class(null if static) 89 | /// The parameters of the method 90 | public static void RunMethod(this MethodInfo method, object instance, params object[] parameters) => 91 | RunMethod(method, instance, parameters); 92 | #endregion 93 | 94 | #region Objects 95 | /// 96 | /// Converts an object to a specific type 97 | /// 98 | /// The type to change the object to 99 | /// The object instance 100 | /// The value as the specified type 101 | public static T Get(this object obj) => (T)obj; 102 | #endregion 103 | } 104 | 105 | public delegate void VoidHandler(); 106 | } 107 | -------------------------------------------------------------------------------- /PointBlank/API/Implements/PointBlank.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Implements 7 | { 8 | public static class PointBlank 9 | { 10 | #region Metadata 11 | /// 12 | /// Returns the metadata value with assigned type 13 | /// 14 | /// The type to assign the value to 15 | /// The metadata to search in 16 | /// The key to search for 17 | /// The value with assigned type 18 | public static T Get(this Dictionary metadata, string key) => (T)metadata[key]; 19 | #endregion 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /PointBlank/API/Implements/UnityEngine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace PointBlank.API.Implements 8 | { 9 | public static class UnityEngine 10 | { 11 | /// 12 | /// Duplicates a Vector3 instance 13 | /// 14 | /// The Vector3 instance to duplicate 15 | /// The duplicated instance of the Vector3 instance specified 16 | public static Vector3 Duplicate(this Vector3 vector3) => new Vector3(vector3.x, vector3.y, vector3.z); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /PointBlank/API/Interfaces/IConfigurable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.API.Collections; 6 | 7 | namespace PointBlank.API.Interfaces 8 | { 9 | /// 10 | /// Makes a class configurable by adding configurations to it 11 | /// 12 | public interface IConfigurable 13 | { 14 | /// 15 | /// The directory inside the configurations folder where the file will be save(leave null or empty to use default path) 16 | /// 17 | string ConfigurationDirectory { get; } 18 | /// 19 | /// The list of configurations 20 | /// 21 | ConfigurationList Configurations { get; } 22 | /// 23 | /// The dictionary to save the IConfigurable instance to(set to null if the Configurations and ConfigurationDirectory are static) 24 | /// 25 | Dictionary ConfigurationDictionary { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /PointBlank/API/Interfaces/ITranslatable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.API.Collections; 6 | 7 | namespace PointBlank.API.Interfaces 8 | { 9 | /// 10 | /// Makes a class translatable by adding translations to it 11 | /// 12 | public interface ITranslatable 13 | { 14 | /// 15 | /// The directory inside the translations folder where the file will be save(leave null or empty to use default path) 16 | /// 17 | string TranslationDirectory { get; } 18 | /// 19 | /// The list of translations 20 | /// 21 | TranslationList Translations { get; } 22 | /// 23 | /// The dictionary to save the ITranslatable instance to(set to null if the Translations and TranslationDirectory are static) 24 | /// 25 | Dictionary TranslationDictionary { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /PointBlank/API/Player/PointBlankPlayerComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.API.Plugins; 6 | using UnityEngine; 7 | 8 | namespace PointBlank.API.Player 9 | { 10 | /// 11 | /// The attachable component for the player 12 | /// 13 | public class PointBlankPlayerComponent : MonoBehaviour 14 | { 15 | #region Mono Functions 16 | void Awake() 17 | { 18 | DontDestroyOnLoad(this); 19 | } 20 | #endregion 21 | 22 | #region Virtual Functions 23 | /// 24 | /// Called for loading the component 25 | /// 26 | public virtual void Load() { } 27 | 28 | /// 29 | /// Called for unloading the component 30 | /// 31 | public virtual void Unload() { } 32 | #endregion 33 | 34 | #region Functions 35 | /// 36 | /// Translates a key and data to text depending on the translation 37 | /// 38 | /// The key of the translation 39 | /// The data to modify the translation 40 | /// The translated text 41 | public string Translate(string key, params object[] data) => PointBlankPlugin.GetInstance(this).Translate(key, data); 42 | 43 | /// 44 | /// Easy to use configuration value extractor 45 | /// 46 | /// The configuration value type 47 | /// The key of the configuration value 48 | /// The configuration value with specified type 49 | public T Configure(string key) => PointBlankPlugin.GetInstance(this).Configure(key); 50 | #endregion 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /PointBlank/API/Player/PointBlankPlayerEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.API.Groups; 6 | 7 | namespace PointBlank.API.Player 8 | { 9 | public static class PointBlankPlayerEvents 10 | { 11 | #region Handlers 12 | /// 13 | /// Handles permission changes of the player 14 | /// 15 | /// The affected player 16 | /// The changed permission 17 | public delegate void PermissionsChangedHandler(PointBlankPlayer player, string permission); 18 | /// 19 | /// Handles group changes of the player 20 | /// 21 | /// The affected player 22 | /// The changed group 23 | public delegate void GroupsChangedHandler(PointBlankPlayer player, PointBlankGroup group); 24 | #endregion 25 | 26 | #region Events 27 | /// 28 | /// Called when a permission is added 29 | /// 30 | public static event PermissionsChangedHandler OnPermissionAdded; 31 | /// 32 | /// Called when a permission is removed 33 | /// 34 | public static event PermissionsChangedHandler OnPermissionRemoved; 35 | 36 | /// 37 | /// Called when a group is added 38 | /// 39 | public static event GroupsChangedHandler OnGroupAdded; 40 | /// 41 | /// Called when a group is removed 42 | /// 43 | public static event GroupsChangedHandler OnGroupRemoved; 44 | #endregion 45 | 46 | #region Functions 47 | internal static void RunPermissionAdd(PointBlankPlayer player, string permission) => OnPermissionAdded?.Invoke(player, permission); 48 | internal static void RunPermissionRemove(PointBlankPlayer player, string permission) => OnPermissionRemoved?.Invoke(player, permission); 49 | 50 | internal static void RunGroupAdd(PointBlankPlayer player, PointBlankGroup group) => OnGroupAdded?.Invoke(player, group); 51 | internal static void RunGroupRemove(PointBlankPlayer player, PointBlankGroup group) => OnGroupRemoved?.Invoke(player, group); 52 | #endregion 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /PointBlank/API/Plugins/PointBlankPlugin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Diagnostics; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using PointBlank.API; 8 | using PointBlank.API.Collections; 9 | using PointBlank.Services.PluginManager; 10 | using UnityEngine; 11 | 12 | namespace PointBlank.API.Plugins 13 | { 14 | /// 15 | /// Used to specify the entrypoint of the plugin 16 | /// 17 | public abstract class PointBlankPlugin : MonoBehaviour 18 | { 19 | #region Abstract Properties 20 | /// 21 | /// The translations for the plugin 22 | /// 23 | public abstract TranslationList Translations { get; } 24 | 25 | /// 26 | /// The configurations for the plugin 27 | /// 28 | public abstract ConfigurationList Configurations { get; } 29 | 30 | /// 31 | /// The current version of the plugin 32 | /// 33 | public abstract string Version { get; } 34 | #endregion 35 | 36 | #region Virtual Properties 37 | /// 38 | /// The latest version of the plugin(for auto-update)(Leave null if you don't want a version check) 39 | /// 40 | public virtual string VersionURL => null; 41 | 42 | /// 43 | /// The latest build of the plugin(for auto-update)(Leave null if you don't want an auto-update system) 44 | /// 45 | public virtual string BuildURL => null; 46 | #endregion 47 | 48 | #region Abstract Functions 49 | /// 50 | /// Called when the plugin is loading 51 | /// 52 | public abstract void Load(); 53 | 54 | /// 55 | /// Called when the plugin is unloading 56 | /// 57 | public abstract void Unload(); 58 | #endregion 59 | 60 | #region Functions 61 | /// 62 | /// Easy translation with string formatting 63 | /// 64 | /// The translation key 65 | /// The arguments for string formatting 66 | /// The formatted message 67 | public string Translate(string key, params object[] data) => (Translations.ContainsKey(key) ? string.Format(Translations[key], data) : "#" + key); 68 | 69 | /// 70 | /// Easy to use configuration value extractor 71 | /// 72 | /// The configuration value type 73 | /// The key of the configuration value 74 | /// The configuration value with specified type 75 | public T Configure(string key) => (T)Configurations[key]; 76 | 77 | /// 78 | /// Gets the plugin instance based on any instance of any class inside the plugin dll 79 | /// 80 | /// The instance of any class inside the plugin dll 81 | /// The plugin instance 82 | public static PointBlankPlugin GetInstance(object pluginObject) 83 | { 84 | PluginWrapper wrapper = PluginManager.Plugins.FirstOrDefault(a => a.PluginAssembly == pluginObject.GetType().Assembly); 85 | 86 | return (wrapper == null ? null : wrapper.PluginClass); 87 | } 88 | /// 89 | /// Gets the plugin instance based on any type of any class inside the plugin dll 90 | /// 91 | /// The type of any class inside the plugin dll 92 | /// The plugin instance 93 | public static PointBlankPlugin GetInstance(Type type) 94 | { 95 | PluginWrapper wrapper = PluginManager.Plugins.FirstOrDefault(a => a.PluginAssembly == type.Assembly); 96 | 97 | return (wrapper == null ? null : wrapper.PluginClass); 98 | } 99 | /// 100 | /// Gets the plugin instance based on the plugin class provided 101 | /// 102 | /// The plugin class 103 | /// The plugin instance 104 | public static T GetInstance() where T : PointBlankPlugin 105 | { 106 | PluginWrapper wrapper = PluginManager.Plugins.FirstOrDefault(a => a.PluginClass.GetType() == typeof(T)); 107 | 108 | return (wrapper == null ? null : (T)wrapper.PluginClass); 109 | } 110 | #endregion 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /PointBlank/API/Plugins/PointBlankPluginEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.API.Implements; 6 | 7 | namespace PointBlank.API.Plugins 8 | { 9 | /// 10 | /// All the plugin events 11 | /// 12 | public static class PointBlankPluginEvents 13 | { 14 | #region Handlers 15 | /// 16 | /// The handler for any plugin events 17 | /// 18 | /// The plugin 19 | public delegate void PluginEventHandler(PointBlankPlugin plugin); 20 | #endregion 21 | 22 | #region Events 23 | /// 24 | /// Called when the plugin is being started 25 | /// 26 | public static event PluginEventHandler OnPluginStart; 27 | /// 28 | /// Called when the plugin has loaded 29 | /// 30 | public static event PluginEventHandler OnPluginLoaded; 31 | /// 32 | /// Called when all plugins have been loaded 33 | /// 34 | public static event VoidHandler OnPluginsLoaded; 35 | 36 | /// 37 | /// Called when the plugin is being stopped 38 | /// 39 | public static event PluginEventHandler OnPluginStop; 40 | /// 41 | /// Called when the plugin has unloaded 42 | /// 43 | public static event PluginEventHandler OnPluginUnloaded; 44 | /// 45 | /// Called when all plugins have been unloaded 46 | /// 47 | public static event VoidHandler OnPluginsUnloaded; 48 | #endregion 49 | 50 | #region Functions 51 | internal static void RunPluginStart(PointBlankPlugin plugin) => OnPluginStart?.Invoke(plugin); 52 | internal static void RunPluginLoaded(PointBlankPlugin plugin) => OnPluginLoaded?.Invoke(plugin); 53 | internal static void RunPluginsLoaded() => OnPluginsLoaded?.Invoke(); 54 | 55 | internal static void RunPluginStop(PointBlankPlugin plugin) => OnPluginStop?.Invoke(plugin); 56 | internal static void RunPluginUnloaded(PointBlankPlugin plugin) => OnPluginUnloaded?.Invoke(plugin); 57 | internal static void RunPluginsUnloaded() => OnPluginsUnloaded?.Invoke(); 58 | #endregion 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /PointBlank/API/Plugins/PointBlankPluginManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using PointBlank.Services.PluginManager; 7 | using PM = PointBlank.Services.PluginManager.PluginManager; 8 | 9 | namespace PointBlank.API.Plugins 10 | { 11 | /// 12 | /// Functions for managing plugins 13 | /// 14 | public static class PointBlankPluginManager 15 | { 16 | #region Properties 17 | /// 18 | /// Array of all the loaded plugins 19 | /// 20 | public static PointBlankPlugin[] LoadedPlugins => PM.Plugins.Select(a => a.PluginClass).ToArray(); 21 | /// 22 | /// Array of all the loaded libraries 23 | /// 24 | public static Assembly[] LoadedLibraries => PM.Libraries; 25 | #endregion 26 | 27 | #region Functions 28 | /// 29 | /// Returns the plugin name of a specific plugin 30 | /// 31 | /// The plugin to get the name of 32 | /// The name of the plugin 33 | public static string GetPluginName(PointBlankPlugin plugin) => PM.Plugins.FirstOrDefault(a => a.PluginClass == plugin).Name; 34 | 35 | /// 36 | /// Reloads the plugin manager 37 | /// 38 | public static void Reload() 39 | { 40 | PM manager = (PM)Enviroment.services["PluginManager.PluginManager"].ServiceClass; 41 | 42 | manager.LoadConfig(); 43 | foreach(PluginWrapper wrapper in PM.Plugins) 44 | { 45 | wrapper.LoadConfiguration(); 46 | wrapper.LoadTranslation(); 47 | } 48 | } 49 | 50 | /// 51 | /// Reloads a specific plugin 52 | /// 53 | /// The plugin to reload 54 | public static void Reload(PointBlankPlugin plugin) 55 | { 56 | PluginWrapper wrapper = PM.Plugins.FirstOrDefault(a => a.PluginClass == plugin); 57 | 58 | if(wrapper != null) 59 | { 60 | wrapper.Unload(); 61 | wrapper.Load(); 62 | } 63 | } 64 | #endregion 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /PointBlank/API/PointBlankConsole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace PointBlank.API 8 | { 9 | /// 10 | /// The server console functions for easier use of the console 11 | /// 12 | public static class PointBlankConsole 13 | { 14 | #region Variables 15 | private static ConsoleColor SavedColor = ConsoleColor.White; 16 | #endregion 17 | 18 | /// 19 | /// Writes a line in the console with custom color 20 | /// 21 | /// The text to write 22 | /// The color to use 23 | public static void WriteLine(object text, ConsoleColor color = ConsoleColor.White) 24 | { 25 | SavedColor = Console.ForegroundColor; 26 | Console.ForegroundColor = color; 27 | 28 | if (Console.CursorLeft != 0) 29 | ClearLine(); 30 | Console.WriteLine(text); 31 | Console.ForegroundColor = SavedColor; 32 | } 33 | 34 | /// 35 | /// Clears the console line 36 | /// 37 | public static void ClearLine() 38 | { 39 | Console.CursorLeft = 0; 40 | Console.Write(new string(' ', Console.BufferWidth)); 41 | Console.CursorTop--; 42 | Console.CursorLeft = 0; 43 | } 44 | 45 | /// 46 | /// Converts the console color to unity3d color and returns it 47 | /// 48 | /// The console color to use for the conversion 49 | /// The unity3d color 50 | public static Color ConsoleColorToColor(ConsoleColor color) 51 | { 52 | switch (color) 53 | { 54 | case ConsoleColor.Black: 55 | return Color.black; 56 | case ConsoleColor.Blue: 57 | return Color.blue; 58 | case ConsoleColor.Cyan: 59 | return Color.cyan; 60 | case ConsoleColor.DarkBlue: 61 | return new Color(0, 0, 139); 62 | case ConsoleColor.DarkCyan: 63 | return new Color(0, 139, 139); 64 | case ConsoleColor.DarkGray: 65 | return new Color(169, 169, 169); 66 | case ConsoleColor.DarkGreen: 67 | return new Color(0, 100, 0); 68 | case ConsoleColor.DarkMagenta: 69 | return new Color(139, 0, 139); 70 | case ConsoleColor.DarkRed: 71 | return new Color(139, 0, 0); 72 | case ConsoleColor.DarkYellow: 73 | return new Color(153, 153, 0); 74 | case ConsoleColor.Gray: 75 | return Color.gray; 76 | case ConsoleColor.Green: 77 | return Color.green; 78 | case ConsoleColor.Magenta: 79 | return Color.magenta; 80 | case ConsoleColor.Red: 81 | return Color.red; 82 | case ConsoleColor.White: 83 | return Color.white; 84 | case ConsoleColor.Yellow: 85 | return Color.yellow; 86 | default: 87 | return Color.white; 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /PointBlank/API/PointBlankLogging.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Diagnostics; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace PointBlank.API 9 | { 10 | /// 11 | /// Logging methods for PointBlank 12 | /// 13 | public static class PointBlankLogging 14 | { 15 | #region Info 16 | public static readonly string LogPath = Directory.GetCurrentDirectory() + "//PointBlank.log"; 17 | public static readonly string LogPathPrev = Directory.GetCurrentDirectory() + "//PointBlankOld.log"; 18 | #endregion 19 | 20 | static PointBlankLogging() 21 | { 22 | if (File.Exists(LogPathPrev)) 23 | File.Delete(LogPathPrev); 24 | if (File.Exists(LogPath)) 25 | File.Move(LogPath, LogPathPrev); 26 | } 27 | 28 | /// 29 | /// Logs text into the logs file and console 30 | /// 31 | /// Object/Text to log 32 | /// Should the text be printed into the console 33 | public static void Log(object log, bool inConsole = true) 34 | { 35 | StackTrace stack = new StackTrace(false); 36 | string asm = ""; 37 | 38 | try 39 | { 40 | asm = stack.FrameCount > 0 ? stack.GetFrame(1).GetMethod().DeclaringType.Assembly.GetName().Name : "Not Found"; 41 | 42 | if (stack.FrameCount > 1 && (asm == "PointBlank" || asm == "Assembly-CSharp" || asm == "UnityEngine")) 43 | asm = stack.GetFrame(2).GetMethod().DeclaringType.Assembly.GetName().Name; 44 | if (asm == "Assembly-CSharp" || asm == "UnityEngine") 45 | asm = "Game"; 46 | } 47 | catch (Exception ex) 48 | { 49 | asm = "Mono"; 50 | } 51 | 52 | log = "[LOG] " + asm + " >> " + log; 53 | File.AppendAllText(LogPath, log.ToString() + Environment.NewLine); 54 | if (inConsole) 55 | PointBlankConsole.WriteLine(log); 56 | } 57 | 58 | /// 59 | /// Logs an error into the logs file and console 60 | /// 61 | /// Object/Text to log 62 | /// Exception to log 63 | /// Should the exception show in the console 64 | /// Should the text be printed into the console 65 | public static void LogError(object log, Exception ex, bool exInConsole = false, bool inConsole = true) 66 | { 67 | StackTrace stack = new StackTrace(false); 68 | string asm = ""; 69 | 70 | try 71 | { 72 | asm = stack.FrameCount > 0 ? stack.GetFrame(1).GetMethod().DeclaringType.Assembly.GetName().Name : "Not Found"; 73 | 74 | if (stack.FrameCount > 1 && (asm == "PointBlank" || asm == "Assembly-CSharp" || asm == "UnityEngine")) 75 | asm = stack.GetFrame(2).GetMethod().DeclaringType.Assembly.GetName().Name; 76 | if (asm == "Assembly-CSharp" || asm == "UnityEngine") 77 | asm = "Game"; 78 | } 79 | catch (Exception exc) 80 | { 81 | asm = "Mono"; 82 | } 83 | 84 | log = "[ERROR] " + asm + " >> " + log; 85 | File.AppendAllText(LogPath, log.ToString() + Environment.NewLine); 86 | File.AppendAllText(LogPath, ex.ToString() + Environment.NewLine); 87 | if (inConsole) 88 | PointBlankConsole.WriteLine(log, ConsoleColor.Red); 89 | if (exInConsole) 90 | PointBlankConsole.WriteLine(ex, ConsoleColor.Red); 91 | } 92 | 93 | /// 94 | /// Logs a warning into the logs file and console 95 | /// 96 | /// Object/Text to log 97 | /// Should the text be printed into the console 98 | public static void LogWarning(object log, bool inConsole = true) 99 | { 100 | StackTrace stack = new StackTrace(false); 101 | string asm = ""; 102 | 103 | try 104 | { 105 | asm = stack.FrameCount > 0 ? stack.GetFrame(1).GetMethod().DeclaringType.Assembly.GetName().Name : "Not Found"; 106 | 107 | if (stack.FrameCount > 1 && (asm == "PointBlank" || asm == "Assembly-CSharp" || asm == "UnityEngine")) 108 | asm = stack.GetFrame(2).GetMethod().DeclaringType.Assembly.GetName().Name; 109 | if (asm == "Assembly-CSharp" || asm == "UnityEngine") 110 | asm = "Game"; 111 | } 112 | catch (Exception ex) 113 | { 114 | asm = "Mono"; 115 | } 116 | 117 | log = "[WARNING] " + asm + " >> " + log; 118 | File.AppendAllText(LogPath, log.ToString() + Environment.NewLine); 119 | if (inConsole) 120 | PointBlankConsole.WriteLine(log, ConsoleColor.Yellow); 121 | } 122 | 123 | /// 124 | /// Logs important text into the logs file and console 125 | /// 126 | /// Object/Text to log 127 | /// Should the text be printed into the console 128 | public static void LogImportant(object log, bool inConsole = true) 129 | { 130 | StackTrace stack = new StackTrace(false); 131 | string asm = ""; 132 | 133 | try 134 | { 135 | asm = stack.FrameCount > 0 ? stack.GetFrame(1).GetMethod().DeclaringType.Assembly.GetName().Name : "Not Found"; 136 | 137 | if (stack.FrameCount > 1 && (asm == "PointBlank" || asm == "Assembly-CSharp" || asm == "UnityEngine")) 138 | asm = stack.GetFrame(2).GetMethod().DeclaringType.Assembly.GetName().Name; 139 | if (asm == "Assembly-CSharp" || asm == "UnityEngine") 140 | asm = "Game"; 141 | } 142 | catch (Exception ex) 143 | { 144 | asm = "Mono"; 145 | } 146 | 147 | log = "[IMPORTANT] " + asm + " >> " + log; 148 | File.AppendAllText(LogPath, log.ToString() + Environment.NewLine); 149 | if (inConsole) 150 | PointBlankConsole.WriteLine(log, ConsoleColor.Cyan); 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /PointBlank/API/PointBlankTools.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Security.Permissions; 7 | using PointBlank.Framework.Permissions.Ring; 8 | using UnityEngine; 9 | 10 | namespace PointBlank.API 11 | { 12 | /// 13 | /// Contains methods that you need but aren't available by default 14 | /// 15 | [RingPermission(SecurityAction.Demand, ring = RingPermissionRing.None)] 16 | public static class PointBlankTools 17 | { 18 | #region Public Functions 19 | /// 20 | /// Generates a random string 21 | /// 22 | /// The length of the string 23 | /// A random string 24 | public static string RandomString() 25 | { 26 | string path = Path.GetRandomFileName(); 27 | path = path.Replace(".", ""); 28 | 29 | return path; 30 | } 31 | 32 | /// 33 | /// Emulates a foreach loop using the for loop. This is useful as the foreach loop is slower than a for loop 34 | /// 35 | /// The type of objects inside the array 36 | /// The array of objects to loop through 37 | /// The function to run 38 | public static void ForeachLoop(T[] array, Action functions) 39 | { 40 | for(int i = 0; i < array.Length; i++) 41 | functions(i, array[i]); 42 | } 43 | 44 | /// 45 | /// Emulates a foreach loop using the for loop. This is useful as the foreach loop is slower than a for loop 46 | /// 47 | /// The type of objects inside the list 48 | /// The list of objects to loop through 49 | /// The function to run 50 | public static void ForeachLoop(List list, Action functions) 51 | { 52 | for (int i = 0; i < list.Count; i++) 53 | functions(i, list[i]); 54 | } 55 | 56 | /// 57 | /// Gets the byte array of the string without using encoders 58 | /// 59 | /// The string to convert 60 | /// Byte array of the converted string 61 | public static byte[] GetBytes(string str) 62 | { 63 | byte[] bytes = new byte[str.Length * sizeof(char)]; 64 | 65 | Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); 66 | 67 | return bytes; 68 | } 69 | 70 | /// 71 | /// Gets the string of the byte array without using encoders 72 | /// 73 | /// The byte array to convert 74 | /// The converted string 75 | public static string GetString(byte[] bytes) 76 | { 77 | char[] chars = new char[bytes.Length / sizeof(char)]; 78 | 79 | Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length); 80 | 81 | return new string(chars); 82 | } 83 | 84 | /// 85 | /// Gets the string of the byte array with a specific length without using encoders 86 | /// 87 | /// The byte array to convert 88 | /// The length of the string 89 | /// The converted string 90 | public static string GetString(byte[] bytes, int length) 91 | { 92 | char[] chars = new char[length / sizeof(char)]; 93 | 94 | Buffer.BlockCopy(bytes, 0, chars, 0, length); 95 | 96 | return new string(chars); 97 | } 98 | 99 | /// 100 | /// Converts a float to a byte 101 | /// 102 | /// The float 103 | /// The output byte 104 | public static byte ToByte(float f) 105 | { 106 | f = Mathf.Clamp01(f); 107 | return (byte)(f * 255); 108 | } 109 | 110 | /// 111 | /// Converts the unix time to date time 112 | /// 113 | /// The unix time to convert 114 | /// The date time from the unix time 115 | public static DateTime FromUnixTime(long unix) 116 | { 117 | DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); 118 | return epoch.AddSeconds(unix).ToLocalTime(); 119 | } 120 | #endregion 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /PointBlank/API/Server/PointBlankServer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.API.Commands; 6 | 7 | namespace PointBlank.API.Server 8 | { 9 | /// 10 | /// All information about the server 11 | /// 12 | public static class PointBlankServer 13 | { 14 | #region Information 15 | /// 16 | /// The location of the server 17 | /// 18 | public static string ServerLocation { get; set; } 19 | /// 20 | /// The path of the mod loader saving location for everything 21 | /// 22 | public static string ModLoaderPath => ServerLocation + "/PointBlank"; 23 | 24 | /// 25 | /// The path to the libraries directory 26 | /// 27 | public static string LibrariesPath => ModLoaderPath + "/Libraries"; 28 | /// 29 | /// The path to the plugins directory 30 | /// 31 | public static string PluginsPath => ModLoaderPath + "/Plugins"; 32 | /// 33 | /// The path to the configurations directory 34 | /// 35 | public static string ConfigurationsPath => ModLoaderPath + "/Configurations"; 36 | /// 37 | /// The path to the translations directory 38 | /// 39 | public static string TranslationsPath => ModLoaderPath + "/Translations"; 40 | /// 41 | /// The path to the data directory 42 | /// 43 | public static string DataPath => ModLoaderPath + "/Data"; 44 | #endregion 45 | 46 | /// 47 | /// Is the server running 48 | /// 49 | public static bool IsRunning { get; set; } = false; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /PointBlank/API/Services/PointBlankService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using UnityEngine; 7 | 8 | namespace PointBlank.API.Services 9 | { 10 | /// 11 | /// Used to specify a service based class 12 | /// 13 | public abstract class PointBlankService : MonoBehaviour 14 | { 15 | #region Properties 16 | /// 17 | /// Can the service be replaced 18 | /// 19 | public bool Replacable => !Replace; 20 | 21 | /// 22 | /// The full name of the service 23 | /// 24 | public string FullName => this.GetType().Name + "." + Name; 25 | #endregion 26 | 27 | #region Virtual Properties 28 | /// 29 | /// The name of the service 30 | /// 31 | public virtual string Name => this.GetType().Name; 32 | 33 | /// 34 | /// Should the service be started on load 35 | /// 36 | public virtual bool AutoStart { get; set; } = true; 37 | 38 | /// 39 | /// Does the service replace an existing service 40 | /// 41 | public virtual bool Replace { get; set; } = false; 42 | 43 | /// 44 | /// The launch index specifies when the service is launched(the higher it is the slower it will launch) 45 | /// 46 | public virtual int LaunchIndex => 0; 47 | #endregion 48 | 49 | #region Abstract Functions 50 | /// 51 | /// Called when the service is loading 52 | /// 53 | public abstract void Load(); 54 | 55 | /// 56 | /// Called when the service is unloading 57 | /// 58 | public abstract void Unload(); 59 | #endregion 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /PointBlank/API/Services/PointBlankServiceEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Security.Permissions; 6 | using PointBlank.Framework.Permissions.Ring; 7 | 8 | namespace PointBlank.API.Services 9 | { 10 | /// 11 | /// All the service events 12 | /// 13 | [RingPermission(SecurityAction.Demand, ring = RingPermissionRing.None)] 14 | public static class PointBlankServiceEvents 15 | { 16 | #region Handlers 17 | /// 18 | /// Called when the service is being started 19 | /// 20 | /// The service 21 | public delegate void ServiceStartHandler(PointBlankService service); 22 | /// 23 | /// Called when the service is loaded/started 24 | /// 25 | /// The service 26 | public delegate void ServiceLoadedHandler(PointBlankService service); 27 | 28 | /// 29 | /// Called when the service is being stopped 30 | /// 31 | /// The service 32 | public delegate void ServiceStopHandler(PointBlankService service); 33 | /// 34 | /// Called when the service is unloaded/stopped 35 | /// 36 | /// THe service 37 | public delegate void ServiceUnloadedHandler(PointBlankService service); 38 | #endregion 39 | 40 | #region Events 41 | /// 42 | /// Called when the service is being started 43 | /// 44 | public static event ServiceStartHandler OnServiceStart; 45 | /// 46 | /// Called when the service is loaded/started 47 | /// 48 | public static event ServiceLoadedHandler OnServiceLoaded; 49 | 50 | /// 51 | /// Called when the service is being stopped 52 | /// 53 | public static event ServiceStopHandler OnServiceStop; 54 | /// 55 | /// Called when the service is unloaded/stopped 56 | /// 57 | public static event ServiceUnloadedHandler OnServiceUnloaded; 58 | #endregion 59 | 60 | #region Functions 61 | internal static void RunServiceStart(PointBlankService service) => OnServiceStart?.Invoke(service); 62 | 63 | internal static void RunServiceLoaded(PointBlankService service) => OnServiceLoaded?.Invoke(service); 64 | 65 | internal static void RunServiceStop(PointBlankService service) => OnServiceStop?.Invoke(service); 66 | 67 | internal static void RunServiceUnloaded(PointBlankService service) => OnServiceUnloaded?.Invoke(service); 68 | 69 | #endregion 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /PointBlank/API/Services/PointBlankServiceManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Services 7 | { 8 | /// 9 | /// The service manager class allows you to manage services at ease 10 | /// 11 | public static class PointBlankServiceManager 12 | { 13 | #region Properties 14 | /// 15 | /// Returns a list of the current running services 16 | /// 17 | public static string[] RunningServices => Enviroment.services.Where(a => a.Value.Enabled).Select(a => a.Key) as string[]; 18 | 19 | /// 20 | /// Returns a list of the current stopped services 21 | /// 22 | public static string[] StoppedServices => Enviroment.services.Where(a => !a.Value.Enabled).Select(a => a.Key) as string[]; 23 | 24 | /// 25 | /// Returns a list of all the current services 26 | /// 27 | public static string[] AllServices => Enviroment.services.Select(a => a.Key) as string[]; 28 | #endregion 29 | 30 | #region Functions 31 | /// 32 | /// Attempts to stop a running service 33 | /// 34 | /// The target service name 35 | /// If the service was successfully stopped 36 | public static bool StopService(string serviceName) => Enviroment.services[serviceName].Stop(); 37 | 38 | /// 39 | /// Attempts to start a stopped service 40 | /// 41 | /// The target service name 42 | /// If the service was successfully started 43 | public static bool StartService(string serviceName) => Enviroment.services[serviceName].Start(); 44 | 45 | /// 46 | /// Attempts to get the service by name and return the class 47 | /// 48 | /// The service name to query for 49 | /// The service class/instance 50 | public static PointBlankService GetService(string serviceName) => Enviroment.services[serviceName].ServiceClass; 51 | #endregion 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /PointBlank/API/Storage/Compressions/GZip.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.IO.Compression; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using PointBlank.API.Implements; 8 | 9 | namespace PointBlank.API.Storage.Compressions 10 | { 11 | internal static class GZip 12 | { 13 | #region Public Functions 14 | public static byte[] Zip(byte[] bytes) 15 | { 16 | using(MemoryStream memoryIn = new MemoryStream(bytes)) 17 | { 18 | using(MemoryStream memoryOut = new MemoryStream()) 19 | { 20 | using(GZipStream gzip = new GZipStream(memoryOut, CompressionMode.Compress)) 21 | memoryIn.CopyTo(gzip); 22 | 23 | return memoryOut.ToArray(); 24 | } 25 | } 26 | } 27 | 28 | public static byte[] UnZip(byte[] bytes) 29 | { 30 | using(MemoryStream memoryIn = new MemoryStream(bytes)) 31 | { 32 | using(MemoryStream memoryOut = new MemoryStream()) 33 | { 34 | using (GZipStream gzip = new GZipStream(memoryIn, CompressionMode.Decompress)) 35 | gzip.CopyTo(memoryOut); 36 | 37 | return memoryOut.ToArray(); 38 | } 39 | } 40 | } 41 | #endregion 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /PointBlank/API/Storage/Compressions/Huffman.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Storage.Compressions 7 | { 8 | internal static class Huffman 9 | { 10 | #region Public Functions 11 | public static byte[] Compress(string text) 12 | { 13 | List nodes = text.GroupBy(a => a).Select(a => new Node(a.Key, a.Count())).ToList(); 14 | int highestNumber = 0; 15 | 16 | while(highestNumber < text.Length || nodes.Count != 1) 17 | { 18 | nodes = nodes.OrderByDescending(a => a.Frequency).ToList(); 19 | Node[] temp = nodes.Where(a => !a.Used).ToArray(); 20 | Node left = temp[0]; 21 | Node right = temp[1]; 22 | Node parent = new Node(left.Frequency + right.Frequency, left, right); 23 | 24 | left.Parent = parent; 25 | right.Parent = parent; 26 | nodes.Add(parent); 27 | highestNumber = parent.Frequency; 28 | left.Used = true; 29 | right.Used = true; 30 | } 31 | 32 | return null; 33 | } 34 | 35 | public static byte[] Decompress(string text) 36 | { 37 | return null; 38 | } 39 | #endregion 40 | 41 | #region Private Functions 42 | private static string GenerateHeader(List nodes) 43 | { 44 | string header = ""; 45 | Node[] nodeArr = nodes.Where(a => a.Left == null && a.Right == null && a.Parent != null).ToArray(); ; 46 | 47 | header += (char)(nodes.Count * 2); // Header size 48 | foreach(Node node in nodes) 49 | { 50 | 51 | } 52 | 53 | return header; 54 | } 55 | #endregion 56 | 57 | #region Sub Classes 58 | private class Node 59 | { 60 | #region Properties 61 | public char Character { get; private set; } 62 | public int Frequency { get; private set; } 63 | 64 | public Node Left { get; set; } 65 | public Node Right { get; set; } 66 | public Node Parent { get; set; } 67 | public bool Used { get; set; } = false; 68 | #endregion 69 | 70 | public Node(char Character, int Frequency) 71 | { 72 | // Set the variables 73 | this.Character = Character; 74 | this.Frequency = Frequency; 75 | } 76 | 77 | public Node(int Frequency, Node Left, Node Right) 78 | { 79 | // Set the variables 80 | this.Frequency = Frequency; 81 | this.Left = Left; 82 | this.Right = Right; 83 | } 84 | } 85 | #endregion 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /PointBlank/API/Storage/ECompression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Storage 7 | { 8 | /// 9 | /// Types of compressions that can be used to compress your file 10 | /// 11 | public enum ECompression 12 | { 13 | /// 14 | /// Use no compression 15 | /// 16 | NONE, 17 | /// 18 | /// Use GZIP for compressing the file 19 | /// 20 | GZIP, 21 | /*/// 22 | /// Use the huffman algorithm to compress the file 23 | /// 24 | HUFFMAN, 25 | /// 26 | /// Check for similar words and convert them to bytes 27 | /// 28 | SIMILARITY, 29 | /// 30 | /// Use both Huffman and Similarity compressions 31 | /// 32 | DUAL*/ 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /PointBlank/API/Storage/PointBlankStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using PointBlank.API.Server; 7 | using PointBlank.API.Storage.Compressions; 8 | 9 | namespace PointBlank.API.Storage 10 | { 11 | /// 12 | /// Used for managing stored data 13 | /// 14 | public class PointBlankStorage 15 | { 16 | #region Properties 17 | /// 18 | /// The name of the file 19 | /// 20 | public string Name { get; private set; } 21 | /// 22 | /// The path to the file 23 | /// 24 | public string Path { get; private set; } 25 | /// 26 | /// The compression to be use 27 | /// 28 | public ECompression Compression { get; private set; } 29 | 30 | /// 31 | /// This is the compressed version of the file 32 | /// 33 | public byte[] File_Compressed { get; private set; } 34 | /// 35 | /// This is the raw version of the file 36 | /// 37 | public byte[] File_Decompressed { get; private set; } 38 | /// 39 | /// This is the file contents. Anything you write here will be written back to the file 40 | /// 41 | public string File_String { get; set; } 42 | #endregion 43 | 44 | /// 45 | /// Create storage to manage stored data 46 | /// 47 | /// The name of the storage/file 48 | /// The compression to use 49 | public PointBlankStorage(string name, ECompression compression) 50 | { 51 | // Set the variables 52 | Name = name; 53 | Path = PointBlankServer.DataPath + "/" + Name + ".dat"; 54 | Compression = compression; 55 | 56 | // Run the code 57 | if (File.Exists(Path)) 58 | Read(); 59 | } 60 | 61 | #region Private Functions 62 | private void Read() 63 | { 64 | switch (Compression) 65 | { 66 | case ECompression.GZIP: 67 | File_Compressed = File.ReadAllBytes(Path); 68 | File_Decompressed = GZip.UnZip(File_Compressed); 69 | break; 70 | default: 71 | File_Decompressed = File.ReadAllBytes(Path); 72 | break; 73 | } 74 | File_String = Encoding.Unicode.GetString(File_Decompressed); 75 | } 76 | #endregion 77 | 78 | #region Public Functions 79 | /// 80 | /// Compresses the data and writes it to the file 81 | /// 82 | public void Write() 83 | { 84 | if (!string.IsNullOrEmpty(File_String)) 85 | File_Decompressed = Encoding.Unicode.GetBytes(File_String); 86 | switch (Compression) 87 | { 88 | case ECompression.GZIP: 89 | File_Compressed = GZip.Zip(File_Decompressed); 90 | File.WriteAllBytes(Path, File_Compressed); 91 | break; 92 | default: 93 | File.WriteAllBytes(Path, File_Decompressed); 94 | break; 95 | } 96 | } 97 | #endregion 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /PointBlank/API/Tasks/PointBlankTask.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Diagnostics; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using PointBlank.Services.TaskManager; 8 | 9 | namespace PointBlank.API.Tasks 10 | { 11 | /// 12 | /// Used for tasking events and actions 13 | /// 14 | public class PointBlankTask // I won't lie I liked the one from uEssentials so I stole the idea 15 | { 16 | #region Properties 17 | /// 18 | /// Should the task be executed in a thread 19 | /// 20 | public bool IsThreaded { get; internal set; } 21 | /// 22 | /// Should the task be looped(milliseconds) 23 | /// 24 | public bool Loop { get; internal set; } 25 | /// 26 | /// The task delay 27 | /// 28 | public int Delay { get; internal set; } 29 | /// 30 | /// The code to be executed 31 | /// 32 | public Action Action { get; internal set; } 33 | 34 | /// 35 | /// Is the task running 36 | /// 37 | public bool Running { get; private set; } = false; 38 | /// 39 | /// The next time the code will be executed 40 | /// 41 | public DateTime NextExecution { get; internal set; } 42 | #endregion 43 | 44 | private PointBlankTask() 45 | { 46 | // Set the default properties 47 | IsThreaded = false; 48 | Loop = false; 49 | Delay = 1000; 50 | Action = (a => 51 | { 52 | // Do nothing 53 | }); 54 | } 55 | 56 | #region Static Functions 57 | /// 58 | /// Creates the task and returns it's instance 59 | /// 60 | /// The instance of the task 61 | public static Builder Create() 62 | { 63 | PointBlankTask task = new PointBlankTask(); 64 | 65 | return new Builder(task); 66 | } 67 | #endregion 68 | 69 | #region Functions 70 | /// 71 | /// Starts the task 72 | /// 73 | public void Start() 74 | { 75 | // Set the variables 76 | Running = true; 77 | NextExecution = DateTime.Now.AddMilliseconds(Delay); 78 | } 79 | /// 80 | /// Stops the task 81 | /// 82 | public void Stop() 83 | { 84 | // Set the variables 85 | Running = false; 86 | 87 | // Run the code 88 | TaskManager.Tasks.Remove(this); 89 | } 90 | 91 | /// 92 | /// Executes the task's code once 93 | /// 94 | public void Run() => Action(this); 95 | #endregion 96 | 97 | #region Sub Classes 98 | /// 99 | /// Used for building the tasks 100 | /// 101 | public class Builder 102 | { 103 | #region Properties 104 | /// 105 | /// The task instance that's being built 106 | /// 107 | public PointBlankTask Task { get; private set; } 108 | #endregion 109 | 110 | internal Builder(PointBlankTask task) 111 | { 112 | // Set the variables 113 | Task = task; 114 | } 115 | 116 | #region Functions 117 | /// 118 | /// Toggle threading of the task 119 | /// 120 | /// The builder instance 121 | public Builder Threaded() 122 | { 123 | Task.IsThreaded = !Task.IsThreaded; 124 | return this; 125 | } 126 | 127 | /// 128 | /// Toggle looping of the task 129 | /// 130 | /// The builder instance 131 | public Builder Loop() 132 | { 133 | Task.Loop = !Task.Loop; 134 | return this; 135 | } 136 | 137 | /// 138 | /// Time until task code gets executed 139 | /// 140 | /// The amount of time in milliseconds 141 | /// The builder instance 142 | public Builder Delay(int ms) 143 | { 144 | Task.Delay = ms; 145 | return this; 146 | } 147 | /// 148 | /// Time until task code gets executed 149 | /// 150 | /// The amount of time with TimeSpan instance 151 | /// The builder instance 152 | public Builder Delay(TimeSpan span) 153 | { 154 | Task.Delay = (int)span.TotalMilliseconds; 155 | return this; 156 | } 157 | 158 | /// 159 | /// Sets the task code that gets executed 160 | /// 161 | /// The code that gets executed 162 | /// The builder instance 163 | public Builder Action(Action action) 164 | { 165 | Task.Action = (a => action()); 166 | return this; 167 | } 168 | /// 169 | /// Sets the task code that gets executed 170 | /// 171 | /// The code that gets executed 172 | /// The builder instance 173 | public Builder Action(Action action) 174 | { 175 | Task.Action = action; 176 | return this; 177 | } 178 | 179 | /// 180 | /// Build the task and return it's instance 181 | /// 182 | /// Should the task be ran on build 183 | /// The task instance 184 | public PointBlankTask Build(bool AutoStart = false) 185 | { 186 | TaskManager.Tasks.Add(Task); 187 | 188 | if (AutoStart) 189 | Task.Start(); 190 | return Task; 191 | } 192 | #endregion 193 | } 194 | #endregion 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /PointBlank/Enviroment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.Framework.Objects; 6 | using PointBlank.Framework.Wrappers; 7 | using PointBlank.API.DataManagment; 8 | using PointBlank.Services.DetourManager; 9 | using PointBlank.API.Interfaces; 10 | using UnityEngine; 11 | 12 | namespace PointBlank 13 | { 14 | internal static class Enviroment // Yes I know it is spelled wrong but Environment already exists so we need to use the name 15 | { 16 | public static Dictionary services = new Dictionary(); // The list of services and their properties 17 | public static Dictionary runtimeObjects = new Dictionary(); // The list of runtime objects 18 | 19 | public static List SQLConnections = new List(); // The list of all the sql connections 20 | 21 | public static Dictionary FrameworkConfig = new Dictionary(); // Configuration for the framework 22 | public static Dictionary ServiceConfig = new Dictionary(); // Configuration for the services 23 | public static Dictionary ServiceTranslations = new Dictionary(); // Translations for the services 24 | 25 | public static bool Running = true; // Is pointblank running 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /PointBlank/Framework/Configurations/PointBlankConfigurations.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.API.Collections; 6 | using PointBlank.API.Interfaces; 7 | using PointBlank.API.DataManagment; 8 | 9 | namespace PointBlank.Framework.Configurations 10 | { 11 | internal class PointBlankConfigurations 12 | { 13 | public string ConfigurationDirectory => null; 14 | 15 | public ConfigurationList Configurations => new ConfigurationList() 16 | { 17 | //{ "ConfigFormat", EDataType.JSON } 18 | }; 19 | 20 | public Dictionary ConfigurationDictionary => Enviroment.FrameworkConfig; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /PointBlank/Framework/Objects/RuntimeObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace PointBlank.Framework.Objects 8 | { 9 | internal class RuntimeObject : MonoBehaviour 10 | { 11 | #region Properties 12 | public GameObject GameObject { get; private set; } // The instance of the gameobject 13 | public Dictionary CodeObjects { get; private set; } // The instances of the code objects/monobehaviour 14 | #endregion 15 | 16 | #region Entry Points 17 | public RuntimeObject() // Default everything 18 | { 19 | // Setup the variables 20 | GameObject = new GameObject(); 21 | CodeObjects = new Dictionary(); 22 | 23 | // Run the methods 24 | DontDestroyOnLoad(GameObject); 25 | } 26 | 27 | public RuntimeObject(GameObject gameObject) // Set the gameobject 28 | { 29 | // Setup the variables 30 | this.GameObject = gameObject; 31 | CodeObjects = new Dictionary(); 32 | 33 | // Run the methods 34 | DontDestroyOnLoad(gameObject); 35 | } 36 | 37 | public RuntimeObject(Dictionary codeObjects) // Set the codeobjects 38 | { 39 | // Setup the variables 40 | GameObject = new GameObject(); 41 | this.CodeObjects = codeObjects; 42 | 43 | // Run the methods 44 | DontDestroyOnLoad(GameObject); 45 | } 46 | 47 | public RuntimeObject(MonoBehaviour[] codeObjects) // Insert the codeobjects 48 | { 49 | // Setup the variables 50 | GameObject = new GameObject(); 51 | this.CodeObjects = new Dictionary(); 52 | 53 | // Run important code 54 | for (int i = 0; i < codeObjects.Length; i++) 55 | this.CodeObjects.Add(codeObjects[i].GetType().Name, codeObjects[i]); 56 | 57 | // Run the methods 58 | DontDestroyOnLoad(GameObject); 59 | } 60 | 61 | public RuntimeObject(GameObject gameObject, Dictionary codeObjects) // Set the gameobject and the codeobject 62 | { 63 | // Setup the variables 64 | this.GameObject = gameObject; 65 | this.CodeObjects = codeObjects; 66 | 67 | // Run the methods 68 | DontDestroyOnLoad(gameObject); 69 | } 70 | 71 | public RuntimeObject(GameObject gameObject, MonoBehaviour[] codeObjects) // Set the gameobject and insert the code objects 72 | { 73 | // Setup the variables 74 | this.GameObject = new GameObject(); 75 | this.CodeObjects = new Dictionary(); 76 | 77 | // Run important code 78 | for (int i = 0; i < codeObjects.Length; i++) 79 | this.CodeObjects.Add(codeObjects[i].GetType().Name, codeObjects[i]); 80 | 81 | // Run the methods 82 | DontDestroyOnLoad(gameObject); 83 | } 84 | #endregion 85 | 86 | #region Functions 87 | public MonoBehaviour AddCodeObject() where T : MonoBehaviour // For adding the code object 88 | { 89 | MonoBehaviour comp = (MonoBehaviour)GameObject.AddComponent(); 90 | 91 | CodeObjects.Add(comp.GetType().Name, comp); 92 | return comp; 93 | } 94 | 95 | public MonoBehaviour AddCodeObject(Type t) // For adding the code object 96 | { 97 | MonoBehaviour comp = (MonoBehaviour)GameObject.AddComponent(t); 98 | 99 | CodeObjects.Add(comp.GetType().Name, comp); 100 | return comp; 101 | } 102 | 103 | public void RemoveCodeObject(string name) // For removing code objects 104 | { 105 | GameObject.Destroy(CodeObjects[name]); 106 | CodeObjects.Remove(name); 107 | } 108 | 109 | public void RemoveCodeObject() where T : MonoBehaviour // For removing code objects 110 | { 111 | MonoBehaviour comp = GetCodeObject(); 112 | 113 | GameObject.Destroy(comp); 114 | CodeObjects.Remove(comp.GetType().Name); 115 | } 116 | 117 | public T GetCodeObject() where T : MonoBehaviour => (T)CodeObjects.First(a => a.Value.GetType() == typeof(T)).Value; // Returns code object 118 | 119 | public MonoBehaviour GetCodeObject(string name) => CodeObjects[name]; // Returns code object 120 | #endregion 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /PointBlank/Framework/Permissions/Ring/RingPermission.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Security; 6 | using System.Security.Permissions; 7 | using PointBlank.API.Implements; 8 | 9 | namespace PointBlank.Framework.Permissions.Ring 10 | { 11 | [Serializable] 12 | internal sealed class RingPermission : CodeAccessPermission, IUnrestrictedPermission 13 | { 14 | #region Variables 15 | private RingPermissionRing _ring; 16 | #endregion 17 | 18 | #region Properties 19 | public RingPermissionRing ring 20 | { 21 | get => _ring; 22 | set 23 | { 24 | VerifyRing(value); 25 | _ring = value; 26 | } 27 | } 28 | #endregion 29 | 30 | public RingPermission(PermissionState state) 31 | { 32 | switch (state) 33 | { 34 | case PermissionState.None: 35 | SetUnrestricted(false); 36 | return; 37 | case PermissionState.Unrestricted: 38 | SetUnrestricted(true); 39 | return; 40 | } 41 | throw new ArgumentException("Invalid permission state!"); 42 | } 43 | 44 | public RingPermission(RingPermissionRing ringFlag) 45 | { 46 | VerifyRing(ringFlag); 47 | _ring = ringFlag; 48 | } 49 | 50 | #region IUnrestrictedPermission Functions 51 | public bool IsUnrestricted() => (_ring == RingPermissionRing.Framework); 52 | #endregion 53 | 54 | #region CodeAccessPermission Functions 55 | public override bool IsSubsetOf(IPermission target) 56 | { 57 | if (target == null) 58 | return (_ring == RingPermissionRing.None); 59 | 60 | RingPermission ringPermissions = (RingPermission)target; 61 | 62 | if (ringPermissions.IsUnrestricted()) 63 | return true; 64 | else if (IsUnrestricted()) 65 | return false; 66 | else 67 | return isAllowed(ringPermissions); 68 | } 69 | 70 | public override IPermission Intersect(IPermission target) 71 | { 72 | if (target == null) 73 | return null; 74 | 75 | RingPermission ringPermissions = (RingPermission)target; 76 | RingPermissionRing ringPermissionsRing = (_ring < ringPermissions.ring ? _ring : ringPermissions.ring); 77 | 78 | return ringPermissionsRing == RingPermissionRing.None ? null : new RingPermission(ringPermissionsRing); 79 | } 80 | 81 | public override IPermission Union(IPermission target) 82 | { 83 | if (target == null) 84 | return Copy(); 85 | 86 | RingPermission ringPermissions = (RingPermission)target; 87 | RingPermissionRing ringPermissionsRing = (_ring < ringPermissions.ring ? _ring : ringPermissions.ring); 88 | 89 | return ringPermissionsRing == RingPermissionRing.None ? null : new RingPermission(ringPermissionsRing); 90 | } 91 | 92 | public override IPermission Copy() => new RingPermission(_ring); 93 | 94 | public override SecurityElement ToXml() 95 | { 96 | SecurityElement element = new SecurityElement("IPermission"); 97 | Type type = GetType(); 98 | StringBuilder sb = new StringBuilder(type.Assembly.ToString()); 99 | 100 | sb.Replace('\"', '\''); 101 | element.AddAttribute("class", type.FullName + ", " + sb); 102 | element.AddAttribute("version", "1"); 103 | if (!IsUnrestricted()) 104 | { 105 | if (_ring != RingPermissionRing.None) 106 | element.AddAttribute("Ring", Enum.GetName(typeof(RingPermission), _ring)); 107 | } 108 | else 109 | { 110 | element.AddAttribute("Unrestricted", "true"); 111 | } 112 | return element; 113 | } 114 | 115 | public override void FromXml(SecurityElement elem) 116 | { 117 | string eUnrestricted = elem.Attribute("Unrestricted"); 118 | string eRing = elem.Attribute("Ring"); 119 | 120 | if (eUnrestricted != null) 121 | SetUnrestricted(Convert.ToBoolean(eUnrestricted)); 122 | if (eRing != null) 123 | _ring = (RingPermissionRing)Enum.Parse(typeof(RingPermissionRing), eRing); 124 | } 125 | #endregion 126 | 127 | #region Private Functions 128 | private void SetUnrestricted(bool unrestricted) 129 | { 130 | if(unrestricted) 131 | ring = RingPermissionRing.Framework; 132 | } 133 | 134 | private void VerifyRing(RingPermissionRing ring) 135 | { 136 | if (ring < RingPermissionRing.None || ring > RingPermissionRing.Framework) 137 | throw new ArgumentException("Invalid ring!"); 138 | } 139 | 140 | private bool isAllowed(RingPermission rp) 141 | { 142 | if (_ring == RingPermissionRing.None) 143 | return true; 144 | return rp.ring != RingPermissionRing.None && rp.ring.HasFlag(_ring); 145 | } 146 | #endregion 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /PointBlank/Framework/Permissions/Ring/RingPermissionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Security.Permissions; 6 | using System.Security; 7 | 8 | namespace PointBlank.Framework.Permissions.Ring 9 | { 10 | [Serializable] 11 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Enum, AllowMultiple = false)] 12 | internal class RingPermissionAttribute : CodeAccessSecurityAttribute 13 | { 14 | #region Properties 15 | public RingPermissionRing ring { get; set; } 16 | #endregion 17 | 18 | public RingPermissionAttribute(SecurityAction action) : base(action) 19 | { 20 | } 21 | 22 | #region CodeAccessSecurityAttribute Functions 23 | public override IPermission CreatePermission() 24 | { 25 | return Unrestricted ? new RingPermission(PermissionState.Unrestricted) : new RingPermission(ring); 26 | } 27 | #endregion 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /PointBlank/Framework/Permissions/Ring/RingPermissionRing.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.Framework.Permissions.Ring 7 | { 8 | [Flags] 9 | [Serializable] 10 | internal enum RingPermissionRing 11 | { 12 | None = 1, 13 | Plugins = 2, 14 | Mods = 4, 15 | Extensions = 8, 16 | Framework = 16 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /PointBlank/Framework/Translations/ServiceTranslations.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.API.Collections; 6 | using PointBlank.API.Interfaces; 7 | 8 | namespace PointBlank.Framework.Translations 9 | { 10 | internal class ServiceTranslations : ITranslatable 11 | { 12 | public string TranslationDirectory => ""; 13 | 14 | public TranslationList Translations => new TranslationList() 15 | { 16 | // CommandManager 17 | { "CommandManager_Invalid", "Invalid command! Use the help command to get the list of commands!" }, 18 | { "CommandManager_NotEnoughPermissions", "You do not have enough permissions to execute this command!" }, 19 | 20 | // CommandWrapper 21 | { "CommandWrapper_Arguments", "Not enough arguments!" }, 22 | { "CommandWrapper_Cooldown", "This command currently has a cooldown!" }, 23 | { "CommandWrapper_NotConsole", "This command can only be executed from the console!" }, 24 | { "CommandWrapper_NotPlayer", "This command can only be executed by a player!" }, 25 | { "CommandWrapper_NotRunning", "This command can only be executed while the server is running!" }, 26 | { "CommandWrapper_Running", "This command can only be executed while the server is loading!" } 27 | }; 28 | 29 | public Dictionary TranslationDictionary => Enviroment.ServiceTranslations; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /PointBlank/Framework/Wrappers/ServiceWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PointBlank.API.Services; 6 | using PointBlank.API; 7 | 8 | namespace PointBlank.Framework.Wrappers 9 | { 10 | internal class ServiceWrapper 11 | { 12 | #region Properties 13 | public bool Enabled { get; private set; } // Is the service running 14 | public PointBlankService ServiceClass { get; private set; } // The service class 15 | #endregion 16 | 17 | public ServiceWrapper(PointBlankService ServiceClass) 18 | { 19 | // Setup variables 20 | this.ServiceClass = ServiceClass; 21 | 22 | // Setup data 23 | Enviroment.services.Add(ServiceClass.GetType().Name + "." + ServiceClass.Name, this); // Add the service 24 | 25 | // Run functions 26 | if (ServiceClass.AutoStart) 27 | Start(); 28 | } 29 | 30 | #region Functions 31 | public bool Start() 32 | { 33 | if (Enabled) // Don't run if it is already running 34 | return true; 35 | 36 | PointBlankLogging.Log("Starting service: " + ServiceClass.Name); 37 | 38 | // Call the important functions 39 | try 40 | { 41 | PointBlankServiceEvents.RunServiceStart(ServiceClass); // Run the pre-run event 42 | ServiceClass.Load(); // Run the code 43 | PointBlankServiceEvents.RunServiceLoaded(ServiceClass); // Run the post-run event 44 | } 45 | catch (Exception ex) 46 | { 47 | PointBlankLogging.LogError("Error when starting service: " + ServiceClass.Name, ex); 48 | } 49 | 50 | // Set the variables 51 | Enabled = true; 52 | 53 | PointBlankLogging.Log("Started service: " + ServiceClass.Name); 54 | return true; 55 | } 56 | 57 | public bool Stop() 58 | { 59 | if (!Enabled) // Don't stop if it isn't running 60 | return true; 61 | 62 | PointBlankLogging.Log("Stopping service: " + ServiceClass.Name); 63 | 64 | // Call the important functions 65 | try 66 | { 67 | PointBlankServiceEvents.RunServiceStop(ServiceClass); // Run the pre-stop event 68 | ServiceClass.Unload(); // Run the code 69 | PointBlankServiceEvents.RunServiceUnloaded(ServiceClass); // Run the post-stop event 70 | } 71 | catch (Exception ex) 72 | { 73 | PointBlankLogging.LogError("Error when stopping service: " + ServiceClass.Name, ex); 74 | } 75 | 76 | // Set the variables 77 | Enabled = false; 78 | 79 | PointBlankLogging.Log("Stopped service: " + ServiceClass.Name); 80 | return true; 81 | } 82 | #endregion 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /PointBlank/PointBlank.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Reflection; 5 | using System.Net.Security; 6 | using System.Collections.Generic; 7 | using System.Security.Cryptography.X509Certificates; 8 | using System.Linq; 9 | using System.Text; 10 | using PointBlank.API; 11 | using UnityEngine; 12 | using PointBlank.Framework.Objects; 13 | using PointBlank.Framework; 14 | using PointBlank.API.DataManagment; 15 | using PointBlank.API.Interfaces; 16 | using PointBlank.Services.PluginManager; 17 | using Newtonsoft.Json.Linq; 18 | using PointBlank.API.Collections; 19 | 20 | namespace PointBlank 21 | { 22 | public class PointBlank 23 | { 24 | #region Properties 25 | public static PointBlank Instance { get; private set; } // Self instance 26 | public static bool Enabled { get; private set; } // Is PointBlank running 27 | #endregion 28 | 29 | #region Loader Functions 30 | public void Initialize() 31 | { 32 | if (!Environment.GetCommandLineArgs().Contains("-pointblank")) // Don't run if this isn't a server or if the -pointblank argument wasn't added 33 | return; 34 | if (Instance != null && Enabled) // Don't run if already running 35 | return; 36 | 37 | PointBlankLogging.LogImportant("Loading " + PointBlankInfo.Name + " v" + PointBlankInfo.Version + "..."); 38 | 39 | // Run required methods 40 | ApplyPatches(); 41 | 42 | // Setup the runtime objects 43 | Enviroment.runtimeObjects.Add("Framework", new RuntimeObject(new GameObject("Framework"))); 44 | Enviroment.runtimeObjects.Add("Extensions", new RuntimeObject(new GameObject("Extensions"))); 45 | Enviroment.runtimeObjects.Add("Services", new RuntimeObject(new GameObject("Services"))); 46 | Enviroment.runtimeObjects.Add("Plugins", new RuntimeObject(new GameObject("Plugins"))); 47 | 48 | // Add the code objects 49 | Enviroment.runtimeObjects["Framework"].AddCodeObject(); // Both the service manager and interface manager are important without them 50 | Enviroment.runtimeObjects["Framework"].AddCodeObject(); // the modloader won't be able to function properly making it as usefull as Rocket 51 | 52 | // Run the inits 53 | Enviroment.runtimeObjects["Framework"].GetCodeObject().Init(); 54 | Enviroment.runtimeObjects["Framework"].GetCodeObject().Init(); 55 | 56 | // Run required methods 57 | RunRequirements(); 58 | 59 | // Initialize 60 | Instance = this; 61 | Enabled = true; 62 | #if !DEBUG 63 | Console.Clear(); 64 | #endif 65 | 66 | PointBlankLogging.LogImportant("Loaded " + PointBlankInfo.Name + " v" + PointBlankInfo.Version + "!"); 67 | } 68 | 69 | public void Shutdown() 70 | { 71 | if (!Environment.GetCommandLineArgs().Contains("-pointblank")) // Don't shutdown if this isn't a server or if the -pointblank argument wasn't added 72 | return; 73 | if (Instance == null || !Enabled) // Don't shutdown if it is not running 74 | return; 75 | 76 | PointBlankLogging.LogImportant("Shutting down " + PointBlankInfo.Name + " v" + PointBlankInfo.Version + "..."); 77 | 78 | // Uninit 79 | Enabled = false; 80 | Instance = null; 81 | 82 | // Run the shutdowns 83 | Enviroment.runtimeObjects["Framework"].GetCodeObject().Shutdown(); 84 | Enviroment.runtimeObjects["Framework"].GetCodeObject().Shutdown(); 85 | 86 | // Remove the runtime objects 87 | Enviroment.runtimeObjects["Framework"].RemoveCodeObject(); 88 | Enviroment.runtimeObjects["Framework"].RemoveCodeObject(); 89 | 90 | // Remove the runtime objects 91 | Enviroment.runtimeObjects.Remove("Plugins"); 92 | Enviroment.runtimeObjects.Remove("Services"); 93 | Enviroment.runtimeObjects.Remove("Extensions"); 94 | Enviroment.runtimeObjects.Remove("Framework"); 95 | 96 | // Run the required functions 97 | RunRequirementsShutdown(); 98 | 99 | PointBlankLogging.LogImportant("Shut down " + PointBlankInfo.Name + " v" + PointBlankInfo.Version + "!"); 100 | } 101 | #endregion 102 | 103 | #region Functions 104 | private void ApplyPatches() => new I18N.West.CP1250(); 105 | 106 | private void RunRequirements() 107 | { 108 | // Need to add something here 109 | } 110 | 111 | private void RunRequirementsShutdown() 112 | { 113 | Enviroment.Running = false; 114 | foreach(SQLData sql in Enviroment.SQLConnections.Where(a => a.Connected)) 115 | sql.Disconnect(); 116 | } 117 | #endregion 118 | 119 | #region Event Functions 120 | internal static bool ValidateCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors) => (errors == SslPolicyErrors.None); 121 | #endregion 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /PointBlank/PointBlank.csproj.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | CSharp70 -------------------------------------------------------------------------------- /PointBlank/PointBlankInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using System.Diagnostics; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace PointBlank 10 | { 11 | /// 12 | /// All information about PointBlank can be found here 13 | /// 14 | public static class PointBlankInfo 15 | { 16 | #region Private Info 17 | private static Assembly pbAssembly = Assembly.GetExecutingAssembly(); 18 | private static FileVersionInfo pbFileVersionInfo = FileVersionInfo.GetVersionInfo(pbAssembly.Location); 19 | #endregion 20 | 21 | #region Public Info 22 | /// 23 | /// The name of the program 24 | /// 25 | public static readonly string Name = pbFileVersionInfo.ProductName; 26 | /// 27 | /// The creator of the program 28 | /// 29 | public static readonly string Creator = pbFileVersionInfo.CompanyName; 30 | /// 31 | /// The version of the program 32 | /// 33 | public static readonly string Version = pbFileVersionInfo.ProductVersion; 34 | /// 35 | /// The description of the program 36 | /// 37 | public static readonly string Description = pbFileVersionInfo.FileDescription; 38 | /// 39 | /// Is the program in debug release 40 | /// 41 | public static readonly bool IsDebug = pbFileVersionInfo.IsDebug; 42 | /// 43 | /// The directory of pointblank 44 | /// 45 | public static readonly string Location = Path.GetDirectoryName(Uri.UnescapeDataString((new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path))); 46 | #endregion 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /PointBlank/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PointBlank")] 9 | [assembly: AssemblyDescription("PointBlank is an Unturned modding API that allows for easier creation of mods")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("AtiLion")] 12 | [assembly: AssemblyProduct("PointBlank")] 13 | [assembly: AssemblyCopyright("Copyright © AtiLion 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0788fc32-724c-40cd-9652-54929d16ff43")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: PointBlank.API.Extension.PointBlankExtension] 38 | -------------------------------------------------------------------------------- /PointBlank/Services/CommandManager/CommandWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using PointBlank.API; 7 | using PointBlank.API.Commands; 8 | using CMD = PointBlank.API.Commands.PointBlankCommand; 9 | using Newtonsoft.Json.Linq; 10 | using UnityEngine; 11 | using PointBlank.Framework.Translations; 12 | using PointBlank.API.Collections; 13 | using PointBlank.API.Player; 14 | using PointBlank.API.Server; 15 | 16 | namespace PointBlank.Services.CommandManager 17 | { 18 | internal class CommandWrapper 19 | { 20 | #region Variables 21 | private TranslationList Translations; 22 | #endregion 23 | 24 | #region Properties 25 | public Type Class { get; private set; } 26 | public JObject Config { get; private set; } 27 | 28 | public CMD CommandClass { get; private set; } 29 | 30 | public string[] Commands { get; private set; } 31 | public string Permission { get; private set; } 32 | public int Cooldown { get; private set; } 33 | public bool Enabled { get; private set; } 34 | #endregion 35 | 36 | public CommandWrapper(Type _class, JObject config) 37 | { 38 | // Set the variables 39 | this.Class = _class; 40 | this.Config = config; 41 | 42 | // Setup the variables 43 | CommandClass = (CMD)Activator.CreateInstance(Class); 44 | Translations = Enviroment.ServiceTranslations[typeof(ServiceTranslations)].Translations; 45 | 46 | // Run the code 47 | Reload(); 48 | 49 | PointBlankLogging.Log("Loaded command: " + Commands[0]); 50 | } 51 | 52 | #region Public Functions 53 | public void Enable() 54 | { 55 | Enabled = true; 56 | PointBlankCommandEvents.RunCommandEnable(CommandClass); 57 | } 58 | 59 | public void Disable() 60 | { 61 | Enabled = false; 62 | PointBlankCommandEvents.RunCommandDisable(CommandClass); 63 | } 64 | 65 | public void Reload() 66 | { 67 | string name = Class.Assembly.GetName().Name + "." + Class.Name; 68 | if (Config["Name"] == null) 69 | { 70 | Config["Name"] = name; 71 | Config["Commands"] = JToken.FromObject(CommandClass.DefaultCommands); 72 | Config["Permission"] = CommandClass.DefaultPermission; 73 | Config["Cooldown"] = CommandClass.DefaultCooldown; 74 | Config["Enabled"] = Enabled; 75 | 76 | Commands = CommandClass.DefaultCommands; 77 | Permission = CommandClass.DefaultPermission; 78 | Cooldown = CommandClass.DefaultCooldown; 79 | Enabled = true; 80 | } 81 | else 82 | { 83 | Commands = Config["Commands"].ToObject(); 84 | Permission = (string)Config["Permission"]; 85 | Cooldown = (int)Config["Cooldown"]; 86 | Enabled = (bool)Config["Enabled"]; 87 | } 88 | } 89 | 90 | public void Save() => Config["Enabled"] = Enabled; 91 | 92 | public ECommandRunError Execute(PointBlankPlayer executor, string[] args) 93 | { 94 | try 95 | { 96 | if (CommandClass.AllowedServerState == EAllowedServerState.LOADING && PointBlankServer.IsRunning) 97 | { 98 | PointBlankPlayer.SendMessage(executor, Translations["CommandWrapper_Running"], ConsoleColor.Red); 99 | return ECommandRunError.SERVER_RUNNING; 100 | } 101 | if (CommandClass.AllowedServerState == EAllowedServerState.RUNNING && !PointBlankServer.IsRunning) 102 | { 103 | PointBlankPlayer.SendMessage(executor, Translations["CommandWrapper_NotRunning"], ConsoleColor.Red); 104 | return ECommandRunError.SERVER_LOADING; 105 | } 106 | if (CommandClass.AllowedCaller == EAllowedCaller.SERVER && executor != null) 107 | { 108 | executor.SendMessage(Translations["CommandWrapper_NotConsole"], Color.red); 109 | return ECommandRunError.NOT_CONSOLE; 110 | } 111 | if (CommandClass.AllowedCaller == EAllowedCaller.PLAYER && executor == null) 112 | { 113 | executor.SendMessage(Translations["CommandWrapper_NotPlayer"], Color.red); 114 | return ECommandRunError.NOT_PLAYER; 115 | } 116 | if (CommandClass.MinimumParams > args.Length) 117 | { 118 | PointBlankPlayer.SendMessage(executor, Translations["CommandWrapper_Arguments"], ConsoleColor.Red); 119 | return ECommandRunError.ARGUMENT_COUNT; 120 | } 121 | if(executor != null && executor.HasCooldown(CommandClass)) 122 | { 123 | executor.SendMessage(Translations["CommandWrapper_Cooldown"], Color.red); 124 | return ECommandRunError.COOLDOWN; 125 | } 126 | bool shouldExecute = true; 127 | 128 | PointBlankCommandEvents.RunCommandExecute(CommandClass, args, executor, ref shouldExecute); 129 | if (!shouldExecute) return ECommandRunError.NO_EXECUTE; 130 | executor?.SetCooldown(CommandClass, DateTime.Now); 131 | CommandClass.Execute(executor, args); 132 | return ECommandRunError.NONE; 133 | } 134 | catch (Exception ex) 135 | { 136 | PointBlankLogging.LogError("Error when running command: " + Class.Name, ex); 137 | return ECommandRunError.EXCEPTION; 138 | } 139 | } 140 | #endregion 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /PointBlank/Services/DetourManager/DetourManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using PointBlank.API; 7 | using PointBlank.API.Plugins; 8 | using PointBlank.API.Services; 9 | using PointBlank.API.Detour; 10 | using PointBlank.API.Extension; 11 | 12 | namespace PointBlank.Services.DetourManager 13 | { 14 | internal class DetourManager : PointBlankService 15 | { 16 | #region Variables 17 | private static Dictionary _Detours = new Dictionary(); // Dictionary of detours 18 | #endregion 19 | 20 | #region Properties 21 | public static Dictionary Detours => _Detours; // The public detours 22 | 23 | public bool Initialized { get; private set; } = false; // Is the detour manager initialized 24 | 25 | public override int LaunchIndex => 0; 26 | #endregion 27 | 28 | public override void Load() 29 | { 30 | if (Initialized) 31 | return; 32 | 33 | // Set the events 34 | PointBlankPluginEvents.OnPluginLoaded += OnPluginLoaded; 35 | PointBlankPluginEvents.OnPluginUnloaded += OnPluginUnloaded; 36 | 37 | // Main code 38 | foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies().Where(a => Attribute.GetCustomAttribute(a, typeof(PointBlankExtensionAttribute)) != null)) 39 | foreach (Type tClass in asm.GetTypes()) 40 | if (tClass.IsClass) 41 | foreach(MethodInfo method in tClass.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance)) 42 | LoadDetour(method); 43 | 44 | // Set the variables 45 | Initialized = true; 46 | } 47 | 48 | public override void Unload() 49 | { 50 | if (!Initialized) 51 | return; 52 | 53 | // Unload the events 54 | PointBlankPluginEvents.OnPluginLoaded -= OnPluginLoaded; 55 | PointBlankPluginEvents.OnPluginUnloaded -= OnPluginUnloaded; 56 | 57 | // Main code 58 | while(Detours.Count > 0) 59 | { 60 | DetourAttribute att = Detours.Keys.ElementAt(0); 61 | 62 | Detours[att].Revert(); 63 | Detours.Remove(att); 64 | } 65 | 66 | // Set the variables 67 | Initialized = false; 68 | } 69 | 70 | #region Public Functions 71 | public void LoadDetour(MethodInfo method) 72 | { 73 | // Setup variables 74 | DetourAttribute attribute = (DetourAttribute)Attribute.GetCustomAttribute(method, typeof(DetourAttribute)); 75 | 76 | // Do checks 77 | if (attribute == null) 78 | return; 79 | if (!attribute.MethodFound) 80 | return; 81 | if (Detours.Count(a => a.Key.Method == attribute.Method) > 0) 82 | return; 83 | 84 | try 85 | { 86 | DetourWrapper wrapper = new DetourWrapper(attribute.Method, method, attribute); 87 | 88 | wrapper.Detour(); 89 | 90 | Detours.Add(attribute, wrapper); 91 | } 92 | catch (Exception ex) 93 | { 94 | PointBlankLogging.LogError("Error detouring: " + method.Name, ex); 95 | } 96 | } 97 | #endregion 98 | 99 | #region Event Functions 100 | private void OnPluginLoaded(PointBlankPlugin plugin) 101 | { 102 | foreach(Type tClass in plugin.GetType().Assembly.GetTypes()) 103 | if (tClass.IsClass) 104 | foreach (MethodInfo method in tClass.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance)) 105 | LoadDetour(method); 106 | } 107 | 108 | private void OnPluginUnloaded(PointBlankPlugin plugin) 109 | { 110 | foreach(KeyValuePair kvp in Detours.Where(a => a.Key.Method.DeclaringType.Assembly == plugin.GetType().Assembly && !a.Value.Local)) 111 | { 112 | kvp.Value.Revert(); 113 | Detours.Remove(kvp.Key); 114 | } 115 | } 116 | #endregion 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /PointBlank/Services/DetourManager/DetourWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Diagnostics; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using PointBlank.API; 8 | using PointBlank.API.Detour; 9 | 10 | namespace PointBlank.Services.DetourManager 11 | { 12 | internal class DetourWrapper 13 | { 14 | #region Properties 15 | public MethodInfo Original { get; private set; } 16 | public MethodInfo Modified { get; private set; } 17 | 18 | public IntPtr ptrOriginal { get; private set; } 19 | public IntPtr ptrModified { get; private set; } 20 | 21 | public RedirectionHelper.OffsetBackup OffsetBackup { get; private set; } 22 | public DetourAttribute Attribute { get; private set; } 23 | 24 | public bool Detoured { get; private set; } 25 | public object Instance { get; private set; } 26 | public bool Local { get; private set; } 27 | #endregion 28 | 29 | public DetourWrapper(MethodInfo original, MethodInfo modified, DetourAttribute attribute, object instance = null) 30 | { 31 | // Set the variables 32 | Original = original; 33 | Modified = modified; 34 | Instance = instance; 35 | Attribute = attribute; 36 | Local = (Modified.DeclaringType.Assembly == Assembly.GetExecutingAssembly()); 37 | 38 | ptrOriginal = Original.MethodHandle.GetFunctionPointer(); 39 | ptrModified = Modified.MethodHandle.GetFunctionPointer(); 40 | 41 | OffsetBackup = new RedirectionHelper.OffsetBackup(ptrOriginal); 42 | Detoured = false; 43 | } 44 | 45 | #region Public Functions 46 | public bool Detour() 47 | { 48 | if (Detoured) 49 | return true; 50 | bool result = RedirectionHelper.DetourFunction(ptrOriginal, ptrModified); 51 | 52 | if(result) 53 | Detoured = true; 54 | 55 | return result; 56 | } 57 | 58 | public bool Revert() 59 | { 60 | if (!Detoured) 61 | return false; 62 | bool result = RedirectionHelper.RevertDetour(OffsetBackup); 63 | 64 | if(result) 65 | Detoured = false; 66 | 67 | return result; 68 | } 69 | 70 | public object CallOriginal(object[] args, object instance = null) 71 | { 72 | Revert(); 73 | object result = null; 74 | try 75 | { 76 | result = Original.Invoke(instance ?? Instance, args); 77 | } 78 | catch (Exception ex) 79 | { 80 | PointBlankLogging.LogError("Error when attempting to run original method!", ex); 81 | } 82 | 83 | Detour(); 84 | return result; 85 | } 86 | #endregion 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /PointBlank/Services/DetourManager/RedirectionHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | Copyright (c) 2015 Sebastian Schöner 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 18 | THE SOFTWARE. 19 | */ 20 | 21 | using System; 22 | using System.Reflection; 23 | using System.Collections.Generic; 24 | using System.Runtime.InteropServices; 25 | using System.Linq; 26 | using System.Text; 27 | using PointBlank.API; 28 | 29 | namespace PointBlank.Services.DetourManager 30 | { 31 | internal class RedirectionHelper 32 | { 33 | #region Public Functions 34 | public static bool DetourFunction(IntPtr ptrOriginal, IntPtr ptrModified) 35 | { 36 | try 37 | { 38 | switch (IntPtr.Size) 39 | { 40 | case sizeof(Int32): 41 | unsafe 42 | { 43 | byte* ptrFrom = (byte*)ptrOriginal.ToPointer(); 44 | 45 | *(ptrFrom + 1) = 0xBB; 46 | *((uint*)(ptrFrom + 2)) = (uint)ptrModified.ToInt32(); 47 | *(ptrFrom + 11) = 0xFF; 48 | *(ptrFrom + 12) = 0xE3; 49 | } 50 | break; 51 | case sizeof(Int64): 52 | unsafe 53 | { 54 | byte* ptrFrom = (byte*)ptrOriginal.ToPointer(); 55 | 56 | *ptrFrom = 0x49; 57 | *(ptrFrom + 1) = 0xBB; 58 | *((ulong*)(ptrFrom + 2)) = (ulong)ptrModified.ToInt64(); 59 | *(ptrFrom + 10) = 0x41; 60 | *(ptrFrom + 11) = 0xFF; 61 | *(ptrFrom + 12) = 0xE3; 62 | } 63 | break; 64 | default: 65 | return false; 66 | } 67 | 68 | return true; 69 | } 70 | catch (Exception ex) 71 | { 72 | PointBlankLogging.LogError("Error adding detour!", ex); 73 | return false; 74 | } 75 | } 76 | 77 | public static bool RevertDetour(OffsetBackup backup) 78 | { 79 | try 80 | { 81 | unsafe 82 | { 83 | byte* ptrOriginal = (byte*)backup.Method.ToPointer(); 84 | 85 | *ptrOriginal = backup.A; 86 | *(ptrOriginal + 1) = backup.B; 87 | *(ptrOriginal + 10) = backup.C; 88 | *(ptrOriginal + 11) = backup.D; 89 | *(ptrOriginal + 12) = backup.E; 90 | if (IntPtr.Size == sizeof(Int32)) 91 | *((uint*)(ptrOriginal + 2)) = backup.F32; 92 | else 93 | *((ulong*)(ptrOriginal + 2)) = backup.F64; 94 | } 95 | 96 | return true; 97 | } 98 | catch (Exception ex) 99 | { 100 | PointBlankLogging.LogError("Error reverting detour!", ex); 101 | return false; 102 | } 103 | } 104 | #endregion 105 | 106 | #region SubClasses 107 | internal class OffsetBackup 108 | { 109 | #region Variables 110 | public IntPtr Method; 111 | 112 | public byte A, B, C, D, E; 113 | public ulong F64; 114 | public uint F32; 115 | #endregion 116 | 117 | public OffsetBackup(IntPtr method) 118 | { 119 | Method = method; 120 | 121 | unsafe 122 | { 123 | byte* ptrMethod = (byte*)method.ToPointer(); 124 | 125 | A = *ptrMethod; 126 | B = *(ptrMethod + 1); 127 | C = *(ptrMethod + 10); 128 | D = *(ptrMethod + 11); 129 | E = *(ptrMethod + 12); 130 | if (IntPtr.Size == sizeof(Int32)) 131 | F32 = *((uint*)(ptrMethod + 2)); 132 | else 133 | F64 = *((ulong*)(ptrMethod + 2)); 134 | } 135 | } 136 | } 137 | #endregion 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /PointBlank/Services/IPCManager/IPCManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using PointBlank.API; 8 | using PointBlank.API.Services; 9 | using PointBlank.API.IPC; 10 | using IPCM = PointBlank.API.IPC.IPCManager; 11 | 12 | namespace PointBlank.Services.IPCManager 13 | { 14 | internal class IPCManager : PointBlankService 15 | { 16 | #region Info 17 | public static readonly string FileLocation = Directory.GetCurrentDirectory() + "/IPC.ipc"; 18 | #endregion 19 | 20 | #region Variables 21 | private bool _Update = false; 22 | private bool _Running = true; 23 | private Thread _FileUpdaterThread; 24 | #endregion 25 | 26 | #region Properties 27 | public static Dictionary IPC { get; } = new Dictionary(); 28 | 29 | public override int LaunchIndex => 1; 30 | #endregion 31 | 32 | public override void Load() 33 | { 34 | if (File.Exists(FileLocation)) 35 | File.Delete(FileLocation); 36 | 37 | // Setup the thread 38 | _FileUpdaterThread = new Thread(new ThreadStart(UpdateFile)); 39 | _FileUpdaterThread.Start(); 40 | 41 | // Setup the events 42 | IPCEvents.OnKeyValueChanged += new IPCEvents.KeyValueChangedHandler(OnKeySet); 43 | IPCEvents.OnKeyRemoved += new IPCEvents.KeyListChangedHandler(OnKeyUpdated); 44 | IPCEvents.OnKeyAdded += new IPCEvents.KeyListChangedHandler(OnKeyUpdated); 45 | } 46 | 47 | public override void Unload() 48 | { 49 | _Running = false; 50 | _FileUpdaterThread.Abort(); 51 | File.Delete(FileLocation); 52 | } 53 | 54 | #region Private Functions 55 | private void UpdateFile() 56 | { 57 | while(_Running) 58 | { 59 | if (!_Update || IPCM.IPCType != EIPCType.FILE) 60 | continue; 61 | List contents = new List(); 62 | 63 | foreach (string key in IPC.Keys) 64 | contents.Add(key + ":" + IPC[key]); 65 | 66 | try 67 | { 68 | File.WriteAllLines(FileLocation, contents.ToArray()); 69 | _Update = false; 70 | } 71 | #pragma warning disable CS0168 // Variable is declared but never used 72 | catch (Exception ex) 73 | #pragma warning restore CS0168 // Variable is declared but never used 74 | { 75 | Thread.Sleep(1); 76 | } 77 | } 78 | } 79 | #endregion 80 | 81 | #region Event Functions 82 | public static void OnOutput(string text) 83 | { 84 | if (IPCM.IPCType == EIPCType.CONSOLE) 85 | PointBlankConsole.WriteLine("0x0:" + text); 86 | } 87 | 88 | private void OnKeySet(string key, string value) 89 | { 90 | if (IPCM.IPCType == EIPCType.CONSOLE) 91 | PointBlankConsole.WriteLine("0x1:" + key + ":" + value); 92 | else if (IPCM.IPCType == EIPCType.FILE) 93 | _Update = true; 94 | } 95 | 96 | private void OnKeyUpdated(string key) 97 | { 98 | if (IPCM.IPCType == EIPCType.CONSOLE) 99 | PointBlankConsole.WriteLine("0x1:" + key + ":" + IPC[key]); 100 | else if (IPCM.IPCType == EIPCType.FILE) 101 | _Update = true; 102 | } 103 | #endregion 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /PointBlank/Services/PluginManager/PluginConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.Services.PluginManager 7 | { 8 | internal static class PluginConfiguration 9 | { 10 | public static bool ContinueOnError; 11 | public static bool AutoUpdate; 12 | public static bool NotifyUpdates; 13 | public static int CheckUpdateTimeSeconds; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /PointBlank/Services/PluginManager/PluginManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using PointBlank.API; 8 | using PointBlank.API.Server; 9 | using PointBlank.API.Plugins; 10 | using PointBlank.API.Services; 11 | using PointBlank.API.DataManagment; 12 | using SM = PointBlank.Framework.ServiceManager; 13 | 14 | namespace PointBlank.Services.PluginManager 15 | { 16 | internal class PluginManager : PointBlankService 17 | { 18 | #region Info 19 | public static readonly string ConfigurationPath = PointBlankServer.ConfigurationsPath + "/Plugins"; // Set the plugins configuration path 20 | public static readonly string TranslationPath = PointBlankServer.TranslationsPath + "/Plugins"; 21 | #endregion 22 | 23 | #region Variables 24 | private static List _plugins = new List(); // List of plugins 25 | private static List _libraries = new List(); // List of libraries 26 | #endregion 27 | 28 | #region Properties 29 | public static PluginWrapper[] Plugins => _plugins.ToArray(); // Returns the plugins 30 | 31 | public static Assembly[] Libraries => _libraries.ToArray(); // Returns the libraries 32 | 33 | public UniversalData UniConfig { get; private set; } // The universal config data 34 | public JsonData JSONConfig { get; private set; } // The JSON config data 35 | 36 | public override int LaunchIndex => 3; 37 | #endregion 38 | 39 | public override void Load() 40 | { 41 | if (!Directory.Exists(PointBlankServer.LibrariesPath)) 42 | Directory.CreateDirectory(PointBlankServer.LibrariesPath); // Create libraries directory 43 | if (!Directory.Exists(PointBlankServer.PluginsPath)) 44 | Directory.CreateDirectory(PointBlankServer.PluginsPath); // Create plugins directory 45 | if (!Directory.Exists(ConfigurationPath)) 46 | Directory.CreateDirectory(ConfigurationPath); // Create plugins directory 47 | if (!Directory.Exists(TranslationPath)) 48 | Directory.CreateDirectory(TranslationPath); // Create plugins directory 49 | 50 | // Setup the config 51 | UniConfig = new UniversalData(SM.ConfigurationPath + "\\PluginManager"); 52 | JSONConfig = UniConfig.GetData(EDataType.JSON) as JsonData; 53 | LoadConfig(); 54 | 55 | foreach (string library in Directory.GetFiles(PointBlankServer.LibrariesPath, "*.dll")) // Get all the dll files in libraries directory 56 | _libraries.Add(Assembly.Load(File.ReadAllBytes(library))); // Load and add the library 57 | foreach (string plugin in Directory.GetFiles(PointBlankServer.PluginsPath, "*.dll")) // Get all the dll files in plugins directory 58 | { 59 | try 60 | { 61 | PluginWrapper wrapper = new PluginWrapper(plugin); // Create the plugin wrapper 62 | 63 | _plugins.Add(wrapper); // Add the wrapper 64 | if (!wrapper.Load() && !PluginConfiguration.ContinueOnError) 65 | break; 66 | } 67 | catch (Exception ex) 68 | { 69 | PointBlankLogging.LogError("Error initializing plugin!", ex); 70 | if (!PluginConfiguration.ContinueOnError) 71 | break; 72 | } 73 | } 74 | PointBlankPluginEvents.RunPluginsLoaded(); 75 | } 76 | 77 | public override void Unload() 78 | { 79 | foreach (PluginWrapper wrapper in _plugins) 80 | wrapper.Unload(); // Unload the wrapper 81 | PointBlankPluginEvents.RunPluginsUnloaded(); 82 | SaveConfig(); 83 | } 84 | 85 | #region Public Functions 86 | public PluginWrapper GetWrapper(PointBlankPlugin plugin) => Plugins.First(a => a.PluginClass == plugin); 87 | #endregion 88 | 89 | #region Private Functions 90 | internal void LoadConfig() 91 | { 92 | if (UniConfig.CreatedNew) 93 | { 94 | PluginConfiguration.AutoUpdate = false; 95 | PluginConfiguration.ContinueOnError = true; 96 | PluginConfiguration.NotifyUpdates = true; 97 | PluginConfiguration.CheckUpdateTimeSeconds = 1800; 98 | 99 | JSONConfig.Document.Add("AutoUpdate", (PluginConfiguration.AutoUpdate ? "true" : "false")); 100 | JSONConfig.Document.Add("ContinueOnError", (PluginConfiguration.ContinueOnError ? "true" : "false")); 101 | JSONConfig.Document.Add("NotifyUpdates", (PluginConfiguration.NotifyUpdates ? "true" : "false")); 102 | JSONConfig.Document.Add("CheckUpdateTimeSeconds", PluginConfiguration.CheckUpdateTimeSeconds.ToString()); 103 | UniConfig.Save(); 104 | } 105 | else 106 | { 107 | JSONConfig.Verify(new Dictionary() 108 | { 109 | { "AutoUpdate", "false" }, 110 | { "ContinueOnError", "true" }, 111 | { "NotifyUpdates", "true" }, 112 | { "CheckUpdateTimeSeconds", "1800" } 113 | }); 114 | 115 | PluginConfiguration.AutoUpdate = ((string)JSONConfig.Document["AutoUpdate"] == "true"); 116 | PluginConfiguration.ContinueOnError = ((string)JSONConfig.Document["ContinueOnError"] == "true"); 117 | PluginConfiguration.NotifyUpdates = ((string)JSONConfig.Document["NotifyUpdates"] == "true"); 118 | PluginConfiguration.CheckUpdateTimeSeconds = int.Parse((string)JSONConfig.Document["CheckUpdateTimeSeconds"]); 119 | } 120 | } 121 | 122 | internal void SaveConfig() => UniConfig.Save(); 123 | #endregion 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /PointBlank/Services/TaskManager/TaskManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Reflection; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using PointBlank.API; 8 | using PointBlank.API.Services; 9 | using PointBlank.API.Tasks; 10 | using PointBlank.API.Plugins; 11 | 12 | namespace PointBlank.Services.TaskManager 13 | { 14 | internal class TaskManager : PointBlankService 15 | { 16 | #region Variables 17 | private Thread _tTasker; 18 | private Queue _Remove = new Queue(); 19 | 20 | private bool _Running = false; 21 | #endregion 22 | 23 | #region Properties 24 | public static List Tasks { get; private set; } 25 | 26 | public override int LaunchIndex => 2; 27 | #endregion 28 | 29 | public override void Load() 30 | { 31 | // Set the variables 32 | Tasks = new List(); 33 | _tTasker = new Thread(new ThreadStart(Tasker)); 34 | _Running = true; 35 | 36 | // Run the code 37 | _tTasker.Start(); 38 | } 39 | 40 | public override void Unload() 41 | { 42 | // Set the variables 43 | _Running = false; 44 | } 45 | 46 | #region Threads 47 | private void Tasker() 48 | { 49 | while (_Running) 50 | { 51 | Thread.Sleep(1); 52 | 53 | if (Tasks.Count < 1) 54 | continue; 55 | foreach (PointBlankTask task in Tasks) 56 | { 57 | if (!task.Running) 58 | continue; 59 | if (!task.IsThreaded) 60 | continue; 61 | if (task.NextExecution == null) 62 | continue; 63 | 64 | if ((DateTime.Now - task.NextExecution).TotalMilliseconds >= 0) 65 | { 66 | task.Run(); 67 | 68 | if (!task.Loop) 69 | _Remove.Enqueue(task); 70 | } 71 | } 72 | } 73 | } 74 | #endregion 75 | 76 | #region Mono Functions 77 | void Update() 78 | { 79 | if (!_Running) 80 | return; 81 | 82 | if (Tasks.Count < 1) 83 | return; 84 | foreach (PointBlankTask task in Tasks) 85 | { 86 | if (!task.Running) 87 | continue; 88 | if (task.IsThreaded) 89 | continue; 90 | if (task.NextExecution == null) 91 | continue; 92 | 93 | if ((DateTime.Now - task.NextExecution).TotalMilliseconds >= 0) 94 | { 95 | task.Run(); 96 | 97 | if (!task.Loop) 98 | _Remove.Enqueue(task); 99 | } 100 | } 101 | 102 | lock (Tasks) 103 | { 104 | lock (_Remove) 105 | { 106 | while (_Remove.Count > 0) 107 | _Remove.Dequeue().Stop(); 108 | } 109 | } 110 | } 111 | #endregion 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /PointBlank/Services/UpdateChecker/UpdateChecker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using PointBlank.API; 7 | using PointBlank.API.Services; 8 | using PointBlank.API.DataManagment; 9 | using Newtonsoft.Json.Linq; 10 | 11 | namespace PointBlank.Services.UpdateChecker 12 | { 13 | internal class UpdateChecker : PointBlankService 14 | { 15 | #region Info 16 | public static readonly string URL = "http://pastebin.com/raw/ZVcNXEVw"; 17 | #endregion 18 | 19 | #region Variables 20 | private Thread tChecker; 21 | 22 | private bool Running = true; 23 | #endregion 24 | 25 | #region Properties 26 | public override int LaunchIndex => 0; 27 | #endregion 28 | 29 | public override void Load() 30 | { 31 | // Setup the variables 32 | tChecker = new Thread(new ThreadStart(CheckUpdates)); 33 | 34 | // Run the code 35 | tChecker.Start(); 36 | } 37 | 38 | public override void Unload() 39 | { 40 | Running = false; 41 | tChecker.Abort(); 42 | } 43 | 44 | #region Thread Functions 45 | private void CheckUpdates() 46 | { 47 | while (Running) 48 | { 49 | Thread.Sleep(300000); // Check every 5 minutes 50 | if (WebsiteData.GetData(URL, out string data)) 51 | { 52 | JObject info = JObject.Parse(data); 53 | 54 | if ((string)info["PointBlank_Version"] == "0") // Ignore if no version 55 | continue; 56 | if ((string)info["PointBlank_Version"] != PointBlankInfo.Version) 57 | PointBlankLogging.LogImportant("A new update is available for PointBlank!"); 58 | } 59 | } 60 | } 61 | #endregion 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /PointBlankSecurity/API/License/LicenseVerifier.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Collections.Generic; 4 | using System.Collections.Specialized; 5 | using System.Linq; 6 | using System.Text; 7 | using PointBlank.API.DataManagment; 8 | using PointBlank.API.Security; 9 | 10 | namespace PointBlank.API.License 11 | { 12 | /// 13 | /// Allows you to easily verify the license of your plugin 14 | /// 15 | public static class LicenseVerifier 16 | { 17 | #region Functions 18 | public static bool VerifyLicense(string file, string website, EHashType hash = EHashType.NONE) 19 | { 20 | if (!File.Exists(file)) 21 | return false; 22 | string response = "false"; 23 | 24 | switch (hash) 25 | { 26 | case EHashType.MD5: 27 | WebsiteData.PostData(website, new NameValueCollection() { { "License", Hashing.CalculateMD5String(File.ReadAllBytes(file)) } }, out response); 28 | break; 29 | case EHashType.SHA1: 30 | WebsiteData.PostData(website, new NameValueCollection() { { "License", Hashing.CalculateSHA1String(File.ReadAllBytes(file)) } }, out response); 31 | break; 32 | case EHashType.SHA256: 33 | WebsiteData.PostData(website, new NameValueCollection() { { "License", Hashing.CalculateSHA256String(File.ReadAllBytes(file)) } }, out response); 34 | break; 35 | case EHashType.SHA512: 36 | WebsiteData.PostData(website, new NameValueCollection() { { "License", Hashing.CalculateSHA512String(File.ReadAllBytes(file)) } }, out response); 37 | break; 38 | default: 39 | if (WebsiteData.UploadFile(website, file, out byte[] data)) 40 | response = Encoding.UTF8.GetString(data); 41 | break; 42 | } 43 | 44 | if (response == "true") 45 | return true; 46 | else 47 | return false; 48 | } 49 | 50 | public static bool VerifyLicense(byte[] bytes, string website, EHashType hash = EHashType.NONE) 51 | { 52 | string response = "false"; 53 | 54 | switch (hash) 55 | { 56 | case EHashType.MD5: 57 | WebsiteData.PostData(website, new NameValueCollection() { { "License", Hashing.CalculateMD5String(bytes) } }, out response); 58 | break; 59 | case EHashType.SHA1: 60 | WebsiteData.PostData(website, new NameValueCollection() { { "License", Hashing.CalculateSHA1String(bytes) } }, out response); 61 | break; 62 | case EHashType.SHA256: 63 | WebsiteData.PostData(website, new NameValueCollection() { { "License", Hashing.CalculateSHA256String(bytes) } }, out response); 64 | break; 65 | case EHashType.SHA512: 66 | WebsiteData.PostData(website, new NameValueCollection() { { "License", Hashing.CalculateSHA512String(bytes) } }, out response); 67 | break; 68 | default: 69 | WebsiteData.PostData(website, new NameValueCollection() { { "License", Encoding.UTF8.GetString(bytes) } }, out response); 70 | break; 71 | } 72 | 73 | if (response == "true") 74 | return true; 75 | else 76 | return false; 77 | } 78 | #endregion 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /PointBlankSecurity/API/Security/EHashType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PointBlank.API.Security 7 | { 8 | /// 9 | /// All supported hashing types 10 | /// 11 | public enum EHashType 12 | { 13 | NONE, 14 | MD5, 15 | SHA1, 16 | SHA256, 17 | SHA512 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /PointBlankSecurity/API/Security/Hashing.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Security.Cryptography; 6 | 7 | namespace PointBlank.API.Security 8 | { 9 | /// 10 | /// Used for easier hashing so you won't have to make it yourself 11 | /// 12 | public static class Hashing 13 | { 14 | #region MD5 15 | 16 | /// 17 | /// Calculate the MD5 hash from a string and return the hash in string format 18 | /// 19 | /// The string to hash using MD5 20 | /// The MD5 hash of the string 21 | [Obsolete("MD5 is highly insecure and should be avoided wherever possible", false)] 22 | public static string CalculateMD5String(string input) => CalculateMD5String(Encoding.UTF8.GetBytes(input)); 23 | /// 24 | /// Calculate the MD5 hash from a byte array and return the hash in string format 25 | /// 26 | /// The byte array to hash using MD5 27 | /// The MD5 hash of the byte array 28 | [Obsolete("MD5 is highly insecure and should be avoided wherever possible", false)] 29 | public static string CalculateMD5String(byte[] bytes) => BitConverter.ToString(CalculateMD5Bytes(bytes)).Replace("-", string.Empty).ToLower(); 30 | 31 | /// 32 | /// Calculate the MD5 hash from a string and return the hash in byte array format 33 | /// 34 | /// The string to hash using MD5 35 | /// The MD5 hash of the string 36 | [Obsolete("MD5 is highly insecure and should be avoided wherever possible", false)] 37 | public static byte[] CalculateMD5Bytes(string input) => CalculateMD5Bytes(Encoding.UTF8.GetBytes(input)); 38 | /// 39 | /// Calculate the MD5 hash from a byte array and return the hash in byte array format 40 | /// 41 | /// The byte array to hash using MD5 42 | /// The MD5 hash of the byte array 43 | [Obsolete("MD5 is highly insecure and should be avoided wherever possible", false)] 44 | public static byte[] CalculateMD5Bytes(byte[] bytes) => ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(bytes); 45 | #endregion 46 | 47 | #region SHA1 48 | [Obsolete("SHA1 is prone to collisions and should be avoided if possible", false)] 49 | public static string CalculateSHA1String(string input) => CalculateSHA1String(Encoding.UTF8.GetBytes(input)); 50 | [Obsolete("SHA1 is prone to collisions and should be avoided if possible", false)] 51 | public static string CalculateSHA1String(byte[] bytes) => string.Join("", CalculateSHA1Bytes(bytes).Select(a => a.ToString("x2")).ToArray()); 52 | 53 | [Obsolete("SHA1 is prone to collisions and should be avoided if possible", false)] 54 | public static byte[] CalculateSHA1Bytes(string input) => CalculateSHA1Bytes(Encoding.UTF8.GetBytes(input)); 55 | [Obsolete("SHA1 is prone to collisions and should be avoided if possible", false)] 56 | public static byte[] CalculateSHA1Bytes(byte[] bytes) 57 | { 58 | using(SHA1Managed sha1 = new SHA1Managed()) 59 | return sha1.ComputeHash(bytes); 60 | } 61 | #endregion 62 | 63 | #region SHA256 64 | public static string CalculateSHA256String(string input) => CalculateSHA256String(Encoding.UTF8.GetBytes(input)); 65 | public static string CalculateSHA256String(byte[] bytes) => string.Join("", CalculateSHA256Bytes(bytes).Select(a => a.ToString("x2")).ToArray()); 66 | 67 | public static byte[] CalculateSHA256Bytes(string input) => CalculateSHA256Bytes(Encoding.UTF8.GetBytes(input)); 68 | public static byte[] CalculateSHA256Bytes(byte[] bytes) 69 | { 70 | using (SHA256 sha256 = SHA256Managed.Create()) 71 | return sha256.ComputeHash(bytes); 72 | } 73 | #endregion 74 | 75 | #region SHA512 76 | public static string CalculateSHA512String(string input) => CalculateSHA512String(Encoding.UTF8.GetBytes(input)); 77 | public static string CalculateSHA512String(byte[] bytes) => string.Join("", CalculateSHA512Bytes(bytes).Select(a => a.ToString("x2")).ToArray()); 78 | 79 | public static byte[] CalculateSHA512Bytes(string input) => CalculateSHA512Bytes(Encoding.UTF8.GetBytes(input)); 80 | public static byte[] CalculateSHA512Bytes(byte[] bytes) 81 | { 82 | using (SHA512 sha512 = SHA512Managed.Create()) 83 | return sha512.ComputeHash(bytes); 84 | } 85 | #endregion 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /PointBlankSecurity/PointBlankSecurity.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1D66EA7A-036C-4C75-AF4A-1D89F7DE91A4} 8 | Library 9 | Properties 10 | PointBlank 11 | PointBlankSecurity 12 | v3.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | ..\bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | ..\bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | true 34 | 35 | 36 | PointBlank.pfx 37 | 38 | 39 | 40 | False 41 | ..\bin\Debug\PointBlank.dll 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /PointBlankSecurity/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PointBlankSecurity")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("AtiLion")] 12 | [assembly: AssemblyProduct("PointBlankSecurity")] 13 | [assembly: AssemblyCopyright("Copyright © AtiLion 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1d66ea7a-036c-4c75-af4a-1d89f7de91a4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: PointBlank.API.Extension.PointBlankExtension] 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PointBlank 2 | The pointblank framework for unturned 3 | 4 | # Testing instructions 5 | 1. Install the PointBlank folder from the Modules into Unturned/Modules 6 | 2. Compile the PointBlank dll 7 | 3. Copy the PointBlank dll into Unturned/Modules/PointBlank 8 | 4. Make sure you start the server with -pointblank in the arguments 9 | 5. Done! 10 | --------------------------------------------------------------------------------