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

Clean up and extend ArkApiUtils. #18

Open
wants to merge 18 commits 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
2 changes: 0 additions & 2 deletions AsaApi/AsaApi.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,6 @@ copy "$(SolutionDir)$(PlatformName)\$(ConfigurationName)\$(ProjectName).pdb" "F:
<ClInclude Include="Core\Public\API\ARK\Actor.h" />
<ClInclude Include="Core\Public\API\ARK\Ark.h" />
<ClInclude Include="Core\Public\API\ARK\Buff.h" />
<ClInclude Include="Core\Public\API\ARK\ExtensionsDeclaration.h" />
<ClInclude Include="Core\Public\API\ARK\ExtensionsDefinition.h" />
<ClInclude Include="Core\Public\API\ARK\GameMode.h" />
<ClInclude Include="Core\Public\API\ARK\Inventory.h" />
<ClInclude Include="Core\Public\API\ARK\ModParamStructs.h" />
Expand Down
8 changes: 7 additions & 1 deletion AsaApi/Core/Private/UE/UE.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ReSharper disable CppInconsistentNaming
#include "API/ARK/Ark.h"
#include "API/ARK/UE.h"

Expand All @@ -9,4 +10,9 @@ ARK_API FProperty* UObject::FindProperty(FName name)
return Property;
}
return nullptr;
}
}

bool UObjectBaseUtility::IsA(const UClass* base)
{
return this->ClassPrivateField()->IsChildOf(base);
}
69 changes: 65 additions & 4 deletions AsaApi/Core/Public/API/ARK/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1377,8 +1377,24 @@ struct UInstancedStaticMeshComponent : UStaticMeshComponent
void ReceiveComponentDamage(float DamageAmount, const FDamageEvent* DamageEvent, AController* EventInstigator, AActor* DamageCauser) { NativeCall<void, float, const FDamageEvent*, AController*, AActor*>(this, "UInstancedStaticMeshComponent.ReceiveComponentDamage(float,FDamageEvent&,AController*,AActor*)", DamageAmount, DamageEvent, EventInstigator, DamageCauser); }
};

struct AActor : UPrimalActor, ActorExtensions
struct AActor : UPrimalActor
{
// Start AsaApi Extensions
FORCEINLINE FVector GetActorForwardVector()
{
if (USceneComponent* root_component = RootComponentField())
return root_component->ComponentToWorldField().GetUnitAxis(EAxis::X);
return FVector::ZeroVector;
}

FORCEINLINE FVector GetLocation()
{
if (const auto& root = RootComponentField())
return root->ComponentToWorldField().GetLocation();
return FVector::ZeroVector;
}
// End AsaApi Extensions

// Fields

FActorTickFunction& PrimaryActorTickField() { return *GetNativePointerField<FActorTickFunction*>(this, "AActor.PrimaryActorTick"); }
Expand Down Expand Up @@ -1957,7 +1973,15 @@ struct AInfo : AActor
};

struct UPlayer : UObject {
TObjectPtr<APlayerController>& PlayerControllerField() { return *GetNativePointerField<TObjectPtr<APlayerController>*>(this, "UPlayer.PlayerController"); }
// Start AsaApi Extensions
FString ConsoleCommand(const FString& Command, bool bWriteToLog)
{
FString result = *ConsoleCommand(&result, &Command, bWriteToLog);
return result;
}
// End AsaApi Extensions

TObjectPtr<APlayerController>& PlayerControllerField() { return *GetNativePointerField<TObjectPtr<APlayerController>*>(this, "UPlayer.PlayerController"); }
// int CurrentNetSpeed;
// int ConfiguredInternetSpeed;
// int ConfiguredLanSpeed;
Expand Down Expand Up @@ -2584,7 +2608,7 @@ struct APrimalController : AController
};


struct APlayerController : APrimalController, PlayerControllerExtensions
struct APlayerController : APrimalController
{
// Fields

Expand Down Expand Up @@ -3056,8 +3080,45 @@ struct ABasePlayerController : APrimalPlayerController

struct AShooterPlayerController : ABasePlayerController
{
// Fields
public:
// Start AsaApi Extensions
FString GetPlayerCharacterName()
{
FString player_name = *GetPlayerCharacterName(&player_name);
return player_name;
}

FString GetUniqueNetIdAsString()
{
FString unique_id = *GetUniqueNetIdAsString(&unique_id);
return unique_id;
}

void ClientServerChatDirectMessage(const FString& MessageText, FLinearColor MessageColor, bool bIsBold, const FString& SenderId)
{
ClientServerChatDirectMessage(&MessageText, MessageColor, bIsBold, &SenderId);
}

void ClientServerNotification(const FString& MessageText, FLinearColor MessageColor, float DisplayScale, float DisplayTime, UTexture2D* MessageIcon, USoundBase* SoundToPlay, int Priority)
{
ClientServerNotification(&MessageText, MessageColor, DisplayScale, DisplayTime, MessageIcon, SoundToPlay, Priority);
}

FString ConsoleCommand(const FString& Command, bool bWriteToLog)
{
FString result = *ConsoleCommand(&result, &Command, bWriteToLog);
return result;
}

void RunHiddenCommand(const FString& Command)
{
this->PlayerField().Get()->ConsoleCommand(Command, false);
}


// End AsaApi Extensions

// Fields
UPaintingStreamingComponent*& PaintingStreamingComponentField() { return *GetNativePointerField<UPaintingStreamingComponent**>(this, "AShooterPlayerController.PaintingStreamingComponent"); }
FieldArray<unsigned __int8, 10> HeldItemSlotField() { return { this, "AShooterPlayerController.HeldItemSlot" }; }
FieldArray<unsigned __int8, 10> UsedItemSlotField() { return { this, "AShooterPlayerController.UsedItemSlot" }; }
Expand Down
2 changes: 0 additions & 2 deletions AsaApi/Core/Public/API/ARK/Ark.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "../UE/Math/ColorList.h"
#include "UE.h"

#include "ExtensionsDeclaration.h"
//#include "Tribe.h"
#include "Actor.h"
#include "Other.h"
Expand All @@ -40,4 +39,3 @@
#include "../../ICommands.h"
#include "IHooks.h"
#include "Tools.h"
#include "ExtensionsDefinition.h"
36 changes: 0 additions & 36 deletions AsaApi/Core/Public/API/ARK/ExtensionsDeclaration.h

This file was deleted.

45 changes: 0 additions & 45 deletions AsaApi/Core/Public/API/ARK/ExtensionsDefinition.h

This file was deleted.

7 changes: 7 additions & 0 deletions AsaApi/Core/Public/API/ARK/GameMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,13 @@ struct UPrimalGlobals : UObject

struct FMapData
{
UE4_SizeOf(128);

FMapData()
{
UE4_CheckSize(FMapData);
NativeCall<void>(this, "FMapData.FMapData()");
}
// Fields

FString& MapNameField() { return *GetNativePointerField<FString*>(this, "FMapData.MapName"); }
Expand Down
29 changes: 28 additions & 1 deletion AsaApi/Core/Public/API/ARK/Other.h
Original file line number Diff line number Diff line change
Expand Up @@ -1900,10 +1900,35 @@ struct FItemMultiplier
static UScriptStruct* StaticStruct() { return NativeCall<UScriptStruct*>(nullptr, "FItemMultiplier.StaticStruct()"); }
};

#define UE4_SizeOf(size) \
constexpr static std::size_t size_of = size; \
char storage[size_of] = { 0 };

#define UE4_CheckSize(Name) \
{ \
const std::ptrdiff_t size_diff = size_of - GetStructSize<Name>(); \
if(size_diff < 0) \
{ \
Log::GetLog()->critical(#Name" will overrun ({} bytes smaller), please report this.", std::abs(size_diff)); \
throw std::overflow_error(#Name" is not sufficiently sized."); \
} \
if (size_diff > 0) \
{ \
Log::GetLog()->warn(#Name" exceeds real size ({} bytes larger), please report this.", std::abs(size_diff)); \
throw std::underflow_error(#Name" is not sufficiently sized."); \
} \
}


struct FItemNetInfo
{
UE4_SizeOf(528);
FItemNetInfo()
{
UE4_CheckSize(FItemNetInfo);
NativeCall<void>(this, "FItemNetInfo.FItemNetInfo()");
}
// Fields

TSubclassOf<UPrimalItem>& ItemArchetypeField() { return *GetNativePointerField<TSubclassOf<UPrimalItem>*>(this, "FItemNetInfo.ItemArchetype"); }
FItemNetID& ItemIDField() { return *GetNativePointerField<FItemNetID*>(this, "FItemNetInfo.ItemID"); }
unsigned int& ItemQuantityField() { return *GetNativePointerField<unsigned int*>(this, "FItemNetInfo.ItemQuantity"); }
Expand Down Expand Up @@ -1976,6 +2001,8 @@ struct FItemNetInfo
bool NetSerialize(FArchive* Ar, UPackageMap* Map, bool* bOutSuccess) { return NativeCall<bool, FArchive*, UPackageMap*, bool*>(this, "FItemNetInfo.NetSerialize(FArchive&,UPackageMap*,bool&)", Ar, Map, bOutSuccess); }
};



struct FItemSetup
{
// Fields
Expand Down
16 changes: 15 additions & 1 deletion AsaApi/Core/Public/API/ARK/UE.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

// ReSharper disable CppInconsistentNaming
#ifdef ARK_EXPORTS
#define ARK_API __declspec(dllexport)
#else
Expand Down Expand Up @@ -251,6 +251,14 @@ struct UObjectBase

struct UObjectBaseUtility : UObjectBase
{
// Start AsaApi Extensions
bool IsA(const UClass* base);
template<typename T>
bool IsA()
{
return IsA(T::StaticClass());
}
// End AsaApi Extensions
// Fields


Expand Down Expand Up @@ -1507,6 +1515,12 @@ int GetStructSize()
// Credits to Substitute#0001 for the idea
int size = 0;
UScriptStruct* staticStruct = T::StaticStruct();

size = staticStruct ? staticStruct->PropertiesSizeField() : 0;

printf("The size of this struct is %d bytes.", size);
return size;

if (staticStruct)
{
return staticStruct->PropertiesSizeField();
Expand Down
5 changes: 5 additions & 0 deletions AsaApi/Core/Public/API/UE/Math/Rotator.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ struct TRotator
explicit TRotator(const TRotator<FArg>& From) : TRotator<T>((T)From.Pitch, (T)From.Yaw, (T)From.Roll) {}
};


template<typename T>
inline const TRotator<T> TRotator<T>::ZeroRotator = { 0,0,0 };


#if !defined(_MSC_VER) || defined(__clang__) // MSVC can't forward declare explicit specializations
template<> const FRotator3f FRotator3f::ZeroRotator;
template<> const FRotator3d FRotator3d::ZeroRotator;
Expand Down
36 changes: 35 additions & 1 deletion AsaApi/Core/Public/API/UE/Math/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct TVector
};

/** A zero vector (0,0,0) */
static const TVector<T> ZeroVector;
static const TVector<T> ZeroVector;

/** One vector (1,1,1) */
static const TVector<T> OneVector;
Expand Down Expand Up @@ -1184,6 +1184,40 @@ struct TVector
explicit TVector(const TVector<FArg>& From) : TVector<T>((T)From.X, (T)From.Y, (T)From.Z) {}
};


template<typename T>
inline const TVector<T> TVector<T>::ZeroVector = { 0,0,0 };

template<typename T>
inline const TVector<T> TVector<T>::OneVector = { 1,1,1 };

template<typename T>
inline const TVector<T> TVector<T>::UpVector = { 0,0,1 };

template<typename T>
inline const TVector<T> TVector<T>::DownVector = { 0,0,-1 };

template<typename T>
inline const TVector<T> TVector<T>::ForwardVector = { 1,0,0 };

template<typename T>
inline const TVector<T> TVector<T>::BackwardVector = { -1,0,0 };

template<typename T>
inline const TVector<T> TVector<T>::RightVector = { 0,1,0 };

template<typename T>
inline const TVector<T> TVector<T>::LeftVector = { 0,-1,0 };

template<typename T>
inline const TVector<T> TVector<T>::XAxisVector = { 1,0,0 };

template<typename T>
inline const TVector<T> TVector<T>::YAxisVector = { 0,1,0 };

template<typename T>
inline const TVector<T> TVector<T>::ZAxisVector = { 0,0,1 };

/**
* Structured archive slot serializer for FVector3f.
*
Expand Down
Loading