Example #1
0
        internal override void SerializeChunk(UndertaleWriter writer)
        {
            UndertaleInstruction.Reference <UndertaleFunction> .SerializeReferenceChain(writer, writer.undertaleData.Code, Functions);

            writer.WriteUndertaleObject(Functions);
            writer.WriteUndertaleObject(CodeLocals);
        }
 public void Serialize(UndertaleWriter writer)
 {
     if (NewFormat)
     {
         writer.Write(Unknown1);
         writer.Write(Unknown2);
         writer.Write((ulong)Info);
         writer.Write(Scale);
         writer.Write(WindowColor);
         writer.Write(ColorDepth);
         writer.Write(Resolution);
         writer.Write(Frequency);
         writer.Write(VertexSync);
         writer.Write(Priority);
         writer.WriteUndertaleObject(BackImage);
         writer.WriteUndertaleObject(FrontImage);
         writer.WriteUndertaleObject(LoadImage);
         writer.Write(LoadAlpha);
         writer.WriteUndertaleObject(Constants);
     }
     else
     {
         writer.Write((Info & OptionsFlags.FullScreen) == OptionsFlags.FullScreen);
         writer.Write((Info & OptionsFlags.InterpolatePixels) == OptionsFlags.InterpolatePixels);
         writer.Write((Info & OptionsFlags.UseNewAudio) == OptionsFlags.UseNewAudio);
         writer.Write((Info & OptionsFlags.NoBorder) == OptionsFlags.NoBorder);
         writer.Write((Info & OptionsFlags.ShowCursor) == OptionsFlags.ShowCursor);
         writer.Write(Scale);
         writer.Write((Info & OptionsFlags.Sizeable) == OptionsFlags.Sizeable);
         writer.Write((Info & OptionsFlags.StayOnTop) == OptionsFlags.StayOnTop);
         writer.Write(WindowColor);
         writer.Write((Info & OptionsFlags.ChangeResolution) == OptionsFlags.ChangeResolution);
         writer.Write(ColorDepth);
         writer.Write(Resolution);
         writer.Write(Frequency);
         writer.Write((Info & OptionsFlags.NoButtons) == OptionsFlags.NoButtons);
         writer.Write(VertexSync);
         writer.Write((Info & OptionsFlags.ScreenKey) == OptionsFlags.ScreenKey);
         writer.Write((Info & OptionsFlags.HelpKey) == OptionsFlags.HelpKey);
         writer.Write((Info & OptionsFlags.QuitKey) == OptionsFlags.QuitKey);
         writer.Write((Info & OptionsFlags.SaveKey) == OptionsFlags.SaveKey);
         writer.Write((Info & OptionsFlags.ScreenShotKey) == OptionsFlags.ScreenShotKey);
         writer.Write((Info & OptionsFlags.CloseSec) == OptionsFlags.CloseSec);
         writer.Write(Priority);
         writer.Write((Info & OptionsFlags.Freeze) == OptionsFlags.Freeze);
         writer.Write((Info & OptionsFlags.ShowProgress) == OptionsFlags.ShowProgress);
         writer.WriteUndertaleObject(BackImage);
         writer.WriteUndertaleObject(FrontImage);
         writer.WriteUndertaleObject(LoadImage);
         writer.Write((Info & OptionsFlags.LoadTransparent) == OptionsFlags.LoadTransparent);
         writer.Write(LoadAlpha);
         writer.Write((Info & OptionsFlags.ScaleProgress) == OptionsFlags.ScaleProgress);
         writer.Write((Info & OptionsFlags.DisplayErrors) == OptionsFlags.DisplayErrors);
         writer.Write((Info & OptionsFlags.WriteErrors) == OptionsFlags.WriteErrors);
         writer.Write((Info & OptionsFlags.AbortErrors) == OptionsFlags.AbortErrors);
         writer.Write((Info & OptionsFlags.VariableErrors) == OptionsFlags.VariableErrors);
         writer.Write((Info & OptionsFlags.CreationEventOrder) == OptionsFlags.CreationEventOrder);
         writer.WriteUndertaleObject(Constants);
     }
 }
Example #3
0
        internal override void SerializeChunk(UndertaleWriter writer)
        {
            writer.Write(List.Count);
            uint baseAddr = writer.Position;

            for (int i = 0; i < List.Count; i++)
            {
                writer.Write(0);
            }
            for (int i = 0; i < List.Count; i++)
            {
                if (Align)
                {
                    while (writer.Position % Alignment != 0)
                    {
                        writer.Write((byte)0);
                    }
                }
                uint returnTo = writer.Position;
                writer.Position = baseAddr + ((uint)i * 4);
                writer.Write(returnTo);
                writer.Position = returnTo;
                writer.WriteUndertaleObject(List[i]);
            }
        }
Example #4
0
        public void Serialize(UndertaleWriter writer)
        {
            writer.WriteUndertaleString(Name);

            writer.WriteUndertaleObjectPointer(TexturePages);
            writer.WriteUndertaleObjectPointer(Sprites);
            writer.WriteUndertaleObjectPointer(SpineSprites);
            writer.WriteUndertaleObjectPointer(Fonts);
            writer.WriteUndertaleObjectPointer(Tilesets);

            writer.WriteUndertaleObject(TexturePages);
            writer.WriteUndertaleObject(Sprites);
            writer.WriteUndertaleObject(SpineSprites);
            writer.WriteUndertaleObject(Fonts);
            writer.WriteUndertaleObject(Tilesets);
        }
    /// <inheritdoc />
    public void Serialize(UndertaleWriter writer)
    {
        writer.WriteUndertaleString(Name);
        writer.WriteUndertaleString(DisplayName);
        if (EmSizeIsFloat)
        {
            // cast to a float and negate.
            writer.Write(0.0f - EmSize);
        }
        else
        {
            // pre-GMS2.3
            writer.Write(EmSize);
        }

        writer.Write(Bold);
        writer.Write(Italic);
        writer.Write(RangeStart);
        writer.Write(Charset);
        writer.Write(AntiAliasing);
        writer.Write(RangeEnd);
        writer.WriteUndertaleObjectPointer(Texture);
        writer.Write(ScaleX);
        writer.Write(ScaleY);
        if (writer.undertaleData.GeneralInfo?.BytecodeVersion >= 17)
        {
            writer.Write(AscenderOffset);
        }
        if (writer.undertaleData.GMS2022_2)
        {
            writer.Write(Ascender);
        }
        writer.WriteUndertaleObject(Glyphs);
    }
Example #6
0
 public void Serialize(UndertaleWriter writer)
 {
     writer.Write((uint)Count);
     foreach (T obj in this)
     {
         writer.WriteUndertaleObjectPointer <T>(obj);
     }
     for (int i = 0; i < Count; i++)
     {
         try
         {
             (this[i] as UndertaleObjectWithBlobs)?.SerializeBlobBefore(writer);
         }
         catch (UndertaleSerializationException e)
         {
             throw new UndertaleSerializationException(e.Message + "\nwhile writing blob for item " + (i + 1) + " of " + Count + " in a list of " + typeof(T).FullName, e);
         }
     }
     for (int i = 0; i < Count; i++)
     {
         try
         {
             writer.WriteUndertaleObject <T>(this[i]);
             // The last object does NOT get padding (TODO: at least in AUDO)
             if (IndexOf(this[i]) != Count - 1)
             {
                 (this[i] as PaddedObject)?.SerializePadding(writer);
             }
         }
         catch (UndertaleSerializationException e)
         {
             throw new UndertaleSerializationException(e.Message + "\nwhile writing item " + (i + 1) + " of " + Count + " in a list of " + typeof(T).FullName, e);
         }
     }
 }
        internal override void SerializeChunk(UndertaleWriter writer)
        {
            if (List == null)
            {
                return;
            }

            if (writer.undertaleData.UnsupportedBytecodeVersion)
            {
                return;
            }

            UndertaleInstruction.Reference <UndertaleVariable> .SerializeReferenceChain(writer, writer.undertaleData.Code, List);

            if (!writer.Bytecode14OrLower)
            {
                writer.Write(InstanceVarCount);
                writer.Write(InstanceVarCountAgain);
                writer.Write(MaxLocalVarCount);
            }
            foreach (UndertaleVariable var in List)
            {
                writer.WriteUndertaleObject(var);
            }
        }
 public void Serialize(UndertaleWriter writer)
 {
     writer.WriteUndertaleString(FolderName);
     writer.WriteUndertaleString(Name);
     writer.WriteUndertaleString(ClassName);
     writer.WriteUndertaleObject(Files);
 }
Example #9
0
 public void Serialize(UndertaleWriter writer)
 {
     writer.WriteUndertaleString(Name);
     writer.Write(IsSmooth);
     writer.Write(IsClosed);
     writer.Write(Precision);
     writer.WriteUndertaleObject(Points);
 }
 public void Serialize(UndertaleWriter writer)
 {
     writer.WriteUndertaleString(Filename);
     writer.WriteUndertaleString(CleanupScript);
     writer.WriteUndertaleString(InitScript);
     writer.Write((uint)Kind);
     writer.WriteUndertaleObject(Functions);
 }
        internal override void SerializeChunk(UndertaleWriter writer)
        {
            // Update references
            Dictionary <UndertaleFunction, List <UndertaleInstruction> > references = UndertaleInstruction.Reference <UndertaleFunction> .CollectReferences(writer.undertaleData.Code);

            uint pos = writer.Position;

            // TODO: don't repeat the code from VARI, I spent 6 hours debugging the fact that I didn't copy one change from 0 to 1 between them :P
            foreach (UndertaleFunction var in Functions)
            {
                var.Occurrences = references.ContainsKey(var) ? (uint)references[var].Count : 0;
                if (var.Occurrences > 0)
                {
                    var.FirstAddress = references[var][0];
                    for (int i = 0; i < references[var].Count; i++)
                    {
                        uint thisAddr = writer.GetAddressForUndertaleObject(references[var][i]);
                        int  addrDiff;
                        if (i < references[var].Count - 1)
                        {
                            uint nextAddr = writer.GetAddressForUndertaleObject(references[var][i + 1]);
                            addrDiff = (int)(nextAddr - thisAddr);
                        }
                        else
                        {
                            addrDiff = var.UnknownChainEndingValue;
                        }
                        // references[var][i].GetReference<UndertaleFunction>().NextOccurrenceOffset = addrDiff;

                        /*if (addrDiff != references[var][i].GetReference<UndertaleFunction>().NextOccurrenceOffset)
                         *  Debug.WriteLine("FUNC Changes at " + writer.GetAddressForUndertaleObject(references[var][i].GetReference<UndertaleFunction>()) + ": " + references[var][i].GetReference<UndertaleFunction>().NextOccurrenceOffset + " to " + addrDiff);*/
                        writer.Position = writer.GetAddressForUndertaleObject(references[var][i].GetReference <UndertaleFunction>());
                        writer.WriteInt24(addrDiff);
                    }
                }
                else
                {
                    var.FirstAddress = null;
                }
            }
            writer.Position = pos;

            writer.WriteUndertaleObject(Functions);
            writer.WriteUndertaleObject(CodeLocals);
        }
Example #12
0
 public void Serialize(UndertaleWriter writer)
 {
     writer.Write(Unknown1);
     writer.Write(Unknown2);
     writer.Write((ulong)Info);
     writer.Write(Scale);
     writer.Write(WindowColor);
     writer.Write(ColorDepth);
     writer.Write(Resolution);
     writer.Write(Frequency);
     writer.Write(VertexSync);
     writer.Write(Priority);
     writer.WriteUndertaleObject(BackImage);
     writer.WriteUndertaleObject(FrontImage);
     writer.WriteUndertaleObject(LoadImage);
     writer.Write(LoadAlpha);
     writer.WriteUndertaleObject(Constants);
 }
Example #13
0
 public void Serialize(UndertaleWriter writer)
 {
     writer.Write((uint)Locals.Count);
     writer.WriteUndertaleString(Name);
     foreach (LocalVar var in Locals)
     {
         writer.WriteUndertaleObject(var);
     }
 }
 public void Serialize(UndertaleWriter writer)
 {
     writer.WriteUndertaleString(Name);
     writer.Write(ID);
     writer.Write(Kind);
     writer.Write((uint)RetType);
     writer.WriteUndertaleString(ExtName);
     writer.WriteUndertaleObject(Arguments);
 }
Example #15
0
        /// <summary>
        /// TODO!
        /// </summary>
        /// <param name="writer">Where to serialize to.</param>
        public void SerializeBlob(UndertaleWriter writer)
        {
            // padding
            while (writer.Position % 0x80 != 0)
            {
                writer.Write((byte)0);
            }

            writer.WriteUndertaleObject(TextureData);
        }
Example #16
0
 /// <inheritdoc />
 public void Serialize(UndertaleWriter writer)
 {
     writer.Write(Character);
     writer.Write(SourceX);
     writer.Write(SourceY);
     writer.Write(SourceWidth);
     writer.Write(SourceHeight);
     writer.Write(Shift);
     writer.Write(Offset);
     writer.WriteUndertaleObject(Kerning);
 }
Example #17
0
        internal override void SerializeChunk(UndertaleWriter writer)
        {
            UndertaleInstruction.Reference <UndertaleVariable> .SerializeReferenceChain(writer, writer.undertaleData.Code, List);

            writer.Write(InstanceVarCount);
            writer.Write(InstanceVarCountAgain);
            writer.Write(MaxLocalVarCount);
            foreach (UndertaleVariable var in List)
            {
                writer.WriteUndertaleObject(var);
            }
        }
        } = new byte[16];                                        // more high entropy data

        public void Serialize(UndertaleWriter writer)
        {
            writer.Write(DisableDebugger ? (byte)1 : (byte)0);
            writer.Write(BytecodeVersion);
            writer.Write(Unknown);
            writer.WriteUndertaleString(Filename);
            writer.WriteUndertaleString(Config);
            writer.Write(LastObj);
            writer.Write(LastTile);
            writer.Write(GameID);
            writer.Write(Unknown1);
            writer.Write(Unknown2);
            writer.Write(Unknown3);
            writer.Write(Unknown4);
            writer.WriteUndertaleString(Name);
            writer.Write(Major);
            writer.Write(Minor);
            writer.Write(Release);
            writer.Write(Build);
            writer.Write(DefaultWindowWidth);
            writer.Write(DefaultWindowHeight);
            writer.Write((uint)Info);
            if (LicenseMD5.Length != 16)
            {
                throw new IOException("LicenseMD5 has invalid length");
            }
            writer.Write(LicenseMD5);
            writer.Write(LicenseCRC32);
            writer.Write(Timestamp);
            writer.WriteUndertaleString(DisplayName);
            writer.Write(ActiveTargets1);
            writer.Write(ActiveTargets2);
            writer.Write(FunctionClassifications1);
            writer.Write(FunctionClassifications2);
            writer.Write(SteamAppID);
            writer.Write(DebuggerPort);
            writer.WriteUndertaleObject(RoomOrder);
            if (Major >= 2)
            {
                if (GMS2RandomUID.Length != 40)
                {
                    throw new IOException("GMS2RandomUID has invalid length");
                }
                writer.Write(GMS2RandomUID);
                writer.Write(GMS2FPS);
                if (GMS2GameGUID.Length != 16)
                {
                    throw new IOException("GMS2GameGUID has invalid length");
                }
                writer.Write(GMS2AllowStatistics);
                writer.Write(GMS2GameGUID);
            }
        }
 public virtual void Serialize(UndertaleWriter writer)
 {
     writer.Write(IsCurveEmbedded);
     if (IsCurveEmbedded)
     {
         writer.Write(-1);
         writer.WriteUndertaleObject(EmbeddedAnimCurve);
     }
     else
     {
         AssetAnimCurve.Serialize(writer);
     }
 }
        internal override void SerializeChunk(UndertaleWriter writer)
        {
            if (Functions == null && CodeLocals == null)
            {
                return;
            }

            UndertaleInstruction.Reference <UndertaleFunction> .SerializeReferenceChain(writer, writer.undertaleData.Code, Functions);

            if (writer.Bytecode14OrLower)
            {
                foreach (UndertaleFunction f in Functions)
                {
                    writer.WriteUndertaleObject(f);
                }
            }
            else
            {
                writer.WriteUndertaleObject(Functions);
                writer.WriteUndertaleObject(CodeLocals);
            }
        }
        internal override void SerializeChunk(UndertaleWriter writer)
        {
            // Update references
            Dictionary <UndertaleVariable, List <UndertaleInstruction> > references = UndertaleInstruction.Reference <UndertaleVariable> .CollectReferences(writer.undertaleData.Code);

            uint pos = writer.Position;

            foreach (UndertaleVariable var in List)
            {
                var.Occurrences = references.ContainsKey(var) ? (uint)references[var].Count : 0;
                if (var.Occurrences > 0)
                {
                    var.FirstAddress = references[var][0];
                    for (int i = 0; i < references[var].Count; i++)
                    {
                        uint thisAddr = writer.GetAddressForUndertaleObject(references[var][i]);
                        int  addrDiff;
                        if (i < references[var].Count - 1)
                        {
                            uint nextAddr = writer.GetAddressForUndertaleObject(references[var][i + 1]);
                            addrDiff = (int)(nextAddr - thisAddr);
                        }
                        else
                        {
                            addrDiff = var.UnknownChainEndingValue;
                        }
                        // references[var][i].GetReference<UndertaleVariable>().NextOccurrenceOffset = addrDiff;

                        /*if (addrDiff != references[var][i].GetReference<UndertaleVariable>().NextOccurrenceOffset)
                         *  Debug.WriteLine("VARI Changes at " + writer.GetAddressForUndertaleObject(references[var][i].GetReference<UndertaleVariable>()) + ": " + references[var][i].GetReference<UndertaleVariable>().NextOccurrenceOffset + " to " + addrDiff);*/
                        writer.Position = writer.GetAddressForUndertaleObject(references[var][i].GetReference <UndertaleVariable>());
                        writer.WriteInt24(addrDiff);
                    }
                }
                else
                {
                    var.FirstAddress = null;
                }
            }
            writer.Position = pos;

            writer.Write(InstanceVarCount);
            writer.Write(InstanceVarCountAgain);
            writer.Write(MaxLocalVarCount);
            foreach (UndertaleVariable var in List)
            {
                writer.WriteUndertaleObject(var);
            }
        }
 public void Serialize(UndertaleWriter writer)
 {
     writer.Write((ushort)Count);
     for (int i = 0; i < Count; i++)
     {
         try
         {
             writer.WriteUndertaleObject <T>(this[i]);
         }
         catch (UndertaleSerializationException e)
         {
             throw new UndertaleSerializationException(e.Message + "\nwhile writing item " + (i + 1) + " of " + Count + " in a list of " + typeof(T).FullName, e);
         }
     }
 }
 public void Serialize(UndertaleWriter writer)
 {
     writer.Write(Unknown1);
     writer.Write(Unknown2);
     writer.Write(Info);
     writer.Write(Unknown3);
     writer.Write(Unknown4);
     writer.Write(Unknown5);
     writer.Write(Unknown6);
     writer.Write(Unknown7);
     writer.Write(Unknown8);
     writer.Write(Unknown9);
     writer.Write(Unknown10);
     writer.Write(Unknown11);
     writer.Write(Unknown12);
     writer.Write(Unknown13);
     writer.Write(Unknown14);
     writer.WriteUndertaleObject(Constants);
 }
Example #24
0
        public void Serialize(UndertaleWriter writer)
        {
            writer.WriteUndertaleString(Name);

            writer.Write(Moments.Count);
            for (int i = 0; i < Moments.Count; i++)
            {
                // Write the time point
                writer.Write(Moments[i].Step);

                // Unnecessary pointer to next array
                writer.WriteUndertaleObjectPointer(Moments[i].Event);
            }

            for (int i = 0; i < Moments.Count; i++)
            {
                // Write the actions for this moment
                writer.WriteUndertaleObject(Moments[i].Event);
            }
        }
        public void Serialize(UndertaleWriter writer)
        {
            switch (GetInstructionType(Kind))
            {
            case InstructionType.SingleTypeInstruction:
            case InstructionType.DoubleTypeInstruction:
            case InstructionType.ComparisonInstruction:
            {
                writer.Write(DupExtra);
                writer.Write((byte)ComparisonKind);
                byte TypePair = (byte)((byte)Type2 << 4 | (byte)Type1);
                writer.Write(TypePair);
                writer.Write((byte)Kind);
            }
            break;

            case InstructionType.GotoInstruction:
            {
                // See unserialize
                if (JumpOffsetPopenvExitMagic)
                {
                    writer.WriteInt24(0xF00000);
                }
                else
                {
                    uint JumpOffsetFixed = (uint)JumpOffset;
                    JumpOffsetFixed &= ~0xFF800000;
                    writer.WriteInt24((int)JumpOffsetFixed);
                }

                writer.Write((byte)Kind);
            }
            break;

            case InstructionType.PopInstruction:
            {
                if (Type1 == DataType.Int16)
                {
                    // Special scenario - the swap instruction
                    // TODO: Figure out the proper syntax, see #129
                    writer.Write(SwapExtra);
                    byte TypePair = (byte)((byte)Type2 << 4 | (byte)Type1);
                    writer.Write(TypePair);
                    writer.Write((byte)Kind);
                }
                else
                {
                    writer.Write((short)TypeInst);
                    byte TypePair = (byte)((byte)Type2 << 4 | (byte)Type1);
                    writer.Write(TypePair);
                    writer.Write((byte)Kind);
                    writer.WriteUndertaleObject(Destination);
                }
            }
            break;

            case InstructionType.PushInstruction:
            {
                if (Type1 == DataType.Int16)
                {
                    Debug.Assert(Value.GetType() == typeof(short));
                    writer.Write((short)Value);
                }
                else if (Type1 == DataType.Variable)
                {
                    writer.Write((short)TypeInst);
                }
                else
                {
                    writer.Write((short)0);
                }
                writer.Write((byte)Type1);
                writer.Write((byte)Kind);
                switch (Type1)
                {
                case DataType.Double:
                    Debug.Assert(Value.GetType() == typeof(double));
                    writer.Write((double)Value);
                    break;

                case DataType.Float:
                    Debug.Assert(Value.GetType() == typeof(float));
                    writer.Write((float)Value);
                    break;

                case DataType.Int32:
                    Debug.Assert(Value.GetType() == typeof(int));
                    writer.Write((int)Value);
                    break;

                case DataType.Int64:
                    Debug.Assert(Value.GetType() == typeof(long));
                    writer.Write((long)Value);
                    break;

                case DataType.Boolean:
                    Debug.Assert(Value.GetType() == typeof(bool));
                    writer.Write((bool)Value ? 1 : 0);
                    break;

                case DataType.Variable:
                    Debug.Assert(Value.GetType() == typeof(Reference <UndertaleVariable>));
                    writer.WriteUndertaleObject((Reference <UndertaleVariable>)Value);
                    break;

                case DataType.String:
                    Debug.Assert(Value.GetType() == typeof(UndertaleResourceById <UndertaleString, UndertaleChunkSTRG>));
                    writer.WriteUndertaleObject((UndertaleResourceById <UndertaleString, UndertaleChunkSTRG>)Value);
                    break;

                case DataType.Int16:
                    break;
                }
            }
            break;

            case InstructionType.CallInstruction:
            {
                writer.Write(ArgumentsCount);
                writer.Write((byte)Type1);
                writer.Write((byte)Kind);
                writer.WriteUndertaleObject(Function);
            }
            break;

            case InstructionType.BreakInstruction:
            {
                Debug.Assert(Value.GetType() == typeof(short));
                writer.Write((short)Value);
                writer.Write((byte)Type1);
                writer.Write((byte)Kind);
            }
            break;

            default:
                throw new IOException("Unknown opcode " + Kind.ToString().ToUpper());
            }
        }
Example #26
0
        } = new byte[16];                                        // more high entropy data

        public void Serialize(UndertaleWriter writer)
        {
            writer.Write(DisableDebugger ? (byte)1 : (byte)0);
            writer.Write(BytecodeVersion);
            writer.Write(Unknown);
            writer.WriteUndertaleString(Filename);
            writer.WriteUndertaleString(Config);
            writer.Write(LastObj);
            writer.Write(LastTile);
            writer.Write(GameID);
            writer.Write(DirectPlayGuid.ToByteArray());
            writer.WriteUndertaleString(Name);
            writer.Write(Major);
            writer.Write(Minor);
            writer.Write(Release);
            writer.Write(Build);
            writer.Write(DefaultWindowWidth);
            writer.Write(DefaultWindowHeight);
            writer.Write((uint)Info);
            if (LicenseMD5.Length != 16)
            {
                throw new IOException("LicenseMD5 has invalid length");
            }
            writer.Write(LicenseMD5);
            writer.Write(LicenseCRC32);
            writer.Write(Timestamp);
            writer.WriteUndertaleString(DisplayName);

            // Should always be zero.
            writer.Write(ActiveTargets);

            // Very weird value. Decides if Runner should initialize certain subsystems.
            writer.Write((ulong)FunctionClassifications);

            writer.Write(SteamAppID);
            writer.Write(DebuggerPort);
            writer.WriteUndertaleObject(RoomOrder);
            if (Major >= 2)
            {
                // Write random UID
                Random random      = new Random((int)(Timestamp & 4294967295L));
                long   firstRandom = (long)random.Next() << 32 | (long)random.Next();
                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 = Math.Abs((int)((int)(Timestamp & 65535L) / 7 + (GameID - DefaultWindowWidth) + RoomOrder.Count)) % 4;
                GMS2RandomUID.Clear();
                writer.Write(firstRandom);
                GMS2RandomUID.Add(firstRandom);
                for (int i = 0; i < 4; i++)
                {
                    if (i == infoLocation)
                    {
                        writer.Write(infoNumber);
                        GMS2RandomUID.Add(infoNumber);
                    }
                    else
                    {
                        int first  = random.Next();
                        int second = random.Next();
                        writer.Write(first);
                        writer.Write(second);
                        GMS2RandomUID.Add(((long)first << 32) | (long)second);
                    }
                }
                writer.Write(GMS2FPS);
                if (GMS2GameGUID.Length != 16)
                {
                    throw new IOException("GMS2GameGUID has invalid length");
                }
                writer.Write(GMS2AllowStatistics);
                writer.Write(GMS2GameGUID);
            }
        }
        public void Serialize(UndertaleWriter writer)
        {
            writer.WriteUndertaleString(Name);
            writer.Write((uint)Type | 0x80000000u); // in big-endian?

            writer.WriteUndertaleString(GLSL_ES_Vertex);
            writer.WriteUndertaleString(GLSL_ES_Fragment);
            writer.WriteUndertaleString(GLSL_Vertex);
            writer.WriteUndertaleString(GLSL_Fragment);
            writer.WriteUndertaleString(HLSL9_Vertex);
            writer.WriteUndertaleString(HLSL9_Fragment);

            HLSL11_VertexData.Serialize(writer, false);
            HLSL11_PixelData.Serialize(writer, false);

            writer.WriteUndertaleObject(VertexShaderAttributes);

            writer.Write(Version);

            PSSL_VertexData.Serialize(writer);
            PSSL_PixelData.Serialize(writer);
            Cg_PSVita_VertexData.Serialize(writer);
            Cg_PSVita_PixelData.Serialize(writer);

            if (Version >= 2)
            {
                Cg_PS3_VertexData.Serialize(writer);
                Cg_PS3_PixelData.Serialize(writer);
            }

            if (!HLSL11_VertexData.IsNull)
            {
                WritePadding(writer, 7);

                HLSL11_VertexData.WriteData(writer);
            }
            if (!HLSL11_PixelData.IsNull)
            {
                WritePadding(writer, 7);

                HLSL11_PixelData.WriteData(writer);
            }

            if (!PSSL_VertexData.IsNull)
            {
                WritePadding(writer, 7);

                PSSL_VertexData.WriteData(writer);
            }
            if (!PSSL_PixelData.IsNull)
            {
                WritePadding(writer, 7);

                PSSL_PixelData.WriteData(writer);
            }

            if (!Cg_PSVita_VertexData.IsNull)
            {
                WritePadding(writer, 7);

                Cg_PSVita_VertexData.WriteData(writer);
            }
            if (!Cg_PSVita_PixelData.IsNull)
            {
                WritePadding(writer, 7);

                Cg_PSVita_PixelData.WriteData(writer);
            }

            if (Version >= 2)
            {
                if (!Cg_PS3_VertexData.IsNull)
                {
                    WritePadding(writer, 15);

                    Cg_PS3_VertexData.WriteData(writer);
                }
                if (!Cg_PS3_PixelData.IsNull)
                {
                    WritePadding(writer, 15);

                    Cg_PS3_PixelData.WriteData(writer);
                }
            }
        }
Example #28
0
        public void Serialize(UndertaleWriter writer)
        {
            switch (GetInstructionType(Kind))
            {
            case InstructionType.SingleTypeInstruction:
            case InstructionType.DoubleTypeInstruction:
            case InstructionType.ComparisonInstruction:
            {
                writer.Write(DupExtra);
                writer.Write((byte)ComparisonKind);
                byte TypePair = (byte)((byte)Type2 << 4 | (byte)Type1);
                writer.Write(TypePair);
                writer.Write((byte)Kind);
            }
            break;

            case InstructionType.GotoInstruction:
            {
                // TODO: see unserialize
                // TODO: why the hell is there exactly ONE number that was NOT encoded in a weird way? If you just rewrite the file with the 'fix' it differs one one byte
                uint JumpOffsetFixed = (uint)JumpOffset;
                JumpOffsetFixed &= ~0xFF800000;
                if (JumpOffsetIsWeird)
                {
                    JumpOffsetFixed |= 0x00800000;
                }
                writer.WriteInt24((int)JumpOffsetFixed);

                writer.Write((byte)Kind);
            }
            break;

            case InstructionType.PopInstruction:
            {
                writer.Write((short)TypeInst);
                byte TypePair = (byte)((byte)Type2 << 4 | (byte)Type1);
                writer.Write(TypePair);
                writer.Write((byte)Kind);
                writer.WriteUndertaleObject(Destination);
            }
            break;

            case InstructionType.PushInstruction:
            {
                if (Type1 == DataType.Int16)
                {
                    Debug.Assert(Value.GetType() == typeof(short));
                    writer.Write((short)Value);
                }
                else if (Type1 == DataType.Variable)
                {
                    writer.Write((short)TypeInst);
                }
                else
                {
                    writer.Write((short)0);
                }
                writer.Write((byte)Type1);
                writer.Write((byte)Kind);
                switch (Type1)
                {
                case DataType.Double:
                    Debug.Assert(Value.GetType() == typeof(double));
                    writer.Write((double)Value);
                    break;

                case DataType.Float:
                    Debug.Assert(Value.GetType() == typeof(float));
                    writer.Write((float)Value);
                    break;

                case DataType.Int32:
                    Debug.Assert(Value.GetType() == typeof(int));
                    writer.Write((int)Value);
                    break;

                case DataType.Int64:
                    Debug.Assert(Value.GetType() == typeof(long));
                    writer.Write((long)Value);
                    break;

                case DataType.Boolean:
                    Debug.Assert(Value.GetType() == typeof(bool));
                    writer.Write((bool)Value ? 1 : 0);
                    break;

                case DataType.Variable:
                    Debug.Assert(Value.GetType() == typeof(Reference <UndertaleVariable>));
                    writer.WriteUndertaleObject((Reference <UndertaleVariable>)Value);
                    break;

                case DataType.String:
                    Debug.Assert(Value.GetType() == typeof(UndertaleResourceById <UndertaleString>));
                    UndertaleResourceById <UndertaleString> str = (UndertaleResourceById <UndertaleString>)Value;
                    writer.Write(str.Serialize(writer));
                    break;

                case DataType.Int16:
                    break;
                }
            }
            break;

            case InstructionType.CallInstruction:
            {
                writer.Write(ArgumentsCount);
                writer.Write((byte)Type1);
                writer.Write((byte)Kind);
                writer.WriteUndertaleObject(Function);
            }
            break;

            case InstructionType.BreakInstruction:
            {
                Debug.Assert(Value.GetType() == typeof(short));
                writer.Write((short)Value);
                writer.Write((byte)Type1);
                writer.Write((byte)Kind);
            }
            break;

            default:
                throw new IOException("Unknown opcode " + Kind.ToString().ToUpper());
            }
        }
            public void Serialize(UndertaleWriter writer)
            {
                writer.WriteUndertaleString(ModelName);
                writer.WriteUndertaleString(Name);
                writer.Write(BuiltinName);
                writer.Write(Traits);
                writer.Write(IsCreationTrack);

                writer.Write(Tags.Count);
                writer.Write(OwnedResources.Count);
                writer.Write(Tracks.Count);

                foreach (int i in Tags)
                {
                    writer.Write(i);
                }

                foreach (UndertaleResource res in OwnedResources)
                {
                    if (res is UndertaleAnimationCurve)
                    {
                        writer.WriteUndertaleString(GMAnimCurveString);
                        res.Serialize(writer);
                    }
                    else
                    {
                        throw new IOException("Expected an animation curve");
                    }
                }

                foreach (Track t in Tracks)
                {
                    writer.WriteUndertaleObject(t);
                }

                // Now, handle specific keyframe/etc. data
                switch (ModelName.Content)
                {
                case "GMAudioTrack":
                    writer.WriteUndertaleObject(Keyframes as AudioKeyframes);
                    break;

                case "GMInstanceTrack":
                    writer.WriteUndertaleObject(Keyframes as InstanceKeyframes);
                    break;

                case "GMGraphicTrack":
                    writer.WriteUndertaleObject(Keyframes as GraphicKeyframes);
                    break;

                case "GMSequenceTrack":
                    writer.WriteUndertaleObject(Keyframes as SequenceKeyframes);
                    break;

                case "GMSpriteFramesTrack":
                    writer.WriteUndertaleObject(Keyframes as SpriteFramesKeyframes);
                    break;

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

                case "GMBoolTrack":
                    writer.WriteUndertaleObject(Keyframes as BoolKeyframes);
                    break;

                case "GMStringTrack":
                    writer.WriteUndertaleObject(Keyframes as StringKeyframes);
                    break;

                // TODO?
                //case "GMIntTrack":
                //  writer.WriteUndertaleObject(Keyframes as IntKeyframes);
                //  break;
                case "GMRealTrack":
                    writer.WriteUndertaleObject(Keyframes as RealKeyframes);
                    break;
                }
            }
Example #30
0
 internal override void SerializeChunk(UndertaleWriter writer)
 {
     writer.WriteUndertaleObject(Object);
 }