2012-11-11 06:24:13 -07:00
|
|
|
-- Apply or remove binary patches at runtime.
|
|
|
|
|
2012-11-12 01:26:31 -07:00
|
|
|
local bp = require('binpatch')
|
2012-11-11 06:24:13 -07:00
|
|
|
|
|
|
|
function run_command(cmd,name)
|
2012-11-12 01:26:31 -07:00
|
|
|
local pfix = name..': '
|
2012-11-11 06:24:13 -07:00
|
|
|
|
2012-11-12 01:26:31 -07:00
|
|
|
local patch, err = bp.load_dif_file(name)
|
|
|
|
if not patch then
|
|
|
|
dfhack.printerr(pfix..err)
|
2012-11-11 06:24:13 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if cmd == 'check' then
|
2012-11-12 01:26:31 -07:00
|
|
|
local status, addr = patch:status()
|
|
|
|
if status == 'conflict' then
|
|
|
|
dfhack.printerr(string.format('%sconflict at address %x', pfix, addr))
|
2012-11-11 06:24:13 -07:00
|
|
|
else
|
2012-11-12 01:26:31 -07:00
|
|
|
print(pfix..'patch is '..status)
|
2012-11-11 06:24:13 -07:00
|
|
|
end
|
|
|
|
elseif cmd == 'apply' then
|
2012-11-12 01:26:31 -07:00
|
|
|
local ok, msg = patch:apply()
|
2012-11-11 06:24:13 -07:00
|
|
|
if ok then
|
2012-11-12 01:26:31 -07:00
|
|
|
print(pfix..msg)
|
2012-11-11 06:24:13 -07:00
|
|
|
else
|
2012-11-12 01:26:31 -07:00
|
|
|
dfhack.printerr(pfix..msg)
|
2012-11-11 06:24:13 -07:00
|
|
|
end
|
|
|
|
elseif cmd == 'remove' then
|
2012-11-12 01:26:31 -07:00
|
|
|
local ok, msg = patch:remove()
|
2012-11-11 06:24:13 -07:00
|
|
|
if ok then
|
2012-11-12 01:26:31 -07:00
|
|
|
print(pfix..msg)
|
2012-11-11 06:24:13 -07:00
|
|
|
else
|
2012-11-12 01:26:31 -07:00
|
|
|
dfhack.printerr(pfix..msg)
|
2012-11-11 06:24:13 -07:00
|
|
|
end
|
|
|
|
else
|
|
|
|
qerror('Invalid command: '..cmd)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local cmd,name = ...
|
|
|
|
if not cmd or not name then
|
|
|
|
qerror('Usage: binpatch check/apply/remove <patchname>')
|
|
|
|
end
|
|
|
|
run_command(cmd, name)
|