Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Add rustfmt.toml & cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
PieKing1215 committed Aug 19, 2024
1 parent 7dd39f3 commit d34b23a
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 103 deletions.
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
match_block_trailing_comma = true
struct_lit_width = 50
use_field_init_shorthand = true
2 changes: 1 addition & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
// this only exists so I can use option_env!("OUT_DIR") elsewhere
}
}
19 changes: 11 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ use windows::Win32::System::SystemServices::DLL_PROCESS_ATTACH;

#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "stdcall" fn DllMain(
hmodule: HINSTANCE,
reason: u32,
_: *mut std::ffi::c_void,
) {
pub unsafe extern "stdcall" fn DllMain(hmodule: HINSTANCE, reason: u32, _: *mut std::ffi::c_void) {
if reason == DLL_PROCESS_ATTACH {
trace!("DllMain()");
std::thread::spawn(move || {
Expand Down Expand Up @@ -59,7 +55,11 @@ struct MainHud {
impl MainHud {
fn new() -> Self {
let mut this = Self {
version_string: format!("swQolSuite v{}{}", env!("CARGO_PKG_VERSION"), option_env!("SHA").map_or_else(|| "".to_string(), |sha| format!(" ({sha})"))),
version_string: format!(
"swQolSuite v{}{}",
env!("CARGO_PKG_VERSION"),
option_env!("SHA").map_or_else(|| "".to_string(), |sha| format!(" ({sha})"))
),
show: true,
tweaks: vec![],
errors: vec![],
Expand All @@ -79,7 +79,7 @@ impl MainHud {
this
}

fn add_tweak<T: Tweak + Send + Sync + 'static>(&mut self, tw: anyhow::Result<T>){
fn add_tweak<T: Tweak + Send + Sync + 'static>(&mut self, tw: anyhow::Result<T>) {
match tw {
Ok(tw) => self.tweaks.push(Box::new(tw)),
Err(e) => self.errors.push(e),
Expand Down Expand Up @@ -128,7 +128,10 @@ impl ImguiRenderLoop for MainHud {
.position_pivot([1., 1.])
.position(ui.io().display_size, Condition::Always)
.build(|| {
let text_color = ui.push_style_color(StyleColor::Text, [0.8, 0.8, 0.8, if self.show { 0.9 } else { 0.4 }]);
let text_color = ui.push_style_color(
StyleColor::Text,
[0.8, 0.8, 0.8, if self.show { 0.9 } else { 0.4 }],
);
if self.show {
ui.text(format!("{} [~]", self.version_string));
} else {
Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ fn main() {
let dll_path = cur_exe.canonicalize().unwrap();

println!("Injecting DLL @ {dll_path:?}");
Process::by_name("stormworks64.exe").expect("Failed to find stormworks64.exe")
.inject(dll_path).expect("Failed to inject DLL");
}
Process::by_name("stormworks64.exe")
.expect("Failed to find stormworks64.exe")
.inject(dll_path)
.expect("Failed to inject DLL");
}
49 changes: 34 additions & 15 deletions src/tweaks/editor_camera_speed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ use std::{arch::asm, sync::atomic::Ordering};
use anyhow::Context;
use atomic_float::AtomicF32;
use hudhook::imgui::TreeNodeFlags;
use memory_rs::{generate_aob_pattern, internal::{injections::{Inject, Injection}, memory_region::MemoryRegion}};
use memory_rs::{
generate_aob_pattern,
internal::{
injections::{Inject, Injection},
memory_region::MemoryRegion,
},
};

use super::{MemoryRegionExt, Tweak};

Expand All @@ -21,7 +27,8 @@ const DEFAULT_WHEEL_MULTIPLIER: f32 = 1.1;

static SPEED: AtomicF32 = AtomicF32::new(1.0);

#[no_mangle] static mut jmp_back_addr: usize = 0x0;
#[no_mangle]
static mut jmp_back_addr: usize = 0x0;

pub struct EditorCameraSpeedTweak {
base_speed: f32,
Expand All @@ -38,14 +45,18 @@ impl EditorCameraSpeedTweak {
pub fn new(region: &MemoryRegion) -> anyhow::Result<Self> {
// `xmm5 = param_1->shift_down ? 0.2 : 1.0`
let memory_pattern = generate_aob_pattern![
0x80, 0xb9, 0x1a, 0x0e, 0x00, 0x00, 0x00, // CMP byte ptr [RCX + param_1->shift_down],0x0
0x74, 0x0a, // JZ +0xA
0xf3, 0x0f, 0x10, 0x2d, _, _, _, _, // MOVSS XMM5,dword ptr [FLOAT_XXX] = 0.2
0xeb, 0x08, // JMP +0x8
0xf3, 0x0f, 0x10, 0x2d, _, _, _, _ // MOVSS XMM5,dword ptr [FLOAT_XXX] = 1.0
0x80, 0xb9, 0x1a, 0x0e, 0x00, 0x00,
0x00, // CMP byte ptr [RCX + param_1->shift_down],0x0
0x74, 0x0a, // JZ +0xA
0xf3, 0x0f, 0x10, 0x2d, _, _, _,
_, // MOVSS XMM5,dword ptr [FLOAT_XXX] = 0.2
0xeb, 0x08, // JMP +0x8
0xf3, 0x0f, 0x10, 0x2d, _, _, _,
_ // MOVSS XMM5,dword ptr [FLOAT_XXX] = 1.0
];
let speed_addr = {
region.scan_aob_single(&memory_pattern)
region
.scan_aob_single(&memory_pattern)
.context("Error finding editor camera speed addr")?
};

Expand All @@ -63,7 +74,7 @@ impl EditorCameraSpeedTweak {
shift_multiplier: DEFAULT_SHIFT_MULTIPLIER,
control_multiplier: DEFAULT_CONTROL_MULTIPLIER,
wheel_multiplier: DEFAULT_WHEEL_MULTIPLIER,

current_wheel_multiplier: 1.0,
current_speed: DEFAULT_BASE_SPEED,
_speed_inject: speed_inject,
Expand All @@ -81,13 +92,17 @@ impl Tweak for EditorCameraSpeedTweak {
ui.set_next_item_width(100.0);
ui.slider("Base Speed", 0.1, 4.0, &mut self.base_speed);
if ui.is_item_hovered() {
ui.tooltip_text(format!("(default: {DEFAULT_BASE_SPEED}, vanilla: {VANILLA_BASE_SPEED})"));
ui.tooltip_text(format!(
"(default: {DEFAULT_BASE_SPEED}, vanilla: {VANILLA_BASE_SPEED})"
));
}

ui.set_next_item_width(100.0);
ui.slider("Shift Multiplier", 0.1, 4.0, &mut self.shift_multiplier);
if ui.is_item_hovered() {
ui.tooltip_text(format!("(default: {DEFAULT_SHIFT_MULTIPLIER}, vanilla: {VANILLA_SHIFT_MULTIPLIER})"));
ui.tooltip_text(format!(
"(default: {DEFAULT_SHIFT_MULTIPLIER}, vanilla: {VANILLA_SHIFT_MULTIPLIER})"
));
}

ui.set_next_item_width(100.0);
Expand All @@ -101,7 +116,7 @@ impl Tweak for EditorCameraSpeedTweak {
// if ui.is_item_hovered() {
// ui.tooltip_text(format!("(default: {DEFAULT_WHEEL_MULTIPLIER}, vanilla: {VANILLA_WHEEL_MULTIPLIER})"));
// }

// ui.text(format!("{}", self.current_speed));
// ui.text(format!("{}", self.current_wheel_multiplier));
}
Expand All @@ -114,11 +129,15 @@ impl Tweak for EditorCameraSpeedTweak {

self.current_speed = self.base_speed * self.current_wheel_multiplier;

if ui.is_key_down(hudhook::imgui::Key::LeftShift) || ui.is_key_down(hudhook::imgui::Key::RightShift) {
if ui.is_key_down(hudhook::imgui::Key::LeftShift)
|| ui.is_key_down(hudhook::imgui::Key::RightShift)
{
self.current_speed *= self.shift_multiplier;
}

if ui.is_key_down(hudhook::imgui::Key::LeftCtrl) || ui.is_key_down(hudhook::imgui::Key::RightCtrl) {
if ui.is_key_down(hudhook::imgui::Key::LeftCtrl)
|| ui.is_key_down(hudhook::imgui::Key::RightCtrl)
{
self.current_speed *= self.control_multiplier;
}

Expand Down Expand Up @@ -150,4 +169,4 @@ extern "stdcall" fn custom_speed() {
options(nostack),
);
}
}
}
62 changes: 36 additions & 26 deletions src/tweaks/editor_placement.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use anyhow::Context;
use memory_rs::{generate_aob_pattern, internal::{injections::{Inject, Injection}, memory_region::MemoryRegion}};
use memory_rs::{
generate_aob_pattern,
internal::{
injections::{Inject, Injection},
memory_region::MemoryRegion,
},
};

use super::{MemoryRegionExt, Tweak};


const VANILLA_SUPPORT_CHECK: bool = true;
const DEFAULT_SUPPORT_CHECK: bool = false;

Expand All @@ -23,25 +28,26 @@ impl EditorPlacementTweak {

// The start of the function that determines if a component placement has support
let memory_pattern = generate_aob_pattern![
0x4c, 0x8b, 0xdc, // MOV R11,RSP
0x49, 0x89, 0x5b, 0x10, // MOV qword ptr [R11 + local_res10],RBX
0x49, 0x89, 0x6b, 0x18, // MOV qword ptr [R11 + local_res18],RBP
0x56, // PUSH RSI
0x57, // PUSH RDI
0x41, 0x54, // PUSH R12
0x41, 0x56, // PUSH R14
0x41, 0x57, // PUSH R15
0x48, 0x81, 0xec, 0xb0, 0x00, 0x00, 0x00 // SUB RSP,0xb0
0x4c, 0x8b, 0xdc, // MOV R11,RSP
0x49, 0x89, 0x5b, 0x10, // MOV qword ptr [R11 + local_res10],RBX
0x49, 0x89, 0x6b, 0x18, // MOV qword ptr [R11 + local_res18],RBP
0x56, // PUSH RSI
0x57, // PUSH RDI
0x41, 0x54, // PUSH R12
0x41, 0x56, // PUSH R14
0x41, 0x57, // PUSH R15
0x48, 0x81, 0xec, 0xb0, 0x00, 0x00, 0x00 // SUB RSP,0xb0
];
let support_addr = {
region.scan_aob_single(&memory_pattern)
region
.scan_aob_single(&memory_pattern)
.context("Error finding placement support check function")?
};

// basically just early exit `return true`
let inject = vec![
0xB0, 0x01, // MOV al,01
0xC3, // RET
0xC3, // RET
];

let mut disable_support_check_inject = Injection::new(support_addr, inject);
Expand All @@ -54,25 +60,26 @@ impl EditorPlacementTweak {

// The start of the function that determines if a merge is valid
let memory_pattern = generate_aob_pattern![
0x48, 0x8b, 0xc4, // MOV RAX,RSP
0x4c, 0x89, 0x40, 0x18, // MOV qword ptr [RAX + local_res18],R8
0x48, 0x89, 0x50, 0x10, // MOV qword ptr [RAX + local_res10],RDX
0x48, 0x89, 0x48, 0x08, // MOV qword ptr [RAX + local_res8],RCX
0x55, // PUSH RBP
0x56, // PUSH RSI
0x57, // PUSH RDI
0x41, 0x54, // PUSH R12
0x48, 0x81, 0xec, 0xf8, 0x00, 0x00, 0x00 // SUB RSP,0xf8
0x48, 0x8b, 0xc4, // MOV RAX,RSP
0x4c, 0x89, 0x40, 0x18, // MOV qword ptr [RAX + local_res18],R8
0x48, 0x89, 0x50, 0x10, // MOV qword ptr [RAX + local_res10],RDX
0x48, 0x89, 0x48, 0x08, // MOV qword ptr [RAX + local_res8],RCX
0x55, // PUSH RBP
0x56, // PUSH RSI
0x57, // PUSH RDI
0x41, 0x54, // PUSH R12
0x48, 0x81, 0xec, 0xf8, 0x00, 0x00, 0x00 // SUB RSP,0xf8
];
let merge_addr = {
region.scan_aob_single(&memory_pattern)
region
.scan_aob_single(&memory_pattern)
.context("Error finding merge check function")?
};

// basically just early exit `return true`
let inject = vec![
0xB0, 0x01, // MOV al,01
0xC3, // RET
0xC3, // RET
];

let mut disable_merge_check_inject = Injection::new(merge_addr, inject);
Expand Down Expand Up @@ -116,7 +123,10 @@ impl Tweak for EditorPlacementTweak {
}

fn render(&mut self, ui: &hudhook::imgui::Ui) {
if ui.checkbox("Disable Placement Support Check", &mut self.disable_support_check) {
if ui.checkbox(
"Disable Placement Support Check",
&mut self.disable_support_check,
) {
self.set_support_check(!self.disable_support_check);
}
if ui.is_item_hovered() {
Expand All @@ -140,4 +150,4 @@ impl Tweak for EditorPlacementTweak {
self.set_support_check(VANILLA_SUPPORT_CHECK);
self.set_merge_check(VANILLA_MERGE_CHECK);
}
}
}
40 changes: 27 additions & 13 deletions src/tweaks/editor_show_hidden.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use anyhow::{anyhow, Context};
use memory_rs::{generate_aob_pattern, internal::{injections::{Inject, Injection}, memory_region::MemoryRegion}};
use memory_rs::{
generate_aob_pattern,
internal::{
injections::{Inject, Injection},
memory_region::MemoryRegion,
},
};

use super::{MemoryRegionExt, Tweak};

Expand All @@ -18,18 +24,21 @@ impl ShowHiddenComponents {

// check for hidden flag
let memory_pattern = generate_aob_pattern![
0xf7, 0x86, 0xa0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, // TEST dword ptr [RSI + 0x2a0],0x20000000
0x77, 0x67 // JA LAB_140444479
0xf7, 0x86, 0xa0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x20, // TEST dword ptr [RSI + 0x2a0],0x20000000
0x77, 0x67 // JA LAB_140444479
];

let check_addr = {
region.scan_aob_single(&memory_pattern)
region
.scan_aob_single(&memory_pattern)
.context(anyhow!("Error finding menu fade addr"))?
};

// NOP the JA
let inject = vec![0x90; 2];
let mut injection_1 = Injection::new(check_addr + memory_pattern.size - inject.len(), inject);
let mut injection_1 =
Injection::new(check_addr + memory_pattern.size - inject.len(), inject);

if DEFAULT_SHOW_HIDDEN_COMPONENTS {
injection_1.inject();
Expand All @@ -40,18 +49,20 @@ impl ShowHiddenComponents {
// check for hidden flag
let memory_pattern = generate_aob_pattern![
0x8b, 0x86, 0xa0, 0x02, 0x00, 0x00, // MOV EAX,dword ptr [RSI + 0x2a0]
0xa9, 0x00, 0x00, 0x00, 0x20, // TEST EAX,0x20000000
0x0f, 0x87, 0x14, 0x01, 0x00, 0x00 // JA LAB_1405ce8a6
0xa9, 0x00, 0x00, 0x00, 0x20, // TEST EAX,0x20000000
0x0f, 0x87, 0x14, 0x01, 0x00, 0x00 // JA LAB_1405ce8a6
];

let check_addr = {
region.scan_aob_single(&memory_pattern)
region
.scan_aob_single(&memory_pattern)
.context(anyhow!("Error finding menu fade addr"))?
};

// NOP the JA
let inject = vec![0x90; 6];
let mut injection_2 = Injection::new(check_addr + memory_pattern.size - inject.len(), inject);
let mut injection_2 =
Injection::new(check_addr + memory_pattern.size - inject.len(), inject);

if DEFAULT_SHOW_HIDDEN_COMPONENTS {
injection_2.inject();
Expand Down Expand Up @@ -81,20 +92,23 @@ impl Tweak for ShowHiddenComponents {
fn uninit(&mut self) -> anyhow::Result<()> {
Ok(())
}

fn render(&mut self, ui: &hudhook::imgui::Ui) {
if ui.checkbox("Show Hidden Components (reload save)", &mut self.show_hidden_components) {
if ui.checkbox(
"Show Hidden Components (reload save)",
&mut self.show_hidden_components,
) {
self.set_show_hidden_components(self.show_hidden_components);
}
if ui.is_item_hovered() {
ui.tooltip_text(format!("Forces editor to show components flagged as hidden.\nChanging this setting requires reloading your save to apply.\n(default: {DEFAULT_SHOW_HIDDEN_COMPONENTS}, vanilla: {VANILLA_SHOW_HIDDEN_COMPONENTS})"));
}
}

fn reset_to_default(&mut self) {
self.set_show_hidden_components(DEFAULT_SHOW_HIDDEN_COMPONENTS);
}

fn reset_to_vanilla(&mut self) {
self.set_show_hidden_components(VANILLA_SHOW_HIDDEN_COMPONENTS);
}
Expand Down
Loading

0 comments on commit d34b23a

Please sign in to comment.