mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2025-03-14 02:16:10 +00:00
Move nn to nnsdk, Begin documenting skyline-rs
This commit is contained in:
parent
ba437edf35
commit
36d7d33443
10 changed files with 78 additions and 42 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -7,7 +7,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "nn"
|
||||
name = "nnsdk"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"skyline_libc",
|
||||
|
@ -42,7 +42,7 @@ dependencies = [
|
|||
name = "skyline"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"nn",
|
||||
"nnsdk",
|
||||
"skyline_libc",
|
||||
"skyline_macro",
|
||||
]
|
||||
|
|
4
skyline/Cargo.lock
generated
4
skyline/Cargo.lock
generated
|
@ -6,7 +6,7 @@ version = "1.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "nn"
|
||||
name = "nnsdk"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"skyline_libc 0.1.0",
|
||||
|
@ -32,7 +32,7 @@ dependencies = [
|
|||
name = "skyline"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"nn 0.1.0",
|
||||
"nnsdk 0.1.0",
|
||||
"skyline_libc 0.1.0",
|
||||
"skyline_macro 0.1.0",
|
||||
]
|
||||
|
|
|
@ -8,5 +8,5 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
skyline_macro = { path = "./skyline_macro" }
|
||||
nn = { path = "./nn" }
|
||||
nnsdk = { path = "./nnsdk" }
|
||||
skyline_libc = { path = "./skyline_libc" }
|
||||
|
|
0
skyline/nn/Cargo.lock → skyline/nnsdk/Cargo.lock
generated
0
skyline/nn/Cargo.lock → skyline/nnsdk/Cargo.lock
generated
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "nn"
|
||||
name = "nnsdk"
|
||||
version = "0.1.0"
|
||||
authors = ["jam1garner <jam1.mcleod@hotmail.com>"]
|
||||
edition = "2018"
|
|
@ -7,7 +7,7 @@ extern fn eh_personality() {
|
|||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
|
||||
crate::log("Panic at the Rust lib!\n");
|
||||
crate::logging::log("Panic at the Rust lib!\n");
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
@ -41,4 +41,11 @@ impl<const LEN: usize> ModuleName<LEN> {
|
|||
#[link_section = ".rodata.module_name"]
|
||||
pub static MODULE_NAME: impl Any = ModuleName::new(b"no_std_test\0");
|
||||
|
||||
|
||||
/// one-time setup for skyline
|
||||
#[doc(hidden)]
|
||||
#[macro_export] macro_rules! setup {
|
||||
() => {
|
||||
#[global_allocator]
|
||||
pub static ALLOCATOR: $crate::extern_alloc::Allocator = $crate::extern_alloc::Allocator;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,15 +1,28 @@
|
|||
use crate::alloc::string::String;
|
||||
|
||||
pub struct HookInfo {
|
||||
/// Name of the function being used as the override
|
||||
pub fn_name: &'static str,
|
||||
|
||||
/// User-given name of what the hook represents
|
||||
pub name: Option<String>,
|
||||
|
||||
/// Offset of where to install the hook
|
||||
pub offset: Option<u64>,
|
||||
|
||||
/// Symbol of where to install the hook
|
||||
pub symbol: Option<String>,
|
||||
|
||||
/// Whether or not this is an inline hook
|
||||
pub inline: bool
|
||||
}
|
||||
|
||||
/// Type for representing a hook for this plugin
|
||||
pub struct Hook {
|
||||
/// Pointer to the overloading function
|
||||
pub ptr: *const (),
|
||||
|
||||
/// Info needed to identify and install this hook
|
||||
pub info: &'static HookInfo,
|
||||
}
|
||||
|
||||
|
@ -29,6 +42,7 @@ extern "C" {
|
|||
static __hook_array_end: Hook;
|
||||
}
|
||||
|
||||
/// Iterate over the loaded hooks for this plugin
|
||||
pub fn iter_hooks() -> impl Iterator<Item = &'static Hook> {
|
||||
let hook_start = unsafe {&__hook_array_start as *const Hook};
|
||||
let hook_end = unsafe {&__hook_array_end as *const Hook};
|
||||
|
|
|
@ -2,54 +2,45 @@
|
|||
#![allow(incomplete_features)]
|
||||
#![feature(alloc_error_handler, lang_items, start, global_asm, const_generics, impl_trait_in_bindings, proc_macro_hygiene, alloc_prelude)]
|
||||
|
||||
/// The rust core allocation and collections library
|
||||
pub extern crate alloc;
|
||||
|
||||
/// Types and functions for working with hooking
|
||||
pub mod hooks;
|
||||
pub mod build;
|
||||
pub mod logging;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod extern_alloc;
|
||||
pub use extern_alloc::Allocator;
|
||||
pub use skyline_macro::{main, hook};
|
||||
pub use hooks::iter_hooks;
|
||||
|
||||
pub use skyline_libc as libc;
|
||||
#[doc(hidden)]
|
||||
pub mod build;
|
||||
|
||||
extern "C" {
|
||||
fn skyline_tcp_send_raw(bytes: *const u8, usize: u64);
|
||||
// nnsdk API bindings
|
||||
pub mod nn {
|
||||
pub use nnsdk::root::nn::*;
|
||||
}
|
||||
|
||||
pub fn log(message: &str) {
|
||||
unsafe {
|
||||
skyline_tcp_send_raw(message.as_bytes().as_ptr(), message.as_bytes().len() as _);
|
||||
}
|
||||
}
|
||||
#[doc(inline)]
|
||||
pub use {
|
||||
skyline_libc as libc,
|
||||
skyline_macro::{main, hook},
|
||||
hooks::iter_hooks,
|
||||
};
|
||||
|
||||
/// Helper to convert a str to a *const u8 (to be replaced)
|
||||
pub fn c_str(string: &str) -> *const u8 {
|
||||
string.as_bytes().as_ptr()
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! setup {
|
||||
() => {
|
||||
#[global_allocator]
|
||||
pub static ALLOCATOR: $crate::Allocator = $crate::Allocator;
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! println {
|
||||
() => {
|
||||
$crate::log();
|
||||
};
|
||||
($($arg:tt)*) => {
|
||||
{
|
||||
use $crate::alloc::format;
|
||||
$crate::log(&format!(
|
||||
$($arg)*
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// A set of items that will likely be useful to import anyway
|
||||
///
|
||||
/// Designed to be used as such:
|
||||
/// ```
|
||||
/// use skyline::prelude::*;
|
||||
/// ```
|
||||
pub mod prelude {
|
||||
pub use crate::Allocator;
|
||||
pub use crate::println;
|
||||
pub use alloc::format;
|
||||
pub use alloc::vec;
|
||||
pub use crate::alloc::prelude::v1::*;
|
||||
}
|
||||
|
|
24
skyline/src/logging.rs
Normal file
24
skyline/src/logging.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
extern "C" {
|
||||
fn skyline_tcp_send_raw(bytes: *const u8, usize: u64);
|
||||
}
|
||||
|
||||
pub fn log(message: &str) {
|
||||
unsafe {
|
||||
skyline_tcp_send_raw(message.as_bytes().as_ptr(), message.as_bytes().len() as _);
|
||||
}
|
||||
}
|
||||
|
||||
/// Prints to the standard output, with a newline.
|
||||
#[macro_export] macro_rules! println {
|
||||
() => {
|
||||
$crate::log();
|
||||
};
|
||||
($($arg:tt)*) => {
|
||||
{
|
||||
use $crate::alloc::format;
|
||||
$crate::logging::log(&format!(
|
||||
$($arg)*
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Add table
Reference in a new issue