Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obliterate loader lock #23

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading