Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- #include <tchar.h>
- #define patch(a, v, s) _patch((void*)(a), (void*)(v), (s))
- #define insertCallWithJump(a, f) _insertCallWithJump((void *)(a), (void *)(f))
- #define redirectCall(a, f) _redirectCall((void *)(a), (void *)(f))
- void _patch (void*, void*, int);
- void _insertCallWithJump(void*, void*);
- void _redirectCall (void*, void*);
- void Debug (const char *, ...);
- void ProcessDebug (int);
- #define GAME_TIME *g_TimeMs
- #define SCREEN_WIDTH *g_ScreenWidth
- #define SCREEN_HEIGHT *g_ScreenHeight
- #define VERSION *g_VersionIdentifier
- #define GTA_3_1_0 0x6B636F52
- #define GTA_3_1_1 0x49535049
- int * g_TimeMs;
- int * g_ScreenWidth;
- int * g_ScreenHeight;
- DWORD *g_VersionIdentifier = (DWORD *) 0x60F428;
- FILE *g_DebugFile;
- struct RwRGBA { unsigned char r, g, b, a; };
- struct ScrollText { int index; char text[256]; int timeStart; };
- void (__cdecl *AsciiToUnicode) (const char *ascii, short *pUni);
- void (__cdecl *PrintString) (float x, float y, short *text);
- void (__cdecl *SetFontStyle) (int style);
- void (__cdecl *SetScale) (float w, float h);
- void (__cdecl *SetColor) (RwRGBA *color);
- void (__cdecl *SetJustifyOn) ();
- void (__cdecl *SetDropShadowPosition)(int position);
- void (__cdecl *SetPropOn) ();
- void (__cdecl *DrawBank) (int num);
- struct ScrollText g_aScrolls[20];
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID lpReserved)
- {
- int i;
- if(reason==DLL_PROCESS_ATTACH)
- {
- switch(VERSION)
- {
- case GTA_3_1_0:
- redirectCall(0x501B56, ProcessDebug);
- g_TimeMs = (int *) 0x885B48;
- g_ScreenWidth = (int *) 0x8F436C;
- g_ScreenHeight = (int *) 0x8F4370;
- AsciiToUnicode = (void (__cdecl *)(const char *, short *)) 0x5009C0;
- PrintString = (void (__cdecl *)(float, float, short *)) 0x500F50;
- SetFontStyle = (void (__cdecl *)(int) ) 0x501DB0;
- SetScale = (void (__cdecl *)(float, float) ) 0x501B80;
- SetColor = (void (__cdecl *)(RwRGBA *) ) 0x501BD0;
- SetJustifyOn = (void (__cdecl *)() ) 0x501C60;
- SetDropShadowPosition = (void (__cdecl *)(int) ) 0x501E70;
- SetPropOn = (void (__cdecl *)() ) 0x501DA0;
- DrawBank = (void (__cdecl *)(int) ) 0x51EC50;
- break;
- case GTA_3_1_1:
- redirectCall(0x501C36, ProcessDebug);
- g_TimeMs = (int *) 0x885AF8;
- g_ScreenWidth = (int *) 0x8F4420;
- g_ScreenHeight = (int *) 0x8F4424;
- AsciiToUnicode = (void (__cdecl *)(const char *, short *)) 0x500AA0;
- PrintString = (void (__cdecl *)(float, float, short *)) 0x501030;
- SetFontStyle = (void (__cdecl *)(int) ) 0x501E90;
- SetScale = (void (__cdecl *)(float, float) ) 0x501C60;
- SetColor = (void (__cdecl *)(RwRGBA *) ) 0x501CB0;
- SetJustifyOn = (void (__cdecl *)() ) 0x501D40;
- SetDropShadowPosition = (void (__cdecl *)(int) ) 0x501F50;
- SetPropOn = (void (__cdecl *)() ) 0x501E80;
- DrawBank = (void (__cdecl *)(int) ) 0x51EE80;
- break;
- default:
- MessageBox(0, "Unknown GTA 3 version", "gta3debug.asi", MB_OK);
- return FALSE;
- }
- insertCallWithJump(0x405DB0, Debug);
- g_DebugFile = fopen("debug_log.txt", "w");
- }
- return TRUE;
- }
- void ProcessDebug(int num)
- {
- short buf[128];
- RwRGBA color;
- unsigned int i, j, time;
- float y, r, b, a, w, h;
- for(i = 0; i < 20; i++)
- {
- if(g_aScrolls[i].index && GAME_TIME > g_aScrolls[i].timeStart + 5000)
- g_aScrolls[i].index = 0;
- }
- for(i = 0; i < 20; i++)
- {
- time = GAME_TIME - g_aScrolls[i].timeStart;
- if(g_aScrolls[i].index)
- {
- if(time < 2000)
- {
- if(time < 1000)
- r = b = 0.0;
- else
- r = b = time * 0.255 + 255.0;
- a = 255.0;
- }
- else if(time > 4000)
- {
- r = b = 255.0;
- a = (time - 4000) * -0.255 + 255.0;
- }
- else r = b = a = 255.0;
- SetFontStyle(0);
- SetPropOn();
- SetJustifyOn();
- SetScale(0.45, 1.0);
- SetDropShadowPosition(0);
- color.r = r; color.g = 255; color.b = b; color.a = a;
- SetColor(&color);
- AsciiToUnicode(g_aScrolls[i].text, buf);
- PrintString(SCREEN_WIDTH / 640 * 10, SCREEN_HEIGHT / 448 + 10 + (g_aScrolls[i].index - 1) * 20, buf);
- }
- }
- }
- void Debug(const char *format, ...)
- {
- char final[256];
- char debug[272];
- char temp[16];
- int i;
- SYSTEMTIME time;
- // update indices
- for(i = 0; i < 20; i++)
- {
- if(g_aScrolls[i].index)
- g_aScrolls[i].index += 1;
- if(g_aScrolls[i].index > 20)
- g_aScrolls[i].index = 0;
- }
- // place new text
- for(i = 0; i < 20; i++)
- {
- if(!g_aScrolls[i].index)
- {
- g_aScrolls[i].index = 1;
- g_aScrolls[i].timeStart = GAME_TIME;
- break;
- }
- }
- va_list ap;
- va_start(ap, format);
- vsnprintf(final, INT_MAX, format, ap);
- va_end(ap);
- strcpy_s(g_aScrolls[i].text, final);
- GetLocalTime(&time);
- sprintf_s(temp, "%02d:%02d:%02d::%03d: ", time.wHour, time.wMinute, time.wSecond, time.wMilliseconds);
- strcpy_s(debug, temp);
- strcat_s(debug, final);
- fputs(debug, g_DebugFile); fputs("\n", g_DebugFile);
- }
- void _patch(void* pAddress, void* pData, int iSize)
- {
- unsigned long dwProtect[2];
- VirtualProtect(pAddress, iSize, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
- memcpy(pAddress, pData, iSize);
- VirtualProtect(pAddress, iSize, dwProtect[0], &dwProtect[1]);
- }
- void _insertCallWithJump(void * pAddress, void * newFunc)
- {
- DWORD pFunc = 0xE9;
- patch((int)pAddress, &pFunc, 1);
- pFunc = (int)newFunc - ((int)pAddress + 5);
- patch((int)pAddress + 1, &pFunc, 4);
- pFunc = 0xC3;
- patch((int)pAddress + 5, &pFunc, 1);
- };
- void _redirectCall(void * pAddress, void * newFunc)
- {
- DWORD pFunc = (int)newFunc - ((int)pAddress + 5);
- patch((int)pAddress + 1, &pFunc, 4);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement