added IsNull function
IsNull(app::Object_1*): detects whether objects are null, works more efficiently than a nullptr check.
This commit is contained in:
@@ -73,6 +73,14 @@ bool IsInGame()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsNull(app::Object_1* obj)
|
||||||
|
{
|
||||||
|
if (obj == nullptr)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return !app::Object_1_op_Implicit(obj, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
app::GameObject* GetAzazel(app::Survival* survival)
|
app::GameObject* GetAzazel(app::Survival* survival)
|
||||||
{
|
{
|
||||||
app::GameObject* ai = app::Survival_GetAzazel(survival, nullptr);
|
app::GameObject* ai = app::Survival_GetAzazel(survival, nullptr);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ bool IsLocalPlayer(app::NolanBehaviour* player);
|
|||||||
bool IsPlayerCrawling();
|
bool IsPlayerCrawling();
|
||||||
bool IsPlayerCrawling(app::GameObject* go);
|
bool IsPlayerCrawling(app::GameObject* go);
|
||||||
bool IsInGame();
|
bool IsInGame();
|
||||||
|
bool IsNull(app::Object_1* obj);
|
||||||
|
|
||||||
app::GameObject* GetAzazel(app::Survival* survival);
|
app::GameObject* GetAzazel(app::Survival* survival);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "Wrapper.h"
|
#include "Wrapper.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "ClientHelper.h"
|
||||||
|
|
||||||
namespace Unity {
|
namespace Unity {
|
||||||
namespace GameObject {
|
namespace GameObject {
|
||||||
@@ -10,14 +11,14 @@ namespace Unity {
|
|||||||
app::Component* GetComponentByName(app::GameObject* go, const char* type);
|
app::Component* GetComponentByName(app::GameObject* go, const char* type);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Math{
|
namespace Math {
|
||||||
namespace Vector3 {
|
namespace Vector3 {
|
||||||
std::string ToString(app::Vector3* v);
|
std::string ToString(app::Vector3* v);
|
||||||
std::string ToString(app::Vector3 v);
|
std::string ToString(app::Vector3 v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Transform{
|
namespace Transform {
|
||||||
app::Transform* Get(app::GameObject* go);
|
app::Transform* Get(app::GameObject* go);
|
||||||
app::Vector3 Position(app::Transform* transform);
|
app::Vector3 Position(app::Transform* transform);
|
||||||
}
|
}
|
||||||
@@ -44,11 +45,12 @@ namespace UnityCore {
|
|||||||
|
|
||||||
app::Object_1* obj_1 = app::Object_1_FindObjectOfType(reinterpret_cast<app::Type*>(object), nullptr);
|
app::Object_1* obj_1 = app::Object_1_FindObjectOfType(reinterpret_cast<app::Type*>(object), nullptr);
|
||||||
|
|
||||||
if (obj_1) {
|
if (IsNull(obj_1) || obj_1 == nullptr) return nullptr;
|
||||||
T* foundObject = reinterpret_cast<T*>(obj_1);
|
|
||||||
if (foundObject) {
|
T* foundObject = reinterpret_cast<T*>(obj_1);
|
||||||
return foundObject;
|
|
||||||
}
|
if (foundObject) {
|
||||||
|
return foundObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "players.h"
|
#include "players.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "ClientHelper.h"
|
||||||
|
|
||||||
|
|
||||||
app::GameObject__Array* Players::GetAllPlayers()
|
app::GameObject__Array* Players::GetAllPlayers()
|
||||||
@@ -22,6 +23,18 @@ app::GameObject__Array* Players::GetAllPlayers()
|
|||||||
|
|
||||||
app::GameObject* Player::GetLocalPlayer()
|
app::GameObject* Player::GetLocalPlayer()
|
||||||
{
|
{
|
||||||
|
static app::GameObject* cachedLocalPlayer = nullptr;
|
||||||
|
|
||||||
|
if (cachedLocalPlayer != nullptr) {
|
||||||
|
// Check if cached player is still valid
|
||||||
|
if (IsNull((app::Object_1*)cachedLocalPlayer)) {
|
||||||
|
cachedLocalPlayer = nullptr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return cachedLocalPlayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app::GameObject__Array* playerList = Players::GetAllPlayers();
|
app::GameObject__Array* playerList = Players::GetAllPlayers();
|
||||||
app::String* NolanBehaviourStr = reinterpret_cast<app::String*>(il2cpp_string_new("NolanBehaviour"));
|
app::String* NolanBehaviourStr = reinterpret_cast<app::String*>(il2cpp_string_new("NolanBehaviour"));
|
||||||
|
|
||||||
@@ -32,24 +45,23 @@ app::GameObject* Player::GetLocalPlayer()
|
|||||||
for (int i = 0; i < _size; i++) {
|
for (int i = 0; i < _size; i++) {
|
||||||
app::GameObject* currentPlayer = playerList->vector[i];
|
app::GameObject* currentPlayer = playerList->vector[i];
|
||||||
|
|
||||||
if (app::GameObject_GetComponentByName) {
|
if (IsNull((app::Object_1*)currentPlayer)) {
|
||||||
app::Component* nbComponent = app::GameObject_GetComponentByName(currentPlayer, NolanBehaviourStr, nullptr);
|
return nullptr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (app::GameObject_GetComponentByName) {
|
||||||
|
app::Component* nbComponent = app::GameObject_GetComponentByName(currentPlayer, NolanBehaviourStr, nullptr);
|
||||||
|
|
||||||
if (nbComponent) {
|
if (nbComponent) {
|
||||||
app::NolanBehaviour* nb = reinterpret_cast<app::NolanBehaviour*>(nbComponent);
|
app::NolanBehaviour* nb = reinterpret_cast<app::NolanBehaviour*>(nbComponent);
|
||||||
|
|
||||||
if (nb) {
|
if (nb) {
|
||||||
|
if (IsLocalPlayer(nb)) {
|
||||||
if (app::BoltEntity_get_IsOwner != nullptr && currentPlayer != nullptr) {
|
return currentPlayer;
|
||||||
|
}
|
||||||
app::BoltEntity* entity = nb->fields._._._._._entity;
|
else {
|
||||||
|
return nullptr;
|
||||||
if (entity) {
|
|
||||||
if (app::BoltEntity_get_IsOwner(entity, nullptr)) {
|
|
||||||
return currentPlayer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user