Modding Help Game Serialization Help

Discussion in 'Mods' started by zipy199522, Jun 14, 2016.

  1. zipy199522

    zipy199522 Pangalactic Porcupine

    Good evening everyone I hope summer has been treating you all well.
    Let's get down to business. Today I need help from all of you.

    While working on Stardew Valley over the course of the last few days I have run into an issue that i simply don't understand and that is about how the game's internal serializer/ or save game manager works. I'm trying to add a new object type to the game but every time I try and save the game it throws an error at me in SMAPI along these lines.


    [08:41:38.012 PM] [ERROR] An error occurred in the overridden update loop: System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type Stardew_Modding_Expansion.Objects_Extended.Furniture_Extended was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
    at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSaveGame.Write22_Item(String n, String ns, Item o, Boolean isNullable, Boolean needType)
    at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSaveGame.Write122_Farmer(String n, String ns, Farmer o, Boolean isNullable, Boolean needType)
    at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSaveGame.Write127_SaveGame(String n, String ns, SaveGame o, Boolean isNullable, Boolean needType)
    at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSaveGame.Write128_SaveGame(Object o)
    --- End of inner exception stack trace ---
    at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
    at StardewValley.SaveGame.<getSaveEnumerator>d__0.MoveNext()
    at StardewValley.Menus.SaveGameMenu.update(GameTime time)
    at StardewValley.Game1.updateActiveMenu(GameTime gameTime)
    at StardewModdingAPI.Inheritance.SGame.Update(GameTime gameTime)


    I'm not sure at all about how to go about fixing this and any sort of help would be greatly appreciated.

    P.S. If I can get the serializer working, I have a great mod in store that also includes being able to place furniture ANYWHERE in the game. That is just one of the many pieces I am working on right now.

    Thanks!

    -Alpha_Omegasis

    In the meantime I'll just be chilling with my chair at the bus station.
    upload_2016-6-13_20-44-42.png
     
    • Jinxiewinxie

      Jinxiewinxie Farmer Fashionista

    • zipy199522

      zipy199522 Pangalactic Porcupine

    • Hammurabi

      Hammurabi Big Damn Hero

    • zipy199522

      zipy199522 Pangalactic Porcupine

      I tried to use it, but it didn't work?

      Read: Even after completely disabling the native save functionality, and rewriting it as my own, things are still breaking, which means that I simply don't understand XML Serialization in my classes, or the serializer is weirder than I expected it to be.
       
      • ClxS

        ClxS Pangalactic Porcupine

        Mmm what method did you try?
        The way to do it is to edit the SaveGame's serializer, farmerSerializer and locationSerializer prior to saving/loading. Here's how I approach it in Farmhand: https://github.com/ClxS/Stardew-Farmhand/blob/master/Libraries/Farmhand/API/Serializer.cs

        I don't know if there's a way to handle loading XML files which have types which you've not made your serialiser with though, please let me know if you find a way! I've love it use it.
         
        • zipy199522

          zipy199522 Pangalactic Porcupine

          The method I used was probably 1000x more complex than the usual way of doing things.

          1st. I disabled the native save functionality of Stardew. Pretty easy actually since there was already a switch to do this.

          2nd. I ported over the code for the Save functionality (menu and actual savecode) into my project, and it was there that I updated the serializer giving absolute control to everything.

          3rd. I made some new types that allowed me to add in cooler things to Stardew.....however I finally discovered my issue.

          In short what I was trying to do was add in a new type of furniture that would allow players to place their furniture anywhere in the game. This furniture originally derived from the game's native Object code which told the game how to handle everything in the game's world.

          This is where I ran into the problem. In the game's native code it has a bunch of XML include declarations to tell the game what type of objects to expect in the game's world. These include things such as crab pots, boots, fences, etc. However what this doesn't include is a declaration of my new type of object, crudely named Furniture_Extended.

          After basically importing all of the game's native object code into my project and calling it Object_Extended I finally was able to see what my issue was, which was what I stated about Objects telling the game how they worked. What was biggest issue is that it is how Objects are stored to the world and was that each GameLocation had a XML serializable dictionary that had a key value of the vector of the object, and the actual Object type itself, so I knew that I had to do next...

          So basically after porting over the GameLocation code into my project and changed the dictionary info, I ran into my final road block, which was that my new GameLocation types didn't exist in the game. Sure I could copy every native GameLocation into my new GameLocation type, but they didn't exist as the player would always be at the old GameLocation, so the code wouldn't be able to place objects at that location anyways.

          And that is my issue thus far. Storing game objects into the world revert them back to the native Object type and then breaks the serializer.

          I know that this is the issue because I can store my furniture inside my inventory and the serializer doesn't break.

          Sorry if this was a giant wall of (IDontKnowWhatThisIs) but maybe someone with some more code knowledge than me will.

          Anywho thanks again everyone, and have a good one!
           
            BlankSlater likes this.

          Share This Page