<commit_before>#define SAVEFILE_VERSION_MIN	4
#define SAVEFILE_VERSION_MAX	5

datum/preferences/proc/savefile_path(mob/user)
	return "data/player_saves/[copytext(user.ckey, 1, 2)]/[user.ckey]/preferences.sav"

datum/preferences/proc/savefile_save(mob/user)
	if (IsGuestKey(user.key))
		return 0

	var/savefile/F = new /savefile(src.savefile_path(user))
//	var/version
//	F["version"] >> version

	F["version"] << SAVEFILE_VERSION_MAX

	F["real_name"] << src.real_name
	F["name_is_always_random"] << src.be_random_name

	F["gender"] << src.gender
	F["age"] << src.age

	//Job data
	F["job_civilian_high"] << src.job_civilian_high
	F["job_civilian_med"] << src.job_civilian_med
	F["job_civilian_low"] << src.job_civilian_low

	F["job_medsci_high"] << src.job_medsci_high
	F["job_medsci_med"] << src.job_medsci_med
	F["job_medsci_low"] << src.job_medsci_low

	F["job_engsec_high"] << src.job_engsec_high
	F["job_engsec_med"] << src.job_engsec_med
	F["job_engsec_low"] << src.job_engsec_low

	//Body data
	F["hair_red"] << src.r_hair
	F["hair_green"] << src.g_hair
	F["hair_blue"] << src.b_hair
	F["facial_red"] << src.r_facial
	F["facial_green"] << src.g_facial
	F["facial_blue"] << src.b_facial
	F["skin_tone"] << src.s_tone
	F["hair_style_name"] << src.h_style
	F["facial_style_name"] << src.f_style
	F["eyes_red"] << src.r_eyes
	F["eyes_green"] << src.g_eyes
	F["eyes_blue"] << src.b_eyes
	F["blood_type"] << src.b_type
	F["underwear"] << src.underwear

	F["be_special"] << src.be_special
	F["UI"] << src.UI
	F["midis"] << src.midis
	F["ooccolor"] << src.ooccolor
	F["lastchangelog"] << src.lastchangelog

	return 1

// loads the savefile corresponding to the mob's ckey
// if silent=true, report incompatible savefiles
// returns 1 if loaded (or file was incompatible)
// returns 0 if savefile did not exist

datum/preferences/proc/savefile_load(mob/user)
	if(IsGuestKey(user.key))	return 0

	var/path = savefile_path(user)
	if(!fexists(path))	return 0

	var/savefile/F = new /savefile(path)

	var/version = null
	F["version"] >> version

	if (isnull(version) || version < SAVEFILE_VERSION_MIN || version > SAVEFILE_VERSION_MAX)
		fdel(path)
		alert(user, "Your savefile was incompatible with this version and was deleted.")
		return 0

	F["real_name"] >> src.real_name
	F["gender"] >> src.gender
	F["age"] >> src.age

	F["hair_red"] >> src.r_hair
	F["hair_green"] >> src.g_hair
	F["hair_blue"] >> src.b_hair
	F["facial_red"] >> src.r_facial
	F["facial_green"] >> src.g_facial
	F["facial_blue"] >> src.b_facial
	F["skin_tone"] >> src.s_tone
	F["hair_style_name"] >> src.h_style
	F["facial_style_name"] >> src.f_style
	F["eyes_red"] >> src.r_eyes
	F["eyes_green"] >> src.g_eyes
	F["eyes_blue"] >> src.b_eyes
	F["blood_type"] >> src.b_type
	F["underwear"] >> src.underwear
	F["name_is_always_random"] >> src.be_random_name
	F["midis"] >> src.midis
	F["ooccolor"] >> src.ooccolor
	F["lastchangelog"] >> src.lastchangelog
	F["UI"] >> src.UI
	F["be_special"] >> src.be_special

	F["job_civilian_high"] >> src.job_civilian_high
	F["job_civilian_med"] >> src.job_civilian_med
	F["job_civilian_low"] >> src.job_civilian_low

	F["job_medsci_high"] >> src.job_medsci_high
	F["job_medsci_med"] >> src.job_medsci_med
	F["job_medsci_low"] >> src.job_medsci_low

	F["job_engsec_high"] >> src.job_engsec_high
	F["job_engsec_med"] >> src.job_engsec_med
	F["job_engsec_low"] >> src.job_engsec_low

	if(version && version < 5)
		convert_hairstyles_four() // convert version 4 hairstyles to version 5


	style_to_datum() // convert f_style and h_style to /datum


	return 1

#undef SAVEFILE_VERSION_MAX
#undef SAVEFILE_VERSION_MIN



datum/preferences/proc/convert_hairstyles_four()
	// convert hairstyle names from savefile version 4 to version 5.
	switch(h_style)
		if("Balding")
			h_style = "Balding Hair"
		if("Fag")
			h_style = "Flow Hair"
		if("Jensen Hair")
			h_style = "Adam Jensen Hair"

	switch(f_style)
		if("Watson")
			f_style = "Watson Mustache"
		if("Chaplin")
			f_style = "Square Mustache"
		if("Selleck")
			f_style = "Selleck Mustache"
		if("Van Dyke")
			f_style = "Van Dyke Mustache"
		if("Elvis")<commit_msg>Fix for save files. This might be totally unnecessary, but I doubt it.<commit_after>#define SAVEFILE_VERSION_MIN	4
#define SAVEFILE_VERSION_MAX	5

datum/preferences/proc/savefile_path(mob/user)
	return "data/player_saves/[copytext(user.ckey, 1, 2)]/[user.ckey]/preferences.sav"

datum/preferences/proc/savefile_save(mob/user)
	if (IsGuestKey(user.key))
		return 0

	var/savefile/F = new /savefile(src.savefile_path(user))
//	var/version
//	F["version"] >> version

	F["version"] << SAVEFILE_VERSION_MAX

	F["real_name"] << src.real_name
	F["name_is_always_random"] << src.be_random_name

	F["gender"] << src.gender
	F["age"] << src.age

	//Job data
	F["job_civilian_high"] << src.job_civilian_high
	F["job_civilian_med"] << src.job_civilian_med
	F["job_civilian_low"] << src.job_civilian_low

	F["job_medsci_high"] << src.job_medsci_high
	F["job_medsci_med"] << src.job_medsci_med
	F["job_medsci_low"] << src.job_medsci_low

	F["job_engsec_high"] << src.job_engsec_high
	F["job_engsec_med"] << src.job_engsec_med
	F["job_engsec_low"] << src.job_engsec_low

	//Body data
	F["hair_red"] << src.r_hair
	F["hair_green"] << src.g_hair
	F["hair_blue"] << src.b_hair
	F["facial_red"] << src.r_facial
	F["facial_green"] << src.g_facial
	F["facial_blue"] << src.b_facial
	F["skin_tone"] << src.s_tone
	F["hair_style_name"] << src.h_style
	F["facial_style_name"] << src.f_style
	F["eyes_red"] << src.r_eyes
	F["eyes_green"] << src.g_eyes
	F["eyes_blue"] << src.b_eyes
	F["blood_type"] << src.b_type
	F["underwear"] << src.underwear

	F["be_special"] << src.be_special
	F["UI"] << src.UI
	F["midis"] << src.midis
	F["ooccolor"] << src.ooccolor
	F["lastchangelog"] << src.lastchangelog

	return 1

// loads the savefile corresponding to the mob's ckey
// if silent=true, report incompatible savefiles
// returns 1 if loaded (or file was incompatible)
// returns 0 if savefile did not exist

datum/preferences/proc/savefile_load(mob/user)
	if(IsGuestKey(user.key))	return 0

	var/path = savefile_path(user)
	if(!fexists(path))	return 0

	var/savefile/F = new /savefile(path)

	var/version = null
	F["version"] >> version

	if (isnull(version) || version < SAVEFILE_VERSION_MIN || version > SAVEFILE_VERSION_MAX)
		fdel(path)
		alert(user, "Your savefile was incompatible with this version and was deleted.")
		return 0

	F["real_name"] >> src.real_name
	F["gender"] >> src.gender
	F["age"] >> src.age

	F["hair_red"] >> src.r_hair
	F["hair_green"] >> src.g_hair
	F["hair_blue"] >> src.b_hair
	F["facial_red"] >> src.r_facial
	F["facial_green"] >> src.g_facial
	F["facial_blue"] >> src.b_facial
	F["skin_tone"] >> src.s_tone
	F["hair_style_name"] >> src.h_style
	F["facial_style_name"] >> src.f_style
	F["eyes_red"] >> src.r_eyes
	F["eyes_green"] >> src.g_eyes
	F["eyes_blue"] >> src.b_eyes
	F["blood_type"] >> src.b_type
	F["underwear"] >> src.underwear
	F["name_is_always_random"] >> src.be_random_name
	F["midis"] >> src.midis
	F["ooccolor"] >> src.ooccolor
	F["lastchangelog"] >> src.lastchangelog
	F["UI"] >> src.UI
	F["be_special"] >> src.be_special

	F["job_civilian_high"] >> src.job_civilian_high
	F["job_civilian_med"] >> src.job_civilian_med
	F["job_civilian_low"] >> src.job_civilian_low

	F["job_medsci_high"] >> src.job_medsci_high
	F["job_medsci_med"] >> src.job_medsci_med
	F["job_medsci_low"] >> src.job_medsci_low

	F["job_engsec_high"] >> src.job_engsec_high
	F["job_engsec_med"] >> src.job_engsec_med
	F["job_engsec_low"] >> src.job_engsec_low

	if(version && version < 5)
		convert_hairstyles_four() // convert version 4 hairstyles to version 5


	style_to_datum() // convert f_style and h_style to /datum


	return 1

#undef SAVEFILE_VERSION_MAX
#undef SAVEFILE_VERSION_MIN



datum/preferences/proc/convert_hairstyles_four()
	// convert hairstyle names from savefile version 4 to version 5.
	switch(h_style)
		if("Balding")
			h_style = "Balding Hair"
		if("Fag")
			h_style = "Flow Hair"
		if("Jensen Hair")
			h_style = "Adam Jensen Hair"
		if("Kusangi Hair")
			h_style = "Kusanagi Hair"

	switch(f_style)
		if("Watson")
			f_style = "Watson Mustache"
		if("Chaplin")
			f_style = "Square Mustache"
		if("Selleck")
			f_style = "Selleck Mustache"
		if("Van Dyke")
			f_style = "Van Dyke Mustache"
		if("Elvis")
{'fraction_non_alphanumeric': 0.1602494902243013, 'fraction_numerical': 0.004078205589540602, 'mean_word_length': 5.095029239766082, 'pattern_counts': {'":': 0, '<': 139, '<?xml version=': 0, '>': 141, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2219494', 'n_tokens_mistral': 3649, 'n_tokens_neox': 3358, 'n_words': 600}