private PoseEffect ParseEffect(BinaryDataReader reader) { var count = reader.ReadUInt16(); var events = new PoseEvent[count]; for (int i = 0; i < events.Length; i++) { var ev = new PoseEvent(); ev.Time = reader.ReadFloat40(); ev.Type = reader.ReadByte(); switch (ev.Type) { case 0: var resnm = reader.ReadCString(); var resver = reader.ReadUInt16(); ev.ResRef = new ResourceRef(resnm, resver); ev.Data = reader.ReadBytes(reader.ReadByte()); break; case 1: ev.Id = reader.ReadCString(); break; default: throw new ResourceException("Illegal control event: " + ev.Type); } events[i] = ev; } return(new PoseEffect { Events = events.ToArray() }); }
protected override SkeletonLayer Deserialize(BinaryDataReader reader) { var bones = new List <SkeletonBone>(); while (reader.HasRemaining) { var bone = new SkeletonBone(); bone.Name = reader.ReadCString(); bone.Position = new float[3]; for (int i = 0; i < 3; i++) { bone.Position[i] = (float)reader.ReadFloat40(); } bone.RotationAxis = new float[3]; for (int i = 0; i < 3; i++) { bone.RotationAxis[i] = (float)reader.ReadFloat40(); } bone.RotationAngle = (float)reader.ReadFloat40(); bone.Parent = reader.ReadCString(); bones.Add(bone); } return(new SkeletonLayer { Bones = bones.ToArray() }); }
protected override ActionLayer Deserialize(BinaryDataReader reader) { var action = new ActionLayer(); action.Parent = new ResourceRef(reader.ReadCString(), reader.ReadUInt16()); action.Name = reader.ReadCString(); action.Prerequisite = reader.ReadCString(); action.Hotkey = (char)reader.ReadUInt16(); action.Verbs = new string[reader.ReadUInt16()]; for (int i = 0; i < action.Verbs.Length; i++) { action.Verbs[i] = reader.ReadCString(); } return(action); }
protected override MaterialLayer Deserialize(BinaryDataReader reader) { var layer = new MaterialLayer(); layer.Id = reader.ReadUInt16(); // read materials var materials = new List <MaterialLayer.Part>(); while (reader.HasRemaining) { var mat = new MaterialLayer.Part(); mat.Name = reader.ReadCString(); mat.Properties = reader.ReadList(); materials.Add(mat); // WTF, loftar? switch (mat.Name) { case "linear": layer.IsLinear = true; break; case "mipmap": layer.IsMipmap = true; break; } } layer.Parts = materials.ToArray(); return(layer); }
private static VertexLayer.Bone ReadBone(BinaryDataReader reader) { var boneName = reader.ReadCString(); if (string.IsNullOrEmpty(boneName)) { return(null); } var vertices = new List <VertexLayer.BoneVertex>(); while (true) { var run = reader.ReadUInt16(); var vn = reader.ReadUInt16(); if (run == 0) { break; } var weights = new float[run]; for (int i = 0; i < run; i++) { weights[i] = reader.ReadSingle(); } vertices.Add(new VertexLayer.BoneVertex { Vn = vn, Weights = weights }); } return(new VertexLayer.Bone { Name = boneName, Vertices = vertices.ToArray() }); }
public static GobDelta.Speech ReadGobSpeech(this BinaryDataReader reader) { return(new GobDelta.Speech { Offset = reader.ReadInt32Coord(), Text = reader.ReadCString() }); }
public static GobDelta.CompositeEqu ReadGobCompositeEqu(this BinaryDataReader reader) { while (true) { int h = reader.ReadByte(); if (h == 255) break; int ef = h & 0x80; int et = h & 0x7f; string at = reader.ReadCString(); int resId = reader.ReadUInt16(); if ((resId & 0x8000) != 0) { resId &= ~0x8000; reader.ReadBytes(reader.ReadByte()); } Point3F off; if ((ef & 128) != 0) { int x = reader.ReadInt16(); int y = reader.ReadInt16(); int z = reader.ReadInt16(); off = new Point3F(x / 1000.0f, y / 1000.0f, z / 1000.0f); } else { off = Point3F.Empty; } } return new GobDelta.CompositeEqu(); }
protected override PoseLayer Deserialize(BinaryDataReader reader) { var pose = new PoseLayer(); pose.Id = reader.ReadInt16(); pose.Flags = reader.ReadByte(); pose.Mode = reader.ReadByte(); pose.Length = reader.ReadFloat40(); if ((pose.Flags & 1) != 0) { pose.Speed = reader.ReadFloat40(); } var effects = new List <PoseEffect>(); var tracks = new List <PoseTrack>(); while (reader.HasRemaining) { var boneName = reader.ReadCString(); if (boneName == "{ctl}") { effects.Add(ParseEffect(reader)); } else { tracks.Add(new PoseTrack { BoneName = boneName, Frames = ParseFrames(reader) }); } } pose.Effects = effects.ToArray(); pose.Tracks = tracks.ToArray(); return(pose); }
public static WidgetMessage ReadWidgetMessageEvent(this BinaryDataReader reader) { var widgetId = reader.ReadUInt16(); var name = reader.ReadCString(); object[] args; // HACK: workaround for a bugged i-atime message in the BuddyWidget if (name == "i-atime") { // read one integer parameter from the list args = new object[1]; reader.ReadByte(); args[0] = reader.ReadInt32(); // skip remaining data while (true) { if (!reader.HasRemaining || reader.ReadByte() == (byte)BinaryListType.End) { break; } } } else { args = reader.ReadList(); } return(new WidgetMessage { WidgetId = widgetId, Name = name, Args = args }); }
public static MapUpdateGrid ReadMapUpdateEvent(this BinaryDataReader reader) { var msg = new MapUpdateGrid { Coord = reader.ReadInt32Coord(), MinimapName = reader.ReadCString(), Overlays = new int[100 * 100] }; var pfl = new byte[256]; while (true) { int pidx = reader.ReadByte(); if (pidx == 255) { break; } pfl[pidx] = reader.ReadByte(); } reader = new BinaryDataReader(Unpack(reader.ReadRemaining())); msg.Tiles = reader.ReadBytes(100 * 100); while (true) { int pidx = reader.ReadByte(); if (pidx == 255) { break; } int fl = pfl[pidx]; int type = reader.ReadByte(); var c1 = new Point2D(reader.ReadByte(), reader.ReadByte()); var c2 = new Point2D(reader.ReadByte(), reader.ReadByte()); int ol; if (type == 0) { ol = ((fl & 1) == 1) ? 2 : 1; } else if (type == 1) { ol = ((fl & 1) == 1) ? 8 : 4; } else { continue; } for (int y = c1.Y; y <= c2.Y; y++) { for (int x = c1.X; x <= c2.X; x++) { msg.Overlays[y * 100 + x] |= ol; } } } return(msg); }
public static LoadResource ReadResourceLoadEvent(this BinaryDataReader reader) { return(new LoadResource { ResourceId = reader.ReadUInt16(), Name = reader.ReadCString(), Version = reader.ReadUInt16() }); }
public static GobDelta.Buddy ReadGobBuddy(this BinaryDataReader reader) { return(new GobDelta.Buddy { Name = reader.ReadCString(), Group = reader.ReadByte(), Type = reader.ReadByte() }); }
protected override CodeLayer Deserialize(BinaryDataReader reader) { var code = new CodeLayer(); code.Name = reader.ReadCString(); code.ByteCode = reader.ReadRemaining(); return(code); }
public static WidgetMessage ReadWidgetMessageEvent(this BinaryDataReader reader) { return(new WidgetMessage { WidgetId = reader.ReadUInt16(), Name = reader.ReadCString(), Args = reader.ReadList() }); }
public static GobDelta.Speech ReadGobSpeech(this BinaryDataReader reader) { return new GobDelta.Speech { Offset = reader.ReadInt16() / 100.0f, Text = reader.ReadCString() }; }
private static SpriteLink.Resource ReadResourceLink(BinaryDataReader reader) { var name = reader.ReadCString(); var version = reader.ReadUInt16(); return(new SpriteLink.Resource { Name = name, Version = version }); }
private static void ReadArray(VertexLayer layer, BinaryDataReader reader) { var vertexCount = layer.VertexCount; var type = reader.ReadCString(); switch (type) { case "pos": layer.Positions = ReadArray(ReadFloat, reader, vertexCount * 3); break; case "nrm": layer.Normals = ReadArray(ReadFloat, reader, vertexCount * 3); break; case "tan": layer.Tangents = ReadArray(ReadFloat, reader, vertexCount * 3); break; case "bit": layer.Bitangents = ReadArray(ReadFloat, reader, vertexCount * 3); break; case "col": layer.Colors = ReadArray(ReadFloat, reader, vertexCount * 4); break; case "tex": layer.TexCoords = ReadArray(ReadFloat, reader, vertexCount * 2); break; case "otex": layer.OverlayTexCoords = ReadArray(ReadFloat, reader, vertexCount * 2); break; case "bones": layer.Bones = new VertexLayer.BoneArray(); layer.Bones.Mba = reader.ReadByte(); var bones = new List <VertexLayer.Bone>(); while (true) { var bone = ReadBone(reader); if (bone == null) { break; } bones.Add(bone); } layer.Bones.Bones = bones.ToArray(); break; default: throw new ResourceException("Unsupported vertex attrib array type: " + type); } }
protected override CodeEntryLayer Deserialize(BinaryDataReader reader) { var entries = new List <CodeEntry>(); var classpath = new List <ResourceRef>(); while (reader.HasRemaining) { var type = reader.ReadByte(); switch (type) { case EntriesPart: while (true) { var name = reader.ReadCString(); var className = reader.ReadCString(); if (name.Length == 0) { break; } entries.Add(new CodeEntry(name, className)); } break; case ClasspathPart: while (true) { var ln = reader.ReadCString(); if (ln.Length == 0) { break; } var ver = reader.ReadUInt16(); classpath.Add(new ResourceRef(ln, ver)); } break; } } return(new CodeEntryLayer { Entries = entries.ToArray(), Classpath = classpath.ToArray() }); }
protected override Tileset2Layer Deserialize(BinaryDataReader reader) { var data = new Tileset2Layer(); while (reader.HasRemaining) { var part = reader.ReadByte(); switch (part) { case Tiler: data.TilerName = reader.ReadCString(); data.TilerAttributes = reader.ReadList(); break; case Flavor: var flavorCount = reader.ReadUInt16(); data.FlavorDensity = reader.ReadUInt16(); data.FlavorObjects = new FlavorObjectData[flavorCount]; for (int i = 0; i < flavorCount; i++) { var fob = new FlavorObjectData(); fob.Resource = new ResourceRef(reader.ReadCString(), reader.ReadUInt16()); fob.Weight = reader.ReadByte(); data.FlavorObjects[i] = fob; } break; case Tags: data.Tags = new string[reader.ReadByte()]; for (int i = 0; i < data.Tags.Length; i++) { data.Tags[i] = reader.ReadCString(); } break; default: throw new ResourceException($"Invalid tileset part {part}"); } } return(data); }
public static GobDelta.Buddy ReadGobBuddy(this BinaryDataReader reader) { var name = reader.ReadCString(); byte group = 0; byte type = 0; if (!string.IsNullOrEmpty(name)) { group = reader.ReadByte(); type = reader.ReadByte(); } return new GobDelta.Buddy { Name = name, Group = group, Type = type }; }
private object ReadLayer(BinaryDataReader buffer) { var layerName = buffer.ReadCString(); if (string.IsNullOrEmpty(layerName)) { return(null); } var size = buffer.ReadInt32(); var layerBuffer = new BinaryDataReader(buffer, size); return(handlerProvider.GetByName(layerName).Deserialize(layerBuffer)); }
public static BuffUpdate ReadBuffUpdateEvent(this BinaryDataReader reader) { return(new BuffUpdate { Id = reader.ReadInt32(), ResourceId = reader.ReadUInt16(), Tooltip = reader.ReadCString(), AMeter = reader.ReadInt32(), NMeter = reader.ReadInt32(), CMeter = reader.ReadInt32(), CTicks = reader.ReadInt32(), IsMajor = reader.ReadByte() != 0 }); }
protected override MeshLayer Deserialize(BinaryDataReader reader) { var flags = reader.ReadByte(); if ((flags & ~15) != 0) { throw new ResourceException($"Unsupported flags in fastmesh: {flags}"); } var data = new MeshLayer(); var indexCount = reader.ReadUInt16(); data.Indexes = new short[indexCount * 3]; data.MaterialId = reader.ReadInt16(); data.Id = ((flags & 2) != 0) ? reader.ReadInt16() : (short)-1; data.Ref = ((flags & 4) != 0) ? reader.ReadInt16() : (short)-1; data.RData = new Dictionary <string, string>(); if ((flags & 8) != 0) { while (true) { var key = reader.ReadCString(); if (string.IsNullOrEmpty(key)) { break; } data.RData[key] = reader.ReadCString(); } } for (int i = 0; i < data.Indexes.Length; i++) { data.Indexes[i] = (short)reader.ReadUInt16(); } return(data); }
protected override AudioLayer Deserialize(BinaryDataReader reader) { var version = reader.ReadByte(); if (version != 1 && version != 2) { throw new ResourceException($"Unknown audio layer version: {version}"); } var data = new AudioLayer(); data.Id = reader.ReadCString(); data.BaseVolume = (version == 2) ? reader.ReadUInt16() / 1000.0 : 1.0; data.Data = reader.ReadRemaining(); return(data); }
public static GobDelta.Follow ReadGobFollow(this BinaryDataReader reader) { long oid = reader.ReadUInt32(); if (oid != 0xffffffffL) { var resId = reader.ReadUInt16(); var name = reader.ReadCString(); return new GobDelta.Follow { GobId = oid, ResId = resId, Name = name }; } return new GobDelta.Follow { GobId = oid }; }
public static WidgetCreate ReadWidgetCreateEvent(this BinaryDataReader reader) { var id = reader.ReadUInt16(); var type = reader.ReadCString(); var parentId = reader.ReadUInt16(); var pargs = reader.ReadList(); var cargs = reader.ReadList(); return(new WidgetCreate { Id = id, Type = type, ParentId = parentId, CArgs = cargs, PArgs = pargs }); }
protected override FoodEventLayer Deserialize(BinaryDataReader reader) { var version = reader.ReadByte(); if (version != 1) { throw new ResourceException($"Unknown foodev version: {version}"); } var data = new FoodEventLayer(); data.Color = reader.ReadColor(); data.Name = reader.ReadCString(); data.Sort = reader.ReadInt16(); return(data); }
public static LoadTilesets ReadTilesetsLoadEvent(this BinaryDataReader reader) { var tilesets = new List <TilesetBinding>(); while (reader.HasRemaining) { tilesets.Add(new TilesetBinding { Id = reader.ReadByte(), Name = reader.ReadCString(), Version = reader.ReadUInt16() }); } return(new LoadTilesets { Tilesets = tilesets.ToArray() }); }
public static UpdateCharAttributes ReadCharAttributesUpdateEvent(this BinaryDataReader reader) { var attributes = new List <CharAttribute>(); while (reader.HasRemaining) { attributes.Add(new CharAttribute { Name = reader.ReadCString(), BaseValue = reader.ReadInt32(), ModifiedValue = reader.ReadInt32() }); } return(new UpdateCharAttributes { Attributes = attributes.ToArray() }); }
public static WidgetCreate ReadWidgetCreateEvent(this BinaryDataReader reader) { var id = reader.ReadUInt16(); var type = reader.ReadCString(); var position = reader.ReadInt32Coord(); var parentId = reader.ReadUInt16(); var args = reader.ReadList(); return(new WidgetCreate { Id = id, Type = type, Position = position, ParentId = parentId, Args = args }); }