Advertisement
nikich340

WKIT script for serializing cvar on Read(..)

Apr 30th, 2022
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. from pathlib import Path
  2. import fileinput
  3.  
  4. cs_list = list( Path("D:/_ССС/Types").rglob("*.cs") )
  5. special_list = set()
  6. dupl_list = set()
  7.  
  8. for cs in cs_list:
  9.     print(f"CS: {cs}")
  10.     read_wait = False
  11.     read_base = False
  12.     read_lock = False
  13.     offset = 8
  14.     brackets = 0
  15.     brackets_cnt = 0
  16.  
  17.     with fileinput.input(cs, inplace=True) as file:
  18.         for line in file:
  19.             if read_lock:
  20.                 print(line, end='')
  21.                 continue
  22.  
  23.             if line.find("public override void Read(") >= 0:
  24.                 offset = line.find("public override void Read(") + 4
  25.                 read_wait = True
  26.  
  27.             if read_wait:
  28.                 if line.find("base.Read(") >= 0:
  29.                     read_base = True
  30.                 if line.find("=>") >= 0:
  31.                     read_lock = True
  32.                 if line.find("for(") >= 0 or line.find("for (") >= 0:
  33.                     special_list.add(cs)
  34.                 if line.find("SetIsSerialized") >= 0:
  35.                     dupl_list.add(cs)
  36.  
  37.                 for char in line:
  38.                     if char == '{':
  39.                         brackets += 1
  40.                         brackets_cnt += 1
  41.                     elif char == '}':
  42.                         brackets -= 1
  43.                         brackets_cnt += 1
  44.  
  45.                 if brackets == 0 and brackets_cnt >= 2 and not read_lock:
  46.                     if read_base:
  47.                         print(f"{' ' * offset}//SetIsSerialized() in base")
  48.                     else:
  49.                         print(f"{' ' * offset}SetIsSerialized();")
  50.                     read_lock = True
  51.             print(line, end='')
  52.  
  53.     if read_wait:
  54.         print(f"    read_wait = {read_wait}, read_base = {read_base}, offset = {offset}, brackets_cnt = {brackets_cnt}, brackets = {brackets}")
  55.     else:
  56.         print(f"  ----------------")
  57.  
  58. print(dupl_list)
  59. print("---------------")
  60. print(special_list)
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement