From e7bf306211eee03880cd50ed99694a84f755b789 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sat, 17 Aug 2024 10:52:09 +0100 Subject: [PATCH] Fixed everything being broken and ImHex memory leak --- patterns/Common.hexpat | 14 ++++++ patterns/db_files/Common.hexpat | 48 --------------------- patterns/db_files/CowFile.hexpat | 11 ++--- patterns/db_files/FileBase.pat | 48 +++++++++++++++++++++ patterns/db_files/Utils.hexpat | 14 ------ patterns/db_files/chunks/AI_ROOM_DB.hexpat | 1 - patterns/db_files/chunks/BRLIST.hexpat | 2 +- patterns/db_files/chunks/CELL_MOTION.hexpat | 2 +- patterns/db_files/chunks/CELOBJVAR.hexpat | 2 + patterns/db_files/chunks/CLOUDOBJVAR.hexpat | 3 +- patterns/db_files/chunks/DISTOBJVAR.hexpat | 2 + patterns/db_files/chunks/FOGZONEVAR.hexpat | 2 +- patterns/db_files/chunks/RENDPARAMS.hexpat | 2 +- patterns/db_files/chunks/ROOM_DB.hexpat | 2 +- patterns/db_files/chunks/SKYOBJVAR.hexpat | 3 +- patterns/db_files/chunks/WATERBANKS.hexpat | 2 + patterns/db_files/chunks/WEATHERVAR.hexpat | 2 + patterns/db_files/chunks/WREXT.hexpat | 2 +- 18 files changed, 86 insertions(+), 76 deletions(-) create mode 100644 patterns/db_files/FileBase.pat delete mode 100644 patterns/db_files/Utils.hexpat diff --git a/patterns/Common.hexpat b/patterns/Common.hexpat index d8342b2..347a446 100644 --- a/patterns/Common.hexpat +++ b/patterns/Common.hexpat @@ -16,4 +16,18 @@ struct Vec4 { T y; T z; T w; +}; + +struct Plane { + float x; + float y; + float z; + float d; +}; + +struct DPlane { + double x; + double y; + double z; + double d; }; \ No newline at end of file diff --git a/patterns/db_files/Common.hexpat b/patterns/db_files/Common.hexpat index e7aef9f..827630c 100644 --- a/patterns/db_files/Common.hexpat +++ b/patterns/db_files/Common.hexpat @@ -1,53 +1,5 @@ #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; -}; - -struct Plane { - float x; - float y; - float z; - float d; -}; - -struct DPlane { - double x; - double y; - double z; - double d; -}; - namespace NameNum { struct Tag { s32 value; diff --git a/patterns/db_files/CowFile.hexpat b/patterns/db_files/CowFile.hexpat index 75961c7..f484207 100644 --- a/patterns/db_files/CowFile.hexpat +++ b/patterns/db_files/CowFile.hexpat @@ -1,9 +1,10 @@ +#pragma once + #include #include -#include "FileBase.hexpat" -#include "lgtypes.hexpat" - +#include "db_files/FileBase.pat" +#include "db_files/Common.hexpat" #include "db_files/AllChunks.pat" FileHeader file_header @ 0x0; @@ -40,10 +41,10 @@ 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 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 multibrush @ get_offset(toc, "MultiBrush"); Chunk rend_params @ get_offset(toc, "RENDPARAMS"); Chunk room_db @ get_offset(toc, "ROOM_DB"); Chunk room_eax @ get_offset(toc, "ROOM_EAX"); diff --git a/patterns/db_files/FileBase.pat b/patterns/db_files/FileBase.pat new file mode 100644 index 0000000..f8c1883 --- /dev/null +++ b/patterns/db_files/FileBase.pat @@ -0,0 +1,48 @@ +#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; +}; \ No newline at end of file diff --git a/patterns/db_files/Utils.hexpat b/patterns/db_files/Utils.hexpat deleted file mode 100644 index 5a11456..0000000 --- a/patterns/db_files/Utils.hexpat +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -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; -}; \ No newline at end of file diff --git a/patterns/db_files/chunks/AI_ROOM_DB.hexpat b/patterns/db_files/chunks/AI_ROOM_DB.hexpat index b9d00b4..ebdeb0b 100644 --- a/patterns/db_files/chunks/AI_ROOM_DB.hexpat +++ b/patterns/db_files/chunks/AI_ROOM_DB.hexpat @@ -1,7 +1,6 @@ #pragma once #include "Common.hexpat" -#include "lgtypes.hexpat" namespace AiRoomDb { struct Cell { diff --git a/patterns/db_files/chunks/BRLIST.hexpat b/patterns/db_files/chunks/BRLIST.hexpat index 3eccfdd..443a1fa 100644 --- a/patterns/db_files/chunks/BRLIST.hexpat +++ b/patterns/db_files/chunks/BRLIST.hexpat @@ -1,6 +1,6 @@ #pragma once -#include "lgtypes.hexpat" +#include "Common.hexpat" using Br; using Grid; diff --git a/patterns/db_files/chunks/CELL_MOTION.hexpat b/patterns/db_files/chunks/CELL_MOTION.hexpat index 01732e9..587d7a4 100644 --- a/patterns/db_files/chunks/CELL_MOTION.hexpat +++ b/patterns/db_files/chunks/CELL_MOTION.hexpat @@ -1,6 +1,6 @@ #pragma once -#include "lgtypes.hexpat" +#include "Common.hexpat" struct CellMotionPortal { Vec3 center; diff --git a/patterns/db_files/chunks/CELOBJVAR.hexpat b/patterns/db_files/chunks/CELOBJVAR.hexpat index ec0173d..bb2d445 100644 --- a/patterns/db_files/chunks/CELOBJVAR.hexpat +++ b/patterns/db_files/chunks/CELOBJVAR.hexpat @@ -1,5 +1,7 @@ #pragma once +#include "Common.hexpat" + struct CelObjVar { bool enable_object; padding[3]; diff --git a/patterns/db_files/chunks/CLOUDOBJVAR.hexpat b/patterns/db_files/chunks/CLOUDOBJVAR.hexpat index b898aad..dd91259 100644 --- a/patterns/db_files/chunks/CLOUDOBJVAR.hexpat +++ b/patterns/db_files/chunks/CLOUDOBJVAR.hexpat @@ -1,6 +1,7 @@ #pragma once -#include "lgtypes.hexpat" +#include "Common.hexpat" +#include "db_files/Common.hexpat" using ColorSettings; diff --git a/patterns/db_files/chunks/DISTOBJVAR.hexpat b/patterns/db_files/chunks/DISTOBJVAR.hexpat index a2711ae..e02a69e 100644 --- a/patterns/db_files/chunks/DISTOBJVAR.hexpat +++ b/patterns/db_files/chunks/DISTOBJVAR.hexpat @@ -1,5 +1,7 @@ #pragma once +#include "Common.hexpat" + struct DistantArtVar { bool enable_distant_art; padding[3]; diff --git a/patterns/db_files/chunks/FOGZONEVAR.hexpat b/patterns/db_files/chunks/FOGZONEVAR.hexpat index 98a189d..a46e34c 100644 --- a/patterns/db_files/chunks/FOGZONEVAR.hexpat +++ b/patterns/db_files/chunks/FOGZONEVAR.hexpat @@ -1,6 +1,6 @@ #pragma once -#include "lgtypes.hexpat" +#include "Common.hexpat" struct FogZone { padding[1]; diff --git a/patterns/db_files/chunks/RENDPARAMS.hexpat b/patterns/db_files/chunks/RENDPARAMS.hexpat index 343e97f..4f2b3a7 100644 --- a/patterns/db_files/chunks/RENDPARAMS.hexpat +++ b/patterns/db_files/chunks/RENDPARAMS.hexpat @@ -1,6 +1,6 @@ #pragma once -#include "lgtypes.hexpat" +#include "Common.hexpat" enum SunlightMode : s32 { SingleUnshadowed = 0x0, diff --git a/patterns/db_files/chunks/ROOM_DB.hexpat b/patterns/db_files/chunks/ROOM_DB.hexpat index 3ba4ae8..8f1af77 100644 --- a/patterns/db_files/chunks/ROOM_DB.hexpat +++ b/patterns/db_files/chunks/ROOM_DB.hexpat @@ -1,6 +1,6 @@ #pragma once -#include "lgtypes.hexpat" +#include "Common.hexpat" struct RoomPortal { s32 id; diff --git a/patterns/db_files/chunks/SKYOBJVAR.hexpat b/patterns/db_files/chunks/SKYOBJVAR.hexpat index 19068a2..b157a73 100644 --- a/patterns/db_files/chunks/SKYOBJVAR.hexpat +++ b/patterns/db_files/chunks/SKYOBJVAR.hexpat @@ -1,6 +1,7 @@ #pragma once -#include "lgtypes.hexpat" +#include "Common.hexpat" +#include "db_files/Common.hexpat" struct SkyObjVar { bool enable_new_sky; diff --git a/patterns/db_files/chunks/WATERBANKS.hexpat b/patterns/db_files/chunks/WATERBANKS.hexpat index 3cc26cb..72d5d37 100644 --- a/patterns/db_files/chunks/WATERBANKS.hexpat +++ b/patterns/db_files/chunks/WATERBANKS.hexpat @@ -1,5 +1,7 @@ #pragma once +#include "Common.hexpat" + struct RGBA { Vec3 rgb; padding[1]; diff --git a/patterns/db_files/chunks/WEATHERVAR.hexpat b/patterns/db_files/chunks/WEATHERVAR.hexpat index 63aa177..09d2c3e 100644 --- a/patterns/db_files/chunks/WEATHERVAR.hexpat +++ b/patterns/db_files/chunks/WEATHERVAR.hexpat @@ -1,5 +1,7 @@ #pragma once +#include "Common.hexpat" + enum Precipitation : u32 { Snow = 0x0, Rain = 0x1, diff --git a/patterns/db_files/chunks/WREXT.hexpat b/patterns/db_files/chunks/WREXT.hexpat index 73934ed..dbca12f 100644 --- a/patterns/db_files/chunks/WREXT.hexpat +++ b/patterns/db_files/chunks/WREXT.hexpat @@ -4,7 +4,7 @@ #include #include #include -#include "FileBase.hexpat" +#include "Common.hexpat" using WrHeader; using WrCell;