Last active
December 4, 2021 04:06
-
-
Save Grayfox96/1811315da997cc8140ecebdf94f4878a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def s32(integer: int) -> int: | |
return ((integer & 0xffffffff) ^ 0x80000000) - 0x80000000 | |
def datetime_to_seed(datetime: int) -> int: | |
seed = s32(datetime + 1) | |
seed = s32(s32(seed * 1108104919) + 11786) | |
seed = s32(s32(seed * 1566083941) + 15413) | |
seed = s32(s32(seed >> 16) + s32(seed << 16)) | |
if seed >= 0: | |
return seed | |
else: | |
return 0x100000000 + seed | |
def main(): | |
target_seed = int(input('Seed: ')) | |
if target_seed not in POSSIBLE_SEEDS: | |
print(f'Seed {target_seed} is not a possible HD seed') | |
return | |
dt = datetime.datetime.now() | |
dt_limit = dt + ONE_HOUR | |
print('Time now: ', dt.strftime('%m/%d/%Y %H:%M:%S')) | |
current_seed = 0x100000000 | |
while target_seed != current_seed: | |
dt = dt + ONE_SECOND | |
xored_datetime = (dt.month | |
^ dt.day | |
^ int(hex(dt.year)[-2:], 16) | |
^ dt.hour | |
^ dt.minute | |
^ dt.second | |
^ 0b00010010) | |
current_seed = datetime_to_seed(xored_datetime) | |
if dt == dt_limit: | |
year = (dt.year // 64 + 1) * 64 | |
dt = datetime.datetime(year=year, month=1, day=1) | |
dt_limit = dt + ONE_HOUR | |
dt = dt - ONE_SECOND | |
print('Press new game at:', dt.strftime('%m/%d/%Y %H:%M:%S')) | |
POSSIBLE_SEEDS = [datetime_to_seed(i) for i in range(256)] | |
ONE_SECOND = datetime.timedelta(seconds=1) | |
ONE_HOUR = datetime.timedelta(hours=1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment