The opening movie plays on first boot and from Cinematics (#2398)

The opening movie never played. `StartMovie` returned nil, so the stock `MovieFrame` hid at once.

1.12.1's movie frame (`0x78ce40`) reads the AVI, decodes, and streams the MP3. Its clock is the audio's play time, or the wall clock without audio. It shows clock × rate frames, decoding skipped ones unseen (`0x78cf30`). It reads `.sbt` captions (`0x78cb00`), and draws 2 or 6 tiles with the picture 24 or 6 rows up (`0x81d400`). On first boot the `movie` CVar flips to "0" and opens the movie screen (`0x402b3b`).

benilla now does all of that on the decoder crate, along with `StopMovie`, `EnableSubtitles`, `OnMovieFinished` (including on teardown), the captions' show and hide handlers, and screenshots waiting while a movie plays. Unattended runs skip the movie.

Tests cover each of these. Live, the logo and the intro played through to login.

Fixes #968

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sam Sung
2026-10-25 15:49:14 +07:00
committed by GitHub
parent 96356c7984
commit 1befd0404d
32 changed files with 2184 additions and 182 deletions
Generated
+2
View File
@@ -503,6 +503,7 @@ dependencies = [
"avian3d",
"benilla-assets",
"benilla-formats",
"benilla-movie",
"benilla-protocol",
"benilla-srp",
"benilla-ui",
@@ -665,6 +666,7 @@ name = "benilla-ui"
version = "0.2.0"
dependencies = [
"benilla-mlua",
"benilla-movie",
"libc",
"roxmltree",
]
+2
View File
@@ -124,6 +124,8 @@ windows-sys = { version = "0.59", features = [
# The login cycle's fake realmd runs the server half of SRP6 (`net::io::cycle_tests`).
[dev-dependencies]
benilla-srp = { path = "../benilla-srp" }
# The synthetic movie the movie screen's tests open.
benilla-movie = { path = "../benilla-movie", features = ["test-support"] }
# The UI's geometry comparisons (`benilla_ui::assert_near!`).
benilla-ui = { path = "../benilla-ui", features = ["test-support"] }
# The schedule census keeps the build's own graph, sync points included, through a build pass,
-1
View File
@@ -237,7 +237,6 @@ pub(super) const INERT: &[Registered] = &[
same("MapWaterSounds", "1"), // 0x462ac9
same("MaxLights", "4").checked(benilla_ui::script::check_max_lights), // 0x688596
same("mouseInvertYaw", "0"), // 0x50b72d
same("movie", "1"), // 0x402bf5
same("ObjectSelectionCircle", "1"), // 0x6146ec
same("occlusion", "1"), // 0x6888da
same("particleDensity", "1.0").checked(benilla_ui::script::check_particle_density), // 0x688738
+6 -2
View File
@@ -785,9 +785,13 @@ pub(crate) const REGISTERED: &[Registered] = &[
// World LOD: bit 2 of `[0xc7b2a4]`, which gates the doodad LOD distance test at `0x6afb11`. No
// effect here: benilla has no doodad LOD swap, as `lodDist` above has no row.
same("lod", "1"),
// `movie` (`0x402bf5`: name `0x82e74c`, "1", flags 0, record `[0x8826e0]`), Show movie on
// startup: the startup puts the intro movies up while it is 1, setting it to "0"
// (`0x402b3b`-`0x402b65`, `ui_script::glue::startup_screen`).
same("movie", "1"),
// `movieSubtitle` (`0x402c18`: name `0x82e9d8`, "0", flags 0, record `[0x882640]`), Cinematic
// Subtitles: the pre-rendered movies' subtitles, read by the glue's `GetMovieSubtitles`
// (`0x46dbc0`). No effect here: benilla plays no pre-rendered movie.
// Subtitles: the pre-rendered movies' subtitles, which the glue's `GetMovieSubtitles`
// (`0x46dbc0`) hands the movie frame's `EnableSubtitles` (`MovieFrame.lua:35`).
same("movieSubtitle", "0"),
// `useWeatherShaders` (`0x67b81d`: name `0x868598`, "1", flags 0, no callback, record
// `[0xc7b588]`), Weather Shaders: read in each precipitation effect's constructor (`0x67480f`,
+4
View File
@@ -2005,6 +2005,10 @@ pub(crate) mod schedule_tests {
"it acts only on a glue-kind VM (`script.filter(vm_kind() == Glue)`, documented at the fire sites), never the entry VM the window leaves frameless; news that arrives with no glue VM is held in `AddonInfoReply` for the next one"),
("ui_script/extract/mod.rs", "paint_script", Because::Deliberate,
"per-frame paint and cost state, not a queue"),
("ui_script/movie.rs", "feed_movie_audio", Because::SelfHealing,
"its takes are the sound side's stream reports, sent again every frame and keyed by a movie number only the VM that started the movie holds, and the VM's own audio starts, which only `StartMovie` leaves"),
("ui_script/movie.rs", "upload_movie_pictures", Because::Deliberate,
"per-frame upload scratch, not a queue: it reads each playing movie's picture as it stands"),
("ui_social/feed.rs", "feed_social", Because::Deliberate,
"its take is the handlers' list events and lines: those taken into the glue VM are lost there, and the in-game VM's first feed fires both list events again over the lists as they stand"),
("ui_stable/mod.rs", "feed_stable", Because::PlayerRoundTrip,
+42 -1
View File
@@ -95,13 +95,20 @@ impl ScreenshotState {
}
/// Captures each `Screenshot()` one frame after the call. Spawn last frame's asks before draining
/// this frame's: that order is the one-frame hold (module doc).
/// this frame's: that order is the one-frame hold (module doc). While a movie plays the frame pass
/// skips its present block, the capture in it (`0x44267c`), so the asks wait for its end.
fn ask_for_captures(
mut commands: Commands,
mut hosted_vm: crate::script_calls::HostedVm,
mut state: ResMut<ScreenshotState>,
) {
hosted_vm.run(|script| {
if script
.as_deref()
.is_some_and(benilla_ui::script::UiScript::movie_playing)
{
return;
}
spawn_captures(&mut commands, std::mem::take(&mut state.pending));
if let Some(script) = script {
state.pending += script.take_screenshot_asks();
@@ -327,6 +334,40 @@ mod tests {
}
/// The real [`ask_for_captures`] with no VM, as at character select.
/// While a movie plays the frame pass presents nothing, so an ask waits (`0x44267c`): no
/// capture until the movie stops, then the held one.
#[test]
fn an_ask_waits_while_a_movie_plays() {
let mut s = benilla_ui::script::UiScript::new_glue().unwrap();
s.set_movie_reader(Box::new(|path, _| {
path.ends_with(".avi").then(|| {
benilla_movie::testing::synthetic_avi(1024, 464, (1, 25), 9, &[&[][..]; 9], &[])
})
}));
s.run(r#"M = CreateFrame("MovieFrame", "MovieProbe") M:StartMovie("A")"#)
.unwrap();
let mut app = App::new();
app.init_resource::<ScreenshotState>();
app.insert_non_send_resource(s);
app.add_systems(Update, ask_for_captures);
app.world_mut().resource_mut::<ScreenshotState>().pending = 1;
let shots = |app: &mut App| {
app.world_mut()
.query::<&Screenshot>()
.iter(app.world())
.count()
};
app.update();
app.update();
assert_eq!(shots(&mut app), 0, "held while the movie plays");
app.world()
.non_send_resource::<benilla_ui::script::UiScript>()
.run("M:StopMovie()")
.unwrap();
app.update();
assert_eq!(shots(&mut app), 1, "taken once it stops");
}
fn spawn_pending_only(mut commands: Commands, mut state: ResMut<ScreenshotState>) {
spawn_captures(&mut commands, std::mem::take(&mut state.pending));
}
+11 -1
View File
@@ -32,6 +32,7 @@ mod mix_tap;
mod mixer;
mod money;
mod mount;
mod movie;
mod net;
// Crate-visible for the dev stall watchdog, which asks `output::device_open`.
pub(crate) mod output;
@@ -56,6 +57,7 @@ pub(crate) use greeting::NpcGreetingRequest;
pub(crate) use kit::SoundKits;
pub(crate) use message::MessageSounds;
pub(crate) use mixer::Mixer;
pub(crate) use movie::{MovieAudioReports, MovieAudioRequest};
#[cfg(test)]
pub(crate) use spell::HoldLoops;
pub(crate) use ui::{AutoEquipSound, LootPickupSound};
@@ -241,6 +243,8 @@ pub(crate) struct SoundOutput {
pub(crate) zone_streams: usize,
pub(crate) glue_streams: usize,
pub(crate) cinematic_streams: usize,
/// The movie frame's audio ([`movie`]).
pub(crate) movie_streams: usize,
/// One-shots that lost their slot to a louder newcomer, and plays refused because nothing
/// live was quieter.
pub(crate) voices_stolen: u64,
@@ -252,7 +256,11 @@ pub(crate) struct SoundOutput {
impl SoundOutput {
/// Everything the device is mixing, the number [`kit::SOFTWARE_CHANNELS`] bounds.
pub(crate) fn live_voices(&self) -> usize {
self.channels.len() + self.zone_streams + self.glue_streams + self.cinematic_streams
self.channels.len()
+ self.zone_streams
+ self.glue_streams
+ self.cinematic_streams
+ self.movie_streams
}
}
@@ -387,6 +395,7 @@ impl Plugin for SoundPlugin {
zone_streams: 0,
glue_streams: 0,
cinematic_streams: 0,
movie_streams: 0,
voices_stolen: 0,
voices_denied: 0,
copies_dropped: 0,
@@ -436,6 +445,7 @@ impl Plugin for SoundPlugin {
vocal::plugin(app);
message::plugin(app);
glue::plugin(app);
movie::plugin(app);
money::plugin(app);
reverb::plugin(app);
interior::plugin(app);
+110
View File
@@ -0,0 +1,110 @@
//! The movie frame's audio: each movie's MP3 stream, opened from the AVI's audio chunks as the
//! reference's `0x78ca30` opens a memory stream (`FSOUND_Stream_Open` with `0x8000`, then
//! `FSOUND_Stream_Play` on channel 0, its volume never set). The movie feed
//! (`ui_script::movie`) asks for each stream and its stop, and reads back each stream's play
//! time or end, which the movie's clock steps on.
use std::collections::HashMap;
use bevy::prelude::*;
use benilla_ui::script::MovieAudio;
use super::{mixer, SoundConfig, SoundOutput};
/// The movie feed's asks, by movie number.
#[derive(Message, Clone, Debug)]
pub(crate) enum MovieAudioRequest {
/// Open and play this movie's audio.
Start { id: u64, mp3: Vec<u8> },
/// The movie stopped: its stream stops with it (`0x78caa0`).
Stop { id: u64 },
}
/// What the streams did since the feed last read: a failed open, then each stream's play time
/// or its end, by movie number.
#[derive(Resource, Default)]
pub(crate) struct MovieAudioReports(pub(crate) Vec<(u64, MovieAudio)>);
/// The streams the movies hold, by movie number.
#[derive(Default)]
struct MovieStreams(HashMap<u64, mixer::StreamingSoundHandle<kira::sound::FromFileError>>);
/// Carry out the feed's asks and report every stream. With sound off, or no device, no stream
/// opens and the movie runs on the wall clock, as an open fails with FMOD not started.
fn drive_movie_audio(
mut requests: MessageReader<MovieAudioRequest>,
mut streams: NonSendMut<MovieStreams>,
mut out: NonSendMut<SoundOutput>,
config: Res<SoundConfig>,
mut reports: ResMut<MovieAudioReports>,
) {
for request in requests.read() {
match request {
MovieAudioRequest::Start { id, mp3 } => {
match open_stream(&mut out, &config, mp3.clone()) {
Some(h) => {
// A number is never handed out twice; a stream under it would leak.
if let Some(mut old) = streams.0.insert(*id, h) {
old.stop(mixer::fade(0));
}
}
None => reports.0.push((*id, MovieAudio::Failed)),
}
}
MovieAudioRequest::Stop { id } => {
if let Some(mut h) = streams.0.remove(id) {
h.stop(mixer::fade(0));
}
}
}
}
for (&id, h) in &streams.0 {
let report = if h.state() == kira::sound::PlaybackState::Stopped {
MovieAudio::Ended
} else {
MovieAudio::At((h.position() * 1000.0) as u32)
};
reports.0.push((id, report));
}
out.movie_streams = streams
.0
.values()
.filter(|h| h.state() != kira::sound::PlaybackState::Stopped)
.count();
}
/// The stream at full volume: the reference sets none on the channel it plays.
fn open_stream(
out: &mut SoundOutput,
config: &SoundConfig,
mp3: Vec<u8>,
) -> Option<mixer::StreamingSoundHandle<kira::sound::FromFileError>> {
if !config.enabled {
return None;
}
let mixer = out.mixer.as_mut()?;
let data = mixer::stream_from_bytes(mp3)
.inspect_err(|e| warn!("movie audio: {e:#}"))
.ok()?;
mixer
.play_stream(data)
.inspect_err(|e| warn!("movie audio: {e:#}"))
.ok()
}
pub(super) fn plugin(app: &mut App) {
app.add_message::<MovieAudioRequest>()
.init_resource::<MovieAudioReports>()
.insert_non_send_resource(MovieStreams::default())
.add_systems(
Update,
// After the feed's asks and the tick, its reports reaching the next frame's feed;
// after the frame's mute toggle and the cinematic's music hold settle the config it
// opens under, and after the streaming stage's main-thread work.
drive_movie_audio
.after(crate::ui_script::UiTick)
.after(super::toggle_mute)
.after(benilla_world::schedule::WorldStage::Stream),
);
}
+1 -1
View File
@@ -535,7 +535,7 @@ fn feed_tutorials(
/// Before the feed: the selections' ladder (`0x493789`-`0x49383c`), in their order, each judged
/// against the bank as the ones before it left it.
fn judge_selections(
pub(crate) fn judge_selections(
tutorials: Res<Tutorials>,
self_q: Query<&ObjectStore, With<SelfPlayer>>,
stores: Query<&ObjectStore>,
@@ -97,6 +97,7 @@ fn content_kind(c: &QuadContent) -> &'static str {
QuadContent::Texture { .. } => "texture",
QuadContent::ColorWheel => "colorwheel",
QuadContent::ColorValue { .. } => "colorvalue",
QuadContent::Movie { .. } => "movie",
QuadContent::Text { .. } => "text",
}
}
@@ -305,6 +306,7 @@ fn splice_simple(eq: &benilla_ui::script::ExtractedQuad) -> bool {
QuadContent::Frame
// At most one quad and one idempotent tile request.
| QuadContent::ModelPane { .. }
| QuadContent::Movie { .. }
| QuadContent::ColorWheel
| QuadContent::ColorValue { .. } => true,
// Region text only: a message line's link spans replace the whole set, and a line losing
@@ -334,6 +336,7 @@ fn verify_splice(
text_ui: Option<&benilla_ui::script::EditBoxTextUi>,
caret_pinned: bool,
script: &UiScript,
movies: &super::movie::MovieScreen,
) {
let mut check: Vec<UiQuad> = Vec::with_capacity(quads.quads.len());
let mut spans: Vec<u32> = Vec::with_capacity(prev.extracted.len());
@@ -354,6 +357,7 @@ fn verify_splice(
&mut check,
&mut links,
&mut slot,
movies,
);
spans.push(check.len() as u32);
}
@@ -674,7 +678,10 @@ pub(super) fn paint_script(
mut prev: Local<crate::ui_script::VmMemo<GateInputs>>,
mut ui_cost: ResMut<super::UiFrameCost>,
pass: Res<super::UiPassState>,
movies: Option<Res<super::movie::MovieScreen>>,
) {
let no_movies = super::movie::MovieScreen::default();
let movies = movies.as_deref().unwrap_or(&no_movies);
hosted_vm.run(|script| {
let (capture, ui_cost_wanted) = run;
// Stand down with the tick half, which already cleared the booth panes.
@@ -899,6 +906,7 @@ pub(super) fn paint_script(
&mut scratch,
&mut scratch_links,
&mut scratch_slot,
movies,
);
scratch_ranges.push(at..scratch.len());
}
@@ -984,6 +992,7 @@ pub(super) fn paint_script(
text_ui.as_ref(),
capture.is_some(),
script,
movies,
);
}
drop(extract_span);
@@ -1047,6 +1056,7 @@ pub(super) fn paint_script(
&mut out,
&mut link_spans,
&mut minimap_slot,
movies,
);
spans.push(out.len() as u32);
}
@@ -1170,7 +1180,13 @@ fn convert_entry(
String,
)>,
minimap_slot: &mut Option<crate::minimap::MinimapSlot>,
movies: &super::movie::MovieScreen,
) {
// A movie's picture is placed on the window, not on its frame's rect ([`super::movie`]).
if let QuadContent::Movie { handle } = eq.content {
out.extend(movies.quad(handle, w, h, eq.z));
return;
}
let Some(r) = eq.rect else { return };
// WoW UI space is y-up from the bottom-left: scale ×s, then flip through the window height.
let rect = Rect::new(r.left * s, h - r.top * s, r.right * s, h - r.bottom * s);
@@ -1182,8 +1198,9 @@ fn convert_entry(
.clip
.map(|c| Rect::new(c.left * s, h - c.top * s, c.right * s, h - c.bottom * s));
match eq.content {
// A frame draws nothing itself; its regions carry the visuals.
QuadContent::Frame => {}
// A frame draws nothing itself; its regions carry the visuals. A movie's picture was
// placed above.
QuadContent::Frame | QuadContent::Movie { .. } => {}
// The `<Minimap>` content hole, parked for the minimap renderer to fill at this `z`.
QuadContent::Minimap { zoom, inside_zoom } => {
*minimap_slot = Some(crate::minimap::MinimapSlot {
+116 -3
View File
@@ -17,9 +17,8 @@
//! file is loaded rather than refused.
//!
//! The screen comes after the build: at startup the reference fires `SET_GLUE_SCREEN` with
//! `"movie"` while the `movie` CVar is 1 (clearing it), else `"login"` (`0x402b3b`–`0x402b65`);
//! back from the world `0x402090` fires it with `"charselect"` or `"login"`. benilla plays no movie
//! yet (#968), so its boot screen is `"login"`.
//! `"movie"` while the `movie` CVar is 1 (clearing it), else `"login"` (`0x402b3b`–`0x402b65`,
//! [`startup_screen`]); back from the world `0x402090` fires it with `"charselect"` or `"login"`.
//!
//! The screens' `ModelFFX` panes drive the glue booth ([`super::glue_scene`]): its scene rig, the
//! scene M2's own point lights and the `FfxGlow::GLUE_SCENE` pass, never the `ui_models` tile
@@ -192,6 +191,57 @@ pub(super) fn finish_glue_load_log(script: &mut UiScript) {
super::load_log::write_glue(script.take_load_log_writes());
}
/// The screen the startup puts up (`0x402b3b`-`0x402b65`): `"movie"` while the `movie` CVar's
/// integer (`rec+0x28`, `0x402b41`) is 1, which first sets it to `"0"` (`0x402b54`, `0x82e570`), so
/// the intro plays once; else `"login"` (`0x82e3e0`). With no CVar table, `"login"`.
pub(super) fn startup_screen(cvars: Option<Mut<'_, crate::cvars::Cvars>>) -> &'static str {
let Some(mut cvars) = cvars else {
return GlueScreen::Login.key();
};
if cvars
.get("movie")
.is_some_and(|v| benilla_ui::script::s_str_to_int(v) == 1)
{
cvars.set("movie", "0");
"movie"
} else {
GlueScreen::Login.key()
}
}
/// Whether a run skips the startup's movie: one nobody watches ([`crate::run_mode::unattended`])
/// does, unless it asks to play it (`WOW_PLAY_MOVIE=1`). Tooling: the client plays it as the
/// reference does, and a probe, a capture or a smoke run skips it as a player can.
fn skips_startup_movie(unattended: bool, play_movie: bool) -> bool {
unattended && !play_movie
}
/// Skip a playing movie as Escape does: `MovieFrame_OnKeyUp` hides the frame, whose `OnHide`
/// stops the movie and puts the login screen up (`MovieFrame.lua:40-44`, `:59-61`).
fn skip_startup_movie(vm: StockVm) {
if vm.frame_visible("MovieFrame") {
info!("glue: an unattended run skips the startup movie (WOW_PLAY_MOVIE=1 plays it)");
vm.press("MovieFrame:Hide()");
}
}
/// The first frame the glue stands, an unattended run's startup movie is skipped
/// ([`skips_startup_movie`]); a movie asked for later plays.
pub(crate) fn skip_unattended_startup_movie(stock: StockGlueProbe, mut done: Local<bool>) {
if *done {
return;
}
let vm = stock.vm();
if !vm.is_up() {
return;
}
*done = true;
let play = std::env::var("WOW_PLAY_MOVIE").as_deref() == Ok("1");
if skips_startup_movie(crate::run_mode::unattended(), play) {
skip_startup_movie(vm);
}
}
/// Put `screen` up: `SET_GLUE_SCREEN` with its key as `arg1` (`0x46b840`, event 0).
#[cfg(test)]
pub(super) fn set_glue_screen(script: &mut UiScript, screen: GlueScreen) {
@@ -380,6 +430,69 @@ mod tests {
"AddonList",
];
/// The startup's screen: the movie while the `movie` CVar's integer is 1, which the pick sets
/// to "0" so the next start is the login screen; any other integer, "2" or "0", leaves the CVar
/// and puts the login screen up (`0x402b41`-`0x402b60`).
#[test]
fn the_first_start_plays_the_movie_once_and_clears_its_cvar() {
let mut world = World::new();
world.insert_resource(crate::cvars::Cvars::default());
assert_eq!(
world.resource::<crate::cvars::Cvars>().get("movie"),
Some("1"),
"the registered default"
);
let pick = |world: &mut World| startup_screen(world.get_resource_mut());
assert_eq!(pick(&mut world), "movie");
assert_eq!(
world.resource::<crate::cvars::Cvars>().get("movie"),
Some("0")
);
assert_eq!(pick(&mut world), "login");
for (value, screen, after) in [
("2", "login", "2"),
("1x", "movie", "0"),
("-1", "login", "-1"),
] {
world.insert_resource(crate::cvars::Cvars::with_value("movie", value));
assert_eq!(pick(&mut world), screen, "{value}");
assert_eq!(
world.resource::<crate::cvars::Cvars>().get("movie"),
Some(after),
"{value}"
);
}
assert_eq!(startup_screen(None), "login");
}
/// An unattended run lets nobody watch the startup's movie: it is skipped at once, by the
/// stock Escape path's `Hide()`, unless the run asks to play it (`WOW_PLAY_MOVIE=1`); an
/// attended run plays it. The skip puts the login screen up and leaves no movie playing.
#[test]
fn an_unattended_run_skips_the_startup_movie_as_escape_does() {
assert!(skips_startup_movie(true, false));
assert!(!skips_startup_movie(true, true));
assert!(!skips_startup_movie(false, false));
let _ = benilla_formats::wow_data_or_skip!();
let mut s = UiScript::new_glue().unwrap();
s.set_screen_size(1024.0, 768.0);
s.register_cvars([("movieSubtitle", "0"), ("gxResolution", "1024x768")]);
s.set_movie_reader(Box::new(|path, _| {
path.ends_with(".avi").then(|| {
benilla_movie::testing::synthetic_avi(1024, 464, (1, 25), 9, &[&[][..]; 9], &[])
})
}));
let _ = load_glue(&mut s);
signal_glue_screen(&mut s, "movie");
s.resolve();
assert!(s.movie_playing());
skip_startup_movie(StockVm(Some(&s)));
s.resolve();
assert!(!s.movie_playing());
assert!(!s.frame_visible("MovieFrame"));
assert_eq!(s.glue_screen(), "login");
}
/// The name a "nil value" call error names, in either of Lua's two spellings of it.
fn nil_call(error: &str) -> Option<&str> {
let (_, rest) = error.split_once("attempt to call ")?;
@@ -1,7 +1,7 @@
//! Keys on the stock glue screens, end to end: the host's key and char events into the stock
//! GlueXML in the glue VM.
use benilla_ui::script::{GlueNotice, NoticeState, UiScript};
use benilla_ui::script::{GlueNotice, GlueRequest, NoticeState, UiScript};
use super::glue::{load_glue, set_glue_screen, GlueScreen};
@@ -68,7 +68,7 @@ fn the_stock_login_boxes_take_typed_keys() {
assert!(s.take_errors().is_empty());
}
/// The login screen's Cinematics button shows `MovieFrame`; no movie plays here, so
/// The login screen's Cinematics button shows `MovieFrame`; with no movie file to open
/// `StartMovie` answers nil and the stock `MovieFrame_PlayMovie` hides the frame, whose `OnHide`
/// puts the login screen back and the pointer with it (`MovieFrame.lua:18-23,40-44`).
#[test]
@@ -127,6 +127,67 @@ fn escape_on_a_playing_movie_returns_to_login_on_the_key_up() {
assert_eq!(s.take_errors(), Vec::<String>::new());
}
/// The movie screen stops the glue music (`GlueParent.lua:50-51`), and the movies' end brings it
/// back: each movie's last frame fires `OnMovieFinished`, which starts the next
/// (`MovieFrame_PlayNextMovie`); past the last the frame hides, and its `OnHide` puts the login
/// screen up, which plays the music (`MovieFrame.lua:18-23,40-44`, `GlueParent.lua:53`).
#[test]
fn the_movies_end_returns_to_the_login_screen_and_its_music() {
let _ = benilla_formats::wow_data_or_skip!();
let mut s = glue_on(GlueScreen::Login);
s.register_cvars([("movieSubtitle", "0"), ("gxResolution", "1024x768")]);
let opened = std::rc::Rc::new(std::cell::RefCell::new(Vec::new()));
let log = opened.clone();
s.set_movie_reader(Box::new(move |path, _| {
log.borrow_mut().push(path.to_string());
path.ends_with(".avi").then(|| {
benilla_movie::testing::synthetic_avi(1024, 464, (1, 25), 3, &[b"", b"", b""], &[])
})
}));
s.set_now(8.0);
let _ = s.take_glue_requests();
super::glue::signal_glue_screen(&mut s, "movie");
s.resolve();
assert!(s.eval::<bool>("return MovieFrame:IsShown() == 1").unwrap());
let requests = |s: &mut UiScript| format!("{:?}", s.take_glue_requests());
assert_eq!(
requests(&mut s),
format!("{:?}", [GlueRequest::StopGlueMusic])
);
// The logo: frame 0 at the first step, its count of 3 reached at 100 ms.
s.tick(0.0);
s.tick(0.125);
assert!(s.eval::<bool>("return MovieFrame:IsShown() == 1").unwrap());
assert_eq!(requests(&mut s), "[]", "the intro follows the logo");
s.tick(0.0);
s.tick(0.125);
s.resolve();
assert_eq!(
opened.borrow().clone(),
[
"Interface\\Cinematics\\Logo_1024.avi",
"Interface\\Cinematics\\Logo_1024.sbt",
"Interface\\Cinematics\\WOW_Intro_1024.avi",
"Interface\\Cinematics\\WOW_Intro_1024.sbt",
]
);
assert!(!s.eval::<bool>("return MovieFrame:IsShown() == 1").unwrap());
assert!(s
.eval::<bool>("return AccountLoginUI:IsVisible() == 1")
.unwrap());
assert_eq!(
requests(&mut s),
format!(
"{:?}",
[GlueRequest::PlayGlueMusic(
"Sound\\Music\\GlueScreenMusic\\wow_main_theme.mp3".to_string()
)]
)
);
assert!(!s.movie_playing());
assert_eq!(s.take_errors(), Vec::<String>::new());
}
/// The Realmlist dialog widens the stock edit box, whose border is two 75-pixel caps that meet at
/// its own 130 pixels: while it is wide the stretched middle fills the gap between the caps, as the
/// chat box's does (`ChatFrame.xml:41-55`), and the stock box comes back untouched.
+29 -8
View File
@@ -13,15 +13,19 @@ use super::manifest::silenced_ui_load;
use super::{load_ingame_ui, CursorPayloadHeld, PlayerUiHover, UiClock, UiKeyboardCapture};
use crate::ui_script::addons;
/// The startup's glue: built, then put up on the screen the `movie` CVar picks
/// ([`super::glue::startup_screen`]).
pub(crate) fn setup_script(world: &mut World) {
install_glue_side_vm(world, super::glue::GlueScreen::Login.key());
if !install_glue_vm(world, None) {
error!("ui_script: the glue VM did not come up with its character select screen");
}
}
/// Install the VM the world holds outside the world: the glue screens', put up on the screen
/// named `screen`. A glue whose select screen did not load (logged as an error by [`new_vm`] or
/// the load) asks for no roster, and nothing else does.
pub(super) fn install_glue_side_vm(world: &mut World, screen: &str) {
if !install_glue_vm(world, screen) {
if !install_glue_vm(world, Some(screen)) {
error!("ui_script: the glue VM did not come up with its character select screen");
}
}
@@ -45,11 +49,11 @@ pub(crate) fn strings_vm(world: &mut World) -> Option<UiScript> {
Some(script)
}
/// Build the glue VM, load the stock GlueXML onto it, install it and put `screen` up: the glue
/// builder `0x46a7b0` then `SET_GLUE_SCREEN` (`0x402b65` at startup, `0x402090` back from the
/// world). It holds what the glue state holds and nothing of a boot VM's: no `GlobalStrings.lua`,
/// no emote tokens.
fn install_glue_vm(world: &mut World, screen: &str) -> bool {
/// Build the glue VM, load the stock GlueXML onto it, install it and put `screen` up, or with
/// `None` the startup's pick: the glue builder `0x46a7b0` then `SET_GLUE_SCREEN` (`0x402b65` at
/// startup, `0x402090` back from the world). It holds what the glue state holds and nothing of a
/// boot VM's: no `GlobalStrings.lua`, no emote tokens.
fn install_glue_vm(world: &mut World, screen: Option<&str>) -> bool {
let Some(mut script) = new_vm(world, UiScript::new_glue) else {
return false;
};
@@ -69,6 +73,12 @@ fn install_glue_vm(world: &mut World, screen: &str) -> bool {
start_server_alert(world, &script);
// What the glue carries across its rebuild, in place before the screen's `OnShow` reads it.
super::glue_mgr::seat_glue_build(world, &mut script);
// The startup reads the `movie` CVar after the build (`0x402b3b`), its write reaching the
// VM's mirror with the next sync.
let screen = match screen {
Some(screen) => screen,
None => super::glue::startup_screen(world.get_resource_mut::<crate::cvars::Cvars>()),
};
// `SetCurrentScreen`'s buffer is the client's (`[0xb41478]`) and outlives the Lua state: a
// rebuild signals what it holds (`0x46b9a2`), and the screen's handler writes the same name.
script.set_glue_screen_name(screen);
@@ -204,7 +214,7 @@ fn seed_game_time(world: &World, script: &mut UiScript) {
/// authored size on an axis takes it from its art as the client's virtual size getters do. Each
/// probe resolves through the store and the open its renderer reads (an interface texture's,
/// [`LooseOpen::Index`], and a font face's, [`LooseOpen::BareNameFirst`]), so the answer is what
/// draws; they test existence, not decode.
/// draws; they test existence, not decode. The movie frame's reader rides along.
fn install_addon_asset_resolvers(world: &mut World, script: &mut UiScript) {
let Some(mut assets) = world.get_resource_mut::<benilla_assets::WorldAssets>() else {
return;
@@ -218,6 +228,8 @@ fn install_addon_asset_resolvers(world: &mut World, script: &mut UiScript) {
let cursor_loose = loose.clone();
let font_chain = chain.clone();
let font_loose = loose.clone();
let movie_chain = chain.clone();
let movie_loose = loose.clone();
// `SetTexture` runs per frame in the addons that set an icon every `OnUpdate`: the probe
// keeps what it read of a file.
let probe = benilla_assets::SpriteProbe::default();
@@ -234,6 +246,15 @@ fn install_addon_asset_resolvers(world: &mut World, script: &mut UiScript) {
sizes.borrow_mut().insert(path.to_string(), measured);
measured
}));
// The movie frame's files: the `.avi` loose first (`0x78c39f`, flag 1), the `.sbt` from the
// archives alone (`0x6485f0`, flags 0).
script.set_movie_reader(Box::new(move |path, open| {
let open = match open {
benilla_ui::script::MovieOpen::LooseFirst => LooseOpen::Index,
benilla_ui::script::MovieOpen::Archives => LooseOpen::Archives,
};
benilla_assets::read_loose_or_chain(&movie_chain, &movie_loose, path, open)
}));
// `SetCursor`'s 32×32 test reads the picture the cursor code opens (`0x449610`), its `.blp`
// alone, decoded each call as `0x523c98` waits on the load.
script.set_cursor_size_probe(Box::new(move |path| {
+23
View File
@@ -24,6 +24,7 @@ pub(crate) mod glue_create;
pub(crate) mod glue_mgr;
pub(crate) mod glue_scene;
mod input;
mod movie;
/// The server alert's fetch and `LaunchURL`'s browser, for the stock glue screens.
pub(crate) mod server_alert;
#[cfg(test)]
@@ -471,6 +472,28 @@ impl Plugin for UiScriptPlugin {
)
// After the plate driver seats this frame's nameplates, and before the append lane
// fills the widget slot this pass parks.
// A scripted run's startup movie skipped before its first tick.
.add_systems(Update, glue::skip_unattended_startup_movie.in_set(UiInput))
// The movie audio's play times, a feed of the tick whose clock reads them.
// After the tutorial's selection judge, which reads the same VM.
.add_systems(
Update,
movie::feed_movie_audio
.in_set(UiFeed)
.after(crate::tutorial::judge_selections),
)
// The movie pictures the tick showed, ahead of the paint that draws them.
.init_resource::<movie::MovieScreen>()
.add_systems(
Update,
// After the frame's window and present modes apply, so the aspect is the
// window's this frame.
movie::upload_movie_pictures
.in_set(UiPaint)
.after(crate::video::apply_present_mode)
.after(crate::video::apply_window_mode)
.before(extract::paint_script),
)
.add_systems(
Update,
extract::paint_script
+318
View File
@@ -0,0 +1,318 @@
//! The movie frame's picture: each playing movie's last shown frame, uploaded into its output
//! bitmap ([`benilla_ui::script::MovieBitmap`]) and drawn as the reference's draw (`0x78d1a0`)
//! places its tiles: across the whole window, centred on its height, `A` times the tiles' extent
//! tall, where `A` is the scaled screen aspect (`0x41ad70`, 1.0 at 4:3), blending, lighting and
//! fog off (`0x78d3f7`-`0x78d414`: render states 14, 15 and 7 set to 0). One texture holds the
//! bitmap the reference splits into two or six for its power-of-two tiles (`0x81d280`), which
//! cover it edge to edge. And its audio's feed: the streams the movies ask for go to the sound
//! side ([`crate::sound::MovieAudioRequest`]), and the play times it reports come back.
use std::collections::HashMap;
use bevy::prelude::*;
use bevy::window::PrimaryWindow;
use benilla_ui::script::{movie_bitmap, MovieBitmap};
use benilla_ui::widget::FrameHandle;
use crate::sound::{MovieAudioReports, MovieAudioRequest};
use crate::ui_pass::{UiQuad, UvRect};
/// The audio feed, ahead of the tick whose clock reads it: last frame's stream reports into the
/// movies, then each new movie's stream asked for and each stopped movie's stream let go.
pub(super) fn feed_movie_audio(
mut hosted_vm: crate::script_calls::HostedVm,
mut reports: ResMut<MovieAudioReports>,
mut requests: MessageWriter<MovieAudioRequest>,
mut held: Local<Vec<u64>>,
) {
hosted_vm.run(|script| {
let reports = std::mem::take(&mut reports.0);
let live = match script {
Some(script) => {
for (id, report) in reports {
script.set_movie_audio(id, report);
}
for start in script.take_movie_audio_starts() {
held.push(start.id);
requests.write(MovieAudioRequest::Start {
id: start.id,
mp3: start.mp3,
});
}
script.movie_audio_ids()
}
None => Vec::new(),
};
held.retain(|id| {
let keep = live.contains(id);
if !keep {
requests.write(MovieAudioRequest::Stop { id: *id });
}
keep
});
});
}
/// The pictures the paint draws, by movie frame, and the scaled aspect they draw at.
#[derive(Resource, Default)]
pub(crate) struct MovieScreen {
images: HashMap<FrameHandle, MovieImage>,
/// `A = [0x832a4c]`, [`crate::loading_screen::scaled_aspect`].
scaled_aspect: f32,
}
struct MovieImage {
serial: u64,
id: u64,
handle: Handle<Image>,
bitmap: MovieBitmap,
}
impl MovieScreen {
/// Frame `frame`'s picture as a quad in a window `w` by `h` logical pixels, y down, at paint
/// key `z`: the tiles' extent `y_bottom..y_top` times `A`, in units of the window's height
/// about its middle, and the whole width (`0x78d46a`-`0x78d4d0`).
pub(super) fn quad(&self, frame: FrameHandle, w: f32, h: f32, z: u128) -> Option<UiQuad> {
let image = self.images.get(&frame)?;
let a = self.scaled_aspect;
let top = h * (0.5 - a * image.bitmap.y_top);
let bottom = h * (0.5 - a * image.bitmap.y_bottom);
Some(UiQuad {
rect: Rect::new(0.0, top, w, bottom),
z_key: z,
texture: Some(image.handle.clone()),
uv: UvRect::FULL,
color: [1.0; 4],
blend: benilla_ui::script::BlendMode::Disable,
..default()
})
}
}
/// `picture`, `width` by `rows` RGBA8 rows top down, into its bitmap as the tiles show it, top
/// down: the bitmap's first row draws at the bottom, and the decoder writes the picture bottom-up
/// from [`MovieBitmap::picture_row`]; every other row stays black (`0x78c89b` zeroes the bitmap;
/// blending is off, so they draw opaque).
fn fill_bitmap(bitmap: MovieBitmap, picture: &[u8], rows: u32, out: &mut Vec<u8>) {
let row_bytes = bitmap.width as usize * 4;
let rows = rows.min(bitmap.height.saturating_sub(bitmap.picture_row));
let top = (bitmap.height - bitmap.picture_row - rows) as usize * row_bytes;
let shown = rows as usize * row_bytes;
out.clear();
out.resize(row_bytes * bitmap.height as usize, 0);
for px in out.as_chunks_mut::<4>().0 {
px[3] = 255;
}
out[top..top + shown].copy_from_slice(&picture[..shown]);
}
/// Upload each playing movie's new picture, drop the pictures of movies that stopped, and take
/// the frame's scaled aspect; a line per hundred frames and one at each movie's end with the glue
/// screen it left up, the instrument a run's log reads the playback off.
pub(super) fn upload_movie_pictures(
mut hosted_vm: crate::script_calls::HostedVm,
window: Query<&Window, With<PrimaryWindow>>,
cvars: Option<Res<crate::cvars::Cvars>>,
mut screen: ResMut<MovieScreen>,
mut images: ResMut<Assets<Image>>,
mut scratch: Local<(Vec<u8>, Vec<u8>)>,
mut seen: Local<HashMap<u64, (String, i32, u32)>>,
) {
let size = window
.single()
.map_or(Vec2::ZERO, |w| Vec2::new(w.width(), w.height()));
screen.scaled_aspect = crate::loading_screen::scaled_aspect(
size,
crate::loading_screen::widescreen(cvars.as_deref()),
);
hosted_vm.run(|script| {
let pictures = script
.as_deref()
.map(|s| s.movie_pictures())
.unwrap_or_default();
screen.images.retain(|frame, image| {
pictures
.iter()
.any(|p| p.frame == *frame && p.id == image.id)
});
let screen_now = script
.as_deref()
.map(|s| s.glue_screen())
.unwrap_or_default();
seen.retain(|id, (name, shown, count)| {
if pictures.iter().any(|p| p.id == *id) {
return true;
}
info!("movie: {name} stopped at frame {shown}/{count}, glue screen \"{screen_now}\"");
false
});
let Some(script) = script else {
return;
};
let (rgba, bitmap_bytes) = &mut *scratch;
for p in pictures {
let name = p.name.clone().unwrap_or_default();
let last = seen.insert(p.id, (name.clone(), p.shown, p.frame_count));
if last.is_none() || last.is_some_and(|(_, s, _)| s / 100 != p.shown / 100) {
info!(
"movie: {name} frame {}/{} at {} ms, {} dropped",
p.shown, p.frame_count, p.clock_ms, p.dropped
);
}
let Some(bitmap) = movie_bitmap(p.width) else {
continue;
};
if screen
.images
.get(&p.frame)
.is_some_and(|i| i.id == p.id && i.serial == p.serial)
{
continue;
}
if !script.write_movie_rgba(p.frame, rgba) {
continue;
}
fill_bitmap(bitmap, rgba, p.height, bitmap_bytes);
let image = benilla_assets::sprite_image(
bitmap.width,
bitmap.height,
std::mem::take(bitmap_bytes),
);
match screen.images.get_mut(&p.frame) {
Some(slot) => {
// The same handle, so the painted quads keep their texture.
let _ = images.insert(&slot.handle, image);
slot.serial = p.serial;
slot.id = p.id;
slot.bitmap = bitmap;
}
None => {
screen.images.insert(
p.frame,
MovieImage {
serial: p.serial,
id: p.id,
handle: images.add(image),
bitmap,
},
);
}
}
}
});
}
#[cfg(test)]
mod tests {
use super::*;
/// A glue VM whose `MovieProbe` frame plays a 1024-wide movie with audio.
fn playing_vm() -> benilla_ui::script::UiScript {
let mut s = benilla_ui::script::UiScript::new_glue().unwrap();
s.set_movie_reader(Box::new(|path, _| {
path.ends_with(".avi").then(|| {
benilla_movie::testing::synthetic_avi(1024, 464, (1, 25), 2, &[b"", b""], &[b"mp3"])
})
}));
s.run(r#"M = CreateFrame("MovieFrame", "MovieProbe") M:StartMovie("A")"#)
.unwrap();
s
}
/// The feed asks for each new movie's stream once, and lets it go when its movie is gone,
/// the VM that played it replaced by one that never did.
#[test]
fn the_feed_starts_a_movies_stream_and_stops_it_with_its_vm() {
let mut world = World::new();
// One schedule, so the feed keeps its own record of the streams it asked for.
let mut schedule = Schedule::default();
schedule.add_systems(feed_movie_audio);
world.init_resource::<MovieAudioReports>();
world.init_resource::<Messages<MovieAudioRequest>>();
world.insert_non_send_resource(playing_vm());
let mut asked = |world: &mut World| -> Vec<String> {
schedule.run(world);
world
.resource_mut::<Messages<MovieAudioRequest>>()
.drain()
.map(|r| match r {
MovieAudioRequest::Start { mp3, .. } => format!("start {mp3:?}"),
MovieAudioRequest::Stop { .. } => "stop".to_string(),
})
.collect()
};
assert_eq!(asked(&mut world), [format!("start {:?}", b"mp3".to_vec())]);
assert!(asked(&mut world).is_empty(), "asked once");
world.insert_non_send_resource(benilla_ui::script::UiScript::new_glue().unwrap());
assert_eq!(asked(&mut world), ["stop"]);
assert!(asked(&mut world).is_empty());
}
/// The picture starts `0x81d400`'s rows above the bitmap's bottom (19200 bytes, 6 rows of
/// 800; 98304, 24 rows of 1024) and the rest stays opaque black: 800×368 is texture rows
/// 10..378 of 384, 1024×464 rows 24..488 of 512.
#[test]
fn the_picture_sits_where_the_decoder_writes_it_between_black_rows() {
for (width, rows, top, bottom) in [(800u32, 368u32, 10usize, 6usize), (1024, 464, 24, 24)] {
let bitmap = movie_bitmap(width).unwrap();
let picture: Vec<u8> = (0..width * rows)
.flat_map(|i| [1, 2, 3, (i % 251) as u8])
.collect();
let mut out = Vec::new();
fill_bitmap(bitmap, &picture, rows, &mut out);
let row = width as usize * 4;
assert_eq!(out.len(), row * bitmap.height as usize, "{width}");
let black = |bytes: &[u8]| {
bytes
.as_chunks::<4>()
.0
.iter()
.all(|px| *px == [0, 0, 0, 255])
};
assert!(black(&out[..top * row]), "{width}: the rows above");
assert!(
out[top * row..top * row + picture.len()] == picture[..],
"{width}: the picture's rows"
);
assert!(
black(&out[out.len() - bottom * row..]),
"{width}: the rows below"
);
assert_eq!(top + rows as usize + bottom, bitmap.height as usize);
}
}
/// At 4:3 the 1024 bitmap is the window's width and two thirds of its height, centred: rows
/// 128 to 640 of 768, its 512 rows one window pixel each. At 16:9 it grows with `A`.
#[test]
fn the_quad_spans_the_window_width_centred_on_its_height() {
let s = benilla_ui::script::UiScript::new_glue().unwrap();
s.run(r#"CreateFrame("MovieFrame", "MovieProbe")"#).unwrap();
let frame = s.frame_handle("MovieProbe").unwrap();
let mut screen = MovieScreen {
images: HashMap::new(),
scaled_aspect: 1.0,
};
screen.images.insert(
frame,
MovieImage {
serial: 1,
id: 1,
handle: Handle::default(),
bitmap: movie_bitmap(1024).unwrap(),
},
);
let q = screen.quad(frame, 1024.0, 768.0, 7).unwrap();
assert_eq!(q.rect.min.x, 0.0);
assert_eq!(q.rect.max.x, 1024.0);
assert!((q.rect.min.y - 128.256).abs() < 1e-3, "{:?}", q.rect);
assert!((q.rect.max.y - 639.744).abs() < 1e-3, "{:?}", q.rect);
screen.scaled_aspect =
crate::loading_screen::scaled_aspect(Vec2::new(1920.0, 1080.0), true);
let q = screen.quad(frame, 1920.0, 1080.0, 7).unwrap();
let tall = q.rect.max.y - q.rect.min.y;
assert!((tall - 0.666 * 1080.0 * 4.0 / 3.0).abs() < 0.01, "{tall}");
assert!(((q.rect.min.y + q.rect.max.y) / 2.0 - 540.0).abs() < 1e-3);
}
}
+4
View File
@@ -8,6 +8,10 @@ description = "The 1.12.1 intro movies: the AVI reader and an MPEG-4 Part 2 Simp
[lints]
workspace = true
[features]
# `testing`: the synthetic AVI the players' tests open.
test-support = []
[dependencies]
benilla-bytes = { path = "../benilla-bytes" }
+1 -68
View File
@@ -153,33 +153,6 @@ pub(crate) fn read(file: &[u8]) -> Result<Avi, Error> {
pub(crate) mod tests {
use super::*;
fn chunk(id: &[u8; 4], body: &[u8]) -> Vec<u8> {
let mut out = id.to_vec();
out.extend_from_slice(&(body.len() as u32).to_le_bytes());
out.extend_from_slice(body);
if body.len() % 2 == 1 {
out.push(0);
}
out
}
fn list(kind: &[u8; 4], parts: &[Vec<u8>]) -> Vec<u8> {
let mut body = kind.to_vec();
for p in parts {
body.extend_from_slice(p);
}
chunk(b"LIST", &body)
}
fn strh(kind: &[u8; 4], scale: u32, rate: u32, length: u32) -> Vec<u8> {
let mut h = vec![0u8; 56];
h[..4].copy_from_slice(kind);
h[20..24].copy_from_slice(&scale.to_le_bytes());
h[24..28].copy_from_slice(&rate.to_le_bytes());
h[32..36].copy_from_slice(&length.to_le_bytes());
chunk(b"strh", &h)
}
/// A RIFF AVI with an audio stream listed before the video one, `frames` as the video chunks
/// and `sounds` as the audio ones, interleaved, an odd-sized chunk among them.
pub(crate) fn synthetic(
@@ -188,47 +161,7 @@ pub(crate) mod tests {
frames: &[&[u8]],
sounds: &[&[u8]],
) -> Vec<u8> {
let mut bih = vec![0u8; 40];
bih[..4].copy_from_slice(&40u32.to_le_bytes());
bih[4..8].copy_from_slice(&width.to_le_bytes());
bih[8..12].copy_from_slice(&height.to_le_bytes());
let hdrl = list(
b"hdrl",
&[
chunk(b"avih", &[0u8; 56]),
list(
b"strl",
&[strh(b"auds", 1, 44100, 0), chunk(b"strf", &[0u8; 30])],
),
list(
b"strl",
&[strh(b"vids", 41764, 1_000_000, 648), chunk(b"strf", &bih)],
),
],
);
let mut movi_body = b"movi".to_vec();
let mut index = Vec::new();
let mut entry = |id: &[u8; 4], data: &[u8], movi_body: &mut Vec<u8>| {
index.extend_from_slice(id);
index.extend_from_slice(&0x10u32.to_le_bytes());
index.extend_from_slice(&(movi_body.len() as u32).to_le_bytes());
index.extend_from_slice(&(data.len() as u32).to_le_bytes());
movi_body.extend_from_slice(&chunk(id, data));
};
for i in 0..frames.len().max(sounds.len()) {
if let Some(s) = sounds.get(i) {
entry(b"01wb", s, &mut movi_body);
}
if let Some(f) = frames.get(i) {
entry(b"00dc", f, &mut movi_body);
}
}
let mut body = b"AVI ".to_vec();
body.extend_from_slice(&hdrl);
body.extend_from_slice(&chunk(b"JUNK", &[0; 3]));
body.extend_from_slice(&chunk(b"LIST", &movi_body));
body.extend_from_slice(&chunk(b"idx1", &index));
chunk(b"RIFF", &body)
crate::testing::synthetic_avi(width, height, (41764, 1_000_000), 648, frames, sounds)
}
#[test]
+3
View File
@@ -12,6 +12,7 @@ use crate::vlc::{
};
/// One sample plane. `width` and `height` are the VOL's; the buffer covers whole macroblocks.
#[derive(Clone)]
pub(crate) struct Plane {
pub(crate) data: Vec<u8>,
pub(crate) stride: usize,
@@ -31,6 +32,7 @@ impl Plane {
}
/// A 4:2:0 picture.
#[derive(Clone)]
pub(crate) struct Picture {
pub(crate) y: Plane,
pub(crate) cb: Plane,
@@ -291,6 +293,7 @@ fn add_block(p: &mut Plane, x: usize, y: usize, s: &[i32; 64]) {
/// The decoder's state across VOPs: the picture being built, the last one decoded, and the
/// per-macroblock and per-block predictors of the VOP in progress.
#[derive(Clone)]
pub(crate) struct Decoder {
mb_w: usize,
mb_h: usize,
+5 -1
View File
@@ -19,6 +19,8 @@ mod decoder;
mod headers;
mod idct;
mod scan;
#[cfg(any(test, feature = "test-support"))]
pub mod testing;
mod vlc;
use std::ops::Range;
@@ -98,7 +100,9 @@ pub struct Yuv<'a> {
pub c_stride: usize,
}
/// A movie open for decoding, its frames pulled one at a time.
/// A movie open for decoding, its frames pulled one at a time; a clone decodes on from where
/// this one is.
#[derive(Clone)]
pub struct Movie {
file: Vec<u8>,
width: u32,
+83
View File
@@ -0,0 +1,83 @@
//! A synthetic AVI for the tests of this crate and of the crates that play its movies
//! (`test-support`).
fn chunk(id: &[u8; 4], body: &[u8]) -> Vec<u8> {
let mut out = id.to_vec();
out.extend_from_slice(&(body.len() as u32).to_le_bytes());
out.extend_from_slice(body);
if body.len() % 2 == 1 {
out.push(0);
}
out
}
fn list(kind: &[u8; 4], parts: &[Vec<u8>]) -> Vec<u8> {
let mut body = kind.to_vec();
for p in parts {
body.extend_from_slice(p);
}
chunk(b"LIST", &body)
}
fn strh(kind: &[u8; 4], scale: u32, rate: u32, length: u32) -> Vec<u8> {
let mut h = vec![0u8; 56];
h[..4].copy_from_slice(kind);
h[20..24].copy_from_slice(&scale.to_le_bytes());
h[24..28].copy_from_slice(&rate.to_le_bytes());
h[32..36].copy_from_slice(&length.to_le_bytes());
chunk(b"strh", &h)
}
/// A RIFF AVI with an audio stream listed before the video one, its video header's
/// `(dwScale, dwRate)` and `dwLength` as given, `frames` as the video chunks and `sounds` as the
/// audio ones, interleaved. An empty frame chunk decodes as a repeat of the picture before it.
pub fn synthetic_avi(
width: i32,
height: i32,
(scale, rate): (u32, u32),
length: u32,
frames: &[&[u8]],
sounds: &[&[u8]],
) -> Vec<u8> {
let mut bih = vec![0u8; 40];
bih[..4].copy_from_slice(&40u32.to_le_bytes());
bih[4..8].copy_from_slice(&width.to_le_bytes());
bih[8..12].copy_from_slice(&height.to_le_bytes());
let hdrl = list(
b"hdrl",
&[
chunk(b"avih", &[0u8; 56]),
list(
b"strl",
&[strh(b"auds", 1, 44100, 0), chunk(b"strf", &[0u8; 30])],
),
list(
b"strl",
&[strh(b"vids", scale, rate, length), chunk(b"strf", &bih)],
),
],
);
let mut movi_body = b"movi".to_vec();
let mut index = Vec::new();
let mut entry = |id: &[u8; 4], data: &[u8], movi_body: &mut Vec<u8>| {
index.extend_from_slice(id);
index.extend_from_slice(&0x10u32.to_le_bytes());
index.extend_from_slice(&(movi_body.len() as u32).to_le_bytes());
index.extend_from_slice(&(data.len() as u32).to_le_bytes());
movi_body.extend_from_slice(&chunk(id, data));
};
for i in 0..frames.len().max(sounds.len()) {
if let Some(s) = sounds.get(i) {
entry(b"01wb", s, &mut movi_body);
}
if let Some(f) = frames.get(i) {
entry(b"00dc", f, &mut movi_body);
}
}
let mut body = b"AVI ".to_vec();
body.extend_from_slice(&hdrl);
body.extend_from_slice(&chunk(b"JUNK", &[0; 3]));
body.extend_from_slice(&chunk(b"LIST", &movi_body));
body.extend_from_slice(&chunk(b"idx1", &index));
chunk(b"RIFF", &body)
}
+6
View File
@@ -17,6 +17,12 @@ roxmltree = "0.20"
# The script host's Lua: benilla's own interpreter, through a crate that answers to the name
# `mlua` (`src/lib.rs`).
benilla-mlua = { path = "../benilla-mlua" }
# The intro movies' reader and decoder, which `MovieFrame:StartMovie` opens.
benilla-movie = { path = "../benilla-movie" }
# `date` and `time`'s local zone: `localtime_r`, `mktime` and `tzname` on unix, the CRT's
# `localtime_s` and zone globals on Windows (`civil`).
libc = "0.2"
[dev-dependencies]
# The synthetic movie the movie frame's tests open.
benilla-movie = { path = "../benilla-movie", features = ["test-support"] }
+6 -1
View File
@@ -113,6 +113,8 @@ impl UiScript {
fog: m.scene_fog(),
ffx: m.ffx,
},
// A playing movie's picture, once it has shown one (`0x78d68b`).
_ if model.movie_drawn(fh) => QuadContent::Movie { handle: fh },
_ => QuadContent::Frame,
};
(model.frame_rect(fh), alpha, content, clip, scale)
@@ -372,8 +374,11 @@ impl UiScript {
// quads, text, then render callbacks, and `0x76d160` registers the model's callback
// for layer 2 only (`0x76d17f cmp ebx,2`). So the world map's player arrow draws over
// the zone overlays at the same level, below its own OVERLAY and HIGHLIGHT regions.
// A movie's picture likewise: `0x78d650` registers its callback for layer 2 alone.
let z = match &content {
QuadContent::ModelPane { .. } => zkey.callback(order::DrawLayer::Artwork).raw(),
QuadContent::ModelPane { .. } | QuadContent::Movie { .. } => {
zkey.callback(order::DrawLayer::Artwork).raw()
}
_ => zkey.raw(),
};
// A slot's texture by its stamp; the colour picker's two images, built when it loads
+15 -2
View File
@@ -305,6 +305,10 @@ pub use item_read::{ItemInfoFields, ItemKey, ItemRead, ItemRoll};
pub use lfg::LfgDungeon;
pub use lottery::UnservedSend;
pub use modelframe::{CharacterPaneFrame, ModelPaneFrame, ModelWanted};
pub use movieframe::{
movie_bitmap, MovieAudio, MovieAudioStart, MovieBitmap, MovieOpen, MoviePicture, MovieReadFn,
MovieReader,
};
pub use petition::{
validate_guild_name, PetitionCall, PetitionRecordView, PetitionState, PETITION_TYPE_CHARTER,
PETITION_TYPE_PETITION,
@@ -617,8 +621,7 @@ const SCRIPT_KINDS: [&str; 46] = [
"OnDoubleClick",
// The layout event (base map `0x76a0d0`, `+0x120`), fired by the resolve pass on a size change.
"OnSizeChanged",
// The movie frame's three (script map `0x78c2e0`): fired by its player alone, which does not
// exist here ([`movieframe`]), so they are stored and never run.
// The movie frame's three (script map `0x78c2e0`), fired by its player ([`movieframe`]).
"OnMovieFinished",
"OnMovieShowSubtitle",
"OnMovieHideSubtitle",
@@ -644,6 +647,16 @@ pub struct UiScript {
session: u64,
}
/// A VM's end destroys its frames, and a movie frame's destructor stops its movie, firing
/// `OnMovieFinished` (`0x78c280`).
impl Drop for UiScript {
fn drop(&mut self) {
if self.lua.app_data_ref::<Model>().is_some() {
self.stop_movies();
}
}
}
/// Hands out [`UiScript::session`] ids: process-global and monotone, so an id is never reused.
static NEXT_SESSION: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
+3
View File
@@ -156,6 +156,8 @@ pub(crate) struct Model {
/// 1 for a non-empty path: without a font backend nothing failed, and addons revert their font
/// on a nil.
pub(crate) font_probe: Option<FontProbe>,
/// The movie frames' reader, subtitle flags and playing movies ([`super::movieframe`]).
pub(crate) movies: super::movieframe::Movies,
/// Saved-variables folders, one `<Addon>.lua` each: the account's, then this character's.
pub(crate) addons_saved_account: Option<std::path::PathBuf>,
pub(crate) addons_saved_character: Option<std::path::PathBuf>,
@@ -1330,6 +1332,7 @@ impl Model {
texture_size_probe: None,
cursor_size_probe: None,
font_probe: None,
movies: Default::default(),
addons_saved_account: None,
addons_saved_character: None,
framexml_templates: Default::default(),
+476 -73
View File
@@ -1,73 +1,352 @@
//! The `MovieFrame` methods (`CSimpleMovieFrame`, factory `0x6ef000`; method table `0x87ab4c`):
//! `StartMovie` (`0x78d770`), `StopMovie` (`0x78d870`) and `EnableSubtitles` (`0x78d940`).
//! The `MovieFrame` (`CSimpleMovieFrame`, factory `0x6ef000`; method table `0x87ab4c`) and its
//! player: `StartMovie` (`0x78d770`), `StopMovie` (`0x78d870`) and `EnableSubtitles`
//! (`0x78d940`), the clock its draw callback steps (`0x78d680` → `0x78cf30`), and the three
//! `OnMovie*` scripts it fires (script map `0x78c2e0`, slots `+0x320`/`+0x328`/`+0x330`).
//!
//! Deviation: benilla plays no pre-rendered movie (#968), so `StartMovie` answers nil, the
//! reference's "could not start" (`0x78d861`), which the stock `MovieFrame_PlayMovie` answers by
//! hiding the frame and so by returning to the login screen. With no movie ever running,
//! `StopMovie` has nothing to stop: `0x78ced0` returns at once when the playing slot `+0x314` is
//! clear, and only past that test fires `OnMovieFinished` (`0x78cf0b`-`0x78cf1e`). The three
//! `OnMovie*` scripts (script map `0x78c2e0`, slots `+0x320`/`+0x328`/`+0x330`) are accepted by
//! `SetScript` and never run.
//! `StartMovie` reads `<name>.avi` whole and starts the decoder (`0x78c360`, `0x78c7a0`); either
//! failing answers nil. Then it starts the audio (`0x78ca30`) and loads `<name>.sbt`'s captions
//! (`0x78cb00`), whose results it ignores, sets the playing flag (`+0x314`) and answers 1
//! (`0x78ce40`). The host plays the audio: it takes each new stream's MP3 bytes
//! ([`UiScript::take_movie_audio_starts`]) and reports its play time or its failure back
//! ([`UiScript::set_movie_audio`]) ahead of each tick, and the movie's draw is the host's too
//! ([`UiScript::movie_pictures`]). A movie stops at its last frame, at its audio's end, or by
//! `StopMovie`, each through the one teardown (`0x78ced0`) that fires `OnMovieFinished`.
mod captions;
mod player;
use std::collections::HashMap;
use mlua::{Lua, MultiValue, Table, Value};
use super::binding_abi::bool_or_default;
use super::binding_abi::name_of;
use super::binding_abi::{flag_or_default, name_of, optional_string};
use super::event;
use super::object::frame_handle_of;
use super::Model;
use crate::widget::FrameKind;
use super::{Model, UiScript};
use crate::widget::{FrameHandle, FrameKind};
use player::{Audio, Playback, Step};
/// Registry key of the MovieFrame method table (the MAXCSTACK discipline: a Lua-side root).
pub(super) const REG_MOVIEFRAME_METHODS: &str = "__benilla_movieframe_methods";
/// How a movie's file opens.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MovieOpen {
/// The loose files by the whole name, then the archives: the `.avi`, which `0x78c39f` opens
/// through `SFile::OpenEx` with flag 1.
LooseFirst,
/// The archives alone: the `.sbt`, which `SFile::LoadByName` (`0x6485f0`) opens with flags 0.
Archives,
}
/// The host's file reader for the movie files: a path's bytes, or `None` when nothing opens it.
pub type MovieReadFn = dyn Fn(&str, MovieOpen) -> Option<Vec<u8>>;
/// [`MovieReadFn`] as the model holds it.
pub type MovieReader = std::rc::Rc<MovieReadFn>;
/// A new movie's audio, for the host to open as a stream and play (`0x78ca30`).
pub struct MovieAudioStart {
/// The movie's number, which [`UiScript::set_movie_audio`] answers under.
pub id: u64,
/// The AVI's audio chunks, concatenated: an MP3 stream for the 1.12.1 movies.
pub mp3: Vec<u8>,
}
/// What the host reports of a movie's audio stream.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MovieAudio {
/// The stream would not open or play: the movie runs on the wall clock (`0x78ca91`).
Failed,
/// The stream's play time in milliseconds (`FSOUND_Stream_GetTime`).
At(u32),
/// The stream played out: its end callback finishes the movie (`0x78c070`).
Ended,
}
/// A playing movie's last shown picture and its clock, for the host's draw and its instruments.
#[derive(Clone, Debug, PartialEq)]
pub struct MoviePicture {
pub frame: FrameHandle,
/// The movie frame's global name.
pub name: Option<String>,
/// The movie's number ([`MovieAudioStart::id`]).
pub id: u64,
/// The pictures shown so far: a new one means a new picture to upload.
pub serial: u64,
pub width: u32,
pub height: u32,
/// The frame shown (`+0x3b8`) and the header's frame count (`+0x348`).
pub shown: i32,
pub frame_count: u32,
/// The steps that skipped frames (`+0x3c0`).
pub dropped: u32,
/// The movie clock in milliseconds (`+0x3c8`).
pub clock_ms: u32,
}
/// The output bitmap and its tiles' quad as the decoder start lays them out for a width (the
/// size class at `+0x34c`, `0x78c815`-`0x78c833`): the bitmap's size (`0x81d1ac`, `0x81d1b4`), and
/// the extent the tile quads (`0x81d1c0`) cover, in the draw's orthographic units (`0x78d321`:
/// x from 0 to 1 across the window, y from -0.5 to 0.5 up it), y before the scaled screen aspect
/// multiplies it (`0x41ad70`, `0x78d480`). The bitmap's first row draws at the bottom
/// (`0x78d46a`-`0x78d4d0`), so the decoder's bottom-up picture stands upright on it, and the rows
/// around the picture stay black (`0x78c89b`).
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MovieBitmap {
pub width: u32,
pub height: u32,
/// The bitmap row the decoder's output starts at, counted from its first: the frame decode
/// hands `DivxDecode` the bitmap plus `0x81d400`'s bytes for the size class (`0x78d58e`),
/// 19200 (6 rows of 800) and 98304 (24 rows of 1024), as the tiles' update rects at
/// `0x81d340` start at row 6 and 24.
pub picture_row: u32,
pub y_bottom: f32,
pub y_top: f32,
}
/// [`MovieBitmap`] for a movie `width` wide: 800 (six tiles, 0.66 of a unit tall) or 1024 (two
/// tiles, 0.666).
pub fn movie_bitmap(width: u32) -> Option<MovieBitmap> {
match width {
800 => Some(MovieBitmap {
width: 800,
height: 384,
picture_row: 6,
y_bottom: -0.33,
y_top: 0.33,
}),
1024 => Some(MovieBitmap {
width: 1024,
height: 512,
picture_row: 24,
y_bottom: -0.333,
y_top: 0.333,
}),
_ => None,
}
}
/// The movie frames' player state: the host's reader and, per frame, the subtitle flag and the
/// playing movie.
#[derive(Clone, Default)]
pub(crate) struct Movies {
reader: Option<MovieReader>,
frames: HashMap<FrameHandle, MovieFrameState>,
}
/// Hands out each start's number: process-wide, so a stream the host still holds for a VM that
/// is gone never shares a number with a movie of the VM that replaced it.
static NEXT_MOVIE: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
#[derive(Clone, Default)]
struct MovieFrameState {
/// `+0x31c`, `EnableSubtitles`' flag as `GetScriptFlagArg` gave it; 0 from the constructor
/// (`0x78c0ee`).
subtitles: i32,
playback: Option<Playback>,
/// The playing movie's audio has been handed to the host.
audio_asked: bool,
}
/// `SStrPrintf` into the open's `0x104`-byte path buffer (`0x78c389`, `0x78cb21`): at most 259
/// bytes.
fn movie_path(name: &str, ext: &str) -> String {
let mut path = format!("{name}.{ext}").into_bytes();
path.truncate(0x103);
String::from_utf8_lossy(&path).into_owned()
}
impl Model {
/// `0x78ce40`: start the movie `name` on frame `h`. Whether it started.
fn start_movie(&mut self, h: FrameHandle, name: &str) -> bool {
let Some(reader) = self.movies.reader.clone() else {
return false;
};
let Some(file) = reader(&movie_path(name, "avi"), MovieOpen::LooseFirst) else {
return false;
};
let Ok(movie) = benilla_movie::Movie::open(file) else {
return false;
};
// An AVI with no audio chunks opens no stream: `FSOUND_Stream_Open` of an empty buffer.
let audio = if movie.audio().is_empty() {
Audio::None
} else {
Audio::Pending
};
let captions = reader(&movie_path(name, "sbt"), MovieOpen::Archives)
.map(|f| captions::parse(&f))
.unwrap_or_default();
let id = NEXT_MOVIE.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
let state = self.movies.frames.entry(h).or_default();
state.playback = Some(Playback::new(id, movie, audio, captions));
state.audio_asked = false;
true
}
/// `0x78ced0`'s teardown on frame `h`: nothing unless a movie plays; else the decoder, the
/// audio and the captions go, and the playing and finished flags clear. Whether a caption
/// was up, which the caption free hides (`0x78cda0`), or `None` when nothing played.
fn take_movie(&mut self, h: FrameHandle) -> Option<bool> {
let state = self.movies.frames.get_mut(&h)?;
let playback = state.playback.take()?;
state.audio_asked = false;
Some(playback.caption.is_some())
}
/// Frame `h` draws a movie picture: a movie plays there and has shown one.
pub(crate) fn movie_drawn(&self, h: FrameHandle) -> bool {
self.movies
.frames
.get(&h)
.and_then(|s| s.playback.as_ref())
.is_some_and(|p| p.shown >= 0)
}
}
/// Raises unless `this` is a live MovieFrame: the method table is a plain Lua value a caller can
/// lift onto another frame (`0x847e98`, "Wrong object type for member function").
fn check_movie_frame(lua: &Lua, this: &Table) -> mlua::Result<()> {
fn movie_frame_of(lua: &Lua, this: &Table) -> mlua::Result<FrameHandle> {
let h = frame_handle_of(lua, this)?;
let model = lua.app_data_ref::<Model>().expect("model app_data");
match model.arena.frame(h) {
Some(f) if f.kind == FrameKind::MovieFrame => Ok(()),
Some(f) if f.kind == FrameKind::MovieFrame => Ok(h),
_ => Err(mlua::Error::runtime(
"Wrong object type for member function",
)),
}
}
/// Fire `script` on frame `h` with `args`; a handler error goes to [`Model::errors`].
fn fire(lua: &Lua, h: FrameHandle, script: &str, args: Vec<Value>) {
let id = lua
.app_data_mut::<Model>()
.expect("model app_data")
.frame_id(h);
if let Err(e) = event::fire_widget_handler(lua, id, script, args) {
lua.app_data_mut::<Model>()
.expect("model app_data")
.record_lua_error(&e);
}
}
/// `0x78ced0` on frame `h`: the teardown, the caption's `OnMovieHideSubtitle` if one was up, and
/// `OnMovieFinished` (`0x78cf1e`). Nothing when no movie plays (`0x78cedb`).
fn stop_movie(lua: &Lua, h: FrameHandle) {
let caption_up = lua
.app_data_mut::<Model>()
.expect("model app_data")
.take_movie(h);
let Some(caption_up) = caption_up else {
return;
};
if caption_up {
fire(lua, h, "OnMovieHideSubtitle", Vec::new());
}
fire(lua, h, "OnMovieFinished", Vec::new());
}
/// The draw callback's step on frame `h` (`0x78d680`): the clock, then after a shown frame the
/// caption that ended comes down and the one the clock reached goes up (`0x78d0ca`-`0x78d191`).
fn step_movie(lua: &Lua, h: FrameHandle) {
let (step, id, hide) = {
let mut model = lua.app_data_mut::<Model>().expect("model app_data");
let now = model.now_ms() as u32;
let Some(p) = model
.movies
.frames
.get_mut(&h)
.and_then(|s| s.playback.as_mut())
else {
return;
};
let step = p.step(now);
(step, p.id, step == Step::Shown && p.caption_ended())
};
match step {
Step::Hold => {}
Step::Finish => stop_movie(lua, h),
Step::Shown => {
if hide {
fire(lua, h, "OnMovieHideSubtitle", Vec::new());
}
let show = {
let mut model = lua.app_data_mut::<Model>().expect("model app_data");
let Some(state) = model.movies.frames.get_mut(&h) else {
return;
};
let subtitles = state.subtitles != 0;
match state.playback.as_mut() {
// A movie a handler started in this one's place has its own clock.
Some(p) if p.id == id => p.caption_to_show(subtitles),
_ => None,
}
};
if let Some(text) = show {
match lua.create_string(&text) {
Ok(s) => fire(lua, h, "OnMovieShowSubtitle", vec![Value::String(s)]),
Err(e) => lua
.app_data_mut::<Model>()
.expect("model app_data")
.record_lua_error(&e),
}
}
}
}
}
pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
let m = lua.create_table()?;
// `lua_isstring` on the path (`0x6f3510`: a string or a number), else
// `Usage: %s:StartMovie("filename")` (`0x87ab8c`); one value back (`0x78d84d`/`0x78d861`),
// 1 for a movie that started and nil for one that did not.
// `Usage: %s:StartMovie("filename")` (`0x87ab8c`); one value back, 1 for a movie that
// started (`0x78d84d`) and nil for one whose file or decoder failed (`0x78d861`).
m.set(
"StartMovie",
lua.create_function(|lua, (this, path): (Table, Value)| {
check_movie_frame(lua, &this)?;
if !matches!(
path,
Value::String(_) | Value::Integer(_) | Value::Number(_)
) {
let h = movie_frame_of(lua, &this)?;
let Some(name) = optional_string(lua, &path) else {
return Err(mlua::Error::runtime(format!(
"Usage: {}:StartMovie(\"filename\")",
name_of(lua, &this)
)));
}
Ok(Value::Nil)
};
let started = lua
.app_data_mut::<Model>()
.expect("model app_data")
.start_movie(h, &name);
Ok(if started {
Value::Number(1.0)
} else {
Value::Nil
})
})?,
)?;
// No arguments, no returns (`0x78d8b8`).
m.set(
"StopMovie",
lua.create_function(|lua, this: Table| check_movie_frame(lua, &this))?,
lua.create_function(|lua, this: Table| {
let h = movie_frame_of(lua, &this)?;
stop_movie(lua, h);
Ok(())
})?,
)?;
// The flag defaults to true when absent (`0x6f1c10` with the default `1`, as
// `EnableKeyboard`'s `0x776f4e`), stored at `+0x31c` for the player's subtitle events, which
// nothing here fires; no returns.
// `GetScriptFlagArg` with the default 1 (`0x78d9c5`-`0x78d9ce`), so an absent flag is on and
// an explicit nil off, stored as given at `+0x31c` (`0x78d9d3`); no returns.
m.set(
"EnableSubtitles",
lua.create_function(|lua, (this, args): (Table, MultiValue)| {
check_movie_frame(lua, &this)?;
let _enabled = bool_or_default(args.front(), true);
let h = movie_frame_of(lua, &this)?;
let flag = flag_or_default(args.front(), 1);
lua.app_data_mut::<Model>()
.expect("model app_data")
.movies
.frames
.entry(h)
.or_default()
.subtitles = flag;
Ok(())
})?,
)?;
@@ -76,51 +355,175 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
Ok(())
}
#[cfg(test)]
mod tests {
use crate::script::UiScript;
impl UiScript {
/// Install the host's reader for the movie files.
pub fn set_movie_reader(&mut self, reader: Box<MovieReadFn>) {
self.model_mut().movies.reader = Some(reader.into());
}
/// `StartMovie` answers nil (no player), takes a string or a number, and raises its usage on
/// anything else; `StopMovie` and `EnableSubtitles` answer nothing; and the three player
/// scripts are taken by `SetScript` and read back.
#[test]
fn the_movie_frame_takes_its_methods_and_scripts_and_plays_nothing() {
let s = UiScript::new_glue().unwrap();
s.run(r#"M = CreateFrame("MovieFrame", "MovieProbe")"#)
.unwrap();
assert!(s
.eval::<bool>(r#"return M:StartMovie("a\\b") == nil"#)
.unwrap());
assert!(s.eval::<bool>("return M:StartMovie(7) == nil").unwrap());
assert!(s
.eval::<bool>("return table.getn({M:StopMovie()}) == 0")
.unwrap());
assert!(s
.eval::<bool>("return table.getn({M:EnableSubtitles(1)}) + table.getn({M:EnableSubtitles()}) == 0")
.unwrap());
for bad in ["M:StartMovie()", "M:StartMovie({})", "M:StartMovie(true)"] {
let err = s.run(bad).unwrap_err().to_string();
assert!(
err.contains(r#"Usage: MovieProbe:StartMovie("filename")"#),
"{bad}: {err}"
);
/// A movie plays on some frame: the word `0x885604` the movie start sets (`0x78ce8b`) and the
/// teardown clears (`0x78cf06`), under which the frame pass presents nothing and a screenshot
/// asked for waits (`0x442681`).
pub fn movie_playing(&self) -> bool {
self.model_ref()
.movies
.frames
.values()
.any(|s| s.playback.is_some())
}
/// The audio of each movie started since the last call, for the host to open and play.
pub fn take_movie_audio_starts(&mut self) -> Vec<MovieAudioStart> {
let mut model = self.model_mut();
let mut out = Vec::new();
for state in model.movies.frames.values_mut() {
let Some(p) = state.playback.as_ref() else {
continue;
};
if p.audio == Audio::Pending && !state.audio_asked {
state.audio_asked = true;
out.push(MovieAudioStart {
id: p.id,
mp3: p.movie.audio().to_vec(),
});
}
}
for name in [
"OnMovieFinished",
"OnMovieShowSubtitle",
"OnMovieHideSubtitle",
] {
s.run(&format!("M:SetScript('{name}', function() end)"))
.unwrap();
assert!(
s.eval::<bool>(&format!("return M:GetScript('{name}') ~= nil"))
.unwrap(),
"{name}"
);
out.sort_by_key(|s| s.id);
out
}
/// The movies whose audio stream the host should hold: every other stream it holds belongs
/// to a movie that stopped, and stops with it (`0x78caa0`).
pub fn movie_audio_ids(&self) -> Vec<u64> {
let model = self.model_ref();
let mut ids: Vec<u64> = model
.movies
.frames
.values()
.filter_map(|s| s.playback.as_ref())
.filter(|p| p.audio != Audio::None)
.map(|p| p.id)
.collect();
ids.sort_unstable();
ids
}
/// The host's report on movie `id`'s audio stream.
pub fn set_movie_audio(&mut self, id: u64, report: MovieAudio) {
let mut model = self.model_mut();
let Some(p) = model
.movies
.frames
.values_mut()
.filter_map(|s| s.playback.as_mut())
.find(|p| p.id == id)
else {
return;
};
match report {
MovieAudio::Failed => p.audio = Audio::None,
MovieAudio::At(ms) => p.audio = Audio::At(ms),
MovieAudio::Ended => {
p.finished = true;
// A stream that ended having played nothing gives the clock no time to anchor
// to, where `0x78cf5d` waits on it: it counts as no stream, so the clock runs
// and the flag stops the movie.
if !matches!(p.audio, Audio::At(t) if t > 0) {
p.audio = Audio::None;
}
}
}
}
/// Each playing movie that has shown a picture, by start.
pub fn movie_pictures(&self) -> Vec<MoviePicture> {
let model = self.model_ref();
let mut out: Vec<MoviePicture> = model
.movies
.frames
.iter()
.filter_map(|(&h, s)| {
let p = s.playback.as_ref().filter(|p| p.shown >= 0)?;
Some(MoviePicture {
frame: h,
name: model.arena.frame(h).and_then(|f| f.name.clone()),
id: p.id,
serial: p.serial,
width: p.movie.width(),
height: p.movie.height(),
shown: p.shown,
frame_count: p.movie.frame_count(),
dropped: p.dropped,
clock_ms: p.clock,
})
})
.collect();
out.sort_by_key(|p| p.id);
out
}
/// The last picture frame `h`'s movie decoded, as RGBA8 rows top down, into `out`; false when
/// no movie plays there.
pub fn write_movie_rgba(&self, h: FrameHandle, out: &mut Vec<u8>) -> bool {
let model = self.model_ref();
match model
.movies
.frames
.get(&h)
.and_then(|s| s.playback.as_ref())
{
Some(p) => {
p.movie.write_rgba(out);
true
}
None => false,
}
}
/// The frames' destructor's teardown (`0x78c280` calls `0x78ced0`), as the VM goes: each
/// playing movie stops and fires its `OnMovieFinished`.
pub(super) fn stop_movies(&mut self) {
let mut frames: Vec<FrameHandle> = {
let model = self.model_ref();
model
.movies
.frames
.iter()
.filter(|(_, s)| s.playback.is_some())
.map(|(&h, _)| h)
.collect()
};
frames.sort_by_key(|h| self.model_ref().arena.frame(*h).map(|f| f.insertion_seq));
for h in frames {
stop_movie(&self.lua, h);
}
}
/// The draw pass's movie callbacks (`0x78d650` registers `0x78d680` on layer 2): each visible
/// movie frame that plays steps its clock, in the strata, level and creation order the frames
/// draw in.
pub(super) fn paint_movies(&mut self) {
let frames: Vec<FrameHandle> = {
let model = self.model_ref();
let mut frames: Vec<(u8, u16, u32, FrameHandle)> = model
.movies
.frames
.iter()
.filter(|(_, s)| s.playback.is_some())
.filter_map(|(&h, _)| {
let f = model.arena.frame(h)?;
f.effective_visible
.then(|| (f.strata.index(), f.level, f.insertion_seq, h))
})
.collect();
frames.sort_unstable_by_key(|&(strata, level, seq, _)| (strata, level, seq));
frames.into_iter().map(|(_, _, _, h)| h).collect()
};
for h in frames {
step_movie(&self.lua, h);
}
// A plain frame has none of the methods.
s.run(r#"P = CreateFrame("Frame", "NotAMovie")"#).unwrap();
assert!(s.eval::<bool>("return P.StartMovie == nil").unwrap());
assert!(s.errors().is_empty(), "{:?}", s.errors());
}
}
#[cfg(test)]
mod tests;
@@ -0,0 +1,140 @@
//! A movie's subtitle file, `<name>.sbt`, as the subtitle loader reads it (`0x78cb00`).
use super::super::console_exec::s_str_tokenize;
/// One caption: its start and end on the movie clock, in milliseconds, and its text, the 12-byte
/// record the loader appends (`0x78cceb`, `0x78cd44`, `0x78cd62`).
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct Caption {
pub(crate) start: u32,
pub(crate) end: u32,
pub(crate) text: Vec<u8>,
}
/// The line buffer the loader tokenizes into (`[ebp-0x408]`, `0x400` bytes).
const LINE_BYTES: usize = 0x400;
/// The milliseconds a caption time's frame field counts (`0x78ccdf imul eax,eax,0x29`).
const FRAME_MS: i32 = 41;
/// The captions of an `.sbt` file. A leading `0xef` skips three bytes, a UTF-8 mark
/// (`0x78cb4d`). The file is cut into lines at `\r` and `\n` (`0x64ae50`, delimiters `0x82edfc`),
/// empty ones skipped; a line that starts with `0` (`0x78cb8a`) is a time line,
/// `HH:MM:SS:FF - HH:MM:SS:FF`, and the line after it is the caption's text. Any other line is
/// passed over. The read ends at an empty token, a caption with an empty text included, or the
/// file's end.
pub(crate) fn parse(file: &[u8]) -> Vec<Caption> {
// The loaded file ends at its terminator, and the cursor stops at the first NUL (`0x78cd72`).
let end = file.iter().position(|&b| b == 0).unwrap_or(file.len());
let mut cursor = &file[..end];
if cursor.first() == Some(&0xef) {
cursor = cursor.get(3..).unwrap_or(&[]);
}
let mut line = [0u8; LINE_BYTES];
let next_line = |cursor: &mut &[u8], line: &mut [u8; LINE_BYTES]| {
let token = s_str_tokenize(cursor, LINE_BYTES, b"\r\n");
line[..token.len()].copy_from_slice(&token);
line[token.len()] = 0;
token
};
let mut out = Vec::new();
loop {
let token = next_line(&mut cursor, &mut line);
let Some(&first) = token.first() else {
break;
};
if first == b'0' {
// Each field is `SStrToInt` at its fixed column of the buffer (`0x78cca4`-`0x78cd28`),
// which reads past a short line into what the longer lines before it left there.
let start = time_at(&line, 0);
let end = time_at(&line, 14);
let text = next_line(&mut cursor, &mut line);
let empty = text.is_empty();
out.push(Caption { start, end, text });
if empty {
break;
}
}
if cursor.is_empty() {
break;
}
}
out
}
/// The time whose hours field starts at `at`: hours, minutes and seconds at `at`, `at + 3` and
/// `at + 6` as milliseconds, plus the frames at `at + 9` times [`FRAME_MS`], in the 32-bit
/// register's wrapping arithmetic.
fn time_at(line: &[u8; LINE_BYTES], at: usize) -> u32 {
let field = |off: usize| int_at(line, at + off);
let hms = field(0)
.wrapping_mul(60)
.wrapping_add(field(3))
.wrapping_mul(60)
.wrapping_add(field(6))
.wrapping_mul(1000);
hms.wrapping_add(field(9).wrapping_mul(FRAME_MS)) as u32
}
/// `SStrToInt` (`0x64ac60`) of the NUL-terminated bytes at `at`.
fn int_at(line: &[u8; LINE_BYTES], at: usize) -> i32 {
let rest = &line[at.min(LINE_BYTES)..];
let end = rest.iter().position(|&b| b == 0).unwrap_or(rest.len());
super::super::binding_abi::s_str_to_int(&String::from_utf8_lossy(&rest[..end]))
}
#[cfg(test)]
mod tests {
use super::*;
fn caption(start: u32, end: u32, text: &str) -> Caption {
Caption {
start,
end,
text: text.as_bytes().to_vec(),
}
}
/// The time lines' fields at their columns, the frames at 41 ms; the mark skipped, `\r\n`
/// and blank lines alike as one break, and a line that is no time line passed over.
#[test]
fn an_sbt_file_reads_as_its_captions() {
let file = b"\xef\xbb\xbfMovie captions\r\n\r\n\
00:00:01:12 - 00:00:04:00\r\nFirst line\r\n\
\n00:01:02:03 - 01:00:00:24\nSecond\n";
assert_eq!(
parse(file),
[
caption(1000 + 12 * 41, 4000, "First line"),
caption(62_000 + 3 * 41, 3_600_000 + 24 * 41, "Second"),
]
);
}
/// The fields are read at fixed columns of the line buffer, so a short time line reads the
/// bytes a longer line left past its end; a caption with no text ends the file, kept.
#[test]
fn a_short_time_line_reads_what_the_buffer_holds_and_an_empty_text_ends_the_read() {
// `0:5` puts its terminator at column 3, so the minutes read 0 and the seconds at column
// 6 read the first line's `01`, and the end's fields read its `00:00:09:00`. A blank line
// is no token, so the line after it is the third caption's text, and `C`, no time line,
// is passed over.
let file = b"00:00:01:00 - 00:00:09:00\nA\n0:5\nB\n00:00:20:00 - 00:00:21:00\n\n\
00:00:30:00 - 00:00:31:00\nC\n";
assert_eq!(
parse(file),
[
caption(1000, 9000, "A"),
caption(1000, 9000, "B"),
caption(20_000, 21_000, "00:00:30:00 - 00:00:31:00"),
]
);
// The text line is tokenized whatever it holds; only an empty token stops the read.
assert_eq!(
parse(b"00:00:01:00 - 00:00:02:00\n"),
[caption(1000, 2000, "")]
);
assert!(parse(b"").is_empty());
assert!(parse(b"\xef\xbb").is_empty());
}
}
@@ -0,0 +1,322 @@
//! A playing movie: the decoder, the clock that picks its frame (`0x78cf30`) and its captions.
use benilla_movie::Movie;
use super::captions::Caption;
/// The movie's audio stream as the host reports it: the reference opens it inside `StartMovie`
/// (`0x78ca30`), the host one frame later.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum Audio {
/// No stream: the file has no audio, or it would not open or play, so the movie runs on the
/// wall clock (`0x78ca7f`, the handle `+0x3b0` left 0).
None,
/// Asked of the host, not yet answered: a stream that has played nothing, so the clock waits
/// (`0x78cf5d`).
Pending,
/// Playing, at this play time (`FSOUND_Stream_GetTime`, `0x7fdaa2`).
At(u32),
}
/// What one clock step did.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum Step {
/// Nothing new to show: the audio has not started, or the frame is the one shown.
Hold,
/// The movie is over: its last frame passed, its audio ended or a shown frame failed.
Finish,
/// A new frame was decoded and shown.
Shown,
}
/// The playing state `StartMovie` builds and `StopMovie` tears down, the fields of the frame from
/// `+0x318` on that the clock reads.
#[derive(Clone)]
pub(crate) struct Playback {
/// The start's number, by which the host keys the audio stream it holds for it.
pub(crate) id: u64,
pub(crate) movie: Movie,
pub(crate) audio: Audio,
/// `+0x318`: set by the clock at the last frame, by the audio's end callback (`0x78c070`) and
/// by a shown frame's failure (`0x78d0c0`); the next step stops the movie.
pub(crate) finished: bool,
/// `+0x3b4`: the wall time the clock counts from, 0 until the first step anchors it.
base: u32,
/// `+0x3c8`: the movie clock in milliseconds.
pub(crate) clock: u32,
/// `+0x3b8`: the frame shown, -1 before the first.
pub(crate) shown: i32,
/// `+0x3bc`: the frame the last step aimed at.
pub(crate) target: i32,
/// `+0x3c4`: the frames the audio clock has pulled the wall clock by.
pub(crate) offset: i32,
/// `+0x3c0`: the steps that skipped frames.
pub(crate) dropped: u32,
pub(crate) captions: Vec<Caption>,
/// `+0x3dc`: the caption shown, `None` for -1.
pub(crate) caption: Option<usize>,
/// Frames shown, so the host uploads each picture once.
pub(crate) serial: u64,
}
/// The x87's `fmul dword [0x801360]`: 0.001 as a single.
const MS_TO_S: f32 = 0.001;
impl Playback {
pub(crate) fn new(id: u64, movie: Movie, audio: Audio, captions: Vec<Caption>) -> Self {
// The decoder start's resets (`0x78c95f`-`0x78c975`) and the audio start's (`0x78ca83`,
// `0x78ca89`); the loader leaves no caption shown (`0x78cd86`).
Self {
id,
movie,
audio,
finished: false,
base: 0,
clock: 0,
shown: -1,
target: 0,
offset: 0,
dropped: 0,
captions,
caption: None,
serial: 0,
}
}
/// The frame at `ms` on a clock: `trunc(ms · rate · 0.001 + 0.5)` at the x87's 53 bits, the
/// clock loaded as an unsigned 64-bit integer (`0x78cf9c`-`0x78cfb1`).
fn frame_at(&self, ms: u32) -> i32 {
let rate = f64::from(self.movie.rate());
(f64::from(ms) * rate * f64::from(MS_TO_S) + 0.5) as i64 as i32
}
/// One step of the clock (`0x78cf30`), at the wall time `now` in milliseconds (`0x42c010`).
///
/// The first step anchors the clock: to the audio's play time, waiting while that is 0, or
/// with no audio to now. Each later one reads the wall clock since the anchor, and with audio
/// moves the offset one frame toward the audio's frame when the two differ by more than two
/// frames, or by two while the frame would not move. The target is the clock's frame plus the
/// offset, never behind the frame shown; at the frame count, or with the finished flag set,
/// the movie finishes. A target past the next frame decodes the frames between without
/// showing them, then shows the target.
pub(crate) fn step(&mut self, now: u32) -> Step {
let audio = match self.audio {
Audio::None => None,
Audio::Pending => Some(0),
Audio::At(t) => Some(t),
};
if self.base == 0 {
if let Some(t) = audio {
self.clock = t;
if t == 0 {
return Step::Hold;
}
}
self.base = now.wrapping_sub(self.clock);
} else {
self.clock = now.wrapping_sub(self.base);
}
let wall = self.frame_at(self.clock);
if let Some(t) = audio {
let d = self
.frame_at(t)
.wrapping_sub(self.offset)
.wrapping_sub(wall);
let gap = d.wrapping_abs();
if gap > 2 || (gap == 2 && self.offset.wrapping_add(wall) == self.shown) {
self.offset += if d > 0 { 1 } else { -1 };
}
}
let target = self.offset.wrapping_add(wall).max(self.shown);
self.target = target;
if target >= self.movie.frame_count() as i32 {
self.finished = true;
}
if self.finished {
return Step::Finish;
}
if target == self.shown {
return Step::Hold;
}
if target != self.shown + 1 {
self.dropped += 1;
}
// `0x78d090`: each frame up to the one before the target, decoded and not shown.
while self.shown < target - 1 {
let _ = self.movie.decode_next();
self.shown += 1;
}
// A frame past the file's index fails as a decoder error does.
if matches!(self.movie.decode_next(), Ok(true)) {
self.serial += 1;
} else {
self.finished = true;
}
self.shown = target;
Step::Shown
}
/// The caption step after a shown frame (`0x78d0ca`-`0x78d10d`): the caption up whose end the
/// clock has reached comes down. Whether it did.
pub(crate) fn caption_ended(&mut self) -> bool {
match self.caption {
Some(i) if self.captions.get(i).is_none_or(|c| c.end <= self.clock) => {
self.caption = None;
true
}
_ => false,
}
}
/// The next caption step (`0x78d117`-`0x78d191`): with none up, and subtitles enabled or no
/// audio stream, the first caption whose range holds the clock goes up. Its text.
pub(crate) fn caption_to_show(&mut self, subtitles: bool) -> Option<Vec<u8>> {
if self.caption.is_some() || !(subtitles || self.audio == Audio::None) {
return None;
}
let clock = self.clock;
let i = self
.captions
.iter()
.position(|c| c.start <= clock && clock < c.end)?;
self.caption = Some(i);
Some(self.captions[i].text.clone())
}
}
#[cfg(test)]
mod tests {
use super::*;
/// A 1024-wide movie of `frames` empty chunks (each a repeat of the picture before it) at
/// 25 frames a second, its header's frame count `count`.
fn movie(frames: usize, count: u32) -> Movie {
let empty: Vec<&[u8]> = vec![b""; frames];
let file = benilla_movie::testing::synthetic_avi(1024, 464, (1, 25), count, &empty, &[]);
Movie::open(file).expect("synthetic movie")
}
fn playback(audio: Audio) -> Playback {
Playback::new(1, movie(100, 100), audio, Vec::new())
}
/// The wall clock alone: the first step anchors at now and shows frame 0; a step on the same
/// frame holds; a late step decodes the frames it passed without counting them shown, and
/// counts one drop; the frame is `trunc(ms · 25 · 0.001 + 0.5)`, so 20 ms is frame 1.
#[test]
fn the_wall_clock_picks_the_rounded_frame_and_skips_what_it_passed() {
let mut p = playback(Audio::None);
assert_eq!(p.step(5000), Step::Shown);
assert_eq!((p.shown, p.serial, p.movie.next_frame()), (0, 1, 1));
assert_eq!(p.step(5019), Step::Hold, "19 ms rounds to frame 0");
assert_eq!(p.step(5020), Step::Shown, "20 ms is half a frame: frame 1");
assert_eq!((p.shown, p.dropped), (1, 0));
// 300 ms is frame 8 (7.5 rounded up): frames 2..=7 decoded unshown, 8 shown.
assert_eq!(p.step(5300), Step::Shown);
assert_eq!(
(p.shown, p.serial, p.movie.next_frame(), p.dropped),
(8, 3, 9, 1)
);
assert_eq!(p.clock, 300);
}
/// The finish: the step whose frame reaches the header's frame count finishes without
/// decoding; so does a finished flag the audio set, whatever the clock says.
#[test]
fn the_frame_count_and_the_audio_end_finish_the_movie() {
let mut p = playback(Audio::None);
assert_eq!(p.step(1000), Step::Shown);
// 99 frames on is 3960 ms; frame 100 is 3980 ms.
assert_eq!(p.step(1000 + 3960), Step::Shown);
assert_eq!(p.shown, 99);
assert_eq!(p.step(1000 + 3979), Step::Hold);
assert_eq!(p.step(1000 + 3980), Step::Finish);
assert_eq!((p.target, p.shown), (100, 99));
let mut p = playback(Audio::At(40));
assert_eq!(p.step(1000), Step::Shown);
p.finished = true;
assert_eq!(p.step(1000), Step::Finish);
}
/// The header's count rules, not the index: a count past the indexed frames fails the first
/// frame past them, which finishes the movie at the next step.
#[test]
fn a_frame_past_the_index_fails_and_finishes() {
let mut p = Playback::new(1, movie(2, 10), Audio::None, Vec::new());
assert_eq!(p.step(1000), Step::Shown);
assert_eq!(p.step(1040), Step::Shown);
assert_eq!((p.shown, p.serial, p.finished), (1, 2, false));
assert_eq!(p.step(1080), Step::Shown);
assert_eq!((p.shown, p.serial, p.finished), (2, 2, true));
assert_eq!(p.step(1080), Step::Finish);
}
/// With audio the clock waits for the stream's first played millisecond and anchors to it;
/// then the audio clock pulls the wall clock one frame a step when the two part by more than
/// two frames, or by exactly two while the frame stands still.
#[test]
fn the_audio_anchors_the_clock_and_nudges_it_a_frame_at_a_time() {
let mut p = playback(Audio::Pending);
assert_eq!(p.step(5000), Step::Hold, "a stream that has played nothing");
p.audio = Audio::At(0);
assert_eq!(p.step(5010), Step::Hold);
p.audio = Audio::At(400);
// Anchored at 400 ms of audio: frame 10.
assert_eq!(p.step(6000), Step::Shown);
assert_eq!((p.clock, p.shown, p.offset), (400, 10, 0));
// The wall clock 40 ms on (frame 11), the audio three frames ahead of it (frame 14):
// the offset moves one frame.
p.audio = Audio::At(560);
assert_eq!(p.step(6040), Step::Shown);
assert_eq!((p.clock, p.offset, p.shown), (440, 1, 12));
// Two frames apart while the target moves: no nudge.
p.audio = Audio::At(560);
assert_eq!(p.step(6080), Step::Shown);
assert_eq!((p.offset, p.shown), (1, 13));
// Two apart and the target the frame shown: the nudge, back toward the audio.
p.audio = Audio::At(440);
assert_eq!(p.step(6080), Step::Hold);
assert_eq!(
p.offset, 0,
"the audio frame 11 is two behind the target 13"
);
// The target never falls behind the frame shown.
assert_eq!((p.target, p.shown), (13, 13));
}
/// A caption comes down at its end, and the one that holds the clock goes up only with
/// subtitles enabled or no audio.
#[test]
fn captions_follow_the_clock_and_the_subtitle_switch() {
let captions = vec![
Caption {
start: 100,
end: 200,
text: b"one".to_vec(),
},
Caption {
start: 200,
end: 300,
text: b"two".to_vec(),
},
];
let mut p = Playback::new(1, movie(100, 100), Audio::None, captions.clone());
p.step(1000);
assert_eq!(p.caption_to_show(false), None, "the clock is at 0");
p.step(1100);
assert!(!p.caption_ended());
assert_eq!(p.caption_to_show(false).as_deref(), Some(&b"one"[..]));
assert_eq!(p.caption_to_show(false), None, "one is up");
p.step(1199);
assert!(!p.caption_ended(), "199 ms is inside the first");
p.step(1200);
assert!(p.caption_ended());
assert_eq!(p.caption_to_show(false).as_deref(), Some(&b"two"[..]));
let mut p = Playback::new(1, movie(100, 100), Audio::At(100), captions);
p.step(1000);
assert_eq!(p.caption_to_show(false), None, "audio and subtitles off");
assert_eq!(p.caption_to_show(true).as_deref(), Some(&b"one"[..]));
}
}
@@ -0,0 +1,350 @@
use std::cell::RefCell;
use std::rc::Rc;
use crate::script::{MovieAudio, MovieOpen, QuadContent, UiScript};
/// Every path the reader was asked for, and how it opened.
type Asked = Rc<RefCell<Vec<(String, MovieOpen)>>>;
/// A 1024-wide movie of `frames` empty chunks at 25 frames a second, `sounds` its audio chunks.
fn avi(frames: u32, sounds: &[&[u8]]) -> Vec<u8> {
let empty: Vec<&[u8]> = vec![b""; frames as usize];
benilla_movie::testing::synthetic_avi(1024, 464, (1, 25), frames, &empty, sounds)
}
/// A glue VM whose reader answers `files` by exact path and logs every ask, with `M` a movie
/// frame whose three scripts append to the Lua list `log`.
fn movie_vm(files: Vec<(&'static str, Vec<u8>)>) -> (UiScript, Asked) {
let mut s = UiScript::new_glue().unwrap();
let asked = Rc::new(RefCell::new(Vec::new()));
let seen = asked.clone();
s.set_movie_reader(Box::new(move |path, open| {
seen.borrow_mut().push((path.to_string(), open));
files
.iter()
.find(|(p, _)| *p == path)
.map(|(_, bytes)| bytes.clone())
}));
s.run(
r#"log = {}
M = CreateFrame("MovieFrame", "MovieProbe")
M:SetScript("OnMovieFinished", function() table.insert(log, "finished") end)
M:SetScript("OnMovieShowSubtitle", function() table.insert(log, "show:" .. arg1) end)
M:SetScript("OnMovieHideSubtitle", function() table.insert(log, "hide") end)"#,
)
.unwrap();
s.set_now(8.0);
(s, asked)
}
fn log(s: &UiScript) -> String {
s.eval::<String>("return table.concat(log, ' ')").unwrap()
}
fn shown(s: &UiScript) -> Option<i32> {
s.movie_pictures().first().map(|p| p.shown)
}
/// `StartMovie` answers 1 for a movie whose file and decoder start, and nil when the `.avi` is
/// missing, is no AVI, or is a width the decoder refuses (`0x78ce52`, `0x78ce64`); a missing
/// `.sbt` is ignored (`0x78ce77`). The `.avi` opens loose first and the `.sbt` from the archives,
/// each the name with its extension.
#[test]
fn start_movie_answers_1_for_a_movie_that_starts_and_nil_otherwise() {
let narrow = benilla_movie::testing::synthetic_avi(640, 480, (1, 25), 1, &[b""], &[]);
let (s, asked) = movie_vm(vec![
("Interface\\Cinematics\\Good.avi", avi(4, &[])),
("Bad.avi", b"RIFF\0\0\0\0WAVE".to_vec()),
("Narrow.avi", narrow),
]);
assert!(s
.eval::<bool>(r#"return M:StartMovie("Missing") == nil"#)
.unwrap());
assert!(s
.eval::<bool>(r#"return M:StartMovie("Bad") == nil"#)
.unwrap());
assert!(s
.eval::<bool>(r#"return M:StartMovie("Narrow") == nil"#)
.unwrap());
assert!(!s.movie_playing(), "no failed start plays");
assert!(s
.eval::<bool>(r#"return M:StartMovie("Interface\\Cinematics\\Good") == 1"#)
.unwrap());
assert!(s.movie_playing());
assert_eq!(
asked.borrow().clone(),
[
("Missing.avi".to_string(), MovieOpen::LooseFirst),
("Bad.avi".to_string(), MovieOpen::LooseFirst),
("Narrow.avi".to_string(), MovieOpen::LooseFirst),
(
"Interface\\Cinematics\\Good.avi".to_string(),
MovieOpen::LooseFirst
),
(
"Interface\\Cinematics\\Good.sbt".to_string(),
MovieOpen::Archives
),
]
);
assert!(s.errors().is_empty(), "{:?}", s.errors());
}
/// The usage line for anything but a string or a number, the methods on no other frame type, and
/// the three scripts kept by `SetScript`.
#[test]
fn the_movie_methods_check_their_arguments_and_their_frame() {
let (s, _) = movie_vm(Vec::new());
assert!(s.eval::<bool>("return M:StartMovie(7) == nil").unwrap());
assert!(s
.eval::<bool>("return table.getn({M:StopMovie()}) == 0")
.unwrap());
assert!(s
.eval::<bool>(
"return table.getn({M:EnableSubtitles(1)}) + table.getn({M:EnableSubtitles()}) == 0"
)
.unwrap());
for bad in ["M:StartMovie()", "M:StartMovie({})", "M:StartMovie(true)"] {
let err = s.run(bad).unwrap_err().to_string();
assert!(
err.contains(r#"Usage: MovieProbe:StartMovie("filename")"#),
"{bad}: {err}"
);
}
for name in [
"OnMovieFinished",
"OnMovieShowSubtitle",
"OnMovieHideSubtitle",
] {
assert!(
s.eval::<bool>(&format!("return M:GetScript('{name}') ~= nil"))
.unwrap(),
"{name}"
);
}
s.run(r#"P = CreateFrame("Frame", "NotAMovie")"#).unwrap();
assert!(s.eval::<bool>("return P.StartMovie == nil").unwrap());
let err = s.run("M.StopMovie(P)").unwrap_err().to_string();
assert!(
err.contains("Wrong object type for member function"),
"{err}"
);
assert_eq!(
log(&s),
"",
"a StopMovie with nothing playing fires nothing"
);
}
/// `StopMovie` tears a playing movie down and fires `OnMovieFinished` once (`0x78cf1e`); with
/// nothing playing it fires nothing (`0x78cedb`).
#[test]
fn stop_movie_fires_on_movie_finished_once() {
let (mut s, _) = movie_vm(vec![("A.avi", avi(10, &[]))]);
assert!(s.eval::<bool>(r#"return M:StartMovie("A") == 1"#).unwrap());
s.tick(0.0);
assert_eq!(shown(&s), Some(0));
s.run("M:StopMovie() M:StopMovie()").unwrap();
assert_eq!(log(&s), "finished");
assert!(!s.movie_playing());
assert!(s.movie_pictures().is_empty());
assert!(s.errors().is_empty(), "{:?}", s.errors());
}
/// The clock runs on the tick's clock: the first step shows frame 0, each later step the frame
/// its time rounds to, and the step whose frame reaches the count ends the movie, firing
/// `OnMovieFinished`. A hidden frame steps nothing, as its draw callback is not called.
#[test]
fn a_movie_plays_to_its_frame_count_and_finishes() {
let (mut s, _) = movie_vm(vec![("A.avi", avi(10, &[]))]);
assert!(s.eval::<bool>(r#"return M:StartMovie("A") == 1"#).unwrap());
assert_eq!(shown(&s), None, "nothing shown before the first step");
s.tick(0.0);
assert_eq!(shown(&s), Some(0));
s.run("M:Hide()").unwrap();
s.tick(0.125);
assert_eq!(shown(&s), Some(0), "hidden, the clock does not step");
s.run("M:Show()").unwrap();
s.tick(0.0);
assert_eq!(shown(&s), Some(3), "125 ms is frame 3");
s.tick(0.25);
assert_eq!(shown(&s), Some(9), "375 ms rounds to frame 9");
assert_eq!(log(&s), "");
s.tick(0.0078125);
assert_eq!(log(&s), "finished", "382 ms is frame 10, the count");
assert!(!s.movie_playing());
assert!(s.errors().is_empty(), "{:?}", s.errors());
}
/// A caption goes up on the first shown frame whose clock its range holds, with subtitles enabled
/// or no audio, and comes down on the first shown frame past its end (`0x78d0ed`); a step that
/// shows no new frame reads no caption. `StopMovie` with a caption up hides it before the finish
/// (`0x78cda0`).
#[test]
fn captions_go_up_and_come_down_on_shown_frames() {
let sbt = b"00:00:00:02 - 00:00:00:05\r\nHi there\r\n".to_vec();
let (mut s, _) = movie_vm(vec![("A.avi", avi(100, &[])), ("A.sbt", sbt)]);
assert!(s.eval::<bool>(r#"return M:StartMovie("A") == 1"#).unwrap());
s.tick(0.0);
assert_eq!(log(&s), "", "0 ms is before 82 ms");
s.tick(0.125);
assert_eq!(log(&s), "show:Hi there");
s.tick(0.0625);
assert_eq!(log(&s), "show:Hi there", "187 ms is before 205 ms");
s.tick(0.015625);
assert_eq!(
(shown(&s), log(&s).as_str()),
(Some(5), "show:Hi there"),
"203 ms shows no new frame"
);
s.tick(0.03125);
assert_eq!(
log(&s),
"show:Hi there hide",
"234 ms, frame 6, is past the end"
);
let sbt = b"00:00:00:00 - 00:00:10:00\nLong\n".to_vec();
let (mut s, _) = movie_vm(vec![("A.avi", avi(100, &[])), ("A.sbt", sbt)]);
s.run(r#"M:StartMovie("A")"#).unwrap();
s.tick(0.0);
s.tick(0.125);
assert_eq!(log(&s), "show:Long");
s.run("M:StopMovie()").unwrap();
assert_eq!(log(&s), "show:Long hide finished");
}
/// With audio the captions wait for `EnableSubtitles` (`0x78d121`): its flag defaults on when
/// absent and is off for an explicit nil, as `GetScriptFlagArg` reads it; the constructor's is
/// off (`0x78c0ee`).
#[test]
fn enable_subtitles_gates_the_captions_of_a_movie_with_audio() {
let sbt = b"00:00:00:00 - 00:00:10:00\nWords\n".to_vec();
let files = vec![("A.avi", avi(100, &[b"mp3"])), ("A.sbt", sbt)];
for (call, expect) in [
("", ""),
("M:EnableSubtitles()", "show:Words"),
("M:EnableSubtitles(nil)", ""),
("M:EnableSubtitles(1)", "show:Words"),
("M:EnableSubtitles(0)", ""),
] {
let (mut s, _) = movie_vm(files.clone());
s.run(call).unwrap();
s.run(r#"M:StartMovie("A")"#).unwrap();
let starts = s.take_movie_audio_starts();
assert_eq!(starts.len(), 1);
s.set_movie_audio(starts[0].id, MovieAudio::At(100));
s.tick(0.0);
s.set_movie_audio(starts[0].id, MovieAudio::At(225));
s.tick(0.125);
assert_eq!(shown(&s), Some(6), "{call}: anchored at 100 ms of audio");
assert_eq!(log(&s), expect, "{call}");
}
}
/// The audio: its MP3 bytes go to the host once; the clock waits while the stream has played
/// nothing, runs on the wall clock once the stream failed, and the stream's end finishes the
/// movie at the next step. The host holds a stream only for a movie still playing.
#[test]
fn the_host_plays_the_audio_and_its_end_finishes_the_movie() {
let (mut s, _) = movie_vm(vec![("A.avi", avi(100, &[b"ab", b"c"]))]);
s.run(r#"M:StartMovie("A")"#).unwrap();
let starts = s.take_movie_audio_starts();
assert_eq!(
starts.iter().map(|a| a.mp3.clone()).collect::<Vec<_>>(),
[b"abc".to_vec()]
);
assert!(s.take_movie_audio_starts().is_empty(), "handed over once");
let id = starts[0].id;
assert_eq!(s.movie_audio_ids(), [id]);
s.tick(0.0);
s.set_movie_audio(id, MovieAudio::At(0));
s.tick(0.125);
assert_eq!(shown(&s), None, "a stream at 0 ms holds the clock");
s.set_movie_audio(id, MovieAudio::Failed);
assert!(s.movie_audio_ids().is_empty());
s.tick(0.0);
assert_eq!(shown(&s), Some(0), "on the wall clock from here");
s.set_movie_audio(id, MovieAudio::Ended);
assert_eq!(log(&s), "");
s.tick(0.0);
assert_eq!(log(&s), "finished");
assert!(s.movie_audio_ids().is_empty());
}
/// The picture draws at the frame's ARTWORK callback slot once a frame is shown, and no longer
/// once the movie stops.
#[test]
fn the_picture_is_extracted_while_the_movie_shows_one() {
let (mut s, _) = movie_vm(vec![("A.avi", avi(10, &[]))]);
let movie_quads = |s: &mut UiScript| {
s.resolve();
s.extract()
.into_iter()
.filter(|q| matches!(q.content, QuadContent::Movie { .. }))
.count()
};
s.run(r#"M:StartMovie("A")"#).unwrap();
assert_eq!(movie_quads(&mut s), 0);
s.tick(0.0);
assert_eq!(movie_quads(&mut s), 1);
let p = &s.movie_pictures()[0];
assert_eq!((p.width, p.height, p.serial), (1024, 464, 1));
let mut rgba = Vec::new();
assert!(s.write_movie_rgba(p.frame, &mut rgba));
assert_eq!(rgba.len(), 1024 * 464 * 4);
s.run("M:StopMovie()").unwrap();
assert_eq!(movie_quads(&mut s), 0);
}
/// A movie's number is the process's, not the VM's: a rebuilt glue VM's first movie never takes
/// the number of a stream the host still holds for the old VM's.
#[test]
fn movie_numbers_are_never_reused_across_vms() {
let start = || {
let (mut s, _) = movie_vm(vec![("A.avi", avi(10, &[b"mp3"]))]);
s.run(r#"M:StartMovie("A")"#).unwrap();
let ids: Vec<u64> = s.take_movie_audio_starts().iter().map(|a| a.id).collect();
(s, ids)
};
let (_old, first) = start();
let (_new, second) = start();
assert_eq!((first.len(), second.len()), (1, 1));
assert_ne!(first, second);
}
/// A stream that ends before it played a millisecond ends the movie: with no play time to anchor
/// to, the clock runs on the wall clock, and the finished flag the end set stops it.
#[test]
fn a_stream_that_ends_unplayed_still_ends_the_movie() {
let (mut s, _) = movie_vm(vec![("A.avi", avi(100, &[b"mp3"]))]);
s.run(r#"M:StartMovie("A")"#).unwrap();
let id = s.take_movie_audio_starts()[0].id;
s.tick(0.0);
s.set_movie_audio(id, MovieAudio::Ended);
s.tick(0.0);
assert_eq!(log(&s), "finished");
assert!(!s.movie_playing());
}
/// The frame's destructor runs the teardown (`0x78c280` calls `0x78ced0`), so a VM dropped with a
/// movie playing fires its `OnMovieFinished`.
#[test]
fn a_vm_dropped_mid_movie_finishes_its_movie() {
let (mut s, _) = movie_vm(vec![("A.avi", avi(100, &[]))]);
let fired = Rc::new(RefCell::new(0));
let count = fired.clone();
let f = s
.lua()
.create_function(move |_, ()| {
*count.borrow_mut() += 1;
Ok(())
})
.unwrap();
s.lua().globals().set("note_finished", f).unwrap();
s.run(r#"M:SetScript("OnMovieFinished", function() note_finished() end) M:StartMovie("A")"#)
.unwrap();
s.tick(0.0);
drop(s);
assert_eq!(*fired.borrow(), 1);
}
+1
View File
@@ -384,6 +384,7 @@ impl super::UiScript {
self.mouse_move(x, y);
}
self.paint_model_panes();
self.paint_movies();
// `WOW_UI_HANDLERS=<secs>`: last, so its report covers everything this tick fired.
self.report_handler_profile(elapsed);
}
+7
View File
@@ -104,6 +104,13 @@ pub enum QuadContent {
/// A `ModelFFX` (`0x46fa00`): the glue screens' scene, which the app's glue booth draws.
ffx: bool,
},
/// A playing `MovieFrame`'s picture, its draw callback's quad (`0x78d1a0`): placed on the
/// whole window, not the frame's rect, from the movie's [`crate::script::MovieBitmap`]; the
/// pixels are [`crate::script::UiScript::write_movie_rgba`]'s.
Movie {
/// The movie frame, which keys its picture.
handle: crate::widget::FrameHandle,
},
/// A `Texture` region: a BLP path, a solid or vertex colour, or both (a tinted texture).
Texture {
path: Option<String>,
+14 -15
View File
@@ -36,7 +36,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- [benilla-lua](#benilla-lua): 11
- [benilla-protocol](#benilla-protocol): 27
- [benilla-srp](#benilla-srp): 2
- [benilla-ui](#benilla-ui): 133
- [benilla-ui](#benilla-ui): 132
- [benilla-world](#benilla-world): 49
### benilla-app
@@ -264,10 +264,10 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- The reference never steals. Every WoW voice is an `FSOUND_Stream` at priority 256 (`fmod.dll 0x1002be47`) and FMOD's steal scan skips `>= 256` (`0x100268e9`), so its 13th sound is dropped. ([`src/sound/kit.rs:284`](../crates/benilla-app/src/sound/kit.rs#L284))
- The reference sums at full scale and clips (a close 1.0 kit reaches `FSOUND_SetVolume(255)` through `0x7a5dc0`, FMOD's MMX mixers saturate with `paddsw`, and no gain depends on the live voice count); this limits, because every WoW SFX is mastered to full scale, so overlapping kits clip into broadband distortion, as when a mass buff lands five sample-aligned copies of one 0 dBFS file. `SoundOutputLimiter 0` turns it off. ([`src/sound/limiter.rs:3`](../crates/benilla-app/src/sound/limiter.rs#L3))
- The mantissa-bit volume curve (`0x7a5d70`, `(v·255+512.5).bits >> 14 & 0xff`) and the `__ftol` truncations are dropped, because they only quantized to FMOD's integer levels and our backend takes float amplitudes. ([`src/sound/math.rs:4`](../crates/benilla-app/src/sound/math.rs#L4))
- The reference also refuses to open a new non-music stream while inactive (`0x7a52bf`); benilla starts everything and gates the output, because a refusal at kit start would make an unattended capture record silence. ([`src/sound/mod.rs:95`](../crates/benilla-app/src/sound/mod.rs#L95))
- Default off where the reference registers "1". Its reverb is FMOD 3's EAX API, which renders only with hardware 3D mixing, so off is what the reference is heard to produce (inferred: `fmod.dll`'s render side is untraced). ([`src/sound/mod.rs:103`](../crates/benilla-app/src/sound/mod.rs#L103))
- `SoundOutputLimiter`, not a 1.12 CVar, default on, so overlapping full-scale kits are limited rather than clipped. ([`src/sound/mod.rs:121`](../crates/benilla-app/src/sound/mod.rs#L121))
- With no character the reference leaves the listener where it was; benilla seats it on the camera, where the view is. ([`src/sound/mod.rs:474`](../crates/benilla-app/src/sound/mod.rs#L474))
- The reference also refuses to open a new non-music stream while inactive (`0x7a52bf`); benilla starts everything and gates the output, because a refusal at kit start would make an unattended capture record silence. ([`src/sound/mod.rs:97`](../crates/benilla-app/src/sound/mod.rs#L97))
- Default off where the reference registers "1". Its reverb is FMOD 3's EAX API, which renders only with hardware 3D mixing, so off is what the reference is heard to produce (inferred: `fmod.dll`'s render side is untraced). ([`src/sound/mod.rs:105`](../crates/benilla-app/src/sound/mod.rs#L105))
- `SoundOutputLimiter`, not a 1.12 CVar, default on, so overlapping full-scale kits are limited rather than clipped. ([`src/sound/mod.rs:123`](../crates/benilla-app/src/sound/mod.rs#L123))
- With no character the reference leaves the listener where it was; benilla seats it on the camera, where the view is. ([`src/sound/mod.rs:484`](../crates/benilla-app/src/sound/mod.rs#L484))
- The reference also plays an optimistic coin at the loot-money click, and at the auto-loot sweep's money, once a session (`0x4c201b`-`0x4c2020`, the same `0x458030` call), so looted money sounds twice; benilla plays the watcher's coin alone, because one coin on the confirmed change reads cleanly and the round trip the early coin hides is imperceptible on a local server. ([`src/sound/money.rs:7`](../crates/benilla-app/src/sound/money.rs#L7))
- 1.12.1 sets FMOD up on driver 0 and, when that fails, runs silent for the session (`Sound::Initialize` `0x7a4330`, the driver −1 → 0 at `0x7a445f`); here another output stands in, because on Linux the default is often a stock `dmix` whose card a sound server holds. ([`src/sound/output/cpal.rs:193`](../crates/benilla-app/src/sound/output/cpal.rs#L193))
- A change of the default output device is followed (here and in `coreaudio.rs`), where 1.12.1 initialises its sound device once and never again (`Sound::Initialize` `0x7a4330` refuses a second call; the driver-enumeration functions `0x7a6320`-`0x7a6380` have no caller), because a headset plugged in mid-session should play at once. ([`src/sound/output/cpal.rs:544`](../crates/benilla-app/src/sound/output/cpal.rs#L544))
@@ -428,17 +428,17 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- The reference reads the install's `Interface\AddOns\`; benilla reads an install and does not live in one, so its addons live in its own state folder, and only there. ([`src/ui_script/addons.rs:264`](../crates/benilla-app/src/ui_script/addons.rs#L264))
- That file is renamed to `<Name>.lua.bak`, where the reference deletes it, so an addon update that drops its toc line costs the player nothing they cannot get back. ([`src/ui_script/addons.rs:657`](../crates/benilla-app/src/ui_script/addons.rs#L657))
- The reference writes none (its file opens with a blank line); ours names the file, because players open this folder. ([`src/ui_script/addons.rs:715`](../crates/benilla-app/src/ui_script/addons.rs#L715))
- The reference then re-reads the aspect (`0x492f13`), and on a change of 0.001 or more calls `0x491380`, which sets the reload trigger (`[0xb4b3f4]`) when the script-context check `0x494a50(0xa)` allows it; here a resize re-lays out the live UI, the chat bubbles' window-derived `BubbleGeometry` with it, because the window resizes freely and a reload on each resize would tear down every addon's state mid-play. ([`src/ui_script/extract/mod.rs:528`](../crates/benilla-app/src/ui_script/extract/mod.rs#L528))
- The V-plate border is resampled sharp to the quad's physical size rather than GPU-magnified, so its 1 px bevel stays crisp; keyed by that size, so only a resize re-rasterises it. ([`src/ui_script/extract/mod.rs:1426`](../crates/benilla-app/src/ui_script/extract/mod.rs#L1426))
- The reference then re-reads the aspect (`0x492f13`), and on a change of 0.001 or more calls `0x491380`, which sets the reload trigger (`[0xb4b3f4]`) when the script-context check `0x494a50(0xa)` allows it; here a resize re-lays out the live UI, the chat bubbles' window-derived `BubbleGeometry` with it, because the window resizes freely and a reload on each resize would tear down every addon's state mid-play. ([`src/ui_script/extract/mod.rs:532`](../crates/benilla-app/src/ui_script/extract/mod.rs#L532))
- The V-plate border is resampled sharp to the quad's physical size rather than GPU-magnified, so its 1 px bevel stays crisp; keyed by that size, so only a resize re-rasterises it. ([`src/ui_script/extract/mod.rs:1443`](../crates/benilla-app/src/ui_script/extract/mod.rs#L1443))
- No signature or digest check (`0x46a90b`, `0x46a9d3`, `0x401560(9)`), so the chain's toc always loads and `FRAMES_LOADED` follows, because the check verifies Blizzard's signature with a key carried in the client binary, which benilla does not ship, and a modified interface file is loaded rather than refused. ([`src/ui_script/glue.rs:14`](../crates/benilla-app/src/ui_script/glue.rs#L14))
- The reference's size callback only re-scales `GlueParent` and re-lays it out (`0x46ac51`, `0x46ac56`), as its root keeps `gxResolution`'s aspect until a rebuild (`0x41ad10` at `0x46a828`) and its window keeps that shape while dragged (`0x5989d7`); here the root is the window's, which takes any shape, so the box follows it on every resize, where a rebuild would reset the screen (the create screen's character and name, the typed password, the selection). ([`src/ui_script/glue.rs:296`](../crates/benilla-app/src/ui_script/glue.rs#L296))
- The reference's size callback only re-scales `GlueParent` and re-lays it out (`0x46ac51`, `0x46ac56`), as its root keeps `gxResolution`'s aspect until a rebuild (`0x41ad10` at `0x46a828`) and its window keeps that shape while dragged (`0x5989d7`); here the root is the window's, which takes any shape, so the box follows it on every resize, where a rebuild would reset the screen (the create screen's character and name, the typed password, the selection). ([`src/ui_script/glue.rs:346`](../crates/benilla-app/src/ui_script/glue.rs#L346))
- The reference's handler completes whichever operation is current; here only the character list's does, in state 3, and a reply of another cause (a roster nothing of the screen asked for) or of another link (before a realm change) completes nothing. ([`src/ui_script/glue_mgr.rs:1516`](../crates/benilla-app/src/ui_script/glue_mgr.rs#L1516))
- The character is the platform's Unicode text, so a player can type any language on any platform. ([`src/ui_script/input.rs:472`](../crates/benilla-app/src/ui_script/input.rs#L472))
- A capture run (`scenario_active`) keeps the CRT's default seed, 1, so its frames reproduce. ([`src/ui_script/lifecycle.rs:160`](../crates/benilla-app/src/ui_script/lifecycle.rs#L160))
- A capture run (`scenario_active`) keeps the CRT's default seed, 1, so its frames reproduce. ([`src/ui_script/lifecycle.rs:170`](../crates/benilla-app/src/ui_script/lifecycle.rs#L170))
- The files are under `benilla-config/Logs/`, since the install is read-only. ([`src/ui_script/load_log.rs:5`](../crates/benilla-app/src/ui_script/load_log.rs#L5))
- `FULLSCREEN_QUADS_RESEAT` re-sizes the full-screen quads, which the stock files size only in their OnLoads, because a resize here keeps the loaded UI and the blackout would stop short of the new screen. ([`src/ui_script/manifest.rs:64`](../crates/benilla-app/src/ui_script/manifest.rs#L64))
- No `FrameXML.toc` signature check, where `UI_Init` loads on a failed one and then quits (`0x401560(0xa)` at `0x48ff90`), because the check verifies Blizzard's signature with a key carried in the client binary, which benilla does not ship, and a modified interface file is loaded rather than refused. ([`src/ui_script/manifest.rs:161`](../crates/benilla-app/src/ui_script/manifest.rs#L161))
- A flat 0.9, because 1.0 reads oversized. With `useUiScale` off, its default (`0x8430c0`), the reference sets `max(768/H, 0.9)` above 768 px tall and 1.0 at or below (`0x492f70`, on a mode set and from `0x4908ad`), so the two agree from ~853 px up. benilla never reads `useUiScale`: this CVar always applies to `UIParent` alone, as with it on. ([`src/ui_script/mod.rs:255`](../crates/benilla-app/src/ui_script/mod.rs#L255))
- A flat 0.9, because 1.0 reads oversized. With `useUiScale` off, its default (`0x8430c0`), the reference sets `max(768/H, 0.9)` above 768 px tall and 1.0 at or below (`0x492f70`, on a mode set and from `0x4908ad`), so the two agree from ~853 px up. benilla never reads `useUiScale`: this CVar always applies to `UIParent` alone, as with it on. ([`src/ui_script/mod.rs:256`](../crates/benilla-app/src/ui_script/mod.rs#L256))
- The body is read with 0x4000-byte reads filled to the end of the body, so what a read returns does not depend on how the network cut the packets; and the reading stops once the buffer is full, since no later byte can change it. ([`src/ui_script/server_alert.rs:23`](../crates/benilla-app/src/ui_script/server_alert.rs#L23))
- The connection is direct. The reference opens its session with access type 0 (`InternetOpenA`, `0x7a6d97`), the system's proxy settings, which benilla does not read. ([`src/ui_script/server_alert.rs:26`](../crates/benilla-app/src/ui_script/server_alert.rs#L26))
- On a worldport it fires with our descriptor present, so `UnitExists("player")` answers true where the reference's (`0x515970`) misses, because matching it breaks `UnitExists` for no stock reader. ([`src/ui_script/sweep.rs:151`](../crates/benilla-app/src/ui_script/sweep.rs#L151))
@@ -744,7 +744,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- 1.12 has no such CVar; it exists because our Graphics page needs somewhere to keep the stop, and takes the API's name. ([`src/script/cvars.rs:1013`](../crates/benilla-ui/src/script/cvars.rs#L1013))
- The getter reads `CVAR_WORLD_DETAIL`, where the reference's reads only `smallCull` (`0x488d77`), because benilla's stop follows the knob that draws: a console `frillDensity` write moves the ground clutter and `WorldDetail` with it, and no renderer reads `smallCull` (its callback's `[0x868620]` has no reader). ([`src/script/cvars.rs:1041`](../crates/benilla-ui/src/script/cvars.rs#L1041))
- The promotion's IME legs (`0x77d417`–`0x77d431`) and the IME writer's `or 6` (`0x77acde`, in `0x77ac60`) are not modelled: benilla has no IME composition. ([`src/script/editbox/flush.rs:28`](../crates/benilla-ui/src/script/editbox/flush.rs#L28))
- The nameplate glow is shown but never drawn, because its additive rim reads as hard edge lines in our linear-blending pipeline; the lit plate brightens its bar instead. ([`src/script/extract.rs:221`](../crates/benilla-ui/src/script/extract.rs#L221))
- The nameplate glow is shown but never drawn, because its additive rim reads as hard edge lines in our linear-blending pipeline; the lit plate brightens its bar instead. ([`src/script/extract.rs:223`](../crates/benilla-ui/src/script/extract.rs#L223))
- A host of 0x80 bytes or more is refused. The reference copies the host into a 0x80-byte buffer (`0x5abc7c`-`0x5abc9c`) and writes its terminator one byte past the end, and the cut host could end in a whitelisted suffix the real one does not; this takes the safe side. ([`src/script/glue_core.rs:412`](../crates/benilla-ui/src/script/glue_core.rs#L412))
- Benilla keeps that decode and then encodes it again, every byte outside the URL characters `URL_SAFE` as `%XY` (a decoded `%` too), because the opener on some platforms is a shell script (`xdg-open`) or takes the raw command tail (`rundll32`) and the string comes off the wire: no space, quote, backtick, `$`, `;`, `<`, `>`, `|`, `^`, `\`, brace or control byte reaches it. ([`src/script/glue_core.rs:456`](../crates/benilla-ui/src/script/glue_core.rs#L456))
- Past `NAME_TRIES` names the answer is nil, where the reference keeps trying, forever when the generator has learned nothing. ([`src/script/glue_create.rs:968`](../crates/benilla-ui/src/script/glue_create.rs#L968))
@@ -761,10 +761,9 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- A listing that finds no icon stays empty, to be listed again on the next ask, where the reference's dedup then reads below its null list (`0x4f0134`-`0x4f0145`) and faults. ([`src/script/macros.rs:534`](../crates/benilla-ui/src/script/macros.rs#L534))
- Each line is trimmed, because the reference sends an indented `" /say hi"` as plain chat, never as the command meant. ([`src/script/macros/bind.rs:30`](../crates/benilla-ui/src/script/macros/bind.rs#L30))
- The `/cast` argument is trimmed, because the reference binds `/cast Fireball` (two spaces) to a name that never resolves. ([`src/script/macros/bind.rs:50`](../crates/benilla-ui/src/script/macros/bind.rs#L50))
- The client's Lua has no such bound, as nothing sets a hook (`lua_sethook`, `0x6fba40`, has no caller and no pointer to it), so a load that never ends hangs it. ([`src/script/mod.rs:905`](../crates/benilla-ui/src/script/mod.rs#L905))
- The reference sets the cells only when glue or the interface is built, `0x41ad10` from `0x46a828` (`0x46a7b0`) and `0x48fe2b` (`0x48fbf0`), and a resize reaches them only through the rebuild it asks for. ([`src/script/mod.rs:956`](../crates/benilla-ui/src/script/mod.rs#L956))
- The client's Lua has no such bound, as nothing sets a hook (`lua_sethook`, `0x6fba40`, has no caller and no pointer to it), so a load that never ends hangs it. ([`src/script/mod.rs:918`](../crates/benilla-ui/src/script/mod.rs#L918))
- The reference sets the cells only when glue or the interface is built, `0x41ad10` from `0x46a828` (`0x46a7b0`) and `0x48fe2b` (`0x48fbf0`), and a resize reaches them only through the rebuild it asks for. ([`src/script/mod.rs:969`](../crates/benilla-ui/src/script/mod.rs#L969))
- A path that does not resolve is stored, where the reference raises `Invalid model file: %s` (`0x878b44`), because the file loads asynchronously here and the call cannot know yet. ([`src/script/modelframe.rs:339`](../crates/benilla-ui/src/script/modelframe.rs#L339))
- Benilla plays no pre-rendered movie (#968), so `StartMovie` answers nil, the reference's "could not start" (`0x78d861`), which the stock `MovieFrame_PlayMovie` answers by hiding the frame and so by returning to the login screen. ([`src/script/movieframe.rs:4`](../crates/benilla-ui/src/script/movieframe.rs#L4))
- The reference's free list is FIFO; either keeps every index stable, all an addon can observe. ([`src/script/nameplate.rs:455`](../crates/benilla-ui/src/script/nameplate.rs#L455))
- The reference adds this rim over the bar; we brighten the bar (`LIT_BOOST`), because the rim reads as hard edge lines in our linear-blending pipeline. ([`src/script/nameplate.rs:911`](../crates/benilla-ui/src/script/nameplate.rs#L911))
- A wrapper that decodes to no live widget takes `default_parent`, because the reference, with no `IsA` check, reads a wild pointer. ([`src/script/object/anchor_args.rs:159`](../crates/benilla-ui/src/script/object/anchor_args.rs#L159))
@@ -804,7 +803,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- The selection clears to 0, because the header the reference re-selects (`0x4d7b42`, reading 1) has no spell id; the stock window's `> 1` test treats 0 and 1 alike. ([`src/script/trainer/mod.rs:278`](../crates/benilla-ui/src/script/trainer/mod.rs#L278))
- A header clears it too, because it has no spell id; the reference stores its `0xffffffff` (`0x4d7b05`) and reads back 1, which the stock window's `> 1` test treats the same as 0. ([`src/script/trainer/mod.rs:1224`](../crates/benilla-ui/src/script/trainer/mod.rs#L1224))
- Index 0 is a no-op, because one stray call would spend the purse; the reference buys every visible service for any index at or below 0 (`0x4da244`, `0x4d8a70`). ([`src/script/trainer/mod.rs:1248`](../crates/benilla-ui/src/script/trainer/mod.rs#L1248))
- Kept apart from `Self::vertex_color`, which the reference's `Texture:SetAlpha` (`0x79b580`) rewrites, because the drawn product differs only on a region that sets both, or a gradient and an alpha, which no stock code does, and a FontString's `SetAlpha` then keeps its font colour. ([`src/script/types.rs:421`](../crates/benilla-ui/src/script/types.rs#L421))
- Kept apart from `Self::vertex_color`, which the reference's `Texture:SetAlpha` (`0x79b580`) rewrites, because the drawn product differs only on a region that sets both, or a gradient and an alpha, which no stock code does, and a FontString's `SetAlpha` then keeps its font colour. ([`src/script/types.rs:428`](../crates/benilla-ui/src/script/types.rs#L428))
- Among whole-name matches ours picks the nearest, because the reference's first-walked pick is order-dependent and reads as a bug. ([`src/script/unit/bindings.rs:990`](../crates/benilla-ui/src/script/unit/bindings.rs#L990))
- The reference's matcher takes a whole-string hit at once only when it is nearer than the best so far (`0x493c88`-`0x493ca2`); an exact hit that is not nearer competes on prefix length alone (`0x493cf8`-`0x493d09`), so a nearer "Bobby" walked first beats an exact "Bob", and the pick follows the object list's order. ([`src/script/unit/by_name.rs:19`](../crates/benilla-ui/src/script/unit/by_name.rs#L19))
- A full tie goes to the lower guid, where the reference keeps the first unit its walk (`0x493aa0`) reaches, an order neither of ours has; a guid keeps the two picks equal. ([`src/script/unit/by_name.rs:61`](../crates/benilla-ui/src/script/unit/by_name.rs#L61))
+2 -1
View File
@@ -114,7 +114,7 @@
- **benilla-lua** (lib.rs): api cfmt compile heap lex lib_base lib_math lib_string lib_table number parse pools proto reload table value vm
- **benilla-m2** (lib.rs): error model skin tests track
- **benilla-mlua** (lib.rs): conv error
- **benilla-movie** (lib.rs): avi bits color decoder headers idct scan vlc
- **benilla-movie** (lib.rs): avi bits color decoder headers idct scan testing vlc
- **benilla-mpq** (lib.rs): crypto
- **benilla-protocol** (lib.rs): auth events guid messages wire world
- **benilla-srp** (lib.rs): vanilla_header
@@ -386,6 +386,7 @@
- `WOW_PIN_UID` — benilla-world/src/wmo_portal/audit/pin.rs
- `WOW_PIN_WMO` — benilla-world/src/wmo_portal/audit/pin.rs
- `WOW_PIPE_TRACE` — benilla-app/src/pipe_warm/mod.rs
- `WOW_PLAY_MOVIE` — benilla-app/src/ui_script/glue.rs
- `WOW_POINTS_DUMP` — benilla-world/src/lighting/global_light.rs
- `WOW_PORTRAIT_TEST` — benilla-app/src/portrait/mod.rs, benilla-app/src/portrait/test_bake.rs, benilla-world/src/bgwin.rs
- `WOW_PORTRAIT_TEST_SKIN` — benilla-app/src/portrait/test_bake.rs