From 6aba869fb781a46487be9c89b2981e9b70a9b12b Mon Sep 17 00:00:00 2001 From: Gnome Ann <> Date: Sat, 18 Dec 2021 18:00:06 -0500 Subject: [PATCH] Make sure uninitialized WI entries are given UIDs when loading saves --- aiserver.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/aiserver.py b/aiserver.py index e1db156e..d27b148f 100644 --- a/aiserver.py +++ b/aiserver.py @@ -3488,6 +3488,12 @@ def loadRequest(loadpath, filename=None): for uid in vars.wifolders_l + [None]: vars.worldinfo.append({"key": "", "keysecondary": "", "content": "", "comment": "", "folder": uid, "num": None, "init": False, "selective": False, "constant": False, "uid": None}) + while(True): + uid = int.from_bytes(os.urandom(4), "little", signed=True) + if(uid not in vars.worldinfo_u): + break + vars.worldinfo_u[uid] = vars.worldinfo[-1] + vars.worldinfo[-1]["uid"] = uid stablesortwi() vars.worldinfo_i = [wi for wi in vars.worldinfo if wi["init"]] @@ -3677,6 +3683,12 @@ def importgame(): for uid in vars.wifolders_l + [None]: vars.worldinfo.append({"key": "", "keysecondary": "", "content": "", "comment": "", "folder": uid, "num": None, "init": False, "selective": False, "constant": False, "uid": None}) + while(True): + uid = int.from_bytes(os.urandom(4), "little", signed=True) + if(uid not in vars.worldinfo_u): + break + vars.worldinfo_u[uid] = vars.worldinfo[-1] + vars.worldinfo[-1]["uid"] = uid stablesortwi() vars.worldinfo_i = [wi for wi in vars.worldinfo if wi["init"]] @@ -3748,6 +3760,12 @@ def importAidgRequest(id): for uid in vars.wifolders_l + [None]: vars.worldinfo.append({"key": "", "keysecondary": "", "content": "", "comment": "", "folder": uid, "num": None, "init": False, "selective": False, "constant": False, "uid": None}) + while(True): + uid = int.from_bytes(os.urandom(4), "little", signed=True) + if(uid not in vars.worldinfo_u): + break + vars.worldinfo_u[uid] = vars.worldinfo[-1] + vars.worldinfo[-1]["uid"] = uid stablesortwi() vars.worldinfo_i = [wi for wi in vars.worldinfo if wi["init"]] @@ -3797,6 +3815,14 @@ def wiimportrequest(): vars.worldinfo_u[uid] = vars.worldinfo[-1] vars.worldinfo[-1]["uid"] = uid num += 1 + for uid in [None]: + vars.worldinfo.append({"key": "", "keysecondary": "", "content": "", "comment": "", "folder": uid, "num": None, "init": False, "selective": False, "constant": False, "uid": None}) + while(True): + uid = int.from_bytes(os.urandom(4), "little", signed=True) + if(uid not in vars.worldinfo_u): + break + vars.worldinfo_u[uid] = vars.worldinfo[-1] + vars.worldinfo[-1]["uid"] = uid print("{0}".format(vars.worldinfo[0]))