Compare commits

...
7 Commits
Author SHA1 Message Date
bicarus ae433ccb1d iidx: movie decoder workaround for dxvk (#939)
## Link to GitHub Issue or related Pull Request, if one exists
https://github.com/eamuse/sp2xpatcher/pull/12

## Description of change
Subsumes https://github.com/eamuse/sp2xpatcher/pull/12 into a hook-based
fix that is automatically applied when Vulcan is detected.

## Testing
2026-11-28 20:21:33 -08:00
bicarus 57c083e7ad audio: workaround audio buffer issue in wine (#937)
## Link to GitHub Issue or related Pull Request, if one exists
Fixes #931

## Description of change
Implement workaround for audio bug in Wine which caused loud static with
`-wasapishared` due to the way wine maps 24-bit PCM into 32-bit
container when handing off to PulseAudio.

## Testing
tbd
2026-11-28 18:41:41 -08:00
Will e2fd48953e update XP LLVM to 23.1.5, DLL compatibility checker to 1.6 (#938)
## Link to GitHub Issue or related Pull Request, if one exists
n/a

## Description of change
Typical toolchain churn, but also fixes an issue with Win7 compat
checking where API set DLLs weren't mapped right

## Testing
Builds
2026-11-27 22:55:21 -08:00
bicarus a4850165bb net: improve TLS handshake (#936)
## Link to GitHub Issue or related Pull Request, if one exists
Fixes #928

## Description of change
Before: hardcoded 100ms timeout on TLS reply, if timed out, drop the
handshake

After: wait for reply, process right away. Use default (10s) socket
receive timeout as fallback.

## Testing
Tested EA on a server that supports SSL.
2026-11-27 20:08:56 -08:00
bicarus ae7d169b3f cfg: trim surrounding whitespace in options tab (#935)
## Link to GitHub Issue or related Pull Request, if one exists
n/a

## Description of change
Remove leading and trailing whitespace for some commonly used options
(EA server URL, pcbid, etc) to prevent users copy-pasting wrong text.

## Testing
cfg only
2026-11-26 02:17:52 -08:00
bicarus-dev ce87d20f25 sdvx: cache result from K32GetPerformanceInfo to avoid performance issues on some PCs 2026-11-19 23:35:28 -08:00
鲸流 3e3db7a411 bc: add light support and unity player arguments injection (#932)
## Link to GitHub Issue or related Pull Request, if one exists
#0

## Description of change

_Just imitation of the existing implementations of CCJ, MFG or QKS._

- Add BI2X hook and lighting support.
- Align Unity launch argument handling and cursor visibility with other
Unity games in spice2x using `unity_utils::force_show_cursor` and
`unity_utils::set_args`.
- Add `-bcargs` command-line option to pass custom arguments directly to
the Unity player.
- Upgrade I/O initialization to `devicehook_init_trampoline()` and
ensure the raw log directory is created recursively.

## Testing
- Verified build on GitHub Actions with no compiler warnings.
- Tested with the CI compiled executable.
   - HID lighting worked fine on aic_pico and iidx_pico.
- Display arguments such as `-w`, `-windowborder` and `-windowsize` are
correctly passed.
_(However, once the game launches, it reinitializes the window and
switches to fullscreen before the checking phase begins. To maintain
these arguments, an additional hook is required. I resolved this issue
using a BepInEx plugin.)_
2026-10-31 15:02:12 -07:00
23 changed files with 590 additions and 116 deletions

No files matched your search

+2
View File
@@ -453,6 +453,7 @@ set(SOURCE_FILES ${SOURCE_FILES}
games/hpm/hpm.cpp
games/hpm/io.cpp
games/iidx/iidx.cpp
games/iidx/dxva2.cpp
games/iidx/io.cpp
games/iidx/poke.cpp
games/iidx/bi2a.cpp
@@ -541,6 +542,7 @@ set(SOURCE_FILES ${SOURCE_FILES}
games/onpara/touchpanel.cpp
games/bc/bc.cpp
games/bc/io.cpp
games/bc/bi2x_hook.cpp
games/ccj/ccj.cpp
games/ccj/io.cpp
games/ccj/bi2x_hook.cpp
+2
View File
@@ -2,6 +2,8 @@
#include "external/rapidjson/document.h"
#include "cfg/screen_resize.h"
#include <vector>
using namespace std::placeholders;
using namespace rapidjson;
+60 -95
View File
@@ -1,5 +1,8 @@
#define SECURITY_WIN32
#include <algorithm>
#include <chrono>
#include <climits>
#include <cstring>
#include <iostream>
#include <vector>
@@ -91,6 +94,7 @@ namespace avs {
};
static constexpr size_t alignment = 16;
using handshake_clock = std::chrono::steady_clock;
static int io_buf_init(struct io_buf *buf, size_t initial_capacity) {
uint8_t *tmp_bytes = nullptr;
@@ -261,89 +265,35 @@ arg_fail:
return 0;
}
static int impl_socket_recv_all(
static int tls_recv_handshake(
struct avs_net_sock_desc_work *work,
struct io_buf *buf,
uint32_t recv_timeout)
handshake_clock::time_point deadline)
{
uint8_t old_non_blocking_value = 0;
uint8_t non_blocking = 0;
avs_net_size_t old_non_blocking_value_size = 0;
struct avs_net_poll_fd poll_fds[1] {};
int ret = 0;
if (work == nullptr || work->sock_fd < 0) {
return -1;
}
auto err = io_buf_validate(buf);
if (err != 0) {
return -1;
}
if (buf->pos == buf->limit) {
return -1;
}
poll_fds[0].socket = work->sock_fd;
poll_fds[0].events = AVS_NET_POLL_POLLIN;
non_blocking = 1;
old_non_blocking_value_size = sizeof(old_non_blocking_value);
core::avs_net_getsockopt(work->sock_fd, AVS_SO_NONBLOCK, &old_non_blocking_value, &old_non_blocking_value_size);
core::avs_net_setsockopt(work->sock_fd, AVS_SO_NONBLOCK, &non_blocking, sizeof(non_blocking));
while (true) {
auto result = core::avs_net_poll(poll_fds, std::size(poll_fds), recv_timeout);
const auto now = handshake_clock::now();
if (now < deadline) {
const auto remaining = std::chrono::ceil<std::chrono::milliseconds>(deadline - now);
avs_net_poll_fd poll_fd {};
poll_fd.socket = work->sock_fd;
poll_fd.events = AVS_NET_POLL_POLLIN;
const auto result = core::avs_net_poll(&poll_fd, 1,
static_cast<int>(remaining.count()));
if (result < 0) {
log_warning("avs::ssl", "avs_net_poll failed: 0x{:08x}", result);
ret = -1;
goto out;
log_warning("avs::ssl", "avs_net_poll failed during TLS handshake: 0x{:08x}", result);
return result;
}
if (!result) {
#if 0
log_warning("avs::ssl", "socket timeout, no data received after {} milliseconds", recv_timeout);
#endif
goto poll_succeeded_or_empty;
}
if (poll_fds[0].r_events & AVS_NET_POLL_POLLIN) {
result = core::avs_net_recv(work->sock_fd, &buf->bytes[buf->pos], buf->limit - buf->pos);
if (result < 0) {
break;
if (result > 0) {
if (poll_fd.r_events & AVS_NET_POLL_POLLIN) {
return impl_socket_recv(work, &work->recv_buf);
}
if (result == 0) {
log_misc("avs::ssl", "connection closed");
ret = -1;
goto out;
}
#if 0
log_warning("avs::ssl", "socket({}) got {} bytes during handshake", work->sock_fd, result);
#endif
buf->pos += result;
log_warning("avs::ssl", "unexpected TLS handshake poll events: 0x{:04x}",
poll_fd.r_events);
return core::avs_error_make(AVS_ERROR_CLASS_NET, AVS_ERROR_SUBCLASS_SC_BADMSG);
}
}
poll_succeeded_or_empty:
ret = 0;
out:
core::avs_net_setsockopt(work->sock_fd, AVS_SO_NONBLOCK, &old_non_blocking_value, sizeof(old_non_blocking_value));
return ret;
log_warning("avs::ssl", "timed out waiting for TLS handshake data");
return core::avs_error_make(AVS_ERROR_CLASS_NET, AVS_ERROR_SUBCLASS_NET_TIMEOUT);
}
static int impl_socket_send(struct avs_net_sock_desc_work *work, struct io_buf *buf) {
@@ -897,6 +847,7 @@ out:
uint32_t address,
avs_net_port_t port)
{
constexpr uint32_t default_handshake_timeout_ms = 10000;
constexpr uint32_t security_context_flags = ISC_REQ_CONFIDENTIALITY |
ISC_REQ_INTEGRITY |
ISC_REQ_STREAM |
@@ -912,6 +863,7 @@ out:
SECURITY_STATUS status = SEC_E_OK;
int result = 0;
int err = 0;
handshake_clock::time_point handshake_deadline;
char hostname[256];
@@ -987,6 +939,11 @@ out:
goto first_isc_fail;
}
// share one receive budget across all TLS flights and partial reads
handshake_deadline = handshake_clock::now() + std::chrono::milliseconds(work->recv_timeout
? std::min<uint32_t>(work->recv_timeout, INT_MAX)
: default_handshake_timeout_ms);
while (status != SEC_E_OK) {
switch (status) {
case SEC_I_CONTINUE_NEEDED:
@@ -1002,33 +959,26 @@ out:
}
}
work->recv_buf.pos = 0;
work->recv_buf.limit = work->recv_buf.capacity;
err = impl_socket_recv_all(work, &work->recv_buf, 100);
if (err != 0) {
goto loop_fail;
if (work->recv_buf.pos == 0) {
err = tls_recv_handshake(work, handshake_deadline);
if (err != 0) {
goto loop_fail;
}
}
break;
case SEC_E_INCOMPLETE_MESSAGE:
if (recv_bufs[1].BufferType != SECBUFFER_MISSING) {
err = core::avs_error_make(AVS_ERROR_CLASS_NET, AVS_ERROR_SUBCLASS_SC_BADMSG);
goto loop_fail;
case SEC_E_INCOMPLETE_MESSAGE:
if (work->recv_buf.pos == work->recv_buf.capacity) {
err = io_buf_grow(&work->recv_buf);
if (err != 0) {
log_warning("avs::ssl", "failed to grow TLS handshake receive buffer");
goto loop_fail;
}
work->recv_buf.limit = work->recv_buf.capacity;
}
err = io_buf_grow_to(&work->recv_buf, work->recv_buf.pos + recv_bufs[1].cbBuffer);
if (err != 0) {
goto loop_fail;
}
work->recv_buf.limit = work->recv_buf.capacity;
err = impl_socket_recv(work, &work->recv_buf);
err = tls_recv_handshake(work, handshake_deadline);
if (err != 0) {
goto loop_fail;
@@ -1093,6 +1043,21 @@ out:
&send_vec,
&attributes,
nullptr);
if (status == SEC_I_CONTINUE_NEEDED || status == SEC_E_OK) {
const auto extra = recv_bufs[1].BufferType == SECBUFFER_EXTRA
? recv_bufs[1].cbBuffer : 0;
if (extra > 0) {
const auto tail = work->recv_buf.bytes + (work->recv_buf.pos - extra);
if (status == SEC_E_OK) {
work->recv_ciphertext_tail = tail;
work->recv_ciphertext_count = extra;
} else {
memmove(work->recv_buf.bytes, tail, extra);
}
}
work->recv_buf.pos = extra;
}
}
log_misc("avs::ssl", "TLS handshake complete");
+2
View File
@@ -48,6 +48,8 @@ struct OptionDefinition {
std::string file_extension = "";
std::string quick_setting_category = "";
bool trim_whitespace = false;
};
class Option {
+2 -2
View File
@@ -18,11 +18,11 @@ RUN useradd user -m && echo "ALL ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
RUN su user -c "cd /tmp/ && git clone https://aur.archlinux.org/yay-bin.git --depth=1 && cd yay-bin && makepkg --noconfirm -si && yay --noconfirm -S mingw-w64-cmake"
RUN mkdir -p /opt/llvm-mingw-xp \
&& curl -fsSL "https://github.com/mon/llvm-mingw-xp/releases/download/llvm-mingw-xp-22.1.0/llvm-mingw-llvm-mingw-xp-22.1.0-msvcrt-ubuntu-22.04-x86_64.tar.xz" \
&& curl -fsSL "https://github.com/mon/llvm-mingw-xp/releases/download/llvm-mingw-xp-23.1.5/llvm-mingw-xp-23.1.5-msvcrt-ubuntu-22.04-x86_64.tar.xz" \
| tar -xJ --strip-components=1 -C /opt/llvm-mingw-xp
ENV PATH="$PATH:/opt/llvm-mingw-xp/bin"
RUN curl -fsSL "https://github.com/mon/windows-dll-compat-checker/releases/download/v1.3/windows_dll_compat_checker-linux-x86_64.tar.xz" \
RUN curl -fsSL "https://github.com/mon/windows-dll-compat-checker/releases/download/v1.6/windows_dll_compat_checker-linux-x86_64.tar.xz" \
| tar -xJ -C /usr/local/bin
# Stock makepkg.conf builds serially; this makes the AUR compiles below parallel.
+28 -14
View File
@@ -1,25 +1,30 @@
#include "bc.h"
#include <format>
#include "hooks/setupapihook.h"
#include "util/fileutils.h"
#include "util/libutils.h"
#include "acio2emu/handle.h"
#include "acioemu/handle.h"
#include "hooks/graphics/graphics.h"
#include "util/detour.h"
#include "util/unity_player.h"
#include "node.h"
#include "bi2x_hook.h"
namespace games::bc {
static decltype(ShowCursor) *ShowCursor_orig = nullptr;
static int WINAPI ShowCursor_hook(BOOL bShow) {
// log_misc("bsac", "ShowCursor {}", bShow);
return 1;
}
std::string BC_INJECT_ARGS = "";
void BCGame::attach() {
Game::attach();
// create required directories
fileutils::dir_create_recursive("dev/raw/log");
// preload libraries
libutils::load_library("libaio.dll");
libutils::load_library("libaio-iob2_video.dll");
setupapihook_init(libutils::load_library("libaio.dll"));
SETUPAPI_SETTINGS settings {};
@@ -32,15 +37,24 @@ namespace games::bc {
auto iob = new acio2emu::IOBHandle(L"COM3");
iob->register_node(std::make_unique<TBSNode>());
if (GRAPHICS_SHOW_CURSOR) {
detour::trampoline_try(
"user32.dll", "ShowCursor",
(void*)ShowCursor_hook, (void**)&ShowCursor_orig);
}
#if SPICE64
// insert BI2X hooks
bi2x_hook_init();
#endif
devicehook_init();
devicehook_init_trampoline();
devicehook_add(iob);
devicehook_add(new acioemu::ACIOHandle(L"COM1"));
if (GRAPHICS_SHOW_CURSOR) {
unity_utils::force_show_cursor(true);
}
unity_utils::set_args(
std::format("{} {}{}",
GetCommandLineA(),
BC_INJECT_ARGS,
unity_utils::get_unity_player_args()));
}
void BCGame::detach() {
@@ -48,4 +62,4 @@ namespace games::bc {
devicehook_dispose();
}
}
}
+3
View File
@@ -1,8 +1,11 @@
#pragma once
#include <string>
#include "games/game.h"
namespace games::bc {
extern std::string BC_INJECT_ARGS;
class BCGame : public games::Game {
public:
BCGame() : Game("Busou Shinki: Armored Princess Battle Conductor") {}
+163
View File
@@ -0,0 +1,163 @@
#include "bi2x_hook.h"
#if SPICE64
#include <cstdint>
#include <iterator>
#include "util/detour.h"
#include "util/logging.h"
#include "rawinput/rawinput.h"
#include "games/io.h"
#include "io.h"
#include "util/tapeled.h"
namespace games::bc {
struct AIO_IOB2_BI2X_TBS;
/*
* typedefs
*/
typedef void (__fastcall *aioIob2Bi2xTBS_GetDeviceStatus_t)(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, void *o_DevStatus);
typedef void (__fastcall *aioIob2Bi2xTBS_SetButton0Lamp_t)(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, bool i_bOn);
typedef void (__fastcall *aioIob2Bi2xTBS_SetIrLed_t)(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, bool i_bOn);
typedef void (__fastcall *aioIob2Bi2xTBS_SetIccrLed_t)(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, uint32_t i_RGB);
typedef void (__fastcall *aioIob2Bi2xTBS_SetStickLed_t)(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, uint32_t i_RGB);
typedef void (__fastcall *aioIob2Bi2xTBS_SetTapeLedData_t)(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, uint32_t i_TapeLed, uint8_t *i_pData);
static aioIob2Bi2xTBS_GetDeviceStatus_t aioIob2Bi2xTBS_GetDeviceStatus_orig = nullptr;
static aioIob2Bi2xTBS_SetButton0Lamp_t aioIob2Bi2xTBS_SetButton0Lamp_orig = nullptr;
static aioIob2Bi2xTBS_SetIrLed_t aioIob2Bi2xTBS_SetIrLed_orig = nullptr;
static aioIob2Bi2xTBS_SetIccrLed_t aioIob2Bi2xTBS_SetIccrLed_orig = nullptr;
static aioIob2Bi2xTBS_SetStickLed_t aioIob2Bi2xTBS_SetStickLed_orig = nullptr;
static aioIob2Bi2xTBS_SetTapeLedData_t aioIob2Bi2xTBS_SetTapeLedData_orig = nullptr;
/*
* hooks
*/
static void write_light_rgb(
Lights::bc_lights_t r, Lights::bc_lights_t g, Lights::bc_lights_t b, uint32_t color) {
auto &lights = get_lights();
GameAPI::Lights::writeLight(RI_MGR, lights.at(r), ((color >> 16) & 0xFF) / 255.f);
GameAPI::Lights::writeLight(RI_MGR, lights.at(g), ((color >> 8) & 0xFF) / 255.f);
GameAPI::Lights::writeLight(RI_MGR, lights.at(b), (color & 0xFF) / 255.f);
}
static void __fastcall aioIob2Bi2xTBS_GetDeviceStatus(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, void *o_DevStatus) {
RI_MGR->devices_flush_output();
if (aioIob2Bi2xTBS_GetDeviceStatus_orig) {
aioIob2Bi2xTBS_GetDeviceStatus_orig(i_pNodeCtl, o_DevStatus);
}
}
static void __fastcall aioIob2Bi2xTBS_SetButton0Lamp(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, bool i_bOn) {
auto &lights = get_lights();
GameAPI::Lights::writeLight(RI_MGR, lights.at(Lights::Button), (i_bOn ? 1.f : 0.f));
if (aioIob2Bi2xTBS_SetButton0Lamp_orig) {
aioIob2Bi2xTBS_SetButton0Lamp_orig(i_pNodeCtl, i_bOn);
}
}
static void __fastcall aioIob2Bi2xTBS_SetIrLed(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, bool i_bOn) {
auto &lights = get_lights();
GameAPI::Lights::writeLight(RI_MGR, lights.at(Lights::IrLed), (i_bOn ? 1.f : 0.f));
if (aioIob2Bi2xTBS_SetIrLed_orig) {
aioIob2Bi2xTBS_SetIrLed_orig(i_pNodeCtl, i_bOn);
}
}
static void __fastcall aioIob2Bi2xTBS_SetIccrLed(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, uint32_t i_RGB) {
write_light_rgb(Lights::CardReader_R, Lights::CardReader_G, Lights::CardReader_B, i_RGB);
if (aioIob2Bi2xTBS_SetIccrLed_orig) {
aioIob2Bi2xTBS_SetIccrLed_orig(i_pNodeCtl, i_RGB);
}
}
static void __fastcall aioIob2Bi2xTBS_SetStickLed(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, uint32_t i_RGB) {
write_light_rgb(Lights::Joystick_R, Lights::Joystick_G, Lights::Joystick_B, i_RGB);
if (aioIob2Bi2xTBS_SetStickLed_orig) {
aioIob2Bi2xTBS_SetStickLed_orig(i_pNodeCtl, i_RGB);
}
}
static void __fastcall aioIob2Bi2xTBS_SetTapeLedData(
AIO_IOB2_BI2X_TBS *i_pNodeCtl, uint32_t i_TapeLed, uint8_t *i_pData) {
static struct TapeLedMapping {
size_t data_size;
int r, g, b;
TapeLedMapping(size_t data_size, int r, int g, int b)
: data_size(data_size), r(r), g(g), b(b) {}
} mapping[] = {
{ 48, Lights::TitlePanel_R, Lights::TitlePanel_G, Lights::TitlePanel_B },
{ 49, Lights::SidePanel_R, Lights::SidePanel_G, Lights::SidePanel_B },
};
if (tapeledutils::is_enabled() && i_TapeLed < std::size(mapping)) {
auto &map = mapping[i_TapeLed];
const auto rgb = tapeledutils::pick_color_from_led_tape(i_pData, map.data_size);
auto &lights = get_lights();
GameAPI::Lights::writeLight(RI_MGR, lights.at(map.r), rgb.r);
GameAPI::Lights::writeLight(RI_MGR, lights.at(map.g), rgb.g);
GameAPI::Lights::writeLight(RI_MGR, lights.at(map.b), rgb.b);
}
if (aioIob2Bi2xTBS_SetTapeLedData_orig) {
aioIob2Bi2xTBS_SetTapeLedData_orig(i_pNodeCtl, i_TapeLed, i_pData);
}
}
void bi2x_hook_init() {
static bool initialized = false;
if (initialized) {
return;
} else {
initialized = true;
}
log_info("bc_bi2x_hook", "init");
const auto libaioIob2VideoDll = "libaio-iob2_video.dll";
detour::trampoline_try(libaioIob2VideoDll, "aioIob2Bi2xTBS_GetDeviceStatus",
aioIob2Bi2xTBS_GetDeviceStatus, &aioIob2Bi2xTBS_GetDeviceStatus_orig);
detour::trampoline_try(libaioIob2VideoDll, "aioIob2Bi2xTBS_SetButton0Lamp",
aioIob2Bi2xTBS_SetButton0Lamp, &aioIob2Bi2xTBS_SetButton0Lamp_orig);
detour::trampoline_try(libaioIob2VideoDll, "aioIob2Bi2xTBS_SetIrLed",
aioIob2Bi2xTBS_SetIrLed, &aioIob2Bi2xTBS_SetIrLed_orig);
detour::trampoline_try(libaioIob2VideoDll, "aioIob2Bi2xTBS_SetIccrLed",
aioIob2Bi2xTBS_SetIccrLed, &aioIob2Bi2xTBS_SetIccrLed_orig);
detour::trampoline_try(libaioIob2VideoDll, "aioIob2Bi2xTBS_SetStickLed",
aioIob2Bi2xTBS_SetStickLed, &aioIob2Bi2xTBS_SetStickLed_orig);
detour::trampoline_try(libaioIob2VideoDll, "aioIob2Bi2xTBS_SetTapeLedData",
aioIob2Bi2xTBS_SetTapeLedData, &aioIob2Bi2xTBS_SetTapeLedData_orig);
}
}
#endif
+9
View File
@@ -0,0 +1,9 @@
#pragma once
#if SPICE64
namespace games::bc {
void bi2x_hook_init();
}
#endif
+29 -1
View File
@@ -47,4 +47,32 @@ std::vector<Analog> &games::bc::get_analogs() {
}
return analogs;
}
}
std::vector<Light> &games::bc::get_lights() {
static std::vector<Light> lights;
if (lights.empty()) {
lights = GameAPI::Lights::getLights("Busou Shinki: Armored Princess Battle Conductor");
GameAPI::Lights::sortLights(
&lights,
"Title Panel R",
"Title Panel G",
"Title Panel B",
"Side Panel R",
"Side Panel G",
"Side Panel B",
"Card Reader R",
"Card Reader G",
"Card Reader B",
"Joystick R",
"Joystick G",
"Joystick B",
"Button",
"IR LED"
);
}
return lights;
}
+20
View File
@@ -30,7 +30,27 @@ namespace games::bc {
};
}
namespace Lights {
typedef enum {
TitlePanel_R,
TitlePanel_G,
TitlePanel_B,
SidePanel_R,
SidePanel_G,
SidePanel_B,
CardReader_R,
CardReader_G,
CardReader_B,
Joystick_R,
Joystick_G,
Joystick_B,
Button,
IrLed,
} bc_lights_t;
}
std::vector<Button> &get_buttons();
std::string get_buttons_help();
std::vector<Analog> &get_analogs();
std::vector<Light> &get_lights();
}
+114
View File
@@ -0,0 +1,114 @@
#include "dxva2.h"
#include <algorithm>
#include <atomic>
#include <cstring>
#include <windows.h>
#include <d3d9.h>
#include <dxva2api.h>
#include "avs/game.h"
#include "hooks/graphics/backends/d3d9/d3d9_backend.h"
#include "util/detour.h"
#include "util/logging.h"
namespace games::iidx {
static decltype(DXVA2CreateDirect3DDeviceManager9) *create_dxva2_manager_orig = nullptr;
static bool force_dxva2_workaround = false;
static bool has_video_player_with_dxva2_fallback(HMODULE module) {
// iidx34+ tries AVMfVideoPlayerWithDxva and falls back to MF-based software decoder
// (can install dxva2 hooks to trigger the fallback)
//
// older iidx (003 variants of iidx29-30?) uses MfVideo::DxvaDeviceImpl and does not automatically fallback
// (requires a DLL patch to trigger the fallback)
//
// this function detects the AVMfVideoPlayerWithDxva case and returns true
constexpr char player_type[] = ".?AVMfVideoPlayerWithDxva@Video@Graphics@@";
const auto *image = reinterpret_cast<const char *>(module);
const auto *dos_header = reinterpret_cast<const IMAGE_DOS_HEADER *>(image);
const auto *nt_headers =
reinterpret_cast<const IMAGE_NT_HEADERS *>(image + dos_header->e_lfanew);
const auto *section = IMAGE_FIRST_SECTION(nt_headers);
for (WORD i = 0; i < nt_headers->FileHeader.NumberOfSections; i++, section++) {
if (std::memcmp(section->Name, ".data", sizeof(".data")) != 0) {
continue;
}
const auto size = std::min(section->Misc.VirtualSize, section->SizeOfRawData);
const std::string_view data(image + section->VirtualAddress, size);
const std::string_view marker(player_type, sizeof(player_type));
return data.find(marker) != std::string_view::npos;
}
return false;
}
static HRESULT WINAPI create_dxva2_manager_hook(UINT *reset_token, IDirect3DDeviceManager9 **manager) {
if (!force_dxva2_workaround && !graphics_d3d9_is_dxvk()) {
return create_dxva2_manager_orig(reset_token, manager);
}
// dxvk can create the manager without providing a usable decoder; failing creation
// lets iidx fall back to software decoding on builds that support it.
static std::atomic_bool logged = false;
if (!logged.exchange(true, std::memory_order_relaxed)) {
log_info(
"iidx",
"DXVA2 workaround active ({}): returning E_FAIL from DXVA2CreateDirect3DDeviceManager9",
force_dxva2_workaround ? "forced on by user" : "automatically for DXVK");
}
return E_FAIL;
}
void init_dxva2_workaround(std::string_view mode) {
// default (no selection) is auto
if (mode.empty()) {
mode = "auto";
}
// forced off by user
if (mode == "off") {
return;
}
const bool forced_on_by_user = (mode == "on");
// invalid option value
if (!forced_on_by_user && mode != "auto") {
log_warning("iidx", "invalid DXVA2 workaround mode '{}'; expected auto, on, or off", mode);
return;
}
const auto module = avs::game::DLL_INSTANCE;
if (!module) {
if (forced_on_by_user) {
log_warning("iidx", "DXVA2 workaround requested, but the game DLL is not loaded");
}
return;
}
if (!forced_on_by_user && !has_video_player_with_dxva2_fallback(module)) {
return;
}
force_dxva2_workaround = forced_on_by_user;
// install hook
create_dxva2_manager_orig = detour::iat_try(
"DXVA2CreateDirect3DDeviceManager9", create_dxva2_manager_hook, module, "dxva2.dll");
if (!create_dxva2_manager_orig) {
if (forced_on_by_user) {
log_warning("iidx", "DXVA2 workaround requested, but the DXVA2 import was not found");
}
return;
}
if (forced_on_by_user) {
log_info("iidx", "DXVA2 disabled by user");
}
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#include <string_view>
namespace games::iidx {
void init_dxva2_workaround(std::string_view mode);
}
+7 -1
View File
@@ -39,6 +39,7 @@
#include "bi2a.h"
#include "bi2x_hook.h"
#include "dxva2.h"
#include "ezusb.h"
#include "io.h"
#include "poke.h"
@@ -311,8 +312,9 @@ namespace games::iidx {
void IIDXGame::attach() {
Game::attach();
// IO boards
auto options = games::get_options(eamuse_get_game());
// IO boards
if (!options->at(launcher::Options::IIDXBIO2FW).value_bool()) {
// reduce boot wait time
@@ -452,6 +454,10 @@ namespace games::iidx {
#if SPICE64
// dxvk workaround for movie decoder
init_dxva2_workaround(
options->at(launcher::Options::IIDXNoDxva2).value_text());
if (TDJ_MODE) {
sysutils::hook_EnumDisplayDevicesA();
}
+1
View File
@@ -301,6 +301,7 @@ namespace games {
buttons.insert({ bc, bc::get_buttons() });
buttons_help.insert({ bc, bc::get_buttons_help() });
analogs.insert({ bc, bc::get_analogs() });
lights.insert({ bc, bc::get_lights() });
file_hints[bc].push_back({"game/bsac_app.exe"});
// ccj
+42
View File
@@ -9,6 +9,8 @@
#include "hooks/devicehook.h"
#include "hooks/libraryhook.h"
#ifdef SPICE64
#include <mutex>
#include <psapi.h>
#include "hooks/graphics/nvapi_impl.h"
#endif
#include "hooks/graphics/nvapi_hook.h"
@@ -40,6 +42,9 @@ static decltype(RegEnumKeyA) *RegEnumKeyA_orig = nullptr;
static decltype(RegOpenKeyA) *RegOpenKeyA_orig = nullptr;
static decltype(RegOpenKeyExA) *RegOpenKeyExA_orig = nullptr;
static decltype(RegQueryValueExA) *RegQueryValueExA_orig = nullptr;
#ifdef SPICE64
static decltype(K32GetPerformanceInfo) *K32GetPerformanceInfo_orig = nullptr;
#endif
namespace games::sdvx {
@@ -200,6 +205,35 @@ namespace games::sdvx {
}
#ifdef SPICE64
static BOOL WINAPI K32GetPerformanceInfo_hook(PPERFORMANCE_INFORMATION info, DWORD cb) {
if (info == nullptr) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (cb < sizeof(*info)) {
SetLastError(ERROR_BAD_LENGTH);
return FALSE;
}
// store a cached copy of the first successful call to K32GetPerformanceInfo
static std::mutex cache_mutex;
static PERFORMANCE_INFORMATION cached {};
static bool cached_valid = false;
std::lock_guard<std::mutex> lock(cache_mutex);
if (!cached_valid) {
if (!K32GetPerformanceInfo_orig(info, cb)) {
return FALSE;
}
cached = *info;
cached_valid = true;
}
// return the cached copy to avoid performance issues with the game calling this every frame
*info = cached;
return TRUE;
}
static bool sdvx64_spam_remover(void *user, const std::string &data, logger::Style style, std::string &out) {
if (data.empty() || data[0] != '[') {
return false;
@@ -534,6 +568,14 @@ namespace games::sdvx {
if (is_valkyrie_model()) {
sysutils::hook_EnumDisplayDevicesA();
}
// keep one real snapshot for the session instead of querying statistics every frame
K32GetPerformanceInfo_orig = detour::iat_try(
"K32GetPerformanceInfo", K32GetPerformanceInfo_hook, avs::game::DLL_INSTANCE);
if (K32GetPerformanceInfo_orig != nullptr) {
log_info("sdvx", "installed cached hook for K32GetPerformanceInfo");
}
#endif
}
@@ -183,6 +183,30 @@ HRESULT STDMETHODCALLTYPE WrappedIAudioClient::Initialize(
WAVEFORMATEXTENSIBLE resample_storage = {};
const WAVEFORMATEX *device_format = pFormat;
#if SPICE_LINUX
WAVEFORMATEXTENSIBLE full_width_storage = {};
if (this->shared.redirected_from_exclusive &&
pFormat->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
pFormat->cbSize == sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) &&
pFormat->wBitsPerSample == 32) {
const auto *ext = reinterpret_cast<const WAVEFORMATEXTENSIBLE *>(pFormat);
if (ext->SubFormat == GUID_KSDATAFORMAT_SUBTYPE_PCM &&
ext->Samples.wValidBitsPerSample == 24) {
// workaround for bug in wine
//
// Windows reads audio data in the **top** 24 bits, but Wine's PulseAudio mapping
// for this format reads the **bottom** 24 bits, causing static.
// report 32 valid bits so Wine selects s32le and reads the whole sample.
// the bottom 8 bits are zero padding, so the audio data and volume stay the same.
full_width_storage = *ext;
full_width_storage.Samples.wValidBitsPerSample = 32;
device_format = &full_width_storage.Format;
log_info("audio::wasapi", "using 32-bit PCM for Linux shared-mode 24-in-32 audio");
}
}
#endif
if (!this->shared.redirected_from_exclusive) {
// when downmixing, open the real device as stereo while the game keeps writing its native
@@ -286,8 +286,37 @@ static bool is_dx9_on_12_enabled() {
return result;
}
static bool detect_dxvk(HMODULE d3d9) {
// **mostly** reliable detection for dxvk; these are used internally for debugging
constexpr WORD register_annotation = 28257;
constexpr WORD unregister_annotation = 28258;
if (!d3d9 ||
!GetProcAddress(d3d9, MAKEINTRESOURCEA(register_annotation)) ||
!GetProcAddress(d3d9, MAKEINTRESOURCEA(unregister_annotation))) {
return false;
}
// log once
static std::atomic_bool logged = false;
if (!logged.exchange(true, std::memory_order_relaxed)) {
log_info("graphics::d3d9", "DXVK detected");
deferredlogs::defer_error_messages({
"dxvk detected",
" Vulkan-based renderer may cause graphical issues or crashes",
" it should only be used if necessary on your PC",
});
}
return true;
}
bool graphics_d3d9_is_dxvk() {
return detect_dxvk(libutils::try_module("d3d9.dll"));
}
static IDirect3D9 *WINAPI Direct3DCreate9_hook(UINT SDKVersion) {
log_misc("graphics::d3d9", "Direct3DCreate9 hook hit");
graphics_d3d9_is_dxvk();
// remove hook
if (D3D9_DIRECT3D_CREATE9_ADR) {
@@ -330,6 +359,7 @@ static IDirect3D9 *WINAPI Direct3DCreate9_hook(UINT SDKVersion) {
static HRESULT WINAPI Direct3DCreate9Ex_hook(UINT SDKVersion, IDirect3D9Ex **d3d9ex) {
log_misc("graphics::d3d9", "Direct3DCreate9Ex hook hit");
graphics_d3d9_is_dxvk();
// call original
HRESULT result;
@@ -366,6 +396,7 @@ void graphics_d3d9_init() {
if (!d3d9) {
log_info("graphics::d3d9", "skipping inline hooks");
} else {
detect_dxvk(d3d9);
// 9 on 12
Direct3DCreate9On12_orig = (Direct3DCreate9On12_t) libutils::try_proc(d3d9, "Direct3DCreate9On12");
@@ -12,6 +12,7 @@ static const GUID IID_WrappedIDirect3D9 = {
};
void graphics_d3d9_init();
bool graphics_d3d9_is_dxvk();
void graphics_d3d9_on_present(
HWND hFocusWindow,
IDirect3DDevice9 *device,
+3
View File
@@ -1485,6 +1485,9 @@ int main_implementation(int argc, char *argv[]) {
if (options[launcher::Options::CCJMouseTrackballWithToggle].value_bool()) {
games::ccj::MOUSE_TRACKBALL_USE_TOGGLE = true;
}
if (options[launcher::Options::BCArgs].is_active()) {
games::bc::BC_INJECT_ARGS = options[launcher::Options::BCArgs].value_text();
}
if (options[launcher::Options::CCJArgs].is_active()) {
games::ccj::CCJ_INJECT_ARGS = options[launcher::Options::CCJArgs].value_text();
}
+28
View File
@@ -138,6 +138,7 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = std::invoke([]()
.setting_name = "example.com:8083",
.category = "Network",
.quick_setting_category = "Network",
.trim_whitespace = true,
};
c[launcher::Options::PCBID] = {
.title = "PCBID",
@@ -148,6 +149,7 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = std::invoke([]()
.category = "Network",
.sensitive = true,
.quick_setting_category = "Network",
.trim_whitespace = true,
};
c[launcher::Options::Player1Card] = {
.title = "Player 1 Card",
@@ -159,6 +161,7 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = std::invoke([]()
.sensitive = true,
.picker = OptionPickerType::EACard,
.quick_setting_category = "Network",
.trim_whitespace = true,
};
c[launcher::Options::Player2Card] = {
.title = "Player 2 Card",
@@ -170,6 +173,7 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = std::invoke([]()
.sensitive = true,
.picker = OptionPickerType::EACard,
.quick_setting_category = "Network",
.trim_whitespace = true,
};
c[launcher::Options::Player1PinMacro] = {
.title = "Player 1 PIN Macro",
@@ -842,6 +846,21 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = std::invoke([]()
.game_name = "Beatmania IIDX",
.category = "Game Overlay",
};
c[launcher::Options::IIDXNoDxva2] = {
.title = "IIDX Disable DXVA2 Decoder",
.name = "iidxnodxva2",
.desc =
"Forcibly disables the DXVA2 decoder, causing the game to use the software decoder instead "
"on some versions of IIDX",
.type = OptionType::Enum,
.game_name = "Beatmania IIDX",
.category = "Advanced Game Options",
.elements = {
{"auto", ""},
{"on", ""},
{"off", ""},
},
};
c[launcher::Options::LoadSoundVoltexModule] = {
.title = "Force Load Sound Voltex Module",
.name = "sdvx",
@@ -2362,6 +2381,15 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = std::invoke([]()
{"all", "basic + HID devices"},
},
};
c[launcher::Options::BCArgs] = {
.title = "BC Arguments Override",
.name = "bcargs",
.desc = "Command line arguments passed to the game.",
.type = OptionType::Text,
.setting_name = "",
.game_name = "Busou Shinki: Armored Princess Battle Conductor",
.category = "Advanced Game Options",
};
c[launcher::Options::QKSArgs] = {
.title = "QKS Arguments Override",
.name = "qksargs",
+2
View File
@@ -83,6 +83,7 @@ namespace launcher {
spice2x_IIDXLEDColor,
spice2x_IIDXLEDPos,
IIDXLEDBorderless,
IIDXNoDxva2,
LoadSoundVoltexModule,
SDVXForce720p,
SDVXPrinterEmulation,
@@ -241,6 +242,7 @@ namespace launcher {
DisableAvsCache,
OutputPEB,
DumpSystemInfo,
BCArgs,
QKSArgs,
CCJArgs,
CCJMouseTrackball,
+10 -3
View File
@@ -5282,9 +5282,16 @@ namespace overlay::windows {
ImGui::InputTextWithHint("", hint, buffer, sizeof(buffer) - 1);
// would like to use IsItemDeactivatedAfterEdit but can't handle the case when window is closed while editing
if (ImGui::IsItemEdited()) {
this->options_dirty = true;
option.value = buffer;
::Config::getInstance().updateBinding(games_list[games_selected], option);
// trim whitespace to prevent copy/paste errors
auto value = definition.trim_whitespace ?
strtrim(buffer) : std::string(buffer);
if (option.value != value) {
this->options_dirty = true;
option.value = std::move(value);
::Config::getInstance().updateBinding(games_list[games_selected], option);
}
}
if (ImGui::IsItemHovered(ImGui::TOOLTIP_FLAGS)) {
ImGui::HelpTooltip(definition.desc.c_str());