From 6324bdee090fdd2d9d6639b5ccb71852b68b2d92 Mon Sep 17 00:00:00 2001 From: oldnapalm <38410858+oldnapalm@users.noreply.github.com> Date: Sun, 7 Jan 2024 18:29:05 -0300 Subject: [PATCH] Update zwift_offline.py --- zwift_offline.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/zwift_offline.py b/zwift_offline.py index 53a86deb..7ed6dc90 100644 --- a/zwift_offline.py +++ b/zwift_offline.py @@ -1269,7 +1269,30 @@ def api_users_login(): udp_node.port = 3023 response.relay_session_id = player_id response.expiration = 70 - with open(os.path.join(SCRIPT_DIR, "economy_config.txt")) as f: + profile_dir = os.path.join(STORAGE_DIR, str(current_user.player_id)) + config_file = os.path.join(profile_dir, 'economy_config.txt') + if not os.path.isfile(config_file): + with open(os.path.join(SCRIPT_DIR, 'economy_config.txt')) as f: + economy_config = json.load(f) + profile_file = os.path.join(profile_dir, 'profile.bin') + if os.path.isfile(profile_file): + profile = profile_pb2.PlayerProfile() + with open(profile_file, 'rb') as f: + profile.ParseFromString(f.read()) + current_level = profile.achievement_level // 100 + levels = [x for x in economy_config['cyclingLevels'] if x['level'] >= current_level] + if len(levels) > 1 and profile.total_xp > levels[1]['xp']: + offset = profile.total_xp - levels[0]['xp'] + levels = [x for x in economy_config['cyclingLevels'] if x['xp'] <= profile.total_xp] + transition_end = levels[-1]['level'] + for level in economy_config['cyclingLevels']: + if level['level'] >= current_level: + level['xp'] += offset + economy_config['transition_start'] = current_level + economy_config['transition_end'] = transition_end + with open(config_file, 'w') as f: + json.dump(economy_config, f, indent=2) + with open(config_file) as f: Parse(f.read(), response.economy_config) return response.SerializeToString(), 200