From 2a61dd1ae836acd4c0f049830e6428ccf498433f Mon Sep 17 00:00:00 2001 From: huttsMichael Date: Wed, 16 Nov 2022 14:45:17 -0500 Subject: [PATCH 1/7] added frame advance call to client type calls --- hook.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/hook.lua b/hook.lua index 1bdf4ae..46f3b4f 100644 --- a/hook.lua +++ b/hook.lua @@ -83,7 +83,12 @@ qtype = { INPUT = 0; READ = 1; WRITE = 2; - CLIENT = 3 + CLIENT = 3; +} + +-- Cient command types +ctype = { + ADVANCE = 0; } -- Response codes @@ -91,14 +96,15 @@ rcodes = { INPUT = 0; -- Successfully wrote to memory BYTE = 1; -- Successfully read byte INTEGER = 2; -- Successfully read integer - FLOAT = 3; -- Successfully read float + CLIENT = 3; -- Successfully controlled client ERROR = 4; -- Generic error } function format_response(code, message) - emu.frameadvance() + -- emu.frameadvance() -- Format response code and message into a valid response + -- console.log(code, "_", message) return tostring(code) .. '_' .. tostring(message) end @@ -116,6 +122,9 @@ local function handleRequest(data) elseif form == qtype["READ"] then query_type, domain, mem_address = string.match(data, "(%d)%/(.+)%/(.+)%/") mem_address = tonumber(mem_address) + elseif form == qtype["CLIENT"] then + query_type, client_type = string.match(data, "(%d)%/(%d)%/") + client_type = tonumber(client_type) end query_type = tonumber(query_type) @@ -141,6 +150,17 @@ local function handleRequest(data) memory.readbyte(mem_address, domain) ) end + -- [ CLIENT ] + if form == qtype["CLIENT"] then + -- [ FRAME ADVANCE ] + if client_type == ctype["ADVANCE"] then + emu.frameadvance() + return format_response( + rcodes.CLIENT, + true + ) + end + end -- If nothing is matched, From 642e40f9e71766c4f9676f5cfdec4b356d0e8c8e Mon Sep 17 00:00:00 2001 From: huttsMichael Date: Mon, 21 Nov 2022 15:29:58 -0500 Subject: [PATCH 2/7] frame advance feature --- hook.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hook.lua b/hook.lua index 46f3b4f..8750937 100644 --- a/hook.lua +++ b/hook.lua @@ -125,6 +125,9 @@ local function handleRequest(data) elseif form == qtype["CLIENT"] then query_type, client_type = string.match(data, "(%d)%/(%d)%/") client_type = tonumber(client_type) + if client_type == ctype["ADVANCE"] then + frames = string.match(data, "%d%/%d%/(%d)") + end end query_type = tonumber(query_type) @@ -154,7 +157,11 @@ local function handleRequest(data) if form == qtype["CLIENT"] then -- [ FRAME ADVANCE ] if client_type == ctype["ADVANCE"] then - emu.frameadvance() + repeat + emu.frameadvance() + frames = frames - 1 + until (frame <= 0) + return format_response( rcodes.CLIENT, true From c5faf2122dc8972b2baa8cdf9ec391608dd181bb Mon Sep 17 00:00:00 2001 From: huttsMichael Date: Fri, 2 Dec 2022 17:14:35 -0500 Subject: [PATCH 3/7] button table no longer reinstates with every call --- hook.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hook.lua b/hook.lua index 8750937..41e1c1e 100644 --- a/hook.lua +++ b/hook.lua @@ -100,6 +100,7 @@ rcodes = { ERROR = 4; -- Generic error } +button_table = {} function format_response(code, message) -- emu.frameadvance() @@ -115,7 +116,6 @@ local function handleRequest(data) if form == qtype["INPUT"] then -- TODO: make a proper lua table query_type, button_name, button_state = string.match(data, "(%d)%/(.+)%/(.+)%/") - button_table = {} button_table[button_name] = button_state -- console.log("Sending Input:") -- console.log(button_table) From d5adccc01a2e8ff222808a8d204eef52dfa1a2f7 Mon Sep 17 00:00:00 2001 From: huttsMichael Date: Fri, 2 Dec 2022 19:08:11 -0500 Subject: [PATCH 4/7] added save state call --- hook.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hook.lua b/hook.lua index 41e1c1e..8e8a010 100644 --- a/hook.lua +++ b/hook.lua @@ -89,6 +89,8 @@ qtype = { -- Cient command types ctype = { ADVANCE = 0; + SAVE = 1; + LOAD = 2; } -- Response codes @@ -160,8 +162,23 @@ local function handleRequest(data) repeat emu.frameadvance() frames = frames - 1 + joypad.set(button_table) until (frame <= 0) + return format_response( + rcodes.CLIENT, + true + ) + elseif client_type == ctype["SAVE"] then + savestate.saveslot(0) + + return format_response( + rcodes.CLIENT, + true + ) + elseif client_type == ctype["LOAD"] then + savestate.loadslot(0) + return format_response( rcodes.CLIENT, true From cd82bba6abe30c8b0736f9ce4806919a55ef5898 Mon Sep 17 00:00:00 2001 From: huttsMichael Date: Tue, 13 Dec 2022 23:34:45 -0500 Subject: [PATCH 5/7] expanded readme before maing public --- README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a1afe9..2fc5c1d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ -# lua-components -The actual lua contents that Bizhook unzips +# Lua Socket Server and API for Bizhawk + +The Lua socket server usually extracted by Bizhook for use with [AutoHawk](https://github.com/SuperBlueHenBros/middle-tier) in via [AutoHawk-API-Client](https://github.com/SuperBlueHenBros/Bizhook). + +## Information + +hook.lua is a based on OpenDisrupt's Bizhook library but is not compatible with the original API located on [GitLab](https://gitlab.com/OpenDisrupt/bizhook). Please don't contact them regarding any issues encountered when using this fork. This implementation has been completely reworked to support manual frame advancement and automated input as supported in [our fork of the Bizhook API](https://github.com/SuperBlueHenBros/Bizhook). Full credit to [Maximillian Strand](https://gitlab.com/deepadmax) and [Autumn](https://github.com/rosemash/luape) for getting this originally working. + +## Usage + +### Manual + +Open and run with Bizhawk's Lua console + +### Automatic + +Automatically launched with Bizhawk via [AutoHawk](https://github.com/SuperBlueHenBros/middle-tier) once configured. \ No newline at end of file From 98b4d896410102d2e137547a35eb437b92dfd8a6 Mon Sep 17 00:00:00 2001 From: huttsMichael Date: Tue, 13 Dec 2022 23:36:17 -0500 Subject: [PATCH 6/7] slight rewording for clarity --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2fc5c1d..f0b746c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ The Lua socket server usually extracted by Bizhook for use with [AutoHawk](https ## Information -hook.lua is a based on OpenDisrupt's Bizhook library but is not compatible with the original API located on [GitLab](https://gitlab.com/OpenDisrupt/bizhook). Please don't contact them regarding any issues encountered when using this fork. This implementation has been completely reworked to support manual frame advancement and automated input as supported in [our fork of the Bizhook API](https://github.com/SuperBlueHenBros/Bizhook). Full credit to [Maximillian Strand](https://gitlab.com/deepadmax) and [Autumn](https://github.com/rosemash/luape) for getting this originally working. +hook.lua is a based on OpenDisrupt's Bizhook library but is not compatible with the original API located on [GitLab](https://gitlab.com/OpenDisrupt/bizhook). Please don't bother them regarding any issues encountered when using this fork. This implementation has been completely reworked to support manual frame advancement and automated input as supported in [our fork of the Bizhook API](https://github.com/SuperBlueHenBros/Bizhook). Full credit to [Maximillian Strand](https://gitlab.com/deepadmax) and [Autumn](https://github.com/rosemash/luape) for getting this originally working. ## Usage From d588a058a50603b700f1e53f5dea096791035fd3 Mon Sep 17 00:00:00 2001 From: huttsMichael Date: Tue, 13 Dec 2022 23:46:12 -0500 Subject: [PATCH 7/7] better manual usage information via original repo --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f0b746c..d3733c3 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,18 @@ hook.lua is a based on OpenDisrupt's Bizhook library but is not compatible with ## Usage -### Manual +### Manual Server Start-Up -Open and run with Bizhawk's Lua console +#### Opening socket -### Automatic +In Bizhawk, go to `Tools` > `Lua Console`. Select `Open script` and open `hook.lua` from the exported components. + +##### Is it working? + +If it starts successfully, you should see output in Bizhawk's Lua console stating it is running. + +**Note**: Do not try to communicate with the socket *before* the text has disappeared, as it isn't actually opened yet. The message is there to make it clear that the script is running successfully. + +### Automatic Server Start-Up Automatically launched with Bizhawk via [AutoHawk](https://github.com/SuperBlueHenBros/middle-tier) once configured. \ No newline at end of file