do local function S(a) return function(b) return { __tag = "S", a, b } end end local function MkSome(a) return function(b) return { __tag = "MkSome", a, b } end end local Proxy = { __tag = "Proxy" } local function Some(a) return { __tag = "Some", a } end local Nil = { __tag = "Nil" } local None = { __tag = "None" } local function _TypeRep(x) return { { name = x.name .. "#" .. x.fingerprint }, __tag = "TypeRep" } end local function __eq_type_rep(tr_a, tr_b, keq, kne) if tr_a[1].name == tr_b[1].name then return keq()() else return kne() end end local function _Typeable_app(pair) local ta, tb = pair._1[1], pair._2[1] return { { name = "(" .. ta.name .. ") :$ (" .. tb.name .. ")" }, __tag = "TypeRep" } end local string_of_int = tostring local function _dollardExceptionljv(tmp) return { from_exception = function(x) return Some(x) end, ["Exception$lae"] = _Typeable_app({ _1 = (function(tmp0) return _TypeRep({ fingerprint = 271, name = "some" }) end)(), _2 = (function(tmp0) return _TypeRep({ fingerprint = 276, name = "exception" }) end)() }), describe_exception = function(tmp0) return tmp0[1].describe_exception(tmp0[2]) end, into_exception = function(x) return x end } end local function from_exception(mdm, mgf) local tmp = (function(tmp) return _TypeRep({ fingerprint = 304, name = "user_error" }) end)() local x = mgf[2] return __eq_type_rep((function() return mgf[1]["Exception$lae"] end)(Proxy), (function() return tmp end)(Proxy), function(tmp0) return function(tmp1) return Some(x) end end, function(tmp0) return None end) end local function from_exception0(mdm) return function(mgf) return from_exception(mdm, mgf) end end local function _dollardExceptionmcp(tmp) return { describe_exception = function(tmp0) return "User error: " .. tmp0 end, ["Exception$lae"] = (function(tmp0) return _TypeRep({ fingerprint = 304, name = "user_error" }) end)(), into_exception = function(mgv) return MkSome(_dollardExceptionmcp(nil))(mgv) end, from_exception = from_exception0(tmp) } end local function _dollarfoldr(ukg) return function(f) return function(z) local function loop(k, x) if x.__tag ~= "Cons" then return k(z) end local tmp = x[1] local x0 = tmp._1 return loop(function(r) return k(f(x0)(r)) end, tmp._2) end return function(x) return loop(function(x0) return x0 end, x) end end end end local _dollardFoldableujg, foldl1, foldl10 _dollardFoldableujg = function(tmp) return { foldl1 = foldl1(tmp), foldr = _dollarfoldr(tmp), ["Foldable$tre"] = function(f) return function(xs) local function avi(xss) if xss.__tag ~= "Cons" then return Nil end local tmp0 = xss[1] return { { _1 = f(tmp0._1), _2 = avi(tmp0._2) }, __tag = "Cons" } end return avi(xs) end end, foldl = function(f) local function loop(z) return function(x) if x.__tag ~= "Cons" then return z end local tmp0 = x[1] return loop(f(z)(tmp0._1))(tmp0._2) end end return loop end } end foldl1 = function(ukg) return function(uvw) return function(uvx) return foldl10(ukg, uvw, uvx) end end end foldl10 = function(ukg, uvw, uvx) local tmp = _dollardFoldableujg(nil).foldl(function(m) return function(y) if m.__tag == "None" then return Some(y) end return Some(uvw(m[1])(y)) end end)(None)(uvx) if tmp.__tag == "None" then return error(setmetatable(_dollardExceptionmcp(nil).into_exception("foldl1: empty structure"), { __tostring = _dollardExceptionljv(nil).describe_exception })) end return tmp[1] end local io_stdout = io.stdout local io_stderr = io.stderr local io_stdin = io.stdin local read_value_16 = ReadValue16 local set_screen_text = SetScreenText local function pretty_from_record(agyo, a, w) local function smul(s, n) if n <= 0 then return "" end return s .. smul(s, n - 1) end local prep = smul(" ", w) local rf = agyo.fields(a) local x = w + 2 return agyo.name(a) .. " {\n" .. _dollardFoldableujg(nil).foldl(function(acc) return function(f) local name = f._1 local field = f._2 if field.__tag == "S" then return acc .. prep .. " " .. (name .. " = " .. field[1](field[2])) .. ",\n" end return acc .. prep .. " " .. (name .. " = " .. field[1](field[2])(x)) .. ",\n" end end)("")(rf) .. prep .. "}" end local function onScriptStart(tmp) return nil end local function onScriptCancel(tmp) return nil end local function onScriptUpdate(tmp) local u16 = read_value_16(17295140) local function tmp0(save_ctx) return set_screen_text(pretty_from_record({ fields = function(tmp0) return { { _2 = Nil, _1 = { _1 = "rupees", _2 = S(function(tmp1) return string_of_int(tmp1) .. "_s16" end)(tmp0.rupees) } }, __tag = "Cons" } end, name = function(tmp0) return "SaveContext" end }, save_ctx, 0)) end if u16 > 32767 then return tmp0({ rupees = 0 - (65536 - u16) }) end return tmp0({ rupees = u16 }) end local function onStateLoaded(tmp) return nil end local function onStateSaved(tmp) return nil end return { base_address = 16138528, g_save_ctx_address = 1156560, onScriptCancel = onScriptCancel, onScriptStart = onScriptStart, onScriptUpdate = onScriptUpdate, onStateLoaded = onStateLoaded, onStateSaved = onStateSaved } end