imhex.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. #pragma endian little
  2. #pragma pattern_limit 512000
  3. #include <std/sys.pat>
  4. #include <std/mem.pat>
  5. #include <std/io.pat>
  6. #include <std/core.pat>
  7. struct RGBA8 {
  8. u8 red;
  9. u8 green;
  10. u8 blue;
  11. u8 alpha;
  12. } [[static, color(std::format("{:02X}{:02X}{:02X}", red, green, blue))]];
  13. struct Point {
  14. double x;
  15. double y;
  16. };
  17. struct MultiLine {
  18. u32 points;
  19. Point point[points];
  20. };
  21. enum WobbleType : u32 {
  22. Spiral = 0,
  23. Sinusoidal = 1,
  24. Ellipse = 2,
  25. Vert_8 = 3,
  26. Hoti_8 = 4,
  27. };
  28. // Field of a custom defined type
  29. struct FieldOf<T> {
  30. u32 length;
  31. T value;
  32. if (length != sizeof(value)) {
  33. std::error(std::format("Field size mismatch at 0x{:02X}", $));
  34. }
  35. } [[sealed, format("format_field_of")]];
  36. fn format_field_of(FieldOf<u8> f) {
  37. return f.value;
  38. };
  39. // Field of generic types
  40. struct Field {
  41. u32 length;
  42. match (length) {
  43. (4): u32 value;
  44. (8): double value;
  45. (2): u16 value; // ??
  46. (16): Point value; // ??
  47. (_): {
  48. std::warning(std::format("Unknown length tag: {} at 0x{:02X}", length, $));
  49. u8 value[length];
  50. }
  51. }
  52. } [[sealed, format("format_field")]];
  53. fn format_field(Field f) {
  54. return f.value;
  55. };
  56. // Variable length field of a fixed type.
  57. struct String {
  58. u32 length;
  59. char16 value[length / sizeof(char16)];
  60. } [[sealed, format("format_string")]];
  61. fn format_string(String s) {
  62. return s.value;
  63. };
  64. struct Header {
  65. char16 magic[0x8];
  66. u8 unknown[0x338];
  67. };
  68. struct Pen {
  69. u32 num_fields; // Number of fields in this struct (236)
  70. Field color;
  71. String name;
  72. Field disabled;
  73. Field use_default_param;
  74. Field loop_count;
  75. Field speed; // Changes with wobble relative speed
  76. Field power;
  77. Field frequency;
  78. Field unknown_1[1];
  79. Field start_tc;
  80. Field end_tc;
  81. Field polygon_tc;
  82. Field jump_speed;
  83. Field unknown_2[10];
  84. Field laser_off_tc;
  85. Field wave; // Only available if continue_mode is false
  86. Field unknown_3[1];
  87. Field wobble_enable;
  88. Field wobble_diameter;
  89. Field wobble_distance;
  90. Field unknown_4[8];
  91. Field min_jump_tc;
  92. Field max_jump_tc;
  93. Field jump_limit;
  94. Field unknown_5[2];
  95. Field frequency2;
  96. Field unknown_6[152];
  97. FieldOf<WobbleType> wobble_type;
  98. Field continue_mode;
  99. Field unknown_7[12];
  100. Field wobble_diameter2; // Only with wobble type ellipse
  101. Field unknown_8[26];
  102. };
  103. bitfield ObjectFlags {
  104. disabled : 1;
  105. aspect_ratio_unlocked : 1; // ??
  106. padding : 14;
  107. };
  108. enum ObjectType: u16 {
  109. Curve = 1,
  110. Point = 2,
  111. Rectangle = 3,
  112. Circle = 4,
  113. Ellipse = 5,
  114. Polygon = 6,
  115. HatchLine = 16,
  116. Hatch = 32,
  117. };
  118. struct ObjCommon {
  119. u32 num_fields; // Number of fields in this struct (17)
  120. Field pen;
  121. //Field type; // Seems to always be same value as object type
  122. FieldOf<ObjectType>;
  123. FieldOf<ObjectFlags>;
  124. String name;
  125. Field count;
  126. Field unknown_2;
  127. Field io_control_enable_mask;
  128. Field io_control_disable_mask;
  129. Field unknown_3[5];
  130. FieldOf<Point> origin;
  131. Field z;
  132. Field a;
  133. Field index; // Increments for each hatch line, -1 for certain hatch patterns
  134. if (index.value != 0) {
  135. std::warning(std::format("Unexpected unknown value {} at 0x{:02X}", index.value, $));
  136. }
  137. };
  138. enum LineType : u16 {
  139. Point = 0x0001,
  140. Line = 0x0100,
  141. Bezier = 0x0300,
  142. };
  143. struct LineEntry {
  144. LineType type;
  145. u32; // Zeros
  146. match (type) {
  147. (LineType::Point): Point;
  148. (LineType::Line): {
  149. u32 count;
  150. Point points[count];
  151. }
  152. (LineType::Bezier): {
  153. u32 count;
  154. Point points[count];
  155. }
  156. (_): std::error(std::format("Unknown line type: 0x{:02X} at 0x{:02X}", u32(type), $));
  157. }
  158. };
  159. struct LineSet : ObjCommon {
  160. u32 count;
  161. u32; // Zeros
  162. LineEntry entries[count];
  163. };
  164. struct ClosedSet : ObjCommon {
  165. u32 count;
  166. Field entries[count];
  167. };
  168. struct Rectangle : ObjCommon {
  169. u32 num_fields; // Number of fields in this struct (8)
  170. FieldOf<Point> corner_a;
  171. FieldOf<Point> corner_b;
  172. Field round_bottom_left;
  173. Field round_bottom_right;
  174. Field round_top_right;
  175. Field round_top_left;
  176. Field unknown;
  177. u32 length;
  178. u8 bytes[length];
  179. };
  180. struct Circle : ObjCommon {
  181. u32 num_fields; // Number of fields in this struct (6)
  182. FieldOf<Point> origin;
  183. Field radius;
  184. Field start_angle; // Radians
  185. Field clockwise;
  186. Field unknown[2];
  187. };
  188. struct Ellipse : ObjCommon {
  189. u32 num_fields; // Number of fields in this struct (8)
  190. Field clockwise;
  191. FieldOf<Point> corner_a;
  192. FieldOf<Point> corner_b;
  193. Field start_angle; // Radians
  194. Field end_angle; // Radians
  195. Field unknown[2];
  196. Field open_curve;
  197. };
  198. struct Polygon : ObjCommon {
  199. u32 num_fields; // Number of fields in this struct (10)
  200. Field invert_shape;
  201. FieldOf<Point> corner_a;
  202. FieldOf<Point> corner_b;
  203. Field offset_cx; // Moves (intial) sharper corner
  204. Field offset_cy; // Moves (initial)sharper corner
  205. Field offset_dx;
  206. Field offset_dy;
  207. Field edges;
  208. Field unknown_3[2];
  209. };
  210. struct HatchLine {
  211. u32 num_lines;
  212. LineSet line[num_lines];
  213. };
  214. using Object;
  215. bitfield HatchFlags {
  216. all_calc : 1; // Will always be set when background_pattern is set
  217. follow_edge_once : 1;
  218. continuous_pattern : 1; // Hatch type 4 when combined with bidirectional_pattern
  219. bidirectional_pattern : 1; // Hatch type 2
  220. ring_pattern : 1; // Hatch type 3
  221. padding : 1;
  222. auto_rotate_hatch_angle : 1;
  223. average_distribut_line : 1;
  224. padding : 1;
  225. gong_pattern : 1; // Hatch type 5 when combined with bidirectional_pattern
  226. cross_hatch : 1;
  227. background_pattern: 1; // Hatch type 6 (TODO, missing parsing)
  228. fill_pattern : 1; // Hatch type 7 when combined with continuous_pattern and bidirectional_pattern
  229. zigzag_pattern : 1; // Hatch type 8
  230. padding : 18;
  231. };
  232. // TODO: hatch types 1/2 will set last field of ObjCommon in HatchLines to 1
  233. // TODO: hatch types 3/4/5/7/8 will set last field of ObjCommon in HatchLines to -1 (0xFFFFFFFF)
  234. struct HatchSettings {
  235. u32 num_fields; // 46
  236. Field mark_contour;
  237. Field hatch_1_enable;
  238. Field hatch_1_pen;
  239. FieldOf<HatchFlags> hatch_1_flags;
  240. Field hatch_1_edge_offset;
  241. Field hatch_1_line_spacing;
  242. Field hatch_1_start_offset;
  243. Field hatch_1_end_offset;
  244. Field hatch_1_angle;
  245. Field hatch_2_enable;
  246. Field hatch_2_pen;
  247. FieldOf<HatchFlags> hatch_2_flags;
  248. Field hatch_2_edge_offset;
  249. Field hatch_2_line_space;
  250. Field hatch_2_start_offset;
  251. Field hatch_2_end_offset;
  252. Field hatch_2_angle;
  253. Field any_hatch_enabled;
  254. Field hatch_1_auto_rotate_angle;
  255. Field hatch_2_auto_rotate_angle;
  256. Field hatch_3_enable;
  257. Field hatch_3_pen;
  258. FieldOf<HatchFlags> hatch_3_flags;
  259. Field hatch_3_edge_offset;
  260. Field hatch_3_line_space;
  261. Field hatch_3_start_offset;
  262. Field hatch_3_end_offset;
  263. Field hatch_3_angle;
  264. Field hatch_3_auto_rotate_angle;
  265. Field hatch_1_line_reduction;
  266. Field hatch_2_line_reduction;
  267. Field hatch_3_line_reduction;
  268. Field hatch_1_num_loops;
  269. Field hatch_2_num_loops;
  270. Field hatch_3_num_loops;
  271. Field hatch_1_loop_distance;
  272. Field hatch_2_loop_distance;
  273. Field hatch_3_loop_distance;
  274. Field unknown_1[3];
  275. Field contour_priority;
  276. Field hatch_1_count;
  277. Field hatch_2_count;
  278. Field hatch_3_count;
  279. };
  280. struct HatchSettings2 {
  281. u32 num_fields; // 15
  282. Field count;
  283. Field enabled;
  284. Field pen;
  285. FieldOf<HatchFlags> flags;
  286. Field edge_offset;
  287. Field line_spacing;
  288. Field start_offset;
  289. Field end_offset;
  290. Field angle;
  291. Field auto_rotate_angle;
  292. Field line_reduction;
  293. Field loop_distance;
  294. Field num_loops;
  295. Field unknown_1; // Mirror unknown_1 in settings
  296. Field unknown_2;
  297. };
  298. struct HatchLines {
  299. u32; // 16 (tag?)
  300. ObjCommon;
  301. u32 num_lines;
  302. HatchLine lines2[num_lines];
  303. };
  304. struct Hatch : ObjCommon {
  305. u32 num_outlines;
  306. Object outline[num_outlines];
  307. HatchSettings settings;
  308. Field num_settings;
  309. HatchSettings2 settings_2[num_settings.value];
  310. // Following fields are not defined if hatch is disabled
  311. if (settings.any_hatch_enabled.value == 1) {
  312. ObjCommon;
  313. u32 num_hatches;
  314. HatchLines hatches[num_hatches];
  315. }
  316. };
  317. struct Object {
  318. ObjectType type;
  319. u16; // zero
  320. match (type) {
  321. (ObjectType::Curve): LineSet;
  322. (ObjectType::Point): LineSet;
  323. (ObjectType::Rectangle): Rectangle;
  324. (ObjectType::Circle): Circle;
  325. (ObjectType::Ellipse): Ellipse;
  326. (ObjectType::Polygon): Polygon;
  327. (ObjectType::Hatch): Hatch;
  328. (_): std::error(std::format("Unknown object type: 0x{:02X} at 0x{:02X}", u32(type), $));
  329. }
  330. };
  331. struct Layer {
  332. u32 num_fields_1; // Number of fields before object list (17)
  333. Field unknown_1[3];
  334. String name;
  335. Field count;
  336. Field unknown_2[1];
  337. Field input_signal_wait_enable_mask;
  338. Field input_signal_wait_disable_mask;
  339. Field unknown_3[9];
  340. u32 object_count;
  341. Object objects[object_count];
  342. u32 num_fields_2; // Number of fields to footer (151)
  343. Field unknown_4[54];
  344. Field output_signal_start_enable_mask;
  345. Field output_signal_start_disable_mask;
  346. Field output_signal_end_enable_mask;
  347. Field output_signal_end_disable_mask;
  348. Field unknown_5[9];
  349. Field fixture_offset;
  350. Field unknown_6[64];
  351. Field output_signal_start_delay;
  352. Field output_signal_end_delay;
  353. Field input_signal_wait_enable;
  354. Field unknown_7[2];
  355. Field output_signal_start_pulse;
  356. Field output_signal_end_pulse;
  357. Field unknown_8[12];
  358. u32 footer;
  359. };
  360. struct Layers {
  361. u32 count;
  362. Layer layer[count];
  363. };
  364. struct File {
  365. Header header;
  366. RGBA8 thumbnail[40000]; // 200x200?
  367. padding[16];
  368. Pen pens[256];
  369. Layers;
  370. };
  371. File file @ 0x0;