diff --git a/src/FriendButton.cpp b/src/FriendButton.cpp index ef492b1..b3769e5 100644 --- a/src/FriendButton.cpp +++ b/src/FriendButton.cpp @@ -22,7 +22,8 @@ UnityEngine::Color m_clrVerifiedColor = UnityEngine::Color(0.5f, 1.0f, 0.5f, 1.0 static bool IsVerified(std::string userID) { il2cpp_utils::getLogger().info("Checking if player is verified"); - for(int i = 0; i < GorillaFriends::WebVerified::verifiedUserIds.size(); i++) + int listsize = GorillaFriends::WebVerified::verifiedUserIds.size(); + for(int i = 0; i < listsize; ++i) { if(GorillaFriends::WebVerified::verifiedUserIds[i] == userID) return true; } @@ -37,7 +38,8 @@ static bool IsFriend(std::string userID) static bool IsInFriendList(std::string userID) { - for(int i = 0; i < GorillaFriends::WebVerified::m_listCurrentSessionFriends.size(); i++) + int listsize = GorillaFriends::WebVerified::m_listCurrentSessionFriends.size(); + for(int i = 0; i < listsize; ++i) { if(GorillaFriends::WebVerified::m_listCurrentSessionFriends[i] == userID) return true; } @@ -77,7 +79,7 @@ void GorillaFriends::FriendButton::Update() if(!IsInFriendList(to_utf8(csstrtostr(parentLine->linePlayer->UserId)))) GorillaFriends::WebVerified::m_listCurrentSessionFriends.push_back(to_utf8(csstrtostr(parentLine->linePlayer->UserId))); parentLine->playerName->set_color(m_clrFriendColor); isOn = true; - myText->set_text(onText); + //myText->set_text(onText); UpdateColor(); } else @@ -104,13 +106,13 @@ void GorillaFriends::FriendButton::Update() parentLine->playerName->set_color(UnityEngine::Color::get_white()); parentLine->playerVRRig->playerText->set_color(UnityEngine::Color::get_white()); } - myText->set_text(onText); + //myText->set_text(offText); } else { parentLine->playerName->set_color(m_clrFriendColor); parentLine->playerVRRig->playerText->set_color(m_clrFriendColor); - myText->set_text(onText); + //myText->set_text(onText); } } } @@ -131,11 +133,12 @@ void GorillaFriends::FriendButton::OnTriggerEnter(UnityEngine::Collider* collide GorillaFriends::WebVerified::m_listCurrentSessionFriends.push_back(to_utf8(csstrtostr(parentLine->linePlayer->UserId))); UnityEngine::PlayerPrefs::SetInt(il2cpp_utils::createcsstr(to_utf8(csstrtostr(parentLine->linePlayer->UserId)) + "_friend"), 1); parentLine->playerName->set_color(m_clrFriendColor); - myText->set_text(onText); + //myText->set_text(onText); return; } - for(int i = 0; i < GorillaFriends::WebVerified::m_listCurrentSessionFriends.size(); i++) + int listsize = GorillaFriends::WebVerified::m_listCurrentSessionFriends.size(); + for(int i = 0; i < listsize; ++i) { if(GorillaFriends::WebVerified::m_listCurrentSessionFriends[i] == to_utf8(csstrtostr(parentLine->linePlayer->UserId))) { @@ -143,7 +146,7 @@ void GorillaFriends::FriendButton::OnTriggerEnter(UnityEngine::Collider* collide } } UnityEngine::PlayerPrefs::SetInt(il2cpp_utils::createcsstr(to_utf8(csstrtostr(parentLine->linePlayer->UserId)) + "_friend"), 0); - myText->set_text(offText); + //myText->set_text(offText); if(IsVerified(to_utf8(csstrtostr(parentLine->linePlayer->UserId)))) { diff --git a/src/main.cpp b/src/main.cpp index 4ad2422..de5634a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,17 +72,19 @@ GorillaFriends::FriendButton* m_pFriendButtonController; MAKE_HOOK_OFFSETLESS(GSB_Awake, void, GlobalNamespace::GorillaScoreBoard* self) { - GorillaFriends::WebVerified::m_listCurrentSessionFriends.clear(); + if(m_pScoreboardFriendBtn != nullptr) + { + // Friend Button prefab has been created, skip our code + GSB_Awake(self); + return; + } + // I think we dont need it here: + // GorillaFriends::WebVerified::m_listCurrentSessionFriends.clear(); getLogger().info("GSB_AWAKE"); auto transform = self->scoreBoardLinePrefab->get_transform(); int transformNum = transform->get_childCount(); - for(int i = 0; i < transformNum; i++) + for(int i = 0; i < transformNum; ++i) { - if(m_pScoreboardFriendBtn != nullptr) - { - GSB_Awake(self); - return; - } getLogger().info("ooga"); auto t = transform->GetChild(i); if(to_utf8(csstrtostr(t->get_name())) == "Mute Button") @@ -104,14 +106,19 @@ MAKE_HOOK_OFFSETLESS(GSB_Awake, void, GlobalNamespace::GorillaScoreBoard* self) m_pFriendButtonController->myText = controller->myText; m_pFriendButtonController->myText->set_text(m_pFriendButtonController->offText); m_pFriendButtonController->offMaterial = controller->offMaterial; + /* Maybe we need to instantiate onMaterial, please check */ m_pFriendButtonController->onMaterial = controller->onMaterial; m_pFriendButtonController->onMaterial->set_color(UnityEngine::Color(0.8f, 0.5f, 0.9f, 1.0f)); UnityEngine::GameObject::Destroy(controller); } } + // We're added a Friend Button! Break our "for loop" + break; } } + // Call original function + GSB_Awake(self); } MAKE_HOOK_OFFSETLESS(PN_Disconnect, void, Photon::Pun::PhotonNetwork* self)