diff --git a/configs/config_turnback.json b/configs/config_turnback.json index fa7d0a5..89acef8 100644 --- a/configs/config_turnback.json +++ b/configs/config_turnback.json @@ -1,10 +1,10 @@ { - "MonitorWindow": 1, + "MonitorWindow": true, "WindowPrefix": "SysDVR-Client [PID ", "image": "./images/spear_pillar/eye.png", "view": [ - 621, - 343, + 622, + 341, 17, 19 ], diff --git a/memo.md b/memo.md index 4001c2b..ef83512 100644 --- a/memo.md +++ b/memo.md @@ -2,11 +2,12 @@ memo.md type : roi_x, roi_y, roi_w, roi_h munchlax : 730, 670 ,50, 60 -home/eye_blur : 905, 750, 55, 55 -home/eye_normal : 905, 480, 55, 200 -ruin/eye : 920, 490, 35, 50 -secretbase/eye : 870, 680, 85, 90 -underground/eye : 925, 520, 35, 35 -trophygarden/eye : 930, 505, 30, 30 -mtcoronet/eye : 930, 510, 30, 40 -spearpillar/eye : 935,505,25,30 \ No newline at end of file +trainer/home/eye_blur : 905, 750, 55, 55 +trainer/home/eye_normal : 905, 480, 55, 200 +trainer/ruin/eye : 920, 490, 35, 50 +trainer/secretbase/eye : 870, 680, 85, 90 +trainer/underground/eye : 925, 520, 35, 35 +trainer/trophygarden/eye : 930, 505, 30, 30 +trainer/mtcoronet/eye : 930, 510, 30, 40 +trainer/spearpillar/eye : 935,505,25,30 +barry/eye : 1065, 490, 30, 35 \ No newline at end of file diff --git a/src/player_blink_gui.py b/src/player_blink_gui.py index 14ccdb4..fc6f47f 100644 --- a/src/player_blink_gui.py +++ b/src/player_blink_gui.py @@ -467,8 +467,9 @@ class Application(tk.Frame): self.s01_23.insert(1.0,s01+"\n"+s23) print([hex(x) for x in state]) - observed_blinks, _, offset_time = rngtool.tracking_blink(self.player_eye, *self.config_json["view"], MonitorWindow=self.config_json["MonitorWindow"], WindowPrefix=self.config_json["WindowPrefix"], crop=self.config_json["crop"], camera=self.config_json["camera"], tk_window=self, th=self.config_json["thresh"], size=20) - self.rng, adv = rngtool.reidentifyByBlinks(Xorshift(*state), observed_blinks, return_advance=True, npc=self.config_json["npc"]) + observed_blinks, observed_intervals, offset_time = rngtool.tracking_blink(self.player_eye, *self.config_json["view"], MonitorWindow=self.config_json["MonitorWindow"], WindowPrefix=self.config_json["WindowPrefix"], crop=self.config_json["crop"], camera=self.config_json["camera"], tk_window=self, th=self.config_json["thresh"], size=6) + # self.rng, adv = rngtool.reidentifyByBlinks(Xorshift(*state), observed_blinks, return_advance=True, npc=self.config_json["npc"]) + self.rng, adv = rngtool.reidentifyByIntervals(Xorshift(*state), observed_intervals, return_advance=True, npc=self.config_json["npc"]) self.reidentify_button['text'] = "Reidentify" diff --git a/src/rngtool.py b/src/rngtool.py index f8e70ec..dd5cd3c 100644 --- a/src/rngtool.py +++ b/src/rngtool.py @@ -310,6 +310,19 @@ def recov(blinks:List[int],rawintervals:List[int])->Xorshift: return result def reidentifyByBlinks(rng:Xorshift, observed_blinks:List[int], npc = 0, search_max=10**6, search_min=0, return_advance=False)->Xorshift: + """reidentify Xorshift state by type of observed blinks. + + Args: + rng (Xorshift): identified rng + observed_blinks (List[int]): + npc (int, optional): num of npcs. Defaults to 0. + search_max (int, optional): . Defaults to 10**6. + search_min (int, optional): . Defaults to 0. + + Returns: + Xorshift: reidentified rng + """ + if search_maxXorshift: + """reidentify Xorshift state by intervals of observed blinks. + This method is faster than "reidentifyByBlinks" in most cases since it can be reidentified by less blinking. + + Args: + rng (Xorshift): [description] + rawintervals (List[int]): list of intervals of blinks. 6 or more is recommended. + npc (int, optional): [description]. Defaults to 0. + search_max ([type], optional): [description]. Defaults to 10**6. + search_min (int, optional): [description]. Defaults to 0. + + Returns: + Xorshift: [description] + """ + intervals = rawintervals[1:] + if search_maxXorshift: """Recover the xorshift from the interval of Munchlax blinks. diff --git a/src/starter.py b/src/starter.py new file mode 100644 index 0000000..d3d9ab9 --- /dev/null +++ b/src/starter.py @@ -0,0 +1,175 @@ +import rngtool +import calc +import cv2 +import time +from xorshift import Xorshift +import heapq + +def firstspecify(): + imgpath = "./trainer/home/eye_blur.png" + player_eye = cv2.imread(imgpath, cv2.IMREAD_GRAYSCALE) + if player_eye is None: + print("path is wrong") + return + blinks, intervals, offset_time = rngtool.tracking_blink(player_eye, 905, 750, 55, 55) + prng = rngtool.recov(blinks, intervals) + + waituntil = time.perf_counter() + diff = round(waituntil-offset_time) + prng.getNextRandSequence(diff) + + state = prng.getState() + print("state(64bit 64bit)") + print(hex(state[0]<<32|state[1]), hex(state[2]<<32|state[3])) + print("state(32bit 32bit 32bit 32bit)") + print(*[hex(s) for s in state]) + +def reidentify(): + print("input xorshift state(state[0] state[1] state[2] state[3])") + state = [int(x,0) for x in input().split()] + + imgpath = "./barry/eye.png" + player_eye = cv2.imread(imgpath, cv2.IMREAD_GRAYSCALE) + if player_eye is None: + print("path is wrong") + return + + observed_blinks, _, offset_time = rngtool.tracking_blink(player_eye, 1065, 490, 30, 35,size=20) + reidentified_rng = rngtool.reidentifyByBlinks(Xorshift(*state), observed_blinks,npc=1) + if reidentified_rng is None: + print("couldn't reidentify state.") + return + + waituntil = time.perf_counter() + diff = int(-(-(waituntil-offset_time)//1)) + print(diff, waituntil-offset_time) + reidentified_rng.advances(max(diff,0)*2) + + state = reidentified_rng.getState() + print("state(64bit 64bit)") + print(hex(state[0]<<32|state[1]), hex(state[2]<<32|state[3])) + print("state(32bit 32bit 32bit 32bit)") + print(*[hex(s) for s in state]) + + advances = 0 + waituntil = time.perf_counter() + time.sleep(diff - (waituntil - offset_time)) + + while True: + waituntil += 1.018 + + next_time = waituntil - time.perf_counter() or 0 + time.sleep(next_time) + #player/barry + advances += 1 + r = reidentified_rng.next() + print(f"advances:{advances}, blinks:{hex(r&0xF)}", end=" ") + #barry/player + advances += 1 + r = reidentified_rng.next() + print(f"advances:{advances}, blinks:{hex(r&0xF)}", end=" ") + print() + +def starter_timeline(): + print("input xorshift state(state[0] state[1] state[2] state[3])") + state = [int(x,0) for x in input().split()] + + imgpath = "./barry/eye.png" + player_eye = cv2.imread(imgpath, cv2.IMREAD_GRAYSCALE) + if player_eye is None: + print("path is wrong") + return + + observed_blinks, _, offset_time = rngtool.tracking_blink(player_eye, 1065, 490, 30, 35,size=20) + reidentified_rng = rngtool.reidentifyByBlinks(Xorshift(*state), observed_blinks,npc=1) + if reidentified_rng is None: + print("couldn't reidentify state.") + return + + waituntil = time.perf_counter() + diff = int(-(-(waituntil-offset_time)//1)) + print(waituntil-offset_time) + reidentified_rng.advances(max(diff,0)*2) + + state = reidentified_rng.getState() + print("state(64bit 64bit)") + print(hex(state[0]<<32|state[1]), hex(state[2]<<32|state[3])) + print("state(32bit 32bit 32bit 32bit)") + print(*[hex(s) for s in state]) + + #timecounter reset + advances = 0 + waituntil = time.perf_counter() + time.sleep(diff - (waituntil - offset_time)) + print("next message 'I heard them say professor...'") + + for _ in [0]*20: + waituntil += 1.018 + next_time = waituntil - time.perf_counter() or 0 + time.sleep(next_time) + #player/barry + advances += 1 + r = reidentified_rng.next() + print(f"advances:{advances}, blinks:{hex(r&0xF)}", end=" ") + #barry/player + advances += 1 + r = reidentified_rng.next() + print(f"advances:{advances}, blinks:{hex(r&0xF)}", end=" ") + print() + + #advances(reference:https://github.com/Lincoln-LM/Project_Xs/blob/main/configs/config_starter.json) + advances += 41 #"advance_delay" + reidentified_rng.advances(41) + waituntil = time.perf_counter() + print("press A") + queue = [] + + #first(?) starly + advances += 1 + #blink_int = reidentified_rng.range(3.0, 12.0) + 0.285 + blink_int = reidentified_rng.rangefloat(3,12) + 0.285 + heapq.heappush(queue, waituntil+blink_int) + + #second(?) starly + advances += 1 + #blink_int = reidentified_rng.range(3.0, 12.0) + 0.285 + blink_int = reidentified_rng.rangefloat(3,12) + 0.285 + heapq.heappush(queue, waituntil+blink_int) + print("next massage:'What's going on?!'") + for _ in range(4): + advances += 1 + w = heapq.heappop(queue) + next_time = w - time.perf_counter() or 0 + if next_time>0: + time.sleep(next_time) + + #blink_int = reidentified_rng.range(3.0, 12.0) + 0.285 + blink_int = reidentified_rng.rangefloat(3,12) + 0.285 + heapq.heappush(queue, w+blink_int) + print(f"advances:{advances}, interval:{blink_int}") + + #advances(reference:https://github.com/Lincoln-LM/Project_Xs/blob/main/configs/config_starter.json) + advances += 49 #"advance_delay_2" + reidentified_rng.advances(49) + print("press A") + + #advance(+1 when select sterter) + advances += 1 + while queue: + advances += 1 + w = heapq.heappop(queue) + next_time = w - time.perf_counter() or 0 + if next_time>0: + time.sleep(next_time) + + #blink_int = reidentified_rng.range(3.0, 12.0) + 0.285 + blink_int = reidentified_rng.rangefloat(3,12) + 0.285 + + heapq.heappush(queue, w+blink_int) + print(f"advances:{advances}, interval:{blink_int}") + + +if __name__ == "__main__": + #firstspecify() + #reidentify() + starter_timeline() \ No newline at end of file diff --git a/src/stationary.py b/src/stationary.py index 7296eac..997588d 100644 --- a/src/stationary.py +++ b/src/stationary.py @@ -121,8 +121,8 @@ def stationary_timeline(): queue = [] heapq.heappush(queue, (waituntil+1.017,0)) - #blink_int = reidentified_rng.range(3.0, 12.0) + 0.3 - blink_int = reidentified_rng.rangefloat(3,12) + 0.3 + #blink_int = reidentified_rng.range(3.0, 12.0) + 0.285 + blink_int = reidentified_rng.rangefloat(3,12) + 0.285 heapq.heappush(queue, (waituntil+blink_int,1)) while queue: diff --git a/src/tidsid.py b/src/tidsid.py index df809d1..c84c588 100644 --- a/src/tidsid.py +++ b/src/tidsid.py @@ -16,16 +16,17 @@ def getids(r): tid,sid = r&0xFFFF, r>>16 return g7tid, tid, sid -def generate_dangerintervals_list(k): +def generate_dangerintervals_list(k,eps): lst = [] for b in range(1<