From 3eb18496264b4f4dd1b7fb3e253b27b334e402f8 Mon Sep 17 00:00:00 2001 From: ShadowLarkens Date: Sun, 1 Sep 2024 13:55:40 -0700 Subject: [PATCH] Fix NIFs being horrible and overriding prefs with byond savefiles --- .../preference_setup/general/03_body.dm | 2 +- .../client/preference_setup/vore/08_nif.dm | 19 ++----------- code/modules/client/preferences.dm | 4 +-- code/modules/client/preferences_savefile.dm | 13 +++++++++ code/modules/vore/eating/living_vr.dm | 27 +++++++------------ code/modules/vore/persist/persist_vr.dm | 9 ++----- 6 files changed, 30 insertions(+), 44 deletions(-) diff --git a/code/modules/client/preference_setup/general/03_body.dm b/code/modules/client/preference_setup/general/03_body.dm index cadd0a7a4c..735b4990b8 100644 --- a/code/modules/client/preference_setup/general/03_body.dm +++ b/code/modules/client/preference_setup/general/03_body.dm @@ -220,7 +220,7 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O save_data["b_wing3"] = pref.b_wing3 save_data["digitigrade"] = pref.digitigrade -/datum/category_item/player_setup_item/general/body/sanitize_character(var/savefile/S) +/datum/category_item/player_setup_item/general/body/sanitize_character() if(!pref.species || !(pref.species in GLOB.playable_species)) pref.species = SPECIES_HUMAN pref.r_hair = sanitize_integer(pref.r_hair, 0, 255, initial(pref.r_hair)) diff --git a/code/modules/client/preference_setup/vore/08_nif.dm b/code/modules/client/preference_setup/vore/08_nif.dm index 11e1f563dc..365b072f39 100644 --- a/code/modules/client/preference_setup/vore/08_nif.dm +++ b/code/modules/client/preference_setup/vore/08_nif.dm @@ -38,23 +38,8 @@ /datum/category_item/player_setup_item/vore/nif/copy_to_mob(var/mob/living/carbon/human/character) //If you had a NIF... - if((character.type == /mob/living/carbon/human) && ispath(pref.nif_path) && pref.nif_durability) - new pref.nif_path(character,pref.nif_durability,pref.nif_savedata) - - /* - //And now here's the trick. We wipe these so that if they die, they lose the NIF. - //Backup implants will start saving this again periodically, and so will cryo'ing out. - pref.nif_path = null - pref.nif_durability = null - pref.nif_savedata = null - */ - //No we do not, that's lame and admins have to re-NIF them later. - //If they leave round after they get their NIF extracted, it will save as 'gone' anyway - //The NIF will save automatically every time durability changes too now. - var/savefile/S = new /savefile(pref.path) - if(!S) WARNING ("Couldn't load NIF save savefile? [pref.real_name]") - S.cd = "/character[pref.default_slot]" - save_character(S) + if(istype(character) && ispath(pref.nif_path) && pref.nif_durability) + new pref.nif_path(character, pref.nif_durability, pref.nif_savedata) /datum/category_item/player_setup_item/vore/nif/content(var/mob/user) . += "NIF: [ispath(pref.nif_path) ? "Present" : "None"]" diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index fe950956e7..c7284fd15c 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -460,7 +460,7 @@ var/list/preferences_datums = list() var/default var/list/charlist = list() - for(var/i = 1 to config.character_slots) + for(var/i in 1 to config.character_slots) var/list/save_data = savefile.get_entry("character[i]", list()) var/name = save_data["real_name"] var/nickname = save_data["nickname"] @@ -506,7 +506,7 @@ var/list/preferences_datums = list() if(!name) name = "[i] - \[Unused Slot\]" - if(i == default_slot) + else if(i == default_slot) name = "►[i] - [name]" else name = "[i] - [name]" diff --git a/code/modules/client/preferences_savefile.dm b/code/modules/client/preferences_savefile.dm index 0f3aecbf84..622e693379 100644 --- a/code/modules/client/preferences_savefile.dm +++ b/code/modules/client/preferences_savefile.dm @@ -41,8 +41,14 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car // Migration for client preferences if(current_version < 13) + log_debug("[client_ckey] preferences migrating from [current_version] to v13....") + to_chat(client, span_danger("Migrating savefile from version [current_version] to v13...")) + migration_13_preferences(S) + log_debug("[client_ckey] preferences successfully migrated from [current_version] to v13.") + to_chat(client, span_danger("v13 savefile migration complete.")) + /datum/preferences/proc/update_character(current_version, list/save_data) // Migration from BYOND savefiles to JSON: Important milemark. @@ -52,6 +58,9 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car /// Migrates from byond savefile to json savefile /datum/preferences/proc/try_savefile_type_migration() + log_debug("[client_ckey] preferences migrating from savefile to JSON...") + to_chat(client, span_danger("Savefile migration to JSON in progress...")) + load_path(client.ckey, "preferences.sav") // old save file var/old_path = path load_path(client.ckey) @@ -60,6 +69,10 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car var/datum/json_savefile/json_savefile = new(path) json_savefile.import_byond_savefile(new /savefile(old_path)) json_savefile.save() + + log_debug("[client_ckey] preferences successfully migrated from savefile to JSON.") + to_chat(client, span_danger("Savefile migration to JSON is complete.")) + return TRUE /datum/preferences/proc/load_path(ckey, filename = "preferences.json") diff --git a/code/modules/vore/eating/living_vr.dm b/code/modules/vore/eating/living_vr.dm index bc36cff0d0..37e1bb8707 100644 --- a/code/modules/vore/eating/living_vr.dm +++ b/code/modules/vore/eating/living_vr.dm @@ -353,27 +353,25 @@ if(selecting_slots) to_chat(user, "You already have a slot selection dialog open!") return - var/savefile/S = new /savefile(path) - if(!S) - error("Somehow missing savefile path?! [path]") + if(!savefile) return - var/name - var/nickname //vorestation edit - This set appends nicknames to the save slot var/list/charlist = list() - var/default //VOREStation edit - for(var/i=1, i<= config.character_slots, i++) - S.cd = "/character[i]" - S["real_name"] >> name - S["nickname"] >> nickname //vorestation edit + + var/default + for(var/i in 1 to config.character_slots) + var/list/save_data = savefile.get_entry("character[i]", list()) + var/name = save_data["real_name"] + var/nickname = save_data["nickname"] + if(!name) name = "[i] - \[Unused Slot\]" else if(i == default_slot) name = "►[i] - [name]" + default = "[name][nickname ? " ([nickname])" : ""]" else name = "[i] - [name]" - if (i == default_slot) //VOREStation edit - default = "[name][nickname ? " ([nickname])" : ""]" + charlist["[name][nickname ? " ([nickname])" : ""]"] = i var/remember_default = default_slot @@ -396,11 +394,6 @@ return remember_default /datum/preferences/proc/return_to_character_slot(mob/user, var/remembered_default) - var/savefile/S = new /savefile(path) - if(!S) - error("Somehow missing savefile path?! [path]") - return - load_character(remembered_default) attempt_vr(user.client?.prefs_vr,"load_vore","") //VOREStation Edit sanitize_preferences() diff --git a/code/modules/vore/persist/persist_vr.dm b/code/modules/vore/persist/persist_vr.dm index 60311e9889..0d55a07e27 100644 --- a/code/modules/vore/persist/persist_vr.dm +++ b/code/modules/vore/persist/persist_vr.dm @@ -260,10 +260,5 @@ prefs.nif_durability = null prefs.nif_savedata = null - var/datum/category_group/player_setup_category/vore_cat = prefs.player_setup.categories_by_name["VORE"] - var/datum/category_item/player_setup_item/vore/nif/nif_prefs = vore_cat.items_by_name["NIF Data"] - - var/savefile/S = new /savefile(prefs.path) - if(!S) warning("Persist (NIF): Couldn't load NIF save savefile? [prefs.real_name]") - S.cd = "/character[prefs.default_slot]" - nif_prefs.save_character(S) + prefs.save_character() + prefs.save_preferences()