Skip to content

Commit

Permalink
Update Code to run on Linux & BizHawk 2.9.1 (#34)
Browse files Browse the repository at this point in the history
* Update Code to run on Linux & BizHawk 2.9.1

* Add linux binary generation

* Undo Accidental Refactoring

* Add missing gitkeeps

* Prepare for Pull Request

* Undo gitkeep

* Change savestates to correct case-sensitive extension

* Comment DEBUG message

* Fix Test for case-sensitive OS

* Update README.md
  • Loading branch information
RPGReki authored Feb 10, 2024
1 parent f9ee238 commit 4a57b2c
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 18 deletions.
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
dist/
node_modules/
CurrentRoms/
!sessions/default/CurrentRoms/DeleteMe
CurrentROMs/
CurrentSaves/
!sessions/default/CurrentROMs/.gitkeep
!sessions/default/CurrentSaves/.gitkeep
./config.json
*.exe
config.json
bizhawk-crowd-shuffler-*
!bizhawk-crowd-shuffler-win.bat
!bizhawk-crowd-shuffler-linux.sh
.env
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ npm test
If the Lua script is run outside of the BizHawk environment the test suite at the bottom will be run

```
lua bizhawk-crowd-shuffler.ua
lua bizhawk-crowd-shuffler.lua
```
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@

## Setup

Note this has only been tested with Bizhawk 2.5.x releases
Note this has only been tested with Bizhawk 2.9.1.

1. Install a [2.5.x version](https://github.com/TASVideos/BizHawk/releases/tag/2.5.2) of BizHawk.
1. Install a [2.9.x version](https://github.com/TASVideos/BizHawk/releases/tag/2.9.1) of BizHawk.

2. Download the latest release of this project [bizhawk-crowd-shuffler](https://github.com/alexjpaz-twitch/bizhawk-crowd-shuffler/releases/latest).

3. Create a folder called `bizhawk-crowd-shuffler` where the BizHawk is installed in from **step 1** and unzip the release file from **step 2** inside of the newly created folder.

4. Open the `bizhawk-crowd-shuffler` folder and copy any roms that you want shuffled into the `sessions/default/CurrentRoms` folder
4. Open the `bizhawk-crowd-shuffler` folder and copy any roms that you want shuffled into the `sessions/default/CurrentROMs` folder

5. Edit the `Start.bat` to fill in the `CHANNEL` with your Twitch channel name.
5. Edit the `bizhawk-crowd-shuffler-win.bat` (for Windows) or `bizhawk-crowd-shuffler-win.sh` (for Linux) to fill in the `CHANNEL` with your Twitch channel name.

**Note:** You may have a popup saying "Windows protected your PC". Click *more info* and click "Run anyway"

**Note:** You may have a popup about the "Windows Firewall". You will need to allow access for the applications to work.

**Note:** On Linux, you need to manually run `start-bizhawk-listen-to-crowd-shuffler.sh` to start BizHawk.

## Advanced Setup

Expand Down Expand Up @@ -53,7 +54,7 @@ channel:manage:redemptions channel:read:redemptions user:read:email chat:edit ch

**Note:** Treat the token like a password and do not share that with anyone.

10. Copy the OAuth token into the `Start.bat` file in the `TWITCH_TOKEN` field
10. Copy the OAuth token into the `bizhawk-crowd-shuffler-win.bat` (for Windows) or `bizhawk-crowd-shuffler-win.sh` (for Linux) file in the `TWITCH_TOKEN` field

11. Create redemption named "swap"

Expand Down
11 changes: 11 additions & 0 deletions bizhawk-crowd-shuffler-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

export HOST=127.0.0.1
export PORT=7070
export CHANNEL=MyTwitchChannel
export BIZHAWK_PATH=..\\
export TWITCH_TOKEN=

./bizhawk-crowd-shuffler-linux

# node src
File renamed without changes.
15 changes: 9 additions & 6 deletions bizhawk-crowd-shuffler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ local config = {}

config.sessionPath = os.getenv("session") and os.getenv("session") or 'default'

config.gamePath = ".\\sessions\\" .. config.sessionPath .. "\\CurrentROMs\\"
config.savePath = ".\\sessions\\" .. config.sessionPath .. "\\CurrentSaves\\"
local pathseparator = package.config:sub(1,1)
config.gamePath = "." .. pathseparator .. "sessions" .. pathseparator .. config.sessionPath .. pathseparator .. "CurrentROMs" .. pathseparator
config.savePath = "." .. pathseparator .. "sessions" .. pathseparator .. config.sessionPath .. pathseparator .. "CurrentSaves" .. pathseparator

local frame = 0

Expand All @@ -21,13 +22,13 @@ function commands.switchRom(rom)
print("DEBUG: switchRom=" .. rom)

if(currentGame ) then
savestate.save(config.savePath .. currentGame .. ".state")
savestate.save(config.savePath .. currentGame .. ".State")
end

local nextGame = rom

client.openrom(config.gamePath .. nextGame)
savestate.load(config.savePath .. nextGame .. ".state")
savestate.load(config.savePath .. nextGame .. ".State")

userdata.set("currentGame", nextGame)
end
Expand Down Expand Up @@ -62,12 +63,14 @@ end

local function main()
-- purge socket data
comm.socketServerSetTimeout(14)
comm.socketServerResponse()

while true do -- The main cycle that causes the emulator to advance and trigger a game switch.
frame = frame + 1

if (frame % frame_check_mod) == 0 then
frame = 0
local response = comm.socketServerResponse()

if isempty(response) == false then
Expand Down Expand Up @@ -168,9 +171,9 @@ else

commands.switchRom("bar.nes")

assert(savestate.load__args == config.savePath .. "bar.nes.state")
assert(savestate.load__args == config.savePath .. "bar.nes.State")
assert(userdata.set__value == "bar.nes")
assert(savestate.save__args == config.savePath .. "foo.nes.state")
assert(savestate.save__args == config.savePath .. "foo.nes.State")
assert(client.openrom__args == config.gamePath .. "bar.nes")
end

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"scripts": {
"start": "node src/",
"test": "mocha 'src/*.spec.js'",
"package": "pkg -t node14-win-x64 --out-path=./ src/bin/bizhawk-crowd-shuffler"
"package": "pkg -t node14-win-x64,node14-linux-x64 --out-path=./ src/bin/bizhawk-crowd-shuffler"
},
"keywords": [],
"author": "",
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const logger = console;
const open = require('open');
const net = require('net');

const common = require('./common');
const { RomShuffler } = require('./swap');
const { TwitchShufflerListener } = require('./twitch')

Expand Down Expand Up @@ -49,8 +50,9 @@ const startServer = async () => {
const romName = rom.replace(/\.[a-zA-Z]+$/, '')

twitchShufflerListener.say(`/me Swapping to "${romName}" (${cause})`);
message = `switchRom\t${rom}\n`;
sockets.forEach((sock) => {
sock.write(`switchRom\t${rom}\n`);
sock.write((message.length - 1) + ' ' + message);
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RomShuffler {
}

async fetchCurrentRoms() {
let roms = await fs.readdir(`./sessions/${config.session}/CurrentRoms`);
let roms = await fs.readdir(`./sessions/${config.session}/CurrentROMs`);

return roms;
}
Expand Down
7 changes: 7 additions & 0 deletions start-bizhawk-listen-to-crowd-shuffler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
export HOST=127.0.0.1
export PORT=7070
export BIZHAWK_PATH="${HOME}/Games/PC Games/BizHawk-2.9.1"
export LUA_SCRIPT="$(realpath $(dirname ${BASH_SOURCE}))/bizhawk-crowd-shuffler.lua"

bash "${BIZHAWK_PATH}/EmuHawkMono.sh" "--socket_ip=${HOST}" "--socket_port=${PORT}" "--lua=${LUA_SCRIPT}"

0 comments on commit 4a57b2c

Please sign in to comment.