Tutorial Basic Patching Now With Path Guide [v1.9]

Discussion in 'Starbound Modding' started by The | Suit, Sep 19, 2014.

  1. The | Suit

    The | Suit Agent S. Forum Moderator

    UPDATED TO v1.5
    ADDED A SMALL EXAM QUESTION AT END OF TUTORIAL, TO CHECK TO SEE HOW MUCH YOU LEARNED
     
  2. Wise Nyt

    Wise Nyt Subatomic Cosmonaut

    I was pretty sure that the ogg. was just for music but the text I saw didn't just appear in ogg. files. I saw other files which weren't ogg. have the kind of text. The shipworld file, metadata and BAK files all have it look the same way, I just wanted to be sure instead of just assuming and possibly getting it wrong. Thanks for the guide though.
     
  3. The | Suit

    The | Suit Agent S. Forum Moderator

    Well the general rule of thumb is only the files inside the unpacked folder you made is moddable.


    UPDATED TO v1.6
    ADDED KNOWN ISSUES SECTION

    UPDATED TO v1.7
    ADDED ONLINE COMMENT STRIPPER

    Comment stripper will automatically remove comment tags from a file. This will help make testing patches much easier.
     
    Last edited: Jan 22, 2015
  4. Silent Strider

    Silent Strider Pangalactic Porcupine

    A small question: I want to add an element to the end of the "/learnBlueprintsOnPickup" array in a number of items (more specifically, the ores). Some of them come with that array already defined and some don't. Is there a way to alternatively add elements to an array if it exists, and add a whole array if it doesn't, so I don't clobber elements that already exist?
     
  5. The | Suit

    The | Suit Agent S. Forum Moderator


    For an already existing array you can only add 1 item at a time. Something very important to remember.

    Code:
    [{
    "op" : "add",
    "path" : "/learnBlueprintsOnPickup/-",
    "value" : "dog"
    }]
    If the array doesn't exist you can add as many as you want
    Code:
    [{
    "op" : "add",
    "path" : "/learnBlueprintsOnPickup",
    "value" : ["dog", "cat", "cow", "chicken"]
    }]
     
  6. AstralGhost

    AstralGhost Pangalactic Porcupine

    I think Silent Strider is asking about the "test" operation, swat.
     
  7. The | Suit

    The | Suit Agent S. Forum Moderator

    Ohhhhh....
    Well the way test works is - if that argument is false. It kills the entire patch file. Kind of a Do or die mechanic. So there really is no wiggle room.
     
  8. Silent Strider

    Silent Strider Pangalactic Porcupine

    My question was more about if there is a way to add an element to an array regardless of whether it exists or not, and if it does already exits without clobbering what is already there. Both to be future-proof (if the game adds that array to a file I'm modifying, my patch adding the array again will remove what is already there, creating errors that could be potentially hard to figure) and to increase mod compatibility (if going by the RFC, two mods trying to add the same array to the same file will conflict without an error message, removing the changes made by the first one).

    In other words, I want to know if there is a single patch when applied to:
    Code:
    {
      "itemName" : "uraniumore",
      "rarity" : "Uncommon",
      "inventoryIcon" : "uraniumore.png",
      "description" : "It's uranium. A good source of fuel.",
      "shortdescription" : "Uranium Ore",
      "fuelAmount" : 4
    }
    turns it into
    Code:
    {
      "itemName" : "uraniumore",
      "rarity" : "Uncommon",
      "inventoryIcon" : "uraniumore.png",
      "description" : "It's uranium. A good source of fuel.",
      "shortdescription" : "Uranium Ore",
      "fuelAmount" : 4,
      "learnBlueprintsOnPickup" : [  "testObject" ]
    }
    and when applied to
    Code:
    {
      "itemName" : "uraniumore",
      "rarity" : "Uncommon",
      "inventoryIcon" : "uraniumore.png",
      "description" : "It's uranium. A good source of fuel.",
      "shortdescription" : "Uranium Ore",
      "fuelAmount" : 4,
      "learnBlueprintsOnPickup" : [  "oldBlueprint" ]
    }
    turns it into
    Code:
    {
      "itemName" : "uraniumore",
      "rarity" : "Uncommon",
      "inventoryIcon" : "uraniumore.png",
      "description" : "It's uranium. A good source of fuel.",
      "shortdescription" : "Uranium Ore",
      "fuelAmount" : 4,
      "learnBlueprintsOnPickup" : [  "oldBlueprint", "testObject" ]
    }
    If there isn't, no biggie, I'll simply shelve the idea and deal with conflicts as they happen (though I do think it would be something nice for the devs to add, makes mod compatibility easier).
     
  9. The | Suit

    The | Suit Agent S. Forum Moderator

    Aye - I wunderstood after Astral suggested test. His reasoning would have been more closer to home.
    Starbound is not full RFC complaint so if you use add function to overwrite an existing data set it will cause starbound to crash.

    It can only be done on a non existing data set..
    Overwrite will crash if that path does not exist.
    So the best option would have been test - but test is a do or die patch system. If the test fails the patch dies.

    If the test system was more robust you would have been good.
    ==
    So the answer would be No. Right now there is no way to make it compliant.
     
  10. AstralGhost

    AstralGhost Pangalactic Porcupine

    I was trying to think of a workaround to this, and the real problem lies in not having a 'not' feature.
    So here's my solution: We need a "testnot" operation for performing the patch only when the test fails. :D

    Either that or just make the entire system compliant so the entire patch fails if it doesn't succeed instead of corrupting the JSON file. Come on, Devs, one or the other! :p
     
  11. Taiine

    Taiine Pangalactic Porcupine

    So just a question... you gave a nice example of replacing with the ores. But that was for a single value, what if you wanted to replace the -whole- thing? __merge use to work, but it don't seem to anymore.
     
  12. Olxinos

    Olxinos Scruffy Nerf-Herder

    What do you mean the whole thing? The whole "surfaceOres" table?
    Then instead of
    Code:
    [
      {
        "op":"replace",
        "path":"/surfaceOres/2/1/1",
        "value":  [ "uranium", 11.00]
      }
    ]
    simply use:
    Code:
    [
      {
        "op":"replace",
        "path":"/surfaceOres",
        "value":
        [
          [
            0.5,
            [
              [ "uranium", 11.00],
              [ "plutonium", 42.00],
            ]
          ],
          [
            1.5,
            [
              [ "uranium", 11.01],
              [ "plutonium", 42.01],
            ]
          ],
          [
            2.5,
            [
              [ "uranium", 11.02],
              [ "plutonium", 42.02],
            ]
          ]
        ]
      }
    ]
     
  13. Taiine

    Taiine Pangalactic Porcupine

    Holy cow... I mean the -whole- file. I have a mod the edits -every- ore to change the spawn rates so it's less even across all depths and difficulties. Before it was just as simple as telling it to __merge and replace each depth.
     
  14. Olxinos

    Olxinos Scruffy Nerf-Herder

    The whole file? Then don't use a patch, simply use exactly the same filename, and the file will be overwritten (i don't recommend it though as it can break compatibility with some mods which also alter the same files).
    Well if you absolutely want to use the patching system, you can do this:
    Code:
    [
      {
        "op":"add",
        "path":"/",
        "value":
        //your file (surrounded in brackets)
      }
    ]
    but that's a bit silly to make that kind of patch.
     
  15. Taiine

    Taiine Pangalactic Porcupine

    Welp I'm already doing what you don't recommend with my mod. Was just looking into ways to do it sense __merge went bye bye. Ah well.
    Now if I can only find tech tutorials, been wanting to make a tech that makes ores glow.
     
  16. Mackinz

    Mackinz The Waste of Time

    Hello there. I am trying to update an older mod (Compact Crops; not mine) and I was hoping to use this thread to proofread my patching code.

    Now, let's see...

    I need to update the code of wheatseed.object from this:

    Code:
      "orientations" : [
        {
          "dualImage" : "wheatseed.png:<color>.<stage>.<alt>",
          "imagePosition" : [0, 0],
    
          "spaces" : [ [1, 0], [0, 0], [1, 1], [0, 1], [1, 2], [0, 2], [1, 3], [0, 3] ],
          "requireTilledAnchors" : true,
          "anchors" : [ "bottom" ]
        }
      ],
    ...to this:

    Code:
      "orientations" : [
        {
          "dualImage" : "wheatseed.png:<color>.<stage>.<alt>",
          "imagePosition" : [-4, 0],
          "frames" : 1,
          "animationCycle" : 0.5,
    
          "spaceScan" : 0.1,
          "requireTilledAnchors" : true,
          "anchors" : [ "bottom" ]
    
        }
      ]
    This means I need a replace code. Considering that the mod is old, and that there are no entries in the current files for half the entries in the old __merge file, I can probably get rid of those and simplify things. "Spaces" could potentially be relevant, but the mod only altered "imagePosition" so that is what I will attempt to modify.

    How does this look?

    Code:
    [
      {
        "op":"replace",
        "path":"/orientations/",
        "value":  [ "imagePosition" : [-4, 0] ]
      }
    ]
    
     
    Last edited: Feb 1, 2015
  17. Olxinos

    Olxinos Scruffy Nerf-Herder

    Your patch file is invalid, first of all
    Code:
    [ "imagePosition" : [-4, 0] ]
    isn't a valid json value, object, or array (a json patch is still a json document) because:
    - there is an unmatched bracket
    - ":" only delimits the name and its value in an object ({ })
    If you only want to replace the value of imagePosition, it should simply be the new value (ie, [-4, 0])
    The path is also wrong, you only have the beginning, here, you want to replace the value of "imagePosition" which is inside the first element of the array ([ ] = array) "orientations".
    So the path should be: "/orientations/0/imagePosition".
    Again with colors:
    you want to replace the value of "imagePosition" which is inside the first element of the array ([ ] = array) "orientations", so the path should be: "/orientations/0/imagePosition" (the first array index is 0 not 1).
    So your patch should be
    Code:
    [
      {
        "op":"replace",
        "path":"/orientations/0/imagePosition",
        "value":[-4, 0]
      }
    ]
    If you're not sure whether your patch is right or wrong don't forget to test it
     
    Last edited: Feb 1, 2015
    Mackinz and The | Suit like this.
  18. Mackinz

    Mackinz The Waste of Time

    Thanks much for the correction. I applied the patch, and it didn't work as expected in-game. I'll probably have to fiddle with the "Spaces" now.

    So... let me try some coding.

    Code:
    [
      {
        "op":"replace",
        "path":"/orientations/0/imagePosition",
        "value":[-4, 0]
      },
      {
        "op":"replace",
        "path":"/orientations/0/spaces/0/0",
        "value":0.5
      },
      {
        "op":"replace",
        "path":"/orientations/0/spaces/2/0",
        "value":0.5
      },
      {
        "op":"replace",
        "path":"/orientations/0/spaces/4/0",
        "value":0.5
      },
      {
        "op":"replace",
        "path":"/orientations/0/spaces/6/0",
        "value":0.5
      }
    ]
    
    Hmm... This gives the desired effect on Wheat. Fantastic. Thank you so much for your help!
     
    Last edited: Feb 2, 2015
  19. The | Suit

    The | Suit Agent S. Forum Moderator



    I am guessing you caught that mistake.
    Don't worry happens to everyone. Keeping an eye on the brackets you use is important.
    [DOUBLEPOST=1422855383][/DOUBLEPOST]
    ==

    Once you understand how the path is setup - patching is simple as picking an apple.
     
    Last edited: Feb 2, 2015
    Mackinz likes this.
  20. Shadow Wolf TJC

    Shadow Wolf TJC Spaceman Spiff

    Hey, I've recently started updating my mods to Upbeat Giraffe, and am in the process of transitioning from the old __merge system to the new patch system, and I'm thankful for this tutorial. However, earlier, when doing modifications to client.config (in order to bring back the old battle music from the Koala versions), even when my patches' syntax was perfect, I kept getting error messages that caused the game to crash at the start. I then took a quick look at how another mod's files were working, and I found my answer. Here's a bit of advice if you encounter the same problems I did when switching over from the __merge system to the patch system:

    Always remember to add ".patch" at the end of your file names if you wish to add or overwrite some files without breaking compatability or replacing the entire file.

    Edit: If you're having trouble changing your files to .patch files, know that I had to rename them as such through WinRAR, although I'm sure there are other ways that I'm not aware of...
     
    Last edited: Feb 2, 2015
    The | Suit likes this.

Share This Page