[MODULAR] Fixes All Known Modular Persistence (NIF) Saving Issues (#19096)

* Fuck

* Holy shit
This commit is contained in:
Rimi Nosha
2023-02-08 02:01:25 +00:00
committed by GitHub
parent bd94f41033
commit d95ca04819
5 changed files with 40 additions and 25 deletions
+1 -1
View File
@@ -325,7 +325,7 @@ SUBSYSTEM_DEF(ticker)
iter_human.increment_scar_slot()
iter_human.load_persistent_scars()
SSpersistence.load_modular_persistence(iter_human) // SKYRAT EDIT ADDITION - MODULAR_PERSISTENCE
SSpersistence.load_modular_persistence(iter_human.getorganslot(ORGAN_SLOT_BRAIN)) // SKYRAT EDIT ADDITION - MODULAR_PERSISTENCE
if(!iter_human.hardcore_survival_score)
continue
@@ -236,7 +236,7 @@
humanc.increment_scar_slot()
humanc.load_persistent_scars()
SSpersistence.load_modular_persistence(humanc) // SKYRAT EDIT ADDITION - MODULAR_PERSISTENCE
SSpersistence.load_modular_persistence(humanc.getorganslot(ORGAN_SLOT_BRAIN)) // SKYRAT EDIT ADDITION - MODULAR_PERSISTENCE
if(GLOB.curse_of_madness_triggered)
give_madness(humanc, GLOB.curse_of_madness_triggered)
@@ -380,6 +380,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/computer/cryopod, 32)
GLOB.joined_player_list -= stored_ckey
handle_objectives()
mob_occupant.ghostize()
QDEL_NULL(occupant)
open_machine()
name = initial(name)
@@ -388,12 +389,12 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/computer/cryopod, 32)
/obj/machinery/cryopod/proc/reset_religion()
// set the altar references to the old religious_sect to null
for(var/obj/structure/altar_of_gods/altar in GLOB.chaplain_altars)
for(var/obj/structure/altar_of_gods/altar in GLOB.chaplain_altars)
altar.GetComponent(/datum/component/religious_tool).easy_access_sect = null
altar.sect_to_altar = null
QDEL_NULL(GLOB.religious_sect) // queue for removal but also set it to null, in case a new chaplain joins before it can be deleted
// set the rest of the global vars to null for the new chaplain
GLOB.religion = null
GLOB.deity = null
@@ -162,7 +162,8 @@
if(found_component)
qdel(found_component)
UnregisterSignal(linked_mob, COMSIG_LIVING_DEATH, PROC_REF(damage_on_death))
if(linked_mob)
UnregisterSignal(linked_mob, COMSIG_LIVING_DEATH, PROC_REF(damage_on_death))
/obj/item/organ/internal/cyberimp/brain/nif/process(delta_time)
. = ..()
@@ -30,31 +30,32 @@ GLOBAL_LIST_INIT(modular_persistence_ignored_vars, list(
player.save_individual_persistence()
/// Loads the contents of the player's modular_persistence file to their character.
/datum/controller/subsystem/persistence/proc/load_modular_persistence(mob/living/carbon/human/player)
if(!ishuman(player))
return FALSE
var/obj/item/organ/internal/brain/brain = player.getorganslot(ORGAN_SLOT_BRAIN)
/datum/controller/subsystem/persistence/proc/load_modular_persistence(obj/item/organ/internal/brain/brain)
if(!brain)
return FALSE
if(!ishuman(brain.owner))
return FALSE
var/mob/living/carbon/human/player = brain.owner
var/json_file = file("data/player_saves/[player.ckey[1]]/[player.ckey]/modular_persistence.json")
var/list/json = fexists(json_file) ? json_decode(file2text(json_file)) : null
brain.modular_persistence = new(player, islist(json) ? json["[player.mind.original_character_slot_index]"] : null)
brain.modular_persistence = new(brain, islist(json) ? json["[player.mind.original_character_slot_index]"] : null)
/// The master persistence datum. Add vars onto this in your own code. Just be aware that you'll need to use simple data types, such as strings, ints, and lists.
/datum/modular_persistence
/// The human that this is attached to.
var/mob/living/carbon/human/owner
var/obj/item/organ/internal/brain/owner
/// The owner's character slot index.
var/stored_character_slot_index
/datum/modular_persistence/New(mob/living/carbon/human/player, list/persistence_data)
owner = player
/datum/modular_persistence/New(obj/item/organ/internal/brain/brain, list/persistence_data)
owner = brain
. = ..()
stored_character_slot_index = player.mind?.original_character_slot_index
stored_character_slot_index = owner.owner.mind?.original_character_slot_index
if(!persistence_data)
return
@@ -65,7 +66,11 @@ GLOBAL_LIST_INIT(modular_persistence_ignored_vars, list(
if(var_entry)
vars[var_name] = var_entry
owner.load_nif_data(src)
if(!owner.owner)
CRASH("Tried to load modular persistence on a brain with no owner! How did this happen?! (\ref[brain], [brain.brainmob?.ckey], [brain])")
var/mob/living/carbon/human/human = owner.owner
human.load_nif_data(src)
/datum/modular_persistence/Destroy(force, ...)
owner = null
@@ -75,7 +80,8 @@ GLOBAL_LIST_INIT(modular_persistence_ignored_vars, list(
/datum/modular_persistence/proc/serialize_contents_to_list()
var/list/returned_list = list()
owner.save_nif_data(src)
var/mob/living/carbon/human/human = owner.owner
human.save_nif_data(src)
for(var/var_name in vars)
if(var_name in GLOB.modular_persistence_ignored_vars)
@@ -88,12 +94,13 @@ GLOBAL_LIST_INIT(modular_persistence_ignored_vars, list(
return returned_list
/// Saves the persistence data for the owner.
/mob/living/carbon/human/proc/save_individual_persistence()
var/obj/item/organ/internal/brain/brain = getorganslot(ORGAN_SLOT_BRAIN)
if(!client?.prefs || !brain || ! brain.modular_persistence)
return FALSE
/// Saves the held persistence data to where it needs to go.
/datum/modular_persistence/proc/save_data()
var/ckey = replacetext(owner.owner?.ckey || owner.brainmob?.ckey, "@", "")
if(!owner.owner && !owner.brainmob)
CRASH("Modular persistence save called on a brain with no owning mob or brainmob! How did this happen?! (\ref[owner], [owner])")
if(!ckey)
CRASH("Modular persistence save called on a brain with no ckey! How did this happen?! (\ref[owner], [owner])")
var/json_file = file("data/player_saves/[ckey[1]]/[ckey]/modular_persistence.json")
var/list/json = fexists(json_file) ? json_decode(file2text(json_file)) : list()
@@ -102,5 +109,11 @@ GLOBAL_LIST_INIT(modular_persistence_ignored_vars, list(
if(!islist(json))
json = list()
json["[brain.modular_persistence.stored_character_slot_index]"] = brain.modular_persistence.serialize_contents_to_list()
json["[stored_character_slot_index]"] = serialize_contents_to_list()
WRITE_FILE(json_file, json_encode(json))
/// Saves the persistence data for the owner.
/mob/living/carbon/human/proc/save_individual_persistence()
var/obj/item/organ/internal/brain/brain = getorganslot(ORGAN_SLOT_BRAIN)
return brain?.modular_persistence?.save_data()