From b4cedffe6562aecc3b7afe6c480427e05b8fa277 Mon Sep 17 00:00:00 2001 From: Treeki Date: Mon, 16 Jan 2012 23:35:17 +0100 Subject: mapfile_tool handles the two projects now --- src/levelinfo.cpp | 36 --------------------------------- src/levelinfo.h | 56 --------------------------------------------------- src/levelinfo_old.cpp | 36 +++++++++++++++++++++++++++++++++ src/levelinfo_old.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/mapfile_tool.py | 10 ++++++--- 5 files changed, 99 insertions(+), 95 deletions(-) delete mode 100644 src/levelinfo.cpp delete mode 100644 src/levelinfo.h create mode 100644 src/levelinfo_old.cpp create mode 100644 src/levelinfo_old.h diff --git a/src/levelinfo.cpp b/src/levelinfo.cpp deleted file mode 100644 index ec65350..0000000 --- a/src/levelinfo.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "levelinfo.h" - -void LevelInfo_Prepare(FileHandle *fh) { - void *file = fh->filePtr; - - // decrypt all the level names - for (int sect = 0; sect < LevelInfo_GetSectionCount(file); sect++) { - // parse this section - LevelInfo_Section *thisSect = LevelInfo_GetSection(file, sect); - LevelInfo_Entry *levels = LevelInfo_GetLevels(file, thisSect); - - for (int lev = 0; lev < thisSect->levelCount; lev++) { - LevelInfo_Entry *level = &levels[lev]; - - char *name = LevelInfo_GetName(file, level); - - for (int i = 0; i < level->nameLength+1; i++) { - name[i] -= 0xD0; - } - } - } -} - -LevelInfo_Entry *LevelInfo_Search(void *file, int world, int level) { - for (int i = 0; i < LevelInfo_GetSectionCount(file); i++) { - LevelInfo_Section *sect = LevelInfo_GetSection(file, i); - - for (int j = 0; j < sect->levelCount; j++) { - LevelInfo_Entry *entry = &LevelInfo_GetLevels(file, sect)[j]; - if (entry->world == world && entry->level == level) - return entry; - } - } - - return 0; -} diff --git a/src/levelinfo.h b/src/levelinfo.h deleted file mode 100644 index 8e1e916..0000000 --- a/src/levelinfo.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef __NEWER_LEVELINFO_H -#define __NEWER_LEVELINFO_H - -#include -#include "fileload.h" - -struct LevelInfo_Header { - u32 magic; - u32 sectionCount; -}; - -struct LevelInfo_Section { - u32 levelCount; -}; - -struct LevelInfo_Entry { - u8 world; - u8 level; - u8 reserved1; - u8 reserved2; - u8 nameLength; - u8 reserved3; - u16 flags; - u32 nameOffset; -}; - -inline u32 LevelInfo_GetSectionCount(void *file) { - return ((LevelInfo_Header*)file)->sectionCount; -} - -inline u32 *LevelInfo_GetOffsets(void *file) { - return (u32*)(((LevelInfo_Header*)file)+1); -} - -inline LevelInfo_Section *LevelInfo_GetSection(void *file, int id) { - u32 offs = LevelInfo_GetOffsets(file)[id]; - return (LevelInfo_Section*)(((char*)file)+offs); -}; - -inline LevelInfo_Entry *LevelInfo_GetLevels(void *file, LevelInfo_Section *section) { - return (LevelInfo_Entry*)(section+1); -} - -inline LevelInfo_Entry *LevelInfo_GetLevels(void *file, int sectionID) { - return (LevelInfo_Entry*)(LevelInfo_GetSection(file, sectionID)+1); -} - -inline char *LevelInfo_GetName(void *file, LevelInfo_Entry *entry) { - return ((char*)file)+entry->nameOffset; -} - -void LevelInfo_Prepare(FileHandle *fh); -LevelInfo_Entry *LevelInfo_Search(void *file, int world, int level); - - -#endif diff --git a/src/levelinfo_old.cpp b/src/levelinfo_old.cpp new file mode 100644 index 0000000..ec65350 --- /dev/null +++ b/src/levelinfo_old.cpp @@ -0,0 +1,36 @@ +#include "levelinfo.h" + +void LevelInfo_Prepare(FileHandle *fh) { + void *file = fh->filePtr; + + // decrypt all the level names + for (int sect = 0; sect < LevelInfo_GetSectionCount(file); sect++) { + // parse this section + LevelInfo_Section *thisSect = LevelInfo_GetSection(file, sect); + LevelInfo_Entry *levels = LevelInfo_GetLevels(file, thisSect); + + for (int lev = 0; lev < thisSect->levelCount; lev++) { + LevelInfo_Entry *level = &levels[lev]; + + char *name = LevelInfo_GetName(file, level); + + for (int i = 0; i < level->nameLength+1; i++) { + name[i] -= 0xD0; + } + } + } +} + +LevelInfo_Entry *LevelInfo_Search(void *file, int world, int level) { + for (int i = 0; i < LevelInfo_GetSectionCount(file); i++) { + LevelInfo_Section *sect = LevelInfo_GetSection(file, i); + + for (int j = 0; j < sect->levelCount; j++) { + LevelInfo_Entry *entry = &LevelInfo_GetLevels(file, sect)[j]; + if (entry->world == world && entry->level == level) + return entry; + } + } + + return 0; +} diff --git a/src/levelinfo_old.h b/src/levelinfo_old.h new file mode 100644 index 0000000..8e1e916 --- /dev/null +++ b/src/levelinfo_old.h @@ -0,0 +1,56 @@ +#ifndef __NEWER_LEVELINFO_H +#define __NEWER_LEVELINFO_H + +#include +#include "fileload.h" + +struct LevelInfo_Header { + u32 magic; + u32 sectionCount; +}; + +struct LevelInfo_Section { + u32 levelCount; +}; + +struct LevelInfo_Entry { + u8 world; + u8 level; + u8 reserved1; + u8 reserved2; + u8 nameLength; + u8 reserved3; + u16 flags; + u32 nameOffset; +}; + +inline u32 LevelInfo_GetSectionCount(void *file) { + return ((LevelInfo_Header*)file)->sectionCount; +} + +inline u32 *LevelInfo_GetOffsets(void *file) { + return (u32*)(((LevelInfo_Header*)file)+1); +} + +inline LevelInfo_Section *LevelInfo_GetSection(void *file, int id) { + u32 offs = LevelInfo_GetOffsets(file)[id]; + return (LevelInfo_Section*)(((char*)file)+offs); +}; + +inline LevelInfo_Entry *LevelInfo_GetLevels(void *file, LevelInfo_Section *section) { + return (LevelInfo_Entry*)(section+1); +} + +inline LevelInfo_Entry *LevelInfo_GetLevels(void *file, int sectionID) { + return (LevelInfo_Entry*)(LevelInfo_GetSection(file, sectionID)+1); +} + +inline char *LevelInfo_GetName(void *file, LevelInfo_Entry *entry) { + return ((char*)file)+entry->nameOffset; +} + +void LevelInfo_Prepare(FileHandle *fh); +LevelInfo_Entry *LevelInfo_Search(void *file, int world, int level); + + +#endif diff --git a/tools/mapfile_tool.py b/tools/mapfile_tool.py index 4ebd288..540d3e0 100755 --- a/tools/mapfile_tool.py +++ b/tools/mapfile_tool.py @@ -252,11 +252,13 @@ def do_module(src, dest): open(dest, 'w').write(yaml.dump(m)) -def do_project(f): +def do_project(f, already_done): proj = yaml.safe_load(open(f, 'r').read()) for m in proj['modules']: - do_module(m.replace('processed/', ''), m) + if m not in already_done: + already_done.add(m) + do_module(m.replace('processed/', ''), m) def main(): @@ -264,7 +266,9 @@ def main(): do_mapfile('kamek_pal.x', 'kamek_ntsc.x', fix_offs_ntsc_v1) do_mapfile('kamek_pal.x', 'kamek_ntsc2.x', fix_offs_ntsc_v2) - do_project('NewerProject.yaml') + already_done = set() + do_project('NewerProject.yaml', already_done) + do_project('NewerProjectKP.yaml', already_done) do_module('anotherhax.yaml', 'processed/anotherhax.yaml') -- cgit v1.2.3