All pastes #491940 Raw Edit

Cody Brocious

public c v1 · immutable
·published 2007-05-16 22:49 UTC
rendered paste body
#include <windows.h>#include <stdio.h>unsigned short nWidth = 1280, nHeight = 800;static unsigned int protold;static void *protaddr;#define clientreloc(addr) reloc(client, 0x6FAB0000, (addr))#define d3dreloc(addr) reloc(d3d, 0x6F880000, (addr))#define gfxreloc(addr) reloc(gfx, 0x6FA80000, (addr))#define winreloc(addr) reloc(win, 0x6F8E0000, (addr))#define reloc(module, base, addr) ((void *) ((unsigned int) (addr) + ((signed int) module - base)))#define unprotect(addr) { protaddr = (unsigned int) addr & ~0x0FFF; VirtualProtect(protaddr, 0x1000, PAGE_EXECUTE_READWRITE, &protold); }#define reprotect() VirtualProtect(protaddr, 0x1000, protold, NULL)#define movR32Imm32V(addr, value) \{ \	unsigned int *tempPtr = (unsigned char *) (addr) + 1; \	unprotect(tempPtr); \	*tempPtr = (value); \	reprotect(); \}#define movRM32Imm32V(addr, value) \{ \	unsigned int *tempPtr = (unsigned char *) (addr) + 6; \	unprotect(tempPtr); \	*tempPtr = (value); \	reprotect(); \}#define setMovValue(addr, value) \{ \	unsigned char *tempCharPtr = (unsigned char *) (addr); \	if(*tempCharPtr == 0xC7) \		movRM32Imm32V((addr), (value)) \	else \		movR32Imm32V((addr), (value)) \}#define setValue(addr, value) \{ \	unsigned int *tempPtr = (unsigned int *) (addr); \	unprotect(tempPtr); \	*tempPtr = value; \	reprotect(tempPtr); \}void PatchBinary() {	HMODULE client = LoadLibrary("D2Client.dll");	HMODULE d3d = LoadLibrary("D2Direct3D.dll");	HMODULE gfx = LoadLibrary("D2gfx.dll");	HMODULE win = LoadLibrary("D2Win.dll");	unsigned int *addr;	char temp[256];	unsigned char *ptr;	// Global override in d3d	setValue(d3dreloc(0x6F8B2854), nWidth);	setValue(d3dreloc(0x6F8B2CE4), nHeight);	// Local override in d3d	setMovValue(d3dreloc(0x6F888A53), nWidth);	setMovValue(d3dreloc(0x6F888A5D), nHeight);	// Local override in d3d	setMovValue(d3dreloc(0x6F88951C), nWidth);	setMovValue(d3dreloc(0x6F889526), nHeight);	// Set height and width in client	setMovValue(clientreloc(0x6FAE3A62), nWidth);	setMovValue(clientreloc(0x6FAE6FF9), nWidth);	setMovValue(clientreloc(0x6FAE3A6E), nHeight);	setMovValue(clientreloc(0x6FAE7003), nHeight);	// Patch some shit in win	// setMovValue(winreloc(0x6F8EA917), nWidth);	// setMovValue(winreloc(0x6F8EA91E), nWidth);	setMovValue(gfxreloc(0x6FA8863E), nWidth);	setMovValue(gfxreloc(0x6FA88109), nWidth);	setMovValue(gfxreloc(0x6FA8810F), nHeight);	setMovValue(gfxreloc(0x6FA88685), nWidth);	setMovValue(gfxreloc(0x6FA88690), nHeight);}