All checks were successful
Build and Test / account (push) Successful in 6m10s
it was just causing headaches
63 lines
No EOL
1.5 KiB
Rust
63 lines
No EOL
1.5 KiB
Rust
use bytemuck::{try_from_bytes, Pod, Zeroable};
|
|
use base64::Engine;
|
|
use base64::prelude::BASE64_STANDARD;
|
|
use std::env;
|
|
use once_cell::sync::Lazy;
|
|
|
|
#[derive(Pod, Zeroable, Copy, Clone)]
|
|
#[repr(C, packed)]
|
|
struct FFLStoreData{
|
|
mii_data: FFLiMiiDataOfficial
|
|
}
|
|
|
|
#[derive(Pod, Zeroable, Copy, Clone)]
|
|
#[repr(C, packed)]
|
|
struct FFLiMiiDataOfficial{
|
|
core_data: FFLiMiiDataCore
|
|
}
|
|
|
|
#[derive(Pod, Zeroable, Copy, Clone)]
|
|
#[repr(C, packed)]
|
|
struct FFLiMiiDataCore{
|
|
stuff: u32,
|
|
author_id: u64,
|
|
create_id: [u8; 10],
|
|
unk_1: u16,
|
|
unk_2: u16,
|
|
pub name: [u16; 10],
|
|
}
|
|
|
|
pub struct MiiData{
|
|
pub name: String
|
|
}
|
|
|
|
impl MiiData{
|
|
pub fn read(data: &str) -> Option<Self>{
|
|
let data = BASE64_STANDARD.decode(data).ok()?;
|
|
|
|
let data: &FFLStoreData = try_from_bytes(data.get(0..size_of::<FFLStoreData>())?).ok()?;
|
|
|
|
let name = data.mii_data.core_data.name;
|
|
let idx = name.iter().position(|v| *v == 0x0).unwrap_or(10);
|
|
|
|
let name = &name[0..idx];
|
|
|
|
let name = String::from_utf16(&name).ok()?;
|
|
|
|
Some(Self{
|
|
name
|
|
})
|
|
}
|
|
}
|
|
|
|
pub static MII_PROVIDER_SERVER_URL: Lazy<Box<str>> = Lazy::new(||
|
|
env::var("MII_PROVIDER_SERVER_URL").expect("MII_PROVIDER_SERVER_URL not specified").into_boxed_str()
|
|
);
|
|
|
|
fn get_mii_img_url_path(pid: i32, format: &str) -> String{
|
|
format!("{}/main.{}", pid, format)
|
|
}
|
|
|
|
pub fn get_mii_img_url(pid: i32, format: &str) -> String{
|
|
format!("{}/{}", &*MII_PROVIDER_SERVER_URL, get_mii_img_url_path(pid, format))
|
|
} |