import codecs import re import os def process_file(path): with codecs.open(path, 'r', 'utf-8') as f: content = f.read() orig = content # We must be careful not to replace `std::string Name` or `Guid` in structs, # but `object.Id` or `sceneObject.Id` is fine. # Let's target specific variable names: sceneObject, object, gameObject, parentObject, currentObject, rootObject, childObject, selectedObject vars = r'(sceneObject|object|gameObject|parentObject|currentObject|rootObject|childObject|selectedObject)' content = re.sub(vars + r'\.Id\b', r'\1.GetId()', content) content = re.sub(vars + r'->Id\b', r'\1->GetId()', content) content = re.sub(vars + r'\.ParentId\b', r'\1.GetParentId()', content) content = re.sub(vars + r'->ParentId\b', r'\1->GetParentId()', content) content = re.sub(vars + r'\.Name\b', r'\1.GetName()', content) content = re.sub(vars + r'->Name\b', r'\1->GetName()', content) content = re.sub(vars + r'\.Transform\b', r'\1.GetComponent()', content) content = re.sub(vars + r'->Transform\b', r'\1->GetComponent()', content) content = content.replace('MetaCoreGameObject* ', 'MetaCoreGameObject ') content = content.replace('const MetaCoreGameObject* ', 'const MetaCoreGameObject ') content = re.sub(vars + r'\s*==\s*nullptr', lambda m: f"!{m.group(1)}", content) content = re.sub(vars + r'\s*!=\s*nullptr', lambda m: m.group(1), content) # Convert -> to . if it was a pointer that is now an object content = re.sub(vars + r'->', r'\1.', content) if content != orig: with codecs.open(path, 'w', 'utf-8') as f: f.write(content) print(f"Fixed {path}") process_file('Source/MetaCoreEditor/Private/MetaCoreSceneInteractionService.cpp') process_file('Source/MetaCoreEditor/Private/MetaCoreBuiltinEditorModule.cpp') process_file('Source/MetaCoreEditor/Private/MetaCoreEditorApp.cpp') process_file('Source/MetaCoreEditor/Private/MetaCoreBuiltinCoreServicesModule.cpp') process_file('Source/MetaCoreEditor/Private/MetaCoreEditorContext.cpp') process_file('Source/MetaCoreEditor/Private/MetaCoreAssetBrowserRenderer.cpp') process_file('Source/MetaCoreEditor/Private/MetaCoreInspectorRenderer.cpp') process_file('Source/MetaCoreEditor/Private/MetaCoreHierarchyRenderer.cpp')