public ThirdGenLanguageGlobals(ThirdGenCacheFile cacheFile, StructureValueCollection values, IndexOffsetConverter converter, BuildInformation buildInfo)
 {
     _cacheFile = cacheFile;
     _converter = converter;
     _languages = LoadLanguages(values, converter, buildInfo);
     _alignment = buildInfo.LocaleAlignment;
 }
예제 #2
0
 private void Load(StructureValueCollection values)
 {
     Magic = (int)values.GetNumber("magic");
     ParentMagic = (int)values.GetNumber("parent magic");
     GrandparentMagic = (int)values.GetNumber("grandparent magic");
     Description = new StringID((int)values.GetNumberOrDefault("stringid", 0));
 }
예제 #3
0
        private IReader _reader; // The stream to read from

        #endregion Fields

        #region Constructors

        /// <summary>
        /// (private) Constructs a new StructureReader.
        /// </summary>
        /// <param name="reader">The IReader to read from.</param>
        /// <param name="layout">The structure layout to follow.</param>
        private StructureReader(IReader reader, StructureLayout layout)
        {
            _reader = reader;
            _layout = layout;
            _baseOffset = reader.Position;
            _offset = _baseOffset;
            _collection = new StructureValueCollection();
        }
예제 #4
0
        public ThirdGenGlobal(StructureValueCollection values, ExpressionTable allExpressions)
        {
            Name = values.GetString("name");
            Type = (short)values.GetNumber("type");

            DatumIndex valueIndex = new DatumIndex(values.GetNumber("expression index"));
            if (valueIndex.IsValid)
                Value = allExpressions.FindExpression(valueIndex);
        }
예제 #5
0
 public ThirdGenLanguage(ThirdGenLanguageGlobals languageGlobals, StructureValueCollection values, IndexOffsetConverter converter, BuildInformation buildInfo)
 {
     _languageGlobals = languageGlobals;
     _pointerLayout = buildInfo.GetLayout("locale index table entry");
     _encryptionKey = buildInfo.LocaleKey;
     _symbols = buildInfo.LocaleSymbols;
     _converter = converter;
     _pageSize = buildInfo.LocaleAlignment;
     Load(values, converter);
 }
예제 #6
0
        void Load(StructureValueCollection values, ushort index, MetaAddressConverter converter, IList<ITagClass> classList)
        {
            int classIndex = (int)values.GetNumber("class index");
            if (classIndex >= 0)
                Class = classList[classIndex];

            ushort salt = (ushort)values.GetNumber("datum index salt");
            Index = new DatumIndex(salt, index);

            MetaLocation = new Pointer(values.GetNumber("memory address"), converter);
        }
예제 #7
0
 /// <summary>
 /// Loads data from a StructureValueCollection containing data read from a unic tag.
 /// </summary>
 /// <param name="values">The StructureValueCollection to retrieve values from.</param>
 private void Load(StructureValueCollection values)
 {
     // Load ranges
     StructureValueCollection[] rangeValues = values.GetArray("language ranges");
     Ranges = new LocaleRange[rangeValues.Length];
     for (int i = 0; i < rangeValues.Length; i++)
     {
         int startIndex = (int)rangeValues[i].GetNumber("range start index");
         int size = (int)rangeValues[i].GetNumber("range size");
         Ranges[i] = new LocaleRange(startIndex, size);
     }
 }
예제 #8
0
        private void Load(IReader reader, StructureValueCollection values, MetaAddressConverter addrConverter, IStringIDSource stringIDs, ExpressionTable expressions, BuildInformation buildInfo)
        {
            Name = stringIDs.GetString(new StringID((int)values.GetNumber("name index")));
            ExecutionType = (short)values.GetNumber("execution type");
            ReturnType = (short)values.GetNumber("return type");
            DatumIndex rootExpr = new DatumIndex(values.GetNumber("first expression index"));
            if (rootExpr.IsValid)
                RootExpression = expressions.FindExpression(rootExpr);
            if (Name == null)
                Name = "script_" + rootExpr.Value.ToString("X8");

            Parameters = LoadParameters(reader, values, addrConverter, buildInfo);
        }
예제 #9
0
        private void Load(StructureValueCollection values, ushort index, StringTableReader stringReader)
        {
            ushort salt = (ushort)values.GetNumber("datum index salt");
            Index = new DatumIndex(salt, index);

            Opcode = (ushort)values.GetNumber("opcode");
            ValueType = (short)values.GetNumber("value type");
            Type = (ExpressionType)values.GetNumber("expression type");
            _nextIndex = new DatumIndex(values.GetNumber("next expression index"));
            _stringTableOffset = (int)values.GetNumber("string table offset");
            Value = values.GetNumber("value");
            LineNumber = (short)values.GetNumber("source line");

            stringReader.RequestString(_stringTableOffset);
        }
예제 #10
0
        private void Load(IReader reader, StructureValueCollection values, MetaAddressConverter converter, BuildInformation buildInfo)
        {
            if (values.GetNumber("magic") != CharConstant.FromString("tags"))
                throw new ArgumentException("Invalid index table header magic");

            // Classes
            int numClasses = (int)values.GetNumber("number of classes");
            Pointer classTableLocation = new Pointer(values.GetNumber("class table address"), converter);
            _classes = ReadClasses(reader, classTableLocation, numClasses, buildInfo);

            // Tags
            int numTags = (int)values.GetNumber("number of tags");
            Pointer tagTableLocation = new Pointer(values.GetNumber("tag table address"), converter);
            _tags = ReadTags(reader, tagTableLocation, numTags, buildInfo, converter);
        }
예제 #11
0
        private IList<IScriptParameter> LoadParameters(IReader reader, StructureValueCollection values, MetaAddressConverter addrConverter, BuildInformation buildInfo)
        {
            int paramCount = (int)values.GetNumber("number of parameters");
            Pointer paramListLocation = new Pointer(values.GetNumber("address of parameter list"), addrConverter);

            StructureLayout layout = buildInfo.GetLayout("script parameter entry");
            List<IScriptParameter> result = new List<IScriptParameter>();

            reader.SeekTo(paramListLocation.AsOffset());
            for (int i = 0; i < paramCount; i++)
            {
                StructureValueCollection paramValues = StructureReader.ReadStructure(reader, layout);
                result.Add(new ThirdGenScriptParameter(paramValues));
            }
            return result;
        }
예제 #12
0
        private void Load(StructureValueCollection values, IReader reader, MetaAddressConverter addrConverter, IStringIDSource stringIDs, BuildInformation buildInfo)
        {
            StringTableReader stringReader = new StringTableReader();
            ScriptExpressions = LoadScriptExpressions(values, reader, addrConverter, stringReader, buildInfo.GetLayout("script expression entry"));
            ScriptObjects = LoadScriptObjects(values, reader, addrConverter, stringIDs, buildInfo.GetLayout("script object entry"));
            ScriptGlobals = LoadScriptGlobals(values, reader, addrConverter, ScriptExpressions, buildInfo.GetLayout("script global entry"));
            Scripts = LoadScripts(values, reader, addrConverter, stringIDs, ScriptExpressions, buildInfo.GetLayout("script entry"), buildInfo);

            CachedStringTable strings = LoadStrings(values, reader, stringReader, addrConverter);
            foreach (IExpression expr in ScriptExpressions)
            {
                // FIXME: hax
                if (expr != null)
                    ((ThirdGenExpression)expr).ResolveStrings(strings);
            }
        }
        /// <summary>
        /// Serializes the language data into a StructureValueCollection.
        /// </summary>
        /// <returns>The StructureValueCollection that was created from the language table.</returns>
        public StructureValueCollection Serialize()
        {
            StructureValueCollection[] languageSet = new StructureValueCollection[_languages.Count];
            for (int i = 0; i < _languages.Count; i++)
                languageSet[i] = _languages[i].Serialize();

            StructureValueCollection result = new StructureValueCollection();
            result.SetArray("languages", languageSet);
            return result;
        }
예제 #14
0
        private List<IGlobal> LoadScriptGlobals(StructureValueCollection values, IReader reader, MetaAddressConverter addrConverter, ExpressionTable expressions, StructureLayout entryLayout)
        {
            int globalsCount = (int)values.GetNumber("number of script globals");
            ScriptGlobalsLocation = new Pointer(values.GetNumber("script global table address"), addrConverter);

            List<IGlobal> result = new List<IGlobal>();
            reader.SeekTo(ScriptGlobalsLocation.AsOffset());
            for (int i = 0; i < globalsCount; i++)
            {
                StructureValueCollection globalValues = StructureReader.ReadStructure(reader, entryLayout);
                result.Add(new ThirdGenGlobal(globalValues, expressions));
            }
            return result;
        }
예제 #15
0
 public ThirdGenExpression(StructureValueCollection values, ushort index, StringTableReader stringReader)
 {
     Load(values, index, stringReader);
 }
예제 #16
0
 public ThirdGenHeader(StructureValueCollection values, BuildInformation info, string buildString)
 {
     BuildString = buildString;
     HeaderSize = info.HeaderSize;
     Load(values);
 }
예제 #17
0
 private StructureValueCollection[] SerializePartitions()
 {
     StructureValueCollection[] results = new StructureValueCollection[Partitions.Length];
     for (int i = 0; i < Partitions.Length; i++)
     {
         StructureValueCollection values = new StructureValueCollection();
         values.SetNumber("load address", Partitions[i].BasePointer.AsAddress());
         values.SetNumber("size", Partitions[i].Size);
         results[i] = values;
     }
     return results;
 }
예제 #18
0
 private Partition[] LoadPartitions(StructureValueCollection[] partitionValues)
 {
     var result = from partition in partitionValues
                  select new Partition
                  (
                      new Pointer(partition.GetNumber("load address"), _addrConverter),
                      partition.GetNumber("size")
                  );
     return result.ToArray();
 }
예제 #19
0
 public ThirdGenScenarioMeta(StructureValueCollection values, IReader reader, MetaAddressConverter addrConverter, IStringIDSource stringIDs, BuildInformation buildInfo)
 {
     Load(values, reader, addrConverter, stringIDs, buildInfo);
 }
예제 #20
0
        private HeaderOffsetConverter LoadHeaderOffsetConverter(StructureValueCollection values)
        {
            // Only apply a modifier if the original raw table offset wasn't zero
            StringOffsetMagic = (uint)HeaderSize;
            if (values.HasNumber("raw table offset") && values.GetNumber("raw table offset") > 0)
                StringOffsetMagic = values.GetNumberOrDefault("string offset magic", (uint)HeaderSize);

            return new HeaderOffsetConverter(this);
        }
예제 #21
0
        private List<IGlobalObject> LoadScriptObjects(StructureValueCollection values, IReader reader, MetaAddressConverter addrConverter, IStringIDSource stringIDs, StructureLayout entryLayout)
        {
            int objectsCount = (int)values.GetNumber("number of script objects");
            ScriptObjectsLocation = new Pointer(values.GetNumber("script object table address"), addrConverter);

            List<IGlobalObject> result = new List<IGlobalObject>();
            reader.SeekTo(ScriptObjectsLocation.AsOffset());
            for (int i = 0; i < objectsCount; i++)
            {
                StructureValueCollection objValues = StructureReader.ReadStructure(reader, entryLayout);
                result.Add(new ThirdGenGlobalObject(objValues, stringIDs));
            }
            return result;
        }
예제 #22
0
 public ThirdGenTagClass(StructureValueCollection values)
 {
     Load(values);
 }
예제 #23
0
        private List<IScript> LoadScripts(StructureValueCollection values, IReader reader, MetaAddressConverter addrConverter, IStringIDSource stringIDs, ExpressionTable expressions, StructureLayout entryLayout, BuildInformation buildInfo)
        {
            int script = (int)values.GetNumber("number of scripts");
            ScriptsLocation = new Pointer(values.GetNumber("script table address"), addrConverter);

            // Read all of the script entries first, then go back and create the objects
            // ThirdGenScript reads parameters from its constructor - this may or may not need cleaning up to make this more obvious
            reader.SeekTo(ScriptsLocation.AsOffset());
            List<StructureValueCollection> scriptData = new List<StructureValueCollection>();
            for (int i = 0; i < script; i++)
                scriptData.Add(StructureReader.ReadStructure(reader, entryLayout));

            List<IScript> result = new List<IScript>();
            foreach (StructureValueCollection scriptValues in scriptData)
                result.Add(new ThirdGenScript(reader, scriptValues, addrConverter, stringIDs, expressions, buildInfo));
            return result;
        }
예제 #24
0
        private ExpressionTable LoadScriptExpressions(StructureValueCollection values, IReader reader, MetaAddressConverter addrConverter, StringTableReader stringReader, StructureLayout entryLayout)
        {
            int exprCount = (int)values.GetNumber("number of script expressions");
            ScriptExpressionsLocation = new Pointer(values.GetNumber("script expression table address"), addrConverter);

            ExpressionTable result = new ExpressionTable();
            reader.SeekTo(ScriptExpressionsLocation.AsOffset());
            for (int i = 0; i < exprCount; i++)
            {
                StructureValueCollection exprValues = StructureReader.ReadStructure(reader, entryLayout);
                result.AddExpression(new ThirdGenExpression(exprValues, (ushort)i, stringReader));
            }

            foreach (IExpression expr in result)
            {
                // FIXME: hax
                if (expr != null)
                    ((ThirdGenExpression)expr).ResolveReferences(result);
            }
            return result;
        }
        private List<ThirdGenLanguage> LoadLanguages(StructureValueCollection values, IndexOffsetConverter converter, BuildInformation buildInfo)
        {
            StructureValueCollection[] languageSet = values.GetArray("languages");

            var result = from language in languageSet
                         select new ThirdGenLanguage(this, language, converter, buildInfo);
            return result.ToList<ThirdGenLanguage>();
        }
예제 #26
0
 private IndexOffsetConverter LoadIndexOffsetConverter(StructureValueCollection values)
 {
     LocaleOffsetMask = values.GetNumberOrDefault("locale offset magic", 0);
     return new IndexOffsetConverter(this);
 }
예제 #27
0
        private void Load(StructureValueCollection values)
        {
            _addrConverter = LoadAddressConverter(values);
            _indexConverter = LoadIndexOffsetConverter(values);
            _stringOffsetConverter = LoadHeaderOffsetConverter(values);

            FileSize = values.GetNumber("file size");
            IndexHeaderLocation = new Pointer(values.GetNumber("index header address"), _addrConverter);
            MetaSize = values.GetNumber("virtual size");
            Type = (CacheFileType)values.GetNumber("type");

            StringIDCount = (int)values.GetNumber("string table count");
            StringIDTableSize = (int)values.GetNumber("string table size");
            StringIDIndexTableLocation = new Pointer(values.GetNumber("string index table offset"), _stringOffsetConverter);
            StringIDDataLocation = new Pointer(values.GetNumber("string table offset"), _stringOffsetConverter);

            InternalName = values.GetString("internal name");
            ScenarioName = values.GetString("scenario name");

            FileNameCount = (int)values.GetNumber("file table count");
            FileNameDataLocation = new Pointer(values.GetNumber("file table offset"), _stringOffsetConverter);
            FileNameTableSize = (int)values.GetNumber("file table size");
            FileNameIndexTableLocation = new Pointer(values.GetNumber("file index table offset"), _stringOffsetConverter);

            XDKVersion = (int)values.GetNumber("xdk version");
            Partitions = LoadPartitions(values.GetArray("partitions"));

            LocaleDataLocation = new Pointer(values.GetNumberOrDefault("locale data index offset", (uint)HeaderSize), _indexConverter);
            LocaleDataSize = (int)values.GetNumberOrDefault("locale data size", 0);
        }
예제 #28
0
        private CachedStringTable LoadStrings(StructureValueCollection values, IReader reader, StringTableReader stringReader, MetaAddressConverter addrConverter)
        {
            int stringsSize = (int)values.GetNumber("script string table size");
            Pointer stringsLocation = new Pointer(values.GetNumber("script string table address"), addrConverter);

            CachedStringTable result = new CachedStringTable();
            stringReader.ReadRequestedStrings(reader, stringsLocation, result);
            return result;
        }
예제 #29
0
        /// <summary>
        /// Serializes the header's values, storing them into a StructureValueCollection.
        /// </summary>
        /// <returns>The resulting StructureValueCollection.</returns>
        public StructureValueCollection Serialize()
        {
            StructureValueCollection values = new StructureValueCollection();

            if (_originalRawTableOffset != 0)
                values.SetNumber("raw table offset", RawTableOffset);
            else
                values.SetNumber("meta offset", MetaOffset);

            values.SetNumber("virtual base address", VirtualBaseAddress);
            values.SetNumber("raw table offset from header", (uint)(RawTableOffset - HeaderSize));
            values.SetNumber("raw table size", RawTableSize);
            values.SetNumber("locale offset magic", LocaleOffsetMask);
            values.SetNumber("file size", FileSize);
            values.SetNumber("index header address", IndexHeaderLocation.AsAddress());
            values.SetNumber("virtual size", MetaSize);
            values.SetNumber("type", (uint)Type);
            values.SetNumber("string table count", (uint)StringIDCount);
            values.SetNumber("string table size", (uint)StringIDTableSize);
            values.SetNumber("string index table offset", _stringOffsetConverter.PointerToRaw(StringIDIndexTableLocation));
            values.SetNumber("string table offset", _stringOffsetConverter.PointerToRaw(StringIDDataLocation));
            values.SetString("internal name", InternalName);
            values.SetString("scenario name", ScenarioName);
            values.SetNumber("file table count", (uint)FileNameCount);
            values.SetNumber("file table offset", _stringOffsetConverter.PointerToRaw(FileNameDataLocation));
            values.SetNumber("file table size", (uint)FileNameTableSize);
            values.SetNumber("file index table offset", _stringOffsetConverter.PointerToRaw(FileNameIndexTableLocation));
            values.SetNumber("xdk version", (uint)XDKVersion);
            values.SetArray("partitions", SerializePartitions());
            values.SetNumber("locale data index offset", _indexConverter.PointerToRaw(LocaleDataLocation));
            values.SetNumber("locale data size", (uint)LocaleDataSize);
            return values;
        }
예제 #30
0
        private MetaAddressConverter LoadAddressConverter(StructureValueCollection values)
        {
            VirtualBaseAddress = values.GetNumber("virtual base address");

            if (values.HasNumber("raw table offset") && values.HasNumber("raw table size"))
            {
                // Load raw table info
                RawTableSize = values.GetNumber("raw table size");
                RawTableOffset = values.GetNumber("raw table offset");
                _originalRawTableOffset = RawTableOffset;

                // There are two ways to get the meta offset:
                // 1. Raw table offset + raw table size
                // 2. If raw table offset is zero, then the meta offset is directly stored in the header
                //    (The raw table offset can still be calculated in this case, but can't be used to find the meta the traditional way)
                if (RawTableOffset != 0)
                    MetaOffset = RawTableOffset + RawTableSize;
                else
                    RawTableOffset = values.GetNumber("raw table offset from header") + (uint)HeaderSize;
            }

            uint temp = MetaOffset;
            if (MetaOffset == 0 && !values.FindNumber("meta offset", out temp))
            {
                throw new ArgumentException("The XML layout file is missing information on how to calculate map magic.");
            }
            MetaOffset = temp;

            return new MetaAddressConverter(this);
        }