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

Default to the ramcontroller that matches the current ROM #47

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions bizhawk-co-op.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ function leaveRoom()
end


--Returns a list of files in a given directory
--Returns a list of files in a given directory in case-insensitive sorted order
function os.dir(dir)
local files = {}
local f = assert(io.popen('dir \"' .. dir .. '\" /b ', 'r'))
local f = assert(io.popen('dir \"' .. dir .. '\" /b /on', 'r'))
for file in f:lines() do
table.insert(files, file)
end
Expand All @@ -235,6 +235,28 @@ function os.dir(dir)
end


--Returns a list of ramcontrollers and the 1-based index of the ramcontroller
--that matches the current ROM. Returns a nil index if none match.
--
--Ramcontrollers may start with the comment '-- romname: <pattern>' to indicate
--what romnames the ramcontroller supports. '<pattern>' should be a valid Lua
--pattern, and is partially matched agains the romname.
function getRamControllers(dir)
local prefix = '-- romname: '
local romname = gameinfo.getromname()
local files = os.dir(dir)
for i, file in ipairs(files) do
local f = assert(io.open(dir .. '\\' .. file))
local line = f:read('*l')
f:close()
if line:sub(1, #prefix) == prefix and string.match(romname, line:sub(#prefix + 1)) then
return files, i
end
end
return files, nil
end


math.randomseed(os.time())

--Create the form
Expand Down Expand Up @@ -270,7 +292,12 @@ txtUser = forms.textbox(mainform, "", 200, 20, nil, 80, 64, false, false)
txtPass = forms.textbox(mainform, "", 200, 20, nil, 80, 88, false, false)
formPlayerNumber = forms.textbox(mainform, "", 200, 20, nil, 80, 114, false, false)
txtPort = forms.textbox(mainform, '50000', 200, 20, nil, 80, 138, false, false)
ddRamCode = forms.dropdown(mainform, os.dir("bizhawk-co-op\\ramcontroller"), 80, 162, 200, 10)
local ramCodes, defaultRamCodeIndex = getRamControllers("bizhawk-co-op\\ramcontroller")
ddRamCode = forms.dropdown(mainform, ramCodes, 80, 162, 200, 10)
if defaultRamCodeIndex then
-- SelectedIndex is 0-based.
forms.setproperty(ddRamCode, "SelectedIndex", defaultRamCodeIndex - 1)
end
lblIP = forms.label(mainform, "Host IP:", 32, 42)
lblUser = forms.label(mainform, "Username:", 19, 66)
lblPass = forms.label(mainform, "Password:", 21, 90)
Expand Down
2 changes: 2 additions & 0 deletions bizhawk-co-op/ramcontroller/Link to the Past.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- romname: Legend of Zelda, The [-] A Link to the Past

local items = {
[0x5A] = 'Nothing',
[0x49] = 'Fighters Sword',
Expand Down
2 changes: 2 additions & 0 deletions bizhawk-co-op/ramcontroller/Metroid Zero Mission.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- romname: Metroid [-] Zero Mission

-- Mapping for the flags of each ability (little endian)
local AbilityMap = {
--longbeam = 0
Expand Down
1 change: 1 addition & 0 deletions bizhawk-co-op/ramcontroller/Ocarina of Time.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- romname: OoTR

console.log('------------------')
local old_global_metatable = getmetatable(_G)
Expand Down