Skip to content

Commit

Permalink
Upgrade VectorUE4 And UE4Actor
Browse files Browse the repository at this point in the history
Now actors automatically update
  • Loading branch information
CorentinPtrl committed Dec 17, 2021
1 parent f7e8fb3 commit a24fa3a
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 88 deletions.
13 changes: 10 additions & 3 deletions SotCoreTest/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using SoT;
namespace SotEspCoreTest
{
Expand All @@ -7,18 +8,24 @@ class Program

public static string convertVecToStr(VectorUE4 vec)
{
return "(X: " + vec.x + " Y: " +vec.y+ " Z: " + vec.z + ")";
return "(X: " + vec.getX() + " Y: " +vec.getY()+ " Z: " + vec.getZ() + ")";
}
static void Main(string[] args)
{
SotCore core = new SotCore();
if (core.Prepare())
{
UE4Actor[] actors = core.GetActors();
core.GetLocalPlayer();
foreach (UE4Actor actor in actors)
{
Console.WriteLine("Name : " + actor.name + " Pos: " + convertVecToStr(actor.pos));
if (actor.getName().Equals("BP_PlayerPirate_C"))
{
while (true)
{
Console.WriteLine("Name : " + actor.BaseName + " | Actual Name :" + actor.getName() + " Pos :" + convertVecToStr(actor.getPos()));
Thread.Sleep(500);
}
}
}
}

Expand Down
66 changes: 15 additions & 51 deletions SotCoreWrapper/SotCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
using namespace System;
namespace Core
{
SotCore* SotCore::singleton;

SotCore::SotCore()
{
if (!singleton)
singleton = this;
}

bool SotCore::Prepare()
Expand Down Expand Up @@ -79,7 +83,7 @@ namespace Core
}


std::string getNameFromIDmem(int ID)
std::string SotCore::getNameFromIDmem(int ID)
{
try
{
Expand All @@ -93,25 +97,7 @@ namespace Core
}
}


SotCore::UE4Actor SotCore::GetLocalPlayer()
{
auto gameWorld = MemoryManager->Read<cUWorld>(MemoryManager->Read<uintptr_t>(Core::UWorld));
auto LP = gameWorld.GetGameInstance().GetLocalPlayer();
auto LPController = LP.GetPlayerController();
auto pos = LPController.GetActor().GetRootComponent().GetPosition();
auto objectName = getNameFromIDmem(LPController.GetActor().GetID());
Core::SotCore::Vector ActorPos;
ActorPos.x = pos.x;
ActorPos.y = pos.y;
ActorPos.z = pos.z;
UE4Actor actor;
actor.name = objectName;
actor.pos = ActorPos;
return actor;
}

std::vector<SotCore::UE4Actor> SotCore::getActors()
std::vector<AActor> SotCore::getActors()
{
auto gameWorld = MemoryManager->Read<cUWorld>(MemoryManager->Read<uintptr_t>(Core::UWorld));
auto LP = gameWorld.GetGameInstance().GetLocalPlayer();
Expand All @@ -128,49 +114,27 @@ namespace Core

auto worldLevel = gameWorld.GetLevel();
TArray<Chunk*> worldActors = worldLevel.GetActors();
std::vector<SotCore::UE4Actor> actors;
std::vector<AActor> actors;

for (int i = 0; i < worldActors.Length(); ++i)
{
auto objectActor = *reinterpret_cast<AActor*>(&worldActors[i]);
auto objectID = objectActor.GetID();
auto pos = objectActor.GetRootComponent().GetPosition();
auto objectName = getNameFromIDmem(objectID);
Core::SotCore::Vector ActorPos;
ActorPos.x = pos.x;
ActorPos.y = pos.y;
ActorPos.z = pos.z;
UE4Actor actor;
actor.name = objectName;
actor.pos = ActorPos;
actors.push_back(actor);
;
actors.push_back(objectActor);
}
TempActors = actors;
return actors;
}

System::String^ StdStringToUTF16(std::string s)
SoT::UE4Actor^ SotCore::ActorToManaged(int id, AActor actor)
{

cli::array<System::Byte>^ a = gcnew cli::array<System::Byte>(s.length());
int i = s.length();
while (i-- > 0)
{
a[i] = s[i];
}

return System::Text::Encoding::UTF8->GetString(a);
SoT::UE4Actor^ act = gcnew SoT::UE4Actor;
act->BaseName = gcnew System::String(getNameFromIDmem(actor.GetID()).c_str());
act->IDActors = gcnew System::Int32(id);
return act;
}


SoT::UE4Actor^ SotCore::UE4Actor::ActorToManagedActor()
{
SoT::UE4Actor^ actorWrapper = gcnew SoT::UE4Actor;
SoT::VectorUE4^ posWrapper = gcnew SoT::VectorUE4;
posWrapper->x = pos.x;
posWrapper->y = pos.y;
posWrapper->z = pos.z;
actorWrapper->pos = posWrapper;
actorWrapper->name = StdStringToUTF16(name);
return actorWrapper;
}
}
21 changes: 6 additions & 15 deletions SotCoreWrapper/SotCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,21 @@
#include <thread>
#include <chrono>
#include <vector>
#include "SOTStuff.h"
#include "UE4ActorWrapper.h"
namespace Core
{
class SotCore
{
public:
struct Vector {
public:
float x;
float y;
float z;
};
struct UE4Actor {
public:
std::string name;
Vector pos;
SoT::UE4Actor^ ActorToManagedActor();
};

static SotCore* singleton;
std::vector<AActor> TempActors;
public:
SotCore();
bool Prepare();
Core::SotCore::UE4Actor GetLocalPlayer();
std::vector<Core::SotCore::UE4Actor> getActors();
std::vector<AActor> getActors();
std::string getNameFromIDmem(int ID);
SoT::UE4Actor^ ActorToManaged(int id, AActor actor);

};
}
10 changes: 2 additions & 8 deletions SotCoreWrapper/SotCoreWrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "pch.h"
#include "SOTStuff.h"
#include "SotCoreWrapper.h"
namespace SoT
{
Expand All @@ -12,21 +13,14 @@ namespace SoT
return m_Instance->Prepare();
}

UE4Actor^ SotCore::GetLocalPlayer()
{
auto actor = m_Instance->GetLocalPlayer();
return actor.ActorToManagedActor();
}


array<UE4Actor^>^ SotCore::GetActors()
{
auto actors = m_Instance->getActors();
array<UE4Actor^>^ list = gcnew array< UE4Actor^ >(actors.size());

for (int i = 0; i < actors.size(); i++)
{
list[i] = actors[i].ActorToManagedActor();
list[i] = m_Instance->ActorToManaged(i, actors[i]);
}
return list;
}
Expand Down
1 change: 0 additions & 1 deletion SotCoreWrapper/SotCoreWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace SoT

SotCore();
bool Prepare();
UE4Actor^ GetLocalPlayer();
array<UE4Actor^>^ GetActors();
};
}
42 changes: 42 additions & 0 deletions SotCoreWrapper/UE4ActorWrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
#include "pch.h"
#include "Core.h"
#include "UE4ActorWrapper.h"
#include <msclr\marshal_cppstd.h>
using namespace msclr::interop;

namespace SoT
{

std::string ToUnmanagedString(String^ stringIncoming)
{
std::string unmanagedString = marshal_as<std::string>(stringIncoming);
return unmanagedString;
}

bool UE4Actor::isValid()
{
AActor actor = Core::SotCore::singleton->TempActors[(int)this->IDActors];
std::string test = Core::SotCore::singleton->getNameFromIDmem(actor.GetID());
std::string standardString = ToUnmanagedString(this->BaseName);
return test.compare(standardString) == 0;
}

VectorUE4^ UE4Actor::getPos()
{
if (isValid())
{
AActor actor = Core::SotCore::singleton->TempActors[(int)this->IDActors];
return gcnew VectorUE4(actor.GetRootComponent().GetPosition());
}
}

System::String^ UE4Actor::getName()
{
if (isValid())
{
AActor actor = Core::SotCore::singleton->TempActors[(int)this->IDActors];
std::string test = Core::SotCore::singleton->getNameFromIDmem(actor.GetID());
return gcnew System::String(test.c_str());
}
return gcnew System::String("NonePasCool");
}

}
8 changes: 6 additions & 2 deletions SotCoreWrapper/UE4ActorWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ namespace SoT
{
public ref class UE4Actor
{
private:
bool isValid();
public:
System::String^ name;
VectorUE4^ pos;
System::String^ getName();
VectorUE4^ UE4Actor::getPos();
System::String^ BaseName;
System::Int32^ IDActors;
};
}

Expand Down
24 changes: 20 additions & 4 deletions SotCoreWrapper/VectorUE4.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
#include "pch.h"
#include "VectorUE4.h"
namespace Core
namespace SoT
{
int x = 0;
int y = 0;
int z = 0;
VectorUE4::VectorUE4(Vector3 vec) : ManagedObject(&vec)
{

}

float VectorUE4::getX()
{
return this->m_Instance->x;
}

float VectorUE4::getY()
{
return this->m_Instance->y;
}

float VectorUE4::getZ()
{
return this->m_Instance->z;
}

}
12 changes: 8 additions & 4 deletions SotCoreWrapper/VectorUE4.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#pragma once
#include "pch.h"
#include "ManagedObject.h"
#include "vector.h"
namespace SoT
{
public ref class VectorUE4
public ref class VectorUE4 : public ManagedObject<Vector3>
{
public:
float x;
float y;
float z;
VectorUE4(Vector3 vec);
float getX();
float getY();
float getZ();

};
}

0 comments on commit a24fa3a

Please sign in to comment.