Tool SMAPI: Stardew Modding API

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

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

    Androxilogin Giant Laser Beams

    Probably the conversion from .txt to .bat to .exe while playing host to the api.

    It's a simple way to do it, just figured I'd share it. Drag, drop, double-click. I use other options like automatic dropbox uploads, opens stardew_rocks and JoyToKey configs along with the API and close everything as soon as the program exits so it comes in handy for me. I couldn't get anything else to work this way through Steam allowing the overlay to still be displayed. Before I used a .bat, no overlay. Converting it to an .exe solved this problem.
     
    • Nurio

      Nurio Cosmic Narwhal

      But why even do this? What is wrong with a simple .bat file?
       
      • Igorious

        Igorious Sandwich Man

        I'm happy to read that and waiting to try new API.
        What new features will be in Farmhand?
        Seems, it will provide a way to save custom classes? If I'm not mistaken, this is cool!
        I hope, it will be easy to migrate from SMAPI to Farmhand.
         
        • Entoarox

          Entoarox Oxygen Tank

          FarmHand comes with a SMAPI compatiblity layer, most SMAPI mods will "Just work" with FarmHand (Explictly excepting those that modify the Serializer or ContentManager, meaing ALL and similar mods)

          First off, it replaces the Serializer and ContentManager on its own, giving us modders a way to mess with them that doesnt make your mod incompatible with any other mod that does the same thing.
          Second off, FarmHand has some new API's for things like buildings or GUI's, or override textures without needing to mess with the XNB files.
          Finally and perhaps most awesomely it comes with perhaps the most awesome feature yet, the Global Route
          The Global Route is effectively a way to hook into any method in Stardew and replace its behaviours with your own, or (Once CLxS gets done with that part) modify its return value after the fact.

          So this will allow us modders to do many things that are currently simply not possible due to SMAPI's limits :D
           
            Davrial, Hammurabi and Igorious like this.
          • Igorious

            Igorious Sandwich Man

            @Entoarox, thanks for response.
            It's great. Sure, all users will migrate in short terms, if their old mods works with new API.
            I tried to use custom serialization, but seems SerializableDictionary<K,V> with hardcoded types is used everywhere. Is this problem solved?
            Will common repository be used? Or will each mod have separate one?
            I think, now it's not problem at all, because we can just copy mod sprites to appropriate Texture2D static properties and allow doing work to native draw methods.
            I definitely will try to create custom GUI popups and menus, if it is not difficult :)
            It sounds like magic. I can not imagine how it's possible. Does C# provide such functionality?
            Will it works only with virtual methods? I want to change some methods with hardcoded logic, but they are in non-virtual methods. And it's really headache to copy full code of ancestor functions to change single line.
             
              Last edited: May 10, 2016
            • Entoarox

              Entoarox Oxygen Tank

              You will be able to add new types to the Serializer, so if SerializableDictionary doesnt work for you, you can make your own version of it that does :)
              Mods put the files in their own Mods directory, and then tell FarmHand what files and what x,y/width,height they want to replace the texture of
              The Global Route is pretty much magic (@ClxS is obviously a wizard of great renown :p), but it will function similar to Events, just with the added ability to get the arguments for the method in question, and if you want, override its behaviour or simply modify its return value.
               
                Hammurabi and Igorious like this.
              • Igorious

                Igorious Sandwich Man

                OK, I've just read some articles about JIT headers and it's already not so magic for me :)
                But I have some doubts about performance of this approach.
                 
                • Androxilogin

                  Androxilogin Giant Laser Beams

                  Oi.. Because Steam doesn't allow the overlay with a .bat initially! A simple solution, sheesh.
                   
                  • Nurio

                    Nurio Cosmic Narwhal

                    Oi? Sheesh? Such a simple question makes you go Oi and Sheesh?
                     
                    • ClxS

                      ClxS Pangalactic Porcupine

                      It's pretty similar to SMAPI really. Modders will still have access to the actual game objects. Hopefully someone will write a proper API layer at some point in a pull request so modders can indirectly modify things - I just don't have the time to do it right now, and I'm not going to auto-generate it.

                      So far I've been able to add custom items, recipes, buildings (which work with the carpenter), custom NPCs will be coming soon enough. Saving things to the serialiser will be handled automatically by the API. (And I'll be forcing the serialiser to be internal only - so SMAPI mods which change it will be the ones which wont work without changes in Farmhand)

                      Other stuff like mods being automatically unloaded if they cause an error - rather than crashing they'll just be unloaded.

                      Another feature is the GRM, which lets you listen to any function in the game.

                      There was some initial performance problems I had to work out. It works okay on my machine now and it has such a low profiling footprint, but I'll need some lower-end machines to test it on. It works by injecting a pre-post function call into every method in the game. A modder would use the GlobalRouteManager.Listen("ClassName", "MethodName", Callback) to attach a listener for whatever methods they want.

                      Injection is handled at install time

                      The global route method and cancellable events would let you cancel a function and provide your own implementation, but like you said you'd need reflection to get at any private variables that involves changing.
                      Alternatively, I can selectively make classes public/virtual using injection. That only can happen at install time so requires a API change - but I'm pretty open to adding whatever people want.

                      Sooooo, to explain how it works, the injected GRM call would look like this when decompiled:
                      Code:
                      if(GlobalRouteManager.IsEnabled)
                      {
                          if(GlobalRouteManager.IsBeingPreListenedTo(FunctionsGeneratedIndex))
                          {
                               object outputObj;
                               if(GlobalRouteManager.PreInvoke(FunctionsGeneratedIndex, ref outputObj, params))
                               {
                                   stackPushAndCast outputObj;
                                   goto LastInstructionInMethod //Will pretty much always be a ret operation.
                               }
                          }
                      }
                      
                       
                        Last edited: May 10, 2016
                        Hammurabi and Igorious like this.
                      • Androxilogin

                        Androxilogin Giant Laser Beams

                        Just what I was getting at in the beginning. Understandable to be weary of .exe files, I want to reassure everyone that I'm not interested in harming anyone's computer. And to imply it is indeed a fix, it makes it work correctly when otherwise it wouldn't.
                         
                        • Deadcoffee

                          Deadcoffee Void-Bound Voyager

                          Noob question, but I'm honestly confused. Why do some mods say to throw them into the Mods folder in the game directory, and some in AppData/Stardew Valley directory?

                          EDIT:
                          Thanks. Such inconsistency was just a bit weird to me...
                           
                            Last edited: May 12, 2016
                          • Nurio

                            Nurio Cosmic Narwhal

                            Because SMAPI checks for both locations. It doesn't matter which you pick
                             
                            • KindleBoy123

                              KindleBoy123 Orbital Explorer

                              I want to install the In-Game Cheat Menu, but in the "How to install" section, it says make sure to have SMAPI 0.37.1+ installed. I have SMAPI 0.40.0, will the mod still work?
                               
                              • Nurio

                                Nurio Cosmic Narwhal

                                It will definitely work

                                (Or at least, if it doesn't work, it isn't because of this.)
                                 
                                • KindleBoy123

                                  KindleBoy123 Orbital Explorer

                                  Thx
                                   
                                  • FarmerSunflower

                                    FarmerSunflower Space Hobo

                                    Alright, I browsed the thread, and can't seem to find the issue I'm having; I apologize if I missed it, and I apologize if it's not with SMAPI itself, but with one of the mods I'm using. I'm not sure where the problem lies.

                                    I'm running SMAPI, Advanced Location Loader, Tego's Stardew Expanded, and Yama's Desert Expansion. Started a new game, and after day 28 of Spring, it immediately jumps to saying Day 30; the game no longer saves after this point, after sleeping in bed, my character awakes in front of the door, the calendar does not update (but my crops from Spring are dead, and Pierre sells new seeds, new fish appear, new forage appears, etc). I have no clue what's going on, and I'm hoping someone can help me figure it out.
                                     
                                    • Androxilogin

                                      Androxilogin Giant Laser Beams

                                      I can't say I've heard of or used Yama's Desert Expansion, nor can I find it anywhere. As for the others I've never run into any problems so I'd say that may be where your problem lies. Hope you have a backup save!
                                       
                                      • Nurio

                                        Nurio Cosmic Narwhal

                                        If he runs Stardew Valley 1.07, it should create an automatic backup of the previous day. As long as he didn't save again after this glitch occured, the backup should be there
                                         
                                        • Androxilogin

                                          Androxilogin Giant Laser Beams

                                          I suppose that's true but sometimes the addiction takes over and you just can't stop yourself. Noverwrite is also awesome when it comes to this.
                                           
                                          Thread Status:
                                          Not open for further replies.

                                          Share This Page