コード例 #1
0
ファイル: StringTable.cs プロジェクト: exodus444/swtoremu2
        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;
                }
            }
        }