Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 5f9c708

Browse files
committed
Add hack to reset autorun block
1.0.0-beta2 stripped out the lua_newstate detour, which meant it'd only run autorun.lua the first server you joined. This adds a hacky reset using stored curtime. Hopefully It can be removed with further additions to rglua. * Disable gui builds * Bump to 1.0.0-beta3 * Add Debug trait to Realm
1 parent 06fa2b4 commit 5f9c708

File tree

6 files changed

+57
-46
lines changed

6 files changed

+57
-46
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ jobs:
1616
cd autorun
1717
cargo build --release --verbose
1818
19-
buildgui64:
20-
runs-on: windows-latest
21-
steps:
22-
- uses: actions/checkout@v2
23-
- name: Build GUI
24-
run: |
25-
rustup default nightly
26-
cd autorun-gui
27-
cargo build --release --verbose
19+
#buildgui64:
20+
# runs-on: windows-latest
21+
# steps:
22+
# - uses: actions/checkout@v2
23+
# - name: Build GUI
24+
# run: |
25+
# rustup default nightly
26+
# cd autorun-gui
27+
# cargo build --release --verbose
2828

2929
# In the future make this run on an x86 machine https://github.com/actions/runner/issues/423
3030
build86:

.github/workflows/downloads.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@ jobs:
2323
name: 64 Bit
2424
path: target/release/Autorun.dll
2525

26-
buildgui64:
27-
runs-on: windows-latest
28-
steps:
29-
- uses: actions/checkout@v2
30-
- name: Build GUI
31-
run: |
32-
rustup default nightly
33-
cd autorun-gui
34-
cargo build --release --verbose
35-
cd ..
36-
37-
- name: Upload EXE
38-
uses: actions/upload-artifact@v2
39-
with:
40-
name: 64 Bit
41-
path: target/release/autorun-gui.exe
26+
# Re-enable this when gui is ready.
27+
#buildgui64:
28+
# runs-on: windows-latest
29+
# steps:
30+
# - uses: actions/checkout@v2
31+
# - name: Build GUI
32+
# run: |
33+
# rustup default nightly
34+
# cd autorun-gui
35+
# cargo build --release --verbose
36+
# cd ..
37+
38+
# - name: Upload EXE
39+
# uses: actions/upload-artifact@v2
40+
# with:
41+
# name: 64 Bit
42+
# path: target/release/autorun-gui.exe
4243

4344
# In the future make this run on an x86 machine https://github.com/actions/runner/issues/423
4445
build86:

autorun-shared/src/top.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22

33
// I know this is a waste to contain 'server' but I want it to be able to be used with GetLuaInterface
44
#[repr(u8)]
5-
#[derive(Clone, Copy)]
5+
#[derive(Clone, Copy, Debug)]
66
pub enum Realm {
77
Client = 0,
88
Server = 1,

autorun/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "autorun"
3-
version = "1.0.0-beta2"
3+
version = "1.0.0-beta3"
44
authors = ["Vurv78 <Vurv78@users.noreply.github.com>"]
55
edition = "2021"
66
publish = false

autorun/src/global.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use once_cell::sync::Lazy;
66

77
use autorun_shared::Realm;
88

9-
pub static HAS_AUTORAN: AtomicBool = AtomicBool::new(false); // Whether an autorun script has been run and detected already.
10-
119
type LuaScript = Vec<(Realm, String)>;
1210
// Scripts waiting to be ran in painttraverse
1311
pub static LUA_SCRIPTS: Lazy<Arc<Mutex<LuaScript>>> =

autorun/src/hooks/mod.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ffi::CStr;
22
use std::io::Write;
33
use std::{fs, sync::atomic::Ordering};
4+
use std::sync::atomic::AtomicU64;
45

56
use crate::{configs, global, lua::{self, AutorunEnv}, util, logging};
67

@@ -27,6 +28,8 @@ lazy_detour! {
2728
static PAINT_TRAVERSE_H: PaintTraverseFn;
2829
}
2930

31+
static CONNECTED: AtomicU64 = AtomicU64::new(99999);
32+
3033
fn loadbufferx_hook(l: LuaState, code: LuaString, len: usize, identifier: LuaString, mode: LuaString) -> Result<i32, interface::Error> {
3134
let engine = iface!(EngineClient)?;
3235

@@ -36,12 +39,25 @@ fn loadbufferx_hook(l: LuaState, code: LuaString, len: usize, identifier: LuaStr
3639

3740
if let Some(net) = unsafe { net.as_mut() } {
3841
let ip = net.GetAddress();
42+
let mut startup = false;
43+
44+
// TODO: It'd be great to hook net connections instead of doing this.
45+
// However, this works fine for now.
46+
let curtime = net.GetTimeConnected() as u64;
47+
if curtime < CONNECTED.load(Ordering::Relaxed) {
48+
debug!("Curtime is less than last time connected, assuming startup");
49+
startup = true;
50+
CONNECTED.store(curtime, Ordering::Relaxed);
51+
} else {
52+
// Awful
53+
CONNECTED.store(curtime, Ordering::Relaxed);
54+
}
3955

4056
let raw_path = unsafe { CStr::from_ptr(identifier) };
4157
let path = &raw_path.to_string_lossy()[1..]; // Remove the @ from the beginning of the path
4258

4359
// There's way too many params here
44-
do_run = dispatch(l, path, ip, code, len, identifier);
60+
do_run = dispatch(l, startup, path, ip, code, len, identifier);
4561
if !do_run {
4662
return Ok(0);
4763
}
@@ -72,23 +88,19 @@ extern "C" fn loadbufferx_h(
7288
}
7389
}
7490

75-
pub fn dispatch(l: LuaState, path: &str, server_ip: LuaString, mut code: LuaString, mut len: SizeT, identifier: LuaString) -> bool {
91+
pub fn dispatch(l: LuaState, startup: bool, path: &str, ip: LuaString, mut code: LuaString, mut len: SizeT, identifier: LuaString) -> bool {
7692
let mut do_run = true;
7793

78-
let before_autorun = global::HAS_AUTORAN
79-
.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
80-
.is_ok();
81-
82-
if before_autorun {
94+
if startup {
8395
let env = AutorunEnv {
8496
is_autorun_file: true,
85-
startup: before_autorun,
97+
startup,
8698

87-
identifier: identifier,
88-
code: code,
99+
identifier,
100+
code,
89101
code_len: len,
90102

91-
ip: server_ip,
103+
ip,
92104
};
93105
// This will only run once when HAS_AUTORAN is false, setting it to true.
94106
// Will be reset by JoinServer.
@@ -97,7 +109,7 @@ pub fn dispatch(l: LuaState, path: &str, server_ip: LuaString, mut code: LuaStri
97109
if let Ok(script) = fs::read_to_string(&ar_path) {
98110
// Try to run here
99111
if let Err(why) = lua::run_env(&script, env) {
100-
error!("{}", why);
112+
error!("{why}");
101113
}
102114
} else {
103115
error!(
@@ -110,13 +122,13 @@ pub fn dispatch(l: LuaState, path: &str, server_ip: LuaString, mut code: LuaStri
110122
if let Ok(script) = fs::read_to_string(configs::path(configs::HOOK_PATH)) {
111123
let env = AutorunEnv {
112124
is_autorun_file: false,
113-
startup: before_autorun,
125+
startup,
114126

115-
identifier: identifier,
116-
code: code,
127+
identifier,
128+
code,
117129
code_len: len,
118130

119-
ip: server_ip,
131+
ip: ip,
120132
};
121133

122134
match lua::run_env(&script, env) {
@@ -140,7 +152,7 @@ pub fn dispatch(l: LuaState, path: &str, server_ip: LuaString, mut code: LuaStri
140152
}
141153

142154
if global::FILESTEAL_ENABLED.load(Ordering::Relaxed) {
143-
let ip = unsafe { CStr::from_ptr(server_ip) };
155+
let ip = unsafe { CStr::from_ptr(ip) };
144156

145157
if let Ok(mut file) = util::get_handle(path, ip.to_string_lossy()) {
146158
if let Err(why) = file.write_all(unsafe { std::ffi::CStr::from_ptr(code) }.to_bytes()) {

0 commit comments

Comments
 (0)