// Finds the correct type of AnimEntity and returns the data. // TODO: Ideally move this to our friend MemoryStream. public static AnimEntityWrapper ReadAnimEntityWrapperFromFile(AnimEntityTypes EntityType, MemoryStream Reader) { // Construct our AnimEntity AnimEntityWrapper Entity = ConstructAnimEntityWrapper(EntityType); bool isBigEndian = false; // Make sure our entity is not valid, and read our data if (Entity != null) { Entity.ReadFromFile(Reader, isBigEndian); } Debug.Assert(Entity != null, "Did not find a AnimEntityType. Maybe the Toolkit does not support it?"); Debug.Assert(Reader.Position == Reader.Length, "When reading the AnimEntity Definition, we did not reach the end of stream!"); return(Entity); }
private string CutsceneName; // For debugging public void ReadFromFile(BinaryReader reader, string name) { CutsceneName = name; int magic = reader.ReadInt32(); if (magic == 1000) { //the size includes the size and the magic, A.K.A: (magic and size == 8) Size = reader.ReadUInt32(); int fourcc = reader.ReadInt32(); if (fourcc == 0x21445053) { Unk01 = reader.ReadInt32(); Unk02 = reader.ReadSingle(); int NumEntities = reader.ReadInt32(); EntityDefinitions = new AnimEntityWrapper[NumEntities]; for (int i = 0; i < NumEntities; i++) { int Header = reader.ReadInt32(); Debug.Assert(Header == 126, "We've missed the entity definition Magic!"); // Or 0x7F int Size = reader.ReadInt32(); int RawAnimEntityType = reader.ReadInt32(); AnimEntityTypes AnimEntityType = (AnimEntityTypes)RawAnimEntityType; byte[] DefintionData = reader.ReadBytes(Size - 12); using (MemoryStream Reader = new MemoryStream(DefintionData)) { AnimEntityWrapper Entity = CutsceneEntityFactory.ReadAnimEntityWrapperFromFile(AnimEntityType, Reader); // Debugging: If the AnimEntity is null and a debugger is attached, we should save it to the disc. string format = string.Format("CutsceneInfo/{0}/Entity_SPD_{1}_{2}.bin", CutsceneName, AnimEntityType, i); File.WriteAllBytes(format, DefintionData); EntityDefinitions[i] = Entity; } } for (int z = 0; z < NumEntities; z++) { // Export this first int dataType = reader.ReadInt32(); int entitySize = reader.ReadInt32(); reader.BaseStream.Position -= 8; byte[] dataBytes = reader.ReadBytes(entitySize); string format = string.Format("CutsceneInfo/{2}/{0}_SPD_{1}.bin", EntityDefinitions[z], z, CutsceneName); File.WriteAllBytes(format, dataBytes); // And then This using (MemoryStream stream = new MemoryStream(dataBytes)) { EntityDefinitions[z].AnimEntityData.ReadFromFile(stream, false); } } } } }
public void ReadFromFile(BinaryReader reader, string name) { CutsceneName = name; header = new string(reader.ReadChars(4)); unk02 = reader.ReadInt32(); unk03 = reader.ReadSingle(); unk04 = reader.ReadInt16(); unk05 = reader.ReadInt16(); unk06 = reader.ReadInt32(); unk07 = reader.ReadInt32(); unk08 = reader.ReadBytes(unk07 - 4); unk09 = reader.ReadInt32(); numEntities = reader.ReadUInt16(); entities = new AnimEntityWrapper[numEntities]; for (int i = 0; i < numEntities; i++) { int Header = reader.ReadInt32(); Debug.Assert(Header == 126, "We've missed the entity definition Magic!"); // Or 0x7F int Size = reader.ReadInt32(); int RawAnimEntityType = reader.ReadInt32(); AnimEntityTypes AnimEntityType = (AnimEntityTypes)RawAnimEntityType; byte[] DefintionData = reader.ReadBytes(Size - 12); using (MemoryStream Reader = new MemoryStream(DefintionData)) { AnimEntityWrapper EntityWrapper = CutsceneEntityFactory.ReadAnimEntityWrapperFromFile(AnimEntityType, Reader); string format = string.Format("CutsceneInfo/{2}/Entity_{0}_{1}.bin", AnimEntityType, i, CutsceneName); File.WriteAllBytes(format, DefintionData); entities[i] = EntityWrapper; } } for (int z = 0; z < numEntities; z++) { // Export this first int dataType = reader.ReadInt32(); int size = reader.ReadInt32(); reader.BaseStream.Position -= 8; byte[] dataBytes = reader.ReadBytes(size); string format = string.Format("CutsceneInfo/{2}/{0}_{1}.bin", entities[z], z, CutsceneName); File.WriteAllBytes(format, dataBytes); // And then This using (MemoryStream stream = new MemoryStream(dataBytes)) { entities[z].AnimEntityData.ReadFromFile(stream, false); Debug.Assert(stream.Position == stream.Length, "When reading the AnimEntity Data, we did not reach the end of the stream!"); } } unk10 = reader.ReadInt32(); unk11 = reader.ReadSingle(); unk12 = reader.ReadInt32(); unk13 = reader.ReadSingle(); unk14 = reader.ReadInt32(); }
public static AnimEntityWrapper ConstructAnimEntityWrapper(AnimEntityTypes EntityType) { AnimEntityWrapper Entity = new AnimEntityWrapper(); switch (EntityType) { case AnimEntityTypes.AeOmniLight: Entity = new AeOmniLightWrapper(); break; case AnimEntityTypes.AeSpotLight: Entity = new AeSpotLightWrapper(); break; case AnimEntityTypes.AeCamera: Entity = new AeCameraWrapper(); break; case AnimEntityTypes.AeTargetCamera: Entity = new AeTargetCameraWrapper(); break; case AnimEntityTypes.AeModel: Entity = new AeModelWrapper(); break; case AnimEntityTypes.AeUnk7: Entity = new AeUnk7Wrapper(); break; case AnimEntityTypes.AeSoundPoint: Entity = new AeSoundPointWrapper(); break; case AnimEntityTypes.AeScript: Entity = new AeScriptWrapper(); break; case AnimEntityTypes.AeSubtitles: Entity = new AeSubtitlesWrapper(); break; case AnimEntityTypes.AeParticles: Entity = new AeParticlesWrapper(); break; case AnimEntityTypes.AeCutEdit: Entity = new AeCutEditWrapper(); break; case AnimEntityTypes.AeVehicle: Entity = new AeVehicleWrapper(); break; case AnimEntityTypes.AeFrame: Entity = new AeFrameWrapper(); break; case AnimEntityTypes.AeHumanFx: Entity = new AeHumanFxWrapper(); break; case AnimEntityTypes.AeEffects: Entity = new AeEffectsWrapper(); break; case AnimEntityTypes.AeSoundSphereAmbient: Entity = new AeSoundSphereAmbientWrapper(); break; case AnimEntityTypes.AeSunLight: Entity = new AeSunLightWrapper(); break; case AnimEntityTypes.AeSoundListener: Entity = new AeSoundListenerWrapper(); break; case AnimEntityTypes.AeSoundEntity: Entity = new AeSoundEntityWrapper(); break; case AnimEntityTypes.AeUnk32: Entity = new AeUnk32Wrapper(); break; case AnimEntityTypes.AeSound_Type33: Entity = new AeSound_Type33Wrapper(); break; } return(Entity); }