|
@@ -1394,7 +1394,7 @@ let convert_header ver (w,h,fps,bg) =
|
|
let default_header ver =
|
|
let default_header ver =
|
|
convert_header ver (400,300,30.,0xFFFFFF)
|
|
convert_header ver (400,300,30.,0xFFFFFF)
|
|
|
|
|
|
-let generate_code file ver types hres =
|
|
|
|
|
|
+let generate file ver types hres =
|
|
let ctx = {
|
|
let ctx = {
|
|
segs = [];
|
|
segs = [];
|
|
opcodes = DynArray.create();
|
|
opcodes = DynArray.create();
|
|
@@ -1478,136 +1478,3 @@ let generate_code file ver types hres =
|
|
IO.close_out ch;
|
|
IO.close_out ch;
|
|
end;
|
|
end;
|
|
List.map fst tags , ctx.movieclips
|
|
List.map fst tags , ctx.movieclips
|
|
-
|
|
|
|
-let generate file ver header infile types hres =
|
|
|
|
- let t = Plugin.timer "generate swf" in
|
|
|
|
- let file , codeclip = (try let f , c = ExtString.String.split file "@" in f, Some c with _ -> file , None) in
|
|
|
|
- let tag_code, boot_name , movieclips = (if ver = 9 then
|
|
|
|
- (* hack for an ocaml bug *)
|
|
|
|
- let f (h:(string,string) Hashtbl.t) = Genswf9.generate types h in
|
|
|
|
- let tmp : (string,string) Hashtbl.t = hres in
|
|
|
|
- let c, b = f (Obj.magic tmp) in
|
|
|
|
- c,b,[]
|
|
|
|
- else
|
|
|
|
- let c, m = generate_code file ver types hres in
|
|
|
|
- c,"",m
|
|
|
|
- ) in
|
|
|
|
- let tag ?(ext=false) d = {
|
|
|
|
- tid = 0;
|
|
|
|
- textended = ext;
|
|
|
|
- tdata = d;
|
|
|
|
- } in
|
|
|
|
- let base_id = ref 0x5000 in
|
|
|
|
- let tag_code = (match codeclip with
|
|
|
|
- | None -> List.map tag tag_code
|
|
|
|
- | Some link ->
|
|
|
|
- incr base_id;
|
|
|
|
- [
|
|
|
|
- tag (TClip {
|
|
|
|
- c_id = !base_id;
|
|
|
|
- c_frame_count = 1;
|
|
|
|
- c_tags = List.map tag tag_code @ [tag TShowFrame];
|
|
|
|
- });
|
|
|
|
- tag (TExport [{ exp_id = !base_id; exp_name = link }]);
|
|
|
|
- ]
|
|
|
|
- ) in
|
|
|
|
- let movieclips = ref movieclips in
|
|
|
|
- let f9clips = ref [{ f9_cid = None; f9_classname = boot_name }] in
|
|
|
|
- let tagclips() = List.fold_left (fun acc m ->
|
|
|
|
- incr base_id;
|
|
|
|
- tag ~ext:true (TClip { c_id = !base_id; c_frame_count = 1; c_tags = [] }) ::
|
|
|
|
- tag ~ext:true (TExport [{ exp_id = !base_id; exp_name = s_type_path m }]) ::
|
|
|
|
- acc
|
|
|
|
- ) [] (!movieclips) in
|
|
|
|
- let tagclips9() =
|
|
|
|
- if ver = 9 then
|
|
|
|
- [tag (TF9Classes !f9clips)]
|
|
|
|
- else
|
|
|
|
- []
|
|
|
|
- in
|
|
|
|
- let sandbox() =
|
|
|
|
- let net = Plugin.defined "network-sandbox" in
|
|
|
|
- tag (TSandbox (match ver, net with
|
|
|
|
- | 9, true -> SBUnknown 9
|
|
|
|
- | 9, false -> SBUnknown 8
|
|
|
|
- | _, true -> SBNetwork
|
|
|
|
- | _, false -> SBLocal
|
|
|
|
- ))
|
|
|
|
- in
|
|
|
|
- let debug() = tag (TEnableDebugger2 !debug_pass) in
|
|
|
|
- let swf = (match infile with
|
|
|
|
- | None ->
|
|
|
|
- let header , bg = (match header with None -> default_header ver | Some h -> convert_header ver h) in
|
|
|
|
- let tagbg = tag (TSetBgColor { cr = bg lsr 16; cg = (bg lsr 8) land 0xFF; cb = bg land 0xFF }) in
|
|
|
|
- let tagstart = (if ver >= 8 then [sandbox()] else []) @ (if ver = 9 && Plugin.defined "debug" then [debug()] else []) @ [tagbg] in
|
|
|
|
- let tagshow = tag TShowFrame in
|
|
|
|
- (header,tagstart @ tagclips() @ tag_code @ tagclips9() @ [tagshow])
|
|
|
|
- | Some file ->
|
|
|
|
- let file = (try Plugin.find_file file with Not_found -> failwith ("File not found : " ^ file)) in
|
|
|
|
- let ch = IO.input_channel (open_in_bin file) in
|
|
|
|
- let h, swf = (try Swf.parse ch with _ -> failwith ("The input swf " ^ file ^ " is corrupted")) in
|
|
|
|
- let header , tagbg = (match header with
|
|
|
|
- | None ->
|
|
|
|
- { h with h_version = ver }, None
|
|
|
|
- | Some h ->
|
|
|
|
- let h , bg = convert_header ver h in
|
|
|
|
- let tagbg = tag (TSetBgColor { cr = bg lsr 16; cg = (bg lsr 8) land 0xFF; cb = bg land 0xFF }) in
|
|
|
|
- h , Some tagbg
|
|
|
|
- ) in
|
|
|
|
- IO.close_in ch;
|
|
|
|
- let has_sandbox = ref false in
|
|
|
|
- let has_debug = ref false in
|
|
|
|
- let rec loop = function
|
|
|
|
- | [] ->
|
|
|
|
- failwith ("Frame 1 not found in " ^ file)
|
|
|
|
- | { tdata = TUnknown (0x1A,_) } :: l (*// PlaceObject2 *)
|
|
|
|
- | { tdata = TUnknown (0x46,_) } :: l (*// PlaceObject3 *)
|
|
|
|
- | { tdata = TPlaceObject2 _ } :: l
|
|
|
|
- | { tdata = TPlaceObject3 _ } :: l
|
|
|
|
- | { tdata = TRemoveObject2 _ } :: l
|
|
|
|
- | { tdata = TRemoveObject _ } :: l when not (Plugin.defined "flash_use_stage") ->
|
|
|
|
- loop l
|
|
|
|
- | ({ tdata = TSetBgColor _ } as t) :: l ->
|
|
|
|
- (match tagbg with
|
|
|
|
- | None -> t :: loop l
|
|
|
|
- | Some bg -> bg :: loop l)
|
|
|
|
- | ({ tdata = TShowFrame } as t) :: l ->
|
|
|
|
- tagclips() @ tag_code @ tagclips9() @ t :: l
|
|
|
|
- | ({ tdata = TExport el } as t) :: l ->
|
|
|
|
- if ver = 9 then begin
|
|
|
|
- List.iter (fun e ->
|
|
|
|
- f9clips := { f9_cid = Some e.exp_id; f9_classname = e.exp_name } :: !f9clips
|
|
|
|
- ) el;
|
|
|
|
- loop l
|
|
|
|
- end else begin
|
|
|
|
- List.iter (fun e ->
|
|
|
|
- movieclips := List.filter (fun x -> s_type_path x <> e.exp_name) (!movieclips)
|
|
|
|
- ) el;
|
|
|
|
- t :: loop l
|
|
|
|
- end;
|
|
|
|
- | { tdata = TSandbox _ } :: l ->
|
|
|
|
- has_sandbox := true;
|
|
|
|
- sandbox() :: loop l
|
|
|
|
- | ({ tdata = TEnableDebugger2 _ } as t) :: l ->
|
|
|
|
- has_debug := true;
|
|
|
|
- if Plugin.defined "debug" then t :: loop l else loop l
|
|
|
|
- | t :: l ->
|
|
|
|
- t :: loop l
|
|
|
|
- in
|
|
|
|
- let tags = loop swf in
|
|
|
|
- let tags = (if not !has_sandbox && ver >= 8 then sandbox() :: tags else tags) in
|
|
|
|
- let tags = (if not !has_debug && ver = 9 && Plugin.defined "debug" then debug() :: tags else tags) in
|
|
|
|
- (header , tags)
|
|
|
|
- ) in
|
|
|
|
- let swf = if ver = 8 && Plugin.defined "flash_v9" then ({ (fst swf) with h_version = 9 }, snd swf) else swf in
|
|
|
|
- t();
|
|
|
|
- let t = Plugin.timer "write swf" in
|
|
|
|
- let ch = IO.output_channel (open_out_bin file) in
|
|
|
|
- Swf.write ch swf;
|
|
|
|
- IO.close_out ch;
|
|
|
|
- t();
|
|
|
|
-
|
|
|
|
-;;
|
|
|
|
-SwfParser.init SwfZip.inflate SwfZip.deflate;
|
|
|
|
-SwfParser.full_parsing := false;
|
|
|
|
-Swf.warnings := false;
|
|
|