Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
ArkApiUtils.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4
5#include <API/ARK/Ark.h>
6#include <../Private/Ark/Globals.h>
7
8namespace ArkApi
9{
10 enum class ServerStatus { Loading, Ready };
11
12 struct MapCoords
13 {
14 float x = 0.f;
15 float y = 0.f;
16 };
17
18 class ARK_API IApiUtils
19 {
20 public:
21 virtual ~IApiUtils() = default;
22 //bool HideCommand = false;
23 /**
24 * \brief Returns a pointer to UWorld
25 */
26 virtual UWorld* GetWorld() const = 0;
27
28 /**
29 * \brief Returns a pointer to AShooterGameMode
30 */
32
33 /**
34 * \brief Returns the current server status
35 */
36 virtual ServerStatus GetStatus() const = 0;
37
38 /**
39 * \brief Returns a point to URCON CheatManager
40 */
42 /**
43 * \brief Sends server message to the specific player. Using fmt::format.
44 * \tparam T Either a a char or wchar_t
45 * \tparam Args Optional arguments types
46 * \param player_controller Player
47 * \param msg_color Message color
48 * \param msg Message
49 * \param args Optional arguments
50 */
51 template <typename T, typename... Args>
53 Args&&... args)
54 {
56 {
59 }
60 }
61
62 /**
63 * \brief Sends notification (on-screen message) to the specific player. Using fmt::format.
64 * \tparam T Either a a char or wchar_t
65 * \tparam Args Optional arguments types
66 * \param player_controller Player
67 * \param color Message color
68 * \param display_scale Size of text
69 * \param display_time Display time
70 * \param icon Message icon (optional)
71 * \param msg Message
72 * \param args Optional arguments
73 */
74 template <typename T, typename... Args>
76 float display_time, UTexture2D* icon, const T* msg, Args&&... args)
77 {
79 {
81
83 nullptr);
84 }
85 }
86
87 /**
88 * \brief Sends chat message to the specific player. Using fmt::format.
89 * \tparam T Either a a char or wchar_t
90 * \tparam Args Optional arguments types
91 * \param player_controller Player
92 * \param sender_name Name of the sender
93 * \param msg Message
94 * \param args Optional arguments
95 */
96 template <typename T, typename... Args>
98 Args&&... args)
99 {
101 {
102 const FString text(FString::Format(msg, std::forward<Args>(args)...));
103
107
109 }
110 }
111
112 /**
113 * \brief Sends server message to all players. Using fmt::format.
114 * \tparam T Either a a char or wchar_t
115 * \tparam Args Optional arguments types
116 * \param msg_color Message color
117 * \param msg Message
118 * \param args Optional arguments
119 */
120 template <typename T, typename... Args>
122 Args&&... args)
123 {
125
128 {
130 if (shooter_pc)
131 {
133 }
134 }
135 }
136
137 /**
138 * \brief Sends notification (on-screen message) to all players. Using fmt::format.
139 * \tparam T Either a a char or wchar_t
140 * \tparam Args Optional arguments types
141 * \param color Message color
142 * \param display_scale Size of text
143 * \param display_time Display time
144 * \param icon Message icon (optional)
145 * \param msg Message
146 * \param args Optional arguments
147 */
148 template <typename T, typename... Args>
150 float display_time, UTexture2D* icon, const T* msg, Args&&... args)
151 {
153
156 {
158 if (shooter_pc)
159 {
160 shooter_pc->
162 }
163 }
164 }
165
166 /**
167 * \brief Sends chat message to all players. Using fmt::format.
168 * \tparam T Either a a char or wchar_t
169 * \tparam Args Optional arguments types
170 * \param sender_name Name of the sender
171 * \param msg Message
172 * \param args Optional arguments
173 */
174 template <typename T, typename... Args>
175 FORCEINLINE void SendChatMessageToAll(const FString& sender_name, const T* msg, Args&&... args)
176 {
177 const FString text(FString::Format(msg, std::forward<Args>(args)...));
178
182
185 {
187 if (shooter_pc)
188 {
190 }
191 }
192 }
193
194 /**
195 * \brief Returns Steam ID from player controller
196 */
198 {
199 uint64 steam_id = 0;
200
202 if (playerController != nullptr)
203 {
205 }
206
207 return steam_id;
208 }
209
210 /**
211 * \brief Finds player from the given steam name
212 * \param steam_name Steam name
213 * \return Pointer to AShooterPlayerController
214 */
216 {
218
221 {
224 {
226
228 break;
229 }
230 }
231
232 return result;
233 }
234
235 /**
236 * \brief Finds player controller from the given player character
237 * \param character Player character
238 * \return Pointer to AShooterPlayerController
239 */
241 {
243
244 if (character != nullptr
245 && !character->IsDead())
246 {
249 :
251 }
252
253 return result;
254 }
255
256 /**
257 * \brief Finds all matching players from the given character name
258 * \param character_name Character name
259 * \param search Type Defaulted To ESearchCase::Type::IgnoreCase
260 * \param full_match Will match the full length of the string if true
261 * \return Array of AShooterPlayerController*
262 */
265 bool full_match) const
266 {
268
271 {
274
275 if (!char_name.IsEmpty() && (full_match
278 {
280 }
281 }
282
283 return found_players;
284 }
285
286 /**
287 * \brief Returns the character name of player
288 * \param player_controller Player
289 */
291 {
292 if (player_controller != nullptr)
293 {
296 return player_name;
297 }
298
299 return FString("");
300 }
301
302 /**
303 * \brief Returns the steam name of player
304 * \param player_controller Player
305 */
307 {
309 }
310
311 /**
312 * \brief Finds player from the given steam id
313 * \param steam_id Steam id
314 * \return Pointer to AShooterPlayerController
315 */
317 {
319 }
320
321 /**
322 * \brief Spawns an item drop
323 * \param blueprint Item simplified BP
324 * Example: '/Game/PrimalEarth/CoreBlueprints/Items/Armor/Riot/PrimalItemArmor_RiotPants.PrimalItemArmor_RiotPants_C'
325 * \param pos Spawn position
326 * \param amount Quantity
327 * \param item_quality Quality
328 * \param force_blueprint Is blueprint
329 * \param life_span Life span
330 * \return Returns true if drop was spawned, false otherwise
331 */
332 FORCEINLINE bool SpawnDrop(const wchar_t* blueprint, FVector pos, int amount, float item_quality = 0.0f,
333 bool force_blueprint = false, float life_span = 0.0f) const
334 {
336 if (!player)
337 {
338 return false;
339 }
340
342 StaticLoadObject(UObject::StaticClass(), nullptr, blueprint, nullptr, 0, 0, true);
343 if (!object)
344 {
345 return false;
346 }
347
349 archetype.uClass = reinterpret_cast<UClass*>(object);
350
351 UPrimalItem* item = UPrimalItem::AddNewItem(archetype, nullptr, false, false, item_quality, false, amount,
352 force_blueprint, 0, false, nullptr, 0, 0, 0);
353 if (!item)
354 {
355 return false;
356 }
357
358 FItemNetInfo* info = static_cast<FItemNetInfo*>(FMemory::Malloc(0x400));
360
361 item->GetItemNetInfo(info, false);
362
364 archetype_dropped.uClass = reinterpret_cast<UClass*>(object);
365
366 FVector zero_vector{ 0, 0, 0 };
367 FRotator rot{ 0, 0, 0 };
368
370 false, false, true, nullptr, &zero_vector, nullptr, life_span);
371
372 FMemory::Free(info);
373
374 return true;
375 }
376
377 /**
378 * \brief Spawns a dino near player or at specific coordinates
379 * \param player Player. If null, random player will be chosen. At least one player should be on the map
380 * \param blueprint Blueprint path
381 * \param location Spawn position. If null, dino will be spawned near player
382 * \param lvl Level of the dino
383 * \param force_tame Force tame
384 * \param neutered Neuter dino
385 * \return Spawned dino or null
386 */
388 bool force_tame, bool neutered) const
389 {
390 if (player == nullptr)
391 {
393 if (player == nullptr)
394 {
395 return nullptr;
396 }
397 }
398
399 AActor* actor = player->SpawnActor(&blueprint, 100, 0, 0, true);
401 {
402 auto* dino = static_cast<APrimalDinoCharacter*>(actor);
403
404 if (location != nullptr && !location->IsZero())
405 {
406 FRotator rotation{ 0, 0, 0 };
407 dino->TeleportTo(location, &rotation, true, false);
408 }
409
410 if (force_tame)
411 {
413
414 auto* state = static_cast<AShooterPlayerState*>(player->PlayerStateField());
415
418
420
422
423 dino->TameDino(player, true, 0, true, true, false);
424 }
425
426 if (neutered)
427 {
429 }
430
432
433 dino->BeginPlay();
434
435 return dino;
436 }
437
438 return nullptr;
439 }
440
441 /**
442 * \brief Returns true if character is riding a dino, false otherwise
443 * \param player_controller Player
444 */
446 {
447 return player_controller != nullptr && player_controller->GetPlayerCharacter() != nullptr
449 }
450
451 /**
452 * \brief Returns the dino the character is riding
453 * \param player_controller Player
454 * \return APrimalDinoCharacter*
455 */
457 {
458 return player_controller != nullptr && player_controller->GetPlayerCharacter() != nullptr
460 : nullptr;
461 }
462
463 /**
464 * \brief Returns the position of a player
465 * \param player_controller Player
466 * \return FVector
467 */
469 {
470 return player_controller != nullptr ? player_controller->DefaultActorLocationField() : FVector{ 0, 0, 0 };
471 }
472
473 /**
474 * \brief Teleport one player to another
475 * \param me Player
476 * \param him Other Player
477 * \param check_for_dino If set true prevents players teleporting with dino's or teleporting to a player on a dino
478 * \param max_dist Is the max distance the characters can be away from each other -1 is disabled
479 */
481 bool check_for_dino, float max_dist)
482 {
483 if (!(me != nullptr && him != nullptr && me->GetPlayerCharacter() != nullptr && him->
485 != nullptr
487 )
488 {
489 return "One of players is dead";
490 }
491
493 {
494 return "One of players is riding a dino";
495 }
496
498 {
499 return "Person is too far away";
500 }
501
503
505
506 return {};
507 }
508
509 /**
510 * \brief Teleports player to the given position
511 * \param player_controller Player
512 * \param pos New position
513 */
515 {
517 {
519 return true;
520 }
521
522 return false;
523 }
524
525 /**
526 * \brief Counts a specific items quantity
527 * \param player_controller Player
528 * \param item_name The name of the item you want to count the quantity of
529 * \return On success, the function returns amount of items player has. Returns -1 if the function has failed.
530 */
532 {
533 if (player_controller == nullptr)
534 {
535 return -1;
536 }
537
540 if (inventory_component == nullptr)
541 {
542 return -1;
543 }
544
546 int item_count = 0;
547
549 {
550 item->GetItemName(&name, true, false, nullptr);
551
553 {
555 }
556 }
557
558 return item_count;
559 }
560
561 /**
562 * \brief Returns IP address of player
563 */
565 {
567 }
568
569 /**
570 * \brief Returns blueprint from UPrimalItem
571 */
573 {
574 return GetBlueprint(item);
575 }
576
577 /**
578 * \brief Returns true if player is dead, false otherwise
579 */
581 {
582 if (player == nullptr || player->GetPlayerCharacter() == nullptr)
583 {
584 return true;
585 }
586
587 return player->GetPlayerCharacter()->IsDead();
588 }
589
591 {
592 auto* shooter_character = static_cast<AShooterCharacter*>(character);
593 return shooter_character != nullptr && shooter_character->GetPlayerData() != nullptr
595 : -1;
596 }
597
599 {
600 auto* player = static_cast<AShooterPlayerController*>(controller);
601 return player != nullptr ? player->LinkedPlayerIDField() : 0;
602 }
603
605 {
607 if (steam_id == 0)
608 {
611 {
613 if (shooter_pc != nullptr && shooter_pc->LinkedPlayerIDField() == player_id)
614 {
616 break;
617 }
618 }
619
621 }
622
623 return steam_id;
624 }
625
626 /**
627 * \brief Returns blueprint path from any UObject
628 */
630 {
631 if (object != nullptr && object->ClassField() != nullptr)
632 {
634 }
635
636 return FString("");
637 }
638
639 /**
640 * \brief Returns blueprint path from any UClass
641 */
643 {
644 if (the_class != nullptr)
645 {
648 return "Blueprint'" + path.LeftChop(2) + "'";
649 }
650
651 return FString("");
652 }
653
654 /**
655 * \brief Get Shooter Game State
656 */
658 {
659 return static_cast<AShooterGameState*>(GetWorld()->GameStateField());
660 }
661
662 /**
663 * \brief Get UShooterCheatManager* of player controller
664 */
666 {
667 if (!SPC) return nullptr;
668
670
671 if (cheat)
672 {
673 return static_cast<UShooterCheatManager*>(cheat);
674 }
675
676 return nullptr;
677 }
678
679 /**
680 * \brief Get Tribe ID of player controller
681 */
683 {
684 int team = 0;
685
687 {
689 }
690
691 return team;
692 }
693
694 /**
695 * \brief Get Tribe ID of character
696 */
698 {
699 int team = 0;
700
702 {
704 }
705
706 return team;
707 }
708
709 /**
710 * \brief Returns pointer to Primal Game Data
711 */
713 {
716 }
717
718 /**
719 * \brief Gets all actors in radius at location
720 */
722 {
724
726
727 return out_actors;
728 }
729
730 /**
731 * \brief Gets all actors in radius at location, with ignore actors
732 */
734 {
736
738
739 for (AActor* ignore : ignores)
741
742 return out_actors;
743 }
744
745 /**
746 * \brief Converts FVector into coords that are displayed when you view the ingame map
747 */
749 {
753
756
759
760 float lat_div = 100.f / lat_scale;
761 float lat = (lat_div * actor_position.Y + lat_div * abs(lat_origin)) / 1000.f;
762
763 float lon_div = 100.f / lon_scale;
764 float lon = (lon_div * actor_position.X + lon_div * abs(lon_origin)) / 1000.f;
765
766 coords.x = std::floor(lon * 10.0f) / 10.0f;
767 coords.y = std::floor(lat * 10.0f) / 10.0f;
768
769 return coords;
770 }
771
772 /**
773 * \brief obtains the steam ID of an attacker, meant to be used in hooks such as TakeDamage
774 * \param tribe_check if set to true will return NULL if the target is from the same tribe as the attacker
775 */
777 {
778 uint64 steam_id = NULL;
779
780 if (target)
781 {
787 {
790 }
791 }
792
793 return steam_id;
794 }
795
797 {
799 HideCommand = true;
801 HideCommand = false;
802 }
803 private:
805 };
806
807 ARK_API IApiUtils& APIENTRY GetApiUtils();
808} // namespace ArkApi
#define ARK_API
Definition Base.h:9
IApiUtils & GetApiUtils()
Definition ApiUtils.cpp:99