├── .gitignore ├── LICENSE ├── README.md ├── appveyor.yml ├── doc ├── Doxyfile └── README.md ├── examples ├── AHK │ ├── gta_world.ahk │ ├── health_overlay.ahk │ ├── remote_player.ahk │ ├── samp_functions.ahk │ └── weapon_functions.ahk └── C++ │ └── OverlayExample │ ├── OverlayExample.sln │ └── OverlayExample │ ├── OverlayExample.vcxproj │ ├── OverlayExample.vcxproj.filters │ └── main.cpp ├── include ├── AHK │ └── SAMP_API.ahk ├── C# │ └── SAMP_API.cs ├── C++ │ └── SAMP_API.h └── generate.py ├── src ├── Open-SAMP-API.sln └── Open-SAMP-API │ ├── Client │ ├── Client.cpp │ ├── Client.hpp │ ├── GTAFunctions.cpp │ ├── GTAFunctions.hpp │ ├── GTAStructs.hpp │ ├── MemoryFunctions.cpp │ ├── MemoryFunctions.hpp │ ├── PlayerFunctions.cpp │ ├── PlayerFunctions.hpp │ ├── RenderFunctions.cpp │ ├── RenderFunctions.hpp │ ├── SAMPFunctions.cpp │ ├── SAMPFunctions.hpp │ ├── VehicleFunctions.cpp │ ├── VehicleFunctions.hpp │ ├── WeaponFunctions.cpp │ └── WeaponFunctions.hpp │ ├── Game │ ├── GTA │ │ ├── World.cpp │ │ └── World.hpp │ ├── Game.cpp │ ├── Game.hpp │ ├── Messagehandler.cpp │ ├── Messagehandler.hpp │ ├── Rendering │ │ ├── Box.cpp │ │ ├── Box.hpp │ │ ├── D3DFont.cpp │ │ ├── D3DFont.hpp │ │ ├── Image.cpp │ │ ├── Image.hpp │ │ ├── Line.cpp │ │ ├── Line.hpp │ │ ├── RenderBase.cpp │ │ ├── RenderBase.hpp │ │ ├── Renderer.cpp │ │ ├── Renderer.hpp │ │ ├── Text.cpp │ │ ├── Text.hpp │ │ ├── dx_utils.cpp │ │ └── dx_utils.hpp │ └── SAMP │ │ ├── PatternTable.hpp │ │ ├── RemotePlayer.cpp │ │ ├── RemotePlayer.hpp │ │ ├── SAMP.cpp │ │ └── SAMP.hpp │ ├── Open-SAMP-API.vcxproj │ ├── Open-SAMP-API.vcxproj.filters │ ├── Shared │ ├── Config.hpp │ └── PipeMessages.hpp │ ├── Utils │ ├── D3DX9 │ │ ├── d3d9.h │ │ ├── d3d9caps.h │ │ ├── d3d9types.h │ │ ├── d3dx9.h │ │ ├── d3dx9.lib │ │ ├── d3dx9anim.h │ │ ├── d3dx9core.h │ │ ├── d3dx9effect.h │ │ ├── d3dx9math.h │ │ ├── d3dx9math.inl │ │ ├── d3dx9mesh.h │ │ ├── d3dx9shader.h │ │ ├── d3dx9shape.h │ │ ├── d3dx9tex.h │ │ └── d3dx9xof.h │ ├── Detours │ │ ├── detours.h │ │ ├── detours.lib │ │ └── detours.pdb │ ├── Hook.hpp │ ├── Memory.cpp │ ├── Memory.hpp │ ├── Module.cpp │ ├── Module.hpp │ ├── NakedHook.cpp │ ├── NakedHook.hpp │ ├── Pattern.cpp │ ├── Pattern.hpp │ ├── PipeClient.cpp │ ├── PipeClient.hpp │ ├── PipeServer.cpp │ ├── PipeServer.hpp │ ├── Process.cpp │ ├── Process.hpp │ ├── SafeBlock.hpp │ ├── Serializer.cpp │ ├── Serializer.hpp │ ├── Windows.hpp │ └── algorithm.hpp │ ├── dllmain.cpp │ ├── dllmain.hpp │ └── packages.config └── test └── AHK ├── classes ├── DefaultPrintAdapter.ahk ├── GamePrintAdapter.ahk ├── PrintAdapter.ahk └── TestBase.ahk ├── test.ahk └── tests ├── OverlayFunctions.ahk └── SAMPFunctions.ahk /.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 | *.appx 187 | 188 | # Visual Studio cache files 189 | # files ending in .cache can be ignored 190 | *.[Cc]ache 191 | # but keep track of directories ending in .cache 192 | !*.[Cc]ache/ 193 | 194 | # Others 195 | ClientBin/ 196 | ~$* 197 | *~ 198 | *.dbmdl 199 | *.dbproj.schemaview 200 | *.jfm 201 | *.pfx 202 | *.publishsettings 203 | orleans.codegen.cs 204 | 205 | # Since there are multiple workflows, uncomment next line to ignore bower_components 206 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 207 | #bower_components/ 208 | 209 | # RIA/Silverlight projects 210 | Generated_Code/ 211 | 212 | # Backup & report files from converting an old project file 213 | # to a newer Visual Studio version. Backup files are not needed, 214 | # because we have git ;-) 215 | _UpgradeReport_Files/ 216 | Backup*/ 217 | UpgradeLog*.XML 218 | UpgradeLog*.htm 219 | 220 | # SQL Server files 221 | *.mdf 222 | *.ldf 223 | *.ndf 224 | 225 | # Business Intelligence projects 226 | *.rdl.data 227 | *.bim.layout 228 | *.bim_*.settings 229 | 230 | # Microsoft Fakes 231 | FakesAssemblies/ 232 | 233 | # GhostDoc plugin setting file 234 | *.GhostDoc.xml 235 | 236 | # Node.js Tools for Visual Studio 237 | .ntvs_analysis.dat 238 | node_modules/ 239 | 240 | # Typescript v1 declaration files 241 | typings/ 242 | 243 | # Visual Studio 6 build log 244 | *.plg 245 | 246 | # Visual Studio 6 workspace options file 247 | *.opt 248 | 249 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 250 | *.vbw 251 | 252 | # Visual Studio LightSwitch build output 253 | **/*.HTMLClient/GeneratedArtifacts 254 | **/*.DesktopClient/GeneratedArtifacts 255 | **/*.DesktopClient/ModelManifest.xml 256 | **/*.Server/GeneratedArtifacts 257 | **/*.Server/ModelManifest.xml 258 | _Pvt_Extensions 259 | 260 | # Paket dependency manager 261 | .paket/paket.exe 262 | paket-files/ 263 | 264 | # FAKE - F# Make 265 | .fake/ 266 | 267 | # JetBrains Rider 268 | .idea/ 269 | *.sln.iml 270 | 271 | # CodeRush 272 | .cr/ 273 | 274 | # Python Tools for Visual Studio (PTVS) 275 | __pycache__/ 276 | *.pyc 277 | 278 | # Cake - Uncomment if you are using it 279 | # tools/** 280 | # !tools/packages.config 281 | 282 | # Telerik's JustMock configuration file 283 | *.jmconfig 284 | 285 | # BizTalk build output 286 | *.btp.cs 287 | *.btm.cs 288 | *.odx.cs 289 | *.xsd.cs 290 | 291 | # Doxygen output 292 | doc/latex 293 | doc/html 294 | *.bak 295 | 296 | #Allow detours 297 | !src/Open-SAMP-API/Utils/Detours/detours.pdb -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | 167 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Open-SAMP-API [![Build status](https://ci.appveyor.com/api/projects/status/62qftruy4mwi934p?svg=true)](https://ci.appveyor.com/project/agrippa1994/open-samp-api) 2 | ============= 3 | 4 | An open source API for GTA SA:MP licensed under the terms of the LGPL 3.0. Dependencies are under their respective licenses. 5 | 6 | Compilation 7 | --------------- 8 | Dependencies can be installed via nuget, check appveyor.yml for further build instructions 9 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2015 2 | 3 | clone_folder: c:\projects\open-samp-api 4 | 5 | pull_requests: 6 | do_not_increment_build_number: true 7 | 8 | skip_tags: true 9 | 10 | platform: Win32 11 | configuration: Release 12 | 13 | install: 14 | - set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH% 15 | - nuget restore src\Open-SAMP-API.sln 16 | 17 | build_script: 18 | - cmd: MSBuild src\Open-SAMP-API.sln /p:Configuration=Release /p:Platform=Win32 19 | 20 | after_build: 21 | - 7z a API.zip bin include test examples 22 | 23 | artifacts: 24 | path: API.zip 25 | name: API 26 | 27 | 28 | deploy: 29 | provider: GitHub 30 | auth_token: 31 | secure: G3Sfnp3bZeRUQNfYjuJB+8zbF5DXhMfj0wRad5ALRIZiGZodgrpOSj/umuR0zsGt 32 | artifact: API.zip 33 | draft: true 34 | on: 35 | branch: master 36 | appveyor_repo_tag: true 37 | -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAMPProjects/Open-SAMP-API/d409a384bda26b996f2023d5199904186788708c/doc/README.md -------------------------------------------------------------------------------- /examples/AHK/gta_world.ahk: -------------------------------------------------------------------------------- 1 | #SingleInstance, force 2 | #NoEnv 3 | #include ..\..\include\AHK\SAMP_API.ahk 4 | 5 | text_overlay :=- 1 6 | 7 | Gui, Show, w200 h50, World functions 8 | 9 | SetTimer, Timer, 10 10 | return 11 | 12 | ; Delete the overlay if the application will be closed by the user 13 | GuiClose: 14 | if(text_overlay != -1) 15 | TextDestroy(text_overlay) 16 | ExitApp 17 | 18 | ; Timer callback 19 | Timer: 20 | if(text_overlay == -1) { 21 | text_overlay := TextCreate("Arial", 30, false, false, -1, -1, 0xFFFF0000, "X", true, true) 22 | 23 | ; Every overlay object is rendered for a resolution of 800 x 600 24 | ; If you want to disable this kind of calculation, you can do this via "SetOverlayCalculationEnabled" 25 | ; We've to do this here because WorldToScreen returns the physical pixel coordinates on your screen 26 | SetOverlayCalculationEnabled(text_overlay, false) 27 | } 28 | 29 | if(text_overlay == -1) 30 | return 31 | 32 | ; Draw the overlay at the farm in Redwood 33 | if(WorldToScreen(0, 0, 0, x, y)) { 34 | if(TextSetPos(text_overlay, x, y) == 0) { 35 | TextDestroy(text_overlay) 36 | text_overlay := -1 37 | } 38 | } 39 | return 40 | -------------------------------------------------------------------------------- /examples/AHK/health_overlay.ahk: -------------------------------------------------------------------------------- 1 | #SingleInstance, force 2 | #NoEnv 3 | #include ..\..\include\AHK\SAMP_API.ahk 4 | 5 | text_overlay :=- 1 6 | 7 | ; Set the API's parameters 8 | ;SetParam("use_window", "1") 9 | ;SetParam("window", "GTA:SA:MP") 10 | 11 | ; Create GUI 12 | Gui, Show, w237 h52, Health-Overlay 13 | 14 | SetTimer, Timer, 50 15 | return 16 | 17 | ; Delete the overlay if the application will be closed by the user 18 | GuiClose: 19 | if(text_overlay != -1) 20 | TextDestroy(text_overlay) 21 | ExitApp 22 | 23 | ; Timer callback 24 | Timer: 25 | if(text_overlay == -1) 26 | text_overlay := TextCreate("Arial", 6, false, false, 720, 91, 0xFFFFFFFF, "100", true, true) 27 | 28 | if(text_overlay == -1) 29 | return 30 | 31 | health := GetPlayerHealth() 32 | 33 | if(TextSetString(text_overlay, health) == 0) 34 | { 35 | TextDestroy(text_overlay) 36 | text_overlay := -1 37 | } 38 | return 39 | -------------------------------------------------------------------------------- /examples/AHK/remote_player.ahk: -------------------------------------------------------------------------------- 1 | #SingleInstance, force 2 | #NoEnv 3 | #include ..\..\include\AHK\SAMP_API.ahk 4 | 5 | 1:: 6 | loop, 20 7 | { 8 | res:=GetPlayerNameByID(A_Index, name, 32) 9 | id := GetPlayerIDByName(name) ; id MUST BE A_Index 10 | 11 | AddChatMessage("Name of ID " A_Index "(" id "): " name ", result: " res) 12 | } 13 | return -------------------------------------------------------------------------------- /examples/AHK/samp_functions.ahk: -------------------------------------------------------------------------------- 1 | #SingleInstance, force 2 | #NoEnv 3 | #include ..\..\include\AHK\SAMP_API.ahk 4 | 5 | ; Set the API's parameters 6 | SetParam("use_window", "1") 7 | SetParam("window", "GTA:SA:MP") 8 | 9 | ; Create GUI 10 | Gui, Show, w237 h52, SAMP functions test 11 | 12 | return 13 | 14 | GuiClose: 15 | ExitApp 16 | 17 | ~1:: 18 | AddChatMessage("Hello world") 19 | AddChatMessage("{ff0000}Hello {00ff00}world") 20 | return 21 | 22 | ~2:: 23 | ShowGameText("Hello world", 1000, 3) 24 | return 25 | 26 | ~3:: 27 | SendChat("hello") 28 | SendChat("/hello") 29 | return 30 | 31 | ~4:: 32 | ShowDialog(1200, 0, "Hello world", "How are you?", "Button 1", "") 33 | return -------------------------------------------------------------------------------- /examples/AHK/weapon_functions.ahk: -------------------------------------------------------------------------------- 1 | #SingleInstance, force 2 | #NoEnv 3 | #include ..\..\include\AHK\SAMP_API.ahk 4 | 5 | ; Set the API's parameters 6 | SetParam("use_window", "1") 7 | SetParam("window", "GTA:SA:MP") 8 | 9 | ; Create GUI 10 | Gui, Show, w237 h52, SAMP weapon test 11 | return 12 | 13 | 1:: 14 | AddChatMessage("ID: " GetPlayerWeaponID()) 15 | slot := GetPlayerWeaponSlot() 16 | AddChatMessage("Slot " slot) 17 | AddChatMessage("State " GetPlayerWeaponState()) 18 | AddChatMessage("Type " GetPlayerWeaponType()) 19 | AddChatMessage("HasClip " HasWeaponIDClip(GetPlayerWeaponID())) 20 | 21 | if(slot != -1) { 22 | AddChatMessage("Clip: " GetPlayerWeaponClip(slot)) 23 | AddChatMessage("Total-Clip: " GetPlayerWeaponTotalClip(slot)) 24 | 25 | returnValue := GetPlayerWeaponName(slot, wname, 32) 26 | AddChatMessage("Weapon " wname " return val " returnValue) 27 | } 28 | return -------------------------------------------------------------------------------- /examples/C++/OverlayExample/OverlayExample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OverlayExample", "OverlayExample\OverlayExample.vcxproj", "{44A5F252-90EE-4452-8AE7-A60B4F2F78D0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {44A5F252-90EE-4452-8AE7-A60B4F2F78D0}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {44A5F252-90EE-4452-8AE7-A60B4F2F78D0}.Debug|Win32.Build.0 = Debug|Win32 16 | {44A5F252-90EE-4452-8AE7-A60B4F2F78D0}.Release|Win32.ActiveCfg = Release|Win32 17 | {44A5F252-90EE-4452-8AE7-A60B4F2F78D0}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /examples/C++/OverlayExample/OverlayExample/OverlayExample.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {44A5F252-90EE-4452-8AE7-A60B4F2F78D0} 15 | Win32Proj 16 | OverlayExample 17 | 18 | 19 | 20 | Application 21 | true 22 | v120 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v120 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /examples/C++/OverlayExample/OverlayExample/OverlayExample.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Quelldateien 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/C++/OverlayExample/OverlayExample/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAMPProjects/Open-SAMP-API/d409a384bda26b996f2023d5199904186788708c/examples/C++/OverlayExample/OverlayExample/main.cpp -------------------------------------------------------------------------------- /include/C++/SAMP_API.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define IMPORT extern "C" __declspec(dllimport) 3 | 4 | // Client.hpp 5 | IMPORT int Init(); 6 | IMPORT void SetParam(char* _szParamName, char* _szParamValue); 7 | 8 | // GTAFunctions.hpp 9 | IMPORT int GetGTACommandLine(char* &line, int max_len); 10 | IMPORT bool IsMenuOpen(); 11 | IMPORT bool ScreenToWorld(float x, float y, float &worldX, float &worldY, float &worldZ); 12 | IMPORT bool WorldToScreen(float x, float y, float z, float &screenX, float &screenY); 13 | 14 | // PlayerFunctions.hpp 15 | IMPORT int GetPlayerCPed(); 16 | IMPORT int GetPlayerHealth(); 17 | IMPORT int GetPlayerArmor(); 18 | IMPORT int GetPlayerMoney(); 19 | IMPORT int GetPlayerSkinID(); 20 | IMPORT int GetPlayerInterior(); 21 | IMPORT int IsPlayerInAnyVehicle(); 22 | IMPORT int IsPlayerDriver(); 23 | IMPORT int IsPlayerPassenger(); 24 | IMPORT int IsPlayerInInterior(); 25 | IMPORT int GetPlayerX(float &posX); 26 | IMPORT int GetPlayerY(float &posY); 27 | IMPORT int GetPlayerZ(float &posZ); 28 | IMPORT int GetPlayerPosition(float &posX, float &posY, float &posZ); 29 | IMPORT int IsPlayerInRange2D(float posX, float posY, float radius); 30 | IMPORT int IsPlayerInRange3D(float posX, float posY, float posZ, float radius); 31 | IMPORT int GetCityName(char* &cityName, int max_len); 32 | IMPORT int GetZoneName(char* &zoneName, int max_len); 33 | 34 | // RenderFunctions.hpp 35 | IMPORT int TextCreate(const char* Font, int FontSize, bool bBold, bool bItalic, int x, int y, unsigned int color, const char* text, bool bShadow, bool bShow); 36 | IMPORT int TextDestroy(int ID); 37 | IMPORT int TextSetShadow(int id, bool b); 38 | IMPORT int TextSetShown(int id, bool b); 39 | IMPORT int TextSetColor(int id, unsigned int color); 40 | IMPORT int TextSetPos(int id, int x, int y); 41 | IMPORT int TextSetString(int id, const char* str); 42 | IMPORT int TextUpdate(int id, const char* Font, int FontSize, bool bBold, bool bItalic); 43 | IMPORT int BoxCreate(int x, int y, int w, int h, unsigned int dwColor, bool bShow); 44 | IMPORT int BoxDestroy(int id); 45 | IMPORT int BoxSetShown(int id, bool bShown); 46 | IMPORT int BoxSetBorder(int id, int height, bool bShown); 47 | IMPORT int BoxSetBorderColor(int id, unsigned int dwColor); 48 | IMPORT int BoxSetColor(int id, unsigned int dwColor); 49 | IMPORT int BoxSetHeight(int id, int height); 50 | IMPORT int BoxSetPos(int id, int x, int y); 51 | IMPORT int BoxSetWidth(int id, int width); 52 | IMPORT int LineCreate(int x1, int y1, int x2, int y2, int width, unsigned int color, bool bShow); 53 | IMPORT int LineDestroy(int id); 54 | IMPORT int LineSetShown(int id, bool bShown); 55 | IMPORT int LineSetColor(int id, unsigned int color); 56 | IMPORT int LineSetWidth(int id, int width); 57 | IMPORT int LineSetPos(int id, int x1, int y1, int x2, int y2); 58 | IMPORT int ImageCreate(const char* path, int x, int y, int rotation, int align, bool bShow); 59 | IMPORT int ImageDestroy(int id); 60 | IMPORT int ImageSetShown(int id, bool bShown); 61 | IMPORT int ImageSetAlign(int id, int align); 62 | IMPORT int ImageSetPos(int id, int x, int y); 63 | IMPORT int ImageSetRotation(int id, int rotation); 64 | IMPORT int DestroyAllVisual(); 65 | IMPORT int ShowAllVisual(); 66 | IMPORT int HideAllVisual(); 67 | IMPORT int GetFrameRate(); 68 | IMPORT int GetScreenSpecs(int &width, int &height); 69 | IMPORT int SetCalculationRatio(int width, int height); 70 | IMPORT int SetOverlayPriority(int id, int priority); 71 | IMPORT int SetOverlayCalculationEnabled(int id, bool enabled); 72 | 73 | // SAMPFunctions.hpp 74 | IMPORT int GetServerIP(char* &ip, int max_len); 75 | IMPORT int GetServerPort(); 76 | IMPORT int SendChat(const char* msg); 77 | IMPORT int ShowGameText(const char* msg, int time, int style); 78 | IMPORT int AddChatMessage(const char* msg); 79 | IMPORT int ShowDialog(int id, int style, const char* caption, const char* text, const char* button, const char* button2); 80 | IMPORT int GetPlayerNameByID(int id, char* &playername, int max_len); 81 | IMPORT int GetPlayerIDByName(const char* name); 82 | IMPORT int GetPlayerName(char* &playername, int max_len); 83 | IMPORT int GetPlayerId(); 84 | IMPORT int IsChatOpen(); 85 | IMPORT int IsDialogOpen(); 86 | 87 | // VehicleFunctions.hpp 88 | IMPORT unsigned int GetVehiclePointer(); 89 | IMPORT int GetVehicleSpeed(float factor); 90 | IMPORT float GetVehicleHealth(); 91 | IMPORT int GetVehicleModelId(); 92 | IMPORT int GetVehicleModelName(char* &name, int max_len); 93 | IMPORT int GetVehicleModelNameById(int vehicleID, char* &name, int max_len); 94 | IMPORT int GetVehicleType(); 95 | IMPORT int GetVehicleFreeSeats(int &seatFL, int &seatFR, int &seatRL, int &seatRR); 96 | IMPORT int GetVehicleFirstColor(); 97 | IMPORT int GetVehicleSecondColor(); 98 | IMPORT int GetVehicleColor(int &color1, int &color2); 99 | IMPORT int IsVehicleSeatUsed(int seat); 100 | IMPORT int IsVehicleLocked(); 101 | IMPORT int IsVehicleHornEnabled(); 102 | IMPORT int IsVehicleSirenEnabled(); 103 | IMPORT int IsVehicleAlternateSirenEnabled(); 104 | IMPORT int IsVehicleEngineEnabled(); 105 | IMPORT int IsVehicleLightEnabled(); 106 | IMPORT int IsVehicleCar(); 107 | IMPORT int IsVehiclePlane(); 108 | IMPORT int IsVehicleBoat(); 109 | IMPORT int IsVehicleTrain(); 110 | IMPORT int IsVehicleBike(); 111 | 112 | // WeaponFunctions.hpp 113 | IMPORT int HasWeaponIDClip(int weaponID); 114 | IMPORT int GetPlayerWeaponID(); 115 | IMPORT int GetPlayerWeaponType(); 116 | IMPORT int GetPlayerWeaponSlot(); 117 | IMPORT int GetPlayerWeaponName(int dwWeapSlot, char* &_szWeapName, int max_len); 118 | IMPORT int GetPlayerWeaponClip(int dwWeapSlot); 119 | IMPORT int GetPlayerWeaponTotalClip(int dwWeapSlot); 120 | IMPORT int GetPlayerWeaponState(); 121 | IMPORT int GetPlayerWeaponAmmo(int weaponType); 122 | IMPORT int GetPlayerWeaponAmmoInClip(int weaponType); 123 | -------------------------------------------------------------------------------- /include/generate.py: -------------------------------------------------------------------------------- 1 | # coding: utf8 2 | # Python 3 3 | 4 | import re 5 | import codecs 6 | import os 7 | import fnmatch 8 | 9 | class Function: 10 | def __init__(self, name, arguments, retType, origin): 11 | self.name = name 12 | self.arguments = arguments 13 | self.retType = retType 14 | self.origin = origin 15 | 16 | class Argument: 17 | def __init__(self, name, aType, isPtr): 18 | self.name = name 19 | self.aType = aType 20 | self.isPtr = isPtr 21 | 22 | class Type: 23 | def __init__(self, typeName, isConst, isArray, isUnsigned): 24 | self.typeName = typeName 25 | self.isConst = isConst 26 | self.isArray = isArray 27 | self.isUnsigned = isUnsigned 28 | 29 | functions = [] 30 | 31 | def parseDefinition(expression): 32 | expression = expression.strip() 33 | expression = re.sub(r'\t', " ", expression) 34 | (expression, isArray) = re.subn(r'\*', "", expression) 35 | (expression, isPtr) = re.subn(r'&', "", expression) 36 | (expression, isConst) = re.subn(r'^const ', "", expression) 37 | (expression, isUnsigned) = re.subn(r'^unsigned ', "", expression) 38 | parts = expression.split() 39 | name = parts.pop() 40 | typeName = " ".join(parts) 41 | return Argument( 42 | name, 43 | Type( 44 | typeName, 45 | bool(isConst), 46 | bool(isArray), 47 | bool(isUnsigned) 48 | ), 49 | bool(isPtr) 50 | ) 51 | 52 | def scan(): 53 | os.chdir("src/Open-SAMP-API/Client") 54 | for filename in os.listdir("."): 55 | if filename in ["GTAStructs.hpp", "MemoryFunctions.hpp"] or not fnmatch.fnmatch(filename, "*.hpp"): 56 | continue 57 | with codecs.open(filename, encoding="utf-8-sig") as file: 58 | content = file.read() 59 | matches = re.findall(r'^\s*EXPORT (.+)\((.*)\);\s*$', content, flags=re.M) 60 | for match in matches: 61 | functionDefinition = parseDefinition(match[0]) 62 | (name, retType) = (functionDefinition.name, functionDefinition.aType) 63 | arguments = match[1].split(",") 64 | if arguments[0] == "": 65 | arguments.pop(0) 66 | arguments = list(map(parseDefinition, arguments)) 67 | function = Function( 68 | name, 69 | arguments, 70 | retType, 71 | filename 72 | ) 73 | functions.append(function) 74 | 75 | def gen_ahk(): 76 | header = '''#NoEnv 77 | 78 | PATH_SAMP_API := PathCombine(A_ScriptDir, "..\..\\bin\Open-SAMP-API.dll") 79 | 80 | hModule := DllCall("LoadLibrary", Str, PATH_SAMP_API) 81 | if(hModule == -1 || hModule == 0) 82 | { 83 | MsgBox, 48, Error, The dll-file couldn't be found! 84 | ExitApp 85 | } 86 | ''' 87 | footer = ''' 88 | PathCombine(abs, rel) { 89 | VarSetCapacity(dest, (A_IsUnicode ? 2 : 1) * 260, 1) ; MAX_PATH 90 | DllCall("Shlwapi.dll\PathCombine", "UInt", &dest, "UInt", &abs, "UInt", &rel) 91 | Return, dest 92 | } 93 | ''' 94 | output = header 95 | GetProcAddressTemplate = '{0}_func := DllCall("GetProcAddress", "UInt", hModule, "AStr", "{0}")\n' 96 | currentOrigin = "" 97 | for function in functions: 98 | if currentOrigin != function.origin: 99 | output += "\n;{0}\n".format(function.origin) 100 | currentOrigin = function.origin 101 | output += GetProcAddressTemplate.format(function.name) 102 | output += "\n" 103 | FunctionTemplate = '''{0}({1}) 104 | {{ 105 | global {0}_func 106 | return DllCall({0}_func{2}) 107 | }} 108 | 109 | ''' 110 | FunctionTemplatePtr = '''{0}({1}) 111 | {{ 112 | global {0}_func 113 | {3} 114 | res := DllCall({0}_func{2}) 115 | ; We need StrGet to convert the API answer (ANSI) to the charset AHK uses (ANSI or Unicode) 116 | {4} 117 | return res 118 | }} 119 | 120 | ''' 121 | dataTypeMap = { 122 | "bool": "UChar", 123 | "char": "AStr", 124 | "float": "Float", 125 | "int": "Int" 126 | } 127 | for function in functions: 128 | hasStrPtr = False 129 | VarSetCapacity_opt = StrGet_opt = DllCallArguments = "" 130 | for argument in function.arguments: 131 | dataType = dataTypeMap[argument.aType.typeName] 132 | if argument.isPtr and argument.aType.typeName == "char" and argument.aType.isArray: 133 | hasStrPtr = True 134 | dataType = "Str" # Don't use AStr so we don't get AStrP later on (the P is added below) 135 | for innerArgument in function.arguments: 136 | if innerArgument.name == "max_len": 137 | maxVarLen = "max_len" 138 | if not maxVarLen: 139 | maxVarLen = input("Maximum output length for " + function.name + " (variable name or value): ") 140 | print("You may also add a param named max_len so we can make it work automatically") 141 | VarSetCapacity_opt += "\n\tVarSetCapacity({0}, {1} * (A_IsUnicode ? 2 : 1), 0)".format(argument.name, maxVarLen) 142 | StrGet_opt += "\n\t{0} := StrGet(&{0}, \"cp0\")".format(argument.name) 143 | 144 | if argument.aType.isUnsigned: 145 | dataType = "U" + dataType 146 | if argument.isPtr: 147 | dataType += "P" 148 | DllCallArguments += ', "{0}", {1}'.format(dataType, argument.name) 149 | if function.retType.typeName not in ["void", "bool", "int"]: 150 | DllCallArguments += ', "Cdecl {0}"'.format(function.retType.typeName) 151 | template = FunctionTemplatePtr if hasStrPtr else FunctionTemplate 152 | functionBody = template.format( 153 | function.name, 154 | ", ".join(map(lambda argument: ("ByRef " if argument.isPtr else "") + argument.name, function.arguments)), 155 | DllCallArguments, 156 | VarSetCapacity_opt.strip(), 157 | StrGet_opt.strip() 158 | ) 159 | output += functionBody 160 | output += footer 161 | with codecs.open("AHK/SAMP_API.ahk", encoding="utf-8", mode="w") as file: 162 | file.write(output) 163 | 164 | def gen_cs(): 165 | header = '''using System; 166 | using System.Drawing; 167 | using System.Runtime.InteropServices; 168 | 169 | namespace SAMP_API 170 | { 171 | class API 172 | { 173 | public const String PATH = "Open-SAMP-API.dll"; 174 | ''' 175 | footer = ''' 176 | /// 177 | /// Send a message/command to the server 178 | /// 179 | /// The message/command 180 | /// Arguments for a command, e.g an ID 181 | public static void SendChatEx(string message, params object[] args) 182 | { 183 | if (message.Length != 0) 184 | { 185 | if (args.Length > 0) 186 | message += " " + string.Join(" ", args); 187 | SendChat(message); 188 | } 189 | } 190 | 191 | /// 192 | /// Add a new message in the SAMP chat (only local) 193 | /// 194 | /// The text to be written 195 | /// A color in Hex 196 | public static void AddChatMessageEx(string text, string color = "FFFFFF") 197 | { 198 | AddChatMessage("{" + color + "}" + text); 199 | } 200 | 201 | /// 202 | /// Add a new message in the SAMP chat (only local) 203 | /// 204 | /// The text to be written 205 | /// A Color-Type 206 | public static void AddChatMessageEx(string text, Color color) 207 | { 208 | AddChatMessage("{" + ColorToHexRGB(color) + "}" + text); 209 | } 210 | 211 | /// 212 | /// Add a new message in the SAMP chat (only local) 213 | /// 214 | /// The prefix to be written 215 | /// A prefix color in Hex 216 | /// The text to be written 217 | /// A color in Hex 218 | public static void AddChatMessageEx(string prefix, string prefixColor, string text, string color = "FFFFFF") 219 | { 220 | AddChatMessage("{" + prefixColor + "}" + prefix + " {" + color + "}" + text); 221 | } 222 | 223 | /// 224 | /// Add a new message in the SAMP chat (only local) 225 | /// 226 | /// The prefix to be written 227 | /// A Color-Type 228 | /// The text to be written 229 | /// A Color-Type 230 | public static void AddChatMessageEx(string prefix, Color prefixColor, string text, Color color) 231 | { 232 | AddChatMessage("{" + ColorToHexRGB(prefixColor) + "}" + prefix + " {" + ColorToHexRGB(color) + "}" + text); 233 | } 234 | 235 | public static string GetPlayerNameByIDEx(int id) 236 | { 237 | StringBuilder builder = new StringBuilder(32); 238 | GetPlayerNameByID(id, ref builder, builder.Capacity); 239 | 240 | return builder.ToString(); 241 | } 242 | 243 | /// 244 | /// Convert a Color to Hex (RGB) 245 | /// 246 | /// Color convert to Hex 247 | /// 248 | public static String ColorToHexRGB(Color color) 249 | { 250 | return color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2"); 251 | } 252 | 253 | /// 254 | /// Convert a Color to Hex (ARGB) 255 | /// 256 | /// Color convert to Hex 257 | /// 258 | public static String ColorToHexARGB(Color color) 259 | { 260 | return color.A.ToString("X2") + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2"); 261 | } 262 | } 263 | } 264 | ''' 265 | output = header 266 | FunctionTemplate = ''' [DllImport(PATH, CallingConvention = CallingConvention.Cdecl)] 267 | public static extern {0} {1}({2}); 268 | ''' 269 | currentOrigin = "" 270 | for function in functions: 271 | if currentOrigin != function.origin: 272 | output += "\n // {0}\n".format(function.origin) 273 | currentOrigin = function.origin 274 | paramList = [] 275 | for argument in function.arguments: 276 | curParam = "" 277 | if argument.isPtr: 278 | curParam = "out " 279 | if argument.isPtr and argument.aType.typeName == "char": 280 | curParam = "ref StringBuilder " 281 | elif argument.aType.isArray and argument.aType.typeName == "char": 282 | curParam += "string " 283 | else: 284 | curParam += argument.aType.typeName + " " 285 | curParam += argument.name 286 | paramList.append(curParam) 287 | output += FunctionTemplate.format( 288 | function.retType.typeName, 289 | function.name, 290 | ", ".join(paramList) 291 | ) 292 | output += footer 293 | with codecs.open("C#/SAMP_API.cs", encoding="utf-8", mode="w") as file: 294 | file.write(output) 295 | 296 | def gen_cpp(): 297 | header = '''#pragma once 298 | #define IMPORT extern "C" __declspec(dllimport) 299 | ''' 300 | output = header 301 | FunctionTemplate = '''IMPORT {0} {1}({2}); 302 | ''' 303 | currentOrigin = "" 304 | for function in functions: 305 | if currentOrigin != function.origin: 306 | output += "\n// {0}\n".format(function.origin) 307 | currentOrigin = function.origin 308 | paramList = [] 309 | for argument in function.arguments: 310 | curParam = "" 311 | if argument.aType.isConst: 312 | curParam += "const " 313 | if argument.aType.isUnsigned: 314 | curParam += "unsigned " 315 | curParam += argument.aType.typeName 316 | if argument.aType.isArray: 317 | curParam += "*" 318 | curParam += " " 319 | if argument.isPtr: 320 | curParam += "&" 321 | curParam += argument.name 322 | paramList.append(curParam) 323 | retType = "" 324 | if function.retType.isConst: 325 | retType += "const " 326 | if function.retType.isUnsigned: 327 | retType += "unsigned " 328 | retType += function.retType.typeName 329 | output += FunctionTemplate.format( 330 | retType, 331 | function.name, 332 | ", ".join(paramList) 333 | ) 334 | with codecs.open("C++/SAMP_API.h", encoding="utf-8", mode="w") as file: 335 | file.write(output) 336 | 337 | 338 | if os.path.split(os.getcwd())[-1] == "include": 339 | os.chdir("..") 340 | print("Parsing C++ header files...", end=" ") 341 | scan() 342 | print("Done.") 343 | os.chdir("../../../include") 344 | print("Generating AHK include...", end=" ") 345 | gen_ahk() 346 | print("Done.") 347 | print("Generating C# include...", end=" ") 348 | gen_cs() 349 | print("Done.") 350 | print("Generating C++ include...", end=" ") 351 | gen_cpp() 352 | print("Done.") 353 | -------------------------------------------------------------------------------- /src/Open-SAMP-API.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Open-SAMP-API", "Open-SAMP-API\Open-SAMP-API.vcxproj", "{B8A30F01-BE67-45B9-AE80-47CB9A95BCF8}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B8A30F01-BE67-45B9-AE80-47CB9A95BCF8}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {B8A30F01-BE67-45B9-AE80-47CB9A95BCF8}.Debug|Win32.Build.0 = Debug|Win32 16 | {B8A30F01-BE67-45B9-AE80-47CB9A95BCF8}.Release|Win32.ActiveCfg = Release|Win32 17 | {B8A30F01-BE67-45B9-AE80-47CB9A95BCF8}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/Client.cpp: -------------------------------------------------------------------------------- 1 | #include "Client.hpp" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | struct stParamInfo 9 | { 10 | std::string szParamName; 11 | std::string szParamValue; 12 | }; 13 | 14 | stParamInfo g_paramArray[3] = 15 | { 16 | "process", "", 17 | "window", "", 18 | "use_window", "1" 19 | }; 20 | 21 | bool Client::Client::IsServerAvailable() 22 | { 23 | Utils::Serializer serializerIn, serializerOut; 24 | 25 | serializerIn << Shared::PipeMessages::Ping; 26 | 27 | return Utils::PipeClient(serializerIn, serializerOut).success(); 28 | } 29 | 30 | EXPORT void Client::Client::SetParam(char *_szParamName, char *_szParamValue) 31 | { 32 | for (int i = 0; i < ARRAYSIZE(g_paramArray); i++) 33 | if (boost::iequals(_szParamName, g_paramArray[i].szParamName)) 34 | g_paramArray[i].szParamValue = _szParamValue; 35 | 36 | return; 37 | } 38 | 39 | std::string GetParam(char *_szParamName) 40 | { 41 | for (int i = 0; i < ARRAYSIZE(g_paramArray); i++) 42 | if (boost::iequals(_szParamName, g_paramArray[i].szParamName)) 43 | return g_paramArray[i].szParamValue; 44 | 45 | return ""; 46 | } 47 | 48 | 49 | EXPORT int Client::Client::Init() 50 | { 51 | char szDLLPath[MAX_PATH + 1] = { 0 }; 52 | DWORD dwPId = 0; 53 | BOOL bRetn; 54 | 55 | GetModuleFileName((HMODULE) g_hDllHandle, szDLLPath, sizeof(szDLLPath)); 56 | if (!atoi(GetParam("use_window").c_str())) 57 | { 58 | std::string szSearchName = GetParam("process"); 59 | dwPId = Utils::Process::pidByProcessName(szSearchName); 60 | 61 | if (dwPId != 0) { 62 | // We want to wait until after SAMP is fully loaded (that is, the window is 63 | // no longer named "GTA: San Andreas") so we can actually access all SAMP features 64 | DWORD dwPIdStartup = Utils::Process::pidByWindowName("GTA: San Andreas"); 65 | if (dwPId == dwPIdStartup) 66 | return 0; 67 | } 68 | } 69 | else 70 | { 71 | std::string szSearchName = GetParam("window"); 72 | if (szSearchName.length() == 0) 73 | szSearchName = "GTA:SA:MP"; 74 | 75 | dwPId = Utils::Process::pidByWindowName(szSearchName); 76 | } 77 | 78 | if (dwPId == 0) 79 | return 0; 80 | 81 | HANDLE hHandle = OpenProcess((STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF), FALSE, dwPId); 82 | if (hHandle == 0 || hHandle == INVALID_HANDLE_VALUE) 83 | return 0; 84 | 85 | void *pAddr = VirtualAllocEx(hHandle, NULL, strlen(szDLLPath) + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); 86 | if (pAddr == NULL) 87 | { 88 | CloseHandle(hHandle); 89 | return 0; 90 | } 91 | 92 | bRetn = WriteProcessMemory(hHandle, pAddr, szDLLPath, strlen(szDLLPath) + 1, NULL); 93 | if (bRetn == FALSE) 94 | { 95 | VirtualFreeEx(hHandle, pAddr, strlen(szDLLPath) + 1, MEM_RELEASE); 96 | CloseHandle(hHandle); 97 | return 0; 98 | } 99 | 100 | DWORD dwBase = 0; 101 | 102 | // Load DLL-file 103 | { 104 | LPTHREAD_START_ROUTINE pFunc = (LPTHREAD_START_ROUTINE) GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA"); 105 | if (pFunc == NULL) 106 | { 107 | VirtualFreeEx(hHandle, pAddr, strlen(szDLLPath) + 1, MEM_RELEASE); 108 | CloseHandle(hHandle); 109 | return 0; 110 | } 111 | 112 | HANDLE hThread = CreateRemoteThread(hHandle, 0, 0, pFunc, pAddr, 0, 0); 113 | if (hThread == NULL || hThread == INVALID_HANDLE_VALUE) 114 | { 115 | VirtualFreeEx(hHandle, pAddr, strlen(szDLLPath) + 1, MEM_RELEASE); 116 | CloseHandle(hHandle); 117 | return 0; 118 | } 119 | 120 | WaitForSingleObject(hThread, INFINITE); 121 | GetExitCodeThread(hThread, &dwBase); 122 | VirtualFreeEx(hHandle, pAddr, strlen(szDLLPath) + 1, MEM_RELEASE); 123 | CloseHandle(hThread); 124 | } 125 | 126 | // Start Remote-IPC 127 | { 128 | if (dwBase == 0) 129 | { 130 | CloseHandle(hHandle); 131 | return 0; 132 | } 133 | 134 | 135 | DWORD pFunc = (DWORD) GetProcAddress((HMODULE) g_hDllHandle, "enable"); 136 | pFunc -= (DWORD) g_hDllHandle; 137 | pFunc += (DWORD) dwBase; 138 | 139 | if (pFunc == NULL) 140 | { 141 | CloseHandle(hHandle); 142 | return 0; 143 | } 144 | 145 | HANDLE hThread = CreateRemoteThread(hHandle, 0, 0, (LPTHREAD_START_ROUTINE) pFunc, 0, 0, 0); 146 | if (hThread == NULL || hThread == INVALID_HANDLE_VALUE) 147 | { 148 | CloseHandle(hHandle); 149 | return 0; 150 | } 151 | 152 | WaitForSingleObject(hThread, INFINITE); 153 | CloseHandle(hThread); 154 | CloseHandle(hHandle); 155 | 156 | return 1; 157 | } 158 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/Client.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #define EXPORT extern "C" __declspec(dllexport) 7 | 8 | #define SERVER_CHECK(retn) if(!Client::IsServerAvailable()){ if(!Client::Init()) return retn; else Sleep(250); } 9 | #define SERIALIZER_RET(T) { T retVal; serializerOut >> retVal; return retVal; } 10 | 11 | namespace Client 12 | { 13 | namespace Client 14 | { 15 | bool IsServerAvailable(); 16 | 17 | EXPORT int Init(); 18 | EXPORT void SetParam(char *_szParamName, char *_szParamValue); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/GTAFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "GTAFunctions.hpp" 2 | #include "MemoryFunctions.hpp" 3 | #include 4 | 5 | EXPORT int Client::GTAFunctions::GetGTACommandLine(char* &line, int max_len) 6 | { 7 | SERVER_CHECK(0) 8 | 9 | Utils::Serializer serializerIn, serializerOut; 10 | 11 | serializerIn << Shared::PipeMessages::GetGTACommandLine; 12 | 13 | if (Utils::PipeClient(serializerIn, serializerOut).success()) 14 | { 15 | std::string out; 16 | serializerOut >> out; 17 | 18 | if (!out.length()) 19 | return 0; 20 | 21 | strcpy_s(line, max_len, out.c_str()); 22 | return 1; 23 | } 24 | 25 | return 0; 26 | } 27 | 28 | EXPORT bool Client::GTAFunctions::IsMenuOpen() 29 | { 30 | BYTE bOpen; 31 | MemoryFunctions::ReadMemory(0xB6B964, 1, &bOpen); 32 | return bOpen != 0; 33 | } 34 | 35 | EXPORT bool Client::GTAFunctions::ScreenToWorld(float x, float y, float &worldX, float &worldY, float &worldZ) 36 | { 37 | SERVER_CHECK(0) 38 | 39 | Utils::Serializer serializerIn, serializerOut; 40 | 41 | serializerIn << Shared::PipeMessages::ScreenToWorld << x << y; 42 | 43 | if (Utils::PipeClient(serializerIn, serializerOut).success()) 44 | { 45 | bool bRes = false; 46 | serializerOut >> bRes >> worldX >> worldY >> worldZ; 47 | return bRes; 48 | } 49 | 50 | return 0; 51 | } 52 | 53 | EXPORT bool Client::GTAFunctions::WorldToScreen(float x, float y, float z, float& screenX, float& screenY) 54 | { 55 | SERVER_CHECK(0) 56 | 57 | Utils::Serializer serializerIn, serializerOut; 58 | 59 | serializerIn << Shared::PipeMessages::WorldToScreen << x << y << z; 60 | 61 | if (Utils::PipeClient(serializerIn, serializerOut).success()) 62 | { 63 | bool bRes = false; 64 | serializerOut >> bRes >> screenX >> screenY; 65 | return bRes; 66 | } 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/GTAFunctions.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Client.hpp" 3 | 4 | namespace Client 5 | { 6 | namespace GTAFunctions 7 | { 8 | EXPORT int GetGTACommandLine(char* &line, int max_len); 9 | EXPORT bool IsMenuOpen(); 10 | EXPORT bool ScreenToWorld(float x, float y, float &worldX, float &worldY, float &worldZ); 11 | EXPORT bool WorldToScreen(float x, float y, float z, float& screenX, float& screenY); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/MemoryFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "MemoryFunctions.hpp" 2 | #include 3 | 4 | EXPORT int Client::MemoryFunctions::ReadMemoryRef(unsigned int address, unsigned int len, char *&ptr) 5 | { 6 | return ReadMemory(address, len, ptr); 7 | } 8 | 9 | EXPORT int Client::MemoryFunctions::ReadMemory(unsigned int address, unsigned int len, void *ptr) 10 | { 11 | SERVER_CHECK(0) 12 | 13 | Utils::Serializer serializerIn, serializerOut; 14 | 15 | serializerIn << Shared::PipeMessages::ReadMemory << address << len; 16 | 17 | if (Utils::PipeClient(serializerIn, serializerOut).success()) 18 | { 19 | std::string ret; 20 | serializerOut >> ret; 21 | 22 | if (ret.size() != len) 23 | return 0; 24 | 25 | memcpy_s(ptr, len, ret.c_str(), len); 26 | return ret.size(); 27 | } 28 | 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/MemoryFunctions.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Client.hpp" 3 | 4 | namespace Client 5 | { 6 | namespace MemoryFunctions 7 | { 8 | EXPORT int ReadMemoryRef(unsigned int address, unsigned int len, char *&ptr); 9 | EXPORT int ReadMemory(unsigned int address, unsigned int len, void *ptr); 10 | } 11 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/PlayerFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "PlayerFunctions.hpp" 2 | #include "MemoryFunctions.hpp" 3 | #include "VehicleFunctions.hpp" 4 | #include "GTAStructs.hpp" 5 | #include 6 | 7 | 8 | EXPORT int Client::PlayerFunctions::GetPlayerCPed() 9 | { 10 | DWORD pedPtr = 0; 11 | MemoryFunctions::ReadMemory(0xB6F5F0, 4, &pedPtr); 12 | return pedPtr; 13 | } 14 | 15 | EXPORT int Client::PlayerFunctions::GetPlayerHealth() 16 | { 17 | DWORD pedPtr = 0; 18 | if (MemoryFunctions::ReadMemory(0xB6F5F0, 4, &pedPtr) != 4) 19 | return -1; 20 | 21 | float health = 0.0; 22 | if (MemoryFunctions::ReadMemory(pedPtr + 0x540, 4, &health) != 4) 23 | return -1; 24 | 25 | return (int)health; 26 | } 27 | 28 | EXPORT int Client::PlayerFunctions::GetPlayerArmor() 29 | { 30 | DWORD pedPtr = 0; 31 | if (MemoryFunctions::ReadMemory(0xB6F5F0, 4, &pedPtr) != 4) 32 | return -1; 33 | 34 | float armor = 0.0; 35 | if (MemoryFunctions::ReadMemory(pedPtr + 0x548, 4, &armor) != 4) 36 | return -1; 37 | 38 | return (int)armor; 39 | } 40 | 41 | EXPORT int Client::PlayerFunctions::GetPlayerMoney() 42 | { 43 | DWORD money = 0; 44 | if (MemoryFunctions::ReadMemory(0xB7CE50, 4, &money) != 4) 45 | return -1; 46 | 47 | return (int)money; 48 | } 49 | 50 | EXPORT int Client::PlayerFunctions::GetPlayerSkinID() 51 | { 52 | DWORD pedPtr = 0; 53 | if (MemoryFunctions::ReadMemory(0xB6F5F0, 4, &pedPtr) != 4) 54 | return -1; 55 | 56 | int skin = 0; 57 | if (MemoryFunctions::ReadMemory(pedPtr + 0x22, 2, &skin) != 2) 58 | return -1; 59 | 60 | return (int)skin; 61 | } 62 | 63 | EXPORT int Client::PlayerFunctions::GetPlayerInterior() 64 | { 65 | DWORD pedPtr = 0; 66 | if (MemoryFunctions::ReadMemory(0xB6F5F0, 4, &pedPtr) != 4) 67 | return 0; 68 | 69 | int interior = 0; 70 | if (MemoryFunctions::ReadMemory(pedPtr + 0x2F, 1, &interior) != 1) 71 | return 0; 72 | 73 | return interior; 74 | } 75 | 76 | EXPORT int Client::PlayerFunctions::IsPlayerInAnyVehicle() 77 | { 78 | return (int)(VehicleFunctions::GetVehiclePointer() != 0); 79 | } 80 | 81 | EXPORT int Client::PlayerFunctions::IsPlayerDriver() 82 | { 83 | DWORD dwVehiclePtr = VehicleFunctions::GetVehiclePointer(); 84 | if (!dwVehiclePtr) 85 | return 0; 86 | 87 | DWORD dwPlayerPtr = PlayerFunctions::GetPlayerCPed(); 88 | DWORD dwDriverPtr = 0; 89 | 90 | MemoryFunctions::ReadMemory(dwVehiclePtr + 0x460, 4, &dwDriverPtr); 91 | if (dwPlayerPtr == dwDriverPtr) 92 | return 1; 93 | 94 | return 0; 95 | } 96 | 97 | EXPORT int Client::PlayerFunctions::IsPlayerPassenger() 98 | { 99 | if (!IsPlayerInAnyVehicle()) 100 | return 0; 101 | 102 | return (int)(IsPlayerDriver() == 0); 103 | } 104 | 105 | EXPORT int Client::PlayerFunctions::IsPlayerInInterior() 106 | { 107 | int interior = GetPlayerInterior(); 108 | return (int)(interior != 0); 109 | } 110 | 111 | EXPORT int Client::PlayerFunctions::GetPlayerX(float &posX) 112 | { 113 | DWORD pedPtr = 0; 114 | if (MemoryFunctions::ReadMemory(0xB6F5F0, 4, &pedPtr) != 4) 115 | return 0; 116 | 117 | DWORD matrixPtr = 0; 118 | if (MemoryFunctions::ReadMemory(pedPtr + 0x14, 4, &matrixPtr) != 4) 119 | return 0; 120 | 121 | DWORD positionPtr = 0; 122 | if (MemoryFunctions::ReadMemory(matrixPtr + 0x30, 4, &positionPtr) != 4) 123 | return 0; 124 | 125 | float position = 0.0f; 126 | if (MemoryFunctions::ReadMemory(positionPtr, 4, &position) != 4) 127 | return 0; 128 | 129 | posX = position; 130 | return 1; 131 | } 132 | 133 | EXPORT int Client::PlayerFunctions::GetPlayerY(float &posY) 134 | { 135 | DWORD pedPtr = 0; 136 | if (MemoryFunctions::ReadMemory(0xB6F5F0, 4, &pedPtr) != 4) 137 | return 0; 138 | 139 | DWORD matrixPtr = 0; 140 | if (MemoryFunctions::ReadMemory(pedPtr + 0x14, 4, &matrixPtr) != 4) 141 | return 0; 142 | 143 | DWORD positionPtr = 0; 144 | if (MemoryFunctions::ReadMemory(matrixPtr + 0x34, 4, &positionPtr) != 4) 145 | return 0; 146 | 147 | float position = 0.0f; 148 | if (MemoryFunctions::ReadMemory(positionPtr, 4, &position) != 4) 149 | return 0; 150 | 151 | posY = position; 152 | return 1; 153 | } 154 | 155 | EXPORT int Client::PlayerFunctions::GetPlayerZ(float &posZ) 156 | { 157 | DWORD pedPtr = 0; 158 | if (MemoryFunctions::ReadMemory(0xB6F5F0, 4, &pedPtr) != 4) 159 | return 0; 160 | 161 | DWORD matrixPtr = 0; 162 | if (MemoryFunctions::ReadMemory(pedPtr + 0x14, 4, &matrixPtr) != 4) 163 | return 0; 164 | 165 | DWORD positionPtr = 0; 166 | if (MemoryFunctions::ReadMemory(matrixPtr + 0x38, 4, &positionPtr) != 4) 167 | return 0; 168 | 169 | float position = 0.0f; 170 | if (MemoryFunctions::ReadMemory(positionPtr, 4, &position) != 4) 171 | return 0; 172 | 173 | posZ = position; 174 | return 1; 175 | } 176 | 177 | EXPORT int Client::PlayerFunctions::GetPlayerPosition(float &posX, float &posY, float &posZ) 178 | { 179 | DWORD pedPtr = 0; 180 | if (MemoryFunctions::ReadMemory(0xB6F5F0, 4, &pedPtr) != 4) 181 | return 0; 182 | 183 | DWORD matrixPtr = 0; 184 | if (MemoryFunctions::ReadMemory(pedPtr + 0x14, 4, &matrixPtr) != 4) 185 | return 0; 186 | 187 | DWORD positionPtr = 0; 188 | if (MemoryFunctions::ReadMemory(matrixPtr + 0x34, 4, &positionPtr) != 4) 189 | return 0; 190 | 191 | 192 | float positionX = 0.0f; 193 | if (MemoryFunctions::ReadMemory(matrixPtr + 0x30, 4, &positionX) != 4) 194 | return 0; 195 | 196 | float positionY = 0.0f; 197 | if (MemoryFunctions::ReadMemory(matrixPtr + 0x34, 4, &positionY) != 4) 198 | return 0; 199 | 200 | float positionZ = 0.0f; 201 | if (MemoryFunctions::ReadMemory(matrixPtr + 0x38, 4, &positionZ) != 4) 202 | return 0; 203 | 204 | posX = positionX; 205 | posY = positionY; 206 | posZ = positionZ; 207 | return 1; 208 | } 209 | 210 | EXPORT int Client::PlayerFunctions::IsPlayerInRange2D(float posX, float posY, float radius) 211 | { 212 | float x, y = 0; 213 | if (!GetPlayerX(x) || !GetPlayerY(y)) 214 | return 0; 215 | 216 | x -= posX; 217 | y -= posY; 218 | 219 | if ((x < radius) && (x > -radius) && (y < radius) && (y > -radius)) 220 | return 1; 221 | 222 | return 0; 223 | } 224 | 225 | EXPORT int Client::PlayerFunctions::IsPlayerInRange3D(float posX, float posY, float posZ, float radius) 226 | { 227 | float x, y, z = 0.0f; 228 | if (!GetPlayerPosition(x, y, z)) 229 | return 0; 230 | 231 | x -= posX; 232 | y -= posY; 233 | z -= posZ; 234 | 235 | if ((x < radius) && (x > -radius) && (y < radius) && (y > -radius) && (z < radius) && (z > -radius)) 236 | return 1; 237 | 238 | return 0; 239 | } 240 | 241 | EXPORT int Client::PlayerFunctions::GetCityName(char* &cityName, int max_len) 242 | { 243 | float x, y, z = 0.0f; 244 | if (!GetPlayerPosition(x, y, z)) 245 | return 0; 246 | 247 | for (int i = 0; i < ARRAYSIZE(GTAStructs::cities); i++) 248 | { 249 | const GTAStructs::City& cCity = GTAStructs::cities[i]; 250 | if (x > cCity.minX && y > cCity.minY && z > cCity.minZ && x < cCity.maxX && y < cCity.maxY && z < cCity.maxZ) 251 | { 252 | strcpy_s(cityName, max_len, cCity.name.c_str()); 253 | return 1; 254 | } 255 | } 256 | 257 | return 0; 258 | } 259 | 260 | EXPORT int Client::PlayerFunctions::GetZoneName(char* &zoneName, int max_len) 261 | { 262 | float x, y, z = 0.0f; 263 | if (!GetPlayerPosition(x, y, z)) 264 | return 0; 265 | 266 | for (int i = 0; i < ARRAYSIZE(GTAStructs::zones); i++) 267 | { 268 | const GTAStructs::Zone& cZone = GTAStructs::zones[i]; 269 | if (x > cZone.minX && y > cZone.minY && z > cZone.minZ && x < cZone.maxX && y < cZone.maxY && z < cZone.maxZ) 270 | { 271 | strcpy_s(zoneName, max_len, cZone.name.c_str()); 272 | return 1; 273 | } 274 | } 275 | 276 | return 0; 277 | } 278 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/PlayerFunctions.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Client.hpp" 3 | 4 | namespace Client 5 | { 6 | namespace PlayerFunctions 7 | { 8 | EXPORT int GetPlayerCPed(); 9 | EXPORT int GetPlayerHealth(); 10 | EXPORT int GetPlayerArmor(); 11 | EXPORT int GetPlayerMoney(); 12 | EXPORT int GetPlayerSkinID(); 13 | EXPORT int GetPlayerInterior(); 14 | EXPORT int IsPlayerInAnyVehicle(); 15 | EXPORT int IsPlayerDriver(); 16 | EXPORT int IsPlayerPassenger(); 17 | EXPORT int IsPlayerInInterior(); 18 | EXPORT int GetPlayerX(float &posX); 19 | EXPORT int GetPlayerY(float &posY); 20 | EXPORT int GetPlayerZ(float &posZ); 21 | EXPORT int GetPlayerPosition(float &posX, float &posY, float &posZ); 22 | EXPORT int IsPlayerInRange2D(float posX, float posY, float radius); 23 | EXPORT int IsPlayerInRange3D(float posX, float posY, float posZ, float radius); 24 | EXPORT int GetCityName(char* &cityName, int max_len); 25 | EXPORT int GetZoneName(char* &zoneName, int max_len); 26 | } 27 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/RenderFunctions.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Client.hpp" 3 | 4 | namespace Client 5 | { 6 | namespace RenderFunctions 7 | { 8 | EXPORT int TextCreate(const char *Font, int FontSize, bool bBold, bool bItalic, int x, int y, unsigned int color, const char *text, bool bShadow, bool bShow); 9 | EXPORT int TextDestroy(int ID); 10 | EXPORT int TextSetShadow(int id, bool b); 11 | EXPORT int TextSetShown(int id, bool b); 12 | EXPORT int TextSetColor(int id, unsigned int color); 13 | EXPORT int TextSetPos(int id, int x, int y); 14 | EXPORT int TextSetString(int id, const char *str); 15 | EXPORT int TextUpdate(int id, const char *Font, int FontSize, bool bBold, bool bItalic); 16 | 17 | EXPORT int BoxCreate(int x, int y, int w, int h, unsigned int dwColor, bool bShow); 18 | EXPORT int BoxDestroy(int id); 19 | EXPORT int BoxSetShown(int id, bool bShown); 20 | EXPORT int BoxSetBorder(int id, int height, bool bShown); 21 | EXPORT int BoxSetBorderColor(int id, unsigned int dwColor); 22 | EXPORT int BoxSetColor(int id, unsigned int dwColor); 23 | EXPORT int BoxSetHeight(int id, int height); 24 | EXPORT int BoxSetPos(int id, int x, int y); 25 | EXPORT int BoxSetWidth(int id, int width); 26 | 27 | EXPORT int LineCreate(int x1, int y1, int x2, int y2, int width, unsigned int color, bool bShow); 28 | EXPORT int LineDestroy(int id); 29 | EXPORT int LineSetShown(int id, bool bShown); 30 | EXPORT int LineSetColor(int id, unsigned int color); 31 | EXPORT int LineSetWidth(int id, int width); 32 | EXPORT int LineSetPos(int id, int x1, int y1, int x2, int y2); 33 | 34 | EXPORT int ImageCreate(const char *path, int x, int y, int rotation, int align, bool bShow); 35 | EXPORT int ImageDestroy(int id); 36 | EXPORT int ImageSetShown(int id, bool bShown); 37 | EXPORT int ImageSetAlign(int id, int align); 38 | EXPORT int ImageSetPos(int id, int x, int y); 39 | EXPORT int ImageSetRotation(int id, int rotation); 40 | 41 | EXPORT int DestroyAllVisual(); 42 | EXPORT int ShowAllVisual(); 43 | EXPORT int HideAllVisual(); 44 | 45 | EXPORT int GetFrameRate(); 46 | EXPORT int GetScreenSpecs(int& width, int& height); 47 | 48 | EXPORT int SetCalculationRatio(int width, int height); 49 | EXPORT int SetOverlayPriority(int id, int priority); 50 | EXPORT int SetOverlayCalculationEnabled(int id, bool enabled); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/SAMPFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "SAMPFunctions.hpp" 2 | #include "GTAFunctions.hpp" 3 | #include 4 | #include 5 | #include 6 | 7 | int Client::SAMPFunctions::ReadGTACmdArgument(const char *option, char *&str, const int max_len) { 8 | auto *szCommandLine = new char[513]; 9 | ZeroMemory(szCommandLine, 513); 10 | 11 | if (GTAFunctions::GetGTACommandLine(szCommandLine, 512) == 0) { 12 | delete[] szCommandLine; 13 | return 0; 14 | } 15 | 16 | // The gta_sa.exe process of SAMP looks something like this: 17 | // PATH/TO/gta_sa.exe -n NAME -h IP -p PORT 18 | // In here, we attempt to read any attributes that were passed in there 19 | char *context = nullptr; 20 | auto *token = strtok_s(szCommandLine, " ", &context); 21 | 22 | while (token != nullptr) { 23 | token = strtok_s(nullptr, " ", &context); 24 | if (strcmp(token, option) == 0) 25 | break; 26 | } 27 | 28 | if (token != nullptr) 29 | { 30 | token = strtok_s(nullptr, " ", &context); 31 | strcpy_s(str, max_len, token); 32 | } 33 | 34 | delete[] szCommandLine; 35 | return token != nullptr; 36 | } 37 | 38 | EXPORT int Client::SAMPFunctions::GetServerIP(char *&ip, const int max_len) 39 | { 40 | return ReadGTACmdArgument("-h", ip, max_len); 41 | } 42 | 43 | EXPORT int Client::SAMPFunctions::GetServerPort() 44 | { 45 | auto *portStr = new char[7]; 46 | ZeroMemory(portStr, 7); 47 | 48 | BOOST_SCOPE_EXIT_ALL(portStr) { 49 | delete[] portStr; 50 | }; 51 | 52 | if (ReadGTACmdArgument("-p", portStr, 6)) { 53 | errno = 0; 54 | const int port = strtol(portStr, nullptr, 10); 55 | if (errno != 0) 56 | return -1; 57 | return port; 58 | } 59 | 60 | return -1; 61 | } 62 | 63 | EXPORT int Client::SAMPFunctions::SendChat(const char *msg) 64 | { 65 | SERVER_CHECK(0) 66 | 67 | Utils::Serializer serializerIn, serializerOut; 68 | 69 | serializerIn << Shared::PipeMessages::SendChat << std::string(msg); 70 | 71 | if (Utils::PipeClient(serializerIn, serializerOut).success()) 72 | SERIALIZER_RET(int); 73 | 74 | return 0; 75 | } 76 | 77 | EXPORT int Client::SAMPFunctions::ShowGameText(const char *msg, int time, int style) 78 | { 79 | SERVER_CHECK(0) 80 | 81 | Utils::Serializer serializerIn, serializerOut; 82 | 83 | serializerIn << Shared::PipeMessages::ShowGameText << std::string(msg) << time << style; 84 | 85 | if (Utils::PipeClient(serializerIn, serializerOut).success()) 86 | SERIALIZER_RET(int); 87 | 88 | return 0; 89 | } 90 | 91 | EXPORT int Client::SAMPFunctions::AddChatMessage(const char *msg) 92 | { 93 | SERVER_CHECK(0) 94 | 95 | Utils::Serializer serializerIn, serializerOut; 96 | 97 | serializerIn << Shared::PipeMessages::AddChatMessage << std::string(msg); 98 | 99 | if (Utils::PipeClient(serializerIn, serializerOut).success()) 100 | SERIALIZER_RET(int); 101 | 102 | return 0; 103 | } 104 | 105 | EXPORT int Client::SAMPFunctions::ShowDialog(int id, int style, const char * caption, const char * text, const char * button, const char * button2) 106 | { 107 | SERVER_CHECK(0) 108 | 109 | Utils::Serializer serializerIn, serializerOut; 110 | 111 | serializerIn << Shared::PipeMessages::ShowDialog << id << style << std::string(caption) << std::string(text) << std::string(button) << std::string(button2); 112 | 113 | if (Utils::PipeClient(serializerIn, serializerOut).success()) 114 | SERIALIZER_RET(int); 115 | 116 | return 0; 117 | } 118 | 119 | EXPORT int Client::SAMPFunctions::GetPlayerNameByID(int id, char *&playername, int max_len) 120 | { 121 | SERVER_CHECK(0) 122 | 123 | Utils::Serializer serializerIn, serializerOut; 124 | 125 | serializerIn << Shared::PipeMessages::GetPlayerNameByID << id; 126 | 127 | if (Utils::PipeClient(serializerIn, serializerOut).success()) 128 | { 129 | std::string out; 130 | serializerOut >> out; 131 | 132 | if (!out.length()) 133 | return 0; 134 | 135 | strcpy_s(playername, max_len, out.c_str()); 136 | return 1; 137 | } 138 | 139 | return 0; 140 | } 141 | 142 | EXPORT int Client::SAMPFunctions::GetPlayerIDByName(const char *name) 143 | { 144 | for (int i = 0; i < 1004; i++) 145 | { 146 | char szBuffer[32] = { 0 }; 147 | char *ptr = szBuffer; 148 | 149 | if (GetPlayerNameByID(i, ptr, sizeof(szBuffer) - 1)) 150 | if (boost::iequals(std::string(szBuffer), std::string(name))) 151 | return i; 152 | } 153 | 154 | return -1; 155 | } 156 | 157 | EXPORT int Client::SAMPFunctions::GetPlayerName(char *&playername, const int max_len) 158 | { 159 | return ReadGTACmdArgument("-n", playername, max_len); 160 | } 161 | 162 | EXPORT int Client::SAMPFunctions::GetPlayerId() 163 | { 164 | auto *szName = new char[26]; 165 | ZeroMemory(szName, 26); 166 | 167 | GetPlayerName(szName, 25); 168 | 169 | const int iID = GetPlayerIDByName(szName); 170 | 171 | delete[] szName; 172 | 173 | return iID; 174 | } 175 | 176 | EXPORT int Client::SAMPFunctions::IsChatOpen() 177 | { 178 | SERVER_CHECK(0) 179 | 180 | Utils::Serializer serializerIn, serializerOut; 181 | 182 | serializerIn << Shared::PipeMessages::IsChatOpen; 183 | 184 | if (Utils::PipeClient(serializerIn, serializerOut).success()) 185 | SERIALIZER_RET(int); 186 | 187 | return 0; 188 | } 189 | 190 | EXPORT int Client::SAMPFunctions::IsDialogOpen() 191 | { 192 | SERVER_CHECK(0) 193 | 194 | Utils::Serializer serializerIn, serializerOut; 195 | 196 | serializerIn << Shared::PipeMessages::IsDialogOpen; 197 | 198 | if (Utils::PipeClient(serializerIn, serializerOut).success()) 199 | SERIALIZER_RET(int); 200 | 201 | return 0; 202 | } 203 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/SAMPFunctions.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Client.hpp" 3 | 4 | namespace Client 5 | { 6 | namespace SAMPFunctions 7 | { 8 | int ReadGTACmdArgument(const char * option, char *& str, int max_len); 9 | EXPORT int GetServerIP(char *&ip, int max_len); 10 | EXPORT int GetServerPort(); 11 | EXPORT int SendChat(const char *msg); 12 | EXPORT int ShowGameText(const char *msg, int time, int style); 13 | EXPORT int AddChatMessage(const char *msg); 14 | EXPORT int ShowDialog(int id, int style, const char *caption, const char *text, const char *button, const char *button2); 15 | EXPORT int GetPlayerNameByID(int id, char *&playername, int max_len); 16 | EXPORT int GetPlayerIDByName(const char *name); 17 | EXPORT int GetPlayerName(char *&playername, int max_len); 18 | EXPORT int GetPlayerId(); 19 | EXPORT int IsChatOpen(); 20 | EXPORT int IsDialogOpen(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/VehicleFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "VehicleFunctions.hpp" 2 | #include "MemoryFunctions.hpp" 3 | #include "PlayerFunctions.hpp" 4 | #include "GTAStructs.hpp" 5 | #include 6 | 7 | EXPORT unsigned int Client::VehicleFunctions::GetVehiclePointer() 8 | { 9 | unsigned int ptr = 0; 10 | if (MemoryFunctions::ReadMemory(0xBA18FC, 4, &ptr) != 4) 11 | return 0; 12 | 13 | return ptr; 14 | } 15 | 16 | EXPORT int Client::VehicleFunctions::GetVehicleSpeed(float factor) 17 | { 18 | DWORD ptr = GetVehiclePointer(); 19 | if (ptr == NULL) 20 | return -1; 21 | 22 | float x = 0.0, y = 0.0, z = 0.0; 23 | if (MemoryFunctions::ReadMemory(ptr + 0x44, 4, &x) != 4) 24 | return -1; 25 | 26 | if (MemoryFunctions::ReadMemory(ptr + 0x48, 4, &y) != 4) 27 | return -1; 28 | 29 | if (MemoryFunctions::ReadMemory(ptr + 0x4C, 4, &z) != 4) 30 | return -1; 31 | 32 | float speed = sqrt((x*x) + (y*y) + (z*z)) * (float)100.0 * factor; 33 | return (int)speed; 34 | } 35 | 36 | EXPORT float Client::VehicleFunctions::GetVehicleHealth() 37 | { 38 | DWORD ptr = GetVehiclePointer(); 39 | if (ptr == NULL) 40 | return -1.0f; 41 | 42 | float health = 0.0f; 43 | if (MemoryFunctions::ReadMemory(ptr + 0x4C0, 4, &health) != 4) 44 | return -1.0f; 45 | 46 | return health; 47 | } 48 | 49 | EXPORT int Client::VehicleFunctions::GetVehicleModelId() 50 | { 51 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 52 | return 0; 53 | 54 | int dwVehicleId = 0; 55 | MemoryFunctions::ReadMemory(GetVehiclePointer() + 0x22, 2, &dwVehicleId); 56 | return dwVehicleId; 57 | } 58 | 59 | EXPORT int Client::VehicleFunctions::GetVehicleModelName(char* &name, int max_len) 60 | { 61 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 62 | return 0; 63 | 64 | strcpy_s(name, max_len, GTAStructs::vehicles[GetVehicleModelId() - 400].c_str()); 65 | return 1; 66 | } 67 | 68 | EXPORT int Client::VehicleFunctions::GetVehicleModelNameById(int vehicleID, char* &name, int max_len) 69 | { 70 | strcpy_s(name, max_len, GTAStructs::vehicles[vehicleID - 400].c_str()); 71 | return 1; 72 | } 73 | 74 | EXPORT int Client::VehicleFunctions::GetVehicleType() 75 | { 76 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 77 | return -1; 78 | 79 | int dwVehicleType = 0; 80 | MemoryFunctions::ReadMemory(GetVehiclePointer() + 0x590, 1, &dwVehicleType); 81 | return dwVehicleType; 82 | } 83 | 84 | EXPORT int Client::VehicleFunctions::GetVehicleFreeSeats(int &seatFL, int &seatFR, int &seatRL, int &seatRR) 85 | { 86 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 87 | return 0; 88 | 89 | seatFL = IsVehicleSeatUsed(1); 90 | seatFR = IsVehicleSeatUsed(2); 91 | seatRL = IsVehicleSeatUsed(3); 92 | seatRR = IsVehicleSeatUsed(4); 93 | return 1; 94 | } 95 | 96 | EXPORT INT Client::VehicleFunctions::GetVehicleFirstColor() 97 | { 98 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 99 | return -1; 100 | 101 | int dwColor = 0; 102 | MemoryFunctions::ReadMemory(GetVehiclePointer() + 0x434, 1, &dwColor); 103 | return dwColor; 104 | } 105 | 106 | EXPORT INT Client::VehicleFunctions::GetVehicleSecondColor() 107 | { 108 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 109 | return -1; 110 | 111 | int dwColor = 0; 112 | MemoryFunctions::ReadMemory(GetVehiclePointer() + 0x435, 1, &dwColor); 113 | return dwColor; 114 | } 115 | 116 | EXPORT int Client::VehicleFunctions::GetVehicleColor(int &color1, int &color2) 117 | { 118 | color1 = -1; 119 | color2 = -1; 120 | 121 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 122 | return 0; 123 | 124 | color1 = GetVehicleFirstColor(); 125 | color2 = GetVehicleSecondColor(); 126 | return 1; 127 | } 128 | 129 | EXPORT int Client::VehicleFunctions::IsVehicleSeatUsed(int seat) 130 | { 131 | DWORD dwVehiclePtr = GetVehiclePointer(); 132 | if (!dwVehiclePtr) 133 | return 0; 134 | 135 | DWORD dwSeatPointer; 136 | seat = seat - 1; 137 | if (seat >= 0 && seat <= 8) 138 | MemoryFunctions::ReadMemory(dwVehiclePtr + 0x460 + seat * 4, 4, &dwSeatPointer); 139 | else 140 | return 0; 141 | 142 | if (dwSeatPointer) 143 | return 1; 144 | 145 | return 0; 146 | } 147 | 148 | EXPORT int Client::VehicleFunctions::IsVehicleLocked() 149 | { 150 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 151 | return 0; 152 | 153 | int dwDoorLockState = 0; 154 | MemoryFunctions::ReadMemory(GetVehiclePointer() + 0x4F8, 4, &dwDoorLockState); 155 | 156 | return (dwDoorLockState >> 1) & 1; 157 | } 158 | 159 | EXPORT int Client::VehicleFunctions::IsVehicleHornEnabled() 160 | { 161 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 162 | return 0; 163 | 164 | int dwHornState = 0; 165 | MemoryFunctions::ReadMemory(GetVehiclePointer() + 0x514, 1, &dwHornState); 166 | return dwHornState; 167 | } 168 | 169 | EXPORT int Client::VehicleFunctions::IsVehicleSirenEnabled() 170 | { 171 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 172 | return 0; 173 | 174 | int dwSirenState = 0; 175 | MemoryFunctions::ReadMemory(GetVehiclePointer() + 0x42D, 1, &dwSirenState); 176 | 177 | return (dwSirenState >> 7) & 1; 178 | } 179 | 180 | EXPORT int Client::VehicleFunctions::IsVehicleAlternateSirenEnabled() 181 | { 182 | return IsVehicleHornEnabled() && IsVehicleSirenEnabled(); 183 | } 184 | 185 | EXPORT int Client::VehicleFunctions::IsVehicleEngineEnabled() 186 | { 187 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 188 | return 0; 189 | 190 | int dwEngineState = 0; 191 | MemoryFunctions::ReadMemory(GetVehiclePointer() + 0x428, 1, &dwEngineState); 192 | 193 | return (dwEngineState >> 4) & 1; 194 | } 195 | 196 | EXPORT int Client::VehicleFunctions::IsVehicleLightEnabled() 197 | { 198 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 199 | return 0; 200 | 201 | int dwLightState = 0; 202 | MemoryFunctions::ReadMemory(GetVehiclePointer() + 0x4A8, 1, (char *)&dwLightState); 203 | 204 | return !((dwLightState >> 3) & 1); 205 | } 206 | 207 | EXPORT int Client::VehicleFunctions::IsVehicleCar() 208 | { 209 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 210 | return 0; 211 | 212 | if (GetVehicleType() != 0) 213 | return 0; 214 | 215 | for (int i = 0; i < ARRAYSIZE(GTAStructs::planeIDs); i++) 216 | if (GetVehicleModelId() == GTAStructs::planeIDs[i]) 217 | return 0; 218 | 219 | return 1; 220 | } 221 | 222 | EXPORT int Client::VehicleFunctions::IsVehiclePlane() 223 | { 224 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 225 | return 0; 226 | 227 | if (GetVehicleType() != 0) 228 | return 0; 229 | 230 | for (int i = 0; i < ARRAYSIZE(GTAStructs::planeIDs); i++) 231 | if (GetVehicleModelId() == GTAStructs::planeIDs[i]) 232 | return 1; 233 | 234 | return 0; 235 | } 236 | 237 | EXPORT int Client::VehicleFunctions::IsVehicleBoat() 238 | { 239 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 240 | return 0; 241 | 242 | if (GetVehicleType() != 5) 243 | return 0; 244 | 245 | return GetVehicleType() == 5; 246 | } 247 | 248 | EXPORT int Client::VehicleFunctions::IsVehicleTrain() 249 | { 250 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 251 | return 0; 252 | 253 | return GetVehicleType() == 6; 254 | } 255 | 256 | EXPORT int Client::VehicleFunctions::IsVehicleBike() 257 | { 258 | if (!PlayerFunctions::IsPlayerInAnyVehicle()) 259 | return 0; 260 | 261 | return GetVehicleType() == 9; 262 | } 263 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/VehicleFunctions.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Client.hpp" 3 | 4 | namespace Client 5 | { 6 | namespace VehicleFunctions 7 | { 8 | EXPORT unsigned int GetVehiclePointer(); 9 | 10 | EXPORT int GetVehicleSpeed(float factor); 11 | EXPORT float GetVehicleHealth(); 12 | EXPORT int GetVehicleModelId(); 13 | EXPORT int GetVehicleModelName(char* &name, int max_len); 14 | EXPORT int GetVehicleModelNameById(int vehicleID, char* &name, int max_len); 15 | EXPORT int GetVehicleType(); 16 | EXPORT int GetVehicleFreeSeats(int &seatFL, int &seatFR, int &seatRL, int &seatRR); 17 | EXPORT int GetVehicleFirstColor(); 18 | EXPORT int GetVehicleSecondColor(); 19 | EXPORT int GetVehicleColor(int &color1, int &color2); 20 | 21 | EXPORT int IsVehicleSeatUsed(int seat); 22 | EXPORT int IsVehicleLocked(); 23 | EXPORT int IsVehicleHornEnabled(); 24 | EXPORT int IsVehicleSirenEnabled(); 25 | EXPORT int IsVehicleAlternateSirenEnabled(); 26 | EXPORT int IsVehicleEngineEnabled(); 27 | EXPORT int IsVehicleLightEnabled(); 28 | EXPORT int IsVehicleCar(); 29 | EXPORT int IsVehiclePlane(); 30 | EXPORT int IsVehicleBoat(); 31 | EXPORT int IsVehicleTrain(); 32 | EXPORT int IsVehicleBike(); 33 | } 34 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/WeaponFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "WeaponFunctions.hpp" 2 | #include 3 | #include "PlayerFunctions.hpp" 4 | #include "MemoryFunctions.hpp" 5 | #include 6 | 7 | const char* weapNameArray[] = { "Fist", "Brass Knuckles", "Golf Club", "Nightstick", "Knife", // 0-4 8 | "Baseball Bat", "Shovel", "Pool Cue", "Katana", "Chainsaw", // 5 - 9 9 | "Purple Dildo", "Dildo", "Vibrator", "Silver Vibrator", "Flowers", // 10 - 14 10 | "Cane", "Grenade", "Tear Gas", "Molotov Cocktail", "", // 15 - 19 11 | "", "", "9mm", "Silenced 9mm", "Desert Eagle", // 20 - 24 12 | "Shotgun", "Sawnoff Shotgun", "Combat Shotgun", "Micro SMG/Uzi", "MP5", // 25 - 29 13 | "AK-47", "M4", "Tec-9", "Country Rifle", "Sniper Rifle",// 30 - 24 14 | "RPG", "Heatseeker RPG", "Flamethrower", "Minigun", "Satchel Charge",// 35 - 39 15 | "Detonator", "Spraycan", "Fire Extinguisher", "Camera", "Night Vision Googles",// 40 - 44 16 | "Thermal Googles", "Parachute",// 45 - 46 17 | }; 18 | 19 | const int weaponIdNoClip[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 40, 44, 45, 46 }; 20 | 21 | struct PedWeaponSlot 22 | { 23 | unsigned long type; 24 | unsigned long state; 25 | unsigned long ammoInClip; 26 | unsigned long ammoRemaining; 27 | float unknown; 28 | double unknown2; 29 | }; 30 | 31 | std::shared_ptr GetPlayerWeaponSlotStruct(int slot) 32 | { 33 | auto pws = std::make_shared(); 34 | auto cped = Client::PlayerFunctions::GetPlayerCPed(); 35 | if (cped == NULL) 36 | return nullptr; 37 | 38 | if (Client::MemoryFunctions::ReadMemory(cped + 0x5A0 + (slot * 0x1C), sizeof(PedWeaponSlot), pws.get()) == 0) 39 | return nullptr; 40 | 41 | return pws; 42 | 43 | } 44 | 45 | EXPORT int Client::WeaponFunctions::HasWeaponIDClip(int weaponID) 46 | { 47 | for (int i = 0; i < ARRAYSIZE(weaponIdNoClip); i++) 48 | if (weaponIdNoClip[i] == weaponID) 49 | return 0; 50 | 51 | return 1; 52 | } 53 | 54 | EXPORT int Client::WeaponFunctions::GetPlayerWeaponID() 55 | { 56 | DWORD cped = PlayerFunctions::GetPlayerCPed(); 57 | if (cped == NULL) 58 | return -1; 59 | 60 | int weaponType = GetPlayerWeaponType(); 61 | if (weaponType == -1) 62 | return -1; 63 | 64 | int weapon = 0; 65 | if (MemoryFunctions::ReadMemory(cped + 0x5A0 + (weaponType * 0x1C), 4, &weapon) != 4) 66 | return -1; 67 | 68 | return weapon; 69 | } 70 | 71 | EXPORT int Client::WeaponFunctions::GetPlayerWeaponType() 72 | { 73 | DWORD cped = PlayerFunctions::GetPlayerCPed(); 74 | if (cped == NULL) 75 | return -1; 76 | 77 | int weaponType = 0; 78 | if (MemoryFunctions::ReadMemory(cped + 0x718, 1, &weaponType) != 1) 79 | return -1; 80 | 81 | return weaponType; 82 | } 83 | 84 | EXPORT int Client::WeaponFunctions::GetPlayerWeaponSlot() 85 | { 86 | int dwWeaponSlot = 0; 87 | const int cped = PlayerFunctions::GetPlayerCPed(); 88 | if (cped == NULL) 89 | return -1; 90 | 91 | if (MemoryFunctions::ReadMemory(cped + 0x718, 1, &dwWeaponSlot) != 1) 92 | return -1; 93 | 94 | return dwWeaponSlot; 95 | } 96 | 97 | EXPORT int Client::WeaponFunctions::GetPlayerWeaponName(int dwWeapSlot, char* &_szWeapName, int max_len) 98 | { 99 | auto pws = GetPlayerWeaponSlotStruct(dwWeapSlot); 100 | if (pws == nullptr) 101 | return 0; 102 | 103 | if (pws->type < 0 || pws->type >= ARRAYSIZE(weapNameArray)) 104 | return 0; 105 | 106 | const char *ptr = weapNameArray[pws->type]; 107 | strcpy_s(_szWeapName, max_len, ptr); 108 | return 1; 109 | } 110 | 111 | EXPORT int Client::WeaponFunctions::GetPlayerWeaponClip(int dwWeapSlot) 112 | { 113 | auto pws = GetPlayerWeaponSlotStruct(dwWeapSlot); 114 | if (pws == nullptr) 115 | return -1; 116 | 117 | if(!HasWeaponIDClip(pws->type)) 118 | return 0; 119 | 120 | return pws->ammoInClip; 121 | } 122 | 123 | EXPORT int Client::WeaponFunctions::GetPlayerWeaponTotalClip(int dwWeapSlot) 124 | { 125 | auto pws = GetPlayerWeaponSlotStruct(dwWeapSlot); 126 | if (pws == nullptr) 127 | return -1; 128 | 129 | if (!HasWeaponIDClip(pws->type)) 130 | return 0; 131 | 132 | return pws->ammoRemaining; 133 | } 134 | 135 | EXPORT int Client::WeaponFunctions::GetPlayerWeaponState() 136 | { 137 | auto slot = GetPlayerWeaponSlot(); 138 | if (slot == -1) 139 | return -1; 140 | 141 | auto pws = GetPlayerWeaponSlotStruct(slot); 142 | if (pws == nullptr) 143 | return -1; 144 | 145 | return pws->state; 146 | } 147 | 148 | EXPORT int Client::WeaponFunctions::GetPlayerWeaponAmmo(int weaponType) 149 | { 150 | DWORD pedPtr = PlayerFunctions::GetPlayerCPed(); 151 | if (pedPtr == NULL) 152 | return -1; 153 | 154 | int ammo = 0; 155 | if (MemoryFunctions::ReadMemory(pedPtr + 0x5A0 + (weaponType * 0x1C) + 0x0C, 4, &ammo) != 4) 156 | return -1; 157 | 158 | return ammo; 159 | } 160 | 161 | EXPORT int Client::WeaponFunctions::GetPlayerWeaponAmmoInClip(int weaponType) 162 | { 163 | DWORD pedPtr = PlayerFunctions::GetPlayerCPed(); 164 | if (pedPtr == NULL) 165 | return -1; 166 | 167 | int ammo = 0; 168 | if (MemoryFunctions::ReadMemory(pedPtr + 0x5A0 + (weaponType * 0x1C) + 0x08, 4, &ammo) != 4) 169 | return -1; 170 | 171 | return ammo; 172 | } 173 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Client/WeaponFunctions.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Client.hpp" 3 | 4 | namespace Client 5 | { 6 | namespace WeaponFunctions 7 | { 8 | EXPORT int HasWeaponIDClip(int weaponID); 9 | EXPORT int GetPlayerWeaponID(); 10 | EXPORT int GetPlayerWeaponType(); 11 | EXPORT int GetPlayerWeaponSlot(); 12 | EXPORT int GetPlayerWeaponName(int dwWeapSlot, char* &_szWeapName, int max_len); 13 | EXPORT int GetPlayerWeaponClip(int dwWeapSlot); 14 | EXPORT int GetPlayerWeaponTotalClip(int dwWeapSlot); 15 | EXPORT int GetPlayerWeaponState(); 16 | EXPORT int GetPlayerWeaponAmmo(int weaponType); 17 | EXPORT int GetPlayerWeaponAmmoInClip(int weaponType); 18 | } 19 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/GTA/World.cpp: -------------------------------------------------------------------------------- 1 | #include "World.hpp" 2 | #include 3 | #include 4 | 5 | void CalcScreenCoords(D3DXVECTOR3 *vecWorld, D3DXVECTOR3 *vecScreen) 6 | { 7 | D3DXMATRIX m((float *)(0xB6FA2C)); 8 | 9 | DWORD *dwLenX = (DWORD *)(0xC17044); 10 | DWORD *dwLenY = (DWORD *)(0xC17048); 11 | 12 | vecScreen->x = (vecWorld->z * m._31) + (vecWorld->y * m._21) + (vecWorld->x * m._11) + m._41; 13 | vecScreen->y = (vecWorld->z * m._32) + (vecWorld->y * m._22) + (vecWorld->x * m._12) + m._42; 14 | vecScreen->z = (vecWorld->z * m._33) + (vecWorld->y * m._23) + (vecWorld->x * m._13) + m._43; 15 | 16 | double fRecip = (double) 1.0 / vecScreen->z; 17 | vecScreen->x *= (float)(fRecip * (*dwLenX)); 18 | vecScreen->y *= (float)(fRecip * (*dwLenY)); 19 | } 20 | 21 | void CalcWorldCoords(D3DXVECTOR3 *vecScreen, D3DXVECTOR3 *vecWorld) 22 | { 23 | D3DXMATRIX m((float *)(0xB6FA2C)); 24 | 25 | D3DXMATRIX minv; 26 | memset(&minv, 0, sizeof(D3DXMATRIX)); 27 | m._44 = 1.0f; 28 | D3DXMatrixInverse(&minv, NULL, &m); 29 | 30 | DWORD *dwLenX = (DWORD *)(0xC17044); 31 | DWORD *dwLenY = (DWORD *)(0xC17048); 32 | 33 | double fRecip = (double)1.0 / vecScreen->z; 34 | vecScreen->x /= (float)(fRecip * (*dwLenX)); 35 | vecScreen->y /= (float)(fRecip * (*dwLenY)); 36 | 37 | vecWorld->x = (vecScreen->z * minv._31) + (vecScreen->y * minv._21) + (vecScreen->x * minv._11) + minv._41; 38 | vecWorld->y = (vecScreen->z * minv._32) + (vecScreen->y * minv._22) + (vecScreen->x * minv._12) + minv._42; 39 | vecWorld->z = (vecScreen->z * minv._33) + (vecScreen->y * minv._23) + (vecScreen->x * minv._13) + minv._43; 40 | } 41 | 42 | bool Game::GTA::ScreenToWorld(float screenX, float screenY, float &worldX, float &worldY, float &worldZ) 43 | { 44 | D3DXVECTOR3 vecScreen(screenX, screenY, 700.0f), vecWorld; 45 | 46 | CalcWorldCoords(&vecScreen, &vecWorld); 47 | 48 | worldX = vecWorld.x; 49 | worldY = vecWorld.y; 50 | worldZ = vecWorld.z; 51 | 52 | return true; 53 | } 54 | 55 | bool Game::GTA::WorldToScreen(float x, float y, float z, float &screenX, float &screenY) 56 | { 57 | D3DXVECTOR3 vecScreen, vecWorld(x, y, z); 58 | 59 | CalcScreenCoords(&vecWorld, &vecScreen); 60 | 61 | screenX = vecScreen.x; 62 | screenY = vecScreen.y; 63 | 64 | if (vecScreen.z > 1.0f) 65 | return true; 66 | 67 | return false; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/GTA/World.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Game 4 | { 5 | namespace GTA 6 | { 7 | bool ScreenToWorld(float screenX, float screenY, float &worldX, float &worldY, float &worldZ); 8 | bool WorldToScreen(float x, float y, float z, float &screenX, float &screenY); 9 | } 10 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Game.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.hpp" 2 | #include "Messagehandler.hpp" 3 | #include "SAMP/SAMP.hpp" 4 | #include "SAMP/RemotePlayer.hpp" 5 | #include "Rendering/Renderer.hpp" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define BIND(T) PaketHandler[Shared::PipeMessages::T] = std::bind(Game::MessageHandler::T, std::placeholders::_1, std::placeholders::_2); 14 | 15 | Utils::Hook::Hook g_presentHook; 16 | Utils::Hook::Hook g_resetHook; 17 | 18 | bool g_bEnabled = false; 19 | 20 | extern "C" __declspec(dllexport) void enable() 21 | { 22 | g_bEnabled = true; 23 | } 24 | 25 | void initGame() 26 | { 27 | // initialize DirectX stuff 28 | { 29 | HMODULE hMod = NULL; 30 | 31 | while ((hMod = GetModuleHandle("d3d9.dll")) == NULL || g_bEnabled == false) 32 | Sleep(200); 33 | 34 | DWORD *vtbl = 0; 35 | DWORD dwDevice = Utils::Pattern::findPattern((DWORD)hMod, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx"); 36 | memcpy(&vtbl, (void *)(dwDevice + 0x2), 4); 37 | 38 | g_presentHook.apply(vtbl[17], [](LPDIRECT3DDEVICE9 dev, CONST RECT * a1, CONST RECT * a2, HWND a3, CONST RGNDATA *a4) -> HRESULT 39 | { 40 | __asm pushad 41 | Game::Rendering::Renderer::sharedRenderer().draw(dev); 42 | __asm popad 43 | 44 | return g_presentHook.callOrig(dev, a1, a2, a3, a4); 45 | }); 46 | 47 | g_resetHook.apply(vtbl[16], [](LPDIRECT3DDEVICE9 dev, D3DPRESENT_PARAMETERS *pp) -> HRESULT 48 | { 49 | __asm pushad 50 | Game::Rendering::Renderer::sharedRenderer().reset(dev); 51 | __asm popad 52 | 53 | return g_resetHook.callOrig(dev, pp); 54 | }); 55 | } 56 | 57 | // initialize SAMP 58 | { 59 | while (GetModuleHandleA("samp.dll") == NULL) 60 | Sleep(50); 61 | 62 | Game::SAMP::initSAMP(); 63 | } 64 | 65 | // initialize RPC 66 | typedef std::map > MessagePaketHandler; 67 | MessagePaketHandler PaketHandler; 68 | { 69 | BIND(TextCreate); 70 | BIND(TextDestroy); 71 | BIND(TextSetShadow); 72 | BIND(TextSetShown); 73 | BIND(TextSetColor); 74 | BIND(TextSetPos); 75 | BIND(TextSetString); 76 | BIND(TextUpdate); 77 | 78 | BIND(BoxCreate); 79 | BIND(BoxDestroy); 80 | BIND(BoxSetShown); 81 | BIND(BoxSetBorder); 82 | BIND(BoxSetBorderColor); 83 | BIND(BoxSetColor); 84 | BIND(BoxSetHeight); 85 | BIND(BoxSetPos); 86 | BIND(BoxSetWidth); 87 | 88 | BIND(LineCreate); 89 | BIND(LineDestroy); 90 | BIND(LineSetShown); 91 | BIND(LineSetColor); 92 | BIND(LineSetWidth); 93 | BIND(LineSetPos); 94 | 95 | BIND(ImageCreate); 96 | BIND(ImageDestroy); 97 | BIND(ImageSetShown); 98 | BIND(ImageSetAlign); 99 | BIND(ImageSetPos); 100 | BIND(ImageSetRotation); 101 | 102 | BIND(DestroyAllVisual); 103 | BIND(ShowAllVisual); 104 | BIND(HideAllVisual); 105 | 106 | BIND(GetFrameRate); 107 | BIND(GetScreenSpecs); 108 | 109 | BIND(SetCalculationRatio); 110 | BIND(SetOverlayPriority); 111 | BIND(SetOverlayCalculationEnabled); 112 | 113 | BIND(GetGTACommandLine); 114 | 115 | BIND(SendChat); 116 | BIND(ShowGameText); 117 | BIND(AddChatMessage); 118 | BIND(ShowDialog); 119 | BIND(GetPlayerNameByID); 120 | BIND(IsChatOpen); 121 | BIND(IsDialogOpen); 122 | 123 | BIND(ReadMemory); 124 | 125 | BIND(ScreenToWorld); 126 | BIND(WorldToScreen); 127 | 128 | new Utils::PipeServer([&](Utils::Serializer& serializerIn, Utils::Serializer& serializerOut) 129 | { 130 | SERIALIZATION_READ(serializerIn, Shared::PipeMessages, eMessage); 131 | 132 | try 133 | { 134 | auto it = PaketHandler.find(eMessage); 135 | if (it == PaketHandler.end()) 136 | return; 137 | 138 | if (!PaketHandler[eMessage]) 139 | return; 140 | 141 | PaketHandler[eMessage](serializerIn, serializerOut); 142 | } 143 | catch (...) 144 | { 145 | } 146 | }); 147 | } 148 | 149 | while (true){ 150 | Sleep(100); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Game.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | void initGame(); -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Messagehandler.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAMPProjects/Open-SAMP-API/d409a384bda26b996f2023d5199904186788708c/src/Open-SAMP-API/Game/Messagehandler.cpp -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Messagehandler.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Game 7 | { 8 | namespace MessageHandler 9 | { 10 | void TextCreate(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 11 | void TextDestroy(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 12 | void TextSetShadow(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 13 | void TextSetShown(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 14 | void TextSetColor(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 15 | void TextSetPos(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 16 | void TextSetString(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 17 | void TextUpdate(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 18 | 19 | void BoxCreate(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 20 | void BoxDestroy(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 21 | void BoxSetShown(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 22 | void BoxSetBorder(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 23 | void BoxSetBorderColor(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 24 | void BoxSetColor(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 25 | void BoxSetHeight(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 26 | void BoxSetPos(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 27 | void BoxSetWidth(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 28 | 29 | void LineCreate(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 30 | void LineDestroy(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 31 | void LineSetShown(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 32 | void LineSetColor(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 33 | void LineSetWidth(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 34 | void LineSetPos(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 35 | 36 | void ImageCreate(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 37 | void ImageDestroy(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 38 | void ImageSetShown(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 39 | void ImageSetAlign(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 40 | void ImageSetPos(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 41 | void ImageSetRotation(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 42 | 43 | void DestroyAllVisual(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 44 | void ShowAllVisual(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 45 | void HideAllVisual(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 46 | 47 | void GetFrameRate(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 48 | void GetScreenSpecs(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 49 | 50 | void SetCalculationRatio(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 51 | 52 | void SetOverlayPriority(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 53 | void SetOverlayCalculationEnabled(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 54 | 55 | void GetGTACommandLine(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 56 | 57 | void SendChat(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 58 | void ShowGameText(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 59 | void AddChatMessage(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 60 | void ShowDialog(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 61 | void GetPlayerNameByID(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 62 | void IsChatOpen(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 63 | void IsDialogOpen(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 64 | 65 | void ReadMemory(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 66 | 67 | void ScreenToWorld(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 68 | void WorldToScreen(Utils::Serializer& serializerIn, Utils::Serializer& serializerOut); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/Box.cpp: -------------------------------------------------------------------------------- 1 | #include "Box.hpp" 2 | #include "dx_utils.hpp" 3 | 4 | Game::Rendering::Box::Box(Renderer *renderer, int x, int y, int w, int h, D3DCOLOR color, bool show) 5 | : RenderBase(renderer), m_bShown(false) 6 | { 7 | setPos(x, y); 8 | setBoxWidth(w); 9 | setBoxHeight(h); 10 | setBoxColor(color); 11 | setShown(show); 12 | 13 | setBoxColor(color); 14 | setBorderWidth(0); 15 | setBorderShown(false); 16 | } 17 | 18 | 19 | void Game::Rendering::Box::setPos(int x,int y) 20 | { 21 | m_iX = x, m_iY = y; 22 | } 23 | 24 | void Game::Rendering::Box::setBorderColor(D3DCOLOR dwColor) 25 | { 26 | m_dwBorderColor = dwColor; 27 | } 28 | 29 | void Game::Rendering::Box::setBoxColor(D3DCOLOR dwColor) 30 | { 31 | m_dwBoxColor = dwColor; 32 | } 33 | 34 | void Game::Rendering::Box::setBorderWidth(DWORD dwWidth) 35 | { 36 | m_dwBorderWidth = dwWidth; 37 | } 38 | 39 | void Game::Rendering::Box::setBoxWidth(DWORD dwWidth) 40 | { 41 | m_dwBoxWidth = dwWidth; 42 | } 43 | 44 | void Game::Rendering::Box::setBoxHeight(DWORD dwHeight) 45 | { 46 | m_dwBoxHeight = dwHeight; 47 | } 48 | 49 | void Game::Rendering::Box::setBorderShown(bool b) 50 | { 51 | m_bBorderShown = b; 52 | } 53 | 54 | void Game::Rendering::Box::setShown(bool b) 55 | { 56 | m_bShown = b; 57 | } 58 | 59 | void Game::Rendering::Box::draw(IDirect3DDevice9 *pDevice) 60 | { 61 | if(!m_bShown) 62 | return; 63 | 64 | float x = (float)calculatedXPos(m_iX); 65 | float y = (float)calculatedYPos(m_iY); 66 | float w = (float)calculatedXPos(m_dwBoxWidth); 67 | float h = (float)calculatedYPos(m_dwBoxHeight); 68 | 69 | Drawing::DrawBox(x, y, w, h, m_dwBoxColor, pDevice); 70 | 71 | if(m_bBorderShown) 72 | Drawing::DrawRectangular(x, y, w, h, (float)m_dwBorderWidth, m_dwBorderColor, pDevice); 73 | } 74 | 75 | void Game::Rendering::Box::reset(IDirect3DDevice9 *pDevice) 76 | { 77 | 78 | } 79 | 80 | void Game::Rendering::Box::show() 81 | { 82 | setShown(true); 83 | } 84 | 85 | void Game::Rendering::Box::hide() 86 | { 87 | setShown(false); 88 | } 89 | 90 | void Game::Rendering::Box::releaseResourcesForDeletion(IDirect3DDevice9 *pDevice) 91 | { 92 | m_bShown = false; 93 | m_bBorderShown = false; 94 | } 95 | 96 | bool Game::Rendering::Box::canBeDeleted() 97 | { 98 | return true; 99 | } 100 | 101 | bool Game::Rendering::Box::loadResource(IDirect3DDevice9 *pDevice) 102 | { 103 | return true; 104 | } 105 | 106 | void Game::Rendering::Box::firstDrawAfterReset(IDirect3DDevice9 *pDevice) 107 | { 108 | 109 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/Box.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RenderBase.hpp" 3 | 4 | namespace Game 5 | { 6 | namespace Rendering 7 | { 8 | class Box : public RenderBase 9 | { 10 | public: 11 | Box(Renderer *renderer, int x, int y, int w, int h, D3DCOLOR color, bool show); 12 | 13 | void setPos(int x, int y); 14 | void setBorderColor(D3DCOLOR dwColor); 15 | void setBoxColor(D3DCOLOR dwColor); 16 | void setBorderWidth(DWORD dwWidth); 17 | void setBoxWidth(DWORD dwWidth); 18 | void setBoxHeight(DWORD dwHeight); 19 | void setBorderShown(bool b); 20 | void setShown(bool b); 21 | 22 | protected: 23 | virtual void draw(IDirect3DDevice9 *pDevice) sealed; 24 | virtual void reset(IDirect3DDevice9 *pDevice) sealed; 25 | 26 | virtual void show() sealed; 27 | virtual void hide() sealed; 28 | 29 | virtual void releaseResourcesForDeletion(IDirect3DDevice9 *pDevice) sealed; 30 | virtual bool canBeDeleted() sealed; 31 | 32 | virtual bool loadResource(IDirect3DDevice9 *pDevice) override sealed; 33 | virtual void firstDrawAfterReset(IDirect3DDevice9 *pDevice) override sealed; 34 | 35 | private: 36 | bool m_bShown, m_bBorderShown; 37 | D3DCOLOR m_dwBoxColor, m_dwBorderColor; 38 | DWORD m_dwBorderWidth, m_dwBoxWidth, m_dwBoxHeight; 39 | int m_iX, m_iY; 40 | }; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/D3DFont.hpp: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // File: D3DFont.h 3 | // 4 | // Desc: Texture-based font class 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //----------------------------------------------------------------------------- 8 | #ifndef D3DFONT_H 9 | #define D3DFONT_H 10 | #include 11 | #include 12 | 13 | 14 | // Font creation flags 15 | #define D3DFONT_BOLD 0x0001 16 | #define D3DFONT_ITALIC 0x0002 17 | #define D3DFONT_ZENABLE 0x0004 18 | 19 | // Font rendering flags 20 | #define D3DFONT_CENTERED_X 0x0001 21 | #define D3DFONT_CENTERED_Y 0x0002 22 | #define D3DFONT_TWOSIDED 0x0004 23 | #define D3DFONT_FILTERED 0x0008 24 | #define D3DFONT_BORDER 0x0010 25 | #define D3DFONT_COLORTABLE 0x0020 26 | 27 | 28 | //----------------------------------------------------------------------------- 29 | // Name: class CD3DFont 30 | // Desc: Texture-based font class for doing text in a 3D scene. 31 | //----------------------------------------------------------------------------- 32 | class CD3DFont 33 | { 34 | TCHAR m_strFontName[80]; // Font properties 35 | DWORD m_dwFontHeight; 36 | DWORD m_dwFontFlags; 37 | 38 | LPDIRECT3DDEVICE9 m_pd3dDevice; // A D3DDevice used for rendering 39 | LPDIRECT3DTEXTURE9 m_pTexture; // The d3d texture for this font 40 | LPDIRECT3DVERTEXBUFFER9 m_pVB; // VertexBuffer for rendering text 41 | DWORD m_dwTexWidth; // Texture dimensions 42 | DWORD m_dwTexHeight; 43 | FLOAT m_fTextScale; 44 | FLOAT m_fTexCoords[256 - 32][4]; 45 | DWORD m_dwSpacing; // Character pixel spacing per side 46 | 47 | // Stateblocks for setting and restoring render states 48 | LPDIRECT3DSTATEBLOCK9 m_pStateBlockSaved; 49 | LPDIRECT3DSTATEBLOCK9 m_pStateBlockDrawText; 50 | 51 | public: 52 | // 2D and 3D text drawing functions 53 | HRESULT DrawText(FLOAT x, FLOAT y, DWORD dwColor, const WCHAR* strText, DWORD dwFlags = 0L); 54 | 55 | // Function to get extent of text 56 | HRESULT GetTextExtent(const WCHAR* strText, SIZE* pSize); 57 | 58 | // Initializing and destroying device-dependent objects 59 | HRESULT InitDeviceObjects(LPDIRECT3DDEVICE9 pd3dDevice); 60 | HRESULT RestoreDeviceObjects(); 61 | HRESULT InvalidateDeviceObjects(); 62 | HRESULT DeleteDeviceObjects(); 63 | 64 | LPDIRECT3DDEVICE9 getDevice() const { return m_pd3dDevice; } 65 | // Constructor / destructor 66 | CD3DFont(const TCHAR* strFontName, DWORD dwHeight, DWORD dwFlags = 0L); 67 | ~CD3DFont(); 68 | }; 69 | 70 | #endif -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/Image.cpp: -------------------------------------------------------------------------------- 1 | #include "Image.hpp" 2 | #include "dx_utils.hpp" 3 | 4 | Game::Rendering::Image::Image(Renderer *renderer, const std::string& file_path, int x, int y, int rotation, int align, bool bShow) 5 | : RenderBase(renderer), m_pSprite(NULL), m_pTexture(NULL) 6 | { 7 | setFilePath(file_path); 8 | setPos(x, y); 9 | setRotation(rotation); 10 | setAlign(align); 11 | setShown(bShow); 12 | } 13 | 14 | void Game::Rendering::Image::setFilePath(const std::string & path) 15 | { 16 | m_filePath = path; 17 | } 18 | 19 | void Game::Rendering::Image::setPos(int x, int y) 20 | { 21 | m_x = x, m_y = y; 22 | } 23 | 24 | void Game::Rendering::Image::setRotation(int rotation) 25 | { 26 | m_rotation = rotation; 27 | } 28 | 29 | void Game::Rendering::Image::setAlign(int align) 30 | { 31 | m_align = align; 32 | } 33 | 34 | void Game::Rendering::Image::setShown(bool show) 35 | { 36 | m_bShow = show; 37 | } 38 | 39 | bool Game::Rendering::Image::updateImage(const std::string& file_path, int x, int y, int rotation, int align, bool bShow) 40 | { 41 | setFilePath(file_path); 42 | setPos(x, y); 43 | setRotation(rotation); 44 | setAlign(align); 45 | setShown(bShow); 46 | 47 | changeResource(); 48 | 49 | return true; 50 | } 51 | 52 | void Game::Rendering::Image::draw(IDirect3DDevice9 *pDevice) 53 | { 54 | if(!m_bShow) 55 | return; 56 | 57 | int x = calculatedXPos(m_x); 58 | int y = calculatedYPos(m_y); 59 | 60 | if(m_pTexture && m_pSprite) 61 | Drawing::DrawSprite(m_pSprite, m_pTexture, x, y, m_rotation, m_align); 62 | } 63 | 64 | void Game::Rendering::Image::reset(IDirect3DDevice9 *pDevice) 65 | { 66 | if(m_pSprite) 67 | { 68 | m_pSprite->OnLostDevice(); 69 | m_pSprite->OnResetDevice(); 70 | } 71 | } 72 | 73 | 74 | void Game::Rendering::Image::show() 75 | { 76 | setShown(true); 77 | } 78 | 79 | void Game::Rendering::Image::hide() 80 | { 81 | setShown(false); 82 | } 83 | 84 | 85 | void Game::Rendering::Image::releaseResourcesForDeletion(IDirect3DDevice9 *pDevice) 86 | { 87 | if(m_pSprite) 88 | { 89 | m_pSprite->Release(); 90 | m_pSprite = NULL; 91 | } 92 | 93 | if(m_pTexture) 94 | { 95 | m_pTexture->Release(); 96 | m_pTexture = NULL; 97 | } 98 | } 99 | 100 | bool Game::Rendering::Image::canBeDeleted() 101 | { 102 | return (m_pTexture == NULL && m_pSprite == NULL); 103 | } 104 | 105 | bool Game::Rendering::Image::loadResource(IDirect3DDevice9 *pDevice) 106 | { 107 | if(m_pSprite) 108 | { 109 | m_pSprite->Release(); 110 | m_pSprite = NULL; 111 | } 112 | 113 | if(m_pTexture) 114 | { 115 | m_pTexture->Release(); 116 | m_pTexture = NULL; 117 | } 118 | 119 | D3DXCreateTextureFromFileA(pDevice, m_filePath.c_str(), &m_pTexture); 120 | D3DXCreateSprite(pDevice, &m_pSprite); 121 | 122 | return (m_pTexture != NULL && m_pSprite != NULL); 123 | } 124 | 125 | void Game::Rendering::Image::firstDrawAfterReset(IDirect3DDevice9 *pDevice) 126 | { 127 | 128 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/Image.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RenderBase.hpp" 3 | 4 | namespace Game 5 | { 6 | namespace Rendering 7 | { 8 | class Image : public RenderBase 9 | { 10 | public: 11 | static void DrawSprite(LPD3DXSPRITE SpriteInterface, LPDIRECT3DTEXTURE9 TextureInterface, int PosX, int PosY, int Rotation, int Align); 12 | 13 | Image(Renderer *renderer, const std::string& file_path, int x, int y, int rotation, int align, bool bShow); 14 | 15 | void setFilePath(const std::string & path); 16 | void setPos(int x, int y); 17 | void setRotation(int rotation); 18 | void setAlign(int align); 19 | void setShown(bool show); 20 | bool updateImage(const std::string& file_path, int x, int y, int rotation, int align, bool bShow); 21 | 22 | protected: 23 | virtual void draw(IDirect3DDevice9 *pDevice) sealed; 24 | virtual void reset(IDirect3DDevice9 *pDevice) sealed; 25 | 26 | virtual void show() sealed; 27 | virtual void hide() sealed; 28 | 29 | virtual void releaseResourcesForDeletion(IDirect3DDevice9 *pDevice) sealed; 30 | virtual bool canBeDeleted() sealed; 31 | 32 | virtual bool loadResource(IDirect3DDevice9 *pDevice) override sealed; 33 | virtual void firstDrawAfterReset(IDirect3DDevice9 *pDevice) override sealed; 34 | 35 | private: 36 | std::string m_filePath; 37 | 38 | int m_x, m_y, m_rotation, m_align; 39 | 40 | bool m_bShow; 41 | 42 | LPDIRECT3DTEXTURE9 m_pTexture; 43 | LPD3DXSPRITE m_pSprite; 44 | }; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/Line.cpp: -------------------------------------------------------------------------------- 1 | #include "Line.hpp" 2 | 3 | Game::Rendering::Line::Line(Renderer *renderer, int x1,int y1,int x2,int y2,int width,D3DCOLOR color, bool bShow) 4 | : RenderBase(renderer), m_Line(NULL) 5 | { 6 | setPos(x1,y1,x2,y2); 7 | setWidth(width); 8 | setColor(color); 9 | setShown(bShow); 10 | } 11 | 12 | void Game::Rendering::Line::setPos(int x1,int y1,int x2,int y2) 13 | { 14 | m_X1 = x1, m_X2 = x2; 15 | m_Y1 = y1, m_Y2 = y2; 16 | } 17 | 18 | void Game::Rendering::Line::setWidth(int width) 19 | { 20 | m_Width = width; 21 | } 22 | 23 | void Game::Rendering::Line::setColor(D3DCOLOR color) 24 | { 25 | m_Color = color; 26 | } 27 | 28 | void Game::Rendering::Line::setShown(bool show) 29 | { 30 | m_bShow = show; 31 | } 32 | 33 | void Game::Rendering::Line::draw(IDirect3DDevice9 *pDevice) 34 | { 35 | if(!m_bShow || m_Line == NULL) 36 | return; 37 | 38 | D3DXVECTOR2 LinePos[2]; 39 | 40 | m_Line->SetAntialias(TRUE); 41 | m_Line->SetWidth((FLOAT)m_Width); 42 | 43 | m_Line->Begin(); 44 | 45 | LinePos[0].x = (float)calculatedXPos(m_X1); 46 | LinePos[0].y = (float)calculatedYPos(m_Y1); 47 | LinePos[1].x = (float)calculatedXPos(m_X2); 48 | LinePos[1].y = (float)calculatedYPos(m_Y2); 49 | 50 | m_Line->Draw(LinePos,2,m_Color); 51 | m_Line->End(); 52 | } 53 | 54 | void Game::Rendering::Line::reset(IDirect3DDevice9 *pDevice) 55 | { 56 | if(m_Line) 57 | { 58 | m_Line->OnLostDevice(); 59 | m_Line->OnResetDevice(); 60 | } 61 | } 62 | 63 | void Game::Rendering::Line::show() 64 | { 65 | setShown(true); 66 | } 67 | 68 | void Game::Rendering::Line::hide() 69 | { 70 | setShown(false); 71 | } 72 | 73 | void Game::Rendering::Line::releaseResourcesForDeletion(IDirect3DDevice9 *pDevice) 74 | { 75 | if(m_Line) 76 | { 77 | m_Line->Release(); 78 | m_Line = NULL; 79 | } 80 | } 81 | 82 | bool Game::Rendering::Line::canBeDeleted() 83 | { 84 | return (m_Line == NULL) ? true : false; 85 | } 86 | 87 | bool Game::Rendering::Line::loadResource(IDirect3DDevice9 *pDevice) 88 | { 89 | if(m_Line) 90 | { 91 | m_Line->Release(); 92 | m_Line = NULL; 93 | } 94 | 95 | D3DXCreateLine(pDevice,&m_Line); 96 | 97 | return m_Line != NULL; 98 | } 99 | 100 | void Game::Rendering::Line::firstDrawAfterReset(IDirect3DDevice9 *pDevice) 101 | { 102 | 103 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/Line.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RenderBase.hpp" 3 | 4 | namespace Game 5 | { 6 | namespace Rendering 7 | { 8 | class Line : public RenderBase 9 | { 10 | public: 11 | Line(Renderer *renderer, int x1, int y1, int x2, int y2, int width, D3DCOLOR color, bool bShow); 12 | 13 | void setPos(int x1, int y1, int x2, int y2); 14 | void setWidth(int width); 15 | void setColor(D3DCOLOR color); 16 | void setShown(bool show); 17 | 18 | protected: 19 | virtual void draw(IDirect3DDevice9 *pDevice) sealed; 20 | virtual void reset(IDirect3DDevice9 *pDevice) sealed; 21 | 22 | virtual void show() sealed; 23 | virtual void hide() sealed; 24 | 25 | virtual void releaseResourcesForDeletion(IDirect3DDevice9 *pDevice) sealed; 26 | virtual bool canBeDeleted() sealed; 27 | 28 | virtual bool loadResource(IDirect3DDevice9 *pDevice) override sealed; 29 | virtual void firstDrawAfterReset(IDirect3DDevice9 *pDevice) override sealed; 30 | 31 | private: 32 | int m_X1, m_X2, m_Y1, m_Y2, m_Width; 33 | 34 | bool m_bShow; 35 | 36 | D3DCOLOR m_Color; 37 | 38 | LPD3DXLINE m_Line; 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/RenderBase.cpp: -------------------------------------------------------------------------------- 1 | #include "RenderBase.hpp" 2 | 3 | int Game::Rendering::RenderBase::xCalculator = 800; 4 | int Game::Rendering::RenderBase::yCalculator = 600; 5 | 6 | Game::Rendering::RenderBase::RenderBase(Renderer *renderer) 7 | : _renderer(renderer), _isMarkedForDeletion(false), _resourceChanged(false), _hasToBeInitialised(true), _firstDrawAfterReset(false) 8 | { 9 | } 10 | 11 | Game::Rendering::RenderBase::~RenderBase() 12 | { 13 | } 14 | 15 | void Game::Rendering::RenderBase::setPriority(int p) 16 | { 17 | _priority = p; 18 | } 19 | 20 | int Game::Rendering::RenderBase::priority() 21 | { 22 | return _priority; 23 | } 24 | 25 | void Game::Rendering::RenderBase::setCalculationEnabled(bool enabled) 26 | { 27 | _calculationEnabled = enabled; 28 | } 29 | 30 | bool Game::Rendering::RenderBase::isCalculationEnabled() 31 | { 32 | return _calculationEnabled; 33 | } 34 | 35 | void Game::Rendering::RenderBase::changeResource() 36 | { 37 | _resourceChanged = true; 38 | } 39 | 40 | int Game::Rendering::RenderBase::calculatedXPos(int x) 41 | { 42 | return _calculationEnabled ? (int)(((float)x / (float)xCalculator) * (float)_renderer->screenWidth()) : x; 43 | } 44 | 45 | int Game::Rendering::RenderBase::calculatedYPos(int y) 46 | { 47 | return _calculationEnabled ? (int)(((float)y / (float)yCalculator) * (float)_renderer->screenHeight()) : y; 48 | } 49 | 50 | Game::Rendering::Renderer *Game::Rendering::RenderBase::renderer() 51 | { 52 | return _renderer; 53 | } 54 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/RenderBase.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Renderer.hpp" 3 | 4 | namespace Game 5 | { 6 | namespace Rendering 7 | { 8 | class RenderBase 9 | { 10 | friend class Renderer; 11 | public: 12 | static int xCalculator; 13 | static int yCalculator; 14 | 15 | RenderBase(Renderer *render); 16 | virtual ~RenderBase(void); 17 | 18 | void setPriority(int p); 19 | int priority(); 20 | 21 | void setCalculationEnabled(bool enabled); 22 | bool isCalculationEnabled(); 23 | 24 | protected: 25 | virtual void draw(IDirect3DDevice9 *pDevice) = 0; 26 | virtual void reset(IDirect3DDevice9 *pDevice) = 0; 27 | 28 | virtual void show() = 0; 29 | virtual void hide() = 0; 30 | 31 | virtual void releaseResourcesForDeletion(IDirect3DDevice9 *pDevice) = 0; 32 | 33 | virtual bool canBeDeleted() = 0; 34 | 35 | virtual bool loadResource(IDirect3DDevice9 *pDevice) = 0; 36 | 37 | virtual void firstDrawAfterReset(IDirect3DDevice9 *pDevice) = 0; 38 | 39 | void changeResource(); 40 | 41 | int calculatedXPos(int x); 42 | int calculatedYPos(int y); 43 | 44 | Renderer *renderer(); 45 | 46 | private: 47 | bool _hasToBeInitialised, _isMarkedForDeletion, _resourceChanged, _firstDrawAfterReset; 48 | 49 | int _priority = 0; 50 | bool _calculationEnabled = true; 51 | 52 | Renderer *_renderer; 53 | }; 54 | } 55 | } 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/Renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "Renderer.hpp" 2 | #include "RenderBase.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | Game::Rendering::Renderer::RenderObjects Game::Rendering::Renderer::_renderObjects; 9 | std::recursive_mutex Game::Rendering::Renderer::_mtx; 10 | 11 | int Game::Rendering::Renderer::add(SharedRenderObject Object) 12 | { 13 | std::lock_guard l(_mtx); 14 | 15 | int id = 0; 16 | 17 | if(!_renderObjects.empty()) 18 | for(;;id++) 19 | if(_renderObjects.find(id) == _renderObjects.end()) 20 | break; 21 | 22 | _renderObjects[id] = Object; 23 | 24 | return id; 25 | } 26 | 27 | bool Game::Rendering::Renderer::remove(int id) 28 | { 29 | std::lock_guard l(_mtx); 30 | 31 | auto ptr = get(id); 32 | if (!ptr) 33 | return false; 34 | 35 | return ptr->_isMarkedForDeletion = true; 36 | } 37 | 38 | std::shared_ptr Game::Rendering::Renderer::get(int id) 39 | { 40 | if (_renderObjects.empty()) 41 | return nullptr; 42 | 43 | if (_renderObjects.find(id) == _renderObjects.end()) 44 | return nullptr; 45 | 46 | if (_renderObjects[id]->_isMarkedForDeletion) 47 | return nullptr; 48 | 49 | return _renderObjects[id]; 50 | } 51 | 52 | void Game::Rendering::Renderer::draw(IDirect3DDevice9 *pDevice) 53 | { 54 | std::lock_guard l(_mtx); 55 | 56 | // Read frame rate 57 | { 58 | static DWORD dwFrames = 0; 59 | static boost::posix_time::ptime TimeNow; 60 | static boost::posix_time::ptime TimeLast = boost::posix_time::microsec_clock::local_time(); 61 | static DWORD dwElapsedTime = 0; 62 | 63 | dwFrames++; 64 | TimeNow = boost::posix_time::microsec_clock::local_time(); 65 | dwElapsedTime = (TimeNow - TimeLast).total_milliseconds() & 0xFFFFFFFF; 66 | 67 | if (dwElapsedTime >= 500) 68 | { 69 | float fFPS = (((float) dwFrames) * 1000.0f) / ((float) dwElapsedTime); 70 | _frameRate = (int) fFPS; 71 | dwFrames = 0; 72 | TimeLast = TimeNow; 73 | } 74 | } 75 | 76 | // Get frame's screen bounds 77 | { 78 | D3DVIEWPORT9 viewPort; 79 | pDevice->GetViewport(&viewPort); 80 | 81 | _width = viewPort.Width; 82 | _height = viewPort.Height; 83 | } 84 | 85 | if(_renderObjects.empty()) 86 | return; 87 | 88 | // Delete all objects from the map which are marked for deletion 89 | erase_if(_renderObjects, [&](int id, SharedRenderObject obj) -> bool 90 | { 91 | if(obj->_isMarkedForDeletion) 92 | { 93 | obj->releaseResourcesForDeletion(pDevice); 94 | return obj->canBeDeleted(); 95 | } 96 | 97 | return false; 98 | }); 99 | 100 | 101 | // Push all render objects in a vector which will be sorted later 102 | std::vector sortedObjects; 103 | for (auto it = _renderObjects.begin(); it != _renderObjects.end(); it++) 104 | sortedObjects.push_back(it->second); 105 | 106 | // Sort render objects by priority 107 | std::sort(sortedObjects.begin(), sortedObjects.end(), [](SharedRenderObject& i, SharedRenderObject& j){ 108 | return i->priority() < j->priority(); 109 | }); 110 | 111 | // Process sorted render objects 112 | for (auto& i : sortedObjects) 113 | { 114 | if(i->_hasToBeInitialised) 115 | { 116 | if(!i->loadResource(pDevice)) 117 | continue; 118 | 119 | i->_hasToBeInitialised = false; 120 | } 121 | 122 | if(i->_firstDrawAfterReset) 123 | { 124 | i->firstDrawAfterReset(pDevice); 125 | i->_firstDrawAfterReset = false; 126 | } 127 | 128 | if(i->_resourceChanged) 129 | { 130 | i->releaseResourcesForDeletion(pDevice); 131 | if(!i->loadResource(pDevice)) 132 | continue; 133 | 134 | i->_resourceChanged = false; 135 | } 136 | 137 | i->draw(pDevice); 138 | } 139 | } 140 | 141 | void Game::Rendering::Renderer::reset(IDirect3DDevice9 *pDevice) 142 | { 143 | std::lock_guard l(_mtx); 144 | 145 | if(_renderObjects.empty()) 146 | return; 147 | 148 | for(auto it = _renderObjects.begin(); it != _renderObjects.end(); it ++) 149 | { 150 | it->second->reset(pDevice); 151 | it->second->_firstDrawAfterReset = true; 152 | } 153 | } 154 | 155 | void Game::Rendering::Renderer::showAll() 156 | { 157 | std::lock_guard l(_mtx); 158 | 159 | if(_renderObjects.empty()) 160 | return; 161 | 162 | for(auto it = _renderObjects.begin(); it != _renderObjects.end();it ++) 163 | { 164 | if(it->second->_isMarkedForDeletion) 165 | continue; 166 | 167 | it->second->show(); 168 | } 169 | } 170 | 171 | void Game::Rendering::Renderer::hideAll() 172 | { 173 | std::lock_guard l(_mtx); 174 | 175 | if(_renderObjects.empty()) 176 | return; 177 | 178 | for(auto it = _renderObjects.begin(); it != _renderObjects.end();it ++) 179 | { 180 | if(it->second->_isMarkedForDeletion) 181 | continue; 182 | 183 | it->second->hide(); 184 | } 185 | } 186 | 187 | void Game::Rendering::Renderer::destroyAll() 188 | { 189 | std::lock_guard l(_mtx); 190 | 191 | if(_renderObjects.empty()) 192 | return; 193 | 194 | for(auto it = _renderObjects.begin(); it != _renderObjects.end(); it ++) 195 | it->second->_isMarkedForDeletion = true; 196 | } 197 | 198 | int Game::Rendering::Renderer::frameRate() const 199 | { 200 | return _frameRate; 201 | } 202 | 203 | int Game::Rendering::Renderer::screenWidth() const 204 | { 205 | return _width; 206 | } 207 | 208 | int Game::Rendering::Renderer::screenHeight() const 209 | { 210 | return _height; 211 | } 212 | 213 | std::recursive_mutex& Game::Rendering::Renderer::renderMutex() 214 | { 215 | return _mtx; 216 | } 217 | 218 | Game::Rendering::Renderer& Game::Rendering::Renderer::sharedRenderer() 219 | { 220 | static Renderer render; 221 | return render; 222 | } 223 | 224 | Game::Rendering::Renderer::Renderer() 225 | { 226 | 227 | } 228 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/Renderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Game 9 | { 10 | namespace Rendering 11 | { 12 | class RenderBase; 13 | 14 | class Renderer 15 | { 16 | typedef std::shared_ptr SharedRenderObject; 17 | typedef std::map RenderObjects; 18 | 19 | public: 20 | int add(SharedRenderObject Object); 21 | bool remove(int id); 22 | 23 | template 24 | std::shared_ptr getAs(int id) 25 | { 26 | if (_renderObjects.empty()) 27 | return nullptr; 28 | 29 | if (_renderObjects.find(id) == _renderObjects.end()) 30 | return nullptr; 31 | 32 | if (_renderObjects[id]->_isMarkedForDeletion) 33 | return nullptr; 34 | 35 | return std::dynamic_pointer_cast(_renderObjects[id]); 36 | } 37 | 38 | std::shared_ptr get(int id); 39 | 40 | template 41 | void execute(int id, std::function)> successor = nullptr, std::function error = nullptr) 42 | { 43 | auto obj = getAs(id); 44 | if (obj && successor) 45 | return successor(obj); 46 | 47 | if (error) 48 | return error(); 49 | } 50 | 51 | void draw(IDirect3DDevice9 *pDevice); 52 | void reset(IDirect3DDevice9 *pDevice); 53 | 54 | void showAll(); 55 | void hideAll(); 56 | void destroyAll(); 57 | 58 | int frameRate() const; 59 | 60 | int screenWidth() const; 61 | int screenHeight() const; 62 | 63 | std::recursive_mutex& renderMutex(); 64 | 65 | static Renderer& sharedRenderer(); 66 | 67 | private: 68 | Renderer(); 69 | 70 | int _frameRate, _width, _height; 71 | 72 | static RenderObjects _renderObjects; 73 | static std::recursive_mutex _mtx; 74 | }; 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/Text.cpp: -------------------------------------------------------------------------------- 1 | #include "Text.hpp" 2 | #include "dx_utils.hpp" 3 | #include 4 | 5 | Game::Rendering::Text::Text(Renderer *renderer, const std::string& font,int iFontSize,bool Bold,bool Italic,int x,int y,D3DCOLOR color,const std::string& text, bool bShadow, bool bShow) 6 | : RenderBase(renderer), m_D3DFont(NULL) 7 | { 8 | setPos(x,y); 9 | setColor(color); 10 | setText(text); 11 | setShadow(bShadow); 12 | setShown(bShow); 13 | 14 | m_Font = font; 15 | m_FontSize = iFontSize; 16 | m_bBold = Bold; 17 | m_bItalic = Italic; 18 | } 19 | 20 | 21 | bool Game::Rendering::Text::updateText(const std::string& Font,int FontSize,bool Bold,bool Italic) 22 | { 23 | m_Font = Font; 24 | m_FontSize = FontSize; 25 | m_bBold = Bold; 26 | m_bItalic = Italic; 27 | 28 | changeResource(); 29 | return true; 30 | } 31 | 32 | void Game::Rendering::Text::setText(const std::string& str) 33 | { 34 | int length = str.length(); 35 | 36 | if (length > 0) 37 | { 38 | auto nativeWideString = std::unique_ptr(new wchar_t[length + 1]); 39 | nativeWideString.get()[length] = '\0'; 40 | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str.c_str(), length, nativeWideString.get(), length); 41 | 42 | std::wstring newString = std::wstring(nativeWideString.get()); 43 | m_Text = newString; 44 | } 45 | else 46 | m_Text = L""; 47 | } 48 | 49 | void Game::Rendering::Text::setColor(D3DCOLOR color) 50 | { 51 | m_Color = color; 52 | } 53 | 54 | void Game::Rendering::Text::setPos(int x,int y) 55 | { 56 | m_X = x, m_Y = y; 57 | } 58 | 59 | void Game::Rendering::Text::setShown(bool bShown) 60 | { 61 | m_bShown = bShown; 62 | } 63 | 64 | void Game::Rendering::Text::setShadow(bool bShadow) 65 | { 66 | m_bShadow = bShadow; 67 | } 68 | 69 | void Game::Rendering::Text::draw(IDirect3DDevice9 *pDevice) 70 | { 71 | if(!m_bShown) 72 | return; 73 | 74 | int x = calculatedXPos(m_X); 75 | int y = calculatedYPos(m_Y); 76 | 77 | if(m_bShadow) 78 | { 79 | const int shadowOffset = 1; 80 | 81 | drawText(x - shadowOffset, y, D3DCOLOR_ARGB(255, 0, 0, 0), m_Text); 82 | drawText(x + shadowOffset, y, D3DCOLOR_ARGB(255, 0, 0, 0), m_Text); 83 | drawText(x, y - shadowOffset, D3DCOLOR_ARGB(255, 0, 0, 0), m_Text); 84 | drawText(x, y + shadowOffset, D3DCOLOR_ARGB(255, 0, 0, 0), m_Text); 85 | } 86 | 87 | drawText(x, y, m_Color, m_Text, D3DFONT_COLORTABLE); 88 | } 89 | 90 | void Game::Rendering::Text::reset(IDirect3DDevice9 *pDevice) 91 | { 92 | resetFont(); 93 | } 94 | 95 | void Game::Rendering::Text::show() 96 | { 97 | setShown(true); 98 | } 99 | 100 | void Game::Rendering::Text::hide() 101 | { 102 | setShown(false); 103 | } 104 | 105 | void Game::Rendering::Text::releaseResourcesForDeletion(IDirect3DDevice9 *pDevice) 106 | { 107 | resetFont(); 108 | } 109 | 110 | bool Game::Rendering::Text::canBeDeleted() 111 | { 112 | return m_D3DFont == nullptr; 113 | } 114 | 115 | bool Game::Rendering::Text::loadResource(IDirect3DDevice9 *pDevice) 116 | { 117 | initFont(pDevice); 118 | return true; 119 | } 120 | 121 | void Game::Rendering::Text::firstDrawAfterReset(IDirect3DDevice9 *pDevice) 122 | { 123 | loadResource(pDevice); 124 | } 125 | 126 | void Game::Rendering::Text::initFont(IDirect3DDevice9 *pDevice) 127 | { 128 | int size = calculatedYPos(m_FontSize); 129 | 130 | m_D3DFont = std::make_shared(m_Font.c_str(), size, (m_bBold) ? D3DFONT_BOLD : 0 | (m_bItalic) ? D3DFONT_ITALIC : 0 | D3DFONT_FILTERED); 131 | m_D3DFont->InitDeviceObjects(pDevice); 132 | m_D3DFont->RestoreDeviceObjects(); 133 | } 134 | 135 | void Game::Rendering::Text::resetFont() 136 | { 137 | m_D3DFont.reset(); 138 | } 139 | 140 | bool Game::Rendering::Text::drawText(int x, int y, DWORD dwColor, const std::wstring& strText, DWORD dwFlags /*= 0L*/) 141 | { 142 | return Utils::SafeBlock::safeExecuteWithValidation([&](){ 143 | m_D3DFont->DrawTextA((float)x, (float)y, dwColor, m_Text.c_str(), dwFlags); 144 | }); 145 | } 146 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/Text.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RenderBase.hpp" 3 | #include "D3DFont.hpp" 4 | #include 5 | 6 | namespace Game 7 | { 8 | namespace Rendering 9 | { 10 | class Text : public RenderBase 11 | { 12 | public: 13 | Text(Renderer *renderer, const std::string& font, int iFontSize, bool Bold, bool Italic, int x, int y, D3DCOLOR color, const std::string& text, bool bShadow, bool bShow); 14 | 15 | bool updateText(const std::string& Font, int FontSize, bool Bold, bool Italic); 16 | void setText(const std::string& str); 17 | void setColor(D3DCOLOR color); 18 | void setPos(int x, int y); 19 | void setShown(bool bShow); 20 | void setShadow(bool bShadow); 21 | 22 | protected: 23 | virtual void draw(IDirect3DDevice9 *pDevice) sealed; 24 | virtual void reset(IDirect3DDevice9 *pDevice) sealed; 25 | 26 | virtual void show() override sealed; 27 | virtual void hide() override sealed; 28 | 29 | virtual void releaseResourcesForDeletion(IDirect3DDevice9 *pDevice) override sealed; 30 | virtual bool canBeDeleted() override sealed; 31 | 32 | virtual bool loadResource(IDirect3DDevice9 *pDevice) override sealed; 33 | virtual void firstDrawAfterReset(IDirect3DDevice9 *pDevice) override sealed; 34 | 35 | private: 36 | std::wstring m_Text; 37 | std::string m_Font; 38 | int m_X, m_Y, m_FontSize; 39 | D3DCOLOR m_Color; 40 | std::shared_ptr m_D3DFont; 41 | bool m_bShown, m_bShadow, m_bItalic, m_bBold; 42 | 43 | void initFont(IDirect3DDevice9 *pDevice); 44 | void resetFont(); 45 | bool drawText(int x, int y, DWORD dwColor, const std::wstring& strText, DWORD dwFlags = 0L); 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/dx_utils.cpp: -------------------------------------------------------------------------------- 1 | #include "dx_utils.hpp" 2 | 3 | 4 | struct stVertex 5 | { 6 | float fX, fY, fZ, fRHW; 7 | D3DCOLOR dwColor; 8 | }; 9 | 10 | void Game::Rendering::Drawing::DrawBox(float x, float y, float w, float h, DWORD color, LPDIRECT3DDEVICE9 pDevice) 11 | { 12 | stVertex q[4]; 13 | 14 | q[0].dwColor = q[1].dwColor = q[2].dwColor = q[3].dwColor = color; 15 | 16 | q[0].fZ = q[1].fZ = q[2].fZ = q[3].fZ = 0; 17 | q[0].fRHW = q[1].fRHW = q[2].fRHW = q[3].fRHW = 0; 18 | 19 | q[0].fX = q[2].fX = x; 20 | q[0].fY = q[1].fY = y; 21 | q[1].fX = q[3].fX = x + w; 22 | q[2].fY = q[3].fY = y + h; 23 | 24 | Game::Rendering::Drawing::DrawPrimtive(pDevice, D3DPT_TRIANGLESTRIP, 2, q, sizeof(stVertex)); 25 | } 26 | 27 | void Game::Rendering::Drawing::DrawRectangular(float X, float Y, float Width, float Height, float Thickness, D3DCOLOR Color, LPDIRECT3DDEVICE9 pDev) 28 | { 29 | Game::Rendering::Drawing::DrawBox(X, Y + Height - Thickness, Width, Thickness, Color, pDev); 30 | Game::Rendering::Drawing::DrawBox(X, Y, Thickness, Height, Color, pDev); 31 | Game::Rendering::Drawing::DrawBox(X, Y, Width, Thickness, Color, pDev); 32 | Game::Rendering::Drawing::DrawBox(X + Width - Thickness, Y, Thickness, Height, Color, pDev); 33 | } 34 | 35 | void Game::Rendering::Drawing::DrawPrimtive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride, DWORD FVF) 36 | { 37 | DWORD dwOldFVF; 38 | LPDIRECT3DPIXELSHADER9 ppixelShader; 39 | LPDIRECT3DBASETEXTURE9 ppTexture; 40 | 41 | pDevice->GetFVF(&dwOldFVF); 42 | pDevice->GetPixelShader(&ppixelShader); 43 | pDevice->GetTexture(0, &ppTexture); 44 | 45 | pDevice->SetPixelShader(NULL); 46 | pDevice->SetTexture(0, NULL); 47 | pDevice->SetFVF(FVF); 48 | 49 | pDevice->DrawPrimitiveUP(PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride); 50 | 51 | pDevice->SetPixelShader(ppixelShader); 52 | pDevice->SetTexture(0, ppTexture); 53 | pDevice->SetFVF(dwOldFVF); 54 | } 55 | 56 | void Game::Rendering::Drawing::DrawSprite(LPD3DXSPRITE SpriteInterface, LPDIRECT3DTEXTURE9 TextureInterface, int PosX, int PosY, int Rotation, int Align) 57 | { 58 | if (SpriteInterface == NULL || TextureInterface == NULL) 59 | return; 60 | 61 | D3DXVECTOR3 Vec; 62 | 63 | Vec.x = (FLOAT) PosX; 64 | Vec.y = (FLOAT) PosY; 65 | Vec.z = (FLOAT)0.0f; 66 | 67 | D3DXMATRIX mat; 68 | D3DXVECTOR2 scaling(1.0f, 1.0f); 69 | D3DSURFACE_DESC desc; 70 | 71 | TextureInterface->GetLevelDesc(0, &desc); 72 | 73 | D3DXVECTOR2 spriteCentre; 74 | if (Align == 1) 75 | spriteCentre = D3DXVECTOR2((FLOAT) desc.Width / 2, (FLOAT) desc.Height / 2); 76 | else 77 | spriteCentre = D3DXVECTOR2(0, 0); 78 | 79 | D3DXVECTOR2 trans = D3DXVECTOR2(0, 0); 80 | D3DXMatrixTransformation2D(&mat, NULL, 0.0, &scaling, &spriteCentre, (FLOAT) Rotation, &trans); 81 | 82 | SpriteInterface->SetTransform(&mat); 83 | SpriteInterface->Begin(D3DXSPRITE_ALPHABLEND); 84 | SpriteInterface->Draw(TextureInterface, NULL, NULL, &Vec, 0xFFFFFFFF); 85 | SpriteInterface->End(); 86 | } 87 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/Rendering/dx_utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #define DRAW_FVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1) 6 | 7 | class CD3DFont; 8 | 9 | namespace Game 10 | { 11 | namespace Rendering 12 | { 13 | namespace Drawing 14 | { 15 | void DrawBox(float x, float y, float w, float h, DWORD color, LPDIRECT3DDEVICE9 pDevice); 16 | void DrawRectangular(float X, float Y, float Width, float Height, float Thickness, D3DCOLOR Color, LPDIRECT3DDEVICE9 pDev); 17 | void DrawPrimtive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride, DWORD FVF = DRAW_FVF); 18 | 19 | void DrawSprite(LPD3DXSPRITE SpriteInterface, LPDIRECT3DTEXTURE9 TextureInterface, int PosX, int PosY, int Rotation, int Align); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/SAMP/PatternTable.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Game 5 | { 6 | namespace SAMP 7 | { 8 | namespace PatternTable 9 | { 10 | namespace SendChat 11 | { 12 | namespace Command 13 | { 14 | static const BYTE *byteMask = (const BYTE *)"\x64\xA1\x00\x00\x00\x00\x6A\xFF\x68\x00\x00\x00\x00\x50\xA1\x00\x00\x00\x00\x64\x89\x25\x00\x00\x00\x00\x81\xEC\x00\x00\x00\x00\x85\xC0"; 15 | static const char *useMask = "xx????xxx????xx????xxx????xx????xx"; 16 | } 17 | 18 | namespace Chat 19 | { 20 | static const BYTE *byteMask = (const BYTE *)"\x64\xA1\x00\x00\x00\x00\x6A\xFF\x68\x00\x00\x00\x00\x50\x64\x89\x25\x00\x00\x00\x00\x81\xEC\x00\x00\x00\x00\x53\x56\x8B\xB4\x24\x00\x00\x00\x00\x8B\xC6"; 21 | static const char *useMask = "xx????xxx????xxxx????xx????xxxxx????xx"; 22 | } 23 | } 24 | 25 | namespace GameText 26 | { 27 | static const BYTE *byteMask = (const BYTE *)"\x55\x8B\xEC\x81\x7D\x10\xC8\x00\x00\x00\x7F\x36\x68\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x8B\x4D\x08\x8B\x15\x00\x00\x00\x00\x83"; 28 | static const char *useMask = "xxxxxxxxxxxxx????x????xxxxx????x"; 29 | } 30 | 31 | namespace AddChatMessage 32 | { 33 | static const BYTE *byteMask = (const BYTE *)"\x8B\x15\x00\x00\x00\x00\x68\x00\x00\x00\x00\x52\xE8\x00\x00\x00\x00\x83\xC4\x08\x5F\x5E"; 34 | static const char *useMask = "xx????x????xx????xxxxx"; 35 | } 36 | 37 | namespace GetPlayerNameByID 38 | { 39 | // X86 ASM-Code 40 | // push edi 41 | // push edi 42 | // mov ecx, ebx 43 | // call sub_10011ED0 <-- -> GetPlayerNameByID 44 | // push eax 45 | 46 | // HEX-Code 47 | // 57 48 | // 57 49 | // 8B CB 50 | // E8 00 00 00 00 51 | // 50 52 | 53 | static const BYTE *byteMask = (const BYTE *)"\x57\x57\x8B\xCB\xE8\x00\x00\x00\x00\x50"; 54 | static const char *useMask = "xxxxx????x"; 55 | } 56 | 57 | namespace UpdatePlayerData 58 | { 59 | // HEX-Code 60 | // 8B 0D 00 00 00 00 61 | // E8 00 00 00 00 62 | // 8B 0D 00 00 00 00 63 | // 8B 5E 34 64 | 65 | static const BYTE *byteMask = (const BYTE *)"\x8B\x0D\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x8B\x0D\x00\x00\x00\x00\x8B\x5E\x34"; 66 | static const char *useMask = "xx????x????xx????xxx"; 67 | } 68 | 69 | namespace Input 70 | { 71 | static const BYTE *byteMask = (const BYTE *)"\x8B\x0D\x00\x00\x00\x00\x68\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x8B\x0D\x00\x00\x00\x00\x68\x00\x00\x00\x00\x68\x00\x00\x00\x00\xE8"; 72 | static const char *useMask = "xx????x????x????xx????x????x????x"; 73 | } 74 | 75 | namespace ShowDialog 76 | { 77 | // HEX-Code 78 | // 8B 0D 00 00 00 00 79 | // 8B 41 28 80 | // 85 C0 81 | // 75 1F 82 | // 6A 00 83 | // 68 00 00 00 00 84 | // 68 00 00 00 00 85 | // 68 00 00 00 00 86 | // 68 00 87 | 88 | static const BYTE *byteMask = (const BYTE *)"\x8B\x0D\x00\x00\x00\x00\x8B\x41\x28\x85\xC0\x75\x1F\x6A\x00\x68\x00\x00\x00\x00\x68\x00\x00\x00\x00\x68\x00\x00\x00\x00\x68\x00"; 89 | static const char *useMask = "xx????xxxxxxxxxx????x????x????x?"; 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/SAMP/RemotePlayer.cpp: -------------------------------------------------------------------------------- 1 | #include "RemotePlayer.hpp" 2 | #include "PatternTable.hpp" 3 | #include 4 | #include 5 | #include 6 | 7 | // updatePlayerData 8 | DWORD g_dwUpdatePlayerDataFunctionPtr = 0; 9 | DWORD g_dwUpdatePlayerDataObjectPtr = 0; 10 | 11 | // getPlayerNameByID 12 | DWORD g_dwPlayerNameByIDFunction = 0; 13 | DWORD g_dwPlayerNamebyIDJMP = 0; 14 | DWORD g_dwPlayerDataOffset = 0; 15 | Utils::NakedHook::NakedHook g_playerNameByIDHook; 16 | 17 | 18 | void __declspec(naked) playerNameByIDNakedHandler() 19 | { 20 | __asm pushad 21 | __asm pushfd 22 | 23 | __asm mov g_dwPlayerDataOffset, ecx 24 | 25 | // Remove the hook if the offset has been fetched successfully 26 | if (g_dwPlayerDataOffset) 27 | g_playerNameByIDHook.remove(); 28 | 29 | __asm popfd 30 | __asm popad 31 | 32 | __asm mov ax, [esp + 4h] 33 | __asm jmp[g_dwPlayerNamebyIDJMP] 34 | } 35 | 36 | void Game::SAMP::RemotePlayer::Internal::init(DWORD dwModuleBase, DWORD dwModuleLen) 37 | { 38 | // updatePlayerData 39 | { 40 | DWORD dwPattern = Utils::Pattern::findPattern(dwModuleBase, dwModuleLen, PatternTable::UpdatePlayerData::byteMask, PatternTable::UpdatePlayerData::useMask); 41 | if (dwPattern) 42 | { 43 | g_dwUpdatePlayerDataObjectPtr = *(DWORD *)(dwPattern + 0x2); 44 | g_dwUpdatePlayerDataFunctionPtr = *(DWORD *)(dwPattern + 0x7) + dwPattern + 0x7 + 0x4; 45 | } 46 | } 47 | 48 | // getPlayerNameByID 49 | { 50 | DWORD dwPattern = Utils::Pattern::findPattern(dwModuleBase, dwModuleLen, PatternTable::GetPlayerNameByID::byteMask, PatternTable::GetPlayerNameByID::useMask); 51 | if (dwPattern) 52 | { 53 | g_dwPlayerNameByIDFunction = *(DWORD *)(dwPattern + 0x5) + dwPattern + 0x5 + 0x4; // Calculate real address 54 | 55 | // Create a naked hook to fetch the object pointer passed by the ecx register 56 | // This object is needed to invoke the function 57 | g_playerNameByIDHook.init((PBYTE)g_dwPlayerNameByIDFunction, (DWORD)playerNameByIDNakedHandler, 5); 58 | g_dwPlayerNamebyIDJMP = g_playerNameByIDHook.jmp(); 59 | 60 | g_playerNameByIDHook.apply(); 61 | } 62 | } 63 | } 64 | 65 | bool Game::SAMP::RemotePlayer::updatePlayerData() 66 | { 67 | if (g_dwUpdatePlayerDataFunctionPtr == 0 || g_dwUpdatePlayerDataObjectPtr == 0) 68 | return false; 69 | 70 | __asm 71 | { 72 | mov eax, g_dwUpdatePlayerDataObjectPtr 73 | mov ecx, [eax] 74 | call g_dwUpdatePlayerDataFunctionPtr 75 | } 76 | 77 | return true; 78 | } 79 | 80 | const char *Game::SAMP::RemotePlayer::playerNameByID(unsigned short id) 81 | { 82 | if (g_dwPlayerDataOffset == 0 || g_dwPlayerNameByIDFunction == 0) 83 | return nullptr; 84 | 85 | updatePlayerData(); 86 | 87 | char *ptr_ = nullptr; 88 | __asm 89 | { 90 | mov ecx, g_dwPlayerDataOffset 91 | push id 92 | call g_dwPlayerNameByIDFunction 93 | mov ptr_, eax 94 | } 95 | 96 | return ptr_; 97 | } 98 | 99 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/SAMP/RemotePlayer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Game 6 | { 7 | namespace SAMP 8 | { 9 | namespace RemotePlayer 10 | { 11 | namespace Internal 12 | { 13 | void init(DWORD dwModuleBase, DWORD dwModuleLen); 14 | } 15 | 16 | bool updatePlayerData(); 17 | const char *playerNameByID(unsigned short id); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/SAMP/SAMP.cpp: -------------------------------------------------------------------------------- 1 | #include "SAMP.hpp" 2 | #include "PatternTable.hpp" 3 | #include "RemotePlayer.hpp" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | #define CHECK_OFFSET(X, RET, TYPE) \ 13 | if (auto val = Utils::Memory::readMemory(X)) { if (*val == 0) return RET; } else return RET; 14 | 15 | DWORD g_dwModuleLength = 0; 16 | DWORD g_dwModuleBase = 0; 17 | 18 | DWORD m_dwShowDialogCall = 0; 19 | DWORD m_dwShowDialogCallInfo = 0; 20 | DWORD m_dwShowDialogInfo = 0; 21 | Game::SAMP::stDialog *m_pDialog; 22 | 23 | void Game::SAMP::initSAMP() 24 | { 25 | g_dwModuleBase = Utils::Module::moduleBase("samp.dll"); 26 | g_dwModuleLength = Utils::Module::moduleLength((HMODULE)g_dwModuleBase); 27 | 28 | if (g_dwModuleBase == 0 || g_dwModuleLength == 0) 29 | throw std::exception("Error while initializing SA:MP"); 30 | 31 | RemotePlayer::Internal::init(g_dwModuleBase, g_dwModuleLength); 32 | 33 | DWORD dwShowDialog = Utils::Pattern::findPattern( 34 | g_dwModuleBase, 35 | g_dwModuleLength, 36 | Game::SAMP::PatternTable::ShowDialog::byteMask, 37 | Game::SAMP::PatternTable::ShowDialog::useMask 38 | ); 39 | 40 | if (dwShowDialog) 41 | { 42 | m_dwShowDialogCall = *(DWORD *)(dwShowDialog + 0x28) + dwShowDialog + 0x28 + 0x4; 43 | m_dwShowDialogCallInfo = *(DWORD *)(dwShowDialog + 0x10); 44 | m_dwShowDialogInfo = *(DWORD *)(dwShowDialog + 0x2); 45 | 46 | m_pDialog = *(stDialog **)m_dwShowDialogInfo; 47 | } 48 | } 49 | 50 | void Game::SAMP::exitSAMP() 51 | { 52 | 53 | } 54 | 55 | bool Game::SAMP::sendChat(const char *msg) 56 | { 57 | if (msg == nullptr) 58 | return false; 59 | 60 | DWORD dwAddr = 0; 61 | if (msg[0] == '/') 62 | { 63 | static auto addr = Utils::Pattern::findPattern( 64 | g_dwModuleBase, 65 | g_dwModuleLength, 66 | Game::SAMP::PatternTable::SendChat::Command::byteMask, 67 | Game::SAMP::PatternTable::SendChat::Command::useMask 68 | ); 69 | 70 | dwAddr = addr; 71 | } 72 | else 73 | { 74 | static auto addr = Utils::Pattern::findPattern( 75 | g_dwModuleBase, 76 | g_dwModuleLength, 77 | Game::SAMP::PatternTable::SendChat::Chat::byteMask, 78 | Game::SAMP::PatternTable::SendChat::Chat::useMask 79 | ); 80 | 81 | dwAddr = addr; 82 | } 83 | 84 | if (dwAddr == 0) 85 | return false; 86 | 87 | __asm push msg 88 | __asm call dwAddr 89 | return true; 90 | } 91 | 92 | bool Game::SAMP::showGameText(const char *text, int iTime, int iStyle) 93 | { 94 | static auto addr = Utils::Pattern::findPattern( 95 | g_dwModuleBase, 96 | g_dwModuleLength, 97 | Game::SAMP::PatternTable::GameText::byteMask, 98 | Game::SAMP::PatternTable::GameText::useMask 99 | ); 100 | 101 | if (addr == 0) 102 | return false; 103 | 104 | __asm push iStyle 105 | __asm push iTime 106 | __asm push text 107 | __asm call addr 108 | return true; 109 | } 110 | 111 | bool Game::SAMP::addChatMessage(const char *text) 112 | { 113 | static auto addr = Utils::Pattern::findPattern( 114 | g_dwModuleBase, 115 | g_dwModuleLength, 116 | Game::SAMP::PatternTable::AddChatMessage::byteMask, 117 | Game::SAMP::PatternTable::AddChatMessage::useMask 118 | ); 119 | 120 | if (addr == 0) 121 | return false; 122 | 123 | DWORD dwCallAddr = *(DWORD *)(addr + 0xD) + addr + 0xD + 0x4; 124 | DWORD dwInfo = *(DWORD *)(addr + 0x2); 125 | 126 | CHECK_OFFSET(dwInfo, false, DWORD) 127 | 128 | __asm mov edx, dword ptr[dwInfo] 129 | __asm mov eax, [edx] 130 | __asm push text 131 | __asm push eax 132 | __asm call dwCallAddr 133 | __asm add esp, 8 134 | return true; 135 | } 136 | 137 | bool Game::SAMP::showDialog(int id, int style, const char * caption, const char *text, const char * button, const char * button2, int isServerDialog) 138 | { 139 | if (!m_pDialog || !m_dwShowDialogCall) 140 | return false; 141 | 142 | __asm 143 | { 144 | push isServerDialog 145 | push button2 146 | push button 147 | push text 148 | push caption 149 | push style 150 | push id 151 | mov ecx, m_pDialog 152 | call m_dwShowDialogCall 153 | } 154 | 155 | return true; 156 | } 157 | 158 | 159 | bool Game::SAMP::isChatOpen() 160 | { 161 | static auto addr = Utils::Pattern::findPattern( 162 | g_dwModuleBase, 163 | g_dwModuleBase, 164 | Game::SAMP::PatternTable::Input::byteMask, 165 | Game::SAMP::PatternTable::Input::useMask 166 | ); 167 | 168 | if (addr == 0) 169 | return false; 170 | 171 | stInputInfo *pInputInfo = *(stInputInfo **)*(DWORD *)(addr + 0x2); 172 | 173 | if (pInputInfo == NULL) 174 | return false; 175 | if (pInputInfo->pInputBox == NULL) 176 | return false; 177 | 178 | return pInputInfo->pInputBox->bChatboxOpen != 0; 179 | } 180 | 181 | bool Game::SAMP::isDialogOpen() 182 | { 183 | if (m_pDialog) 184 | return m_pDialog->iDialogOpen != 0; 185 | 186 | return false; 187 | } 188 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Game/SAMP/SAMP.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Game 6 | { 7 | namespace SAMP 8 | { 9 | struct stInputBox 10 | { 11 | void *pUnknown; 12 | uint8_t bChatboxOpen; 13 | }; 14 | 15 | struct stInputInfo 16 | { 17 | void *pUnknown[2]; 18 | stInputBox *pInputBox; 19 | }; 20 | 21 | struct stDialog 22 | { 23 | char szUnknown[0x28]; 24 | __int32 iDialogOpen; 25 | __int32 iType; 26 | __int32 iId; 27 | }; 28 | 29 | void initSAMP(); 30 | void exitSAMP(); 31 | 32 | bool sendChat(const char *msg); 33 | bool showGameText(const char *text, int iTime, int iStyle); 34 | bool addChatMessage(const char *text); 35 | bool showDialog(int id, int style, const char *caption, const char *text, const char *button, const char *button2, int isServerDialog); 36 | bool isChatOpen(); 37 | bool isDialogOpen(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Open-SAMP-API.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Client %28Keybinder%29 7 | 8 | 9 | Game %28GTA SA%29 10 | 11 | 12 | Game %28GTA SA%29 13 | 14 | 15 | Game %28GTA SA%29\Rendering 16 | 17 | 18 | Game %28GTA SA%29\Rendering 19 | 20 | 21 | Game %28GTA SA%29\Rendering 22 | 23 | 24 | Game %28GTA SA%29\Rendering 25 | 26 | 27 | Game %28GTA SA%29\Rendering 28 | 29 | 30 | Game %28GTA SA%29\Rendering 31 | 32 | 33 | Game %28GTA SA%29\Rendering 34 | 35 | 36 | Game %28GTA SA%29\Rendering 37 | 38 | 39 | Utils 40 | 41 | 42 | Utils 43 | 44 | 45 | Utils 46 | 47 | 48 | Utils 49 | 50 | 51 | Utils 52 | 53 | 54 | Utils 55 | 56 | 57 | Client %28Keybinder%29 58 | 59 | 60 | Client %28Keybinder%29 61 | 62 | 63 | Utils 64 | 65 | 66 | Client %28Keybinder%29 67 | 68 | 69 | Client %28Keybinder%29 70 | 71 | 72 | Client %28Keybinder%29 73 | 74 | 75 | Utils 76 | 77 | 78 | Game %28GTA SA%29\SAMP 79 | 80 | 81 | Game %28GTA SA%29\SAMP 82 | 83 | 84 | Client %28Keybinder%29 85 | 86 | 87 | Game %28GTA SA%29\GTA 88 | 89 | 90 | Client %28Keybinder%29 91 | 92 | 93 | 94 | 95 | Game %28GTA SA%29 96 | 97 | 98 | Game %28GTA SA%29 99 | 100 | 101 | Game %28GTA SA%29\Rendering 102 | 103 | 104 | Game %28GTA SA%29\Rendering 105 | 106 | 107 | Game %28GTA SA%29\Rendering 108 | 109 | 110 | Game %28GTA SA%29\Rendering 111 | 112 | 113 | Game %28GTA SA%29\Rendering 114 | 115 | 116 | Game %28GTA SA%29\Rendering 117 | 118 | 119 | Game %28GTA SA%29\Rendering 120 | 121 | 122 | Game %28GTA SA%29\Rendering 123 | 124 | 125 | Client %28Keybinder%29 126 | 127 | 128 | Utils 129 | 130 | 131 | Utils 132 | 133 | 134 | Utils 135 | 136 | 137 | Utils 138 | 139 | 140 | Utils 141 | 142 | 143 | Utils 144 | 145 | 146 | Utils 147 | 148 | 149 | Utils 150 | 151 | 152 | Shared 153 | 154 | 155 | Shared 156 | 157 | 158 | 159 | Utils 160 | 161 | 162 | Utils 163 | 164 | 165 | Client %28Keybinder%29 166 | 167 | 168 | Client %28Keybinder%29 169 | 170 | 171 | Utils 172 | 173 | 174 | Client %28Keybinder%29 175 | 176 | 177 | Client %28Keybinder%29 178 | 179 | 180 | Client %28Keybinder%29 181 | 182 | 183 | Client %28Keybinder%29 184 | 185 | 186 | Utils\Detours 187 | 188 | 189 | Utils\D3DX9 190 | 191 | 192 | Utils\D3DX9 193 | 194 | 195 | Utils\D3DX9 196 | 197 | 198 | Utils\D3DX9 199 | 200 | 201 | Utils\D3DX9 202 | 203 | 204 | Utils\D3DX9 205 | 206 | 207 | Utils\D3DX9 208 | 209 | 210 | Utils\D3DX9 211 | 212 | 213 | Utils\D3DX9 214 | 215 | 216 | Utils\D3DX9 217 | 218 | 219 | Utils\D3DX9 220 | 221 | 222 | Utils\D3DX9 223 | 224 | 225 | Utils\D3DX9 226 | 227 | 228 | Utils 229 | 230 | 231 | Game %28GTA SA%29\SAMP 232 | 233 | 234 | Game %28GTA SA%29\SAMP 235 | 236 | 237 | Game %28GTA SA%29\SAMP 238 | 239 | 240 | Client %28Keybinder%29 241 | 242 | 243 | Game %28GTA SA%29\GTA 244 | 245 | 246 | Client %28Keybinder%29 247 | 248 | 249 | 250 | 251 | {cded1b7c-176b-4965-942a-d5743809c49f} 252 | 253 | 254 | {7b6b209b-c84e-4c76-a339-fb670fc07052} 255 | 256 | 257 | {1ccb526a-ebdd-439e-88e9-63c154e8550a} 258 | 259 | 260 | {aecba2e8-2069-427f-a0d0-8978e4da9998} 261 | 262 | 263 | {d51ce45c-1411-4620-ae2f-4fc869d96b4e} 264 | 265 | 266 | {339f8d66-1a33-415c-bd77-6989c614783c} 267 | 268 | 269 | {c1775da1-bca9-48e0-9fe2-f272fd3467f1} 270 | 271 | 272 | {3d923964-ebb6-4cfd-b73f-fc0bfd26f2fb} 273 | 274 | 275 | {4ad632c8-c447-4282-8f8b-39d9af614a87} 276 | 277 | 278 | 279 | 280 | Utils\Detours 281 | 282 | 283 | Utils\D3DX9 284 | 285 | 286 | 287 | 288 | Utils\D3DX9 289 | 290 | 291 | 292 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Shared/Config.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Shared 4 | { 5 | namespace Config 6 | { 7 | const char *const pipeName = "SAMP_API_SERVER"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Shared/PipeMessages.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Shared 4 | { 5 | enum class PipeMessages : short 6 | { 7 | // Internal use 8 | Ping = 1, 9 | 10 | // Text functions 11 | TextCreate, 12 | TextDestroy, 13 | TextSetShadow, 14 | TextSetShown, 15 | TextSetColor, 16 | TextSetPos, 17 | TextSetString, 18 | TextUpdate, 19 | 20 | // Box functions 21 | BoxCreate, 22 | BoxDestroy, 23 | BoxSetShown, 24 | BoxSetBorder, 25 | BoxSetBorderColor, 26 | BoxSetColor, 27 | BoxSetHeight, 28 | BoxSetPos, 29 | BoxSetWidth, 30 | 31 | // Line functions 32 | LineCreate, 33 | LineDestroy, 34 | LineSetShown, 35 | LineSetColor, 36 | LineSetWidth, 37 | LineSetPos, 38 | 39 | // Image functions 40 | ImageCreate, 41 | ImageDestroy, 42 | ImageSetShown, 43 | ImageSetAlign, 44 | ImageSetPos, 45 | ImageSetRotation, 46 | 47 | // Misc overlay functions 48 | DestroyAllVisual, 49 | ShowAllVisual, 50 | HideAllVisual, 51 | GetFrameRate, 52 | GetScreenSpecs, 53 | SetCalculationRatio, 54 | SetOverlayPriority, 55 | SetOverlayCalculationEnabled, 56 | 57 | // GTA functions 58 | GetGTACommandLine, 59 | 60 | // SAMP functions 61 | SendChat, 62 | ShowGameText, 63 | AddChatMessage, 64 | ShowDialog, 65 | GetPlayerNameByID, 66 | IsChatOpen, 67 | IsDialogOpen, 68 | 69 | // Memory functions 70 | ReadMemory, 71 | 72 | // Misc GTA functions 73 | ScreenToWorld, 74 | WorldToScreen 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/D3DX9/d3dx9.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx9.h 6 | // Content: D3DX utility library 7 | // 8 | ////////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifdef __D3DX_INTERNAL__ 11 | #error Incorrect D3DX header used 12 | #endif 13 | 14 | #ifndef __D3DX9_H__ 15 | #define __D3DX9_H__ 16 | 17 | 18 | // Defines 19 | #include 20 | 21 | #define D3DX_DEFAULT ((UINT) -1) 22 | #define D3DX_DEFAULT_NONPOW2 ((UINT) -2) 23 | #define D3DX_DEFAULT_FLOAT FLT_MAX 24 | #define D3DX_FROM_FILE ((UINT) -3) 25 | #define D3DFMT_FROM_FILE ((D3DFORMAT) -3) 26 | 27 | #ifndef D3DXINLINE 28 | #ifdef _MSC_VER 29 | #if (_MSC_VER >= 1200) 30 | #define D3DXINLINE __forceinline 31 | #else 32 | #define D3DXINLINE __inline 33 | #endif 34 | #else 35 | #ifdef __cplusplus 36 | #define D3DXINLINE inline 37 | #else 38 | #define D3DXINLINE 39 | #endif 40 | #endif 41 | #endif 42 | 43 | 44 | 45 | // Includes 46 | #include "d3d9.h" 47 | #include "d3dx9math.h" 48 | #include "d3dx9core.h" 49 | #include "d3dx9xof.h" 50 | #include "d3dx9mesh.h" 51 | #include "d3dx9shader.h" 52 | #include "d3dx9effect.h" 53 | 54 | #include "d3dx9tex.h" 55 | #include "d3dx9shape.h" 56 | #include "d3dx9anim.h" 57 | 58 | 59 | 60 | // Errors 61 | #define _FACDD 0x876 62 | #define MAKE_DDHRESULT( code ) MAKE_HRESULT( 1, _FACDD, code ) 63 | 64 | enum _D3DXERR { 65 | D3DXERR_CANNOTMODIFYINDEXBUFFER = MAKE_DDHRESULT(2900), 66 | D3DXERR_INVALIDMESH = MAKE_DDHRESULT(2901), 67 | D3DXERR_CANNOTATTRSORT = MAKE_DDHRESULT(2902), 68 | D3DXERR_SKINNINGNOTSUPPORTED = MAKE_DDHRESULT(2903), 69 | D3DXERR_TOOMANYINFLUENCES = MAKE_DDHRESULT(2904), 70 | D3DXERR_INVALIDDATA = MAKE_DDHRESULT(2905), 71 | D3DXERR_LOADEDMESHASNODATA = MAKE_DDHRESULT(2906), 72 | D3DXERR_DUPLICATENAMEDFRAGMENT = MAKE_DDHRESULT(2907), 73 | D3DXERR_CANNOTREMOVELASTITEM = MAKE_DDHRESULT(2908), 74 | }; 75 | 76 | 77 | #endif //__D3DX9_H__ 78 | 79 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/D3DX9/d3dx9.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAMPProjects/Open-SAMP-API/d409a384bda26b996f2023d5199904186788708c/src/Open-SAMP-API/Utils/D3DX9/d3dx9.lib -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/D3DX9/d3dx9shape.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx9shapes.h 6 | // Content: D3DX simple shapes 7 | // 8 | /////////////////////////////////////////////////////////////////////////// 9 | 10 | #include "d3dx9.h" 11 | 12 | #ifndef __D3DX9SHAPES_H__ 13 | #define __D3DX9SHAPES_H__ 14 | 15 | /////////////////////////////////////////////////////////////////////////// 16 | // Functions: 17 | /////////////////////////////////////////////////////////////////////////// 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif //__cplusplus 22 | 23 | 24 | //------------------------------------------------------------------------- 25 | // D3DXCreatePolygon: 26 | // ------------------ 27 | // Creates a mesh containing an n-sided polygon. The polygon is centered 28 | // at the origin. 29 | // 30 | // Parameters: 31 | // 32 | // pDevice The D3D device with which the mesh is going to be used. 33 | // Length Length of each side. 34 | // Sides Number of sides the polygon has. (Must be >= 3) 35 | // ppMesh The mesh object which will be created 36 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 37 | //------------------------------------------------------------------------- 38 | HRESULT WINAPI 39 | D3DXCreatePolygon( 40 | LPDIRECT3DDEVICE9 pDevice, 41 | FLOAT Length, 42 | UINT Sides, 43 | LPD3DXMESH* ppMesh, 44 | LPD3DXBUFFER* ppAdjacency); 45 | 46 | 47 | //------------------------------------------------------------------------- 48 | // D3DXCreateBox: 49 | // -------------- 50 | // Creates a mesh containing an axis-aligned box. The box is centered at 51 | // the origin. 52 | // 53 | // Parameters: 54 | // 55 | // pDevice The D3D device with which the mesh is going to be used. 56 | // Width Width of box (along X-axis) 57 | // Height Height of box (along Y-axis) 58 | // Depth Depth of box (along Z-axis) 59 | // ppMesh The mesh object which will be created 60 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 61 | //------------------------------------------------------------------------- 62 | HRESULT WINAPI 63 | D3DXCreateBox( 64 | LPDIRECT3DDEVICE9 pDevice, 65 | FLOAT Width, 66 | FLOAT Height, 67 | FLOAT Depth, 68 | LPD3DXMESH* ppMesh, 69 | LPD3DXBUFFER* ppAdjacency); 70 | 71 | 72 | //------------------------------------------------------------------------- 73 | // D3DXCreateCylinder: 74 | // ------------------- 75 | // Creates a mesh containing a cylinder. The generated cylinder is 76 | // centered at the origin, and its axis is aligned with the Z-axis. 77 | // 78 | // Parameters: 79 | // 80 | // pDevice The D3D device with which the mesh is going to be used. 81 | // Radius1 Radius at -Z end (should be >= 0.0f) 82 | // Radius2 Radius at +Z end (should be >= 0.0f) 83 | // Length Length of cylinder (along Z-axis) 84 | // Slices Number of slices about the main axis 85 | // Stacks Number of stacks along the main axis 86 | // ppMesh The mesh object which will be created 87 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 88 | //------------------------------------------------------------------------- 89 | HRESULT WINAPI 90 | D3DXCreateCylinder( 91 | LPDIRECT3DDEVICE9 pDevice, 92 | FLOAT Radius1, 93 | FLOAT Radius2, 94 | FLOAT Length, 95 | UINT Slices, 96 | UINT Stacks, 97 | LPD3DXMESH* ppMesh, 98 | LPD3DXBUFFER* ppAdjacency); 99 | 100 | 101 | //------------------------------------------------------------------------- 102 | // D3DXCreateSphere: 103 | // ----------------- 104 | // Creates a mesh containing a sphere. The sphere is centered at the 105 | // origin. 106 | // 107 | // Parameters: 108 | // 109 | // pDevice The D3D device with which the mesh is going to be used. 110 | // Radius Radius of the sphere (should be >= 0.0f) 111 | // Slices Number of slices about the main axis 112 | // Stacks Number of stacks along the main axis 113 | // ppMesh The mesh object which will be created 114 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 115 | //------------------------------------------------------------------------- 116 | HRESULT WINAPI 117 | D3DXCreateSphere( 118 | LPDIRECT3DDEVICE9 pDevice, 119 | FLOAT Radius, 120 | UINT Slices, 121 | UINT Stacks, 122 | LPD3DXMESH* ppMesh, 123 | LPD3DXBUFFER* ppAdjacency); 124 | 125 | 126 | //------------------------------------------------------------------------- 127 | // D3DXCreateTorus: 128 | // ---------------- 129 | // Creates a mesh containing a torus. The generated torus is centered at 130 | // the origin, and its axis is aligned with the Z-axis. 131 | // 132 | // Parameters: 133 | // 134 | // pDevice The D3D device with which the mesh is going to be used. 135 | // InnerRadius Inner radius of the torus (should be >= 0.0f) 136 | // OuterRadius Outer radius of the torue (should be >= 0.0f) 137 | // Sides Number of sides in a cross-section (must be >= 3) 138 | // Rings Number of rings making up the torus (must be >= 3) 139 | // ppMesh The mesh object which will be created 140 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 141 | //------------------------------------------------------------------------- 142 | HRESULT WINAPI 143 | D3DXCreateTorus( 144 | LPDIRECT3DDEVICE9 pDevice, 145 | FLOAT InnerRadius, 146 | FLOAT OuterRadius, 147 | UINT Sides, 148 | UINT Rings, 149 | LPD3DXMESH* ppMesh, 150 | LPD3DXBUFFER* ppAdjacency); 151 | 152 | 153 | //------------------------------------------------------------------------- 154 | // D3DXCreateTeapot: 155 | // ----------------- 156 | // Creates a mesh containing a teapot. 157 | // 158 | // Parameters: 159 | // 160 | // pDevice The D3D device with which the mesh is going to be used. 161 | // ppMesh The mesh object which will be created 162 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 163 | //------------------------------------------------------------------------- 164 | HRESULT WINAPI 165 | D3DXCreateTeapot( 166 | LPDIRECT3DDEVICE9 pDevice, 167 | LPD3DXMESH* ppMesh, 168 | LPD3DXBUFFER* ppAdjacency); 169 | 170 | 171 | //------------------------------------------------------------------------- 172 | // D3DXCreateText: 173 | // --------------- 174 | // Creates a mesh containing the specified text using the font associated 175 | // with the device context. 176 | // 177 | // Parameters: 178 | // 179 | // pDevice The D3D device with which the mesh is going to be used. 180 | // hDC Device context, with desired font selected 181 | // pText Text to generate 182 | // Deviation Maximum chordal deviation from true font outlines 183 | // Extrusion Amount to extrude text in -Z direction 184 | // ppMesh The mesh object which will be created 185 | // pGlyphMetrics Address of buffer to receive glyph metric data (or NULL) 186 | //------------------------------------------------------------------------- 187 | HRESULT WINAPI 188 | D3DXCreateTextA( 189 | LPDIRECT3DDEVICE9 pDevice, 190 | HDC hDC, 191 | LPCSTR pText, 192 | FLOAT Deviation, 193 | FLOAT Extrusion, 194 | LPD3DXMESH* ppMesh, 195 | LPD3DXBUFFER* ppAdjacency, 196 | LPGLYPHMETRICSFLOAT pGlyphMetrics); 197 | 198 | HRESULT WINAPI 199 | D3DXCreateTextW( 200 | LPDIRECT3DDEVICE9 pDevice, 201 | HDC hDC, 202 | LPCWSTR pText, 203 | FLOAT Deviation, 204 | FLOAT Extrusion, 205 | LPD3DXMESH* ppMesh, 206 | LPD3DXBUFFER* ppAdjacency, 207 | LPGLYPHMETRICSFLOAT pGlyphMetrics); 208 | 209 | #ifdef UNICODE 210 | #define D3DXCreateText D3DXCreateTextW 211 | #else 212 | #define D3DXCreateText D3DXCreateTextA 213 | #endif 214 | 215 | 216 | #ifdef __cplusplus 217 | } 218 | #endif //__cplusplus 219 | 220 | #endif //__D3DX9SHAPES_H__ 221 | 222 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/D3DX9/d3dx9xof.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx9xof.h 6 | // Content: D3DX .X File types and functions 7 | // 8 | /////////////////////////////////////////////////////////////////////////// 9 | 10 | #include "d3dx9.h" 11 | 12 | #if !defined( __D3DX9XOF_H__ ) 13 | #define __D3DX9XOF_H__ 14 | 15 | #if defined( __cplusplus ) 16 | extern "C" { 17 | #endif // defined( __cplusplus ) 18 | 19 | //---------------------------------------------------------------------------- 20 | // D3DXF_FILEFORMAT 21 | // This flag is used to specify what file type to use when saving to disk. 22 | // _BINARY, and _TEXT are mutually exclusive, while 23 | // _COMPRESSED is an optional setting that works with all file types. 24 | //---------------------------------------------------------------------------- 25 | typedef DWORD D3DXF_FILEFORMAT; 26 | 27 | #define D3DXF_FILEFORMAT_BINARY 0 28 | #define D3DXF_FILEFORMAT_TEXT 1 29 | #define D3DXF_FILEFORMAT_COMPRESSED 2 30 | 31 | //---------------------------------------------------------------------------- 32 | // D3DXF_FILESAVEOPTIONS 33 | // This flag is used to specify where to save the file to. Each flag is 34 | // mutually exclusive, indicates the data location of the file, and also 35 | // chooses which additional data will specify the location. 36 | // _TOFILE is paired with a filename (LPCSTR) 37 | // _TOWFILE is paired with a filename (LPWSTR) 38 | //---------------------------------------------------------------------------- 39 | typedef DWORD D3DXF_FILESAVEOPTIONS; 40 | 41 | #define D3DXF_FILESAVE_TOFILE 0x00L 42 | #define D3DXF_FILESAVE_TOWFILE 0x01L 43 | 44 | //---------------------------------------------------------------------------- 45 | // D3DXF_FILELOADOPTIONS 46 | // This flag is used to specify where to load the file from. Each flag is 47 | // mutually exclusive, indicates the data location of the file, and also 48 | // chooses which additional data will specify the location. 49 | // _FROMFILE is paired with a filename (LPCSTR) 50 | // _FROMWFILE is paired with a filename (LPWSTR) 51 | // _FROMRESOURCE is paired with a (D3DXF_FILELOADRESOUCE*) description. 52 | // _FROMMEMORY is paired with a (D3DXF_FILELOADMEMORY*) description. 53 | //---------------------------------------------------------------------------- 54 | typedef DWORD D3DXF_FILELOADOPTIONS; 55 | 56 | #define D3DXF_FILELOAD_FROMFILE 0x00L 57 | #define D3DXF_FILELOAD_FROMWFILE 0x01L 58 | #define D3DXF_FILELOAD_FROMRESOURCE 0x02L 59 | #define D3DXF_FILELOAD_FROMMEMORY 0x03L 60 | 61 | //---------------------------------------------------------------------------- 62 | // D3DXF_FILELOADRESOURCE: 63 | //---------------------------------------------------------------------------- 64 | 65 | typedef struct _D3DXF_FILELOADRESOURCE 66 | { 67 | HMODULE hModule; // Desc 68 | LPCSTR lpName; // Desc 69 | LPCSTR lpType; // Desc 70 | } D3DXF_FILELOADRESOURCE; 71 | 72 | //---------------------------------------------------------------------------- 73 | // D3DXF_FILELOADMEMORY: 74 | //---------------------------------------------------------------------------- 75 | 76 | typedef struct _D3DXF_FILELOADMEMORY 77 | { 78 | LPCVOID lpMemory; // Desc 79 | SIZE_T dSize; // Desc 80 | } D3DXF_FILELOADMEMORY; 81 | 82 | #if defined( _WIN32 ) && !defined( _NO_COM ) 83 | 84 | // {cef08cf9-7b4f-4429-9624-2a690a933201} 85 | DEFINE_GUID( IID_ID3DXFile, 86 | 0xcef08cf9, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 87 | 88 | // {cef08cfa-7b4f-4429-9624-2a690a933201} 89 | DEFINE_GUID( IID_ID3DXFileSaveObject, 90 | 0xcef08cfa, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 91 | 92 | // {cef08cfb-7b4f-4429-9624-2a690a933201} 93 | DEFINE_GUID( IID_ID3DXFileSaveData, 94 | 0xcef08cfb, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 95 | 96 | // {cef08cfc-7b4f-4429-9624-2a690a933201} 97 | DEFINE_GUID( IID_ID3DXFileEnumObject, 98 | 0xcef08cfc, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 99 | 100 | // {cef08cfd-7b4f-4429-9624-2a690a933201} 101 | DEFINE_GUID( IID_ID3DXFileData, 102 | 0xcef08cfd, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 103 | 104 | #endif // defined( _WIN32 ) && !defined( _NO_COM ) 105 | 106 | #if defined( __cplusplus ) 107 | #if !defined( DECLSPEC_UUID ) 108 | #if _MSC_VER >= 1100 109 | #define DECLSPEC_UUID( x ) __declspec( uuid( x ) ) 110 | #else // !( _MSC_VER >= 1100 ) 111 | #define DECLSPEC_UUID( x ) 112 | #endif // !( _MSC_VER >= 1100 ) 113 | #endif // !defined( DECLSPEC_UUID ) 114 | 115 | interface DECLSPEC_UUID( "cef08cf9-7b4f-4429-9624-2a690a933201" ) 116 | ID3DXFile; 117 | interface DECLSPEC_UUID( "cef08cfa-7b4f-4429-9624-2a690a933201" ) 118 | ID3DXFileSaveObject; 119 | interface DECLSPEC_UUID( "cef08cfb-7b4f-4429-9624-2a690a933201" ) 120 | ID3DXFileSaveData; 121 | interface DECLSPEC_UUID( "cef08cfc-7b4f-4429-9624-2a690a933201" ) 122 | ID3DXFileEnumObject; 123 | interface DECLSPEC_UUID( "cef08cfd-7b4f-4429-9624-2a690a933201" ) 124 | ID3DXFileData; 125 | 126 | #if defined( _COM_SMARTPTR_TYPEDEF ) 127 | _COM_SMARTPTR_TYPEDEF( ID3DXFile, 128 | __uuidof( ID3DXFile ) ); 129 | _COM_SMARTPTR_TYPEDEF( ID3DXFileSaveObject, 130 | __uuidof( ID3DXFileSaveObject ) ); 131 | _COM_SMARTPTR_TYPEDEF( ID3DXFileSaveData, 132 | __uuidof( ID3DXFileSaveData ) ); 133 | _COM_SMARTPTR_TYPEDEF( ID3DXFileEnumObject, 134 | __uuidof( ID3DXFileEnumObject ) ); 135 | _COM_SMARTPTR_TYPEDEF( ID3DXFileData, 136 | __uuidof( ID3DXFileData ) ); 137 | #endif // defined( _COM_SMARTPTR_TYPEDEF ) 138 | #endif // defined( __cplusplus ) 139 | 140 | typedef interface ID3DXFile ID3DXFile; 141 | typedef interface ID3DXFileSaveObject ID3DXFileSaveObject; 142 | typedef interface ID3DXFileSaveData ID3DXFileSaveData; 143 | typedef interface ID3DXFileEnumObject ID3DXFileEnumObject; 144 | typedef interface ID3DXFileData ID3DXFileData; 145 | 146 | ////////////////////////////////////////////////////////////////////////////// 147 | // ID3DXFile ///////////////////////////////////////////////////////////////// 148 | ////////////////////////////////////////////////////////////////////////////// 149 | 150 | #undef INTERFACE 151 | #define INTERFACE ID3DXFile 152 | 153 | DECLARE_INTERFACE_( ID3DXFile, IUnknown ) 154 | { 155 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 156 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 157 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 158 | 159 | STDMETHOD( CreateEnumObject )( THIS_ LPCVOID, D3DXF_FILELOADOPTIONS, 160 | ID3DXFileEnumObject** ) PURE; 161 | STDMETHOD( CreateSaveObject )( THIS_ LPCVOID, D3DXF_FILESAVEOPTIONS, 162 | D3DXF_FILEFORMAT, ID3DXFileSaveObject** ) PURE; 163 | STDMETHOD( RegisterTemplates )( THIS_ LPCVOID, SIZE_T ) PURE; 164 | STDMETHOD( RegisterEnumTemplates )( THIS_ ID3DXFileEnumObject* ) PURE; 165 | }; 166 | 167 | ////////////////////////////////////////////////////////////////////////////// 168 | // ID3DXFileSaveObject /////////////////////////////////////////////////////// 169 | ////////////////////////////////////////////////////////////////////////////// 170 | 171 | #undef INTERFACE 172 | #define INTERFACE ID3DXFileSaveObject 173 | 174 | DECLARE_INTERFACE_( ID3DXFileSaveObject, IUnknown ) 175 | { 176 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 177 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 178 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 179 | 180 | STDMETHOD( GetFile )( THIS_ ID3DXFile** ) PURE; 181 | STDMETHOD( AddDataObject )( THIS_ REFGUID, LPCSTR, CONST GUID*, 182 | SIZE_T, LPCVOID, ID3DXFileSaveData** ) PURE; 183 | STDMETHOD( Save )( THIS ) PURE; 184 | }; 185 | 186 | ////////////////////////////////////////////////////////////////////////////// 187 | // ID3DXFileSaveData ///////////////////////////////////////////////////////// 188 | ////////////////////////////////////////////////////////////////////////////// 189 | 190 | #undef INTERFACE 191 | #define INTERFACE ID3DXFileSaveData 192 | 193 | DECLARE_INTERFACE_( ID3DXFileSaveData, IUnknown ) 194 | { 195 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 196 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 197 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 198 | 199 | STDMETHOD( GetSave )( THIS_ ID3DXFileSaveObject** ) PURE; 200 | STDMETHOD( GetName )( THIS_ LPSTR, SIZE_T* ) PURE; 201 | STDMETHOD( GetId )( THIS_ LPGUID ) PURE; 202 | STDMETHOD( GetType )( THIS_ GUID* ) PURE; 203 | STDMETHOD( AddDataObject )( THIS_ REFGUID, LPCSTR, CONST GUID*, 204 | SIZE_T, LPCVOID, ID3DXFileSaveData** ) PURE; 205 | STDMETHOD( AddDataReference )( THIS_ LPCSTR, CONST GUID* ) PURE; 206 | }; 207 | 208 | ////////////////////////////////////////////////////////////////////////////// 209 | // ID3DXFileEnumObject /////////////////////////////////////////////////////// 210 | ////////////////////////////////////////////////////////////////////////////// 211 | 212 | #undef INTERFACE 213 | #define INTERFACE ID3DXFileEnumObject 214 | 215 | DECLARE_INTERFACE_( ID3DXFileEnumObject, IUnknown ) 216 | { 217 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 218 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 219 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 220 | 221 | STDMETHOD( GetFile )( THIS_ ID3DXFile** ) PURE; 222 | STDMETHOD( GetChildren )( THIS_ SIZE_T* ) PURE; 223 | STDMETHOD( GetChild )( THIS_ SIZE_T, ID3DXFileData** ) PURE; 224 | STDMETHOD( GetDataObjectById )( THIS_ REFGUID, ID3DXFileData** ) PURE; 225 | STDMETHOD( GetDataObjectByName )( THIS_ LPCSTR, ID3DXFileData** ) PURE; 226 | }; 227 | 228 | ////////////////////////////////////////////////////////////////////////////// 229 | // ID3DXFileData ///////////////////////////////////////////////////////////// 230 | ////////////////////////////////////////////////////////////////////////////// 231 | 232 | #undef INTERFACE 233 | #define INTERFACE ID3DXFileData 234 | 235 | DECLARE_INTERFACE_( ID3DXFileData, IUnknown ) 236 | { 237 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 238 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 239 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 240 | 241 | STDMETHOD( GetEnum )( THIS_ ID3DXFileEnumObject** ) PURE; 242 | STDMETHOD( GetName )( THIS_ LPSTR, SIZE_T* ) PURE; 243 | STDMETHOD( GetId )( THIS_ LPGUID ) PURE; 244 | STDMETHOD( Lock )( THIS_ SIZE_T*, LPCVOID* ) PURE; 245 | STDMETHOD( Unlock )( THIS ) PURE; 246 | STDMETHOD( GetType )( THIS_ GUID* ) PURE; 247 | STDMETHOD_( BOOL, IsReference )( THIS ) PURE; 248 | STDMETHOD( GetChildren )( THIS_ SIZE_T* ) PURE; 249 | STDMETHOD( GetChild )( THIS_ SIZE_T, ID3DXFileData** ) PURE; 250 | }; 251 | 252 | STDAPI D3DXFileCreate( ID3DXFile** lplpDirectXFile ); 253 | 254 | /* 255 | * DirectX File errors. 256 | */ 257 | 258 | #define _FACD3DXF 0x876 259 | 260 | #define D3DXFERR_BADOBJECT MAKE_HRESULT( 1, _FACD3DXF, 900 ) 261 | #define D3DXFERR_BADVALUE MAKE_HRESULT( 1, _FACD3DXF, 901 ) 262 | #define D3DXFERR_BADTYPE MAKE_HRESULT( 1, _FACD3DXF, 902 ) 263 | #define D3DXFERR_NOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 903 ) 264 | #define D3DXFERR_NOTDONEYET MAKE_HRESULT( 1, _FACD3DXF, 904 ) 265 | #define D3DXFERR_FILENOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 905 ) 266 | #define D3DXFERR_RESOURCENOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 906 ) 267 | #define D3DXFERR_BADRESOURCE MAKE_HRESULT( 1, _FACD3DXF, 907 ) 268 | #define D3DXFERR_BADFILETYPE MAKE_HRESULT( 1, _FACD3DXF, 908 ) 269 | #define D3DXFERR_BADFILEVERSION MAKE_HRESULT( 1, _FACD3DXF, 909 ) 270 | #define D3DXFERR_BADFILEFLOATSIZE MAKE_HRESULT( 1, _FACD3DXF, 910 ) 271 | #define D3DXFERR_BADFILE MAKE_HRESULT( 1, _FACD3DXF, 911 ) 272 | #define D3DXFERR_PARSEERROR MAKE_HRESULT( 1, _FACD3DXF, 912 ) 273 | #define D3DXFERR_BADARRAYSIZE MAKE_HRESULT( 1, _FACD3DXF, 913 ) 274 | #define D3DXFERR_BADDATAREFERENCE MAKE_HRESULT( 1, _FACD3DXF, 914 ) 275 | #define D3DXFERR_NOMOREOBJECTS MAKE_HRESULT( 1, _FACD3DXF, 915 ) 276 | #define D3DXFERR_NOMOREDATA MAKE_HRESULT( 1, _FACD3DXF, 916 ) 277 | #define D3DXFERR_BADCACHEFILE MAKE_HRESULT( 1, _FACD3DXF, 917 ) 278 | 279 | /* 280 | * DirectX File object types. 281 | */ 282 | 283 | #ifndef WIN_TYPES 284 | #define WIN_TYPES(itype, ptype) typedef interface itype *LP##ptype, **LPLP##ptype 285 | #endif 286 | 287 | WIN_TYPES(ID3DXFile, D3DXFILE); 288 | WIN_TYPES(ID3DXFileEnumObject, D3DXFILEENUMOBJECT); 289 | WIN_TYPES(ID3DXFileSaveObject, D3DXFILESAVEOBJECT); 290 | WIN_TYPES(ID3DXFileData, D3DXFILEDATA); 291 | WIN_TYPES(ID3DXFileSaveData, D3DXFILESAVEDATA); 292 | 293 | #if defined( __cplusplus ) 294 | } // extern "C" 295 | #endif // defined( __cplusplus ) 296 | 297 | #endif // !defined( __D3DX9XOF_H__ ) 298 | 299 | 300 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Detours/detours.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAMPProjects/Open-SAMP-API/d409a384bda26b996f2023d5199904186788708c/src/Open-SAMP-API/Utils/Detours/detours.lib -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Detours/detours.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAMPProjects/Open-SAMP-API/d409a384bda26b996f2023d5199904186788708c/src/Open-SAMP-API/Utils/Detours/detours.pdb -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Hook.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Windows.h" 3 | #include "Detours/detours.h" 4 | #include 5 | 6 | namespace Utils 7 | { 8 | namespace Hook 9 | { 10 | enum class CallConvention{ 11 | stdcall_t, cdecl_t 12 | }; 13 | 14 | template struct convention; 15 | 16 | template 17 | struct convention < CallConvention::stdcall_t, retn, args... > { 18 | typedef retn(__stdcall *type)(args...); 19 | }; 20 | 21 | template 22 | struct convention < CallConvention::cdecl_t, retn, args... > { 23 | typedef retn(__cdecl *type)(args...); 24 | }; 25 | 26 | 27 | template class Hook 28 | { 29 | typedef typename convention::type type; 30 | 31 | type _orig; 32 | type _detour; 33 | 34 | bool _isApplied; 35 | public: 36 | Hook() : _isApplied(false), _orig(0), _detour(0) { } 37 | 38 | template 39 | Hook(T pFunc, type detour) : apply(pFunc, detour) { } 40 | 41 | ~Hook(){ 42 | remove(); 43 | } 44 | 45 | template 46 | void apply(T pFunc, type detour) 47 | { 48 | _detour = detour; 49 | _orig = (type)DetourFunction((PBYTE)pFunc, (PBYTE)_detour); 50 | _isApplied = true; 51 | } 52 | 53 | bool remove() 54 | { 55 | if (!_isApplied) 56 | return false; 57 | 58 | _isApplied = false; 59 | return DetourRemove((PBYTE)_orig, (PBYTE)_detour) > 0; 60 | } 61 | 62 | retn callOrig(args... p) 63 | { 64 | return _orig(p...); 65 | } 66 | 67 | const bool isApplied() const { 68 | return _isApplied; 69 | } 70 | }; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Memory.cpp: -------------------------------------------------------------------------------- 1 | #include "Memory.hpp" 2 | 3 | int Utils::Memory::Internal::filter(unsigned int code, struct _EXCEPTION_POINTERS *ep) 4 | { 5 | return code == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH; 6 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Memory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Windows.hpp" 3 | #include 4 | 5 | namespace Utils 6 | { 7 | namespace Memory 8 | { 9 | namespace Internal 10 | { 11 | int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep); 12 | 13 | template 14 | T readMemory(uintptr_t addr, bool& success) 15 | { 16 | __try 17 | { 18 | auto val = *(T *)(addr); 19 | success = true; 20 | return val; 21 | } 22 | __except (filter(GetExceptionCode(), GetExceptionInformation())) 23 | { 24 | success = false; 25 | } 26 | 27 | return T(); 28 | } 29 | } 30 | 31 | template 32 | boost::optional readMemory(uintptr_t addr) 33 | { 34 | bool success = false; 35 | auto t = Internal::readMemory(addr, success); 36 | 37 | return success ? boost::optional(t) : boost::optional(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Module.cpp: -------------------------------------------------------------------------------- 1 | #include "module.hpp" 2 | #include 3 | 4 | 5 | DWORD Utils::Module::moduleBase(LPCTSTR file) 6 | { 7 | return (DWORD)GetModuleHandle(file); 8 | } 9 | 10 | DWORD Utils::Module::moduleLength(HMODULE hModule) 11 | { 12 | MODULEINFO info; 13 | GetModuleInformation(GetCurrentProcess(), hModule, &info, sizeof(info)); 14 | return info.SizeOfImage; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Module.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Windows.hpp" 3 | 4 | namespace Utils 5 | { 6 | namespace Module 7 | { 8 | DWORD moduleBase(LPCTSTR file); 9 | DWORD moduleLength(HMODULE hModule); 10 | } 11 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/NakedHook.cpp: -------------------------------------------------------------------------------- 1 | #include "NakedHook.hpp" 2 | 3 | 4 | Utils::NakedHook::NakedHook::~NakedHook() 5 | { 6 | if (applied()) 7 | remove(); 8 | 9 | delete[] m_pOrigData; 10 | } 11 | 12 | void Utils::NakedHook::NakedHook::init(BYTE* pTarget, DWORD dwTo, SIZE_T Len) 13 | { 14 | m_pTarget = pTarget; 15 | m_To = dwTo; 16 | m_Len = Len; 17 | m_pOrigData = new UCHAR[Len]; 18 | } 19 | 20 | BOOL Utils::NakedHook::NakedHook::remove() 21 | { 22 | if (!applied()) 23 | return FALSE; 24 | 25 | DWORD dwProtect; 26 | if (VirtualProtect((void *) m_pTarget, m_Len, PAGE_EXECUTE_READWRITE, &dwProtect)){ 27 | 28 | memcpy(m_pTarget, m_pOrigData, m_Len); 29 | 30 | VirtualProtect((void *) m_pTarget, m_Len, dwProtect, NULL); 31 | FlushInstructionCache(GetCurrentProcess(), m_pTarget, m_Len); 32 | 33 | m_IsApplied = FALSE; 34 | } 35 | 36 | return applied(); 37 | } 38 | 39 | BOOL Utils::NakedHook::NakedHook::apply() 40 | { 41 | if (applied()) 42 | return FALSE; 43 | 44 | DWORD dwProtect; 45 | if (VirtualProtect((void *) m_pTarget, m_Len, PAGE_EXECUTE_READWRITE, &dwProtect)){ 46 | memcpy(m_pOrigData, m_pTarget, m_Len); 47 | 48 | DWORD jmp = m_To - (DWORD) m_pTarget - 0x5; 49 | m_pTarget[0] = 0xE9; 50 | memcpy((void *) (BYTE *) (m_pTarget + 1), &jmp, 4); 51 | 52 | VirtualProtect((void *) m_pTarget, m_Len, dwProtect, NULL); 53 | FlushInstructionCache(GetCurrentProcess(), m_pTarget, m_Len); 54 | 55 | m_IsApplied = TRUE; 56 | return TRUE; 57 | } 58 | 59 | m_IsApplied = FALSE; 60 | return FALSE; 61 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/NakedHook.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "windows.h" 3 | 4 | namespace Utils 5 | { 6 | namespace NakedHook 7 | { 8 | class NakedHook 9 | { 10 | UCHAR* m_pOrigData; 11 | BYTE* m_pTarget; 12 | DWORD m_To; 13 | SIZE_T m_Len; 14 | BOOL m_IsApplied; 15 | 16 | public: 17 | ~NakedHook(); 18 | 19 | void init(BYTE* pTarget, DWORD dwTo, SIZE_T Len); 20 | 21 | BOOL remove(); 22 | BOOL apply(); 23 | 24 | BOOL applied() const { return m_IsApplied; } 25 | DWORD jmp() const { return (DWORD)m_pTarget + m_Len; } 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Pattern.cpp: -------------------------------------------------------------------------------- 1 | #include "Pattern.hpp" 2 | 3 | bool Utils::Pattern::Internal::dataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask) 4 | { 5 | for (; *szMask; ++szMask, ++pData, ++bMask) 6 | if (*szMask == 'x' && *pData != *bMask) 7 | return false; 8 | return (*szMask) == NULL; 9 | } 10 | 11 | 12 | DWORD Utils::Pattern::findPattern(DWORD addr, DWORD len, const BYTE *bMask, const char *szMask) 13 | { 14 | for (DWORD i = 0; i < len; i++) 15 | if (Internal::dataCompare((BYTE*) (addr + i), bMask, szMask)) 16 | return (DWORD) (addr + i); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Pattern.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Windows.hpp" 3 | 4 | namespace Utils 5 | { 6 | namespace Pattern 7 | { 8 | namespace Internal 9 | { 10 | bool dataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask); 11 | } 12 | 13 | DWORD findPattern(DWORD addr, DWORD len, const BYTE *bMask, const char *szMask); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/PipeClient.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows.hpp" 2 | #include "PipeClient.hpp" 3 | #include "Serializer.hpp" 4 | #include 5 | #include 6 | 7 | Utils::PipeClient::PipeClient(Serializer& serializerIn, Serializer& serializerOut) : 8 | m_bSuccess(false) 9 | { 10 | char szData[BUFSIZE] = { 0 }; 11 | char szPipe[MAX_PATH + 1] = { 0 }; 12 | DWORD dwReaded; 13 | 14 | sprintf_s(szPipe, "\\\\.\\pipe\\%s", Shared::Config::pipeName); 15 | 16 | if (CallNamedPipe(szPipe, (LPVOID)serializerIn.data(), serializerIn.numberOfBytesUsed(), szData, sizeof(szData), &dwReaded, TIME_OUT)) 17 | { 18 | serializerOut.setData(szData, sizeof(szData)); 19 | m_bSuccess = true; 20 | } 21 | } 22 | 23 | bool Utils::PipeClient::success() const 24 | { 25 | return m_bSuccess; 26 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/PipeClient.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define BUFSIZE 4096 4 | #define TIME_OUT 100 5 | 6 | namespace Utils 7 | { 8 | class Serializer; 9 | 10 | class PipeClient 11 | { 12 | public: 13 | PipeClient(Serializer& serializerIn, Serializer& serializerOut); 14 | 15 | bool success() const; 16 | private: 17 | bool m_bSuccess; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/PipeServer.cpp: -------------------------------------------------------------------------------- 1 | #include "PipeServer.hpp" 2 | #include "Serializer.hpp" 3 | #include 4 | #include 5 | 6 | #define CONNECTING_STATE 0 7 | #define READING_STATE 1 8 | #define WRITING_STATE 2 9 | 10 | BOOL Utils::PipeServer::connectToNewClient(HANDLE hPipe, LPOVERLAPPED lpo) 11 | { 12 | BOOL fConnected, fPendingIO = FALSE; 13 | 14 | fConnected = ConnectNamedPipe(hPipe, lpo); 15 | 16 | if (fConnected) 17 | return 0; 18 | 19 | switch (GetLastError()) 20 | { 21 | case ERROR_IO_PENDING: 22 | fPendingIO = TRUE; 23 | break; 24 | 25 | case ERROR_PIPE_CONNECTED: 26 | if (SetEvent(lpo->hEvent)) 27 | break; 28 | default: 29 | { 30 | return 0; 31 | } 32 | } 33 | 34 | return fPendingIO; 35 | } 36 | 37 | void Utils::PipeServer::disconnectAndReconnect(DWORD dwIdx) 38 | { 39 | DisconnectNamedPipe(m_Pipes[dwIdx].m_hPipe); 40 | m_Pipes[dwIdx].m_fPendingIO = connectToNewClient(m_Pipes[dwIdx].m_hPipe, &m_Pipes[dwIdx].m_Overlapped); 41 | m_Pipes[dwIdx].m_dwState = m_Pipes[dwIdx].m_fPendingIO ? CONNECTING_STATE : READING_STATE; 42 | 43 | } 44 | Utils::PipeServer::PipeServer(boost::function func) : m_cbCallback(func), m_thread(0) 45 | { 46 | memset(m_szPipe, 0, sizeof(m_szPipe)); 47 | memset(m_Pipes, 0, sizeof(m_Pipes)); 48 | 49 | sprintf_s(m_szPipe, "\\\\.\\pipe\\%s", Shared::Config::pipeName); 50 | 51 | for (int i = 0; i < MAX_CLIENTS; i++) 52 | { 53 | m_hEvents[i] = CreateEvent(NULL, TRUE, TRUE, NULL); 54 | m_Pipes[i].m_Overlapped.hEvent = m_hEvents[i]; 55 | m_Pipes[i].m_hPipe = CreateNamedPipeA(m_szPipe, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 56 | MAX_CLIENTS, BUFSIZE, BUFSIZE, PIPE_TIMEOUT, NULL); 57 | 58 | m_Pipes[i].m_fPendingIO = connectToNewClient(m_Pipes[i].m_hPipe, &m_Pipes[i].m_Overlapped); 59 | m_Pipes[i].m_dwState = m_Pipes[i].m_fPendingIO ? CONNECTING_STATE : READING_STATE; 60 | } 61 | 62 | m_thread = new boost::thread(boost::bind(&PipeServer::thread, this)); 63 | } 64 | 65 | 66 | Utils::PipeServer::~PipeServer(void) 67 | { 68 | if (m_thread) 69 | { 70 | m_thread->interrupt(); 71 | if (m_thread->joinable()) 72 | m_thread->join(); 73 | delete m_thread; 74 | m_thread = NULL; 75 | } 76 | } 77 | 78 | void Utils::PipeServer::thread() 79 | { 80 | BOOL bSuccess; 81 | DWORD dwRet; 82 | 83 | while (true) 84 | { 85 | boost::this_thread::interruption_point(); 86 | 87 | DWORD dwWait = WaitForMultipleObjects(MAX_CLIENTS, m_hEvents, FALSE, INFINITE); 88 | 89 | int idx = dwWait - WAIT_OBJECT_0; 90 | if (idx < 0 || idx >(MAX_CLIENTS - 1)) 91 | continue; 92 | 93 | if (m_Pipes[idx].m_fPendingIO) 94 | { 95 | bSuccess = GetOverlappedResult(m_Pipes[idx].m_hPipe, &m_Pipes[idx].m_Overlapped, &dwRet, FALSE); 96 | 97 | switch (m_Pipes[idx].m_dwState) 98 | { 99 | case CONNECTING_STATE: 100 | if (!bSuccess) 101 | return; 102 | m_Pipes[idx].m_dwState = READING_STATE; 103 | break; 104 | case READING_STATE: 105 | if (!bSuccess || dwRet == 0) 106 | { 107 | disconnectAndReconnect(idx); 108 | continue; 109 | } 110 | m_Pipes[idx].m_dwRead = dwRet; 111 | m_Pipes[idx].m_dwState = WRITING_STATE; 112 | break; 113 | case WRITING_STATE: 114 | if (!bSuccess || dwRet != m_Pipes[idx].m_dwToWrite) 115 | { 116 | disconnectAndReconnect(idx); 117 | continue; 118 | } 119 | m_Pipes[idx].m_dwState = READING_STATE; 120 | break; 121 | default: 122 | return; 123 | } 124 | } 125 | 126 | switch (m_Pipes[idx].m_dwState) 127 | { 128 | 129 | case READING_STATE: 130 | bSuccess = ReadFile(m_Pipes[idx].m_hPipe, m_Pipes[idx].m_szRequest, BUFSIZE, &m_Pipes[idx].m_dwRead, &m_Pipes[idx].m_Overlapped); 131 | 132 | if (bSuccess && m_Pipes[idx].m_dwRead != 0) 133 | { 134 | m_Pipes[idx].m_fPendingIO = FALSE; 135 | m_Pipes[idx].m_dwState = WRITING_STATE; 136 | continue; 137 | } 138 | if (!bSuccess && (GetLastError() == ERROR_IO_PENDING)) 139 | { 140 | m_Pipes[idx].m_fPendingIO = TRUE; 141 | continue; 142 | } 143 | disconnectAndReconnect(idx); 144 | break; 145 | case WRITING_STATE: 146 | Serializer serializerIn(m_Pipes[idx].m_szRequest, m_Pipes[idx].m_dwRead); 147 | Serializer serializerOut; 148 | 149 | m_cbCallback(serializerIn, serializerOut); 150 | 151 | memset(m_Pipes[idx].m_szReply, 0, BUFSIZE); 152 | memset(m_Pipes[idx].m_szRequest, 0, BUFSIZE); 153 | memcpy(m_Pipes[idx].m_szReply, serializerOut.data(), serializerOut.numberOfBytesUsed()); 154 | 155 | m_Pipes[idx].m_dwToWrite = serializerOut.numberOfBytesUsed(); 156 | 157 | bSuccess = WriteFile(m_Pipes[idx].m_hPipe, m_Pipes[idx].m_szReply, m_Pipes[idx].m_dwToWrite, &dwRet, &m_Pipes[idx].m_Overlapped); 158 | if (bSuccess && dwRet == m_Pipes[idx].m_dwToWrite) 159 | { 160 | m_Pipes[idx].m_fPendingIO = FALSE; 161 | m_Pipes[idx].m_dwState = READING_STATE; 162 | continue; 163 | } 164 | if (!bSuccess && GetLastError() == ERROR_IO_PENDING) 165 | { 166 | m_Pipes[idx].m_fPendingIO = true; 167 | continue; 168 | } 169 | disconnectAndReconnect(idx); 170 | break; 171 | } 172 | } 173 | } 174 | 175 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/PipeServer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Windows.h" 3 | #include 4 | #include 5 | 6 | #define MAX_CLIENTS 16 7 | #define BUFSIZE 4096 8 | #define PIPE_TIMEOUT 5000 9 | 10 | namespace boost 11 | { 12 | class thread; 13 | } 14 | 15 | namespace Utils 16 | { 17 | class Serializer; 18 | 19 | class PipeServer 20 | { 21 | typedef struct 22 | { 23 | OVERLAPPED m_Overlapped; 24 | HANDLE m_hPipe; 25 | char m_szRequest[BUFSIZE], 26 | m_szReply[BUFSIZE]; 27 | DWORD m_dwRead, 28 | m_dwToWrite, 29 | m_dwState; 30 | BOOL m_fPendingIO; 31 | } PIPEINSTANCE, *LPPIPEINSTANCE; 32 | 33 | public: 34 | PipeServer(boost::function func); 35 | ~PipeServer(); 36 | 37 | private: 38 | void thread(); 39 | BOOL connectToNewClient(HANDLE hPipe, LPOVERLAPPED lpo); 40 | void disconnectAndReconnect(DWORD dwIdx); 41 | 42 | PIPEINSTANCE m_Pipes[MAX_CLIENTS]; 43 | HANDLE m_hEvents[MAX_CLIENTS]; 44 | 45 | char m_szPipe[MAX_PATH]; 46 | 47 | boost::thread *m_thread; 48 | boost::function m_cbCallback; 49 | }; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Process.cpp: -------------------------------------------------------------------------------- 1 | #include "Process.hpp" 2 | #include "Windows.hpp" 3 | #include 4 | #include 5 | 6 | unsigned long Utils::Process::pidByWindowName(const std::string& windName) 7 | { 8 | DWORD dwPID = 0; 9 | HWND wHandle = 0; 10 | wHandle = FindWindow(NULL, windName.c_str()); 11 | if (wHandle == 0 || wHandle == INVALID_HANDLE_VALUE) 12 | return dwPID; 13 | 14 | GetWindowThreadProcessId(wHandle, &dwPID); 15 | return dwPID; 16 | } 17 | 18 | unsigned long Utils::Process::pidByProcessName(const std::string& procName) 19 | { 20 | PROCESSENTRY32 entry; 21 | DWORD dwPID = 0; 22 | 23 | HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 24 | if (hSnapshot == 0 || hSnapshot == INVALID_HANDLE_VALUE) 25 | return dwPID; 26 | 27 | entry.dwSize = sizeof(entry); 28 | Process32First(hSnapshot, &entry); 29 | 30 | while (Process32Next(hSnapshot, &entry)) 31 | { 32 | if (boost::iequals(entry.szExeFile, procName)) 33 | { 34 | dwPID = entry.th32ProcessID; 35 | break; 36 | } 37 | } 38 | 39 | CloseHandle(hSnapshot); 40 | return dwPID; 41 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Process.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Utils 5 | { 6 | namespace Process 7 | { 8 | unsigned long pidByProcessName(const std::string&); 9 | unsigned long pidByWindowName(const std::string&); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/SafeBlock.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Utils 7 | { 8 | namespace SafeBlock 9 | { 10 | template::type> 11 | Ret safeExecute(Executer executer, T&&... args) 12 | { 13 | try 14 | { 15 | return executer(args...); 16 | } 17 | catch (...) 18 | { 19 | return Ret(); 20 | } 21 | } 22 | 23 | template 24 | bool safeExecuteWithValidation(Executer executer, T&&... args) 25 | { 26 | try 27 | { 28 | executer(args...); 29 | return true; 30 | } 31 | catch (...) 32 | { 33 | return false; 34 | } 35 | } 36 | 37 | template 38 | std::shared_ptr safeMakeShared(Args&&... p) 39 | { 40 | try 41 | { 42 | return std::make_shared(p...); 43 | } 44 | catch (...) 45 | { 46 | return nullptr; 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Serializer.cpp: -------------------------------------------------------------------------------- 1 | #include "Serializer.hpp" 2 | 3 | Utils::Serializer::Serializer() 4 | { 5 | _oa = SafeBlock::safeMakeShared(_ss); 6 | } 7 | 8 | Utils::Serializer::Serializer(const char * const _data, const unsigned int len) : _ss(std::string(_data, len)) 9 | { 10 | _ia = SafeBlock::safeMakeShared(_ss); 11 | } 12 | 13 | Utils::Serializer::~Serializer() 14 | { 15 | SafeBlock::safeExecute([&](){ 16 | _oa.reset(); 17 | _ia.reset(); 18 | }); 19 | } 20 | 21 | const char * Utils::Serializer::data() 22 | { 23 | _ss_str = _ss.str(); 24 | return _ss_str.c_str(); 25 | } 26 | 27 | void Utils::Serializer::setData(const char *szData, const size_t size) 28 | { 29 | _ss = std::stringstream(std::string(szData, size)); 30 | _ia = SafeBlock::safeMakeShared(_ss); 31 | } 32 | 33 | int Utils::Serializer::numberOfBytesUsed() const 34 | { 35 | return _ss.str().length(); 36 | } 37 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Serializer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SafeBlock.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define SERIALIZATION_READ(S, T, V) T V; S >> V; 10 | 11 | namespace Utils 12 | { 13 | class Serializer 14 | { 15 | typedef boost::archive::text_iarchive iarchive; 16 | typedef boost::archive::text_oarchive oarchive; 17 | 18 | std::shared_ptr _oa; 19 | std::shared_ptr _ia; 20 | 21 | std::stringstream _ss; 22 | std::string _ss_str; 23 | 24 | public: 25 | Serializer(); 26 | Serializer(const char * const _data, const unsigned int len); 27 | 28 | ~Serializer(); 29 | 30 | const char *data(); 31 | void setData(const char *szData, const size_t size); 32 | 33 | int numberOfBytesUsed() const; 34 | 35 | template 36 | Serializer& operator<<(const T& t) 37 | { 38 | write(t); 39 | return *this; 40 | } 41 | template 42 | Serializer& operator>>(T& t) 43 | { 44 | read(t); 45 | return *this; 46 | } 47 | 48 | private: 49 | template 50 | void write(const T& t) 51 | { 52 | SafeBlock::safeExecute([&](){ 53 | *_oa & t; 54 | }); 55 | } 56 | 57 | template 58 | void read(T& t) 59 | { 60 | SafeBlock::safeExecute([&](){ 61 | *_ia & t; 62 | }); 63 | } 64 | }; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/Windows.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define WIN32_LEAN_AND_MEAN 3 | 4 | #include 5 | #include -------------------------------------------------------------------------------- /src/Open-SAMP-API/Utils/algorithm.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | void erase_if(MapContainer &c, Pred pred) 5 | { 6 | for (auto p = c.begin(); p != c.end();) 7 | if (pred(p->first, p->second)) 8 | p = c.erase(p); 9 | else ++p; 10 | } 11 | -------------------------------------------------------------------------------- /src/Open-SAMP-API/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include "dllmain.hpp" 2 | #include 3 | #include 4 | 5 | HANDLE g_hDllHandle = 0; 6 | 7 | BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID) 8 | { 9 | g_hDllHandle = hInstance; 10 | 11 | DisableThreadLibraryCalls((HMODULE) hInstance); 12 | 13 | if (dwReason != DLL_PROCESS_ATTACH) 14 | return FALSE; 15 | 16 | if (GetModuleHandle("samp.dll")) 17 | return CreateThread(0, 0, (LPTHREAD_START_ROUTINE) initGame, 0, 0, 0) > 0; 18 | 19 | return TRUE; 20 | } -------------------------------------------------------------------------------- /src/Open-SAMP-API/dllmain.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | extern HANDLE g_hDllHandle; -------------------------------------------------------------------------------- /src/Open-SAMP-API/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /test/AHK/classes/DefaultPrintAdapter.ahk: -------------------------------------------------------------------------------- 1 | #include PrintAdapter.ahk 2 | 3 | class DefaultPrintAdapter extends PrintAdapter { 4 | print(text) { 5 | MsgBox, %text% 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/AHK/classes/GamePrintAdapter.ahk: -------------------------------------------------------------------------------- 1 | #include classes\PrintAdapter.ahk 2 | #include ..\..\include\AHK\SAMP_API.ahk 3 | 4 | class GamePrintAdapter extends PrintAdapter { 5 | print(text) { 6 | AddChatMessage(text) 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/AHK/classes/PrintAdapter.ahk: -------------------------------------------------------------------------------- 1 | 2 | class PrintAdapter { 3 | ; abstract 4 | print(text) { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/AHK/classes/TestBase.ahk: -------------------------------------------------------------------------------- 1 | #include classes\PrintAdapter.ahk 2 | 3 | class TestBase { 4 | __New(printAdapter) { 5 | this.printAdapter := printAdapter 6 | this.verified := 0 7 | this.failed := 0 8 | this.sleepAmount := 0 9 | } 10 | 11 | _verified(text) { 12 | this.printAdapter.print("{0000ff}TEST:{ffffff} " . text . ": {00ff00}Verified") 13 | this.verified++ 14 | } 15 | 16 | _failed(text) { 17 | this.printAdapter.print("{0000ff}TEST:{ffffff} " . text . ": {ff0000}Failed") 18 | this.failed++ 19 | } 20 | 21 | setSleep(ms) { 22 | this.sleepAmount := ms 23 | } 24 | 25 | verify(func, text) { 26 | if(func) 27 | this._verified(text) 28 | else 29 | this._failed(text) 30 | Sleep, % this.sleepAmount 31 | } 32 | 33 | compare(expected, actual, text) { 34 | if(expected == actual) 35 | this._verified(text) 36 | else 37 | this._failed(text . "(" . expected . " != " . actual . ")") 38 | Sleep, % this.sleepAmount 39 | } 40 | 41 | printSummary() { 42 | this.printAdapter.print("{0000ff}-----------------------SUMMARY------------------------------") 43 | if(this.failed == 0) { 44 | this.printAdapter.print("Verified " . this.verified . " tests") 45 | } else { 46 | this.printAdapter.print("Failed: {ff0000}" + this.failed . "{ffffff} test(s), Verified: {00ff00}" . this.verified . "{ffffff} test(s)") 47 | } 48 | this.printAdapter.print("{0000ff}------------------------------------------------------------") 49 | } 50 | 51 | main() { 52 | this.runTest() 53 | this.printSummary() 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /test/AHK/test.ahk: -------------------------------------------------------------------------------- 1 | #SingleInstance, force 2 | #NoEnv 3 | #IfWinActive, GTA:SA:MP 4 | #include ..\..\include\AHK\SAMP_API.ahk 5 | #include classes\GamePrintAdapter.ahk 6 | 7 | ; Test cases 8 | #include tests\SAMPFunctions.ahk 9 | #include tests\OverlayFunctions.ahk 10 | 11 | ; Set the API's parameters 12 | SetParam("use_window", "1") 13 | SetParam("window", "GTA:SA:MP") 14 | 15 | ; Create GUI 16 | Gui, Show, w250 h50, Tests 17 | return 18 | 19 | GuiClose: 20 | ExitApp 21 | 22 | ; Factory for executing Tests 23 | executeTest(class_name) { 24 | test := new class_name(new GamePrintAdapter()) 25 | test.main() 26 | test := 0 27 | } 28 | 29 | 1::executeTest(SAMPFunctions) 30 | 2::executeTest(OverlayFunctions) 31 | 32 | -------------------------------------------------------------------------------- /test/AHK/tests/OverlayFunctions.ahk: -------------------------------------------------------------------------------- 1 | #include classes/TestBase.ahk 2 | 3 | class OverlayFunctions extends TestBase { 4 | runTest() { 5 | this.setSleep(2000) 6 | this.compare(1, DestroyAllVisual(), "Destroy all visuals") 7 | 8 | this.runTextTests() 9 | this.runBoxTests() 10 | } 11 | 12 | __Delete() { 13 | if(this.text != -1) 14 | TextDestroy(this.text) 15 | 16 | if(this.box != -1) 17 | BoxDestroy(this.box) 18 | } 19 | 20 | runTextTests() { 21 | this.text := TextCreate("Arial", 6, false, false, 720, 91, 0xFFFFFFFF, "100", true, true) 22 | this.verify(this.text != -1, "Create a text") 23 | this.compare(1, TextSetShadow(this.text, true), "Set text shadow to true") 24 | this.compare(1, TextSetShadow(this.text, false), "Set text shadow to false") 25 | this.compare(1, TextSetShown(this.text, false), "Set text shown to false") 26 | this.compare(1, TextSetShown(this.text, true), "Set text shown to true") 27 | this.compare(1, TextSetColor(this.text, 0xFFFF0000), "Set text color to red") 28 | this.compare(1, TextSetPos(this.text, 200, 200), "Set text position to (200|200)") 29 | this.compare(1, TextSetString(this.text, "test"), "Set string to test") 30 | this.compare(1, TextUpdate(this.text, "Arial", 30, true, true), "Update text") 31 | if(TextDestroy(this.text)) 32 | this.text := -1 33 | 34 | this.compare(-1, this.text, "Destroyed the text") 35 | } 36 | 37 | runBoxTests() { 38 | this.box := BoxCreate(200, 200, 200, 200, 0xFFFF0000, true) 39 | this.verify(this.box != -1, "Create a box") 40 | 41 | this.compare(1, BoxSetShown(this.box, false), "Set box shown to false") 42 | this.compare(1, BoxSetShown(this.box, true), "Set box shown to true") 43 | this.compare(1, BoxSetBorder(this.box, 5, true), "Enable box border") 44 | this.compare(1, BoxSetBorderColor(this.box, 0xFF00FF00), "Set box border color to green") 45 | this.compare(1, BoxSetBorder(this.box, 5, false), "Disable box border") 46 | this.compare(1, BoxSetColor(this.box, 0xFF0000FF), "Set box color to blue") 47 | this.compare(1, BoxSetHeight(this.box, 300), "Set box height to 300") 48 | this.compare(1, BoxSetPos(this.box, 400, 400), "Set box position to (400|400)") 49 | this.compare(1, BoxSetWidth(this.box, 300), "Set box with to 300") 50 | if(BoxDestroy(this.box)) 51 | this.box := -1 52 | 53 | this.compare(-1, this.box, "Destroyed the box") 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /test/AHK/tests/SAMPFunctions.ahk: -------------------------------------------------------------------------------- 1 | #include classes/TestBase.ahk 2 | 3 | class SAMPFunctions extends TestBase { 4 | runTest() { 5 | this.compare(1, AddChatMessage("Hello world"), "Add chat message") 6 | this.compare(1, AddChatMessage("{ff0000}Hello {00ff00}world"), "Add chat with colors") 7 | this.compare(1, SendChat("hello"), "send hello to chat") 8 | this.compare(1, SendChat("/hello"), "send command to chat") 9 | this.compare(1, ShowGameText("Hello world", 1000, 3), "show gametext") 10 | } 11 | } 12 | --------------------------------------------------------------------------------