Game quits when I alt+tab (Reset hook)

Loku

Известный
Автор темы
30
7
I'm using @AnWu template which is amazing, well it's not really a template but you can use it as is as you have imgui, sampapi and some other plugins so it's nice, thing is to hook Present and Reset it does it like this :
Perhaps I saw some people that somehow don't have permission to d3d9.dll thus failing to hook anything, that's why I tried to do it directly from gta sa pointer to d3d9 interface aka:
C++:
 DWORD pDevice = *reinterpret_cast<DWORD*>(0xC97C28);
    void** vTable = *reinterpret_cast<void***>(pDevice);
 
    hookPresent.set_dest(vTable[17]);
    hookPresent.before.connect(std::bind(&PluginRender::onPresent, this, _1, _2, _3, _4, _5, _6));
    hookPresent.install();
    hookReset.set_dest(vTable[16]);
    hookReset.before.connect(std::bind(&PluginRender::onLost, this, _1, _2, _3));
    hookReset.after.connect(std::bind(&PluginRender::onReset, this, _1, _2, _3, _4));
    hookReset.install();

And it does work good, thing is that whenever I alt+tab the game basically exits, what I saw different from the other hook method is that in the original code onLost and onReset get both called but doing it directly with d3d9 interface only onLost does get called, I'm out of ideas so if anyone can give me a hand, it would be amazing.
Thanks!
 

Loku

Известный
Автор темы
30
7
Use it:
I was changing everything from my project to your template and I noticed why it happened fast, it's basically here:
C++:
void CTimer__Update(const decltype(CTimerHook)& hook) {
    static bool init{};
    if (!init) {
        setD3D9Hooks();
        init = { true };
    }

    hook.get_trampoline()();
}

I basically add a message like "Plugin Loaded" so I just waited for samp "samp::RefChat() != nullptr" but if you do so and hook d3d9 after it, it's when onReset doesn't get called thus crashing when alt +tabbing, so you just need to hook d3d9 just after CTimer hook and before samp initialization. If I renember correctly samp overrided everything of gta so it could be because of it? Idk but well, gotcha.
 
Последнее редактирование: