Skip to content

Commit

Permalink
studio: Add check for BXT TAS editor being enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Jul 1, 2023
1 parent 9a3fd91 commit 8e4e763
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/hooks/bxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ pub static BXT_SIMULATION_IPC_IS_CLIENT_INITIALIZED: Pointer<unsafe extern "C" f
Pointer::empty(b"bxt_simulation_ipc_is_client_initialized\0");
pub static BXT_TAS_LOAD_SCRIPT_FROM_STRING: Pointer<unsafe extern "C" fn(*const c_char)> =
Pointer::empty(b"bxt_tas_load_script_from_string\0");
pub static BXT_IS_TAS_EDITOR_ACTIVE: Pointer<unsafe extern "C" fn() -> 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)]
Expand Down
18 changes: 17 additions & 1 deletion src/modules/tas_studio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8e4e763

Please sign in to comment.