From 41797a0c17035ae38e227c1a6efcdf4d82c9e326 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Fri, 23 Aug 2024 13:29:37 +0100 Subject: [PATCH] Load all chunk types as part of toc entry --- patterns/db_files/CowFile.hexpat | 65 ------------- patterns/db_files/DbFile.pat | 101 +++++++++++++++++++++ patterns/db_files/FileBase.pat | 58 ------------ patterns/db_files/chunks/BRLIST.hexpat | 2 +- patterns/db_files/chunks/OBJ_MAP.hexpat | 2 +- patterns/db_files/chunks/P$_.hexpat | 2 +- patterns/db_files/chunks/ScrModules.hexpat | 2 +- 7 files changed, 105 insertions(+), 127 deletions(-) delete mode 100644 patterns/db_files/CowFile.hexpat create mode 100644 patterns/db_files/DbFile.pat delete mode 100644 patterns/db_files/FileBase.pat diff --git a/patterns/db_files/CowFile.hexpat b/patterns/db_files/CowFile.hexpat deleted file mode 100644 index a851c07..0000000 --- a/patterns/db_files/CowFile.hexpat +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once - -#include -#include - -#include "db_files/FileBase.pat" -#include "db_files/AllChunks.pat" - -FileHeader file_header @ 0x0; -TableOfContents toc @ file_header.toc_offset; - -TOCEntry brlist_toc = get_toc_entry(toc, "BRLIST"); -TOCEntry objmap_toc = get_toc_entry(toc, "OBJ_MAP"); -TOCEntry scrmodules_toc = get_toc_entry(toc, "ScrModules"); - -Chunk ai_room_db @ get_offset(toc, "AI_ROOM_DB"); -Chunk ai_acuity_sets @ get_offset(toc, "AIACS"); -Chunk ai_conversations @ get_offset(toc, "AICONVERSE"); -Chunk ai_creature_sizes @ get_offset(toc, "AICRTSZ"); -Chunk ai_gamesys_path_options @ get_offset(toc, "AIGPTHVAR"); -Chunk ai_hear_stat @ get_offset(toc, "AIHearStat"); -Chunk ai_path_var @ get_offset(toc, "AIPATHVAR"); -Chunk ai_sound_tweaks @ get_offset(toc, "AISNDTWK"); -Chunk ambient @ get_offset(toc, "AMBIENT"); -Chunk bash @ get_offset(toc, "BASH"); -Chunk br_head @ get_offset(toc, "BRHEAD"); -Chunk br_list @ get_offset(toc, "BRLIST"); -Chunk brush_version @ get_offset(toc, "BRVER"); -Chunk cell_motion @ get_offset(toc, "CELL_MOTION"); -Chunk celestial_object_var_1 @ get_offset(toc, "CELOBJVAR1"); -Chunk celestial_object_var_2 @ get_offset(toc, "CELOBJVAR2"); -Chunk celestial_object_var_3 @ get_offset(toc, "CELOBJVAR3"); -Chunk cloud_object_var @ get_offset(toc, "CLOUDOBJVAR"); -Chunk dark_combat @ get_offset(toc, "DARKCOMBAT"); -Chunk dark_miss @ get_offset(toc, "DARKMISS"); -Chunk distant_art_var @ get_offset(toc, "DISTOBJVAR"); -Chunk dark_settings @ get_offset(toc, "DRKSET"); -Chunk env_map_var @ get_offset(toc, "ENVMAPVAR"); -Chunk family @ get_offset(toc, "FAMILY"); -Chunk file_type @ get_offset(toc, "FILE_TYPE"); -Chunk flow_tex @ get_offset(toc, "FLOW_TEX"); -Chunk fog_zone_var @ get_offset(toc, "FOGZONEVAR"); -Chunk gamesys_eax @ get_offset(toc, "GameSysEAX"); -Chunk hot_regions @ get_offset(toc, "HotRegions"); -Chunk map_i_src @ get_offset(toc, "MAPISRC"); -Chunk mission_eax @ get_offset(toc, "MissionEAX"); -Chunk multibrush @ get_offset(toc, "MultiBrush"); -Chunk obj_map @ get_offset(toc, "OBJ_MAP"); -Chunk rend_params @ get_offset(toc, "RENDPARAMS"); -Chunk room_db @ get_offset(toc, "ROOM_DB"); -Chunk room_eax @ get_offset(toc, "ROOM_EAX"); -Chunk script_modules @ get_offset(toc, "ScrModules"); -Chunk sky_mode @ get_offset(toc, "SKYMODE"); -Chunk sky_object_var @ get_offset(toc, "SKYOBJVAR"); -Chunk mision_song_params @ get_offset(toc, "SONGPARAMS"); -Chunk star_object_var @ get_offset(toc, "STAROBJVAR"); -Chunk ti_list @ get_offset(toc, "TILIST"); -Chunk texture_list @ get_offset(toc, "TXLIST"); -Chunk texture_patch_database @ get_offset(toc, "TXTPAT_DB"); -Chunk water_banks @ get_offset(toc, "WATERBANKS"); -Chunk weather_var @ get_offset(toc, "WEATHERVAR"); -Chunk world_rep @ get_offset(toc, "WREXT"); - -// TODO: Have a nice function for doing all of these? -Chunk p_model_name @ get_offset(toc, "P$ModelName"); \ No newline at end of file diff --git a/patterns/db_files/DbFile.pat b/patterns/db_files/DbFile.pat new file mode 100644 index 0000000..fd6624c --- /dev/null +++ b/patterns/db_files/DbFile.pat @@ -0,0 +1,101 @@ +#pragma once +#pragma pattern_limit 262144 + +#include +#include + +#include "db_files/AllChunks.pat" + +struct Version { + u32 major; + u32 minor; +}; + +struct ChunkHeader { + char name[12]; + Version version; + padding[4]; +}; + +struct Chunk { + ChunkHeader header; + T data; +}; + +struct FileHeader { + u32 toc_offset; + Version version; + padding[256]; + u32 deadbeef; +}; + +struct TOCEntry { + char name[while($[$] != 0x00)]; + $ = $ + 12 - std::string::length(name); + u32 offset; + u32 size; + u32 data_end = offset + size + 24; + + match (name) { + ("AI_ROOM_DB"): Chunk ai_room_db @ offset; + ("AIACS"): Chunk ai_acuity_sets @ offset; + ("AICONVERSE"): Chunk ai_conversations @ offset; + ("AICRTSZ"): Chunk ai_creature_sizes @ offset; + ("AIGPTHVAR"): Chunk ai_gamesys_path_options @ offset; + ("AIHearStat"): Chunk ai_hear_stat @ offset; + ("AIPATHVAR"): Chunk ai_path_var @ offset; + ("AISNDTWK"): Chunk ai_sound_tweaks @ offset; + ("AMBIENT"): Chunk ambient @ offset; + ("BASH"): Chunk bash @ offset; + ("BRHEAD"): Chunk br_head @ offset; + ("BRLIST"): Chunk br_list @ offset; + ("BRVER"): Chunk brush_version @ offset; + ("CELL_MOTION"): Chunk cell_motion @ offset; + ("CELOBJVAR1"): Chunk celestial_object_var_1 @ offset; + ("CELOBJVAR2"): Chunk celestial_object_var_2 @ offset; + ("CELOBJVAR3"): Chunk celestial_object_var_3 @ offset; + ("CLOUDOBJVAR"): Chunk cloud_object_var @ offset; + ("DARKCOMBAT"): Chunk dark_combat @ offset; + ("DARKMISS"): Chunk dark_miss @ offset; + ("DISTOBJVAR"): Chunk distant_art_var @ offset; + ("DRKSET"): Chunk dark_settings @ offset; + ("ENVMAPVAR"): Chunk env_map_var @ offset; + ("FAMILY"): Chunk family @ offset; + ("FILE_TYPE"): Chunk file_type @ offset; + ("FLOW_TEX"): Chunk flow_tex @ offset; + ("FOGZONEVAR"): Chunk fog_zone_var @ offset; + ("GameSysEAX"): Chunk gamesys_eax @ offset; + ("HotRegions"): Chunk hot_regions @ offset; + ("MAPISRC"): Chunk map_i_src @ offset; + ("MissionEAX"): Chunk mission_eax @ offset; + ("MultiBrush"): Chunk multibrush @ offset; + ("OBJ_MAP"): Chunk obj_map @ offset; + ("RENDPARAMS"): Chunk rend_params @ offset; + ("ROOM_DB"): Chunk room_db @ offset; + ("ROOM_EAX"): Chunk room_eax @ offset; + ("ScrModules"): Chunk script_modules @ offset; + ("SKYMODE"): Chunk sky_mode @ offset; + ("SKYOBJVAR"): Chunk sky_object_var @ offset; + ("SONGPARAMS"): Chunk mision_song_params @ offset; + ("STAROBJVAR"): Chunk star_object_var @ offset; + ("TILIST"): Chunk ti_list @ offset; + ("TXLIST"): Chunk texture_list @ offset; + ("TXTPAT_DB"): Chunk texture_patch_database @ offset; + ("WATERBANKS"): Chunk water_banks @ offset; + ("WEATHERVAR"): Chunk weather_var @ offset; + ("WREXT"): Chunk world_rep @ offset; + (_): { + if (std::string::starts_with(name, "P$")) { + Chunk property_chunk @ offset; + } + } + } +}; + +struct TableOfContents { + u32 item_count; + TOCEntry items[item_count]; +}; + +FileHeader file_header @ 0x0; +TableOfContents toc @ file_header.toc_offset; \ No newline at end of file diff --git a/patterns/db_files/FileBase.pat b/patterns/db_files/FileBase.pat deleted file mode 100644 index 47e22a8..0000000 --- a/patterns/db_files/FileBase.pat +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once - -struct Version { - u32 major; - u32 minor; -}; - -struct FileHeader { - u32 toc_offset; - Version version; - padding[256]; - u32 deadbeef; -}; - -struct TOCEntry { - char name[12]; - u32 offset; - u32 size; -}; - -struct TableOfContents { - u32 item_count; - TOCEntry items[item_count]; -}; - -struct ChunkHeader { - char name[12]; - Version version; - padding[4]; -}; - -struct Chunk { - ChunkHeader header; - T data; -}; - -fn get_toc_entry(TableOfContents toc, str entry_name) { - for (u32 i = 0, i < toc.item_count, i = i + 1) { - if (std::string::starts_with(toc.items[i].name, entry_name)) { - return toc.items[i]; - } - } -}; - -fn get_offset(TableOfContents toc, str entry_name) { - TOCEntry entry = get_toc_entry(toc, entry_name); - return entry.offset; -}; - -fn get_size(TableOfContents toc, str entry_name) { - TOCEntry entry = get_toc_entry(toc, entry_name); - return entry.size; -}; - -fn get_end(TableOfContents toc, str entry_name) { - TOCEntry entry = get_toc_entry(toc, entry_name); - return entry.offset + entry.size + 24; -}; \ No newline at end of file diff --git a/patterns/db_files/chunks/BRLIST.hexpat b/patterns/db_files/chunks/BRLIST.hexpat index 2191882..ca729c3 100644 --- a/patterns/db_files/chunks/BRLIST.hexpat +++ b/patterns/db_files/chunks/BRLIST.hexpat @@ -9,7 +9,7 @@ using BrMedia; using BrType; struct BrList { - u32 max = get_end(toc, parent.header.name); + u32 max = parent.parent.data_end; Br brushes[while($ < max)]; }; diff --git a/patterns/db_files/chunks/OBJ_MAP.hexpat b/patterns/db_files/chunks/OBJ_MAP.hexpat index 54d1d5f..37ce5eb 100644 --- a/patterns/db_files/chunks/OBJ_MAP.hexpat +++ b/patterns/db_files/chunks/OBJ_MAP.hexpat @@ -9,6 +9,6 @@ struct ObjMapElement { }; struct ObjMap { - u32 max = get_end(toc, parent.header.name); + u32 max = parent.parent.data_end; ObjMapElement objects[while($ < max)]; }; \ No newline at end of file diff --git a/patterns/db_files/chunks/P$_.hexpat b/patterns/db_files/chunks/P$_.hexpat index afbb539..aee7ed3 100644 --- a/patterns/db_files/chunks/P$_.hexpat +++ b/patterns/db_files/chunks/P$_.hexpat @@ -9,6 +9,6 @@ struct ObjectProperty { }; struct PropertyMap { - u32 max = get_end(toc, parent.header.name); + u32 max = parent.parent.data_end; ObjectProperty props[while($ < max)]; }; diff --git a/patterns/db_files/chunks/ScrModules.hexpat b/patterns/db_files/chunks/ScrModules.hexpat index e46cb3b..ae54ff9 100644 --- a/patterns/db_files/chunks/ScrModules.hexpat +++ b/patterns/db_files/chunks/ScrModules.hexpat @@ -9,7 +9,7 @@ namespace ScrModules { }; struct ChunkData { - u32 max = get_end(toc, parent.header.name); + u32 max = parent.parent.data_end; Name names[while($ < max)]; }; } \ No newline at end of file