Skip to content

Commit

Permalink
change lazy static dep
Browse files Browse the repository at this point in the history
  • Loading branch information
shevernitskiy committed Sep 25, 2023
1 parent 1d7f29c commit 31cf5b6
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 42 deletions.
111 changes: 105 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ winapi = { version = "^0.3.9", features = [
encoding_rs = "*"
encoding_rs_io = "*"
regex = "*"
toml = "0.7.6"
lazy_static = "1.4.0"
toml = "0.8.0"
exe = "0.5.6"
walkdir = "2.3.3"
backtrace = "0.3.69"
chrono = "0.4.26"
serde_derive = "1.0.164"
serde = "1.0.185"
static_init = "1.0.3"
13 changes: 8 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use std::error::Error;
use std::path::Path;

use crate::utils;
use exe::{VecPE, PE};
use static_init::dynamic;
use walkdir::WalkDir;

use crate::utils;

static EXE_FILE: &str = "./Dwarf Fortress.exe";
static CONFIG_FILE: &str = "./dfint_data/dfint_config.toml";
static OFFSETS_DIR: &str = "./dfint_data/offsets/";

lazy_static! {
pub static ref CONFIG: Config = Config::new().unwrap();
}
#[dynamic]
pub static CONFIG: Config = Config::new().unwrap();

// lazy_static! {
// pub static ref CONFIG: Config = Config::new().unwrap();
// }

pub struct Config {
pub metadata: ConfigMetadata,
Expand Down
6 changes: 3 additions & 3 deletions src/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use std::io::prelude::*;
use encoding_rs::WINDOWS_1251;
use encoding_rs_io::DecodeReaderBytesBuilder;
use regex::Regex;
use static_init::dynamic;

use crate::config::CONFIG;

lazy_static! {
pub static ref DICTIONARY: Dictionary = Dictionary::new(&CONFIG.settings.dictionary);
}
#[dynamic]
pub static DICTIONARY: Dictionary = Dictionary::new(&CONFIG.settings.dictionary);

pub struct Dictionary {
map: HashMap<String, Vec<u8>>,
Expand Down
33 changes: 10 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[macro_use(lazy_static)]
extern crate lazy_static;
#[macro_use]
extern crate serde_derive;
extern crate toml;
Expand All @@ -14,28 +12,17 @@ mod utils;

use log::LevelFilter;
use log::{error, info, trace};
use std::error::Error;
use winapi::shared::minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE};
use winapi::um::winnt::{DLL_PROCESS_ATTACH, DLL_PROCESS_DETACH};
use static_init::{constructor, destructor};

use crate::config::CONFIG;

#[constructor]
#[no_mangle]
pub unsafe extern "system" fn DllMain(
_module: HINSTANCE,
call_reason: DWORD,
_reserved: LPVOID,
) -> BOOL {
crash::install();
match call_reason {
DLL_PROCESS_ATTACH => attach().is_ok() as BOOL,
DLL_PROCESS_DETACH => detach().is_ok() as BOOL,
_ => TRUE,
extern "C" fn attach() {
unsafe {
crash::install();
}
}

fn attach() -> Result<(), Box<dyn Error>> {
simple_logging::log_to_file(&CONFIG.settings.log_file, LevelFilter::Trace)?;
simple_logging::log_to_file(&CONFIG.settings.log_file, LevelFilter::Trace).unwrap();
if CONFIG.metadata.name != "dfint localization hook" {
error!("unable to find config file");
unsafe {
Expand All @@ -51,13 +38,13 @@ fn attach() -> Result<(), Box<dyn Error>> {
info!("offsets version: {}", CONFIG.offset_metadata.version);
info!("hook version: {}", CONFIG.hook_version);
unsafe {
hooks::attach_all()?;
hooks::attach_all().unwrap();
}
trace!("hooks attached");
Ok(())
}

fn detach() -> Result<(), Box<dyn Error>> {
#[destructor]
#[no_mangle]
extern "C" fn detach() {
trace!("hooks detached");
Ok(())
}
6 changes: 3 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use static_init::dynamic;
use std::ptr;
use winapi::um::libloaderapi::GetModuleHandleW;
use winapi::um::winuser::MessageBoxW;

lazy_static! {
static ref MODULE: usize = unsafe { GetModuleHandleW(ptr::null()) as usize };
}
#[dynamic]
static MODULE: usize = unsafe { GetModuleHandleW(ptr::null()) as usize };

#[allow(dead_code)]
pub fn address(offset: usize) -> usize {
Expand Down

0 comments on commit 31cf5b6

Please sign in to comment.