From e317be4989e1d2194ad0180589c9228754773c82 Mon Sep 17 00:00:00 2001 From: SandPoot Date: Wed, 27 Sep 2023 17:11:10 -0300 Subject: [PATCH 1/3] oh boy i can't wait to find out people managing to exploit this --- code/modules/client/preferences.dm | 41 +++++++++++++++++++ code/modules/client/preferences_savefile.dm | 28 ++++++++----- .../code/modules/client/client_procs.dm | 4 ++ tgstation.dme | 1 + 4 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 modular_sand/code/modules/client/client_procs.dm diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index e580089b0efd..f434a4fe6764 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -350,6 +350,22 @@ GLOBAL_LIST_EMPTY(preferences_datums) dat += "
" + dat += "
" + var/client_file = user.client.Import() + var/savefile_name + if(client_file) + var/savefile/cache_savefile = new(user.client.Import()) + if(!cache_savefile["deleted"] || savefile_needs_update(cache_savefile) != -2) + cache_savefile["real_name"] >> savefile_name + dat += "Local storage: [savefile_name ? savefile_name : "Empty"]" + dat += "
" + dat += "Export current slot" + dat += "Import into current slot" + dat += "Delete locally saved character" + dat += "
" + + dat += "
" + dat += "
" dat += "General" dat += "Appearance" @@ -3355,6 +3371,31 @@ GLOBAL_LIST_EMPTY(preferences_datums) if(href_list["tab"]) preferences_tab = text2num(href_list["tab"]) + if("export_slot") + var/savefile/S = save_character(export = TRUE) + if(istype(S, /savefile)) + user.client.Export(S) + tgui_alert_async(user, "Successfully saved character slot") + else + tgui_alert_async(user, "Failed saving character slot") + return + + if("import_slot") + var/savefile/S = new(user.client.Import()) + if(istype(S, /savefile)) + if(load_character(provided = S) == TRUE) + tgui_alert_async(user, "Successfully loaded character slot.") + else + tgui_alert_async(user, "Failed loading character slot") + return + else + tgui_alert_async(user, "Failed loading character slot") + return + + if("delete_local_copy") + user.client.clear_export() + tgui_alert_async(user, "Local save data erased.") + if(href_list["preference"] == "gear") if(href_list["clear_loadout"]) loadout_data["SAVE_[loadout_slot]"] = list() diff --git a/code/modules/client/preferences_savefile.dm b/code/modules/client/preferences_savefile.dm index 05422b52a7be..5c44a0b7ad0d 100644 --- a/code/modules/client/preferences_savefile.dm +++ b/code/modules/client/preferences_savefile.dm @@ -689,9 +689,10 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car return 1 -/datum/preferences/proc/load_character(slot, bypass_cooldown = FALSE) - if(!path) - return FALSE +/datum/preferences/proc/load_character(slot, bypass_cooldown = FALSE, savefile/provided) + if(!provided) + if(!path) + return FALSE if(!bypass_cooldown) if(world.time < loadcharcooldown) //This is before the check to see if the filepath exists to ensure that BYOND can't get hung up on read attempts when the hard drive is a little slow if(istype(parent)) @@ -700,10 +701,13 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car loadcharcooldown = world.time + PREF_SAVELOAD_COOLDOWN if(!fexists(path)) return FALSE - var/savefile/S = new /savefile(path) + var/savefile/S + if(provided) + S = provided + else + S = new /savefile(path) if(!S) return FALSE - features = list("mcolor" = "FFFFFF", "mcolor2" = "FFFFFF", "mcolor3" = "FFFFFF", "tail_lizard" = "Smooth", "tail_human" = "None", "snout" = "Round", "horns" = "None", "horns_color" = "85615a", "ears" = "None", "wings" = "None", "wings_color" = "FFF", "frills" = "None", "deco_wings" = "None", "spines" = "None", "legs" = "Plantigrade", "insect_wings" = "Plain", "insect_fluff" = "None", "insect_markings" = "None", "arachnid_legs" = "Plain", "arachnid_spinneret" = "Plain", "arachnid_mandibles" = "Plain", "mam_body_markings" = "Plain", "mam_ears" = "None", "mam_snouts" = "None", "mam_tail" = "None", "mam_tail_animated" = "None", "xenodorsal" = "Standard", "xenohead" = "Standard", "xenotail" = "Xenomorph Tail", "taur" = "None", "genitals_use_skintone" = FALSE, "has_cock" = FALSE, "cock_shape" = DEF_COCK_SHAPE, "cock_length" = COCK_SIZE_DEF, "cock_diameter_ratio" = COCK_DIAMETER_RATIO_DEF, "cock_color" = "ffffff", "cock_taur" = FALSE, "has_balls" = FALSE, "balls_color" = "ffffff", "balls_shape" = DEF_BALLS_SHAPE, "balls_size" = BALLS_SIZE_DEF, "balls_cum_rate" = CUM_RATE, "balls_cum_mult" = CUM_RATE_MULT, "balls_efficiency" = CUM_EFFICIENCY, "has_breasts" = FALSE, "breasts_color" = "ffffff", "breasts_size" = BREASTS_SIZE_DEF, "breasts_shape" = DEF_BREASTS_SHAPE, "breasts_producing" = FALSE, "has_vag" = FALSE, "vag_shape" = DEF_VAGINA_SHAPE, "vag_color" = "ffffff", "has_womb" = FALSE, "has_butt" = FALSE, "butt_color" = "ffffff", "butt_size" = BUTT_SIZE_DEF, "balls_visibility" = GEN_VISIBLE_NO_UNDIES, "breasts_visibility"= GEN_VISIBLE_NO_UNDIES, "cock_visibility" = GEN_VISIBLE_NO_UNDIES, "vag_visibility" = GEN_VISIBLE_NO_UNDIES, "butt_visibility" = GEN_VISIBLE_NO_UNDIES, "ipc_screen" = "Sunburst", "ipc_antenna" = "None", "flavor_text" = "", "silicon_flavor_text" = "", "ooc_notes" = "", "meat_type" = "Mammalian", "body_model" = MALE, "body_size" = RESIZE_DEFAULT_SIZE, "color_scheme" = OLD_CHARACTER_COLORING) S.cd = "/" if(!slot) @@ -713,13 +717,16 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car default_slot = slot WRITE_FILE(S["default_slot"] , slot) - S.cd = "/character[slot]" + if(!provided) + S.cd = "/character[slot]" var/needs_update = savefile_needs_update(S) if(needs_update == -2) //fatal, can't load any data return FALSE . = TRUE + features = list("mcolor" = "FFFFFF", "mcolor2" = "FFFFFF", "mcolor3" = "FFFFFF", "tail_lizard" = "Smooth", "tail_human" = "None", "snout" = "Round", "horns" = "None", "horns_color" = "85615a", "ears" = "None", "wings" = "None", "wings_color" = "FFF", "frills" = "None", "deco_wings" = "None", "spines" = "None", "legs" = "Plantigrade", "insect_wings" = "Plain", "insect_fluff" = "None", "insect_markings" = "None", "arachnid_legs" = "Plain", "arachnid_spinneret" = "Plain", "arachnid_mandibles" = "Plain", "mam_body_markings" = "Plain", "mam_ears" = "None", "mam_snouts" = "None", "mam_tail" = "None", "mam_tail_animated" = "None", "xenodorsal" = "Standard", "xenohead" = "Standard", "xenotail" = "Xenomorph Tail", "taur" = "None", "genitals_use_skintone" = FALSE, "has_cock" = FALSE, "cock_shape" = DEF_COCK_SHAPE, "cock_length" = COCK_SIZE_DEF, "cock_diameter_ratio" = COCK_DIAMETER_RATIO_DEF, "cock_color" = "ffffff", "cock_taur" = FALSE, "has_balls" = FALSE, "balls_color" = "ffffff", "balls_shape" = DEF_BALLS_SHAPE, "balls_size" = BALLS_SIZE_DEF, "balls_cum_rate" = CUM_RATE, "balls_cum_mult" = CUM_RATE_MULT, "balls_efficiency" = CUM_EFFICIENCY, "has_breasts" = FALSE, "breasts_color" = "ffffff", "breasts_size" = BREASTS_SIZE_DEF, "breasts_shape" = DEF_BREASTS_SHAPE, "breasts_producing" = FALSE, "has_vag" = FALSE, "vag_shape" = DEF_VAGINA_SHAPE, "vag_color" = "ffffff", "has_womb" = FALSE, "has_butt" = FALSE, "butt_color" = "ffffff", "butt_size" = BUTT_SIZE_DEF, "balls_visibility" = GEN_VISIBLE_NO_UNDIES, "breasts_visibility"= GEN_VISIBLE_NO_UNDIES, "cock_visibility" = GEN_VISIBLE_NO_UNDIES, "vag_visibility" = GEN_VISIBLE_NO_UNDIES, "butt_visibility" = GEN_VISIBLE_NO_UNDIES, "ipc_screen" = "Sunburst", "ipc_antenna" = "None", "flavor_text" = "", "silicon_flavor_text" = "", "ooc_notes" = "", "meat_type" = "Mammalian", "body_model" = MALE, "body_size" = RESIZE_DEFAULT_SIZE, "color_scheme" = OLD_CHARACTER_COLORING) + //Species var/species_id S["species"] >> species_id @@ -1101,7 +1108,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car return 1 -/datum/preferences/proc/save_character(bypass_cooldown = FALSE) +/datum/preferences/proc/save_character(bypass_cooldown = FALSE, export = FALSE) if(!path) return 0 if(!bypass_cooldown) @@ -1110,10 +1117,11 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car to_chat(parent, "You're attempting to save your character a little too fast. Wait half a second, then try again.") return 0 savecharcooldown = world.time + PREF_SAVELOAD_COOLDOWN - var/savefile/S = new /savefile(path) + var/savefile/S = new /savefile(export ? null : path) if(!S) return 0 - S.cd = "/character[default_slot]" + if(!export) + S.cd = "/character[default_slot]" WRITE_FILE(S["version"] , SAVEFILE_VERSION_MAX) //load_character will sanitize any bad data, so assume up-to-date.) @@ -1298,7 +1306,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car cit_character_pref_save(S) - return 1 + return S #undef SAVEFILE_VERSION_MAX diff --git a/modular_sand/code/modules/client/client_procs.dm b/modular_sand/code/modules/client/client_procs.dm new file mode 100644 index 000000000000..e00adda2dc58 --- /dev/null +++ b/modular_sand/code/modules/client/client_procs.dm @@ -0,0 +1,4 @@ +/client/proc/clear_export() + var/savefile/S = new() + S["deleted"] << 1 + Export(S) diff --git a/tgstation.dme b/tgstation.dme index f493adf6f248..a32ef4a9354f 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -4113,6 +4113,7 @@ #include "modular_sand\code\modules\cargo\packs\supply_pack.dm" #include "modular_sand\code\modules\cargo\packs\vending.dm" #include "modular_sand\code\modules\client\asset_cache.dm" +#include "modular_sand\code\modules\client\client_procs.dm" #include "modular_sand\code\modules\client\preferences.dm" #include "modular_sand\code\modules\client\preferences_savefile.dm" #include "modular_sand\code\modules\client\loadout\_security.dm" From 0f99dd997458c3b71b0db8c8efeb9d25f1f1b2ef Mon Sep 17 00:00:00 2001 From: Sandstorm Bot <85452301+Sandstorm-Bot@users.noreply.github.com> Date: Wed, 27 Sep 2023 20:26:12 +0000 Subject: [PATCH 2/3] Automatic changelog generation for PR #345 [ci skip] --- html/changelogs/AutoChangeLog-pr-345.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 html/changelogs/AutoChangeLog-pr-345.yml diff --git a/html/changelogs/AutoChangeLog-pr-345.yml b/html/changelogs/AutoChangeLog-pr-345.yml new file mode 100644 index 000000000000..33c568cd35c0 --- /dev/null +++ b/html/changelogs/AutoChangeLog-pr-345.yml @@ -0,0 +1,5 @@ +author: SandPoot +delete-after: true +changes: + - rscadd: Added importing/exporting characters, they will be saved on your computer + and you can take your character into other servers. From 502fbb6d4f83ceae2127f3dcef3619baef3fa86a Mon Sep 17 00:00:00 2001 From: Sandstorm Bot <85452301+Sandstorm-Bot@users.noreply.github.com> Date: Wed, 27 Sep 2023 20:27:18 +0000 Subject: [PATCH 3/3] Automatic changelog compile [ci skip] --- html/changelogs/AutoChangeLog-pr-345.yml | 5 ----- html/changelogs/archive/2023-09.yml | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) delete mode 100644 html/changelogs/AutoChangeLog-pr-345.yml diff --git a/html/changelogs/AutoChangeLog-pr-345.yml b/html/changelogs/AutoChangeLog-pr-345.yml deleted file mode 100644 index 33c568cd35c0..000000000000 --- a/html/changelogs/AutoChangeLog-pr-345.yml +++ /dev/null @@ -1,5 +0,0 @@ -author: SandPoot -delete-after: true -changes: - - rscadd: Added importing/exporting characters, they will be saved on your computer - and you can take your character into other servers. diff --git a/html/changelogs/archive/2023-09.yml b/html/changelogs/archive/2023-09.yml index 50a27b364724..9a2e25931721 100644 --- a/html/changelogs/archive/2023-09.yml +++ b/html/changelogs/archive/2023-09.yml @@ -6,3 +6,7 @@ 2023-09-23: SandPoot: - code_imp: Adds signals for sex to be used by coders in the future. +2023-09-27: + SandPoot: + - rscadd: Added importing/exporting characters, they will be saved on your computer + and you can take your character into other servers.