mirror of
https://github.com/zoffline/zwift-offline.git
synced 2025-12-12 23:59:43 -08:00
Add economy config
This commit is contained in:
1
economy_config.txt
Normal file
1
economy_config.txt
Normal file
File diff suppressed because one or more lines are too long
@@ -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 {
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -14,21 +14,25 @@ _sym_db = _symbol_database.Default()
|
||||
import per_session_info_pb2 as per__session__info__pb2
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0blogin.proto\x1a\x16per-session-info.proto\"s\n\rLoginResponse\x12\x15\n\rsession_state\x18\x01 \x02(\t\x12\x1d\n\x04info\x18\x02 \x02(\x0b\x32\x0f.PerSessionInfo\x12\x18\n\x10relay_session_id\x18\x03 \x01(\r\x12\x12\n\nexpiration\x18\x04 \x01(\r\"J\n\x0cLoginRequest\x12-\n\nproperties\x18\x01 \x02(\x0b\x32\x19.AnalyticsEventProperties\x12\x0b\n\x03key\x18\x02 \x02(\x0c\"0\n\x16\x41nalyticsEventProperty\x12\n\n\x02\x66\x31\x18\x01 \x02(\t\x12\n\n\x02\x66\x32\x18\x02 \x02(\t\"E\n\x18\x41nalyticsEventProperties\x12)\n\x08property\x18\x02 \x03(\x0b\x32\x17.AnalyticsEventProperty\"K\n\x1bRelaySessionRefreshResponse\x12\x18\n\x10relay_session_id\x18\x01 \x02(\r\x12\x12\n\nexpiration\x18\x02 \x02(\r')
|
||||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0blogin.proto\x1a\x16per-session-info.proto\"\x9b\x01\n\rLoginResponse\x12\x15\n\rsession_state\x18\x01 \x02(\t\x12\x1d\n\x04info\x18\x02 \x02(\x0b\x32\x0f.PerSessionInfo\x12\x18\n\x10relay_session_id\x18\x03 \x01(\r\x12\x12\n\nexpiration\x18\x04 \x01(\r\x12&\n\x0e\x65\x63onomy_config\x18\x05 \x01(\x0b\x32\x0e.EconomyConfig\"J\n\x0cLoginRequest\x12-\n\nproperties\x18\x01 \x02(\x0b\x32\x19.AnalyticsEventProperties\x12\x0b\n\x03key\x18\x02 \x02(\x0c\"0\n\x16\x41nalyticsEventProperty\x12\n\n\x02\x66\x31\x18\x01 \x02(\t\x12\n\n\x02\x66\x32\x18\x02 \x02(\t\"E\n\x18\x41nalyticsEventProperties\x12)\n\x08property\x18\x02 \x03(\x0b\x32\x17.AnalyticsEventProperty\"K\n\x1bRelaySessionRefreshResponse\x12\x18\n\x10relay_session_id\x18\x01 \x02(\r\x12\x12\n\nexpiration\x18\x02 \x02(\r\"\xa5\x01\n\rEconomyConfig\x12\x1e\n\x0e\x63ycling_levels\x18\x01 \x03(\x0b\x32\x06.Level\x12\x1e\n\x0erunning_levels\x18\x02 \x03(\x0b\x32\x06.Level\x12\n\n\x02\x66\x33\x18\x03 \x02(\r\x12\n\n\x02\x66\x34\x18\x04 \x02(\r\x12\n\n\x02\x66\x35\x18\x05 \x02(\r\x12\x18\n\x10transition_start\x18\x06 \x01(\r\x12\x16\n\x0etransition_end\x18\x07 \x01(\r\"k\n\x05Level\x12\r\n\x05level\x18\x01 \x02(\r\x12\n\n\x02xp\x18\x02 \x02(\r\x12\r\n\x05\x64rops\x18\x03 \x02(\r\x12\n\n\x02\x66\x34\x18\x04 \x01(\r\x12\x15\n\rentitlement_1\x18\x05 \x01(\t\x12\x15\n\rentitlement_2\x18\x06 \x01(\t')
|
||||
|
||||
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
|
||||
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'login_pb2', globals())
|
||||
if _descriptor._USE_C_DESCRIPTORS == False:
|
||||
|
||||
DESCRIPTOR._options = None
|
||||
_LOGINRESPONSE._serialized_start=39
|
||||
_LOGINRESPONSE._serialized_end=154
|
||||
_LOGINREQUEST._serialized_start=156
|
||||
_LOGINREQUEST._serialized_end=230
|
||||
_ANALYTICSEVENTPROPERTY._serialized_start=232
|
||||
_ANALYTICSEVENTPROPERTY._serialized_end=280
|
||||
_ANALYTICSEVENTPROPERTIES._serialized_start=282
|
||||
_ANALYTICSEVENTPROPERTIES._serialized_end=351
|
||||
_RELAYSESSIONREFRESHRESPONSE._serialized_start=353
|
||||
_RELAYSESSIONREFRESHRESPONSE._serialized_end=428
|
||||
_LOGINRESPONSE._serialized_start=40
|
||||
_LOGINRESPONSE._serialized_end=195
|
||||
_LOGINREQUEST._serialized_start=197
|
||||
_LOGINREQUEST._serialized_end=271
|
||||
_ANALYTICSEVENTPROPERTY._serialized_start=273
|
||||
_ANALYTICSEVENTPROPERTY._serialized_end=321
|
||||
_ANALYTICSEVENTPROPERTIES._serialized_start=323
|
||||
_ANALYTICSEVENTPROPERTIES._serialized_end=392
|
||||
_RELAYSESSIONREFRESHRESPONSE._serialized_start=394
|
||||
_RELAYSESSIONREFRESHRESPONSE._serialized_end=469
|
||||
_ECONOMYCONFIG._serialized_start=472
|
||||
_ECONOMYCONFIG._serialized_end=637
|
||||
_LEVEL._serialized_start=639
|
||||
_LEVEL._serialized_end=746
|
||||
# @@protoc_insertion_point(module_scope)
|
||||
|
||||
12
scripts/login_to_json.py
Normal file
12
scripts/login_to_json.py
Normal file
@@ -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)
|
||||
@@ -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=[],
|
||||
|
||||
@@ -1036,7 +1036,7 @@
|
||||
"boolValue": false
|
||||
},
|
||||
"ServerConfigXP": {
|
||||
"varintValue": "0"
|
||||
"varintValue": "2"
|
||||
},
|
||||
"ShowRideStreaksScreen": {
|
||||
"boolValue": true
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user