Вопрос How to fix cheat crash

  • Автор темы Автор темы Trna
  • Дата начала Дата начала
Начинающий
Начинающий
Статус
Оффлайн
Регистрация
16 Авг 2022
Сообщения
51
Реакции
4
hello,
currently I'm writing my first internal cheat, I'm learning it by reading available dota 2 cheat sources.
my issue is, I have multiple crash in my cheat and I don't know how to fix them.


C++:
Expand Collapse Copy
SDK::CDOTAModifierManager* SDK::CDOTABaseNPC::GetModifierManager() const
{
    return MemberInline<SDK::CDOTAModifierManager>(Netvars["C_DOTA_BaseNPC"]["m_ModifierManager"]);
}

CUtlVector<SDK::CDOTAModifier*>* SDK::CDOTAModifierManager::GetModifierListRaw() const
{
    return MemberInline<CUtlVector<SDK::CDOTAModifier*>>(0x10);
}

void Hacks::DrawTargetAlert()
{
    const auto LocalPlayer = (SDK::CDOTAPlayerController*)Interfaces::EntitySystem->GetEntity(Interfaces::IEngineClient->GetLocalPlayer() + 1);

    for (const auto& Controller : Globals::Controllers)
    {
        CDOTABaseNPC_Hero* Hero = (CDOTABaseNPC_Hero*)Interfaces::EntitySystem->GetEntity(H2IDX(Controller->GetAssignedHeroHandle()));

        if (!Hero)
            continue;

        if (LocalPlayer->GetTeam() == Hero->GetTeam())
        {
            // Invalid modifier list
            auto ModifierList = Hero->GetModifierManager()->GetModifierListRaw();
            // Error on count();
            for (int32_t i = 0; i < ModifierList->Count(); i++


For example one place that my cheat get crashes is when I'm reading my teammates modifier list and somehow ( Idk how ), it gets invalid ModifierList and it crashes on calling Count. It happens rarely and I don't know exactly why and how (maybe the Hero dies or something? )

Another place that I have the exact same issue:

C++:
Expand Collapse Copy
std::array<Handle, 19> SDK::CDOTAUnitInventory::GetItemHandles() const
{
    auto span = std::span<Handle, 19>{ MemberInline<Handle>(Netvars["C_DOTA_UnitInventory"]["m_hItems"]), 19 };
}

std::vector<SDK::CDOTAItem*> SDK::CDOTAUnitInventory::GetInHandItems() const
{
    std::vector<CDOTAItem*> Items;
    auto ItemsHandle = GetItemHandles();

    for (int i = 0; i <= 5; i++)
    {
        if (HVALID(ItemsHandle[i]))
        {
            auto Item = (CDOTAItem*)Interfaces::EntitySystem->GetEntity(H2IDX(ItemsHandle[i]));
            Items.push_back(Item);
        }
    }

    return Items;
}

SDK::CDOTAItem* SDK::CDOTAUnitInventory::GetItem(const char* ItemName) const
{
    auto Items = GetInHandItems();

    for (auto& Item : Items)
    {
        if (!Item) // It's wrong. but what should I do?
            continue;

        if (strstr(Item->GetIdentity()->GetName(), ItemName))
            returnItem;
    }

    return nullptr;
}

When I'm iterating over Items, it gets invalidated
 
Try attaching Visual Studio debugger with breakpoints set on specific line with modifiers;

Most probably there is something wrong with your
C++:
Expand Collapse Copy
GetModifierListRaw()
function
also make sure your GetModifierManager works correctly.

What does it return for enemies, though?
 
hello,
currently I'm writing my first internal cheat, I'm learning it by reading available dota 2 cheat sources.
my issue is, I have multiple crash in my cheat and I don't know how to fix them.


C++:
Expand Collapse Copy
SDK::CDOTAModifierManager* SDK::CDOTABaseNPC::GetModifierManager() const
{
    return MemberInline<SDK::CDOTAModifierManager>(Netvars["C_DOTA_BaseNPC"]["m_ModifierManager"]);
}

CUtlVector<SDK::CDOTAModifier*>* SDK::CDOTAModifierManager::GetModifierListRaw() const
{
    return MemberInline<CUtlVector<SDK::CDOTAModifier*>>(0x10);
}

void Hacks::DrawTargetAlert()
{
    const auto LocalPlayer = (SDK::CDOTAPlayerController*)Interfaces::EntitySystem->GetEntity(Interfaces::IEngineClient->GetLocalPlayer() + 1);

    for (const auto& Controller : Globals::Controllers)
    {
        CDOTABaseNPC_Hero* Hero = (CDOTABaseNPC_Hero*)Interfaces::EntitySystem->GetEntity(H2IDX(Controller->GetAssignedHeroHandle()));

        if (!Hero)
            continue;

        if (LocalPlayer->GetTeam() == Hero->GetTeam())
        {
            // Invalid modifier list
            auto ModifierList = Hero->GetModifierManager()->GetModifierListRaw();
            // Error on count();
            for (int32_t i = 0; i < ModifierList->Count(); i++


For example one place that my cheat get crashes is when I'm reading my teammates modifier list and somehow ( Idk how ), it gets invalid ModifierList and it crashes on calling Count. It happens rarely and I don't know exactly why and how (maybe the Hero dies or something? )

Another place that I have the exact same issue:

C++:
Expand Collapse Copy
std::array<Handle, 19> SDK::CDOTAUnitInventory::GetItemHandles() const
{
    auto span = std::span<Handle, 19>{ MemberInline<Handle>(Netvars["C_DOTA_UnitInventory"]["m_hItems"]), 19 };
}

std::vector<SDK::CDOTAItem*> SDK::CDOTAUnitInventory::GetInHandItems() const
{
    std::vector<CDOTAItem*> Items;
    auto ItemsHandle = GetItemHandles();

    for (int i = 0; i <= 5; i++)
    {
        if (HVALID(ItemsHandle[i]))
        {
            auto Item = (CDOTAItem*)Interfaces::EntitySystem->GetEntity(H2IDX(ItemsHandle[i]));
            Items.push_back(Item);
        }
    }

    return Items;
}

SDK::CDOTAItem* SDK::CDOTAUnitInventory::GetItem(const char* ItemName) const
{
    auto Items = GetInHandItems();

    for (auto& Item : Items)
    {
        if (!Item) // It's wrong. but what should I do?
            continue;

        if (strstr(Item->GetIdentity()->GetName(), ItemName))
            returnItem;
    }

    return nullptr;
}

When I'm iterating over Items, it gets invalidated
1) use a debugger
2) log all kinds of stuff.
3) nullptr check? (preferably with logging - such as "Modifier list nullptr for entity npc_dota_hero_something" - so that you can can see which entity is problematic, then you can check in-game if it's dead/invisible etc and then correlate the facts and draw a conclusion)
4) verify all offsets are correct(log them and, using memory inspection tools(reclass etc), verify that the data you're seeking is indeed located there)
5) verify addition of offsets(sometimes one adds to the wrong pointer or uses wrong operators) and the data you read(log stuff, and using memory inspection tools, validate that the data you read is correct, and that you read it from the correct place). basically, correlate what you get in your software(pointers offsets etc) to what you see in memory inspection tools
6) are you lacking a return statement or did you just post the code wrong?
C++:
Expand Collapse Copy
std::array<Handle, 19> SDK::CDOTAUnitInventory::GetItemHandles() const
{
    auto span = std::span<Handle, 19>{ MemberInline<Handle>(Netvars["C_DOTA_UnitInventory"]["m_hItems"]), 19 };
}
 
1) use a debugger
2) log all kinds of stuff.
3) nullptr check? (preferably with logging - such as "Modifier list nullptr for entity npc_dota_hero_something" - so that you can see which entity is problematic, then you can check in-game if it's dead/invisible etc and then correlate the facts and draw a conclusion)
4) verify all offsets are correct(log them and, using memory inspection tools(reclass etc), verify that the data you're seeking is indeed located there)
5) verify addition of offsets(sometimes one adds to the wrong pointer or uses wrong operators) and the data you read(log stuff, and using memory inspection tools, validate that the data you read is correct, and that you read it from the correct place). basically, correlate what you get in your software(pointers offsets etc) to what you see in memory inspection tools
6) are you missing a return statement or did you just post the code wrong?
C++:
Expand Collapse Copy
std::array<Handle, 19> SDK::CDOTAUnitInventory::GetItemHandles() const
{
    auto span = std::span<Handle, 19>{ MemberInline<Handle>(Netvars["C_DOTA_UnitInventory"]["m_hItems"]), 19 };
}


I founded the issue.
I have this piece of code in frameStageNotify, I didn't consider the case when the player lefts the game. ( Controllers is a std::unordered_set<SDK::CDOTAPlayerController*> )

C++:
Expand Collapse Copy
 if (BinaryName.find("C_DOTAPlayerController") != std::string::npos)
    {
        const auto PlayerController = (CDOTAPlayerController*)Entity;
        Globals::Controllers.insert(PlayerController);
    }

My goal was to read controllers just in one thread and store them and use them on another thread.
 
Последнее редактирование:
Назад
Сверху Снизу