TwoAbove / noita-tools

A collection of tools for Nolla Game's Noita that help get insight into seeds and find ones with special constraints.
https://www.noitool.com/
MIT License
59 stars 8 forks source link
emscripten noita react typescript wasm webassembly webworker

Noitool

A web app for many things Noita.

Helps you get a specific seed for your specific needs.

Current features include:

Connecting as a compute node

Prerequisites

Installing and connecting

Docker

You can use docker to simply spin up a compute node:

docker run -it -e NOITOOL_USER_ID=xxx ghcr.io/twoabove/noitool-console-search:latest

Or for dev

docker run -it -e NOITOOL_USER_ID=xxx -e NOITOOL_URL=https://dev.noitool.com/ ghcr.io/twoabove/noitool-console-search:latest-dev

CLI

To connect to noitool as a compute node, follow these steps:

git clone https://github.com/TwoAbove/noita-tools.git
cd noita-tools
git checkout master # for https://www.noitool.com
# git checkout develop # for https://dev.noitool.com
npm install --frozen-lockfile
npm run console-build
npm run console-search --userId <your id>

console-search args (or env vars):

Automating deployment of Noitool to several machines

You can use the deploy_to_servers.sh script to deploy to several machines. You need to create .servers file with the following format:

user@server1,,main_user_id
user@server2,dev_user_id,

This is a headerless csv file with the following columns: ssh,main_user_id,dev_user_id.

Note the missing entry for the dev user id on server1 and the missing entry for the main user id on server2. That means that server 1 will connect to the main instance and server 2 will connect to the dev instance without both searchers competing for CPU time.

Then run ./deploy_to_servers.sh to deploy to all servers.

Technical details and implementation details that I found interesting

WASM is shaping up to be a very interesting technology. In our use-case, the communication overhead of JS <-> WASM is usually worth it, but it's the main vector of performance improvements, since we're constantly bouncing between JS and WASM for noita_random calls.

Many parts of the critical core game functions that are needed to generate everything are written in C++. The c++ code is then compiled to wasm and is run in web workers (and partly in the main thread). The performance improvements are 20-fold by transferring seed functions (like randoms and lc & ap recipes) from a typescript implementation to c++, even with the call overhead from worker -> wasm code.

In Noita, for map generation, wang tiles are used. In lua/xml code, ARGB color formats are used for color targeting. In browsers, in general, RGBA is used. The transformed colors (in data json) use RGBA to homogenize color format.

Credits to the developers of similar tools: The code for finding LC and AP values was transferred from noita_unicorn's Program.cs from c# to c++. Also, I took inspiration from cr4xy for extra features. You rock! <3

Development

I use linux or mac for development, so I can't guarantee that everything works on windows. On windows, you can use WSL2 to run the dev environment.

Prerequisites:

Before running npm run dev, please copy the .env.example file to .env.local and fill in the values. For non-patreon and discord features, you can leave the file as-is.

Also, run docker compose up -d to easily spin up a local db instance.

Noita data

You will need to unpack Noita wak data (see here) and copy/link several things into the dataScripts/noita-data folder. Note that translations and fonts are in the main Noita folder, not in the Nolla_Games_Noita folder. Here is the list: data, translations, fonts.

To create a symlink, run ln -s <path to noita data> dataScripts/noita-data/data. For debian, that would be

ln -s ~/.steam/debian-installation/steamapps/compatdata/881100/pfx/drive_c/users/steamuser/AppData/LocalLow/Nolla_Games_Noita/data dataScripts/noita-data/data
ln -s ~/.steam/debian-installation/steamapps/common/Noita/data/translations dataScripts/noita-data/translations
ln -s ~/.steam/debian-installation/steamapps/common/Noita/data/fonts dataScripts/noita-data/fonts

Use the ./dataScripts/full_parse.sh script to clean and parse the data files.

For emscripten, some edits need to be done to enable the closure compiler:

emscripten installation and required changes

I recommend using the git repo to install emsdk. Install the latest version.

Installation (after emscripten): npm i

When running npm run dev a build script will listen to changes in .cpp files and rebuild the wasm files.

For vscode to work with the c++ files, install the c++ extension.

Then, go to C/C++: Edit configurations (UI) and add <emscripten installation path>/upstream/emscripten/cache/** to Include path so that vscode can find the emscripten headers.