Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use __try in functions that require object unwinding fix

Tags:

c++

I've got this loop here for a game bot which requires a __try __except to prevent insta-crashing when the code is injected. However, I'm getting the error: Cannot use __try in functions that require object unwinding fix.

I've looked through all function calls inside of this function, and not a single one of them contain a nested __try __except and I'm also building with /EHs.

Here's my code;

void bot::logic::loop()
{
    while (true)
    {
        __try
        {
            if (bot::logic::should_close())
                exit(33062);

            om::refresh_minions();

            if (local_player::is_threatened())
                local_player::handle_threat();

            if (local_player::is_in_turret())
            {
                utils::move_to_suitable_pos();
                std::this_thread::sleep_for(12s);
            }

            object* localplayer = obj_local_player;
            bot::logic::calculate_buys(localplayer->current_gold);

            obj_manager* manager = (obj_manager*)(m_base + o_obj_manager);
            for (int32_t i = 0; i < manager->highest_index; i++)
            {
                object* this_object = manager->ptrs[i];

                if (this_object)
                {      
                    if (is_minion(this_object) == 3073)
                        if (local_player::object_is_enemy(this_object))
                            if (utils::is_object_mid(this_object))
                                if (is_alive(this_object) == TRUE)
                                    utils::Log("all passed");

                    if (local_player::object_is_enemy(this_object) && utils::is_object_mid(this_object) && is_alive(this_object) == TRUE && is_minion(this_object) == 3073)
                    {
                        object* enemy_minion = this_object;

                        for (int i = 0; i < game::minion_maxed_index; i++)
                        {
                            bot::logic::moving_to_cs_loop(om_ally_minions[i].minion_object, enemy_minion);
                            bot::logic::csing_loop();
                        }
                    }
                }
            }
            std::this_thread::sleep_for(100ms);
        }
        __except (EXCEPTION_EXECUTE_HANDLER) {};
    }
}

Can anyone tell me which objects 'require unwinding' and how I can prevent this error?

EDIT: I've found the error occurs within the code;

if (is_minion(this_object) == 3073)
    if (local_player::object_is_enemy(this_object))
        if (utils::is_object_mid(this_object))
            if (is_alive(this_object) == TRUE)
                utils::Log("all passed");
like image 594
siroot Avatar asked Aug 06 '18 06:08

siroot


2 Answers

Anyway I would suggest you move the code within __try/__except to an own function then call it, that way the stack unwinding occurs in the other function.

e.g.

void loop()
{
  __try  { loopimpl(); }
  __except(EXCEPTION_EXECUTE_HANDLER) {};
}

void loopimpl()
{
  while (true) { ... }
}
like image 57
AndersK Avatar answered Nov 10 '22 00:11

AndersK


Move __try/__except upper in call hierarchy

void test() {
    myClass m;
    __try
    {
        m.run();
    }
    __except (GenerateDump(GetExceptionInformation())){}
}
int main()
{
    test();
}

Result: Error C2712 Cannot use __try in functions that require object unwinding ...

But:

void test() {
    myClass m;  
    m.run();
}
int main()
{
    __try
    {
        test();
    }
    __except (GenerateDump(GetExceptionInformation())) {}
}

Result: OK

like image 29
Piotr Sydow Avatar answered Nov 09 '22 22:11

Piotr Sydow