Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed non-cn backgrounds #50

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 32 additions & 31 deletions src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,40 @@ pub struct Background {
pub hash: String
}

pub fn get_uri() -> String {
let lang = crate::i18n::get_lang();

if lang.language == unic_langid::langid!("zh-cn").language {
concat!("https://hyp-api.", "mi", "ho", "yo", ".com/hyp/hyp-connect/api/getAllGameBasicInfo?launcher_id=jGHBHlcOq1").to_owned()
}

else {
let uri = concat!("https://sg-hyp-api.", "ho", "yo", "verse", ".com/hyp/hyp-connect/api/getAllGameBasicInfo?launcher_id=VYTpXlbWo8&language=");

uri.to_owned() + &crate::i18n::format_lang(lang)
}
}

#[cached::proc_macro::cached(result)]
pub fn get_background_info() -> anyhow::Result<Background> {
let json = serde_json::from_slice::<serde_json::Value>(minreq::get(get_uri()).send()?.as_bytes())?;

let uri = json["data"]["game_info_list"].as_array()
.ok_or_else(|| anyhow::anyhow!("Failed to list games in the backgrounds API"))?
.iter()
.find(|game| {
match game["game"]["biz"].as_str() {
Some(biz) => biz.starts_with("bh3_"),
_ => false
}
})
.ok_or_else(|| anyhow::anyhow!("Failed to find the game in the backgrounds API"))?["backgrounds"]
.as_array()
.and_then(|backgrounds| backgrounds.iter().next())
.and_then(|background| background["background"]["url"].as_str())
.ok_or_else(|| anyhow::anyhow!("Failed to get background picture url"))?
.to_string();
let lang = crate::i18n::get_lang();

let uri = if lang.language == unic_langid::langid!("zh-cn").language {
let api_uri = concat!("https://hyp-api.", "mi", "ho", "yo", ".com/hyp/hyp-connect/api/getAllGameBasicInfo?launcher_id=jGHBHlcOq1");

let json = serde_json::from_slice::<serde_json::Value>(minreq::get(api_uri).send()?.as_bytes())?;

json["data"]["game_info_list"].as_array()
.ok_or_else(|| anyhow::anyhow!("Failed to list games in the backgrounds API"))?
.iter()
.find(|game| {
match game["game"]["biz"].as_str() {
Some(biz) => biz.starts_with("bh3_"),
_ => false
}
})
.ok_or_else(|| anyhow::anyhow!("Failed to find the game in the backgrounds API"))?["backgrounds"]
.as_array()
.and_then(|backgrounds| backgrounds.iter().next())
.and_then(|background| background["background"]["url"].as_str())
.map(|background| background.to_owned())
} else {
let api_uri = concat!("https://bh3-launcher.", "ho", "yo", "verse", ".com/bh3_global/mdk/launcher/api/content?filter_adv=true&key=dpz65xJ3&launcher_id=10&language=");

let json = serde_json::from_slice::<serde_json::Value>(minreq::get(api_uri.to_string() + &crate::i18n::format_lang(lang)).send()?.as_bytes())?;

json["data"]["adv"]["background"].as_str().map(|background| background.to_owned())
};

let Some(uri) = uri else {
anyhow::bail!("Failed to get background picture url");
};

let hash = uri.split('/')
.last()
Expand Down
Loading