123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- #pragma endian little
- #pragma pattern_limit 512000
- #include <std/sys.pat>
- #include <std/mem.pat>
- #include <std/io.pat>
- #include <std/core.pat>
- struct RGBA8 {
- u8 red;
- u8 green;
- u8 blue;
- u8 alpha;
- } [[static, color(std::format("{:02X}{:02X}{:02X}", red, green, blue))]];
- struct Point {
- double x;
- double y;
- };
- struct MultiLine {
- u32 points;
- Point point[points];
- };
- enum WobbleType : u32 {
- Spiral = 0,
- Sinusoidal = 1,
- Ellipse = 2,
- Vert_8 = 3,
- Hoti_8 = 4,
- };
- // Field of a custom defined type
- struct FieldOf<T> {
- u32 length;
- T value;
-
- if (length != sizeof(value)) {
- std::error(std::format("Field size mismatch at 0x{:02X}", $));
- }
- } [[sealed, format("format_field_of")]];
- fn format_field_of(FieldOf<u8> f) {
- return f.value;
- };
- // Field of generic types
- struct Field {
- u32 length;
-
- match (length) {
- (4): u32 value;
- (8): double value;
- (2): u16 value; // ??
- (16): Point value; // ??
- (_): {
- std::warning(std::format("Unknown length tag: {} at 0x{:02X}", length, $));
- u8 value[length];
- }
- }
- } [[sealed, format("format_field")]];
- fn format_field(Field f) {
- return f.value;
- };
- // Variable length field of a fixed type.
- struct String {
- u32 length;
- char16 value[length / sizeof(char16)];
- } [[sealed, format("format_string")]];
- fn format_string(String s) {
- return s.value;
- };
- struct Header {
- char16 magic[0x8];
- u8 unknown[0x338];
- };
- struct Pen {
- u32 num_fields; // Number of fields in this struct (236)
- Field color;
- String name;
- Field disabled;
- Field use_default_param;
- Field loop_count;
- Field speed; // Changes with wobble relative speed
- Field power;
- Field frequency;
- Field unknown_1[1];
- Field start_tc;
- Field end_tc;
- Field polygon_tc;
- Field jump_speed;
- Field unknown_2[10];
- Field laser_off_tc;
- Field wave; // Only available if continue_mode is false
- Field unknown_3[1];
- Field wobble_enable;
- Field wobble_diameter;
- Field wobble_distance;
- Field unknown_4[8];
- Field min_jump_tc;
- Field max_jump_tc;
- Field jump_limit;
- Field unknown_5[2];
- Field frequency2;
- Field unknown_6[152];
- FieldOf<WobbleType> wobble_type;
- Field continue_mode;
- Field unknown_7[12];
- Field wobble_diameter2; // Only with wobble type ellipse
- Field unknown_8[26];
- };
- bitfield ObjectFlags {
- disabled : 1;
- aspect_ratio_unlocked : 1; // ??
- padding : 14;
- };
- enum ObjectType: u16 {
- Curve = 1,
- Point = 2,
- Rectangle = 3,
- Circle = 4,
- Ellipse = 5,
- Polygon = 6,
- HatchLine = 16,
- Hatch = 32,
- };
- struct ObjCommon {
- u32 num_fields; // Number of fields in this struct (17)
- Field pen;
- //Field type; // Seems to always be same value as object type
- FieldOf<ObjectType>;
- FieldOf<ObjectFlags>;
- String name;
- Field count;
- Field unknown_2;
- Field io_control_enable_mask;
- Field io_control_disable_mask;
- Field unknown_3[5];
- FieldOf<Point> origin;
- Field z;
- Field a;
- Field index; // Increments for each hatch line, -1 for certain hatch patterns
- if (index.value != 0) {
- std::warning(std::format("Unexpected unknown value {} at 0x{:02X}", index.value, $));
- }
- };
- enum LineType : u16 {
- Point = 0x0001,
- Line = 0x0100,
- Bezier = 0x0300,
- };
- struct LineEntry {
- LineType type;
- u32; // Zeros
-
- match (type) {
- (LineType::Point): Point;
- (LineType::Line): {
- u32 count;
- Point points[count];
- }
- (LineType::Bezier): {
- u32 count;
- Point points[count];
- }
- (_): std::error(std::format("Unknown line type: 0x{:02X} at 0x{:02X}", u32(type), $));
- }
- };
- struct LineSet : ObjCommon {
- u32 count;
- u32; // Zeros
-
- LineEntry entries[count];
- };
- struct ClosedSet : ObjCommon {
- u32 count;
- Field entries[count];
- };
- struct Rectangle : ObjCommon {
- u32 num_fields; // Number of fields in this struct (8)
- FieldOf<Point> corner_a;
- FieldOf<Point> corner_b;
- Field round_bottom_left;
- Field round_bottom_right;
- Field round_top_right;
- Field round_top_left;
- Field unknown;
- u32 length;
- u8 bytes[length];
- };
- struct Circle : ObjCommon {
- u32 num_fields; // Number of fields in this struct (6)
- FieldOf<Point> origin;
- Field radius;
- Field start_angle; // Radians
- Field clockwise;
- Field unknown[2];
- };
- struct Ellipse : ObjCommon {
- u32 num_fields; // Number of fields in this struct (8)
- Field clockwise;
- FieldOf<Point> corner_a;
- FieldOf<Point> corner_b;
- Field start_angle; // Radians
- Field end_angle; // Radians
- Field unknown[2];
- Field open_curve;
- };
- struct Polygon : ObjCommon {
- u32 num_fields; // Number of fields in this struct (10)
- Field invert_shape;
- FieldOf<Point> corner_a;
- FieldOf<Point> corner_b;
- Field offset_cx; // Moves (intial) sharper corner
- Field offset_cy; // Moves (initial)sharper corner
- Field offset_dx;
- Field offset_dy;
- Field edges;
- Field unknown_3[2];
- };
- struct HatchLine {
- u32 num_lines;
- LineSet line[num_lines];
- };
- using Object;
- bitfield HatchFlags {
- all_calc : 1; // Will always be set when background_pattern is set
- follow_edge_once : 1;
- continuous_pattern : 1; // Hatch type 4 when combined with bidirectional_pattern
- bidirectional_pattern : 1; // Hatch type 2
- ring_pattern : 1; // Hatch type 3
- padding : 1;
- auto_rotate_hatch_angle : 1;
- average_distribut_line : 1;
- padding : 1;
- gong_pattern : 1; // Hatch type 5 when combined with bidirectional_pattern
- cross_hatch : 1;
- background_pattern: 1; // Hatch type 6 (TODO, missing parsing)
- fill_pattern : 1; // Hatch type 7 when combined with continuous_pattern and bidirectional_pattern
- zigzag_pattern : 1; // Hatch type 8
- padding : 18;
- };
- // TODO: hatch types 1/2 will set last field of ObjCommon in HatchLines to 1
- // TODO: hatch types 3/4/5/7/8 will set last field of ObjCommon in HatchLines to -1 (0xFFFFFFFF)
- struct HatchSettings {
- u32 num_fields; // 46
- Field mark_contour;
- Field hatch_1_enable;
- Field hatch_1_pen;
- FieldOf<HatchFlags> hatch_1_flags;
- Field hatch_1_edge_offset;
- Field hatch_1_line_spacing;
- Field hatch_1_start_offset;
- Field hatch_1_end_offset;
- Field hatch_1_angle;
- Field hatch_2_enable;
- Field hatch_2_pen;
- FieldOf<HatchFlags> hatch_2_flags;
- Field hatch_2_edge_offset;
- Field hatch_2_line_space;
- Field hatch_2_start_offset;
- Field hatch_2_end_offset;
- Field hatch_2_angle;
- Field any_hatch_enabled;
- Field hatch_1_auto_rotate_angle;
- Field hatch_2_auto_rotate_angle;
- Field hatch_3_enable;
- Field hatch_3_pen;
- FieldOf<HatchFlags> hatch_3_flags;
- Field hatch_3_edge_offset;
- Field hatch_3_line_space;
- Field hatch_3_start_offset;
- Field hatch_3_end_offset;
- Field hatch_3_angle;
- Field hatch_3_auto_rotate_angle;
- Field hatch_1_line_reduction;
- Field hatch_2_line_reduction;
- Field hatch_3_line_reduction;
- Field hatch_1_num_loops;
- Field hatch_2_num_loops;
- Field hatch_3_num_loops;
- Field hatch_1_loop_distance;
- Field hatch_2_loop_distance;
- Field hatch_3_loop_distance;
- Field unknown_1[3];
- Field contour_priority;
- Field hatch_1_count;
- Field hatch_2_count;
- Field hatch_3_count;
- };
- struct HatchSettings2 {
- u32 num_fields; // 15
- Field count;
- Field enabled;
- Field pen;
- FieldOf<HatchFlags> flags;
- Field edge_offset;
- Field line_spacing;
- Field start_offset;
- Field end_offset;
- Field angle;
- Field auto_rotate_angle;
- Field line_reduction;
- Field loop_distance;
- Field num_loops;
- Field unknown_1; // Mirror unknown_1 in settings
- Field unknown_2;
- };
- struct HatchLines {
- u32; // 16 (tag?)
- ObjCommon;
- u32 num_lines;
- HatchLine lines2[num_lines];
- };
- struct Hatch : ObjCommon {
- u32 num_outlines;
- Object outline[num_outlines];
- HatchSettings settings;
- Field num_settings;
- HatchSettings2 settings_2[num_settings.value];
-
- // Following fields are not defined if hatch is disabled
- if (settings.any_hatch_enabled.value == 1) {
- ObjCommon;
- u32 num_hatches;
- HatchLines hatches[num_hatches];
- }
- };
- struct Object {
- ObjectType type;
- u16; // zero
-
- match (type) {
- (ObjectType::Curve): LineSet;
- (ObjectType::Point): LineSet;
- (ObjectType::Rectangle): Rectangle;
- (ObjectType::Circle): Circle;
- (ObjectType::Ellipse): Ellipse;
- (ObjectType::Polygon): Polygon;
- (ObjectType::Hatch): Hatch;
- (_): std::error(std::format("Unknown object type: 0x{:02X} at 0x{:02X}", u32(type), $));
- }
- };
- struct Layer {
- u32 num_fields_1; // Number of fields before object list (17)
- Field unknown_1[3];
- String name;
- Field count;
- Field unknown_2[1];
- Field input_signal_wait_enable_mask;
- Field input_signal_wait_disable_mask;
- Field unknown_3[9];
- u32 object_count;
- Object objects[object_count];
- u32 num_fields_2; // Number of fields to footer (151)
- Field unknown_4[54];
- Field output_signal_start_enable_mask;
- Field output_signal_start_disable_mask;
- Field output_signal_end_enable_mask;
- Field output_signal_end_disable_mask;
- Field unknown_5[9];
- Field fixture_offset;
- Field unknown_6[64];
- Field output_signal_start_delay;
- Field output_signal_end_delay;
- Field input_signal_wait_enable;
- Field unknown_7[2];
- Field output_signal_start_pulse;
- Field output_signal_end_pulse;
- Field unknown_8[12];
- u32 footer;
- };
- struct Layers {
- u32 count;
- Layer layer[count];
- };
- struct File {
- Header header;
- RGBA8 thumbnail[40000]; // 200x200?
- padding[16];
- Pen pens[256];
- Layers;
- };
- File file @ 0x0;
|