From aa7db534ca34299260034649e6e0ff1e62e49a98 Mon Sep 17 00:00:00 2001 From: Yauhen Pahrabniak Date: Mon, 18 Sep 2023 17:02:24 +0200 Subject: [PATCH 01/14] cpp-sdk update --- cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-sdk b/cpp-sdk index 22c74ce..d5ad9b4 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit 22c74ce2dc45891de76ed80ba37ee9628f0c56b3 +Subproject commit d5ad9b4eaf2a1b31cd2be20ebdfe576bc13b9187 From 2f23b953ac720c3cc35e06e18f76d98210d77f83 Mon Sep 17 00:00:00 2001 From: Kiwi <40145372+KiwisKiwi@users.noreply.github.com> Date: Tue, 19 Sep 2023 09:38:44 +0200 Subject: [PATCH 02/14] added give ped scripted task event (#150) * added give ped scripted task event * updated cpp-sdk --- server/include/CSharpResourceImpl.h | 8 +++++++- server/src/CSharpResourceImpl.cpp | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/server/include/CSharpResourceImpl.h b/server/include/CSharpResourceImpl.h index 0e7a614..85e1e70 100644 --- a/server/include/CSharpResourceImpl.h +++ b/server/include/CSharpResourceImpl.h @@ -195,6 +195,8 @@ typedef void (* ClientDeleteObjectDelegate_t)(const alt::CEvent* event, alt::IPl typedef void (* PlayerHealDelegate_t)(alt::IPlayer* target, uint16_t oldHealth, uint16_t newHealth, uint16_t oldArmour, uint16_t newArmour); +typedef void (* GivePedScriptedTaskDelegate_t)(alt::IPlayer* source, alt::IPed* target, int32_t taskType); + class CSharpResourceImpl : public alt::IResource::Impl { void OnEvent(const alt::CEvent* ev) override; @@ -328,6 +330,8 @@ class CSharpResourceImpl : public alt::IResource::Impl { PlayerHealDelegate_t OnPlayerHealDelegate = nullptr; + GivePedScriptedTaskDelegate_t OnGivePedScriptedTaskDelegate = nullptr; + std::vector invokers; std::mutex invokersLock = {}; CoreClr* coreClr; @@ -536,4 +540,6 @@ EXPORT void CSharpResourceImpl_SetClientRequestObjectDelegate(CSharpResourceImpl EXPORT void CSharpResourceImpl_SetClientDeleteObjectDelegate(CSharpResourceImpl* resource, ClientDeleteObjectDelegate_t delegate); -EXPORT void CSharpResourceImpl_SetPlayerHealDelegate(CSharpResourceImpl* resource, PlayerHealDelegate_t delegate); \ No newline at end of file +EXPORT void CSharpResourceImpl_SetPlayerHealDelegate(CSharpResourceImpl* resource, PlayerHealDelegate_t delegate); + +EXPORT void CSharpResourceImpl_SetGivePedScriptedTaskDelegate(CSharpResourceImpl* resource, GivePedScriptedTaskDelegate_t delegate); \ No newline at end of file diff --git a/server/src/CSharpResourceImpl.cpp b/server/src/CSharpResourceImpl.cpp index b367f10..20eaa8e 100644 --- a/server/src/CSharpResourceImpl.cpp +++ b/server/src/CSharpResourceImpl.cpp @@ -70,6 +70,8 @@ void CSharpResourceImpl::ResetDelegates() OnClientDeleteObjectDelegate = [](auto var, auto var2) {}; OnPlayerHealDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5) {}; + + OnGivePedScriptedTaskDelegate = [](auto var, auto var2, auto var3) {}; } bool CSharpResourceImpl::Start() @@ -743,6 +745,20 @@ case alt::CEvent::Type::SYNCED_META_CHANGE: playerHealEvent->GetNewArmour()); break; } + case alt::CEvent::Type::GIVE_PED_SCRIPTED_TASK: + { + auto givePedScriptedTaskEvent = dynamic_cast(ev); + + auto target = givePedScriptedTaskEvent->GetTarget(); + auto source = givePedScriptedTaskEvent->GetSource(); + + if (target == nullptr) return; + if (source == nullptr) return; + + OnGivePedScriptedTaskDelegate(source, target, givePedScriptedTaskEvent->GetTaskType()); + + break; + } default: { std::cout << "Unhandled server event #" << static_cast(ev->GetType()) << " got called" << std::endl; @@ -1253,6 +1269,11 @@ void CSharpResourceImpl_SetPlayerHealDelegate(CSharpResourceImpl* resource, Play resource->OnPlayerHealDelegate = delegate; } +void CSharpResourceImpl_SetGivePedScriptedTaskDelegate(CSharpResourceImpl* resource, GivePedScriptedTaskDelegate_t delegate) +{ + resource->OnGivePedScriptedTaskDelegate = delegate; +} + bool CSharpResourceImpl::MakeClient(alt::IResource::CreationInfo* info, std::vector files) { const std::string clientMain = resource->GetClientMain(); From 4130cbdf4df24a7fdad2ae444864abdddf083452 Mon Sep 17 00:00:00 2001 From: doxoh Date: Tue, 19 Sep 2023 09:49:39 +0200 Subject: [PATCH 03/14] fix OnGivePedScriptedTaskDelegate --- server/include/CSharpResourceImpl.h | 4 ++-- server/src/CSharpResourceImpl.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/include/CSharpResourceImpl.h b/server/include/CSharpResourceImpl.h index 85e1e70..cf7d3a6 100644 --- a/server/include/CSharpResourceImpl.h +++ b/server/include/CSharpResourceImpl.h @@ -195,7 +195,7 @@ typedef void (* ClientDeleteObjectDelegate_t)(const alt::CEvent* event, alt::IPl typedef void (* PlayerHealDelegate_t)(alt::IPlayer* target, uint16_t oldHealth, uint16_t newHealth, uint16_t oldArmour, uint16_t newArmour); -typedef void (* GivePedScriptedTaskDelegate_t)(alt::IPlayer* source, alt::IPed* target, int32_t taskType); +typedef void (* GivePedScriptedTaskDelegate_t)(const alt::CEvent* event, alt::IPlayer* source, alt::IPed* target, int32_t taskType); class CSharpResourceImpl : public alt::IResource::Impl { void OnEvent(const alt::CEvent* ev) override; @@ -540,6 +540,6 @@ EXPORT void CSharpResourceImpl_SetClientRequestObjectDelegate(CSharpResourceImpl EXPORT void CSharpResourceImpl_SetClientDeleteObjectDelegate(CSharpResourceImpl* resource, ClientDeleteObjectDelegate_t delegate); -EXPORT void CSharpResourceImpl_SetPlayerHealDelegate(CSharpResourceImpl* resource, PlayerHealDelegate_t delegate); +EXPORT void CSharpResourceImpl_SetPlayerHealDelegate(CSharpResourceImpl* resource, PlayerHealDelegate_t delegate); EXPORT void CSharpResourceImpl_SetGivePedScriptedTaskDelegate(CSharpResourceImpl* resource, GivePedScriptedTaskDelegate_t delegate); \ No newline at end of file diff --git a/server/src/CSharpResourceImpl.cpp b/server/src/CSharpResourceImpl.cpp index 20eaa8e..e8f27f0 100644 --- a/server/src/CSharpResourceImpl.cpp +++ b/server/src/CSharpResourceImpl.cpp @@ -71,7 +71,7 @@ void CSharpResourceImpl::ResetDelegates() OnPlayerHealDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5) {}; - OnGivePedScriptedTaskDelegate = [](auto var, auto var2, auto var3) {}; + OnGivePedScriptedTaskDelegate = [](auto var, auto var2, auto var3, auto var4) {}; } bool CSharpResourceImpl::Start() @@ -755,7 +755,7 @@ case alt::CEvent::Type::SYNCED_META_CHANGE: if (target == nullptr) return; if (source == nullptr) return; - OnGivePedScriptedTaskDelegate(source, target, givePedScriptedTaskEvent->GetTaskType()); + OnGivePedScriptedTaskDelegate(givePedScriptedTaskEvent, source, target, givePedScriptedTaskEvent->GetTaskType()); break; } From bcd23a30bdf3b55d547f95a0b0ac8f10e5f91969 Mon Sep 17 00:00:00 2001 From: doxoh Date: Tue, 19 Sep 2023 09:49:50 +0200 Subject: [PATCH 04/14] update to latest sdk --- c-api/core.cpp | 8 +++--- c-api/core.h | 2 +- c-api/data/vehicle_model_info.h | 43 ++++++++++++++++++--------------- c-api/func_table.cpp | 4 +-- cpp-sdk | 2 +- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/c-api/core.cpp b/c-api/core.cpp index 1412ecc..5c50759 100644 --- a/c-api/core.cpp +++ b/c-api/core.cpp @@ -468,6 +468,10 @@ alt::IColShape* Core_CreateColShapePolygon(alt::ICore* core, float minZ, float m return colShape; } +int32_t Core_GetNetTime(alt::ICore* core) { + return core->GetNetTime(); +} + #ifdef ALT_SERVER_API uint8_t Core_SubscribeCommand(alt::ICore* core, const char* cmd, alt::CommandCallback cb) { return core->SubscribeCommand(cmd, cb); @@ -685,10 +689,6 @@ void Core_DestroyColShape(alt::ICore* core, alt::IColShape* baseObject) { return core->DestroyBaseObject(baseObject); } -int32_t Core_GetNetTime(alt::ICore* core) { - return core->GetNetTime(); -} - const char* Core_GetRootDirectory(alt::ICore* core, int32_t& size) { return AllocateString(core->GetRootDirectory(), size); } diff --git a/c-api/core.h b/c-api/core.h index 46779fa..48e4513 100644 --- a/c-api/core.h +++ b/c-api/core.h @@ -114,7 +114,7 @@ EXPORT_SERVER void Core_DestroyVehicle(alt::ICore* server, alt::IVehicle* baseOb EXPORT_SERVER void Core_DestroyCheckpoint(alt::ICore* server, alt::ICheckpoint* baseObject); EXPORT_SERVER void Core_DestroyVoiceChannel(alt::ICore* server, alt::IVoiceChannel* baseObject); EXPORT_SERVER void Core_DestroyColShape(alt::ICore* server, alt::IColShape* baseObject); -EXPORT_SERVER int32_t Core_GetNetTime(alt::ICore* server); +EXPORT_SHARED int32_t Core_GetNetTime(alt::ICore* server); EXPORT_SERVER const char* Core_GetRootDirectory(alt::ICore* server, int32_t& size); EXPORT_SERVER void Core_StartResource(alt::ICore* server, const char* text); EXPORT_SERVER void Core_StopResource(alt::ICore* server, const char* text); diff --git a/c-api/data/vehicle_model_info.h b/c-api/data/vehicle_model_info.h index c8fe491..84560f3 100644 --- a/c-api/data/vehicle_model_info.h +++ b/c-api/data/vehicle_model_info.h @@ -3,7 +3,8 @@ #include "cpp-sdk/ICore.h" #include "bone_info.h" -struct ClrVehicleModelInfo { +struct ClrVehicleModelInfo +{ char* title = nullptr; alt::VehicleModelInfo::Type modelType; uint8_t wheelsCount; @@ -24,26 +25,28 @@ struct ClrVehicleModelInfo { uint32_t boneSize; uint8_t canAttachCars; + uint32_t handlingNameHash; ClrVehicleModelInfo() = default; ClrVehicleModelInfo(alt::VehicleModelInfo info) : - modelType(info.modelType), - wheelsCount(info.wheelsCount), - hasArmoredWindows(info.hasArmoredWindows), - primaryColor(info.primaryColor), - secondaryColor(info.secondaryColor), - pearlColor(info.pearlColor), - wheelsColor(info.wheelsColor), - interiorColor(info.interiorColor), - dashboardColor(info.dashboardColor), - extras(info.extras), - defaultExtras(info.defaultExtras), - hasAutoAttachTrailer(info.hasAutoAttachTrailer), - canAttachCars(info.canAttachCars){ - + modelType(info.modelType), + wheelsCount(info.wheelsCount), + hasArmoredWindows(info.hasArmoredWindows), + primaryColor(info.primaryColor), + secondaryColor(info.secondaryColor), + pearlColor(info.pearlColor), + wheelsColor(info.wheelsColor), + interiorColor(info.interiorColor), + dashboardColor(info.dashboardColor), + extras(info.extras), + defaultExtras(info.defaultExtras), + hasAutoAttachTrailer(info.hasAutoAttachTrailer), + canAttachCars(info.canAttachCars), + handlingNameHash(info.handlingNameHash) + { size_t modkitsSize = std::size(info.modkits); - for(size_t i = 0; i < modkitsSize; i++) + for (size_t i = 0; i < modkitsSize; i++) { modkits[i] = info.modkits[i] != 0xFFFF; } @@ -54,12 +57,14 @@ struct ClrVehicleModelInfo { const auto vehModelBones = info.bones; boneSize = vehModelBones.size(); bones = new ClrBoneInfo[boneSize]; - for (uint32_t i = 0; i < boneSize; i++) { + for (uint32_t i = 0; i < boneSize; i++) + { bones[i] = ClrBoneInfo(vehModelBones[i]); } } - ~ClrVehicleModelInfo() { + ~ClrVehicleModelInfo() + { delete[] title; } -}; \ No newline at end of file +}; diff --git a/c-api/func_table.cpp b/c-api/func_table.cpp index 22deb47..020a425 100644 --- a/c-api/func_table.cpp +++ b/c-api/func_table.cpp @@ -1052,6 +1052,7 @@ inline uint64_t capiHashes[] = { 6921054663232355759UL, 7482854450085275693UL, 2139798095052897524UL, + 15652019729912249391UL, 8454955647873390265UL, 5411021830103603795UL, 6799731000550763773UL, @@ -1332,7 +1333,6 @@ inline uint64_t capiHashes[] = { 8442828755754917489UL, 5757616980701278724UL, 9990683150417934189UL, - 15652019729912249391UL, 7718568480211772772UL, 12125306445698504265UL, 14723504540957489106UL, @@ -2775,6 +2775,7 @@ inline void* capiPointers[] = { (void*) Core_GetEventEnumSize, (void*) Core_GetMarkers, (void*) Core_GetMetaData, + (void*) Core_GetNetTime, (void*) Core_GetNetworkObjects, (void*) Core_GetPeds, (void*) Core_GetPlayers, @@ -3055,7 +3056,6 @@ inline void* capiPointers[] = { (void*) Core_GetMigrationDistance, (void*) Core_GetMigrationThreadCount, (void*) Core_GetMigrationTickRate, - (void*) Core_GetNetTime, (void*) Core_GetPedModelInfo, (void*) Core_GetRootDirectory, (void*) Core_GetServerConfig, diff --git a/cpp-sdk b/cpp-sdk index d5ad9b4..c6cb971 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit d5ad9b4eaf2a1b31cd2be20ebdfe576bc13b9187 +Subproject commit c6cb971264871a6826062c9c1fa7983214872cf7 From 1c4e19fdc3dd9c7eb94c541c32aae702fb58e262 Mon Sep 17 00:00:00 2001 From: doxoh Date: Tue, 19 Sep 2023 11:38:29 +0200 Subject: [PATCH 05/14] change CGivePedScriptedTaskEvent taskType to uint32_t --- cpp-sdk | 2 +- server/include/CSharpResourceImpl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp-sdk b/cpp-sdk index c6cb971..957a076 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit c6cb971264871a6826062c9c1fa7983214872cf7 +Subproject commit 957a076008ec5fcf28670da0e7466c0fbfcc5846 diff --git a/server/include/CSharpResourceImpl.h b/server/include/CSharpResourceImpl.h index cf7d3a6..ec1f8e4 100644 --- a/server/include/CSharpResourceImpl.h +++ b/server/include/CSharpResourceImpl.h @@ -195,7 +195,7 @@ typedef void (* ClientDeleteObjectDelegate_t)(const alt::CEvent* event, alt::IPl typedef void (* PlayerHealDelegate_t)(alt::IPlayer* target, uint16_t oldHealth, uint16_t newHealth, uint16_t oldArmour, uint16_t newArmour); -typedef void (* GivePedScriptedTaskDelegate_t)(const alt::CEvent* event, alt::IPlayer* source, alt::IPed* target, int32_t taskType); +typedef void (* GivePedScriptedTaskDelegate_t)(const alt::CEvent* event, alt::IPlayer* source, alt::IPed* target, uint32_t taskType); class CSharpResourceImpl : public alt::IResource::Impl { void OnEvent(const alt::CEvent* ev) override; From 721b4a913258f72415f4093918ceb0e71419feb1 Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 21 Sep 2023 14:09:22 +0200 Subject: [PATCH 06/14] task debug --- c-api/cache/CachedPlayer.h | 5 +++++ cpp-sdk | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/c-api/cache/CachedPlayer.h b/c-api/cache/CachedPlayer.h index 6d8ede7..687ef3c 100644 --- a/c-api/cache/CachedPlayer.h +++ b/c-api/cache/CachedPlayer.h @@ -599,6 +599,11 @@ namespace cache void RemoveFilter() override {} alt::IAudioFilter* GetFilter() const override { return nullptr; } + std::string _taskData; + std::string GetTaskData() const override { + return _taskData; + } + #endif }; diff --git a/cpp-sdk b/cpp-sdk index 957a076..0f3a3ee 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit 957a076008ec5fcf28670da0e7466c0fbfcc5846 +Subproject commit 0f3a3ee06926acca68a4304c387c7b8469f99441 From 460ad87357f4467c17599c8c6aefa3dc39416371 Mon Sep 17 00:00:00 2001 From: Artem Dzhemesiuk Date: Fri, 22 Sep 2023 17:03:43 +0200 Subject: [PATCH 07/14] SDK update --- cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-sdk b/cpp-sdk index 0f3a3ee..2e9be03 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit 0f3a3ee06926acca68a4304c387c7b8469f99441 +Subproject commit 2e9be033b8902c54779ea8b9da3d185b0771770a From 81c8e2e2659c0c9c9d96e40ba20ff46a3b3856d0 Mon Sep 17 00:00:00 2001 From: Artem Dzhemesiuk Date: Fri, 22 Sep 2023 17:57:00 +0200 Subject: [PATCH 08/14] Build fix --- c-api/cache/CachedPlayer.h | 76 +++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/c-api/cache/CachedPlayer.h b/c-api/cache/CachedPlayer.h index 6d8ede7..2d77435 100644 --- a/c-api/cache/CachedPlayer.h +++ b/c-api/cache/CachedPlayer.h @@ -14,40 +14,40 @@ namespace cache public: CachedPlayer(IPlayer* base) : CachedBaseObject(base), CachedWorldObject(base), CachedEntity(base), - _name(base->GetName()), - _health(base->GetHealth()), - _maxHealth(base->GetMaxHealth()), - _currentWeapon(base->GetCurrentWeapon()), - _dead(base->IsDead()), - _jumping(base->IsJumping()), - _inRagdoll(base->IsInRagdoll()), - _aiming(base->IsAiming()), - _shooting(base->IsShooting()), - _reloading(base->IsReloading()), - _enteringVehicle(base->IsEnteringVehicle()), - _leavingVehicle(base->IsLeavingVehicle()), - _onLadder(base->IsOnLadder()), - _inMelee(base->IsInMelee()), - _inCover(base->IsInCover()), - _armour(base->GetArmour()), - _maxArmour(base->GetMaxArmour()), - _moveSpeed(base->GetMoveSpeed()), - _aimPos(base->GetAimPos()), - _headRotation(base->GetHeadRotation()), - _inVehicle(base->IsInVehicle()), - _vehicle(base->GetVehicle()), - _seat(base->GetSeat()), - _entityAimingAt(base->GetEntityAimingAt()), - _entityAimOffset(base->GetEntityAimOffset()), - _flashlightActive(base->IsFlashlightActive()), - _currentAnimationDict(base->GetCurrentAnimationDict()), - _currentAnimationName(base->GetCurrentAnimationName()), - _spawned(base->IsSpawned()), - _forwardSpeed(base->GetForwardSpeed()), - _strafeSpeed(base->GetStrafeSpeed()), - _parachuting(base->IsParachuting()), + _name(base->GetName()), + _health(base->GetHealth()), + _maxHealth(base->GetMaxHealth()), + _currentWeaponTintIndex(base->GetCurrentWeaponTintIndex()), + _currentWeapon(base->GetCurrentWeapon()), + _dead(base->IsDead()), + _jumping(base->IsJumping()), + _inRagdoll(base->IsInRagdoll()), + _aiming(base->IsAiming()), + _shooting(base->IsShooting()), + _reloading(base->IsReloading()), + _enteringVehicle(base->IsEnteringVehicle()), + _leavingVehicle(base->IsLeavingVehicle()), + _onLadder(base->IsOnLadder()), + _inMelee(base->IsInMelee()), + _inCover(base->IsInCover()), + _armour(base->GetArmour()), + _maxArmour(base->GetMaxArmour()), + _moveSpeed(base->GetMoveSpeed()), + _aimPos(base->GetAimPos()), + _headRotation(base->GetHeadRotation()), + _inVehicle(base->IsInVehicle()), + _vehicle(base->GetVehicle()), + _seat(base->GetSeat()), + _entityAimingAt(base->GetEntityAimingAt()), + _entityAimOffset(base->GetEntityAimOffset()), + _flashlightActive(base->IsFlashlightActive()), _superJumpEnabled(false), _crouching(false), _stealthy(false), + _currentAnimationDict(base->GetCurrentAnimationDict()), + _currentAnimationName(base->GetCurrentAnimationName()), + _spawned(base->IsSpawned()), + _forwardSpeed(base->GetForwardSpeed()), + _strafeSpeed(base->GetStrafeSpeed()), + _parachuting(base->IsParachuting()), #ifdef ALT_SERVER_API - _currentWeaponTintIndex(base->GetCurrentWeaponTintIndex()), _superJumpEnabled(base->IsSuperJumpEnabled()), _crouching(base->IsCrouching()), _stealthy(base->IsStealthy()), @@ -75,10 +75,10 @@ namespace cache _faceFeatures(20, 0.0f), _socialClubName(base->GetSocialClubName()) #elif ALT_CLIENT_API - _talking(base->IsTalking()), - _micLevel(base->GetMicLevel()), - _spatialVolume(base->GetSpatialVolume()), - _nonSpatialVolume(base->GetNonSpatialVolume()) + _talking(base->IsTalking()), + _micLevel(base->GetMicLevel()), + _spatialVolume(base->GetSpatialVolume()), + _nonSpatialVolume(base->GetNonSpatialVolume()) #endif { #ifdef ALT_SERVER_API @@ -598,6 +598,8 @@ namespace cache void AddFilter(alt::IAudioFilter* filter) override {} void RemoveFilter() override {} alt::IAudioFilter* GetFilter() const override { return nullptr; } + + std::string GetTaskData() const override { return ""; } #endif From 9667ff523ad8f2be2141b180a941098f9c173314 Mon Sep 17 00:00:00 2001 From: doxoh Date: Sat, 23 Sep 2023 13:43:46 +0200 Subject: [PATCH 09/14] add latest events and fix runtime --- c-api/cache/CachedPlayer.h | 4 +- c-api/entities/player.cpp | 5 ++ c-api/entities/player.h | 4 +- c-api/func_table.cpp | 4 +- cpp-sdk | 2 +- server/include/CSharpResourceImpl.h | 34 ++++++++- server/src/CSharpResourceImpl.cpp | 113 ++++++++++++++++++++++++++-- 7 files changed, 152 insertions(+), 14 deletions(-) diff --git a/c-api/cache/CachedPlayer.h b/c-api/cache/CachedPlayer.h index b1cfc79..9c9e241 100644 --- a/c-api/cache/CachedPlayer.h +++ b/c-api/cache/CachedPlayer.h @@ -40,7 +40,7 @@ namespace cache _seat(base->GetSeat()), _entityAimingAt(base->GetEntityAimingAt()), _entityAimOffset(base->GetEntityAimOffset()), - _flashlightActive(base->IsFlashlightActive()), _superJumpEnabled(false), _crouching(false), _stealthy(false), + _flashlightActive(base->IsFlashlightActive()), _currentAnimationDict(base->GetCurrentAnimationDict()), _currentAnimationName(base->GetCurrentAnimationName()), _spawned(base->IsSpawned()), @@ -598,8 +598,6 @@ namespace cache void AddFilter(alt::IAudioFilter* filter) override {} void RemoveFilter() override {} alt::IAudioFilter* GetFilter() const override { return nullptr; } - - std::string GetTaskData() const override { return ""; } std::string _taskData; std::string GetTaskData() const override { diff --git a/c-api/entities/player.cpp b/c-api/entities/player.cpp index 7775159..a568853 100644 --- a/c-api/entities/player.cpp +++ b/c-api/entities/player.cpp @@ -846,6 +846,11 @@ alt::IAudioFilter* Player_GetFilter(alt::IPlayer* player) return player->GetFilter(); } +const char* Player_GetTaskData(alt::IPlayer* player, int32_t& size) +{ + return AllocateString(player->GetTaskData(), size); +} + #endif CAPI_END() \ No newline at end of file diff --git a/c-api/entities/player.h b/c-api/entities/player.h index ed5fe13..374ce44 100644 --- a/c-api/entities/player.h +++ b/c-api/entities/player.h @@ -251,4 +251,6 @@ EXPORT_CLIENT void Player_AddFilter(alt::IPlayer* player, alt::IAudioFilter* fil EXPORT_CLIENT void Player_RemoveFilter(alt::IPlayer* player); EXPORT_CLIENT alt::IAudioFilter* Player_GetFilter(alt::IPlayer* player); -EXPORT_SHARED uint8_t Player_IsParachuting(alt::IPlayer* player); \ No newline at end of file +EXPORT_SHARED uint8_t Player_IsParachuting(alt::IPlayer* player); + +EXPORT_CLIENT const char* Player_GetTaskData(alt::IPlayer* player, int32_t& size); \ No newline at end of file diff --git a/c-api/func_table.cpp b/c-api/func_table.cpp index 020a425..2bafd5d 100644 --- a/c-api/func_table.cpp +++ b/c-api/func_table.cpp @@ -1,6 +1,6 @@ #include "func_table.h" -inline uint64_t capiHash = 10494575567167650847UL; +inline uint64_t capiHash = 3088291357268716232UL; inline uint64_t capiHashes[] = { 0, #ifdef ALT_CLIENT_API @@ -531,6 +531,7 @@ inline uint64_t capiHashes[] = { 15449156962697427469UL, 3333598534924196965UL, 1924883508304421034UL, + 15465454396501521389UL, 2228995248668686637UL, 14799984366573861130UL, 13836779891982146248UL, @@ -2254,6 +2255,7 @@ inline void* capiPointers[] = { (void*) Player_GetMicLevel, (void*) Player_GetNonSpatialVolume, (void*) Player_GetSpatialVolume, + (void*) Player_GetTaskData, (void*) Player_IsTalking, (void*) Player_RemoveFilter, (void*) Player_SetNonSpatialVolume, diff --git a/cpp-sdk b/cpp-sdk index 2e9be03..55041d3 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit 2e9be033b8902c54779ea8b9da3d185b0771770a +Subproject commit 55041d3e7624bd9566e8b20b740fe52dac22210f diff --git a/server/include/CSharpResourceImpl.h b/server/include/CSharpResourceImpl.h index ec1f8e4..36cb84b 100644 --- a/server/include/CSharpResourceImpl.h +++ b/server/include/CSharpResourceImpl.h @@ -86,14 +86,14 @@ typedef void (* CheckpointDelegate_t)(alt::ICheckpoint* checkpoint, void* entity typedef void (* ClientEventDelegate_t)(alt::IPlayer* player, const char* name, alt::MValueConst** args, uint64_t); -typedef void (* PlayerConnectDelegate_t)(alt::IPlayer* player, uint16_t playerId, const char* reason); +typedef void (* PlayerConnectDelegate_t)(alt::IPlayer* player, const char* reason); typedef void (* PlayerConnectDeniedDelegate_t)(alt::CPlayerConnectDeniedEvent::Reason reason, const char* name, const char* ip, uint64_t passwortHash, uint8_t isDebug, const char* branch, uint32_t majorVersion, const char* cdnUrl, int64_t discordId); typedef void (* ResourceEventDelegate_t)(alt::IResource* resource); typedef void (* PlayerDamageDelegate_t)(alt::IPlayer* player, void* attacker, - alt::IBaseObject::Type attackerType, uint16_t attackerId, uint32_t weapon, + alt::IBaseObject::Type attackerType, uint32_t weapon, uint16_t healthDamage, uint16_t armourDamage); typedef void (* PlayerDeathDelegate_t)(alt::IPlayer* player, void* killer, alt::IBaseObject::Type killerType, @@ -197,6 +197,18 @@ typedef void (* PlayerHealDelegate_t)(alt::IPlayer* target, uint16_t oldHealth, typedef void (* GivePedScriptedTaskDelegate_t)(const alt::CEvent* event, alt::IPlayer* source, alt::IPed* target, uint32_t taskType); +typedef void (* PedDamageDelegate_t)(alt::IPed* target, void* attacker, + alt::IBaseObject::Type attackerType, uint32_t weapon, + uint16_t healthDamage, uint16_t armourDamage); + +typedef void (* PedDeathDelegate_t)(alt::IPed* target, void* killer, alt::IBaseObject::Type killerType, + uint32_t weapon); + +typedef void (* PedHealDelegate_t)(alt::IPed* target, uint16_t oldHealth, uint16_t newHealth, uint16_t oldArmour, uint16_t newArmour); + +typedef void (* PlayerStartTalkingDelegate_t)(alt::IPlayer* player); +typedef void (* PlayerStopTalkingDelegate_t)(alt::IPlayer* player); + class CSharpResourceImpl : public alt::IResource::Impl { void OnEvent(const alt::CEvent* ev) override; @@ -332,6 +344,13 @@ class CSharpResourceImpl : public alt::IResource::Impl { GivePedScriptedTaskDelegate_t OnGivePedScriptedTaskDelegate = nullptr; + PedDamageDelegate_t OnPedDamageDelegate = nullptr; + PedDeathDelegate_t OnPedDeathDelegate = nullptr; + PedHealDelegate_t OnPedHealDelegate = nullptr; + + PlayerStartTalkingDelegate_t OnPlayerStartTalkingDelegate = nullptr; + PlayerStopTalkingDelegate_t OnPlayerStopTalkingDelegate = nullptr; + std::vector invokers; std::mutex invokersLock = {}; CoreClr* coreClr; @@ -542,4 +561,13 @@ EXPORT void CSharpResourceImpl_SetClientDeleteObjectDelegate(CSharpResourceImpl* EXPORT void CSharpResourceImpl_SetPlayerHealDelegate(CSharpResourceImpl* resource, PlayerHealDelegate_t delegate); -EXPORT void CSharpResourceImpl_SetGivePedScriptedTaskDelegate(CSharpResourceImpl* resource, GivePedScriptedTaskDelegate_t delegate); \ No newline at end of file +EXPORT void CSharpResourceImpl_SetGivePedScriptedTaskDelegate(CSharpResourceImpl* resource, GivePedScriptedTaskDelegate_t delegate); + +EXPORT void CSharpResourceImpl_SetPedDamageDelegate(CSharpResourceImpl* resource, PedDamageDelegate_t delegate); + +EXPORT void CSharpResourceImpl_SetPedDeathDelegate(CSharpResourceImpl* resource, PedDeathDelegate_t delegate); + +EXPORT void CSharpResourceImpl_SetPedHealDelegate(CSharpResourceImpl* resource, PedHealDelegate_t delegate); + +EXPORT void CSharpResourceImpl_SetPlayerStartTalkingDelegate(CSharpResourceImpl* resource, PlayerStartTalkingDelegate_t delegate); +EXPORT void CSharpResourceImpl_SetPlayerStopTalkingDelegate(CSharpResourceImpl* resource, PlayerStopTalkingDelegate_t delegate); diff --git a/server/src/CSharpResourceImpl.cpp b/server/src/CSharpResourceImpl.cpp index e8f27f0..fcb6d98 100644 --- a/server/src/CSharpResourceImpl.cpp +++ b/server/src/CSharpResourceImpl.cpp @@ -15,12 +15,12 @@ void CSharpResourceImpl::ResetDelegates() { MainDelegate = [](auto var, auto var2, auto var3, auto var4) {}; OnClientEventDelegate = [](auto var, auto var2, auto var3, auto var4) {}; - OnPlayerConnectDelegate = [](auto var, auto var2, auto var3) {}; + OnPlayerConnectDelegate = [](auto var, auto var2) {}; OnPlayerConnectDeniedDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5, auto var6, auto var7, auto var8, auto var9) {}; OnResourceStartDelegate = [](auto var) {}; OnResourceStopDelegate = [](auto var) {}; OnResourceErrorDelegate = [](auto var) {}; - OnPlayerDamageDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5, auto var6, auto var7) {}; + OnPlayerDamageDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5, auto var6) {}; OnPlayerDeathDelegate = [](auto var, auto var2, auto var3, auto var4) {}; OnExplosionDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5, auto var6, auto var7) {}; OnWeaponDamageDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5, auto var6, auto var7, @@ -72,6 +72,10 @@ void CSharpResourceImpl::ResetDelegates() OnPlayerHealDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5) {}; OnGivePedScriptedTaskDelegate = [](auto var, auto var2, auto var3, auto var4) {}; + + OnPedDamageDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5, auto var6) {}; + OnPedDeathDelegate = [](auto var, auto var2, auto var3, auto var4) {}; + OnPedHealDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5) {}; } bool CSharpResourceImpl::Start() @@ -191,7 +195,6 @@ case alt::CEvent::Type::SYNCED_META_CHANGE: auto playerConnectEvent = dynamic_cast(ev); auto connectPlayer = playerConnectEvent->GetTarget(); OnPlayerConnectDelegate(connectPlayer, - connectPlayer->GetID(), playerConnectEvent->GetReason().c_str()); break; } @@ -237,7 +240,6 @@ case alt::CEvent::Type::SYNCED_META_CHANGE: OnPlayerDamageDelegate(damageEvent->GetTarget(), entityPtr, entity->GetType(), - entity->GetID(), damageEvent->GetWeapon(), damageEvent->GetHealthDamage(), damageEvent->GetArmourDamage()); @@ -247,7 +249,6 @@ case alt::CEvent::Type::SYNCED_META_CHANGE: OnPlayerDamageDelegate(damageEvent->GetTarget(), nullptr, alt::IBaseObject::Type::PLAYER, - 0, damageEvent->GetWeapon(), damageEvent->GetHealthDamage(), damageEvent->GetArmourDamage()); @@ -757,6 +758,82 @@ case alt::CEvent::Type::SYNCED_META_CHANGE: OnGivePedScriptedTaskDelegate(givePedScriptedTaskEvent, source, target, givePedScriptedTaskEvent->GetTaskType()); + break; + } + case alt::CEvent::Type::PED_DAMAGE: + { + auto damageEvent = dynamic_cast(ev); + auto entity = damageEvent->GetAttacker(); + auto entityPtr = GetEntityPointer(entity); + if (entity != nullptr && entityPtr != nullptr) + { + OnPedDamageDelegate(damageEvent->GetTarget(), + entityPtr, + entity->GetType(), + damageEvent->GetWeapon(), + damageEvent->GetHealthDamage(), + damageEvent->GetArmourDamage()); + } + else + { + OnPedDamageDelegate(damageEvent->GetTarget(), + nullptr, + alt::IBaseObject::Type::PLAYER, + damageEvent->GetWeapon(), + damageEvent->GetHealthDamage(), + damageEvent->GetArmourDamage()); + } + break; + } + case alt::CEvent::Type::PED_DEATH: + { + auto deathEvent = dynamic_cast(ev); + auto entity = deathEvent->GetKiller(); + + auto type = alt::IBaseObject::Type::PLAYER; + void* entityPtr = nullptr; + + if (entity != nullptr) + { + entityPtr = GetEntityPointer(entity); + type = entity->GetType(); + } + + OnPedDeathDelegate(deathEvent->GetTarget(), + entityPtr, + type, + deathEvent->GetWeapon()); + break; + } + case alt::CEvent::Type::PED_HEAL: + { + auto healEvent = dynamic_cast(ev); + + auto target = healEvent->GetTarget(); + if (target == nullptr) return; + OnPedHealDelegate(target, + healEvent->GetOldHealth(), + healEvent->GetNewHealth(), + healEvent->GetOldArmour(), + healEvent->GetNewArmour()); + break; + } + case alt::CEvent::Type::PLAYER_START_TALKING: + { + auto playerStartTalkingEvent = dynamic_cast(ev); + + auto player = playerStartTalkingEvent->GetPlayer(); + if (player == nullptr) return; + OnPlayerStartTalkingDelegate(player); + break; + } + case alt::CEvent::Type::PLAYER_STOP_TALKING: + { + auto playerStopTalkingEvent = dynamic_cast(ev); + + auto player = playerStopTalkingEvent->GetPlayer(); + if (player == nullptr) return; + OnPlayerStopTalkingDelegate(player); break; } default: @@ -1274,6 +1351,32 @@ void CSharpResourceImpl_SetGivePedScriptedTaskDelegate(CSharpResourceImpl* resou resource->OnGivePedScriptedTaskDelegate = delegate; } +void CSharpResourceImpl_SetPedDamageDelegate(CSharpResourceImpl* resource, PedDamageDelegate_t delegate) +{ + resource->OnPedDamageDelegate = delegate; +} + +void CSharpResourceImpl_SetPedDeathDelegate(CSharpResourceImpl* resource, PedDeathDelegate_t delegate) +{ + resource->OnPedDeathDelegate = delegate; +} + +void CSharpResourceImpl_SetPedHealDelegate(CSharpResourceImpl* resource, PedHealDelegate_t delegate) +{ + resource->OnPedHealDelegate = delegate; +} + +void CSharpResourceImpl_SetPlayerStartTalkingDelegate(CSharpResourceImpl* resource, + PlayerStartTalkingDelegate_t delegate) +{ + resource->OnPlayerStartTalkingDelegate = delegate; +} + +void CSharpResourceImpl_SetPlayerStopTalkingDelegate(CSharpResourceImpl* resource, PlayerStopTalkingDelegate_t delegate) +{ + resource->OnPlayerStopTalkingDelegate = delegate; +} + bool CSharpResourceImpl::MakeClient(alt::IResource::CreationInfo* info, std::vector files) { const std::string clientMain = resource->GetClientMain(); From 09d6a7ccf2781da06846457e4824c62834de4ad9 Mon Sep 17 00:00:00 2001 From: doxoh Date: Sun, 24 Sep 2023 10:50:19 +0200 Subject: [PATCH 10/14] Updated submodule cpp-sdk --- cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-sdk b/cpp-sdk index 55041d3..8c65d5a 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit 55041d3e7624bd9566e8b20b740fe52dac22210f +Subproject commit 8c65d5a1614a9d50a39726f4cf3405ed6a326574 From 740dbed1aa2bbd97c0950c7f12128dfba7329116 Mon Sep 17 00:00:00 2001 From: doxoh Date: Sun, 24 Sep 2023 14:03:24 +0200 Subject: [PATCH 11/14] Updated submodule cpp-sdk --- cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-sdk b/cpp-sdk index 8c65d5a..f119fa3 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit 8c65d5a1614a9d50a39726f4cf3405ed6a326574 +Subproject commit f119fa30e45aa6c37a4900827889672173054684 From e3f3f8fdda263358641b101b82ab2294cbd72361 Mon Sep 17 00:00:00 2001 From: doxoh Date: Sun, 24 Sep 2023 14:12:02 +0200 Subject: [PATCH 12/14] add RPC events --- c-api/core.cpp | 19 +++++++++++++ c-api/core.h | 5 +++- c-api/event.cpp | 27 ++++++++++++++++++- c-api/event.h | 4 +++ c-api/func_table.cpp | 14 +++++++++- client/src/runtime/CSharpResourceImpl.cpp | 20 ++++++++++++++ client/src/runtime/CSharpResourceImpl.h | 2 ++ client/src/runtime/eventDelegates.h | 1 + server/include/CSharpResourceImpl.h | 6 +++++ server/src/CSharpResourceImpl.cpp | 33 +++++++++++++++++++++++ 10 files changed, 128 insertions(+), 3 deletions(-) diff --git a/c-api/core.cpp b/c-api/core.cpp index 5c50759..0aa6e10 100644 --- a/c-api/core.cpp +++ b/c-api/core.cpp @@ -1000,6 +1000,16 @@ void Core_SetMigrationDistance(alt::ICore* core, uint32_t limit) { core->SetMigrationDistance(limit); } + +void Core_TriggerClientRPCAnswer(alt::ICore* core, alt::IPlayer* target, uint16_t answerID, alt::MValueConst* args[], + int size, const char* error) +{ + alt::MValueArgs mValues = alt::MValueArgs(size); + for (int i = 0; i < size; i++) { + ToMValueArg(mValues, core, args[i], i); + } + core->TriggerClientRPCAnswer(target, answerID, mValues, error); +} #endif #ifdef ALT_CLIENT_API @@ -1998,6 +2008,15 @@ void Core_GetAllWeaponData(alt::ICore* core, uint32_t weaponHashes[], uint64_t s weaponHashes[i] = weaponData[i]->GetNameHash(); } } + +uint16_t Core_TriggerServerRPCEvent(alt::ICore* core, const char* ev, alt::MValueConst* args[], int size) +{ + alt::MValueArgs mValues = alt::MValueArgs(size); + for (int i = 0; i < size; i++) { + ToMValueArg(mValues, core, args[i], i); + } + return core->TriggerServerRPCEvent(ev, mValues); +} #endif CAPI_END() diff --git a/c-api/core.h b/c-api/core.h index 48e4513..7cebfd9 100644 --- a/c-api/core.h +++ b/c-api/core.h @@ -396,4 +396,7 @@ EXPORT_SERVER uint32_t Core_GetColShapeTickRate(alt::ICore* core); EXPORT_SERVER void Core_SetColShapeTickRate(alt::ICore* core, uint32_t limit); EXPORT_SERVER uint32_t Core_GetMigrationDistance(alt::ICore* core); -EXPORT_SERVER void Core_SetMigrationDistance(alt::ICore* core, uint32_t limit); \ No newline at end of file +EXPORT_SERVER void Core_SetMigrationDistance(alt::ICore* core, uint32_t limit); + +EXPORT_SERVER void Core_TriggerClientRPCAnswer(alt::ICore* server, alt::IPlayer* target, uint16_t answerID, alt::MValueConst* args[], int size, const char* error); +EXPORT_CLIENT uint16_t Core_TriggerServerRPCEvent(alt::ICore* server, const char* ev, alt::MValueConst* args[], int size); diff --git a/c-api/event.cpp b/c-api/event.cpp index 116cfba..42f8161 100644 --- a/c-api/event.cpp +++ b/c-api/event.cpp @@ -1,5 +1,6 @@ #include "event.h" +#include "mvalue.h" #include "utils/macros.h" CAPI_START() @@ -7,7 +8,29 @@ CAPI_START() #ifdef ALT_SERVER_API void Event_WeaponDamageEvent_SetDamageValue(alt::CEvent* event, uint32_t damageValue) { - ((alt::CWeaponDamageEvent*) event)->SetDamageValue(damageValue); + dynamic_cast(event)->SetDamageValue(damageValue); +} + +uint8_t Event_ClientScriptRPCEvent_WillAnswer(alt::CEvent* event) +{ + auto rpcEvent = dynamic_cast(event); + return rpcEvent->WillAnswer(); +} + +uint8_t Event_ClientScriptRPCEvent_Answer(alt::CEvent* event, alt::ICore* core, alt::MValueConst* args[], int size) +{ + alt::MValueArgs mValues = alt::MValueArgs(size); + for (int i = 0; i < size; i++) { + ToMValueArg(mValues, core, args[i], i); + } + auto rpcEvent = dynamic_cast(event); + return rpcEvent->Answer(mValues); +} + +uint8_t Event_ClientScriptRPCEvent_AnswerWithError(alt::CEvent* event, const char* error) +{ + auto rpcEvent = dynamic_cast(event); + return rpcEvent->AnswerWithError(error); } #endif @@ -90,6 +113,8 @@ SetDelegate(PlayerBulletHit); SetDelegate(VoiceConnection); SetDelegate(AudioEvent); +SetDelegate(ServerScriptRPCAnswer) + #endif CAPI_END() \ No newline at end of file diff --git a/c-api/event.h b/c-api/event.h index 9b7a527..75324d6 100644 --- a/c-api/event.h +++ b/c-api/event.h @@ -21,6 +21,9 @@ EXPORT_SHARED void Event_Cancel(alt::CCancellableEvent* event); EXPORT_SERVER void Event_WeaponDamageEvent_SetDamageValue(alt::CEvent* event, uint32_t damageValue); +EXPORT_SERVER uint8_t Event_ClientScriptRPCEvent_WillAnswer(alt::CEvent* event); +EXPORT_SERVER uint8_t Event_ClientScriptRPCEvent_Answer(alt::CEvent* event, alt::MValueConst* args[], int size); +EXPORT_SERVER uint8_t Event_ClientScriptRPCEvent_AnswerWithError(alt::CEvent* event, const char* error); EXPORT_SHARED uint8_t Event_WasCancelled(alt::CCancellableEvent* event); #ifdef ALT_CLIENT_API @@ -92,4 +95,5 @@ EXPORT_CLIENT void Event_SetPlayerStartLeaveVehicleDelegate(CSharpResourceImpl* EXPORT_CLIENT void Event_SetPlayerBulletHitDelegate(CSharpResourceImpl* resource, /** ClientEvents.PlayerBulletHitModuleDelegate */ PlayerBulletHitDelegate_t delegate); EXPORT_CLIENT void Event_SetVoiceConnectionDelegate(CSharpResourceImpl* resource, /** ClientEvents.VoiceConnectionModuleDelegate */ VoiceConnectionDelegate_t delegate); +EXPORT_CLIENT void Event_SetServerScriptRPCAnswerDelegate(CSharpResourceImpl* resource, /** ClientEvents.ServerScriptRPCAnswerModuleDelegate */ ServerScriptRPCAnswerDelegate_t delegate); #endif diff --git a/c-api/func_table.cpp b/c-api/func_table.cpp index 2bafd5d..6587372 100644 --- a/c-api/func_table.cpp +++ b/c-api/func_table.cpp @@ -1,6 +1,6 @@ #include "func_table.h" -inline uint64_t capiHash = 3088291357268716232UL; +inline uint64_t capiHash = 11229478147648242923UL; inline uint64_t capiHashes[] = { 0, #ifdef ALT_CLIENT_API @@ -245,6 +245,7 @@ inline uint64_t capiHashes[] = { 1817218062913323235UL, 4092140335578989631UL, 718150788563346996UL, + 5920144219377072122UL, 3268039739443301173UL, 17753040748478874447UL, 5389506501733691988UL, @@ -286,6 +287,7 @@ inline uint64_t capiHashes[] = { 8121512912272945641UL, 1513529985252499227UL, 5521055548998327457UL, + 13554094634858443749UL, 8576321635222028243UL, 12745100726667735891UL, 11607888672861240667UL, @@ -1374,6 +1376,7 @@ inline uint64_t capiHashes[] = { 4821179867491879744UL, 9578627964183564598UL, 14557546483922608997UL, + 9224620724544415249UL, 4092140335578989631UL, 17237210604041123822UL, 11965009764904998252UL, @@ -1390,6 +1393,9 @@ inline uint64_t capiHashes[] = { 6004628797499736605UL, 12798418058428333585UL, 8026011842118229214UL, + 9846613369628943706UL, + 2674464925851684396UL, + 5065438074644693875UL, 18440396865533386791UL, 2348810001298180138UL, 13016512038826983106UL, @@ -1969,6 +1975,7 @@ inline void* capiPointers[] = { (void*) Core_ToggleVoiceInput, (void*) Core_TriggerServerEvent, (void*) Core_TriggerServerEventUnreliable, + (void*) Core_TriggerServerRPCEvent, (void*) Core_TriggerWebViewEvent, (void*) Core_UnloadYtyp, (void*) Core_WorldToScreen, @@ -2010,6 +2017,7 @@ inline void* capiPointers[] = { (void*) Event_SetRemoveBaseObjectDelegate, (void*) Event_SetRmlEventDelegate, (void*) Event_SetServerEventDelegate, + (void*) Event_SetServerScriptRPCAnswerDelegate, (void*) Event_SetStreamSyncedMetaChangeDelegate, (void*) Event_SetSyncedMetaChangeDelegate, (void*) Event_SetTaskChangeDelegate, @@ -3098,6 +3106,7 @@ inline void* capiPointers[] = { (void*) Core_TriggerClientEventUnreliable, (void*) Core_TriggerClientEventUnreliableForAll, (void*) Core_TriggerClientEventUnreliableForSome, + (void*) Core_TriggerClientRPCAnswer, (void*) Core_TriggerServerEvent, (void*) Core_UnregisterMetric, (void*) Entity_AttachToEntity, @@ -3114,6 +3123,9 @@ inline void* capiPointers[] = { (void*) Entity_SetStreamed, (void*) Entity_SetStreamSyncedMetaData, (void*) Entity_SetVisible, + (void*) Event_ClientScriptRPCEvent_Answer, + (void*) Event_ClientScriptRPCEvent_AnswerWithError, + (void*) Event_ClientScriptRPCEvent_WillAnswer, (void*) Event_WeaponDamageEvent_SetDamageValue, (void*) Metric_Begin, (void*) Metric_End, diff --git a/client/src/runtime/CSharpResourceImpl.cpp b/client/src/runtime/CSharpResourceImpl.cpp index 9659340..d49babd 100644 --- a/client/src/runtime/CSharpResourceImpl.cpp +++ b/client/src/runtime/CSharpResourceImpl.cpp @@ -586,6 +586,24 @@ void CSharpResourceImpl::OnEvent(const alt::CEvent* ev) size); break; } + case alt::CEvent::Type::SERVER_SCRIPT_RPC_ANSWER_EVENT: + { + auto serverScriptRPCAnswerEvent = dynamic_cast(ev); + + auto answers = serverScriptRPCAnswerEvent->GetAnswer(); + auto size = answers.size(); + auto constAnswers = new alt::MValueConst*[size]; + + for (uint64_t i = 0; i < size; i++) + { + constAnswers[i] = &answers[i]; + } + OnServerScriptRPCAnswerDelegate(serverScriptRPCAnswerEvent->GetAnswerID(), + constAnswers, + size, + serverScriptRPCAnswerEvent->GetAnswerError().c_str()); + break; + } default: { std::cout << "Unhandled client event #" << static_cast(ev->GetType()) << " got called" << std::endl; @@ -1012,4 +1030,6 @@ void CSharpResourceImpl::ResetDelegates() { OnPlayerBulletHitDelegate = [](auto var, auto var2, auto var3, auto var4) {}; OnVoiceConnectionDelegate = [](auto var) {}; + + OnServerScriptRPCAnswerDelegate = [](auto var, auto var2, auto var3, auto var4) {}; } \ No newline at end of file diff --git a/client/src/runtime/CSharpResourceImpl.h b/client/src/runtime/CSharpResourceImpl.h index b8ac171..0469cfc 100644 --- a/client/src/runtime/CSharpResourceImpl.h +++ b/client/src/runtime/CSharpResourceImpl.h @@ -102,6 +102,8 @@ class CSharpResourceImpl : public alt::IResource::Impl VoiceConnectionDelegate_t OnVoiceConnectionDelegate = nullptr; + ServerScriptRPCAnswerDelegate_t OnServerScriptRPCAnswerDelegate = nullptr; + bool MakeClient(alt::IResource::CreationInfo* info, std::vector files) { diff --git a/client/src/runtime/eventDelegates.h b/client/src/runtime/eventDelegates.h index 7799cb0..08638bb 100644 --- a/client/src/runtime/eventDelegates.h +++ b/client/src/runtime/eventDelegates.h @@ -77,3 +77,4 @@ typedef void (* PlayerStartLeaveVehicleDelegate_t)(void* target, void* player, u typedef void (* PlayerBulletHitDelegate_t)(uint32_t weapon, void* victim, alt::IBaseObject::Type victimType, position_t pos); typedef void (* VoiceConnectionDelegate_t)(uint8_t state); +typedef void (* ServerScriptRPCAnswerDelegate_t)(uint16_t answerId, alt::MValueConst** answer, uint64_t size, const char* answerError); diff --git a/server/include/CSharpResourceImpl.h b/server/include/CSharpResourceImpl.h index 36cb84b..00f13cb 100644 --- a/server/include/CSharpResourceImpl.h +++ b/server/include/CSharpResourceImpl.h @@ -209,6 +209,8 @@ typedef void (* PedHealDelegate_t)(alt::IPed* target, uint16_t oldHealth, uint16 typedef void (* PlayerStartTalkingDelegate_t)(alt::IPlayer* player); typedef void (* PlayerStopTalkingDelegate_t)(alt::IPlayer* player); +typedef void (* ClientScriptRPCDelegate_t)(const alt::CEvent* event, alt::IPlayer* target, const char* name, alt::MValueConst** args, uint64_t size, uint16_t answerID); + class CSharpResourceImpl : public alt::IResource::Impl { void OnEvent(const alt::CEvent* ev) override; @@ -351,6 +353,8 @@ class CSharpResourceImpl : public alt::IResource::Impl { PlayerStartTalkingDelegate_t OnPlayerStartTalkingDelegate = nullptr; PlayerStopTalkingDelegate_t OnPlayerStopTalkingDelegate = nullptr; + ClientScriptRPCDelegate_t OnClientScriptRPCDelegate = nullptr; + std::vector invokers; std::mutex invokersLock = {}; CoreClr* coreClr; @@ -571,3 +575,5 @@ EXPORT void CSharpResourceImpl_SetPedHealDelegate(CSharpResourceImpl* resource, EXPORT void CSharpResourceImpl_SetPlayerStartTalkingDelegate(CSharpResourceImpl* resource, PlayerStartTalkingDelegate_t delegate); EXPORT void CSharpResourceImpl_SetPlayerStopTalkingDelegate(CSharpResourceImpl* resource, PlayerStopTalkingDelegate_t delegate); + +EXPORT void CSharpResourceImpl_SetClientScriptRPCDelegate(CSharpResourceImpl* resource, ClientScriptRPCDelegate_t delegate); diff --git a/server/src/CSharpResourceImpl.cpp b/server/src/CSharpResourceImpl.cpp index fcb6d98..1395d38 100644 --- a/server/src/CSharpResourceImpl.cpp +++ b/server/src/CSharpResourceImpl.cpp @@ -76,6 +76,8 @@ void CSharpResourceImpl::ResetDelegates() OnPedDamageDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5, auto var6) {}; OnPedDeathDelegate = [](auto var, auto var2, auto var3, auto var4) {}; OnPedHealDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5) {}; + + OnClientScriptRPCDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5, auto var6) {}; } bool CSharpResourceImpl::Start() @@ -836,6 +838,32 @@ case alt::CEvent::Type::SYNCED_META_CHANGE: OnPlayerStopTalkingDelegate(player); break; } + case alt::CEvent::Type::CLIENT_SCRIPT_RPC_EVENT: + { + auto clientScriptRPCEvent = dynamic_cast(ev); + + auto target = clientScriptRPCEvent->GetTarget(); + if (target == nullptr) return; + + auto name = clientScriptRPCEvent->GetName(); + auto args = clientScriptRPCEvent->GetArgs(); + auto size = args.size(); + auto constArgs = new alt::MValueConst*[size]; + + for (uint64_t i = 0; i < size; i++) + { + constArgs[i] = &args[i]; + } + + OnClientScriptRPCDelegate(clientScriptRPCEvent, + target, + name.c_str(), + constArgs, + size, + clientScriptRPCEvent->GetAnswerID() + ); + break; + } default: { std::cout << "Unhandled server event #" << static_cast(ev->GetType()) << " got called" << std::endl; @@ -1377,6 +1405,11 @@ void CSharpResourceImpl_SetPlayerStopTalkingDelegate(CSharpResourceImpl* resourc resource->OnPlayerStopTalkingDelegate = delegate; } +void CSharpResourceImpl_SetClientScriptRPCDelegate(CSharpResourceImpl* resource, ClientScriptRPCDelegate_t delegate) +{ + resource->OnClientScriptRPCDelegate = delegate; +} + bool CSharpResourceImpl::MakeClient(alt::IResource::CreationInfo* info, std::vector files) { const std::string clientMain = resource->GetClientMain(); From f44a4ad1e11fc4827ed079cf92130dc25ab65876 Mon Sep 17 00:00:00 2001 From: doxoh Date: Sun, 24 Sep 2023 14:26:54 +0200 Subject: [PATCH 13/14] fix runtime --- c-api/event.h | 2 +- c-api/func_table.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/c-api/event.h b/c-api/event.h index 75324d6..130f699 100644 --- a/c-api/event.h +++ b/c-api/event.h @@ -22,7 +22,7 @@ EXPORT_SHARED void Event_Cancel(alt::CCancellableEvent* event); EXPORT_SERVER void Event_WeaponDamageEvent_SetDamageValue(alt::CEvent* event, uint32_t damageValue); EXPORT_SERVER uint8_t Event_ClientScriptRPCEvent_WillAnswer(alt::CEvent* event); -EXPORT_SERVER uint8_t Event_ClientScriptRPCEvent_Answer(alt::CEvent* event, alt::MValueConst* args[], int size); +EXPORT_SERVER uint8_t Event_ClientScriptRPCEvent_Answer(alt::CEvent* event, alt::ICore* core, alt::MValueConst* args[], int size); EXPORT_SERVER uint8_t Event_ClientScriptRPCEvent_AnswerWithError(alt::CEvent* event, const char* error); EXPORT_SHARED uint8_t Event_WasCancelled(alt::CCancellableEvent* event); diff --git a/c-api/func_table.cpp b/c-api/func_table.cpp index 6587372..2a52047 100644 --- a/c-api/func_table.cpp +++ b/c-api/func_table.cpp @@ -1,6 +1,6 @@ #include "func_table.h" -inline uint64_t capiHash = 11229478147648242923UL; +inline uint64_t capiHash = 1071294164973163825UL; inline uint64_t capiHashes[] = { 0, #ifdef ALT_CLIENT_API @@ -1393,7 +1393,7 @@ inline uint64_t capiHashes[] = { 6004628797499736605UL, 12798418058428333585UL, 8026011842118229214UL, - 9846613369628943706UL, + 11300708773696104108UL, 2674464925851684396UL, 5065438074644693875UL, 18440396865533386791UL, From f8160eee532fc5be88dbfe3305d30ac1fdda0a80 Mon Sep 17 00:00:00 2001 From: doxoh Date: Sun, 24 Sep 2023 20:56:29 +0200 Subject: [PATCH 14/14] change answer type for RPC --- c-api/core.cpp | 10 +++------- c-api/core.h | 2 +- c-api/event.cpp | 9 +++------ c-api/event.h | 2 +- c-api/func_table.cpp | 6 +++--- client/src/runtime/CSharpResourceImpl.cpp | 12 ++---------- client/src/runtime/eventDelegates.h | 2 +- cpp-sdk | 2 +- 8 files changed, 15 insertions(+), 30 deletions(-) diff --git a/c-api/core.cpp b/c-api/core.cpp index 0aa6e10..7b72980 100644 --- a/c-api/core.cpp +++ b/c-api/core.cpp @@ -1001,14 +1001,10 @@ void Core_SetMigrationDistance(alt::ICore* core, uint32_t limit) core->SetMigrationDistance(limit); } -void Core_TriggerClientRPCAnswer(alt::ICore* core, alt::IPlayer* target, uint16_t answerID, alt::MValueConst* args[], - int size, const char* error) +void Core_TriggerClientRPCAnswer(alt::ICore* core, alt::IPlayer* target, uint16_t answerID, alt::MValueConst* answer, const char* error) { - alt::MValueArgs mValues = alt::MValueArgs(size); - for (int i = 0; i < size; i++) { - ToMValueArg(mValues, core, args[i], i); - } - core->TriggerClientRPCAnswer(target, answerID, mValues, error); + if(answer == nullptr) return; + core->TriggerClientRPCAnswer(target, answerID, answer->get()->Clone(), error); } #endif diff --git a/c-api/core.h b/c-api/core.h index 7cebfd9..b43bb52 100644 --- a/c-api/core.h +++ b/c-api/core.h @@ -398,5 +398,5 @@ EXPORT_SERVER void Core_SetColShapeTickRate(alt::ICore* core, uint32_t limit); EXPORT_SERVER uint32_t Core_GetMigrationDistance(alt::ICore* core); EXPORT_SERVER void Core_SetMigrationDistance(alt::ICore* core, uint32_t limit); -EXPORT_SERVER void Core_TriggerClientRPCAnswer(alt::ICore* server, alt::IPlayer* target, uint16_t answerID, alt::MValueConst* args[], int size, const char* error); +EXPORT_SERVER void Core_TriggerClientRPCAnswer(alt::ICore* server, alt::IPlayer* target, uint16_t answerID, alt::MValueConst* answer, const char* error); EXPORT_CLIENT uint16_t Core_TriggerServerRPCEvent(alt::ICore* server, const char* ev, alt::MValueConst* args[], int size); diff --git a/c-api/event.cpp b/c-api/event.cpp index 42f8161..24b6bf3 100644 --- a/c-api/event.cpp +++ b/c-api/event.cpp @@ -17,14 +17,11 @@ uint8_t Event_ClientScriptRPCEvent_WillAnswer(alt::CEvent* event) return rpcEvent->WillAnswer(); } -uint8_t Event_ClientScriptRPCEvent_Answer(alt::CEvent* event, alt::ICore* core, alt::MValueConst* args[], int size) +uint8_t Event_ClientScriptRPCEvent_Answer(alt::CEvent* event, alt::MValueConst* answer) { - alt::MValueArgs mValues = alt::MValueArgs(size); - for (int i = 0; i < size; i++) { - ToMValueArg(mValues, core, args[i], i); - } + if (answer == nullptr) return false; auto rpcEvent = dynamic_cast(event); - return rpcEvent->Answer(mValues); + return rpcEvent->Answer(answer->get()->Clone()); } uint8_t Event_ClientScriptRPCEvent_AnswerWithError(alt::CEvent* event, const char* error) diff --git a/c-api/event.h b/c-api/event.h index 130f699..b3f62ec 100644 --- a/c-api/event.h +++ b/c-api/event.h @@ -22,7 +22,7 @@ EXPORT_SHARED void Event_Cancel(alt::CCancellableEvent* event); EXPORT_SERVER void Event_WeaponDamageEvent_SetDamageValue(alt::CEvent* event, uint32_t damageValue); EXPORT_SERVER uint8_t Event_ClientScriptRPCEvent_WillAnswer(alt::CEvent* event); -EXPORT_SERVER uint8_t Event_ClientScriptRPCEvent_Answer(alt::CEvent* event, alt::ICore* core, alt::MValueConst* args[], int size); +EXPORT_SERVER uint8_t Event_ClientScriptRPCEvent_Answer(alt::CEvent* event, alt::MValueConst* answer); EXPORT_SERVER uint8_t Event_ClientScriptRPCEvent_AnswerWithError(alt::CEvent* event, const char* error); EXPORT_SHARED uint8_t Event_WasCancelled(alt::CCancellableEvent* event); diff --git a/c-api/func_table.cpp b/c-api/func_table.cpp index 2a52047..0b7d197 100644 --- a/c-api/func_table.cpp +++ b/c-api/func_table.cpp @@ -1,6 +1,6 @@ #include "func_table.h" -inline uint64_t capiHash = 1071294164973163825UL; +inline uint64_t capiHash = 10439883327927219649UL; inline uint64_t capiHashes[] = { 0, #ifdef ALT_CLIENT_API @@ -1376,7 +1376,7 @@ inline uint64_t capiHashes[] = { 4821179867491879744UL, 9578627964183564598UL, 14557546483922608997UL, - 9224620724544415249UL, + 15767989313971387723UL, 4092140335578989631UL, 17237210604041123822UL, 11965009764904998252UL, @@ -1393,7 +1393,7 @@ inline uint64_t capiHashes[] = { 6004628797499736605UL, 12798418058428333585UL, 8026011842118229214UL, - 11300708773696104108UL, + 10935127918561517872UL, 2674464925851684396UL, 5065438074644693875UL, 18440396865533386791UL, diff --git a/client/src/runtime/CSharpResourceImpl.cpp b/client/src/runtime/CSharpResourceImpl.cpp index d49babd..e71948b 100644 --- a/client/src/runtime/CSharpResourceImpl.cpp +++ b/client/src/runtime/CSharpResourceImpl.cpp @@ -591,16 +591,8 @@ void CSharpResourceImpl::OnEvent(const alt::CEvent* ev) auto serverScriptRPCAnswerEvent = dynamic_cast(ev); auto answers = serverScriptRPCAnswerEvent->GetAnswer(); - auto size = answers.size(); - auto constAnswers = new alt::MValueConst*[size]; - - for (uint64_t i = 0; i < size; i++) - { - constAnswers[i] = &answers[i]; - } OnServerScriptRPCAnswerDelegate(serverScriptRPCAnswerEvent->GetAnswerID(), - constAnswers, - size, + AllocMValue(answers), serverScriptRPCAnswerEvent->GetAnswerError().c_str()); break; } @@ -1031,5 +1023,5 @@ void CSharpResourceImpl::ResetDelegates() { OnVoiceConnectionDelegate = [](auto var) {}; - OnServerScriptRPCAnswerDelegate = [](auto var, auto var2, auto var3, auto var4) {}; + OnServerScriptRPCAnswerDelegate = [](auto var, auto var2, auto var3) {}; } \ No newline at end of file diff --git a/client/src/runtime/eventDelegates.h b/client/src/runtime/eventDelegates.h index 08638bb..3988c93 100644 --- a/client/src/runtime/eventDelegates.h +++ b/client/src/runtime/eventDelegates.h @@ -77,4 +77,4 @@ typedef void (* PlayerStartLeaveVehicleDelegate_t)(void* target, void* player, u typedef void (* PlayerBulletHitDelegate_t)(uint32_t weapon, void* victim, alt::IBaseObject::Type victimType, position_t pos); typedef void (* VoiceConnectionDelegate_t)(uint8_t state); -typedef void (* ServerScriptRPCAnswerDelegate_t)(uint16_t answerId, alt::MValueConst** answer, uint64_t size, const char* answerError); +typedef void (* ServerScriptRPCAnswerDelegate_t)(uint16_t answerId, alt::MValueConst* answer, const char* answerError); diff --git a/cpp-sdk b/cpp-sdk index f119fa3..91be63b 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit f119fa30e45aa6c37a4900827889672173054684 +Subproject commit 91be63bbdff082ece762e0c829b108e7867e47f3