Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I try to compile this dll for MW2. It will not compile due to the fact that detour function is undefined.

Here's the code:

// dll_load.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include <stdio.h>
#include <string>
using std::string;

typedef void (*SV_GameSendServerCommand_t)(int clientNum, /*svscmd_type*/int type, const char *text);
SV_GameSendServerCommand_t SV_GameSendServerCommand = (SV_GameSendServerCommand_t)0x822548C8;

typedef int (*Key_IsDown)(int ClientNum, int ButtonEnum);
Key_IsDown button_Pressed = (Key_IsDown)0x82141308;

typedef void* (*R_RegisterFont_t)(char* asset, int imagetrack);
R_RegisterFont_t R_RegisterFont = (R_RegisterFont_t)0x8234DC20;

typedef void (*R_AddCmdDrawText_t)(const char *text, int maxChars, void *font, float x, float y, float xScale, float yScale, float rotation, const float *color, int style);
R_AddCmdDrawText_t R_AddCmdDrawText = (R_AddCmdDrawText_t)0x823501E8;

typedef bool (__cdecl * Dvar_GetBool_t)(const char * dvarName);
Dvar_GetBool_t Dvar_GetBool = (Dvar_GetBool_t)0x8229EEE0;

void AddCmdDrawText(char* Text, int Unknown1, void* Font, float X, float Y, float Unknown2, float Unknown3, float Unknown4, const float *Color, int Unknown5)
{
    void* font = R_RegisterFont("fonts/smalldevFont", 1);
    float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
    R_AddCmdDrawText("undefined", 0x7FFFFFFF, font, 100, 400, 1.0f, 1.0f, 0.0f,   color, 0);
}

typedef void ( _cdecl* tRenderStuff )(); 

tRenderStuff oRenderStuff=0; 

void hRenderStuff() 
{ 
    void* font = R_RegisterFont("fonts/smalldevFont", 1);
    float colorWhite[4] = {1.0f, 1.0f, 1.0f, 1.0f};
    R_AddCmdDrawText("undefined", 0x7FFFFFFF, font, 100, 400, 1.0f, 1.0f, 0.0f, colorWhite, 0);

oRenderStuff(); 
} 

DWORD WINAPI commands(LPVOID)
{
        for(;;)
        {
            if (Dvar_GetBool("cl_ingame"))
            {
                oRenderStuff = (tRenderStuff)DetourFunction( ( PBYTE )0x585830, ( PBYTE )&hRenderStuff );     //hook endframe
            return 0;
        }
        Sleep(45);
    }
    Sleep(45);
}




BOOL WINAPI DllMain(HANDLE hInstDLL, DWORD reason, LPVOID lpReserved)
{
    if(reason==DLL_PROCESS_ATTACH)
    {
      CreateThread(0,0,commands,0,0,0);
    }
  return TRUE;
}
share|improve this question
1  
Please modify your source to not include obscenities. –  Byte56 Aug 9 '12 at 22:47
    
what do you mean –  DARK3ZOOZ Aug 9 '12 at 22:49
    
sorry im fairly new to c++ and the terms –  DARK3ZOOZ Aug 9 '12 at 22:49
1  
Obscenities is not a programming term. I've made the changes for you. Further, you are attempting to call DetourFunction but you never define what DetourFunction does. Hence the error. Why are you calling it? –  Byte56 Aug 9 '12 at 22:56
    
im calling it to change the api, I think thats what im going about. –  DARK3ZOOZ Aug 9 '12 at 22:58
show 4 more comments

1 Answer

Your code is missing this include:

#include <detours.h>

Which is likely the header file that has the definition for DetourFunction. Try to just compile the exact code in the tutorial first, then make your changes from there. Recompile/test after each change you make, then you'll know which change broke the code and you won't have to backtrack so much.

share|improve this answer
    
ok ive done some changes, still no success. do you think you could possibly teamviewer –  DARK3ZOOZ Aug 9 '12 at 23:36
1  
I can teamviewer if you can paypal ;) I charge $156 an hour for coding related tech support. I suggest starting from a known good example. Use the tutorial and try building that. If that's not working, update your question to include exact error messages. –  Byte56 Aug 9 '12 at 23:50
    
I understand -_- I have literally been trying everything, so im just going to follow your instructions and then update later. –  DARK3ZOOZ Aug 10 '12 at 0:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.