Вопрос GetLocalPlayer returns 0

Начинающий
Статус
Оффлайн
Регистрация
28 Июн 2022
Сообщения
15
Реакции[?]
1
Поинты[?]
1K
Код:
class IEngineClient : IAppSystem
{
public:
    virtual bool IsPaused(void) = 0;
    virtual float GetTimeScale(void) = 0;
    virtual void FindOrCreateWorldSession(void) = 0;
    virtual void GetEntityLumpForTemplate(void) = 0;
    virtual void GetStatsAppID(void) = 0;
    virtual void* GetGameClientFactory(void) = 0;
    virtual void* GetSteamUniverse(void) = 0; // Added Late June 2018
    virtual void ServerCmd(int inputCommandSrc, const char* command) = 0;
    virtual void ClientCmd(int inputCommandSrc, const char* command) = 0;
    virtual bool GetPlayerInfo(int iIndex, player_info_t* pInfo) = 0; // 20
    virtual int GetPlayerForUserID(int ID) = 0;
    virtual int GetLocalPlayer(int& LocalPlayerID, int splitScreenSlot = 0) = 0;
    virtual long GetLastTimestamp(void) = 0;
....


class CGameEntitySystem {
public:
    virtual void n_0();
    virtual void BuildResourceManifest(void); // 01
    virtual void n_2();
    virtual void n_3();
    virtual void n_4();
    virtual void n_5();
    virtual void n_6();
    virtual void AddRefKeyValues(); // 7
    virtual void ReleaseKeyValues(); // 8
    virtual void n_9();
    virtual void n_10();
    virtual void ClearEntityDatabase(void); // 11
    virtual CEntityInstance* FindEntityProcedural(const char *...);
    virtual CEntityInstance * OnEntityParentChanged (CEntityInstance *, CEntityInstance *); // 13
    virtual CEntityInstance* OnAddEntity(CEntityInstance*, CEntityHandle); // 14
    virtual CEntityInstance * OnRemoveEntity (CEntityInstance *, CEntityHandle); // 15
    virtual void n_16();
    virtual void SortEntities(int, EntitySpawnInfo_t*, int*, int*); // 17
    virtual void n_18();
    virtual void n_19();
    virtual void n_20();
    virtual void n_21();

    void* unk;
    CEntityIdentities* m_pEntityList[MAX_ENTITY_LISTS];

    CEntityInstance* GetBaseEntity(int index)
    {
        if (index <= -1 || index >= MAX_TOTAL_ENTITIES)
            return nullptr;

        int listToUse = (index / MAX_ENTITIES_IN_LIST);
        if (!m_pEntityList[listToUse])
            return nullptr;

        if (m_pEntityList[listToUse]->m_pIdentities[index % MAX_ENTITIES_IN_LIST].entity)
            return m_pEntityList[listToUse]->m_pIdentities[index % MAX_ENTITIES_IN_LIST].entity;
        else
            return nullptr;
    }
};


void Start(){
void* client = GetInterface("client.dll", "Source2Client002");
uintptr_t* vmt_slot = *(uintptr_t**)client + 25;
uintptr_t addr_start = *vmt_slot + 3;
entity = *(CGameEntitySystem**)(addr_start + *(uint32_t*)(addr_start)+4);
IEngineClient* engine = static_cast<IEngineClient*>(GetInterface("engine2.dll", "Source2EngineToClient001"));

int result = 0;
int entID= engine->GetLocalPlayer(result , 0);
CBaseEntity* ent = (CBaseEntity*)entity->GetBaseEntity(entID);
}
i already have DOTA_Unit_Hero entity list created and i want to know which of the entity is my localplayer entity.
both result and entID only returns 0.
any help please ? thanks
 
Shitcode lord 💩
Забаненный
Статус
Оффлайн
Регистрация
25 Ноя 2020
Сообщения
272
Реакции[?]
84
Поинты[?]
8K
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
C++:
static int g_LocalIndex = -1;
...
int& GetLocalPlayer(int& = g_LocalIndex, int screen = 0) {
    typedef int& (*Fn)(void*, int&, int);
    return Memory::GetVFunc<Fn>(this, 22)(this, g_LocalIndex, screen);
}
...
int LocalPlayerIndex = vmt.engine->GetLocalPlayer() + 1;
 
Начинающий
Статус
Оффлайн
Регистрация
28 Июн 2022
Сообщения
15
Реакции[?]
1
Поинты[?]
1K
C++:
static int g_LocalIndex = -1;
...
int& GetLocalPlayer(int& = g_LocalIndex, int screen = 0) {
    typedef int& (*Fn)(void*, int&, int);
    return Memory::GetVFunc<Fn>(this, 22)(this, g_LocalIndex, screen);
}
...
int LocalPlayerIndex = vmt.engine->GetLocalPlayer() + 1;
thanks for this <3
 
Участник
Статус
Оффлайн
Регистрация
23 Май 2019
Сообщения
781
Реакции[?]
331
Поинты[?]
63K
Код:
class IEngineClient : IAppSystem
{
public:
    virtual bool IsPaused(void) = 0;
    virtual float GetTimeScale(void) = 0;
    virtual void FindOrCreateWorldSession(void) = 0;
    virtual void GetEntityLumpForTemplate(void) = 0;
    virtual void GetStatsAppID(void) = 0;
    virtual void* GetGameClientFactory(void) = 0;
    virtual void* GetSteamUniverse(void) = 0; // Added Late June 2018
    virtual void ServerCmd(int inputCommandSrc, const char* command) = 0;
    virtual void ClientCmd(int inputCommandSrc, const char* command) = 0;
    virtual bool GetPlayerInfo(int iIndex, player_info_t* pInfo) = 0; // 20
    virtual int GetPlayerForUserID(int ID) = 0;
    virtual int GetLocalPlayer(int& LocalPlayerID, int splitScreenSlot = 0) = 0;
    virtual long GetLastTimestamp(void) = 0;
....


class CGameEntitySystem {
public:
    virtual void n_0();
    virtual void BuildResourceManifest(void); // 01
    virtual void n_2();
    virtual void n_3();
    virtual void n_4();
    virtual void n_5();
    virtual void n_6();
    virtual void AddRefKeyValues(); // 7
    virtual void ReleaseKeyValues(); // 8
    virtual void n_9();
    virtual void n_10();
    virtual void ClearEntityDatabase(void); // 11
    virtual CEntityInstance* FindEntityProcedural(const char *...);
    virtual CEntityInstance * OnEntityParentChanged (CEntityInstance *, CEntityInstance *); // 13
    virtual CEntityInstance* OnAddEntity(CEntityInstance*, CEntityHandle); // 14
    virtual CEntityInstance * OnRemoveEntity (CEntityInstance *, CEntityHandle); // 15
    virtual void n_16();
    virtual void SortEntities(int, EntitySpawnInfo_t*, int*, int*); // 17
    virtual void n_18();
    virtual void n_19();
    virtual void n_20();
    virtual void n_21();

    void* unk;
    CEntityIdentities* m_pEntityList[MAX_ENTITY_LISTS];

    CEntityInstance* GetBaseEntity(int index)
    {
        if (index <= -1 || index >= MAX_TOTAL_ENTITIES)
            return nullptr;

        int listToUse = (index / MAX_ENTITIES_IN_LIST);
        if (!m_pEntityList[listToUse])
            return nullptr;

        if (m_pEntityList[listToUse]->m_pIdentities[index % MAX_ENTITIES_IN_LIST].entity)
            return m_pEntityList[listToUse]->m_pIdentities[index % MAX_ENTITIES_IN_LIST].entity;
        else
            return nullptr;
    }
};


void Start(){
void* client = GetInterface("client.dll", "Source2Client002");
uintptr_t* vmt_slot = *(uintptr_t**)client + 25;
uintptr_t addr_start = *vmt_slot + 3;
entity = *(CGameEntitySystem**)(addr_start + *(uint32_t*)(addr_start)+4);
IEngineClient* engine = static_cast<IEngineClient*>(GetInterface("engine2.dll", "Source2EngineToClient001"));

int result = 0;
int entID= engine->GetLocalPlayer(result , 0);
CBaseEntity* ent = (CBaseEntity*)entity->GetBaseEntity(entID);
}
i already have DOTA_Unit_Hero entity list created and i want to know which of the entity is my localplayer entity.
both result and entID only returns 0.
any help please ? thanks
that's because GetLocalPlayer returns a CPlayerSlot(basically an int but with a special meaning) and not an int. CPlayerSlot is converted to CEntityIndex by adding 1. CEntityIndex(an int basically) is then used within the entity system.
C++:
//CEngineClient VVV
private:
    static inline constexpr auto GetLocalPlayerIndex_VMT_Index = 22;
public:
    CPlayerSlot GetLocalPlayerSlot()
    {
        CPlayerSlot result{};
        CallVFunc<GetLocalPlayerIndex_VMT_Index>(&result, /*splitscreen slot*/0);
        return result;
    }
C++:
CPlayerSlot::operator CEntityIndex() const noexcept
{
    return { Get() + 1 };
}
 
Начинающий
Статус
Оффлайн
Регистрация
28 Июн 2022
Сообщения
15
Реакции[?]
1
Поинты[?]
1K
that's because GetLocalPlayer returns a CPlayerSlot(basically an int but with a special meaning) and not an int. CPlayerSlot is converted to CEntityIndex by adding 1. CEntityIndex(an int basically) is then used within the entity system.
C++:
//CEngineClient VVV
private:
    static inline constexpr auto GetLocalPlayerIndex_VMT_Index = 22;
public:
    CPlayerSlot GetLocalPlayerSlot()
    {
        CPlayerSlot result{};
        CallVFunc<GetLocalPlayerIndex_VMT_Index>(&result, /*splitscreen slot*/0);
        return result;
    }
C++:
CPlayerSlot::operator CEntityIndex() const noexcept
{
    return { Get() + 1 };
}
thanks i understand now
one last question please.

Код:
std::vector<CBaseEntInstance*> CPlayers;

CBaseEntInstance* OnAddEntity(CGameEntitySystem* ecx, CBaseEntInstance* ptr, EntityHandle index)
{
    auto ret = entityVMT->GetOriginalMethod(OnAddEntity)(ecx, ptr, index);
    const char* typeName = ptr->Schema_DynamicBinding()->bindingName;

    if (strstr(typeName, "DOTA_Unit_Hero")) {

        auto alreadyExists = false;
        for (auto cplayer: CPlayers)
        {
            if (typeName == cplayer->Schema_DynamicBinding()->bindingName)
            {
                alreadyExists = true;
                break;
            }
        }

        if (!alreadyExists)
        {
                CPlayers.emplace_back(ptr);
        }
    }

    return ret;
}

CBaseEntInstance* OnRemoveEntity(CGameEntitySystem* ecx, CBaseEntInstance* ptr, EntityHandle index)
{
    const char* typeName = ptr->Schema_DynamicBinding()->bindingName;

    if (strstr(typeName, "DOTA_Unit_Hero")) {
        for (size_t i = CPlayers.size(); i-- > 0; ) {
            if (CPlayers[i] == ptr) {
                CPlayers.erase(CPlayers.begin() + i);
                break;
            }
        }
    }

    return entityVMT->GetOriginalMethod(OnRemoveEntity)(ecx, ptr, index);
}
i have array of std::vector<CBaseEntInstance*> CPlayers;
How to know which is my local player entity in the array?
 
Shitcode lord 💩
Забаненный
Статус
Оффлайн
Регистрация
25 Ноя 2020
Сообщения
272
Реакции[?]
84
Поинты[?]
8K
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
thanks i understand now
one last question please.

Код:
std::vector<CBaseEntInstance*> CPlayers;

CBaseEntInstance* OnAddEntity(CGameEntitySystem* ecx, CBaseEntInstance* ptr, EntityHandle index)
{
    auto ret = entityVMT->GetOriginalMethod(OnAddEntity)(ecx, ptr, index);
    const char* typeName = ptr->Schema_DynamicBinding()->bindingName;

    if (strstr(typeName, "DOTA_Unit_Hero")) {

        auto alreadyExists = false;
        for (auto cplayer: CPlayers)
        {
            if (typeName == cplayer->Schema_DynamicBinding()->bindingName)
            {
                alreadyExists = true;
                break;
            }
        }

        if (!alreadyExists)
        {
                CPlayers.emplace_back(ptr);
        }
    }

    return ret;
}

CBaseEntInstance* OnRemoveEntity(CGameEntitySystem* ecx, CBaseEntInstance* ptr, EntityHandle index)
{
    const char* typeName = ptr->Schema_DynamicBinding()->bindingName;

    if (strstr(typeName, "DOTA_Unit_Hero")) {
        for (size_t i = CPlayers.size(); i-- > 0; ) {
            if (CPlayers[i] == ptr) {
                CPlayers.erase(CPlayers.begin() + i);
                break;
            }
        }
    }

    return entityVMT->GetOriginalMethod(OnRemoveEntity)(ecx, ptr, index);
}
i have array of std::vector<CBaseEntInstance*> CPlayers;
How to know which is my local player entity in the array?
Just do smth like this at "player_connect_full" event.
CDOTAPlayerController* LocalPlayer = vmt.EntitySystem->GetBaseEntity(vmt.engine->GetLocalPlayer());
 
Сверху Снизу