How to build a compatibility patch for YeOlde - (MCM) Settings
By YeOldeDragon
By YeOldeDragon
WARNING: this article is a work in progress.
YeOlde - (MCM) Settings can backup and restore settings from a lot of mods automatically. But for some mods, it's just impossible to do without a patch.
To buid a patch for YeOlde - (MCM) Settings, you'll need to implement 3 functions:
In the following article, I'll explain why and how to implement theses functions.
To backup a mod (called "active mod" in this text), YeOlde - (MCM) Settings simulate a PageReset for every page of the active mod. The But instead of resetting and displaying the page, it collects all the option values and write them in a json file.
It works well for most of the mods, but it will fail if the active mod does some "complex tasks" (anything else than simple value assignations) in the OnPageReset function.
When a mod fails to backup, the solution is to overwrite the generic calls to backup your own values. To do this, the active mod must define and overwrite the YeOlde - (MCM) Settings backup main function: OnBackupRequest
.
Example 1: OnBackupRequest definition
This function receives a JMap container id (see JContainer's library) to store your data. The JMap data will be automatically saved after the function completes.
Example 2: OnBackupRequest content example:
To restore any mod's values, YeOlde - (MCM) Settings simulate user actions on the UI and send new values to the active mod. Since the active mod thinks these actions come from the user, it will apply the new values and save them as usual.
Again, it works well for most of the mods, but it will fail if the active mod does some "complex tasks" (anything else than simple value assignations) in its related options events.
When a mod can't restore data using the generic method, the solution is to overwrite the restore call and apply our values correctly. To do this, the active mod must define and overwrite the YeOlde - (MCM) Settings import main function: OnRestoreRequest
.
Example 3: OnRestoreRequest definition
This function receives a JMap container id (see JContainer's library) to store your data. The JMap data will be automatically saved after the function completes.
Example 4: OnRestoreRequest content example:
Since your mod is considered "failing" by YeOlde - (MCM) Settings, it is categorized as a "NEED PATCH" mod.
To inform YeOlde - (MCM) Settings that you have an active patch installed, your script must overwrite the IsBackupRestoreEnabled()
function to return true
and activate the patch in the Backup/Import tool.
Example 5: IsBackupRestoreEnabled example
It's important to understand that if you have overwritten OnBackupRequest
and OnRestoreRequest
functions, your patch will be applied no matter if IsBackupRestoreEnabled()
returns true or false. IsBackupRestoreEnabled()
is only used to inform the Blacklist menu page that there is a patch available, to change your mod status from "Need patch" to "mod OK".
Thanks for reading, have fun patching! :)