public static Vdf ParseVdf(string filename) { using (Bwd2Reader br = new Bwd2Reader(filename)) { Vdf vdf = new Vdf(); br.FindNext("VDFC"); vdf.Name = br.ReadCString(20); vdf.VehicleType = br.ReadUInt32(); vdf.VehicleSize = br.ReadUInt32(); vdf.LODDistance1 = br.ReadSingle(); vdf.LODDistance2 = br.ReadSingle(); vdf.LODDistance3 = br.ReadSingle(); vdf.LODDistance4 = br.ReadSingle(); vdf.LODDistance5 = br.ReadSingle(); vdf.Mass = br.ReadSingle(); vdf.CollisionMultiplier = br.ReadSingle(); vdf.DragCoefficient = br.ReadSingle(); vdf.Unknown = br.ReadUInt32(); if (br.Current.DataLength == 77) { vdf.EltFile = br.ReadCString(13); } br.FindNext("SOBJ"); vdf.SOBJGeoName = br.ReadCString(8); vdf.VLocs = new List <VLoc>(); br.FindNext("VLOC"); while (br.Current != null && br.Current.Name != "EXIT") { VLoc vloc = new VLoc { Number = br.ReadUInt32(), Right = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), Up = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), Forward = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), Position = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()) }; vdf.VLocs.Add(vloc); br.Next(); } br.FindNext("VGEO"); uint numParts = br.ReadUInt32(); vdf.PartsThirdPerson = new List <SdfPart[]>(4); for (int damageState = 0; damageState < 4; damageState++) { SdfPart[] parts = new SdfPart[numParts]; for (int i = 0; i < numParts; i++) { SdfPart sdfPart = new SdfPart(); sdfPart.Name = br.ReadCString(8); sdfPart.Right = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); sdfPart.Up = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); sdfPart.Forward = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); sdfPart.Position = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); sdfPart.ParentName = br.ReadCString(8); br.Position += 36; parts[i] = sdfPart; } vdf.PartsThirdPerson.Add(parts); } br.Position += 100 * numParts * 12; vdf.PartsFirstPerson = new SdfPart[numParts]; for (int i = 0; i < numParts; i++) { SdfPart sdfPart = new SdfPart(); sdfPart.Name = br.ReadCString(8); sdfPart.Right = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); sdfPart.Up = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); sdfPart.Forward = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); sdfPart.Position = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); sdfPart.ParentName = br.ReadCString(8); br.Position += 36; vdf.PartsFirstPerson[i] = sdfPart; } br.FindNext("COLP"); float zMaxOuter = br.ReadSingle(); float zMaxInner = br.ReadSingle(); float zMinInner = br.ReadSingle(); float zMinOuter = br.ReadSingle(); float xMaxOuter = br.ReadSingle(); float xMaxInner = br.ReadSingle(); float xMinInner = br.ReadSingle(); float xMinOuter = br.ReadSingle(); float yMaxOuter = br.ReadSingle(); float yMaxInner = br.ReadSingle(); float yMinInner = br.ReadSingle(); float yMinOuter = br.ReadSingle(); Bounds innerBounds = new Bounds(); innerBounds.SetMinMax(new Vector3(xMinInner, yMinInner, zMinInner), new Vector3(xMaxInner, yMaxInner, zMaxInner)); vdf.BoundsInner = innerBounds; Bounds outerBounds = new Bounds(); outerBounds.SetMinMax(new Vector3(xMinOuter, yMinOuter, zMinOuter), new Vector3(xMaxOuter, yMaxOuter, zMaxOuter)); vdf.BoundsOuter = outerBounds; br.FindNext("WLOC"); vdf.WheelLoc = new WheelLoc[6]; for (int i = 0; i < 6; i++) { WheelLoc wheelLoc = vdf.WheelLoc[i] = new WheelLoc(); uint unk1 = br.ReadUInt32(); wheelLoc.Right = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); wheelLoc.Up = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); wheelLoc.Forward = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); wheelLoc.Position = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); float unk2 = br.ReadSingle(); } vdf.HLocs = new List <HLoc>(); br.FindNext("HLOC"); while (br.Current != null && br.Current.Name != "EXIT") { HLoc hloc = new HLoc { Label = br.ReadCString(16), HardpointIndex = br.ReadUInt32(), FacingDirection = br.ReadUInt32(), MeshType = (HardpointMeshType)br.ReadUInt32(), Right = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), Up = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), Forward = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), Position = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), Unk = br.ReadSingle() }; vdf.HLocs.Add(hloc); br.Next(); } if (!SpriteManager.Instance.Initialised) { if (vdf.EltFile == null) { vdf.Etbls = new List <ETbl>(); br.FindNext("ETBL"); while (br.Current != null && br.Current.Name != "EXIT") { long tableEnd = br.Current.DataPosition + br.Current.DataLength; while (br.Position < tableEnd) { ETbl etbl = new ETbl { MapFile = br.ReadCString(13), IsReferenceImage = br.ReadUInt32() == 1, ItemCount = br.ReadUInt32(), }; uint itemCount = etbl.ItemCount; etbl.Items = new Dictionary <string, ETbl.ETblItem>((int)itemCount); for (uint i = 0; i < itemCount; ++i) { ETbl.ETblItem etblItem = new ETbl.ETblItem { Name = br.ReadCString(16), XOffset = br.ReadInt32(), YOffset = br.ReadInt32(), Width = br.ReadInt32(), Height = br.ReadInt32() }; etbl.Items.Add(etblItem.Name, etblItem); } vdf.Etbls.Add(etbl); } br.Next(); } } else { vdf.Etbls = EltParser.ParseElt(vdf.EltFile); } if (vdf.Etbls != null && vdf.Etbls.Count > 0) { SpriteManager.Instance.Initialise(vdf); } } return(vdf); } }
public static List <ETbl> ParseElt(string fileName) { List <ETbl> etblList = new List <ETbl>(); using (FastBinaryReader br = VirtualFilesystem.Instance.GetFileStream(fileName)) { string eltText = Encoding.ASCII.GetString(br.Data, (int)br.Position, br.Length - (int)br.Position); string[] lines = eltText.Split('\n'); ETbl currentEtbl = null; int lineCount = lines.Length; for (int i = 0; i < lineCount; ++i) { string[] lineParts = lines[i].Trim().Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int linePartCount = lineParts.Length; if (linePartCount == 2) { if (currentEtbl != null) { currentEtbl.ItemCount = (uint)currentEtbl.Items.Count; etblList.Add(currentEtbl); } currentEtbl = new ETbl { IsReferenceImage = lineParts[0] == "dst", MapFile = lineParts[1], Items = new Dictionary <string, ETbl.ETblItem>() }; } else if (linePartCount == 6) { if (currentEtbl == null) { Debug.LogErrorFormat("Received ETBL data before ETBL was declared."); continue; } ETbl.ETblItem item = new ETbl.ETblItem { Name = lineParts[1], XOffset = int.Parse(lineParts[2]), YOffset = int.Parse(lineParts[3]), Width = int.Parse(lineParts[4]), Height = int.Parse(lineParts[5]) }; currentEtbl.Items.Add(item.Name, item); } else if (linePartCount > 0) { Debug.LogErrorFormat("Unexpected word count in ELT file on line {0}. Found {1} words.'", i, linePartCount); } } if (currentEtbl != null) { currentEtbl.ItemCount = (uint)currentEtbl.Items.Count; etblList.Add(currentEtbl); } } return(etblList); }