Velinquish

Strip PublicizedFrom attributes from lambdas

Jul 26th, 2025
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | Source Code | 0 0
  1. """
  2. Python script to clear all the PublicizedFrom attributes from lambdas
  3. in its parent directory.
  4.  
  5. Put it in Assets/Scripts/Assembly-CSharp as strip_lambda_attributes.py,
  6. open the folder in terminal, and run:
  7. python strip_lambda_attributes.py
  8. """
  9.  
  10. import os
  11. import re
  12.  
  13. # Regex to match `[PublicizedFrom(...)]` before a lambda parameter
  14. lambda_attr_regex = re.compile(
  15.     r"""\[\s*PublicizedFrom\s*\([^)]*\)\s*\]\s*(?=\()""",
  16.     re.MULTILINE
  17. )
  18.  
  19. def process_file(filepath):
  20.     with open(filepath, "r", encoding="utf-8") as f:
  21.         content = f.read()
  22.  
  23.     new_content, count = lambda_attr_regex.subn('', content)
  24.  
  25.     if count > 0:
  26.         with open(filepath, "w", encoding="utf-8") as f:
  27.             f.write(new_content)
  28.         print(f"✅ Fixed {count} lambda(s) in {filepath}")
  29.  
  30. def walk_and_process(directory):
  31.     for root, _, files in os.walk(directory):
  32.         for name in files:
  33.             if name.endswith(".cs"):
  34.                 process_file(os.path.join(root, name))
  35.  
  36. if __name__ == "__main__":
  37.     project_dir = os.getcwd()  # Run the script from the Unity project root
  38.     print(f"🔍 Scanning project: {project_dir}")
  39.     walk_and_process(project_dir)
  40.     print("🎉 Done! All `[PublicizedFrom(...)]` lambdas cleaned.")
Advertisement
Add Comment
Please, Sign In to add comment