Tool SMAPI: Stardew Modding API

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

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

    ThatNorthernMonkey Aquatic Astronaut

    So correct me if I'm wrong, but you're going to inject code to expose things inside methods that we wouldn't normally be able to get to? So if somebody is wanting to make a mod that disables item removal on death for example, they could make a merge request wrapping that entire section of code in if(ShouldRemoveItemsOnDeath) and put a public property bool ShouldRemoveItemsOnDeath in the class? And then edit it back in every SV update? Or will that just become an unmanageable mess?
     
    • ClxS

      ClxS Pangalactic Porcupine

      This one wont rewrite the code directly for like you said, it'd become a mess.
      I can't find exactly which function is responsible for removing those items, but there would be two ways to go about it. If I've already written an event for it you'd register to say, PlayerEvents.OnPrePlayerDeathRemoveItems, and in the function registered you do e.Cancel = true to stop the rest of the function running - that would stop the items being removed.
      You could do the same by listening to PlayerEvents.OnItemRemovedFromInventory, and manually disabling the function if you detect that it's being called because you just died.

      Which is best just depends on how the game removes those items. I'm not sure yet how it does it.
       
        ThatNorthernMonkey likes this.
      • Sempiternity87

        Sempiternity87 Big Damn Hero

        Started making a mod over the weekend using 39.2 of SMAPI. I'm adding a basement location to the house, and patching the FarmHouse map if it has at least the first upgrade (added stairs, and warps). Everything works fine. When warping from the basement back to the farmhouse, the warp location I specified is being overridden by a function (OnFarmHouseEntry or something) that places the character at the FarmHouse.getEntryPoint instead.

        I can't seem to find a way of getting around this issue in the current version, but it sounds like some of this new stuff may be what I'm looking for.

        Also, any items I place down in the basement get placed just fine, and are still there when returning to the basement in the same play session. It doesn't seem like it saves any of the contents at the end of the night however, and reloading the game gives me back an empty basement. Is there some event I need to register in order to save the content in the basement, or am I just missing something simple? It's possible that there could have been an error when I got married, as I didn't account for that originally when doing the FarmHouse patching, and I didn't make a backup of my save (stupid mistake on my part).

        I haven't made a thread for this mod yet, as I wanted to make sure there aren't game-breaking bugs like the one above. If I can get that resolved, I'll make a thread for it.
         
        • ThatNorthernMonkey

          ThatNorthernMonkey Aquatic Astronaut

          Just something from a PM. Ignore. :)
           

            Attached Files:

            Jinxiewinxie likes this.
          • ssgb99

            ssgb99 Intergalactic Tourist

            now i use SMAPI 0.39.1 but cmd console doesn't open. how to open it? it just run few minute and close when game start.
             
            • Advize

              Advize Cosmic Narwhal

              You don't know what you're talking about. I checked both of those mods and they support both Storm and SMAPI. SMAPI is the superior option when it comes to functionality.
               
              • ClxS

                ClxS Pangalactic Porcupine

                Mmm are you sure you're running StardewModdingAPI.exe, and not Stardew Valley.exe? The console should open even before the game does.
                 
                • ThatNorthernMonkey

                  ThatNorthernMonkey Aquatic Astronaut

                  This is your delay "Revolution" ETA request post. Please state your current ETA after the beep... *beeeep* :V
                   
                  • ClxS

                    ClxS Pangalactic Porcupine

                    I'll open it to modders to give feedback on this week (Sunday at latest, as I have all day free then :)). I'm really open/hoping for feedback from people at that point since I have no experience in API design (C++ game programming/C# webdev is my background). After that we can have a look at how much work needs to be done at that point.
                     
                      dsrules and ThatNorthernMonkey like this.
                    • Zer0Trinity

                      Zer0Trinity Void-Bound Voyager

                      Using Smapi 39.4 - playing one of the dealers games in the casino causes the game to freeze/ unable to do anything, anything to resolve it or should just close game?
                       
                      • ClxS

                        ClxS Pangalactic Porcupine

                        That's a known problem with 0.39.4. It's best to revert to 0.39.2 for now, both .3 and. 4 have a few issues and are marked as pre-release.
                         
                        • Travoos

                          Travoos Gotta Catch 'em All! Mk.2

                          I just picked up SMAPI about a week ago and have been working on adding things without replacing XNB files, and have ran into something that bugs me.

                          In order for my NPC addition to work, I needed to create an override class for it (AshleyNPC) and have the game use that instead. However, it made the game crash when saving/loading, until I put some big annoying code at the start of my mod. I also then attempted using a slightly-modified SObject class (CustomItem) to add a new item, and needed to do the same for that.
                          Basically, I have to entirely replace SaveGame.serializer, SaveGame.farmerSerializer, and SaveGame.locationSerializer, which bugs me since I'm going without XNB modifications just so the mod can be compatible with others that might try to do the same things.

                          Here's the main class for my mod: https://github.com/Club559/AshleyMod/blob/master/AshleyMod/AshleyMod.cs

                          I've never personally touched API code so I wouldn't know how it would be done, but it'd be nice if the API could 'ask' mods if they have any types that need to be included in this list, and then modify the list itself. As far as I know, this is needed for mods to be able to use class overrides of types like NPC and Object and not break the saving feature. Or if there's already a way to do this without completely replacing 3 game variables and I'm just blind, I'd like to know.
                           
                          • Advize

                            Advize Cosmic Narwhal

                            This is a major limitation that several modders are facing currently. Object types to serialize are usually specified in their base classes in attributes that can't be modified during runtime. I'm really not sure what could be done about it either.
                             
                            • ClxS

                              ClxS Pangalactic Porcupine

                              Ah thank you for this! It'll really help with looking into it.
                              There's currently a big rework in progress with a public preview this week. Implementing something like this in a way that lets multiple mods have their own content types is definitely something I want so I'll have a look on how best to do it. I'm thinking about having a ContentRegistry class, where modders must register their new content types in their entry function. After mods have been loaded, it'll then do similar to what you did.
                               
                                Travoos likes this.
                              • keyten

                                keyten Cosmic Narwhal

                                I don't quite understand why you need a new class for your npc. The game loads and saves custom npcs just fine, you just need to add it once and save the game. Portraits and sprites don't require any Xnb modifying and schedules and gift tastes can be loaded dynamically after the game loaded.
                                 
                                • ClxS

                                  ClxS Pangalactic Porcupine

                                  Hey keyten, I haven't had chance to try it yet, but what happens if you try to load a game which has custom NPCs added like that in an unmodded game? (Just trying to decide how to approach it on the API side)
                                   
                                  • keyten

                                    keyten Cosmic Narwhal

                                  • Travoos

                                    Travoos Gotta Catch 'em All! Mk.2

                                    It was my own stupid decision to make the sprite 24 pixels wide, when basically everything in the code says that NPC sprites are 16 pixels wide. Also, custom check actions.
                                     
                                    • keyten

                                      keyten Cosmic Narwhal

                                      Custom check action, got it.
                                      As for wide sprites: just change npc's sprite. Worked fine for me.
                                      [​IMG]
                                       
                                        dsrules likes this.
                                      • Travoos

                                        Travoos Gotta Catch 'em All! Mk.2

                                        I don't know about changing the height, but changing the width made the portrait in the social tab get cut off and completely broke pathfinding. If I didn't use the AshleyNPC class, the NPC would always just walk off into the infinite void
                                         
                                        Thread Status:
                                        Not open for further replies.

                                        Share This Page