From dcf9fb2b32ac3e434fba99fb9a364486b4ee727c Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Mon, 17 Jul 2023 03:52:57 +0200 Subject: [PATCH] Add proper RNG send to console --- utilities/gsc_trading.py | 21 ++++++++++++++++----- utilities/rby_trading.py | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/utilities/gsc_trading.py b/utilities/gsc_trading.py index 9ca6de1..bda4dfc 100644 --- a/utilities/gsc_trading.py +++ b/utilities/gsc_trading.py @@ -450,6 +450,7 @@ class GSCTrading: max_tolerance_bytes = 3 special_sections_len = [0xA, 0x1BC, 0xC5, 0x181] special_sections_starter = [next_section, next_section, next_section, mail_next_section] + special_sections_preamble_len = [7, 6, 3, 5] special_sections_sync = [True, True, True, False] drop_bytes_checks = [[0xA, 0x1B9, 0xC5, 0x181], [next_section, next_section, mail_next_section, no_input], [0,0,0,0]] stop_trade = 0x7F @@ -596,11 +597,21 @@ class GSCTrading: if self.special_sections_sync[index]: next = self.no_input # Make sure the device is in the right state - while next != self.special_sections_starter[index]: - next = self.swap_byte(next) - # Sync with the device and start the actual trade - while next == self.special_sections_starter[index]: - next = self.swap_byte(next) + recv = next + while recv != self.special_sections_starter[index]: + recv = self.swap_byte(next) + next = self.special_sections_starter[index] + # Random has no leeway, though it's not needed, since master sets the RNG + if buffered and (index == 0): + # The "+ 1" is because the first one is not counted... + for i in range(self.special_sections_preamble_len[index] + 1): + next = self.swap_byte(next) + if next != self.special_sections_starter[index]: + break + else: + # Sync with the device and start the actual trade + while next == self.special_sections_starter[index]: + next = self.swap_byte(next) # next now contains the first received byte from the device! self.verbose_print(GSCTradingStrings.separate_section_str, end='') diff --git a/utilities/rby_trading.py b/utilities/rby_trading.py index ab28418..e25e5ae 100644 --- a/utilities/rby_trading.py +++ b/utilities/rby_trading.py @@ -84,6 +84,7 @@ class RBYTrading(GSCTrading): enter_room_states = [[0x01, 0x60, 0xD0, 0xD4], [{0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x6F}, {0xD0, 0xD1, 0xD2, 0xD3, 0xD4}, {0xD0, 0xD1, 0xD2, 0xD3, 0xD4}, {0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x6F}]] start_trading_states = [[0x60, 0x60], [{0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x6F}, {0xFD}]] special_sections_len = [0xA, 0x1A2, 0xC5] + special_sections_preamble_len = [7, 6, 3] success_base_value = 0x60 success_values = set(range(success_base_value, success_base_value+0x10)) possible_indexes = set(range(0x60, 0x70))