private static void LoadPrototype(ulong id) { string path = String.Format("/resources/systemgenerated/prototypes/{0}.node", id); File protoFile = Assets.FindFile(path); if (protoFile == null) { Console.WriteLine("Unable to find {0}", path); } using (var fs = protoFile.Open()) using (var br = new GomBinaryReader(fs, Encoding.UTF8)) { // Check PROT int magicNum = br.ReadInt32(); if (magicNum != 0x544F5250) { throw new InvalidOperationException(String.Format("{0} does not begin with PROT", path)); } br.ReadInt32(); // Skip 4 bytes var proto = (GomObject)prototypeLoader.Load(br); proto.Checksum = (long)protoFile.FileInfo.Checksum; DomTypeMap.Add(proto.Id, proto); AddToNameLookup(proto); } }
private static void LoadPrototypes() { File prototypeList = Assets.FindFile("/resources/systemgenerated/prototypes.info"); using (var fs = prototypeList.Open()) using (var br = new GomBinaryReader(fs, Encoding.UTF8)) { // Check PINF int magicNum = br.ReadInt32(); if (magicNum != 0x464E4950) { throw new InvalidOperationException("prototypes.info does not begin with PINF"); } br.ReadInt32(); // Skip 4 bytes int numPrototypes = (int)br.ReadNumber(); int protoLoaded = 0; for (var i = 0; i < numPrototypes; i++) { ulong protId = br.ReadNumber(); byte flag = br.ReadByte(); if (flag == 1) { LoadPrototype(protId); protoLoaded++; } } Console.WriteLine("Loaded {0} prototype files", protoLoaded); } }
private static void LoadClientGom() { File gomFile = Assets.FindFile("/resources/systemgenerated/client.gom"); using (var fs = gomFile.Open()) using (var br = new GomBinaryReader(fs, Encoding.UTF8)) { // Check DBLB int magicNum = br.ReadInt32(); if (magicNum != 0x424C4244) { throw new InvalidOperationException("client.gom does not begin with DBLB"); } br.ReadInt32(); // Skip 4 bytes ReadAllItems(br, 8); } }
private static void ReadAllItems(GomBinaryReader br, long offset) { while (true) { // Begin Reading Gom Definitions int defLength = br.ReadInt32(); // Length == 0 means we've read them all! if (defLength == 0) { break; } //short defFlags = br.ReadInt16(); //int defType = (defFlags >> 3) & 0x7; byte[] defBuffer = new byte[defLength]; int defZero = br.ReadInt32(); // 4 blank bytes ulong defId = br.ReadUInt64(); // 8-byte type ID short defFlags = br.ReadInt16(); // 16-bit flag field int defType = (defFlags >> 3) & 0x7; //var defData = br.ReadBytes(defLength - 6); var defData = br.ReadBytes(defLength - 18); Buffer.BlockCopy(defData, 0, defBuffer, 18, defData.Length); using (var memStream = new System.IO.MemoryStream(defBuffer)) using (var defReader = new GomBinaryReader(memStream, Encoding.UTF8)) { DomTypeLoaders.IDomTypeLoader loader; if (typeLoaderMap.TryGetValue(defType, out loader)) { var domType = loader.Load(defReader); domType.Id = defId; DomTypeMap.Add(domType.Id, domType); if (String.IsNullOrEmpty(domType.Name)) { string storedTypeName; if (StoredNameMap.TryGetValue(domType.Id, out storedTypeName)) { domType.Name = storedTypeName; } } AddToNameLookup(domType); } else { throw new InvalidOperationException(String.Format("No loader for DomType 0x{1:X} as offset 0x{0:X}", offset, defType)); } } // Read the required number of padding bytes int padding = ((8 - (defLength & 0x7)) & 0x7); if (padding > 0) { br.ReadBytes(padding); } offset = offset + defLength + padding; } }
private void Load() { // Version with String Tables as XML files //var path = String.Format("/resources/en-us/{0}.str", this.Fqn.Replace('.','/')); //var file = Assets.FindFile(path); //if (file == null) { throw new Exception("File not found"); } //using (var fs = file.Open()) //{ // var xmlReader = XmlReader.Create(fs); // var xdoc = XDocument.Load(xmlReader); // var xroot = xdoc.Root; // this.Version = xroot.Attribute("version").AsInt(); // this.OwnerFqn = (string)xroot.Attribute("owner"); // this.OwnerId = xroot.Attribute("ownerID").AsLong(); // this.Guid = xroot.Attribute("GUID").AsLong(); // this.Fqn = (string)xroot.Attribute("fqn"); // var results = from row in xdoc.Descendants("string") select LoadString(row); // data = results.ToDictionary(k => k.Id, v => v); //} // Version with String Tables as nodes //var enUsPath = "en-us." + this.Fqn; //var file = DataObjectModel.GetObject(enUsPath); //if (file == null) { throw new Exception("StringTable not found"); } //var strings = file.Data.strTableVariantStrings as IDictionary<object, object>; // Map<enum, Map<int, string>> //var entries = (IDictionary<object,object>)strings.First(kvp => ((ScriptEnum)kvp.Key).ToString() == "MaleMale").Value; //data = new Dictionary<long, StringTableEntry>(); //foreach (var kvp in entries) //{ // var entry = new StringTableEntry() // { // Id = (long)kvp.Key, // Text = (string)kvp.Value // }; // data[entry.Id] = entry; //} // Version with String Tables as unique file format contained in swtor_en-us_global_1.tor var path = String.Format("/resources/en-us/{0}.stb", this.Fqn.Replace('.', '/')); var file = TorLib.Assets.FindFile(path); if (file == null) { throw new Exception("File not found"); } data = new Dictionary <long, StringTableEntry>(); using (var fs = file.OpenCopyInMemory()) { var br = new GomBinaryReader(fs); br.ReadBytes(3); int numStrings = br.ReadInt32(); long streamPos = 0; for (var i = 0; i < numStrings; i++) { var entryId = br.ReadInt64(); var entry_8 = br.ReadInt16(); var entry_A = br.ReadSingle(); var entryLength = br.ReadInt32(); var entryOffset = br.ReadInt32(); var entryLength2 = br.ReadInt32(); var entry = new StringTableEntry() { Id = entryId, Text = String.Empty }; if (entryLength > 0) { streamPos = fs.Position; fs.Position = entryOffset; entry.Text = br.ReadFixedLengthString(entryLength); fs.Position = streamPos; } data[entryId] = entry; } } }