Skip to content

Instantly share code, notes, and snippets.

@ChadSki
Created May 1, 2014 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChadSki/937f847110fd209b4593 to your computer and use it in GitHub Desktop.
Save ChadSki/937f847110fd209b4593 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#define MEMORY_FIX_OFFSET 0x40440000
// Ensure correct alignment
#pragma pack(push, 1)
// Structure of map header
struct hMapHeader
{
DWORD integrity; // should be 'daeh' if not corrupt
DWORD type; // 7 for halo PC, ce is 0x261
DWORD filesize;
DWORD highSize;
DWORD offset; // offset to data that is read, not sure what this data is yet.
DWORD readSize; // data to read at offset
BYTE unk1[8]; // Unknown atm, seem to be byte fillers
char name[32]; // map name
char version[32];
DWORD mapType; // 0 campaign, 1 multiplayer, 2 data (ui.map)
BYTE unk2[0x798]; // first few bytes have data, rest are 00
DWORD integrity2;
};
// Structure of tag index table
struct hTagTableHeader
{
DWORD next_ptr;
DWORD starting_index; // ??
DWORD unk;
DWORD entityCount;
DWORD unk1;
DWORD readOffset;
BYTE unk2[8];
DWORD readSize;
DWORD unk3;
};
// Structure of the tag header
struct hTag
{
DWORD tagType; // ie weap
DWORD unk[2]; // I don't know
DWORD id; // unique id
char* tagName; // name of tag
LPBYTE metaData; // data for this tag
DWORD unk1[2]; // I don't know
};
#pragma pack(pop)
DWORD endian_swap(unsigned int x)
{
return (x>>24) | ((x<<8) & 0x00FF0000) |((x>>8) & 0x0000FF00) | (x<<24);
}
int main()
{
// Open the mapfile
HANDLE hFile = CreateFileW( TEXT("C:\\bloodgulch.map"), GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("Couldn't open the map file.\n");
system("PAUSE");
return 0;
}
BYTE m_header[2048] = {0};
DWORD dwRead = 0;
if (!ReadFile(hFile, &m_header, sizeof(m_header), &dwRead, NULL))
{
CloseHandle(hFile);
printf("Couldn't read the map header.\n");
system("PAUSE");
return 0;
}
hMapHeader* header = (hMapHeader*)m_header;
// Start reading from offset
SetFilePointer(hFile, header->offset, NULL, FILE_BEGIN);
// Allocate memory for the read
LPBYTE m_tagData = new BYTE[header->readSize];
// Read the data
if (!ReadFile(hFile, m_tagData, header->readSize, &dwRead, NULL))
{
delete[] m_tagData;
CloseHandle(hFile);
printf("Couldn't read the tag data.\n");
system("PAUSE");
return 0;
}
hTagTableHeader* tableHeader = (hTagTableHeader*)m_tagData;
// Iterate through the items
for (size_t x = 0; x < tableHeader->entityCount; x++)
{
hTag* tag = (hTag*)(m_tagData + tableHeader->next_ptr - MEMORY_FIX_OFFSET + (0x20 * x));
// We need to fix these addresses
tag->tagName = (char*)(tag->tagName - MEMORY_FIX_OFFSET + (DWORD)m_tagData);
tag->metaData = (LPBYTE)(tag->metaData - MEMORY_FIX_OFFSET + (DWORD)m_tagData);
// The tag id is in little endian, let's swap around
char disp[5] = {0};
*(DWORD*)disp = endian_swap(tag->tagType);
printf("[%s] %s\n", disp, tag->tagName);
}
delete[] m_tagData;
// Close the file
CloseHandle(hFile);
system("PAUSE");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment