diff --git a/SotCoreTest/Program.cs b/SotCoreTest/Program.cs index dfce25c..3a779cb 100644 --- a/SotCoreTest/Program.cs +++ b/SotCoreTest/Program.cs @@ -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) @@ -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++; + } } } } diff --git a/SotCoreWrapper/SotCore.cpp b/SotCoreWrapper/SotCore.cpp index 13443eb..7c4cb1e 100644 --- a/SotCoreWrapper/SotCore.cpp +++ b/SotCoreWrapper/SotCore.cpp @@ -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; - } - } diff --git a/SotCoreWrapper/SotCore.h b/SotCoreWrapper/SotCore.h index 966ea74..5a9f80f 100644 --- a/SotCoreWrapper/SotCore.h +++ b/SotCoreWrapper/SotCore.h @@ -25,8 +25,5 @@ namespace Core Vector3 GetCameraPosition(); std::vector getActors(); std::string getNameFromIDmem(int ID); - SoT::UE4Actor^ ActorToManaged(int id, AActor actor); - - }; } diff --git a/SotCoreWrapper/SotCoreWrapper.cpp b/SotCoreWrapper/SotCoreWrapper.cpp index ff0a2bd..66408e5 100644 --- a/SotCoreWrapper/SotCoreWrapper.cpp +++ b/SotCoreWrapper/SotCoreWrapper.cpp @@ -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() @@ -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; } diff --git a/SotCoreWrapper/UE4ActorWrapper.cpp b/SotCoreWrapper/UE4ActorWrapper.cpp index 4a001fa..cb2630b 100644 --- a/SotCoreWrapper/UE4ActorWrapper.cpp +++ b/SotCoreWrapper/UE4ActorWrapper.cpp @@ -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(stringIncoming); @@ -39,8 +45,20 @@ 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; + } } } @@ -48,8 +66,20 @@ namespace SoT { 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; + } } } diff --git a/SotCoreWrapper/UE4ActorWrapper.h b/SotCoreWrapper/UE4ActorWrapper.h index 8f29c0a..7ce6529 100644 --- a/SotCoreWrapper/UE4ActorWrapper.h +++ b/SotCoreWrapper/UE4ActorWrapper.h @@ -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(); diff --git a/SotCoreWrapper/VectorUE4.cpp b/SotCoreWrapper/VectorUE4.cpp index a2cbb7b..2ba1b5c 100644 --- a/SotCoreWrapper/VectorUE4.cpp +++ b/SotCoreWrapper/VectorUE4.cpp @@ -7,6 +7,11 @@ namespace SoT } + void VectorUE4::updateInstance(Vector3 vec) + { + this->m_Instance = &vec; + } + float VectorUE4::getX() { return this->m_Instance->x; diff --git a/SotCoreWrapper/VectorUE4.h b/SotCoreWrapper/VectorUE4.h index 43b7aaa..bdca93c 100644 --- a/SotCoreWrapper/VectorUE4.h +++ b/SotCoreWrapper/VectorUE4.h @@ -8,6 +8,7 @@ namespace SoT { public: VectorUE4(Vector3 vec); + void VectorUE4::updateInstance(Vector3 vec); float getX(); float getY(); float getZ();