import codecs import re import os def replace_in_file(path): with codecs.open(path, 'r', 'utf-8') as f: content = f.read() orig = content content = content.replace('*selectedObject.MeshRenderer', 'selectedObject.GetComponent()') content = content.replace('*gameObject.MeshRenderer', 'gameObject.GetComponent()') content = content.replace('*gameObject.Camera', 'gameObject.GetComponent()') content = content.replace('*gameObject.Light', 'gameObject.GetComponent()') content = content.replace('gameObject.PrefabInstance.reset()', 'gameObject.RemoveComponent()') content = content.replace('gameObject.Camera.reset()', 'gameObject.RemoveComponent()') content = content.replace('gameObject.Light.reset()', 'gameObject.RemoveComponent()') content = content.replace('gameObject.MeshRenderer.reset()', 'gameObject.RemoveComponent()') content = content.replace('clonedObject.PrefabInstance = MetaCorePrefabInstanceMetadata{', 'clonedObject.AddComponent(MetaCorePrefabInstanceMetadata{') content = re.sub(r'(clonedObject\.AddComponent\([\s\S]*?\n\s*\})(\s*;)', r'\1)\2', content) content = content.replace('prefabObjectIterator->AddComponent(prefabObject.Camera);', 'if (prefabObject.Camera.has_value()) prefabObjectIterator->AddComponent(prefabObject.Camera.value());') content = content.replace('prefabObjectIterator->AddComponent(prefabObject.Light);', 'if (prefabObject.Light.has_value()) prefabObjectIterator->AddComponent(prefabObject.Light.value());') content = content.replace('prefabObjectIterator->AddComponent(prefabObject.MeshRenderer);', 'if (prefabObject.MeshRenderer.has_value()) prefabObjectIterator->AddComponent(prefabObject.MeshRenderer.value());') if content != orig: with codecs.open(path, 'w', 'utf-8') as f: f.write(content) print(f"Fixed {path}") for root, _, files in os.walk('Source'): for file in files: if file.endswith('.cpp') or file.endswith('.h'): replace_in_file(os.path.join(root, file))