private void Import(Stream Source) { // Format from http://simswiki.info/wiki.php?title=Sims_3:0x6B20C4F3 // Read Main Header //Stream F = File.Create(@"C:\temp\clips\test.clip"); //Source.CopyTo(F); //F.Close(); //Source.Position = 0; BinaryReader Reader = new BinaryReader(Source); UInt32 TID = Reader.ReadUInt32(); if (TID != 0x6b20c4f3) throw new InvalidDataException(); UInt32 Offset = Reader.ReadUInt32(); UInt32 ClipSize = Reader.ReadUInt32(); UInt32 ClipOffset = (UInt32)Reader.BaseStream.Position + Reader.ReadUInt32(); UInt32 SlotOffset = (UInt32)Reader.BaseStream.Position + Reader.ReadUInt32(); UInt32 ActorOffset = (UInt32)Reader.BaseStream.Position + Reader.ReadUInt32(); UInt32 EventOffset = (UInt32)Reader.BaseStream.Position + Reader.ReadUInt32(); Unknown1 = Reader.ReadUInt32(); Unknown2 = Reader.ReadUInt32(); UInt32 EndOffset = Reader.ReadUInt32(); byte[] Buffer = Reader.ReadBytes(16); // get the end buffer values Reader.BaseStream.Position = EndOffset; EndData = new Single[4]; EndData[0] = Reader.ReadSingle(); EndData[1] = Reader.ReadSingle(); EndData[2] = Reader.ReadSingle(); EndData[3] = Reader.ReadSingle(); // Get Clip Stream ClipStream = new SubStream(Source, ClipOffset, ClipSize); ImportClip(ClipStream); // Get Slot Table Stream SlotStream = new SubStream(Source, SlotOffset, ActorOffset - SlotOffset); ImportSlotTable(SlotStream); // Get Actor Name Reader.BaseStream.Position = ActorOffset; int actorlen = (int)(EventOffset - ActorOffset); ActorName = ReadNullASCIIString(Reader, actorlen); // Get Event Table Reader.BaseStream.Position = EventOffset; string ceSIG = Encoding.ASCII.GetString(Reader.ReadBytes(4)); if (ceSIG != "=CE=") throw new InvalidDataException(); UInt32 ceVersion = Reader.ReadUInt32(); if (ceVersion != 0x0103) throw new InvalidDataException(); UInt32 ceCount = Reader.ReadUInt32(); UInt32 ceSize = Reader.ReadUInt32(); UInt32 ceOffset = Reader.ReadUInt32(); ClipTable = new ClipEvent[ceCount]; for (int ceI = 0; ceI < ceCount; ceI++) { UInt16 ceType = Reader.ReadUInt16(); ClipEvent Event; switch (ceType) { case 1: Event = new ClipEventAttach(); break; case 2: Event = new ClipEventUnParent(); break; case 3: Event = new ClipEventPlaySound(); break; case 4: Event = new ClipEventSACS(); break; case 5: Event = new ClipEventPlayEffect(); break; case 6: Event = new ClipEventVisibility(); break; case 9: Event = new ClipEventDestroyProp(); break; case 10: Event = new ClipEventStopEffect(); break; default: throw new InvalidDataException(); } ClipTable[ceI] = Event; Event.Import(Reader); //Console.WriteLine(Event.ToString()); } Source.Close(); }
public void PlayAnimation(ClipEvent clipEvent) { Format.MovieClipEvent[] clipEvents = m_lwf.data.movieClipEvents; for (int i = 0; i < m_data.clipEvents; ++i) { Format.MovieClipEvent c = clipEvents[m_data.clipEventId + i]; if ((c.clipEvent & (int)clipEvent) != 0) m_lwf.PlayAnimation(c.animationId, this); } }