All pastes #611521 Raw Edit

Someone

public text v1 · immutable
·published 2007-07-09 23:33 UTC
rendered paste body
#include <windows.h>
#include "D2Helpers.h"

void ReadCurrentLevel(HANDLE d2Hnd)
{
	DWORD read;
	DWORD addr;
	DWORD addr2;
	DWORD addr3;
	DWORD addr4;
	DWORD addr5;
	BYTE LevelArray[532];
	ROOMTILE roomTile;

	ReadProcessMemory(d2Hnd, (LPCVOID) (DLLBASE_D2CLIENT + 0x11c1e0), &addr, sizeof(addr), NULL);
	printf("Pointer to Level struct is: %X.\n", addr);
	ReadProcessMemory(d2Hnd, (LPCVOID) (addr + 0x2c), &addr2, 4, &read);
	printf("Read %i bytes.\n", read);
	ReadProcessMemory(d2Hnd, (LPCVOID)(addr2 + 0x1c), &addr3, 4, &read);
	printf("Read %i bytes.\n", read);
	ReadProcessMemory(d2Hnd, (LPCVOID)(addr3 + 0x38), &addr4, 4, &read);
	printf("Read %i bytes.\n", read);
	ReadProcessMemory(d2Hnd, (LPCVOID)(addr4 + 0x1c), &addr5, 4, &read);
	printf("Read %i bytes : %X\n", read, addr5);
	ReadProcessMemory(d2Hnd, (LPCVOID)addr5, LevelArray, sizeof(LevelArray), &read);
	printf("Read %i bytes.\n", read);

	LEVEL* currentLevel = (LEVEL*)LevelArray;

	printf("Level Structure:\n _1: %u\n xPos: %u\nyPos: %u\nSizeX: %u\nSizeY: %u\nLevelNo: %u\n",
		currentLevel->_1, currentLevel->dwPosX, currentLevel->dwPosY, currentLevel->dwSizeX, currentLevel->dwSizeY, currentLevel->dwLevelNo);


	BYTE Room2Array[239];

	ReadProcessMemory(d2Hnd, (LPCVOID)currentLevel->pRoom2First, Room2Array, sizeof(Room2Array), &read);
	printf("Read %i bytes.\n", read);

	ROOM2* room2 = (ROOM2*)Room2Array;

	printf("xPos: %u, yPos: %u\n", room2->dwPosX, room2->dwPosY);
	printf("PreSetType: %u\n", room2->dwPresetType);

	BYTE RoomTile[16];
	ReadProcessMemory(d2Hnd, (LPCVOID)room2->pRoomTiles, RoomTile, sizeof(RoomTile), &read);
	printf("Read %i bytes.\n", read);


	ROOMTILE* roomtile = (ROOMTILE*)RoomTile;

	printf("RoomTile structure:\n_1 = %u\npRoom2 = %u\npNext = %u\nnNum = %u\n", roomtile->_1, roomtile->pRoom2, roomtile->pNext, roomtile->nNum);

	



	//Room1 Info isn't all that useful most of the time.
	/*
	BYTE Room1Array[128];

	ReadProcessMemory(d2Hnd, (LPCVOID)room2->pRoom1, Room1Array, sizeof(Room1Array), &read);
	printf("Read %i bytes.\n", read);

	ROOM1* room1 = (ROOM1*)Room1Array;

	printf("XStart: %u, YStart: %u\nXSize: %u, YSize: %u\n", room1->dwXStart, room1->dwYStart, room1->dwXSize, room1->dwYSize);
	*/


}

void ReadControls(HANDLE d2Hnd)
{
	DWORD read;
	DWORD* addr;
	BYTE ControlArray[0x264];

	ReadProcessMemory(d2Hnd, (LPCVOID)(DLLBASE_D2WIN + 0x20488), &addr, sizeof(addr), &read);
	printf("Read %i bytes.\n", read);
	
	CONTROL* control =  ReadControl(d2Hnd, addr);
	printf("Control Info:\nType: %u\nxPos: %u\n yPos: %u\nControl Text: %s\n", control->dwType, control->dwPosX, control->dwPosY, control->wText);

	for (int i = 0; control->pNext != 0; i++)
	{
		 control = ReadControl(d2Hnd, control->pNext);
		 printf("Control Info:\nType: %u\nxPos: %u\n yPos: %u\n", control->dwType, control->dwPosX, control->dwPosY);
		 for (int i = 0; control->wText[i] != 0; i++)
		 {
			 printf("%c", control->wText[i]);
		 }
		 printf("\n");
		 
	}
}

CONTROL* ReadControl(HANDLE d2Hnd, DWORD* pControl)
{
	DWORD read;
	BYTE ControlArray[0x264];

	ReadProcessMemory(d2Hnd, (LPCVOID)(pControl), ControlArray, sizeof(ControlArray), &read);
	printf("Read %i bytes.\n", read);

	return (CONTROL*)ControlArray;
}