Po0ka

Member
I have some trouble generating the corresponding image to the BMP format.
The image is displayable but highly distorted for an unknown reason.
Here is a rescaled example:
https://dl.dropboxusercontent.com/s/m8t3s2i2o8lug5l/distorted.bmp?dl=0
So anyone that masters C++ and has already worked with BMP generation would be great.
I've tried alot of things and commented the most promising ones, but yet i always get such image.
I heard about the padding issues for the BMP file, but 6114 and 4096 are both divisible by 4, so i guess that's not the problem.

Well, PM me or post here if you are willing to help.
Thanks.

(Code sent by PM)
 
Not having done much C++ lately, and not having to look anything up, Here is what I gathered from about 2 mins of looking at this code and your picture. Seems like the offset you are jumping or writing per pixel is wrong (hence the diagnol looking striations in the image).

sizeof(Color) * 8

I would assume this would just be sizeof(Color) or 24. Color is 3 char's = 24 bits, 8 bytes per char.

Try that, see what happens, if it needs more work lemme know and Ill look at the code more intently at home.
 
I tested out with the basic sizeof(Color), and with 24, but i could not have any working result with any of the three test loops i had.
 
I tested out with the basic sizeof(Color), and with 24, but i could not have any working result with any of the three test loops i had.
Does the result look different though? If so, post it. The image really helps me figure these things out, there are patterns to look for (I do a lot of image manipulation with pointers at work, so I see common things in the images, that help me understand what the problem is)
 
Could this have to do with padding?
As 6144 and 4096 are divisible by 4 i think i don't need that.
 
Hi Po0ka!

It has been a long time since I programmed in C++ but maybe i can give you a little help.

The first thing that seems to be wrong is the MapXBlock definition: what is the "bool bDif" variable?
If I remember well, this variable doesn't exist in the map block and it causes a wrong block size calculation (blocks are 196 bytes = 64 x 3 + 4)

The weird thing is that the function "fread" should give you an error if it can't read at least the element's count passed in input (and this should happened if the file has the preML size), so maybe your map file isn't the old format (768x512) but the postML format (896x512).

The last problem is related to the order of read:
  • Blocks are read top-bottom then left-right
  • Cells inside a block are read left-right then top-bottom

Try to check these observations, maybe they were helpful.
 
I was using pre-ML format, when i switched to larger scales the map seemed more complete at compiling from a bmp, so i'll see what decompiling to bmp does with that.

EDIT: blocks are read from top to bottom, but the problem is the BMP file writes left-right but from the bottom left of the picture.
 
Last edited:
I scrapped my function and tried another approach.
So far i must say it is my reader that fails hard, MapXBlock should be 196 bytes indeed, but "sizeof( MapXBlock )" seems to give me 260...

Code:
struct MapXCell
{
	unsigned short TileID;		//65536
	char Z;						//255
};
struct MapXBlock	//sizeof(BYTE)*196 -- block size is 196 bytes
{
	int header;	//gives out 256 without the header, but i guess this is needed too.
	MapXCell cells[64];
	//bool bDif;	//removed.
};

So basically my mistake is in the read method, but i don't know what might be wrong.
EDIT: here is the file i now use:
https://www.dropbox.com/s/994gtd576ne5inh/Decompiler_attempt2.cpp?dl=0
 
Last edited:
The problem with your struct is related to c++ standards (or missing of them :p ).
When you compile a struct, its size is calculated based on the target architecture, an often is not the sum of its member's size (in your case the "char" variable will be padded to 2 byte for better memory organization).
This is called "Struct Padding": here you can find two example of the "problem":

http://stackoverflow.com/questions/5397447/struct-padding-in-c
http://www.cplusplus.com/forum/beginner/47771/

I suggest you to handle the stream at lower level and populate yourself your structs/objects.
 
Thanks man!!!! :D

Code:
#pragmapack(push, 1)
and
Code:
#pragmapack(pop)

Fixed all the trouble xD
I now have a valid decompiled image of a .mul file :D
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back