mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-16 14:11:19 +07:00
structure refactoring
This commit is contained in:
@@ -5,8 +5,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Ionic.Zlib;
|
||||
using FlashTools.Internal.SwfTags;
|
||||
using FlashTools.Internal.SwfTools;
|
||||
using FlashTools.Internal.SwfTools.SwfTags;
|
||||
|
||||
namespace FlashTools.Internal {
|
||||
public class FlashAnimSwfPostprocessor : AssetPostprocessor {
|
||||
@@ -23,36 +23,17 @@ namespace FlashTools.Internal {
|
||||
|
||||
static void SwfAssetProcess(string swf_asset) {
|
||||
Debug.LogFormat("SwfAssetProcess: {0}", swf_asset);
|
||||
var raw_reader = new SwfStreamReader(swf_asset);
|
||||
var header = SwfHeader.Read(raw_reader);
|
||||
Debug.LogFormat("Header: {0}", header);
|
||||
SwfStreamReader swf_reader;
|
||||
switch ( header.Format ) {
|
||||
case "FWS":
|
||||
swf_reader = raw_reader;
|
||||
SwfRect.Read(swf_reader);
|
||||
swf_reader.ReadFixedPoint8();
|
||||
swf_reader.Reader.ReadUInt16();
|
||||
break;
|
||||
case "CWS":
|
||||
var mem = new MemoryStream();
|
||||
Decompress(new MemoryStream(raw_reader.ReadRest()), mem);
|
||||
swf_reader = new SwfStreamReader(mem);
|
||||
SwfRect.Read(swf_reader);
|
||||
swf_reader.ReadFixedPoint8();
|
||||
swf_reader.Reader.ReadUInt16();
|
||||
|
||||
//var swf_rest = raw_reader.ReadRest();
|
||||
//var raw_rest = Decompress(swf_rest);
|
||||
//swf_reader = new SwfStreamReader(new MemoryStream(raw_rest));
|
||||
break;
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
"Unsupported swf format: {0}", header.Format));
|
||||
}
|
||||
while ( !swf_reader.IsEOF ) {
|
||||
var tag_data = SwfTagData.Read(swf_reader);
|
||||
var tag = SwfTagBase.Create(tag_data);
|
||||
var decoder = new SwfDecoder(swf_asset);
|
||||
Debug.LogWarningFormat(
|
||||
"OriginalHeader: {0}",
|
||||
decoder.OriginalHeader);
|
||||
Debug.LogWarningFormat(
|
||||
"UncompressedHeader: {0}",
|
||||
decoder.UncompressedHeader);
|
||||
Debug.LogWarningFormat(
|
||||
"Tags: {0}",
|
||||
decoder.Tags.Count);
|
||||
foreach ( var tag in decoder.Tags ) {
|
||||
if ( tag.TagType == SwfTagType.Unknown ) {
|
||||
Debug.LogWarningFormat("Tag: {0}", tag.ToString());
|
||||
} else {
|
||||
@@ -86,23 +67,5 @@ namespace FlashTools.Internal {
|
||||
atlas_path,
|
||||
ImportAssetOptions.ForceUncompressedImport);
|
||||
}*/
|
||||
|
||||
static void Decompress(Stream compressed, Stream target) {
|
||||
var zip = new ZlibStream(target, CompressionMode.Decompress);
|
||||
int readBytes;
|
||||
var buffer = new byte[512];
|
||||
do {
|
||||
readBytes = compressed.Read(buffer, 0, buffer.Length);
|
||||
zip.Write(buffer, 0, readBytes);
|
||||
} while (readBytes > 0);
|
||||
zip.Flush();
|
||||
target.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
static byte[] Decompress(byte[] compressed) {
|
||||
var mem = new MemoryStream();
|
||||
Decompress(new MemoryStream(compressed), mem);
|
||||
return mem.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
Assets/FlashTools/Scripts/Internal/Editor/SwfTools.meta
Normal file
9
Assets/FlashTools/Scripts/Internal/Editor/SwfTools.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 484a94bbfa1744985a66e8f387d32d00
|
||||
folderAsset: yes
|
||||
timeCreated: 1457862313
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,140 +1,9 @@
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using FlashTools.Internal.SwfTags;
|
||||
|
||||
namespace FlashTools.Internal {
|
||||
class SwfStreamReader {
|
||||
struct BitContext {
|
||||
public byte CachedByte;
|
||||
public byte BitIndex;
|
||||
}
|
||||
BitContext _bitContext;
|
||||
BinaryReader _reader;
|
||||
|
||||
long Length {
|
||||
get { return _reader.BaseStream.Length; }
|
||||
}
|
||||
|
||||
long Position {
|
||||
get { return _reader.BaseStream.Position; }
|
||||
}
|
||||
|
||||
long BytesLeft {
|
||||
get { return Length - Position; }
|
||||
}
|
||||
|
||||
public SwfStreamReader(string path) {
|
||||
_reader = new BinaryReader(File.OpenRead(path));
|
||||
}
|
||||
|
||||
public SwfStreamReader(byte[] data) {
|
||||
_reader = new BinaryReader(new MemoryStream(data));
|
||||
}
|
||||
|
||||
public SwfStreamReader(Stream stream) {
|
||||
_reader = new BinaryReader(stream);
|
||||
}
|
||||
|
||||
public BinaryReader Reader {
|
||||
get { return _reader; }
|
||||
}
|
||||
|
||||
public bool ReadBit() {
|
||||
var bitIndex = _bitContext.BitIndex & 0x07;
|
||||
if ( bitIndex == 0 ) {
|
||||
_bitContext.CachedByte = Reader.ReadByte();
|
||||
}
|
||||
++_bitContext.BitIndex;
|
||||
return ((_bitContext.CachedByte << bitIndex) & 0x80) != 0;
|
||||
}
|
||||
|
||||
public int ReadSignedBits(uint count) {
|
||||
if ( count == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
bool sign = ReadBit();
|
||||
var res = sign ? uint.MaxValue : 0;
|
||||
--count;
|
||||
for ( var i = 0; i < count; ++i ) {
|
||||
var bit = ReadBit();
|
||||
res = (res << 1 | (bit ? 1u : 0u));
|
||||
}
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
public uint ReadUnsignedBits(uint count) {
|
||||
if ( count == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
uint res = 0;
|
||||
for ( var i = 0; i < count; ++i ) {
|
||||
var bit = ReadBit();
|
||||
res = (res << 1 | (bit ? 1u : 0u));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public void AlignToByte() {
|
||||
_bitContext.BitIndex = 0;
|
||||
_bitContext.CachedByte = 0;
|
||||
}
|
||||
|
||||
public string ReadString() {
|
||||
var data_stream = new MemoryStream();
|
||||
byte bt = 1;
|
||||
while ( bt > 0 ) {
|
||||
bt = _reader.ReadByte();
|
||||
if ( bt > 0 ) {
|
||||
data_stream.WriteByte(bt);
|
||||
}
|
||||
}
|
||||
return Encoding.UTF8.GetString(data_stream.ToArray());
|
||||
}
|
||||
|
||||
public float ReadFixedPoint8() {
|
||||
return Reader.ReadInt16() / 256.0f;
|
||||
}
|
||||
|
||||
public float ReadFixedPoint16(uint bits) {
|
||||
var value = ReadSignedBits(bits);
|
||||
return value / 65536.0f;
|
||||
}
|
||||
|
||||
public uint ReadEncodedU32() {
|
||||
AlignToByte();
|
||||
uint val = 0;
|
||||
var bt = _reader.ReadByte();
|
||||
val |= bt & 0x7fu;
|
||||
if ((bt & 0x80) == 0) return val;
|
||||
|
||||
bt = _reader.ReadByte();
|
||||
val |= (bt & 0x7fu) << 7;
|
||||
if ((bt & 0x80) == 0) return val;
|
||||
|
||||
bt = _reader.ReadByte();
|
||||
val |= (bt & 0x7fu) << 14;
|
||||
if ((bt & 0x80) == 0) return val;
|
||||
|
||||
bt = _reader.ReadByte();
|
||||
val |= (bt & 0x7fu) << 21;
|
||||
if ((bt & 0x80) == 0) return val;
|
||||
|
||||
bt = _reader.ReadByte();
|
||||
val |= (bt & 0x7fu) << 28;
|
||||
return val;
|
||||
}
|
||||
|
||||
public byte[] ReadRest() {
|
||||
return Reader.ReadBytes((int)BytesLeft);
|
||||
}
|
||||
|
||||
public bool IsEOF {
|
||||
get { return Position == Length; }
|
||||
}
|
||||
}
|
||||
using FlashTools.Internal.SwfTools.SwfTags;
|
||||
|
||||
namespace FlashTools.Internal.SwfTools {
|
||||
enum SwfBlendMode : byte {
|
||||
Normal = 0,
|
||||
Normal1 = 1,
|
||||
@@ -153,71 +22,103 @@ namespace FlashTools.Internal {
|
||||
Hardlight = 14
|
||||
}
|
||||
|
||||
struct SwfHeader {
|
||||
public string Format;
|
||||
public byte Version;
|
||||
public uint FileLength;
|
||||
public SwfRect FrameSize;
|
||||
public float FrameRate;
|
||||
public ushort FrameCount;
|
||||
struct SwfShortHeader {
|
||||
public string Format;
|
||||
public byte Version;
|
||||
public uint FileLength;
|
||||
|
||||
public static SwfHeader Read(SwfStreamReader reader) {
|
||||
var header = new SwfHeader();
|
||||
header.Format = new string(reader.Reader.ReadChars(3));
|
||||
header.Version = reader.Reader.ReadByte();
|
||||
header.FileLength = reader.Reader.ReadUInt32();
|
||||
//header.FrameSize = SwfRect.Read(reader);
|
||||
//header.FrameRate = reader.ReadFixedPoint8();
|
||||
//header.FrameCount = reader.Reader.ReadUInt16();
|
||||
public static SwfShortHeader Read(SwfStreamReader reader) {
|
||||
var header = new SwfShortHeader();
|
||||
header.Format = new string(reader.ReadChars(3));
|
||||
header.Version = reader.ReadByte();
|
||||
header.FileLength = reader.ReadUInt32();
|
||||
return header;
|
||||
}
|
||||
|
||||
public void Write(Stream stream) {
|
||||
if ( Format == null || Format.Length != 3 ) {
|
||||
throw new UnityException("Incorrect SwfShortHeader Format");
|
||||
}
|
||||
stream.WriteByte((byte)Format[0]);
|
||||
stream.WriteByte((byte)Format[1]);
|
||||
stream.WriteByte((byte)Format[2]);
|
||||
stream.WriteByte(Version);
|
||||
stream.WriteByte((byte)((FileLength >> 0) & 0xff));
|
||||
stream.WriteByte((byte)((FileLength >> 8) & 0xff));
|
||||
stream.WriteByte((byte)((FileLength >> 16) & 0xff));
|
||||
stream.WriteByte((byte)((FileLength >> 24) & 0xff));
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format(
|
||||
"Format: {0}, Version: {1}, FileLength: {2}",
|
||||
Format, Version, FileLength);
|
||||
}
|
||||
}
|
||||
|
||||
struct SwfLongHeader {
|
||||
public SwfShortHeader ShortHeader;
|
||||
public SwfRect FrameSize;
|
||||
public float FrameRate;
|
||||
public ushort FrameCount;
|
||||
|
||||
public static SwfLongHeader Read(SwfStreamReader reader) {
|
||||
var header = new SwfLongHeader();
|
||||
header.ShortHeader = SwfShortHeader.Read(reader);
|
||||
header.FrameSize = SwfRect.Read(reader);
|
||||
header.FrameRate = reader.ReadFixedPoint8();
|
||||
header.FrameCount = reader.ReadUInt16();
|
||||
return header;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format(
|
||||
"Format: {0}, Version: {1}, FileLength: {2}, FrameSize: {3}, FrameRate: {4}, FrameCount: {5}",
|
||||
Format, Version, FileLength, FrameSize, FrameRate, FrameCount);
|
||||
"Format: {0}, Version: {1}, FileLength: {2}, " +
|
||||
"FrameSize: {3}, FrameRate: {4}, FrameCount: {5}",
|
||||
ShortHeader.Format, ShortHeader.Version, ShortHeader.FileLength,
|
||||
FrameSize, FrameRate, FrameCount);
|
||||
}
|
||||
}
|
||||
|
||||
struct SwfRGB {
|
||||
public byte Red;
|
||||
public byte Green;
|
||||
public byte Blue;
|
||||
public byte R;
|
||||
public byte G;
|
||||
public byte B;
|
||||
|
||||
public static SwfRGB Read(SwfStreamReader reader) {
|
||||
var rgb = new SwfRGB();
|
||||
rgb.Red = reader.Reader.ReadByte();
|
||||
rgb.Green = reader.Reader.ReadByte();
|
||||
rgb.Blue = reader.Reader.ReadByte();
|
||||
var rgb = new SwfRGB();
|
||||
rgb.R = reader.ReadByte();
|
||||
rgb.G = reader.ReadByte();
|
||||
rgb.B = reader.ReadByte();
|
||||
return rgb;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format(
|
||||
"R: {0}, G: {1}, B: {2}",
|
||||
Red, Green, Blue);
|
||||
R, G, B);
|
||||
}
|
||||
}
|
||||
|
||||
struct SwfRGBA {
|
||||
public byte Red;
|
||||
public byte Green;
|
||||
public byte Blue;
|
||||
public byte Alpha;
|
||||
public byte R;
|
||||
public byte G;
|
||||
public byte B;
|
||||
public byte A;
|
||||
|
||||
public static SwfRGBA Read(SwfStreamReader reader) {
|
||||
var rgba = new SwfRGBA();
|
||||
rgba.Red = reader.Reader.ReadByte();
|
||||
rgba.Green = reader.Reader.ReadByte();
|
||||
rgba.Blue = reader.Reader.ReadByte();
|
||||
rgba.Alpha = reader.Reader.ReadByte();
|
||||
var rgba = new SwfRGBA();
|
||||
rgba.R = reader.ReadByte();
|
||||
rgba.G = reader.ReadByte();
|
||||
rgba.B = reader.ReadByte();
|
||||
rgba.A = reader.ReadByte();
|
||||
return rgba;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format(
|
||||
"R: {0}, G: {1}, B: {2}, A: {3}",
|
||||
Red, Green, Blue, Alpha);
|
||||
R, G, B, A);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,8 +332,7 @@ namespace FlashTools.Internal {
|
||||
var control_tags = new SwfControlTags();
|
||||
control_tags.Tags = new List<SwfTagBase>();
|
||||
while ( true ) {
|
||||
var tag_data = SwfTagData.Read(reader);
|
||||
var tag = SwfTagBase.Create(tag_data);
|
||||
var tag = SwfTagBase.Read(reader);
|
||||
control_tags.Tags.Add(tag);
|
||||
if ( tag.TagType == SwfTagType.End ) {
|
||||
break;
|
||||
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cbe133e688394de3a3ccafde9ac5942
|
||||
timeCreated: 1457387827
|
||||
guid: 42e458b9c57b64d3f905fbf73ee0547d
|
||||
timeCreated: 1457819522
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,58 @@
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using FlashTools.Internal.SwfTools.SwfTags;
|
||||
using Ionic.Zlib;
|
||||
|
||||
namespace FlashTools.Internal.SwfTools {
|
||||
class SwfDecoder {
|
||||
public SwfShortHeader OriginalHeader;
|
||||
public SwfLongHeader UncompressedHeader;
|
||||
public List<SwfTagBase> Tags = new List<SwfTagBase>();
|
||||
|
||||
public SwfDecoder(string swf_path) {
|
||||
var raw_data = File.ReadAllBytes(swf_path);
|
||||
var uncompressed_stream = DecompressSwfData(raw_data);
|
||||
DecodeSwf(new SwfStreamReader(uncompressed_stream));
|
||||
}
|
||||
|
||||
MemoryStream DecompressSwfData(byte[] raw_swf_data) {
|
||||
var raw_reader = new SwfStreamReader(raw_swf_data);
|
||||
OriginalHeader = SwfShortHeader.Read(raw_reader);
|
||||
switch ( OriginalHeader.Format ) {
|
||||
case "FWS":
|
||||
return new MemoryStream(raw_swf_data);
|
||||
case "CWS":
|
||||
var rest_stream = DecompressZBytes(raw_reader.ReadRest());
|
||||
var new_short_header = new SwfShortHeader{
|
||||
Format = "FWS",
|
||||
Version = OriginalHeader.Version,
|
||||
FileLength = OriginalHeader.FileLength
|
||||
};
|
||||
var uncompressed_stream = new MemoryStream((int)OriginalHeader.FileLength);
|
||||
new_short_header.Write(uncompressed_stream);
|
||||
rest_stream.WriteTo(uncompressed_stream);
|
||||
uncompressed_stream.Position = 0;
|
||||
return uncompressed_stream;
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
"Unsupported swf format: {0}", OriginalHeader.Format));
|
||||
}
|
||||
}
|
||||
|
||||
void DecodeSwf(SwfStreamReader reader) {
|
||||
UncompressedHeader = SwfLongHeader.Read(reader);
|
||||
while ( !reader.IsEOF ) {
|
||||
Tags.Add(SwfTagBase.Read(reader));
|
||||
}
|
||||
}
|
||||
|
||||
static public MemoryStream DecompressZBytes(byte[] compressed_bytes) {
|
||||
var target = new MemoryStream();
|
||||
var zip_stream = new ZlibStream(target, CompressionMode.Decompress);
|
||||
zip_stream.Write(compressed_bytes, 0, compressed_bytes.Length);
|
||||
target.Position = 0;
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec49e670db02d4006b7722966e96ede6
|
||||
timeCreated: 1457864588
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,184 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FlashTools.Internal.SwfTools {
|
||||
class SwfStreamReader {
|
||||
struct BitContext {
|
||||
public byte CachedByte;
|
||||
public byte BitIndex;
|
||||
}
|
||||
BitContext _bitContext;
|
||||
BinaryReader _binaryReader;
|
||||
|
||||
long Length {
|
||||
get { return _binaryReader.BaseStream.Length; }
|
||||
}
|
||||
|
||||
long Position {
|
||||
get { return _binaryReader.BaseStream.Position; }
|
||||
}
|
||||
|
||||
long BytesLeft {
|
||||
get { return Length - Position; }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Public
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public SwfStreamReader(string path) {
|
||||
var file_stream = File.OpenRead(path);
|
||||
_binaryReader = new BinaryReader(file_stream);
|
||||
}
|
||||
|
||||
public SwfStreamReader(byte[] data) {
|
||||
var memory_stream = new MemoryStream(data);
|
||||
_binaryReader = new BinaryReader(memory_stream);
|
||||
}
|
||||
|
||||
public SwfStreamReader(Stream stream) {
|
||||
_binaryReader = new BinaryReader(stream);
|
||||
}
|
||||
|
||||
public SwfStreamReader SeekToBegin() {
|
||||
_binaryReader.BaseStream.Position = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
public bool IsEOF {
|
||||
get { return Position >= Length; }
|
||||
}
|
||||
|
||||
public void AlignToByte() {
|
||||
_bitContext.BitIndex = 0;
|
||||
_bitContext.CachedByte = 0;
|
||||
}
|
||||
|
||||
public byte[] ReadRest() {
|
||||
return ReadBytes((int)BytesLeft);
|
||||
}
|
||||
|
||||
public bool ReadBit() {
|
||||
var bitIndex = _bitContext.BitIndex & 0x07;
|
||||
if ( bitIndex == 0 ) {
|
||||
_bitContext.CachedByte = ReadByte();
|
||||
}
|
||||
++_bitContext.BitIndex;
|
||||
return ((_bitContext.CachedByte << bitIndex) & 0x80) != 0;
|
||||
}
|
||||
|
||||
public byte ReadByte() {
|
||||
return _binaryReader.ReadByte();
|
||||
}
|
||||
|
||||
public byte[] ReadBytes(int count) {
|
||||
return _binaryReader.ReadBytes(count);
|
||||
}
|
||||
|
||||
public char ReadChar() {
|
||||
return _binaryReader.ReadChar();
|
||||
}
|
||||
|
||||
public char[] ReadChars(int count) {
|
||||
return _binaryReader.ReadChars(count);
|
||||
}
|
||||
|
||||
public short ReadInt16() {
|
||||
return _binaryReader.ReadInt16();
|
||||
}
|
||||
|
||||
public int ReadInt32() {
|
||||
return _binaryReader.ReadInt32();
|
||||
}
|
||||
|
||||
public ushort ReadUInt16() {
|
||||
return _binaryReader.ReadUInt16();
|
||||
}
|
||||
|
||||
public uint ReadUInt32() {
|
||||
return _binaryReader.ReadUInt32();
|
||||
}
|
||||
|
||||
public int ReadSignedBits(uint count) {
|
||||
if ( count == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
bool sign = ReadBit();
|
||||
var res = sign ? uint.MaxValue : 0;
|
||||
--count;
|
||||
for ( var i = 0; i < count; ++i ) {
|
||||
var bit = ReadBit();
|
||||
res = (res << 1 | (bit ? 1u : 0u));
|
||||
}
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
public uint ReadUnsignedBits(uint count) {
|
||||
if ( count == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
uint res = 0;
|
||||
for ( var i = 0; i < count; ++i ) {
|
||||
var bit = ReadBit();
|
||||
res = (res << 1 | (bit ? 1u : 0u));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public string ReadString() {
|
||||
var bytes = new List<byte>();
|
||||
while ( true ) {
|
||||
var bt = ReadByte();
|
||||
if ( bt == 0 ) {
|
||||
break;
|
||||
}
|
||||
bytes.Add(bt);
|
||||
}
|
||||
return Encoding.UTF8.GetString(bytes.ToArray());
|
||||
}
|
||||
|
||||
public float ReadFixedPoint8() {
|
||||
return ReadInt16() / 256.0f;
|
||||
}
|
||||
|
||||
public float ReadFixedPoint16(uint bits) {
|
||||
var value = ReadSignedBits(bits);
|
||||
return value / 65536.0f;
|
||||
}
|
||||
|
||||
public uint ReadEncodedU32() {
|
||||
AlignToByte();
|
||||
uint val = 0;
|
||||
var bt = ReadByte();
|
||||
val |= bt & 0x7fu;
|
||||
if ( (bt & 0x80) == 0 ) {
|
||||
return val;
|
||||
}
|
||||
|
||||
bt = ReadByte();
|
||||
val |= (bt & 0x7fu) << 7;
|
||||
if ( (bt & 0x80) == 0 ) {
|
||||
return val;
|
||||
}
|
||||
|
||||
bt = ReadByte();
|
||||
val |= (bt & 0x7fu) << 14;
|
||||
if ( (bt & 0x80) == 0 ) {
|
||||
return val;
|
||||
}
|
||||
|
||||
bt = ReadByte();
|
||||
val |= (bt & 0x7fu) << 21;
|
||||
if ( (bt & 0x80) == 0 ) {
|
||||
return val;
|
||||
}
|
||||
|
||||
bt = ReadByte();
|
||||
val |= (bt & 0x7fu) << 28;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: add0a02be3196481daaf1fd9828f0f4e
|
||||
timeCreated: 1457819513
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class DefineBitsLossless2Tag : SwfTagBase {
|
||||
public ushort CharacterId;
|
||||
public byte BitmapFormat;
|
||||
@@ -20,12 +20,12 @@
|
||||
|
||||
public static DefineBitsLossless2Tag Create(SwfStreamReader reader) {
|
||||
var tag = new DefineBitsLossless2Tag();
|
||||
tag.CharacterId = reader.Reader.ReadUInt16();
|
||||
tag.BitmapFormat = reader.Reader.ReadByte();
|
||||
tag.BitmapWidth = reader.Reader.ReadUInt16();
|
||||
tag.BitmapHeight = reader.Reader.ReadUInt16();
|
||||
tag.CharacterId = reader.ReadUInt16();
|
||||
tag.BitmapFormat = reader.ReadByte();
|
||||
tag.BitmapWidth = reader.ReadUInt16();
|
||||
tag.BitmapHeight = reader.ReadUInt16();
|
||||
if ( tag.BitmapFormat == 3 ) {
|
||||
tag.BitmapColorTableSize = reader.Reader.ReadByte();
|
||||
tag.BitmapColorTableSize = reader.ReadByte();
|
||||
}
|
||||
tag.ZlibBitmapData = reader.ReadRest();
|
||||
return tag;
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class DefineBitsLosslessTag : SwfTagBase {
|
||||
public ushort CharacterId;
|
||||
public byte BitmapFormat;
|
||||
@@ -20,12 +20,12 @@
|
||||
|
||||
public static DefineBitsLosslessTag Create(SwfStreamReader reader) {
|
||||
var tag = new DefineBitsLosslessTag();
|
||||
tag.CharacterId = reader.Reader.ReadUInt16();
|
||||
tag.BitmapFormat = reader.Reader.ReadByte();
|
||||
tag.BitmapWidth = reader.Reader.ReadUInt16();
|
||||
tag.BitmapHeight = reader.Reader.ReadUInt16();
|
||||
tag.CharacterId = reader.ReadUInt16();
|
||||
tag.BitmapFormat = reader.ReadByte();
|
||||
tag.BitmapWidth = reader.ReadUInt16();
|
||||
tag.BitmapHeight = reader.ReadUInt16();
|
||||
if ( tag.BitmapFormat == 3 ) {
|
||||
tag.BitmapColorTableSize = reader.Reader.ReadByte();
|
||||
tag.BitmapColorTableSize = reader.ReadByte();
|
||||
}
|
||||
tag.ZlibBitmapData = reader.ReadRest();
|
||||
return tag;
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class DefineScalingGridTag : SwfTagBase {
|
||||
public ushort CharacterId;
|
||||
public SwfRect Splitter;
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
public static DefineScalingGridTag Create(SwfStreamReader reader) {
|
||||
var tag = new DefineScalingGridTag();
|
||||
tag.CharacterId = reader.Reader.ReadUInt16();
|
||||
tag.CharacterId = reader.ReadUInt16();
|
||||
tag.Splitter = SwfRect.Read(reader);
|
||||
return tag;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class DefineSceneAndFrameLabelDataTag : SwfTagBase {
|
||||
public struct SceneOffsetData {
|
||||
public uint Offset;
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class DefineShape2Tag : SwfTagBase {
|
||||
public ushort ShapeId;
|
||||
public SwfRect ShapeBounds;
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
public static DefineShape2Tag Create(SwfStreamReader reader) {
|
||||
var tag = new DefineShape2Tag();
|
||||
tag.ShapeId = reader.Reader.ReadUInt16();
|
||||
tag.ShapeId = reader.ReadUInt16();
|
||||
tag.ShapeBounds = SwfRect.Read(reader);
|
||||
tag.Shapes = SwfShapesWithStyle.Read(reader);
|
||||
return tag;
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class DefineShape3Tag : SwfTagBase {
|
||||
public ushort ShapeId;
|
||||
public SwfRect ShapeBounds;
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
public static DefineShape3Tag Create(SwfStreamReader reader) {
|
||||
var tag = new DefineShape3Tag();
|
||||
tag.ShapeId = reader.Reader.ReadUInt16();
|
||||
tag.ShapeId = reader.ReadUInt16();
|
||||
tag.ShapeBounds = SwfRect.Read(reader);
|
||||
tag.Shapes = SwfShapesWithStyle.Read(reader);
|
||||
return tag;
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class DefineShape4Tag : SwfTagBase {
|
||||
public ushort ShapeId;
|
||||
public SwfRect ShapeBounds;
|
||||
@@ -18,10 +18,10 @@
|
||||
|
||||
public static DefineShape4Tag Create(SwfStreamReader reader) {
|
||||
var tag = new DefineShape4Tag();
|
||||
tag.ShapeId = reader.Reader.ReadUInt16();
|
||||
tag.ShapeId = reader.ReadUInt16();
|
||||
tag.ShapeBounds = SwfRect.Read(reader);
|
||||
tag.EdgeBounds = SwfRect.Read(reader);
|
||||
reader.Reader.ReadByte(); // Skip flags
|
||||
reader.ReadByte(); // Skip flags
|
||||
tag.Shapes = SwfShapesWithStyle.Read(reader);
|
||||
return tag;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class DefineShapeTag : SwfTagBase {
|
||||
public ushort ShapeId;
|
||||
public SwfRect ShapeBounds;
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
public static DefineShapeTag Create(SwfStreamReader reader) {
|
||||
var tag = new DefineShapeTag();
|
||||
tag.ShapeId = reader.Reader.ReadUInt16();
|
||||
tag.ShapeId = reader.ReadUInt16();
|
||||
tag.ShapeBounds = SwfRect.Read(reader);
|
||||
tag.Shapes = SwfShapesWithStyle.Read(reader);
|
||||
return tag;
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class DefineSpriteTag : SwfTagBase {
|
||||
public ushort SpriteId;
|
||||
public ushort FrameCount;
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
public static DefineSpriteTag Create(SwfStreamReader reader) {
|
||||
var tag = new DefineSpriteTag();
|
||||
tag.SpriteId = reader.Reader.ReadUInt16();
|
||||
tag.FrameCount = reader.Reader.ReadUInt16();
|
||||
tag.SpriteId = reader.ReadUInt16();
|
||||
tag.FrameCount = reader.ReadUInt16();
|
||||
tag.ControlTags = SwfControlTags.Read(reader);
|
||||
return tag;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class EndTag : SwfTagBase {
|
||||
public override SwfTagType TagType {
|
||||
get { return SwfTagType.End; }
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class FileAttributesTag : SwfTagBase {
|
||||
public override SwfTagType TagType {
|
||||
get { return SwfTagType.FileAttributes; }
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class FrameLabelTag : SwfTagBase {
|
||||
public string Name;
|
||||
public byte AnchorFlag;
|
||||
@@ -18,7 +18,7 @@
|
||||
var tag = new FrameLabelTag();
|
||||
tag.Name = reader.ReadString();
|
||||
if ( !reader.IsEOF ) {
|
||||
tag.AnchorFlag = reader.Reader.ReadByte();
|
||||
tag.AnchorFlag = reader.ReadByte();
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Text;
|
||||
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class PlaceObject2Tag : SwfTagBase {
|
||||
public bool HasClipActions;
|
||||
public bool HasClipDepth;
|
||||
@@ -61,9 +61,9 @@ namespace FlashTools.Internal.SwfTags {
|
||||
tag.HasMatrix = reader.ReadBit();
|
||||
tag.HasCharacter = reader.ReadBit();
|
||||
tag.Move = reader.ReadBit();
|
||||
tag.Depth = reader.Reader.ReadUInt16();
|
||||
tag.Depth = reader.ReadUInt16();
|
||||
if ( tag.HasCharacter ) {
|
||||
tag.CharacterId = reader.Reader.ReadUInt16();
|
||||
tag.CharacterId = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasMatrix ) {
|
||||
tag.Matrix = SwfMatrix.Read(reader);
|
||||
@@ -72,13 +72,13 @@ namespace FlashTools.Internal.SwfTags {
|
||||
tag.ColorTransform = SwfColorTransformRGBA.Read(reader);
|
||||
}
|
||||
if ( tag.HasRatio ) {
|
||||
tag.Ratio = reader.Reader.ReadUInt16();
|
||||
tag.Ratio = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasName ) {
|
||||
tag.Name = reader.ReadString();
|
||||
}
|
||||
if ( tag.HasClipDepth ) {
|
||||
tag.ClipDepth = reader.Reader.ReadUInt16();
|
||||
tag.ClipDepth = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasClipActions ) {
|
||||
tag.ClipActions = SwfClipActions.Read(reader);
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Text;
|
||||
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class PlaceObject3Tag : SwfTagBase {
|
||||
public bool HasClipActions;
|
||||
public bool HasClipDepth;
|
||||
@@ -82,12 +82,12 @@ namespace FlashTools.Internal.SwfTags {
|
||||
tag.HasCacheAsBitmap = reader.ReadBit();
|
||||
tag.HasBlendMode = reader.ReadBit();
|
||||
tag.HasFilterList = reader.ReadBit();
|
||||
tag.Depth = reader.Reader.ReadUInt16();
|
||||
tag.Depth = reader.ReadUInt16();
|
||||
if ( tag.HasCharacter || (tag.HasImage && tag.HasCharacter) ) {
|
||||
tag.ClassName = reader.ReadString();
|
||||
}
|
||||
if ( tag.HasCharacter ) {
|
||||
tag.CharacterId = reader.Reader.ReadUInt16();
|
||||
tag.CharacterId = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasMatrix ) {
|
||||
tag.Matrix = SwfMatrix.Read(reader);
|
||||
@@ -96,25 +96,25 @@ namespace FlashTools.Internal.SwfTags {
|
||||
tag.ColorTransform = SwfColorTransformRGBA.Read(reader);
|
||||
}
|
||||
if ( tag.HasRatio ) {
|
||||
tag.Ratio = reader.Reader.ReadUInt16();
|
||||
tag.Ratio = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasName ) {
|
||||
tag.Name = reader.ReadString();
|
||||
}
|
||||
if ( tag.HasClipDepth ) {
|
||||
tag.ClipDepth = reader.Reader.ReadUInt16();
|
||||
tag.ClipDepth = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasFilterList ) {
|
||||
tag.SurfaceFilters = SwfSurfaceFilters.Read(reader);
|
||||
}
|
||||
if ( tag.HasBlendMode ) {
|
||||
tag.BlendMode = (SwfBlendMode)reader.Reader.ReadByte();
|
||||
tag.BlendMode = (SwfBlendMode)reader.ReadByte();
|
||||
}
|
||||
if ( tag.HasCacheAsBitmap ) {
|
||||
tag.BitmapCache = reader.Reader.ReadByte();
|
||||
tag.BitmapCache = reader.ReadByte();
|
||||
}
|
||||
if ( tag.HasVisible ) {
|
||||
tag.Visible = reader.Reader.ReadByte();
|
||||
tag.Visible = reader.ReadByte();
|
||||
tag.BackgroundColor = SwfRGBA.Read(reader);
|
||||
}
|
||||
if ( tag.HasClipActions ) {
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class PlaceObjectTag : SwfTagBase {
|
||||
public ushort CharacterId;
|
||||
public ushort Depth;
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
public static PlaceObjectTag Create(SwfStreamReader reader) {
|
||||
var tag = new PlaceObjectTag();
|
||||
tag.CharacterId = reader.Reader.ReadUInt16();
|
||||
tag.Depth = reader.Reader.ReadUInt16();
|
||||
tag.CharacterId = reader.ReadUInt16();
|
||||
tag.Depth = reader.ReadUInt16();
|
||||
tag.Matrix = SwfMatrix.Read(reader);
|
||||
if ( !reader.IsEOF ) {
|
||||
tag.ColorTransform = SwfColorTransformRGB.Read(reader);
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class RemoveObject2Tag : SwfTagBase {
|
||||
public ushort Depth;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
public static RemoveObject2Tag Create(SwfStreamReader reader) {
|
||||
var tag = new RemoveObject2Tag();
|
||||
tag.Depth = reader.Reader.ReadUInt16();
|
||||
tag.Depth = reader.ReadUInt16();
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class RemoveObjectTag : SwfTagBase {
|
||||
public ushort CharacterId;
|
||||
public ushort Depth;
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
public static RemoveObjectTag Create(SwfStreamReader reader) {
|
||||
var tag = new RemoveObjectTag();
|
||||
tag.CharacterId = reader.Reader.ReadUInt16();
|
||||
tag.Depth = reader.Reader.ReadUInt16();
|
||||
tag.CharacterId = reader.ReadUInt16();
|
||||
tag.Depth = reader.ReadUInt16();
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class SetBackgroundColorTag : SwfTagBase {
|
||||
public SwfRGB BackgroundColor;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class SetTabIndexTag : SwfTagBase {
|
||||
public ushort Depth;
|
||||
public ushort TabIndex;
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
public static SetTabIndexTag Create(SwfStreamReader reader) {
|
||||
var tag = new SetTabIndexTag();
|
||||
tag.Depth = reader.Reader.ReadUInt16();
|
||||
tag.TabIndex = reader.Reader.ReadUInt16();
|
||||
tag.Depth = reader.ReadUInt16();
|
||||
tag.TabIndex = reader.ReadUInt16();
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class ShowFrameTag : SwfTagBase {
|
||||
public override SwfTagType TagType {
|
||||
get { return SwfTagType.ShowFrame; }
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.IO;
|
||||
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
enum SwfTagType {
|
||||
// -----------------------------
|
||||
// Display list
|
||||
@@ -134,23 +132,26 @@ namespace FlashTools.Internal.SwfTags {
|
||||
Unknown
|
||||
}
|
||||
|
||||
struct SwfTagData {
|
||||
public int TagId;
|
||||
public byte[] TagData;
|
||||
abstract class SwfTagBase {
|
||||
struct SwfTagData {
|
||||
public int TagId;
|
||||
public byte[] TagData;
|
||||
}
|
||||
|
||||
public static SwfTagData Read(SwfStreamReader reader) {
|
||||
var type_and_size = reader.Reader.ReadUInt16();
|
||||
public abstract SwfTagType TagType { get; }
|
||||
|
||||
public static SwfTagBase Read(SwfStreamReader reader) {
|
||||
var type_and_size = reader.ReadUInt16();
|
||||
var tag_id = type_and_size >> 6;
|
||||
var short_size = type_and_size & 0x3f;
|
||||
var size = short_size < 0x3f ? short_size : reader.Reader.ReadInt32();
|
||||
var tag_data = reader.Reader.ReadBytes(size);
|
||||
return new SwfTagData{TagId = tag_id, TagData = tag_data};
|
||||
var size = short_size < 0x3f ? short_size : reader.ReadInt32();
|
||||
var tag_data = reader.ReadBytes(size);
|
||||
return Create(new SwfTagData{
|
||||
TagId = tag_id,
|
||||
TagData = tag_data});
|
||||
}
|
||||
}
|
||||
|
||||
abstract class SwfTagBase {
|
||||
public abstract SwfTagType TagType { get; }
|
||||
public static SwfTagBase Create(SwfTagData tag_data) {
|
||||
static SwfTagBase Create(SwfTagData tag_data) {
|
||||
var reader = new SwfStreamReader(tag_data.TagData);
|
||||
switch ( tag_data.TagId ) {
|
||||
case (int)SwfTagType.PlaceObject: return PlaceObjectTag.Create(reader);
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FlashTools.Internal.SwfTags {
|
||||
namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
class UnknownTag : SwfTagBase {
|
||||
public int TagId;
|
||||
|
||||
Reference in New Issue
Block a user