Skip to content

Commit

Permalink
Remove obsolete gas fix patch
Browse files Browse the repository at this point in the history
Implemented in DRG build 104409. Fixes #252
  • Loading branch information
trumank committed Nov 11, 2024
1 parent 8f39d26 commit b26d221
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 94 deletions.
48 changes: 1 addition & 47 deletions hook/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ use std::{
ffi::c_void,
path::{Path, PathBuf},
ptr::NonNull,
sync::{Arc, OnceLock},
sync::OnceLock,
};

use anyhow::{Context, Result};
use fs_err as fs;
use hook_resolvers::GasFixResolution;
use mint_lib::DRGInstallationType;
use windows::Win32::System::Memory::{VirtualProtect, PAGE_EXECUTE_READWRITE};

Expand Down Expand Up @@ -88,12 +87,6 @@ pub unsafe fn initialize() -> Result<()> {

server_list::init_hooks()?;

if !globals().meta.config.disable_fix_exploding_gas {
if let Ok(gas_fix) = &globals().resolution.gas_fix {
apply_gas_fix(gas_fix)?;
}
}

let installation_type = DRGInstallationType::from_exe_path()?;

match installation_type {
Expand Down Expand Up @@ -143,45 +136,6 @@ pub unsafe fn initialize() -> Result<()> {
Ok(())
}

unsafe fn apply_gas_fix(gas_fix: &Arc<GasFixResolution>) -> Result<()> {
#[repr(C)]
struct UObjectTemperatureComponent {
padding: [u8; 0xd8],
on_start_burning: [u64; 2],
on_frozen_server: [u64; 2],
temperature_change_scale: f32,
burn_temperature: f32,
freeze_temperature: f32,
douse_fire_temperature: f32,
cooling_rate: f32,
is_heatsource_when_on_fire: bool,
on_fire_heat_range: f32,
timer_handle: u64,
is_object_on_fire: bool,
current_temperature: f32,
}

let fn_process_multicast_delegate: unsafe extern "system" fn(*mut c_void, *mut c_void) =
std::mem::transmute(gas_fix.process_multicast_delegate.0);

UObjectTemperatureComponentTimerCallback.initialize(
std::mem::transmute(gas_fix.timer_callback.0),
move |this| {
let obj = &*(this as *const UObjectTemperatureComponent);
let on_fire = obj.is_object_on_fire;
UObjectTemperatureComponentTimerCallback.call(this);
if !on_fire && obj.is_object_on_fire {
fn_process_multicast_delegate(
std::ptr::addr_of!(obj.on_start_burning) as *mut c_void,
std::ptr::null_mut(),
);
}
},
)?;
UObjectTemperatureComponentTimerCallback.enable()?;
Ok(())
}

unsafe fn patch_mem(address: *mut u8, patch: impl AsRef<[u8]>) -> Result<()> {
let patch = patch.as_ref();
let patch_mem = std::slice::from_raw_parts_mut(address, patch.len());
Expand Down
33 changes: 0 additions & 33 deletions hook_resolvers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,6 @@ impl_resolver_singleton!(PEImage, Disable, |ctx| async {
Ok(Self(ensure_one(res.into_iter().flatten())?))
});

#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde-resolvers", derive(Serialize, Deserialize))]
pub struct UObjectTemperatureComponentTimerCallback(pub usize);
impl_resolver_singleton!(collect, UObjectTemperatureComponentTimerCallback);
impl_resolver_singleton!(
PEImage,
UObjectTemperatureComponentTimerCallback,
|ctx| async {
let patterns = ["40 55 57 41 56 48 8D 6C 24 ?? 48 81 EC 20 01 00 00"];
let res = join_all(patterns.iter().map(|p| ctx.scan(Pattern::new(p).unwrap()))).await;
Ok(Self(ensure_one(res.into_iter().flatten())?))
}
);
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde-resolvers", derive(Serialize, Deserialize))]
pub struct ProcessMulticastDelegate(pub usize);
impl_resolver_singleton!(collect, ProcessMulticastDelegate);
impl_resolver_singleton!(PEImage, ProcessMulticastDelegate, |ctx| async {
let patterns = ["4C 8B DC 57 41 54 41 56 48 81 EC A0 00 00 00"];
let res = join_all(patterns.iter().map(|p| ctx.scan(Pattern::new(p).unwrap()))).await;
Ok(Self(ensure_one(res.into_iter().flatten())?))
});

impl_try_collector! {
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde-resolvers", derive(Serialize, Deserialize))]
Expand Down Expand Up @@ -159,15 +136,6 @@ impl_try_collector! {
}
}

impl_try_collector! {
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde-resolvers", derive(Serialize, Deserialize))]
pub struct GasFixResolution {
pub timer_callback: UObjectTemperatureComponentTimerCallback,
pub process_multicast_delegate: ProcessMulticastDelegate,
}
}

impl_try_collector! {
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde-resolvers", derive(Serialize, Deserialize))]
Expand All @@ -191,7 +159,6 @@ impl_collector! {
pub server_name: ServerNameResolution,
pub server_mods: ServerModsResolution,
pub save_game: SaveGameResolution,
pub gas_fix: GasFixResolution,
pub core: CoreResolution,
}
}
4 changes: 1 addition & 3 deletions mint_lib/src/mod_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ pub struct Meta {
pub config: MetaConfig,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MetaConfig {
pub disable_fix_exploding_gas: bool,
}
pub struct MetaConfig {}
#[derive(Debug, Serialize, Deserialize)]
pub struct SemverVersion {
pub major: u32,
Expand Down
13 changes: 2 additions & 11 deletions src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,13 @@ impl ModData!["0.1.0"] {
}
}

fn is_false(value: &bool) -> bool {
!value
}

#[obake::versioned]
#[obake(version("0.0.0"))]
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
pub provider_parameters: HashMap<String, HashMap<String, String>>,
pub drg_pak_path: Option<PathBuf>,
pub gui_theme: Option<GuiTheme>,
#[serde(default, skip_serializing_if = "is_false")]
pub disable_fix_exploding_gas: bool,
pub sorting_config: Option<SortingConfig>,
}

Expand Down Expand Up @@ -418,17 +412,14 @@ impl Default for Config!["0.0.0"] {
.as_ref()
.map(DRGInstallation::main_pak),
gui_theme: None,
disable_fix_exploding_gas: false,
sorting_config: None,
}
}
}

impl From<&VersionAnnotatedConfig> for MetaConfig {
fn from(value: &VersionAnnotatedConfig) -> Self {
MetaConfig {
disable_fix_exploding_gas: value.disable_fix_exploding_gas,
}
fn from(_value: &VersionAnnotatedConfig) -> Self {
MetaConfig {}
}
}

Expand Down

0 comments on commit b26d221

Please sign in to comment.