コード例 #1
0
        public void Unserialize(UndertaleReader reader)
        {
            Name              = reader.ReadUndertaleString();
            Playback          = (PlaybackType)reader.ReadUInt32();
            PlaybackSpeed     = reader.ReadSingle();
            PlaybackSpeedType = (AnimSpeedType)reader.ReadUInt32();
            Length            = reader.ReadSingle();
            OriginX           = reader.ReadInt32();
            OriginY           = reader.ReadInt32();
            Volume            = reader.ReadSingle();

            BroadcastMessages = reader.ReadUndertaleObject <UndertaleSimpleList <Keyframe <BroadcastMessage> > >();

            Tracks = reader.ReadUndertaleObject <UndertaleSimpleList <Track> >();

            FunctionIDs = new Dictionary <int, UndertaleString>();
            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                int key = reader.ReadInt32();
                FunctionIDs[key] = reader.ReadUndertaleString();
            }

            Moments = reader.ReadUndertaleObject <UndertaleSimpleList <Keyframe <Moment> > >();
        }
コード例 #2
0
        public void Unserialize(UndertaleReader reader)
        {
            Name = reader.ReadUndertaleString();

            int momentCount = reader.ReadInt32();

            // Read the time points for each moment
            uint[] timePoints          = new uint[momentCount];
            int[]  unnecessaryPointers = new int[momentCount];
            for (int i = 0; i < momentCount; i++)
            {
                timePoints[i]          = reader.ReadUInt32();
                unnecessaryPointers[i] = reader.ReadInt32();
            }

            // Read the actions for each moment
            for (int i = 0; i < momentCount; i++)
            {
                if (reader.Position != unnecessaryPointers[i])
                {
                    throw new UndertaleSerializationException("Invalid action list pointer");
                }

                // Read action list and assign time point (put into list)
                var timeEvent = reader.ReadUndertaleObject <UndertalePointerList <UndertaleGameObject.EventAction> >();
                Moments.Add(new UndertaleTimelineMoment(timePoints[i], timeEvent));
            }
        }
コード例 #3
0
        internal override void UnserializeChunk(UndertaleReader reader)
        {
            reader.Position -= 4;
            int  chunkLength = reader.ReadInt32();
            uint chunkEnd    = reader.Position + (uint)chunkLength;

            uint beginPosition = reader.Position;

            // Figure out where the starts/ends of each shader object are
            int count = reader.ReadInt32();

            uint[] objectLocations = new uint[count + 1];
            for (int i = 0; i < count; i++)
            {
                objectLocations[i] = (uint)reader.ReadInt32();
            }
            objectLocations[count] = chunkEnd;

            Dictionary <uint, UndertaleObject> objPool    = reader.GetOffsetMap();
            Dictionary <UndertaleObject, uint> objPoolRev = reader.GetOffsetMapRev();

            // Setup base shader objects with boundaries set. Load into object pool
            // so that they don't immediately discard.
            for (int i = 0; i < count; i++)
            {
                UndertaleShader s = new UndertaleShader {
                    _EntryEnd = objectLocations[i + 1]
                };
                objPool.Add(objectLocations[i], s);
                objPoolRev.Add(s, objectLocations[i]);
            }

            reader.Position = beginPosition;
            base.UnserializeChunk(reader);
        }
コード例 #4
0
 public void Unserialize(UndertaleReader reader)
 {
     Name        = reader.ReadUndertaleString();
     Occurrences = reader.ReadUInt32();
     if (Occurrences > 0)
     {
         if (reader.GMS2_3)
         {
             GMS2_3       = true;
             FirstAddress = reader.GetUndertaleObjectAtAddress <UndertaleInstruction>(reader.ReadUInt32() - 4);
         }
         else
         {
             FirstAddress = reader.ReadUndertaleObjectPointer <UndertaleInstruction>();
         }
         UndertaleInstruction.Reference <UndertaleFunction> .ParseReferenceChain(reader, this);
     }
     else
     {
         if (reader.ReadInt32() != -1)
         {
             throw new Exception("Function with no occurrences, but still has a first occurrence address");
         }
         FirstAddress = null;
     }
 }
コード例 #5
0
    /// <inheritdoc />
    public void Unserialize(UndertaleReader reader)
    {
        Name          = reader.ReadUndertaleString();
        DisplayName   = reader.ReadUndertaleString();
        EmSize        = reader.ReadUInt32();
        EmSizeIsFloat = false;

        // since the float is always written negated, it has the first bit set.
        if ((EmSize & (1 << 31)) != 0)
        {
            float fsize = -BitConverter.ToSingle(BitConverter.GetBytes(EmSize), 0);
            EmSize        = (uint)fsize;
            EmSizeIsFloat = true;
        }

        Bold         = reader.ReadBoolean();
        Italic       = reader.ReadBoolean();
        RangeStart   = reader.ReadUInt16();
        Charset      = reader.ReadByte();
        AntiAliasing = reader.ReadByte();
        RangeEnd     = reader.ReadUInt32();
        Texture      = reader.ReadUndertaleObjectPointer <UndertaleTexturePageItem>();
        ScaleX       = reader.ReadSingle();
        ScaleY       = reader.ReadSingle();
        if (reader.undertaleData.GeneralInfo?.BytecodeVersion >= 17)
        {
            AscenderOffset = reader.ReadInt32();
        }
        if (reader.undertaleData.GMS2022_2)
        {
            Ascender = reader.ReadUInt32();
        }
        Glyphs = reader.ReadUndertaleObject <UndertalePointerList <Glyph> >();
    }
コード例 #6
0
        public void Unserialize(UndertaleReader reader)
        {
            Name        = reader.ReadUndertaleString();
            Occurrences = reader.ReadUInt32();
            if (Occurrences > 0)
            {
                FirstAddress = reader.ReadUndertaleObjectPointer <UndertaleInstruction>();

                // Parse the chain of references
                UndertaleInstruction.Reference <UndertaleFunction> reference = null;
                uint addr = reader.GetAddressForUndertaleObject(FirstAddress);
                for (int i = 0; i < Occurrences; i++)
                {
                    reference = reader.GetUndertaleObjectAtAddress <UndertaleInstruction>(addr).GetReference <UndertaleFunction>();
                    if (reference == null)
                    {
                        throw new IOException("Failed to find reference at " + addr);
                    }
                    reference.Target = this;
                    addr            += (uint)reference.NextOccurrenceOffset;
                }
                UnknownChainEndingValue = reference.NextOccurrenceOffset;
            }
            else
            {
                if (reader.ReadInt32() != -1)
                {
                    throw new Exception("Function with no occurrences, but still has a first occurrence address");
                }
                FirstAddress = null;
            }
        }
コード例 #7
0
 public void Unserialize(UndertaleReader reader)
 {
     InternalCount = reader.ReadInt32();
     if (InternalCount > 0)
     {
         Event = reader.ReadUndertaleString();
     }
 }
コード例 #8
0
            public void Unserialize(UndertaleReader reader)
            {
                Key      = reader.ReadSingle();
                Length   = reader.ReadSingle();
                Stretch  = reader.ReadBoolean();
                Disabled = reader.ReadBoolean();
                int count = reader.ReadInt32();

                Channels = new Dictionary <int, T>();
                for (int i = 0; i < count; i++)
                {
                    int channel = reader.ReadInt32();
                    T   data    = new T();
                    data.Unserialize(reader);
                    Channels[channel] = data;
                }
            }
コード例 #9
0
 public override void Unserialize(UndertaleReader reader)
 {
     base.Unserialize(reader);
     if (reader.ReadUInt32() != 0)
     {
         throw new IOException("Expected 0 in Audio keyframe");
     }
     Mode = reader.ReadInt32();
 }
コード例 #10
0
 public void Unserialize(UndertaleReader reader)
 {
     X     = reader.ReadSingle();
     Value = reader.ReadSingle();
     if (reader.ReadInt32() != 0)
     {
         throw new Exception("Expected 0 in animation curve point"); // TODO? They might add some "control points" here later it seems
     }
 }
コード例 #11
0
            public override void Unserialize(UndertaleReader reader)
            {
                base.Unserialize(reader);

                Interpolation = reader.ReadInt32();

                List = new UndertaleSimpleList <Keyframe <RealData> >();
                List.Unserialize(reader);
            }
コード例 #12
0
 public void Unserialize(UndertaleReader reader)
 {
     Name         = reader.ReadUndertaleString();
     InstanceType = (UndertaleInstruction.InstanceType)reader.ReadInt32();
     VarID        = reader.ReadInt32();
     Occurrences  = reader.ReadUInt32();
     if (Occurrences > 0)
     {
         FirstAddress = reader.ReadUndertaleObjectPointer <UndertaleInstruction>();
         UndertaleInstruction.Reference <UndertaleVariable> .ParseReferenceChain(reader, this);
     }
     else
     {
         if (reader.ReadInt32() != -1)
         {
             throw new Exception("Variable with no occurrences, but still has a first occurrence address");
         }
         FirstAddress = null;
     }
 }
コード例 #13
0
        //private static int id = 0;
        public void Unserialize(UndertaleReader reader)
        {
            Name         = reader.ReadUndertaleString();
            InstanceType = (UndertaleInstruction.InstanceType)reader.ReadInt32();
            VarID        = reader.ReadInt32();
            Occurrences  = reader.ReadUInt32();
            //Debug.WriteLine("Variable " + (id++) + " at " + reader.GetAddressForUndertaleObject(Name).ToString("X8") + " child of " + Unknown);
            if (Occurrences > 0)
            {
                FirstAddress = reader.ReadUndertaleObjectPointer <UndertaleInstruction>();

                // Parse the chain of references
                UndertaleInstruction.Reference <UndertaleVariable> reference = null;
                uint addr = reader.GetAddressForUndertaleObject(FirstAddress);
                for (int i = 0; i < Occurrences; i++)
                {
                    reference = reader.GetUndertaleObjectAtAddress <UndertaleInstruction>(addr).GetReference <UndertaleVariable>();
                    if (reference == null)
                    {
                        throw new IOException("Failed to find reference at " + addr);
                    }
                    reference.Target = this;
                    // Debug.WriteLine("* " + addr.ToString("X8"));
                    addr += (uint)reference.NextOccurrenceOffset;
                }
                //Debug.WriteLine("* " + reference.NextOccurrenceOffset.ToString() + " (ending value)");
                UnknownChainEndingValue = reference.NextOccurrenceOffset;
            }
            else
            {
                if (reader.ReadInt32() != -1)
                {
                    throw new Exception("Variable with no occurrences, but still has a first occurrence address");
                }
                FirstAddress = null;
            }
        }
コード例 #14
0
 public void Unserialize(UndertaleReader reader)
 {
     Unknown1    = reader.ReadUInt32();
     Unknown2    = reader.ReadUInt32();
     Info        = (OptionsFlags)reader.ReadUInt64();
     Scale       = reader.ReadInt32();
     WindowColor = reader.ReadUInt32();
     ColorDepth  = reader.ReadUInt32();
     Resolution  = reader.ReadUInt32();
     Frequency   = reader.ReadUInt32();
     VertexSync  = reader.ReadUInt32();
     Priority    = reader.ReadUInt32();
     BackImage   = reader.ReadUndertaleObject <UndertaleSprite.TextureEntry>();
     FrontImage  = reader.ReadUndertaleObject <UndertaleSprite.TextureEntry>();
     LoadImage   = reader.ReadUndertaleObject <UndertaleSprite.TextureEntry>();
     LoadAlpha   = reader.ReadUInt32();
     Constants   = reader.ReadUndertaleObject <UndertaleSimpleList <Constant> >();
 }
コード例 #15
0
 public void Unserialize(UndertaleReader reader)
 {
     Unknown1  = reader.ReadUInt32();
     Unknown2  = reader.ReadUInt32();
     Info      = reader.ReadUInt32();
     Unknown3  = reader.ReadUInt32();
     Unknown4  = reader.ReadInt32();
     Unknown5  = reader.ReadUInt32();
     Unknown6  = reader.ReadUInt32();
     Unknown7  = reader.ReadUInt32();
     Unknown8  = reader.ReadUInt32();
     Unknown9  = reader.ReadUInt32();
     Unknown10 = reader.ReadUInt32();
     Unknown11 = reader.ReadUInt32();
     Unknown12 = reader.ReadUInt32();
     Unknown13 = reader.ReadUInt32();
     Unknown14 = reader.ReadUInt32();
     Constants = reader.ReadUndertaleObject <UndertaleSimpleList <Constant> >();
 }
コード例 #16
0
 public void Unserialize(UndertaleReader reader)
 {
     DisableDebugger          = reader.ReadByte() != 0 ? true : false;
     BytecodeVersion          = reader.ReadByte();
     Unknown                  = reader.ReadUInt16();
     Filename                 = reader.ReadUndertaleString();
     Config                   = reader.ReadUndertaleString();
     LastObj                  = reader.ReadUInt32();
     LastTile                 = reader.ReadUInt32();
     GameID                   = reader.ReadUInt32();
     Unknown1                 = reader.ReadUInt32();
     Unknown2                 = reader.ReadUInt32();
     Unknown3                 = reader.ReadUInt32();
     Unknown4                 = reader.ReadUInt32();
     Name                     = reader.ReadUndertaleString();
     Major                    = reader.ReadUInt32();
     Minor                    = reader.ReadUInt32();
     Release                  = reader.ReadUInt32();
     Build                    = reader.ReadUInt32();
     DefaultWindowWidth       = reader.ReadUInt32();
     DefaultWindowHeight      = reader.ReadUInt32();
     Info                     = (InfoFlags)reader.ReadUInt32();
     LicenseMD5               = reader.ReadBytes(16);
     LicenseCRC32             = reader.ReadUInt32();
     Timestamp                = reader.ReadUInt64();
     DisplayName              = reader.ReadUndertaleString();
     ActiveTargets1           = reader.ReadUInt32();
     ActiveTargets2           = reader.ReadUInt32();
     FunctionClassifications1 = reader.ReadUInt32();
     FunctionClassifications2 = reader.ReadUInt32();
     SteamAppID               = reader.ReadInt32();
     DebuggerPort             = reader.ReadUInt32();
     RoomOrder                = reader.ReadUndertaleObject <UndertaleSimpleResourcesList <UndertaleRoom, UndertaleChunkROOM> >();
     if (Major >= 2)
     {
         GMS2RandomUID       = reader.ReadBytes(40);
         GMS2FPS             = reader.ReadSingle();
         GMS2AllowStatistics = reader.ReadBoolean();
         GMS2GameGUID        = reader.ReadBytes(16);
     }
     reader.undertaleData.UnsupportedBytecodeVersion = BytecodeVersion < 14 || BytecodeVersion > 17;
     reader.Bytecode14OrLower = BytecodeVersion <= 14;
 }
コード例 #17
0
 public virtual void Unserialize(UndertaleReader reader)
 {
     if (reader.ReadBoolean())
     {
         // The curve data is embedded in this sequence, right here
         IsCurveEmbedded = true;
         if (reader.ReadInt32() != -1)
         {
             throw new IOException("Expected -1");
         }
         EmbeddedAnimCurve = reader.ReadUndertaleObject <UndertaleAnimationCurve>();
     }
     else
     {
         // The curve data is an asset in the project
         IsCurveEmbedded = false;
         AssetAnimCurve  = new UndertaleResourceById <UndertaleAnimationCurve, UndertaleChunkACRV>();
         AssetAnimCurve.Unserialize(reader);
     }
 }
コード例 #18
0
        public void Unserialize(UndertaleReader reader)
        {
            Name = reader.ReadUndertaleString();
            Type = (ShaderType)(reader.ReadUInt32() & 0x7FFFFFFFu); // in big endian?

            GLSL_ES_Vertex = reader.ReadUndertaleString();
            GLSL_ES_Fragment = reader.ReadUndertaleString();
            GLSL_Vertex = reader.ReadUndertaleString();
            GLSL_Fragment = reader.ReadUndertaleString();
            HLSL9_Vertex = reader.ReadUndertaleString();
            HLSL9_Fragment = reader.ReadUndertaleString();

            HLSL11_VertexData.Unserialize(reader, false);
            HLSL11_PixelData.Unserialize(reader, false);

            VertexShaderAttributes = reader.ReadUndertaleObject<UndertaleSimpleList<VertexShaderAttribute>>();

            Version = reader.ReadInt32();

            PSSL_VertexData.Unserialize(reader);
            PSSL_PixelData.Unserialize(reader);
            Cg_PSVita_VertexData.Unserialize(reader);
            Cg_PSVita_PixelData.Unserialize(reader);
            if (Version >= 2)
            {
                Cg_PS3_VertexData.Unserialize(reader);
                Cg_PS3_PixelData.Unserialize(reader);
            }

            if (!HLSL11_VertexData.IsNull)
            {
                ReadPadding(reader, 7);

                // Calculate length of data
                uint next;
                if (!HLSL11_PixelData.IsNull)
                    next = HLSL11_PixelData._Position;
                else
                    next = _EntryEnd;
                int length = (int)(next - reader.Position);
                HLSL11_VertexData.ReadData(reader, length);
            }
            if (!HLSL11_PixelData.IsNull)
            {
                ReadPadding(reader, 7);

                // Calculate length of data
                uint next;
                if (!PSSL_VertexData.IsNull)
                    next = PSSL_VertexData._Position;
                else
                    next = _EntryEnd;
                int length = (int)(next - reader.Position);
                HLSL11_PixelData.ReadData(reader, length);
            }

            if (!PSSL_VertexData.IsNull)
            {
                ReadPadding(reader, 7);

                // Calculate length of data
                uint next;
                if (!PSSL_PixelData.IsNull)
                    next = PSSL_PixelData._Position;
                else
                    next = _EntryEnd;
                int length = (int)(next - reader.Position);
                PSSL_VertexData.ReadData(reader, length);
            }
            if (!PSSL_PixelData.IsNull)
            {
                ReadPadding(reader, 7);

                // Calculate length of data
                uint next;
                if (!Cg_PSVita_VertexData.IsNull)
                    next = Cg_PSVita_VertexData._Position;
                else
                    next = _EntryEnd;
                int length = (int)(next - reader.Position);
                PSSL_PixelData.ReadData(reader, length);
            }

            if (!Cg_PSVita_VertexData.IsNull)
            {
                ReadPadding(reader, 7);

                // Calculate length of data
                uint next;
                if (!Cg_PSVita_PixelData.IsNull)
                    next = Cg_PSVita_PixelData._Position;
                else
                    next = _EntryEnd;
                int length = (int)(next - reader.Position);
                Cg_PSVita_VertexData.ReadData(reader, length);
            }
            if (!Cg_PSVita_PixelData.IsNull)
            {
                ReadPadding(reader, 7);

                // Calculate length of data
                uint next;
                if (!Cg_PS3_VertexData.IsNull)
                    next = Cg_PS3_VertexData._Position;
                else
                    next = _EntryEnd;
                int length = (int)(next - reader.Position);
                Cg_PSVita_PixelData.ReadData(reader, length);
            }

            if (Version >= 2)
            {
                if (!Cg_PS3_VertexData.IsNull)
                {
                    ReadPadding(reader, 15);

                    // Calculate length of data
                    uint next;
                    if (!Cg_PS3_PixelData.IsNull)
                        next = Cg_PS3_PixelData._Position;
                    else
                        next = _EntryEnd;
                    int length = (int)(next - reader.Position);
                    Cg_PS3_VertexData.ReadData(reader, length);
                }
                if (!Cg_PS3_PixelData.IsNull)
                {
                    ReadPadding(reader, 15);

                    // Calculate length of data
                    uint next = _EntryEnd; // final possible data, nothing else to check for
                    int length = (int)(next - reader.Position);
                    Cg_PS3_PixelData.ReadData(reader, length);
                }
            }
        }
コード例 #19
0
        private void CheckForEffectData(UndertaleReader reader)
        {
            // Do a length check on room layers to see if this is 2022.1 or higher
            if (!reader.undertaleData.GMS2022_1 && reader.undertaleData.GMS2_3)
            {
                uint returnTo = reader.Position;

                // Iterate over all rooms until a length check is performed
                int  roomCount = reader.ReadInt32();
                bool finished  = false;
                for (uint roomIndex = 0; roomIndex < roomCount && !finished; roomIndex++)
                {
                    // Advance to room data we're interested in (and grab pointer for next room)
                    reader.Position = returnTo + 4 + (4 * roomIndex);
                    uint roomPtr = (uint)reader.ReadInt32();
                    reader.Position = roomPtr + (22 * 4);

                    // Get the pointer for this room's layer list, as well as pointer to sequence list
                    uint layerListPtr = (uint)reader.ReadInt32();
                    int  seqnPtr      = reader.ReadInt32();
                    reader.Position = layerListPtr;
                    int layerCount = reader.ReadInt32();
                    if (layerCount >= 1)
                    {
                        // Get pointer into the individual layer data (plus 8 bytes) for the first layer in the room
                        uint jumpOffset = (uint)(reader.ReadInt32() + 8);

                        // Find the offset for the end of this layer
                        int nextOffset;
                        if (layerCount == 1)
                        {
                            nextOffset = seqnPtr;
                        }
                        else
                        {
                            nextOffset = reader.ReadInt32(); // (pointer to next element in the layer list)
                        }
                        // Actually perform the length checks, depending on layer data
                        reader.Position = jumpOffset;
                        switch ((LayerType)reader.ReadInt32())
                        {
                        case LayerType.Background:
                            if (nextOffset - reader.Position > 16 * 4)
                            {
                                reader.undertaleData.GMS2022_1 = true;
                            }
                            finished = true;
                            break;

                        case LayerType.Instances:
                            reader.Position += 6 * 4;
                            int instanceCount = reader.ReadInt32();
                            if (nextOffset - reader.Position != (instanceCount * 4))
                            {
                                reader.undertaleData.GMS2022_1 = true;
                            }
                            finished = true;
                            break;

                        case LayerType.Assets:
                            reader.Position += 6 * 4;
                            int tileOffset = reader.ReadInt32();
                            if (tileOffset != reader.Position + 8)
                            {
                                reader.undertaleData.GMS2022_1 = true;
                            }
                            finished = true;
                            break;

                        case LayerType.Tiles:
                            reader.Position += 7 * 4;
                            int tileMapWidth  = reader.ReadInt32();
                            int tileMapHeight = reader.ReadInt32();
                            if (nextOffset - reader.Position != (tileMapWidth * tileMapHeight * 4))
                            {
                                reader.undertaleData.GMS2022_1 = true;
                            }
                            finished = true;
                            break;

                        case LayerType.Effect:
                            reader.Position += 7 * 4;
                            int propertyCount = reader.ReadInt32();
                            if (nextOffset - reader.Position != (propertyCount * 3 * 4))
                            {
                                reader.undertaleData.GMS2022_1 = true;
                            }
                            finished = true;
                            break;
                        }
                    }
                }

                reader.Position = returnTo;
            }
        }
コード例 #20
0
 public void Unserialize(UndertaleReader reader)
 {
     DisableDebugger = reader.ReadByte() != 0 ? true : false;
     BytecodeVersion = reader.ReadByte();
     Unknown         = reader.ReadUInt16();
     Filename        = reader.ReadUndertaleString();
     Config          = reader.ReadUndertaleString();
     LastObj         = reader.ReadUInt32();
     LastTile        = reader.ReadUInt32();
     GameID          = reader.ReadUInt32();
     byte[] GuidData = reader.ReadBytes(16);
     DirectPlayGuid          = new Guid(GuidData);
     Name                    = reader.ReadUndertaleString();
     Major                   = reader.ReadUInt32();
     Minor                   = reader.ReadUInt32();
     Release                 = reader.ReadUInt32();
     Build                   = reader.ReadUInt32();
     DefaultWindowWidth      = reader.ReadUInt32();
     DefaultWindowHeight     = reader.ReadUInt32();
     Info                    = (InfoFlags)reader.ReadUInt32();
     LicenseMD5              = reader.ReadBytes(16);
     LicenseCRC32            = reader.ReadUInt32();
     Timestamp               = reader.ReadUInt64();
     DisplayName             = reader.ReadUndertaleString();
     ActiveTargets           = reader.ReadUInt64();
     FunctionClassifications = (FunctionClassification)reader.ReadUInt64();
     SteamAppID              = reader.ReadInt32();
     DebuggerPort            = reader.ReadUInt32();
     RoomOrder               = reader.ReadUndertaleObject <UndertaleSimpleResourcesList <UndertaleRoom, UndertaleChunkROOM> >();
     if (Major >= 2)
     {
         // Begin parsing random UID, and verify it based on original algorithm
         GMS2RandomUID = new List <long>();
         Random random      = new Random((int)(Timestamp & 4294967295L));
         long   firstRandom = (long)random.Next() << 32 | (long)random.Next();
         if (reader.ReadInt64() != firstRandom)
         {
             //throw new IOException("Unexpected random UID");
         }
         long  infoNumber = (long)(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 ^= BytecodeVersion;
         int infoLocation = (int)(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();
                 curr = infoNumber;
                 GMS2RandomUID.Add(curr);
             }
             else
             {
                 int first  = reader.ReadInt32();
                 int second = reader.ReadInt32();
                 first  = random.Next();
                 second = random.Next();
                 GMS2RandomUID.Add(((long)first << 32) | (long)second);
             }
         }
         GMS2FPS             = reader.ReadSingle();
         GMS2AllowStatistics = reader.ReadBoolean();
         GMS2GameGUID        = reader.ReadBytes(16);
     }
     reader.undertaleData.UnsupportedBytecodeVersion = BytecodeVersion < 14 || BytecodeVersion > 17;
     reader.Bytecode14OrLower = BytecodeVersion <= 14;
 }
コード例 #21
0
 public void Unserialize(UndertaleReader reader)
 {
     NewFormat        = reader.ReadInt32() == int.MinValue;
     reader.Position -= 4;
     if (NewFormat)
     {
         Unknown1    = reader.ReadUInt32();
         Unknown2    = reader.ReadUInt32();
         Info        = (OptionsFlags)reader.ReadUInt64();
         Scale       = reader.ReadInt32();
         WindowColor = reader.ReadUInt32();
         ColorDepth  = reader.ReadUInt32();
         Resolution  = reader.ReadUInt32();
         Frequency   = reader.ReadUInt32();
         VertexSync  = reader.ReadUInt32();
         Priority    = reader.ReadUInt32();
         BackImage   = reader.ReadUndertaleObject <UndertaleSprite.TextureEntry>();
         FrontImage  = reader.ReadUndertaleObject <UndertaleSprite.TextureEntry>();
         LoadImage   = reader.ReadUndertaleObject <UndertaleSprite.TextureEntry>();
         LoadAlpha   = reader.ReadUInt32();
         Constants   = reader.ReadUndertaleObject <UndertaleSimpleList <Constant> >();
     }
     else
     {
         Info = 0;
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.FullScreen;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.InterpolatePixels;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.UseNewAudio;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.NoBorder;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.ShowCursor;
         }
         Scale = reader.ReadInt32();
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.Sizeable;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.StayOnTop;
         }
         WindowColor = reader.ReadUInt32();
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.ChangeResolution;
         }
         ColorDepth = reader.ReadUInt32();
         Resolution = reader.ReadUInt32();
         Frequency  = reader.ReadUInt32();
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.NoButtons;
         }
         VertexSync = reader.ReadUInt32();
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.ScreenKey;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.HelpKey;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.QuitKey;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.SaveKey;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.ScreenShotKey;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.CloseSec;
         }
         Priority = reader.ReadUInt32();
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.Freeze;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.ShowProgress;
         }
         BackImage  = reader.ReadUndertaleObject <UndertaleSprite.TextureEntry>();
         FrontImage = reader.ReadUndertaleObject <UndertaleSprite.TextureEntry>();
         LoadImage  = reader.ReadUndertaleObject <UndertaleSprite.TextureEntry>();
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.LoadTransparent;
         }
         LoadAlpha = reader.ReadUInt32();
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.ScaleProgress;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.DisplayErrors;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.WriteErrors;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.AbortErrors;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.VariableErrors;
         }
         if (reader.ReadBoolean())
         {
             Info |= OptionsFlags.CreationEventOrder;
         }
         Constants = reader.ReadUndertaleObject <UndertaleSimpleList <Constant> >();
     }
 }
コード例 #22
0
 public void Unserialize(UndertaleReader reader)
 {
     ID   = reader.ReadInt32();
     Tags = reader.ReadUndertaleObject <UndertaleSimpleListString>();
 }
コード例 #23
0
        public void Unserialize(UndertaleReader reader)
        {
            uint instructionStartAddress = reader.Position;

            reader.ReadByte(); reader.ReadByte(); reader.ReadByte(); // skip for now, we'll read them later
            Kind            = (Opcode)reader.ReadByte();
            reader.Position = instructionStartAddress;
            switch (GetInstructionType(Kind))
            {
            case InstructionType.SingleTypeInstruction:
            case InstructionType.DoubleTypeInstruction:
            case InstructionType.ComparisonInstruction:
            {
                DupExtra = reader.ReadByte();
                if (DupExtra != 0 && Kind != Opcode.Dup)
                {
                    throw new IOException("Invalid padding in " + Kind.ToString().ToUpper());
                }
                ComparisonKind = (ComparisonType)reader.ReadByte();
                if ((Kind == Opcode.Cmp) != ((byte)ComparisonKind != 0))
                {
                    throw new IOException("Got unexpected comparison type in " + Kind.ToString().ToUpper() + " (should be only in CMP)");
                }
                byte TypePair = reader.ReadByte();
                Type1 = (DataType)(TypePair & 0xf);
                Type2 = (DataType)(TypePair >> 4);
                if (GetInstructionType(Kind) == InstructionType.SingleTypeInstruction && Type2 != (byte)0)
                {
                    throw new IOException("Second type should be 0 in " + Kind.ToString().ToUpper());
                }
                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
            }
            break;

            case InstructionType.GotoInstruction:
            {
                uint v = reader.ReadUInt24();

                JumpOffsetPopenvExitMagic = (v & 0x800000) != 0;

                // The rest is int23 signed value, so make sure
                uint r = v & 0x003FFFFF;
                if (JumpOffsetPopenvExitMagic && v != 0xF00000)
                {
                    throw new Exception("Popenv magic doesn't work, call issue #90 again");
                }
                else
                {
                    if ((v & 0x00C00000) != 0)
                    {
                        r |= 0xFFC00000;
                    }
                    JumpOffset = (int)r;
                }

                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
            }
            break;

            case InstructionType.PopInstruction:
            {
                TypeInst = (InstanceType)reader.ReadInt16();
                byte TypePair = reader.ReadByte();
                Type1 = (DataType)(TypePair & 0xf);
                Type2 = (DataType)(TypePair >> 4);
                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
                if (Type1 == DataType.Int16)
                {
                    // Special scenario - the swap instruction
                    // TODO: Figure out the proper syntax, see #129
                    SwapExtra = (ushort)TypeInst;
                    TypeInst  = 0;
                }
                else
                {
                    Destination = reader.ReadUndertaleObject <Reference <UndertaleVariable> >();
                }
            }
            break;

            case InstructionType.PushInstruction:
            {
                short val = reader.ReadInt16();
                Type1 = (DataType)reader.ReadByte();
                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
                switch (Type1)
                {
                case DataType.Double:
                    Value = reader.ReadDouble();
                    break;

                case DataType.Float:
                    Value = reader.ReadSingle();
                    break;

                case DataType.Int32:
                    Value = reader.ReadInt32();
                    break;

                case DataType.Int64:
                    Value = reader.ReadInt64();
                    break;

                case DataType.Boolean:
                    Value = (reader.ReadUInt32() == 1);             // TODO: double check
                    break;

                case DataType.Variable:
                    TypeInst = (InstanceType)val;
                    Value    = reader.ReadUndertaleObject <Reference <UndertaleVariable> >();
                    break;

                case DataType.String:
                    Value = reader.ReadUndertaleObject <UndertaleResourceById <UndertaleString, UndertaleChunkSTRG> >();
                    break;

                case DataType.Int16:
                    Value = val;
                    break;
                }
            }
            break;

            case InstructionType.CallInstruction:
            {
                ArgumentsCount = reader.ReadUInt16();
                Type1          = (DataType)reader.ReadByte();
                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
                Function = reader.ReadUndertaleObject <Reference <UndertaleFunction> >();
            }
            break;

            case InstructionType.BreakInstruction:
            {
                Value = reader.ReadInt16();
                Type1 = (DataType)reader.ReadByte();
                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
            }
            break;

            default:
                throw new IOException("Unknown opcode " + Kind.ToString().ToUpper());
            }
        }
コード例 #24
0
            public void Unserialize(UndertaleReader reader)
            {
                // This reads the string content immediately, if necessary (which it should be)
                UndertaleString ForceReadString()
                {
                    UndertaleString res      = reader.ReadUndertaleString();
                    uint            returnTo = reader.Position;

                    reader.Position = reader.GetOffsetMapRev()[res];
                    reader.ReadUndertaleObject <UndertaleString>();
                    reader.Position = returnTo;
                    return(res);
                }

                ModelName       = ForceReadString();
                Name            = reader.ReadUndertaleString();
                BuiltinName     = reader.ReadInt32();
                Traits          = reader.ReadInt32();
                IsCreationTrack = reader.ReadBoolean();

                int tagCount      = reader.ReadInt32();
                int ownedResCount = reader.ReadInt32();
                int trackCount    = reader.ReadInt32();

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

                OwnedResources = new List <UndertaleResource>();
                for (int i = 0; i < ownedResCount; i++)
                {
                    GMAnimCurveString = ForceReadString();
                    if (GMAnimCurveString.Content != "GMAnimCurve")
                    {
                        throw new IOException("Expected GMAnimCurve");
                    }
                    UndertaleAnimationCurve res = new UndertaleAnimationCurve();
                    res.Unserialize(reader);
                    OwnedResources.Add(res);
                }

                Tracks = new List <Track>();
                for (int i = 0; i < trackCount; i++)
                {
                    Tracks.Add(reader.ReadUndertaleObject <Track>());
                }

                // Now, handle specific keyframe/etc. data
                switch (ModelName.Content)
                {
                case "GMAudioTrack":
                    Keyframes = reader.ReadUndertaleObject <AudioKeyframes>();
                    break;

                case "GMInstanceTrack":
                    Keyframes = reader.ReadUndertaleObject <InstanceKeyframes>();
                    break;

                case "GMGraphicTrack":
                    Keyframes = reader.ReadUndertaleObject <GraphicKeyframes>();
                    break;

                case "GMSequenceTrack":
                    Keyframes = reader.ReadUndertaleObject <SequenceKeyframes>();
                    break;

                case "GMSpriteFramesTrack":
                    Keyframes = reader.ReadUndertaleObject <SpriteFramesKeyframes>();
                    break;

                case "GMAssetTrack":     // TODO?
                    throw new NotImplementedException("GMAssetTrack not implemented, report this");

                case "GMBoolTrack":
                    Keyframes = reader.ReadUndertaleObject <BoolKeyframes>();
                    break;

                case "GMStringTrack":
                    Keyframes = reader.ReadUndertaleObject <StringKeyframes>();
                    break;

                // TODO?
                //case "GMIntTrack":
                //  Keyframes = reader.ReadUndertaleObject<IntKeyframes>();
                //  break;
                case "GMRealTrack":
                    Keyframes = reader.ReadUndertaleObject <RealKeyframes>();
                    break;
                }
            }
コード例 #25
0
 public void Unserialize(UndertaleReader reader)
 {
     Value = reader.ReadInt32();
 }
コード例 #26
0
 public override void Unserialize(UndertaleReader reader)
 {
     Value = reader.ReadInt32();
     base.Unserialize(reader);
 }
コード例 #27
0
        public void Unserialize(UndertaleReader reader)
        {
            uint instructionStartAddress = reader.Position;

            reader.ReadByte(); reader.ReadByte(); reader.ReadByte(); // skip for now, we'll read them later
            Kind            = (Opcode)reader.ReadByte();
            reader.Position = instructionStartAddress;
            switch (GetInstructionType(Kind))
            {
            case InstructionType.SingleTypeInstruction:
            case InstructionType.DoubleTypeInstruction:
            case InstructionType.ComparisonInstruction:
            {
                DupExtra = reader.ReadByte();
                if (DupExtra != 0 && Kind != Opcode.Dup)
                {
                    throw new IOException("Invalid padding in " + Kind.ToString().ToUpper());
                }
                ComparisonKind = (ComparisonType)reader.ReadByte();
                if ((Kind == Opcode.Cmp) != ((byte)ComparisonKind != 0))
                {
                    throw new IOException("Got unexpected comparison type in " + Kind.ToString().ToUpper() + " (should be only in CMP)");
                }
                byte TypePair = reader.ReadByte();
                Type1 = (DataType)(TypePair & 0xf);
                Type2 = (DataType)(TypePair >> 4);
                if (GetInstructionType(Kind) == InstructionType.SingleTypeInstruction && Type2 != (byte)0)
                {
                    throw new IOException("Second type should be 0 in " + Kind.ToString().ToUpper());
                }
                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
            }
            break;

            case InstructionType.GotoInstruction:
            {
                uint v = reader.ReadUInt24();

                // TODO: This is SO WRONG that I don't even believe it. Is that Int24 or Int23?!?!
                uint r = v & 0x003FFFFF;

                if ((v & 0x00C00000) != 0)
                {
                    r |= 0xFFC00000;
                }

                JumpOffset        = (int)r;
                JumpOffsetIsWeird = (v & 0x00800000) != 0;

                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
            }
            break;

            case InstructionType.PopInstruction:
            {
                TypeInst = (InstanceType)reader.ReadInt16();
                byte TypePair = reader.ReadByte();
                Type1 = (DataType)(TypePair & 0xf);
                Type2 = (DataType)(TypePair >> 4);
                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
                Destination = reader.ReadUndertaleObject <Reference <UndertaleVariable> >();
            }
            break;

            case InstructionType.PushInstruction:
            {
                short val = reader.ReadInt16();
                Type1 = (DataType)reader.ReadByte();
                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
                switch (Type1)
                {
                case DataType.Double:
                    Value = reader.ReadDouble();
                    break;

                case DataType.Float:
                    Value = reader.ReadSingle();
                    break;

                case DataType.Int32:
                    Value = reader.ReadInt32();
                    break;

                case DataType.Int64:
                    Value = reader.ReadInt64();
                    break;

                case DataType.Boolean:
                    Value = (reader.ReadUInt32() == 1);             // TODO: double check
                    break;

                case DataType.Variable:
                    TypeInst = (InstanceType)val;
                    Value    = reader.ReadUndertaleObject <Reference <UndertaleVariable> >();
                    break;

                case DataType.String:
                    UndertaleResourceById <UndertaleString> str = new UndertaleResourceById <UndertaleString>("STRG");
                    str.Unserialize(reader, reader.ReadInt32());
                    Value = str;
                    break;

                case DataType.Int16:
                    Value = val;
                    break;
                }
            }
            break;

            case InstructionType.CallInstruction:
            {
                ArgumentsCount = reader.ReadUInt16();
                Type1          = (DataType)reader.ReadByte();
                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
                Function = reader.ReadUndertaleObject <Reference <UndertaleFunction> >();
            }
            break;

            case InstructionType.BreakInstruction:
            {
                Value = reader.ReadInt16();
                Type1 = (DataType)reader.ReadByte();
                if (reader.ReadByte() != (byte)Kind)
                {
                    throw new Exception("really shouldn't happen");
                }
            }
            break;

            default:
                throw new IOException("Unknown opcode " + Kind.ToString().ToUpper());
            }
        }