add: GetObjectsThread

This commit is contained in:
ALittlePatate
2022-10-03 20:15:07 +02:00
parent be4b6a8f8f
commit cb072e0515
2 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
#include "Objects.hpp"
#include "../../Utils/Helpers/Helpers.hpp"
namespace Objects {
std::vector<Unity::CGameObject*> ObjectList(NULL);
}
void Objects::GetObjectsThread() {
/*
* Will always lop and get the objects
* This runs in a separate thread to avoid lags because we're fetching the components
* Used as a "cache" - sorta
* I use this instead of my good old corroutine
*/
IL2CPP::Thread::Attach(IL2CPP::Domain::Get());
while (1) {
ObjectList.clear();
auto list = Unity::Object::FindObjectsOfType<Unity::CComponent>("SurvivalInteractable");
for (int i = 0; i < list->m_uMaxLength + 1; i++)
{
if (!list->operator[](i))
continue;
Unity::CGameObject* object = list->operator[](i)->GetMemberValue<Unity::CGameObject*>("gameObject");
if (!object) {
continue;
}
ObjectList.push_back(object);
}
auto list2 = Unity::Object::FindObjectsOfType<Unity::CComponent>("KeyBehaviour");
for (int j = 0; j < list2->m_uMaxLength + 1; j++)
{
if (!list2->operator[](j))
continue;
Unity::CGameObject* object2 = list2->operator[](j)->GetMemberValue<Unity::CGameObject*>("gameObject");
if (!object2) {
continue;
}
ObjectList.push_back(object2);
}
Sleep(5000);
}
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "../Dependencies/IL2CPP_Resolver/il2cpp_resolver.hpp"
namespace Objects {
extern std::vector<Unity::CGameObject*> ObjectList;
void GetObjectsThread();
}