fix friendly fire teams not syncing right sometimes

This commit is contained in:
bgkillas 2024-10-18 07:51:16 -04:00
parent 563a4f3729
commit ac9c5659b3
4 changed files with 14 additions and 15 deletions

View file

@ -60,7 +60,7 @@ can also host via cli, just run `noita_proxy --host [steam/port]`, "--host steam
to connect via steam without the steam version of game, since its more stable you can do the following
on all clients run the game with the NP_APPID=480 environemental variable, you can do that by making a bat/bash file to set that before running the executable
on all clients run the proxy with the NP_APPID=480 environemental variable, you can do that by making a bat/bash file to set that before running the executable
## Thanks

View file

@ -1022,7 +1022,7 @@ impl eframe::App for App {
ui.checkbox(&mut self.app_saved_state.show_extra_debug_stuff, tr("Show-debug-info"));
ui.add_space(15.0);
if self.app_saved_state.game_settings.friendly_fire || netman.settings.lock().map(|a| a.friendly_fire).unwrap_or(false) {
if self.app_saved_state.game_settings.friendly_fire || netman.friendly_fire.load(Ordering::Relaxed) {
let last = self.app_saved_state.game_settings.friendly_fire_team;
ui.add(Slider::new(&mut self.app_saved_state.game_settings.friendly_fire_team, -1..=16));
if last != self.app_saved_state.game_settings.friendly_fire_team {

View file

@ -130,6 +130,7 @@ pub struct NetManager {
pub end_run: AtomicBool,
pub debug_markers: Mutex<Vec<DebugMarker>>,
pub friendly_fire_team: AtomicI32,
pub friendly_fire: AtomicBool,
}
impl NetManager {
@ -149,6 +150,7 @@ impl NetManager {
end_run: AtomicBool::new(false),
debug_markers: Default::default(),
friendly_fire_team: AtomicI32::new(-2),
friendly_fire: AtomicBool::new(false),
}
.into()
}
@ -190,13 +192,6 @@ impl NetManager {
File::create(player_path.parent().unwrap().join("tmp/no_amulet_gem"))?;
}
let mut last_team = -2;
if let Ok(n) = self.settings.lock() {
last_team = n.friendly_fire_team;
self.friendly_fire_team
.store(last_team, atomic::Ordering::Relaxed);
}
let socket = Socket::new(Domain::IPV4, Type::STREAM, None)?;
// This allows several proxies to listen on the same address.
// While this works, I couldn't get Noita to reliably connect to correct proxy instances on my os (linux).
@ -241,6 +236,7 @@ impl NetManager {
&self.init_settings.player_png_desc,
self.is_host(),
);
let mut timer = Instant::now();
while self.continue_running.load(atomic::Ordering::Relaxed) {
if cli {
if let Some(n) = self.peer.lobby_id() {
@ -248,10 +244,12 @@ impl NetManager {
cli = false
}
}
let team = self.friendly_fire_team.load(atomic::Ordering::Relaxed);
if team != last_team {
last_team = team;
state.try_ws_write_option("friendly_fire_team", (team + 1) as u32);
if self.friendly_fire.load(atomic::Ordering::Relaxed) {
let team = self.friendly_fire_team.load(atomic::Ordering::Relaxed);
if timer.elapsed().as_secs() > 2 {
state.try_ws_write_option("friendly_fire_team", (team + 1) as u32);
timer = Instant::now()
}
}
if self.end_run.load(atomic::Ordering::Relaxed) {
for id in self.peer.iter_peer_ids() {
@ -453,6 +451,7 @@ impl NetManager {
} else {
info!("No nickname chosen");
}
self.friendly_fire.store(settings.friendly_fire, atomic::Ordering::Relaxed);
state.try_ws_write_option("friendly_fire", settings.friendly_fire);
state.try_ws_write_option("debug", settings.debug_mode);
state.try_ws_write_option("world_sync_version", settings.world_sync_version);

View file

@ -14,7 +14,7 @@ function rpc.player_update(input_data, pos_data, current_slot, team)
end
local player_data = player_fns.peer_get_player_data(peer_id)
if team ~= nil and not GameHasFlagRun("ending_game_completed") and not EntityHasTag(player_data.entity, "ew_notplayer") then
if team ~= nil and not GameHasFlagRun("ending_game_completed") and not EntityHasTag(player_data.entity, "ew_notplayer") and ctx.proxy_opt.friendly_fire_team ~= nil then
local my_team = ctx.proxy_opt.friendly_fire_team - 1
if my_team ~= -1 and team ~= -1 and (team == 0 or my_team == 0 or team ~= my_team) then
GenomeSetHerdId(player_data.entity, "player_pvp")
@ -51,7 +51,7 @@ function module.on_world_update()
local current_slot = player_fns.get_current_slot(ctx.my_player)
if input_data ~= nil and pos_data ~= nil then
local my_team
if ctx.proxy_opt.friendly_fire and GameGetFrameNum() % 60 == 43 then
if ctx.proxy_opt.friendly_fire and GameGetFrameNum() % 60 == 43 and ctx.proxy_opt.friendly_fire_team ~= nil then
my_team = ctx.proxy_opt.friendly_fire_team - 1
end