forked from hkc/cc-stuff
Reworked wallhack
This commit is contained in:
parent
89f4685a22
commit
1dbf9b56a5
|
@ -8,8 +8,35 @@ _G.canvas3d_src.clear()
|
||||||
_G.canvas3d = canvas3d_src.create()
|
_G.canvas3d = canvas3d_src.create()
|
||||||
|
|
||||||
_G.player = nil
|
_G.player = nil
|
||||||
_G.nearbyEntities = {}
|
_G.surroundings = {
|
||||||
_G.nearbyEntitiesByUUID = {}
|
entities = {},
|
||||||
|
entitiesByUUID = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
table.contains = function(tbl, value)
|
||||||
|
for k, v in pairs(tbl) do
|
||||||
|
if v == value then return true, k end
|
||||||
|
end
|
||||||
|
return false, nil
|
||||||
|
end
|
||||||
|
|
||||||
|
table.keys = function(tbl)
|
||||||
|
local gen = pairs(tbl)
|
||||||
|
local k = nil
|
||||||
|
return function()
|
||||||
|
k = gen(tbl, k)
|
||||||
|
return k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
table.values = function(tbl)
|
||||||
|
local gen = pairs(tbl)
|
||||||
|
local k, v
|
||||||
|
return function()
|
||||||
|
k, v = gen(tbl, k)
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function run_wrapped(func, filename)
|
local function run_wrapped(func, filename)
|
||||||
return function()
|
return function()
|
||||||
|
@ -41,16 +68,16 @@ end
|
||||||
|
|
||||||
print("Loaded " .. #modules .. " modules")
|
print("Loaded " .. #modules .. " modules")
|
||||||
|
|
||||||
local function safeset(func, name, old)
|
local function safeget(func, name, fallback, ...)
|
||||||
if func then
|
if func then
|
||||||
local s, res = pcall(func)
|
local s, res = pcall(func, ...)
|
||||||
if not s then
|
if not s then
|
||||||
print("ERR: " .. name .. " failed: " .. res)
|
printError(name .. " failed: " .. res)
|
||||||
else
|
else
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return old
|
return fallback
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Running...")
|
print("Running...")
|
||||||
|
@ -60,10 +87,7 @@ parallel.waitForAll(function()
|
||||||
local ev = { os.pullEvent("exit") }
|
local ev = { os.pullEvent("exit") }
|
||||||
if ev[1] == "exit" then
|
if ev[1] == "exit" then
|
||||||
_G._running = false
|
_G._running = false
|
||||||
local oldc = term.getTextColor()
|
printError("Caught exit event, shutting down...")
|
||||||
term.setTextColor(colors.red)
|
|
||||||
print("Caught exit event, shutting down...")
|
|
||||||
term.setTextColor(oldc)
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -71,15 +95,28 @@ end,
|
||||||
function() -- Neural Interface coroutine
|
function() -- Neural Interface coroutine
|
||||||
print("NI routine started")
|
print("NI routine started")
|
||||||
while _G._running do
|
while _G._running do
|
||||||
_G.player = safeset(NI.getMetaOwner, "getMetaOwner()", _G.player)
|
_G.player = safeget(NI.getMetaOwner, "getMetaOwner()", _G.player)
|
||||||
_G.nearbyEntities = safeset(NI.sense, "sense()", _G.nearbyEntities or {})
|
|
||||||
_G.nearbyEntitiesByUUID = {}
|
surroundings.entities = safeget(NI.sense, "sense()", surroundings.entities)
|
||||||
for i = 1, #_G.nearbyEntities do
|
|
||||||
_G.nearbyEntitiesByUUID[_G.nearbyEntities[i].id] = _G.nearbyEntities[i]
|
local knownUUIDs = {}
|
||||||
|
for entity in table.values(surroundings.entities) do
|
||||||
|
local s, res = pcall(NI.getMetaByID, entity.id)
|
||||||
|
surroundings.entitiesByUUID[entity.id] = s and res or entity
|
||||||
|
table.insert(knownUUIDs, entity.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for uuid in table.keys(surroundings.entitiesByUUID) do
|
||||||
|
if not table.contains(knownUUIDs, uuid) then
|
||||||
|
surroundings.entitiesByUUID[uuid] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
_G.canvas3d.recenter()
|
_G.canvas3d.recenter()
|
||||||
|
|
||||||
os.sleep(0.05)
|
os.sleep(0.05)
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.canvas3d_src.clear()
|
_G.canvas3d_src.clear()
|
||||||
_G.canvas2d.clear()
|
_G.canvas2d.clear()
|
||||||
end, table.unpack(modules))
|
end, table.unpack(modules))
|
||||||
|
|
|
@ -1,33 +1,64 @@
|
||||||
|
|
||||||
|
local options = {
|
||||||
|
reverse_projection = false,
|
||||||
|
hpbar = {
|
||||||
|
bg = 0x13131355,
|
||||||
|
fg = 0xef787878,
|
||||||
|
txt = 0xffffffff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
local function entityBox(ent)
|
||||||
|
local cube = canvas3d.addBox(ent.x - 0.25, ent.y - 0.25, ent.z - 0.25)
|
||||||
|
local hpbar = canvas3d.addFrame({ ent.x - 0.25, ent.y + 0.25, ent.z - 0.25 })
|
||||||
|
cube.setAlpha(0x20)
|
||||||
|
cube.setDepthTested(false)
|
||||||
|
hpbar.setDepthTested(false)
|
||||||
|
|
||||||
|
local hp_rect_bg = hpbar.addRectangle(-1, -0.25, 2, 0.25, options.hpbar.bg)
|
||||||
|
local hp_rect_fg = hpbar.addRectangle(-1, -0.25, 0, 0.25, options.hpbar.fg)
|
||||||
|
local hp_txt = hpbar.addText({ -1, -0.2 }, ent.name, options.hpbar.txt)
|
||||||
|
|
||||||
|
return {
|
||||||
|
_cube = cube,
|
||||||
|
_hpbar = hpbar,
|
||||||
|
_hp_rect_bg = hp_rect_bg,
|
||||||
|
_hp_rect_fg = hp_rect_fg,
|
||||||
|
_hp_txt = hp_txt,
|
||||||
|
update = function(self, entity)
|
||||||
|
self._cube.setPosition(entity.x - 0.25, entity.y - 0.25, entity.z - 0.25)
|
||||||
|
self._hpbar.setPosition(entity, entity.y + 0.5, entity.z)
|
||||||
|
self._hp_rect_fg.setSize(2 * entity.health / entity.maxHealth, 0.25)
|
||||||
|
self._hp_txt.setText(string.format("%s (%.1f/%.1f)", entity.name, entity.health, entity.maxHealth))
|
||||||
|
end,
|
||||||
|
destroy = function(self)
|
||||||
|
self._cube.remove()
|
||||||
|
self._hpbar.remove()
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
local cache = {}
|
local cache = {}
|
||||||
while _G._running do
|
while _G._running do
|
||||||
for id, entry in pairs(cache) do
|
for uuid in table.keys(cache) do
|
||||||
if nearbyEntitiesByUUID[id] == nil then
|
if surroundings.entitiesByUUID[uuid] == nil then
|
||||||
entry.cube.remove()
|
cache[uuid]:destroy()
|
||||||
entry.frame.remove()
|
cache[uuid] = nil
|
||||||
cache[id] = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for id, entity in pairs(nearbyEntitiesByUUID) do
|
for uuid, entity in pairs(surroundings.entitiesByUUID) do
|
||||||
if id ~= player.id then
|
if cache[uuid] == nil then
|
||||||
if cache[id] == nil then
|
cache[uuid] = entityBox(entity)
|
||||||
cache[id] = {}
|
else
|
||||||
cache[id].cube = canvas3d.addBox(0, 0, 0)
|
cache[uuid]:update(entity)
|
||||||
cache[id].cube.setSize(0.5, 0.5, 0.5)
|
|
||||||
cache[id].frame = canvas3d.addFrame({ 0, 0, 0 })
|
|
||||||
cache[id].text = cache[id].frame.addText({ 0, 0 }, "")
|
|
||||||
end
|
|
||||||
cache[id].cube.setAlpha(0x20)
|
|
||||||
cache[id].cube.setDepthTested(false)
|
|
||||||
cache[id].frame.setDepthTested(false)
|
|
||||||
cache[id].cube.setPosition(entity.x - 0.25, entity.y - 0.25, entity.z - 0.25)
|
|
||||||
cache[id].frame.setPosition(entity.x, entity.y, entity.z)
|
|
||||||
cache[id].text.setAlpha(0xFF)
|
|
||||||
cache[id].text.setText(entity.name .. "\n" .. textutils.serialize(entity))
|
|
||||||
cache[id].text.setColor(0xFF0000FF)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
os.sleep(0.05)
|
os.sleep(0.05)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for uuid in table.keys(cache) do
|
||||||
|
cache[uuid]:destroy()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue