Skip to content

Commit

Permalink
Update zwift_offline.py
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Jan 7, 2024
1 parent b93ec36 commit 6324bde
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion zwift_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6324bde

Please sign in to comment.