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
8
namespace
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
*/
31
virtual
AShooterGameMode
*
GetShooterGameMode
()
const
= 0;
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
*/
41
virtual
UShooterCheatManager
*
GetCheatManager
()
const
= 0;
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
>
52
FORCEINLINE
void
SendServerMessage
(
AShooterPlayerController
*
player_controller
,
FLinearColor
msg_color
,
const
T
*
msg
,
53
Args
&&...
args
)
54
{
55
if
(
player_controller
)
56
{
57
FString
text
(
FString
::
Format
(
msg
,
std
::
forward
<
Args
>(
args
)...));
58
player_controller
->
ClientServerChatDirectMessage
(&
text
,
msg_color
,
false
);
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
>
75
FORCEINLINE
void
SendNotification
(
AShooterPlayerController
*
player_controller
,
FLinearColor
color
,
float
display_scale
,
76
float
display_time
,
UTexture2D
*
icon
,
const
T
*
msg
,
Args
&&...
args
)
77
{
78
if
(
player_controller
)
79
{
80
FString
text
(
FString
::
Format
(
msg
,
std
::
forward
<
Args
>(
args
)...));
81
82
player_controller
->
ClientServerSOTFNotificationCustom
(&
text
,
color
,
display_scale
,
display_time
,
icon
,
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
>
97
FORCEINLINE
void
SendChatMessage
(
AShooterPlayerController
*
player_controller
,
const
FString
&
sender_name
,
const
T
*
msg
,
98
Args
&&...
args
)
99
{
100
if
(
player_controller
)
101
{
102
const
FString
text
(
FString
::
Format
(
msg
,
std
::
forward
<
Args
>(
args
)...));
103
104
FChatMessage
chat_message
=
FChatMessage
();
105
chat_message
.
SenderName
=
sender_name
;
106
chat_message
.
Message
=
text
;
107
108
player_controller
->
ClientChatMessage
(
chat_message
);
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
>
121
FORCEINLINE
void
SendServerMessageToAll
(
FLinearColor
msg_color
,
const
T
*
msg
,
122
Args
&&...
args
)
123
{
124
FString
text
(
FString
::
Format
(
msg
,
std
::
forward
<
Args
>(
args
)...));
125
126
const
auto
&
player_controllers
=
GetWorld
()->
PlayerControllerListField
();
127
for
(
TWeakObjectPtr
<
APlayerController
>
player_controller
:
player_controllers
)
128
{
129
AShooterPlayerController
*
shooter_pc
=
static_cast
<
AShooterPlayerController
*>(
player_controller
.
Get
());
130
if
(
shooter_pc
)
131
{
132
shooter_pc
->
ClientServerChatDirectMessage
(&
text
,
msg_color
,
false
);
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
>
149
FORCEINLINE
void
SendNotificationToAll
(
FLinearColor
color
,
float
display_scale
,
150
float
display_time
,
UTexture2D
*
icon
,
const
T
*
msg
,
Args
&&...
args
)
151
{
152
FString
text
(
FString
::
Format
(
msg
,
std
::
forward
<
Args
>(
args
)...));
153
154
const
auto
&
player_controllers
=
GetWorld
()->
PlayerControllerListField
();
155
for
(
TWeakObjectPtr
<
APlayerController
>
player_controller
:
player_controllers
)
156
{
157
AShooterPlayerController
*
shooter_pc
=
static_cast
<
AShooterPlayerController
*>(
player_controller
.
Get
());
158
if
(
shooter_pc
)
159
{
160
shooter_pc
->
161
ClientServerSOTFNotificationCustom
(&
text
,
color
,
display_scale
,
display_time
,
icon
,
nullptr
);
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
179
FChatMessage
chat_message
=
FChatMessage
();
180
chat_message
.
SenderName
=
sender_name
;
181
chat_message
.
Message
=
text
;
182
183
const
auto
&
player_controllers
=
GetWorld
()->
PlayerControllerListField
();
184
for
(
TWeakObjectPtr
<
APlayerController
>
player_controller
:
player_controllers
)
185
{
186
AShooterPlayerController
*
shooter_pc
=
static_cast
<
AShooterPlayerController
*>(
player_controller
.
Get
());
187
if
(
shooter_pc
)
188
{
189
shooter_pc
->
ClientChatMessage
(
chat_message
);
190
}
191
}
192
}
193
194
/**
195
* \brief Returns Steam ID from player controller
196
*/
197
static
FORCEINLINE
uint64
GetSteamIdFromController
(
AController
*
controller
)
198
{
199
uint64
steam_id
= 0;
200
201
AShooterPlayerController
*
playerController
=
static_cast
<
AShooterPlayerController
*>(
controller
);
202
if
(
playerController
!=
nullptr
)
203
{
204
steam_id
=
playerController
->
GetUniqueNetIdAsUINT64
();
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
*/
215
FORCEINLINE
AShooterPlayerController
*
FindPlayerFromSteamName
(
const
FString
&
steam_name
)
const
216
{
217
AShooterPlayerController
*
result
=
nullptr
;
218
219
const
auto
&
player_controllers
=
GetWorld
()->
PlayerControllerListField
();
220
for
(
TWeakObjectPtr
<
APlayerController
>
player_controller
:
player_controllers
)
221
{
222
const
FString
current_name
=
player_controller
->
PlayerStateField
()->
PlayerNameField
();
223
if
(
current_name
==
steam_name
)
224
{
225
auto
*
shooter_pc
=
static_cast
<
AShooterPlayerController
*>(
player_controller
.
Get
());
226
227
result
=
shooter_pc
;
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
*/
240
FORCEINLINE
AShooterPlayerController
*
FindControllerFromCharacter
(
AShooterCharacter
*
character
)
const
241
{
242
AShooterPlayerController
*
result
=
nullptr
;
243
244
if
(
character
!=
nullptr
245
&& !
character
->
IsDead
())
246
{
247
result
= (
character
->
GetOwnerController
()) ?
248
static_cast
<
AShooterPlayerController
*>(
character
->
GetOwnerController
())
249
:
250
static_cast
<
AShooterPlayerController
*>(
character
->
GetInstigatorController
());
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
*/
263
FORCEINLINE
TArray
<
AShooterPlayerController
*>
FindPlayerFromCharacterName
(
const
FString
&
character_name
,
264
ESearchCase
::
Type
search
,
265
bool
full_match
)
const
266
{
267
TArray
<
AShooterPlayerController
*>
found_players
;
268
269
const
auto
&
player_controllers
=
GetWorld
()->
PlayerControllerListField
();
270
for
(
TWeakObjectPtr
<
APlayerController
>
player_controller
:
player_controllers
)
271
{
272
auto
*
shooter_player
=
static_cast
<
AShooterPlayerController
*>(
player_controller
.
Get
());
273
FString
char_name
=
GetCharacterName
(
shooter_player
);
274
275
if
(!
char_name
.
IsEmpty
() && (
full_match
276
?
char_name
.
Equals
(
character_name
,
search
)
277
:
char_name
.
StartsWith
(
character_name
,
search
)))
278
{
279
found_players
.
Add
(
shooter_player
);
280
}
281
}
282
283
return
found_players
;
284
}
285
286
/**
287
* \brief Returns the character name of player
288
* \param player_controller Player
289
*/
290
static
FORCEINLINE
FString
GetCharacterName
(
AShooterPlayerController
*
player_controller
)
291
{
292
if
(
player_controller
!=
nullptr
)
293
{
294
FString
player_name
(
""
);
295
player_controller
->
GetPlayerCharacterName
(&
player_name
);
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
*/
306
static
FORCEINLINE
FString
GetSteamName
(
AController
*
player_controller
)
307
{
308
return
player_controller
!=
nullptr
?
player_controller
->
PlayerStateField
()->
PlayerNameField
() :
""
;
309
}
310
311
/**
312
* \brief Finds player from the given steam id
313
* \param steam_id Steam id
314
* \return Pointer to AShooterPlayerController
315
*/
316
FORCEINLINE
AShooterPlayerController
*
FindPlayerFromSteamId
(
uint64
steam_id
)
const
317
{
318
return
FindPlayerFromSteamId_Internal
(
steam_id
);
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
{
335
APlayerController
*
player
=
GetWorld
()->
GetFirstPlayerController
();
336
if
(!
player
)
337
{
338
return
false
;
339
}
340
341
UObject
*
object
=
Globals
::
342
StaticLoadObject
(
UObject
::
StaticClass
(),
nullptr
,
blueprint
,
nullptr
, 0, 0,
true
);
343
if
(!
object
)
344
{
345
return
false
;
346
}
347
348
TSubclassOf
<
UPrimalItem
>
archetype
;
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));
359
RtlSecureZeroMemory
(
info
, 0x400);
360
361
item
->
GetItemNetInfo
(
info
,
false
);
362
363
TSubclassOf
<
ADroppedItem
>
archetype_dropped
;
364
archetype_dropped
.
uClass
=
reinterpret_cast
<
UClass
*>(
object
);
365
366
FVector
zero_vector
{ 0, 0, 0 };
367
FRotator
rot
{ 0, 0, 0 };
368
369
UPrimalInventoryComponent
::
StaticDropItem
(
player
,
info
,
archetype_dropped
, &
rot
,
true
, &
pos
, &
rot
,
true
,
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
*/
387
FORCEINLINE
APrimalDinoCharacter
*
SpawnDino
(
AShooterPlayerController
*
player
,
FString
blueprint
,
FVector
*
location
,
int
lvl
,
388
bool
force_tame
,
bool
neutered
)
const
389
{
390
if
(
player
==
nullptr
)
391
{
392
player
=
static_cast
<
AShooterPlayerController
*>(
GetWorld
()->
GetFirstPlayerController
());
393
if
(
player
==
nullptr
)
394
{
395
return
nullptr
;
396
}
397
}
398
399
AActor
*
actor
=
player
->
SpawnActor
(&
blueprint
, 100, 0, 0,
true
);
400
if
(
actor
!=
nullptr
&&
actor
->
IsA
(
APrimalDinoCharacter
::
GetPrivateStaticClass
()))
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
{
412
dino
->
TamingTeamIDField
() =
player
->
TargetingTeamField
();
413
414
auto
*
state
=
static_cast
<
AShooterPlayerState
*>(
player
->
PlayerStateField
());
415
416
FString
player_name
;
417
state
->
GetPlayerName
(&
player_name
);
418
419
dino
->
TamerStringField
() =
player_name
;
420
421
state
->
SetTribeTamingDinoSettings
(
dino
);
422
423
dino
->
TameDino
(
player
,
true
, 0,
true
,
true
,
false
);
424
}
425
426
if
(
neutered
)
427
{
428
dino
->
DoNeuter_Implementation
();
429
}
430
431
dino
->
AbsoluteBaseLevelField
() =
lvl
;
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
*/
445
static
FORCEINLINE
bool
IsRidingDino
(
AShooterPlayerController
*
player_controller
)
446
{
447
return
player_controller
!=
nullptr
&&
player_controller
->
GetPlayerCharacter
() !=
nullptr
448
&&
player_controller
->
GetPlayerCharacter
()->
GetRidingDino
() !=
nullptr
;
449
}
450
451
/**
452
* \brief Returns the dino the character is riding
453
* \param player_controller Player
454
* \return APrimalDinoCharacter*
455
*/
456
static
FORCEINLINE
APrimalDinoCharacter
*
GetRidingDino
(
AShooterPlayerController
*
player_controller
)
457
{
458
return
player_controller
!=
nullptr
&&
player_controller
->
GetPlayerCharacter
() !=
nullptr
459
?
player_controller
->
GetPlayerCharacter
()->
GetRidingDino
()
460
:
nullptr
;
461
}
462
463
/**
464
* \brief Returns the position of a player
465
* \param player_controller Player
466
* \return FVector
467
*/
468
static
FORCEINLINE
FVector
GetPosition
(
APlayerController
*
player_controller
)
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
*/
480
static
FORCEINLINE
std
::
optional
<
FString
>
TeleportToPlayer
(
AShooterPlayerController
*
me
,
AShooterPlayerController
*
him
,
481
bool
check_for_dino
,
float
max_dist
)
482
{
483
if
(!(
me
!=
nullptr
&&
him
!=
nullptr
&&
me
->
GetPlayerCharacter
() !=
nullptr
&&
him
->
484
GetPlayerCharacter
()
485
!=
nullptr
486
&& !
me
->
GetPlayerCharacter
()->
IsDead
() && !
him
->
GetPlayerCharacter
()->
IsDead
())
487
)
488
{
489
return
"One of players is dead"
;
490
}
491
492
if
(
check_for_dino
&& (
IsRidingDino
(
me
) ||
IsRidingDino
(
him
)))
493
{
494
return
"One of players is riding a dino"
;
495
}
496
497
if
(
max_dist
!= -1 &&
FVector
::
Distance
(
GetPosition
(
me
),
GetPosition
(
him
)) >
max_dist
)
498
{
499
return
"Person is too far away"
;
500
}
501
502
const
FVector
pos
=
him
->
DefaultActorLocationField
();
503
504
me
->
SetPlayerPos
(
pos
.
X
,
pos
.
Y
,
pos
.
Z
);
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
*/
514
static
FORCEINLINE
bool
TeleportToPos
(
AShooterPlayerController
*
player_controller
,
const
FVector
&
pos
)
515
{
516
if
(
player_controller
!=
nullptr
&& !
IsPlayerDead
(
player_controller
))
517
{
518
player_controller
->
SetPlayerPos
(
pos
.
X
,
pos
.
Y
,
pos
.
Z
);
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
*/
531
static
FORCEINLINE
int
GetInventoryItemCount
(
AShooterPlayerController
*
player_controller
,
const
FString
&
item_name
)
532
{
533
if
(
player_controller
==
nullptr
)
534
{
535
return
-1;
536
}
537
538
UPrimalInventoryComponent
*
inventory_component
=
539
player_controller
->
GetPlayerCharacter
()->
MyInventoryComponentField
();
540
if
(
inventory_component
==
nullptr
)
541
{
542
return
-1;
543
}
544
545
FString
name
;
546
int
item_count
= 0;
547
548
for
(
UPrimalItem
*
item
:
inventory_component
->
InventoryItemsField
())
549
{
550
item
->
GetItemName
(&
name
,
true
,
false
,
nullptr
);
551
552
if
(
name
.
Equals
(
item_name
,
ESearchCase
::
IgnoreCase
))
553
{
554
item_count
+=
item
->
GetItemQuantity
();
555
}
556
}
557
558
return
item_count
;
559
}
560
561
/**
562
* \brief Returns IP address of player
563
*/
564
static
FORCEINLINE
FString
GetIPAddress
(
AShooterPlayerController
*
player
)
565
{
566
return
player
&&
player
->
GetNetConnection
() && !
player
->
GetNetConnection
()->
ClientGivenIPField
().
IsEmpty
() ?
player
->
GetNetConnection
()->
ClientGivenIPField
() :
""
;
567
}
568
569
/**
570
* \brief Returns blueprint from UPrimalItem
571
*/
572
static
FORCEINLINE
FString
GetItemBlueprint
(
UPrimalItem
*
item
)
573
{
574
return
GetBlueprint
(
item
);
575
}
576
577
/**
578
* \brief Returns true if player is dead, false otherwise
579
*/
580
static
FORCEINLINE
bool
IsPlayerDead
(
AShooterPlayerController
*
player
)
581
{
582
if
(
player
==
nullptr
||
player
->
GetPlayerCharacter
() ==
nullptr
)
583
{
584
return
true
;
585
}
586
587
return
player
->
GetPlayerCharacter
()->
IsDead
();
588
}
589
590
static
FORCEINLINE
uint64
GetPlayerID
(
APrimalCharacter
*
character
)
591
{
592
auto
*
shooter_character
=
static_cast
<
AShooterCharacter
*>(
character
);
593
return
shooter_character
!=
nullptr
&&
shooter_character
->
GetPlayerData
() !=
nullptr
594
?
shooter_character
->
GetPlayerData
()->
MyDataField
()->
PlayerDataIDField
()
595
: -1;
596
}
597
598
static
FORCEINLINE
uint64
GetPlayerID
(
AController
*
controller
)
599
{
600
auto
*
player
=
static_cast
<
AShooterPlayerController
*>(
controller
);
601
return
player
!=
nullptr
?
player
->
LinkedPlayerIDField
() : 0;
602
}
603
604
FORCEINLINE
uint64
GetSteamIDForPlayerID
(
int
player_id
)
const
605
{
606
uint64
steam_id
=
GetShooterGameMode
()->
GetSteamIDForPlayerID
(
player_id
);
607
if
(
steam_id
== 0)
608
{
609
const
auto
&
player_controllers
=
GetWorld
()->
PlayerControllerListField
();
610
for
(
TWeakObjectPtr
<
APlayerController
>
player_controller
:
player_controllers
)
611
{
612
auto
*
shooter_pc
=
static_cast
<
AShooterPlayerController
*>(
player_controller
.
Get
());
613
if
(
shooter_pc
!=
nullptr
&&
shooter_pc
->
LinkedPlayerIDField
() ==
player_id
)
614
{
615
steam_id
=
shooter_pc
->
GetUniqueNetIdAsUINT64
();
616
break
;
617
}
618
}
619
620
GetShooterGameMode
()->
AddPlayerID
(
player_id
,
steam_id
);
621
}
622
623
return
steam_id
;
624
}
625
626
/**
627
* \brief Returns blueprint path from any UObject
628
*/
629
static
FORCEINLINE
FString
GetBlueprint
(
UObjectBase
*
object
)
630
{
631
if
(
object
!=
nullptr
&&
object
->
ClassField
() !=
nullptr
)
632
{
633
return
GetClassBlueprint
(
object
->
ClassField
());
634
}
635
636
return
FString
(
""
);
637
}
638
639
/**
640
* \brief Returns blueprint path from any UClass
641
*/
642
static
FORCEINLINE
FString
GetClassBlueprint
(
UClass
*
the_class
)
643
{
644
if
(
the_class
!=
nullptr
)
645
{
646
FString
path
;
647
UVictoryCore
::
ClassToStringReference
(&
path
,
TSubclassOf
<
UObject
>(
the_class
));
648
return
"Blueprint'"
+
path
.
LeftChop
(2) +
"'"
;
649
}
650
651
return
FString
(
""
);
652
}
653
654
/**
655
* \brief Get Shooter Game State
656
*/
657
FORCEINLINE
AShooterGameState
*
GetGameState
()
658
{
659
return
static_cast
<
AShooterGameState
*>(
GetWorld
()->
GameStateField
());
660
}
661
662
/**
663
* \brief Get UShooterCheatManager* of player controller
664
*/
665
static
FORCEINLINE
UShooterCheatManager
*
GetCheatManagerByPC
(
AShooterPlayerController
*
SPC
)
666
{
667
if
(!
SPC
)
return
nullptr
;
668
669
UCheatManager
*
cheat
=
SPC
->
CheatManagerField
();
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
*/
682
static
FORCEINLINE
int
GetTribeID
(
AShooterPlayerController
*
player_controller
)
683
{
684
int
team
= 0;
685
686
if
(
player_controller
)
687
{
688
team
=
player_controller
->
TargetingTeamField
();
689
}
690
691
return
team
;
692
}
693
694
/**
695
* \brief Get Tribe ID of character
696
*/
697
static
FORCEINLINE
int
GetTribeID
(
AShooterCharacter
*
player_character
)
698
{
699
int
team
= 0;
700
701
if
(
player_character
)
702
{
703
team
=
player_character
->
TargetingTeamField
();
704
}
705
706
return
team
;
707
}
708
709
/**
710
* \brief Returns pointer to Primal Game Data
711
*/
712
FORCEINLINE
UPrimalGameData
*
GetGameData
()
713
{
714
UPrimalGlobals
*
singleton
=
static_cast
<
UPrimalGlobals
*>(
Globals
::
GEngine
()()->
GameSingletonField
());
715
return
(
singleton
->
PrimalGameDataOverrideField
() !=
nullptr
) ?
singleton
->
PrimalGameDataOverrideField
() :
singleton
->
PrimalGameDataField
();
716
}
717
718
/**
719
* \brief Gets all actors in radius at location
720
*/
721
FORCEINLINE
TArray
<
AActor
*>
GetAllActorsInRange
(
FVector
location
,
float
radius
,
EServerOctreeGroup
::
Type
ActorType
)
722
{
723
TArray
<
AActor
*>
out_actors
;
724
725
UVictoryCore
::
ServerOctreeOverlapActors
(&
out_actors
,
GetWorld
(),
location
,
radius
,
ActorType
,
true
);
726
727
return
out_actors
;
728
}
729
730
/**
731
* \brief Gets all actors in radius at location, with ignore actors
732
*/
733
FORCEINLINE
TArray
<
AActor
*>
GetAllActorsInRange
(
FVector
location
,
float
radius
,
EServerOctreeGroup
::
Type
ActorType
,
TArray
<
AActor
*>
ignores
)
734
{
735
TArray
<
AActor
*>
out_actors
;
736
737
UVictoryCore
::
ServerOctreeOverlapActors
(&
out_actors
,
GetWorld
(),
location
,
radius
,
ActorType
,
true
);
738
739
for
(
AActor
*
ignore
:
ignores
)
740
out_actors
.
Remove
(
ignore
);
741
742
return
out_actors
;
743
}
744
745
/**
746
* \brief Converts FVector into coords that are displayed when you view the ingame map
747
*/
748
FORCEINLINE
MapCoords
FVectorToCoords
(
FVector
actor_position
)
749
{
750
AWorldSettings
*
world_settings
=
GetWorld
()->
GetWorldSettings
(
false
,
true
);
751
APrimalWorldSettings
*
p_world_settings
=
static_cast
<
APrimalWorldSettings
*>(
world_settings
);
752
MapCoords
coords
;
753
754
float
lat_scale
=
p_world_settings
->
LatitudeScaleField
() != 0 ?
p_world_settings
->
LatitudeScaleField
() : 800.0f;
755
float
lon_scale
=
p_world_settings
->
LongitudeScaleField
() != 0 ?
p_world_settings
->
LongitudeScaleField
() : 800.0f;
756
757
float
lat_origin
=
p_world_settings
->
LatitudeOriginField
() != 0 ?
p_world_settings
->
LatitudeOriginField
() : -400000.0f;
758
float
lon_origin
=
p_world_settings
->
LongitudeOriginField
() != 0 ?
p_world_settings
->
LongitudeOriginField
() : -400000.0f;
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
*/
776
FORCEINLINE
uint64
GetAttackerSteamID
(
AActor
*
target
,
AController
*
killer
,
AActor
*
damage_causer
,
bool
tribe_check
=
true
)
777
{
778
uint64
steam_id
= NULL;
779
780
if
(
target
)
781
{
782
if
(
killer
&& !
killer
->
IsLocalController
() &&
killer
->
IsA
(
AShooterPlayerController
::
GetPrivateStaticClass
())
783
&& (!
tribe_check
|| (
tribe_check
&&
target
->
TargetingTeamField
() !=
killer
->
TargetingTeamField
())))
784
steam_id
=
GetSteamIdFromController
(
static_cast
<
AShooterPlayerController
*>(
killer
));
785
else
if
(
damage_causer
&& (!
tribe_check
|| (
tribe_check
&&
target
->
TargetingTeamField
() !=
damage_causer
->
TargetingTeamField
()))
786
&&
damage_causer
->
IsA
(
APrimalStructureExplosive
::
StaticClass
()))
787
{
788
APrimalStructureExplosive
*
explosive
=
static_cast
<
APrimalStructureExplosive
*>(
damage_causer
);
789
steam_id
=
GetSteamIDForPlayerID
(
explosive
->
ConstructorPlayerDataIDField
());
790
}
791
}
792
793
return
steam_id
;
794
}
795
796
void
RunHiddenCommand
(
AShooterPlayerController
*
_this
,
FString
*
Command
)
797
{
798
FString
result
;
799
HideCommand
=
true
;
800
_this
->
ConsoleCommand
(&
result
,
Command
,
false
);
801
HideCommand
=
false
;
802
}
803
private
:
804
virtual
AShooterPlayerController
*
FindPlayerFromSteamId_Internal
(
uint64
steam_id
)
const
= 0;
805
};
806
807
ARK_API
IApiUtils
& APIENTRY
GetApiUtils
();
808
}
// namespace ArkApi
ARK_API
#define ARK_API
Definition
Base.h:9
ArkApi::IApiUtils
Definition
AtlasApiUtils.h:12
ArkApi
Definition
ApiUtils.cpp:6
ArkApi::ServerStatus
ServerStatus
Definition
ArkApiUtils.h:10
ArkApi::GetApiUtils
IApiUtils & GetApiUtils()
Definition
ApiUtils.cpp:99
ArkApi::MapCoords
Definition
ArkApiUtils.h:13
Downloads
ArkServerAPI_NEW
ASE
AseApi-main
version
Core
Public
Ark
ArkApiUtils.h
Generated by
1.10.0