Beispiel #1
0
def get_texture_sprite_tags(lm_data, image_2_id, shape_2_id, image_dict):
    global prefix_for_noname

    data = lm_data[0x40:]
    symbol_list = rip_gim.get_symbol_list(data)
    img_fname_list = [symbol for symbol in symbol_list if symbol.endswith(".png")]
    define_sprite_tags = []
    ori_pic_list = rip_gim.list_tagF007_symbol(lm_data, prefix_for_noname)
    while True:
        tag_type, tag_size = struct.unpack("<HH", data[:0x4])
        if tag_type == 0xFF00:
            break
        if tag_type == 0xF022:
            sprite_id, = struct.unpack("<I", data[0x4:0x8])
            img_cnt, = struct.unpack("<H", data[0xA:0xC])
            place_object2_tags = []
            for i in xrange(img_cnt):  # handle each F023 tag
                data = rip_gim.seek_next_tag(data)
                img_fname_idx, flag = struct.unpack("<HH", data[0x44:0x48])

                # calculate upper left corner of the shape
                # in current texture sprite
                all_floats = struct.unpack("<" + "f" * 16, data[0x4 : 0x4 + 0x4 * 16])
                xs = all_floats[::4]
                ys = all_floats[1::4]
                xmin, xmax = min(xs), max(xs)
                ymin, ymax = min(ys), max(ys)

                if flag == 0x00:  # solid fill
                    matrix = swf_helper.pack_matrix(None, None, (xmin, ymin))
                    shape_id = shape_2_id[(sprite_id << 16) + i]
                else:  # clipped bitmap fill or repeating bitmap fill
                    assert flag in (0x40, 0x41), "not supported (fill type) atm! %d" % flag
                    img_fname = symbol_list[ori_pic_list[img_fname_idx][1]]
                    shape_id = image_2_id[img_fname]
                    matrix = swf_helper.pack_matrix(None, None, (xmin, ymin))

                place_object2_tag = swf_helper.make_place_object2_tag(
                    swf_helper.PLACE_FLAG_HAS_CHARACTER | swf_helper.PLACE_FLAG_HAS_MATRIX,
                    i + 1,
                    id=shape_id,
                    matrix=matrix,
                )
                place_object2_tags.append(place_object2_tag)
            show_frame_tag = swf_helper.make_show_frame_tag()

            control_tags = []
            control_tags.extend(place_object2_tags)
            control_tags.append(show_frame_tag)
            control_tags.append(swf_helper.make_end_tag())
            define_sprite_tag = swf_helper.make_define_sprite_tag(sprite_id, 1, control_tags)
            define_sprite_tags.append(define_sprite_tag)
        else:
            data = rip_gim.seek_next_tag(data)
    return define_sprite_tags
Beispiel #2
0
def make_tex_sprite(ctx, d, subds):
	sprite_id = d["character_id"]
	sub_tags = []

	for i, subd in enumerate(subds):
		shape_tag, shape_id = _make_shape(ctx, subd)
		xmin = min(subd["x0"], subd["x1"], subd["x2"], subd["x3"])
		ymin = min(subd["y0"], subd["y1"], subd["y2"], subd["y3"])
		matrix = swf_helper.pack_matrix(None, None, (xmin, ymin))
		place_obj2_tag = swf_helper.make_place_object2_tag(swf_helper.PLACE_FLAG_HAS_CHARACTER | swf_helper.PLACE_FLAG_HAS_MATRIX, i+1, id=shape_id, matrix=matrix)
		sub_tags.append(place_obj2_tag)
		ctx.setdefault("shape_tags", []).append(shape_tag)
	show_frame_tag = swf_helper.make_show_frame_tag()
	sub_tags.append(show_frame_tag)
	sub_tags.append(swf_helper.make_end_tag())
	
	return swf_helper.make_define_sprite_tag(sprite_id, 1, sub_tags)
Beispiel #3
0
def get_define_sprite_tags(lm_data, action_constant_pool, action_record_list):
    # some tables for referrence
    color_list = rip_gim.list_tagF002_symbol(lm_data)
    point_list = rip_gim.list_tagF103_symbol(lm_data)
    matrix_list = rip_gim.list_tagF003_symbol(lm_data)
    symbol_list = rip_gim.get_symbol_list(lm_data[0x40:])
    define_sprite_tags = []

    data = lm_data[0x40:]
    data = rip_gim.seek_next_tag(data, (0x0027,))
    while True:
        # 		print len(data[:0x4])
        tag_type, tag_size = struct.unpack("<HH", data[:0x4])
        if tag_type == 0xFF00:
            break
        if tag_type == 0x0027:

            control_tags = []
            sprite_id, = struct.unpack("<H", data[0x4:0x6])
            frame_count, = struct.unpack("<H", data[0xC:0xE])
            # 			print "frame_count %d" % frame_count

            frame_label_cnt, = struct.unpack("<H", data[0xA:0xC])
            # 			print "frame lable cnt %d" % frame_label_cnt
            frame_label_dict = {}
            for i in xrange(frame_label_cnt):
                data = rip_gim.seek_next_tag(data, (0x002B,))
                frame_label_idx, the_frame = struct.unpack("<HH", data[0x4:0x8])
                frame_label = symbol_list[frame_label_idx]
                frame_label_dict[the_frame] = frame_label

            depth2matrix = {}
            depth2color_trans = {}

            for i in xrange(frame_count):
                data = rip_gim.seek_next_tag(data, (0x0001,))
                ptag_cnt, = struct.unpack("<H", data[0x6:0x8])
                # 				print "frame %d, placeobject%d" % (i, ptag_cnt)
                if i in frame_label_dict:
                    control_tags.append(swf_helper.make_frame_label_tag(frame_label_dict[i]))
                for j in xrange(ptag_cnt):
                    data = rip_gim.seek_next_tag(data, (0x0004, 0x0005, 0x000C))
                    _type = struct.unpack("<H", data[:0x2])[0]
                    if _type == 0x0005:
                        depth, = struct.unpack("<H", data[0x6:0x8])
                        control_tags.append(swf_helper.make_remove_object2_tag(depth + 1))
                        continue
                    if _type == 0x000C:
                        as_idx, = struct.unpack("<H", data[0x4:0x6])
                        control_tags.append(
                            swf_helper.make_do_action_tag([action_constant_pool, action_record_list[as_idx]])
                        )
                        continue
                    elif _type != 0x0004:
                        print "Ignore other tags ATM"
                        continue

                    _flags = struct.unpack("<H", data[0xC:0xE])[0]
                    flags = 0
                    if _flags & 1:
                        flags |= swf_helper.PLACE_FLAG_HAS_CHARACTER
                    if _flags & 2:
                        flags |= swf_helper.PLACE_FLAG_MOVE
                    id, = struct.unpack("<H", data[0x4:0x6])
                    trans_idx = struct.unpack("<H", data[0x18:0x1A])[0]
                    if trans_idx == 0xFFFF:
                        pass
                    elif (trans_idx & 0x8000) == 0:
                        translate = (matrix_list[trans_idx][4], matrix_list[trans_idx][5])
                        scale = (matrix_list[trans_idx][0], matrix_list[trans_idx][3])
                        rotateskew = (matrix_list[trans_idx][1], matrix_list[trans_idx][2])
                        flags |= swf_helper.PLACE_FLAG_HAS_MATRIX
                    else:
                        trans_idx &= 0x7FFF
                        translate = point_list[trans_idx]
                        scale = rotateskew = None
                        flags |= swf_helper.PLACE_FLAG_HAS_MATRIX
                    if flags & swf_helper.PLACE_FLAG_HAS_MATRIX:
                        matrix = swf_helper.pack_matrix(scale, rotateskew, translate)
                    else:
                        matrix = None
                    depth = struct.unpack("<H", data[0x10:0x12])[0] + 1
                    name_idx = struct.unpack("<H", data[0xA:0xC])[0]
                    name = symbol_list[name_idx]
                    if name != "":
                        flags |= swf_helper.PLACE_FLAG_HAS_NAME
                    color_mul_idx = struct.unpack("<h", data[0x1A:0x1C])[0]
                    color_add_idx = struct.unpack("<h", data[0x1C:0x1E])[0]
                    # 					color_mul_idx = -1
                    # 					color_add_idx = -1
                    if color_mul_idx >= 0 or color_add_idx >= 0:
                        flags |= swf_helper.PLACE_FLAG_HAS_COLOR_TRANSFORM
                    if color_mul_idx < 0:
                        color_mul = None
                    else:
                        color_mul = [c / 256.0 for c in color_list[color_mul_idx]]
                    if color_add_idx < 0:
                        color_add = None
                    else:
                        color_add = color_list[color_add_idx]
                    if flags & swf_helper.PLACE_FLAG_HAS_COLOR_TRANSFORM:
                        color_trans = swf_helper.pack_color_transform_with_alpha(color_add, color_mul)
                    else:
                        color_trans = None

                    clip_depth, = struct.unpack("<H", data[0x12:0x14])
                    if clip_depth > 0:
                        flags |= swf_helper.PLACE_FLAG_HAS_CLIP_DEPTH

                    ratio, = struct.unpack("<h", data[0x6:0x8])
                    if ratio >= 0:
                        flags |= swf_helper.PLACE_FLAG_HAS_RATIO

                    if flags & swf_helper.PLACE_FLAG_HAS_CHARACTER and flags & swf_helper.PLACE_FLAG_MOVE:
                        control_tags.append(swf_helper.make_remove_object2_tag(depth))
                        flags &= 0xFFFF - swf_helper.PLACE_FLAG_MOVE
                        if not (flags & swf_helper.PLACE_FLAG_HAS_MATRIX):
                            flags |= swf_helper.PLACE_FLAG_HAS_MATRIX
                            matrix = depth2matrix[depth]

                    clip_action_cnt, = struct.unpack("<H", data[0x20:0x22])
                    if clip_action_cnt > 0:
                        clip_action_records = []
                        for k in range(clip_action_cnt):
                            data = rip_gim.seek_next_tag(data, (0xF014,))
                            as_idx, event_flags, keycode = struct.unpack("<HIB", data[0x4:0xB])
                            clip_action_records.append(
                                swf_helper.pack_clip_action_record(
                                    event_flags, [action_constant_pool, action_record_list[as_idx]], keycode
                                )
                            )

                        flags |= swf_helper.PLACE_FLAG_HAS_CLIP_ACTIONS
                        clip_actions = swf_helper.pack_clip_actions(clip_action_records)
                    else:
                        clip_actions = None

                    ptag = swf_helper.make_place_object2_tag(
                        flags,
                        depth,
                        id,
                        name=name,
                        matrix=matrix,
                        color_trans=color_trans,
                        clip_actions=clip_actions,
                        ratio=ratio,
                        clip_depth=clip_depth,
                    )
                    control_tags.append(ptag)

                    if matrix:
                        depth2matrix[depth] = matrix
                    if color_trans:
                        depth2color_trans[depth] = color_trans

                show_frame_tag = swf_helper.make_show_frame_tag()
                control_tags.append(show_frame_tag)
                # append end tag
            control_tags.append(swf_helper.make_end_tag())
            # build define sprite tag
            define_sprite_tag = swf_helper.make_define_sprite_tag(sprite_id, frame_count, control_tags)
            define_sprite_tags.append(define_sprite_tag)
        else:
            data = rip_gim.seek_next_tag(data)

    return define_sprite_tags
Beispiel #4
0
def make_normal_sprite(ctx, d, subds):
	color_list = ctx["color_list"]
	point_list = ctx["pos_list"]
	matrix_list = ctx["mat_list"]
	symbol_list = ctx["symbol_list"]
	as_list = ctx["as_list"]
	
	frame_label_cnt = d["frame_label_cnt"]
	frame_cnt = d["0001_cnt"]
	sprite_id = d["character_id"]
#	print "sprite id = %d" % sprite_id
	frame_label_dict = {}
	
	# build a frame label dict for later ref	
	for subd in subds[:frame_label_cnt]:
		assert subd["tag_type"] == 0x002B
		frame_id = subd["frame_id"]
		frame_label = symbol_list[subd["name_idx"]]
		frame_label_dict[frame_id] = frame_label
		
#	print "frame_label_cnt = %d" % frame_label_cnt
	# handle the rest, all the frames
	sub_tags = []
	depth2matrix = {}
	depth2color_trans = {}
	clip_action_cnt = -1
	frame_cmd_cnt = -1
	for subd in subds[frame_label_cnt:]:
			
		if subd["tag_type"] == 0x0001:
			frame_cmd_cnt = subd["cmd_cnt"]
			frame_id = subd["frame_id"]
			frame_label = frame_label_dict.get(frame_id, None)
			if frame_label is not None:
				frame_label_tag = swf_helper.make_frame_label_tag(frame_label)
				sub_tags.append(frame_label_tag)
			
		elif subd["tag_type"]	== 0x0005:
			sub_tags.append(swf_helper.make_remove_object2_tag(
				subd["depth"] + 1))
			frame_cmd_cnt -= 1
		elif subd["tag_type"] == 0x000c:
			bytecodes = as_list[subd["as_idx"]]["bytecode"]
			bytecodes = as_fixer.fix(bytecodes, symbol_list)
			sub_tags.append(swf_helper.make_do_action_tag([bytecodes]))
			frame_cmd_cnt -= 1
		elif subd["tag_type"] == 0xf014:

			clip_action_cnt -= 1
			bytecodes = as_fixer.fix(as_list[subd["as_idx"]]["bytecode"], symbol_list)
			event_flags = subd["clip_event_flags"]
			keycode = 0
			clip_action_records.append(
				swf_helper.pack_clip_action_record(event_flags, [bytecodes], keycode))
					
		elif subd["tag_type"] != 0x0004:
			assert False, "unhandled tag! %d" % subd["tag_type"]

		else:	# handle tag0004
		
			# check unknown fields
			assert subd["unk1"] == 0, "unk1 is not zero!"
			
			frame_cmd_cnt -= 1
			_flags = subd["flags"]
			flags = 0
			if _flags & 1:
				flags |= swf_helper.PLACE_FLAG_HAS_CHARACTER
			if _flags & 2:
				flags |= swf_helper.PLACE_FLAG_MOVE
			id = subd["character_id"]
#			print "sub character id = %d" % id
			trans_idx = subd["trans_idx"]
			if trans_idx == -1:
				pass
			elif trans_idx >= 0:
				translate = (matrix_list[trans_idx]["trans_x"],
					matrix_list[trans_idx]["trans_y"])
				scale = (matrix_list[trans_idx]["scale_x"],
					matrix_list[trans_idx]["scale_y"])
				rotateskew = (matrix_list[trans_idx]["rotateskew_x"], 
					matrix_list[trans_idx]["rotateskew_y"])
				flags |= swf_helper.PLACE_FLAG_HAS_MATRIX
			else:
				fdef = format.DATA[0x0004]
				size = 0
				for vname, size, fmt in fdef:
					if vname == "trans_idx":
						break
				mask = (1 << (size * 8 - 1))-1
				trans_idx &= mask
				translate = point_list[trans_idx]["x"], point_list[trans_idx]["y"]
				scale = rotateskew = None
				flags |= swf_helper.PLACE_FLAG_HAS_MATRIX
			if flags & swf_helper.PLACE_FLAG_HAS_MATRIX:
				matrix = swf_helper.pack_matrix(scale, rotateskew, 
					translate)
			else:
				matrix = None
			
			flags2 = 0
			if subd["blend_mode"] > 1:
				flags2 |= swf_helper.PLACE_FLAG2_HAS_BLEND_MODE
				blend_mode = subd["blend_mode"]
			else:
				blend_mode = None
				
			depth = subd["depth"]
			name_idx = subd["name_idx"]
			name = symbol_list[name_idx]
			if name != "":
				flags |= swf_helper.PLACE_FLAG_HAS_NAME
			color_mul_idx = subd["color_mul_idx"]
			color_add_idx = subd["color_add_idx"]

			if color_mul_idx >= 0 or color_add_idx >= 0:
				flags |= swf_helper.PLACE_FLAG_HAS_COLOR_TRANSFORM
			if color_mul_idx < 0:
				color_mul = None
			else:
				c = color_list[color_mul_idx]
				color_mul = [c["R"]/256.0, c["G"]/256.0, c["B"]/256.0, c["A"]/256.0]
			if color_add_idx < 0:
				color_add = None
			else:
				c = color_list[color_add_idx]
				color_add = [c["R"], c["G"], c["B"], c["A"]]
			if flags & swf_helper.PLACE_FLAG_HAS_COLOR_TRANSFORM:
				color_trans = \
					swf_helper.pack_color_transform_with_alpha(
						color_add, color_mul)
			else:
				color_trans = None
			
			if matrix:
				depth2matrix[depth] = matrix
			if color_trans:
				depth2color_trans[depth] = color_trans
				
			clip_depth = subd["clip_depth"]
			if clip_depth > 0:
				flags |= swf_helper.PLACE_FLAG_HAS_CLIP_DEPTH
				
			ratio = subd["inst_id"]	# Not sure??
			if ratio >= 0:
				flags |= swf_helper.PLACE_FLAG_HAS_RATIO

			if flags & swf_helper.PLACE_FLAG_HAS_CHARACTER and \
				flags & swf_helper.PLACE_FLAG_MOVE:
				sub_tags.append(swf_helper.make_remove_object2_tag(depth + 1))
				flags &= (0xFFFF - swf_helper.PLACE_FLAG_MOVE)
				if not (flags & swf_helper.PLACE_FLAG_HAS_MATRIX):
					flags |= swf_helper.PLACE_FLAG_HAS_MATRIX
					matrix = depth2matrix[depth]
			
			clip_action_cnt = subd["clip_action_cnt"]
			clip_action_records = []
	
		# finish all clip_action tags, pack place object2 tag
		if clip_action_cnt == 0:
			if len(clip_action_records) > 0:
				flags |= swf_helper.PLACE_FLAG_HAS_CLIP_ACTIONS
				clip_actions = \
					swf_helper.pack_clip_actions(clip_action_records)
			else:
				clip_actions = None
				
			ptag = swf_helper.make_place_object3_tag(flags, flags2, depth + 1, 
			id=id, name=name, matrix=matrix, color_trans=color_trans, 
			clip_actions=clip_actions, ratio=ratio, clip_depth=clip_depth+1,
			blend_mode=blend_mode)
			
			sub_tags.append(ptag)
			
			clip_action_cnt = -1
					
		if frame_cmd_cnt == 0:
			sub_tags.append(swf_helper.make_show_frame_tag())
			frame_cmd_cnt = -1			
	
	sub_tags.append(swf_helper.make_end_tag())	
	return swf_helper.make_define_sprite_tag(sprite_id, frame_cnt, sub_tags)