Page 1 of 2

Export champions tool

Posted: Sat Feb 20, 2016 12:50 pm
by AndakRainor
Hi!

So after this (long debate :lol:) here I propose to all mod authors here to help me build a small mod used as a tool to export champions.

The problem this tool should solve : casting a new spell crashes the game when any trait a champion had in a previous mod is undefined in the mod you are currently playing.

To avoid this bug I created a basic dungeon which runs the following script:

Code: Select all

mods = {
  mmssp = {
    -- skills traits
    "recover",
    "spirit",
    "parry",
    "missile_weapons_expert",
    "accurate_throw",
    "sniper",
    "haste",
    "sacred_armor",
    "light_speed",
    "fire_sword",
    "thunder_hammer",
    "poisoned_dagger",
    "frost_axe",
    -- spells
    "arcane_storm",
    "arcane_nova",
    "arcane_flash",
    "mirror",
    "fire_wall",
    "pyro_metabolism",
    "fire_enchantment",
    "flashfire_rune",
    "inner_fire",
    "fire_aura",
    "wind_blow",
    "air_enchantment",
    "sleep_rune",
    "teleportation",
    "breath_of_life",
    "thunder_storm",
    "frost_burst",
    "regeneration",
    "osmosis",
    "water_enchantment",
    "freeze_rune",
    "conjure_ice",
    "ice_storm",
    "healing",
    "rock_fall",
    "earth_enchantment",
    "entangling_roots_rune",
    "rock_storm",
    "earthquake",
    "poison_storm",
    "demonic_pact",
    "soul_bound",
    "burning_thunder_shield",
    "burning_thunder",
    "fierce_storm",
    "energy_whirl",
    "water_breathing",
    "blizzard_shield",
    "blizzard",
    "life_flow",
    "life_bloom",
    "health_shield",
    "fever_shield",
    "cold_fever",
    "feast",
    "scorched_earth",
    "inner_strength",
    "volcanic_shield",
    "volcano",
    "higher_metabolism",
    "antipode",
    "frostfireball",
    "frostfire_shield",
    "fire_and_ice",
    "power_flow",
    "angelic_shield",
    "magic_bridge",
    "hurricane_shield",
    "hurricane",
    "rebirth",
    "nature_grace",
    "nature_shield",
    "wrath_of_nature",
    "drain_life_bolt",
    "regrowth",
    "oracle",
    "asphyxia_shield",
    "asphyxia",
    "all_shall_fall",
    "force_tide",
    "life_steal_bolt",
    "desolation_shield",
    "desolation",
    "swap",
    "phoenix",
    "cure_petrify",
    "sky_shield",
    "wrath_of_the_sky",
    "transfer",
    "life_flame",
    "elemental_shield",
    "elemental_storm",
    "superior_cure",
    "might",
    "immortal",
  },
}

function removeTraits()
  for _,mod in pairs(mods) do
    for _,trait in ipairs(mod) do
      for i = 1,4 do
        party.party:getChampionByOrdinal(i):removeTrait(trait)
      end
    end
  end
  hudPrint("Mods traits cleared")
end
I would like to collect as many lists as possible from your mods custom traits (and spells) names and add them in this table. This must be done because it is impossible to remove any trait without knowing its name beforehand.

I did not myself add custom classes or races but I would like also to find what can be done to handle those. So if you have done this in your mod and eventually have a saved game you can share with me to test what conversions can be done, I will work on it.

Thanks !

Re: Export champions tool

Posted: Sat Feb 20, 2016 1:21 pm
by minmay
This seems like it would be better accomplished by making an external tool that changes the savegame file. What you're proposing is that everyone update their own mods every time someone else makes a new trait...it's probably easier to write a python script that edits all non-standard traits out of a savegame. The savegame starts with an 8 byte header and the remainder is a zlib stream. Each party member's traits are in a convenient list, so you just have to worry about updating all the relevant chunk lengths afterwards (or if you're fond of really lazy "solutions", you could define do-nothing traits with names that are 1, 2, 3, 4, etc. characters long, and clobber each list entry with the matching one of those).

Re: Export champions tool

Posted: Sat Feb 20, 2016 2:42 pm
by AndakRainor
minmay wrote:What you're proposing is that everyone update their own mods every time someone else makes a new trait...
Why do you say that ? The tool I propose is a standalone dungeon mod where all traits names would be included. I don't see any need to update any other dungeon mod. The mods handled by the tool would be listed with their versions. Well, if an author publish a new version of his mod with new traits then he would need to give me the new list, sure...

An external tool could be a solution to avoid building the list, but it is a bigger work if I want it to be flexible with gui options to deal with other aspects like races and classes... I will think about it.

Re: Export champions tool

Posted: Sat Feb 20, 2016 9:27 pm
by minmay
AndakRainor wrote:Why do you say that ? The tool I propose is a standalone dungeon mod where all traits names would be included
Oh, I misinterpreted. I thought your idea was to have people put this at the beginning of their own mods. Sorry.

Re: Export champions tool

Posted: Sun Feb 21, 2016 12:39 pm
by AndakRainor
Oh I understand the confusion now that I reread my post with your idea in mind !

Anyway, do we have details somewhere on the structure of savegame files ? (or how to decompile SaveGame.lua ?)

Re: Export champions tool

Posted: Sun Feb 21, 2016 1:03 pm
by minmay
My old Toorumifier script could help in that regard. The actual Toorumifying part won't work anymore but it shows how to read/write the file and traverse chunks.

Re: Export champions tool

Posted: Tue Feb 23, 2016 5:56 pm
by AndakRainor
Ok I managed to locate the party's GOBJ block in an example save file, but honestly I have no idea where the traits hide in that data :?
Could it be provided directly by the strings table (STAB) instead ?

by the way, I think you have a problem in your python script on line 103 :

Code: Select all

while soffset < csize:
with soffset not starting at 0 and csize being the size of the chunk. But it seems to be only wrong by 8 bytes from what I see in every save files I opened for now !

Thank you for this script! Also, how did you guess this about the file structure ? Did you just randomly inflate the data with zlib to see what happens ? Did you compare nearly identical saves to find the party's run speed byte ?

Re: Export champions tool

Posted: Tue Feb 23, 2016 10:15 pm
by minmay
AndakRainor wrote:Thank you for this script! Also, how did you guess this about the file structure ? Did you just randomly inflate the data with zlib to see what happens ? Did you compare nearly identical saves to find the party's run speed byte ?
There's a single bit in the party's flags that indicates whether they're playing as Toorum or not; if it's on, they move at 1.5x speed, turn at 1.2x speed, and have slightly different camera animation while moving. I found this out by comparing Grimrock 1 saves. I happened to know that the same flag existed in Grimrock 2, made a guess that it would be in the party's "flags" field, and used trial and error to find the specific bit.

As far as the save structure itself I was mostly copying from the Grimrock 1 object finder that I linked to in the post.

Grimrock 2 Save Editor

Posted: Wed Jun 08, 2016 5:28 pm
by AndakRainor
Here is a java application I made to edit save files;

http://www.nexusmods.com/legendofgrimrock2/mods/74/?

It would be cool if some of you take the time to test it a bit!
As always, please don't overwrite any of your precious files when using this tool! (It only has a "save as" menu to avoid accidents)
It's user interface requires a mouse to do any significant thing for now (a lot of keyboard shortcuts could be added in a future version).
It only has one global function in the file menu in addition to "open" and "save as"; "remove all mods traits". It does what it says. With it you should be able to import a cleaned party in a new mod and avoid crashing the game when learning new spells.

(copy/paste of strings and images for portraits, undo, typing / removing text, removing chunks, are implemented, try with delete, backspace, left or right click, ctrl+c, ctrl+v, ctrl+z, or any key for text... The focused element is always the one under the mouse cursor)

Re: Export champions tool

Posted: Wed Jun 08, 2016 7:57 pm
by minmay
Well that's way beyond what I was thinking of :shock:

Really useful tool, thank you!