Last active
January 3, 2020 02:44
-
-
Save benhall-7/7514e9c21cd929fea3d40b81e3e8b5cf to your computer and use it in GitHub Desktop.
SSBU const_value_table file generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// has to be run in --release mode or else the lua_bind_hash method fails (due to integer overflows panicking) | |
pub mod lua_bind_hash; // https://github.com/ultimate-research/lua-bind-hash/blob/master/lua_bind_hash.rs | |
use lua_bind_hash as lhash; | |
use std::fs::File; | |
use std::io::{BufReader, BufRead, BufWriter, Write}; | |
use std::collections::BTreeMap; | |
use inflections::case::is_constant_case; | |
fn main() { | |
let mut pairs: BTreeMap<u64, String> = BTreeMap::new(); | |
let mut ordered: Vec<u64> = Vec::new(); | |
let f_hash = File::open("Path/To/Hash/File").unwrap(); | |
let f_str = File::open("Path/To/String/File").unwrap(); | |
let mut reader = BufReader::new(f_hash); | |
for l in reader.lines() { | |
let without_radix = &l.unwrap()[2..]; | |
pairs.insert(u64::from_str_radix(without_radix, 16).unwrap(), String::from("")); | |
ordered.push(u64::from_str_radix(without_radix, 16).unwrap()); | |
} | |
reader = BufReader::new(f_str); | |
for l in reader.lines() { | |
match l { | |
Ok(o) => { | |
//This is only called "trimmed" because I didn't update its name /shrug | |
let trimmed = o; | |
let const_case = is_constant_case(&trimmed); | |
let bytes = trimmed.as_bytes(); | |
let hash = lhash::lua_bind_hash(bytes); | |
if pairs.contains_key(&hash) { | |
if !const_case { | |
println!("{}", &trimmed); | |
} | |
pairs.insert(hash, trimmed); | |
} | |
} | |
Err(_) => continue | |
} | |
} | |
let f = File::create("const_value_tableVERSION.txt").unwrap(); | |
let mut writer = BufWriter::new(f); | |
let mut total: f32 = 0.0; | |
let mut labeled: f32 = 0.0; | |
for h in ordered.iter_mut() { | |
total += 1.0; | |
match pairs.get(&h) { | |
Some(word) => { | |
if !word.is_empty() { | |
labeled += 1.0; | |
} | |
write!(writer, "{},{}\n", format!("0x{:016x}", h), word).unwrap(); | |
} | |
None => continue | |
} | |
} | |
println!("{} labeled out of {}", labeled as u64, total as u64); | |
println!("{:.4}", labeled / total * 100.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment