1.13c Color extension 8 bite to 24 bite

This forum is for discussions on how to edit what can not be edited through the txt files, needless to say this isn't about battle net hacking.

Moderators: Nefarius, Havvoric

Post Reply
nnsky2011
Posts: 3
Joined: Thu Jan 05, 2017 9:36 am

1.13c Color extension 8 bite to 24 bite

Post by nnsky2011 » Mon Apr 23, 2018 7:26 am

Image
load file

Code: Select all

int loadfileprocaddress = (int)LoadLibrary("D2WIN.DLL") + 0x7c60;
__forceinline char* loadfile(char* filename) {
	_asm mov eax, filename;
	return ((char* (_stdcall*)(DWORD, DWORD))loadfileprocaddress)(0, 0);
};
load bitmap

Code: Select all

char* file = loadfile(filename1);
	if (!file)return;
	if (*(WORD*)file == 0x4d42) {
		BITMAPFILEHEADER* bmpfileheader = (BITMAPFILEHEADER*)file;//文件头  
		BITMAPINFOHEADER* bmpinfoheader = (BITMAPINFOHEADER*)(file + sizeof(BITMAPFILEHEADER));//位图头  
		BITMAPINFO* bmpinfo = (BITMAPINFO*)bmpinfoheader;//位图信息  
		HDC hdc = GetDC(0);
		HBITMAP hbitmap = CreateCompatibleBitmap(hdc, bmpinfo->bmiHeader.biWidth, bmpinfo->bmiHeader.biHeight);
		ReleaseDC(0, hdc);
		hdc = CreateCompatibleDC(0);
		SelectObject(hdc, hbitmap);
		SetDIBits(hdc, hbitmap, 0, bmpinfo->bmiHeader.biHeight, file + bmpfileheader->bfOffBits, bmpinfo, 0);
		DeleteDC(hdc);
		i->x = bmpinfo->bmiHeader.biWidth;
		i->y = bmpinfo->bmiHeader.biHeight;
		i->bits = new int[i->x*i->y];
		GetBitmapBits(hbitmap, i->x*i->y * sizeof(int), i->bits);
		dc6bits->dwTermination = (int)i;
		DeleteObject(hbitmap);
	}
draw bitmap

Code: Select all

int TickCount = GetTickCount() / 40;//25f/s
	for (int i = 0; i < drawersize && drawer[i].type; i++) {
		if (drawer[i].type == 1)//bitmap
			if (drawer[i].h->type == 0) {//Static graph
				for (int x = 0; x < drawer[i].h->x; x++)for (int y = 0; y < drawer[i].h->y; y++)
					if ((x + drawer[i].x) >= 0)if ((y + drawer[i].y) >= 0)if ((x + drawer[i].x) < *wSrc)if ((y + drawer[i].y) < *hSrc)
						if (bits[x + drawer[i].x + (drawer[i].y + y + *hSrc) * *wSrc] == 0xffffff)
							bits[x + drawer[i].x + (drawer[i].y + y) * *wSrc] = drawer[i].h->bits[x + y * drawer[i].h->x];
			}
			else {//Dynamic graph
				int *gifbits = &drawer[i].h->bits[drawer[i].h->x*drawer[i].h->y*(TickCount%drawer[i].h->type)];
				for (int x = 0; x < drawer[i].h->x; x++)for (int y = 0; y < drawer[i].h->y; y++)
					if ((x + drawer[i].x) >= 0)if ((y + drawer[i].y) >= 0)if ((x + drawer[i].x) < *wSrc)if ((y + drawer[i].y) < *hSrc)
						if (bits[x + drawer[i].x + (drawer[i].y + y + *hSrc) * *wSrc] == 0xffffff)
							if (gifbits[x + y * drawer[i].h->x])
								bits[x + drawer[i].x + (drawer[i].y + y) * *wSrc] = gifbits[x + y * drawer[i].h->x];
			}
			if (drawer[i].type == 2)//mask
				for (int x = drawer[i].rect.left; x < drawer[i].rect.right; x++)for (int y = drawer[i].rect.top; y < drawer[i].rect.bottom; y++)
					if (x >= 0)if (y >= 0)if (x < *wSrc)if (y < *hSrc)
						if (bits[x + (y + *hSrc) * *wSrc] == 0xffffff) {
							*(BYTE*)&bits[x + y * *wSrc] = (int)*(BYTE*)&bits[x + y * *wSrc] * (drawer[i].color & 0xff) / 0xff;
							*((BYTE*)&bits[x + y * *wSrc] + 1) = (int)*((BYTE*)&bits[x + y * *wSrc] + 1) * (drawer[i].color >> 8 & 0xff) / 0xff;
							*((BYTE*)&bits[x + y * *wSrc] + 2) = (int)*((BYTE*)&bits[x + y * *wSrc] + 2) * (drawer[i].color >> 16 & 0xff) / 0xff;
						}
	}

User avatar
k0r3l1k
Dark Alliance Beta Test
Angel
Posts: 614
Joined: Sun Sep 09, 2007 3:11 am
Location: Arizona, Prescott
United States of America

Re: 1.13c Color extension 8 bite to 24 bite

Post by k0r3l1k » Mon Apr 23, 2018 7:58 pm

Wow very cool.

Not a bad trick. Great for menu screens, maybe even a few ui elements.
Image

jessedazebra
Posts: 20
Joined: Sun Nov 11, 2012 9:46 am
Russia

Re: 1.13c Color extension 8 bite to 24 bite

Post by jessedazebra » Wed Apr 25, 2018 1:22 pm

What exactly program i need to use to make it work? Is there a chance you have an external dll with this code already used? I don't really have any knowledge in C++ or how to use this code with dlls. The only thing i used was just ollydbg, I used it to do some edits in dlls with help of Whist's code edits, like NOPing and other stuff. I really like to do graphic stuff in Diablo 2, like new skill icons and new interface elements, but this 8-bit color palette corrupts like every color, especially blue and magenta and the final outcome sometimes is really dissapointing.
I couldn't find any tutorial that shows how to use C++ with D2 or maybe I just didn't search very carefully.
Thanks in advance.

Post Reply

Return to “Code Editing”