Tool SMAPI: Stardew Modding API

Discussion in 'Mods' started by ClxS, Mar 6, 2016.

Thread Status:
Not open for further replies.
  1. Jessicanity

    Jessicanity Void-Bound Voyager

    Seems to always happen, at least on my current main save (190306304). Haven't tested it on the others recently.
    I'm not sure of an exact time, but when I've been testing it, at or after 5pm does cause the crash, though I'm not sure if it's from 5pm-2am or if there's a time when it starts working again.
     

      Attached Files:

    • jackferno

      jackferno Space Hobo

      here's the file
       

        Attached Files:

      • gothicshy

        gothicshy Intergalactic Tourist

        I just got into the mods of Stardew Valley and now it just crashes seemingly at random... Are the mods I installed outdated or somethin? Pls help...
         

          Attached Files:

        • Pathoschild

          Pathoschild Tiy's Beard

          Try updating to the latest version of SMAPI to fix that. You also have several mods that need an update; see the purple text in the SMAPI console. (Parsed log for reference.)

          It looks like you installed some outdated XNB mods; resetting your content files should fix that. Be careful with XNB mods (the ones that replace files in the Content folder). Those are often outdated, easy to install incorrectly, and can't be validated automatically. SMAPI mods and Content Patcher packs are safer, since they perform compatibility checks automatically. (Parsed log for reference.)
           
          • Pathoschild

            Pathoschild Tiy's Beard

            Can you come come ask in #modding on the Stardew Valley Discord? Your save has some custom content, so it won't load without some custom files you have. It'll be easier to investigate over chat. :)
             
            • Pathoschild

              Pathoschild Tiy's Beard

              SMAPI 2.6 beta 21 is now available! (For Stardew Valley 1.3 beta only.)

              Release notes:
              • Added friendlier error when using SMAPI 2.6 with Stardew Valley 1.2.
              • Fixed mods marked incompatible on Linux/Mac if they reference Microsoft.Xna.Framework.Xact.
              • Fixed console commands being invoked asynchronously.
              • Updated compatibility list.
               
                hatmouse likes this.
              • stinkyfish

                stinkyfish Void-Bound Voyager

                In regards to SMAPI shouldn't one of its main focuses be on allowing easy object/crop/etc to the game? I know this has been discussed somewhat on GITHUB and that Entoarox Framework has done it...but why isn't this a core SMAPI feature?

                Right now i can't make a mod for SMAPI that adds an object and not risk it breaking any other mod which adds an object/crop/whatever. I realize the spritesheets of the game make it somewhat difficult but it isn't exactly a hard thing to overcome when you centralize it all through an API which is what SMAPI is there for.
                 
                • Pathoschild

                  Pathoschild Tiy's Beard

                  @stinkyfish Creating a framework for custom items is harder than you may think (centralised or not), but there are existing frameworks like PyTK and Json Assets you can use. For SMAPI I'm mainly focusing on lower-level features like multiplayer and audio APIs which aren't handled by mod frameworks. SMAPI is open source though, so contributions are welcome if you'd like to work on a custom item API yourself.
                   
                  • Jessicanity

                    Jessicanity Void-Bound Voyager

                    Will do! I've joined so long but it's 2.22am now so I'll pop a message in in the morning.
                     
                    • stinkyfish

                      stinkyfish Void-Bound Voyager

                      Could you briefly summarize why? I added custom items by simply using an ID above all the standard ones and appending them to the sprite sheet at appropriate locations at runtime. This seems incredibly easy to do, so I can't see why SMAPI can't give me an ID to use and create the extra space needed in the spritesheet for my item. It could then save this location by my mod name and number of times I have called "request_itemID" so it gives the same number on the same system each run. Even if an updated version of my mod creates more items provided I kept the ordering it would work as intended. If smapi notices the mod is "gone" it could then open up those spots to new mods if necessary.

                      It seems geodes and rings increase the complexity somewhat but they wouldn't have to necessarily be supported.
                       
                      • Pathoschild

                        Pathoschild Tiy's Beard

                        @stinkyfish What you're suggesting is the ID registry approach.

                        There are a few requirements for that to work well:
                        • A mod can't be assigned another mod's ID.
                        • A mod must always receive the same ID for an item (so their content can be read from the save file).
                        • Saves must be portable — if you load a different save, it should work even if different IDs were assigned for that save.
                        • Saves must be robust — players must be able to remove a custom content mod without being left with invalid data.
                        The API that's been discussed for SMAPI goes something like this:
                        1. A mod requests a unique ID for item key Pineapple:
                          Code:
                          int id = helper.IdRegistry.GetID(ContentType.Crop, "Pineapple");
                          SMAP assigns a unique internal key like PineappleMod/Crop/Pineapple, and saves the key/ID mapping in an app data file. Generated IDs should be high enough to avoid conflicts with future vanilla items.
                        2. The mod injects its item using the content API into the relevant data files (like ObjectInformation.xnb and Crops.xnb) and the spritesheet.
                        3. Right before data is serialised to the save file, SMAPI changes the item ID to 0 (weed) and sets the name to SMAPI/PineappleMod/Crop/Pineapple/1097/Pineapple (containing the internal key, previously assigned ID, and full item name).
                        4. After save, SMAPI switches the item back to normal based on that string.
                        5. When loading an arbitrary save file, SMAPI reads the custom items in the save file and...
                          1. If the mod which added the item isn't loaded, leave the item as-is (in weed form) to avoid errors. If the mod is re-added later, the item data isn't lost and can be restored then.
                          2. Else if the item has an unknown internal key, register it with the given ID. (If the former ID conflicts with an assigned ID, change it.) Then unweed the item.
                          3. Else if the item's former ID doesn't match the ID currently assigned to that key, transparently change the item's ID to match the assigned ID before unweeding the item. (This avoids issues with mods having already saved the assigned ID, e.g. in their Entry methods.)
                          4. Else unweed the item based on that string.
                        This approach ensures you're not left with broken data if the mod is removed, lets you to load a save file with different item IDs by reassigning them automatically, and hides the ID assignment details from mods (so far as your code is concerned, the ID you receive never changes after it's assigned).

                        However, an ID registry has some important limitations:
                        • This only works with vanilla item classes. Mods can't create item subclasses with their own properties and behavior, which significantly limits what they can do.
                        • A lot of the work needs to be handled by the mod (e.g. injecting it into data & spritesheets).
                        • Mods using this ID registry won't conflict with each other, but can conflict with Content Patcher / XNB mods.
                        There are other approaches with their own tradeoffs. For example:
                        • Making the ID mapping save-specific avoids the need to handle ID collisions. However, this means mods can't preload data ahead of time, need to refresh their IDs when the player loads or switches save, and when their ID changes they need to invalidate the assets they changed and re-edit them.
                        • Rewriting the object code to render its own texture avoids ID assignment entirely. However, it also means you can't target the items for features like gift tastes.
                        So it's definitely possible and several modders have thought about or tackled the problem. There are three mod frameworks I can think of which have tackled the problem, and they use three completely different approaches: Json Assets uses an ID registry, PyTK uses object code rewriting, and Entoarox Framework changes the save serialiser.

                        So: possible but not trivial.
                         
                          hatmouse likes this.
                        • stinkyfish

                          stinkyfish Void-Bound Voyager

                          This looks good can't fault it.

                          It can't? Isn't the main reason we need these id's mainly for the game engine to recognize items/crops/etc for the main game engine and to draw them properly? Category is a custom element in Data/ObjectInformation for instance, why couldn't they just put something different there and handle it elsewhere in code?

                          Not if you add the helper functions like "AddItem("ItemString",texturePath);

                          For instance I want to add a redbull drink and I currently do this mod to Data/ObjectInformation
                          asset.AsDictionary<int, string>().Set(804, "RedBull/150/1/Crafting/RedBull/Messes you up but makes you fast./drink/0 0 0 0 0 0 0 0 0 2 0/120");

                          Then this for Maps/springobjects
                          Texture2D texture = Helper.Content.Load<Texture2D>("assets/redbull.png", ContentSource.ModFolder);
                          asset.AsImage().PatchImage(texture, new Rectangle(0,0,16,16),new Rectangle(192,528,16,16));

                          Which SMAPI with AddItem("ItemString",texturePath) could do for you and perhaps return the ID given if necessary to use it in the code. SMAPI could add a bunch of helper functions which add seeds/crops/rings/whatever that needs its own custom handling. In the end a lot of users with no coding experience could then easily add them using "ContentPatcher" and people who are doing code mods still would be compatible and be able to easily add objects too.

                          Content Patcher should probably be updated to use the same method, and XNB mods should be deprecated anyhow.
                           
                          • Pathoschild

                            Pathoschild Tiy's Beard

                            By 'custom class' I mean the C# class (like StardewValley.Object), not the category. Custom subclasses let mods override item methods like performDropDownAction and performObjectDropInAction (e.g. for custom machines), performUseAction and performToolAction, etc. A solution which doesn't allow that is very limited.

                            Yep, there's some extra APIs needed to make an ID registry more convenient.

                            Content Patcher works at the XNB level where this API wouldn't exist. Changing Content Patcher enough to use the suggested API would probably make its format very confusing, and there's already framework mods like Json Assets which specialise in items for that. Ideally the approach SMAPI uses should account for that, which is one of the reasons I don't favour the ID registry approach. Object rewriting (like PyTK does) seems to be a better approach, though it has its own issues. My ideal approach would be a true ID system, but that requires changes to the game itself.
                             
                            • staarfruit

                              staarfruit Pangalactic Porcupine

                              Hello, so I'm having a very odd issue. When I load the game with SMAPI I can't move at all. When I load up the game without SMAPI I can move, so I tried taking all my mods out and trying with just SMAPI to make sure it wasn't a mod. I still cannot move. Did the beta update again earlier today or something? I don't think I have any error messages, but here's my log just to be safe. https://log.smapi.io/vLAw2se5

                              Edit: Just to be safe I also just verified the integrity of the game files and that didn't change anything either sadly.
                               
                                Last edited: Jul 19, 2018
                              • stinkyfish

                                stinkyfish Void-Bound Voyager

                                Sounds like a keyboard/input focus issue.
                                 
                                • staarfruit

                                  staarfruit Pangalactic Porcupine

                                  But if that was it wouldn't it not work in the vanilla game too? Because if I play the game vanilla I can move just fine, but with SMAPI my farmer(s) are just stuck in bed. I've also tried reinstalling SMAPI to see if something somehow got messed up. :/

                                  Also my game was working fine literally a couple of hours ago and I haven't changed any settings on anything.
                                   
                                  • stinkyfish

                                    stinkyfish Void-Bound Voyager

                                    Not necessarily, SMAPI launches its window first then launches Stardew. Have you installed a firewall or antivirus software lately? Sometimes they can mess up input focus in situations like this. Try unplugging the keyboard and putting it back in after youve loaded the game.
                                     
                                    • Allayna

                                      Allayna Ketchup Robot

                                      Having an issue with one of my mods in Content Patcher, giving a console error in SMAPI
                                      This is my mod - https://www.nexusmods.com/stardewvalley/mods/1504/
                                      It runs on the beta version of Stardew just fine, but on the normal version of Stardew, it errors when you try to load a save.
                                      I have freshly installed Stardew, smapi, CP, and my mod on a different computer.
                                      I was able to start a new save just fine, but trying to load that same file a minute later bumps me back to the menu.

                                      https://log.smapi.io/QEZr6DtK
                                       
                                        Last edited: Jul 19, 2018
                                      • staarfruit

                                        staarfruit Pangalactic Porcupine

                                        I haven't installed anything at all today except an update for a completely different game. Also just tried unplugging my keyboard and then plugging it back in after loading up the game, no change. Also opening the menu is completely fine (esc) it's just the letter and number keys for some reason, for example I can't open any of my CJB mods like cheats or the item spawner, I and P. Going to try the magical computer restart and see if that changes anything as it sometimes does. lmao.

                                        Edit: Yupp, the magical computer restart fixed it. I don't know why, but that's never my first thing I try, it should be. :zzz:

                                        Sorry for bugging you. :rofl:
                                         
                                          Last edited: Jul 19, 2018
                                          stinkyfish likes this.
                                        • Pathoschild

                                          Pathoschild Tiy's Beard

                                          @Allayna Stardew Valley 1.3 and SMAPI 2.6 have a lot of improvements for custom maps. They're trickier in earlier versions; in this particular case, make sure any custom non-seasonal tilesheets have "path" or "object" in the name to prevent Stardew Valley 1.2 from trying to seasonalise them.
                                           
                                          Thread Status:
                                          Not open for further replies.

                                          Share This Page