Skip to content

Commit 0c4b522

Browse files
committed
1.0.0
* Added settings folder which is created if it does not already exist. See the default parameters in autorun/src/configs/settings.toml * Overview of settings added: Ability to hide console on startup, disable plugins, disable filesteal, disable logging, and change the name of generated filesteal folders * Added examples in the /examples/ directory * Added ``settings`` command which gives an overview of your current autorun settings * Remove ``sautorun`` alias The only things left to do for 1.0.0 were fix 32 bit (which is not possible without nightly) and make require work relatively. I think I'll push require to be changed in 1.1, there's too many changes to have in just betas, so here it is. 1.0.0 Fixes #36 Fixes #29
1 parent fa88e58 commit 0c4b522

File tree

13 files changed

+379
-165
lines changed

13 files changed

+379
-165
lines changed

README.md

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@
55
## Features
66
* Dumping all lua scripts to ``C:\Users\<User>\autorun\lua_dumps\<ServerIP>\..``
77
* Runtime lua loading through ``lua_run`` and ``lua_openscript`` in an external console
8-
* Supports both 32 and 64 bit branches (WARNING: See [#22](https://github.com/Vurv78/Autorun-rs/issues/22))
8+
* Supports both 32* and 64 bit branches (*See [#22](https://github.com/Vurv78/Autorun-rs/issues/22))
99
* Running a script before autorun (``autorun.lua``), to detour and bypass any 'anticheats'
1010
* Scripthook, stop & run scripts before anything runs on you, gives information & functions to assist in a safe separate lua environment
1111
* File logging (to ``autorun/logs``)
12+
* Plugin system (``autorun/plugins``)
13+
* [Settings using TOML](autorun/src/configs/settings.toml)
1214

1315
## 🤔 Usage
1416
### 🧩 Menu Plugin
1517
Autorun can also be used as a menu plugin / required from lua automatically from the menu state.
16-
1. [Get the DLL](#downloading)
17-
1. Put the ``gmsv_autorun_win<arch>.dll`` file into your ``garrysmod/lua/bin`` folder.
18+
1. Put [the dll](#⬇️-downloading) ``gmsv_autorun_win<arch>.dll`` file into your ``garrysmod/lua/bin`` folder.
1819
2. Add ``require("autorun")`` at the bottom of ``garrysmod/lua/menu/menu.lua``
1920
**It will now run automatically when garrysmod loads at the menu.**
2021

2122
### 💉 Injecting
2223
The traditional (but more inconvenient) method to use this is to just inject it.
2324
1. Get an injector (Make sure it's compatible to inject 32/64 bit code depending on your use).
24-
2. [Get the DLL](#downloading)
25-
3. Inject into gmod while you're in the menu
25+
2. Inject [the dll](#⬇️-downloading) into gmod while you're in the menu
2626

2727
## 📜 Scripthook
2828
Autorun features scripthook, which means we'll run your script before any other garrysmod script executes to verify if you want the code to run by running your own hook script.
29-
*This runs in a separate environment from ``_G``, so to modify globals, do ``_G.foo = bar*``
29+
*This runs in a separate environment from ``_G``, so to modify globals, do ``_G.foo = bar``
3030

3131
Also note that if you are running in ``autorun.lua`` Functions like ``http.Fetch`` & ``file.Write`` won't exist.
3232
Use their C counterparts (``HTTP`` and ``file.Open``)
@@ -37,55 +37,49 @@ __See an example project using the scripthook [here](https://github.com/Vurv78/S
3737
```golo
3838
C:\Users\<User>\autorun
3939
├── \autorun.lua # Runs *once* before autorun
40-
├── \hook.lua # Runs for every script (including init.lua, which triggers autorun.lua)
40+
├── \hook.lua # Runs for every script
4141
├── \lua_dumps\ # Each server gets it's own folder named by its IP
42-
│ ├── \192.168.1.1\
43-
│ ├── \192.168.1.2\
44-
│ └── \241241.352.1.3\
45-
│ \logs\
42+
│ ├── \192.168.1.55_27015\
43+
│ └── \X.Y.Z.W_PORT\
44+
├── \logs\ # Logs are saved here
4645
│ └── August 02, 2021 01-00 pm.log
46+
├── \plugins\ # Folder for Autorun plugins, same behavior as above autorun and hook.lua, but meant for plugin developers.
47+
│ └── \Safety\
48+
│ ├── \src\
49+
| | ├── autorun.lua
50+
| | └── hook.lua
51+
│ └── plugin.toml
52+
├── settings.toml # See autorun/src/configs/settings.toml
4753
└── ...
4854
```
4955

5056
### 🗃️ Fields
51-
Here are the fields for the ``sautorun`` table that gets passed in scripthook.
52-
| Field | Type | Description |
53-
| --- | --- | --- |
54-
| NAME | string | Name of the script, ex: @lua/this/that.lua |
55-
| CODE | string | The contents of the script |
56-
| CODE_LEN | number | Length of the script |
57-
| IP | string | IP of the server you are currently connected to |
58-
| STARTUP | boolean | Whether the script is running from ``autorun.lua`` (true) or false |
59-
| log | fn(string, uint?)| A function that logs to your autorun console. Second param is level ascending with urgency, 1 being error, 2 warning, 3, info, 4 debug, 5 trace. Default 3 |
60-
| require | fn(string) | Works like gmod's include function. Does not cache like regular lua's require for now. Runs a script local to autorun/scripts and passes the returned values |
57+
You can find what is passed to the scripthook environment in [examples/fields.lua](examples/fields.lua) as an EmmyLua definitions file.
58+
This could be used with something like a vscode lua language server extension for intellisense 👍
6159

6260
### ✍️ Examples
6361
__hook.lua__
6462
This file runs before every single lua script run on your client from addons and servers.
63+
You can ``return true`` to not run the script, or a string to replace it.
6564
```lua
66-
local script = sautorun.CODE
65+
-- Replace all 'while true do end' scripts with 'while false do end' 😎
66+
local script = Autorun.CODE
6767
if script:find("while true do end") then
68-
sautorun.log("Found an evil script!")
69-
-- Run our modified script that will replace all ``while true do end`` with ``while false do end``. 😎
70-
68+
Autorun.log("Found an evil script!")
7169
return string.Replace(script, "while true do end", "while false do end")
72-
73-
-- OR: return true to not run the script at all.
7470
end
7571
```
76-
__autorun.lua__
77-
This will be the first lua script to run on your client when you join a server, use this to make detours and whatnot.
78-
```lua
79-
local ERROR, WARN, INFO, DEBUG, TRACE = 1, 2, 3, 4, 5
80-
sautorun.log( "Connected to server " .. sautorun.IP, DEBUG )
81-
```
72+
73+
You can find more [here](examples)
8274

8375
## ⬇️ Downloading
84-
### Stable
76+
### 🦺 Stable
8577
You can get a 'stable' release from [the releases](https://github.com/Vurv78/Autorun-rs/releases/latest).
86-
### Bleeding Edge
78+
### 🩸 Bleeding Edge
8779
You can get the absolute latest download (from code in the repo) in [the Github Actions tab](https://github.com/Vurv78/Autorun-rs/actions/workflows/downloads.yml)
88-
Note it may not work as expected.
80+
Note it may not work as expected (but I'd advise to try this out before trying to report an issue to see if it has been fixed)
81+
82+
__If you are using this as a menu plugin 🧩, make sure the DLL is named ``gmsv_autorun_win<arch>.dll``__
8983

9084
## 🛠️ Building
9185
You may want to build this yourself if you want to make changes / contribute (or don't trust github actions for whatever reason..)

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

autorun/src/configs/mod.rs

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,100 @@ macro_rules! adir {
66
};
77
}
88

9-
pub static DUMP_DIR: &str = concat!(adir!(), "/lua_dumps");
9+
pub const DUMP_DIR: &str = concat!(adir!(), "/lua_dumps");
1010
#[cfg(feature = "logging")]
11-
pub static LOG_DIR: &str = concat!(adir!(), "/logs");
12-
pub static INCLUDE_DIR: &str = concat!(adir!(), "/scripts");
13-
pub static PLUGIN_DIR: &str = concat!(adir!(), "/plugins");
11+
pub const LOG_DIR: &str = concat!(adir!(), "/logs");
12+
pub const INCLUDE_DIR: &str = concat!(adir!(), "/scripts");
13+
pub const PLUGIN_DIR: &str = concat!(adir!(), "/plugins");
1414

15-
pub static AUTORUN_PATH: &str = concat!(adir!(), "/autorun.lua");
16-
pub static HOOK_PATH: &str = concat!(adir!(), "/hook.lua");
15+
pub const AUTORUN_PATH: &str = concat!(adir!(), "/autorun.lua");
16+
pub const HOOK_PATH: &str = concat!(adir!(), "/hook.lua");
17+
pub const SETTINGS_PATH: &str = concat!(adir!(), "/settings.toml");
1718

1819
pub fn path(path: &str) -> std::path::PathBuf {
1920
let home = home::home_dir().expect("Couldn't get your home directory!");
2021
home.join(path)
2122
}
23+
24+
// I know I could just derive / impl Default for all of these settings,
25+
// but then there wouldn't be comments to explain what each setting is for.
26+
use serde::{Deserialize, Serialize};
27+
#[derive(Debug, Deserialize, Serialize)]
28+
pub struct Settings {
29+
pub autorun: AutorunSettings,
30+
pub filesteal: FileSettings,
31+
pub logging: LoggerSettings,
32+
pub plugins: PluginSettings
33+
}
34+
35+
#[derive(Debug, Deserialize, Serialize)]
36+
pub struct AutorunSettings {
37+
pub hide: bool
38+
}
39+
#[derive(Debug, Deserialize, Serialize)]
40+
pub struct FileSettings {
41+
pub enabled: bool,
42+
pub format: String
43+
}
44+
45+
#[derive(Debug, Deserialize, Serialize)]
46+
pub struct LoggerSettings {
47+
pub enabled: bool,
48+
}
49+
50+
#[derive(Debug, Deserialize, Serialize)]
51+
pub struct PluginSettings {
52+
pub enabled: bool
53+
}
54+
55+
use crate::logging::{error, info};
56+
57+
use once_cell::sync::Lazy;
58+
pub static SETTINGS: Lazy<Settings> = Lazy::new(|| {
59+
let settings_file = path(SETTINGS_PATH);
60+
let default_settings = include_str!("settings.toml");
61+
62+
if settings_file.exists() {
63+
match std::fs::read_to_string(&settings_file) {
64+
Ok(content) => {
65+
match toml::from_str(&content) {
66+
Ok(settings) => settings,
67+
Err(why) => {
68+
error!("Failed to parse your autorun/settings.toml file: {why}");
69+
70+
toml::from_str(default_settings)
71+
.expect("Failed to parse default settings")
72+
}
73+
}
74+
},
75+
Err(why) => {
76+
error!("Failed to read your settings file '{why}'. Using default settings!");
77+
78+
toml::from_str(default_settings)
79+
.expect("Failed to parse default settings")
80+
}
81+
}
82+
} else {
83+
// No settings file, create file with default settings, and use that.
84+
match std::fs::File::create(settings_file) {
85+
Err(why) => {
86+
error!("Couldn't create settings file: {why}");
87+
},
88+
Ok(mut handle) => {
89+
use std::io::Write;
90+
match handle.write_all( default_settings.as_bytes() ) {
91+
Err(why) => {
92+
error!("Couldn't write default settings: {why}");
93+
},
94+
Ok(_) => {
95+
info!("No settings found, created default settings file!");
96+
}
97+
}
98+
}
99+
};
100+
101+
toml::from_str(default_settings)
102+
.expect("Failed to parse default settings")
103+
}
104+
105+
});

autorun/src/configs/settings.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[autorun]
2+
# Whether to hide on startup
3+
hide = false
4+
5+
[plugins]
6+
# Whether to run saved plugins
7+
enabled = true
8+
9+
[logging]
10+
# Whether to disable saving log files to disk in autorun/logs
11+
# Will still print info/errors to your console
12+
enabled = true
13+
14+
[filesteal]
15+
# Whether to save lua files from detours in autorun/lua_dumps
16+
enabled = true
17+
18+
# Format to use when saving folders
19+
# Valid tags:
20+
# <ip> IP Address of the server (with port)
21+
# <hostname> Hostname of the server (Currently will just return CLIENT, so don't use.)
22+
format = "<ip>"

autorun/src/global.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/// Most of this should be reworked later.
2-
use std::sync::atomic::AtomicBool;
32
use std::sync::{Arc, Mutex};
43

54
use once_cell::sync::Lazy;
@@ -9,7 +8,4 @@ use autorun_shared::Realm;
98
type LuaScript = Vec<(Realm, String)>;
109
// Scripts waiting to be ran in painttraverse
1110
pub static LUA_SCRIPTS: Lazy<Arc<Mutex<LuaScript>>> =
12-
Lazy::new(|| Arc::new(Mutex::new(Vec::new())));
13-
14-
pub static LOGGING_ENABLED: AtomicBool = AtomicBool::new(true);
15-
pub static FILESTEAL_ENABLED: AtomicBool = AtomicBool::new(true);
11+
Lazy::new(|| Arc::new(Mutex::new(Vec::new())));

0 commit comments

Comments
 (0)