예제 #1
0
        private static void LoadBucketList()
        {
            File gomFile = Assets.FindFile("/resources/systemgenerated/buckets.info");

            using (var fs = gomFile.Open())
                using (var br = new GomBinaryReader(fs, Encoding.UTF8))
                {
                    br.ReadBytes(8); // Skip 8 header bytes

                    var c9 = br.ReadByte();
                    if (c9 != 0xC9)
                    {
                        throw new InvalidOperationException(String.Format("Unexpected character in buckets.info @ offset 0x8 - expected 0xC9 found {0:X2}", c9));
                    }

                    short numEntries = br.ReadInt16(Endianness.BigEndian);

                    for (var i = 0; i < numEntries; i++)
                    {
                        string fileName = br.ReadLengthPrefixString();
                        BucketFiles.Add(fileName);
                    }
                }
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        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;
                }
            }
        }