Skip to content

Commit cee3a5d

Browse files
authored
patterns: Add pattern and magic for Arma 3 PAA (#475)
* patterns/paa: Added pattern for Arma 3 PAA * patterns/paa: Small correction * magic/arma3: Added magic file for Arma 3 formats Only the PAA format for now
1 parent fb84bbb commit cee3a5d

4 files changed

Lines changed: 137 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
3636
| ARC | | [`patterns/arc.hexpat`](patterns/arc.hexpat) | Minecraft Legacy Console Edition ARC files |
3737
| ARIA2 | | [`patterns/aria2.hexpat`](patterns/aria2.hexpat) | ARIA2 Download Manager Control files |
3838
| ARM VTOR | | [`patterns/arm_cm_vtor.hexpat`](patterns/arm_cm_vtor.hexpat) | ARM Cortex M Vector Table Layout |
39+
| Arma 3 PAA | | [`patterns/a3_paa.hexpat`](patterns/a3_paa.hexpat) | Arma 3 PAA texture file |
3940
| Assassin's Creed: Unity | | [`patterns/AC Unity`](patterns/Assassin's Creed: Unity) | Assassin's Creed: Unity archive files -- .forge & .data (compressed and decompressed) -- |
4041
| Bastion | | [`patterns/bastion/*`](https://gitlab.com/EvelynTSMG/imhex-bastion-pats) | Various [Bastion](https://en.wikipedia.org/wiki/Bastion_(video_game)) files |
4142
| BeyondCompare BCSS | | [`patterns/bcss.hexpat`](patterns/bcss.hexpat) | BeyondCompare Snapshot (BCSS) file |
@@ -266,6 +267,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
266267

267268
| Name | Path | Description |
268269
|------|------|-------------|
270+
| Arma 3 | [`magic/arma3_magic`](magic/arma3_magic) | Identifies Arma 3 binary formats |
269271
| Nintendo Switch | [`magic/nintendo_switch_magic`](magic/nintendo_switch_magic) | Identifies common file types used on the Nintendo Switch |
270272
| Portable Executable | [`magic/portable_executable_magic`](magic/portable_executable_magic) | Identifies PE files used on Windows
271273

magic/arma3_magic

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# A libmagic database containing definitions for files used by the Arma 3 game by Bohemia Interactive
2+
3+
# Arma 3 PAA image
4+
0x02 string GGAT Arma 3 PAA image file
5+
!:mime image/x.a3-paa
6+
!:ext paa
7+
>0 leshort 0xff01 DXT1 compression
8+
>0 leshort 0xff02 DXT2 compression
9+
>0 leshort 0xff03 DXT3 compression
10+
>0 leshort 0xff04 DXT4 compression
11+
>0 leshort 0xff05 DXT5 compression
12+
>0 leshort 0x4444 RGBA4 format
13+
>0 leshort 0x1555 RGBA5 format
14+
>0 leshort 0x8888 RGBA8 format
15+
>0 leshort 0x8080 Grayscale format

patterns/a3_paa.hexpat

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#pragma author MrClock
2+
#pragma description Arma 3 PAA image format
3+
4+
#pragma endian little
5+
6+
#pragma MIME image/x.a3-paa
7+
8+
import type.color;
9+
import std.mem;
10+
import std.sys;
11+
12+
struct Color<auto alpha> {
13+
u8 b;
14+
u8 g;
15+
u8 r;
16+
if (alpha) u8 a;
17+
} [[sealed, format("type::impl::format_color"), color(std::format("{0:02X}{1:02X}{2:02X}", r, g, b))]];
18+
19+
using BGR8 = Color<false>;
20+
using BGRA8 = Color<true>;
21+
22+
enum PixelFormat: u16 {
23+
DXT1 = 0xFF01,
24+
DXT2 = 0xFF02,
25+
DXT3 = 0xFF03,
26+
DXT4 = 0xFF04,
27+
DXT5 = 0xFF05,
28+
RGBA4 = 0x4444,
29+
RGBA5 = 0x1555,
30+
RGBA8 = 0x8888,
31+
GRAY = 0x8080
32+
};
33+
34+
enum AlphaMode: u32 {
35+
NONE = 0,
36+
INTERPOLATED = 1,
37+
BINARY = 2
38+
};
39+
40+
enum Swizzle: u8 {
41+
ALPHA = 0,
42+
RED = 1,
43+
GREEN = 2,
44+
BLUE = 3,
45+
INVERTED_ALPHA = 4,
46+
INVERTED_RED = 5,
47+
INVERTED_GREEN = 6,
48+
INVERTED_BLUE = 7,
49+
BLANK_WHITE = 8,
50+
BLANK_BLACK = 9
51+
};
52+
53+
struct Tagg {
54+
char signature[8];
55+
u32 length;
56+
57+
match (signature) {
58+
("GGATCGVA"): BGRA8 color;
59+
("GGATCXAM"): BGRA8 color;
60+
("GGATGALF"): AlphaMode alpha;
61+
("GGATSFFO"): u32 offsets[16];
62+
("GGATZIWS"): Swizzle copies[4];
63+
(_): u8 data[length];
64+
}
65+
} [[format("format_tagg_name")]];
66+
67+
struct Palette {
68+
u16 length;
69+
BGR8 colors[length];
70+
};
71+
72+
struct Mipmap {
73+
u16 width_and_lzo [[format("format_width_lzo")]];
74+
u16 height;
75+
76+
u16 width = width_and_lzo & 0x7FFF;
77+
78+
if (width == 0 && height == 0) {
79+
break;
80+
}
81+
82+
u24 size;
83+
u8 data[size];
84+
} [[format("format_resolution")]];
85+
86+
struct PAA {
87+
PixelFormat format;
88+
Tagg taggs[while(std::mem::read_string($, 4) == "GGAT")];
89+
Palette palette;
90+
Mipmap mipmaps[while(true)];
91+
u16 EOF;
92+
93+
std::assert_warn(EOF == 0, "Invalid EOF sentinel");
94+
};
95+
96+
fn format_resolution(ref auto mip) {
97+
return std::format("{0:d} x {1:d}", mip.width, mip.height);
98+
};
99+
100+
fn format_width_lzo(u16 value) {
101+
u16 width = value & 0x7FFF;
102+
if (value & 0x8000) {
103+
return std::format("{0:d} (+LZO)", width);
104+
} else {
105+
return std::format("{0:d}", width);
106+
}
107+
};
108+
109+
fn format_tagg_name(Tagg data) {
110+
match (data.signature) {
111+
("GGATCGVA"): return "Average color";
112+
("GGATCXAM"): return "Max color";
113+
("GGATGALF"): return "Alpha flag";
114+
("GGATZIWS"): return "Swizzle";
115+
("GGATSFFO"): return "Mipmap offsets";
116+
(_): return "Unknown";
117+
}
118+
};
119+
120+
PAA file @ 0x0000;
21.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)