code optimization &new helper functions added / modified
- UnityCore namespace changed to UnityEngine - Object class is no longer a template. FindObjectOfType function set to template - Added LogComponents function. It helps us retrieve components from the target gameObject. - Added GetObjectName function to Object structure (same method is available in utils header) - Added ConvertToSystemString function. Converts const char to system.string (app::String)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "ClientHelper.h"
|
||||
#include "players/players.h"
|
||||
#include "UnityCore.h"
|
||||
#include "UnityEngine.h"
|
||||
|
||||
bool IsSinglePlayer()
|
||||
{
|
||||
@@ -46,10 +46,8 @@ bool IsPlayerCrawling(app::GameObject* go)
|
||||
if (go == NULL)
|
||||
return false;
|
||||
|
||||
app::String* str = reinterpret_cast<app::String*>(il2cpp_string_new("NolanBehaviour"));
|
||||
|
||||
if (app::GameObject_GetComponentByName != NULL) {
|
||||
app::Component* nbComponent = app::GameObject_GetComponentByName(go, str, nullptr);
|
||||
app::Component* nbComponent = app::GameObject_GetComponentByName(go, ConvertToSystemString("NolanBehaviour"), nullptr);
|
||||
|
||||
if (nbComponent) {
|
||||
app::NolanBehaviour* nb = reinterpret_cast<app::NolanBehaviour*>(nbComponent);
|
||||
@@ -65,7 +63,7 @@ bool IsPlayerCrawling(app::GameObject* go)
|
||||
|
||||
bool IsInGame()
|
||||
{
|
||||
app::OptionsHelpers* optionsHelpers = UnityCore::Object<app::OptionsHelpers>::FindObjectOfType("OptionsHelpers");
|
||||
app::OptionsHelpers* optionsHelpers = UnityEngine::Object::FindObjectOfType<app::OptionsHelpers>("OptionsHelpers");
|
||||
|
||||
if (optionsHelpers)
|
||||
return optionsHelpers->fields._inGame_k__BackingField;
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
#include "pch-il2cpp.h"
|
||||
|
||||
#include "UnityCore.h"
|
||||
#include <helpers.h>
|
||||
|
||||
app::Component* Unity::GameObject::GetComponentByName(app::GameObject* go, const char* type)
|
||||
{
|
||||
app::String* str = reinterpret_cast<app::String*>(il2cpp_string_new(type));
|
||||
|
||||
if (str != nullptr) {
|
||||
app::Component* component = app::GameObject_GetComponentByName(go, str, nullptr);
|
||||
|
||||
if (component != nullptr) {
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string Unity::Math::Vector3::ToString(app::Vector3* v)
|
||||
{
|
||||
app::String* str = app::Vector3_ToString(v, nullptr);
|
||||
|
||||
if (str == NULL) {
|
||||
return std::string("NULL");
|
||||
}
|
||||
|
||||
return il2cppi_to_string(str);
|
||||
}
|
||||
|
||||
std::string Unity::Math::Vector3::ToString(app::Vector3 v)
|
||||
{
|
||||
return ("x: " + std::to_string(v.x) + " y: " + std::to_string(v.y) + " z: " + std::to_string(v.z));
|
||||
}
|
||||
|
||||
|
||||
app::Transform* Unity::Transform::Get(app::GameObject* go)
|
||||
{
|
||||
if (go != nullptr) {
|
||||
if (app::GameObject_get_transform != nullptr) {
|
||||
|
||||
app::Transform* __transform = app::GameObject_get_transform(go, nullptr);
|
||||
|
||||
if (__transform) {
|
||||
return __transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
app::Vector3 Unity::Transform::Position(app::Transform* transform)
|
||||
{
|
||||
if (transform != nullptr) {
|
||||
if (app::Transform_get_position != nullptr) {
|
||||
return app::Transform_get_position(transform, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
return app::Vector3();
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Wrapper.h"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "ClientHelper.h"
|
||||
|
||||
namespace Unity {
|
||||
namespace GameObject {
|
||||
// DO_APP_FUNC(0x02D34DA0, Component *, GameObject_GetComponentByName, (GameObject * __this, String * type, MethodInfo * method));
|
||||
app::Component* GetComponentByName(app::GameObject* go, const char* type);
|
||||
}
|
||||
|
||||
namespace Math {
|
||||
namespace Vector3 {
|
||||
std::string ToString(app::Vector3* v);
|
||||
std::string ToString(app::Vector3 v);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Transform {
|
||||
app::Transform* Get(app::GameObject* go);
|
||||
app::Vector3 Position(app::Transform* transform);
|
||||
}
|
||||
}
|
||||
|
||||
namespace UnityCore {
|
||||
template<typename T>
|
||||
class Object {
|
||||
public:
|
||||
Object() = default;
|
||||
|
||||
static T* FindObjectOfType(const char* className, const char* classNamespace = "");
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline T* Object<T>::FindObjectOfType(const char* className, const char* classNamespace)
|
||||
{
|
||||
Wrapper obj("Assembly-CSharp.dll");
|
||||
|
||||
Il2CppObject* object = obj.find_class(classNamespace, className).get_class();
|
||||
if (object) {
|
||||
|
||||
if (app::Object_1_FindObjectOfType == nullptr) return nullptr;
|
||||
|
||||
app::Object_1* obj_1 = app::Object_1_FindObjectOfType(reinterpret_cast<app::Type*>(object), nullptr);
|
||||
|
||||
if (IsNull(obj_1) || obj_1 == nullptr) return nullptr;
|
||||
|
||||
T* foundObject = reinterpret_cast<T*>(obj_1);
|
||||
|
||||
if (foundObject) {
|
||||
return foundObject;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
72
lib/UnityEngine.cpp
Normal file
72
lib/UnityEngine.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "pch-il2cpp.h"
|
||||
|
||||
#include "UnityEngine.h"
|
||||
#include <helpers.h>
|
||||
|
||||
app::Component* UnityEngine::GameObject::GetComponentByName(app::GameObject* go, const char* type)
|
||||
{
|
||||
app::Component* component = app::GameObject_GetComponentByName(go, ConvertToSystemString(type), nullptr);
|
||||
|
||||
return component ? component : nullptr;
|
||||
}
|
||||
|
||||
app::Component__Array* UnityEngine::GameObject::LogComponents(app::GameObject* go)
|
||||
{
|
||||
Wrapper obj("UnityEngine.CoreModule.dll");
|
||||
|
||||
Il2CppObject* object = obj.find_class("UnityEngine", "Component").get_class();
|
||||
|
||||
if (!object) return nullptr;
|
||||
|
||||
app::Type* type = reinterpret_cast<app::Type*>(object);
|
||||
if (!type) return nullptr;
|
||||
|
||||
app::Component__Array* __components = app::GameObject_GetComponents(go, type, nullptr);
|
||||
|
||||
return __components ? __components : nullptr;
|
||||
}
|
||||
|
||||
const char* UnityEngine::Math::Vector3::ToString(app::Vector3* v)
|
||||
{
|
||||
app::String* str = app::Vector3_ToString(v, nullptr);
|
||||
|
||||
return str ? il2cppi_to_string(str).c_str() : "Vector::ToString returned nullptr!\n";
|
||||
}
|
||||
|
||||
const char* UnityEngine::Math::Vector3::ToString(app::Vector3 v)
|
||||
{
|
||||
return ("x: " + std::to_string(v.x) + " y: " + std::to_string(v.y) + " z: " + std::to_string(v.z)).c_str();
|
||||
}
|
||||
|
||||
app::Transform* UnityEngine::Transform::Get(app::GameObject* go)
|
||||
{
|
||||
if (!go || !app::GameObject_get_transform) return nullptr;
|
||||
|
||||
app::Transform* __transform = app::GameObject_get_transform(go, nullptr);
|
||||
|
||||
return __transform ? __transform : nullptr;
|
||||
}
|
||||
|
||||
app::Vector3 UnityEngine::Transform::Position(app::Transform* transform)
|
||||
{
|
||||
if (!transform || !app::Transform_get_position) return app::Vector3();
|
||||
|
||||
return app::Transform_get_position(transform, nullptr);
|
||||
}
|
||||
|
||||
const char* UnityEngine::Object::GetObjectName(app::Object_1* obj)
|
||||
{
|
||||
static std::string name = il2cppi_to_string(app::Object_1_GetName(obj, nullptr));
|
||||
return name.c_str();
|
||||
}
|
||||
|
||||
app::GameObject__Array* UnityEngine::Object::FindGameObjectsWithTag(const char* tag)
|
||||
{
|
||||
app::GameObject__Array* go_array_result = app::GameObject_FindGameObjectsWithTag(ConvertToSystemString(tag), nullptr);
|
||||
|
||||
return go_array_result ? go_array_result : nullptr;
|
||||
}
|
||||
|
||||
void UnityEngine::Object::FindObjectFromInstanceID(int32_t instanceID)
|
||||
{
|
||||
}
|
||||
51
lib/UnityEngine.h
Normal file
51
lib/UnityEngine.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "Wrapper.h"
|
||||
#include "helpers.h"
|
||||
#include "ClientHelper.h"
|
||||
|
||||
namespace UnityEngine {
|
||||
namespace GameObject {
|
||||
app::Component* GetComponentByName(app::GameObject* go, const char* type);
|
||||
app::Component__Array* LogComponents(app::GameObject* go);
|
||||
}
|
||||
|
||||
namespace Math {
|
||||
namespace Vector3 {
|
||||
const char* ToString(app::Vector3* v);
|
||||
const char* ToString(app::Vector3 v);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Transform {
|
||||
app::Transform* Get(app::GameObject* go);
|
||||
app::Vector3 Position(app::Transform* transform);
|
||||
}
|
||||
|
||||
struct Object {
|
||||
|
||||
static const char* GetObjectName(app::Object_1* obj);
|
||||
|
||||
static app::GameObject__Array* FindGameObjectsWithTag(const char* tag);
|
||||
|
||||
// Object_1_FindObjectFromInstanceID
|
||||
static void FindObjectFromInstanceID(int32_t instanceID);
|
||||
|
||||
template<typename T>
|
||||
static T* FindObjectOfType(const char* className, const char* classNamespace = "", const char* assemblyName = "Assembly-CSharp.dll") {
|
||||
|
||||
Wrapper obj(assemblyName);
|
||||
|
||||
Il2CppObject* object = obj.find_class(classNamespace, className).get_class();
|
||||
|
||||
if (!object || !app::Object_1_FindObjectOfType) return nullptr;
|
||||
|
||||
app::Object_1* obj_1 = app::Object_1_FindObjectOfType(reinterpret_cast<app::Type*>(object), nullptr);
|
||||
|
||||
if (!obj_1 || IsNull(obj_1)) return nullptr;
|
||||
|
||||
return reinterpret_cast<T*>(obj_1);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user