Advertisement
Guest User

Untitled

a guest
Jun 20th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. import os
  2. import re
  3.  
  4. # Directory containing the files
  5. directory = '......\CustomLevels'
  6. # New value for noteJumpMovementSpeed
  7. new_value = 6
  8.  
  9. # Collect debug information
  10. debug_info = []
  11.  
  12. def replace_note_jump_speed(file_path, new_value):
  13. try:
  14. with open(file_path, 'r', encoding='utf-8') as file:
  15. content = file.read()
  16.  
  17. # Regex to find noteJumpMovementSpeed values with different spacing scenarios
  18. pattern = re.compile(r'"_noteJumpMovementSpeed"\s*:\s*\d+(\.\d+)?')
  19. replacement = f'"_noteJumpMovementSpeed": {new_value}'
  20.  
  21. # Check if pattern matches anything
  22. matches = pattern.findall(content)
  23. if matches:
  24. debug_info.append(f"Matches found in {file_path}: {matches}")
  25. else:
  26. debug_info.append(f"No matches found in {file_path}")
  27.  
  28. # Capture content before replacement for debugging
  29. debug_info.append(f"Original content of {file_path}:\n{content}\n")
  30.  
  31. updated_content = pattern.sub(replacement, content)
  32.  
  33. # Capture content after replacement for debugging
  34. debug_info.append(f"Updated content of {file_path}:\n{updated_content}\n")
  35.  
  36. if content != updated_content:
  37. with open(file_path, 'w', encoding='utf-8') as file:
  38. file.write(updated_content)
  39. debug_info.append(f"Updated {file_path}")
  40. else:
  41. debug_info.append(f"No changes made to {file_path}")
  42.  
  43. except Exception as e:
  44. debug_info.append(f"Failed to update {file_path}: {e}")
  45.  
  46. for root, _, files in os.walk(directory):
  47. debug_info.append(f"Checking directory: {root}")
  48. found_info_dat = False
  49. for file in files:
  50. if file.lower() == 'info.dat':
  51. file_path = os.path.join(root, file)
  52. debug_info.append(f"Found file: {file_path}")
  53. replace_note_jump_speed(file_path, new_value)
  54. found_info_dat = True
  55. if not found_info_dat:
  56. debug_info.append(f"No info.dat found in directory: {root}")
  57.  
  58. # Print collected debug information at the end
  59. with open('debug_output.txt', 'w', encoding='utf-8') as debug_file:
  60. for info in debug_info:
  61. debug_file.write(info + '\n')
  62.  
  63. print("All files have been checked. Debug information written to debug_output.txt.")
  64. input("Press Enter to exit...")
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement