mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Made cross calls work within the same lua context
This commit is contained in:
parent
2bd62e5484
commit
628572af84
23 changed files with 56 additions and 45 deletions
|
@ -27,14 +27,6 @@ ctx.init = function()
|
||||||
ctx.host_frame_num = 0
|
ctx.host_frame_num = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_host_frame_num", function()
|
|
||||||
if ctx.my_id == ctx.host_id then
|
|
||||||
return GameGetFrameNum()
|
|
||||||
else
|
|
||||||
return ctx.host_frame_num
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
local function is_measure_perf_enabled()
|
local function is_measure_perf_enabled()
|
||||||
-- return ctx.proxy_opt.debug
|
-- return ctx.proxy_opt.debug
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -324,10 +324,29 @@ function util.deserialize_entity(ent_data, x, y)
|
||||||
np.DeserializeEntity(ent, ent_data, x, y)
|
np.DeserializeEntity(ent, ent_data, x, y)
|
||||||
end
|
end
|
||||||
if EntityGetFirstComponentIncludingDisabled(ent, "WorldStateComponent") ~= nil then
|
if EntityGetFirstComponentIncludingDisabled(ent, "WorldStateComponent") ~= nil then
|
||||||
error("Tried to deserialize WorldStateEntity. The world is screwed.")
|
print("Tried to deserialize WorldStateEntity. The world is screwed.")
|
||||||
EntityKill(ent)
|
EntityKill(ent)
|
||||||
end
|
end
|
||||||
return ent
|
return ent
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local cross_calls = {}
|
||||||
|
|
||||||
|
function util.add_cross_call(name, fn)
|
||||||
|
np.CrossCallAdd(name, fn)
|
||||||
|
cross_calls[name] = fn
|
||||||
|
end
|
||||||
|
|
||||||
|
function CrossCall(name, ...)
|
||||||
|
cross_calls[name](...)
|
||||||
|
end
|
||||||
|
|
||||||
|
util.add_cross_call("ew_host_frame_num", function()
|
||||||
|
if ctx.my_id == ctx.host_id then
|
||||||
|
return GameGetFrameNum()
|
||||||
|
else
|
||||||
|
return ctx.host_frame_num
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
return util
|
return util
|
|
@ -37,7 +37,7 @@ local function damage_received(damage, message, entity_id, add_healing_effect)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_ds_damaged", damage_received)
|
util.add_cross_call("ew_ds_damaged", damage_received)
|
||||||
|
|
||||||
local function do_game_over(message)
|
local function do_game_over(message)
|
||||||
net.proxy_notify_game_over()
|
net.proxy_notify_game_over()
|
||||||
|
@ -215,7 +215,7 @@ function rpc.effect_hearty(applied)
|
||||||
GlobalsSetValue("ew_effect_hearty", tostring(hearty_applied_count))
|
GlobalsSetValue("ew_effect_hearty", tostring(hearty_applied_count))
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_ds_effect_hearty", rpc.effect_hearty)
|
util.add_cross_call("ew_ds_effect_hearty", rpc.effect_hearty)
|
||||||
|
|
||||||
rpc.opts_reliable()
|
rpc.opts_reliable()
|
||||||
function rpc.melee_damage_client(target_peer, damage, message)
|
function rpc.melee_damage_client(target_peer, damage, message)
|
||||||
|
@ -223,6 +223,6 @@ function rpc.melee_damage_client(target_peer, damage, message)
|
||||||
EntityInflictDamage(ctx.my_player.entity, damage, "DAMAGE_MELEE", message, "NONE", 0, 0, 0)
|
EntityInflictDamage(ctx.my_player.entity, damage, "DAMAGE_MELEE", message, "NONE", 0, 0, 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
np.CrossCallAdd("ew_ds_client_damaged", rpc.melee_damage_client)
|
util.add_cross_call("ew_ds_client_damaged", rpc.melee_damage_client)
|
||||||
|
|
||||||
return module
|
return module
|
|
@ -49,7 +49,7 @@ function rpc.gather_and_do_ending(x, y, sx, sy)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_ending_sequence", function(sx, sy, sampo_ent)
|
util.add_cross_call("ew_ending_sequence", function(sx, sy, sampo_ent)
|
||||||
EntityKill(sampo_ent)
|
EntityKill(sampo_ent)
|
||||||
local x, y = EntityGetTransform(ctx.my_player.entity)
|
local x, y = EntityGetTransform(ctx.my_player.entity)
|
||||||
rpc.gather_and_do_ending(x, y, sx, sy)
|
rpc.gather_and_do_ending(x, y, sx, sy)
|
||||||
|
|
|
@ -87,7 +87,7 @@ for filename, _ in pairs(constants.phys_sync_allowed) do
|
||||||
-- util.replace_text_in(filename, 'kill_entity_after_initialized="1"', 'kill_entity_after_initialized="0"')
|
-- util.replace_text_in(filename, 'kill_entity_after_initialized="1"', 'kill_entity_after_initialized="0"')
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_es_death_notify", function(enemy_id, responsible_id)
|
util.add_cross_call("ew_es_death_notify", function(enemy_id, responsible_id)
|
||||||
local player_data = player_fns.get_player_data_by_local_entity_id(responsible_id)
|
local player_data = player_fns.get_player_data_by_local_entity_id(responsible_id)
|
||||||
local responsible
|
local responsible
|
||||||
if player_data ~= nil then
|
if player_data ~= nil then
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
local ffi = require("ffi")
|
local ffi = require("ffi")
|
||||||
local world_ffi = require("noitapatcher.nsew.world_ffi")
|
local world_ffi = require("noitapatcher.nsew.world_ffi")
|
||||||
|
|
||||||
-- np.CrossCallAdd("make_ephemerial", ewext.make_ephemerial)
|
-- util.add_cross_call("make_ephemerial", ewext.make_ephemerial)
|
||||||
|
|
||||||
local initial_world_state_entity = nil
|
local initial_world_state_entity = nil
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,6 @@ function EwHasPersistentFlag(flag)
|
||||||
return has_flag(flag)
|
return has_flag(flag)
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_has_flag", has_flag)
|
util.add_cross_call("ew_has_flag", has_flag)
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -80,11 +80,11 @@ end
|
||||||
|
|
||||||
local conversions = {}
|
local conversions = {}
|
||||||
|
|
||||||
np.CrossCallAdd("ew_fungal_shift_conversion", function(from_mat, to_mat)
|
util.add_cross_call("ew_fungal_shift_conversion", function(from_mat, to_mat)
|
||||||
table.insert(conversions, {from_mat, to_mat})
|
table.insert(conversions, {from_mat, to_mat})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
np.CrossCallAdd("ew_fungal_shift", function(iter, from_material_name)
|
util.add_cross_call("ew_fungal_shift", function(iter, from_material_name)
|
||||||
rpc.fungal_shift(conversions, iter, from_material_name)
|
rpc.fungal_shift(conversions, iter, from_material_name)
|
||||||
conversions = {}
|
conversions = {}
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -19,7 +19,7 @@ function rpc.spawn_gate()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_spawn_gate", function()
|
util.add_cross_call("ew_spawn_gate", function()
|
||||||
rpc.spawn_gate()
|
rpc.spawn_gate()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ function rpc.remote_run_spawn_fn(fn_name, x, y, ...)
|
||||||
run_spawn_fn(fn_name, x, y, ...)
|
run_spawn_fn(fn_name, x, y, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_sync_gen", function(fn_name, x, y, ...)
|
util.add_cross_call("ew_sync_gen", function(fn_name, x, y, ...)
|
||||||
if ctx.is_host then
|
if ctx.is_host then
|
||||||
run_spawn_fn(fn_name, x, y, ...)
|
run_spawn_fn(fn_name, x, y, ...)
|
||||||
else
|
else
|
||||||
|
|
|
@ -54,7 +54,7 @@ function rpc.pet(entity_who_interacted, entity_interacted, num, hx, hy)
|
||||||
GameEntityPlaySound( entity_who_interacted, "pet" )
|
GameEntityPlaySound( entity_who_interacted, "pet" )
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_pet_hamis", function(x, y)
|
util.add_cross_call("ew_pet_hamis", function(x, y)
|
||||||
local hx, hy = EntityGetTransform(y)
|
local hx, hy = EntityGetTransform(y)
|
||||||
local ent = y
|
local ent = y
|
||||||
for a, b in pairs(ctx.entity_by_remote_id) do
|
for a, b in pairs(ctx.entity_by_remote_id) do
|
||||||
|
|
|
@ -82,7 +82,7 @@ function rpc.kolmi_shield(is_on, orbcount)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
np.CrossCallAdd("ew_sampo_spawned", function()
|
util.add_cross_call("ew_sampo_spawned", function()
|
||||||
local sampo_ent = EntityGetClosestWithTag(0, 0, "this_is_sampo")
|
local sampo_ent = EntityGetClosestWithTag(0, 0, "this_is_sampo")
|
||||||
if sampo_ent == nil or sampo_ent == 0 then
|
if sampo_ent == nil or sampo_ent == 0 then
|
||||||
-- In case sampo wasn't actually spawned.
|
-- In case sampo wasn't actually spawned.
|
||||||
|
@ -99,11 +99,11 @@ np.CrossCallAdd("ew_sampo_spawned", function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
np.CrossCallAdd("ew_kolmi_spawn_portal", rpc.spawn_portal)
|
util.add_cross_call("ew_kolmi_spawn_portal", rpc.spawn_portal)
|
||||||
|
|
||||||
np.CrossCallAdd("ew_kolmi_anim", rpc.kolmi_anim)
|
util.add_cross_call("ew_kolmi_anim", rpc.kolmi_anim)
|
||||||
|
|
||||||
np.CrossCallAdd("ew_kolmi_shield", rpc.kolmi_shield)
|
util.add_cross_call("ew_kolmi_shield", rpc.kolmi_shield)
|
||||||
|
|
||||||
local function is_in_box(x1, x2, y1, y2, x, y)
|
local function is_in_box(x1, x2, y1, y2, x, y)
|
||||||
return x1 < x and x < x2 and y1 < y and y < y2
|
return x1 < x and x < x2 and y1 < y and y < y2
|
||||||
|
|
|
@ -20,7 +20,7 @@ local module = {}
|
||||||
|
|
||||||
local last_damage_info = {0, "unknown", 1}
|
local last_damage_info = {0, "unknown", 1}
|
||||||
|
|
||||||
np.CrossCallAdd("ew_damage_message", function(message, entity_thats_responsible)
|
util.add_cross_call("ew_damage_message", function(message, entity_thats_responsible)
|
||||||
last_damage_info = {GameGetFrameNum(), message, entity_thats_responsible}
|
last_damage_info = {GameGetFrameNum(), message, entity_thats_responsible}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -524,7 +524,7 @@ function rpc.melee_damage_client(target_peer, damage, message)
|
||||||
EntityInflictDamage(ctx.my_player.entity, damage, "DAMAGE_MELEE", message, "NONE", 0, 0, 0)
|
EntityInflictDamage(ctx.my_player.entity, damage, "DAMAGE_MELEE", message, "NONE", 0, 0, 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
np.CrossCallAdd("ew_ds_client_damaged", rpc.melee_damage_client)
|
util.add_cross_call("ew_ds_client_damaged", rpc.melee_damage_client)
|
||||||
|
|
||||||
rpc.opts_everywhere()
|
rpc.opts_everywhere()
|
||||||
function rpc.send_status(status)
|
function rpc.send_status(status)
|
||||||
|
|
|
@ -43,17 +43,17 @@ function rpc.modify_max_hp(percent_amount, do_heal)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_perks_modify_max_hp", rpc.modify_max_hp)
|
util.add_cross_call("ew_perks_modify_max_hp", rpc.modify_max_hp)
|
||||||
|
|
||||||
np.CrossCallAdd("ew_ff", function()
|
util.add_cross_call("ew_ff", function()
|
||||||
return ctx.proxy_opt.friendly_fire
|
return ctx.proxy_opt.friendly_fire
|
||||||
end)
|
end)
|
||||||
|
|
||||||
np.CrossCallAdd("ew_perk_ban_list", function()
|
util.add_cross_call("ew_perk_ban_list", function()
|
||||||
return ctx.proxy_opt.perk_ban_list
|
return ctx.proxy_opt.perk_ban_list
|
||||||
end)
|
end)
|
||||||
|
|
||||||
np.CrossCallAdd("ew_randomize_perks", function()
|
util.add_cross_call("ew_randomize_perks", function()
|
||||||
return ctx.proxy_opt.randomize_perks
|
return ctx.proxy_opt.randomize_perks
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,11 @@ function rpc.got_thrown(peer_id, vx, vy)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_potion_mimic_throw", function(item, vx, vy)
|
util.add_cross_call("ew_potion_mimic_throw", function(item, vx, vy)
|
||||||
rpc.got_thrown(player_fns.get_player_data_by_local_entity_id(item).peer_id, vx, vy)
|
rpc.got_thrown(player_fns.get_player_data_by_local_entity_id(item).peer_id, vx, vy)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
np.CrossCallAdd("ew_potion_mimic_pickup", function()
|
util.add_cross_call("ew_potion_mimic_pickup", function()
|
||||||
local inventory_state = player_fns.serialize_items(ctx.my_player)
|
local inventory_state = player_fns.serialize_items(ctx.my_player)
|
||||||
if inventory_state ~= nil then
|
if inventory_state ~= nil then
|
||||||
net.send_player_inventory(inventory_state)
|
net.send_player_inventory(inventory_state)
|
||||||
|
|
|
@ -29,7 +29,7 @@ function rpc.kicked_orb(gid, rx, ry, greed)
|
||||||
drop()
|
drop()
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_kicked_orb", function(entity, entity_who_kicked, greed)
|
util.add_cross_call("ew_kicked_orb", function(entity, entity_who_kicked, greed)
|
||||||
if entity_who_kicked ~= ctx.my_player.entity then
|
if entity_who_kicked ~= ctx.my_player.entity then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,7 +39,7 @@ local function is_sync_item(ent_path)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_spawn_hook_pre", function(ent_path, x, y)
|
util.add_cross_call("ew_spawn_hook_pre", function(ent_path, x, y)
|
||||||
if ctx.is_host then
|
if ctx.is_host then
|
||||||
if is_sync_item(ent_path) then
|
if is_sync_item(ent_path) then
|
||||||
local ent_id = EntityLoad(ent_path, x, y)
|
local ent_id = EntityLoad(ent_path, x, y)
|
||||||
|
@ -57,17 +57,17 @@ np.CrossCallAdd("ew_spawn_hook_pre", function(ent_path, x, y)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
np.CrossCallAdd("ew_action_spawn_hook_pre", function()
|
util.add_cross_call("ew_action_spawn_hook_pre", function()
|
||||||
return (not ctx.proxy_opt.item_dedup) or ctx.is_host
|
return (not ctx.proxy_opt.item_dedup) or ctx.is_host
|
||||||
end)
|
end)
|
||||||
|
|
||||||
np.CrossCallAdd("ew_action_spawn_hook", function(eid)
|
util.add_cross_call("ew_action_spawn_hook", function(eid)
|
||||||
ctx.cap.item_sync.globalize(eid, false)
|
ctx.cap.item_sync.globalize(eid, false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Called after entity was loaded.
|
-- Called after entity was loaded.
|
||||||
-- Might be useless in some cases, as entity was already despawned/serialized due to CameraBoundComponent.
|
-- Might be useless in some cases, as entity was already despawned/serialized due to CameraBoundComponent.
|
||||||
np.CrossCallAdd("ew_spawn_hook_post", function(ent_path, ent)
|
util.add_cross_call("ew_spawn_hook_post", function(ent_path, ent)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
np.CrossCallAdd("ew_refresh_inventory", function()
|
util.add_cross_call("ew_refresh_inventory", function()
|
||||||
local inventory_state = player_fns.serialize_items(ctx.my_player)
|
local inventory_state = player_fns.serialize_items(ctx.my_player)
|
||||||
if inventory_state ~= nil then
|
if inventory_state ~= nil then
|
||||||
net.send_player_inventory(inventory_state)
|
net.send_player_inventory(inventory_state)
|
||||||
|
|
|
@ -25,7 +25,7 @@ function rpc.spawn_stevari(pos_x, pos_y)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_spawn_stevari", function(x, y)
|
util.add_cross_call("ew_spawn_stevari", function(x, y)
|
||||||
rpc.spawn_stevari(x, y)
|
rpc.spawn_stevari(x, y)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,6 @@ function rpc.remote_run_event(id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
np.CrossCallAdd("ew_run_streaming_event", rpc.remote_run_event)
|
util.add_cross_call("ew_run_streaming_event", rpc.remote_run_event)
|
||||||
|
|
||||||
return module
|
return module
|
|
@ -8,7 +8,7 @@ function rpc.charm(gid)
|
||||||
EntityAddComponent2(item, "LuaComponent", {script_source_file = "mods/quant.ew/files/system/wand_charm/charm.lua", remove_after_executed = true})
|
EntityAddComponent2(item, "LuaComponent", {script_source_file = "mods/quant.ew/files/system/wand_charm/charm.lua", remove_after_executed = true})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
np.CrossCallAdd("ew_charm_sync", function(id)
|
util.add_cross_call("ew_charm_sync", function(id)
|
||||||
local gid = EntityGetFirstComponentIncludingDisabled(id, "VariableStorageComponent", "ew_global_item_id")
|
local gid = EntityGetFirstComponentIncludingDisabled(id, "VariableStorageComponent", "ew_global_item_id")
|
||||||
rpc.charm(ComponentGetValue2(gid, "value_string"))
|
rpc.charm(ComponentGetValue2(gid, "value_string"))
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
np.CrossCallAdd("ew_cut_through_world", function(x, min_y, max_y, radius, _radius2)
|
util.add_cross_call("ew_cut_through_world", function(x, min_y, max_y, radius, _radius2)
|
||||||
if ctx.is_host then
|
if ctx.is_host then
|
||||||
net.proxy_send("cut_through_world", x.." "..min_y.." "..max_y.." "..radius)
|
net.proxy_send("cut_through_world", x.." "..min_y.." "..max_y.." "..radius)
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,11 +36,11 @@ ModLuaFileAppend("data/scripts/gun/gun_actions.lua", "mods/quant.ew/files/resour
|
||||||
|
|
||||||
ModMagicNumbersFileAdd("mods/quant.ew/files/magic.xml")
|
ModMagicNumbersFileAdd("mods/quant.ew/files/magic.xml")
|
||||||
|
|
||||||
np.CrossCallAdd("ew_per_peer_seed", function()
|
util.add_cross_call("ew_per_peer_seed", function()
|
||||||
return tonumber(string.sub(ctx.my_id, 8, 12), 16), tonumber(string.sub(ctx.my_id, 12), 16)
|
return tonumber(string.sub(ctx.my_id, 8, 12), 16), tonumber(string.sub(ctx.my_id, 12), 16)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
np.CrossCallAdd("ew_spectator", function()
|
util.add_cross_call("ew_spectator", function()
|
||||||
if ctx.spectating_over_peer_id == nil then
|
if ctx.spectating_over_peer_id == nil then
|
||||||
return ctx.my_player.entity or EntityGetWithTag("player_unit")[1]
|
return ctx.my_player.entity or EntityGetWithTag("player_unit")[1]
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue