Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added RCON structure and dino destruction commands #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,4 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk
/libs/SignalR-Client-Cpp/cpprest_2_10.lib
9 changes: 9 additions & 0 deletions ArkBotLink/ApiExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ namespace ArkExtensions
float& LongitudeOriginField() { return *GetNativePointerField<float*>(this, "APrimalWorldSettings.LongitudeOrigin"); }
float& LatitudeOriginField() { return *GetNativePointerField<float*>(this, "APrimalWorldSettings.LatitudeOrigin"); }
};

inline bool IsPointInside2dCircle(FVector point, float circleX, float circleY, float circleRadius)
{
long double x = point.X - circleX;
long double y = point.Y - circleY;

long double distancesq = x * x + y * y;
return distancesq < circleRadius * circleRadius;
}
}
10 changes: 8 additions & 2 deletions ArkBotLink/ArkBotLink.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DestroyDinosForTeamId.cpp" />
<ClCompile Include="DestroyStructuresForTeamId.cpp" />
<ClCompile Include="DestroyStructuresForTeamIdAtPos.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="CrossServerChat.cpp" />
<ClCompile Include="Hooks.cpp" />
Expand All @@ -31,6 +34,9 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="ApiExtensions.h" />
<ClInclude Include="DestroyDinosForTeamId.h" />
<ClInclude Include="DestroyStructuresForTeamId.h" />
<ClInclude Include="DestroyStructuresForTeamIdAtPos.h" />
<ClInclude Include="Plugin.h" />
<ClInclude Include="CrossServerChat.h" />
<ClInclude Include="Hooks.h" />
Expand Down Expand Up @@ -104,8 +110,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>../libs/SignalR-Client-Cpp/includes;C:\Users\Tobias\Downloads\ARK-Server-API-3.2-986ce4a871cf4f4edd92b79ff94ae1d7093cedfd\version\Core\Public;$(IncludePath)</IncludePath>
<LibraryPath>C:\Users\Tobias\Downloads\ARK-Server-API-3.2-986ce4a871cf4f4edd92b79ff94ae1d7093cedfd\out_lib;$(LibraryPath)</LibraryPath>
<IncludePath>../libs/SignalR-Client-Cpp/includes;C:\Users\avtoj\Desktop\arkServer\API 3.2\version\Core\Public;$(IncludePath)</IncludePath>
<LibraryPath>C:\Users\avtoj\Desktop\arkServer\API 3.2\out_lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down
59 changes: 59 additions & 0 deletions ArkBotLink/DestroyDinosForTeamId.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "DestroyDinosForTeamId.h"

std::string DestroyDinosForTeamIdInternal(FString* cmd)
{
TArray<FString> Parsed;
cmd->ParseIntoArray(Parsed, L" ", true);

if (Parsed.IsValidIndex(1))
{
int teamId;

try
{
teamId = std::stoi(*Parsed[1]);
}
catch (const std::exception&)
{
return {};
}

if (teamId < 10000) return {};

UWorld* world = ArkApi::GetApiUtils().GetWorld();
if (!world) return {};

TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(world, APrimalDinoCharacter::GetPrivateStaticClass(), &FoundActors);

int num = 0;
for (const auto& actor : FoundActors)
{
APrimalDinoCharacter* dino = static_cast<APrimalDinoCharacter*>(actor);

int dinoTeam = dino->TargetingTeamField();
if (dinoTeam == teamId)
{
dino->Suicide();
num++;
}
}
std::string response = fmt::format("Destroyed {} dinos belonging to team {}", num, teamId);

return response;
}

return {};
}

void DestroyDinosForTeamIdRconCommand(RCONClientConnection* rconClientConnection, RCONPacket* rconPacket, UWorld* uWorld)
{
FString msg = rconPacket->Body;

auto result = DestroyDinosForTeamIdInternal(&msg);
if (result.length() == 0) return;

FString reply(result.c_str());
reply.AppendChar(L'\n');
rconClientConnection->SendMessageW(rconPacket->Id, 0, &reply);
}
6 changes: 6 additions & 0 deletions ArkBotLink/DestroyDinosForTeamId.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <API/ARK/Ark.h>

std::string DestroyDinosForTeamIdInternal(FString* cmd);
void DestroyDinosForTeamIdRconCommand(RCONClientConnection* rconClientConnection, RCONPacket* rconPacket, UWorld* uWorld);
65 changes: 65 additions & 0 deletions ArkBotLink/DestroyStructuresForTeamId.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "DestroyStructuresForTeamId.h"

std::string DestroyAllStructuresForTeamIdInternal(FString* cmd)
{
TArray<FString> Parsed;
cmd->ParseIntoArray(Parsed, L" ", true);

if (Parsed.IsValidIndex(1))
{
int teamId;

try
{
teamId = std::stoi(*Parsed[1]);
}
catch (const std::exception&)
{
return {};
}

if (teamId < 10000) return {};

UWorld* world = ArkApi::GetApiUtils().GetWorld();
if (!world) return {};

TArray<AActor*> FoundActors;

UGameplayStatics::GetAllActorsOfClass(world, APrimalStructure::GetPrivateStaticClass(), &FoundActors);

//todo: maybe destroy rafts aswell?
int num = 0;
for (const auto& actor : FoundActors)
{
APrimalStructure* structure = static_cast<APrimalStructure*>(actor);

int structureTeam = structure->TargetingTeamField();
if (structureTeam == teamId)
{
APrimalStructureItemContainer* StructInv = static_cast<APrimalStructureItemContainer*>(structure);
//UPrimalInventoryComponent* inventory = StructInv->MyInventoryComponentField();
if (StructInv) StructInv->bDropInventoryOnDestruction() = false;

structure->Suicide();
num++;
}
}
std::string response = fmt::format("Destroyed {} structures belonging to team {}", num, teamId);

return response;
}

return {};
}

void DestroyAllStructuresForTeamIdRconCommand(RCONClientConnection* rconClientConnection, RCONPacket* rconPacket, UWorld* uWorld)
{
FString msg = rconPacket->Body;

auto result = DestroyAllStructuresForTeamIdInternal(&msg);
if (result.length() == 0) return;

FString reply(result.c_str());
reply.AppendChar(L'\n');
rconClientConnection->SendMessageW(rconPacket->Id, 0, &reply);
}
6 changes: 6 additions & 0 deletions ArkBotLink/DestroyStructuresForTeamId.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <API/ARK/Ark.h>

std::string DestroyAllStructuresForTeamIdInternal(FString* cmd);
void DestroyAllStructuresForTeamIdRconCommand(RCONClientConnection* rconClientConnection, RCONPacket* rconPacket, UWorld* uWorld);
107 changes: 107 additions & 0 deletions ArkBotLink/DestroyStructuresForTeamIdAtPos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include "DestroyStructuresForTeamIdAtPos.h"

std::string DestroyStructuresForTeamIdAtPositionInternal(FString* cmd)
{
TArray<FString> Parsed;
cmd->ParseIntoArray(Parsed, L" ", true);

if (Parsed.IsValidIndex(5))
{
int teamId;
float x;
float y;
//float z;
float radius;
bool rafts;

try
{
teamId = std::stoi(*Parsed[1]);
x = std::stof(*Parsed[2]);
y = std::stof(*Parsed[3]);
radius = std::stof(*Parsed[4]);
rafts = (bool)std::stoi(*Parsed[5]);
//z = std::stof(*Parsed[4]);
}
catch (const std::exception&)
{
return {};
}

if (teamId < 10000) return {};
if (radius <= 0) return {};

UWorld* world = ArkApi::GetApiUtils().GetWorld();
if (!world) return {};

int num = 0;
FVector pos;

TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(world, APrimalStructure::GetPrivateStaticClass(), &FoundActors);

for (const auto& actor : FoundActors)
{
APrimalStructure* structure = static_cast<APrimalStructure*>(actor);

int structureTeam = structure->TargetingTeamField();
structure->RootComponentField()->GetCustomLocation(&pos);
//if (structureTeam == teamId && ArkLibrary::IsPointInsideSphere(pos, x, y, z, radius))
if (structureTeam == teamId && ArkExtensions::IsPointInside2dCircle(pos, x, y, radius))
{
APrimalStructureItemContainer* StructInv = static_cast<APrimalStructureItemContainer*>(structure);
//UPrimalInventoryComponent* inventory = StructInv->MyInventoryComponentField();
if (StructInv) StructInv->bDropInventoryOnDestruction() = false;

structure->Suicide();
num++;
}
}

if (rafts) {
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(world, APrimalDinoCharacter::GetPrivateStaticClass(), &FoundActors);

for (const auto& actor : FoundActors)
{
APrimalDinoCharacter* dino = static_cast<APrimalDinoCharacter*>(actor);

int dinoTeam = dino->TargetingTeamField();

dino->RootComponentField()->GetCustomLocation(&pos);
//if (structureTeam == teamId && ArkLibrary::IsPointInsideSphere(pos, x, y, z, radius))
if (dinoTeam == teamId && ArkExtensions::IsPointInside2dCircle(pos, x, y, radius))
{
FString className;
FName bp = actor->NameField();
bp.ToString(&className);

if (className.Contains("Raft_BP_C") || className.Contains("MotorRaft_BP_C")) {
dino->Destroy(false, true);
num++;
}

}
}
}

//ss << "Destroyed " << num << " structures belonging to team " << teamId << " at position (x: " << x << ", y: " << y << ", z: " << z << ", r: " << radius << ")";
std::string response = fmt::format("Destroyed {} structures belonging to team {} at position (x={}, y={}, r={}, rafts={})", num, teamId, x, y, radius, rafts);

return response;
}

return {};
}

void DestroyStructuresForTeamIdAtPositionRconCommand(RCONClientConnection* rconClientConnection, RCONPacket* rconPacket, UWorld* uWorld)
{
FString msg = rconPacket->Body;

auto result = DestroyStructuresForTeamIdAtPositionInternal(&msg);
if (result.length() == 0) return;

FString reply(result.c_str());
reply.AppendChar(L'\n');
rconClientConnection->SendMessageW(rconPacket->Id, 0, &reply);
}
6 changes: 6 additions & 0 deletions ArkBotLink/DestroyStructuresForTeamIdAtPos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "ApiExtensions.h"

std::string DestroyStructuresForTeamIdAtPositionInternal(FString* cmd);
void DestroyStructuresForTeamIdAtPositionRconCommand(RCONClientConnection* rconClientConnection, RCONPacket* rconPacket, UWorld* uWorld);
11 changes: 11 additions & 0 deletions ArkBotLink/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "Hooks.h"
#include "Timers.h"
#include "CrossServerChat.h"
#include "DestroyDinosForTeamId.h"
#include "DestroyStructuresForTeamId.h"
#include "DestroyStructuresForTeamIdAtPos.h"
#include <fstream>

#pragma comment(lib, "ArkApi.lib")
Expand Down Expand Up @@ -99,6 +102,10 @@ void Load()
//}

commands.AddOnChatMessageCallback("ChatMessageCallback", &ChatMessageCallback);

commands.AddRconCommand("DestroyAllStructuresForTeamId", &DestroyAllStructuresForTeamIdRconCommand);
commands.AddRconCommand("DestroyStructuresForTeamIdAtPosition", &DestroyStructuresForTeamIdAtPositionRconCommand);
commands.AddRconCommand("DestroyDinosForTeamId", &DestroyDinosForTeamIdRconCommand);
}

void Unload()
Expand All @@ -114,6 +121,10 @@ void Unload()
Timers::Unload();

ArkApi::GetCommands().RemoveOnChatMessageCallback("ChatMessageCallback");

ArkApi::GetCommands().RemoveRconCommand("DestroyAllStructuresForTeamId");
ArkApi::GetCommands().RemoveRconCommand("DestroyStructuresForTeamIdAtPosition");
ArkApi::GetCommands().RemoveRconCommand("DestroyDinosForTeamId");
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
Expand Down