diff --git a/c-api/cache/CachedPlayer.h b/c-api/cache/CachedPlayer.h index 6d8ede7..9c9e241 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()), + _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 @@ -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/c-api/core.cpp b/c-api/core.cpp index 1412ecc..7b72980 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); } @@ -1000,6 +1000,12 @@ 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* answer, const char* error) +{ + if(answer == nullptr) return; + core->TriggerClientRPCAnswer(target, answerID, answer->get()->Clone(), error); +} #endif #ifdef ALT_CLIENT_API @@ -1998,6 +2004,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 46779fa..b43bb52 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); @@ -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* 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/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/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/event.cpp b/c-api/event.cpp index 116cfba..24b6bf3 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,26 @@ 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::MValueConst* answer) +{ + if (answer == nullptr) return false; + auto rpcEvent = dynamic_cast(event); + return rpcEvent->Answer(answer->get()->Clone()); +} + +uint8_t Event_ClientScriptRPCEvent_AnswerWithError(alt::CEvent* event, const char* error) +{ + auto rpcEvent = dynamic_cast(event); + return rpcEvent->AnswerWithError(error); } #endif @@ -90,6 +110,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..b3f62ec 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* answer); +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 22deb47..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 = 10494575567167650847UL; +inline uint64_t capiHash = 10439883327927219649UL; 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, @@ -531,6 +533,7 @@ inline uint64_t capiHashes[] = { 15449156962697427469UL, 3333598534924196965UL, 1924883508304421034UL, + 15465454396501521389UL, 2228995248668686637UL, 14799984366573861130UL, 13836779891982146248UL, @@ -1052,6 +1055,7 @@ inline uint64_t capiHashes[] = { 6921054663232355759UL, 7482854450085275693UL, 2139798095052897524UL, + 15652019729912249391UL, 8454955647873390265UL, 5411021830103603795UL, 6799731000550763773UL, @@ -1332,7 +1336,6 @@ inline uint64_t capiHashes[] = { 8442828755754917489UL, 5757616980701278724UL, 9990683150417934189UL, - 15652019729912249391UL, 7718568480211772772UL, 12125306445698504265UL, 14723504540957489106UL, @@ -1373,6 +1376,7 @@ inline uint64_t capiHashes[] = { 4821179867491879744UL, 9578627964183564598UL, 14557546483922608997UL, + 15767989313971387723UL, 4092140335578989631UL, 17237210604041123822UL, 11965009764904998252UL, @@ -1389,6 +1393,9 @@ inline uint64_t capiHashes[] = { 6004628797499736605UL, 12798418058428333585UL, 8026011842118229214UL, + 10935127918561517872UL, + 2674464925851684396UL, + 5065438074644693875UL, 18440396865533386791UL, 2348810001298180138UL, 13016512038826983106UL, @@ -1968,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, @@ -2009,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, @@ -2254,6 +2263,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, @@ -2775,6 +2785,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 +3066,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, @@ -3096,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, @@ -3112,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..e71948b 100644 --- a/client/src/runtime/CSharpResourceImpl.cpp +++ b/client/src/runtime/CSharpResourceImpl.cpp @@ -586,6 +586,16 @@ 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(); + OnServerScriptRPCAnswerDelegate(serverScriptRPCAnswerEvent->GetAnswerID(), + AllocMValue(answers), + serverScriptRPCAnswerEvent->GetAnswerError().c_str()); + break; + } default: { std::cout << "Unhandled client event #" << static_cast(ev->GetType()) << " got called" << std::endl; @@ -1012,4 +1022,6 @@ void CSharpResourceImpl::ResetDelegates() { OnPlayerBulletHitDelegate = [](auto var, auto var2, auto var3, auto var4) {}; OnVoiceConnectionDelegate = [](auto var) {}; + + OnServerScriptRPCAnswerDelegate = [](auto var, auto var2, auto var3) {}; } \ 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..3988c93 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, const char* answerError); diff --git a/cpp-sdk b/cpp-sdk index 22c74ce..91be63b 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit 22c74ce2dc45891de76ed80ba37ee9628f0c56b3 +Subproject commit 91be63bbdff082ece762e0c829b108e7867e47f3 diff --git a/server/include/CSharpResourceImpl.h b/server/include/CSharpResourceImpl.h index 0e7a614..00f13cb 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, @@ -195,6 +195,22 @@ 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, 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); + +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; @@ -328,6 +344,17 @@ class CSharpResourceImpl : public alt::IResource::Impl { PlayerHealDelegate_t OnPlayerHealDelegate = nullptr; + GivePedScriptedTaskDelegate_t OnGivePedScriptedTaskDelegate = nullptr; + + PedDamageDelegate_t OnPedDamageDelegate = nullptr; + PedDeathDelegate_t OnPedDeathDelegate = nullptr; + PedHealDelegate_t OnPedHealDelegate = nullptr; + + PlayerStartTalkingDelegate_t OnPlayerStartTalkingDelegate = nullptr; + PlayerStopTalkingDelegate_t OnPlayerStopTalkingDelegate = nullptr; + + ClientScriptRPCDelegate_t OnClientScriptRPCDelegate = nullptr; + std::vector invokers; std::mutex invokersLock = {}; CoreClr* coreClr; @@ -536,4 +563,17 @@ 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); + +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); + +EXPORT void CSharpResourceImpl_SetClientScriptRPCDelegate(CSharpResourceImpl* resource, ClientScriptRPCDelegate_t delegate); diff --git a/server/src/CSharpResourceImpl.cpp b/server/src/CSharpResourceImpl.cpp index b367f10..1395d38 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, @@ -70,6 +70,14 @@ 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, 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) {}; + + OnClientScriptRPCDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5, auto var6) {}; } bool CSharpResourceImpl::Start() @@ -189,7 +197,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; } @@ -235,7 +242,6 @@ case alt::CEvent::Type::SYNCED_META_CHANGE: OnPlayerDamageDelegate(damageEvent->GetTarget(), entityPtr, entity->GetType(), - entity->GetID(), damageEvent->GetWeapon(), damageEvent->GetHealthDamage(), damageEvent->GetArmourDamage()); @@ -245,7 +251,6 @@ case alt::CEvent::Type::SYNCED_META_CHANGE: OnPlayerDamageDelegate(damageEvent->GetTarget(), nullptr, alt::IBaseObject::Type::PLAYER, - 0, damageEvent->GetWeapon(), damageEvent->GetHealthDamage(), damageEvent->GetArmourDamage()); @@ -743,6 +748,122 @@ 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(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; + } + 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; @@ -1253,6 +1374,42 @@ void CSharpResourceImpl_SetPlayerHealDelegate(CSharpResourceImpl* resource, Play resource->OnPlayerHealDelegate = delegate; } +void CSharpResourceImpl_SetGivePedScriptedTaskDelegate(CSharpResourceImpl* resource, GivePedScriptedTaskDelegate_t delegate) +{ + 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; +} + +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();