Advertisement
MrOstrich

sekiromonitor.py

Jun 13th, 2025 (edited)
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.64 KB | Gaming | 0 0
  1. # Made by Deepseek AI
  2. import os
  3. import time
  4. from datetime import datetime
  5.  
  6. def monitor_save_file(file_path, check_interval=1.0, log_file="changes.txt"):
  7.     if not os.path.exists(file_path):
  8.         print(f"Error: File not found - {file_path}")
  9.         print("Tip: Press Win+R, type '%appdata%', and check the Sekiro folder.")
  10.         return
  11.  
  12.     print(f"Monitoring: {file_path}")
  13.     print(f"Logging to: {log_file}")
  14.     print("Ignoring offsets 0x0300-0x030F (playtime counters).")
  15.     print("Press Ctrl+C to stop.\n")
  16.    
  17.     previous_data = open(file_path, 'rb').read()
  18.  
  19.     try:
  20.         with open(log_file, 'a') as log:
  21.             while True:
  22.                 time.sleep(check_interval)
  23.                 try:
  24.                     current_data = open(file_path, 'rb').read()
  25.                 except PermissionError:
  26.                     print("Error: Could not read the file. Close Sekiro and retry.")
  27.                     break
  28.  
  29.                 if current_data != previous_data:
  30.                     changes = []
  31.                     min_len = min(len(previous_data), len(current_data))
  32.                    
  33.                     # Detect all changes (except 0x0300-0x030F)
  34.                     for offset in range(min_len):
  35.                         if 0x0300 <= offset <= 0x030F:  # Skip playtime/data
  36.                             continue
  37.                         if previous_data[offset] != current_data[offset]:
  38.                             changes.append((offset, previous_data[offset], current_data[offset]))
  39.  
  40.                     timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  41.                     log_msg = f"\n--- Change at {timestamp} ---\n"
  42.                     log_msg += f"Total bytes changed: {len(changes)}\n"
  43.                    
  44.                     # Log ALL changes to file
  45.                     for offset, old_byte, new_byte in changes[:100]:  # Limit to 100 changes per log
  46.                         log_msg += f"Offset: 0x{offset:06X} | Old: 0x{old_byte:02X} | New: 0x{new_byte:02X}\n"
  47.                     log.write(log_msg)
  48.                     log.flush()
  49.  
  50.                     # Print to console + highlight potential flags
  51.                     print(f"\n--- Change at {timestamp} ---")
  52.                     print(f"Total changes: {len(changes)} (Full log in {log_file})")
  53.                    
  54.                     for offset, old_byte, new_byte in changes[:20]:  # Show first 20 changes
  55.                         # Skip playtime/data (redundant check for console output)
  56.                         if 0x0300 <= offset <= 0x030F:
  57.                             continue
  58.                        
  59.                         # Highlight potential flags
  60.                         if old_byte == 0x00 and new_byte in (0x01, 0x02, 0x80):
  61.                             print(f">>> FLAG CANDIDATE (DECISION?) | Offset: 0x{offset:06X} | Old: 0x{old_byte:02X} → New: 0x{new_byte:02X}")
  62.                         elif (old_byte ^ new_byte) in (0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80):
  63.                             print(f">>> BITFLAG TOGGLE | Offset: 0x{offset:06X} | Old: 0x{old_byte:02X} | New: 0x{new_byte:02X}")
  64.                         else:
  65.                             print(f"Offset: 0x{offset:06X} | Old: 0x{old_byte:02X} | New: 0x{new_byte:02X}")
  66.  
  67.                     previous_data = current_data
  68.  
  69.     except KeyboardInterrupt:
  70.         print("\nStopped monitoring.")
  71.     except Exception as e:
  72.         print(f"Error: {e}")
  73.  
  74. # EDIT THIS PATH TO YOUR ACTUAL SAVE FILE!
  75. save_file_path = r"C:\Users\windows11\AppData\Roaming\Sekiro\76561197960267366\S0000.sl2"
  76. monitor_save_file(save_file_path)
  77. input("\nPress Enter to exit...")  # Keeps window open
Tags: program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement