From e576bab3396a203a9654100762316c47ae6bf252 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 5 Jul 2020 19:09:33 -0400 Subject: [PATCH] Limit all SceneObjects to valid Python 2 identifiers. In Path of the Shell, the entire tree from plSceneObject to plPythonFileMod MUST be a valid identifier, otherwise, a SystemError is raised. --- korman/exporter/manager.py | 14 ++++++++++---- korman/nodes/node_core.py | 3 +-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/korman/exporter/manager.py b/korman/exporter/manager.py index 700f223..f62672c 100644 --- a/korman/exporter/manager.py +++ b/korman/exporter/manager.py @@ -19,7 +19,7 @@ from PyHSPlasma import * import weakref from . import explosions -from .. import korlib +from ..korlib import replace_python2_identifier from ..plasma_magic import * # These objects have to be in the plSceneNode pool in order to be loaded... @@ -93,7 +93,7 @@ class ExportManager: else: name = so.key.name assert issubclass(pl, hsKeyedObject) - pl = pl(name) + pl = pl(self._fixup_key_name(pl, name)) self.AddObject(location, pl) node = self._nodes[location] @@ -145,7 +145,7 @@ class ExportManager: self._pack_agesdl_hook(age) sdl = self.add_object(plSceneObject, name="AgeSDLHook", loc=builtin) pfm = self.add_object(plPythonFileMod, name="VeryVerySpecialPythonFileMod", so=sdl) - pfm.filename = korlib.replace_python2_identifier(age) + pfm.filename = replace_python2_identifier(age) # Textures.prp # FIXME: unconditional creation will overwrite any existing textures PRP. This should @@ -212,6 +212,7 @@ class ExportManager: name = bl.name else: name = so.key.name + name = self._fixup_key_name(pClass, name) key = self._keys.get((location, pClass, name), None) if key is not None and so is not None: @@ -239,6 +240,11 @@ class ExportManager: return key.object return None + def _fixup_key_name(self, pClass, name): + if pClass in {plSceneObject, plPythonFileMod}: + return replace_python2_identifier(name) + return name + def get_location(self, bl): """Returns the Page Location of a given Blender Object""" return self._pages[bl.plasma_object.page] @@ -271,7 +277,7 @@ class ExportManager: return result # AgeSDL Hook Python - fixed_agename = korlib.replace_python2_identifier(age) + fixed_agename = replace_python2_identifier(age) py_filename = "{}.py".format(fixed_agename) age_py = get_text(py_filename) if output.want_py_text(age_py): diff --git a/korman/nodes/node_core.py b/korman/nodes/node_core.py index 12e39cc..597b2f5 100644 --- a/korman/nodes/node_core.py +++ b/korman/nodes/node_core.py @@ -20,7 +20,6 @@ from PyHSPlasma import * import time from ..exporter import ExportError -from ..korlib import replace_python2_identifier class PlasmaNodeBase: def generate_notify_msg(self, exporter, so, socket_id, idname=None): @@ -53,7 +52,7 @@ class PlasmaNodeBase: working_name = "{}_{}_{}".format(self.id_data.name, self.name, suffix) else: working_name = "{}_{}".format(self.id_data.name, self.name) - return replace_python2_identifier(working_name) + return working_name def draw_label(self): if hasattr(self, "pl_label_attr") and self.hide: