From 0f6d8dfe9ec3b460821c072f62d049bf110c7926 Mon Sep 17 00:00:00 2001
From: TheAuctioneer9836 <97371998+TheAuctioneer9836@users.noreply.github.com>
Date: Sun, 9 Jan 2022 07:01:12 +0200
Subject: [PATCH] Add BAR template
---
README.md | 4 +-
engines/Gameloft/bar/templates/BAR.bt | 124 ++++++++++++++++++++++++++
2 files changed, 126 insertions(+), 2 deletions(-)
create mode 100644 engines/Gameloft/bar/templates/BAR.bt
diff --git a/README.md b/README.md
index c4c8d26..1a24f09 100644
--- a/README.md
+++ b/README.md
@@ -41,8 +41,8 @@ Status legend:
Description |
- .bar |
- |
+ .bar |
+ Packaged strings of certain language. |
.bdae |
diff --git a/engines/Gameloft/bar/templates/BAR.bt b/engines/Gameloft/bar/templates/BAR.bt
new file mode 100644
index 0000000..5b83f8b
--- /dev/null
+++ b/engines/Gameloft/bar/templates/BAR.bt
@@ -0,0 +1,124 @@
+//------------------------------------------------
+//--- 010 Editor v11.0.1 Binary Template
+//
+// File: BAR.bt
+// Authors: TheAuctioneer9836
+// Version: 1.0
+// Purpose: Parse packaged strings files from some Gameloft games.
+// Category:
+// File Mask: *.bar
+// ID Bytes:
+// History:
+//------------------------------------------------
+
+//------------------------------------------------
+// Variables
+//------------------------------------------------
+
+local ushort packs_count = 0;
+
+local int seek_status;
+
+//------------------------------------------------
+// Structures and functions
+//------------------------------------------------
+
+struct PackOffsets
+{
+ ushort count ;
+ Assert(count >= 2, "Count of pack offsets must be not less than 2");
+
+ packs_count = count - 1;
+
+ uint offset[count] ;
+};
+
+typedef struct
+{
+ local uint real_length = ReadStringLength(FTell());
+ local uint aligned_length = (real_length + 3) & ~3; // 4-byte alignment with respect to pack strings block start
+ byte bytes[aligned_length] ;
+} String ;
+
+// UTF-8 encoding needs to be selected in interface for correct representation of non-ASCII strings
+string ReadPackString(String &str)
+{
+ return str.bytes;
+}
+
+struct PackStrings (struct StringPack &pack, int64 start_pos, int64 size)
+{
+ local uint count = pack.strings_count;
+
+ local uint index;
+ for (index = 0; index < count; index++)
+ {
+ Assert(pack.string_offsets[index] < size, "String offset must be less than pack strings block size");
+
+ seek_status = FSeek(start_pos + pack.string_offsets[index]);
+ Assert(seek_status == 0, "Failed setting current position to string start address");
+
+ String pack_string ;
+ }
+};
+
+string NamePackStrings(PackStrings &strings)
+{
+ string name;
+ SPrintf(name, "Strings[%u]", strings.count);
+ return name;
+}
+
+struct StringPack (ushort index)
+{
+ local int64 pack_size = pack_offsets.offset[index + 1] - pack_offsets.offset[index];
+ Assert(pack_size > 0, "String pack size must be more than 0 bytes");
+
+ local int64 pack_start_pos = FTell();
+
+ uint strings_count ;
+ uint string_offsets[strings_count] ;
+
+ local int64 strings_start_pos = FTell();
+
+ local int64 strings_block_size = pack_size - (strings_start_pos - pack_start_pos);
+ Assert(strings_block_size > 0, "Pack string block size must be more than 0 bytes");
+
+ PackStrings strings(this, strings_start_pos, strings_block_size) ;
+};
+
+struct StringPacks
+{
+ local int64 start_pos = FTell();
+ local int64 remaining_size = FileSize() - start_pos;
+
+ local ushort index;
+ for (index = 0; index < packs_count; index++)
+ {
+ Assert(pack_offsets.offset[index] < remaining_size, "String pack offset must be less than remaining file size");
+
+ seek_status = FSeek(start_pos + pack_offsets.offset[index]);
+ Assert(seek_status == 0, "Failed setting current position to pack start address");
+
+ StringPack pack(index) ;
+ }
+};
+
+string NameStringPacks(StringPacks &packs)
+{
+ string name;
+ SPrintf(name, "String Packs[%hu]", packs_count);
+ return name;
+}
+
+//------------------------------------------------
+// Parsing file
+//------------------------------------------------
+
+if (GetFileCharSet() != CHARSET_UTF8)
+ Warning("Currently selected charset is not UTF-8, non-ASCII strings may be displayed incorrectly");
+
+LittleEndian();
+
+PackOffsets pack_offsets ;
+StringPacks string_packs ;
\ No newline at end of file