use pelite::pe64::PeView;
use std::sync::LazyLock;
use windows::Win32::System::LibraryLoader::GetModuleHandleA;
use windows::core::PCSTR;
mod bundle;
mod rva_jp;
mod rva_ww;
pub use bundle::RvaBundle;
use fromsoftware_shared::game_version::{GameVersion, LANG_ID_EN, LANG_ID_JP};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum ERGameVersion {
Ww262,
Jp2621,
}
impl GameVersion for ERGameVersion {
const NAME: &'static str = "elden ring";
fn from_lang_version(lang_id: u16, version: &str) -> Option<Self> {
match (lang_id, version) {
(LANG_ID_EN, "2.6.2.0") => Some(Self::Ww262),
(LANG_ID_JP, "2.6.2.1") => Some(Self::Jp2621),
_ => None,
}
}
}
impl ERGameVersion {
const fn rvas(self) -> RvaBundle {
match self {
Self::Ww262 => rva_ww::RVAS,
Self::Jp2621 => rva_jp::RVAS,
}
}
}
pub fn get() -> &'static RvaBundle {
static RVAS: LazyLock<RvaBundle> = LazyLock::new(|| {
let module = unsafe {
PeView::module(GetModuleHandleA(PCSTR(std::ptr::null())).unwrap().0 as *const u8)
};
ERGameVersion::detect(&module)
.unwrap_or_else(|e| panic!("{e}"))
.rvas()
});
&RVAS
}