public Data(byte[] bytes) { if (bytes.Length < (int)Format.Constant.HEADER_SIZE) { return; } Stream s = new MemoryStream(bytes); BinaryReader br = new BinaryReader(s); header = new Format.Header(br); if (!Check()) { return; } byte[] stringByteData = br.ReadBytes((int)header.stringBytes.length); byte[] animationByteData = br.ReadBytes((int)header.animationBytes.length); translates = new Translate[header.translate.length]; for (int i = 0; i < translates.Length; ++i) { translates[i] = new Translate(br); } matrices = new Matrix[header.matrix.length]; for (int i = 0; i < matrices.Length; ++i) { matrices[i] = new Matrix(br); } colors = new Color[header.color.length]; for (int i = 0; i < colors.Length; ++i) { colors[i] = new Color(br); } alphaTransforms = new AlphaTransform[header.alphaTransform.length]; for (int i = 0; i < alphaTransforms.Length; ++i) { alphaTransforms[i] = new AlphaTransform(br); } colorTransforms = new ColorTransform[header.colorTransform.length]; for (int i = 0; i < colorTransforms.Length; ++i) { colorTransforms[i] = new ColorTransform(br); } objects = new Format.Object[header.objectData.length]; for (int i = 0; i < objects.Length; ++i) { objects[i] = new Format.Object(br); } textures = new Format.Texture[header.texture.length]; for (int i = 0; i < textures.Length; ++i) { textures[i] = new Format.Texture(br); } textureFragments = new Format.TextureFragment[header.textureFragment.length]; for (int i = 0; i < textureFragments.Length; ++i) { textureFragments[i] = new Format.TextureFragment(br); } bitmaps = new Format.Bitmap[header.bitmap.length]; for (int i = 0; i < bitmaps.Length; ++i) { bitmaps[i] = new Format.Bitmap(br); } bitmapExs = new Format.BitmapEx[header.bitmapEx.length]; for (int i = 0; i < bitmapExs.Length; ++i) { bitmapExs[i] = new Format.BitmapEx(br); } fonts = new Format.Font[header.font.length]; for (int i = 0; i < fonts.Length; ++i) { fonts[i] = new Format.Font(br); } textProperties = new Format.TextProperty[header.textProperty.length]; for (int i = 0; i < textProperties.Length; ++i) { textProperties[i] = new Format.TextProperty(br); } texts = new Format.Text[header.text.length]; for (int i = 0; i < texts.Length; ++i) { texts[i] = new Format.Text(br); } particleDatas = new Format.ParticleData[header.particleData.length]; for (int i = 0; i < particleDatas.Length; ++i) { particleDatas[i] = new Format.ParticleData(br); } particles = new Format.Particle[header.particle.length]; for (int i = 0; i < particles.Length; ++i) { particles[i] = new Format.Particle(br); } programObjects = new Format.ProgramObject[header.programObject.length]; for (int i = 0; i < programObjects.Length; ++i) { programObjects[i] = new Format.ProgramObject(br); } graphicObjects = new Format.GraphicObject[header.graphicObject.length]; for (int i = 0; i < graphicObjects.Length; ++i) { graphicObjects[i] = new Format.GraphicObject(br); } graphics = new Format.Graphic[header.graphic.length]; for (int i = 0; i < graphics.Length; ++i) { graphics[i] = new Format.Graphic(br); } Format.Animation[] animationData = new Format.Animation[header.animation.length]; for (int i = 0; i < animationData.Length; ++i) { animationData[i] = new Format.Animation(br); } buttonConditions = new Format.ButtonCondition[header.buttonCondition.length]; for (int i = 0; i < buttonConditions.Length; ++i) { buttonConditions[i] = new Format.ButtonCondition(br); } buttons = new Format.Button[header.button.length]; for (int i = 0; i < buttons.Length; ++i) { buttons[i] = new Format.Button(br); } labels = new Format.Label[header.label.length]; for (int i = 0; i < labels.Length; ++i) { labels[i] = new Format.Label(br); } instanceNames = new Format.InstanceName[header.instanceName.length]; for (int i = 0; i < instanceNames.Length; ++i) { instanceNames[i] = new Format.InstanceName(br); } events = new Format.Event[header.eventData.length]; for (int i = 0; i < events.Length; ++i) { events[i] = new Format.Event(br); } places = new Format.Place[header.place.length]; for (int i = 0; i < places.Length; ++i) { places[i] = new Format.Place(br); } controlMoveMs = new Format.ControlMoveM[header.controlMoveM.length]; for (int i = 0; i < controlMoveMs.Length; ++i) { controlMoveMs[i] = new Format.ControlMoveM(br); } controlMoveCs = new Format.ControlMoveC[header.controlMoveC.length]; for (int i = 0; i < controlMoveCs.Length; ++i) { controlMoveCs[i] = new Format.ControlMoveC(br); } controlMoveMCs = new Format.ControlMoveMC[header.controlMoveMC.length]; for (int i = 0; i < controlMoveMCs.Length; ++i) { controlMoveMCs[i] = new Format.ControlMoveMC(br); } controls = new Format.Control[header.control.length]; for (int i = 0; i < controls.Length; ++i) { controls[i] = new Format.Control(br); } frames = new Format.Frame[header.frame.length]; for (int i = 0; i < frames.Length; ++i) { frames[i] = new Format.Frame(br); } movieClipEvents = new Format.MovieClipEvent[header.movieClipEvent.length]; for (int i = 0; i < movieClipEvents.Length; ++i) { movieClipEvents[i] = new Format.MovieClipEvent(br); } movies = new Format.Movie[header.movie.length]; for (int i = 0; i < movies.Length; ++i) { movies[i] = new Format.Movie(br); } movieLinkages = new Format.MovieLinkage[header.movieLinkage.length]; for (int i = 0; i < movieLinkages.Length; ++i) { movieLinkages[i] = new Format.MovieLinkage(br); } Format.String[] stringData = new Format.String[header.stringData.length]; for (int i = 0; i < stringData.Length; ++i) { stringData[i] = new Format.String(br); } animations = new int[animationData.Length][]; for (int i = 0; i < animationData.Length; ++i) { animations[i] = ReadAnimation(animationByteData, (int)animationData[i].animationOffset, (int)animationData[i].animationLength); } strings = new string[stringData.Length]; for (int i = 0; i < stringData.Length; ++i) { strings[i] = System.Text.Encoding.UTF8.GetString(stringByteData, (int)stringData[i].stringOffset, (int)stringData[i].stringLength); } stringMap = new Dictionary <string, int>(); for (int i = 0; i < strings.Length; ++i) { stringMap[strings[i]] = i; } instanceNameMap = new Dictionary <int, int>(); for (int i = 0; i < instanceNames.Length; ++i) { instanceNameMap[instanceNames[i].stringId] = i; } eventMap = new Dictionary <int, int>(); for (int i = 0; i < events.Length; ++i) { eventMap[events[i].stringId] = i; } movieLinkageMap = new Dictionary <int, int>(); movieLinkageNameMap = new Dictionary <int, int>(); for (int i = 0; i < movieLinkages.Length; ++i) { movieLinkageMap[movieLinkages[i].stringId] = i; movieLinkageNameMap[movieLinkages[i].movieId] = movieLinkages[i].stringId; } programObjectMap = new Dictionary <int, int>(); for (int i = 0; i < programObjects.Length; ++i) { programObjectMap[programObjects[i].stringId] = i; } labelMap = new Dictionary <int, int> [movies.Length]; for (int i = 0; i < movies.Length; ++i) { Format.Movie m = movies[i]; int o = m.labelOffset; Dictionary <int, int> map = new Dictionary <int, int>(); for (int j = 0; j < m.labels; ++j) { Format.Label l = labels[o + j]; map[l.stringId] = l.frameNo; } labelMap[i] = map; } for (int i = 0; i < textures.Length; ++i) { textures[i].SetFilename(this); } bitmapMap = new Dictionary <string, int>(); var bitmapList = new List <Format.Bitmap>(bitmaps); for (int i = 0; i < textureFragments.Length; ++i) { textureFragments[i].SetFilename(this); bitmapMap[textureFragments[i].filename] = bitmapList.Count; bitmapList.Add( new Format.Bitmap { matrixId = 0, textureFragmentId = i }); } bitmaps = bitmapList.ToArray(); }
public Data(byte[] bytes) { if (bytes.Length < (int)Format.Constant.HEADER_SIZE) return; Stream s = new MemoryStream(bytes); BinaryReader br = new BinaryReader(s); header = new Format.Header(br); if (!Check()) return; byte[] stringByteData = br.ReadBytes((int)header.stringBytes.length); byte[] animationByteData = br.ReadBytes((int)header.animationBytes.length); translates = new Translate[header.translate.length]; for (int i = 0; i < translates.Length; ++i) translates[i] = new Translate(br); matrices = new Matrix[header.matrix.length]; for (int i = 0; i < matrices.Length; ++i) matrices[i] = new Matrix(br); colors = new Color[header.color.length]; for (int i = 0; i < colors.Length; ++i) colors[i] = new Color(br); alphaTransforms = new AlphaTransform[header.alphaTransform.length]; for (int i = 0; i < alphaTransforms.Length; ++i) alphaTransforms[i] = new AlphaTransform(br); colorTransforms = new ColorTransform[header.colorTransform.length]; for (int i = 0; i < colorTransforms.Length; ++i) colorTransforms[i] = new ColorTransform(br); objects = new Format.Object[header.objectData.length]; for (int i = 0; i < objects.Length; ++i) objects[i] = new Format.Object(br); textures = new Format.Texture[header.texture.length]; for (int i = 0; i < textures.Length; ++i) textures[i] = new Format.Texture(br); textureFragments = new Format.TextureFragment[header.textureFragment.length]; for (int i = 0; i < textureFragments.Length; ++i) textureFragments[i] = new Format.TextureFragment(br); bitmaps = new Format.Bitmap[header.bitmap.length]; for (int i = 0; i < bitmaps.Length; ++i) bitmaps[i] = new Format.Bitmap(br); bitmapExs = new Format.BitmapEx[header.bitmapEx.length]; for (int i = 0; i < bitmapExs.Length; ++i) bitmapExs[i] = new Format.BitmapEx(br); fonts = new Format.Font[header.font.length]; for (int i = 0; i < fonts.Length; ++i) fonts[i] = new Format.Font(br); textProperties = new Format.TextProperty[header.textProperty.length]; for (int i = 0; i < textProperties.Length; ++i) textProperties[i] = new Format.TextProperty(br); texts = new Format.Text[header.text.length]; for (int i = 0; i < texts.Length; ++i) texts[i] = new Format.Text(br); particleDatas = new Format.ParticleData[header.particleData.length]; for (int i = 0; i < particleDatas.Length; ++i) particleDatas[i] = new Format.ParticleData(br); particles = new Format.Particle[header.particle.length]; for (int i = 0; i < particles.Length; ++i) particles[i] = new Format.Particle(br); programObjects = new Format.ProgramObject[header.programObject.length]; for (int i = 0; i < programObjects.Length; ++i) programObjects[i] = new Format.ProgramObject(br); graphicObjects = new Format.GraphicObject[header.graphicObject.length]; for (int i = 0; i < graphicObjects.Length; ++i) graphicObjects[i] = new Format.GraphicObject(br); graphics = new Format.Graphic[header.graphic.length]; for (int i = 0; i < graphics.Length; ++i) graphics[i] = new Format.Graphic(br); Format.Animation[] animationData = new Format.Animation[header.animation.length]; for (int i = 0; i < animationData.Length; ++i) animationData[i] = new Format.Animation(br); buttonConditions = new Format.ButtonCondition[header.buttonCondition.length]; for (int i = 0; i < buttonConditions.Length; ++i) buttonConditions[i] = new Format.ButtonCondition(br); buttons = new Format.Button[header.button.length]; for (int i = 0; i < buttons.Length; ++i) buttons[i] = new Format.Button(br); labels = new Format.Label[header.label.length]; for (int i = 0; i < labels.Length; ++i) labels[i] = new Format.Label(br); instanceNames = new Format.InstanceName[header.instanceName.length]; for (int i = 0; i < instanceNames.Length; ++i) instanceNames[i] = new Format.InstanceName(br); events = new Format.Event[header.eventData.length]; for (int i = 0; i < events.Length; ++i) events[i] = new Format.Event(br); places = new Format.Place[header.place.length]; for (int i = 0; i < places.Length; ++i) places[i] = new Format.Place(br); controlMoveMs = new Format.ControlMoveM[header.controlMoveM.length]; for (int i = 0; i < controlMoveMs.Length; ++i) controlMoveMs[i] = new Format.ControlMoveM(br); controlMoveCs = new Format.ControlMoveC[header.controlMoveC.length]; for (int i = 0; i < controlMoveCs.Length; ++i) controlMoveCs[i] = new Format.ControlMoveC(br); controlMoveMCs = new Format.ControlMoveMC[header.controlMoveMC.length]; for (int i = 0; i < controlMoveMCs.Length; ++i) controlMoveMCs[i] = new Format.ControlMoveMC(br); controls = new Format.Control[header.control.length]; for (int i = 0; i < controls.Length; ++i) controls[i] = new Format.Control(br); frames = new Format.Frame[header.frame.length]; for (int i = 0; i < frames.Length; ++i) frames[i] = new Format.Frame(br); movieClipEvents = new Format.MovieClipEvent[header.movieClipEvent.length]; for (int i = 0; i < movieClipEvents.Length; ++i) movieClipEvents[i] = new Format.MovieClipEvent(br); movies = new Format.Movie[header.movie.length]; for (int i = 0; i < movies.Length; ++i) movies[i] = new Format.Movie(br); movieLinkages = new Format.MovieLinkage[header.movieLinkage.length]; for (int i = 0; i < movieLinkages.Length; ++i) movieLinkages[i] = new Format.MovieLinkage(br); Format.String[] stringData = new Format.String[header.stringData.length]; for (int i = 0; i < stringData.Length; ++i) stringData[i] = new Format.String(br); animations = new int[animationData.Length][]; for (int i = 0; i < animationData.Length; ++i) { animations[i] = ReadAnimation(animationByteData, (int)animationData[i].animationOffset, (int)animationData[i].animationLength); } strings = new string[stringData.Length]; for (int i = 0; i < stringData.Length; ++i) { strings[i] = System.Text.Encoding.UTF8.GetString(stringByteData, (int)stringData[i].stringOffset, (int)stringData[i].stringLength); } stringMap = new Dictionary<string, int>(); for (int i = 0; i < strings.Length; ++i) stringMap[strings[i]] = i; instanceNameMap = new Dictionary<int, int>(); for (int i = 0; i < instanceNames.Length; ++i) instanceNameMap[instanceNames[i].stringId] = i; eventMap = new Dictionary<int, int>(); for (int i = 0; i < events.Length; ++i) eventMap[events[i].stringId] = i; movieLinkageMap = new Dictionary<int, int>(); movieLinkageNameMap = new Dictionary<int, int>(); for (int i = 0; i < movieLinkages.Length; ++i) { movieLinkageMap[movieLinkages[i].stringId] = i; movieLinkageNameMap[movieLinkages[i].movieId] = movieLinkages[i].stringId; } programObjectMap = new Dictionary<int, int>(); for (int i = 0; i < programObjects.Length; ++i) programObjectMap[programObjects[i].stringId] = i; labelMap = new Dictionary<int, int>[movies.Length]; for (int i = 0; i < movies.Length; ++i) { Format.Movie m = movies[i]; int o = m.labelOffset; Dictionary<int, int> map = new Dictionary<int, int>(); for (int j = 0; j < m.labels; ++j) { Format.Label l = labels[o + j]; map[l.stringId] = l.frameNo; } labelMap[i] = map; } for (int i = 0; i < textures.Length; ++i) textures[i].SetFilename(this); bitmapMap = new Dictionary<string, int>(); var bitmapList = new List<Format.Bitmap>(bitmaps); for (int i = 0; i < textureFragments.Length; ++i) { textureFragments[i].SetFilename(this); bitmapMap[textureFragments[i].filename] = bitmapList.Count; bitmapList.Add( new Format.Bitmap{matrixId = 0, textureFragmentId = i}); } bitmaps = bitmapList.ToArray(); }