From 8e4e763400a5c66d3b23dbecb14ef0a3a2623193 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 1 Jul 2023 15:22:01 +0400 Subject: [PATCH] studio: Add check for BXT TAS editor being enabled --- src/hooks/bxt.rs | 3 +++ src/modules/tas_studio/mod.rs | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/hooks/bxt.rs b/src/hooks/bxt.rs index 9e692a64..a09e760c 100644 --- a/src/hooks/bxt.rs +++ b/src/hooks/bxt.rs @@ -17,12 +17,15 @@ pub static BXT_SIMULATION_IPC_IS_CLIENT_INITIALIZED: Pointer = Pointer::empty(b"bxt_tas_load_script_from_string\0"); +pub static BXT_IS_TAS_EDITOR_ACTIVE: Pointer c_int> = + Pointer::empty(b"bxt_is_tas_editor_active\0"); static POINTERS: &[&dyn PointerTrait] = &[ &BXT_ON_TAS_PLAYBACK_FRAME, &BXT_ON_TAS_PLAYBACK_STOPPED, &BXT_SIMULATION_IPC_IS_CLIENT_INITIALIZED, &BXT_TAS_LOAD_SCRIPT_FROM_STRING, + &BXT_IS_TAS_EDITOR_ACTIVE, ]; #[cfg(unix)] diff --git a/src/modules/tas_studio/mod.rs b/src/modules/tas_studio/mod.rs index 85d91588..b71ef1aa 100644 --- a/src/modules/tas_studio/mod.rs +++ b/src/modules/tas_studio/mod.rs @@ -34,7 +34,7 @@ use super::{hud, Module}; use crate::ffi::buttons::Buttons; use crate::ffi::usercmd::usercmd_s; use crate::handler; -use crate::hooks::bxt::OnTasPlaybackFrameData; +use crate::hooks::bxt::{OnTasPlaybackFrameData, BXT_IS_TAS_EDITOR_ACTIVE}; use crate::hooks::engine::con_print; use crate::hooks::{bxt, client, engine, sdl}; use crate::utils::*; @@ -99,6 +99,7 @@ impl Module for TasStudio { && sdl::SDL_SetRelativeMouseMode.is_set(marker) && sdl::SDL_GetMouseState.is_set(marker) && bxt::BXT_TAS_LOAD_SCRIPT_FROM_STRING.is_set(marker) + && bxt::BXT_IS_TAS_EDITOR_ACTIVE.is_set(marker) && bxt::BXT_ON_TAS_PLAYBACK_FRAME.is_set(marker) && bxt::BXT_ON_TAS_PLAYBACK_STOPPED.is_set(marker) && TriangleDrawing.is_enabled(marker) @@ -1144,6 +1145,21 @@ pub unsafe fn on_tas_playback_stopped(marker: MainThreadMarker) { "host_framerate 0;_bxt_norefresh 0;_bxt_min_frametime 0;bxt_taslog 0;pause\n", ); + if BXT_IS_TAS_EDITOR_ACTIVE.get(marker)() != 0 { + // If the TAS editor got enabled, print a warning message and disable it, but keep + // the TAS studio running. This is because otherwise there's no easy way for the + // user to actually remove the bxt_tas_editor 1 command (since the script is in the + // .hltasproj). + con_print( + marker, + "The Bunnymod XT TAS editor was enabled while playing back the script in the \ + bxt-rs TAS studio! This is not supported. Please remove any bxt_tas_editor 1 \ + commands from the script!\n", + ); + + engine::prepend_command(marker, "bxt_tas_editor 0\n"); + } + State::Editing { editor, last_generation: generation,