mirror of
https://github.com/zenith391/OCEmu.git
synced 2025-10-01 00:57:36 -04:00
Fix the hack
I totally tested the previous hack New hack! Allow us to travel backwards in time, as far as the computer is concerned, that minute long request only took about ~0 seconds
This commit is contained in:
parent
b3494872f1
commit
744e640bea
@ -1,12 +1,12 @@
|
|||||||
local env = ...
|
local env = ...
|
||||||
|
|
||||||
local sok,socket = pcall(require,"socket")
|
local sok,socket = pcall(require,"socket")
|
||||||
local gettime
|
|
||||||
if sok then
|
if sok then
|
||||||
gettime = socket.gettime
|
gettime = socket.gettime
|
||||||
else
|
else
|
||||||
gettime = os.time
|
gettime = os.time
|
||||||
end
|
end
|
||||||
|
timeoffset = 0
|
||||||
|
|
||||||
local tmpaddr = "tmp-address"
|
local tmpaddr = "tmp-address"
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ env.computer = {}
|
|||||||
function env.computer.realTime()
|
function env.computer.realTime()
|
||||||
--TODO
|
--TODO
|
||||||
--cprint("computer.realTime") -- Spammy
|
--cprint("computer.realTime") -- Spammy
|
||||||
return gettime()
|
return gettime()-timeoffset
|
||||||
end
|
end
|
||||||
function env.computer.uptime()
|
function env.computer.uptime()
|
||||||
--TODO
|
--TODO
|
||||||
|
@ -122,11 +122,11 @@ function obj.request(url, postData) -- Starts an HTTP request. If this returns t
|
|||||||
end
|
end
|
||||||
-- TODO: This works ... but is slow.
|
-- TODO: This works ... but is slow.
|
||||||
-- TODO: Infact so slow, it can trigger the machine's sethook, so we have to work around that.
|
-- TODO: Infact so slow, it can trigger the machine's sethook, so we have to work around that.
|
||||||
local hookf,hookm,hookc = debug.gethook()
|
local starttime = gettime()
|
||||||
local co = coroutine.running()
|
|
||||||
debug.sethook(co)
|
|
||||||
local page, err, headers, status = http.request(url, postData)
|
local page, err, headers, status = http.request(url, postData)
|
||||||
debug.sethook(co,hookf,hookm,hookc)
|
local offset = gettime() - starttime
|
||||||
|
timeoffset = timeoffset + offset
|
||||||
|
cprint("(request.hack) Going back in time: " .. offset .. "s")
|
||||||
if not page then
|
if not page then
|
||||||
cprint("(request) request failed",err)
|
cprint("(request) request failed",err)
|
||||||
end
|
end
|
||||||
|
@ -271,6 +271,7 @@ boot_machine()
|
|||||||
|
|
||||||
local resume_thread
|
local resume_thread
|
||||||
function resume_thread(...)
|
function resume_thread(...)
|
||||||
|
timeoffset = 0
|
||||||
if coroutine.status(machine.thread) ~= "dead" then
|
if coroutine.status(machine.thread) ~= "dead" then
|
||||||
cprint("resume",...)
|
cprint("resume",...)
|
||||||
local results = { coroutine.resume(machine.thread, ...) }
|
local results = { coroutine.resume(machine.thread, ...) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user