Skip to content

Commit

Permalink
Fix _crtisvalidheappointer(block) remove ActorToManagedActor Method
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinPtrl committed Dec 22, 2021
1 parent 6bef7ef commit 21129da
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 19 deletions.
9 changes: 8 additions & 1 deletion SotCoreTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Program

public static string convertVecToStr(VectorUE4 vec)
{
if (vec == null)
return "NULL";
return "(X: " + vec.getX() + " Y: " + vec.getY() + " Z: " + vec.getZ() + ")";
}
static void Main(string[] args)
Expand All @@ -21,7 +23,12 @@ static void Main(string[] args)
Console.WriteLine("Name : " + actor.BaseName + " | Actual Name :" + actor.getName() + " Pos :" + convertVecToStr(actor.getPos()));
}
UE4Actor localPlayer = core.GetLocalPlayer();
Console.WriteLine("LocalPlayer Name : " + localPlayer.BaseName + " | LocalPlayer Actual Name :" + localPlayer.getName() + " LocalPlayer Pos :" + convertVecToStr(localPlayer.getPos()));
int i = 1;
while (true)
{
Console.WriteLine("LocalPlayer Name : {0} | LocalPlayer Actual Name : {1} LocalPlayer Pos : {2} index = {3}", localPlayer.BaseName, localPlayer.getName(), convertVecToStr(localPlayer.getPos()), i);
i++;
}
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions SotCoreWrapper/SotCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,5 @@ namespace Core
TempActors = actors;
return actors;
}

SoT::UE4Actor^ SotCore::ActorToManaged(int id, AActor actor)
{
SoT::UE4Actor^ act = gcnew SoT::UE4Actor;
act->BaseName = gcnew System::String(getNameFromIDmem(actor.GetID()).c_str());
act->IDActors = gcnew System::Int32(id);
return act;
}

}

3 changes: 0 additions & 3 deletions SotCoreWrapper/SotCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@ namespace Core
Vector3 GetCameraPosition();
std::vector<AActor> getActors();
std::string getNameFromIDmem(int ID);
SoT::UE4Actor^ ActorToManaged(int id, AActor actor);


};
}
5 changes: 3 additions & 2 deletions SotCoreWrapper/SotCoreWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace SoT

UE4Actor^ SotCore::GetLocalPlayer()
{
return m_Instance->ActorToManaged(-1, m_Instance->getLocalPlayer());
return gcnew UE4Actor(m_Instance->getNameFromIDmem(m_Instance->getLocalPlayer().GetID()), -1);
}

System::Single^ SotCore::GetCameraFOV()
Expand All @@ -48,7 +48,8 @@ namespace SoT

for (int i = 0; i < actors.size(); i++)
{
list[i] = m_Instance->ActorToManaged(i, actors[i]);
SoT::UE4Actor^ act = gcnew SoT::UE4Actor(m_Instance->getNameFromIDmem(actors[i].GetID()), i);
list[i] = act;
}
return list;
}
Expand Down
38 changes: 34 additions & 4 deletions SotCoreWrapper/UE4ActorWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ using namespace msclr::interop;
namespace SoT
{

UE4Actor::UE4Actor(std::string BaseName, int IDActors)
{
this->BaseName = gcnew System::String(BaseName.c_str());
this->IDActors = gcnew System::Int32(IDActors);
}

std::string ToUnmanagedString(String^ stringIncoming)
{
std::string unmanagedString = marshal_as<std::string>(stringIncoming);
Expand Down Expand Up @@ -39,17 +45,41 @@ namespace SoT
{
if (isValid())
{

return gcnew VectorUE4(getActor().GetRootComponent().GetPosition());
if (this->pos == nullptr)
{
this->pos = gcnew VectorUE4(getActor().GetRootComponent().GetPosition());
return pos;
}
else if (*(uintptr_t*)(this->pos->GetInstance()) == *(uintptr_t*)(&getActor().GetRootComponent().GetPosition()))
{
return this->pos;
}
else
{
this->pos->updateInstance(getActor().GetRootComponent().GetPosition());
return pos;
}
}
}

VectorUE4^ UE4Actor::getRot()
{
if (isValid())
{

return gcnew VectorUE4(getActor().GetRootComponent().GetRotation());
if (this->rot == nullptr)
{
this->rot = gcnew VectorUE4(getActor().GetRootComponent().GetRotation());
return rot;
}
else if (*(uintptr_t*)(this->rot->GetInstance()) == *(uintptr_t*)(&getActor().GetRootComponent().GetRotation()))
{
return this->rot;
}
else
{
this->rot->updateInstance(getActor().GetRootComponent().GetRotation());
return rot;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions SotCoreWrapper/UE4ActorWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ namespace SoT
public ref class UE4Actor
{
private:
VectorUE4^ pos;
VectorUE4^ rot;
bool isValid();
AActor UE4Actor::getActor();
public:
UE4Actor(std::string BaseName, int IDActors);
System::String^ getName();
VectorUE4^ UE4Actor::getPos();
VectorUE4^ UE4Actor::getRot();
Expand Down
5 changes: 5 additions & 0 deletions SotCoreWrapper/VectorUE4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace SoT

}

void VectorUE4::updateInstance(Vector3 vec)
{
this->m_Instance = &vec;
}

float VectorUE4::getX()
{
return this->m_Instance->x;
Expand Down
1 change: 1 addition & 0 deletions SotCoreWrapper/VectorUE4.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace SoT
{
public:
VectorUE4(Vector3 vec);
void VectorUE4::updateInstance(Vector3 vec);
float getX();
float getY();
float getZ();
Expand Down

0 comments on commit 21129da

Please sign in to comment.