From ae474ad1d7b2736fcea85bce04db3369e29c8c10 Mon Sep 17 00:00:00 2001
From: Saksukella <98151720+Saksukella@users.noreply.github.com>
Date: Sat, 28 Nov 2026 23:38:57 +0300
Subject: [PATCH] HLE/Bink: neutralize skipped movie frame buffers to YUV black
---
crates/xcl/src/hle/bink.rs | 300 ++++++++++++++++++++++++++++++++++++-
1 file changed, 298 insertions(+), 2 deletions(-)
diff --git a/crates/xcl/src/hle/bink.rs b/crates/xcl/src/hle/bink.rs
index 84fa573aa5..697d791bd4 100644
--- a/crates/xcl/src/hle/bink.rs
+++ b/crates/xcl/src/hle/bink.rs
@@ -15,7 +15,7 @@
#![allow(non_snake_case)]
-use std::collections::HashSet;
+use std::collections::{HashMap, HashSet};
use std::ffi::c_void;
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
use std::sync::{Mutex, Once, OnceLock};
@@ -38,6 +38,47 @@ pub struct BinkHeader {
/// `BINKWILLLOOP` flag in `BinkHeader::open_flags` (set by `BinkSetWillLoop`).
pub const BINK_WILL_LOOP: u32 = 0x0000_0080;
+/// Single plane descriptor in RAD Bink 2's `BINKFRAMEPLANESET` (verified against `Bink2Scarlett.dll`).
+#[repr(C)]
+#[derive(Debug, Clone, Copy)]
+pub struct BinkPlane {
+ pub buffer: *mut u8, // +0x00
+ pub allocate: i32, // +0x08
+ pub buffer_pitch: u32, // +0x0C
+}
+
+impl Default for BinkPlane {
+ fn default() -> Self {
+ Self { buffer: std::ptr::null_mut(), allocate: 0, buffer_pitch: 0 }
+ }
+}
+
+/// 5-plane set (Y, cR, cB, A, H) for one frame buffer in `BINKFRAMEBUFFERS` (`0x50` bytes).
+#[repr(C)]
+#[derive(Debug, Clone, Copy, Default)]
+pub struct BinkFramePlaneSet {
+ pub y_plane: BinkPlane, // +0x00
+ pub cr_plane: BinkPlane, // +0x10
+ pub cb_plane: BinkPlane, // +0x20
+ pub a_plane: BinkPlane, // +0x30
+ pub h_plane: BinkPlane, // +0x40
+}
+
+/// RAD Bink 2 `BINKFRAMEBUFFERS` struct passed to `BinkRegisterFrameBuffers` (verified against `Bink2Scarlett.dll`).
+#[repr(C)]
+#[derive(Debug, Clone, Copy, Default)]
+pub struct BinkFrameBuffers {
+ pub total_frames: i32, // +0x00
+ pub ya_buffer_width: u32, // +0x04
+ pub ya_buffer_height: u32, // +0x08
+ pub crcb_buffer_width: u32, // +0x0C
+ pub crcb_buffer_height: u32, // +0x10
+ pub frame_num: u32, // +0x14
+ pub frames: [BinkFramePlaneSet; 2], // +0x18
+}
+
+const MAX_BINK_PLANE_BYTES: usize = 64 << 20;
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {
Off,
@@ -90,8 +131,13 @@ static REAL_DO_FRAME_ASYNC: AtomicUsize = AtomicUsize::new(0);
static REAL_DO_FRAME_ASYNC_MULTI: AtomicUsize = AtomicUsize::new(0);
static REAL_DO_FRAME_ASYNC_WAIT: AtomicUsize = AtomicUsize::new(0);
static REAL_GOTO: AtomicUsize = AtomicUsize::new(0);
+static REAL_REGISTER_FRAME_BUFFERS: AtomicUsize = AtomicUsize::new(0);
+static REAL_ALLOCATE_FRAME_BUFFERS: AtomicUsize = AtomicUsize::new(0);
static LOGGED_HANDLES: Mutex