add: objects inspector

just like UnityExplorer, gosh that was a pain
This commit is contained in:
ALittlePatate
2022-10-01 23:53:04 +02:00
parent 5af2f3169c
commit acb3222903
6 changed files with 213 additions and 40 deletions

View File

@@ -310,6 +310,7 @@
<ClInclude Include="pch.h" />
<ClInclude Include="Callbacks\OnUpdate.hpp" />
<ClInclude Include="Utils\Dumper\Dumper.hpp" />
<ClInclude Include="Utils\Helpers\Helpers.hpp" />
<ClInclude Include="Utils\Output\Output.hpp" />
<ClInclude Include="Utils\Players\Players.hpp" />
<ClInclude Include="Utils\Settings\Settings.hpp" />
@@ -356,6 +357,7 @@
</ClCompile>
<ClCompile Include="Callbacks\OnUpdate.cpp" />
<ClCompile Include="Utils\Dumper\Dumper.cpp" />
<ClCompile Include="Utils\Helpers\Helpers.cpp" />
<ClCompile Include="Utils\Output\Output.cpp" />
<ClCompile Include="Utils\Players\Players.cpp" />
<ClCompile Include="Utils\Settings\Settings.cpp" />

View File

@@ -174,6 +174,107 @@ void DrawMapSpecificTab() {
}
}
bool inspector = false;
void DrawInspector() {
ImGui::SetNextWindowSize(ImVec2(600.000f, 600.000f), ImGuiCond_Once);
if (!ImGui::Begin("Inspector", &inspector, 2)) {
ImGui::End();
return;
}
static std::vector<std::string> components;
static std::vector<std::string> classes;
static std::vector<std::string> methods;
static std::string current_comp = "";
ImGui::Text("Components");
if (ImGui::Button("Update##comp")) {
components = Dumper::DumpComponentsString();
}
ImGui::SetNextItemWidth(150.000f);
static int component_current_idx = 0; // Here we store our selection data as an index.
static ImGuiTextFilter c_filter;
c_filter.Draw("Search##compfilter");
if (ImGui::BeginListBox("##Components", ImVec2(-FLT_MIN, 5 * ImGui::GetTextLineHeightWithSpacing())))
{
for (size_t n = 0; n < components.size(); n++)
{
if (!c_filter.PassFilter(components[n].c_str())) {
continue;
}
const bool comp_is_selected = (component_current_idx == (int)n);
if (ImGui::Selectable(components[n].c_str(), comp_is_selected))
component_current_idx = (int)n;
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
if (comp_is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndListBox();
}
ImGui::Spacing();
ImGui::Text("Classes");
if (ImGui::Button("Update##class")) {
classes = Dumper::DumpClassesString(components[component_current_idx]);
current_comp = components[component_current_idx];
}
ImGui::SetNextItemWidth(150.000f);
static int class_current_idx = 0; // Here we store our selection data as an index.
static ImGuiTextFilter cl_filter;
cl_filter.Draw("Search##classfilter");
if (ImGui::BeginListBox("##Class", ImVec2(-FLT_MIN, 5 * ImGui::GetTextLineHeightWithSpacing())))
{
for (size_t n = 0; n < classes.size(); n++)
{
if (!cl_filter.PassFilter(classes[n].c_str())) {
continue;
}
const bool class_is_selected = (class_current_idx == (int)n);
if (ImGui::Selectable(classes[n].c_str(), class_is_selected)) {
class_current_idx = (int)n;
}
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
if (class_is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndListBox();
}
ImGui::Spacing();
ImGui::Text("Methods");
if (ImGui::Button("Update##Methods")) {
methods = Dumper::DumpMethodsString(current_comp, classes[class_current_idx]);
}
ImGui::SetNextItemWidth(150.000f);
static int method_current_idx = 0; // Here we store our selection data as an index.
static ImGuiTextFilter me_filter;
me_filter.Draw("Search##methodfilter");
if (ImGui::BeginListBox("##Methods", ImVec2(-FLT_MIN, -1)))
{
for (size_t n = 0; n < methods.size(); n++)
{
if (!me_filter.PassFilter(methods[n].c_str())) {
continue;
}
const bool meth_is_selected = (method_current_idx == (int)n);
if (ImGui::Selectable(methods[n].c_str(), meth_is_selected))
method_current_idx = (int)n;
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
if (meth_is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndListBox();
}
ImGui::End();
}
void DrawMiscTab() {
ImGui::Checkbox("Chat spam", &settings::chat_spam);
ImGui::InputText("Message", &settings::message);
@@ -220,10 +321,12 @@ void DrawMiscTab() {
#if _DEBUG
ImGui::Spacing();
static std::string component = "NolanBehaviour";
ImGui::InputText("##component", &component);
if (ImGui::Button("FindObjectsOfType")) {
Dump(component);
if (ImGui::Button("Inspector")) {
inspector = !inspector;
}
if (inspector) {
DrawInspector();
}
#endif

View File

@@ -5,13 +5,5 @@ void Misc::SetRank(int rank) {
}
void Misc::WalkInlobby(bool walk) {
Unity::CComponent* UltimateCharacterLocomotionHandler = Players::LocalPlayer->GetComponent("UltimateCharacterLocomotionHandler");
if (UltimateCharacterLocomotionHandler == NULL)
{
Players::LocalPlayer->AddComponent(IL2CPP::Class::GetSystemType("UltimateCharacterLocomotionHandler"));
Players::LocalPlayer->GetComponent("UltimateCharacterLocomotionHandler")->SetMemberValue<bool>("enabled", false);
}
Players::LocalPlayer->GetComponent("UltimateCharacterLocomotionHandler")->SetMemberValue<bool>("enabled", walk);
Players::LocalPlayer->GetComponent("UltimateCharacterLocomotionHandler")->GetGameObject()->SetActive(walk);
}

View File

@@ -1,35 +1,101 @@
#include "Dumper.hpp"
#include "../Output/Output.hpp"
void Dump(std::string component) {
print("\n\n\n");
print("Dumping %s\n\n", component.c_str());
auto list = Unity::Object::FindObjectsOfType<Unity::CComponent>(component.c_str());
std::vector<Unity::il2cppMethodInfo*> Dumper::DumpMethods(std::string component, std::string classname) {
std::vector<Unity::il2cppMethodInfo*> methods_to_return;
Unity::CGameObject* component_obj = Unity::GameObject::Find(component.c_str());
if (!component_obj) {
return methods_to_return;
}
size_t pos = classname.find("::");
classname.erase(0, pos+2);
Unity::CComponent* ccc = component_obj->GetComponent(classname.c_str());
if (!ccc) {
return methods_to_return;
}
ccc->FetchMethods(&methods_to_return);
return methods_to_return;
}
std::vector<std::string> Dumper::DumpMethodsString(std::string component, std::string classname) {
std::vector<std::string> methods_to_return;
std::vector<Unity::il2cppMethodInfo*> methods = Dumper::DumpMethods(component, classname);
for (Unity::il2cppMethodInfo* method : methods) {
if (!method) {
return methods_to_return;
}
methods_to_return.push_back(method->m_pName);
}
return methods_to_return;
}
std::vector<Unity::CComponent*> Dumper::DumpClasses(std::string component) {
std::vector<Unity::CComponent*> classes_to_return;
Unity::CGameObject* component_obj = Unity::GameObject::Find(component.c_str());
if (!component_obj) {
return classes_to_return;
}
auto components = component_obj->GetComponents(UNITY_COMPONENT_CLASS);
for (int n = 0; n < components->m_uMaxLength; n++)
{
if (!components->operator[](n))
continue;
classes_to_return.push_back(components->operator[](n));
}
return classes_to_return;
}
std::vector<std::string> Dumper::DumpClassesString(std::string component) {
std::vector<std::string> classes_to_return;
std::vector<Unity::CComponent*> classes = Dumper::DumpClasses(component);
for (Unity::CComponent* class_obj : classes)
{
if (!class_obj)
continue;
classes_to_return.push_back(std::string(class_obj->m_Object.m_pClass->m_pNamespace) + "::" + std::string(class_obj->m_Object.m_pClass->m_pName));
}
return classes_to_return;
}
std::vector<Unity::CComponent*> Dumper::DumpComponents() {
std::vector<Unity::CComponent*> compenents_to_return;
auto list = Unity::Object::FindObjectsOfType<Unity::CComponent>(UNITY_COMPONENT_CLASS);
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");
print("%s\n", object->GetName()->ToString().c_str()); //SurvivalPlayer(Clone)
auto components = object->GetComponents(UNITY_COMPONENT_CLASS);
for (int n = 0; n < components->m_uMaxLength; n++)
{
if (!components->operator[](n))
continue;
print("| -> %s::%s\n", components->operator[](n)->m_Object.m_pClass->m_pNamespace, components->operator[](n)->m_Object.m_pClass->m_pName);
}
Unity::CComponent* BoltEntity = object->GetComponent("BoltEntity");
if (BoltEntity)
{
print("|-------- owner:%d \n", BoltEntity->CallMethod<bool>("get_IsOwner")); //local player check?
if (BoltEntity->CallMethod<bool>("get_IsOwner"))
{
}
}
compenents_to_return.push_back(list->operator[](i));
}
return compenents_to_return;
}
std::vector<std::string> Dumper::DumpComponentsString() {
std::vector<std::string> compenents_to_return;
std::vector<Unity::CComponent*> components = Dumper::DumpComponents();
for (Unity::CComponent* component : components)
{
if (!component)
continue;
Unity::CGameObject* object = component->GetMemberValue<Unity::CGameObject*>("gameObject");
compenents_to_return.push_back(object->GetName()->ToString());
}
return compenents_to_return;
}

View File

@@ -1,4 +1,14 @@
#pragma once
#include "../Dependencies/IL2CPP_Resolver/il2cpp_resolver.hpp"
void Dump(std::string component);
namespace Dumper {
std::vector<Unity::CComponent*> DumpComponents();
std::vector<std::string> DumpComponentsString();
std::vector<Unity::CComponent*> DumpClasses(std::string component);
std::vector<std::string> DumpClassesString(std::string component);
std::vector<Unity::il2cppMethodInfo*> DumpMethods(std::string component, std::string classname);
std::vector<std::string> DumpMethodsString(std::string component, std::string classname);
}

View File

@@ -40,7 +40,7 @@ void Players::GetPlayersThread() {
}
}
Sleep(500);
Sleep(5000); //FIXME //waiting 5 sec here to avoid crash cuz we're trying to get players when stuff load
}
}