Help! Help with playerlist

libModz

Awesome Active Platinian
Original poster
Jun 2, 2022
169
30
28
UK
Hey guys, I have a playerlist but it only shows players names correctly with 6 or more characters in their nickname, players with 5 or less characters show as weird symbols, I think it has something to do with my monoString struct and the way it converts, but no idea how to fix. Any help appreciated, thanks

C++:
typedef struct _monoString
{
    void *player;
    int id;
    void *photonView;
    char chars[1];
    void PhotonViewInfo(void *player, int id, void *photonView);
    const char* getString()
    {
        std::u16string u16string(reinterpret_cast<const char16_t *>(chars));
        std::wstring wstring(u16string.begin(), u16string.end());
        std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> convert;

        return convert.to_bytes(wstring).c_str();
    }
        std::string stdgetString()
    {
        std::u16string u16string(reinterpret_cast<const char16_t *>(chars));
        std::wstring wstring(u16string.begin(), u16string.end());
        std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> convert;

        return convert.to_bytes(wstring);
    }
    char* getRawChars()
    {
        return chars;
    }
    }
 
Last edited:
  • Like
Reactions: NotAWeeb!

mIsmanXP

Approved Modder
Approved Modder
Feb 20, 2022
205
9,596
193
Republic of Indonesia
Are you using `getString` or `stdgetString`?

If you're using `getString`, the object that holds the `char*` is destroyed when you leave the function.
it may display garbage if the character count is less than 5. However, when the character count is more than 5 or 6, the characters are stored on the heap and remain intact even when you leave the function.
 

libModz

Awesome Active Platinian
Original poster
Jun 2, 2022
169
30
28
UK
I'm not sure, I didn't make the code myself.

C++:
if (PhotonNetwork_get_player!=nullptr) {
    auto playerlist = PhotonNetwork_get_otherPlayers();
    for (int i = 0; i < playerlist->getLength(); ++i) {
        auto players = playerlist->getPointer()[i];
        if (players != NULL) {
            env->SetObjectArrayElement(playerNames, i+1,
            env->NewStringUTF(PlayerExtensions_GetNickname(players)->getString()));
        }
    }
}
return playerNames;
}
 

libModz

Awesome Active Platinian
Original poster
Jun 2, 2022
169
30
28
UK
C++:
if(PhotonPlayer!=nullptr) {
                        monoString *playername = PlayerExtensions_GetNickname(PhotonPlayer);
                        if(playername->stdgetString().compare(PlayerListKick) == 0) {
                            PhotonNetwork_CloseConnection(PhotonPlayer);
 

mIsmanXP

Approved Modder
Approved Modder
Feb 20, 2022
205
9,596
193
Republic of Indonesia
I'm not sure, I didn't make the code myself.

C++:
if (PhotonNetwork_get_player!=nullptr) {
    auto playerlist = PhotonNetwork_get_otherPlayers();
    for (int i = 0; i < playerlist->getLength(); ++i) {
        auto players = playerlist->getPointer()[i];
        if (players != NULL) {
            env->SetObjectArrayElement(playerNames, i+1,
            env->NewStringUTF(PlayerExtensions_GetNickname(players)->getString()));
        }
    }
}
return playerNames;
}
There, replace getString with getstdString().c_str()

Edit* alright, didn't see your post before posting this 😆
 
  • Like
Reactions: libModz