Skip to content

Commit

Permalink
Merge pull request #23 from NotNite/obliterate-loader-lock
Browse files Browse the repository at this point in the history
Obliterate loader lock
  • Loading branch information
NotNite authored Nov 11, 2024
2 parents d956838 + 32ee3e5 commit d7c1793
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 3 deletions.
112 changes: 111 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions GDWeave/Godot/GodotScriptFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class GodotScriptFile {
public const uint Magic = 0x43534447; // 'G', 'D', 'S', 'C'
public const uint Version = 13; // Godot 3.5.2
public const byte UselessXorKey = 0xB6; // What
public const uint TokenLineMask = (1 << 24) - 1;

public List<string> Identifiers = new();
public List<Variant> Constants = new();
Expand Down
3 changes: 3 additions & 0 deletions GDWeave/Script/ScriptModder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public bool Run(GodotScriptFile file, string path) {

// Translate special tokens back into tokens
file.Tokens.Clear();
file.Lines.Clear();
foreach (var token in tokens) {
switch (token) {
case ConstantToken constant: {
Expand All @@ -48,6 +49,8 @@ public bool Run(GodotScriptFile file, string path) {
}

file.Tokens.Add(token);
var idx = (uint) file.Tokens.Count - 1;
file.Lines.Add((idx, idx & GodotScriptFile.TokenLineMask));
}

return true;
Expand Down
6 changes: 6 additions & 0 deletions loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ anyhow = "1.0.89"
isahc = "1.7.2"
netcorehost = "0.17.0"
proxy-dll = "0.2.5"
retour = { version = "0.3.1", features = ["static-detour"] }
thiserror = "1.0.64"
win-msgbox = "0.2.1"
windows = { version = "0.58.0", features = [
"Win32_System_Threading",
"Win32_System_ProcessStatus",
"Win32_System_LibraryLoader",
] }
41 changes: 39 additions & 2 deletions loader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
use isahc::ReadResponseExt;
use netcorehost::{error::HostingError, nethost, pdcstr, pdcstring::PdCString};
use proxy_dll::proxy;
use retour::static_detour;
use thiserror::Error;
use win_msgbox::{Okay, YesNo};
use windows::{
core::PCWSTR,
Win32::System::{
LibraryLoader::GetModuleHandleW,
ProcessStatus::{GetModuleInformation, MODULEINFO},
Threading::GetCurrentProcess,
},
};

#[derive(Error, Debug)]
pub enum LoaderError {
Expand Down Expand Up @@ -89,8 +98,11 @@ fn install_net() -> anyhow::Result<()> {
Ok(())
}

#[proxy]
pub fn main() {
static_detour! {
static MainHook: fn() -> i32;
}

pub fn main_detour() -> i32 {
if let Err(e) = init() {
match e {
LoaderError::LoadHostfxrError(_)
Expand Down Expand Up @@ -123,4 +135,29 @@ pub fn main() {
}
}
}

MainHook.call()
}

#[proxy]
pub fn main() {
unsafe {
let process = GetCurrentProcess();
let module = GetModuleHandleW(PCWSTR::null()).unwrap();
let mut lpmodinfo = MODULEINFO::default();
GetModuleInformation(
process,
module,
&mut lpmodinfo,
size_of::<MODULEINFO>() as u32,
)
.unwrap();

let entry = lpmodinfo.EntryPoint;

MainHook
.initialize(std::mem::transmute(entry), main_detour)
.unwrap();
MainHook.enable().unwrap();
}
}

0 comments on commit d7c1793

Please sign in to comment.