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

Fixing proton/linux and launcher #283

Merged
merged 15 commits into from
Dec 11, 2022
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:
- name: Create artifacts
run: |
mkdir Overlunky
move build\bin\Release\injected.dll Overlunky\injected.dll
move build\bin\Release\injector.exe Overlunky\Overlunky.exe
move build\bin\Release\Overlunky.dll Overlunky\Overlunky.dll
move build\bin\Release\Overlunky.exe Overlunky\Overlunky.exe
move README.md Overlunky\README.txt
move examples Overlunky\Scripts
7z a Overlunky_${{ steps.get_version.outputs.VERSION }}.zip Overlunky\
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/whip-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
- name: Create artifacts
run: |
mkdir Overlunky
move build\bin\injected.dll Overlunky\injected.dll
move build\bin\injector.exe Overlunky\Overlunky.exe
move build\bin\Overlunky.dll Overlunky\Overlunky.dll
move build\bin\Overlunky.exe Overlunky\Overlunky.exe
move README.md Overlunky\README.txt
move examples Overlunky\Scripts
7z a Overlunky_WHIP.zip Overlunky\
Expand All @@ -50,4 +50,4 @@ jobs:
files: |
Overlunky_WHIP.zip
Overlunky/Overlunky.exe
Overlunky/injected.dll
Overlunky/Overlunky.dll
45 changes: 30 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ An overlay for Spelunky 2 to help you with modding, exploring the depths of the

[![Overlunky](https://img.shields.io/github/v/release/spelunky-fyi/overlunky?label=Overlunky)](https://github.com/spelunky-fyi/overlunky/releases/latest) is compatible with ![Spelunky](https://img.shields.io/badge/Spelunky2-1.25.2-green) (Steam version)

[![Overlunky](https://img.shields.io/github/v/release/spelunky-fyi/overlunky?include_prereleases&label=Overlunky)](https://github.com/spelunky-fyi/overlunky/releases/tag/whip) (latest prerelease build) is compatible with ![Spelunky](https://img.shields.io/badge/Spelunky2-1.27-green) (Steam version)
[![Overlunky](https://img.shields.io/github/v/release/spelunky-fyi/overlunky?include_prereleases&label=Overlunky)](https://github.com/spelunky-fyi/overlunky/releases/tag/whip) (latest prerelease build) is compatible with ![Spelunky](https://img.shields.io/badge/Spelunky2-1.28-green) (Steam version)

**Overlunky (or any other modding tool for that matter) does not support the GamePass/Xbox version**, but it might be considered in the future.

Expand All @@ -19,20 +19,24 @@ You are strongly discouraged from using any modding tools in your actual online
## Installation and usage
**[YouTube tutorial](https://youtu.be/Zzba4cV9f2c) for kids who can't read good and who wanna learn to do other stuff good too.**

**[Download the latest stable release](https://github.com/spelunky-fyi/overlunky/releases/latest)** (or a [WHIP build](https://github.com/spelunky-fyi/overlunky/releases/tag/whip) for more experimental stuff) and extract to your game folder, keeping the folder structure. Run the program, leave it running and then start your game, or the other way around! Check the [keyboard shortcuts](#features) and [troubleshooting](#troubleshooting) before asking dumb questions. Overlunky doesn't do any permanent changes to your game, it only exists when you run it.
- **[Download the latest WHIP build](https://github.com/spelunky-fyi/overlunky/releases/tag/whip)** or a [stable release](https://github.com/spelunky-fyi/overlunky/releases/latest)** and extract to your game folder, keeping the folder structure.
+ You can also use [Modlunky2](https://github.com/spelunky-fyi/modlunky2/) to install and launch Overlunky
- Run the program, leave it running and then start your game, or the other way around!
+ It won't automatically start your game, so don't hold your breath waiting for it
+ You can press ENTER in the launcher to try launch the game from the parent folder
- Check the [keyboard shortcuts](#features) and [troubleshooting](#troubleshooting) before asking dumb questions
- It doesn't do any permanent changes to your game, it only exists when you run it

**Overlunky does NOT work online!** I thought the disclaimer was clear on this... Now I'm not going to stop you from trying, but you'll just find yourself in a world of desync and crashes.

Check the generated `Spelunky 2/overlunky.ini` after running to change shortcut keys and check [entities.txt](https://github.com/spelunky-fyi/overlunky/blob/main/docs/game_data/entities.txt) for a list of numerical entity IDs.

## WHIP build and automatic updates

[WHIP builds](https://github.com/spelunky-fyi/overlunky/releases/tag/whip) are whipped together automatically from the latest changes and are not tested or documented at all. They are mainly to keep up with the ever changing scripting api and usually contain bugfixes for that. Use at your own discretion, but if you want to use the latest scripting features, get this.

**WHIP also has an auto-update system to check for a new version on every launch. This only updates the DLL though, NOT the bundled example scripts or the launcher!** So:
**WHIP also has an auto-update system to check for a new version on every launch. This won't update the bundled scripts though, so you might want to do a manual update from time to time.** So:

- If you just want Overlunky for the tools, get the EXE and it will download the DLL and keep it updated for you
- If you want the bundled scripts or need to update the launcher, get the ZIP or use Modlunky2 to update everything
- If you want the bundled scripts, get the ZIP or use [Modlunky2](https://github.com/spelunky-fyi/modlunky2/) to update everything

![WHIP commits](https://img.shields.io/github/commits-since/spelunky-fyi/overlunky/latest)

Expand Down Expand Up @@ -120,11 +124,16 @@ Current features and their *default* keyboard shortcuts.
- **Ctrl+C**: Quick return to camp from anywhere

### Scripts
Lua scripting is still buggy and unfinished and the **API might change**, although we will try to deprecate old stuff without breaking anything. There's an [API documentation](https://spelunky-fyi.github.io/overlunky/), [internal details](https://github.com/spelunky-fyi/overlunky/tree/main/docs) and [examples](https://github.com/spelunky-fyi/overlunky/tree/main/examples) to get you started. The examples should be considered [Unlicensed](https://unlicense.org/), so please DO NOT credit the author when copying them. Scripts are loaded from `Spelunky 2/Overlunky/Scripts` by default, but you can change this in the ini. Optionally you can also load *main.lua* files from `Mods/Packs`. Check the [Playlunky documentation](https://github.com/spelunky-fyi/Playlunky/wiki#script-mods) on how to run your scripts as PL mods. Set `OL_DEBUG=1` in the *game environment* to enable logging script messages to console.
Lua scripting is still buggy and unfinished and the **API might change**, although we will try to deprecate old stuff without breaking anything. There's an [API documentation](https://spelunky-fyi.github.io/overlunky/), [internal details](https://github.com/spelunky-fyi/overlunky/tree/main/docs) and [examples](https://github.com/spelunky-fyi/overlunky/tree/main/examples) to get you started. The examples should be considered [Unlicensed](https://unlicense.org/), so please DO NOT credit the author when copying them. Scripts are loaded from `Spelunky 2/Overlunky/Scripts` by default, but you can change this in the ini. Optionally you can also load *main.lua* files from `Mods/Packs`. Check the [Playlunky documentation](https://github.com/spelunky-fyi/Playlunky/wiki#script-mods) on how to run your scripts as PL mods. Set the [command line switch](#command-line-switches) `--console` to see script messages in the console.

**Scripts don't work online either!** While technically they can work, and there's some work being done on this, yours truly has little interest in making any online features.

## Troubleshooting
- If you're running **Linux**
+ Check the [command line switches](#command-line-switches) to mitigate issues that come with injecting.
+ The game and OL should run fine with Wine 7 if you install DXVK and the steam emu. Without DXVK the game colors are probably messed up, and Overlunky might mess them up even more. These are probably Wine bugs and not Overlunky bugs.
+ Also works with **Proton Experimental** or maybe Proton 7 using the [command line switch](#command-line-switches) `--launch_game` for a non-Steam game shortcut. Just make sure the game and the OL shortcut are set to use the same Proton version under compatibility.
+ You're still mostly on your own here, this is a Windows 10 program for a Windows 10 game.
- If your game **crashes** when launching Overlunky or it just closes and you **don't see the overlay** in game:
+ Make sure you are running the latest version of each. We don't support old game versions and sometimes not the too recent ones either. The latest somewhat tested version can be found at the top if this document.
+ Make sure your antivirus is not blocking it. **This is very likely if you're using one.** Overlunky is very hacky and acts like malware. It isn't, but you can audit the source code and build it yourself if you want.
Expand All @@ -134,7 +143,7 @@ Lua scripting is still buggy and unfinished and the **API might change**, althou
+ See previous section.
+ Some entities just crash the game, try to avoid them next time.
+ Some scripts just crash the game too, the api is not very safe.
- If your game **crashes** and you're using **Modlunky2 or Playlunky**:
- If you have proglems with **Modlunky2 or Playlunky**:
+ While we try to keep all the modding tools compatible, some things may break sometimes.
+ Check the [open issues](https://github.com/spelunky-fyi/overlunky/issues) for known compatibility problems with other tools.
- If you're **missing** some overlay **windows** or tabs:
Expand All @@ -148,10 +157,6 @@ Lua scripting is still buggy and unfinished and the **API might change**, althou
+ Use *Game Capture* and disable *Allow Transparency* if Overlunky looks weird/black.
+ Try toggling the *Capture third-party overlays* option in *Game Capture*. It's possible to hide OL if running the game through Steam.
+ If you have lag or crashes, check previous question.
- If you're running **Linux**
+ The game and OL should run fine with Wine 7 if you install DXVK and the steam emu.
+ Also works with Proton 7 using the [command line switch](#command-line-switches) `--launch_playlunky ..` for a non-Steam game shortcut. Just make sure the game and the OL shortcut are set to use Proton 7. **Proton actually seems broken for some reason.**
+ You're still mostly on your own here, this is a Windows 10 program for a Windows 10 game.
- If you **don't have scripts** in the Scripts tab
+ You didn't put them in the right place. [Follow](#installation-and-usage) the [instructions](#scripts).

Expand All @@ -168,6 +173,16 @@ cmake --build . --config Release --target ALL_BUILD
The binaries will be in `build/bin/Release/`. You can also try the scripts in `.vscode` with VSCode. Set `OL_DEBUG=1` in the *game environment* to enable logging to console. (Run `setx OL_DEBUG 1` to do this system-wide.)

## Command line switches
- `--launch_game <path_to_game_directory>` will launch Spel2.exe from that directory and hook to the game process, rather than trying to find it.
- `--launch_playlunky <path_to_game_directory>` will launch playlunky_launcher.exe from that directory and hook to the game process.
These can be used with Steam, also on Linux, by adding Overlunky.exe as a non-Steam game and adding to launch options.

```
--launch_game [path] launch ../Spel2.exe, path/Spel2.exe, or a specific exe, and load OL with Detours
--console keep console open to debug scripts etc
--inject use the old injection method instead of Detours with --launch_game
--info_dump output a bunch of game data to 'Spelunky 2/game_data'
--update reset AutoUpdate setting and update launcher and DLL to the latest WHIP build
--update_launcher update launcher to the latest WHIP build
--help show this helpful help
--version show version information
```

Without `--launch_game` the launcher will try to find a running instance of Spel2.exe and inject to it. `--launch_game` can be used with Steam, also on Linux, by adding `Overlunky.exe` as a non-Steam game and adding it to **launch options under properties**. If Overlunky is installed in the default location under `Spelunky 2/Overlunky`, a simple `--launch_game` should work. If you want to use **Overlunky with Playlunky** on Steam, you can use launch `playlunky_launcher.exe` with the `-overlunky` launch option.
9 changes: 5 additions & 4 deletions src/game_api/memory.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <Windows.h> // for GetModuleHandleA, LPVOID
#include <cstddef> // for size_t, byte, NULL
#include <cstdint> // for int32_t, int64_t, uint32_t, uint64_t, uint8_t
#include <Windows.h> // for GetModuleHandleA, LPVOID
#include <cstddef> // for size_t, byte, NULL
#include <cstdint> // for int32_t, int64_t, uint32_t, uint64_t, uint8_t
#include <filesystem>
#include <memory> // for unique_ptr
#include <string> // for string, string_literals
#include <string_view> // for string_view
Expand Down Expand Up @@ -52,7 +53,7 @@ struct Memory
{
static Memory mem{[]()
{
auto exe = (size_t)GetModuleHandleA("Spel2.exe");
auto exe = (size_t)GetModuleHandleA(NULL);

// Skipping bundle for faster memory search
auto after_bundle_ = find_after_bundle(exe);
Expand Down
29 changes: 15 additions & 14 deletions src/game_api/script/lua_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@
#include <utility> // for min, max, pair, get
#include <vector> // for vector, _Vector_i...

#include "aliases.hpp" // for CallbackId, ENT_TYPE
#include "color.hpp" // for Color
#include "entities_chars.hpp" // for Player
#include "entities_items.hpp" // for Container, Player...
#include "entity.hpp" // for get_entity_ptr
#include "game_manager.hpp" // for get_game_manager
#include "items.hpp" // for Inventory
#include "layer.hpp" // for g_level_max_x
#include "lua_backend.hpp" // for LuaBackend, ON
#include "lua_console.hpp" // for LuaConsole
#include "lua_libs/lua_libs.hpp" // for require_format_lua
#include "lua_require.hpp" // for register_custom_r...
#include "math.hpp" // for AABB
#include "aliases.hpp" // for CallbackId, ENT_TYPE
#include "color.hpp" // for Color
#include "entities_chars.hpp" // for Player
#include "entities_items.hpp" // for Container, Player...
#include "entity.hpp" // for get_entity_ptr
#include "game_manager.hpp" // for get_game_manager
#include "items.hpp" // for Inventory
#include "layer.hpp" // for g_level_max_x
#include "lua_backend.hpp" // for LuaBackend, ON
#include "lua_console.hpp" // for LuaConsole
#include "lua_libs/lua_libs.hpp" // for require_format_lua
#include "lua_require.hpp" // for register_custom_r...
#include "math.hpp" // for AABB
#include "memory.hpp"
#include "movable.hpp" // for Movable
#include "online.hpp" // for get_online
#include "overloaded.hpp" // for overloaded
Expand Down Expand Up @@ -1856,7 +1857,7 @@ end
/// Get the rva for a pattern name
lua["get_rva"] = [](std::string_view address_name) -> size_t
{
return get_address(address_name) - (size_t)GetModuleHandleA("Spel2.exe"); // shouldn't this be - Memory::get().at_exe(0) ?
return get_address(address_name) - Memory::get().at_exe(0);
};

/// Log to spelunky.log
Expand Down
13 changes: 12 additions & 1 deletion src/game_api/window_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
#include "logger.h"
#include "memory.hpp"

bool detect_wine()
{
static const HMODULE hntdll = GetModuleHandle("ntdll.dll");
if (!hntdll)
return false;
static const void* wgv = GetProcAddress(hntdll, "wine_get_version");
if (!wgv)
return false;
return true;
}

IDXGISwapChain* g_SwapChain{nullptr};
ID3D11Device* g_Device{nullptr};
ID3D11DeviceContext* g_Context{nullptr};
Expand Down Expand Up @@ -311,7 +322,7 @@ void hook_steam_overlay()
// Update 2 days later: They immediately changed for the first time in years
// const size_t present_offset = 0x88E30;
// const size_t resize_offset = 0x890F0;
if (steam_overlay == nullptr)
if (steam_overlay == nullptr || detect_wine())
{
// Steam overlay is not loaded, so we're probably running on steam emu
// Just do the old vtable hook and call it a day
Expand Down
2 changes: 2 additions & 0 deletions src/game_api/window_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <Windows.h>

bool detect_wine();

bool init_hooks(void* swap_chain_ptr);

using OnInputCallback = bool (*)(UINT, WPARAM, LPARAM);
Expand Down
15 changes: 13 additions & 2 deletions src/info_dump/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,14 +1077,14 @@ void to_json(float_json& j, const Texture& tex)

using namespace std::chrono_literals;

extern "C" __declspec(dllexport) void run([[maybe_unused]] DWORD pid)
void run()
{
DEBUG("Game injected! Press Ctrl+C to detach this window from the process.");

while (true)
{
auto entities = list_entities();
if (entities.size() >= 850)
if (entities.size() >= 876)
{
DEBUG("Found {} entities, that's enough", entities.size());
std::this_thread::sleep_for(100ms);
Expand Down Expand Up @@ -1357,3 +1357,14 @@ extern "C" __declspec(dllexport) void run([[maybe_unused]] DWORD pid)

std::exit(0);
}

BOOL WINAPI DllMain([[maybe_unused]] HINSTANCE hinst, DWORD dwReason, [[maybe_unused]] LPVOID reserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hinst);
std::thread thr(run);
thr.detach();
}
return TRUE;
}
2 changes: 2 additions & 0 deletions src/injected/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ if(MSVC)
endif()

target_compile_definitions(imgui PUBLIC IMGUI_USE_WCHAR32)

set_target_properties(injected PROPERTIES OUTPUT_NAME Overlunky)
Loading