Skip to content

Commit 9ee0b28

Browse files
Detect release MBID + send client version to news endpoint
1 parent 1af5229 commit 9ee0b28

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

src/hooking.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use lofty::ItemValue;
1313
use lofty::TaggedFileExt;
1414
use tracing::debug;
1515
use tracing::error;
16+
use tracing::info;
1617
use tracing::trace;
1718
use url_encoded_data::UrlEncodedData;
1819
use windows::core::PCSTR;
@@ -54,7 +55,7 @@ unsafe fn songfilestream_hook(
5455
let tagged_file = match lofty::read_from_path(file_path) {
5556
Ok(res) => res,
5657
Err(e) => {
57-
debug!("lofty::read_from_path failed {:?}", e);
58+
error!("lofty::read_from_path failed {:?}", e);
5859
return call_original!(mem, file, offset, length, flags);
5960
}
6061
};
@@ -67,14 +68,30 @@ unsafe fn songfilestream_hook(
6768
ItemValue::Text(mbid) => {
6869
let mut global_data = state::GLOBAL_DATA.lock().unwrap();
6970
global_data.current_mbid = Some(mbid.to_string());
70-
debug!("Recording MBID tag found: {:?}", mbid);
71+
info!("Recording MBID tag found: {:?}", mbid);
7172
}
7273
_ => {
7374
error!("Recording MBID tag is an invalid data type...?");
7475
}
7576
},
7677
_ => {
77-
debug!("File has no MBID tag");
78+
debug!("File has no recording MBID");
79+
}
80+
};
81+
82+
match tag.get(&ItemKey::MusicBrainzReleaseId) {
83+
Some(item) => match item.value() {
84+
ItemValue::Text(mbid) => {
85+
let mut global_data = state::GLOBAL_DATA.lock().unwrap();
86+
global_data.current_release_mbid = Some(mbid.to_string());
87+
info!("Release MBID tag found: {:?}", mbid);
88+
}
89+
_ => {
90+
error!("Release MBID tag is an invalid data type...?");
91+
}
92+
},
93+
_ => {
94+
debug!("File has no release MBID");
7895
}
7996
};
8097
}
@@ -137,7 +154,9 @@ unsafe fn send_hook(
137154
debug!("Ticket found in data: {:?}", ticket);
138155
}
139156

140-
if url.ends_with("/as_steamlogin/game_AttemptLoginSteamVerified.php") {
157+
if url.ends_with("/as_steamlogin/game_AttemptLoginSteamVerified.php")
158+
|| url.ends_with("//as_steamlogin/game_CustomNews.php")
159+
{
141160
data.set_one("wvbrclientversion", env!("CARGO_PKG_VERSION"));
142161
let new_data_string = data.to_string_of_original_order();
143162

@@ -172,6 +191,12 @@ unsafe fn send_hook(
172191
&& global_data.current_mbid.is_some()
173192
{
174193
data.set_one("mbid", global_data.current_mbid.as_ref().unwrap());
194+
if global_data.current_release_mbid.is_some() {
195+
data.set_one(
196+
"releasembid",
197+
global_data.current_release_mbid.as_ref().unwrap(),
198+
);
199+
}
175200
let new_data_string = data.to_string_of_original_order();
176201
debug!("New score submission form data: {:?}", new_data_string);
177202

@@ -255,13 +280,14 @@ unsafe fn openrequest_hook(
255280
}
256281
debug!("new OpenRequest flags: {:?}", flags);
257282

258-
// reset current_mbid when a new song is loaded
283+
// reset MBIDs when a new song is loaded
259284
// a bit hacky, but we have to do this so we don't submit an old ID when someone starts playing a Radio song
260285
// Radio mode songs are loaded via memory so trying to see what file it loads the song from won't work
261286
// We could just look at the song it loaded into memory, but the MBID doesn't matter for Radio songs anyway
262287
if object_name.to_string().unwrap() == "/as_steamlogin/game_fetchsongid_unicode.php" {
263288
let mut global_data = state::GLOBAL_DATA.lock().unwrap();
264289
global_data.current_mbid = None;
290+
global_data.current_release_mbid = None;
265291
}
266292

267293
call_original!(

src/state.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ use std::sync::Mutex;
22

33
pub struct GlobalData {
44
pub current_mbid: Option<String>,
5+
pub current_release_mbid: Option<String>,
56
pub ticket: Option<String>,
67
}
78

8-
pub static GLOBAL_DATA: Mutex<GlobalData> = Mutex::new(GlobalData { current_mbid: None, ticket: None });
9+
pub static GLOBAL_DATA: Mutex<GlobalData> = Mutex::new(GlobalData {
10+
current_mbid: None,
11+
ticket: None,
12+
current_release_mbid: None,
13+
});

0 commit comments

Comments
 (0)