The file DefaultCHK.h has invalid characters. You shouldn't have non-printable characters in source code.
Look at Buffer.h. You have a "char title[3];", but a loop that iterates through 4 characters in your extract method. Now by pure coincidence there is an alignment directive which gives you an extra byte, but otherwise it would overwrite your "char* data" member. You should instead make it "char title[5]" and make sure the last character is a null terminator.
You should also get into the habit of distinguishing NULL, 0, '\0', nullptr and when to use them.
NULL - In C++11 is being replaced by the type-safe nullptr. You would only use NULL or nullptr with pointers (a HANDLE and such types in the win32 api are also treated as pointers).
'\0' - Always use this when assigning or comparing to a character. It can help distinguish what is happening more quickly.
0 - Only use this when the synonyms above don't apply.
There's a whole bunch of other things as well, but I'm sure you're working on improving your abilities.
On the other hand, a while ago I started a project called Legacy Map Reader which has Starcraft/Beta/Warcraft2 map reading code. The project was incomplete, but feel free to look at the code.
[attach=9072]
This was done in 2011. It is supposed to closely resemble the way Starcraft and Warcraft II actually read map files. I've learned a lot since then though and would have designed it a bit differently with some actual C++. It would have been a better idea to create a base interface class for sections and pull it out of a map, like this:
Section.h
Code
#pragma once
#include <map>
#include <windows.h>
class Section
{
public:
static std::map<DWORD,Section*> sectionMapping;
Section(DWORD dwSectionId);
static bool readSection(SomeBufferClass &buff);
// @TODO writeSection
virtual bool read(DWORD dwSectionId, DWORD dwSectionSize, SomeBufferClass &buff) = 0;
virtual bool write(SomeBufferClass &buff) = 0;
protected:
DWORD id;
};
#include <map>
#include <windows.h>
class Section
{
public:
static std::map<DWORD,Section*> sectionMapping;
Section(DWORD dwSectionId);
static bool readSection(SomeBufferClass &buff);
// @TODO writeSection
virtual bool read(DWORD dwSectionId, DWORD dwSectionSize, SomeBufferClass &buff) = 0;
virtual bool write(SomeBufferClass &buff) = 0;
protected:
DWORD id;
};
Section.cpp
Code
#include "Section.h"
std::map<DWORD,Section*> Section::sectionMapping;
Section::Section(DWORD dwSectionId) : id(dwSectionId)
{
Section::sectionMapping[id] = this;
}
bool Section::readSection(SomeBufferClass &buff)
{
// Read the section header
DWORD dwSectionId, dwSectionSize;
dwSectionId = buff.readDword();
dwSectionSize = buff.readDword();
// Retrieve the section by section ID
auto it = Section::sectionMapping.find(dwSectionId);
if ( it == Section::sectionMapping.end() )
return false;
// Return true if the section was read successfully
return it->second->read(dwSectionId, dwSectionSize, buff);
}
std::map<DWORD,Section*> Section::sectionMapping;
Section::Section(DWORD dwSectionId) : id(dwSectionId)
{
Section::sectionMapping[id] = this;
}
bool Section::readSection(SomeBufferClass &buff)
{
// Read the section header
DWORD dwSectionId, dwSectionSize;
dwSectionId = buff.readDword();
dwSectionSize = buff.readDword();
// Retrieve the section by section ID
auto it = Section::sectionMapping.find(dwSectionId);
if ( it == Section::sectionMapping.end() )
return false;
// Return true if the section was read successfully
return it->second->read(dwSectionId, dwSectionSize, buff);
}
It's just something I came up with now and each section type would extend this base one. I'm actually doing something similar with the AI Script opcodes (here: https://code.google.com/p/bwapi/source/browse/branches/bwapi4/bwapi/BWScriptEmulator/Opcode.h ). Splitting everything up may seem like a lot of work, but the code is much cleaner that way ( https://code.google.com/p/bwapi/source/browse/branches/bwapi4/bwapi/BWScriptEmulator/Build.cpp ).
EDIT: As for drawing tiles, BWAPI has some reverse engineered drawing tile code: https://code.google.com/p/bwapi/source/browse/branches/bwapi4/bwapi/BWAPI/Source/BWDrawing.cpp#127 (includes creep rendering)
Attachments:
Post has been edited 2 time(s), last time on Jan 5 2013, 4:34 am by Heinermann.