コード例 #1
0
        public SubBufferMemoryBehaviorConfiguration <T> WithSize(int offset, int size)
        {
            var elementSize = Marshal.SizeOf <T>();
            var region      = new BufferRegion((uint)elementSize * (uint)offset, (uint)elementSize * (uint)size);

            return(new SubBufferMemoryBehaviorConfiguration <T>(Api, Context, MemoryObjectCreatedCallback, _parent, region));
        }
コード例 #2
0
ファイル: Asset.cs プロジェクト: TheEternalShine/dog-scepter
 /// <summary>
 /// Stores and computes the length and hash of a given asset's buffer.
 /// Takes in a BufferRegion instead of a byte[]
 /// </summary>
 public static void ComputeHash(Asset asset, BufferRegion buff)
 {
     asset.Length           = buff.Length;
     using SHA1Managed sha1 = new SHA1Managed();
     using Stream s         = buff.Memory.AsStream();
     asset.Hash             = sha1.ComputeHash(s);
 }
コード例 #3
0
        public void Unserialize(GMDataReader reader)
        {
            int startOffset = reader.Offset;

            if (!reader.ReadBytes(8).Memory.ToArray().SequenceEqual(new byte[8] {
                137, 80, 78, 71, 13, 10, 26, 10
            }))
            {
                reader.Warnings.Add(new GMWarning("PNG header expected.", GMWarning.WarningLevel.Bad));
            }

            while (true)
            {
                uint   length = (uint)reader.ReadByte() << 24 | (uint)reader.ReadByte() << 16 | (uint)reader.ReadByte() << 8 | (uint)reader.ReadByte();
                string type   = reader.ReadChars(4);
                reader.Offset += (int)length + 4;
                if (type == "IEND")
                {
                    break;
                }
            }

            int texLength = reader.Offset - startOffset;

            reader.Offset = startOffset;
            Data          = reader.ReadBytes(texLength);
        }
コード例 #4
0
ファイル: ModelBasedTest.cs プロジェクト: istolboff/FixedTrie
 public AllocatedBlocksChange(
     IReadOnlyList <BufferRegion> allocatedBlocks,
     AllocatorRequestType requestType,
     BufferRegion changedRegion)
 {
     AllocatedBlocks = allocatedBlocks;
     RequestType     = requestType;
     ChangedRegion   = changedRegion;
 }
コード例 #5
0
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

            List = new GMUniquePointerList <GMFont>();
            List.Unserialize(reader);

            Padding = reader.ReadBytes(512);
        }
コード例 #6
0
ファイル: ModelBasedTest.cs プロジェクト: istolboff/FixedTrie
            private static BufferRegion Join(BufferRegion region1, BufferRegion region2, BufferRegion?region3 = null)
            {
                Assert.IsTrue(region1.End + 2 * sizeof(short) == region2.Start);
                if (region3 != null)
                {
                    Assert.IsTrue(region2.End + 2 * sizeof(short) == region3.Value.Start);
                }

                return(region3 == null
                    ? new BufferRegion(region1.Buffer, regionStart: region1.Start, regionLength: region1.Length + 2 * sizeof(short) + region2.Length)
                    : new BufferRegion(region1.Buffer, regionStart: region1.Start, regionLength: region1.Length + 2 * sizeof(short) + region2.Length + 2 * sizeof(short) + region3.Value.Length));
            }
コード例 #7
0
ファイル: SUT.cs プロジェクト: istolboff/FixedTrie
        public MemoryAllocator()
        {
            _buffer = new byte[32 * 1024];

            var wholeBufferRegion = new BufferRegion(_buffer, regionLength: _buffer.Length, regionStart: 0);

            var(firtsFreeBlockReferenceHolder, initialFreeBlock) = wholeBufferRegion.Split(sizeof(short));

            var theOnlyFreeBlock = AllocationBlock.SetupBlock(initialFreeBlock, true);

            new FreeBlock(theOnlyFreeBlock).NextFreeBlockReference.Reset();

            _referenceToFirstFreeBlock = new MemoryReference(firtsFreeBlockReferenceHolder);
            _referenceToFirstFreeBlock.Set(theOnlyFreeBlock);
        }
コード例 #8
0
        public void Unserialize(GMDataReader reader)
        {
            Name         = reader.ReadStringPointerObject();
            Width        = reader.ReadInt32();
            Height       = reader.ReadInt32();
            MarginLeft   = reader.ReadInt32();
            MarginRight  = reader.ReadInt32();
            MarginBottom = reader.ReadInt32();
            MarginTop    = reader.ReadInt32();
            Transparent  = reader.ReadWideBoolean();
            Smooth       = reader.ReadWideBoolean();
            Preload      = reader.ReadWideBoolean();
            BBoxMode     = reader.ReadUInt32();
            SepMasks     = (SepMaskType)reader.ReadInt32();
            OriginX      = reader.ReadInt32();
            OriginY      = reader.ReadInt32();

            TextureItems = new GMRemotePointerList <GMTextureItem>();
            if (reader.ReadInt32() == -1)
            {
                // Special/GMS2 sprite type
                SpecialOrGMS2 = true;

                int version = reader.ReadInt32();
                S_SpriteType = (SpriteType)reader.ReadInt32();
                if (reader.VersionInfo.IsNumberAtLeast(2))
                {
                    GMS2_PlaybackSpeed     = reader.ReadSingle();
                    GMS2_PlaybackSpeedType = (AnimSpeedType)reader.ReadInt32();
                    if (version >= 2)
                    {
                        GMS2_3_Sequence = reader.ReadPointerObjectUnique <SequenceReference>();
                        if (version >= 3)
                        {
                            reader.VersionInfo.SetNumber(2, 3, 2);
                            GMS2_3_2_NineSlice = reader.ReadPointerObjectUnique <NineSlice>();
                        }
                    }
                }

                switch (S_SpriteType)
                {
                case SpriteType.Normal:
                    TextureItems.Unserialize(reader);
                    ParseMaskData(reader);
                    break;

                case SpriteType.SWF:
                {
                    if (reader.ReadInt32() != 8)
                    {
                        reader.Warnings.Add(new GMWarning("SWF format not correct"));
                    }
                    TextureItems.Unserialize(reader);

                    // Parse the actual data
                    reader.Pad(4);
                    int begin            = reader.Offset;
                    int jpegTablesLength = (reader.ReadInt32() & ~int.MinValue);
                    if (reader.ReadInt32() != 8)
                    {
                        reader.Warnings.Add(new GMWarning("SWF format not correct"));
                    }
                    reader.Offset += jpegTablesLength;
                    reader.Pad(4);
                    reader.Offset += (reader.ReadInt32() * 8) + 4;
                    int frameCount = reader.ReadInt32();
                    reader.Offset += 16;
                    int maskCount = reader.ReadInt32();
                    reader.Offset += 8;
                    for (int i = 0; i < frameCount; i++)
                    {
                        reader.Offset += (reader.ReadInt32() * 100) + 16;
                    }
                    for (int i = 0; i < maskCount; i++)
                    {
                        reader.Offset += reader.ReadInt32();
                        reader.Pad(4);
                    }
                    int swfDataLength = reader.Offset - begin;
                    reader.Offset = begin;
                    S_Buffer      = reader.ReadBytes(swfDataLength);
                }
                break;

                case SpriteType.Spine:
                {
                    reader.Pad(4);

                    int begin = reader.Offset;
                    reader.ReadUInt32();         // version number
                    int jsonLength    = reader.ReadInt32();
                    int atlasLength   = reader.ReadInt32();
                    int textureLength = reader.ReadInt32();
                    reader.ReadUInt32();         // atlas tex width
                    reader.ReadUInt32();         // atlas tex height
                    reader.Offset = begin;

                    S_Buffer = reader.ReadBytes(24 + jsonLength + atlasLength + textureLength);
                }
                break;
                }
            }
            else
            {
                // Normal, GM:S 1.4 sprite
                reader.Offset -= 4;
                TextureItems.Unserialize(reader);
                ParseMaskData(reader);
            }
        }
コード例 #9
0
        public void Unserialize(GMDataReader reader)
        {
            int length = reader.ReadInt32();

            Data = reader.ReadBytes(length);
        }
コード例 #10
0
 internal SubBufferMemoryBehaviorConfiguration(IOpenClApi api, Context context, Action <SubBuffer <T> > memoryObjectCreatedCallback, Buffer <T> parent, BufferRegion region)
     : base(api, context, memoryObjectCreatedCallback)
 {
     _parent = parent;
     _region = region;
 }
コード例 #11
0
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

            DisableDebug = reader.ReadBoolean();
            FormatID     = reader.ReadByte();
            reader.VersionInfo.FormatID = FormatID;
            Unknown      = reader.ReadInt16();
            Filename     = reader.ReadStringPointerObject();
            Config       = reader.ReadStringPointerObject();
            LastObjectID = reader.ReadInt32();
            LastTileID   = reader.ReadInt32();
            GameID       = reader.ReadInt32();
            LegacyGUID   = new Guid(reader.ReadBytes(16).Memory.ToArray());
            GameName     = reader.ReadStringPointerObject();
            Major        = reader.ReadInt32();
            Minor        = reader.ReadInt32();
            Release      = reader.ReadInt32();
            Build        = reader.ReadInt32();
            reader.VersionInfo.SetNumber(Major, Minor, Release, Build);
            DefaultWindowWidth  = reader.ReadInt32();
            DefaultWindowHeight = reader.ReadInt32();
            Info                    = (InfoFlags)reader.ReadUInt32();
            LicenseCRC32            = reader.ReadInt32();
            LicenseMD5              = reader.ReadBytes(16);
            Timestamp               = reader.ReadInt64();
            DisplayName             = reader.ReadStringPointerObject();
            ActiveTargets           = reader.ReadInt64();
            FunctionClassifications = (FunctionClassification)reader.ReadUInt64();
            SteamAppID              = reader.ReadInt32();
            if (FormatID >= 14)
            {
                DebuggerPort = reader.ReadInt32();
            }

            int count = reader.ReadInt32();

            RoomOrder = new List <int>(count);
            for (int i = 0; i < count; i++)
            {
                RoomOrder.Add(reader.ReadInt32());
            }

            if (reader.VersionInfo.Major >= 2)
            {
                // Begin parsing random UID, and verify it based on original algorithm
                GMS2_RandomUID = new List <long>();

                Random random      = new Random((int)(Timestamp & 4294967295L));
                long   firstRandom = (long)random.Next() << 32 | (long)random.Next();
                if (reader.ReadInt64() != firstRandom)
                {
                    reader.Warnings.Add(new GMWarning("Unexpected random UID", GMWarning.WarningLevel.Info));
                }
                long  infoNumber = Timestamp - 1000;
                ulong temp       = (ulong)infoNumber;
                temp = ((temp << 56 & 18374686479671623680UL) | (temp >> 8 & 71776119061217280UL) |
                        (temp << 32 & 280375465082880UL) | (temp >> 16 & 1095216660480UL) | (temp << 8 & 4278190080UL) |
                        (temp >> 24 & 16711680UL) | (temp >> 16 & 65280UL) | (temp >> 32 & 255UL));
                infoNumber  = (long)temp;
                infoNumber ^= firstRandom;
                infoNumber  = ~infoNumber;
                infoNumber ^= ((long)GameID << 32 | (long)GameID);
                infoNumber ^= ((long)(DefaultWindowWidth + (int)Info) << 48 |
                               (long)(DefaultWindowHeight + (int)Info) << 32 |
                               (long)(DefaultWindowHeight + (int)Info) << 16 |
                               (long)(DefaultWindowWidth + (int)Info));
                infoNumber ^= FormatID;
                int infoLocation = Math.Abs((int)(Timestamp & 65535L) / 7 + (GameID - DefaultWindowWidth) + RoomOrder.Count) % 4;
                for (int i = 0; i < 4; i++)
                {
                    if (i == infoLocation)
                    {
                        long curr = reader.ReadInt64();
                        GMS2_RandomUID.Add(curr);
                        if (curr != infoNumber)
                        {
                            reader.Warnings.Add(new GMWarning("Unexpected random UID info", GMWarning.WarningLevel.Info));
                        }
                    }
                    else
                    {
                        int first  = reader.ReadInt32();
                        int second = reader.ReadInt32();
                        if (first != random.Next())
                        {
                            reader.Warnings.Add(new GMWarning("Unexpected random UID", GMWarning.WarningLevel.Info));
                        }
                        if (second != random.Next())
                        {
                            reader.Warnings.Add(new GMWarning("Unexpected random UID", GMWarning.WarningLevel.Info));
                        }
                        GMS2_RandomUID.Add((long)(first << 32) | (long)second);
                    }
                }

                // Other GMS2-specific data
                GMS2_FPS             = reader.ReadSingle();
                GMS2_AllowStatistics = reader.ReadWideBoolean();
                GMS2_GameGUID        = new Guid(reader.ReadBytes(16).Memory.ToArray());
            }
        }
コード例 #12
0
 public void Unserialize(GMDataReader reader, int length)
 {
     Buffer = reader.ReadBytes(length);
 }
コード例 #13
0
 public CachedSoundRefData(BufferRegion soundBuffer, string audioGroupName)
 {
     SoundBuffer    = soundBuffer;
     AudioGroupName = audioGroupName;
 }