imhex.txt 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. #pragma endian little
  2. #pragma pattern_limit 256000
  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. std::assert(length == sizeof(value), "Size mismatch");
  33. } [[sealed, format("format_field_of")]];
  34. fn format_field_of(FieldOf<u8> f) {
  35. return f.value;
  36. };
  37. // Field of generic types
  38. struct Field {
  39. u32 length;
  40. match (length) {
  41. (4): u32 value;
  42. (8): double value;
  43. (2): u16 value; // ??
  44. (16): Point value; // ??
  45. (1): u32 value; // ??
  46. (_): {
  47. std::warning(std::format("Unknown length tag: {} at 0x{:02X}", length, $));
  48. u8 value[length];
  49. }
  50. }
  51. } [[sealed, format("format_field")]];
  52. fn format_field(Field f) {
  53. return f.value;
  54. };
  55. // Variable length field of a fixed type.
  56. struct String {
  57. u32 length;
  58. char16 value[length / sizeof(char16)];
  59. } [[sealed, format("format_string")]];
  60. fn format_string(String s) {
  61. return s.value;
  62. };
  63. struct Header {
  64. char16 magic[0x8];
  65. u8 unknown[0x338];
  66. };
  67. struct Pen {
  68. u32 num_fields; // Number of fields in this struct (236)
  69. Field color;
  70. String name;
  71. Field disabled;
  72. Field use_default_param;
  73. Field loop_count;
  74. Field speed; // Changes with wobble relative speed
  75. Field power;
  76. Field frequency;
  77. Field unknown_1[1];
  78. Field start_tc;
  79. Field end_tc;
  80. Field polygon_tc;
  81. Field jump_speed;
  82. Field unknown_2[10];
  83. Field laser_off_tc;
  84. Field wave; // Only available if continue_mode is false
  85. Field unknown_3[1];
  86. Field wobble_enable;
  87. Field wobble_diameter;
  88. Field wobble_distance;
  89. Field unknown_4[8];
  90. Field min_jump_tc;
  91. Field max_jump_tc;
  92. Field jump_limit;
  93. Field unknown_5[2];
  94. Field frequency2;
  95. Field unknown_6[152];
  96. FieldOf<WobbleType> wobble_type;
  97. Field continue_mode;
  98. Field unknown_7[12];
  99. Field wobble_diameter2; // Only with wobble type ellipse
  100. Field unknown_8[26];
  101. };
  102. bitfield ObjectFlags {
  103. disabled : 1;
  104. aspect_ratio_unlocked : 1; // ??
  105. padding : 14;
  106. };
  107. enum ObjectType: u32 {
  108. Curve = 1,
  109. Point = 2,
  110. Rectangle = 3,
  111. Circle = 4,
  112. Ellipse = 5,
  113. Polygon = 6,
  114. Hatch = 32,
  115. };
  116. struct ObjCommon {
  117. u32 num_fields; // Number of fields in this struct (17)
  118. Field pen;
  119. Field type; // Seems to always be same value as object type
  120. FieldOf<ObjectFlags>;
  121. String name;
  122. Field count;
  123. Field unknown_2[1];
  124. Field io_control_enable_mask;
  125. Field io_control_disable_mask;
  126. Field unknown_3[5];
  127. FieldOf<Point> origin;
  128. Field z;
  129. Field a;
  130. Field unknown_4[1];
  131. };
  132. enum LineType : u16 {
  133. Point = 0x0001,
  134. Line = 0x0100,
  135. Bezier = 0x0300,
  136. };
  137. struct LineEntry {
  138. LineType type;
  139. u32; // Zeros
  140. match (type) {
  141. (LineType::Point): Point;
  142. (LineType::Line): {
  143. u32 count;
  144. Point points[count];
  145. }
  146. (LineType::Bezier): {
  147. u32 count;
  148. Point points[count];
  149. }
  150. (_): std::error(std::format("Unknown line type: 0x{:02X} at 0x{:02X}", u32(type), $));
  151. }
  152. };
  153. struct LineSet : ObjCommon {
  154. u32 count;
  155. u32; // Zeros
  156. LineEntry entries[count];
  157. };
  158. struct ClosedSet : ObjCommon {
  159. u32 count;
  160. Field entries[count];
  161. };
  162. struct Rectangle : ObjCommon {
  163. u32 num_fields; // Number of fields in this struct (8)
  164. FieldOf<Point> corner_a;
  165. FieldOf<Point> corner_b;
  166. Field round_bottom_left;
  167. Field round_bottom_right;
  168. Field round_top_right;
  169. Field round_top_left;
  170. Field unknown[2];
  171. };
  172. struct Circle : ObjCommon {
  173. u32 num_fields; // Number of fields in this struct (6)
  174. FieldOf<Point> origin;
  175. Field radius;
  176. Field start_angle; // Radians
  177. Field clockwise;
  178. Field unknown[2];
  179. };
  180. struct Ellipse : ObjCommon {
  181. u32 num_fields; // Number of fields in this struct (8)
  182. Field clockwise;
  183. FieldOf<Point> corner_a;
  184. FieldOf<Point> corner_b;
  185. Field start_angle; // Radians
  186. Field end_angle; // Radians
  187. Field unknown[2];
  188. Field open_curve;
  189. };
  190. struct Polygon : ObjCommon {
  191. u32 num_fields; // Number of fields in this struct (10)
  192. Field invert_shape;
  193. FieldOf<Point> corner_a;
  194. FieldOf<Point> corner_b;
  195. Field offset_cx; // Moves (intial) sharper corner
  196. Field offset_cy; // Moves (initial)sharper corner
  197. Field offset_dx;
  198. Field offset_dy;
  199. Field edges;
  200. Field unknown_3[2];
  201. };
  202. struct HatchLine {
  203. u32 num_lines;
  204. LineSet line[num_lines];
  205. };
  206. using Object;
  207. bitfield HatchFlags {
  208. padding : 1;
  209. follow_edge_once : 1;
  210. padding : 4;
  211. auto_rotate_hatch_angle : 1;
  212. average_distribut_line : 1;
  213. padding : 2;
  214. cross_hatch : 1;
  215. padding : 21;
  216. };
  217. struct HatchSettings {
  218. u32 num_fields; // 46
  219. Field flags; // 1 = mark contour
  220. Field unknown_1[1];
  221. Field pen;
  222. FieldOf<HatchFlags> flags_2;
  223. Field edge_offset;
  224. Field line_spacing;
  225. Field start_offset;
  226. Field end_offset;
  227. Field angle;
  228. Field unknown_4[9];
  229. Field auto_rotate_angle;
  230. Field unknown_7[10];
  231. Field line_reduction;
  232. Field unknown_3[2];
  233. Field num_loops;
  234. Field unknown_5[2];
  235. Field loop_distance;
  236. Field unknown_6[5];
  237. Field contour_first;
  238. Field count;
  239. Field unknown_2[3];
  240. };
  241. struct HatchSettings2 {
  242. u32 num_fields; // 15
  243. Field count;
  244. Field unknown_1[1];
  245. Field pen;
  246. FieldOf<HatchFlags> flags_2; // Same as HatchSettings.flags_2
  247. Field edge_offset;
  248. Field line_spacing;
  249. Field start_offset;
  250. Field end_offset;
  251. Field angle;
  252. Field auto_rotate_angle;
  253. Field line_reduction;
  254. Field loop_distance;
  255. Field num_loops;
  256. Field unknown_5[2];
  257. };
  258. struct Hatch : ObjCommon {
  259. u32; // 1
  260. Object outline;
  261. HatchSettings settings;
  262. HatchSettings2 settings_2;
  263. u32 count_5; //17
  264. Field unknown_5[count_5];
  265. u32; // 1
  266. u32; // 16
  267. u32 count_6; // 17
  268. Field pen;
  269. Field unknown_6[2];
  270. String hatch_name;
  271. Field unknown_7[count_6 - 4];
  272. //Field unknown_6[count_6];
  273. u32 num_lines;
  274. HatchLine lines[num_lines];
  275. };
  276. struct Object {
  277. ObjectType type;
  278. match (type) {
  279. (ObjectType::Curve): LineSet;
  280. (ObjectType::Point): LineSet;
  281. (ObjectType::Rectangle): Rectangle;
  282. (ObjectType::Circle): Circle;
  283. (ObjectType::Ellipse): Ellipse;
  284. (ObjectType::Polygon): Polygon;
  285. (ObjectType::Hatch): Hatch;
  286. (_): std::error(std::format("Unknown object type: 0x{:02X} at 0x{:02X}", u32(type), $));
  287. }
  288. };
  289. struct Layer {
  290. u32 num_fields_1; // Number of fields before object list (17)
  291. Field unknown_1[3];
  292. String name;
  293. Field count;
  294. Field unknown_2[1];
  295. Field input_signal_wait_enable_mask;
  296. Field input_signal_wait_disable_mask;
  297. Field unknown_3[9];
  298. u32 object_count;
  299. Object objects[object_count];
  300. u32 num_fields_2; // Number of fields to footer (151)
  301. Field unknown_4[54];
  302. Field output_signal_start_enable_mask;
  303. Field output_signal_start_disable_mask;
  304. Field output_signal_end_enable_mask;
  305. Field output_signal_end_disable_mask;
  306. Field unknown_5[9];
  307. Field fixture_offset;
  308. Field unknown_6[64];
  309. Field output_signal_start_delay;
  310. Field output_signal_end_delay;
  311. Field input_signal_wait_enable;
  312. Field unknown_7[2];
  313. Field output_signal_start_pulse;
  314. Field output_signal_end_pulse;
  315. Field unknown_8[12];
  316. u32 footer;
  317. };
  318. struct Layers {
  319. u32 count;
  320. Layer layer[count];
  321. };
  322. struct File {
  323. Header header;
  324. RGBA8 thumbnail[40000]; // 200x200?
  325. padding[16];
  326. Pen pens[256];
  327. Layers;
  328. };
  329. File file @ 0x0;