Skip to content

Commit

Permalink
Add a VC clones table.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkacjios committed Nov 30, 2020
1 parent adbc55b commit ce74f10
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build/
releases/
nativefiledialog-master/
*.psd
nativefiledialog/
5 changes: 5 additions & 0 deletions source/modules/games/vcclones.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Format ["CLONED VC ID"] = "ORIGINAL VC ID",

return {
["NZTE"] = "NACE", -- The Legend of Zelda - A Missing Link
}
52 changes: 52 additions & 0 deletions source/modules/memory/cloneloader.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
local loader = {}

local log = require("log")

local notification = require("notification")
local configdir = love.filesystem.getSaveDirectory()

function loader.loadFile(file, clonesTbl)
if file and love.filesystem.getInfo(file, "file") then
log.info("[CLONES] Load: %s/%s", configdir, file)

local status, chunk = pcall(love.filesystem.load, file)

if not status then
-- Failed loading chunk, chunk is an error string
log.error(chunk)
notification.error(chunk)
elseif chunk then
-- Create a sandboxed lua environment
local env = {}
env._G = env

-- Set the loaded chunk inside the sandbox
setfenv(chunk, env)

local status, custom_clones = pcall(chunk)
if not status then
-- Failed calling the chunk, custom_clones is an error string
log.error(custom_clones)
notification.error(custom_clones)
else
local num_clones = 0
for clone_id, clones in pairs(custom_clones) do
if type(clones) == "table" then
clonesTbl[clone_id] = {}
for version, info in pairs(clones) do
if info.id and info.version then
num_clones = num_clones + 1
log.debug("[CLONES] %s[%d] = %s[%d]", clone_id, version, info.id, info.version)
clonesTbl[clone_id][version] = info
end
end
end
end
log.info("[CLONES] Loaded %d clones from %s", num_clones, file)
notification.coloredMessage(("Loaded %d clones from %s"):format(num_clones, file))
end
end
end
end

return loader
4 changes: 4 additions & 0 deletions source/modules/memory/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local VC_NONE = "\0\0\0\0"

local memory = {
clones = require("games.clones"),
vcclones = require("games.vcclones"),

gameid = GAME_NONE,
vcid = VC_NONE,
Expand Down Expand Up @@ -430,6 +431,9 @@ function memory.findGame()
memory.ingame = true
memory.vcid = vcid

-- Check for VC clones
vcid = memory.vcclones[vcid] or vcid

memory.loadGameScript(vcid)
elseif (not memory.ingame or meleeMode) and gid ~= GAME_NONE then
memory.reset()
Expand Down

0 comments on commit ce74f10

Please sign in to comment.