Skip to content

Commit

Permalink
NEVERHOOD: Add Hall of Records tables
Browse files Browse the repository at this point in the history
- Add tables for Scene2201
  • Loading branch information
johndoe123 authored and wjp committed May 8, 2013
1 parent eb8c44b commit 2817736
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 13 deletions.
99 changes: 86 additions & 13 deletions devtools/create_neverhood/create_neverhood.cpp
Expand Up @@ -60,6 +60,28 @@ byte *getData(uint32 offset) {
return data + offset - dataStart + fileStart;
}

const char *getStringP(uint32 offset) {
return offset != 0 ? (const char*)getData(offset) : NULL;
}

uint32 calcHash(const char *value) {
if (!value)
return 0;
uint32 hash = 0, shiftValue = 0;
while (*value != 0) {
char ch = *value++;
if (ch >= 'a' && ch <= 'z')
ch -= 32;
else if (ch >= '0' && ch <= '9')
ch += 22;
shiftValue += ch - 64;
if (shiftValue >= 32)
shiftValue -= 32;
hash ^= 1 << shiftValue;
}
return hash;
}

struct HitRect {
int16 x1, y1, x2, y2;
uint16 messageNum;
Expand Down Expand Up @@ -217,6 +239,36 @@ struct NavigationItem {

};

struct SceneInfo140Item {
uint32 bgFilename1;
uint32 bgFilename2;
uint32 txFilename;
uint32 bgFilename3;
byte xPosIndex;
byte count;

void load(uint32 offset) {
byte *item = getData(offset);
// Only save the hashes instead of the full names
bgFilename1 = calcHash(getStringP(READ_LE_UINT32(item + 0)));
bgFilename2 = calcHash(getStringP(READ_LE_UINT32(item + 4)));
txFilename = calcHash(getStringP(READ_LE_UINT32(item + 8)));
bgFilename3 = calcHash(getStringP(READ_LE_UINT32(item + 12)));
xPosIndex = item[16];
count = item[17];
}

void save(FILE *fd) {
writeUint32LE(fd, bgFilename1);
writeUint32LE(fd, bgFilename2);
writeUint32LE(fd, txFilename);
writeUint32LE(fd, bgFilename3);
writeByte(fd, xPosIndex);
writeByte(fd, count);
}

};

template<class ITEMCLASS>
class StaticDataList {
public:
Expand Down Expand Up @@ -346,10 +398,33 @@ class StaticDataListVector {

};

template<class ITEMCLASS>
class StaticDataVector {
public:
std::vector<ITEMCLASS> items;

void loadVector(const uint32 *offsets) {
for (int i = 0; offsets[i] != 0; i++) {
ITEMCLASS item;
item.load(offsets[i]);
items.push_back(item);
}
}

void saveVector(FILE *fd) {
writeUint32LE(fd, items.size());
for (typename std::vector<ITEMCLASS>::iterator it = items.begin(); it != items.end(); it++) {
(*it).save(fd);
}
}

};

StaticDataListVector<HitRectList> hitRectLists;
StaticDataListVector<RectList> rectLists;
StaticDataListVector<MessageList> messageLists;
StaticDataListVector<NavigationList> navigationLists;
StaticDataVector<SceneInfo140Item> sceneInfo140Items;

void addMessageList(uint32 messageListCount, uint32 messageListOffset) {
MessageList *messageList = new MessageList();
Expand All @@ -363,24 +438,22 @@ int main(int argc, char *argv[]) {

loadExe("nhc.exe");

hitRectLists.loadListVector(hitRectListOffsets);
rectLists.loadListVector(rectListOffsets);
messageLists.loadListVector(messageListOffsets);
navigationLists.loadListVector(navigationListOffsets);

hitRectLists.loadListVector(hitRectListOffsets);
rectLists.loadListVector(rectListOffsets);
messageLists.loadListVector(messageListOffsets);
navigationLists.loadListVector(navigationListOffsets);
sceneInfo140Items.loadVector(sceneInfo140Offsets);

datFile = fopen("neverhood.dat", "wb");

writeUint32LE(datFile, 0x11223344); // Some magic
writeUint32LE(datFile, DAT_VERSION);

// Write all message lists
messageLists.saveListVector(datFile);
// Write all rect lists
rectLists.saveListVector(datFile);
// Write all hit rect lists
hitRectLists.saveListVector(datFile);
// Write all navigation lists
navigationLists.saveListVector(datFile);
messageLists.saveListVector(datFile);
rectLists.saveListVector(datFile);
hitRectLists.saveListVector(datFile);
navigationLists.saveListVector(datFile);
sceneInfo140Items.saveVector(datFile);

fclose(datFile);

Expand Down
56 changes: 56 additions & 0 deletions devtools/create_neverhood/tables.h
Expand Up @@ -159,6 +159,19 @@ static const uint32 messageListOffsets[] = {
4, 0x004B35F0,
2, 0x004B3550,
1, 0x004B3530,
// Scene2201
1, 0x004B8118,
1, 0x004B8130,
1, 0x004B8178,
2, 0x004B8120,
3, 0x004B81A0,
1, 0x004B81B8,
2, 0x004B8108,
5, 0x004B8150,
4, 0x004B8180,
3, 0x004B8138,
2, 0x004B8108,
2, 0x004B81C8,
0, 0
};

Expand Down Expand Up @@ -196,3 +209,46 @@ static const uint32 navigationListOffsets[] = {
1, 0x004B7FB0,
0, 0
};

// Hall of Records scene definitions

static const uint32 sceneInfo140Offsets[] = {
0x004B7180,
0x004B7198,
0x004B71B0,
0x004B71C8,
0x004B71E0,
0x004B71F8,
0x004B7210,
0x004B7228,
0x004B7240,
0x004B7258,
0x004B7270,
0x004B7288,
0x004B72A0,
0x004B72B8,
0x004B72D0,
0x004B72E8,
0x004B7300,
0x004B7318,
0x004B7330,
0x004B7348,
0x004B7360,
0x004B7378,
0x004B7390,
0x004B73A8,
0x004B73C0,
0x004B73D8,
0x004B73F0,
0x004B7408,
0x004B7420,
0x004B7438,
0x004B7450,
0x004B7468,
0x004B7480,
0x004B7498,
0x004B74B0,
0x004B74C8,
0
};

Binary file modified dists/engine-data/neverhood.dat
Binary file not shown.

0 comments on commit 2817736

Please sign in to comment.