5#include <API/ARK/Ark.h>
6#include <../Private/Ark/Globals.h>
8#include "API/Helpers/Helpers.h"
25
26
30
31
35
36
40
41
44
45
46
47
48
49
50
51
52 template <
typename T,
typename... Args>
59
60
61
62
63
64
65
66
67
68
69
70 template <
typename T,
typename... Args>
72 float display_time,
UTexture2D* icon,
const T* msg, Args&&... args)
78
79
80
81
82
83
84
85
86 template <
typename T,
typename... Args>
94
95
96
97
98
99
100
101 template <
typename T,
typename... Args>
108
109
110
111
112
113
114
115
116
117
118 template <
typename T,
typename... Args>
120 float display_time,
UTexture2D* icon,
const T* msg, Args&&... args)
126
127
128
129
130
131
132
133 template <
typename T,
typename... Args>
140
141
147 if (playerController !=
nullptr)
148 playerController->GetUniqueNetIdAsString(&eos_id);
154
155
156
157
162 for (TWeakObjectPtr<APlayerController> player_controller : player_controllers)
164 const FString current_name = player_controller->PlayerStateField()->PlayerNamePrivateField();
165 if (current_name == steam_name)
167 auto* shooter_pc =
static_cast<AShooterPlayerController*>(player_controller.Get());
178
179
180
181
186 if (character !=
nullptr && !character
->IsDead())
193
194
195
196
197
198
203 TArray<AShooterPlayerController*> found_players;
205 for (TWeakObjectPtr<APlayerController> player_controller : player_controllers)
207 auto* shooter_player =
static_cast<AShooterPlayerController*>(player_controller.Get());
208 FString char_name = GetCharacterName(shooter_player);
210 if (!char_name.IsEmpty() && (full_match
211 ? char_name.Equals(character_name, search)
212 : char_name.StartsWith(character_name, search)))
214 found_players.Add(shooter_player);
217 return found_players;
221
222
223
226 if (player_controller !=
nullptr)
229 player_controller->GetPlayerCharacterName(&player_name);
237
238
239
242 return player_controller !=
nullptr ? player_controller->PlayerStateField()->PlayerNamePrivateField() :
"";
246
247
248
249
256
257
258
259
260
261
262
263
264
265
267 bool force_blueprint =
false,
float life_span = 0.0f)
const
276 UVictoryCore::StringReferenceToClass(&archetype, &bpFstr);
278 UPrimalItem* item = UPrimalItem::AddNewItem(archetype.uClass,
nullptr,
false,
false, item_quality,
false, amount, force_blueprint, 0,
false,
nullptr, 0, 0, 0,
true);
288 archetype_dropped.uClass = archetype.uClass;
290 FVector zero_vector{ 0, 0, 0 };
291 FRotator rot{ 0, 0, 0 };
293 UPrimalInventoryComponent::StaticDropItem(player, info, archetype_dropped, &rot,
true, &pos, &rot,
true,
false,
false,
true,
nullptr, &zero_vector,
nullptr, life_span);
300
301
302
303
304
305
306
307
308
310 bool force_tame,
bool neutered)
const
312 if (player ==
nullptr)
315 if (player ==
nullptr)
321 AActor* actor = player->SpawnActor(&blueprint, 100, 0, 0,
true);
326 if (location !=
nullptr && !location->IsZero())
328 FRotator rotation{ 0, 0, 0 };
329 dino->TeleportTo(location, &rotation,
true,
false);
336 auto* state =
static_cast<AShooterPlayerState*>(player->PlayerStateField().Get());
339 player->GetPlayerCharacterName(&player_name);
343 state->SetTribeTamingDinoSettings(dino);
363
364
365
368 return player_controller !=
nullptr && player_controller->GetPlayerCharacter() !=
nullptr
369 && player_controller->GetPlayerCharacter()->GetRidingDino() !=
nullptr;
373
374
375
376
379 return player_controller !=
nullptr && player_controller->GetPlayerCharacter() !=
nullptr
380 ? player_controller->GetPlayerCharacter()->GetRidingDino()
385
386
387
388
391 return player_controller !=
nullptr && player_controller->PawnField() !=
nullptr ? player_controller->PawnField()->RootComponentField()->RelativeLocationField() : FVector{0, 0, 0};
395
396
397
398
399
400
404 FVector him_position = GetPosition(him);
405 if (!(me !=
nullptr && him !=
nullptr && me->GetPlayerCharacter() !=
nullptr && him->
408 && !me->GetPlayerCharacter()->IsDead() && !him->GetPlayerCharacter()->IsDead())
411 return "One of players is dead";
416 return "One of players is riding a dino";
419 if (max_dist != -1 && FVector::Distance(GetPosition(me), him_position) > max_dist)
421 return "Person is too far away";
424 if (him_position.IsNearlyZero())
426 return "Player location is invalid";
429 me->SetPlayerPos((
float)him_position.X, (
float)him_position.Y, (
float)him_position.Z);
435
436
437
438
441 if (player_controller !=
nullptr && !
IsPlayerDead(player_controller
))
443 player_controller->SetPlayerPos((
float)pos.X, (
float)pos.Y, (
float)pos.Z);
451
452
453
454
455
458 if (player_controller ==
nullptr)
464 player_controller->GetPlayerCharacter()->MyInventoryComponentField();
465 if (inventory_component ==
nullptr)
473 for (UPrimalItem* item : inventory_component->InventoryItemsField())
475 item->GetItemName(&name,
true,
false,
nullptr);
477 if (name.Equals(item_name, ESearchCase::IgnoreCase))
479 item_count += item->GetItemQuantity();
487
488
498
499
506
507
510 if (player ==
nullptr || player->GetPlayerCharacter() ==
nullptr)
515 return player->GetPlayerCharacter()->IsDead();
521 return shooter_character !=
nullptr && shooter_character
->GetPlayerData() !=
nullptr
545 for (TWeakObjectPtr<APlayerController> player_controller : player_controllers)
547 auto* shooter_pc =
static_cast<AShooterPlayerController*>(player_controller.Get());
548 if (shooter_pc !=
nullptr && shooter_pc->LinkedPlayerIDField() == player_id)
550 shooter_pc->GetUniqueNetIdAsString(&eos_id);
565
566
579
580
583 if (the_class !=
nullptr)
591 return "Blueprint'" + path
+ "'";
598
599
602 return static_cast<AShooterGameState*>(GetWorld()->GameStateField().Get());
606
607
610 if (!SPC)
return nullptr;
623
624
629 if (player_controller)
638
639
644 if (player_character)
653
654
657 UPrimalGlobals* singleton =
static_cast<UPrimalGlobals*>(Globals::GEngine()()->GameSingletonField().Get());
662
663
666 TArray<AActor*> out_actors;
668 UVictoryCore::ServerOctreeOverlapActors(&out_actors, GetWorld(), &location, radius, ActorType,
true);
674
675
678 TArray<AActor*> out_actors;
680 UVictoryCore::ServerOctreeOverlapActors(&out_actors, GetWorld(), &location, radius, ActorType,
true);
682 for (AActor* ignore : ignores)
683 out_actors.Remove(ignore);
689
690
703 float lat_div = 100.f / lat_scale;
704 float lat = (lat_div * (
float)actor_position.Y + lat_div * abs(lat_origin)) / 1000.f;
706 float lon_div = 100.f / lon_scale;
707 float lon = (lon_div * (
float)actor_position.X + lon_div * abs(lon_origin)) / 1000.f;
709 coords.x = std::floor(lon * 10.0f) / 10.0f;
710 coords.y = std::floor(lat * 10.0f) / 10.0f;
715
716
717
739
740
741
742
753
754
755
762
763
764
765
775
776
777
780 return GetMessagingManagerInternal(GetDllName());
784
785
786
787
796
797
798
std::unordered_map< const FString, AShooterPlayerController *, FStringHash, FStringEqual > eos_id_map_
void SetStatus(ServerStatus status)
std::shared_ptr< MessagingManager > GetMessagingManagerInternal(const FString &forPlugin) const override
void SetCheatManager(UShooterCheatManager *cheatmanager)
ApiUtils(const ApiUtils &)=delete
std::shared_ptr< MessagingManager > ReadApiMessagingManager()
UShooterCheatManager * GetCheatManager() const override
Returns a point to URCON CheatManager.
ApiUtils(ApiUtils &&)=delete
void CheckMessagingManagersRequirements()
AShooterPlayerController * FindPlayerFromEOSID_Internal(const FString &eos_id) const override
AShooterGameMode * GetShooterGameMode() const override
Returns a pointer to AShooterGameMode.
ApiUtils & operator=(const ApiUtils &)=delete
void SetShooterGameMode(AShooterGameMode *shooter_game_mode)
void RemoveMessagingManagerInternal(const FString &forPlugin)
ApiUtils & operator=(ApiUtils &&)=delete
AShooterGameMode * shooter_game_mode_
UWorld * GetWorld() const override
Returns a pointer to UWorld.
void SetMessagingManagerInternal(const FString &forPlugin, std::shared_ptr< MessagingManager > manager) override
ServerStatus GetStatus() const override
Returns the current server status.
void SetPlayerController(AShooterPlayerController *player_controller)
void RemovePlayerController(AShooterPlayerController *player_controller)
~ApiUtils() override=default
void SetWorld(UWorld *uworld)
UShooterCheatManager * cheatmanager_
FORCEINLINE AShooterGameState * GetGameState()
Get Shooter Game State.
virtual UShooterCheatManager * GetCheatManager() const =0
Returns a point to URCON CheatManager.
FORCEINLINE void SendNotificationToAll(FLinearColor color, float display_scale, float display_time, UTexture2D *icon, const T *msg, Args &&... args)
Sends notification (on-screen message) to all players. Using fmt::format.
FORCEINLINE TArray< AActor * > GetAllActorsInRange(FVector location, float radius, EServerOctreeGroup::Type ActorType)
Gets all actors in radius at location.
FORCEINLINE std::shared_ptr< T > GetMessagingManagerCasted() const
Gets the current messaging manager for the plugin.
FORCEINLINE MapCoords FVectorToCoords(FVector actor_position)
Converts FVector into coords that are displayed when you view the ingame map.
FORCEINLINE const FString GetAttackerEOSID(AActor *target, AController *killer, AActor *damage_causer, bool tribe_check=true)
obtains the steam ID of an attacker, meant to be used in hooks such as TakeDamage
static FORCEINLINE FString GetClassBlueprint(UClass *the_class)
Returns blueprint path from any UClass.
FORCEINLINE AShooterPlayerController * FindPlayerFromEOSID(const FString &eos_id) const
Finds player from the given eos id.
virtual ~IApiUtils()=default
FORCEINLINE void SendNotification(AShooterPlayerController *player_controller, FLinearColor color, float display_scale, float display_time, UTexture2D *icon, const T *msg, Args &&... args)
Sends notification (on-screen message) to the specific player. Using fmt::format.
static FORCEINLINE APrimalDinoCharacter * GetRidingDino(AShooterPlayerController *player_controller)
Returns the dino the character is riding.
FORCEINLINE void SendServerMessageToAll(FLinearColor msg_color, const T *msg, Args &&... args)
Sends server message to all players. Using fmt::format.
static FORCEINLINE int GetTribeID(AShooterCharacter *player_character)
Get Tribe ID of character.
static FORCEINLINE int GetTribeID(AShooterPlayerController *player_controller)
Get Tribe ID of player controller.
static FORCEINLINE uint64 GetPlayerID(AController *controller)
FORCEINLINE TArray< AActor * > GetAllActorsInRange(FVector location, float radius, EServerOctreeGroup::Type ActorType, TArray< AActor * > ignores)
Gets all actors in radius at location, with ignore actors.
FORCEINLINE std::shared_ptr< MessagingManager > GetMessagingManager() const
Gets the current messaging manager for the plugin, without casting.
static FORCEINLINE FVector GetPosition(APlayerController *player_controller)
Returns the position of a player.
FORCEINLINE void SendServerMessage(AShooterPlayerController *player_controller, FLinearColor msg_color, const T *msg, Args &&... args)
Sends server message to the specific player. Using fmt::format.
FORCEINLINE TArray< AShooterPlayerController * > FindPlayerFromCharacterName(const FString &character_name, ESearchCase::Type search, bool full_match) const
Finds all matching players from the given character name.
static FORCEINLINE bool IsRidingDino(AShooterPlayerController *player_controller)
Returns true if character is riding a dino, false otherwise.
static FORCEINLINE uint64 GetPlayerID(APrimalCharacter *character)
FORCEINLINE UPrimalGameData * GetGameData()
Returns pointer to Primal Game Data.
virtual std::shared_ptr< MessagingManager > GetMessagingManagerInternal(const FString &forPlugin) const =0
static FORCEINLINE void FreeStruct(void *obj)
Free a struct allocated.
static FORCEINLINE UShooterCheatManager * GetCheatManagerByPC(AShooterPlayerController *SPC)
Get UShooterCheatManager* of player controller.
FORCEINLINE AShooterPlayerController * FindControllerFromCharacter(AShooterCharacter *character) const
Finds player controller from the given player character.
static FORCEINLINE FString GetIPAddress(AShooterPlayerController *player)
Returns IP address of player.
static FORCEINLINE std::optional< FString > TeleportToPlayer(AShooterPlayerController *me, AShooterPlayerController *him, bool check_for_dino, float max_dist)
Teleport one player to another.
FORCEINLINE bool SpawnDrop(const wchar_t *blueprint, FVector pos, int amount, float item_quality=0.0f, bool force_blueprint=false, float life_span=0.0f) const
Spawns an item drop.
void SetMessagingManager()
Sets the messaging manager for the current plugin.
static FORCEINLINE bool TeleportToPos(AShooterPlayerController *player_controller, const FVector &pos)
Teleports player to the given position.
virtual void SetMessagingManagerInternal(const FString &forPlugin, std::shared_ptr< MessagingManager > manager)=0
static FORCEINLINE bool IsPlayerDead(AShooterPlayerController *player)
Returns true if player is dead, false otherwise.
virtual AShooterGameMode * GetShooterGameMode() const =0
Returns a pointer to AShooterGameMode.
static FORCEINLINE FString GetSteamName(AController *player_controller)
Returns the steam name of player.
static FORCEINLINE FString GetCharacterName(AShooterPlayerController *player_controller)
Returns the character name of player.
FORCEINLINE void SendChatMessage(AShooterPlayerController *player_controller, const FString &sender_name, const T *msg, Args &&... args)
Sends chat message to the specific player. Using fmt::format.
FORCEINLINE AShooterPlayerController * FindPlayerFromPlatformName(const FString &steam_name) const
Finds player from the given platform name (can be steam, Playstation, Xbox, etc......
virtual ServerStatus GetStatus() const =0
Returns the current server status.
FORCEINLINE const FString GetEOSIDForPlayerID(int player_id)
FORCEINLINE APrimalDinoCharacter * SpawnDino(AShooterPlayerController *player, FString blueprint, FVector *location, int lvl, bool force_tame, bool neutered) const
Spawns a dino near player or at specific coordinates.
static FORCEINLINE FString GetItemBlueprint(UPrimalItem *item)
Returns blueprint from UPrimalItem.
FORCEINLINE void SendChatMessageToAll(const FString &sender_name, const T *msg, Args &&... args)
Sends chat message to all players. Using fmt::format.
static FORCEINLINE FString GetEOSIDFromController(AController *controller)
Returns EOS ID from player controller.
static FORCEINLINE int GetInventoryItemCount(AShooterPlayerController *player_controller, const FString &item_name)
Counts a specific items quantity.
static FORCEINLINE T * AllocateStruct()
Create a new object of T, with the correct size.
void RunHiddenCommand(AShooterPlayerController *_this, FString *Command)
Runs a command that is not logged anywhere.
static FORCEINLINE FString GetBlueprint(UObjectBase *object)
Returns blueprint path from any UObject.
virtual UWorld * GetWorld() const =0
Returns a pointer to UWorld.
virtual AShooterPlayerController * FindPlayerFromEOSID_Internal(const FString &eos_id) const =0
UE_NODISCARD bool EndsWith(const TCHAR *InSuffix, ESearchCase::Type SearchCase=ESearchCase::IgnoreCase) const
UE_NODISCARD FORCEINLINE friend FString operator+(const TCHAR *Lhs, FString &&Rhs)
UE_NODISCARD FORCEINLINE friend FString operator+(FString &&Lhs, const TCHAR *Rhs)
FString & operator=(FString &&)=default
UE_NODISCARD FORCEINLINE bool IsEmpty() const
ARK_API FString(const WIDECHAR *Str)
ARK_API FString(const ANSICHAR *Str)
UE_NODISCARD FORCEINLINE friend FString operator+(const TCHAR *Lhs, const FString &Rhs)
UE_NODISCARD FORCEINLINE FString LeftChop(int32 Count) const &
FString & operator=(const FString &)=default
Messaging manager. Allows to send server messages, notifications and chat messages.
IApiUtils & GetApiUtils()
static UClass * GetPrivateStaticClass()
FString * ConsoleCommand(FString *result, const FString *Cmd, bool bWriteToLog)
FString * GetPlayerNetworkAddress(FString *result)
void DoNeuter_Implementation()
void TameDino(AShooterPlayerController *ForPC, bool bIgnoreMaxTameLimit, int OverrideTamingTeamID, bool bPreventNameDialog, bool bSkipAddingTamedLevels, bool bSuppressNotifications)
static UClass * GetPrivateStaticClass()
int & TamingTeamIDField()
FString & TamerStringField()
int & AbsoluteBaseLevelField()
APlayerController * GetOwnerController()
unsigned int & ConstructorPlayerDataIDField()
static UClass * StaticClass()
float & LongitudeOriginField()
float & LatitudeOriginField()
float & LongitudeScaleField()
float & LatitudeScaleField()
UPrimalPlayerData * GetPlayerData()
void AddPlayerID(int playerDataID, FString *netUniqueString, bool bForce)
FString * GetSteamIDStringForPlayerID(FString *result, int playerDataID)
__int64 & LinkedPlayerIDField()
bool IsA(UClass *SomeBase)
Returns if the actor is from SomeBase or a subclass of SomeBase.
static void Free(void *Original)
unsigned __int64 & PlayerDataIDField()
UClass *& ClassPrivateField()
void GetPathName(const UObject *StopOuter, FString *ResultString)
int & TargetingTeamField()
UPrimalGameData *& PrimalGameDataField()
UPrimalGameData *& PrimalGameDataOverrideField()
FItemNetInfo * GetItemNetInfo(FItemNetInfo *result, bool bIsForSendingToClient)
FPrimalPlayerDataStruct * MyDataField()
static UObject * GetClassDefaultObject(UClass *FromClass)
TArray< TWeakObjectPtr< APlayerController >, TSizedDefaultAllocator< 32 > > & PlayerControllerListField()
APlayerController * GetFirstPlayerController()
AWorldSettings * GetWorldSettings(bool bCheckStreamingPersistent, bool bChecked)