Пример #1
0
        string StringToString(XmbVariantMemoryPool pool)
        {
            string result = null;

            if (IsIndirect)
            {
                result = pool.GetString(Offset, IsUnicode);
            }
            else
            {
                // Unicode is always indirect
                //if (IsUnicode) result = new string((char)Char0, 1);
                //else
                {
                    var sb = new System.Text.StringBuilder(3);
                    if (Char0 != '\0')
                    {
                        sb.Append((char)Char0);
                    }
                    if (Char1 != '\0')
                    {
                        sb.Append((char)Char1);
                    }
                    if (Char2 != '\0')
                    {
                        sb.Append((char)Char2);
                    }

                    result = sb.ToString();
                }
            }
            return(result);
        }
Пример #2
0
        uint GetDataSize(XmbVariantMemoryPool pool)
        {
            uint size = Size;

            if (SizeIsIndirect)
            {
                size = pool.GetUInt32(Offset - sizeof(uint));
                Contract.Assert(size > Constants.kSizeBitField.Bitmask32);
            }

            return(size);
        }
Пример #3
0
        internal string ToString(XmbVariantMemoryPool pool)
        {
            string result = "";

            switch (Type)
            {
            case XmbVariantType.Single: {
                float f = Single;
                if (IsIndirect)
                {
                    f = pool.GetSingle(Offset);
                }
                result = f.ToStringInvariant(Numbers.kFloatRoundTripFormatSpecifier);
            } break;

            case XmbVariantType.Int: {
                uint i = Int;
                if (IsIndirect)
                {
                    i = pool.GetUInt32(Offset);
                }
                result = IsUnsigned
                                                ? i.ToString()
                                                : ((int)i).ToString();
            } break;

            case XmbVariantType.Double: {
                double d = pool.GetDouble(Offset);
                result = d.ToStringInvariant(Numbers.kDoubleRoundTripFormatSpecifier);
            } break;

            case XmbVariantType.Bool: {
                // Phoenix uses lower case and Boolean.ToString uppercases the first letter
                result = Bool ? "true" : "false";
            } break;

            case XmbVariantType.String: {
                result = StringToString(pool);
            } break;

            case XmbVariantType.Vector: {
                result = VectorToString(Offset, VectorLength, pool);
            } break;
            }

            return(result);
        }
Пример #4
0
        public uint GetLength(XmbVariantMemoryPool pool)
        {
            uint length = 0;

            switch (Type)
            {
            case BinaryDataTreeVariantType.Null:
                break;

            case BinaryDataTreeVariantType.String:
                length = (uint)StringToString(pool).Length;
                break;

            default:
                length   = GetDataSize(pool);
                length >>= (int)TypeSizeInBytes;
                break;
            }

            return(length);
        }
Пример #5
0
        static string VectorToString(uint offset, int length, XmbVariantMemoryPool pool)
        {
            float x = 0, y = 0, z = 0, w = 0;

            switch (length)
            {
            case 1: {
                x = pool.GetSingle(offset);
            } break;

            case 2: {
                var v = pool.GetVector2D(offset);
                x = v.X;
                y = v.Y;
            } break;

            case 3: {
                var v = pool.GetVector3D(offset);
                x = v.X;
                y = v.Y;
                z = v.Z;
            } break;

            case 4: {
                var v = pool.GetVector4D(offset);
                x = v.X;
                y = v.Y;
                z = v.Z;
                w = v.W;
            } break;

            default:
                throw new ArgumentOutOfRangeException("length", length.ToString());
            }

            var vector = new BVector(x, y, z, w);

            return(vector.ToBVectorString(length));
        }
Пример #6
0
        public void Read(IO.EndianReader s)
        {
            var context = s.UserData as XmbFileContext;

            using (s.ReadSignatureWithByteSwapSupport(kSignature))
            {
                if (context.PointerSize == Shell.ProcessorSize.x64)
                {
                    // #HACK to deal with xmb files which weren't updated with new tools
                    if (s.ByteOrder == Shell.EndianFormat.Big)
                    {
                        context.PointerSize = Shell.ProcessorSize.x32;
                    }
                }

                s.VirtualAddressTranslationInitialize(context.PointerSize);

                Values.PtrHandle elements_offset_pos;

                if (context.PointerSize == Shell.ProcessorSize.x64)
                {
                    s.Pad32();
                }
                #region Initialize elements
                {
                    int count = s.ReadInt32();
                    if (context.PointerSize == Shell.ProcessorSize.x64)
                    {
                        s.Pad32();
                    }
                    s.ReadVirtualAddress(out elements_offset_pos);

                    mElements = new List <Element>(count);
                }
                #endregion
                #region Initialize and read pool
                {
                    int size = s.ReadInt32();
                    if (context.PointerSize == Shell.ProcessorSize.x64)
                    {
                        s.Pad32();
                    }
                    Values.PtrHandle pool_offset_pos = s.ReadVirtualAddress();

                    s.Seek((long)pool_offset_pos);
                    byte[] buffer = s.ReadBytes(size);

                    mPool = new XmbVariantMemoryPool(buffer, s.ByteOrder);
                }
                #endregion

                if (context.PointerSize == Shell.ProcessorSize.x64)
                {
                    s.Pad64();
                }

                s.Seek((long)elements_offset_pos);
                for (int x = 0; x < mElements.Capacity; x++)
                {
                    var e = new Element();
                    mElements.Add(e);

                    e.Index = x;
                    e.Read(this, context, s);
                }

                foreach (var e in mElements)
                {
                    e.ReadAttributes(this, s);
                    e.ReadChildren(s);
                }
            }
        }