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

Play launcher based background support #55

Closed
wants to merge 5 commits into from
Closed
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
92 changes: 62 additions & 30 deletions src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,72 @@ 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 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 gameid: &str;

let Some(uri) = uri else {
anyhow::bail!("Failed to get background picture url");
};
if lang.language == unic_langid::langid!("zh-cn").language
{
gameid = "osvnlOc0S8"
}
else if lang.language == unic_langid::langid!("ja-jp").language
{
gameid = "g0mMIvshDb"
}
else if lang.language == unic_langid::langid!("ko-kr").language
{
gameid = "uxB4MC7nzC"
}
else if lang.language == unic_langid::langid!("id-id").language
{
gameid = "bxPTXSET5t"
}
else if lang.language == unic_langid::langid!("vi-vn").language
{
gameid = "bxPTXSET5t"
}
else if lang.language == unic_langid::langid!("th-th").language
{
gameid = "bxPTXSET5t"
}
else
{
gameid = "5TIVvvcwtM"
}


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"]["id"].as_str() {
Some(id) => id.starts_with(gameid),
_ => 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 hash = uri.split('/')
.last()
Expand Down
Loading