Skip to content

Commit

Permalink
Add economy config
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Jan 8, 2024
1 parent b6cbacb commit 75e26bd
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 13 deletions.
1 change: 1 addition & 0 deletions economy_config.txt

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions protobuf/login.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ message LoginResponse {
required PerSessionInfo info = 2;
optional uint32 relay_session_id = 3;
optional uint32 expiration = 4; // minutes
optional EconomyConfig economy_config = 5;
}

message LoginRequest {
Expand All @@ -27,3 +28,22 @@ message RelaySessionRefreshResponse {
required uint32 relay_session_id = 1;
required uint32 expiration = 2; // minutes
}

message EconomyConfig {
repeated Level cycling_levels = 1;
repeated Level running_levels = 2;
required uint32 f3 = 3;
required uint32 f4 = 4;
required uint32 f5 = 5;
optional uint32 transition_start = 6;
optional uint32 transition_end = 7;
}

message Level {
required uint32 level = 1;
required uint32 xp = 2;
required uint32 drops = 3;
optional uint32 f4 = 4;
optional string entitlement_1 = 5;
optional string entitlement_2 = 6;
}
26 changes: 15 additions & 11 deletions protobuf/login_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions scripts/login_to_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json
import sys
sys.path.insert(0, '../protobuf')
import login_pb2
from google.protobuf.json_format import MessageToDict

with open("login", "rb") as f:
login = login_pb2.LoginResponse()
login.ParseFromString(f.read())

with open('../economy_config.txt', 'w') as f:
json.dump(MessageToDict(login, preserving_proto_field_name=True)['economy_config'], f)
2 changes: 1 addition & 1 deletion standalone.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version = ET.parse('cdn/gameassets/Zwift_Updates_Root/Zwift_ver_cur.xml').getroo
a = Analysis(['standalone.py'],
pathex=['protobuf'],
binaries=[],
datas=[('ssl/*', 'ssl'), ('start_lines.csv', '.'), ('game_info.txt', '.'), ('variants.txt', '.'), ('bot.txt', '.')],
datas=[('ssl/*', 'ssl'), ('start_lines.csv', '.'), ('game_info.txt', '.'), ('variants.txt', '.'), ('economy_config.txt', '.'), ('bot.txt', '.')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
Expand Down
2 changes: 1 addition & 1 deletion variants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@
"boolValue": false
},
"ServerConfigXP": {
"varintValue": "0"
"varintValue": "2"
},
"ShowRideStreaksScreen": {
"boolValue": true
Expand Down
25 changes: 25 additions & 0 deletions zwift_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,31 @@ def api_users_login():
udp_node.port = 3023
response.relay_session_id = player_id
response.expiration = 70
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['cycling_levels'] if x['level'] >= current_level]
if len(levels) > 1 and profile.total_xp > levels[1]['xp']:
offset = profile.total_xp - levels[0]['xp']
transition_end = [x for x in levels if x['xp'] <= profile.total_xp][-1]['level']
for level in economy_config['cycling_levels']:
if level['level'] >= current_level:
level['xp'] += offset
if transition_end > current_level:
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 75e26bd

Please sign in to comment.