[SAMP 0.3.7] Handy function for debugging...

T3KTONIT

Well-known member
Joined
Sep 2, 2013
Messages
308
Reaction score
5
hello, just found this function and its really helpful. i named it "DebugLog", anyways, its the internal debug/warning/error logger function that samp uses.

and it's the function responsible for printing the startup messages, the warnings(Warning: couldn't create vehicle type: %u), etc...

i figured i could share it with y'all so dat u can use it for debugging and stuff...
Code:
#define SAMP_CHAT_INFO_OFFSET     0x21A0E4
#define SAMP_FUNC_DEBUGLOG        0x64520


typedef int  (__cdecl    *__DebugLog)(void *g_Chat, char *log, ...);
__DebugLog DebugLog = (__DebugLog)(SAMP + SAMP_FUNC_DEBUGLOG);

//example usage :
void* g_Chat = (void*)*(DWORD*)(SAMP + SAMP_CHAT_INFO_OFFSET);
DebugLog(g_Chat, "This is a test %d %d %d  Hello ugbase!", 1, 2, 3);

5oN0737.png
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
Nice, here's the one for info messages, green text.
#define FUNC_INFOMSG 0x644A0
 
S

Suppraza

Guest
Sorry for writing here, but how get the pointer of chat message ?
(Like: "SAMP_INFO_OFFSET", "SAMP_CHAT_INFO_OFFSET")
 

T3KTONIT

Well-known member
Joined
Sep 2, 2013
Messages
308
Reaction score
5
Suppraza link said:
Sorry for writing here, but how get the pointer of chat message ?
(Like: "SAMP_INFO_OFFSET", "SAMP_CHAT_INFO_OFFSET")
i already defined SAMP_INFO_OFFSET...

you can find the offsets by disassembling samp.dll.
 
S

Suppraza

Guest
Oh Ok, Thanks, but i have problem with code (sorry if I'm bumbing like an idio..):

[glow=blue,1,600]main.h[/glow]
Code:
/*
	by: Suppraza
	SUPER THANKS TO: T3KTONIT
	Forum: http://ugbase.eu/
*/

#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>
#include <stdio.h>

#pragma message ("# # # # # # # # # # #")
#pragma message ("# http://ugbase.eu/ #")
#pragma message ("# # # # # # # # # # #")

//using namespace std;

void addToChatWindow(char *text, DWORD textColor);
void addMessageToChatWindow(DWORD Color, const char *text, ...);
void AddClientMessage(const char *text, ...);

void WriteMemory(DWORD *Address, DWORD Value);
void WriteMemoryEx(DWORD *Address, DWORD *Value, int Bytes);

extern DWORD g_dwSAMP_Addr;

#define SAMP_CHAT_INFO_OFFSET      0x21A0E4
#define SAMP_CHAT_INPUT_INFO_OFFSET     0x21A0E8
#define SAMP_KILL_INFO_OFFSET      0x21A0EC
#define SAMP_INFO_OFFSET       0x21A0F8
#define SAMP_MISC_INFO        0x21A10C
#define SAMP_SCOREBOARD_INFO      0x21A0B4
#define SAMP_COLOR_OFFSET       0x216378
#define SAMP_DRAWING_DISTANCE      0xD3DCC
#define SAMP_FUNC_ADDTOCHATWND      0x64010

[glow=blue,1,600]main.cpp[/glow]
Code:
/*
	by: Suppraza
	SUPER THANKS TO: T3KTONIT
	Forum: http://ugbase.eu/
*/

#include "main.h"
DWORD g_dwSAMP_Addr = NULL;

void addToChatWindow(char *text, DWORD textColor)
{
	if (!g_dwSAMP_Addr)
		return;
	if (!text)
		return;

	DWORD	chatinfo = g_dwSAMP_Addr + SAMP_CHAT_INFO_OFFSET;
	DWORD	func = g_dwSAMP_Addr + SAMP_FUNC_ADDTOCHATWND;

	__asm mov eax, dword ptr[chatinfo]
		__asm mov ecx, dword ptr[eax]
		__asm push 0
	__asm push textColor
	__asm push 0
	__asm push text
	__asm push 8
	__asm call func
}
void addMessageToChatWindow(DWORD Color, const char *text, ...)
{
	if (g_dwSAMP_Addr != NULL)
	{
		va_list ap;
		if (text == NULL)
			return;

		char	tmp[512];
		memset(tmp, 0, 512);

		va_start(ap, text);
//		vsnprintf(tmp, sizeof(tmp) - 1, text, ap);
		_vsnprintf_s(tmp, sizeof(tmp) - 1, text, ap);
		va_end(ap);

		addToChatWindow(tmp, Color);
	}
}
void AddClientMessage(const char *text, ...)
{
	if (g_dwSAMP_Addr != NULL)
	{
		va_list ap;
		if (text == NULL)
			return;

		char	tmp[256];
		char	buf[512];
		memset(tmp, 0, 256);

		va_start(ap, text);
//		vsnprintf(tmp, sizeof(tmp) - 1, text, ap);
		vsnprintf_s(tmp, sizeof(tmp) - 1, text, ap);
		va_end(ap);
//		sprintf(buf, "{0096FF}[HAX.ASI] » {FFFFFF}%s", tmp);
		sprintf_s(buf, sizeof(buf), "{0096FF}[WUT.ASI] » {FFFFFF}%s", tmp);
		addToChatWindow(buf, 0xFA9A);
	}
}

void WriteMemory(DWORD *Address, DWORD Value)
{
	*(int*)Address = Value;
}
void WriteMemoryEx(DWORD *Address, DWORD *Value, int Bytes)
{
	DWORD OldProtect;
	VirtualProtect(Address, Bytes, PAGE_EXECUTE_READWRITE, &OldProtect);
	memcpy(Address, Value, Bytes);
	VirtualProtect(Address, Bytes, OldProtect, &OldProtect);
}
void LoadSAMP()
{
	while (g_dwSAMP_Addr == NULL)
	{
		g_dwSAMP_Addr = (DWORD)GetModuleHandle("samp.dll");
		Sleep(500);
	}
}

typedef int(__cdecl    *__DebugLog)(void *g_Chat, char *log, ...);
__DebugLog DebugLog = (__DebugLog)(g_dwSAMP_Addr + 0x64520);
void* g_Chat = (void*)*(DWORD*)(g_dwSAMP_Addr + SAMP_CHAT_INFO_OFFSET);

void Main(void)
{
	LoadSAMP();
	while (true)
	{
		//AddClientMessage("WORKS?"); // NOT WORKS
		DebugLog(g_Chat, "WORKS?");
		Sleep(100);
	}
}

BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, LPVOID lpReserved)
{
	DisableThreadLibraryCalls(hDll);
	if (dwReason == DLL_PROCESS_ATTACH)
		CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)Main, NULL, NULL, NULL);

	return TRUE;
}
 

T3KTONIT

Well-known member
Joined
Sep 2, 2013
Messages
308
Reaction score
5
Don't define g_Chat as a global variable like that ...

do this :

Code:
void * g_Chat = NULL;
void Main(void)
{
 LoadSAMP();
 while (true)
 {
 if(!g_Chat)
 g_Chat = (void*)*(DWORD*)(g_dwSAMP_Addr + SAMP_CHAT_INFO_OFFSET);

  //AddClientMessage("WORKS?"); // NOT WORKS
  if(g_Chat)
  DebugLog(g_Chat, "WORKS?");
  Sleep(100);
 }
}

or better : (not tested)

Code:
#define g_Chat (void*)*(DWORD*)(SAMP + SAMP_CHAT_INFO_OFFSET);

main()
.
.
.
.
.
etc


EDIT: make a dll project ofcourse...
Code:
BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, LPVOID lpReserved)
{

	DisableThreadLibraryCalls(hDll);

	if (dwReason == DLL_PROCESS_ATTACH)
	{
		CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)Main, NULL, NULL, NULL);
	}
	return TRUE;
}
 

BBB

Active member
Joined
Apr 5, 2013
Messages
62
Reaction score
1
nice try reviving code section, but now you get zombie  :eek:mg_run:
 
S

Suppraza

Guest
T3K link said:
Don't define g_Chat as a global variable like that ...

do this :

Code:
void * g_Chat = NULL;
void Main(void)
{
 LoadSAMP();
 while (true)
 {
 if(!g_Chat)
 g_Chat = (void*)*(DWORD*)(g_dwSAMP_Addr + SAMP_CHAT_INFO_OFFSET);

  //AddClientMessage("WORKS?"); // NOT WORKS
  if(g_Chat)
  DebugLog(g_Chat, "WORKS?");
  Sleep(100);
 }
}

or better : (not tested)

Code:
#define g_Chat (void*)*(DWORD*)(SAMP + SAMP_CHAT_INFO_OFFSET);

main()
.
.
.
.
.
etc

Doesn't Work
 

whoonga

Active member
Joined
Nov 6, 2014
Messages
52
Reaction score
0
i would like to have that AddChatMessage "Trainer" too.
But mine is also not working..
 
Top