Exemplo n.º 1
0
    def write(self, stream, resources=None):
        s = StreamWriter(stream)
        s.u32(self.version)

        tgi = resources
        use_tgi = not isinstance(tgi, TGIList)
        if use_tgi:
            tgi = TGIList(order='IGT', use_length=False, package=resources, count_size=8)
            tgi.begin_write(self, stream)
        if self.version >= 7:
            s.i8(len(self.fabrics))
            for fabric in self.fabrics:
                s.i8(tgi.get_resource_index(fabric))
                fabric_len = 0
                with BytesIO() as fabric_stream:
                    fabric.write(fabric_stream, tgi)
                    s.u32(fabric_stream.tell())
                    fabric_stream.seek(0, SEEK_SET)
                    stream.write(fabric_stream.read(-1))
            s.u32(self.target_size)
            s.u32(self.part_type)
            s.u8(0)
            s.i32(len(self.steps))
            if self.version >= 0x08:
                s.u8(0)
            for step in self.steps:
                self.write_step(stream, tgi, step)
        if use_tgi:
            tgi.end_read(stream)
        else:
            s.u32(0)
Exemplo n.º 2
0
    def write(self, stream, resources=None):
        s = StreamWriter(stream)
        s.u32(self.version)

        tgi = resources
        use_tgi = not isinstance(tgi, TGIList)
        if use_tgi:
            tgi = TGIList(order='IGT',
                          use_length=False,
                          package=resources,
                          count_size=8)
            tgi.begin_write(self, stream)
        if self.version >= 7:
            s.i8(len(self.fabrics))
            for fabric in self.fabrics:
                s.i8(tgi.get_resource_index(fabric))
                fabric_len = 0
                with BytesIO() as fabric_stream:
                    fabric.write(fabric_stream, tgi)
                    s.u32(fabric_stream.tell())
                    fabric_stream.seek(0, SEEK_SET)
                    stream.write(fabric_stream.read(-1))
            s.u32(self.target_size)
            s.u32(self.part_type)
            s.u8(0)
            s.i32(len(self.steps))
            if self.version >= 0x08:
                s.u8(0)
            for step in self.steps:
                self.write_step(stream, tgi, step)
        if use_tgi:
            tgi.end_read(stream)
        else:
            s.u32(0)
Exemplo n.º 3
0
 def write_rcol(self, stream, rcol):
     s = StreamWriter(stream)
     self.write_tag(stream)
     s.u32(self.version)
     cFootprints = len(self.footprint_polygons)
     s.i8(cFootprints)
     for footprint_index in range(cFootprints): self.footprint_polygons[footprint_index].write(stream)
     cSlots = len(self.routing_slot_footprint_polygons)
     s.i8(cSlots)
     for slot_index in range(cSlots): self.routing_slot_footprint_polygons[slot_index].write(stream)
Exemplo n.º 4
0
 def write_rcol(self, stream, rcol):
     s = StreamWriter(stream)
     self.write_tag(stream)
     s.u32(self.version)
     cFootprints = len(self.footprint_polygons)
     s.i8(cFootprints)
     for footprint_index in range(cFootprints): self.footprint_polygons[footprint_index].write_rcol(stream)
     cSlots = len(self.routing_slot_footprint_polygons)
     s.i8(cSlots)
     for slot_index in range(cSlots): self.routing_slot_footprint_polygons[slot_index].write_rcol(stream)
Exemplo n.º 5
0
 def write_presets(cls, stream,presets, resources):
     s = StreamWriter(stream)
     s.i32(len(presets))
     ce = ComplateEncoder()
     for preset in presets:
         assert isinstance(preset,cls.BuildBuyPreset)
         s.i8(preset.unk1)
         if preset.unk1 != 1:
             s.i32(preset.unk2)
         preset_ptr = StreamPtr.begin_write(s)
         ce.serialize(preset.complate,stream,resources)
         preset_ptr.end()
         s.u32(preset.id)
Exemplo n.º 6
0
    def write(self, stream, resources=None):
        s = StreamWriter(stream)
        s.u32(self.version)
        tgi = TGIList()
        tgi.begin_write(stream)
        if self.version >= 0x00000007:
            ProductBase.write_presets(stream,self.presets,tgi)
        self.product_info.write(stream,tgi)

        s.i32(tgi.get_resource_index(self.model))
        s.i32(tgi.get_resource_index(self.diagonal_model))
        s.i32(tgi.get_resource_index(self.post_model))
        s.i32(self.post_tile_spacing)
        s.i8(1 if self.can_walk_over else 0)

        if self.version >= 0x00000008:
            if self.version >= 0x0000000A:
                s.i8(1 if self.should_not_get_thick_snow else 0)
                s.i8(1 if self.snow_post_shape_is_circle else 0)
                s.f32(self.snow_thickness_post_scale_factor)
                s.f32(self.snow_thickness_rail_scale_factor)
                s.f32(self.snow_thickness_post_vertical_offset)
                s.f32(self.snow_thickness_rail_vertical_offset)
                s.i8(1 if self.has_wall else 0)
            if self.version < 0x0000000A or self.has_wall:
                s.i8(1 if self.raise_fence_geometry_above_wall else 0)
                s.i32(tgi.get_resource_index(self.wall))
        tgi.end_write(stream)
Exemplo n.º 7
0
 def write(self, stream, resource=None):
     s = StreamWriter(stream)
     self.bounds.clear()
     s.hash(self.name)
     s.i8(self.priority)
     s.u32(self.footprint_type_flags)
     s.i32(len(self.points))
     for point in self.points:
         self.bounds.add(point)
         s.f32(point[0])
         s.f32(point[1])
     s.u32(self.allow_intersection_flags)
     s.u32(self.surface_type_flags)
     s.u32(self.surface_attribute_flags)
     s.i8(self.level_offset)
     if self.ftpt.version >= Footprint.VERSION.EXTENDED: s.f32(self.elevation_offset)
     self.bounds.write(stream)
Exemplo n.º 8
0
    def write(self, stream, resources=None):
        s = StreamWriter(stream)
        s.u32(self.version)
        tgi = TGIList()
        tgi.begin_write(stream)
        self.product_info.write(stream,tgi)

        s.i8(self.fireplace_width)
        s.i32(tgi.get_resource_index(self.mantle))
        s.i32(tgi.get_resource_index(self.chimney_mantle))
        s.i32(tgi.get_resource_index(self.chimney_full_level))
        s.i32(tgi.get_resource_index(self.chimney_ground_level))
        s.i32(tgi.get_resource_index(self.chimney_body))
        s.i32(tgi.get_resource_index(self.chimney_top))
        s.i32(tgi.get_resource_index(self.chimney_cap))

        tgi.end_write(stream)
Exemplo n.º 9
0
 def write(self, stream, resource=None):
     s = StreamWriter(stream)
     self.bounds.clear()
     s.hash(self.name)
     s.i8(self.priority)
     s.u32(self.footprint_type_flags)
     s.i32(len(self.points))
     for point in self.points:
         self.bounds.add(point)
         s.f32(point[0])
         s.f32(point[1])
     s.u32(self.allow_intersection_flags)
     s.u32(self.surface_type_flags)
     s.u32(self.surface_attribute_flags)
     s.i8(self.level_offset)
     if self.ftpt.version >= Footprint.VERSION.EXTENDED: s.f32(self.elevation_offset)
     self.bounds.write(stream)
Exemplo n.º 10
0
 def write_rcol(self, stream, rcol):
     s = StreamWriter(stream)
     self.write_tag(stream)
     s.u32(self.version)
     tgi = TGIList(32, 'TGI')
     tgi.begin_write(stream)
     s.hash(self.shader)
     if self.shader:
         self.material.write(stream, tgi)
     s.u32(self.merge_group)
     s.u32(self.sort_order)
     s.u32(len(self.vertices))
     self.vertex_format.from_vertex(self.vertices[0])
     self.vertex_format.write(stream)
     for vertex in self.vertices:
         uv_index = 0
         for declaration in self.vertex_format.declarations:
             if declaration.usage == self.VertexFormat.Declaration.USAGE.POSITION:
                 for i in range(3):
                     s.f32(vertex.position)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.NORMAL:
                 for i in range(3):
                     s.f32(vertex.normal)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.UV:
                 for i in range(2):
                     s.f32(vertex.uv[uv_index])
                 uv_index += 1
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_INDEX:
                 for i in range(4):
                     s.i8(vertex.blend_indices)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_WEIGHT:
                 for i in range(4):
                     s.f32(vertex.blend_weights)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.TANGENT:
                 for i in range(3):
                     s.f32(vertex.tangents)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.COLOUR:
                 for i in range(4):
                     s.i8(vertex.colour)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.ID:
                 s.u32(vertex.id)
     s.u32(tgi.get_resource_index(self.skin_controller))
     s.u32(len(self.bones))
     for bone in self.bones:
         s.u32(bone)
Exemplo n.º 11
0
    def write(self, stream, resources=None):
        s = StreamWriter(stream)
        s.u32(self.version)
        tgi = TGIList(package=resources)
        tgi.begin_write(stream)
        s.i8(len(self.components))
        for component in self.components:
            s.hash(component)

        def write_component_data(data):
            s.i8(data[0])
            val = data[1]
            if isinstance(val, str):
                s.p32(val)
            elif isinstance(val, Resource):
                s.i32(tgi.get_resource_index(val))
            elif isinstance(val, int):
                s.u32(val)
            else:
                raise Exception("Unable to handle data type %" % type(val))

        k = self.component_data.keys()
        s.i8(len(k))
        for key in k:
            s.p32(key)
            write_component_data(self.component_data[key])
        s.i8(self.visible)
        tgi.end_write(stream)
Exemplo n.º 12
0
 def write_rcol(self, stream, rcol):
     s = StreamWriter(stream)
     self.write_tag(stream)
     s.u32(self.version)
     tgi = TGIList(32, 'TGI')
     tgi.begin_write(stream)
     s.hash(self.shader)
     if self.shader:
         self.material.write(stream, tgi)
     s.u32(self.merge_group)
     s.u32(self.sort_order)
     s.u32(len(self.vertices))
     self.vertex_format.from_vertex(self.vertices[0])
     self.vertex_format.write(stream)
     for vertex in self.vertices:
         uv_index = 0
         for declaration in self.vertex_format.declarations:
             if declaration.usage == self.VertexFormat.Declaration.USAGE.POSITION:
                 for i in range(3): s.f32(vertex.position)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.NORMAL:
                 for i in range(3): s.f32(vertex.normal)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.UV:
                 for i in range(2): s.f32(vertex.uv[uv_index])
                 uv_index += 1
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_INDEX:
                 for i in range(4): s.i8(vertex.blend_indices)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_WEIGHT:
                 for i in range(4): s.f32(vertex.blend_weights)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.TANGENT:
                 for i in range(3): s.f32(vertex.tangents)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.COLOUR:
                 for i in range(4): s.i8(vertex.colour)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.ID:
                 s.u32(vertex.id)
     s.u32(tgi.get_resource_index(self.skin_controller))
     s.u32(len(self.bones))
     for bone in self.bones: s.u32(bone)
Exemplo n.º 13
0
    def write_property(self, stream, key, value, tgi):
        s = StreamWriter(stream)
        s.u32(key)
        if value is None:
            s.i8(1)
            return
        else:
            s.i8(0)
            if isinstance(value, bool):
                s.i8(0)
                s.u8(value)

        pass
Exemplo n.º 14
0
    def write_property(self, stream, key, value, tgi):
        s = StreamWriter(stream)
        s.u32(key)
        if value is None:
            s.i8(1)
            return
        else:
            s.i8(0)
            if isinstance(value, bool):
                s.i8(0)
                s.u8(value)

        pass
Exemplo n.º 15
0
 def write(self, stream, resource=None):
     s = StreamWriter(stream)
     s.u32(self.version)
     tgi = TGIList('igt', 8, False)
     tgi.begin_write(stream)
     for preset in self.presets: preset.write(stream)
     s.s7(self.part_name, 16, '>')
     s.f32(self.display_index)
     s.u8(self.has_unique_texture_space)
     s.u32(self.body_type)
     s.u32(self.part_flags)
     s.u32(self.age_gender_flags)
     s.u32(self.clothing_category)
     s.i8(tgi.get_resource_index(self.naked_cas_part))
     s.i8(tgi.get_resource_index(self.base_cas_part))
     s.i8(tgi.get_resource_index(self.blend_fat))
     s.i8(tgi.get_resource_index(self.blend_fit))
     s.i8(tgi.get_resource_index(self.blend_thin))
     s.i8(tgi.get_resource_index(self.blend_special))
     s.u32(self.draw_layer)
     s.i8(len(self.sources))
     for source in self.sources: s.i8(tgi.get_resource_index(source))
     s.i8(len(self.lod_infos))
     for lod_info in self.lod_infos: lod_info.write(stream)
     s.i8(len(self.diffuse_refs))
     for diffuse_ref in self.diffuse_refs: s.i8(tgi.get_resource_index(diffuse_ref))
     s.i8(len(self.specular_refs))
     for specular_ref in self.specular_refs: s.i8(tgi.get_resource_index(specular_ref))
     s.u8(len(self.secondary_diffuse_refs))
     for block in self.secondary_diffuse_refs: s.u8(tgi.get_resource_index(block))
     s.u8(len(self.secondary_specular_refs))
     for block in self.secondary_specular_refs: s.u8(tgi.get_resource_index(block))
     s.u8(len(self.slot_poses))
     for block in self.slot_poses: s.u8(tgi.get_resource_index(block))
     s.s7(self.shoe_material, 16, '>')
     tgi.end_write(stream)
Exemplo n.º 16
0
 def write(self, stream, resources=None):
     s = StreamWriter(stream)
     s.u32(self.version)
     tgi = TGIList()
     tgi.begin_write(stream)
     ProductBase.write_presets(stream,self.presets,tgi)
     if self.version >= 0x00000016:
         s.s7(self.instance_name,size=16,order='>')
     self.product_info.write(stream,tgi)
     s.i32(tgi.get_resource(self.object_component))
     s.u32(self.object_type_flags)
     if self.version >= 0x000001A:
         s.u32(self.object_type_flags_2)
     s.u32(self.wall_placement_flags)
     s.u32(self.movement_flags)
     s.i32(self.num_wall_cutout_tiles_per_level)
     s.i32(self.num_levels)
     s.i8(len(self.wall_masks))
     for wall_mask in self.wall_masks:
         wall_mask.write(stream,tgi)
     s.i8(1 if self.script_enabled else 0)
     s.i32(tgi.get_resource_index(self.diagonal_object))
     s.hash(self.ambiance_type)
     s.u32(self.room_flags)
     s.u32(self.function_category_flags)
     s.u64(self.sub_category_flags)
     if self.version >= 0x0000001C:
         s.u64(self.sub_category_flags_2)
     s.u64(self.sub_room_flags)
     s.u32(self.build_category_flags)
     s.i32(tgi.get_resource_index(self.wall_cutout_texture))
     if self.version >= 0x00000017:
         s.i32(tgi.get_resource_index(self.floor_cutout_texture))
         s.i32(self.floor_cutout_level_offset)
         s.f32(self.floor_cutout_bounds_length )
     if self.version >= 0x00000020:
         s.f32(self.floor_cutout_bounds_width )
     if self.version >= 0x0000021:
         s.f32(self.floor_cutout_offset_x )
         s.f32(self.floor_cutout_offset_z )
     if self.version >= 0x00000018:
         s.i32(len(self.shell_states))
         for shell_state in self.shell_states: s.hash(shell_state)
     if self.version >= 0x00000019:
         s.i32(tgi.get_resource_index(self.shell_level_below ))
     if self.version >= 0x0000001B:
         s.i32(tgi.get_resource_index(self.shell_proxy ))
     if self.version >= 0x0000001D:
         s.i32(tgi.get_resource_index(self.blueprint_xml ))
     if self.version >= 0x0000001E:
         s.i32(tgi.get_resource_index(self.blueprint_icon ))
     if self.version >= 0x0000001F:
         s.f32(self.blueprint_icon_offset_min_x)
         s.f32(self.blueprint_icon_offset_min_z)
         s.f32(self.blueprint_icon_offset_max_x)
         s.f32(self.blueprint_icon_offset_max_z)
     s.u32(self.slot_placement_flags)
     s.s7(self.surface_type,size=16,order='>')
     s.s7(self.source_material,size=16,order='>')
     s.u32(self.moodlet_given)
     s.u32(self.moodlet_score)
     s.u32(5)
     for rating in self.ratings: rating.write(stream)
     s.i32(tgi.get_resource_index(self.fallback))
     if self.version >= 0x00000022:
         s.i32(tgi.get_resource_index(self.modular_arch_end_east_model))
         s.i32(tgi.get_resource_index(self.modular_arch_end_east_model))
         s.i32(tgi.get_resource_index(self.modular_arch_connecting_model))
         s.i32(tgi.get_resource_index(self.modular_arch_single_model))
     tgi.end_write(stream)