#include "main.h"
#include "detours.h"

typedef void (WINAPI *ctFunc)(void);
typedef char* (WINAPI *gtFunc)(void);
typedef void (WINAPI *atFunc)(const char*, unsigned long, bool);
typedef void* (WINAPI *ftFunc)(int);

ctFunc clear_text = reinterpret_cast<ctFunc>(0x66023a70);
gtFunc get_text = reinterpret_cast<gtFunc>(0x66023a10);
atFunc append_text = reinterpret_cast<atFunc>(0x66028870);
ftFunc find_edit = reinterpret_cast<ftFunc>(0x660231f0);

void Mget_text();
char* Mclear_text();
void Mappend_text(const char*, unsigned long, bool);

extern "C" BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
        { 
        	
        //	__asm("mov eax, 1");
        	
            //MessageBox(0, "Attached.", "msg", MB_OK | MB_ICONINFORMATION);
            
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            DetourAttach(&(PVOID&)get_text, (PVOID) Mget_text);
            DetourAttach(&(PVOID&)clear_text, (PVOID) Mclear_text);
            DetourAttach(&(PVOID&)append_text, (PVOID) Mappend_text);
            DetourTransactionCommit();
            
        }
            break;

        case DLL_PROCESS_DETACH:
		{
			DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            DetourDetach(&(PVOID&)get_text, (PVOID) Mget_text);
            DetourDetach(&(PVOID&)clear_text, (PVOID) Mclear_text);
            DetourDetach(&(PVOID&)append_text, (PVOID) Mappend_text);
            DetourTransactionCommit();
            
		}
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // successful
}

void Mget_text()
{
	
}

char* Mclear_text()
{
	
}

void Mappend_text(const char* txt, unsigned long color, bool unk)
{
	
}

/* Errors:

Z]+0x8)||undefined reference to `_SEH_prolog4'|
Z]+0x72)||undefined reference to `_SEH_epilog4'|
Z]+0x8)||undefined reference to `_SEH_prolog4'|
Z]+0x5e)||undefined reference to `_SEH_epilog4'|
0]+0x56)||undefined reference to `??3@YAXPAX@Z'|
0]+0x83)||undefined reference to `??3@YAXPAX@Z'|
4]+0xf)||undefined reference to `__security_cookie'|
4]+0x1d2)||undefined reference to `??3@YAXPAX@Z'|
4]+0x1ff)||undefined reference to `??3@YAXPAX@Z'|
4]+0x236)||undefined reference to `@__security_check_cookie@4'|
4]+0x20)||undefined reference to `??2@YAPAXI@Z'|
4]+0x46)||undefined reference to `??3@YAXPAX@Z'|
20]+0xbc)||undefined reference to `??2@YAPAXI@Z'|
20]+0x1f0)||undefined reference to `??3@YAXPAX@Z'|
8]+0x56)||undefined reference to `??2@YAPAXI@Z'|
8]+0xed)||undefined reference to `??3@YAXPAX@Z'|
16]+0x7)||undefined reference to `__security_cookie'|
16]+0x39)||undefined reference to `@__security_check_cookie@4'|
||=== Build finished: 18 errors, 0 warnings ===|

*/