Skip to content

Commit fa60953

Browse files
committed
Config fix, offset search, version bump
1 parent 96070f1 commit fa60953

4 files changed

Lines changed: 177 additions & 26 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "arcropolis"
3-
version = "0.9.4"
3+
version = "0.9.5"
44
authors = ["Raytwo <[email protected]>, jam1garner <[email protected]>"]
55
edition = "2018"
66

src/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
1414
const CONFIG_PATH: &str = "sd:/atmosphere/contents/01006A800016E000/romfs/arcropolis.toml";
1515

1616
lazy_static::lazy_static! {
17-
pub static ref CONFIG: Config = Config::open().unwrap();
17+
pub static ref CONFIG: Box<Config> = Config::open().unwrap();
1818
}
1919

2020
#[derive(Debug, Default, Serialize, Deserialize)]
@@ -109,22 +109,22 @@ impl Config {
109109
}
110110
}
111111

112-
pub fn open() -> Result<Config, String> {
112+
pub fn open() -> Result<Box<Config>, String> {
113113
match fs::read_to_string(CONFIG_PATH) {
114114
// File exists
115115
Ok(content) => {
116116
// Try deserializing
117117
let mut config = match toml::from_str(&content) {
118118
// Deserialized properly
119119
Ok(conf) => {
120-
conf
120+
Box::new(conf)
121121
},
122122
// Something happened when deserializing
123123
Err(_) => {
124124
println!("[ARC::Config] Configuration file could not be deserialized");
125125
show_error(69, "Configuration file could not be deserialized", &format!("Your configuration file ({}) is either poorly manually edited, outdated, corrupted or in a format unfit for ARCropolis.\n\nA new configuration file will now be generated, but it might ignore your modpacks. Consider double checking.", CONFIG_PATH));
126126
println!("[ARC::Config] Generating configuration file...");
127-
Config::new()
127+
Box::new(Config::new())
128128
}
129129
};
130130

@@ -152,7 +152,7 @@ impl Config {
152152
skyline_web::DialogOk::ok(format!("Thank you for installing ARCropolis!\n\nConfiguration file will now be generated"));
153153
println!("[ARC::Config] Configuration file not found. Generating a new one...");
154154

155-
let config = Config::new();
155+
let config = Box::new(Config::new());
156156
config.save().unwrap();
157157

158158
Ok(config)

src/offsets.rs

Lines changed: 170 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use skyline::hooks::{getRegionAddress, Region};
22

3-
// default 9.0.1 offsets
3+
// default 9.0.2 offsets
4+
pub static mut LOADED_TABLES_ADRP_OFFSET: usize = 0x35bb1f8;
5+
pub static mut RES_SERVICE_ADRP_OFFSET: usize = 0x335a860;
6+
47
pub static mut LOOKUP_STREAM_HASH_OFFSET: usize = 0x335A7F0;
58
pub static mut IDK_OFFSET: usize = 0x335F5F0;
69
pub static mut ADD_IDX_TO_TABLE1_AND_TABLE2_OFFSET: usize = 0x3359A40;
@@ -20,12 +23,127 @@ pub static mut PARSE_MODEL_XMB_2_OFFSET:usize = 0x34073E4;
2023
pub static mut TITLE_SCREEN_VERSION_OFFSET:usize = 0x35BAE00;
2124
pub static mut PARSE_NUS3BANK_FILE_OFFSET:usize = 0x3552D94;
2225

26+
static LOADED_TABLES_ADRP_SEARCH_CODE: &[u8] = &[
27+
0xf3, 0x03, 0x00, 0xaa, 0x1f, 0x01, 0x09, 0x6b, 0xe0, 0x04, 0x00, 0x54,
28+
];
29+
30+
static RES_SERVICE_ADRP_SEARCH_CODE: &[u8] = &[
31+
0x04, 0x01, 0x49, 0xfa, 0x21, 0x05, 0x00, 0x54, 0x5f, 0x00, 0x00, 0xf9, 0x7f, 0x00, 0x00, 0xf9,
32+
];
33+
34+
static IDK_SEARCH_CODE: &[u8] = &[
35+
0xf8, 0x5f, 0xbc, 0xa9, 0xf6, 0x57, 0x01, 0xa9, 0xf4, 0x4f, 0x02, 0xa9, 0xfd, 0x7b, 0x03, 0xa9,
36+
0xfd, 0xc3, 0x00, 0x91, 0xe8, 0x5f, 0x00, 0x32, 0x3f, 0x00, 0x08, 0x6b,
37+
];
38+
39+
static ADD_IDX_TO_TABLE1_AND_TABLE2_SEARCH_CODE: &[u8] = &[
40+
0xf6, 0x57, 0xbd, 0xa9, 0xf4, 0x4f, 0x01, 0xa9, 0xfd, 0x7b, 0x02, 0xa9, 0xfd, 0x83, 0x00, 0x91,
41+
0x08, 0x18, 0x40, 0xb9, 0x1f, 0x01, 0x01, 0x6b,
42+
];
43+
44+
static LOOKUP_STREAM_HASH_SEARCH_CODE: &[u8] = &[
45+
0x29, 0x58, 0x40, 0xf9, 0x28, 0x60, 0x40, 0xf9, 0x2a, 0x05, 0x40, 0xb9, 0x09, 0x0d, 0x0a, 0x8b,
46+
0xaa, 0x01, 0x00, 0x34, 0x5f, 0x01, 0x00, 0xf1,
47+
];
48+
49+
static PARSE_EFF_SEARCH_CODE: &[u8] = &[
50+
0x09, 0x19, 0x40, 0xb9, 0x3f, 0x01, 0x0a, 0x6b, 0xfb, 0x03, 0x16, 0xaa, 0xc9, 0x02, 0x00, 0x54,
51+
0x09, 0x05, 0x40, 0xf9, 0x2b, 0x0d, 0x0a, 0x8b,
52+
];
53+
54+
static PARSE_EFF_NUTEXB_SEARCH_CODE: &[u8] = &[
55+
0x1a, 0x01, 0x40, 0xf9, 0x02, 0x00, 0x00, 0x14, 0xfa, 0x03, 0x1f, 0xaa,
56+
];
57+
58+
static PARSE_PARAM_SEARCH_CODE: &[u8] = &[
59+
0x28, 0x01, 0x40, 0xf9, 0x28, 0x03, 0x00, 0xb4, 0x09, 0x41, 0x00, 0x91, 0x68, 0xa6, 0x01, 0xa9,
60+
0x0a, 0x09, 0x80, 0xb9, 0x29, 0x01, 0x0a, 0x8b, 0x69, 0x16, 0x00, 0xf9, 0x08, 0x0d, 0x80, 0xb9,
61+
];
62+
63+
static PARSE_MODEL_XMB_SEARCH_CODE: &[u8] = &[
64+
0x01, 0x01, 0x40, 0xf9, 0x03, 0x00, 0x00, 0x14, 0xf7, 0x17, 0x40, 0xf9, 0xe1, 0x03, 0x1f, 0xaa,
65+
0xe0, 0x22, 0x42, 0xf9, 0xcd, 0x07, 0x00, 0x94, 0xe8, 0x46, 0x42, 0xf9, 0x08, 0x01, 0x40, 0xf9,
66+
];
67+
68+
static PARSE_MODEL_XMB_2_SEARCH_CODE: &[u8] = &[
69+
0x01, 0x01, 0x40, 0xf9, 0xde, 0xff, 0xff, 0x17, 0x00, 0x00, 0x00, 0x00,
70+
];
71+
72+
static PARSE_LOG_XMB_SEARCH_CODE: &[u8] = &[
73+
0x13, 0x01, 0x40, 0xf9, 0x02, 0x00, 0x00, 0x14, 0xf3, 0x03, 0x1f, 0xaa, 0xe0, 0x03, 0x1c, 0x32,
74+
0xe1, 0x0b, 0x1d, 0x32,
75+
];
76+
77+
static PARSE_ARC_FILE_SEARCH_CODE: &[u8] = &[
78+
0x8a, 0x00, 0x00, 0xb4, 0x55, 0x01, 0x40, 0xf9, 0x02, 0x00, 0x00, 0x14, 0xf5, 0x03, 0x1f, 0xaa,
79+
];
80+
81+
static PARSE_FONT_FILE_SEARCH_CODE: &[u8] = &[
82+
0x01, 0x01, 0x40, 0xf9, 0xad, 0xff, 0xff, 0x17, 0x08, 0xc0, 0x41, 0x39, 0x48, 0x00, 0x00, 0x34,
83+
0xc0, 0x03, 0x5f, 0xd6, 0x00, 0x30, 0x40, 0xf9,
84+
];
85+
86+
static PARSE_NUMATB_NUTEXB_SEARCH_CODE: &[u8] = &[
87+
0x1b, 0x01, 0x40, 0xf9, 0x02, 0x00, 0x00, 0x14, 0xfb, 0x03, 0x1f, 0xaa,
88+
];
89+
90+
static PARSE_NUMSHEXB_FILE_SEARCH_CODE: &[u8] = &[
91+
0x49, 0x01, 0x00, 0x34, 0x28, 0x01, 0x00, 0xb4, 0x16, 0x01, 0x40, 0xf9, 0x07, 0x00, 0x00, 0x14,
92+
];
93+
94+
static PARSE_NUMATB_FILE_SEARCH_CODE: &[u8] = &[
95+
0xea, 0x7e, 0x40, 0x92, 0x4a, 0xf1, 0x7d, 0xd3, 0x29, 0x69, 0x6a, 0xb8, 0xea, 0x5f, 0x00, 0x32,
96+
];
97+
98+
static PARSE_NUMSHB_FILE_SEARCH_CODE: &[u8] = &[
99+
0x0a, 0x7f, 0x40, 0x92, 0x4a, 0xf1, 0x7d, 0xd3, 0x29, 0x69, 0x6a, 0xb8, 0xea, 0x5f, 0x00, 0x32, 0x3f, 0x01, 0x0a, 0x6b, 0xa0, 0x01, 0x00, 0x54
100+
];
101+
102+
static PARSE_NUMDLB_FILE_SEARCH_CODE: &[u8] = &[
103+
0x08, 0x01, 0x40, 0xf9, 0xfb, 0xfe, 0xff, 0x17, 0xf3, 0x0f, 0x1e, 0xf8, 0xfd, 0x7b, 0x01, 0xa9,
104+
0xfd, 0x43, 0x00, 0x91, 0xf3, 0x03, 0x00, 0xaa,
105+
];
106+
107+
static TITLE_SCREEN_VERSION_SEARCH_CODE: &[u8] = &[
108+
0xfc, 0x0f, 0x1d, 0xf8, 0xf4, 0x4f, 0x01, 0xa9, 0xfd, 0x7b, 0x02, 0xa9, 0xfd, 0x83, 0x00, 0x91,
109+
0xff, 0x07, 0x40, 0xd1, 0xf4, 0x03, 0x01, 0xaa, 0xf3, 0x03, 0x00, 0xaa,
110+
];
111+
112+
static PARSE_NUS3BANK_FILE_SEARCH_CODE: &[u8] = &[
113+
0xf6, 0x01, 0x40, 0xf9, 0xf6, 0x10, 0x00, 0xb4, 0x8f, 0x6a, 0x7a, 0xb8, 0xf0, 0x5f, 0x00, 0x32,
114+
0xff, 0x01, 0x10, 0x6b, 0x60, 0x10, 0x00, 0x54,
115+
];
116+
23117
fn find_subsequence(haystack: &[u8], needle: &[u8]) -> Option<usize> {
24118
haystack
25119
.windows(needle.len())
26120
.position(|window| window == needle)
27121
}
28122

123+
fn offset_from_adrp(adrp_offset: usize) -> usize {
124+
unsafe {
125+
let adrp = *(offset_to_addr(adrp_offset) as *const u32);
126+
let immhi = (adrp & 0b0_00_00000_1111111111111111111_00000) >> 3;
127+
let immlo = (adrp & 0b0_11_00000_0000000000000000000_00000) >> 29;
128+
let imm = ((immhi | immlo) << 12) as i32 as usize;
129+
let base = adrp_offset & 0xFFFFFFFFFFFFF000;
130+
base + imm
131+
}
132+
}
133+
134+
fn offset_from_ldr(ldr_offset: usize) -> usize {
135+
unsafe {
136+
let ldr = *(offset_to_addr(ldr_offset) as *const u32);
137+
let size = (ldr & 0b11_000_0_00_00_000000000000_00000_00000) >> 30;
138+
let imm = (ldr & 0b00_000_0_00_00_111111111111_00000_00000) >> 10;
139+
(imm as usize) << size
140+
}
141+
}
142+
143+
pub fn offset_to_addr(offset: usize) -> *const () {
144+
unsafe { (getRegionAddress(Region::Text) as *const u8).offset(offset as isize) as _ }
145+
}
146+
29147
macro_rules! find_offsets {
30148
(
31149
$(
@@ -42,7 +160,7 @@ macro_rules! find_offsets {
42160
if let Some(offset) = find_subsequence(text, $search_pattern) {
43161
$out_variable = offset
44162
} else {
45-
println!("Error: no offset found for '{}'. Defaulting to 8.1.0 offset. This most likely won't work.", stringify!($out_variable));
163+
println!("Error: no offset found for '{}'. Defaulting to 9.0.2 offset. This most likely won't work.", stringify!($out_variable));
46164
}
47165
}
48166
)*
@@ -53,25 +171,58 @@ pub fn search_offsets() {
53171
unsafe {
54172
smash::resource::LOADED_TABLES_OFFSET = 0x50567a0;
55173
smash::resource::RES_SERVICE_OFFSET = 0x50567a8;
56-
}
174+
175+
let text_ptr = getRegionAddress(Region::Text) as *const u8;
176+
let text_size = (getRegionAddress(Region::Rodata) as usize) - (text_ptr as usize);
177+
178+
let text = std::slice::from_raw_parts(text_ptr, text_size);
179+
180+
if let Some(offset) = find_subsequence(text, LOADED_TABLES_ADRP_SEARCH_CODE) {
181+
LOADED_TABLES_ADRP_OFFSET = offset + 12;
182+
183+
let adrp_offset = offset_from_adrp(LOADED_TABLES_ADRP_OFFSET);
184+
let ldr_offset = offset_from_ldr(LOADED_TABLES_ADRP_OFFSET + 4);
185+
smash::resource::LOADED_TABLES_OFFSET = adrp_offset + ldr_offset;
186+
} else {
187+
println!("Error: no offset found for 'loaded_tables_adrp'. Defaulting to 9.0.2 offset. This likely won't work.");
188+
}
189+
190+
if let Some(offset) = find_subsequence(text, RES_SERVICE_ADRP_SEARCH_CODE) {
191+
RES_SERVICE_ADRP_OFFSET = offset + 16;
192+
193+
let adrp_offset = offset_from_adrp(RES_SERVICE_ADRP_OFFSET);
194+
let ldr_offset = offset_from_ldr(RES_SERVICE_ADRP_OFFSET + 4);
195+
smash::resource::RES_SERVICE_OFFSET = adrp_offset + ldr_offset;
196+
} else {
197+
println!("Error: no offset found for 'res_service_adrp'. Defaulting to 9.0.2 offset. This likely won't work.");
198+
}
199+
57200
find_offsets!(
58-
//(IDK_OFFSET, IDK_SEARCH_CODE),
59-
//(ADD_IDX_TO_TABLE1_AND_TABLE2_OFFSET, ADD_IDX_TO_TABLE1_AND_TABLE2_SEARCH_CODE),
60-
//(LOOKUP_STREAM_HASH_OFFSET, LOOKUP_STREAM_HASH_SEARCH_CODE),
61-
// (PARSE_EFF_NUTEXB_OFFSET, PARSE_EFF_NUTEXB_SEARCH_CODE),
62-
// (PARSE_EFF_OFFSET, PARSE_EFF_SEARCH_CODE),
63-
// (PARSE_PARAM_OFFSET, PARSE_PARAM_SEARCH_CODE),
64-
// (PARSE_MODEL_XMB_OFFSET, PARSE_MODEL_XMB_SEARCH_CODE),
65-
// (PARSE_ARC_FILE_OFFSET, PARSE_ARC_FILE_SEARCH_CODE),
66-
// (PARSE_FONT_FILE_OFFSET, PARSE_FONT_FILE_SEARCH_CODE),
67-
// (PARSE_NUMATB_NUTEXB_OFFSET, PARSE_NUMATB_NUTEXB_SEARCH_CODE),
68-
// (PARSE_NUMSHEXB_FILE_OFFSET, PARSE_NUMSHEXB_FILE_SEARCH_CODE),
69-
// (PARSE_NUMATB_FILE_OFFSET, PARSE_NUMATB_FILE_SEARCH_CODE),
70-
// (PARSE_NUMDLB_FILE_OFFSET, PARSE_NUMDLB_FILE_SEARCH_CODE),
71-
// (PARSE_LOG_XMB_OFFSET, PARSE_LOG_XMB_SEARCH_CODE),
72-
// (PARSE_MODEL_XMB_2_OFFSET, PARSE_MODEL_XMB_2_SEARCH_CODE),
73-
//(TITLE_SCREEN_VERSION_OFFSET, TITLE_SCREEN_VERSION_SEARCH_CODE),
201+
(IDK_OFFSET, IDK_SEARCH_CODE),
202+
(ADD_IDX_TO_TABLE1_AND_TABLE2_OFFSET, ADD_IDX_TO_TABLE1_AND_TABLE2_SEARCH_CODE),
203+
(LOOKUP_STREAM_HASH_OFFSET, LOOKUP_STREAM_HASH_SEARCH_CODE),
204+
(PARSE_EFF_OFFSET, PARSE_EFF_SEARCH_CODE),
205+
(PARSE_EFF_NUTEXB_OFFSET, PARSE_EFF_NUTEXB_SEARCH_CODE),
206+
(PARSE_PARAM_OFFSET, PARSE_PARAM_SEARCH_CODE),
207+
(PARSE_MODEL_XMB_OFFSET, PARSE_MODEL_XMB_SEARCH_CODE),
208+
(PARSE_ARC_FILE_OFFSET, PARSE_ARC_FILE_SEARCH_CODE),
209+
(PARSE_FONT_FILE_OFFSET, PARSE_FONT_FILE_SEARCH_CODE),
210+
(PARSE_NUMATB_NUTEXB_OFFSET, PARSE_NUMATB_NUTEXB_SEARCH_CODE),
211+
(PARSE_NUMSHEXB_FILE_OFFSET, PARSE_NUMSHEXB_FILE_SEARCH_CODE),
212+
(PARSE_NUMATB_FILE_OFFSET, PARSE_NUMATB_FILE_SEARCH_CODE),
213+
(PARSE_NUMSHB_FILE_OFFSET, PARSE_NUMSHB_FILE_SEARCH_CODE),
214+
(PARSE_NUMDLB_FILE_OFFSET, PARSE_NUMDLB_FILE_SEARCH_CODE),
215+
(PARSE_LOG_XMB_OFFSET, PARSE_LOG_XMB_SEARCH_CODE),
216+
(PARSE_MODEL_XMB_2_OFFSET, PARSE_MODEL_XMB_2_SEARCH_CODE),
217+
(TITLE_SCREEN_VERSION_OFFSET, TITLE_SCREEN_VERSION_SEARCH_CODE),
218+
(PARSE_NUS3BANK_FILE_OFFSET, PARSE_NUS3BANK_FILE_SEARCH_CODE),
74219
);
220+
221+
PARSE_ARC_FILE_OFFSET += 4;
222+
PARSE_NUMSHEXB_FILE_OFFSET += 8;
223+
PARSE_NUMATB_FILE_OFFSET += 64;
224+
PARSE_NUMSHB_FILE_OFFSET += 64;
225+
}
75226
}
76227

77228
// #[allow(dead_code)]

src/replacement_files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl FileCtx {
293293
pub fn get_subfile(&self, t1_index: u32) -> &mut SubFile {
294294
let loaded_arc = LoadedTables::get_instance().get_arc();
295295

296-
let mut file_info = loaded_arc.lookup_file_information_by_t1_index(t1_index);
296+
let file_info = loaded_arc.lookup_file_information_by_t1_index(t1_index);
297297
//let file_index = loaded_arc.lookup_fileinfoindex_by_t1_index(t1_index);
298298

299299
// TODO: Make a constant for Redirect

0 commit comments

Comments
 (0)