├── .gitignore ├── Entities.hpp ├── Entity.hpp ├── LICENSE ├── Pools.hpp ├── examples ├── CMakeLists.txt └── example.cpp └── rage.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | *.smod 19 | 20 | # Compiled Static libraries 21 | *.lai 22 | *.la 23 | *.a 24 | *.lib 25 | 26 | # Executables 27 | *.exe 28 | *.out 29 | *.app 30 | -------------------------------------------------------------------------------- /Entities.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef GetProp 4 | #undef GetProp 5 | #endif 6 | #ifdef SetProp 7 | #undef SetProp 8 | #endif 9 | 10 | namespace rage 11 | { 12 | 13 | struct rgb_t 14 | { 15 | rgb_t(uint8_t r, uint8_t g, uint8_t b) 16 | : intvalue((b << 16) + (g << 8) + r) { } 17 | 18 | explicit rgb_t(uint32_t val) 19 | : intvalue(val) { } 20 | 21 | rgb_t() 22 | : intvalue(0) { } 23 | 24 | union 25 | { 26 | uint32_t intvalue; 27 | uint8_t rgba[3]; 28 | }; 29 | }; 30 | 31 | struct paintInfo_t 32 | { 33 | uint8_t type; 34 | uint8_t colour; 35 | }; 36 | 37 | enum class material_t : uint8_t 38 | { 39 | Color, 40 | RGB, 41 | Paint 42 | }; 43 | 44 | enum class colshape_t : uint8_t 45 | { 46 | Sphere, 47 | Tube, 48 | Circle, 49 | Polygon, 50 | Cuboid, 51 | Rectangle 52 | }; 53 | 54 | using hash_t = uint32_t; 55 | 56 | class IPlayer; 57 | class IVehicle; 58 | class IColshape; 59 | class ICheckpoint; 60 | class IMarker; 61 | class IBlip; 62 | class IPickup; 63 | 64 | struct headOverlay_t 65 | { 66 | uint8_t index; 67 | float opacity; 68 | uint8_t colorId; 69 | uint8_t secondaryColorId; 70 | }; 71 | 72 | using Entity = 73 | IEntity; 74 | 75 | class IPlayer 76 | : public Entity 77 | { 78 | public: 79 | 80 | virtual void Kick(const char *reason = nullptr) = 0; 81 | virtual void Ban(const char *reason = nullptr) = 0; 82 | virtual void OutputChatBox(const std::string& text) = 0; 83 | virtual void Notify(const std::string& text) = 0; 84 | public: 85 | virtual void _Call(const std::string& eventName, const arg_t *arguments = nullptr, size_t count = 0) = 0; 86 | virtual void _CallHash(uint64_t eventNameHash, const arg_t *arguments = nullptr, size_t count = 0) = 0; // xxhash64 87 | virtual void _Invoke(uint64_t nativeHash, const arg_t *arguments = nullptr, size_t count = 0) = 0; 88 | public: 89 | virtual void Spawn(const vector3& pos, float heading) = 0; 90 | virtual void PlayAnimation(const std::string& dict, const std::string& name, float speed = 8.f, int flags = 0) = 0; 91 | virtual void PlayScenario(const std::string& scenario) = 0; 92 | virtual void StopAnimation() = 0; 93 | 94 | virtual const clothData_t& GetClothes(uint8_t id) = 0; 95 | virtual void SetClothes(uint8_t id, const clothData_t& clothes) = 0; 96 | 97 | virtual void SetClothes(const std::vector>& clothes) = 0; 98 | 99 | virtual const propData_t& GetProp(uint8_t id) = 0; 100 | virtual void SetProp(uint8_t id, const propData_t prop) = 0; 101 | 102 | virtual void SetProp(const std::vector>& clothes) = 0; 103 | 104 | virtual void SetCustomization(bool gender, 105 | const rage::headBlend_t& headBlend, 106 | uint8_t eyeColor, uint8_t hairColor, uint8_t hightlightColor, 107 | const std::vector& faceFeatures, 108 | const std::map& headOverlays, 109 | const std::vector> decorations) = 0; 110 | 111 | virtual uint32_t GetDecoration(uint32_t collection) = 0; 112 | virtual void RemoveDecoration(uint32_t collection, uint32_t overlay) = 0; 113 | virtual void SetDecoration(uint32_t collection, uint32_t overlay) = 0; 114 | virtual void SetDecorations(std::vector> decorations) = 0; 115 | 116 | virtual void ClearDecorations() = 0; 117 | 118 | virtual void EnableVoiceTo(IPlayer *target) = 0; 119 | virtual void DisableVoiceTo(IPlayer *target) = 0; 120 | 121 | virtual std::vector GetVoiceListeners() = 0; 122 | 123 | virtual void Eval(const std::string& code) = 0; 124 | 125 | virtual const std::string& GetName() = 0; 126 | virtual void SetName(const std::string& name) = 0; 127 | 128 | virtual bool IsAiming() = 0; 129 | 130 | virtual float GetHeading() = 0; 131 | virtual void SetHeading(float heading) = 0; 132 | 133 | virtual float GetMoveSpeed() = 0; 134 | 135 | virtual float GetHealth() = 0; 136 | virtual void SetHealth(float armour) = 0; 137 | 138 | virtual float GetArmour() = 0; 139 | virtual void SetArmour(float armour) = 0; 140 | 141 | virtual const vector3& GetAimingAt() = 0; 142 | 143 | virtual int GetPing() = 0; 144 | virtual float GetPacketLoss() = 0; 145 | 146 | virtual const std::string& GetKickReason() = 0; 147 | 148 | virtual std::string GetIp() = 0; 149 | 150 | virtual bool IsJumping() = 0; 151 | virtual bool IsInCover() = 0; 152 | virtual bool IsEnteringVehicle() = 0; 153 | virtual bool IsLeavingVehicle() = 0; 154 | virtual bool IsClimbing() = 0; 155 | virtual bool IsOnLadder() = 0; 156 | virtual bool IsReloading() = 0; 157 | virtual bool IsInMelee() = 0; 158 | virtual std::string GetActionString() = 0; 159 | 160 | // Vehicle 161 | virtual IVehicle *GetVehicle() = 0; 162 | virtual void PutIntoVehicle(IVehicle *vehicle, int8_t seatId) = 0; 163 | virtual void RemoveFromVehicle() = 0; 164 | virtual int8_t GetSeat() = 0; 165 | 166 | // Customization 167 | virtual uint8_t GetEyeColour() = 0; 168 | virtual void SetEyeColour(uint8_t colour) = 0; 169 | 170 | virtual uint8_t GetHairColour() = 0; 171 | virtual uint8_t GetHairHighlightColour() = 0; 172 | virtual void SetHairColour(uint8_t colour, uint8_t highlightColour) = 0; 173 | 174 | virtual float GetFaceFeature(uint8_t id) = 0; 175 | virtual void SetFaceFeature(uint8_t id, float scale) = 0; 176 | 177 | virtual const headBlend_t& GetHeadBlend() = 0; 178 | 179 | virtual void SetHeadBlend(int shapeFirstID, int shapeSecondID, int shapeThirdID, int skinFirstID, int skinSecondID, int skinThirdID, 180 | float shapeMix, float skinMix, float thirdMix) = 0; 181 | 182 | virtual void UpdateHeadBlend(float shapeMix, float skinMix, float thirdMix) = 0; 183 | 184 | virtual headOverlay_t GetHeadOverlay(uint8_t overlayId) = 0; 185 | virtual void SetHeadOverlay(uint8_t overlayId, headOverlay_t overlay) = 0; 186 | 187 | // Weapons 188 | virtual uint32_t GetCurrentWeapon() = 0; 189 | virtual void SetCurrentWeapon(uint32_t weapon) = 0; 190 | 191 | virtual uint16_t GetCurrentWeaponAmmo() = 0; 192 | virtual void SetCurrentWeaponAmmo(uint16_t ammo) = 0; 193 | 194 | virtual uint16_t GetWeaponAmmo(uint32_t weaponHash) = 0; 195 | virtual void SetWeaponAmmo(hash_t hash, uint16_t ammo) = 0; 196 | 197 | virtual std::map GetWeapons() = 0; 198 | 199 | virtual void GiveWeapon(hash_t hash, uint16_t ammo) = 0; 200 | virtual void GiveWeapons(std::vector> weapons) = 0; 201 | 202 | virtual void RemoveWeapon(hash_t hash) = 0; 203 | virtual void RemoveWeapons(const std::vector& hash) = 0; 204 | virtual void RemoveAllWeapons() = 0; 205 | 206 | // 207 | virtual bool IsStreamed(IPlayer *player) = 0; 208 | virtual std::vector GetStreamed() = 0; 209 | 210 | virtual const std::string& GetSerial() = 0; 211 | virtual const std::string& GetSocialClubName() = 0; 212 | 213 | virtual void RemoveObject(uint32_t model, const vector3& position, float radius) = 0; 214 | 215 | public: 216 | template 217 | void Call(const std::string& eventName, Args&&... args) 218 | { 219 | const int count = sizeof...(Args); 220 | 221 | if constexpr(count == 0) 222 | this->_Call(eventName); 223 | else 224 | { 225 | arg_t arguments[count] = { arg_t(std::forward(args))... }; 226 | this->_Call(eventName, arguments, count); 227 | } 228 | } 229 | 230 | template 231 | void Invoke(uint64_t hash, Args&&... args) 232 | { 233 | const int count = sizeof...(Args); 234 | 235 | if constexpr(count == 0) 236 | this->_Invoke(hash); 237 | else 238 | { 239 | arg_t arguments[count] = { arg_t(std::forward(args))... }; 240 | this->_Invoke(hash, arguments, count); 241 | } 242 | } 243 | }; 244 | 245 | class IVehicle 246 | : public Entity 247 | { 248 | public: 249 | virtual bool IsSirenActive() = 0; 250 | virtual void SetSirenActive(bool toggle) = 0; 251 | 252 | virtual bool IsHornActive() = 0; 253 | 254 | virtual bool AreHighbeamsActive() = 0; 255 | virtual void SetHighbeamsActive(bool toggle) = 0; 256 | 257 | virtual bool AreLightsActive() = 0; 258 | virtual void SetLightsActive(bool toggle) = 0; 259 | 260 | virtual bool IsEngineActive() = 0; 261 | virtual void SetEngineActive(bool toggle) = 0; 262 | 263 | virtual bool AreTaxiLightsActive() = 0; 264 | virtual void SetTaxiLightsActive(bool toggle) = 0; 265 | 266 | virtual bool IsRocketBoostActive() = 0; 267 | virtual bool IsBrakeActive() = 0; 268 | virtual float GetSteerAngle() = 0; 269 | virtual float GetGasPedalState() = 0; 270 | 271 | virtual float GetEngineHealth() = 0; 272 | virtual float GetBodyHealth() = 0; 273 | 274 | virtual rage::IPlayer *GetOccupant(uint8_t seat) = 0; 275 | virtual std::vector GetOccupants() = 0; 276 | virtual void SetOccupant(uint8_t seat, rage::IPlayer *player) = 0; 277 | 278 | virtual bool IsLocked() = 0; 279 | virtual void Lock(bool toggle) = 0; 280 | 281 | virtual bool IsDead() = 0; 282 | 283 | virtual void Explode() = 0; 284 | virtual void Spawn(const vector3& pos, float heading) = 0; 285 | 286 | virtual uint8_t GetMod(uint8_t id) = 0; 287 | virtual void SetMod(uint8_t id, uint8_t mod) = 0; 288 | 289 | virtual bool AreNeonsEnabled() = 0; 290 | virtual void EnableNeons(bool toggle) = 0; 291 | 292 | virtual void SetNeonsColour(uint8_t r, uint8_t g, uint8_t b) = 0; 293 | virtual const rage::rgb_t& GetNeonsColour() = 0; 294 | 295 | virtual void Repair() = 0; 296 | 297 | virtual rage::rgb_t GetColourRGB(uint8_t id) = 0; 298 | virtual uint8_t GetColour(uint8_t id) = 0; 299 | virtual uint8_t GetPaint(uint8_t id) = 0; 300 | 301 | virtual void SetColourRGB(const rage::rgb_t& primary, const rage::rgb_t& secondary) = 0; 302 | virtual void SetColour(uint8_t primary, uint8_t secondary) = 0; 303 | virtual void SetPaint(const rage::paintInfo_t& primary, const rage::paintInfo_t& secondary) = 0; 304 | 305 | virtual material_t GetMaterialType() = 0; 306 | 307 | virtual const std::string& GetNumberPlate() = 0; 308 | virtual void SetNumberPlate(const std::string& numberPlate) = 0; 309 | 310 | virtual bool IsStreamed(IPlayer *player) = 0; 311 | virtual std::vector GetStreamed() = 0; 312 | 313 | virtual uint8_t GetLivery() = 0; 314 | virtual void SetLivery(uint8_t livery) = 0; 315 | 316 | virtual uint8_t GetWheelColor() = 0; 317 | virtual void SetWheelColor(uint8_t color) = 0; 318 | 319 | virtual uint8_t GetWheelType() = 0; 320 | virtual void SetWheelType(uint8_t type) = 0; 321 | 322 | virtual uint8_t GetNumberPlateType() = 0; 323 | virtual void SetNumberPlateType(uint8_t type) = 0; 324 | 325 | virtual uint8_t GetPearlescentColor() = 0; 326 | virtual void SetPearlescentColor(uint8_t color) = 0; 327 | 328 | virtual uint8_t GetWindowTint() = 0; 329 | virtual void SetWindowTint(uint8_t tint) = 0; 330 | 331 | virtual uint8_t GetDashboardColor() = 0; 332 | virtual void SetDashboardColor(uint8_t color) = 0; 333 | 334 | virtual uint8_t GetTrimColor() = 0; 335 | virtual void SetTrimColor(uint8_t type) = 0; 336 | 337 | virtual bool GetExtra(uint8_t id) = 0; 338 | virtual void SetExtra(uint8_t id, bool state) = 0; 339 | 340 | virtual float GetMovableState() = 0; 341 | 342 | virtual const quat_t& GetQuaternion() = 0; 343 | virtual float GetHeading() = 0; 344 | 345 | virtual rage::IVehicle *GetTrailer() = 0; 346 | virtual rage::IVehicle *GetTraileredBy() = 0; 347 | }; 348 | 349 | class IColshape 350 | : public Entity 351 | { 352 | public: 353 | virtual bool IsPointWithin(const vector3& pos) = 0; 354 | virtual colshape_t GetShapeType() = 0; 355 | }; 356 | 357 | class ICheckpoint 358 | : public Entity 359 | { 360 | public: 361 | virtual const rage::rgba_t& GetColour() = 0; 362 | virtual void SetColour(uint8_t r, uint8_t g, uint8_t b, uint8_t a) = 0; 363 | 364 | virtual vector3& GetDirection() = 0; 365 | virtual void SetDirection(const vector3& dir) = 0; 366 | 367 | virtual float GetRadius() = 0; 368 | virtual void SetRadius(float radius) = 0; 369 | 370 | virtual bool IsVisible() = 0; 371 | virtual void SetVisible(bool toggle) = 0; 372 | 373 | virtual void ShowFor(const std::vector& players) = 0; 374 | virtual void HideFor(const std::vector& players) = 0; 375 | }; 376 | 377 | class IMarker 378 | : public Entity 379 | { 380 | public: 381 | virtual const rage::rgba_t& GetColour() = 0; 382 | virtual void SetColour(uint8_t r, uint8_t g, uint8_t b, uint8_t a) = 0; 383 | 384 | virtual vector3& GetDirection() = 0; 385 | virtual void SetDirection(const vector3& dir) = 0; 386 | 387 | virtual float GetScale() = 0; 388 | virtual void SetScale(float scale) = 0; 389 | 390 | virtual bool IsVisible() = 0; 391 | virtual void SetVisible(bool toggle) = 0; 392 | 393 | virtual void ShowFor(const std::vector& players) = 0; 394 | virtual void HideFor(const std::vector& players) = 0; 395 | }; 396 | 397 | class IBlip 398 | : public Entity 399 | { 400 | public: 401 | virtual float GetDrawDistance() = 0; 402 | virtual void SetDrawDistance(float distance) = 0; 403 | 404 | virtual short GetBlipRotation() = 0; 405 | virtual void SetRotation(short rotation) = 0; 406 | 407 | virtual bool IsShortRange() = 0; 408 | virtual void SetShortRange(bool toggle) = 0; 409 | 410 | virtual void RouteFor(const std::vector& players, uint8_t colour, float scale) = 0; 411 | virtual void UnrouteFor(const std::vector& players) = 0; 412 | 413 | virtual uint8_t GetColour() = 0; 414 | virtual void SetColour(uint8_t colour) = 0; 415 | 416 | //virtual uint8_t GetAlpha() = 0; 417 | //virtual void SetAlpha(uint8_t alpha) = 0; 418 | 419 | virtual float GetScale() = 0; 420 | virtual void SetScale(float scale) = 0; 421 | 422 | virtual const std::string& GetName() = 0; 423 | virtual void SetName(const std::string& name) = 0; 424 | }; 425 | 426 | class IPickup 427 | : public Entity 428 | { 429 | public: 430 | // todo 431 | }; 432 | 433 | class IObject 434 | : public Entity 435 | { 436 | public: 437 | }; 438 | 439 | class ITextLabel 440 | : public Entity 441 | { 442 | public: 443 | virtual rgba_t GetColor() = 0; 444 | virtual void SetColor(const rgba_t color) = 0; 445 | 446 | virtual const std::string& GetText() = 0; 447 | virtual void SetText(const std::string& text) = 0; 448 | 449 | virtual bool GetLOS() = 0; 450 | virtual void SetLOS(bool toggle) = 0; 451 | 452 | virtual float GetDrawDistance() = 0; 453 | virtual void SetDrawDistance(float distance) = 0; 454 | 455 | virtual uint8_t GetFont() = 0; 456 | virtual void SetFont(uint8_t font) = 0; 457 | }; 458 | } 459 | -------------------------------------------------------------------------------- /Entity.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace rage 4 | { 5 | struct rgba_t 6 | { 7 | rgba_t(uint8_t r, uint8_t g, uint8_t b, uint8_t a) 8 | : intvalue((a << 24) + (b << 16) + (g << 8) + r) { } 9 | 10 | explicit rgba_t(uint32_t val) 11 | : intvalue(val) { } 12 | 13 | rgba_t() 14 | : intvalue(0) { } 15 | 16 | union 17 | { 18 | uint32_t intvalue; 19 | uint8_t rgba[4]; 20 | }; 21 | }; 22 | 23 | using entityId_t = uint16_t; 24 | using dimensionId_t = uint32_t; 25 | 26 | template 27 | struct _vector3 28 | { 29 | T x; 30 | T y; 31 | T z; 32 | }; 33 | 34 | using vector3 = _vector3; 35 | 36 | struct quat_t 37 | { 38 | float x; 39 | float y; 40 | float z; 41 | float w; 42 | }; 43 | 44 | struct vector2 45 | { 46 | float x; 47 | float y; 48 | }; 49 | 50 | enum class entity_t : uint8_t 51 | { 52 | Player, 53 | Vehicle, 54 | Object, 55 | Pickup, 56 | Blip, 57 | Checkpoint, 58 | Marker, 59 | Colshape, 60 | TextLabel, 61 | }; 62 | 63 | class IEntity; 64 | 65 | #pragma pack(push, 1) 66 | struct clothData_t 67 | { 68 | uint8_t drawableId; 69 | uint8_t textureId; 70 | uint8_t paletteId; 71 | }; 72 | 73 | struct headBlend_t 74 | { 75 | uint8_t m_shape[3]; 76 | uint8_t m_skin[3]; 77 | float m_shapeMix; 78 | float m_skinMix; 79 | float m_thirdMix; 80 | }; 81 | 82 | struct propData_t 83 | { 84 | uint8_t drawableId; 85 | uint8_t textureId; 86 | }; 87 | 88 | struct arg_t 89 | { 90 | public: 91 | enum class val_t : uint8_t 92 | { 93 | Int, 94 | Float, 95 | String, 96 | Boolean, 97 | Vector3, 98 | Object, 99 | Null, 100 | 101 | Entity 102 | }; 103 | 104 | arg_t() : type(val_t::Null), v{} { } 105 | arg_t(bool b) : type(val_t::Boolean), v { b } { } 106 | arg_t(int i) : type(val_t::Int), v { i } { } 107 | arg_t(float f) : type(val_t::Float), v { f } { } 108 | arg_t(const std::string& str) : type(val_t::String), v { new char[str.length() + 1] } { memcpy(v.str, str.c_str(), str.length()); v.str[str.length()] = 0; } 109 | arg_t(entity_t entityType, entityId_t id, rage::IEntity *entity) : type(val_t::Entity), v{ entityType, id, entity } { } 110 | arg_t(const arg_t& r) : type(val_t::Null) { *this = r; } 111 | 112 | void SetNull() { DeleteString(); type = val_t::Null; } 113 | void SetBoolean(bool b) { DeleteString(); type = val_t::Boolean; v.b = b; } 114 | void SetInteger(int i) { DeleteString(); type = val_t::Int; v.i = i; } 115 | void SetFloat(float f) { DeleteString(); type = val_t::Float; v.f = f; } 116 | void SetString(const std::string& str) { DeleteString(); type = val_t::String; v.str = new char[str.length() + 1]; memcpy(v.str, str.c_str(), str.length()); v.str[str.length()] = 0; } 117 | void SetJson(const std::string& str) { DeleteString(); type = val_t::Object; v.str = new char[str.length() + 1]; memcpy(v.str, str.c_str(), str.length()); v.str[str.length()] = 0; } 118 | void SetEntity(entity_t entityType, entityId_t id, IEntity *entity) { DeleteString(); type = val_t::Entity; v.entity = { entityType, id, entity }; } 119 | void SetVector3(const vector3& vec) { DeleteString(); type = val_t::Vector3; v.vector = vec; } 120 | 121 | val_t GetType() const { return type; } 122 | bool IsNull() const { return type == val_t::Null; } 123 | bool IsBoolean() const { return type == val_t::Boolean; } 124 | bool IsInt() const { return type == val_t::Int; } 125 | bool IsFloat() const { return type == val_t::Float; } 126 | bool IsString() const { return type == val_t::String; } 127 | bool IsEntity() const { return type == val_t::Entity; } 128 | 129 | bool Boolean() const { return (type == val_t::Boolean) ? v.b : false; } 130 | int Int() const { return (type == val_t::Int) ? v.i : 0; } 131 | float Float() const { return (type == val_t::Float) ? v.f : 0.0f; } 132 | const char *String() const { return (type == val_t::String && v.str) ? v.str : ""; } 133 | const char *Object() const { return (type == val_t::Object && v.str) ? v.str : ""; } 134 | const vector3& Vector3() const { if (type == val_t::Vector3) { return v.vector; } else { static vector3 ret; return ret; } } 135 | 136 | rage::IEntity *Entity() const { return (type == val_t::Entity) ? v.entity.ptr : nullptr; } 137 | entityId_t EntityId() const { return (type == val_t::Entity) ? v.entity.id : 0xFFFF; } 138 | entity_t EntityType() const { return (type == val_t::Entity) ? v.entity.type : static_cast(-1); } 139 | 140 | arg_t& operator=(const arg_t& r) { DeleteString(); if (r.GetType() != val_t::String) { this->v.entity = r.v.entity; type = r.GetType(); } else { this->SetString(r.String()); } return *this; } 141 | arg_t& operator=(arg_t&& r) { DeleteString(); this->v.str = r.v.str; type = r.GetType(); r.type = val_t::Null; r.v.str = nullptr; return *this; } 142 | 143 | ~arg_t() { DeleteString(); } 144 | 145 | private: 146 | bool OwnsAString() { return (type == val_t::Object || type == val_t::String); } 147 | void DeleteString() { if (this->OwnsAString() && v.str) { delete[] v.str; v.str = nullptr; } } 148 | 149 | union _Value 150 | { 151 | bool b; 152 | int i; 153 | float f; 154 | char *str; 155 | 156 | vector3 vector; 157 | 158 | struct _EntityData 159 | { 160 | entity_t type; 161 | entityId_t id; 162 | 163 | IEntity *ptr; 164 | } entity; 165 | 166 | _Value() { memset(this, 0, sizeof(_Value)); } 167 | _Value(bool _b) : b { _b } { } 168 | _Value(int _i) : i { _i } { } 169 | _Value(float _f) : f { _f } { } 170 | _Value(char *_str) : str{ _str } { } 171 | _Value(const vector3& _vec) : vector{ _vec } { } 172 | _Value(entity_t entityType, entityId_t id, IEntity *ptr) : entity{ entityType, id, ptr } { } 173 | } v; 174 | 175 | val_t type; 176 | }; 177 | #pragma pack(pop) 178 | 179 | struct args_t 180 | { 181 | public: 182 | args_t(arg_t *data, size_t len) 183 | : m_data(data), m_len(len) { } 184 | 185 | size_t Length() const { return this->m_len; } 186 | const arg_t& operator[](size_t id) const { if (id >= this->m_len) { static arg_t ar{}; return ar; } return this->m_data[id]; } 187 | 188 | auto begin() const { return m_data; } 189 | auto end() const { return &m_data[this->m_len]; } 190 | 191 | private: 192 | size_t m_len; 193 | arg_t *m_data; 194 | }; 195 | 196 | class IEntity 197 | { 198 | public: 199 | virtual entityId_t GetId() = 0; 200 | virtual entity_t GetType() = 0; 201 | 202 | virtual void Destroy() = 0; 203 | 204 | virtual dimensionId_t GetDimension() = 0; 205 | virtual void SetDimension(dimensionId_t dimension) = 0; 206 | 207 | virtual const vector3& GetPosition() = 0; 208 | virtual void SetPosition(const vector3& pos) = 0; 209 | 210 | virtual const vector3& GetRotation() = 0; 211 | virtual void SetRotation(const vector3& rot) = 0; 212 | 213 | virtual uint32_t GetModel() = 0; 214 | virtual void SetModel(uint32_t model) = 0; 215 | 216 | virtual const vector3& GetVelocity() = 0; 217 | 218 | virtual uint8_t GetAlpha() = 0; 219 | virtual void SetAlpha(uint8_t alpha) = 0; 220 | 221 | private: 222 | virtual void* GetExternalValue() = 0; 223 | virtual void SetExternalValue(void *val) = 0; 224 | 225 | public: 226 | // todo 227 | 228 | public: 229 | template 230 | T* External() { return reinterpret_cast(this->GetExternalValue()); } 231 | 232 | template 233 | void External(T *val) { this->SetExternalValue(reinterpret_cast(val)); } 234 | 235 | virtual const arg_t& GetVariable(const std::string& key) = 0; 236 | virtual void SetVariable(const std::string& key, const arg_t& arg) = 0; 237 | virtual void SetVariables(const std::vector>& vars) = 0; 238 | virtual bool HasVariable(const std::string& key) = 0; 239 | }; 240 | 241 | template 242 | class IPool 243 | { 244 | private: 245 | virtual const T** Data() const = 0; 246 | public: 247 | virtual T *GetAt(entityId_t id) const = 0; 248 | virtual entityId_t Length() const = 0; 249 | virtual entityId_t Count() const = 0; 250 | 251 | virtual std::vector GetInRange(vector3 position, float range, dimensionId_t dimension = 0xFFFFFFFF) const = 0; 252 | virtual std::vector GetInDimension(dimensionId_t dimension) const = 0; 253 | 254 | class iterator 255 | { 256 | public: 257 | typedef iterator self_type; 258 | typedef T* value_type; 259 | typedef T*& reference; 260 | typedef T** pointer; 261 | typedef std::forward_iterator_tag iterator_category; 262 | typedef int difference_type; 263 | iterator(pointer ptr, uint32_t rest) : ptr_(ptr), rest_(rest - 1) { if (*ptr == nullptr) while (*(++ptr_) == nullptr && --rest_ != -1); } 264 | self_type operator++() { self_type i = *this; while (*(++ptr_) == nullptr && --rest_ != -1); return i; } 265 | self_type operator++(int junk) { while (*(++ptr_) == nullptr && --rest_ != -1); return *this; } 266 | reference operator*() { return *ptr_; } 267 | pointer operator->() { return ptr_; } 268 | bool operator==(const self_type& rhs) { return rest_ == -1 ? false : ptr_ == rhs.ptr_; } 269 | bool operator!=(const self_type& rhs) { return rest_ == -1 ? false : ptr_ != rhs.ptr_; } 270 | auto operator-(const self_type& rhs) { return ptr_ - rhs.ptr_; } 271 | 272 | private: 273 | pointer ptr_; 274 | int32_t rest_; 275 | }; 276 | 277 | iterator begin() const 278 | { 279 | return iterator(const_cast(this->Data()), this->Length()); 280 | } 281 | 282 | iterator end() const 283 | { 284 | return iterator(const_cast(this->Data()) + this->Length(), 0); 285 | } 286 | 287 | T* operator[](entityId_t id) const { return this->GetAt(id); } 288 | // todo 289 | }; 290 | } 291 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, RAGE Multiplayer team (https://rage.mp) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /Pools.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Entities.hpp" 4 | 5 | namespace rage 6 | { 7 | class IPlayerPool 8 | : public IPool 9 | { 10 | public: 11 | virtual void Broadcast(const std::string& message) const = 0; 12 | virtual void BroadcastInRange(const std::string& message, const vector3& position, float range, dimensionId_t dimension = 0xFFFFFFFF) const = 0; 13 | virtual void BroadcastInDimension(const std::string& message, dimensionId_t dimension) const = 0; 14 | 15 | public: 16 | virtual void _Call(const std::string& eventName, const arg_t *arguments = nullptr, size_t count = 0) const = 0; 17 | virtual void _CallInRange(const vector3& position, float range, dimensionId_t dimension, const std::string& eventName, const arg_t *arguments = nullptr, size_t count = 0) const = 0; 18 | virtual void _CallInDimension(dimensionId_t dimension, const std::string& eventName, const arg_t *arguments = nullptr, size_t count = 0) const = 0; 19 | virtual void _CallFor(const std::vector& players, const std::string& eventName, const arg_t *arguments = nullptr, size_t count = 0) const = 0; 20 | 21 | virtual void _Call(uint64_t eventName, const rage::arg_t *arguments = nullptr, size_t count = 0) = 0; 22 | virtual void _CallInRange(const vector3& position, float range, dimensionId_t dimension, uint64_t eventName, const rage::arg_t *arguments = nullptr, size_t count = 0) = 0; 23 | virtual void _CallInDimension(dimensionId_t dimension, uint64_t eventName, const rage::arg_t *arguments = nullptr, size_t count = 0) = 0; 24 | virtual void _CallFor(const std::vector& players, uint64_t eventName, const arg_t *arguments = nullptr, size_t count = 0) = 0; 25 | 26 | virtual void _Invoke(uint64_t nativeHash, const arg_t *arguments = nullptr, size_t count = 0) const = 0; 27 | virtual void _InvokeInRange(const vector3& position, float range, dimensionId_t dimension, uint64_t nativeHash, const arg_t *arguments = nullptr, size_t count = 0) const = 0; 28 | virtual void _InvokeInDimension(dimensionId_t dimension, uint64_t nativeHash, const arg_t *arguments = nullptr, size_t count = 0) const = 0; 29 | virtual void _InvokeFor(const std::vector& players, uint64_t nativeHash, const arg_t *arguments = nullptr, size_t count = 0) const = 0; 30 | 31 | public: 32 | template 33 | void Call(const std::string& eventName, Args&&... args) 34 | { 35 | const int count = sizeof...(Args); 36 | 37 | if (count == 0) 38 | this->_Call(eventName); 39 | else 40 | { 41 | arg_t arguments[count] = { arg_t(std::forward(args))... }; 42 | this->_Call(eventName, arguments, count); 43 | } 44 | } 45 | 46 | template 47 | void CallInRange(const vector3& position, float range, dimensionId_t dimension, const std::string& eventName, Args&&... args) 48 | { 49 | const int count = sizeof...(Args); 50 | 51 | if (count == 0) 52 | this->_CallInRange(position, range, dimension, eventName); 53 | else 54 | { 55 | arg_t arguments[count] = { arg_t(std::forward(args))... }; 56 | this->_CallInRange(position, range, dimension, eventName, arguments, count); 57 | } 58 | } 59 | 60 | template 61 | void CallInDimension(dimensionId_t dimension, const std::string& eventName, Args&&... args) 62 | { 63 | const int count = sizeof...(Args); 64 | 65 | if (count == 0) 66 | this->_CallInDimension(dimension, eventName); 67 | else 68 | { 69 | arg_t arguments[count] = { arg_t(std::forward(args))... }; 70 | this->_CallInDimension(dimension, eventName, arguments, count); 71 | } 72 | } 73 | 74 | template 75 | void Invoke(uint64_t hash, Args&&... args) 76 | { 77 | const int count = sizeof...(Args); 78 | 79 | if (count == 0) 80 | this->_Invoke(hash); 81 | else 82 | { 83 | arg_t arguments[count] = { arg_t(std::forward(args))... }; 84 | this->_Invoke(hash, arguments, count); 85 | } 86 | } 87 | 88 | template 89 | void InvokeInRange(const vector3& position, float range, dimensionId_t dimension, uint64_t hash, Args&&... args) 90 | { 91 | const int count = sizeof...(Args); 92 | 93 | if (count == 0) 94 | this->_InvokeInRange(position, range, dimension, hash); 95 | else 96 | { 97 | arg_t arguments[count] = { arg_t(std::forward(args))... }; 98 | this->_InvokeInRange(position, range, dimension, hash, arguments, count); 99 | } 100 | } 101 | 102 | template 103 | void InvokeInDimension(dimensionId_t dimension, uint64_t hash, Args&&... args) 104 | { 105 | const int count = sizeof...(Args); 106 | 107 | if (count == 0) 108 | this->_InvokeInDimension(dimension, hash); 109 | else 110 | { 111 | arg_t arguments[count] = { arg_t(std::forward(args))... }; 112 | this->_InvokeInDimension(dimension, hash, arguments, count); 113 | } 114 | } 115 | }; 116 | 117 | class IVehiclePool 118 | : public IPool 119 | { 120 | public: 121 | virtual IVehicle *New(uint32_t model, const vector3& position, float heading = 0.f, const std::string& numberPlate = "", uint8_t alpha = 255, bool locked = false, bool engine = false, dimensionId_t dimension = 0) const = 0; 122 | }; 123 | 124 | class IColshapePool 125 | : public IPool 126 | { 127 | public: 128 | virtual IColshape *NewCircle(const vector2& position, float radius, dimensionId_t dimension = 0) const = 0; 129 | virtual IColshape *NewSphere(const vector3& position, float radius, dimensionId_t dimension = 0) const = 0; 130 | virtual IColshape *NewTube(const vector3& position, float radius, float height, dimensionId_t dimension = 0) const = 0; 131 | virtual IColshape *NewRectangle(const vector2& position, const vector2& size, dimensionId_t dimension = 0) const = 0; 132 | virtual IColshape *NewCube(const vector3& position, const vector3& size, dimensionId_t dimension = 0) const = 0; 133 | }; 134 | 135 | class ICheckpointPool 136 | : public IPool 137 | { 138 | public: 139 | virtual ICheckpoint *New(uint8_t type, const vector3& position, const vector3& nextPos, float radius, const rgba_t color, bool visible = true, dimensionId_t dimension = 0) const = 0; 140 | }; 141 | 142 | class IMarkerPool 143 | : public IPool 144 | { 145 | public: 146 | virtual IMarker *New(uint32_t model, const vector3& position, const vector3& rotation, const vector3& direction, float scale, rage::rgba_t color, bool visible = true, dimensionId_t dimension = 0) const = 0; 147 | }; 148 | 149 | class IBlipPool 150 | : public IPool 151 | { 152 | public: 153 | virtual IBlip *New(uint32_t sprite, const vector3& position, float scale, uint8_t color, const std::string& name = "", uint8_t alpha = 255, float drawDistance = 0.f, bool shortRange = false, short rotation = 0, dimensionId_t dimension = 0) const = 0; 154 | }; 155 | 156 | class IPickupPool 157 | : public IPool 158 | { 159 | public: 160 | // todo 161 | }; 162 | 163 | class IObjectPool 164 | : public IPool 165 | { 166 | public: 167 | virtual IObject *New(uint32_t model, const vector3& position, const vector3& rotation, dimensionId_t dimension = 0) const = 0; 168 | }; 169 | 170 | class ITextLabelPool 171 | : public IPool 172 | { 173 | public: 174 | virtual ITextLabel *New(const vector3& pos, const std::string& text, uint8_t fontId, rage::rgba_t color, float drawDistance = 150.f, bool los = false, dimensionId_t dimension = 0) const = 0; 175 | }; 176 | } 177 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.0.2 ) 2 | project( shared_lib CXX ) 3 | set( SOURCE_LIB example.cpp ) 4 | add_library( example SHARED ${SOURCE_LIB} ) 5 | add_compile_options( -std=gnu++1y -lstdc++ -fPIC) 6 | -------------------------------------------------------------------------------- /examples/example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../rage.hpp" 4 | 5 | namespace gm 6 | { 7 | class EventHandler 8 | : public rage::IEventHandler, 9 | public rage::IPlayerHandler, 10 | public rage::ITickHandler 11 | { 12 | public: 13 | virtual rage::ITickHandler *GetTickHandler() { return this; } 14 | virtual rage::IPlayerHandler *GetPlayerHandler() { return this; } 15 | 16 | virtual void OnPlayerJoin(rage::IPlayer *player) { std::cout << "Player: " << player->GetId() << std::endl; } 17 | 18 | virtual void Tick() { std::cout << "tick!!!!" << std::endl; } 19 | }; 20 | } 21 | 22 | RAGE_API rage::IPlugin *InitializePlugin(rage::IMultiplayer *mp) 23 | { 24 | mp->AddEventHandler(new gm::EventHandler); 25 | return new rage::IPlugin; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /rage.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "Entity.hpp" 15 | 16 | #include "Pools.hpp" 17 | 18 | #ifdef _WIN32 19 | #define RAGE_API extern "C" __declspec(dllexport) 20 | #else 21 | #define RAGE_API extern "C" 22 | #endif 23 | 24 | namespace rage 25 | { 26 | using removeEventHandler_t = std::function; 27 | 28 | struct time_t 29 | { 30 | union 31 | { 32 | struct 33 | { 34 | uint8_t hour; 35 | uint8_t minute; 36 | uint8_t second; 37 | } a; 38 | uint32_t i; 39 | }; 40 | }; 41 | 42 | class IPlugin 43 | { 44 | public: 45 | static constexpr int sdkver = 0; 46 | 47 | virtual uint32_t GetVersion() { return sdkver; } 48 | virtual void Unload() { } 49 | }; 50 | 51 | class IEntityHandler; 52 | class IPlayerHandler; 53 | class IVehicleHandler; 54 | class IColshapeHandler; 55 | class ICheckpointHandler; 56 | /*class IMarkerHandler; 57 | class IPickupHandler;*/ 58 | class IBlipHandler; 59 | class IStreamerHandler; 60 | class ITickHandler; 61 | 62 | class IEventHandler 63 | { 64 | public: 65 | virtual IEntityHandler *GetEntityHandler() { return nullptr; } 66 | virtual IPlayerHandler *GetPlayerHandler() { return nullptr; } 67 | virtual IVehicleHandler *GetVehicleHandler() { return nullptr; } 68 | virtual IColshapeHandler *GetColshapeHandler() { return nullptr; } 69 | virtual ICheckpointHandler *GetCheckpointHandler() { return nullptr; } 70 | /*virtual IMarkerHandler *GetMarkerHandler() { return nullptr; } 71 | virtual IPickupHandler *GetPickupHandler() { return nullptr; }*/ 72 | virtual IBlipHandler *GetBlipHandler() { return nullptr; } 73 | virtual IStreamerHandler *GetStreamerHandler() { return nullptr; } 74 | virtual ITickHandler *GetTickHandler() { return nullptr; } 75 | }; 76 | 77 | class IEntityHandler 78 | { 79 | public: 80 | virtual void OnEntityCreated(IEntity *entity) { } 81 | virtual void OnEntityDestroyed(IEntity *entity) { } 82 | virtual void OnEntityModelChange(IEntity *entity, hash_t oldModel) { } 83 | }; 84 | 85 | enum class exit_t : uint8_t 86 | { 87 | disconnect, 88 | timeout, 89 | kicked 90 | }; 91 | 92 | class IPlayerHandler 93 | { 94 | public: 95 | virtual void OnPlayerJoin(IPlayer *player) { } 96 | virtual void OnPlayerReady(IPlayer *player) { } 97 | virtual void OnPlayerQuit(IPlayer *player, exit_t exitType, const char *reason) { } 98 | 99 | virtual void OnPlayerCommand(IPlayer *player, const std::u16string& command) { } 100 | virtual void OnPlayerChat(IPlayer *player, const std::u16string& text) { } 101 | 102 | virtual void OnPlayerDeath(IPlayer *player, hash_t reason, IPlayer *killer) { } 103 | virtual void OnPlayerSpawn(IPlayer *player) { } 104 | virtual void OnPlayerDamage(IPlayer *player, float healthLoss, float armorLoss) { } 105 | virtual void OnPlayerWeaponChange(IPlayer *player, hash_t oldWeapon, hash_t newWeapon) { } 106 | 107 | virtual void OnPlayerRemoteEvent(IPlayer *player, uint64_t eventNameHash, const args_t& args) { } // xxhash64 108 | 109 | virtual void OnPlayerStartEnterVehicle(IPlayer *player, IVehicle *vehicle, uint8_t seatId) { } 110 | virtual void OnPlayerEnterVehicle(IPlayer *player, IVehicle *vehicle, uint8_t seatId) { } 111 | virtual void OnPlayerStartExitVehicle(IPlayer *player, IVehicle *vehicle) { } 112 | virtual void OnPlayerExitVehicle(IPlayer *player, IVehicle *vehicle) { } 113 | }; 114 | 115 | class IVehicleHandler 116 | { 117 | public: 118 | virtual void OnVehicleDeath(IVehicle *vehicle, hash_t hash, IPlayer *killer) { } 119 | virtual void OnVehicleSirenToggle(IVehicle *vehicle, bool toggle) { } 120 | virtual void OnVehicleHornToggle(IVehicle *vehicle, bool toggle) { } 121 | virtual void OnTrailerAttached(IVehicle *vehicle, IVehicle *trailer) { } 122 | virtual void OnVehicleDamage(IVehicle *vehicle, float bodyHealthLoss, float engineHealthLoss) { } 123 | }; 124 | 125 | class IColshapeHandler 126 | { 127 | public: 128 | virtual void OnPlayerEnterColshape(IPlayer *player, IColshape *colshape) { } 129 | virtual void OnPlayerExitColshape(IPlayer *player, IColshape *colshape) { } 130 | }; 131 | 132 | class ICheckpointHandler 133 | { 134 | public: 135 | virtual void OnPlayerEnterCheckpoint(IPlayer *player, ICheckpoint *checkpoint) { } 136 | virtual void OnPlayerExitCheckpoint(IPlayer *player, ICheckpoint *checkpoint) { } 137 | }; 138 | 139 | /*class IMarkerHandler 140 | { 141 | public: 142 | }; 143 | 144 | class IPickupHandler 145 | { 146 | public: 147 | };*/ 148 | 149 | class IBlipHandler 150 | { 151 | public: 152 | virtual void OnPlayerCreateWaypoint(rage::IPlayer *player, const vector3& position) { } 153 | virtual void OnPlayerReachWaypoint(rage::IPlayer *player) { } 154 | }; 155 | 156 | class IStreamerHandler 157 | { 158 | public: 159 | virtual void OnPlayerStreamIn(IPlayer *player, IPlayer *forplayer) { } 160 | virtual void OnPlayerStreamOut(IPlayer *player, IPlayer *forplayer) { } 161 | }; 162 | 163 | class ITickHandler 164 | { 165 | public: 166 | virtual void Tick() { } 167 | }; 168 | 169 | class IWorld 170 | { 171 | public: 172 | virtual time_t GetTime() = 0; 173 | virtual void SetTime(time_t time) = 0; 174 | virtual const std::string& GetWeather() = 0; 175 | virtual void SetWeather(const std::string& weather) = 0; 176 | virtual void SetWeatherTransition(const std::string& weather, float time = 0.5f) = 0; 177 | 178 | virtual void RequestIpl(const std::string& ipl) = 0; 179 | virtual void RemoveIpl(const std::string& ipl) = 0; 180 | 181 | virtual bool AreTrafficLightsLocked() = 0; 182 | virtual void LockTrafficLights(bool toggle) = 0; 183 | 184 | virtual int GetTrafficLightsState() = 0; 185 | virtual void SetTrafficLightsState(int state) = 0; 186 | }; 187 | 188 | class IConfig 189 | { 190 | public: 191 | virtual int GetInt(const std::string& key, int def = 0) = 0; 192 | virtual std::string GetString(const std::string& key, const std::string& def = "") = 0; 193 | }; 194 | 195 | class IMultiplayer 196 | { 197 | public: 198 | virtual void AddEventHandler(IEventHandler *handler) = 0; 199 | 200 | virtual void AddRemoteEventHandler(const std::string& eventName, removeEventHandler_t handler) = 0; 201 | 202 | virtual IPlayerPool& GetPlayerPool() = 0; 203 | virtual IVehiclePool& GetVehiclePool() = 0; 204 | virtual IColshapePool& GetColshapePool() = 0; 205 | virtual ICheckpointPool& GetCheckpointPool() = 0; 206 | virtual IMarkerPool& GetMarkerPool() = 0; 207 | virtual IBlipPool& GetBlipPool() = 0; 208 | virtual IPickupPool& GetPickupPool() = 0; 209 | virtual IObjectPool& GetObjectPool() = 0; 210 | virtual ITextLabelPool& GetLabelPool() = 0; 211 | virtual IWorld& GetWorld() = 0; 212 | virtual IConfig& GetConfig() = 0; 213 | }; 214 | 215 | 216 | using initializeFunc_t = IPlugin*( 217 | #ifdef _WIN32 218 | __cdecl 219 | #endif 220 | *) (IMultiplayer *multiplayer); 221 | } 222 | --------------------------------------------------------------------------------