1 #pragma once
2 
3 struct zmap_header_type;
4 struct gdrv_bitmap8;
5 
6 
7 enum class FieldTypes : int16_t
8 {
9 	// One 16 bit signed integer
10 	ShortValue = 0,
11 
12 	// Sprite bitmap, 8bpp, indexed color
13 	Bitmap8bit = 1,
14 
15 	Unknown2 = 2,
16 
17 	// Group name, char[]. Not all groups have names.
18 	GroupName = 3,
19 
20 	Unknown4 = 4,
21 
22 	// Palette, contains 256 RBGA 4-byte colors.
23 	Palette = 5,
24 
25 	Unknown6 = 6,
26 
27 	Unknown7 = 7,
28 
29 	Unknown8 = 8,
30 
31 	// String, char[]
32 	String = 9,
33 
34 	// Array of 16 bit signed integers
35 	ShortArray = 10,
36 
37 	// Array of 32 bit floats
38 	FloatArray = 11,
39 
40 	// Sprite depth map, 16bpp, unsigned
41 	Bitmap16bit = 12,
42 };
43 
44 struct EntryData
45 {
46 	EntryData() = default;
47 
EntryDataEntryData48 	EntryData(FieldTypes entryType, char* buffer): EntryType(entryType), FieldSize(-1), Buffer(buffer)
49 	{
50 	}
51 
52 	~EntryData();
53 	FieldTypes EntryType{};
54 	int FieldSize{};
55 	char* Buffer{};
56 };
57 
58 
59 #pragma pack(push, 1)
60 struct MsgFontChar
61 {
62 	uint8_t Width;
63 	char Data[1];
64 };
65 
66 struct MsgFont
67 {
68 	int16_t GapWidth;
69 	int16_t Unknown1;
70 	int16_t Height;
71 	uint8_t CharWidths[128];
72 	MsgFontChar Data[1];
73 };
74 #pragma pack(pop)
75 
76 static_assert(sizeof(MsgFont) == 136, "Wrong size of MsgFont");
77 
78 
79 class GroupData
80 {
81 public:
82 	int GroupId;
83 	std::string GroupName;
84 
85 	GroupData(int groupId);
86 	void AddEntry(EntryData* entry);
87 	void FinalizeGroup();
GetEntries()88 	const std::vector<EntryData*>& GetEntries() const { return Entries; }
GetEntry(size_t index)89 	const EntryData* GetEntry(size_t index) const { return Entries[index]; }
EntryCount()90 	size_t EntryCount() const { return Entries.size(); }
ReserveEntries(size_t count)91 	void ReserveEntries(size_t count) { Entries.reserve(count); }
92 	gdrv_bitmap8* GetBitmap(int resolution) const;
93 	zmap_header_type* GetZMap(int resolution) const;
94 
95 private:
96 	std::vector<EntryData*> Entries;
97 	gdrv_bitmap8* Bitmaps[3]{};
98 	zmap_header_type* ZMaps[3]{};
99 	bool NeedsSort = false;
100 
101 	static void SplitSplicedBitmap(const gdrv_bitmap8& srcBmp, gdrv_bitmap8& bmp, zmap_header_type& zMap);
102 
103 	void SetBitmap(gdrv_bitmap8* bmp);
104 	void SetZMap(zmap_header_type* zMap);
105 };
106 
107 
108 class DatFile
109 {
110 public:
111 	std::string AppName;
112 	std::string Description;
113 	std::vector<GroupData*> Groups;
114 
115 	~DatFile();
116 	char* field_nth(int groupIndex, FieldTypes targetEntryType, int skipFirstN);
117 	char* field(int groupIndex, FieldTypes entryType);
118 	int field_size_nth(int groupIndex, FieldTypes targetEntryType, int skipFirstN);
119 	int field_size(int groupIndex, FieldTypes targetEntryType);
120 	int record_labeled(LPCSTR targetGroupName);
121 	char* field_labeled(LPCSTR lpString, FieldTypes fieldType);
122 	gdrv_bitmap8* GetBitmap(int groupIndex);
123 	zmap_header_type* GetZMap(int groupIndex);
124 	void Finalize();
125 
126 private:
127 	void AddMsgFont(MsgFont* font, const std::string& fontName);
128 };
129