mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2025-03-23 06:46:11 +00:00
Format Rust code using rustfmt
This commit is contained in:
parent
196949d499
commit
fdd20b9dd2
1 changed files with 185 additions and 190 deletions
|
@ -1,190 +1,185 @@
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use skyline::libc::c_void;
|
use skyline::libc::c_void;
|
||||||
use skyline::nn::{account, oe, time};
|
use skyline::nn::{account, oe, time};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use crate::common::release::CURRENT_VERSION;
|
use crate::common::release::CURRENT_VERSION;
|
||||||
|
|
||||||
pub static mut EVENT_QUEUE: Vec<Event> = vec![];
|
pub static mut EVENT_QUEUE: Vec<Event> = vec![];
|
||||||
static mut SESSION_ID: OnceCell<String> = OnceCell::new();
|
static mut SESSION_ID: OnceCell<String> = OnceCell::new();
|
||||||
static mut DEVICE_ID: OnceCell<String> = OnceCell::new();
|
static mut DEVICE_ID: OnceCell<String> = OnceCell::new();
|
||||||
static mut USER_ID: OnceCell<String> = OnceCell::new();
|
static mut USER_ID: OnceCell<String> = OnceCell::new();
|
||||||
|
|
||||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||||
pub struct Event {
|
pub struct Event {
|
||||||
pub event_name: String,
|
pub event_name: String,
|
||||||
pub user_id: String,
|
pub user_id: String,
|
||||||
pub device_id: String,
|
pub device_id: String,
|
||||||
pub event_time: u128,
|
pub event_time: u128,
|
||||||
pub session_id: String,
|
pub session_id: String,
|
||||||
pub menu_settings: String,
|
pub menu_settings: String,
|
||||||
pub mod_version: String,
|
pub mod_version: String,
|
||||||
pub smash_version: String,
|
pub smash_version: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[link_name = "\u{1}_ZN2nn2oe17GetPseudoDeviceIdEPNS_4util4UuidE"]
|
#[link_name = "\u{1}_ZN2nn2oe17GetPseudoDeviceIdEPNS_4util4UuidE"]
|
||||||
pub fn GetPseudoDeviceId(arg1: *mut Uuid);
|
pub fn GetPseudoDeviceId(arg1: *mut Uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Uuid {
|
pub struct Uuid {
|
||||||
size: u32,
|
size: u32,
|
||||||
string_size: u32,
|
string_size: u32,
|
||||||
data: [u8; 16],
|
data: [u8; 16],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Uuid {
|
impl Uuid {
|
||||||
pub fn to_str(&self) -> String {
|
pub fn to_str(&self) -> String {
|
||||||
self.data
|
self.data
|
||||||
.iter()
|
.iter()
|
||||||
.map(|i| format!("{:02x}", i))
|
.map(|i| format!("{:02x}", i))
|
||||||
.collect::<String>()
|
.collect::<String>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Sha256Hash {
|
struct Sha256Hash {
|
||||||
hash: [u8; 0x20],
|
hash: [u8; 0x20],
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[link_name = "\u{1}_ZN2nn6crypto18GenerateSha256HashEPvmPKvm"]
|
#[link_name = "\u{1}_ZN2nn6crypto18GenerateSha256HashEPvmPKvm"]
|
||||||
pub fn GenerateSha256Hash(
|
pub fn GenerateSha256Hash(arg1: *mut c_void, arg2: u64, arg3: *const c_void, arg4: u64);
|
||||||
arg1: *mut c_void,
|
}
|
||||||
arg2: u64,
|
|
||||||
arg3: *const c_void,
|
impl Event {
|
||||||
arg4: u64,
|
pub fn new() -> Event {
|
||||||
);
|
let mut device_uuid = Uuid {
|
||||||
}
|
size: 16,
|
||||||
|
string_size: 300,
|
||||||
impl Event {
|
data: [0u8; 16],
|
||||||
pub fn new() -> Event {
|
};
|
||||||
let mut device_uuid = Uuid {
|
unsafe {
|
||||||
size: 16,
|
GetPseudoDeviceId(&mut device_uuid as *mut Uuid);
|
||||||
string_size: 300,
|
}
|
||||||
data: [0u8; 16],
|
|
||||||
};
|
unsafe {
|
||||||
unsafe {
|
time::Initialize();
|
||||||
GetPseudoDeviceId(&mut device_uuid as *mut Uuid);
|
let event_time = SystemTime::now()
|
||||||
}
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.expect("Time went backwards")
|
||||||
unsafe {
|
.as_millis();
|
||||||
time::Initialize();
|
|
||||||
let event_time = SystemTime::now()
|
if SESSION_ID.get().is_none() {
|
||||||
.duration_since(UNIX_EPOCH)
|
account::Initialize();
|
||||||
.expect("Time went backwards")
|
let mut user_uid = account::Uid::new();
|
||||||
.as_millis();
|
account::GetLastOpenedUser(&mut user_uid);
|
||||||
|
|
||||||
if SESSION_ID.get().is_none() {
|
let mut user_id_hash = Sha256Hash { hash: [0; 0x20] };
|
||||||
account::Initialize();
|
GenerateSha256Hash(
|
||||||
let mut user_uid = account::Uid::new();
|
&mut user_id_hash as *mut _ as *mut c_void,
|
||||||
account::GetLastOpenedUser(&mut user_uid);
|
0x20 * 8,
|
||||||
|
user_uid.id.as_ptr() as *const c_void,
|
||||||
let mut user_id_hash = Sha256Hash { hash: [0; 0x20] };
|
16 * 8,
|
||||||
GenerateSha256Hash(
|
);
|
||||||
&mut user_id_hash as *mut _ as *mut c_void,
|
|
||||||
0x20 * 8,
|
USER_ID
|
||||||
user_uid.id.as_ptr() as *const c_void,
|
.set(
|
||||||
16 * 8,
|
user_uid
|
||||||
);
|
.id
|
||||||
|
.iter()
|
||||||
USER_ID
|
.map(|i| format!("{:02x}", i))
|
||||||
.set(
|
.collect::<Vec<String>>()
|
||||||
user_uid
|
.join(""),
|
||||||
.id
|
)
|
||||||
.iter()
|
.unwrap();
|
||||||
.map(|i| format!("{:02x}", i))
|
|
||||||
.collect::<Vec<String>>()
|
let mut device_id_hash = Sha256Hash { hash: [0; 0x20] };
|
||||||
.join(""),
|
GenerateSha256Hash(
|
||||||
)
|
&mut device_id_hash as *mut _ as *mut c_void,
|
||||||
.unwrap();
|
0x20 * 8,
|
||||||
|
device_uuid.data.as_ptr() as *const c_void,
|
||||||
let mut device_id_hash = Sha256Hash { hash: [0; 0x20] };
|
64 * 2,
|
||||||
GenerateSha256Hash(
|
);
|
||||||
&mut device_id_hash as *mut _ as *mut c_void,
|
DEVICE_ID
|
||||||
0x20 * 8,
|
.set(
|
||||||
device_uuid.data.as_ptr() as *const c_void,
|
device_uuid
|
||||||
64 * 2,
|
.data
|
||||||
);
|
.iter()
|
||||||
DEVICE_ID
|
.map(|i| format!("{:02x}", i))
|
||||||
.set(
|
.collect::<Vec<String>>()
|
||||||
device_uuid
|
.join(""),
|
||||||
.data
|
)
|
||||||
.iter()
|
.unwrap();
|
||||||
.map(|i| format!("{:02x}", i))
|
|
||||||
.collect::<Vec<String>>()
|
let mut session_id_hash = Sha256Hash { hash: [0; 0x20] };
|
||||||
.join(""),
|
// let mut device_id_0_bytes : [u8; 8] = Default::default();
|
||||||
)
|
// device_id_0_bytes.copy_from_slice(&device_uuid.data[0..8]);
|
||||||
.unwrap();
|
// let mut device_id_1_bytes : [u8; 8] = Default::default();
|
||||||
|
// device_id_1_bytes.copy_from_slice(&device_uuid.data[8..16]);
|
||||||
let mut session_id_hash = Sha256Hash { hash: [0; 0x20] };
|
let event_time_bytes: [u8; 16] = std::mem::transmute(event_time.to_be());
|
||||||
// let mut device_id_0_bytes : [u8; 8] = Default::default();
|
let session_id_bytes: [u8; 32] = [event_time_bytes, device_uuid.data]
|
||||||
// device_id_0_bytes.copy_from_slice(&device_uuid.data[0..8]);
|
.concat()
|
||||||
// let mut device_id_1_bytes : [u8; 8] = Default::default();
|
.try_into()
|
||||||
// device_id_1_bytes.copy_from_slice(&device_uuid.data[8..16]);
|
.unwrap();
|
||||||
let event_time_bytes: [u8; 16] = std::mem::transmute(event_time.to_be());
|
|
||||||
let session_id_bytes: [u8; 32] = [event_time_bytes, device_uuid.data]
|
GenerateSha256Hash(
|
||||||
.concat()
|
&mut session_id_hash as *mut _ as *mut c_void,
|
||||||
.try_into()
|
0x20 * 8,
|
||||||
.unwrap();
|
session_id_bytes.as_ptr() as *const c_void,
|
||||||
|
32 * 8,
|
||||||
GenerateSha256Hash(
|
);
|
||||||
&mut session_id_hash as *mut _ as *mut c_void,
|
SESSION_ID
|
||||||
0x20 * 8,
|
.set(
|
||||||
session_id_bytes.as_ptr() as *const c_void,
|
session_id_hash
|
||||||
32 * 8,
|
.hash
|
||||||
);
|
.iter()
|
||||||
SESSION_ID
|
.map(|i| format!("{:02x}", i))
|
||||||
.set(
|
.collect::<Vec<String>>()
|
||||||
session_id_hash
|
.join(""),
|
||||||
.hash
|
)
|
||||||
.iter()
|
.unwrap();
|
||||||
.map(|i| format!("{:02x}", i))
|
}
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join(""),
|
Event {
|
||||||
)
|
user_id: USER_ID.get().unwrap().to_string(),
|
||||||
.unwrap();
|
device_id: DEVICE_ID.get().unwrap().to_string(),
|
||||||
}
|
event_time,
|
||||||
|
session_id: SESSION_ID.get().unwrap().to_string(),
|
||||||
Event {
|
mod_version: CURRENT_VERSION.to_string(),
|
||||||
user_id: USER_ID.get().unwrap().to_string(),
|
smash_version: smash_version(),
|
||||||
device_id: DEVICE_ID.get().unwrap().to_string(),
|
..Default::default()
|
||||||
event_time,
|
}
|
||||||
session_id: SESSION_ID.get().unwrap().to_string(),
|
}
|
||||||
mod_version: CURRENT_VERSION.to_string(),
|
}
|
||||||
smash_version: smash_version(),
|
|
||||||
..Default::default()
|
pub fn smash_open() -> Event {
|
||||||
}
|
Event {
|
||||||
}
|
event_name: "SMASH_OPEN".to_string(),
|
||||||
}
|
..Event::new()
|
||||||
|
}
|
||||||
pub fn smash_open() -> Event {
|
}
|
||||||
Event {
|
|
||||||
event_name: "SMASH_OPEN".to_string(),
|
pub fn menu_open(menu_settings: String) -> Event {
|
||||||
..Event::new()
|
Event {
|
||||||
}
|
event_name: "MENU_OPEN".to_string(),
|
||||||
}
|
menu_settings,
|
||||||
|
..Event::new()
|
||||||
pub fn menu_open(menu_settings: String) -> Event {
|
}
|
||||||
Event {
|
}
|
||||||
event_name: "MENU_OPEN".to_string(),
|
}
|
||||||
menu_settings,
|
|
||||||
..Event::new()
|
fn smash_version() -> String {
|
||||||
}
|
let mut smash_version = oe::DisplayVersion { name: [0; 16] };
|
||||||
}
|
|
||||||
}
|
unsafe {
|
||||||
|
oe::GetDisplayVersion(&mut smash_version);
|
||||||
fn smash_version() -> String {
|
|
||||||
let mut smash_version = oe::DisplayVersion { name: [0; 16] };
|
std::ffi::CStr::from_ptr(smash_version.name.as_ptr() as *const i8)
|
||||||
|
.to_string_lossy()
|
||||||
unsafe {
|
.into_owned()
|
||||||
oe::GetDisplayVersion(&mut smash_version);
|
}
|
||||||
|
}
|
||||||
std::ffi::CStr::from_ptr(smash_version.name.as_ptr() as *const i8)
|
|
||||||
.to_string_lossy()
|
|
||||||
.into_owned()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue