0

Good afternoon all, I have a slight problem.

I'm using Microsoft Detours 3.0 to hook a game, call my function and change some data.

Now, When I load the game, it's like my ASI file doesn't even exist.

Now, I'm wondering weather this is because I'm hooking the wrong address or the way I've wrote the hook does not work.

Here's my Dllmain:

BOOL APIENTRY dllmain(HINSTANCE hinstDLL, DWORD nReason, LPVOID lpvReserved)
{
    switch(nReason)
    {
        case DLL_PROCESS_ATTACH:
            OriginalFunction = (int(_cdecl*)(int))DetourFunction((PBYTE)GameLoading, (PBYTE)ChangeLoadingBarColor);
        case DLL_PROCESS_DETACH:
            break;
        case DLL_THREAD_ATTACH:
            break;
        case DLL_THREAD_DETACH:
            break;
    }
    return TRUE;
}

My Hook function is here:

BYTE ChangeLoadingBarColor(int a, DWORD Bar_color_R,DWORD Bar_color_G,DWORD Bar_color_B,BYTE Bar_color_set_R,BYTE Bar_color_set_G,BYTE Bar_color_set_B)
{
    return *(BYTE*)Bar_color_R;
    return *(BYTE*)Bar_color_G;
    return *(BYTE*)Bar_color_B;
    *(BYTE*)Bar_color_R = Bar_color_set_R;
    *(BYTE*)Bar_color_G = Bar_color_set_G;
    *(BYTE*)Bar_color_B = Bar_color_set_B;
    return OriginalFunction(a);
}

And here's the defined addresses and pointer to the original function:

DWORD Bar_color_R = 0x4A6B80;
DWORD Bar_color_G = 0x4A6B7E;
DWORD Bar_color_B = 0x4A6B7C;
DWORD Bar_color_set_R = {5};
DWORD Bar_color_set_G = {54};
DWORD Bar_color_set_B = {250};
DWORD GameLoading = 0x587F00;
int (_cdecl* OriginalFunction) (int);

Is my code correctly hooking the specified GameLoading address or is it wrong?

  • Is this [tag:C] or [tag:C++]? As far as I can tell there is nothing C++ about this question. Also if you want to be a little safer about your function pointer you could use an `std::function` which would throw a compiler error if you try to assign something that wouldn't work to it. – Mgetz Dec 06 '13 at 13:13
  • 2
    is that 3 consecutive return statements in ChangeLoadingBarColor? – manuell Dec 06 '13 at 13:19
  • @manuell I think you hit the nail on the head, there is no possible way that function is going to return the correct function pointer. a) the return type is `BYTE` not `std::function` b) it's returning on line 1 with a pointer to `Bar_color_R` – Mgetz Dec 06 '13 at 13:23
  • Thank you for your comments. I was wanting to get the value of the R, G and B of "Bar_color" and then change those values using "Bar_color_set" to change the color of the bar to my liking. – sharpie_eastern Dec 06 '13 at 13:59

0 Answers0