Skip to content

Commit

Permalink
Download economy config
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Aug 9, 2024
1 parent 93aa49a commit 9467ddc
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 3 deletions.
2 changes: 1 addition & 1 deletion LEIAME.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ Entre no grupo **zoffline** no Strava https://www.strava.com/clubs/zoffline

* Desative o zwift-offline (veja [Ativando/Desativando o zwift-offline](https://github.com/oldnapalm/zoffline-helper/blob/master/LEIAME.md#ativandodesativando-o-zwift-offline) acima).
* Execute o **get_profile**, digite seu login do Zwift (e-mail) e sua senha.
* Serão criados os arquivos ``profile.bin`` e ``achievements.bin``, mova esses arquivos para a pasta ``storage\1``.
* Serão criados os arquivos ``profile.bin``, ``achievements.bin`` e ``economy_config.txt``, mova esses arquivos para a pasta ``storage\1``.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ Join the **zoffline** Strava group https://www.strava.com/clubs/zoffline

* Disable zwift-offline (see [Enabling/Disabling zwift-offline](https://github.com/oldnapalm/zoffline-helper#enablingdisabling-zwift-offline) above).
* Run **get_profile**, type your Zwift login (e-mail) and password.
* Move the resulting ``profile.bin`` and ``achievements.bin`` into the ``storage\1`` directory.
* Move the resulting ``profile.bin``, ``achievements.bin`` and ``economy_config.txt`` into the ``storage\1`` directory.
39 changes: 39 additions & 0 deletions get_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
import os
import requests
import sys
sys.path.append(os.path.join(sys.path[0], 'protobuf')) # otherwise import in .proto does not work
import login_pb2
from google.protobuf.json_format import MessageToDict
from random import randbytes


if getattr(sys, 'frozen', False):
Expand Down Expand Up @@ -118,6 +122,33 @@ def query(session, access_token, route):
print('HTTP Request failed: %s' % e)


def api_login(session, access_token, login_request):
try:
response = session.post(
url="https://us-or-rly101.zwift.com/api/users/login",
headers={
"Content-Type": "application/x-protobuf-lite",
"Accept": "application/x-protobuf-lite",
"Connection": "keep-alive",
"Host": "us-or-rly101.zwift.com",
"User-Agent": "Zwift/115 CFNetwork/758.0.2 Darwin/15.0.0",
"Authorization": "Bearer %s" % access_token,
"Accept-Language": "en-us",
},
data=login_request.SerializeToString(),
verify=args.verifyCert,
)

if args.verbose:
print('Response HTTP Status Code: {status_code}'.format(
status_code=response.status_code))

return response.content

except requests.exceptions.RequestException as e:
print('HTTP Request failed: %s' % e)


def logout(session, refresh_token):
# Logout
# POST https://secure.zwift.com/auth/realms/zwift/tokens/logout
Expand Down Expand Up @@ -203,6 +234,14 @@ def main(argv):
achievements = query(session, access_token, "achievement/loadPlayerAchievements")
with open('%s/achievements.bin' % SCRIPT_DIR, 'wb') as f:
f.write(achievements)
login_request = login_pb2.LoginRequest()
login_request.key = randbytes(16)
login_response = login_pb2.LoginResponse()
login_response.ParseFromString(api_login(session, access_token, login_request))
login_response_dict = MessageToDict(login_response, preserving_proto_field_name=True)
if 'economy_config' in login_response_dict:
with open('%s/economy_config.txt' % SCRIPT_DIR, 'w') as f:
json.dump(login_response_dict['economy_config'], f, indent=2)

logout(session, refresh_token)

Expand Down
2 changes: 1 addition & 1 deletion get_profile.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import sys
sys.modules['FixTk'] = None

a = Analysis(['get_profile.py'],
pathex=[],
pathex=['protobuf'],
binaries=[],
datas=[],
hiddenimports=[],
Expand Down
1 change: 1 addition & 0 deletions protobuf/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
all:
protoc --python_out=. activity.proto
protoc --python_out=. login.proto
protoc --python_out=. profile.proto
protoc --python_out=. per-session-info.proto
protoc --python_out=. udp-node-msgs.proto
Expand Down
49 changes: 49 additions & 0 deletions protobuf/login.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
syntax = "proto2";
/* XXX: This is a first approximation of login response. Not looked into or verified. */
import "per-session-info.proto";

message LoginResponse {
required string session_state = 1;
required PerSessionInfo info = 2;
optional uint32 relay_session_id = 3;
optional uint32 expiration = 4; // minutes
optional EconomyConfig economy_config = 5;
}

message LoginRequest {
optional AnalyticsEventProperties properties = 1;
required bytes key = 2;
}

message AnalyticsEventProperty {
required string f1 = 1;
required string f2 = 2;
}

message AnalyticsEventProperties {
repeated AnalyticsEventProperty property = 2;
}

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;
}
38 changes: 38 additions & 0 deletions protobuf/login_pb2.py

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

1 change: 1 addition & 0 deletions protobuf/make.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
del *_pb2.py *_pb2.pyc
protoc --python_out=. activity.proto
protoc --python_out=. login.proto
protoc --python_out=. profile.proto
protoc --python_out=. per-session-info.proto
protoc --python_out=. udp-node-msgs.proto
Expand Down

0 comments on commit 9467ddc

Please sign in to comment.