2022-02-27 14:38:51 +03:00
|
|
|
// Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty
|
|
|
|
// Helper functions
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
2022-05-17 03:13:41 +03:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <cheat-base/Logger.h>
|
2022-02-27 14:38:51 +03:00
|
|
|
|
|
|
|
#include "il2cpp-metadata-version.h"
|
|
|
|
|
2022-05-30 23:52:47 +03:00
|
|
|
#define IS_SINGLETON_LOADED(className) (/**app::Singleton_1_## className ##___TypeInfo != nullptr &&*/ *app::Singleton_1_ ## className ## __get_Instance__MethodInfo != nullptr)
|
2022-05-31 03:44:53 +03:00
|
|
|
#define GET_SINGLETON(tpname) IS_SINGLETON_LOADED(tpname) ? reinterpret_cast<app:: ## tpname ## *>(app::Singleton_GetInstance(*app::Singleton_1_ ## tpname ## __get_Instance__MethodInfo)) : nullptr
|
2022-05-17 03:13:41 +03:00
|
|
|
|
|
|
|
#define INIT_ILCPP_CLASS(className, expr) (il2cpp_runtime_class_init(reinterpret_cast<Il2CppClass*>(*app::## className ##__TypeInfo)), expr)
|
|
|
|
#define GET_STATIC_FIELDS(tpname) INIT_ILCPP_CLASS(tpname, (*app::## tpname ##__TypeInfo)->static_fields)
|
|
|
|
|
|
|
|
#define SAFE_BEGIN() __try {
|
|
|
|
#define SAFE_ERROR() } __except (EXCEPTION_EXECUTE_HANDLER) { \
|
|
|
|
LOG_WARNING("Exception 0x%08x.", GetExceptionCode());
|
|
|
|
|
|
|
|
#define SAFE_END() }
|
|
|
|
#define SAFE_EEND() SAFE_ERROR(); SAFE_END();
|
|
|
|
|
|
|
|
#define COMMA ,
|
|
|
|
#define TO_UNI_COLLECTION(field, collection) reinterpret_cast<collection*>(field)
|
|
|
|
#define TO_UNI_ARRAY(field, type) TO_UNI_COLLECTION(field, UniArray<type>)
|
|
|
|
#define TO_UNI_LIST(field, type) TO_UNI_COLLECTION(field, UniList<type>)
|
|
|
|
#define TO_UNI_LINK_LIST(field, type) TO_UNI_COLLECTION(field, UniLinkList<type>)
|
|
|
|
#define TO_UNI_DICT(field, keyType, valueType) TO_UNI_COLLECTION(field, UniDict<keyType COMMA valueType>)
|
|
|
|
|
|
|
|
template<class ElementT>
|
|
|
|
struct UniLinkList;
|
|
|
|
|
|
|
|
template<class ElementT>
|
|
|
|
struct UniLinkListNode
|
|
|
|
{
|
|
|
|
ElementT item;
|
|
|
|
UniLinkList<ElementT>* container;
|
|
|
|
UniLinkListNode<ElementT>* forward;
|
|
|
|
UniLinkListNode<ElementT>* back;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class ElementT>
|
2022-06-08 07:52:24 +03:00
|
|
|
struct UniLinkList
|
2022-05-17 03:13:41 +03:00
|
|
|
{
|
|
|
|
void* klass;
|
|
|
|
MonitorData* monitor;
|
|
|
|
uint32_t count;
|
|
|
|
uint32_t version;
|
|
|
|
app::Object* syncRoot;
|
|
|
|
UniLinkListNode<ElementT>* first;
|
|
|
|
struct SerializationInfo* si;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename ElementT>
|
|
|
|
struct UniArray {
|
|
|
|
void* klass;
|
|
|
|
MonitorData* monitor;
|
|
|
|
Il2CppArrayBounds* bounds;
|
|
|
|
il2cpp_array_size_t max_length;
|
|
|
|
ElementT vector[32];
|
|
|
|
|
|
|
|
typedef ElementT* iterator;
|
|
|
|
typedef const ElementT* const_iterator;
|
|
|
|
|
|
|
|
size_t length() const { return (bounds == nullptr) ? max_length : bounds->length; }
|
|
|
|
|
|
|
|
iterator begin() { return &vector[0]; }
|
|
|
|
const_iterator begin() const { return &vector[0]; }
|
|
|
|
iterator end() { return &vector[length()]; }
|
|
|
|
const_iterator end() const { return &vector[length()]; }
|
|
|
|
ElementT* operator[](int i) { return &vector[i]; }
|
|
|
|
|
|
|
|
std::vector<ElementT> vec()
|
|
|
|
{
|
|
|
|
auto result = std::vector<ElementT>(length());
|
|
|
|
for (auto i = begin(); i < end(); i++)
|
|
|
|
result.push_back(*i);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct UniList
|
|
|
|
{
|
|
|
|
void* klass;
|
|
|
|
void* monitor;
|
|
|
|
UniArray<T>* store;
|
|
|
|
int32_t size;
|
|
|
|
int32_t version;
|
|
|
|
|
|
|
|
typedef T* iterator;
|
|
|
|
typedef const T* const_iterator;
|
|
|
|
|
|
|
|
iterator begin() { return (*store)[0]; }
|
|
|
|
const_iterator begin() const { return (*store)[0]; }
|
|
|
|
iterator end() { return (*store)[size]; }
|
|
|
|
const_iterator end() const { return (*store)[size]; }
|
|
|
|
|
|
|
|
std::vector<T> vec()
|
|
|
|
{
|
|
|
|
auto result = std::vector<T>();
|
|
|
|
result.reserve(size);
|
|
|
|
for (auto i = begin(); i < end(); i++)
|
|
|
|
result.push_back(*i);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-05-31 18:23:12 +03:00
|
|
|
template<typename KeyT, typename ValT>
|
|
|
|
struct UniDictEntry
|
|
|
|
{
|
|
|
|
int32_t hashCode;
|
|
|
|
int32_t next;
|
|
|
|
KeyT key;
|
|
|
|
ValT value;
|
|
|
|
};
|
|
|
|
|
2022-05-17 03:13:41 +03:00
|
|
|
template<typename KeyT, typename ValT>
|
|
|
|
struct __declspec(align(8)) UniDict {
|
|
|
|
void* klass;
|
|
|
|
MonitorData* monitor;
|
2022-05-31 18:23:12 +03:00
|
|
|
void* buckets;
|
|
|
|
UniArray<UniDictEntry<KeyT, ValT>>* entries;
|
2022-06-08 07:52:24 +03:00
|
|
|
int32_t count;
|
|
|
|
int32_t version;
|
|
|
|
int32_t freeList;
|
|
|
|
int32_t freeCount;
|
|
|
|
void* comparer;
|
2022-05-31 18:23:12 +03:00
|
|
|
void* keys;
|
|
|
|
void* values;
|
2022-05-17 03:13:41 +03:00
|
|
|
|
2022-06-08 07:52:24 +03:00
|
|
|
std::vector<std::pair<KeyT, ValT>> pairs()
|
2022-05-17 03:13:41 +03:00
|
|
|
{
|
|
|
|
auto pairs = std::vector<std::pair<KeyT, ValT>>();
|
|
|
|
|
2022-05-31 20:23:26 +03:00
|
|
|
#define DictCheckNull(field, msg) if (field == nullptr) { /*LOG_WARNING("Failed to get dict pairs: %s", msg);*/ return pairs; }
|
2022-05-17 03:13:41 +03:00
|
|
|
|
2022-05-31 18:23:12 +03:00
|
|
|
DictCheckNull(buckets, "Buckets is null.");
|
|
|
|
DictCheckNull(entries, "Entries is null.");
|
2022-05-17 03:13:41 +03:00
|
|
|
|
|
|
|
#undef DictCheckNull
|
|
|
|
|
2022-05-31 19:28:43 +03:00
|
|
|
int32_t index = 0;
|
2022-05-31 18:23:12 +03:00
|
|
|
for (auto& entry : *entries)
|
2022-05-17 03:13:41 +03:00
|
|
|
{
|
2022-05-31 19:28:43 +03:00
|
|
|
if (index >= count)
|
|
|
|
break;
|
2022-05-31 18:23:12 +03:00
|
|
|
|
2022-05-31 19:28:43 +03:00
|
|
|
if (entry.hashCode > 0)
|
2022-06-08 07:52:24 +03:00
|
|
|
pairs.push_back({ entry.key, entry.value });
|
|
|
|
|
2022-05-31 19:28:43 +03:00
|
|
|
index++;
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
2022-05-31 18:23:12 +03:00
|
|
|
|
2022-05-17 03:13:41 +03:00
|
|
|
return pairs;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
T* CastTo(void* pObject, void* pClass)
|
|
|
|
{
|
2022-06-08 07:52:24 +03:00
|
|
|
auto object = reinterpret_cast<app::Object*>(pObject);
|
|
|
|
if (object == nullptr || object->klass == nullptr || object->klass != pClass)
|
|
|
|
return nullptr;
|
2022-05-17 03:13:41 +03:00
|
|
|
|
2022-06-08 07:52:24 +03:00
|
|
|
return reinterpret_cast<T*>(object);
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector3 operator + (const app::Vector3& A, const app::Vector3& B)
|
|
|
|
{
|
|
|
|
return { A.x + B.x, A.y + B.y, A.z + B.z };
|
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector3 operator + (const app::Vector3& A, const float k)
|
|
|
|
{
|
|
|
|
return { A.x + k, A.y + k, A.z + k };
|
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector3 operator - (const app::Vector3& A, const app::Vector3& B)
|
|
|
|
{
|
|
|
|
return { A.x - B.x, A.y - B.y, A.z - B.z };
|
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector3 operator - (const app::Vector3& A, const float k)
|
|
|
|
{
|
|
|
|
return { A.x - k, A.y - k, A.z - k };
|
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector3 operator * (const app::Vector3& A, const float k)
|
|
|
|
{
|
|
|
|
return { A.x * k, A.y * k, A.z * k };
|
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector3 operator / (const app::Vector3& A, const float k)
|
|
|
|
{
|
|
|
|
return { A.x / k, A.y / k, A.z / k };
|
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector3 operator - (const app::Vector3& A)
|
|
|
|
{
|
2022-06-08 07:52:24 +03:00
|
|
|
return { -A.x, -A.y, -A.z };
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector2 operator + (const app::Vector2& A, const float k)
|
|
|
|
{
|
2022-06-08 07:52:24 +03:00
|
|
|
return { A.x + k, A.y + k };
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector2 operator - (const app::Vector2& A, const app::Vector2& B)
|
|
|
|
{
|
|
|
|
return { A.x - B.x, A.y - B.y };
|
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector2 operator - (const app::Vector2& A, const float k)
|
|
|
|
{
|
2022-06-08 07:52:24 +03:00
|
|
|
return { A.x - k, A.y - k };
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector2 operator + (const app::Vector2& A, const app::Vector2& B)
|
|
|
|
{
|
2022-06-08 07:52:24 +03:00
|
|
|
return { A.x + B.x, A.y + B.y };
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector2 operator * (const app::Vector2& A, const float k)
|
|
|
|
{
|
2022-06-08 07:52:24 +03:00
|
|
|
return { A.x * k, A.y * k };
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector2 operator * (const app::Vector2& A, const app::Vector2& B)
|
|
|
|
{
|
2022-06-08 07:52:24 +03:00
|
|
|
return { A.x * B.x, A.y * B.y };
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector2 operator / (const app::Vector2& A, const float k)
|
|
|
|
{
|
2022-06-08 07:52:24 +03:00
|
|
|
return { A.x / k, A.y / k };
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline app::Vector2 operator - (const app::Vector2& A)
|
|
|
|
{
|
2022-06-08 07:52:24 +03:00
|
|
|
return { -A.x, -A.y };
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
2022-06-08 07:52:24 +03:00
|
|
|
inline float GetVectorMagnitude(const app::Vector3& A)
|
2022-05-17 03:13:41 +03:00
|
|
|
{
|
|
|
|
return sqrtf(A.x * A.x + A.y * A.y + A.z * A.z);
|
|
|
|
}
|
|
|
|
|
2022-06-08 07:52:24 +03:00
|
|
|
inline app::Vector3 GetVectorDirection(const app::Vector3& from, const app::Vector3& to)
|
2022-05-17 03:13:41 +03:00
|
|
|
{
|
|
|
|
auto dirRaw = to - from;
|
|
|
|
return dirRaw / GetVectorMagnitude(dirRaw);
|
|
|
|
}
|
|
|
|
|
2022-06-08 07:52:24 +03:00
|
|
|
inline bool IsVectorZero(const app::Vector3& vector)
|
2022-05-17 03:13:41 +03:00
|
|
|
{
|
|
|
|
return vector.x == 0 && vector.y == 0 && vector.z == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function to get mono module base address
|
|
|
|
uintptr_t il2cpp_get_mono_base_address();
|
|
|
|
|
2022-02-27 14:38:51 +03:00
|
|
|
// Helper function to get the module base address
|
|
|
|
uintptr_t il2cppi_get_base_address();
|
|
|
|
|
2022-05-17 03:13:41 +03:00
|
|
|
// Helper function to get the UnityPlayer.dll base address
|
2022-02-27 14:38:51 +03:00
|
|
|
uintptr_t il2cppi_get_unity_address();
|
|
|
|
|
|
|
|
// Helper function to open a new console window and redirect stdout there
|
|
|
|
void il2cppi_new_console();
|
2022-05-17 03:13:41 +03:00
|
|
|
void il2cppi_close_console();
|
2022-02-27 14:38:51 +03:00
|
|
|
|
|
|
|
#if _MSC_VER >= 1920
|
|
|
|
std::string il2cppi_to_string(Il2CppString* str);
|
|
|
|
std::string il2cppi_to_string(app::String* str);
|
2022-05-17 03:13:41 +03:00
|
|
|
std::string il2cppi_to_string(app::Vector vec);
|
|
|
|
std::string il2cppi_to_string(app::Vector2 vec);
|
|
|
|
std::string il2cppi_to_string(app::Vector3 vec);
|
2022-06-08 07:52:24 +03:00
|
|
|
app::String* string_to_il2cppi(std::string input);
|
2022-05-17 03:13:41 +03:00
|
|
|
std::string to_hex_string(app::Byte__Array* barray, int length);
|
2022-02-27 14:38:51 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Helper function to check if a metadata usage pointer is initialized
|
|
|
|
template<typename T> bool il2cppi_is_initialized(T* metadataItem) {
|
|
|
|
#if __IL2CPP_METADATA_VERISON < 270
|
|
|
|
return *metadataItem != 0;
|
|
|
|
#else
|
|
|
|
// Metadata >=27 (Unity 2020.2)
|
2022-06-08 07:52:24 +03:00
|
|
|
return !((uintptr_t)*metadataItem & 1);
|
2022-02-27 14:38:51 +03:00
|
|
|
#endif
|
|
|
|
}
|