示例#1
0
        /// <summary>
        ///     Loads all of the locale symbols defined in an XML document.
        /// </summary>
        /// <param name="layoutDocument">The XML document to load locale symbols from.</param>
        /// <returns>The symbols that were loaded.</returns>
        public static LocaleSymbolCollection LoadLocaleSymbols(XDocument symbolDocument)
        {
            // Make sure there is a root <symbols> tag
            XContainer container = symbolDocument.Element("symbols");

            if (container == null)
            {
                throw new ArgumentException("Invalid symbols document");
            }

            // Symbol tags have the format:
            // <symbol code="0x(the byte array)" display="(Friendly Name)" />
            var result = new LocaleSymbolCollection();

            foreach (XElement symbol in container.Elements("symbol"))
            {
                string code    = XMLUtil.GetStringAttribute(symbol, "code");
                string display = XMLUtil.GetStringAttribute(symbol, "display");

                // Convert code to int
                code = code.Replace("0x", "");
                byte[] codeBytes  = FunctionHelpers.HexStringToBytes(code);
                string codeString = Encoding.UTF8.GetString(codeBytes);
                char   codeChar   = codeString[0];

                result.AddSymbol(codeChar, display);
            }
            return(result);
        }
示例#2
0
        public void VisitDataRef(DataRef field)
        {
            var values = new StructureValueCollection();

            values.SetInteger("size", (uint)field.Length);

            SeekToOffset(field.Offset);
            StructureWriter.WriteStructure(values, _dataRefLayout, _writer);

            if (field.DataAddress == 0xFFFFFFFF || field.DataAddress <= 0)
            {
                return;
            }

            // Go to the data location
            uint offset     = field.DataAddress;
            uint dataOffset = offset;

            switch (_type)
            {
            case SaveType.Memory:
            {
                if (_cache.GetType() != typeof(Blamite.Blam.FourthGen.FourthGenCacheFile))
                {
                    values.SetInteger("pointer", offset);
                }
                break;
            }

            case SaveType.File:
            {
                if (_cache.GetType() == typeof(Blamite.Blam.FourthGen.FourthGenCacheFile))
                {
                    offset = offset - _headerOffset + 0x40000000;
                }
                values.SetInteger("pointer", offset);
                dataOffset = (uint)_cache.MetaArea.PointerToOffset(dataOffset);
                break;
            }
            }
            _writer.SeekTo(dataOffset);

            // Write its data
            switch (field.Format)
            {
            default:
                _writer.WriteBlock(FunctionHelpers.HexStringToBytes(field.Value), 0, field.Length);
                break;

            case "unicode":
                _writer.WriteUTF16(field.Value);
                break;

            case "asciiz":
                _writer.WriteAscii(field.Value);
                break;
            }
        }
示例#3
0
        public void VisitDataRef(DataRef field)
        {
            var  values  = new StructureValueCollection();
            bool isValid = _cache.MetaArea.ContainsBlockPointer(field.DataAddress, field.Length);

            values.SetInteger("size", isValid ? (uint)field.Length : 0);

            uint cont = _cache.PointerExpander.Contract(field.DataAddress);

            values.SetInteger("pointer", isValid ? cont : 0);

            SeekToOffset(field.Offset);
            StructureWriter.WriteStructure(values, _dataRefLayout, _writer);

            if (isValid)
            {
                // Go to the data location
                long offset = field.DataAddress;
                if (_type == SaveType.File)
                {
                    offset = _cache.MetaArea.PointerToOffset(offset);
                }
                _writer.SeekTo(offset);

                // Build the data
                byte[] buffer = new byte[field.Length];
                byte[] bytes;

                switch (field.Format)
                {
                default:
                    bytes = FunctionHelpers.HexStringToBytes(field.Value);
                    break;

                case "utf16":
                    bytes = Encoding.GetEncoding(1200).GetBytes(field.Value);
                    break;

                case "asciiz":
                    bytes = Encoding.GetEncoding(28591).GetBytes(field.Value);
                    break;
                }

                Array.Copy(bytes, buffer, bytes.Length > field.Length ? field.Length : bytes.Length);
                _writer.WriteBlock(buffer, 0, buffer.Length);
            }
        }
示例#4
0
        public void VisitDataRef(DataRef field)
        {
            var values = new StructureValueCollection();

            values.SetInteger("size", (uint)field.Length);

            uint cont = _cache.PointerExpander.Contract(field.DataAddress);

            values.SetInteger("pointer", cont);

            SeekToOffset(field.Offset);
            StructureWriter.WriteStructure(values, _dataRefLayout, _writer);

            if (field.DataAddress == 0xFFFFFFFF || field.DataAddress <= 0)
            {
                return;
            }

            // Go to the data location
            long offset = field.DataAddress;

            if (_type == SaveType.File)
            {
                offset = _cache.MetaArea.PointerToOffset(offset);
            }
            _writer.SeekTo(offset);

            // Write its data
            switch (field.Format)
            {
            default:
                _writer.WriteBlock(FunctionHelpers.HexStringToBytes(field.Value), 0, field.Length);
                break;

            case "unicode":
                _writer.WriteUTF16(field.Value);
                break;

            case "asciiz":
                _writer.WriteAscii(field.Value);
                break;
            }
        }
示例#5
0
        public override object GetAsJson()
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            dict["Offset"]       = Offset;
            dict["FieldAddress"] = FieldAddress;
            dict["Length"]       = _length;
            dict["Hash"]         = Value.GetHashCode();
            if (IsBinary)
            {
                dict["Encoded"] = Convert.ToBase64String(FunctionHelpers.HexStringToBytes(Value));
            }
            else
            {
                dict["Data"] = Value;
            }

            return(dict);
        }
示例#6
0
 public void VisitRawData(RawData field)
 {
     SeekToOffset(field.Offset);
     _writer.WriteBlock(FunctionHelpers.HexStringToBytes(field.Value), 0, field.Length);
 }