#include "..\..\include\homm3.h"
Patcher* _P;
PatcherInstance* _PI;
_dword_ timeDlgCreditsSmoothly = 0;
// подменяем вызов функции sub_00597C30 по адресу 0x4EE674,
// в оригинале sub_00597C30 проверяет, воспроизводится ли видео
char __cdecl hook_call_sub_00597C30() 
{
    if (o_GetTime() > timeDlgCreditsSmoothly + 15)
    {
        timeDlgCreditsSmoothly = o_GetTime();
        return 1;
    }
    else return 0;
}    
//  вместо mainmenu.pcx рисуем часть GamSelBk.pcx
int __stdcall Draw_GamSelBk(HiHook* hook, int pcx, int srcX, int srcY, int width, int height, int buffer, int x, int y, int maxX, int maxY, int scanline, int TransparentColor)
{
    return CALL_12(int, __thiscall, hook->GetDefaultFunc(), *(int*)0x699568, 460, 0, 340, 600, buffer, x, y, maxX, maxY, scanline, TransparentColor);    
}                                                 
                                             
                                             
                                                                                         
int __stdcall ApplyPatchesInWinMain(LoHook* h, HookContext* c)
{
    //отменяем хук wnd
    _P->UndoAllAt(0x4EE674);     
    //и пишем свой
    _PI->WriteHiHook(0x4EE674, CALL_, DIRECT_, CDECL_, hook_call_sub_00597C30);  
    // более плавное отображение credits /код из wnd, на случай, если wnd отключен) 
    _PI->WriteByte(0x4EE6C0 +2, 1); 
    _PI->WriteByte(0x4EE716 +2, 1); 
    _PI->WriteByte(0x4EE75E +2, 1); 
    _PI->WriteByte(0x4EE761 +2, 1); 
    //забиваем нопами проверку VideoPlaying() /делаем бесконечный цикл
    _PI->WriteHexPatch(0x4EE61E, "9090909090 9090 909090909090"); 
    // избавляемся от mainmenu.pcx
    _PI->WriteHiHook(0x4EF7EF, CALL_, EXTENDED_, THISCALL_, Draw_GamSelBk);
    return EXEC_DEFAULT;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    static _bool_ plugin_On = 0;
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        if (!plugin_On)
        {
            plugin_On = 1;    
            _P = GetPatcher();
            _PI = _P->CreateInstance("credits unlink"); 
            _PI->WriteLoHook(0x4F812E, ApplyPatchesInWinMain); 
        }
        break;
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}