示例#1
0
        public Dictionary <string, MValueConst> GetDictionary()
        {
            var size = AltNative.MValueNative.MValueConst_GetDictSize(nativePointer);

            if (size == 0)
            {
                return(new Dictionary <string, MValueConst>());
            }
            var keyPointers    = new IntPtr[size];
            var mValuePointers = new IntPtr[size];

            AltNative.MValueNative.MValueConst_GetDict(nativePointer, keyPointers, mValuePointers);

            var dictionary = new Dictionary <string, MValueConst>();

            for (ulong i = 0; i < size; i++)
            {
                var keyPointer = keyPointers[i];
                var mValue     = new MValueConst(mValuePointers[i]);
                dictionary[Marshal.PtrToStringUTF8(keyPointer)] = mValue;
                AltNative.FreeCharArray(keyPointer);
                mValue.Dispose();
            }

            return(dictionary);
        }
示例#2
0
        public object ToObject()
        {
            switch (type)
            {
            case Type.None:
                return(None);

            case Type.Nil:
                return(null);

            case Type.Bool:
                return(GetBool());

            case Type.Int:
                return(GetInt());

            case Type.Uint:
                return(GetUint());

            case Type.Double:
                return(GetDouble());

            case Type.String:
                return(GetString());

            case Type.List:
                var listSize = AltNative.MValueNative.MValueConst_GetListSize(nativePointer);
                if (listSize == 0)
                {
                    return new MValueConst[] { }
                }
                ;
                var mValueListPointers = new IntPtr[listSize];
                AltNative.MValueNative.MValueConst_GetList(nativePointer, mValueListPointers);
                var arrayValues = new object[listSize];
                for (ulong i = 0; i < listSize; i++)
                {
                    var mValue = new MValueConst(mValueListPointers[i]);
                    arrayValues[i] = mValue.ToObject();
                    mValue.Dispose();
                }

                return(arrayValues);

            case Type.Dict:
                var size = AltNative.MValueNative.MValueConst_GetDictSize(nativePointer);
                if (size == 0)
                {
                    return(new Dictionary <string, MValueConst>());
                }
                var keyPointers    = new IntPtr[size];
                var mValuePointers = new IntPtr[size];
                if (!AltNative.MValueNative.MValueConst_GetDict(nativePointer, keyPointers, mValuePointers))
                {
                    return(null);
                }

                var dictionary = new Dictionary <string, object>();

                for (ulong i = 0; i < size; i++)
                {
                    var keyPointer = keyPointers[i];
                    var mValue     = new MValueConst(mValuePointers[i]);
                    dictionary[Marshal.PtrToStringUTF8(keyPointer)] = mValue.ToObject();
                    AltNative.FreeCharArray(keyPointer);
                    mValue.Dispose();
                }

                return(dictionary);

            case Type.Entity:
                var entityType    = BaseObjectType.Undefined;
                var entityPointer = GetEntityPointer(ref entityType);
                if (entityPointer == IntPtr.Zero)
                {
                    return(null);
                }
                if (Alt.Module.BaseBaseObjectPool.Get(entityPointer, entityType, out var entity))
                {
                    return(entity);
                }

                return(null);

            case Type.Function:
                return(null);

            case Type.Vector3:
                var position = Position.Zero;
                GetVector3(ref position);
                return(position);

            case Type.Rgba:
                var rgba = Rgba.Zero;
                GetRgba(ref rgba);
                return(rgba);

            case Type.ByteArray:
                return(GetByteArray());

            default:
                return(null);
            }
        }