- 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)
84 lines
1.9 KiB
C++
84 lines
1.9 KiB
C++
#include "pch-il2cpp.h"
|
|
|
|
#include "players.h"
|
|
#include <helpers.h>
|
|
#include "UnityEngine.h"
|
|
#include "ClientHelper.h"
|
|
|
|
app::GameObject__Array* Players::GetAllPlayers()
|
|
{
|
|
app::GameObject__Array* players = UnityEngine::Object::FindGameObjectsWithTag("Player");
|
|
|
|
return players ? players : nullptr;
|
|
}
|
|
|
|
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();
|
|
|
|
if (!playerList || playerList->max_length == 0)
|
|
return nullptr;
|
|
|
|
il2cpp_array_size_t _size = playerList->max_length;
|
|
for (int i = 0; i < _size; i++) {
|
|
app::GameObject* currentPlayer = playerList->vector[i];
|
|
|
|
if (IsNull((app::Object_1*)currentPlayer)) {
|
|
continue;
|
|
}
|
|
else {
|
|
app::Component* nbComponent = UnityEngine::GameObject::GetComponentByName(currentPlayer, "NolanBehaviour");
|
|
|
|
if (nbComponent) {
|
|
app::NolanBehaviour* nb = reinterpret_cast<app::NolanBehaviour*>(nbComponent);
|
|
|
|
if (nb && IsLocalPlayer(nb)) {
|
|
cachedLocalPlayer = currentPlayer;
|
|
return currentPlayer;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
app::NolanBehaviour* Player::GetNolan()
|
|
{
|
|
static app::NolanBehaviour* cachedNolan = nullptr;
|
|
static app::GameObject* lastLocalPlayer = nullptr;
|
|
|
|
app::GameObject* localPlayer = Player::GetLocalPlayer();
|
|
if (localPlayer == nullptr) return nullptr;
|
|
|
|
if (lastLocalPlayer != localPlayer) {
|
|
|
|
app::Component* nbComponent = UnityEngine::GameObject::GetComponentByName(localPlayer, "NolanBehaviour");
|
|
|
|
if (nbComponent) {
|
|
|
|
app::NolanBehaviour* nb = reinterpret_cast<app::NolanBehaviour*>(nbComponent);
|
|
|
|
if (nb) {
|
|
cachedNolan = nb;
|
|
lastLocalPlayer = localPlayer;
|
|
}
|
|
}
|
|
}
|
|
|
|
return cachedNolan;
|
|
}
|
|
|
|
|