Skip to content

Commit e17ec57

Browse files
committed
Fix random Unknown nb_ctl request: 4 errors
Fixes #26 * Bump to 1.0.0-beta4 * Add CODE_LEN field to the ``sautorun`` table
1 parent 5f9c708 commit e17ec57

File tree

5 files changed

+61
-10
lines changed

5 files changed

+61
-10
lines changed

autorun-shared/src/top.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt;
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)]
55
#[derive(Clone, Copy, Debug)]
6+
#[cfg_attr(feature = "gui", derive(bincode::Decode, bincode::Encode))]
67
pub enum Realm {
78
Client = 0,
89
Server = 1,
@@ -19,6 +20,17 @@ impl fmt::Display for Realm {
1920
}
2021
}
2122

23+
impl From<u8> for Realm {
24+
fn from(realm: u8) -> Self {
25+
match realm {
26+
0 => Realm::Client,
27+
1 => Realm::Server,
28+
2 => Realm::Menu,
29+
_ => panic!("Invalid realm")
30+
}
31+
}
32+
}
33+
2234
impl Into<u8> for Realm {
2335
fn into(self) -> u8 {
2436
match self {

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-beta3"
3+
version = "1.0.0-beta4"
44
authors = ["Vurv78 <Vurv78@users.noreply.github.com>"]
55
edition = "2021"
66
publish = false

autorun/src/lua/mod.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,42 @@ pub struct AutorunEnv {
2121
pub code_len: usize,
2222
}
2323

24+
impl AutorunEnv {
25+
pub fn from_lua(state: LuaState) -> Option<Self> {
26+
lua_getglobal(state, cstr!("sautorun"));
27+
if lua_type(state, -1) == rglua::lua::TTABLE {
28+
lua_getfield(state, -1, cstr!("STARTUP"));
29+
let startup = lua_toboolean(state, -1) != 0;
30+
31+
lua_getfield(state, -1, cstr!("NAME"));
32+
let identifier = lua_tostring(state, -1);
33+
34+
lua_getfield(state, -1, cstr!("CODE_LEN"));
35+
let mut code_len = lua_tointeger(state, -1) as usize;
36+
37+
lua_getfield(state, -1, cstr!("CODE"));
38+
let code = lua_tolstring(state, -1, &mut code_len);
39+
40+
lua_getfield(state, -1, cstr!("IP"));
41+
let ip = lua_tostring(state, -1);
42+
43+
lua_pop(state, 6);
44+
45+
return Some(AutorunEnv {
46+
is_autorun_file: false,
47+
startup,
48+
code,
49+
identifier,
50+
code_len,
51+
ip
52+
});
53+
}
54+
55+
lua_pop(state, 1);
56+
None
57+
}
58+
}
59+
2460
// Functions to interact with lua without triggering the detours
2561
pub fn compile<S: AsRef<str>>(l: LuaState, code: S) -> Result<(), &'static str> {
2662
let s = code.as_ref();
@@ -135,6 +171,9 @@ pub fn run_env(
135171
lua_pushstring(l, env.identifier); // stack[3] = identifier
136172
lua_setfield(l, -2, cstr!("NAME")); // stack[2].NAME = table.remove(stack, 3)
137173

174+
lua_pushinteger(l, env.code_len as LuaInteger); // stack[3] = code_len
175+
lua_setfield(l, -2, cstr!("CODE_LEN")); // stack[2].CODE_LEN = table.remove(stack, 3)
176+
138177
lua_pushlstring(l, env.code, env.code_len); // stack[3] = identifier
139178
lua_setfield(l, -2, cstr!("CODE")); // stack[2].CODE = table.remove(stack, 3)
140179

autorun/src/ui/console.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ use std::path::Path;
66
use indoc::printdoc;
77

88
pub fn init() {
9-
unsafe { winapi::um::consoleapi::AllocConsole() };
9+
unsafe {
10+
// Load this library before it starts spamming useless errors into our console.
11+
// https://github.com/Vurv78/Autorun-rs/issues/26
12+
winapi::um::libloaderapi::LoadLibraryA( rglua::cstr!("vaudio_speex.dll") );
13+
winapi::um::consoleapi::AllocConsole()
14+
};
1015

1116
let version = env!("CARGO_PKG_VERSION");
1217
printdoc!("

autorun/src/ui/gui.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::{io::Read, time::Duration};
1+
use std::io::Read;
22
use autorun_shared::serde::{ToGUI, ToAutorun, Setting};
3-
use message_io::{node::{self, NodeEvent}, network::{Transport, NetEvent}};
3+
use message_io::{node, network::{Transport, NetEvent}};
44
use crate::{lua, logging::error, global::{FILESTEAL_ENABLED, LOGGING_ENABLED}};
55

66
pub fn init() {
@@ -12,11 +12,6 @@ pub fn init() {
1212
});
1313
}
1414

15-
enum Signal {
16-
Greet,
17-
Msg(String)
18-
}
19-
2015
pub fn instance(mut stdout: shh::ShhStdout) {
2116
//let connection = std::net::TcpListener::bind("127.0.0.1:8080").unwrap();
2217
// connection.set_nonblocking(true).expect("Couldn't set nonblocking");
@@ -29,7 +24,7 @@ pub fn instance(mut stdout: shh::ShhStdout) {
2924
let endpoints = Arc::new(Mutex::new(vec![]));
3025
let for_listener = Arc::clone(&endpoints);
3126

32-
let config = bincode::config::Configuration::standard();
27+
let config = bincode::config::standard();
3328
listener.for_each(move |event| match event.network() {
3429
NetEvent::Connected(_, _ok) => unreachable!(),
3530
NetEvent::Accepted(endpoint, _) => {

0 commit comments

Comments
 (0)