├── .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 [](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