Skip to content

Commit 3e1f83f

Browse files
committed
chore: add explanation and metadata
1 parent 9cb5ab2 commit 3e1f83f

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT No Attribution
1+
MIT
22

3-
Copyright 2025 ScrappySM
3+
Copyright 2025 Ben McAvoy, ScrappySM
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this
66
software and associated documentation files (the "Software"), to deal in the Software

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
# Getting started
1+
# SM-KeyAPI
22

3-
Welcome to your new DLL mod, you should see you now have a `SM-KeyAPI.sln` file, all the files you see here were generated from the template.
3+
This mod extends the [SM](https://scrapmechanic.com/) Lua API to allow you to query any key on the keyboard as long as the window is focussed!
44

5-
## Usage
5+
## Installation
66

7-
1. Clone this repository locally
8-
2. Open the `SM-KeyAPI.sln` file in Visual Studio
9-
3. Make your changes in `dllmain.cpp`, pressing "Local Windows Debugger" will build and run the game with your mod injected.
10-
4. Add a description to your mod and adjust any of the necessary fields in [manifest.json](manifest.json)
11-
5. When you are ready to release your mod, [commit](https://github.com/git-guides/git-commit), [tag](https://www.slingacademy.com/article/working-with-git-tags-a-complete-guide-with-examples/) your commit and push your changes to GitHub.
12-
6. You can then view the https://github.com/ScrappySM/SM-KeyAPI/releases to see your mod's release page, edit the draft and publish it when you are ready.
7+
> [!TIP]
8+
> The recommended method of installing this is [Carbon Launcher](https://github.com/ScrappySM/CarbonLauncher) which is maintained by me and will let you simply press download and launch the game!
139
14-
## License
10+
However, there are many other ways. Here's a launcher agnostic way of installing this mod:
11+
- Go to releases and download the latest `.dll` file.
12+
- Open a tool like Process Hacker/System Informer and find the process of Scrap Mechanic.
13+
- Inject the `.dll` file as a module into the process.
1514

16-
You should change the authors or the entire license in the [LICENSE](LICENSE) file to your liking, this template is licensed under The MIT-0 license meaning no attribution is required to use this template - see the [LICENSE](LICENSE) file for details, meaning you can do whatever you want with this template! (yes, you can change the license)
15+
You can also use a tool like [SM-DLL-Injector](https://github.com/QuestionableM/SM-DLL-Injector) maintained by [QuestionableM](https://github.com/QuestionableM) and will let you simply inject any DLL files in a folder called `DllModules`, you could use this project and put the `.dll` file in the folder and it will automatically inject it for you.
16+
17+
## Explanation/Updating guide
18+
19+
> [!WARNING]
20+
> This section is for developers and modders who want to understand how the mod works and how to update it.
21+
22+
An explanation of how the mod works and how to update is available in [dllmain](SM-KeyAPI/src/dllmain.cpp).

SM-KeyAPI/src/dllmain.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/// How this mod works:
2+
/// - We hook the loadLuaEnv function, which is called when the game loads the Lua environment.
3+
/// - We inject a function into the Lua environment that allows us to check the state of a key (implemented in C++ as `keyapi_getkeystate`).
4+
///
5+
/// - In the `keyapi_getkeystate` function, we check if the ScrapMechanic window is the active window.
6+
/// - If it is, we check the state of the key and return it to the Lua environment.
7+
///
8+
/// How to update the mod (assumes IDA):
9+
/// - Go the to names subview (Shift + F4)
10+
/// - Search for `luaopen_base`
11+
/// - XRef to the function
12+
/// - The function you arrive at is the loadLuaEnv function, update the offset in `include/sm/offsets.h`
13+
114
#define WIN32_LEAN_AND_MEAN
215

316
#include <Windows.h>

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"url": "https://github.com/ScrappySM/SM-KeyAPI",
66

77
"authors": [
8-
"ScrappySM"
8+
"BenMcAvoy"
99
],
1010

11-
"description": "No description yet, needs to be filled in"
11+
"description": "Extends the SM Lua API to query any keyboard input."
1212
}

0 commit comments

Comments
 (0)