mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-12-06 11:26:41 -08:00
Compare commits
16
Commits
4c77a3f148
...
26-11-19
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c864f69b5 | ||
|
|
5bb526c4ba | ||
|
|
3e3db7a411 | ||
|
|
37f947b57f | ||
|
|
63bfef7c69 | ||
|
|
c83496776e | ||
|
|
fdc7adff7f | ||
|
|
cf5d87d4d5 | ||
|
|
175245333d | ||
|
|
9c8f7f551d | ||
|
|
0684872013 | ||
|
|
ed0ccdd6e3 | ||
|
|
7aba7da3b6 | ||
|
|
197d76755b | ||
|
|
2b6e76730b | ||
|
|
4042b77065 |
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: Bug report
|
name: Bug report (NOT for troubleshooting or asking for help)
|
||||||
about: Create a report to help us improve
|
about: 'File a bug in spice2x'
|
||||||
title: ''
|
title: ''
|
||||||
labels: bug
|
labels: bug
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
name: Continuous Integration
|
name: Continuous Integration
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|||||||
@@ -541,6 +541,7 @@ set(SOURCE_FILES ${SOURCE_FILES}
|
|||||||
games/onpara/touchpanel.cpp
|
games/onpara/touchpanel.cpp
|
||||||
games/bc/bc.cpp
|
games/bc/bc.cpp
|
||||||
games/bc/io.cpp
|
games/bc/io.cpp
|
||||||
|
games/bc/bi2x_hook.cpp
|
||||||
games/ccj/ccj.cpp
|
games/ccj/ccj.cpp
|
||||||
games/ccj/io.cpp
|
games/ccj/io.cpp
|
||||||
games/ccj/bi2x_hook.cpp
|
games/ccj/bi2x_hook.cpp
|
||||||
@@ -554,6 +555,13 @@ set(SOURCE_FILES ${SOURCE_FILES}
|
|||||||
games/pc/pc.cpp
|
games/pc/pc.cpp
|
||||||
games/pc/io.cpp
|
games/pc/io.cpp
|
||||||
games/pc/bi2x_hook.cpp
|
games/pc/bi2x_hook.cpp
|
||||||
|
games/udn/udn.cpp
|
||||||
|
games/udn/io.cpp
|
||||||
|
games/udn/bi2x_hook.cpp
|
||||||
|
games/cardconnect/cardconnect.cpp
|
||||||
|
games/cardconnect/io.cpp
|
||||||
|
games/cardconnect/bi2x_hook.cpp
|
||||||
|
games/cardconnect/printer.cpp
|
||||||
|
|
||||||
# hooks
|
# hooks
|
||||||
hooks/audio/acm.cpp
|
hooks/audio/acm.cpp
|
||||||
@@ -605,6 +613,7 @@ set(SOURCE_FILES ${SOURCE_FILES}
|
|||||||
hooks/graphics/backends/d3d9/d3d9_texture.cpp
|
hooks/graphics/backends/d3d9/d3d9_texture.cpp
|
||||||
hooks/graphics/backends/d3d11/d3d11_backend.cpp
|
hooks/graphics/backends/d3d11/d3d11_backend.cpp
|
||||||
hooks/graphics/backends/d3d11/d3d11_swapchain.cpp
|
hooks/graphics/backends/d3d11/d3d11_swapchain.cpp
|
||||||
|
hooks/graphics/backends/d3d11/d3d11_swapchain_udn.cpp
|
||||||
hooks/graphics/backends/d3d11/d3d11_factory.cpp
|
hooks/graphics/backends/d3d11/d3d11_factory.cpp
|
||||||
hooks/graphics/backends/d3d11/d3d11_vtable_capture.cpp
|
hooks/graphics/backends/d3d11/d3d11_vtable_capture.cpp
|
||||||
hooks/graphics/backends/d3d11/d3d11_screenshot.cpp
|
hooks/graphics/backends/d3d11/d3d11_screenshot.cpp
|
||||||
|
|||||||
@@ -118,11 +118,11 @@ static inline void update_card(int unit_id) {
|
|||||||
const bool card_presented = eamuse_card_insert_consume(icca_get_active_count(), unit_id);
|
const bool card_presented = eamuse_card_insert_consume(icca_get_active_count(), unit_id);
|
||||||
const bool key_pressed = (kb_insert_press && !kb_insert_press_old[unit_id]);
|
const bool key_pressed = (kb_insert_press && !kb_insert_press_old[unit_id]);
|
||||||
|
|
||||||
// beatstream and nostalgia have logic that requires ac_io_icca_get_uid_felica to return the
|
// beatstream, nostalgia and Dance Evolution have logic that requires ac_io_icca_get_uid_felica to return the
|
||||||
// exact same card number multiple times in a row in order for the card number to be read...
|
// exact same card number multiple times in a row in order for the card number to be read...
|
||||||
// for whatever reason setting this to 3-4 doesn't work the very first time the game boots up
|
// for whatever reason setting this to 3-4 doesn't work the very first time the game boots up
|
||||||
// so we use 10 just to be safe
|
// so we use 10 just to be safe
|
||||||
const bool need_felica_retries = avs::game::is_model({"NBT", "PAN"});
|
const bool need_felica_retries = avs::game::is_model({"KDM", "NBT", "PAN"});
|
||||||
if (need_felica_retries && (card_presented || key_pressed)) {
|
if (need_felica_retries && (card_presented || key_pressed)) {
|
||||||
unit->felica_retries = 10;
|
unit->felica_retries = 10;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,17 +46,14 @@ MessageData *ACIODeviceEmu::create_msg(uint8_t addr, uint16_t code, uint8_t pid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// allocate data
|
// allocate data
|
||||||
auto data_raw = new uint8_t[MSG_HEADER_SIZE + data_size];
|
auto msg = new MessageData {};
|
||||||
|
|
||||||
// set header
|
// set header
|
||||||
auto msg = (MessageData *) &data_raw[0];
|
|
||||||
set_header(msg, addr, code, pid, (uint8_t) data_size);
|
set_header(msg, addr, code, pid, (uint8_t) data_size);
|
||||||
|
|
||||||
// set data
|
// set data
|
||||||
if (data) {
|
if (data) {
|
||||||
memcpy(data_raw + MSG_HEADER_SIZE, data, data_size);
|
memcpy(msg->cmd.raw, data, data_size);
|
||||||
} else {
|
|
||||||
memset(data_raw + MSG_HEADER_SIZE, 0, data_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return prepared message
|
// return prepared message
|
||||||
|
|||||||
@@ -14,15 +14,20 @@ bool acioemu::ACIOHandle::open(LPCWSTR lpFileName) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
log_info("acioemu", "Opened {} (ACIO)", ws2s(com_port));
|
log_info("acioemu", "Opened {} (ACIO)", ws2s(com_port));
|
||||||
|
|
||||||
// ACIO device
|
// ACIO device
|
||||||
acio_emu.add_device(new acioemu::ICCADevice(false, true, icca_node_count));
|
if (!initialized) {
|
||||||
|
acio_emu.add_device(new acioemu::ICCADevice(false, true, icca_node_count));
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int acioemu::ACIOHandle::read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) {
|
int acioemu::ACIOHandle::read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
auto buffer = reinterpret_cast<uint8_t *>(lpBuffer);
|
auto buffer = reinterpret_cast<uint8_t *>(lpBuffer);
|
||||||
|
|
||||||
// read from emu
|
// read from emu
|
||||||
@@ -42,6 +47,7 @@ int acioemu::ACIOHandle::read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int acioemu::ACIOHandle::write(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite) {
|
int acioemu::ACIOHandle::write(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
auto buffer = reinterpret_cast<const uint8_t *>(lpBuffer);
|
auto buffer = reinterpret_cast<const uint8_t *>(lpBuffer);
|
||||||
|
|
||||||
// write to emu
|
// write to emu
|
||||||
@@ -64,6 +70,7 @@ int acioemu::ACIOHandle::device_io(
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t acioemu::ACIOHandle::bytes_available() {
|
size_t acioemu::ACIOHandle::bytes_available() {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
return acio_emu.bytes_available();
|
return acio_emu.bytes_available();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "acioemu/acioemu.h"
|
#include "acioemu/acioemu.h"
|
||||||
#include "hooks/devicehook.h"
|
#include "hooks/devicehook.h"
|
||||||
|
|
||||||
@@ -12,6 +14,8 @@ namespace acioemu {
|
|||||||
uint8_t icca_node_count;
|
uint8_t icca_node_count;
|
||||||
|
|
||||||
acioemu::ACIOEmu acio_emu;
|
acioemu::ACIOEmu acio_emu;
|
||||||
|
std::mutex mutex;
|
||||||
|
bool initialized = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ACIOHandle(LPCWSTR lpCOMPort, uint8_t iccaNodeCount = 2);
|
ACIOHandle(LPCWSTR lpCOMPort, uint8_t iccaNodeCount = 2);
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ ICCADevice::ICCADevice(bool flip_order, bool keypad_thread, uint8_t node_count)
|
|||||||
|
|
||||||
// keypad thread for faster polling
|
// keypad thread for faster polling
|
||||||
if (keypad_thread) {
|
if (keypad_thread) {
|
||||||
this->keypad_thread = new std::thread([this]() {
|
this->keypad_thread = std::jthread([this](std::stop_token stop_token) {
|
||||||
timeutils::PreciseSleepTimer timer;
|
timeutils::PreciseSleepTimer timer;
|
||||||
while (this->cards) {
|
while (!stop_token.stop_requested()) {
|
||||||
for (int unit = 0; unit < this->node_count; unit++) {
|
for (int unit = 0; unit < this->node_count; unit++) {
|
||||||
this->update_keypad(unit, false);
|
this->update_keypad(unit, false);
|
||||||
}
|
}
|
||||||
@@ -61,11 +61,15 @@ ICCADevice::ICCADevice(bool flip_order, bool keypad_thread, uint8_t node_count)
|
|||||||
ICCADevice::~ICCADevice() {
|
ICCADevice::~ICCADevice() {
|
||||||
|
|
||||||
// stop thread
|
// stop thread
|
||||||
delete keypad_thread;
|
if (keypad_thread.joinable()) {
|
||||||
|
keypad_thread.request_stop();
|
||||||
|
keypad_thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
// delete cards in array
|
// delete cards in array
|
||||||
for (int i = 0; i < node_count; i++) {
|
for (int i = 0; i < node_count; i++) {
|
||||||
delete cards[i];
|
delete[] cards[i];
|
||||||
|
delete[] keypad_last[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete the rest
|
// delete the rest
|
||||||
@@ -107,7 +111,7 @@ bool ICCADevice::parse_msg(MessageData *msg_in,
|
|||||||
if (avs::game::is_model({"LDJ", "TBS", "UJK", "XIF"}) ||
|
if (avs::game::is_model({"LDJ", "TBS", "UJK", "XIF"}) ||
|
||||||
games::sdvx::is_valkyrie_model()) {
|
games::sdvx::is_valkyrie_model()) {
|
||||||
this->set_version(msg, 0x3, 0, 1, 7, 0, "ICCA");
|
this->set_version(msg, 0x3, 0, 1, 7, 0, "ICCA");
|
||||||
} else if (avs::game::is_model("VFG")) {
|
} else if (avs::game::is_model({"VFG", "TCS"})) {
|
||||||
this->set_version(msg, 0x3, 0, 1, 7, 0, "ICCB");
|
this->set_version(msg, 0x3, 0, 1, 7, 0, "ICCB");
|
||||||
} else {
|
} else {
|
||||||
this->set_version(msg, 0x3, 0, 1, 6, 0, "ICCA");
|
this->set_version(msg, 0x3, 0, 1, 6, 0, "ICCA");
|
||||||
@@ -160,7 +164,7 @@ bool ICCADevice::parse_msg(MessageData *msg_in,
|
|||||||
break;
|
break;
|
||||||
case 0x12: // EJECT
|
case 0x12: // EJECT
|
||||||
if (this->cards[unit] != nullptr) {
|
if (this->cards[unit] != nullptr) {
|
||||||
delete this->cards[unit];
|
delete[] this->cards[unit];
|
||||||
}
|
}
|
||||||
this->cards[unit] = nullptr;
|
this->cards[unit] = nullptr;
|
||||||
this->hold[unit] = false;
|
this->hold[unit] = false;
|
||||||
@@ -267,7 +271,7 @@ bool ICCADevice::parse_msg(MessageData *msg_in,
|
|||||||
memcpy(msg->cmd.raw, this->cards[unit], 8);
|
memcpy(msg->cmd.raw, this->cards[unit], 8);
|
||||||
|
|
||||||
// delete card
|
// delete card
|
||||||
delete this->cards[unit];
|
delete[] this->cards[unit];
|
||||||
this->cards[unit] = nullptr;
|
this->cards[unit] = nullptr;
|
||||||
this->hold[unit] = false;
|
this->hold[unit] = false;
|
||||||
}
|
}
|
||||||
@@ -326,7 +330,9 @@ bool ICCADevice::parse_msg(MessageData *msg_in,
|
|||||||
}
|
}
|
||||||
//log_info("icca", "counter[{}] = {}", unit, this->counter[unit]);
|
//log_info("icca", "counter[{}] = {}", unit, this->counter[unit]);
|
||||||
|
|
||||||
auto msg = this->create_msg_status(msg_in, this->counter[unit]);
|
// Card Connect waits for a successful reply without retrying this command.
|
||||||
|
auto msg = this->create_msg_status(
|
||||||
|
msg_in, avs::game::is_model("TCS") ? 0 : this->counter[unit]);
|
||||||
write_msg(msg, response_buffer);
|
write_msg(msg, response_buffer);
|
||||||
delete msg;
|
delete msg;
|
||||||
break;
|
break;
|
||||||
@@ -363,7 +369,7 @@ void ICCADevice::update_card(int unit) {
|
|||||||
|
|
||||||
if (difftime(t_now, this->cards_time[unit]) >= 10.f) {
|
if (difftime(t_now, this->cards_time[unit]) >= 10.f) {
|
||||||
if (this->cards[unit] != nullptr) {
|
if (this->cards[unit] != nullptr) {
|
||||||
delete this->cards[unit];
|
delete[] this->cards[unit];
|
||||||
}
|
}
|
||||||
this->cards[unit] = nullptr;
|
this->cards[unit] = nullptr;
|
||||||
this->hold[unit] = false;
|
this->hold[unit] = false;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace acioemu {
|
|||||||
private:
|
private:
|
||||||
bool type_new;
|
bool type_new;
|
||||||
bool flip_order;
|
bool flip_order;
|
||||||
std::thread *keypad_thread;
|
std::jthread keypad_thread;
|
||||||
std::mutex keypad_mutex;
|
std::mutex keypad_mutex;
|
||||||
uint8_t **cards;
|
uint8_t **cards;
|
||||||
time_t *cards_time;
|
time_t *cards_time;
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
|
||||||
|
#include <climits>
|
||||||
|
#include <cstring>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "avs/game.h"
|
||||||
#include "external/robin_hood.h"
|
#include "external/robin_hood.h"
|
||||||
#include "games/popn/popn.h"
|
#include "games/popn/popn.h"
|
||||||
#include "launcher/logger.h"
|
#include "launcher/logger.h"
|
||||||
@@ -1181,6 +1184,18 @@ namespace avs {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SPICE64
|
||||||
|
// nabla increased heap size a few months into service (June 2026?)
|
||||||
|
if (dll_name == "soundvoltex.dll" &&
|
||||||
|
avs::game::is_ext(2025121501, INT_MAX)) {
|
||||||
|
auto old_size = HEAP_SIZE;
|
||||||
|
HEAP_SIZE = 0x18000000;
|
||||||
|
DEFAULT_HEAP_SIZE_SET = true;
|
||||||
|
log_info("avs-core", "updated heap size: {} -> {} (nabla)", old_size, avs::core::HEAP_SIZE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// hack, both hello! popn and popn hc using popn.dll
|
// hack, both hello! popn and popn hc using popn.dll
|
||||||
if (games::popn::is_pikapika_model()) {
|
if (games::popn::is_pikapika_model()) {
|
||||||
auto old_size = HEAP_SIZE;
|
auto old_size = HEAP_SIZE;
|
||||||
|
|||||||
@@ -573,6 +573,13 @@ static inline void easrv_init_messages() {
|
|||||||
"\x5b\x99\xa1\x15\x78\x16\x84\xe0\x67\x2c\x75\xf7\xc0\x38\xd5\x20\xf7\x81\xae\x1f\x77\x02\xdf\x0c"
|
"\x5b\x99\xa1\x15\x78\x16\x84\xe0\x67\x2c\x75\xf7\xc0\x38\xd5\x20\xf7\x81\xae\x1f\x77\x02\xdf\x0c"
|
||||||
"\x60\x68\x2e\x26\xe5\xbb\xb7\xb4\x41\x72\xc4\xa4\x43\x2a\xc8\x81\xd3\x8a\x1f\xe8\x94\x39\x7e\xf6"
|
"\x60\x68\x2e\x26\xe5\xbb\xb7\xb4\x41\x72\xc4\xa4\x43\x2a\xc8\x81\xd3\x8a\x1f\xe8\x94\x39\x7e\xf6"
|
||||||
"\x69\x56\x9e\xaf\x06\x10\xfd\x47\x69\xb8\x14\xe6\x48\x36\xd6\x25\x18\x0c\x2b\x3d\x69");
|
"\x69\x56\x9e\xaf\x06\x10\xfd\x47\x69\xb8\x14\xe6\x48\x36\xd6\x25\x18\x0c\x2b\x3d\x69");
|
||||||
|
if (avs::game::is_model("UDN")) {
|
||||||
|
// Only UDN needs an ASCII location/name for the Unity score-screen marshaler.
|
||||||
|
// These 12 encoded bytes replace the name with "SPICE2 LOCAL";
|
||||||
|
// its terminator, the other fields and the response length stay unchanged.
|
||||||
|
EA_FACILITY_GET.replace(311, 12,
|
||||||
|
"\xf2\x20\xcc\x9a\xe3\x32\x78\x80\x9a\xba\xcd\xc3");
|
||||||
|
}
|
||||||
EA_PCBEVENT_PUT = std::string(
|
EA_PCBEVENT_PUT = std::string(
|
||||||
"\x17\x7e\x7c\x0e\x1a\x15\x41\x0b\xae\xd5\xa0\xf5\x2c\xa1\xb9\xd2\x53\xca\xd2\x0d\x81\x34\xdb\x94\x79\xd0"
|
"\x17\x7e\x7c\x0e\x1a\x15\x41\x0b\xae\xd5\xa0\xf5\x2c\xa1\xb9\xd2\x53\xca\xd2\x0d\x81\x34\xdb\x94\x79\xd0"
|
||||||
"\xc8\x9d\xb5\xfb\xef\x97");
|
"\xc8\x9d\xb5\xfb\xef\x97");
|
||||||
|
|||||||
+27
-13
@@ -1,25 +1,30 @@
|
|||||||
#include "bc.h"
|
#include "bc.h"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
#include "hooks/setupapihook.h"
|
#include "hooks/setupapihook.h"
|
||||||
|
#include "util/fileutils.h"
|
||||||
#include "util/libutils.h"
|
#include "util/libutils.h"
|
||||||
#include "acio2emu/handle.h"
|
#include "acio2emu/handle.h"
|
||||||
#include "acioemu/handle.h"
|
#include "acioemu/handle.h"
|
||||||
#include "hooks/graphics/graphics.h"
|
#include "hooks/graphics/graphics.h"
|
||||||
#include "util/detour.h"
|
#include "util/unity_player.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
#include "bi2x_hook.h"
|
||||||
|
|
||||||
namespace games::bc {
|
namespace games::bc {
|
||||||
|
|
||||||
static decltype(ShowCursor) *ShowCursor_orig = nullptr;
|
std::string BC_INJECT_ARGS = "";
|
||||||
|
|
||||||
static int WINAPI ShowCursor_hook(BOOL bShow) {
|
|
||||||
// log_misc("bsac", "ShowCursor {}", bShow);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BCGame::attach() {
|
void BCGame::attach() {
|
||||||
Game::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"));
|
setupapihook_init(libutils::load_library("libaio.dll"));
|
||||||
|
|
||||||
SETUPAPI_SETTINGS settings {};
|
SETUPAPI_SETTINGS settings {};
|
||||||
@@ -32,15 +37,24 @@ namespace games::bc {
|
|||||||
auto iob = new acio2emu::IOBHandle(L"COM3");
|
auto iob = new acio2emu::IOBHandle(L"COM3");
|
||||||
iob->register_node(std::make_unique<TBSNode>());
|
iob->register_node(std::make_unique<TBSNode>());
|
||||||
|
|
||||||
if (GRAPHICS_SHOW_CURSOR) {
|
#if SPICE64
|
||||||
detour::trampoline_try(
|
// insert BI2X hooks
|
||||||
"user32.dll", "ShowCursor",
|
bi2x_hook_init();
|
||||||
(void*)ShowCursor_hook, (void**)&ShowCursor_orig);
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
devicehook_init();
|
devicehook_init_trampoline();
|
||||||
devicehook_add(iob);
|
devicehook_add(iob);
|
||||||
devicehook_add(new acioemu::ACIOHandle(L"COM1"));
|
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() {
|
void BCGame::detach() {
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include "games/game.h"
|
#include "games/game.h"
|
||||||
|
|
||||||
namespace games::bc {
|
namespace games::bc {
|
||||||
|
extern std::string BC_INJECT_ARGS;
|
||||||
|
|
||||||
class BCGame : public games::Game {
|
class BCGame : public games::Game {
|
||||||
public:
|
public:
|
||||||
BCGame() : Game("Busou Shinki: Armored Princess Battle Conductor") {}
|
BCGame() : Game("Busou Shinki: Armored Princess Battle Conductor") {}
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if SPICE64
|
||||||
|
|
||||||
|
namespace games::bc {
|
||||||
|
void bi2x_hook_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -48,3 +48,31 @@ std::vector<Analog> &games::bc::get_analogs() {
|
|||||||
|
|
||||||
return 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;
|
||||||
|
}
|
||||||
@@ -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::vector<Button> &get_buttons();
|
||||||
std::string get_buttons_help();
|
std::string get_buttons_help();
|
||||||
std::vector<Analog> &get_analogs();
|
std::vector<Analog> &get_analogs();
|
||||||
|
std::vector<Light> &get_lights();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,371 @@
|
|||||||
|
#include "bi2x_hook.h"
|
||||||
|
|
||||||
|
#if SPICE64
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "io.h"
|
||||||
|
#include "misc/eamuse.h"
|
||||||
|
#include "rawinput/rawinput.h"
|
||||||
|
#include "util/detour.h"
|
||||||
|
#include "util/logging.h"
|
||||||
|
#include "util/tapeled.h"
|
||||||
|
|
||||||
|
namespace games::cardconnect {
|
||||||
|
|
||||||
|
struct AIO_SCI_COMM {
|
||||||
|
uint8_t data[0xf8];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AIO_NMGR_IOB2 {
|
||||||
|
uint8_t data[0x9f8];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AIO_IOB2_BI2X_TCS {
|
||||||
|
uint8_t data[0x350];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AIO_IOB2_BI2X_WRFIRM {
|
||||||
|
uint8_t data[0x20f48];
|
||||||
|
};
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
struct AIO_IOB2_BI2X_TCS__INPUT {
|
||||||
|
uint8_t DevIoCounter;
|
||||||
|
uint8_t bTest;
|
||||||
|
uint8_t bService;
|
||||||
|
uint8_t bCoinSw;
|
||||||
|
uint8_t bCoinJam;
|
||||||
|
uint8_t CoinCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AIO_IOB2_BI2X_TCS__DEVSTATUS {
|
||||||
|
uint8_t InputCounter;
|
||||||
|
uint8_t OutputCounter;
|
||||||
|
uint8_t TapeLedCounter;
|
||||||
|
AIO_IOB2_BI2X_TCS__INPUT Input;
|
||||||
|
uint8_t reserved[17];
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
// The supplied native DLL copies 26 bytes, even though the managed wrapper requests 27.
|
||||||
|
static_assert(sizeof(AIO_IOB2_BI2X_TCS__DEVSTATUS) == 26);
|
||||||
|
static_assert(offsetof(AIO_IOB2_BI2X_TCS__DEVSTATUS, Input) == 3);
|
||||||
|
static_assert(offsetof(AIO_IOB2_BI2X_TCS__INPUT, bTest) == 1);
|
||||||
|
static_assert(offsetof(AIO_IOB2_BI2X_TCS__INPUT, bService) == 2);
|
||||||
|
static_assert(offsetof(AIO_IOB2_BI2X_TCS__INPUT, bCoinSw) == 3);
|
||||||
|
static_assert(offsetof(AIO_IOB2_BI2X_TCS__INPUT, CoinCount) == 5);
|
||||||
|
|
||||||
|
static AIO_IOB2_BI2X_TCS *(__fastcall *aioIob2Bi2xTCS_Create_orig)(
|
||||||
|
AIO_NMGR_IOB2 *, uint32_t) = nullptr;
|
||||||
|
static uint32_t (__fastcall *aioIob2Bi2xTCS_GetDeviceStatus_orig)(
|
||||||
|
AIO_IOB2_BI2X_TCS *, AIO_IOB2_BI2X_TCS__DEVSTATUS *, uint32_t) = nullptr;
|
||||||
|
static void (__fastcall *aioIob2Bi2xTCS_IoReset_orig)(
|
||||||
|
AIO_IOB2_BI2X_TCS *, uint32_t) = nullptr;
|
||||||
|
static void (__fastcall *aioIob2Bi2xTCS_SetWatchDogTimer_orig)(
|
||||||
|
AIO_IOB2_BI2X_TCS *, uint8_t) = nullptr;
|
||||||
|
static void (__fastcall *aioIob2Bi2xTCS_ControlCoinBlocker_orig)(
|
||||||
|
AIO_IOB2_BI2X_TCS *, uint32_t, bool) = nullptr;
|
||||||
|
static void (__fastcall *aioIob2Bi2xTCS_AddCounter_orig)(
|
||||||
|
AIO_IOB2_BI2X_TCS *, uint32_t, uint32_t) = nullptr;
|
||||||
|
static void (__fastcall *aioIob2Bi2xTCS_SetPhotoLight_orig)(
|
||||||
|
AIO_IOB2_BI2X_TCS *, bool) = nullptr;
|
||||||
|
static void (__fastcall *aioIob2Bi2xTCS_SetIccrLed_orig)(
|
||||||
|
AIO_IOB2_BI2X_TCS *, uint32_t) = nullptr;
|
||||||
|
static void (__fastcall *aioIob2Bi2xTCS_SetTapeLedData_orig)(
|
||||||
|
AIO_IOB2_BI2X_TCS *, uint32_t, uint8_t *) = nullptr;
|
||||||
|
|
||||||
|
static AIO_SCI_COMM *(__fastcall *aioIob2Bi2x_OpenSciUsbCdc_orig)(uint32_t) = nullptr;
|
||||||
|
static AIO_IOB2_BI2X_WRFIRM *(__fastcall *aioIob2Bi2x_CreateWriteFirmContext_orig)(
|
||||||
|
uint32_t, uint32_t) = nullptr;
|
||||||
|
static void (__fastcall *aioIob2Bi2x_DestroyWriteFirmContext_orig)(
|
||||||
|
AIO_IOB2_BI2X_WRFIRM *) = nullptr;
|
||||||
|
static int32_t (__fastcall *aioIob2Bi2x_WriteFirmGetState_orig)(
|
||||||
|
AIO_IOB2_BI2X_WRFIRM *) = nullptr;
|
||||||
|
static AIO_NMGR_IOB2 *(__fastcall *aioNMgrIob2_Create_orig)(
|
||||||
|
AIO_SCI_COMM *, uint32_t) = nullptr;
|
||||||
|
static void (__fastcall *aioNMgrIob_BeginManage_orig)(AIO_NMGR_IOB2 *) = nullptr;
|
||||||
|
|
||||||
|
static void (__fastcall *aioNodeMgr_Destroy_orig)(AIO_NMGR_IOB2 *) = nullptr;
|
||||||
|
static int32_t (__fastcall *aioNodeMgr_GetState_orig)(AIO_NMGR_IOB2 *) = nullptr;
|
||||||
|
static bool (__fastcall *aioNodeMgr_IsReady_orig)(AIO_NMGR_IOB2 *, int32_t) = nullptr;
|
||||||
|
static void (__fastcall *aioNodeCtl_Destroy_orig)(AIO_IOB2_BI2X_TCS *) = nullptr;
|
||||||
|
static int32_t (__fastcall *aioNodeCtl_GetState_orig)(AIO_IOB2_BI2X_TCS *) = nullptr;
|
||||||
|
static bool (__fastcall *aioNodeCtl_IsReady_orig)(AIO_IOB2_BI2X_TCS *, int32_t) = nullptr;
|
||||||
|
static void (__fastcall *aioSci_Destroy_orig)(AIO_SCI_COMM *) = nullptr;
|
||||||
|
|
||||||
|
static std::unique_ptr<AIO_SCI_COMM> aio_sci;
|
||||||
|
static std::unique_ptr<AIO_NMGR_IOB2> aio_manager;
|
||||||
|
static std::unique_ptr<AIO_IOB2_BI2X_TCS> aio_board;
|
||||||
|
static std::unique_ptr<AIO_IOB2_BI2X_WRFIRM> aio_firmware;
|
||||||
|
static uint8_t input_counter = 0;
|
||||||
|
static bool coin_pressed = false;
|
||||||
|
|
||||||
|
static void write_light(size_t index, float value) {
|
||||||
|
auto &lights = get_lights();
|
||||||
|
GameAPI::Lights::writeLight(RI_MGR, lights[index], value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static AIO_IOB2_BI2X_TCS *__fastcall aioIob2Bi2xTCS_Create(
|
||||||
|
AIO_NMGR_IOB2 *manager, uint32_t device_id) {
|
||||||
|
if (!aio_manager || manager != aio_manager.get()) {
|
||||||
|
return aioIob2Bi2xTCS_Create_orig(manager, device_id);
|
||||||
|
}
|
||||||
|
if (!aio_board) {
|
||||||
|
aio_board = std::make_unique<AIO_IOB2_BI2X_TCS>();
|
||||||
|
input_counter = 0;
|
||||||
|
coin_pressed = false;
|
||||||
|
log_info("cardconnect::bi2x", "created emulated BI2X-TCS board");
|
||||||
|
}
|
||||||
|
return aio_board.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t __fastcall aioIob2Bi2xTCS_GetDeviceStatus(
|
||||||
|
AIO_IOB2_BI2X_TCS *board, AIO_IOB2_BI2X_TCS__DEVSTATUS *status,
|
||||||
|
uint32_t status_size) {
|
||||||
|
if (!aio_board || board != aio_board.get()) {
|
||||||
|
return aioIob2Bi2xTCS_GetDeviceStatus_orig(board, status, status_size);
|
||||||
|
}
|
||||||
|
if (!status && status_size > 0) {
|
||||||
|
log_warning("cardconnect::bi2x", "GetDeviceStatus called with a null output buffer");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &buttons = get_buttons();
|
||||||
|
const bool coin = GameAPI::Buttons::getState(RI_MGR, buttons[Buttons::CoinMech]);
|
||||||
|
if (coin && !coin_pressed) {
|
||||||
|
eamuse_coin_insert();
|
||||||
|
}
|
||||||
|
coin_pressed = coin;
|
||||||
|
|
||||||
|
AIO_IOB2_BI2X_TCS__DEVSTATUS current {};
|
||||||
|
current.InputCounter = ++input_counter;
|
||||||
|
current.Input.DevIoCounter = input_counter;
|
||||||
|
current.Input.bTest = GameAPI::Buttons::getState(RI_MGR, buttons[Buttons::Test]) ? 1 : 0;
|
||||||
|
current.Input.bService = GameAPI::Buttons::getState(RI_MGR, buttons[Buttons::Service]) ? 1 : 0;
|
||||||
|
current.Input.bCoinSw = coin ? 1 : 0;
|
||||||
|
current.Input.CoinCount = static_cast<uint8_t>(eamuse_coin_get_stock());
|
||||||
|
|
||||||
|
RI_MGR->devices_flush_output();
|
||||||
|
|
||||||
|
const auto copy_size = std::min<uint32_t>(status_size, sizeof(current));
|
||||||
|
if (copy_size > 0) {
|
||||||
|
std::memcpy(status, ¤t, copy_size);
|
||||||
|
}
|
||||||
|
return copy_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xTCS_IoReset(AIO_IOB2_BI2X_TCS *board, uint32_t bits) {
|
||||||
|
if (!aio_board || board != aio_board.get()) {
|
||||||
|
return aioIob2Bi2xTCS_IoReset_orig(board, bits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xTCS_SetWatchDogTimer(
|
||||||
|
AIO_IOB2_BI2X_TCS *board, uint8_t count) {
|
||||||
|
if (!aio_board || board != aio_board.get()) {
|
||||||
|
return aioIob2Bi2xTCS_SetWatchDogTimer_orig(board, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xTCS_ControlCoinBlocker(
|
||||||
|
AIO_IOB2_BI2X_TCS *board, uint32_t slot, bool open) {
|
||||||
|
if (!aio_board || board != aio_board.get()) {
|
||||||
|
return aioIob2Bi2xTCS_ControlCoinBlocker_orig(board, slot, open);
|
||||||
|
}
|
||||||
|
if (slot != 0) {
|
||||||
|
log_warning("cardconnect::bi2x", "unknown coin blocker slot {}", slot);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
eamuse_coin_set_block(!open);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xTCS_AddCounter(
|
||||||
|
AIO_IOB2_BI2X_TCS *board, uint32_t counter, uint32_t count) {
|
||||||
|
if (!aio_board || board != aio_board.get()) {
|
||||||
|
return aioIob2Bi2xTCS_AddCounter_orig(board, counter, count);
|
||||||
|
}
|
||||||
|
// This drives the physical bookkeeping meter, not the input coin counter.
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xTCS_SetPhotoLight(AIO_IOB2_BI2X_TCS *board, bool on) {
|
||||||
|
if (!aio_board || board != aio_board.get()) {
|
||||||
|
return aioIob2Bi2xTCS_SetPhotoLight_orig(board, on);
|
||||||
|
}
|
||||||
|
write_light(Lights::PhotoLight, on ? 1.f : 0.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xTCS_SetIccrLed(AIO_IOB2_BI2X_TCS *board, uint32_t rgb) {
|
||||||
|
if (!aio_board || board != aio_board.get()) {
|
||||||
|
return aioIob2Bi2xTCS_SetIccrLed_orig(board, rgb);
|
||||||
|
}
|
||||||
|
write_light(Lights::CardReaderR, ((rgb >> 16) & 0xff) / 255.f);
|
||||||
|
write_light(Lights::CardReaderG, ((rgb >> 8) & 0xff) / 255.f);
|
||||||
|
write_light(Lights::CardReaderB, (rgb & 0xff) / 255.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xTCS_SetTapeLedData(
|
||||||
|
AIO_IOB2_BI2X_TCS *board, uint32_t tape, uint8_t *data) {
|
||||||
|
if (!aio_board || board != aio_board.get()) {
|
||||||
|
return aioIob2Bi2xTCS_SetTapeLedData_orig(board, tape, data);
|
||||||
|
}
|
||||||
|
if (!data || tape >= 2) {
|
||||||
|
log_warning("cardconnect::bi2x", "invalid tape LED data for channel {}", tape);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tapeledutils::is_enabled()) {
|
||||||
|
const auto color = tapeledutils::pick_color_from_led_tape(data, 15);
|
||||||
|
const auto first = tape == 0 ? Lights::SideLeftR : Lights::SideRightR;
|
||||||
|
write_light(first, color.r);
|
||||||
|
write_light(first + 1, color.g);
|
||||||
|
write_light(first + 2, color.b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static AIO_SCI_COMM *__fastcall aioIob2Bi2x_OpenSciUsbCdc(uint32_t serial_number) {
|
||||||
|
if (!aio_sci) {
|
||||||
|
aio_sci = std::make_unique<AIO_SCI_COMM>();
|
||||||
|
}
|
||||||
|
return aio_sci.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
static AIO_IOB2_BI2X_WRFIRM *__fastcall aioIob2Bi2x_CreateWriteFirmContext(
|
||||||
|
uint32_t serial_number, uint32_t iob_mask) {
|
||||||
|
if (!aio_firmware) {
|
||||||
|
aio_firmware = std::make_unique<AIO_IOB2_BI2X_WRFIRM>();
|
||||||
|
}
|
||||||
|
return aio_firmware.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2x_DestroyWriteFirmContext(AIO_IOB2_BI2X_WRFIRM *context) {
|
||||||
|
if (!aio_firmware || context != aio_firmware.get()) {
|
||||||
|
return aioIob2Bi2x_DestroyWriteFirmContext_orig(context);
|
||||||
|
}
|
||||||
|
aio_firmware.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t __fastcall aioIob2Bi2x_WriteFirmGetState(AIO_IOB2_BI2X_WRFIRM *context) {
|
||||||
|
if (!aio_firmware || context != aio_firmware.get()) {
|
||||||
|
return aioIob2Bi2x_WriteFirmGetState_orig(context);
|
||||||
|
}
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
static AIO_NMGR_IOB2 *__fastcall aioNMgrIob2_Create(AIO_SCI_COMM *sci, uint32_t mode) {
|
||||||
|
if (!aio_sci || sci != aio_sci.get()) {
|
||||||
|
return aioNMgrIob2_Create_orig(sci, mode);
|
||||||
|
}
|
||||||
|
if (!aio_manager) {
|
||||||
|
aio_manager = std::make_unique<AIO_NMGR_IOB2>();
|
||||||
|
}
|
||||||
|
return aio_manager.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioNMgrIob_BeginManage(AIO_NMGR_IOB2 *manager) {
|
||||||
|
if (!aio_manager || manager != aio_manager.get()) {
|
||||||
|
return aioNMgrIob_BeginManage_orig(manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioNodeMgr_Destroy(AIO_NMGR_IOB2 *manager) {
|
||||||
|
if (!aio_manager || manager != aio_manager.get()) {
|
||||||
|
return aioNodeMgr_Destroy_orig(manager);
|
||||||
|
}
|
||||||
|
aio_manager.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t __fastcall aioNodeMgr_GetState(AIO_NMGR_IOB2 *manager) {
|
||||||
|
if (!aio_manager || manager != aio_manager.get()) {
|
||||||
|
return aioNodeMgr_GetState_orig(manager);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool __fastcall aioNodeMgr_IsReady(AIO_NMGR_IOB2 *manager, int32_t state) {
|
||||||
|
if (!aio_manager || manager != aio_manager.get()) {
|
||||||
|
return aioNodeMgr_IsReady_orig(manager, state);
|
||||||
|
}
|
||||||
|
return state >= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioNodeCtl_Destroy(AIO_IOB2_BI2X_TCS *board) {
|
||||||
|
if (!aio_board || board != aio_board.get()) {
|
||||||
|
return aioNodeCtl_Destroy_orig(board);
|
||||||
|
}
|
||||||
|
aio_board.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t __fastcall aioNodeCtl_GetState(AIO_IOB2_BI2X_TCS *board) {
|
||||||
|
if (!aio_board || board != aio_board.get()) {
|
||||||
|
return aioNodeCtl_GetState_orig(board);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool __fastcall aioNodeCtl_IsReady(AIO_IOB2_BI2X_TCS *board, int32_t state) {
|
||||||
|
if (!aio_board || board != aio_board.get()) {
|
||||||
|
return aioNodeCtl_IsReady_orig(board, state);
|
||||||
|
}
|
||||||
|
return state >= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioSci_Destroy(AIO_SCI_COMM *sci) {
|
||||||
|
if (!aio_sci || sci != aio_sci.get()) {
|
||||||
|
return aioSci_Destroy_orig(sci);
|
||||||
|
}
|
||||||
|
aio_sci.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void bi2x_hook_init() {
|
||||||
|
log_info("cardconnect::bi2x", "initializing native BI2X-TCS hooks");
|
||||||
|
|
||||||
|
const auto video = "libaio-iob2_video.dll";
|
||||||
|
detour::trampoline(video, "aioIob2Bi2xTCS_Create",
|
||||||
|
aioIob2Bi2xTCS_Create, &aioIob2Bi2xTCS_Create_orig);
|
||||||
|
detour::trampoline(video, "aioIob2Bi2xTCS_GetDeviceStatus",
|
||||||
|
aioIob2Bi2xTCS_GetDeviceStatus, &aioIob2Bi2xTCS_GetDeviceStatus_orig);
|
||||||
|
detour::trampoline(video, "aioIob2Bi2xTCS_IoReset",
|
||||||
|
aioIob2Bi2xTCS_IoReset, &aioIob2Bi2xTCS_IoReset_orig);
|
||||||
|
detour::trampoline(video, "aioIob2Bi2xTCS_SetWatchDogTimer",
|
||||||
|
aioIob2Bi2xTCS_SetWatchDogTimer, &aioIob2Bi2xTCS_SetWatchDogTimer_orig);
|
||||||
|
detour::trampoline(video, "aioIob2Bi2xTCS_ControlCoinBlocker",
|
||||||
|
aioIob2Bi2xTCS_ControlCoinBlocker, &aioIob2Bi2xTCS_ControlCoinBlocker_orig);
|
||||||
|
detour::trampoline(video, "aioIob2Bi2xTCS_AddCounter",
|
||||||
|
aioIob2Bi2xTCS_AddCounter, &aioIob2Bi2xTCS_AddCounter_orig);
|
||||||
|
detour::trampoline(video, "aioIob2Bi2xTCS_SetPhotoLight",
|
||||||
|
aioIob2Bi2xTCS_SetPhotoLight, &aioIob2Bi2xTCS_SetPhotoLight_orig);
|
||||||
|
detour::trampoline(video, "aioIob2Bi2xTCS_SetIccrLed",
|
||||||
|
aioIob2Bi2xTCS_SetIccrLed, &aioIob2Bi2xTCS_SetIccrLed_orig);
|
||||||
|
detour::trampoline(video, "aioIob2Bi2xTCS_SetTapeLedData",
|
||||||
|
aioIob2Bi2xTCS_SetTapeLedData, &aioIob2Bi2xTCS_SetTapeLedData_orig);
|
||||||
|
|
||||||
|
const auto iob = "libaio-iob.dll";
|
||||||
|
detour::trampoline(iob, "aioIob2Bi2x_OpenSciUsbCdc",
|
||||||
|
aioIob2Bi2x_OpenSciUsbCdc, &aioIob2Bi2x_OpenSciUsbCdc_orig);
|
||||||
|
detour::trampoline(iob, "aioIob2Bi2x_CreateWriteFirmContext",
|
||||||
|
aioIob2Bi2x_CreateWriteFirmContext, &aioIob2Bi2x_CreateWriteFirmContext_orig);
|
||||||
|
detour::trampoline(iob, "aioIob2Bi2x_DestroyWriteFirmContext",
|
||||||
|
aioIob2Bi2x_DestroyWriteFirmContext, &aioIob2Bi2x_DestroyWriteFirmContext_orig);
|
||||||
|
detour::trampoline(iob, "aioIob2Bi2x_WriteFirmGetState",
|
||||||
|
aioIob2Bi2x_WriteFirmGetState, &aioIob2Bi2x_WriteFirmGetState_orig);
|
||||||
|
detour::trampoline(iob, "aioNMgrIob2_Create",
|
||||||
|
aioNMgrIob2_Create, &aioNMgrIob2_Create_orig);
|
||||||
|
detour::trampoline(iob, "aioNMgrIob_BeginManage",
|
||||||
|
aioNMgrIob_BeginManage, &aioNMgrIob_BeginManage_orig);
|
||||||
|
|
||||||
|
const auto aio = "libaio.dll";
|
||||||
|
detour::trampoline(aio, "aioNodeMgr_Destroy", aioNodeMgr_Destroy, &aioNodeMgr_Destroy_orig);
|
||||||
|
detour::trampoline(aio, "aioNodeMgr_GetState", aioNodeMgr_GetState, &aioNodeMgr_GetState_orig);
|
||||||
|
detour::trampoline(aio, "aioNodeMgr_IsReady", aioNodeMgr_IsReady, &aioNodeMgr_IsReady_orig);
|
||||||
|
detour::trampoline(aio, "aioNodeCtl_Destroy", aioNodeCtl_Destroy, &aioNodeCtl_Destroy_orig);
|
||||||
|
detour::trampoline(aio, "aioNodeCtl_GetState", aioNodeCtl_GetState, &aioNodeCtl_GetState_orig);
|
||||||
|
detour::trampoline(aio, "aioNodeCtl_IsReady", aioNodeCtl_IsReady, &aioNodeCtl_IsReady_orig);
|
||||||
|
detour::trampoline(aio, "aioSci_Destroy", aioSci_Destroy, &aioSci_Destroy_orig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace games::cardconnect {
|
||||||
|
void bi2x_hook_init();
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
#include "cardconnect.h"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
#include "acioemu/handle.h"
|
||||||
|
#include "bi2x_hook.h"
|
||||||
|
#include "printer.h"
|
||||||
|
#include "hooks/graphics/graphics.h"
|
||||||
|
#include "util/execexe.h"
|
||||||
|
#include "util/fileutils.h"
|
||||||
|
#include "util/libutils.h"
|
||||||
|
#include "util/logging.h"
|
||||||
|
#include "util/unity_player.h"
|
||||||
|
|
||||||
|
namespace games::cardconnect {
|
||||||
|
std::string CARDCONNECT_INJECT_ARGS = "";
|
||||||
|
|
||||||
|
static const std::wstring reader_port = L"\\\\.\\COM2";
|
||||||
|
|
||||||
|
void CardConnectGame::attach() {
|
||||||
|
Game::attach();
|
||||||
|
|
||||||
|
fileutils::dir_create_recursive_log("cardconnect", "dev/raw/log");
|
||||||
|
if (!fileutils::bin_write("dev/raw/log/output_log.txt", nullptr, 0)) {
|
||||||
|
log_warning("cardconnect", "failed to create Unity output log");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *reader = new acioemu::ACIOHandle(reader_port.c_str(), 1);
|
||||||
|
devicehook_init_trampoline();
|
||||||
|
devicehook_add(reader);
|
||||||
|
|
||||||
|
execexe::init();
|
||||||
|
execexe::init_port_hook(reader_port, reader);
|
||||||
|
|
||||||
|
#if SPICE64
|
||||||
|
libutils::load_library("libaio.dll");
|
||||||
|
libutils::load_library("libaio-iob.dll");
|
||||||
|
libutils::load_library("libaio-iob2_video.dll");
|
||||||
|
bi2x_hook_init();
|
||||||
|
printer_attach();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (GRAPHICS_SHOW_CURSOR) {
|
||||||
|
unity_utils::force_show_cursor(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
unity_utils::set_args(
|
||||||
|
std::format("{} {}{}",
|
||||||
|
GetCommandLineA(),
|
||||||
|
CARDCONNECT_INJECT_ARGS,
|
||||||
|
unity_utils::get_unity_player_args()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardConnectGame::detach() {
|
||||||
|
Game::detach();
|
||||||
|
devicehook_dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "games/game.h"
|
||||||
|
|
||||||
|
namespace games::cardconnect {
|
||||||
|
extern std::string CARDCONNECT_INJECT_ARGS;
|
||||||
|
|
||||||
|
class CardConnectGame : public games::Game {
|
||||||
|
public:
|
||||||
|
CardConnectGame() : Game("Card Connect") {}
|
||||||
|
|
||||||
|
virtual void attach() override;
|
||||||
|
virtual void detach() override;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#include "io.h"
|
||||||
|
|
||||||
|
std::vector<Button> &games::cardconnect::get_buttons() {
|
||||||
|
static std::vector<Button> buttons;
|
||||||
|
|
||||||
|
if (buttons.empty()) {
|
||||||
|
buttons = GameAPI::Buttons::getButtons("Card Connect");
|
||||||
|
GameAPI::Buttons::sortButtons(
|
||||||
|
&buttons,
|
||||||
|
"Test",
|
||||||
|
"Service",
|
||||||
|
"Coin Mech"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Light> &games::cardconnect::get_lights() {
|
||||||
|
static std::vector<Light> lights;
|
||||||
|
|
||||||
|
if (lights.empty()) {
|
||||||
|
lights = GameAPI::Lights::getLights("Card Connect");
|
||||||
|
GameAPI::Lights::sortLights(
|
||||||
|
&lights,
|
||||||
|
"Photo Light",
|
||||||
|
"Card Reader R",
|
||||||
|
"Card Reader G",
|
||||||
|
"Card Reader B",
|
||||||
|
"Side Left R",
|
||||||
|
"Side Left G",
|
||||||
|
"Side Left B",
|
||||||
|
"Side Right R",
|
||||||
|
"Side Right G",
|
||||||
|
"Side Right B"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lights;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "cfg/api.h"
|
||||||
|
|
||||||
|
namespace games::cardconnect {
|
||||||
|
namespace Buttons {
|
||||||
|
enum {
|
||||||
|
Test,
|
||||||
|
Service,
|
||||||
|
CoinMech,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Lights {
|
||||||
|
enum {
|
||||||
|
PhotoLight,
|
||||||
|
CardReaderR,
|
||||||
|
CardReaderG,
|
||||||
|
CardReaderB,
|
||||||
|
SideLeftR,
|
||||||
|
SideLeftG,
|
||||||
|
SideLeftB,
|
||||||
|
SideRightR,
|
||||||
|
SideRightG,
|
||||||
|
SideRightB,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Button> &get_buttons();
|
||||||
|
std::vector<Light> &get_lights();
|
||||||
|
}
|
||||||
@@ -0,0 +1,617 @@
|
|||||||
|
#include "printer.h"
|
||||||
|
|
||||||
|
#if SPICE64
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <mutex>
|
||||||
|
#include <optional>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "games/shared/printer.h"
|
||||||
|
#include "util/detour.h"
|
||||||
|
#include "util/libutils.h"
|
||||||
|
#include "util/logging.h"
|
||||||
|
|
||||||
|
namespace games::cardconnect {
|
||||||
|
|
||||||
|
// Settings and native protocol values.
|
||||||
|
bool PRINTER_DISABLED = false;
|
||||||
|
bool PRINTER_SIMULATE_DELAY = false;
|
||||||
|
|
||||||
|
static constexpr uint16_t READY = 0;
|
||||||
|
static constexpr uint16_t INVALID_PARAMETER = 1006;
|
||||||
|
static constexpr uint16_t BUSY = 1500;
|
||||||
|
static constexpr uint16_t PRINTING = 2100;
|
||||||
|
static constexpr uint16_t OUTPUT_ERROR = 2504;
|
||||||
|
|
||||||
|
enum PrinterInfoTag : uint16_t {
|
||||||
|
INFO_PAPER = 0,
|
||||||
|
INFO_FIRMWARE = 3,
|
||||||
|
INFO_PRINT_COUNT = 4,
|
||||||
|
INFO_HOLO_REMAINING = 6,
|
||||||
|
INFO_MEMORY = 16,
|
||||||
|
INFO_FRONT_MODE = 19,
|
||||||
|
INFO_BACK_MODE = 20,
|
||||||
|
INFO_IR_CORRECTION = 22,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum PrinterMode : uint8_t {
|
||||||
|
MODE_YMC_MAT = 2,
|
||||||
|
MODE_YMC_LAM = 3,
|
||||||
|
MODE_YMC_MAT_HOLO = 5,
|
||||||
|
MODE_YMC_LAM_HOLO = 6,
|
||||||
|
MODE_IR_R_YMAC_MAT = 8,
|
||||||
|
MODE_IR_R_YMAC_LAM = 9,
|
||||||
|
MODE_R_YMAC_MAT = 10,
|
||||||
|
MODE_R_YMAC_LAM = 11,
|
||||||
|
MODE_YMC_GROSS = 18,
|
||||||
|
MODE_YMC_GROSS_HOLO = 21,
|
||||||
|
MODE_IR_R_YMAC_GROSS = 24,
|
||||||
|
MODE_R_YMAC_GROSS = 25,
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr uint16_t FORMAT_RGB = 3;
|
||||||
|
static constexpr uint16_t FORMAT_BGR = 4;
|
||||||
|
static constexpr uint16_t COLOR_COMPONENTS = 3;
|
||||||
|
static constexpr uint16_t COLOR_DEPTH = 8;
|
||||||
|
static constexpr uint16_t CARD_WIDTH = 662;
|
||||||
|
static constexpr uint16_t CARD_HEIGHT = 1024;
|
||||||
|
static constexpr uint32_t RIBBON_REMAINING = 4096;
|
||||||
|
static constexpr auto PRINT_TIME = std::chrono::seconds(5);
|
||||||
|
|
||||||
|
static constexpr std::optional<std::chrono::seconds> get_mode_delay(uint8_t mode) {
|
||||||
|
// Printer::GetPrintTime adds 10s for holo and 8s per finished side.
|
||||||
|
if (mode == MODE_YMC_GROSS || mode == MODE_IR_R_YMAC_GROSS || mode == MODE_R_YMAC_GROSS) {
|
||||||
|
return std::chrono::seconds(0);
|
||||||
|
}
|
||||||
|
if (mode == MODE_YMC_MAT || mode == MODE_YMC_LAM ||
|
||||||
|
mode == MODE_IR_R_YMAC_MAT || mode == MODE_IR_R_YMAC_LAM ||
|
||||||
|
mode == MODE_R_YMAC_MAT || mode == MODE_R_YMAC_LAM) {
|
||||||
|
return std::chrono::seconds(8);
|
||||||
|
}
|
||||||
|
if (mode == MODE_YMC_GROSS_HOLO) {
|
||||||
|
return std::chrono::seconds(10);
|
||||||
|
}
|
||||||
|
if (mode == MODE_YMC_MAT_HOLO || mode == MODE_YMC_LAM_HOLO) {
|
||||||
|
return std::chrono::seconds(18);
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Native reply layouts.
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
struct FirmwareRecord {
|
||||||
|
std::array<uint8_t, 34> reserved;
|
||||||
|
uint8_t major;
|
||||||
|
uint8_t minor;
|
||||||
|
std::array<uint8_t, 2> reserved_tail;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FirmwareReply {
|
||||||
|
uint8_t count;
|
||||||
|
std::array<FirmwareRecord, 4> records;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PrintCountReply {
|
||||||
|
uint32_t total_count;
|
||||||
|
std::array<uint8_t, 16> reserved;
|
||||||
|
uint32_t ribbon_remaining;
|
||||||
|
std::array<uint8_t, 8> reserved_tail;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct HoloRemainingReply {
|
||||||
|
uint32_t remaining;
|
||||||
|
std::array<uint8_t, 28> reserved;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MemoryReply {
|
||||||
|
uint16_t reserved;
|
||||||
|
uint16_t remaining;
|
||||||
|
uint16_t completed;
|
||||||
|
uint16_t copies;
|
||||||
|
std::array<uint8_t, 10> reserved_tail;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PrintIDReply {
|
||||||
|
uint16_t remaining;
|
||||||
|
std::array<uint8_t, 4> reserved;
|
||||||
|
uint16_t status;
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
static_assert(sizeof(FirmwareRecord) == 38);
|
||||||
|
static_assert(offsetof(FirmwareRecord, major) == 34);
|
||||||
|
static_assert(offsetof(FirmwareRecord, minor) == 35);
|
||||||
|
static_assert(sizeof(FirmwareReply) == 153);
|
||||||
|
static_assert(offsetof(FirmwareReply, records) == 1);
|
||||||
|
|
||||||
|
static_assert(sizeof(PrintCountReply) == 32);
|
||||||
|
static_assert(offsetof(PrintCountReply, ribbon_remaining) == 20);
|
||||||
|
static_assert(sizeof(HoloRemainingReply) == 32);
|
||||||
|
|
||||||
|
static_assert(sizeof(MemoryReply) == 18);
|
||||||
|
static_assert(offsetof(MemoryReply, remaining) == 2);
|
||||||
|
static_assert(offsetof(MemoryReply, completed) == 4);
|
||||||
|
static_assert(offsetof(MemoryReply, copies) == 6);
|
||||||
|
|
||||||
|
static_assert(sizeof(PrintIDReply) == 8);
|
||||||
|
static_assert(offsetof(PrintIDReply, status) == 6);
|
||||||
|
|
||||||
|
// One printer, shared by the game's threads.
|
||||||
|
struct PrintJob {
|
||||||
|
uint16_t id = 0;
|
||||||
|
uint16_t copies = 1;
|
||||||
|
uint16_t remaining = 0;
|
||||||
|
|
||||||
|
uint16_t width = 0;
|
||||||
|
uint16_t height = 0;
|
||||||
|
uint16_t format = FORMAT_RGB;
|
||||||
|
std::array<std::vector<uint8_t>, 2> sides;
|
||||||
|
|
||||||
|
uint16_t error = READY;
|
||||||
|
bool receiving = false;
|
||||||
|
// Submitted jobs stay busy while waiting for this baseline.
|
||||||
|
bool awaiting_counter_baseline = false;
|
||||||
|
std::array<std::chrono::seconds, 2> mode_delays {};
|
||||||
|
std::chrono::seconds print_time = PRINT_TIME;
|
||||||
|
std::chrono::steady_clock::time_point next_copy;
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::mutex printer_mutex;
|
||||||
|
static PrintJob job;
|
||||||
|
static uint16_t next_page_id = 0;
|
||||||
|
static uint32_t total_count = 0;
|
||||||
|
static uint32_t cutter_offset = 0;
|
||||||
|
|
||||||
|
// Write the result; non-ready codes return FALSE.
|
||||||
|
static BOOL set_result(uint16_t *result, uint16_t code = READY) {
|
||||||
|
if (!result) {
|
||||||
|
log_warning("cardconnect::printer", "missing result buffer");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = code;
|
||||||
|
return code == READY;
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL invalid_parameter(uint16_t *result, const char *operation) {
|
||||||
|
log_warning("cardconnect::printer", "{}: invalid parameter or job state", operation);
|
||||||
|
return set_result(result, INVALID_PARAMETER);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Caller holds printer_mutex. The baseline gates completion.
|
||||||
|
static void update_printing() {
|
||||||
|
if (job.awaiting_counter_baseline) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto now = std::chrono::steady_clock::now();
|
||||||
|
while (job.remaining && now >= job.next_copy) {
|
||||||
|
++total_count;
|
||||||
|
--job.remaining;
|
||||||
|
job.next_copy += job.print_time;
|
||||||
|
log_info("cardconnect::printer", "job {}: total count={}, remaining={}",
|
||||||
|
job.id, total_count, job.remaining);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Caller holds printer_mutex.
|
||||||
|
static uint16_t poll_status() {
|
||||||
|
update_printing();
|
||||||
|
if (job.error) {
|
||||||
|
return job.error;
|
||||||
|
}
|
||||||
|
return job.remaining ? PRINTING : READY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Driver lifetime.
|
||||||
|
static void __stdcall chcusb_MakeThread(uint16_t count) {
|
||||||
|
log_info("cardconnect::printer", "initializing printer with {} thread slots", count);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL __stdcall chcusb_open(uint16_t *result) {
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __stdcall chcusb_close() {
|
||||||
|
// Closing a worker must not cancel a submitted job.
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
if (job.receiving) {
|
||||||
|
log_warning("cardconnect::printer", "discarding incomplete print job {}", job.id);
|
||||||
|
job = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL __stdcall chcusb_ReleaseThread(uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
job = {};
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status and printer information.
|
||||||
|
static BOOL __stdcall chcusb_status(uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
return set_result(result, poll_status());
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL __stdcall chcusb_getPrinterInfo(uint16_t tag, void *buffer, uint16_t *length) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
update_printing();
|
||||||
|
|
||||||
|
// Build the requested reply.
|
||||||
|
std::array<uint8_t, sizeof(FirmwareReply)> data {};
|
||||||
|
uint16_t size;
|
||||||
|
switch (tag) {
|
||||||
|
case INFO_FIRMWARE: {
|
||||||
|
FirmwareReply reply {};
|
||||||
|
reply.count = static_cast<uint8_t>(reply.records.size());
|
||||||
|
for (auto &record : reply.records) {
|
||||||
|
record.major = 1;
|
||||||
|
}
|
||||||
|
size = sizeof(reply);
|
||||||
|
std::memcpy(data.data(), &reply, size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case INFO_PRINT_COUNT: {
|
||||||
|
PrintCountReply reply {};
|
||||||
|
reply.total_count = total_count;
|
||||||
|
reply.ribbon_remaining = RIBBON_REMAINING;
|
||||||
|
size = sizeof(reply);
|
||||||
|
std::memcpy(data.data(), &reply, size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case INFO_HOLO_REMAINING: {
|
||||||
|
HoloRemainingReply reply {};
|
||||||
|
reply.remaining = RIBBON_REMAINING;
|
||||||
|
size = sizeof(reply);
|
||||||
|
std::memcpy(data.data(), &reply, size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case INFO_MEMORY: {
|
||||||
|
MemoryReply reply {};
|
||||||
|
reply.remaining = job.remaining;
|
||||||
|
reply.completed = static_cast<uint16_t>(job.copies - job.remaining);
|
||||||
|
reply.copies = job.copies;
|
||||||
|
size = sizeof(reply);
|
||||||
|
std::memcpy(data.data(), &reply, size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log_warning("cardconnect::printer", "unsupported printer info tag {}", tag);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check capacity before writing.
|
||||||
|
if (!buffer || !length || *length < size) {
|
||||||
|
log_warning("cardconnect::printer", "invalid buffer for printer info tag {}", tag);
|
||||||
|
if (length) {
|
||||||
|
*length = size;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
std::memcpy(buffer, data.data(), size);
|
||||||
|
*length = size;
|
||||||
|
|
||||||
|
// CoMain needs its post-cleanup baseline before any copy finishes.
|
||||||
|
if (tag == INFO_PRINT_COUNT && job.awaiting_counter_baseline) {
|
||||||
|
job.awaiting_counter_baseline = false;
|
||||||
|
job.next_copy = std::chrono::steady_clock::now() + job.print_time;
|
||||||
|
log_info("cardconnect::printer",
|
||||||
|
"job {}: counter baseline={}, starting print timer ({}s per copy)",
|
||||||
|
job.id, total_count, job.print_time.count());
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Paper and coating settings do not alter saved RGB data.
|
||||||
|
static BOOL __stdcall chcusb_setPrinterInfo(
|
||||||
|
uint16_t tag, const void *buffer, uint16_t *length, uint16_t *result) {
|
||||||
|
uint16_t expected = 0;
|
||||||
|
switch (tag) {
|
||||||
|
case INFO_PAPER:
|
||||||
|
expected = 10;
|
||||||
|
break;
|
||||||
|
case INFO_FRONT_MODE:
|
||||||
|
case INFO_BACK_MODE:
|
||||||
|
case INFO_IR_CORRECTION:
|
||||||
|
// The managed caller sends one byte, not two.
|
||||||
|
expected = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!expected || !buffer || !length || *length != expected) {
|
||||||
|
log_warning("cardconnect::printer",
|
||||||
|
"setPrinterInfo: tag={}, length={}, expected={}, buffer={}, length pointer={}",
|
||||||
|
tag, length ? *length : 0, expected, buffer != nullptr, length != nullptr);
|
||||||
|
return invalid_parameter(result, "setPrinterInfo");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PRINTER_SIMULATE_DELAY && (tag == INFO_FRONT_MODE || tag == INFO_BACK_MODE)) {
|
||||||
|
const auto mode = *static_cast<const uint8_t *>(buffer);
|
||||||
|
const auto delay = get_mode_delay(mode);
|
||||||
|
if (!delay) {
|
||||||
|
log_warning("cardconnect::printer", "cannot estimate delay for print mode {}", mode);
|
||||||
|
return invalid_parameter(result, "setPrinterInfo print mode");
|
||||||
|
}
|
||||||
|
if (!result) {
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
if (tag == INFO_FRONT_MODE) {
|
||||||
|
job.mode_delays[0] = *delay;
|
||||||
|
} else {
|
||||||
|
job.mode_delays[1] = *delay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure the next job.
|
||||||
|
static BOOL __stdcall chcusb_imageformat(
|
||||||
|
uint16_t format, uint16_t components, uint16_t depth,
|
||||||
|
uint16_t width, uint16_t height, uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
update_printing();
|
||||||
|
|
||||||
|
if ((format != FORMAT_RGB && format != FORMAT_BGR) ||
|
||||||
|
components != COLOR_COMPONENTS || depth != COLOR_DEPTH ||
|
||||||
|
width != CARD_WIDTH || height != CARD_HEIGHT || job.receiving || job.remaining) {
|
||||||
|
return invalid_parameter(result, "imageformat");
|
||||||
|
}
|
||||||
|
|
||||||
|
job.width = width;
|
||||||
|
job.height = height;
|
||||||
|
job.format = format;
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL __stdcall chcusb_copies(uint16_t copies, uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
update_printing();
|
||||||
|
|
||||||
|
if (!copies || job.receiving || job.remaining) {
|
||||||
|
return invalid_parameter(result, "copies");
|
||||||
|
}
|
||||||
|
|
||||||
|
job.copies = copies;
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Receive front and back image data.
|
||||||
|
static BOOL __stdcall chcusb_startpage(uint16_t mode, uint16_t *page_id, uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
update_printing();
|
||||||
|
|
||||||
|
if (job.receiving || job.remaining) {
|
||||||
|
log_warning("cardconnect::printer", "startpage while printer is busy");
|
||||||
|
return set_result(result, BUSY);
|
||||||
|
}
|
||||||
|
if (mode != 0 || !page_id || !result || !job.width || !job.height) {
|
||||||
|
return invalid_parameter(result, "startpage");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep zero reserved for "no job".
|
||||||
|
if (++next_page_id == 0) {
|
||||||
|
++next_page_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
job.id = next_page_id;
|
||||||
|
job.print_time = PRINT_TIME;
|
||||||
|
if (PRINTER_SIMULATE_DELAY) {
|
||||||
|
job.print_time = std::chrono::seconds(73) + job.mode_delays[0] + job.mode_delays[1];
|
||||||
|
}
|
||||||
|
job.error = READY;
|
||||||
|
job.receiving = true;
|
||||||
|
job.sides = {};
|
||||||
|
*page_id = job.id;
|
||||||
|
log_info("cardconnect::printer", "receiving job {} ({} copies)", job.id, job.copies);
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL __stdcall chcusb_write(
|
||||||
|
const uint8_t *data, uint32_t *size, uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
const size_t expected = static_cast<size_t>(job.width) * job.height * COLOR_COMPONENTS;
|
||||||
|
|
||||||
|
if (!job.receiving || !data || !size || !result || !*size) {
|
||||||
|
return invalid_parameter(result, "write");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill the front before accepting the back.
|
||||||
|
auto &side = job.sides[job.sides[0].size() == expected ? 1 : 0];
|
||||||
|
if (*size > expected - side.size()) {
|
||||||
|
return invalid_parameter(result, "write size");
|
||||||
|
}
|
||||||
|
side.insert(side.end(), data, data + *size);
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accept coating masks without saving them.
|
||||||
|
static BOOL __stdcall discard_mask(
|
||||||
|
const uint8_t *data, uint32_t *size, uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
if (!job.receiving || !data || !size ||
|
||||||
|
*size != static_cast<uint32_t>(job.width) * job.height) {
|
||||||
|
return invalid_parameter(result, "mask write");
|
||||||
|
}
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL __stdcall chcusb_endpage(uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
const size_t expected = static_cast<size_t>(job.width) * job.height * COLOR_COMPONENTS;
|
||||||
|
|
||||||
|
// Both sides must be complete.
|
||||||
|
if (!result || !job.receiving ||
|
||||||
|
job.sides[0].size() != expected || job.sides[1].size() != expected) {
|
||||||
|
return invalid_parameter(result, "endpage");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Image files use RGB channel order.
|
||||||
|
if (job.format == FORMAT_BGR) {
|
||||||
|
for (auto &side : job.sides) {
|
||||||
|
for (size_t i = 0; i < side.size(); i += COLOR_COMPONENTS) {
|
||||||
|
std::swap(side[i], side[i + 2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save every copy before reporting success.
|
||||||
|
job.receiving = false;
|
||||||
|
for (uint16_t i = 0; i < job.copies; ++i) {
|
||||||
|
if (!games::shared::printer_write_images({
|
||||||
|
{job.sides[0].data(), job.width, job.height, COLOR_COMPONENTS, "_front"},
|
||||||
|
{job.sides[1].data(), job.width, job.height, COLOR_COMPONENTS, "_back"}})) {
|
||||||
|
job.error = OUTPUT_ERROR;
|
||||||
|
job.sides = {};
|
||||||
|
log_warning("cardconnect::printer", "failed to save job {}", job.id);
|
||||||
|
return set_result(result, job.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the game's counter baseline.
|
||||||
|
job.sides = {};
|
||||||
|
job.remaining = job.copies;
|
||||||
|
job.awaiting_counter_baseline = true;
|
||||||
|
log_info("cardconnect::printer", "submitted job {}, waiting for counter baseline", job.id);
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Job progress and cancellation.
|
||||||
|
static BOOL __stdcall chcusb_getPrintIDStatus(
|
||||||
|
uint16_t page_id, void *buffer, uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
const auto status = poll_status();
|
||||||
|
|
||||||
|
if (!buffer || page_id != job.id) {
|
||||||
|
return invalid_parameter(result, "getPrintIDStatus");
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintIDReply reply {};
|
||||||
|
reply.remaining = job.remaining;
|
||||||
|
reply.status = status;
|
||||||
|
std::memcpy(buffer, &reply, sizeof(reply));
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL __stdcall chcusb_cancelCopies(uint16_t page_id, uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
if (page_id != job.id) {
|
||||||
|
return invalid_parameter(result, "cancelCopies");
|
||||||
|
}
|
||||||
|
|
||||||
|
update_printing();
|
||||||
|
job.remaining = 0;
|
||||||
|
job.receiving = false;
|
||||||
|
job.awaiting_counter_baseline = false;
|
||||||
|
job.sides = {};
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL __stdcall chcusb_resetPrinter(uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
update_printing();
|
||||||
|
job = {};
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Physical-printer controls.
|
||||||
|
static BOOL __stdcall chcusb_setIcctable(
|
||||||
|
[[maybe_unused]] const char *input_profile,
|
||||||
|
[[maybe_unused]] const char *output_profile,
|
||||||
|
[[maybe_unused]] uint16_t rendering_intents,
|
||||||
|
[[maybe_unused]] const void *input_tone_r,
|
||||||
|
[[maybe_unused]] const void *input_tone_g,
|
||||||
|
[[maybe_unused]] const void *input_tone_b,
|
||||||
|
[[maybe_unused]] const void *output_tone_r,
|
||||||
|
[[maybe_unused]] const void *output_tone_g,
|
||||||
|
[[maybe_unused]] const void *output_tone_b,
|
||||||
|
uint16_t *result) {
|
||||||
|
// Keep the original RGB colors.
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __stdcall chcusb_setCutterOffset(uint32_t offset, uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
cutter_offset = offset;
|
||||||
|
set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL __stdcall chcusb_getCutterOffset(uint32_t *offset, uint16_t *result) {
|
||||||
|
std::lock_guard lock(printer_mutex);
|
||||||
|
if (!offset) {
|
||||||
|
return invalid_parameter(result, "getCutterOffset");
|
||||||
|
}
|
||||||
|
*offset = cutter_offset;
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL __stdcall chcusb_getErrorLog(uint16_t index, void *buffer, uint16_t *result) {
|
||||||
|
if (!buffer || index != 0) {
|
||||||
|
return invalid_parameter(result, "getErrorLog");
|
||||||
|
}
|
||||||
|
std::memset(buffer, 0, 16);
|
||||||
|
return set_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static void hook(const char *name, T function) {
|
||||||
|
T original = nullptr;
|
||||||
|
detour::trampoline("C320Dusb.dll", name, function, &original);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printer_attach() {
|
||||||
|
if (PRINTER_DISABLED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_info("cardconnect::printer", "enabling C320D printer emulation");
|
||||||
|
games::shared::printer_init_output({"_front", "_back"});
|
||||||
|
libutils::load_library("game\\tcs_data\\Plugins\\C320Dusb.dll");
|
||||||
|
|
||||||
|
// Connections and status.
|
||||||
|
hook("chcusb_MakeThread", chcusb_MakeThread);
|
||||||
|
hook("chcusb_open", chcusb_open);
|
||||||
|
hook("chcusb_close", chcusb_close);
|
||||||
|
hook("chcusb_ReleaseThread", chcusb_ReleaseThread);
|
||||||
|
hook("chcusb_status", chcusb_status);
|
||||||
|
hook("chcusb_getPrinterInfo", chcusb_getPrinterInfo);
|
||||||
|
hook("chcusb_setPrinterInfo", chcusb_setPrinterInfo);
|
||||||
|
|
||||||
|
// Job setup and image transfer.
|
||||||
|
hook("chcusb_imageformat", chcusb_imageformat);
|
||||||
|
hook("chcusb_copies", chcusb_copies);
|
||||||
|
hook("chcusb_startpage", chcusb_startpage);
|
||||||
|
hook("chcusb_write", chcusb_write);
|
||||||
|
hook("chcusb_writeLaminate", discard_mask);
|
||||||
|
hook("chcusb_writeHolo", discard_mask);
|
||||||
|
hook("chcusb_writeIred", discard_mask);
|
||||||
|
hook("chcusb_endpage", chcusb_endpage);
|
||||||
|
|
||||||
|
// Completion and device controls.
|
||||||
|
hook("chcusb_getPrintIDStatus", chcusb_getPrintIDStatus);
|
||||||
|
hook("chcusb_cancelCopies", chcusb_cancelCopies);
|
||||||
|
hook("chcusb_resetPrinter", chcusb_resetPrinter);
|
||||||
|
hook("chcusb_setIcctable", chcusb_setIcctable);
|
||||||
|
hook("chcusb_setCutterOffset", chcusb_setCutterOffset);
|
||||||
|
hook("chcusb_getCutterOffset", chcusb_getCutterOffset);
|
||||||
|
hook("chcusb_getErrorLog", chcusb_getErrorLog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
namespace games::cardconnect {
|
||||||
|
bool PRINTER_DISABLED = false;
|
||||||
|
bool PRINTER_SIMULATE_DELAY = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace games::cardconnect {
|
||||||
|
extern bool PRINTER_DISABLED;
|
||||||
|
extern bool PRINTER_SIMULATE_DELAY;
|
||||||
|
void printer_attach();
|
||||||
|
}
|
||||||
@@ -199,11 +199,11 @@ namespace games::iidx {
|
|||||||
addr_camera_manager = (addr_camera_manager_ptr - (uint8_t*) iidx_module) + disp_camera_manager + 7;
|
addr_camera_manager = (addr_camera_manager_ptr - (uint8_t*) iidx_module) + disp_camera_manager + 7;
|
||||||
|
|
||||||
// addr_device_offset
|
// addr_device_offset
|
||||||
search_from = (addr_hook_a_ptr - (uint8_t*) iidx_module);
|
search_from = addr_hook_a;
|
||||||
uint8_t *addr_device_ptr = reinterpret_cast<uint8_t *>(find_pattern_from(
|
uint8_t *addr_device_ptr = reinterpret_cast<uint8_t *>(find_pattern_from(
|
||||||
iidx_module,
|
iidx_module,
|
||||||
"488B89",
|
"488B8F00000000488B014C8B870000000033D2FF9028010000",
|
||||||
"XXX",
|
"XXX????XXXXXX????XXXXXXXX",
|
||||||
3, 0, search_from));
|
3, 0, search_from));
|
||||||
|
|
||||||
if (addr_device_ptr == nullptr) {
|
if (addr_device_ptr == nullptr) {
|
||||||
@@ -211,7 +211,7 @@ namespace games::iidx {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr_device_offset = *addr_device_ptr;
|
addr_device_offset = *reinterpret_cast<uint32_t*>(addr_device_ptr);
|
||||||
|
|
||||||
// --- addr_afp_texture_offset ---
|
// --- addr_afp_texture_offset ---
|
||||||
uint8_t *addr_afp_texture_ptr = reinterpret_cast<uint8_t *>(find_pattern(
|
uint8_t *addr_afp_texture_ptr = reinterpret_cast<uint8_t *>(find_pattern(
|
||||||
@@ -233,13 +233,27 @@ namespace games::iidx {
|
|||||||
static void **__fastcall camera_hook_a(PBYTE a1) {
|
static void **__fastcall camera_hook_a(PBYTE a1) {
|
||||||
std::call_once(hook_a_init, [&]{
|
std::call_once(hook_a_init, [&]{
|
||||||
device = *reinterpret_cast<LPDIRECT3DDEVICE9EX*>(a1 + addr_device_offset);
|
device = *reinterpret_cast<LPDIRECT3DDEVICE9EX*>(a1 + addr_device_offset);
|
||||||
auto const preview = *reinterpret_cast<LPDIRECT3DTEXTURE9**>((uint8_t*)iidx_module + addr_textures);
|
auto const registry = reinterpret_cast<Camera::TextureRegistry*>(
|
||||||
|
reinterpret_cast<uint8_t*>(iidx_module) + addr_textures - offsetof(Camera::TextureRegistry, begin));
|
||||||
auto const manager = reinterpret_cast<Camera::CCameraManager2*>((uint8_t*)iidx_module + addr_camera_manager);
|
auto const manager = reinterpret_cast<Camera::CCameraManager2*>((uint8_t*)iidx_module + addr_camera_manager);
|
||||||
|
|
||||||
camera_texture_a = manager->cameras->a->d3d9_texture(addr_afp_texture_offset);
|
auto const camera_count = manager->begin ? manager->end - manager->begin : 0;
|
||||||
camera_texture_b = manager->cameras->b->d3d9_texture(addr_afp_texture_offset);
|
auto const bind_camera = [&](size_t index, LPDIRECT3DTEXTURE9*& texture, LPDIRECT3DTEXTURE9*& preview) {
|
||||||
preview_texture_a = preview;
|
if (index >= static_cast<size_t>(camera_count)) {
|
||||||
preview_texture_b = preview + 2;
|
return; // IIDX 34 only has the TOP camera.
|
||||||
|
}
|
||||||
|
auto const camera = manager->begin[index];
|
||||||
|
auto const afp = camera ? camera->afp_texture(addr_afp_texture_offset) : nullptr;
|
||||||
|
if (!afp || !registry->begin || afp->handle < registry->handle_base ||
|
||||||
|
afp->handle - registry->handle_base >= registry->end - registry->begin) {
|
||||||
|
log_warning("iidx:camhook", "invalid texture destination for camera {}", index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
texture = &afp->texture;
|
||||||
|
preview = registry->begin + (afp->handle - registry->handle_base);
|
||||||
|
};
|
||||||
|
bind_camera(0, camera_texture_a, preview_texture_a);
|
||||||
|
bind_camera(1, camera_texture_b, preview_texture_b);
|
||||||
|
|
||||||
init_local_camera();
|
init_local_camera();
|
||||||
});
|
});
|
||||||
@@ -381,10 +395,10 @@ namespace games::iidx {
|
|||||||
log_misc("iidx:camhook", "Adding user-preferred cameras");
|
log_misc("iidx:camhook", "Adding user-preferred cameras");
|
||||||
for (size_t i = 0; i < numDevices && LOCAL_CAMERA_LIST.size() < 2; i++) {
|
for (size_t i = 0; i < numDevices && LOCAL_CAMERA_LIST.size() < 2; i++) {
|
||||||
auto pActivate = ppDevices[i];
|
auto pActivate = ppDevices[i];
|
||||||
if ((int)i == preferred_top_index && top_camera == nullptr) {
|
if ((int)i == preferred_top_index && top_camera == nullptr && camera_texture_a != nullptr) {
|
||||||
log_misc("iidx:camhook", "Adding user-preferred top camera {} / '{}'", i, top_camera_id);
|
log_misc("iidx:camhook", "Adding user-preferred top camera {} / '{}'", i, top_camera_id);
|
||||||
top_camera = add_top_camera(pActivate);
|
top_camera = add_top_camera(pActivate);
|
||||||
} else if ((int)i == preferred_front_index && front_camera == nullptr) {
|
} else if ((int)i == preferred_front_index && front_camera == nullptr && camera_texture_b != nullptr) {
|
||||||
log_misc("iidx:camhook", "Adding user-preferred front camera {} / '{}'", i, front_camera_id);
|
log_misc("iidx:camhook", "Adding user-preferred front camera {} / '{}'", i, front_camera_id);
|
||||||
front_camera = add_front_camera(pActivate);
|
front_camera = add_front_camera(pActivate);
|
||||||
}
|
}
|
||||||
@@ -402,16 +416,16 @@ namespace games::iidx {
|
|||||||
|
|
||||||
if (!FLIP_CAMS) {
|
if (!FLIP_CAMS) {
|
||||||
// top camera first, then front
|
// top camera first, then front
|
||||||
if (top_camera == nullptr) {
|
if (top_camera == nullptr && camera_texture_a != nullptr) {
|
||||||
top_camera = add_top_camera(pActivate);
|
top_camera = add_top_camera(pActivate);
|
||||||
} else if (front_camera == nullptr) {
|
} else if (front_camera == nullptr && camera_texture_b != nullptr) {
|
||||||
front_camera = add_front_camera(pActivate);
|
front_camera = add_front_camera(pActivate);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// front first, then top
|
// front first, then top
|
||||||
if (front_camera == nullptr) {
|
if (front_camera == nullptr && camera_texture_b != nullptr) {
|
||||||
front_camera = add_front_camera(pActivate);
|
front_camera = add_front_camera(pActivate);
|
||||||
} else if (top_camera == nullptr) {
|
} else if (top_camera == nullptr && camera_texture_a != nullptr) {
|
||||||
top_camera = add_top_camera(pActivate);
|
top_camera = add_top_camera(pActivate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,21 +70,31 @@ namespace games::iidx {
|
|||||||
class IIDXCameraSourceReaderCallback;
|
class IIDXCameraSourceReaderCallback;
|
||||||
|
|
||||||
namespace Camera {
|
namespace Camera {
|
||||||
|
struct AfpTexture {
|
||||||
|
void* vftbl;
|
||||||
|
IDirect3DTexture9* texture;
|
||||||
|
uint32_t handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TextureRegistry {
|
||||||
|
uint32_t handle_base;
|
||||||
|
uint32_t next_slot;
|
||||||
|
IDirect3DTexture9** begin;
|
||||||
|
IDirect3DTexture9** end;
|
||||||
|
IDirect3DTexture9** capacity_end;
|
||||||
|
};
|
||||||
|
|
||||||
struct PlayVideoCamera {
|
struct PlayVideoCamera {
|
||||||
IDirect3DTexture9** d3d9_texture(const uintptr_t offset) {
|
AfpTexture* afp_texture(const uintptr_t offset) {
|
||||||
auto const afp_texture = *reinterpret_cast<uint8_t**>
|
return *reinterpret_cast<AfpTexture**>(reinterpret_cast<uint8_t*>(this) + offset);
|
||||||
(reinterpret_cast<uint8_t*>(this) + offset);
|
|
||||||
return reinterpret_cast<IDirect3DTexture9**>(afp_texture + 0x8);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CCameraManager2 {
|
struct CCameraManager2 {
|
||||||
using camera_pointers = struct {
|
|
||||||
PlayVideoCamera* a;
|
|
||||||
PlayVideoCamera* b;
|
|
||||||
};
|
|
||||||
void* vftbl;
|
void* vftbl;
|
||||||
camera_pointers* cameras;
|
PlayVideoCamera** begin;
|
||||||
|
PlayVideoCamera** end;
|
||||||
|
PlayVideoCamera** capacity_end;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
#include "qks/io.h"
|
#include "qks/io.h"
|
||||||
#include "mfg/io.h"
|
#include "mfg/io.h"
|
||||||
#include "pc/io.h"
|
#include "pc/io.h"
|
||||||
|
#include "udn/io.h"
|
||||||
|
#include "cardconnect/io.h"
|
||||||
|
|
||||||
namespace games {
|
namespace games {
|
||||||
|
|
||||||
@@ -299,6 +301,7 @@ namespace games {
|
|||||||
buttons.insert({ bc, bc::get_buttons() });
|
buttons.insert({ bc, bc::get_buttons() });
|
||||||
buttons_help.insert({ bc, bc::get_buttons_help() });
|
buttons_help.insert({ bc, bc::get_buttons_help() });
|
||||||
analogs.insert({ bc, bc::get_analogs() });
|
analogs.insert({ bc, bc::get_analogs() });
|
||||||
|
lights.insert({ bc, bc::get_lights() });
|
||||||
file_hints[bc].push_back({"game/bsac_app.exe"});
|
file_hints[bc].push_back({"game/bsac_app.exe"});
|
||||||
|
|
||||||
// ccj
|
// ccj
|
||||||
@@ -332,6 +335,21 @@ namespace games {
|
|||||||
analogs.insert({ pc, pc::get_analogs() });
|
analogs.insert({ pc, pc::get_analogs() });
|
||||||
lights.insert({ pc, pc::get_lights() });
|
lights.insert({ pc, pc::get_lights() });
|
||||||
file_hints[pc].push_back({"game/svm.exe"});
|
file_hints[pc].push_back({"game/svm.exe"});
|
||||||
|
|
||||||
|
// DANCE aROUND
|
||||||
|
const std::string udn("DANCE aROUND");
|
||||||
|
games.push_back(udn);
|
||||||
|
buttons.insert({ udn, udn::get_buttons() });
|
||||||
|
buttons_help.insert({ udn, udn::get_buttons_help() });
|
||||||
|
lights.insert({ udn, udn::get_lights() });
|
||||||
|
file_hints[udn].push_back({"game/dancearound_Data"});
|
||||||
|
|
||||||
|
// Card Connect
|
||||||
|
const std::string cardconnect("Card Connect");
|
||||||
|
games.push_back(cardconnect);
|
||||||
|
buttons.insert({ cardconnect, cardconnect::get_buttons() });
|
||||||
|
lights.insert({ cardconnect, cardconnect::get_lights() });
|
||||||
|
file_hints[cardconnect].push_back({"game/tcs.exe"});
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::string> &get_games() {
|
const std::vector<std::string> &get_games() {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "hooks/devicehook.h"
|
#include "hooks/devicehook.h"
|
||||||
#include "hooks/libraryhook.h"
|
#include "hooks/libraryhook.h"
|
||||||
#ifdef SPICE64
|
#ifdef SPICE64
|
||||||
|
#include <psapi.h>
|
||||||
#include "hooks/graphics/nvapi_impl.h"
|
#include "hooks/graphics/nvapi_impl.h"
|
||||||
#endif
|
#endif
|
||||||
#include "hooks/graphics/nvapi_hook.h"
|
#include "hooks/graphics/nvapi_hook.h"
|
||||||
@@ -40,6 +41,9 @@ static decltype(RegEnumKeyA) *RegEnumKeyA_orig = nullptr;
|
|||||||
static decltype(RegOpenKeyA) *RegOpenKeyA_orig = nullptr;
|
static decltype(RegOpenKeyA) *RegOpenKeyA_orig = nullptr;
|
||||||
static decltype(RegOpenKeyExA) *RegOpenKeyExA_orig = nullptr;
|
static decltype(RegOpenKeyExA) *RegOpenKeyExA_orig = nullptr;
|
||||||
static decltype(RegQueryValueExA) *RegQueryValueExA_orig = nullptr;
|
static decltype(RegQueryValueExA) *RegQueryValueExA_orig = nullptr;
|
||||||
|
#ifdef SPICE64
|
||||||
|
static decltype(K32GetPerformanceInfo) *K32GetPerformanceInfo_orig = nullptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace games::sdvx {
|
namespace games::sdvx {
|
||||||
|
|
||||||
@@ -200,6 +204,29 @@ namespace games::sdvx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SPICE64
|
#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 PERFORMANCE_INFORMATION cached {};
|
||||||
|
static const BOOL cached_valid = K32GetPerformanceInfo_orig(&cached, sizeof(cached));
|
||||||
|
if (!cached_valid) {
|
||||||
|
return K32GetPerformanceInfo_orig(info, cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
static bool sdvx64_spam_remover(void *user, const std::string &data, logger::Style style, std::string &out) {
|
||||||
if (data.empty() || data[0] != '[') {
|
if (data.empty() || data[0] != '[') {
|
||||||
return false;
|
return false;
|
||||||
@@ -534,6 +561,14 @@ namespace games::sdvx {
|
|||||||
if (is_valkyrie_model()) {
|
if (is_valkyrie_model()) {
|
||||||
sysutils::hook_EnumDisplayDevicesA();
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
#include "avs/game.h"
|
#include "avs/game.h"
|
||||||
#include "hooks/sleephook.h"
|
#include "hooks/sleephook.h"
|
||||||
@@ -264,7 +265,9 @@ namespace games::shared {
|
|||||||
|
|
||||||
typedef void (CALLBACK *PFNACBfunc)(DWORD dwErr, short PrintFlag, short PrintUsbNo, long nJid, int CopyNumber);
|
typedef void (CALLBACK *PFNACBfunc)(DWORD dwErr, short PrintFlag, short PrintUsbNo, long nJid, int CopyNumber);
|
||||||
|
|
||||||
static inline std::string get_image_out_path(bool clear, std::string path, const std::string &format) {
|
static std::vector<std::string> get_image_out_paths(
|
||||||
|
bool clear, std::string path, const std::string &format,
|
||||||
|
const std::vector<std::string> &suffixes, bool overwrite = false) {
|
||||||
|
|
||||||
// check path
|
// check path
|
||||||
if (path.empty()) {
|
if (path.empty()) {
|
||||||
@@ -277,28 +280,99 @@ namespace games::shared {
|
|||||||
path = std::string(path.c_str(), path.length() - 1);
|
path = std::string(path.c_str(), path.length() - 1);
|
||||||
|
|
||||||
// find non-existing filename
|
// find non-existing filename
|
||||||
static std::string prefix = "printer_";
|
|
||||||
for (int n = 0; n < 4096; n++) {
|
for (int n = 0; n < 4096; n++) {
|
||||||
std::ostringstream filename_s;
|
std::vector<std::string> filenames;
|
||||||
filename_s << path << "\\" << prefix << n << "." << format;
|
bool exists = false;
|
||||||
std::string filename = filename_s.str();
|
for (const auto &suffix : suffixes) {
|
||||||
if (clear && fileutils::file_exists(filename.c_str())) {
|
auto filename = fmt::format("{}\\printer_{}{}.{}", path, n, suffix, format);
|
||||||
log_info("printer", "deleting {}...", filename);
|
if (fileutils::file_exists(filename.c_str())) {
|
||||||
DeleteFile(filename.c_str());
|
exists = true;
|
||||||
if (PRINTER_OVERWRITE_FILE) {
|
if (clear) {
|
||||||
return filename;
|
log_info("printer", "deleting {}...", filename);
|
||||||
|
if (!DeleteFileA(filename.c_str())) {
|
||||||
|
log_warning("printer", "could not delete {}: {}", filename, GetLastError());
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filenames.push_back(std::move(filename));
|
||||||
|
}
|
||||||
|
if ((!clear && !exists) || overwrite) {
|
||||||
|
return filenames;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!clear) {
|
||||||
|
log_warning("printer", "could not find an unused printer output filename");
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool printer_write_image(const uint8_t *data, int width, int height, int components,
|
||||||
|
const std::string &suffix) {
|
||||||
|
return printer_write_images({{data, width, height, components, suffix}});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool printer_write_images(std::initializer_list<PrinterImage> images) {
|
||||||
|
if (images.size() == 0 || PRINTER_PATH.empty() || PRINTER_FORMAT.empty()) {
|
||||||
|
log_warning("printer", "printer output is uninitialized or contains no images");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::vector<std::string> suffixes;
|
||||||
|
for (const auto &image : images) {
|
||||||
|
if (!image.data || image.width <= 0 || image.height <= 0 ||
|
||||||
|
(image.components != 1 && image.components != 3) ||
|
||||||
|
image.width > std::numeric_limits<int>::max() / image.components / image.height) {
|
||||||
|
log_warning("printer", "invalid image supplied for printer output");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
suffixes.push_back(image.suffix);
|
||||||
|
}
|
||||||
|
bool all_saved = true;
|
||||||
|
for (const auto &path : PRINTER_PATH) {
|
||||||
|
for (const auto &format : PRINTER_FORMAT) {
|
||||||
|
const auto image_paths = get_image_out_paths(
|
||||||
|
PRINTER_OVERWRITE_FILE, path, format, suffixes, PRINTER_OVERWRITE_FILE);
|
||||||
|
if (image_paths.size() != images.size()) {
|
||||||
|
log_warning("printer", "could not allocate printer output paths in {}", path);
|
||||||
|
all_saved = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
size_t index = 0;
|
||||||
|
for (const auto &image : images) {
|
||||||
|
const auto &image_path = image_paths[index++];
|
||||||
|
bool success = false;
|
||||||
|
if (format == "png") {
|
||||||
|
success = stbi_write_png(
|
||||||
|
image_path.c_str(), image.width, image.height, image.components,
|
||||||
|
image.data, image.width * image.components);
|
||||||
|
} else if (format == "bmp") {
|
||||||
|
success = stbi_write_bmp(image_path.c_str(), image.width, image.height,
|
||||||
|
image.components, image.data);
|
||||||
|
} else if (format == "tga") {
|
||||||
|
success = stbi_write_tga(image_path.c_str(), image.width, image.height,
|
||||||
|
image.components, image.data);
|
||||||
|
} else if (format == "jpg") {
|
||||||
|
success = stbi_write_jpg(
|
||||||
|
image_path.c_str(), image.width, image.height, image.components,
|
||||||
|
image.data, PRINTER_JPG_QUALITY);
|
||||||
|
}
|
||||||
|
if (success) {
|
||||||
|
log_info("printer", "printer emulation has written an image to {}", image_path);
|
||||||
|
overlay::notifications::add(
|
||||||
|
overlay::notifications::Severity::Success,
|
||||||
|
fmt::format("Printer: saved {}", fileutils::basename(image_path)));
|
||||||
|
} else {
|
||||||
|
all_saved = false;
|
||||||
|
log_warning("printer", "printer emulation failed to write image to {}", image_path);
|
||||||
|
overlay::notifications::add(
|
||||||
|
overlay::notifications::Severity::Error,
|
||||||
|
fmt::format("Printer: failed to write {}", fileutils::basename(image_path)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!fileutils::file_exists(filename.c_str()))
|
|
||||||
return filename;
|
|
||||||
}
|
}
|
||||||
|
return all_saved;
|
||||||
// error
|
|
||||||
if (!clear) {
|
|
||||||
log_fatal("printer", "could not find path");
|
|
||||||
}
|
|
||||||
|
|
||||||
return "DUMMY";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool process_image_print(const CPDBandImageParams *pBandImage) {
|
static inline bool process_image_print(const CPDBandImageParams *pBandImage) {
|
||||||
@@ -372,43 +446,8 @@ namespace games::shared {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate folders
|
// preserve the legacy caller's success behavior after reporting file errors
|
||||||
log_misc("printer", "writing files...");
|
printer_write_image(image_data, image_width, image_height, 3);
|
||||||
for (const auto &path : PRINTER_PATH) {
|
|
||||||
for (const auto &format : PRINTER_FORMAT) {
|
|
||||||
|
|
||||||
// get image path
|
|
||||||
std::string image_path = get_image_out_path(PRINTER_OVERWRITE_FILE, path, format);
|
|
||||||
bool success = false;
|
|
||||||
|
|
||||||
// call write function depending on format
|
|
||||||
if (format == "png" && stbi_write_png(
|
|
||||||
image_path.c_str(), image_width, image_height, 3, image_data, image_width * 3))
|
|
||||||
success = true;
|
|
||||||
if (format == "bmp" && stbi_write_bmp(
|
|
||||||
image_path.c_str(), image_width, image_height, 3, image_data))
|
|
||||||
success = true;
|
|
||||||
if (format == "tga" && stbi_write_tga(
|
|
||||||
image_path.c_str(), image_width, image_height, 3, image_data))
|
|
||||||
success = true;
|
|
||||||
if (format == "jpg" && stbi_write_jpg(
|
|
||||||
image_path.c_str(), image_width, image_height, 3, image_data, PRINTER_JPG_QUALITY))
|
|
||||||
success = true;
|
|
||||||
|
|
||||||
// logging
|
|
||||||
if (success) {
|
|
||||||
log_info("printer", "printer emulation has written an image to {}", image_path);
|
|
||||||
overlay::notifications::add(
|
|
||||||
overlay::notifications::Severity::Success,
|
|
||||||
fmt::format("Printer: saved {}", fileutils::basename(image_path)));
|
|
||||||
} else {
|
|
||||||
log_warning("printer", "printer emulation failed to write image to {}", image_path);
|
|
||||||
overlay::notifications::add(
|
|
||||||
overlay::notifications::Severity::Error,
|
|
||||||
fmt::format("Printer: failed to write {}", fileutils::basename(image_path)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
delete[] image_data;
|
delete[] image_data;
|
||||||
@@ -555,9 +594,7 @@ namespace games::shared {
|
|||||||
log_info("printer", "CPUXInit called");
|
log_info("printer", "CPUXInit called");
|
||||||
}
|
}
|
||||||
|
|
||||||
void printer_attach() {
|
void printer_init_output(std::initializer_list<std::string> suffixes) {
|
||||||
log_info("printer", "SpiceTools Printer");
|
|
||||||
|
|
||||||
// default parameters
|
// default parameters
|
||||||
if (PRINTER_PATH.empty()) {
|
if (PRINTER_PATH.empty()) {
|
||||||
PRINTER_PATH.emplace_back(".");
|
PRINTER_PATH.emplace_back(".");
|
||||||
@@ -588,10 +625,15 @@ namespace games::shared {
|
|||||||
PRINTER_CLEAR = false;
|
PRINTER_CLEAR = false;
|
||||||
for (const auto &path : PRINTER_PATH) {
|
for (const auto &path : PRINTER_PATH) {
|
||||||
for (const auto &format : PRINTER_FORMAT) {
|
for (const auto &format : PRINTER_FORMAT) {
|
||||||
get_image_out_path(true, path, format);
|
get_image_out_paths(true, path, format, suffixes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void printer_attach() {
|
||||||
|
log_info("printer", "SpiceTools Printer");
|
||||||
|
printer_init_output();
|
||||||
|
|
||||||
// IAT hooks
|
// IAT hooks
|
||||||
detour::iat_try("CPU9CheckPaperRemain", CPU9CheckPaperRemain);
|
detour::iat_try("CPU9CheckPaperRemain", CPU9CheckPaperRemain);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
@@ -15,4 +17,16 @@ namespace games::shared {
|
|||||||
extern bool PRINTER_OVERWRITE_FILE;
|
extern bool PRINTER_OVERWRITE_FILE;
|
||||||
|
|
||||||
void printer_attach();
|
void printer_attach();
|
||||||
|
struct PrinterImage {
|
||||||
|
const uint8_t *data;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int components;
|
||||||
|
std::string suffix;
|
||||||
|
};
|
||||||
|
|
||||||
|
void printer_init_output(std::initializer_list<std::string> suffixes = {""});
|
||||||
|
bool printer_write_images(std::initializer_list<PrinterImage> images);
|
||||||
|
bool printer_write_image(const uint8_t *data, int width, int height, int components,
|
||||||
|
const std::string &suffix = "");
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,686 @@
|
|||||||
|
#include "bi2x_hook.h"
|
||||||
|
|
||||||
|
#if SPICE64
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#include "acio/icca/icca.h"
|
||||||
|
#include "games/io.h"
|
||||||
|
#include "io.h"
|
||||||
|
#include "misc/eamuse.h"
|
||||||
|
#include "rawinput/rawinput.h"
|
||||||
|
#include "util/execexe.h"
|
||||||
|
#include "util/logging.h"
|
||||||
|
#include "util/tapeled.h"
|
||||||
|
#include "util/utils.h"
|
||||||
|
|
||||||
|
namespace games::udn {
|
||||||
|
|
||||||
|
struct AIO_SCI_COMM {
|
||||||
|
uint8_t data[0xf8];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AIO_NMGR_IOB2 {
|
||||||
|
uint8_t data[0xe30];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AIO_IOB2_BI2X_UDN {
|
||||||
|
uint8_t data[0x3b00];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AIO_IOB2_BI2X_WRFIRM {
|
||||||
|
uint8_t data[0x20f48];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AIO_IOB_ICCA;
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
struct AIO_IOB2_BI2X_UDN__INPUT {
|
||||||
|
uint8_t DevIoCounter;
|
||||||
|
uint8_t bExIoAErr;
|
||||||
|
uint8_t bExIoBErr;
|
||||||
|
uint8_t bPcPowerOn;
|
||||||
|
uint8_t bPcPowerCheck;
|
||||||
|
uint8_t CoinCount;
|
||||||
|
uint8_t bTest;
|
||||||
|
uint8_t bService;
|
||||||
|
uint8_t bCoinSw;
|
||||||
|
uint8_t bCoinJam;
|
||||||
|
uint8_t bStart;
|
||||||
|
uint8_t bUp;
|
||||||
|
uint8_t bDown;
|
||||||
|
uint8_t bLeft;
|
||||||
|
uint8_t bRight;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AIO_IOB2_BI2X_UDN__DEVSTATUS {
|
||||||
|
uint8_t InputCounter;
|
||||||
|
uint8_t OutputCounter;
|
||||||
|
uint8_t TapeLedCounter;
|
||||||
|
uint8_t TapeLedRate[8];
|
||||||
|
AIO_IOB2_BI2X_UDN__INPUT Input;
|
||||||
|
uint8_t InputData[241];
|
||||||
|
uint8_t OutputData[48];
|
||||||
|
uint8_t IoResetData[4];
|
||||||
|
uint8_t PlyrInHist[18];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fixed card-status wire format used by the compatibility interface.
|
||||||
|
// The payload is exactly 58 bytes.
|
||||||
|
// Field widths remain explicit to keep the boundary stable.
|
||||||
|
struct AIO_IOB_ICCA__CARDID {
|
||||||
|
uint8_t CardType;
|
||||||
|
uint8_t cbCardId;
|
||||||
|
uint8_t CardId[10];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AIO_IOB_ICCA__INPUT {
|
||||||
|
uint8_t cuStatus;
|
||||||
|
uint8_t cuError;
|
||||||
|
AIO_IOB_ICCA__CARDID CardId;
|
||||||
|
uint8_t KeyNo;
|
||||||
|
uint8_t KeyCount;
|
||||||
|
uint8_t bKeyDataValid;
|
||||||
|
uint8_t Key2No;
|
||||||
|
uint8_t Key2Count;
|
||||||
|
uint8_t bKey2DataValid;
|
||||||
|
uint8_t bKey0;
|
||||||
|
uint8_t bKey1;
|
||||||
|
uint8_t bKey4;
|
||||||
|
uint8_t bKey7;
|
||||||
|
uint8_t bKey00;
|
||||||
|
uint8_t bKey2;
|
||||||
|
uint8_t bKey5;
|
||||||
|
uint8_t bKey8;
|
||||||
|
uint8_t bKeyBK;
|
||||||
|
uint8_t bKey3;
|
||||||
|
uint8_t bKey6;
|
||||||
|
uint8_t bKey9;
|
||||||
|
uint8_t CN1_1;
|
||||||
|
uint8_t CN1_2;
|
||||||
|
uint8_t CN1_3;
|
||||||
|
uint8_t CN1_4;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AIO_IOB_ICCA__DEVSTATUS {
|
||||||
|
uint8_t InputCounter;
|
||||||
|
uint8_t OutputCounter;
|
||||||
|
AIO_IOB_ICCA__INPUT Input;
|
||||||
|
uint8_t InputData[16];
|
||||||
|
uint8_t OutputData[4];
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
static_assert(sizeof(AIO_SCI_COMM) == 0xf8);
|
||||||
|
static_assert(sizeof(AIO_NMGR_IOB2) == 0xe30);
|
||||||
|
static_assert(sizeof(AIO_IOB2_BI2X_UDN) == 0x3b00);
|
||||||
|
static_assert(sizeof(AIO_IOB2_BI2X_WRFIRM) == 0x20f48);
|
||||||
|
static_assert(sizeof(AIO_IOB2_BI2X_UDN__INPUT) == 15);
|
||||||
|
static_assert(sizeof(AIO_IOB2_BI2X_UDN__DEVSTATUS) == 337);
|
||||||
|
static_assert(sizeof(AIO_IOB_ICCA__CARDID) == 12);
|
||||||
|
static_assert(sizeof(AIO_IOB_ICCA__INPUT) == 36);
|
||||||
|
static_assert(sizeof(AIO_IOB_ICCA__DEVSTATUS) == 58);
|
||||||
|
|
||||||
|
using aioIob2Bi2xUDN_Create_t = AIO_IOB2_BI2X_UDN *(__fastcall *)(AIO_NMGR_IOB2 *, uint32_t);
|
||||||
|
using aioIob2Bi2xUDN_GetDeviceStatus_t = uint32_t (__fastcall *)(
|
||||||
|
AIO_IOB2_BI2X_UDN *, AIO_IOB2_BI2X_UDN__DEVSTATUS *, uint32_t);
|
||||||
|
using aioIob2Bi2xAC1_GetDeviceStatus_t = uint32_t (__fastcall *)(void *, void *, uint32_t);
|
||||||
|
using aioIob2Bi2xUDN_IoReset_t = void (__fastcall *)(AIO_IOB2_BI2X_UDN *, uint32_t);
|
||||||
|
using aioIob2Bi2xUDN_SetWatchDogTimer_t = void (__fastcall *)(AIO_IOB2_BI2X_UDN *, uint8_t);
|
||||||
|
using aioIob2Bi2xUDN_ControlCoinBlocker_t = void (__fastcall *)(AIO_IOB2_BI2X_UDN *, uint32_t, bool);
|
||||||
|
using aioIob2Bi2xUDN_AddCounter_t = void (__fastcall *)(AIO_IOB2_BI2X_UDN *, uint32_t, uint32_t);
|
||||||
|
using aioIob2Bi2xUDN_SetStartLamp_t = void (__fastcall *)(AIO_IOB2_BI2X_UDN *, bool);
|
||||||
|
using aioIob2Bi2xUDN_SetPlayerButtonLamp_t = void (__fastcall *)(AIO_IOB2_BI2X_UDN *, uint32_t, bool);
|
||||||
|
using aioIob2Bi2xUDN_SetIccrLed_t = void (__fastcall *)(AIO_IOB2_BI2X_UDN *, uint32_t);
|
||||||
|
using aioIob2Bi2xUDN_SetTapeLedDataLimit_t = void (__fastcall *)(
|
||||||
|
AIO_IOB2_BI2X_UDN *, uint32_t, uint8_t, uint8_t);
|
||||||
|
using aioIob2Bi2xUDN_SetTapeLedData_t = void (__fastcall *)(AIO_IOB2_BI2X_UDN *, uint32_t, uint8_t *);
|
||||||
|
using aioIob2Bi2x_OpenSciUsbCdc_t = AIO_SCI_COMM *(__fastcall *)(uint32_t);
|
||||||
|
using aioIob2Bi2x_CreateWriteFirmContext_t = AIO_IOB2_BI2X_WRFIRM *(__fastcall *)(uint32_t, uint32_t);
|
||||||
|
using aioIob2Bi2x_DestroyWriteFirmContext_t = void (__fastcall *)(AIO_IOB2_BI2X_WRFIRM *);
|
||||||
|
using aioIob2Bi2x_WriteFirmGetState_t = int32_t (__fastcall *)(AIO_IOB2_BI2X_WRFIRM *);
|
||||||
|
|
||||||
|
using aioIobIcca_Create_t = AIO_IOB_ICCA *(__fastcall *)(void *, uint32_t, uint8_t);
|
||||||
|
using aioIobIcca_GetDeviceStatus_t = uint32_t (__fastcall *)(
|
||||||
|
AIO_IOB_ICCA *, AIO_IOB_ICCA__DEVSTATUS *, uint32_t);
|
||||||
|
using aioIobIcca_BeginGetCardId_t = void (__fastcall *)(AIO_IOB_ICCA *);
|
||||||
|
using aioIobIcca_EndGetCardId_t = void (__fastcall *)(AIO_IOB_ICCA *);
|
||||||
|
|
||||||
|
using aioNMgrIob2_Create_t = AIO_NMGR_IOB2 *(__fastcall *)(AIO_SCI_COMM *, uint32_t);
|
||||||
|
using aioNMgrIob_BeginManage_t = void (__fastcall *)(AIO_NMGR_IOB2 *);
|
||||||
|
|
||||||
|
using aioNodeMgr_Destroy_t = void (__fastcall *)(AIO_NMGR_IOB2 *);
|
||||||
|
using aioNodeMgr_GetState_t = int32_t (__fastcall *)(AIO_NMGR_IOB2 *);
|
||||||
|
using aioNodeMgr_IsReady_t = bool (__fastcall *)(AIO_NMGR_IOB2 *, int32_t);
|
||||||
|
using aioNodeCtl_Destroy_t = void (__fastcall *)(AIO_IOB2_BI2X_UDN *);
|
||||||
|
using aioNodeCtl_GetState_t = int32_t (__fastcall *)(AIO_IOB2_BI2X_UDN *);
|
||||||
|
using aioNodeCtl_IsReady_t = bool (__fastcall *)(AIO_IOB2_BI2X_UDN *, int32_t);
|
||||||
|
|
||||||
|
static aioIob2Bi2xUDN_Create_t aioIob2Bi2xUDN_Create_orig = nullptr;
|
||||||
|
static aioIob2Bi2xUDN_GetDeviceStatus_t aioIob2Bi2xUDN_GetDeviceStatus_orig = nullptr;
|
||||||
|
static aioIob2Bi2xAC1_GetDeviceStatus_t aioIob2Bi2xAC1_GetDeviceStatus_orig = nullptr;
|
||||||
|
static aioIob2Bi2xUDN_IoReset_t aioIob2Bi2xUDN_IoReset_orig = nullptr;
|
||||||
|
static aioIob2Bi2xUDN_SetWatchDogTimer_t aioIob2Bi2xUDN_SetWatchDogTimer_orig = nullptr;
|
||||||
|
static aioIob2Bi2xUDN_ControlCoinBlocker_t aioIob2Bi2xUDN_ControlCoinBlocker_orig = nullptr;
|
||||||
|
static aioIob2Bi2xUDN_AddCounter_t aioIob2Bi2xUDN_AddCounter_orig = nullptr;
|
||||||
|
static aioIob2Bi2xUDN_SetStartLamp_t aioIob2Bi2xUDN_SetStartLamp_orig = nullptr;
|
||||||
|
static aioIob2Bi2xUDN_SetPlayerButtonLamp_t aioIob2Bi2xUDN_SetPlayerButtonLamp_orig = nullptr;
|
||||||
|
static aioIob2Bi2xUDN_SetIccrLed_t aioIob2Bi2xUDN_SetIccrLed_orig = nullptr;
|
||||||
|
static aioIob2Bi2xUDN_SetTapeLedDataLimit_t aioIob2Bi2xUDN_SetTapeLedDataLimit_orig = nullptr;
|
||||||
|
static aioIob2Bi2xUDN_SetTapeLedData_t aioIob2Bi2xUDN_SetTapeLedData_orig = nullptr;
|
||||||
|
static aioIob2Bi2x_OpenSciUsbCdc_t aioIob2Bi2x_OpenSciUsbCdc_orig = nullptr;
|
||||||
|
static aioIob2Bi2x_CreateWriteFirmContext_t aioIob2Bi2x_CreateWriteFirmContext_orig = nullptr;
|
||||||
|
static aioIob2Bi2x_DestroyWriteFirmContext_t aioIob2Bi2x_DestroyWriteFirmContext_orig = nullptr;
|
||||||
|
static aioIob2Bi2x_WriteFirmGetState_t aioIob2Bi2x_WriteFirmGetState_orig = nullptr;
|
||||||
|
|
||||||
|
static aioIobIcca_Create_t aioIobIcca_Create_orig = nullptr;
|
||||||
|
static aioIobIcca_GetDeviceStatus_t aioIobIcca_GetDeviceStatus_orig = nullptr;
|
||||||
|
static aioIobIcca_BeginGetCardId_t aioIobIcca_BeginGetCardId_orig = nullptr;
|
||||||
|
static aioIobIcca_EndGetCardId_t aioIobIcca_EndGetCardId_orig = nullptr;
|
||||||
|
|
||||||
|
static aioNMgrIob2_Create_t aioNMgrIob2_Create_orig = nullptr;
|
||||||
|
static aioNMgrIob_BeginManage_t aioNMgrIob_BeginManage_orig = nullptr;
|
||||||
|
|
||||||
|
static aioNodeMgr_Destroy_t aioNodeMgr_Destroy_orig = nullptr;
|
||||||
|
static aioNodeMgr_GetState_t aioNodeMgr_GetState_orig = nullptr;
|
||||||
|
static aioNodeMgr_IsReady_t aioNodeMgr_IsReady_orig = nullptr;
|
||||||
|
static aioNodeCtl_Destroy_t aioNodeCtl_Destroy_orig = nullptr;
|
||||||
|
static aioNodeCtl_GetState_t aioNodeCtl_GetState_orig = nullptr;
|
||||||
|
static aioNodeCtl_IsReady_t aioNodeCtl_IsReady_orig = nullptr;
|
||||||
|
|
||||||
|
static std::unique_ptr<AIO_SCI_COMM> aio_sci_comm;
|
||||||
|
static std::unique_ptr<AIO_NMGR_IOB2> aio_node_manager;
|
||||||
|
static AIO_NMGR_IOB2 *aio_icca_node_manager = nullptr;
|
||||||
|
static std::unique_ptr<AIO_IOB2_BI2X_UDN> aio_udn;
|
||||||
|
static std::unique_ptr<AIO_IOB2_BI2X_WRFIRM> aio_write_firm;
|
||||||
|
static uint8_t input_counter = 0;
|
||||||
|
|
||||||
|
// Native ICCA status/begin/end operations also lock the reader state.
|
||||||
|
// The managed wrapper can destroy its node from a finalizer thread.
|
||||||
|
static std::mutex icca_mutex;
|
||||||
|
static AIO_IOB_ICCA *aio_icca = nullptr;
|
||||||
|
static bool icca_reading = false;
|
||||||
|
static bool icca_card_ready = false;
|
||||||
|
static uint8_t icca_card_uid[8] {};
|
||||||
|
static uint8_t icca_input_counter = 0;
|
||||||
|
|
||||||
|
static void write_light(Lights::udn_lights_t light, float value) {
|
||||||
|
auto &lights = get_lights();
|
||||||
|
GameAPI::Lights::writeLight(RI_MGR, lights.at(light), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static AIO_IOB2_BI2X_UDN *__fastcall aioIob2Bi2xUDN_Create(
|
||||||
|
AIO_NMGR_IOB2 *node_manager, uint32_t device_id) {
|
||||||
|
|
||||||
|
if (node_manager != aio_node_manager.get()) {
|
||||||
|
return aioIob2Bi2xUDN_Create_orig(node_manager, device_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!aio_udn) {
|
||||||
|
aio_udn = std::make_unique<AIO_IOB2_BI2X_UDN>();
|
||||||
|
log_info("udn_bi2x", "UDN node created");
|
||||||
|
}
|
||||||
|
return aio_udn.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t __fastcall aioIob2Bi2xAC1_GetDeviceStatus(
|
||||||
|
void *node, void *status, uint32_t status_size) {
|
||||||
|
|
||||||
|
// aioIob2Bi2xUDN.GetDeviceStatus() first invokes its managed AC1 base method.
|
||||||
|
if (node == aio_udn.get()) {
|
||||||
|
if (status && status_size > 0) {
|
||||||
|
std::memset(status, 0, status_size);
|
||||||
|
}
|
||||||
|
return status_size;
|
||||||
|
}
|
||||||
|
return aioIob2Bi2xAC1_GetDeviceStatus_orig(node, status, status_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t __fastcall aioIob2Bi2xUDN_GetDeviceStatus(
|
||||||
|
AIO_IOB2_BI2X_UDN *node, AIO_IOB2_BI2X_UDN__DEVSTATUS *status,
|
||||||
|
uint32_t status_size) {
|
||||||
|
|
||||||
|
if (node != aio_udn.get()) {
|
||||||
|
return aioIob2Bi2xUDN_GetDeviceStatus_orig(node, status, status_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
RI_MGR->devices_flush_output();
|
||||||
|
|
||||||
|
AIO_IOB2_BI2X_UDN__DEVSTATUS current {};
|
||||||
|
current.InputCounter = input_counter;
|
||||||
|
current.Input.DevIoCounter = input_counter++;
|
||||||
|
|
||||||
|
auto &buttons = get_buttons();
|
||||||
|
current.Input.bService = GameAPI::Buttons::getState(RI_MGR, buttons[Buttons::Service]) ? 1 : 0;
|
||||||
|
current.Input.bTest = GameAPI::Buttons::getState(RI_MGR, buttons[Buttons::Test]) ? 1 : 0;
|
||||||
|
current.Input.bCoinSw = GameAPI::Buttons::getState(RI_MGR, buttons[Buttons::CoinMech]) ? 1 : 0;
|
||||||
|
current.Input.bStart = GameAPI::Buttons::getState(RI_MGR, buttons[Buttons::Start]) ? 1 : 0;
|
||||||
|
current.Input.bUp = GameAPI::Buttons::getState(RI_MGR, buttons[Buttons::Up]) ? 1 : 0;
|
||||||
|
current.Input.bDown = GameAPI::Buttons::getState(RI_MGR, buttons[Buttons::Down]) ? 1 : 0;
|
||||||
|
current.Input.bLeft = GameAPI::Buttons::getState(RI_MGR, buttons[Buttons::Left]) ? 1 : 0;
|
||||||
|
current.Input.bRight = GameAPI::Buttons::getState(RI_MGR, buttons[Buttons::Right]) ? 1 : 0;
|
||||||
|
// The hardware counter wraps at 256; clamping it would stop accepting
|
||||||
|
// coins once the shared stock reaches 255.
|
||||||
|
current.Input.CoinCount = static_cast<uint8_t>(eamuse_coin_get_stock());
|
||||||
|
|
||||||
|
const auto copy_size = std::min<uint32_t>(status_size, sizeof(current));
|
||||||
|
if (status && copy_size > 0) {
|
||||||
|
std::memcpy(status, ¤t, copy_size);
|
||||||
|
}
|
||||||
|
return copy_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xUDN_IoReset(AIO_IOB2_BI2X_UDN *node, uint32_t reset_bits) {
|
||||||
|
if (node != aio_udn.get()) {
|
||||||
|
return aioIob2Bi2xUDN_IoReset_orig(node, reset_bits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xUDN_SetWatchDogTimer(AIO_IOB2_BI2X_UDN *node, uint8_t count) {
|
||||||
|
if (node != aio_udn.get()) {
|
||||||
|
return aioIob2Bi2xUDN_SetWatchDogTimer_orig(node, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xUDN_ControlCoinBlocker(
|
||||||
|
AIO_IOB2_BI2X_UDN *node, uint32_t slot, bool open) {
|
||||||
|
|
||||||
|
if (node != aio_udn.get()) {
|
||||||
|
return aioIob2Bi2xUDN_ControlCoinBlocker_orig(node, slot, open);
|
||||||
|
}
|
||||||
|
eamuse_coin_set_block(!open);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xUDN_AddCounter(
|
||||||
|
AIO_IOB2_BI2X_UDN *node, uint32_t counter, uint32_t count) {
|
||||||
|
|
||||||
|
if (node != aio_udn.get()) {
|
||||||
|
return aioIob2Bi2xUDN_AddCounter_orig(node, counter, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xUDN_SetStartLamp(AIO_IOB2_BI2X_UDN *node, bool on) {
|
||||||
|
if (node != aio_udn.get()) {
|
||||||
|
return aioIob2Bi2xUDN_SetStartLamp_orig(node, on);
|
||||||
|
}
|
||||||
|
write_light(Lights::Start, on ? 1.f : 0.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xUDN_SetPlayerButtonLamp(
|
||||||
|
AIO_IOB2_BI2X_UDN *node, uint32_t button, bool on) {
|
||||||
|
|
||||||
|
if (node != aio_udn.get()) {
|
||||||
|
return aioIob2Bi2xUDN_SetPlayerButtonLamp_orig(node, button, on);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const Lights::udn_lights_t mapping[] {
|
||||||
|
Lights::Start,
|
||||||
|
Lights::Up,
|
||||||
|
Lights::Down,
|
||||||
|
Lights::Left,
|
||||||
|
Lights::Right,
|
||||||
|
};
|
||||||
|
if (button < std::size(mapping)) {
|
||||||
|
write_light(mapping[button], on ? 1.f : 0.f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xUDN_SetIccrLed(AIO_IOB2_BI2X_UDN *node, uint32_t rgb) {
|
||||||
|
if (node != aio_udn.get()) {
|
||||||
|
return aioIob2Bi2xUDN_SetIccrLed_orig(node, rgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
write_light(Lights::CardReaderR, ((rgb >> 16) & 0xff) / 255.f);
|
||||||
|
write_light(Lights::CardReaderG, ((rgb >> 8) & 0xff) / 255.f);
|
||||||
|
write_light(Lights::CardReaderB, (rgb & 0xff) / 255.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xUDN_SetTapeLedDataLimit(
|
||||||
|
AIO_IOB2_BI2X_UDN *node, uint32_t channel, uint8_t scale, uint8_t limit) {
|
||||||
|
|
||||||
|
if (node != aio_udn.get()) {
|
||||||
|
return aioIob2Bi2xUDN_SetTapeLedDataLimit_orig(node, channel, scale, limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2xUDN_SetTapeLedData(
|
||||||
|
AIO_IOB2_BI2X_UDN *node, uint32_t tape, uint8_t *data) {
|
||||||
|
|
||||||
|
if (node != aio_udn.get()) {
|
||||||
|
return aioIob2Bi2xUDN_SetTapeLedData_orig(node, tape, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TapeMapping {
|
||||||
|
size_t color_count;
|
||||||
|
Lights::udn_lights_t r;
|
||||||
|
Lights::udn_lights_t g;
|
||||||
|
Lights::udn_lights_t b;
|
||||||
|
};
|
||||||
|
static const TapeMapping mapping[] {
|
||||||
|
{62, Lights::TitleR, Lights::TitleG, Lights::TitleB},
|
||||||
|
{152, Lights::PillarRightTopR, Lights::PillarRightTopG, Lights::PillarRightTopB},
|
||||||
|
{165, Lights::PillarRightBottomR, Lights::PillarRightBottomG, Lights::PillarRightBottomB},
|
||||||
|
{9, Lights::StageLeftR, Lights::StageLeftG, Lights::StageLeftB},
|
||||||
|
{17, Lights::CabinetLeftR, Lights::CabinetLeftG, Lights::CabinetLeftB},
|
||||||
|
{152, Lights::PillarLeftTopR, Lights::PillarLeftTopG, Lights::PillarLeftTopB},
|
||||||
|
{165, Lights::PillarLeftBottomR, Lights::PillarLeftBottomG, Lights::PillarLeftBottomB},
|
||||||
|
{9, Lights::StageRightR, Lights::StageRightG, Lights::StageRightB},
|
||||||
|
{17, Lights::CabinetRightR, Lights::CabinetRightG, Lights::CabinetRightB},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (data && tapeledutils::is_enabled() && tape < std::size(mapping)) {
|
||||||
|
const auto &entry = mapping[tape];
|
||||||
|
const auto color = tapeledutils::pick_color_from_led_tape(data, entry.color_count);
|
||||||
|
write_light(entry.r, color.r);
|
||||||
|
write_light(entry.g, color.g);
|
||||||
|
write_light(entry.b, color.b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static AIO_SCI_COMM *__fastcall aioIob2Bi2x_OpenSciUsbCdc(uint32_t serial_number) {
|
||||||
|
if (!aio_sci_comm) {
|
||||||
|
aio_sci_comm = std::make_unique<AIO_SCI_COMM>();
|
||||||
|
}
|
||||||
|
return aio_sci_comm.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
static AIO_IOB2_BI2X_WRFIRM *__fastcall aioIob2Bi2x_CreateWriteFirmContext(
|
||||||
|
uint32_t serial_number, uint32_t iob_mask) {
|
||||||
|
|
||||||
|
if (!aio_write_firm) {
|
||||||
|
aio_write_firm = std::make_unique<AIO_IOB2_BI2X_WRFIRM>();
|
||||||
|
}
|
||||||
|
return aio_write_firm.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIob2Bi2x_DestroyWriteFirmContext(AIO_IOB2_BI2X_WRFIRM *context) {
|
||||||
|
if (context != aio_write_firm.get()) {
|
||||||
|
return aioIob2Bi2x_DestroyWriteFirmContext_orig(context);
|
||||||
|
}
|
||||||
|
aio_write_firm.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t __fastcall aioIob2Bi2x_WriteFirmGetState(AIO_IOB2_BI2X_WRFIRM *context) {
|
||||||
|
if (context == aio_write_firm.get()) {
|
||||||
|
// The native state machine treats both 7 (NODEV) and 8
|
||||||
|
// (COMPLETED) as a successful terminal state. UDN additionally
|
||||||
|
// interprets state 8 as "firmware was written this boot" and
|
||||||
|
// deliberately powers the cabinet down after loading so the real
|
||||||
|
// I/O board can reboot. There is no physical BI2X board behind
|
||||||
|
// this emulation, so report NODEV: the check is complete without
|
||||||
|
// scheduling that otherwise endless firmware-update reboot.
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
return aioIob2Bi2x_WriteFirmGetState_orig(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
static AIO_IOB_ICCA *__fastcall aioIobIcca_Create(
|
||||||
|
void *node_manager, uint32_t device_id, uint8_t init_mode) {
|
||||||
|
|
||||||
|
auto *node = aioIobIcca_Create_orig(node_manager, device_id, init_mode);
|
||||||
|
if (node) {
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(icca_mutex);
|
||||||
|
aio_icca = node;
|
||||||
|
aio_icca_node_manager =
|
||||||
|
reinterpret_cast<AIO_NMGR_IOB2 *>(node_manager);
|
||||||
|
icca_reading = false;
|
||||||
|
icca_card_ready = false;
|
||||||
|
std::memset(icca_card_uid, 0, sizeof(icca_card_uid));
|
||||||
|
}
|
||||||
|
log_info("udn_bi2x", "ICCA node attached to Spice CardIO bridge");
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t __fastcall aioIobIcca_GetDeviceStatus(
|
||||||
|
AIO_IOB_ICCA *node, AIO_IOB_ICCA__DEVSTATUS *status, uint32_t status_size) {
|
||||||
|
|
||||||
|
std::unique_lock<std::mutex> lock(icca_mutex);
|
||||||
|
if (node != aio_icca) {
|
||||||
|
lock.unlock();
|
||||||
|
return aioIobIcca_GetDeviceStatus_orig(node, status, status_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
AIO_IOB_ICCA__DEVSTATUS current {};
|
||||||
|
current.InputCounter = icca_input_counter++;
|
||||||
|
current.OutputCounter = current.InputCounter;
|
||||||
|
|
||||||
|
// DNI while idle, BUSY while waiting for a card, READY once a UID is
|
||||||
|
// available. The card-reader state machine accepts a card only on READY.
|
||||||
|
current.Input.cuStatus = icca_reading ? 1 : 0;
|
||||||
|
if (icca_reading && !icca_card_ready && eamuse_card_insert_consume(1, 0)) {
|
||||||
|
uint8_t uid[8] {};
|
||||||
|
if (eamuse_get_card(1, 0, uid)) {
|
||||||
|
std::memcpy(icca_card_uid, uid, sizeof(icca_card_uid));
|
||||||
|
icca_card_ready = true;
|
||||||
|
log_info(
|
||||||
|
"udn_bi2x",
|
||||||
|
"ICCA accepted UID {} from the Spice card queue; reporting READY to Unity",
|
||||||
|
bin2hex(icca_card_uid, sizeof(icca_card_uid)));
|
||||||
|
} else {
|
||||||
|
log_warning(
|
||||||
|
"udn_bi2x",
|
||||||
|
"ICCA consumed a card-insert event but Spice returned no UID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (icca_card_ready) {
|
||||||
|
current.Input.cuStatus = 2;
|
||||||
|
current.Input.CardId.CardType = is_card_uid_felica(icca_card_uid) ? 2 : 1;
|
||||||
|
current.Input.CardId.cbCardId = sizeof(icca_card_uid);
|
||||||
|
std::memcpy(current.Input.CardId.CardId, icca_card_uid, sizeof(icca_card_uid));
|
||||||
|
}
|
||||||
|
|
||||||
|
// The ICCA keypad scan-code order is identical to eamuse.h. Keeping
|
||||||
|
// these bits populated also preserves the usual Spice numpad PIN flow.
|
||||||
|
const auto keypad = eamuse_get_keypad_state(0);
|
||||||
|
auto *key_states = ¤t.Input.bKey0;
|
||||||
|
for (size_t key = 0; key < EAM_IO_KEYPAD_COUNT; ++key) {
|
||||||
|
key_states[key] = (keypad & (1u << key)) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto copy_size = std::min<uint32_t>(status_size, sizeof(current));
|
||||||
|
if (status && copy_size > 0) {
|
||||||
|
std::memcpy(status, ¤t, copy_size);
|
||||||
|
}
|
||||||
|
return copy_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIobIcca_BeginGetCardId(AIO_IOB_ICCA *node) {
|
||||||
|
std::unique_lock<std::mutex> lock(icca_mutex);
|
||||||
|
if (node != aio_icca) {
|
||||||
|
lock.unlock();
|
||||||
|
return aioIobIcca_BeginGetCardId_orig(node);
|
||||||
|
}
|
||||||
|
if (!icca_reading) {
|
||||||
|
log_info("udn_bi2x", "ICCA BeginGetCardId: waiting for the Spice/CardIO queue");
|
||||||
|
}
|
||||||
|
icca_reading = true;
|
||||||
|
icca_card_ready = false;
|
||||||
|
std::memset(icca_card_uid, 0, sizeof(icca_card_uid));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioIobIcca_EndGetCardId(AIO_IOB_ICCA *node) {
|
||||||
|
std::unique_lock<std::mutex> lock(icca_mutex);
|
||||||
|
if (node != aio_icca) {
|
||||||
|
lock.unlock();
|
||||||
|
return aioIobIcca_EndGetCardId_orig(node);
|
||||||
|
}
|
||||||
|
if (icca_reading || icca_card_ready) {
|
||||||
|
log_info("udn_bi2x", "ICCA EndGetCardId: returning to idle");
|
||||||
|
}
|
||||||
|
icca_reading = false;
|
||||||
|
icca_card_ready = false;
|
||||||
|
std::memset(icca_card_uid, 0, sizeof(icca_card_uid));
|
||||||
|
}
|
||||||
|
|
||||||
|
static AIO_NMGR_IOB2 *__fastcall aioNMgrIob2_Create(AIO_SCI_COMM *sci, uint32_t mode) {
|
||||||
|
if (sci != aio_sci_comm.get()) {
|
||||||
|
return aioNMgrIob2_Create_orig(sci, mode);
|
||||||
|
}
|
||||||
|
if (!aio_node_manager) {
|
||||||
|
aio_node_manager = std::make_unique<AIO_NMGR_IOB2>();
|
||||||
|
}
|
||||||
|
return aio_node_manager.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioNMgrIob_BeginManage(AIO_NMGR_IOB2 *node_manager) {
|
||||||
|
if (node_manager != aio_node_manager.get()) {
|
||||||
|
return aioNMgrIob_BeginManage_orig(node_manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioNodeMgr_Destroy(AIO_NMGR_IOB2 *node_manager) {
|
||||||
|
if (node_manager != aio_node_manager.get()) {
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(icca_mutex);
|
||||||
|
if (node_manager == aio_icca_node_manager) {
|
||||||
|
aio_icca_node_manager = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return aioNodeMgr_Destroy_orig(node_manager);
|
||||||
|
}
|
||||||
|
aio_node_manager.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t __fastcall aioNodeMgr_GetState(AIO_NMGR_IOB2 *node_manager) {
|
||||||
|
bool virtual_manager = node_manager == aio_node_manager.get();
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(icca_mutex);
|
||||||
|
virtual_manager |= node_manager == aio_icca_node_manager;
|
||||||
|
}
|
||||||
|
if (virtual_manager) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return aioNodeMgr_GetState_orig(node_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool __fastcall aioNodeMgr_IsReady(AIO_NMGR_IOB2 *node_manager, int32_t state) {
|
||||||
|
bool virtual_manager = node_manager == aio_node_manager.get();
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(icca_mutex);
|
||||||
|
virtual_manager |= node_manager == aio_icca_node_manager;
|
||||||
|
}
|
||||||
|
if (virtual_manager) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return aioNodeMgr_IsReady_orig(node_manager, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall aioNodeCtl_Destroy(AIO_IOB2_BI2X_UDN *node) {
|
||||||
|
if (node != aio_udn.get()) {
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(icca_mutex);
|
||||||
|
if (reinterpret_cast<AIO_IOB_ICCA *>(node) == aio_icca) {
|
||||||
|
aio_icca = nullptr;
|
||||||
|
aio_icca_node_manager = nullptr;
|
||||||
|
icca_reading = false;
|
||||||
|
icca_card_ready = false;
|
||||||
|
std::memset(icca_card_uid, 0, sizeof(icca_card_uid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return aioNodeCtl_Destroy_orig(node);
|
||||||
|
}
|
||||||
|
aio_udn.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t __fastcall aioNodeCtl_GetState(AIO_IOB2_BI2X_UDN *node) {
|
||||||
|
bool virtual_node = node == aio_udn.get();
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(icca_mutex);
|
||||||
|
virtual_node |= reinterpret_cast<AIO_IOB_ICCA *>(node) == aio_icca;
|
||||||
|
}
|
||||||
|
if (virtual_node) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return aioNodeCtl_GetState_orig(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool __fastcall aioNodeCtl_IsReady(AIO_IOB2_BI2X_UDN *node, int32_t state) {
|
||||||
|
bool virtual_node = node == aio_udn.get();
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(icca_mutex);
|
||||||
|
virtual_node |= reinterpret_cast<AIO_IOB_ICCA *>(node) == aio_icca;
|
||||||
|
}
|
||||||
|
if (virtual_node) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return aioNodeCtl_IsReady_orig(node, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bi2x_hook_init() {
|
||||||
|
log_info("udn_bi2x", "init (BI2X + ICCA/CardIO bridge)");
|
||||||
|
|
||||||
|
// The runtime imports the alias DLL names, not their lib-prefixed originals.
|
||||||
|
const auto aio_iob2_video = "aio-iob2_video.dll";
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xUDN_Create",
|
||||||
|
aioIob2Bi2xUDN_Create, &aioIob2Bi2xUDN_Create_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xUDN_GetDeviceStatus",
|
||||||
|
aioIob2Bi2xUDN_GetDeviceStatus, &aioIob2Bi2xUDN_GetDeviceStatus_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xAC1_GetDeviceStatus",
|
||||||
|
aioIob2Bi2xAC1_GetDeviceStatus, &aioIob2Bi2xAC1_GetDeviceStatus_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xUDN_IoReset",
|
||||||
|
aioIob2Bi2xUDN_IoReset, &aioIob2Bi2xUDN_IoReset_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xUDN_SetWatchDogTimer",
|
||||||
|
aioIob2Bi2xUDN_SetWatchDogTimer, &aioIob2Bi2xUDN_SetWatchDogTimer_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xUDN_ControlCoinBlocker",
|
||||||
|
aioIob2Bi2xUDN_ControlCoinBlocker, &aioIob2Bi2xUDN_ControlCoinBlocker_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xUDN_AddCounter",
|
||||||
|
aioIob2Bi2xUDN_AddCounter, &aioIob2Bi2xUDN_AddCounter_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xUDN_SetStartLamp",
|
||||||
|
aioIob2Bi2xUDN_SetStartLamp, &aioIob2Bi2xUDN_SetStartLamp_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xUDN_SetPlayerButtonLamp",
|
||||||
|
aioIob2Bi2xUDN_SetPlayerButtonLamp, &aioIob2Bi2xUDN_SetPlayerButtonLamp_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xUDN_SetIccrLed",
|
||||||
|
aioIob2Bi2xUDN_SetIccrLed, &aioIob2Bi2xUDN_SetIccrLed_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xUDN_SetTapeLedDataLimit",
|
||||||
|
aioIob2Bi2xUDN_SetTapeLedDataLimit, &aioIob2Bi2xUDN_SetTapeLedDataLimit_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2xUDN_SetTapeLedData",
|
||||||
|
aioIob2Bi2xUDN_SetTapeLedData, &aioIob2Bi2xUDN_SetTapeLedData_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2x_OpenSciUsbCdc",
|
||||||
|
aioIob2Bi2x_OpenSciUsbCdc, &aioIob2Bi2x_OpenSciUsbCdc_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2x_CreateWriteFirmContext",
|
||||||
|
aioIob2Bi2x_CreateWriteFirmContext, &aioIob2Bi2x_CreateWriteFirmContext_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2x_DestroyWriteFirmContext",
|
||||||
|
aioIob2Bi2x_DestroyWriteFirmContext, &aioIob2Bi2x_DestroyWriteFirmContext_orig);
|
||||||
|
execexe::trampoline_try(aio_iob2_video, "aioIob2Bi2x_WriteFirmGetState",
|
||||||
|
aioIob2Bi2x_WriteFirmGetState, &aioIob2Bi2x_WriteFirmGetState_orig);
|
||||||
|
|
||||||
|
const auto aio_iob_video = "aio-iob_video.dll";
|
||||||
|
execexe::trampoline_try(aio_iob_video, "aioIobIcca_Create",
|
||||||
|
aioIobIcca_Create, &aioIobIcca_Create_orig);
|
||||||
|
execexe::trampoline_try(aio_iob_video, "aioIobIcca_GetDeviceStatus",
|
||||||
|
aioIobIcca_GetDeviceStatus, &aioIobIcca_GetDeviceStatus_orig);
|
||||||
|
execexe::trampoline_try(aio_iob_video, "aioIobIcca_BeginGetCardId",
|
||||||
|
aioIobIcca_BeginGetCardId, &aioIobIcca_BeginGetCardId_orig);
|
||||||
|
execexe::trampoline_try(aio_iob_video, "aioIobIcca_EndGetCardId",
|
||||||
|
aioIobIcca_EndGetCardId, &aioIobIcca_EndGetCardId_orig);
|
||||||
|
|
||||||
|
const auto aio_iob = "aio-iob.dll";
|
||||||
|
execexe::trampoline_try(aio_iob, "aioNMgrIob2_Create",
|
||||||
|
aioNMgrIob2_Create, &aioNMgrIob2_Create_orig);
|
||||||
|
execexe::trampoline_try(aio_iob, "aioNMgrIob_BeginManage",
|
||||||
|
aioNMgrIob_BeginManage, &aioNMgrIob_BeginManage_orig);
|
||||||
|
|
||||||
|
const auto aio = "aio.dll";
|
||||||
|
execexe::trampoline_try(aio, "aioNodeMgr_Destroy",
|
||||||
|
aioNodeMgr_Destroy, &aioNodeMgr_Destroy_orig);
|
||||||
|
execexe::trampoline_try(aio, "aioNodeMgr_GetState",
|
||||||
|
aioNodeMgr_GetState, &aioNodeMgr_GetState_orig);
|
||||||
|
execexe::trampoline_try(aio, "aioNodeMgr_IsReady",
|
||||||
|
aioNodeMgr_IsReady, &aioNodeMgr_IsReady_orig);
|
||||||
|
execexe::trampoline_try(aio, "aioNodeCtl_Destroy",
|
||||||
|
aioNodeCtl_Destroy, &aioNodeCtl_Destroy_orig);
|
||||||
|
execexe::trampoline_try(aio, "aioNodeCtl_GetState",
|
||||||
|
aioNodeCtl_GetState, &aioNodeCtl_GetState_orig);
|
||||||
|
execexe::trampoline_try(aio, "aioNodeCtl_IsReady",
|
||||||
|
aioNodeCtl_IsReady, &aioNodeCtl_IsReady_orig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace games::udn {
|
||||||
|
void bi2x_hook_init();
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
#include "io.h"
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
std::vector<Button> &games::udn::get_buttons() {
|
||||||
|
static std::vector<Button> buttons;
|
||||||
|
|
||||||
|
if (buttons.empty()) {
|
||||||
|
buttons = GameAPI::Buttons::getButtons("DANCE aROUND");
|
||||||
|
|
||||||
|
const std::vector<std::string> names {
|
||||||
|
"Service",
|
||||||
|
"Test",
|
||||||
|
"Coin Mech",
|
||||||
|
"Start",
|
||||||
|
"Up",
|
||||||
|
"Down",
|
||||||
|
"Left",
|
||||||
|
"Right",
|
||||||
|
};
|
||||||
|
const std::vector<unsigned short> vkey_defaults {
|
||||||
|
0xFF,
|
||||||
|
0xFF,
|
||||||
|
0xFF,
|
||||||
|
VK_RETURN,
|
||||||
|
VK_UP,
|
||||||
|
VK_DOWN,
|
||||||
|
VK_LEFT,
|
||||||
|
VK_RIGHT,
|
||||||
|
};
|
||||||
|
|
||||||
|
buttons = GameAPI::Buttons::sortButtons(buttons, names, &vkey_defaults);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string games::udn::get_buttons_help() {
|
||||||
|
return
|
||||||
|
" Arrow keys: menu directions\n"
|
||||||
|
" Enter: start/confirm\n"
|
||||||
|
" MIDI input is disabled for this game.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Light> &games::udn::get_lights() {
|
||||||
|
static std::vector<Light> lights;
|
||||||
|
|
||||||
|
if (lights.empty()) {
|
||||||
|
lights = GameAPI::Lights::getLights("DANCE aROUND");
|
||||||
|
GameAPI::Lights::sortLights(
|
||||||
|
&lights,
|
||||||
|
"Card Reader R",
|
||||||
|
"Card Reader G",
|
||||||
|
"Card Reader B",
|
||||||
|
"Start",
|
||||||
|
"Up",
|
||||||
|
"Down",
|
||||||
|
"Left",
|
||||||
|
"Right",
|
||||||
|
"Title R",
|
||||||
|
"Title G",
|
||||||
|
"Title B",
|
||||||
|
"Pillar Right Top R",
|
||||||
|
"Pillar Right Top G",
|
||||||
|
"Pillar Right Top B",
|
||||||
|
"Pillar Right Bottom R",
|
||||||
|
"Pillar Right Bottom G",
|
||||||
|
"Pillar Right Bottom B",
|
||||||
|
"Stage Left R",
|
||||||
|
"Stage Left G",
|
||||||
|
"Stage Left B",
|
||||||
|
"Cabinet Left R",
|
||||||
|
"Cabinet Left G",
|
||||||
|
"Cabinet Left B",
|
||||||
|
"Pillar Left Top R",
|
||||||
|
"Pillar Left Top G",
|
||||||
|
"Pillar Left Top B",
|
||||||
|
"Pillar Left Bottom R",
|
||||||
|
"Pillar Left Bottom G",
|
||||||
|
"Pillar Left Bottom B",
|
||||||
|
"Stage Right R",
|
||||||
|
"Stage Right G",
|
||||||
|
"Stage Right B",
|
||||||
|
"Cabinet Right R",
|
||||||
|
"Cabinet Right G",
|
||||||
|
"Cabinet Right B"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lights;
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "cfg/api.h"
|
||||||
|
|
||||||
|
namespace games::udn {
|
||||||
|
namespace Buttons {
|
||||||
|
enum {
|
||||||
|
Service,
|
||||||
|
Test,
|
||||||
|
CoinMech,
|
||||||
|
Start,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Lights {
|
||||||
|
enum udn_lights_t {
|
||||||
|
CardReaderR,
|
||||||
|
CardReaderG,
|
||||||
|
CardReaderB,
|
||||||
|
Start,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
TitleR,
|
||||||
|
TitleG,
|
||||||
|
TitleB,
|
||||||
|
PillarRightTopR,
|
||||||
|
PillarRightTopG,
|
||||||
|
PillarRightTopB,
|
||||||
|
PillarRightBottomR,
|
||||||
|
PillarRightBottomG,
|
||||||
|
PillarRightBottomB,
|
||||||
|
StageLeftR,
|
||||||
|
StageLeftG,
|
||||||
|
StageLeftB,
|
||||||
|
CabinetLeftR,
|
||||||
|
CabinetLeftG,
|
||||||
|
CabinetLeftB,
|
||||||
|
PillarLeftTopR,
|
||||||
|
PillarLeftTopG,
|
||||||
|
PillarLeftTopB,
|
||||||
|
PillarLeftBottomR,
|
||||||
|
PillarLeftBottomG,
|
||||||
|
PillarLeftBottomB,
|
||||||
|
StageRightR,
|
||||||
|
StageRightG,
|
||||||
|
StageRightB,
|
||||||
|
CabinetRightR,
|
||||||
|
CabinetRightG,
|
||||||
|
CabinetRightB,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Button> &get_buttons();
|
||||||
|
std::string get_buttons_help();
|
||||||
|
std::vector<Light> &get_lights();
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
// QueryDisplayConfig
|
||||||
|
#define _WIN32_WINNT 0x0601
|
||||||
|
|
||||||
|
#include "udn.h"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
#include "acioemu/handle.h"
|
||||||
|
#include "bi2x_hook.h"
|
||||||
|
#include "cfg/screen_resize.h"
|
||||||
|
#include "hooks/devicehook.h"
|
||||||
|
#include "hooks/graphics/graphics.h"
|
||||||
|
#include "rawinput/rawinput.h"
|
||||||
|
#include "util/detour.h"
|
||||||
|
#include "util/execexe.h"
|
||||||
|
#include "util/logging.h"
|
||||||
|
#include "util/unity_player.h"
|
||||||
|
#include "util/utils.h"
|
||||||
|
|
||||||
|
namespace games::udn {
|
||||||
|
std::string UDN_INJECT_ARGS = "";
|
||||||
|
bool UDN_NO_IO = false;
|
||||||
|
|
||||||
|
static acioemu::ACIOHandle *acio_handle = nullptr;
|
||||||
|
static const std::wstring port_name = L"COM1";
|
||||||
|
|
||||||
|
static decltype(RegisterRawInputDevices) *RegisterRawInputDevices_orig = nullptr;
|
||||||
|
static decltype(EnumDisplaySettingsW) *EnumDisplaySettingsW_orig = nullptr;
|
||||||
|
static decltype(QueryDisplayConfig) *QueryDisplayConfig_orig = nullptr;
|
||||||
|
|
||||||
|
// Unity reapplies its cabinet window settings after startup. Use the
|
||||||
|
// existing graphics message callback so changes stay on the window thread.
|
||||||
|
static LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM w_param, LPARAM l_param) {
|
||||||
|
if (!GRAPHICS_WINDOWED || GRAPHICS_HOOKED_WINDOW != window) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool interactive_resize = false;
|
||||||
|
switch (message) {
|
||||||
|
case WM_ENTERSIZEMOVE:
|
||||||
|
interactive_resize = true;
|
||||||
|
break;
|
||||||
|
case WM_EXITSIZEMOVE:
|
||||||
|
interactive_resize = false;
|
||||||
|
break;
|
||||||
|
case WM_STYLECHANGING:
|
||||||
|
if (w_param == static_cast<WPARAM>(GWL_STYLE)) {
|
||||||
|
auto styles = reinterpret_cast<STYLESTRUCT *>(l_param);
|
||||||
|
styles->styleNew &= ~WS_POPUP;
|
||||||
|
if (cfg::SCREENRESIZE->window_decoration == cfg::WindowDecorationMode::Borderless) {
|
||||||
|
styles->styleNew &= ~WS_OVERLAPPEDWINDOW;
|
||||||
|
} else {
|
||||||
|
styles->styleNew |= WS_OVERLAPPEDWINDOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WM_WINDOWPOSCHANGING:
|
||||||
|
if (!interactive_resize && cfg::SCREENRESIZE->enable_window_resize) {
|
||||||
|
auto position = reinterpret_cast<WINDOWPOS *>(l_param);
|
||||||
|
// The shared WM_MOVE/WM_SIZE handlers keep these values in
|
||||||
|
// sync with interactive changes and the overlay settings.
|
||||||
|
if (!(position->flags & SWP_NOMOVE)) {
|
||||||
|
position->x = cfg::SCREENRESIZE->window_offset_x;
|
||||||
|
position->y = cfg::SCREENRESIZE->window_offset_y;
|
||||||
|
}
|
||||||
|
if (!(position->flags & SWP_NOSIZE)) {
|
||||||
|
position->cx = cfg::SCREENRESIZE->client_width +
|
||||||
|
cfg::SCREENRESIZE->window_deco_width;
|
||||||
|
position->cy = cfg::SCREENRESIZE->client_height +
|
||||||
|
cfg::SCREENRESIZE->window_deco_height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL WINAPI RegisterRawInputDevices_hook(
|
||||||
|
PCRAWINPUTDEVICE devices, UINT device_count, UINT structure_size) {
|
||||||
|
|
||||||
|
if (devices && device_count > 0 && devices[0].hwndTarget == RI_MGR->input_hwnd) {
|
||||||
|
return RegisterRawInputDevices_orig(devices, device_count, structure_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetLastError(0xDEADBEEF);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL WINAPI EnumDisplaySettingsW_hook(
|
||||||
|
LPCWSTR device_name, DWORD mode_number, DEVMODEW *mode) {
|
||||||
|
|
||||||
|
const auto result = EnumDisplaySettingsW_orig(device_name, mode_number, mode);
|
||||||
|
if (result && mode_number == ENUM_CURRENT_SETTINGS) {
|
||||||
|
mode->dmPelsWidth = 1920;
|
||||||
|
mode->dmPelsHeight = 1080;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static LONG WINAPI QueryDisplayConfig_hook(
|
||||||
|
UINT32, UINT32 *, DISPLAYCONFIG_PATH_INFO *, UINT32 *, DISPLAYCONFIG_MODE_INFO *,
|
||||||
|
DISPLAYCONFIG_TOPOLOGY_ID *) {
|
||||||
|
return ERROR_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UDNGame::pre_attach() {
|
||||||
|
// The title has no MIDI controls. The legacy WinMM provider can fault in
|
||||||
|
// MMDevAPI while Unity and its audio backend initialize concurrently, so
|
||||||
|
// disable MIDI enumeration for this game.
|
||||||
|
rawinput::DISABLE_MIDI = true;
|
||||||
|
log_info("udn", "MIDI input disabled to avoid WinMM initialization errors");
|
||||||
|
}
|
||||||
|
|
||||||
|
void UDNGame::attach() {
|
||||||
|
Game::attach();
|
||||||
|
|
||||||
|
acio_handle = new acioemu::ACIOHandle(port_name.c_str(), 1);
|
||||||
|
devicehook_init_trampoline();
|
||||||
|
devicehook_add(acio_handle);
|
||||||
|
|
||||||
|
execexe::init();
|
||||||
|
execexe::init_deferred([]() {
|
||||||
|
execexe::init_port_hook(port_name, acio_handle);
|
||||||
|
|
||||||
|
// Runtime import names omit the "lib" prefix.
|
||||||
|
execexe::load_library("aio.dll");
|
||||||
|
execexe::load_library("aio-iob.dll");
|
||||||
|
execexe::load_library("aio-iob_video.dll");
|
||||||
|
execexe::load_library("aio-iob2_video.dll");
|
||||||
|
execexe::load_library("win10actlog.dll", false);
|
||||||
|
|
||||||
|
#if SPICE64
|
||||||
|
if (!UDN_NO_IO) {
|
||||||
|
bi2x_hook_init();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
});
|
||||||
|
|
||||||
|
const auto user32_dll = "user32.dll";
|
||||||
|
detour::trampoline_try(user32_dll, "RegisterRawInputDevices",
|
||||||
|
RegisterRawInputDevices_hook, &RegisterRawInputDevices_orig);
|
||||||
|
if (GRAPHICS_WINDOWED) {
|
||||||
|
// Keep Unity's cabinet-sized UI in windowed mode. Fullscreen uses
|
||||||
|
// the real display topology and resolution.
|
||||||
|
detour::trampoline_try(user32_dll, "QueryDisplayConfig",
|
||||||
|
QueryDisplayConfig_hook, &QueryDisplayConfig_orig);
|
||||||
|
detour::trampoline_try(user32_dll, "EnumDisplaySettingsW",
|
||||||
|
EnumDisplaySettingsW_hook, &EnumDisplaySettingsW_orig);
|
||||||
|
graphics_add_wnd_proc(window_proc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GRAPHICS_SHOW_CURSOR) {
|
||||||
|
unity_utils::force_show_cursor(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
unity_utils::set_args(
|
||||||
|
std::format("{} {}{}",
|
||||||
|
GetCommandLineA(),
|
||||||
|
UDN_INJECT_ARGS,
|
||||||
|
unity_utils::get_unity_player_args()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void UDNGame::detach() {
|
||||||
|
Game::detach();
|
||||||
|
graphics_remove_wnd_proc(window_proc);
|
||||||
|
devicehook_dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "games/game.h"
|
||||||
|
|
||||||
|
namespace games::udn {
|
||||||
|
extern std::string UDN_INJECT_ARGS;
|
||||||
|
extern bool UDN_NO_IO;
|
||||||
|
|
||||||
|
class UDNGame : public games::Game {
|
||||||
|
public:
|
||||||
|
UDNGame() : Game("DANCE aROUND") {}
|
||||||
|
|
||||||
|
virtual void pre_attach() override;
|
||||||
|
virtual void attach() override;
|
||||||
|
virtual void detach() override;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ namespace d3d11_hooks {
|
|||||||
// ignore_hwnd.
|
// ignore_hwnd.
|
||||||
void note_main_hwnd(HWND hwnd);
|
void note_main_hwnd(HWND hwnd);
|
||||||
HWND main_hwnd();
|
HWND main_hwnd();
|
||||||
|
bool is_main_game_swapchain(IDXGISwapChain *swapchain);
|
||||||
void ignore_hwnd(HWND hwnd);
|
void ignore_hwnd(HWND hwnd);
|
||||||
|
|
||||||
// capture backbuffer to PNG if a screenshot was requested.
|
// capture backbuffer to PNG if a screenshot was requested.
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <dxgi1_2.h>
|
#include <dxgi1_2.h>
|
||||||
|
|
||||||
#include "d3d11_internal.h"
|
#include "d3d11_internal.h"
|
||||||
|
#include "d3d11_swapchain_udn.h"
|
||||||
|
|
||||||
#include "external/imgui/imgui.h"
|
#include "external/imgui/imgui.h"
|
||||||
#include "external/imgui/backends/imgui_impl_dx11.h"
|
#include "external/imgui/backends/imgui_impl_dx11.h"
|
||||||
@@ -115,34 +116,6 @@ bool looks_like_game_window(HWND hwnd) {
|
|||||||
&& client.bottom > client.top;
|
&& client.bottom > client.top;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only the main game window; ignore sub-screens / IME helpers.
|
|
||||||
bool is_main_game_swapchain(IDXGISwapChain *swapchain) {
|
|
||||||
DXGI_SWAP_CHAIN_DESC desc {};
|
|
||||||
if (!swapchain || FAILED(swapchain->GetDesc(&desc)) || !desc.OutputWindow) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
HWND main = d3d11_hooks::main_hwnd();
|
|
||||||
if (!main) {
|
|
||||||
// no creation hook recorded a window, so fall back to the presenting one;
|
|
||||||
// the choice is permanent, so require a plausible game window
|
|
||||||
if (!looks_like_game_window(desc.OutputWindow)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_misc(
|
|
||||||
"graphics::d3d11",
|
|
||||||
"try to notemain hwnd from swapchain present: 0x{:x}",
|
|
||||||
(uintptr_t)desc.OutputWindow);
|
|
||||||
|
|
||||||
d3d11_hooks::note_main_hwnd(desc.OutputWindow);
|
|
||||||
|
|
||||||
// it may have been ignored, or another thread may have won the slot
|
|
||||||
main = d3d11_hooks::main_hwnd();
|
|
||||||
}
|
|
||||||
return desc.OutputWindow == main;
|
|
||||||
}
|
|
||||||
|
|
||||||
// checks are ordered cheapest first, since this runs on every present
|
// checks are ordered cheapest first, since this runs on every present
|
||||||
void try_create_overlay(IDXGISwapChain *swapchain) {
|
void try_create_overlay(IDXGISwapChain *swapchain) {
|
||||||
if (!swapchain) {
|
if (!swapchain) {
|
||||||
@@ -160,7 +133,7 @@ void try_create_overlay(IDXGISwapChain *swapchain) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ignore sub windows
|
// ignore sub windows
|
||||||
if (!is_main_game_swapchain(swapchain)) {
|
if (!d3d11_hooks::is_main_game_swapchain(swapchain)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +171,7 @@ void try_create_overlay(IDXGISwapChain *swapchain) {
|
|||||||
void pump_frame(IDXGISwapChain *swapchain) {
|
void pump_frame(IDXGISwapChain *swapchain) {
|
||||||
const bool has_overlay =
|
const bool has_overlay =
|
||||||
overlay::OVERLAY && overlay::OVERLAY->uses_swapchain(swapchain);
|
overlay::OVERLAY && overlay::OVERLAY->uses_swapchain(swapchain);
|
||||||
if (!has_overlay && !is_main_game_swapchain(swapchain)) {
|
if (!has_overlay && !d3d11_hooks::is_main_game_swapchain(swapchain)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,8 +213,10 @@ HRESULT STDMETHODCALLTYPE Present_hook(
|
|||||||
{
|
{
|
||||||
// a test present doesn't display anything; don't pick a window or take a screenshot off it
|
// a test present doesn't display anything; don't pick a window or take a screenshot off it
|
||||||
if (!(Flags & DXGI_PRESENT_TEST)) {
|
if (!(Flags & DXGI_PRESENT_TEST)) {
|
||||||
|
d3d11_hooks::udn::schedule_window_attach(swapchain);
|
||||||
try_create_overlay(swapchain);
|
try_create_overlay(swapchain);
|
||||||
pump_frame(swapchain);
|
pump_frame(swapchain);
|
||||||
|
d3d11_hooks::udn::apply_present_policy(swapchain, SyncInterval);
|
||||||
}
|
}
|
||||||
return Present_orig(swapchain, SyncInterval, Flags);
|
return Present_orig(swapchain, SyncInterval, Flags);
|
||||||
}
|
}
|
||||||
@@ -251,8 +226,10 @@ HRESULT STDMETHODCALLTYPE Present1_hook(
|
|||||||
const DXGI_PRESENT_PARAMETERS *pParams)
|
const DXGI_PRESENT_PARAMETERS *pParams)
|
||||||
{
|
{
|
||||||
if (!(Flags & DXGI_PRESENT_TEST)) {
|
if (!(Flags & DXGI_PRESENT_TEST)) {
|
||||||
|
d3d11_hooks::udn::schedule_window_attach(swapchain);
|
||||||
try_create_overlay(swapchain);
|
try_create_overlay(swapchain);
|
||||||
pump_frame(swapchain);
|
pump_frame(swapchain);
|
||||||
|
d3d11_hooks::udn::apply_present_policy(swapchain, SyncInterval);
|
||||||
}
|
}
|
||||||
return Present1_orig(swapchain, SyncInterval, Flags, pParams);
|
return Present1_orig(swapchain, SyncInterval, Flags, pParams);
|
||||||
}
|
}
|
||||||
@@ -287,6 +264,33 @@ namespace {
|
|||||||
std::atomic<HWND> g_ignored_hwnd { nullptr };
|
std::atomic<HWND> g_ignored_hwnd { nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_main_game_swapchain(IDXGISwapChain *swapchain) {
|
||||||
|
DXGI_SWAP_CHAIN_DESC desc {};
|
||||||
|
if (!swapchain || FAILED(swapchain->GetDesc(&desc)) || !desc.OutputWindow) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND main = d3d11_hooks::main_hwnd();
|
||||||
|
if (!main) {
|
||||||
|
// no creation hook recorded a window, so fall back to the presenting one;
|
||||||
|
// the choice is permanent, so require a plausible game window
|
||||||
|
if (!looks_like_game_window(desc.OutputWindow)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_misc(
|
||||||
|
"graphics::d3d11",
|
||||||
|
"try to notemain hwnd from swapchain present: 0x{:x}",
|
||||||
|
(uintptr_t)desc.OutputWindow);
|
||||||
|
|
||||||
|
d3d11_hooks::note_main_hwnd(desc.OutputWindow);
|
||||||
|
|
||||||
|
// it may have been ignored, or another thread may have won the slot
|
||||||
|
main = d3d11_hooks::main_hwnd();
|
||||||
|
}
|
||||||
|
return desc.OutputWindow == main;
|
||||||
|
}
|
||||||
|
|
||||||
void note_main_hwnd(HWND hwnd) {
|
void note_main_hwnd(HWND hwnd) {
|
||||||
if (!hwnd || hwnd == g_ignored_hwnd.load()) {
|
if (!hwnd || hwnd == g_ignored_hwnd.load()) {
|
||||||
return;
|
return;
|
||||||
@@ -326,6 +330,8 @@ void install_swapchain_hooks(IDXGISwapChain *swapchain) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
udn::install_swapchain_hooks(swapchain);
|
||||||
|
|
||||||
if (!g_swapchain1_hooked) {
|
if (!g_swapchain1_hooked) {
|
||||||
IDXGISwapChain1 *sc1 = nullptr;
|
IDXGISwapChain1 *sc1 = nullptr;
|
||||||
if (SUCCEEDED(swapchain->QueryInterface(IID_PPV_ARGS(&sc1))) && sc1) {
|
if (SUCCEEDED(swapchain->QueryInterface(IID_PPV_ARGS(&sc1))) && sc1) {
|
||||||
|
|||||||
@@ -0,0 +1,223 @@
|
|||||||
|
// DANCE aROUND window attachment, frame pacing and display-mode overrides.
|
||||||
|
#include "d3d11_backend.h"
|
||||||
|
|
||||||
|
#ifdef SPICE_D3D11
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <d3d11.h>
|
||||||
|
#include <dxgi.h>
|
||||||
|
|
||||||
|
#include "d3d11_internal.h"
|
||||||
|
#include "d3d11_swapchain_udn.h"
|
||||||
|
#include "avs/game.h"
|
||||||
|
#include "hooks/graphics/graphics.h"
|
||||||
|
#include "util/precise_timer.h"
|
||||||
|
|
||||||
|
namespace d3d11_hooks::udn {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using SetFullscreenState_t = HRESULT(STDMETHODCALLTYPE *)(
|
||||||
|
IDXGISwapChain *, BOOL, IDXGIOutput *);
|
||||||
|
using ResizeTarget_t = HRESULT(STDMETHODCALLTYPE *)(
|
||||||
|
IDXGISwapChain *, const DXGI_MODE_DESC *);
|
||||||
|
|
||||||
|
SetFullscreenState_t SetFullscreenState_orig = nullptr;
|
||||||
|
ResizeTarget_t ResizeTarget_orig = nullptr;
|
||||||
|
|
||||||
|
bool g_set_fullscreen_hooked = false;
|
||||||
|
bool g_resize_target_hooked = false;
|
||||||
|
// Present and Present1 share one waitable timer and frame deadline.
|
||||||
|
std::mutex g_forced_present_pacing_mutex;
|
||||||
|
std::chrono::steady_clock::time_point g_next_forced_present {};
|
||||||
|
|
||||||
|
// Unity creates and owns its top-level window on a different thread from the
|
||||||
|
// D3D11 Present thread. Subclassing or resizing that HWND from Present can
|
||||||
|
// synchronously wait for the owner thread and deadlock Unity. A one-time
|
||||||
|
// message-queue hook performs graphics_hook_window on the HWND's owner thread.
|
||||||
|
std::mutex g_window_attach_mutex;
|
||||||
|
HHOOK g_window_attach_hook = nullptr;
|
||||||
|
HWND g_window_attach_target = nullptr;
|
||||||
|
bool g_window_attach_complete = false;
|
||||||
|
|
||||||
|
UINT window_attach_message() {
|
||||||
|
static const UINT message = RegisterWindowMessageW(
|
||||||
|
L"SpiceTools.D3D11.AttachGameWindow");
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pace_forced_present(UINT frame_rate) {
|
||||||
|
static timeutils::PreciseSleepTimer timer;
|
||||||
|
const auto period = std::chrono::nanoseconds(
|
||||||
|
1'000'000'000ULL / static_cast<uint64_t>(frame_rate));
|
||||||
|
std::lock_guard<std::mutex> lock(g_forced_present_pacing_mutex);
|
||||||
|
const auto now = std::chrono::steady_clock::now();
|
||||||
|
if (g_next_forced_present.time_since_epoch().count() == 0 ||
|
||||||
|
now > g_next_forced_present + period) {
|
||||||
|
g_next_forced_present = now + period;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (now < g_next_forced_present) {
|
||||||
|
timer.sleep(g_next_forced_present - now);
|
||||||
|
}
|
||||||
|
g_next_forced_present += period;
|
||||||
|
}
|
||||||
|
|
||||||
|
LRESULT CALLBACK window_attach_getmessage(
|
||||||
|
int code, WPARAM w_param, LPARAM l_param) {
|
||||||
|
HWND target = nullptr;
|
||||||
|
HHOOK hook = nullptr;
|
||||||
|
if (code >= 0 && w_param == PM_REMOVE) {
|
||||||
|
const auto message = reinterpret_cast<const MSG *>(l_param);
|
||||||
|
std::lock_guard<std::mutex> lock(g_window_attach_mutex);
|
||||||
|
if (!g_window_attach_complete && message->hwnd == g_window_attach_target &&
|
||||||
|
message->message == window_attach_message()) {
|
||||||
|
target = g_window_attach_target;
|
||||||
|
hook = g_window_attach_hook;
|
||||||
|
g_window_attach_hook = nullptr;
|
||||||
|
g_window_attach_complete = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const LRESULT result = CallNextHookEx(nullptr, code, w_param, l_param);
|
||||||
|
if (target) {
|
||||||
|
UnhookWindowsHookEx(hook);
|
||||||
|
graphics_hook_window(target, nullptr);
|
||||||
|
log_info(
|
||||||
|
"graphics::d3d11",
|
||||||
|
"attached Spice window hooks on owner thread for hwnd=0x{:x}",
|
||||||
|
(uintptr_t) target);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT STDMETHODCALLTYPE SetFullscreenState_hook(
|
||||||
|
IDXGISwapChain *swapchain, BOOL Fullscreen, IDXGIOutput *Target) {
|
||||||
|
if (Fullscreen && GRAPHICS_WINDOWED && avs::game::is_model("UDN") &&
|
||||||
|
is_main_game_swapchain(swapchain)) {
|
||||||
|
log_info(
|
||||||
|
"graphics::d3d11",
|
||||||
|
"blocked UDN request to enter DXGI exclusive fullscreen");
|
||||||
|
return SetFullscreenState_orig(swapchain, FALSE, nullptr);
|
||||||
|
}
|
||||||
|
return SetFullscreenState_orig(swapchain, Fullscreen, Target);
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT STDMETHODCALLTYPE ResizeTarget_hook(
|
||||||
|
IDXGISwapChain *swapchain, const DXGI_MODE_DESC *NewTargetParameters) {
|
||||||
|
if (GRAPHICS_WINDOWED && avs::game::is_model("UDN") &&
|
||||||
|
is_main_game_swapchain(swapchain)) {
|
||||||
|
if (NewTargetParameters) {
|
||||||
|
log_info(
|
||||||
|
"graphics::d3d11",
|
||||||
|
"blocked UDN output-mode resize to {}x{}",
|
||||||
|
NewTargetParameters->Width,
|
||||||
|
NewTargetParameters->Height);
|
||||||
|
}
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
return ResizeTarget_orig(swapchain, NewTargetParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void schedule_window_attach(IDXGISwapChain *swapchain) {
|
||||||
|
if (!GRAPHICS_WINDOWED || !avs::game::is_model("UDN") ||
|
||||||
|
!is_main_game_swapchain(swapchain)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DXGI_SWAP_CHAIN_DESC desc {};
|
||||||
|
if (FAILED(swapchain->GetDesc(&desc)) || !desc.OutputWindow) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const HWND hwnd = desc.OutputWindow;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(g_window_attach_mutex);
|
||||||
|
if (g_window_attach_complete || g_window_attach_hook != nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (GRAPHICS_HOOKED_WINDOW.has_value()) {
|
||||||
|
g_window_attach_complete = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD process_id = 0;
|
||||||
|
const DWORD thread_id = GetWindowThreadProcessId(hwnd, &process_id);
|
||||||
|
if (!thread_id || process_id != GetCurrentProcessId()) {
|
||||||
|
log_warning(
|
||||||
|
"graphics::d3d11",
|
||||||
|
"could not identify owner thread for hwnd=0x{:x}",
|
||||||
|
(uintptr_t) hwnd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const HHOOK hook = SetWindowsHookExW(
|
||||||
|
WH_GETMESSAGE, window_attach_getmessage, nullptr, thread_id);
|
||||||
|
if (!hook) {
|
||||||
|
log_warning(
|
||||||
|
"graphics::d3d11",
|
||||||
|
"could not schedule owner-thread window attach for hwnd=0x{:x}: {}",
|
||||||
|
(uintptr_t) hwnd,
|
||||||
|
GetLastError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_window_attach_target = hwnd;
|
||||||
|
g_window_attach_hook = hook;
|
||||||
|
if (!PostMessageW(hwnd, window_attach_message(), 0, 0)) {
|
||||||
|
const DWORD error = GetLastError();
|
||||||
|
g_window_attach_hook = nullptr;
|
||||||
|
g_window_attach_target = nullptr;
|
||||||
|
UnhookWindowsHookEx(hook);
|
||||||
|
log_warning(
|
||||||
|
"graphics::d3d11",
|
||||||
|
"could not post owner-thread window attach for hwnd=0x{:x}: {}",
|
||||||
|
(uintptr_t) hwnd,
|
||||||
|
error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_info(
|
||||||
|
"graphics::d3d11",
|
||||||
|
"scheduled Spice window attach on owner thread {} for hwnd=0x{:x}",
|
||||||
|
thread_id,
|
||||||
|
(uintptr_t) hwnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void apply_present_policy(IDXGISwapChain *swapchain, UINT &sync_interval) {
|
||||||
|
if (!GRAPHICS_WINDOWED || !avs::game::is_model("UDN") ||
|
||||||
|
!is_main_game_swapchain(swapchain)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Interval two gives 60 FPS on the cabinet's 120 Hz display, but only
|
||||||
|
// 37.5 FPS on a 75 Hz desktop. Pace windowed mode with an explicit clock.
|
||||||
|
// Fullscreen keeps the game's own presentation interval and flags.
|
||||||
|
pace_forced_present(60);
|
||||||
|
sync_interval = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void install_swapchain_hooks(IDXGISwapChain *swapchain) {
|
||||||
|
if (!GRAPHICS_WINDOWED || !avs::game::is_model("UDN")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// The shared installer holds its mutex while calling this function.
|
||||||
|
if (!g_set_fullscreen_hooked) {
|
||||||
|
g_set_fullscreen_hooked = hook_vtbl(
|
||||||
|
swapchain, 10, (void *) SetFullscreenState_hook,
|
||||||
|
(void **) &SetFullscreenState_orig,
|
||||||
|
"IDXGISwapChain::SetFullscreenState");
|
||||||
|
}
|
||||||
|
if (!g_resize_target_hooked) {
|
||||||
|
g_resize_target_hooked = hook_vtbl(
|
||||||
|
swapchain, 14, (void *) ResizeTarget_hook,
|
||||||
|
(void **) &ResizeTarget_orig, "IDXGISwapChain::ResizeTarget");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace d3d11_hooks::udn
|
||||||
|
|
||||||
|
#endif // SPICE_D3D11
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef SPICE_D3D11
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
struct IDXGISwapChain;
|
||||||
|
|
||||||
|
namespace d3d11_hooks::udn {
|
||||||
|
|
||||||
|
void schedule_window_attach(IDXGISwapChain *swapchain);
|
||||||
|
void apply_present_policy(IDXGISwapChain *swapchain, UINT &sync_interval);
|
||||||
|
void install_swapchain_hooks(IDXGISwapChain *swapchain);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
#include "libraryhook.h"
|
#include "libraryhook.h"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
#include <shared_mutex>
|
||||||
|
|
||||||
#include "external/robin_hood.h"
|
#include "external/robin_hood.h"
|
||||||
#include "util/detour.h"
|
#include "util/detour.h"
|
||||||
#include "util/logging.h"
|
#include "util/logging.h"
|
||||||
#include "util/utils.h"
|
#include "util/utils.h"
|
||||||
|
|
||||||
static bool LHOOK_ENABLED = false;
|
static bool LHOOK_ENABLED = false;
|
||||||
|
// SDK plugins can add aliases while other threads load DLLs.
|
||||||
|
static std::shared_mutex LIBRARIES_MUTEX;
|
||||||
static robin_hood::unordered_map<std::string, HMODULE> LIBRARIES_A;
|
static robin_hood::unordered_map<std::string, HMODULE> LIBRARIES_A;
|
||||||
static robin_hood::unordered_map<std::wstring, HMODULE> LIBRARIES_W;
|
static robin_hood::unordered_map<std::wstring, HMODULE> LIBRARIES_W;
|
||||||
static robin_hood::unordered_map<std::string, FARPROC> PROCS;
|
static robin_hood::unordered_map<std::string, FARPROC> PROCS;
|
||||||
@@ -21,6 +26,7 @@ static HMODULE WINAPI LoadLibraryA_hook(LPCTSTR lpFileName) {
|
|||||||
|
|
||||||
// check hooks
|
// check hooks
|
||||||
if (lpFileName) {
|
if (lpFileName) {
|
||||||
|
std::shared_lock lock(LIBRARIES_MUTEX);
|
||||||
auto module = LIBRARIES_A.find(lpFileName);
|
auto module = LIBRARIES_A.find(lpFileName);
|
||||||
if (module != LIBRARIES_A.end()) {
|
if (module != LIBRARIES_A.end()) {
|
||||||
return module->second;
|
return module->second;
|
||||||
@@ -35,6 +41,7 @@ static HMODULE WINAPI LoadLibraryW_hook(LPCWSTR lpFileName) {
|
|||||||
|
|
||||||
// check hooks
|
// check hooks
|
||||||
if (lpFileName) {
|
if (lpFileName) {
|
||||||
|
std::shared_lock lock(LIBRARIES_MUTEX);
|
||||||
auto module = LIBRARIES_W.find(lpFileName);
|
auto module = LIBRARIES_W.find(lpFileName);
|
||||||
if (module != LIBRARIES_W.end()) {
|
if (module != LIBRARIES_W.end()) {
|
||||||
return module->second;
|
return module->second;
|
||||||
@@ -49,6 +56,7 @@ static HMODULE WINAPI LoadLibraryExW_hook(LPCWSTR lpFileName, HANDLE hFile, DWOR
|
|||||||
|
|
||||||
// check hooks
|
// check hooks
|
||||||
if (lpFileName) {
|
if (lpFileName) {
|
||||||
|
std::shared_lock lock(LIBRARIES_MUTEX);
|
||||||
auto module = LIBRARIES_W.find(lpFileName);
|
auto module = LIBRARIES_W.find(lpFileName);
|
||||||
if (module != LIBRARIES_W.end()) {
|
if (module != LIBRARIES_W.end()) {
|
||||||
return module->second;
|
return module->second;
|
||||||
@@ -63,6 +71,7 @@ static HMODULE WINAPI GetModuleHandleA_hook(LPCSTR lpModuleName) {
|
|||||||
|
|
||||||
// check hooks
|
// check hooks
|
||||||
if (lpModuleName) {
|
if (lpModuleName) {
|
||||||
|
std::shared_lock lock(LIBRARIES_MUTEX);
|
||||||
auto module = LIBRARIES_A.find(lpModuleName);
|
auto module = LIBRARIES_A.find(lpModuleName);
|
||||||
if (module != LIBRARIES_A.end()) {
|
if (module != LIBRARIES_A.end()) {
|
||||||
return module->second;
|
return module->second;
|
||||||
@@ -77,6 +86,7 @@ static HMODULE WINAPI GetModuleHandleW_hook(LPCWSTR lpModuleName) {
|
|||||||
|
|
||||||
// check hooks
|
// check hooks
|
||||||
if (lpModuleName) {
|
if (lpModuleName) {
|
||||||
|
std::shared_lock lock(LIBRARIES_MUTEX);
|
||||||
auto module = LIBRARIES_W.find(lpModuleName);
|
auto module = LIBRARIES_W.find(lpModuleName);
|
||||||
if (module != LIBRARIES_W.end()) {
|
if (module != LIBRARIES_W.end()) {
|
||||||
return module->second;
|
return module->second;
|
||||||
@@ -129,8 +139,10 @@ void libraryhook_enable(HMODULE module) {
|
|||||||
|
|
||||||
void libraryhook_hook_library(std::string library_name, HMODULE library_address) {
|
void libraryhook_hook_library(std::string library_name, HMODULE library_address) {
|
||||||
|
|
||||||
|
const auto library_name_w = s2ws(library_name);
|
||||||
|
std::unique_lock lock(LIBRARIES_MUTEX);
|
||||||
// add library to list
|
// add library to list
|
||||||
LIBRARIES_W.insert_or_assign(s2ws(library_name), library_address);
|
LIBRARIES_W.insert_or_assign(library_name_w, library_address);
|
||||||
LIBRARIES_A.insert_or_assign(std::move(library_name), library_address);
|
LIBRARIES_A.insert_or_assign(std::move(library_name), library_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,9 @@
|
|||||||
#include "games/qks/qks.h"
|
#include "games/qks/qks.h"
|
||||||
#include "games/mfg/mfg.h"
|
#include "games/mfg/mfg.h"
|
||||||
#include "games/pc/pc.h"
|
#include "games/pc/pc.h"
|
||||||
|
#include "games/udn/udn.h"
|
||||||
|
#include "games/cardconnect/cardconnect.h"
|
||||||
|
#include "games/cardconnect/printer.h"
|
||||||
#include "games/museca/museca.h"
|
#include "games/museca/museca.h"
|
||||||
#include "hooks/avshook.h"
|
#include "hooks/avshook.h"
|
||||||
#include "hooks/audio/audio.h"
|
#include "hooks/audio/audio.h"
|
||||||
@@ -171,8 +174,6 @@ static bool check_dll(const std::string &model) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_msvcrt_args(int argc, char *argv[]);
|
|
||||||
|
|
||||||
void dump_button_bindings(std::vector<Button> *buttons);
|
void dump_button_bindings(std::vector<Button> *buttons);
|
||||||
void dump_analog_bindings();
|
void dump_analog_bindings();
|
||||||
|
|
||||||
@@ -248,6 +249,8 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
bool attach_qks = false;
|
bool attach_qks = false;
|
||||||
bool attach_mfg = false;
|
bool attach_mfg = false;
|
||||||
bool attach_pc = false;
|
bool attach_pc = false;
|
||||||
|
bool attach_udn = false;
|
||||||
|
bool attach_cardconnect = false;
|
||||||
bool attach_museca = false;
|
bool attach_museca = false;
|
||||||
bool show_cursor_if_no_touch = false;
|
bool show_cursor_if_no_touch = false;
|
||||||
|
|
||||||
@@ -784,6 +787,12 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
if (options[launcher::Options::LoadPCModule].value_bool()) {
|
if (options[launcher::Options::LoadPCModule].value_bool()) {
|
||||||
attach_pc = true;
|
attach_pc = true;
|
||||||
}
|
}
|
||||||
|
if (options[launcher::Options::LoadUDNModule].value_bool()) {
|
||||||
|
attach_udn = true;
|
||||||
|
}
|
||||||
|
if (options[launcher::Options::LoadCardConnectModule].value_bool()) {
|
||||||
|
attach_cardconnect = true;
|
||||||
|
}
|
||||||
if (options[launcher::Options::LoadMusecaModule].value_bool()) {
|
if (options[launcher::Options::LoadMusecaModule].value_bool()) {
|
||||||
attach_museca = true;
|
attach_museca = true;
|
||||||
}
|
}
|
||||||
@@ -876,7 +885,8 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
|
|
||||||
// printer overwrite
|
// printer overwrite
|
||||||
if (options[launcher::Options::SDVXPrinterOutputOverwrite].value_bool() ||
|
if (options[launcher::Options::SDVXPrinterOutputOverwrite].value_bool() ||
|
||||||
options[launcher::Options::LovePlusPrinterOutputOverwrite].value_bool()) {
|
options[launcher::Options::LovePlusPrinterOutputOverwrite].value_bool() ||
|
||||||
|
options[launcher::Options::CardConnectPrinterOutputOverwrite].value_bool()) {
|
||||||
games::shared::PRINTER_OVERWRITE_FILE = true;
|
games::shared::PRINTER_OVERWRITE_FILE = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -887,6 +897,9 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
for (auto &path : options[launcher::Options::LovePlusPrinterOutputPath].values_text()) {
|
for (auto &path : options[launcher::Options::LovePlusPrinterOutputPath].values_text()) {
|
||||||
games::shared::PRINTER_PATH.push_back(path);
|
games::shared::PRINTER_PATH.push_back(path);
|
||||||
}
|
}
|
||||||
|
for (auto &path : options[launcher::Options::CardConnectPrinterOutputPath].values_text()) {
|
||||||
|
games::shared::PRINTER_PATH.push_back(path);
|
||||||
|
}
|
||||||
|
|
||||||
// printer file format
|
// printer file format
|
||||||
for (auto &path : options[launcher::Options::SDVXPrinterOutputFormat].values_text()) {
|
for (auto &path : options[launcher::Options::SDVXPrinterOutputFormat].values_text()) {
|
||||||
@@ -895,17 +908,24 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
for (auto &path : options[launcher::Options::LovePlusPrinterOutputFormat].values_text()) {
|
for (auto &path : options[launcher::Options::LovePlusPrinterOutputFormat].values_text()) {
|
||||||
games::shared::PRINTER_FORMAT.push_back(path);
|
games::shared::PRINTER_FORMAT.push_back(path);
|
||||||
}
|
}
|
||||||
|
for (auto &format : options[launcher::Options::CardConnectPrinterOutputFormat].values_text()) {
|
||||||
|
games::shared::PRINTER_FORMAT.push_back(format);
|
||||||
|
}
|
||||||
|
|
||||||
// printer JPG quality
|
// printer JPG quality
|
||||||
if (options[launcher::Options::SDVXPrinterJPGQuality].is_active()) {
|
if (options[launcher::Options::SDVXPrinterJPGQuality].is_active()) {
|
||||||
games::shared::PRINTER_JPG_QUALITY = options[launcher::Options::SDVXPrinterJPGQuality].value_uint32();
|
games::shared::PRINTER_JPG_QUALITY = options[launcher::Options::SDVXPrinterJPGQuality].value_uint32();
|
||||||
} else if (options[launcher::Options::LovePlusPrinterJPGQuality].is_active()) {
|
} else if (options[launcher::Options::LovePlusPrinterJPGQuality].is_active()) {
|
||||||
games::shared::PRINTER_JPG_QUALITY = options[launcher::Options::LovePlusPrinterJPGQuality].value_uint32();
|
games::shared::PRINTER_JPG_QUALITY = options[launcher::Options::LovePlusPrinterJPGQuality].value_uint32();
|
||||||
|
} else if (options[launcher::Options::CardConnectPrinterJPGQuality].is_active()) {
|
||||||
|
games::shared::PRINTER_JPG_QUALITY =
|
||||||
|
options[launcher::Options::CardConnectPrinterJPGQuality].value_uint32();
|
||||||
}
|
}
|
||||||
|
|
||||||
// printer output clear
|
// printer output clear
|
||||||
if (options[launcher::Options::SDVXPrinterOutputClear].value_bool() ||
|
if (options[launcher::Options::SDVXPrinterOutputClear].value_bool() ||
|
||||||
options[launcher::Options::LovePlusPrinterOutputClear].value_bool()) {
|
options[launcher::Options::LovePlusPrinterOutputClear].value_bool() ||
|
||||||
|
options[launcher::Options::CardConnectPrinterOutputClear].value_bool()) {
|
||||||
games::shared::PRINTER_CLEAR = true;
|
games::shared::PRINTER_CLEAR = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1465,6 +1485,9 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
if (options[launcher::Options::CCJMouseTrackballWithToggle].value_bool()) {
|
if (options[launcher::Options::CCJMouseTrackballWithToggle].value_bool()) {
|
||||||
games::ccj::MOUSE_TRACKBALL_USE_TOGGLE = true;
|
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()) {
|
if (options[launcher::Options::CCJArgs].is_active()) {
|
||||||
games::ccj::CCJ_INJECT_ARGS = options[launcher::Options::CCJArgs].value_text();
|
games::ccj::CCJ_INJECT_ARGS = options[launcher::Options::CCJArgs].value_text();
|
||||||
}
|
}
|
||||||
@@ -1489,6 +1512,21 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
if (options[launcher::Options::PCKnobMode].value_bool()) {
|
if (options[launcher::Options::PCKnobMode].value_bool()) {
|
||||||
games::pc::PC_KNOB_MODE = true;
|
games::pc::PC_KNOB_MODE = true;
|
||||||
}
|
}
|
||||||
|
if (options[launcher::Options::UDNArgs].is_active()) {
|
||||||
|
games::udn::UDN_INJECT_ARGS = options[launcher::Options::UDNArgs].value_text();
|
||||||
|
}
|
||||||
|
if (options[launcher::Options::UDNNoIO].is_active()) {
|
||||||
|
games::udn::UDN_NO_IO = options[launcher::Options::UDNNoIO].value_bool();
|
||||||
|
}
|
||||||
|
if (options[launcher::Options::CardConnectArgs].is_active()) {
|
||||||
|
games::cardconnect::CARDCONNECT_INJECT_ARGS =
|
||||||
|
options[launcher::Options::CardConnectArgs].value_text();
|
||||||
|
}
|
||||||
|
games::cardconnect::PRINTER_DISABLED =
|
||||||
|
options[launcher::Options::CardConnectNoPrinter].value_bool();
|
||||||
|
if (options[launcher::Options::CardConnectPrinterDelay].value_bool()) {
|
||||||
|
games::cardconnect::PRINTER_SIMULATE_DELAY = true;
|
||||||
|
}
|
||||||
if (options[launcher::Options::spice2x_EnableSMXStage].value_bool()) {
|
if (options[launcher::Options::spice2x_EnableSMXStage].value_bool()) {
|
||||||
rawinput::ENABLE_SMX_STAGE = true;
|
rawinput::ENABLE_SMX_STAGE = true;
|
||||||
}
|
}
|
||||||
@@ -2303,6 +2341,24 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DANCE aROUND
|
||||||
|
if (check_dll("kamunity.dll") && fileutils::dir_exists("game/dancearound_Data")) {
|
||||||
|
avs::game::DLL_NAME = "kamunity.dll";
|
||||||
|
attach_io = true;
|
||||||
|
attach_udn = true;
|
||||||
|
launcher::signal::USE_VEH_WORKAROUND = true;
|
||||||
|
show_cursor_if_no_touch = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Card Connect
|
||||||
|
if (check_dll("kamunity.dll") && fileutils::file_exists("game/tcs.exe")) {
|
||||||
|
avs::game::DLL_NAME = "kamunity.dll";
|
||||||
|
attach_io = true;
|
||||||
|
attach_cardconnect = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Busou Shinki: Armored Princess Battle Conductor
|
// Busou Shinki: Armored Princess Battle Conductor
|
||||||
if (check_dll("kamunity.dll") && fileutils::file_exists("game/bsac_app.exe")) {
|
if (check_dll("kamunity.dll") && fileutils::file_exists("game/bsac_app.exe")) {
|
||||||
avs::game::DLL_NAME = "kamunity.dll";
|
avs::game::DLL_NAME = "kamunity.dll";
|
||||||
@@ -2468,6 +2524,15 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
avs::core::HEAP_SIZE = 536870912; // 512MB
|
avs::core::HEAP_SIZE = 536870912; // 512MB
|
||||||
games.push_back(new games::pc::PCGame());
|
games.push_back(new games::pc::PCGame());
|
||||||
}
|
}
|
||||||
|
if (attach_udn) {
|
||||||
|
avs::core::HEAP_SIZE = 1073741824; // 1GB
|
||||||
|
games.push_back(new games::udn::UDNGame());
|
||||||
|
}
|
||||||
|
if (attach_cardconnect) {
|
||||||
|
show_cursor_if_no_touch = true;
|
||||||
|
avs::core::set_default_heap_size("kamunity.dll");
|
||||||
|
games.push_back(new games::cardconnect::CardConnectGame());
|
||||||
|
}
|
||||||
|
|
||||||
// apply user heap size, if defined
|
// apply user heap size, if defined
|
||||||
if (user_heap_size > 0) {
|
if (user_heap_size > 0) {
|
||||||
@@ -2503,7 +2568,23 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
// log some DLLs found in path (purely for troubleshooting purposes to detect
|
// log some DLLs found in path (purely for troubleshooting purposes to detect
|
||||||
// dxvk, ForceD3D9On12, ifs_layeredfs, etc)
|
// dxvk, ForceD3D9On12, ifs_layeredfs, etc)
|
||||||
libutils::warn_if_dll_exists("d3d8.dll");
|
libutils::warn_if_dll_exists("d3d8.dll");
|
||||||
libutils::warn_if_dll_exists("d3d9.dll");
|
if (libutils::warn_if_dll_exists("d3d9.dll")) {
|
||||||
|
|
||||||
|
#if SPICE64
|
||||||
|
// dx9 subscreen games
|
||||||
|
if (avs::game::is_model({"LDJ", "KFC", "M39", "M32"})) {
|
||||||
|
log_warning(
|
||||||
|
"launcher",
|
||||||
|
"custom d3d9.dll detected - may cause graphics and touch-emulation issues");
|
||||||
|
deferredlogs::defer_error_messages({
|
||||||
|
"found custom d3d9.dll",
|
||||||
|
" custom d3d9.dll wrappers may cause subscreen and touch-emulation issues",
|
||||||
|
" if you encounter problems, close the game, remove the custom d3d9.dll and retry"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
libutils::warn_if_dll_exists("d3d10core.dll");
|
libutils::warn_if_dll_exists("d3d10core.dll");
|
||||||
libutils::warn_if_dll_exists("d3d11.dll");
|
libutils::warn_if_dll_exists("d3d11.dll");
|
||||||
libutils::warn_if_dll_exists("d3d12.dll");
|
libutils::warn_if_dll_exists("d3d12.dll");
|
||||||
@@ -2720,7 +2801,11 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
networkhook_init();
|
networkhook_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
update_msvcrt_args(argc, argv);
|
#if defined(_UCRT) || (defined(_MSC_VER) && _MSC_VER >= 1900)
|
||||||
|
log_info("launcher", "C runtime: UCRT");
|
||||||
|
#else
|
||||||
|
log_info("launcher", "C runtime: MSVCRT");
|
||||||
|
#endif
|
||||||
|
|
||||||
// load hooks
|
// load hooks
|
||||||
for (auto &hook : game_hooks) {
|
for (auto &hook : game_hooks) {
|
||||||
@@ -2961,54 +3046,6 @@ int main_implementation(int argc, char *argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/spice2x/spice2x.github.io/issues/264
|
|
||||||
// huge ugly hack to work around things that broke when MinGW switched from msvcrt to ucrt
|
|
||||||
// this is done to ensure that any DLL hooks that rely on msvcrt continue to work
|
|
||||||
void update_msvcrt_args(int argc, char *argv[]) {
|
|
||||||
#if defined(_UCRT)
|
|
||||||
auto msvc = LoadLibraryA("msvcrt.dll");
|
|
||||||
if (!msvc) {
|
|
||||||
log_warning("launcher", "failed to load msvcrt.dll");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get __argc
|
|
||||||
PINT32 argc_addr = (PINT32)GetProcAddress(msvc, "__argc");
|
|
||||||
if (!argc_addr) {
|
|
||||||
log_warning("launcher", "failed to find msvcrt!__argc");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if (*argc_addr == argc) {
|
|
||||||
log_warning("launcher", "msvcrt!__argc is already set");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (const std::exception &e) {
|
|
||||||
log_warning("launcher", "exception while reading msvcrt!_argc: {}", e.what());
|
|
||||||
}
|
|
||||||
|
|
||||||
// get __argv
|
|
||||||
PCHAR **argv_addr = (PCHAR **)GetProcAddress(msvc, "__argv");
|
|
||||||
if (!argv_addr) {
|
|
||||||
log_warning("launcher", "failed to find msvcrt!__argv");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update them
|
|
||||||
try {
|
|
||||||
log_info("launcher", "msvcrt!__argc value before: {}", *argc_addr);
|
|
||||||
*argc_addr = argc;
|
|
||||||
log_info("launcher", "msvcrt!__argc value after: {}", *argc_addr);
|
|
||||||
*argv_addr = argv;
|
|
||||||
} catch (const std::exception &e) {
|
|
||||||
log_warning("launcher", "exception while messing with msvcrt!_argc and _argv: {}", e.what());
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
log_misc("launcher", "not UCRT, skipping msvcrt!_argc / _argv hacks");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void dump_button_bindings(std::vector<Button> *buttons) {
|
void dump_button_bindings(std::vector<Button> *buttons) {
|
||||||
if (!buttons) {
|
if (!buttons) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1511,6 +1511,14 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = std::invoke([]()
|
|||||||
.game_name = "Polaris Chord",
|
.game_name = "Polaris Chord",
|
||||||
.category = "Advanced Game Options",
|
.category = "Advanced Game Options",
|
||||||
};
|
};
|
||||||
|
c[launcher::Options::LoadUDNModule] = {
|
||||||
|
.title = "Force Load DANCE aROUND Module",
|
||||||
|
.name = "udn",
|
||||||
|
.desc = "Manually enable DANCE aROUND module.",
|
||||||
|
.type = OptionType::Bool,
|
||||||
|
.game_name = "DANCE aROUND",
|
||||||
|
.category = "Advanced Game Options",
|
||||||
|
};
|
||||||
c[launcher::Options::LoadMusecaModule] = {
|
c[launcher::Options::LoadMusecaModule] = {
|
||||||
.title = "Force Load Museca Module",
|
.title = "Force Load Museca Module",
|
||||||
.name = "museca",
|
.name = "museca",
|
||||||
@@ -1519,6 +1527,14 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = std::invoke([]()
|
|||||||
.game_name = "Museca",
|
.game_name = "Museca",
|
||||||
.category = "Advanced Game Options",
|
.category = "Advanced Game Options",
|
||||||
};
|
};
|
||||||
|
c[launcher::Options::LoadCardConnectModule] = {
|
||||||
|
.title = "Force Load Card Connect Module",
|
||||||
|
.name = "cardconnect",
|
||||||
|
.desc = "Manually enable Card Connect module.",
|
||||||
|
.type = OptionType::Bool,
|
||||||
|
.game_name = "Card Connect",
|
||||||
|
.category = "Advanced Game Options",
|
||||||
|
};
|
||||||
c[launcher::Options::PathToModules] = {
|
c[launcher::Options::PathToModules] = {
|
||||||
.title = "Modules Folder Override",
|
.title = "Modules Folder Override",
|
||||||
.name = "modules",
|
.name = "modules",
|
||||||
@@ -2346,6 +2362,15 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = std::invoke([]()
|
|||||||
{"all", "basic + HID devices"},
|
{"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] = {
|
c[launcher::Options::QKSArgs] = {
|
||||||
.title = "QKS Arguments Override",
|
.title = "QKS Arguments Override",
|
||||||
.name = "qksargs",
|
.name = "qksargs",
|
||||||
@@ -2451,6 +2476,93 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = std::invoke([]()
|
|||||||
.game_name = "Polaris Chord",
|
.game_name = "Polaris Chord",
|
||||||
.category = "Game Options",
|
.category = "Game Options",
|
||||||
};
|
};
|
||||||
|
c[launcher::Options::UDNArgs] = {
|
||||||
|
.title = "DANCE aROUND Arguments Override",
|
||||||
|
.name = "udnargs",
|
||||||
|
.desc = "Command line arguments passed to the game.",
|
||||||
|
.type = OptionType::Text,
|
||||||
|
.setting_name = "",
|
||||||
|
.game_name = "DANCE aROUND",
|
||||||
|
.category = "Advanced Game Options",
|
||||||
|
};
|
||||||
|
c[launcher::Options::UDNNoIO] = {
|
||||||
|
.title = "DANCE aROUND Disable IO Emulation",
|
||||||
|
.name = "udnnoio",
|
||||||
|
.desc = "Disables BI2X hooks for DANCE aROUND.",
|
||||||
|
.type = OptionType::Bool,
|
||||||
|
.setting_name = "",
|
||||||
|
.game_name = "DANCE aROUND",
|
||||||
|
.category = "Advanced Game Options",
|
||||||
|
};
|
||||||
|
c[launcher::Options::CardConnectArgs] = {
|
||||||
|
.title = "Card Connect Arguments Override",
|
||||||
|
.name = "cardconnectargs",
|
||||||
|
.desc = "Command line arguments passed to the game.",
|
||||||
|
.type = OptionType::Text,
|
||||||
|
.setting_name = "",
|
||||||
|
.game_name = "Card Connect",
|
||||||
|
.category = "Advanced Game Options",
|
||||||
|
};
|
||||||
|
c[launcher::Options::CardConnectNoPrinter] = {
|
||||||
|
.title = "Card Connect Disable Printer Emulation",
|
||||||
|
.name = "cardconnectnoprinter",
|
||||||
|
.desc = "Leave the native printer driver unhooked for use with a real printer.",
|
||||||
|
.type = OptionType::Bool,
|
||||||
|
.game_name = "Card Connect",
|
||||||
|
.category = "Cab Peripherals",
|
||||||
|
};
|
||||||
|
c[launcher::Options::CardConnectPrinterDelay] = {
|
||||||
|
.title = "Card Connect Simulate Printer Delay",
|
||||||
|
.name = "cardconnectprinterdelay",
|
||||||
|
.desc = "Simulate real printing time: 73 seconds per card, plus hologram and coating delays "
|
||||||
|
"(up to 99 seconds). Off by default (5 seconds per card).",
|
||||||
|
.type = OptionType::Bool,
|
||||||
|
.game_name = "Card Connect",
|
||||||
|
.category = "Cab Peripherals",
|
||||||
|
};
|
||||||
|
c[launcher::Options::CardConnectPrinterOutputPath] = {
|
||||||
|
.title = "Card Connect Printer Output Path",
|
||||||
|
.name = "cardconnectprinterpath",
|
||||||
|
.desc = "Folder for front/back color images. Defaults to the working directory.",
|
||||||
|
.type = OptionType::Text,
|
||||||
|
.game_name = "Card Connect",
|
||||||
|
.category = "Cab Peripherals",
|
||||||
|
.picker = OptionPickerType::DirectoryPath,
|
||||||
|
};
|
||||||
|
c[launcher::Options::CardConnectPrinterOutputClear] = {
|
||||||
|
.title = "Card Connect Printer Output Clear",
|
||||||
|
.name = "cardconnectprinterclear",
|
||||||
|
.desc = "Delete saved front/back images in the output directory on startup.",
|
||||||
|
.type = OptionType::Bool,
|
||||||
|
.game_name = "Card Connect",
|
||||||
|
.category = "Cab Peripherals",
|
||||||
|
};
|
||||||
|
c[launcher::Options::CardConnectPrinterOutputOverwrite] = {
|
||||||
|
.title = "Card Connect Printer Output Overwrite",
|
||||||
|
.name = "cardconnectprinteroverwrite",
|
||||||
|
.desc = "Always overwrite the same front/back image pair.",
|
||||||
|
.type = OptionType::Bool,
|
||||||
|
.game_name = "Card Connect",
|
||||||
|
.category = "Cab Peripherals",
|
||||||
|
};
|
||||||
|
c[launcher::Options::CardConnectPrinterOutputFormat] = {
|
||||||
|
.title = "Card Connect Printer Output Format",
|
||||||
|
.name = "cardconnectprinterformat",
|
||||||
|
.desc = "File format for printer output. Defaults to PNG.",
|
||||||
|
.type = OptionType::Text,
|
||||||
|
.setting_name = "(png/bmp/tga/jpg)",
|
||||||
|
.game_name = "Card Connect",
|
||||||
|
.category = "Cab Peripherals",
|
||||||
|
};
|
||||||
|
c[launcher::Options::CardConnectPrinterJPGQuality] = {
|
||||||
|
.title = "Card Connect Printer JPG Quality",
|
||||||
|
.name = "cardconnectprinterjpgquality",
|
||||||
|
.desc = "Quality setting in percent if JPG format is used.",
|
||||||
|
.type = OptionType::Integer,
|
||||||
|
.setting_name = "(1-100)",
|
||||||
|
.game_name = "Card Connect",
|
||||||
|
.category = "Cab Peripherals",
|
||||||
|
};
|
||||||
c[launcher::Options::spice2x_LightsOverallBrightness] = {
|
c[launcher::Options::spice2x_LightsOverallBrightness] = {
|
||||||
.title = "Lights Brightness Adjustment",
|
.title = "Lights Brightness Adjustment",
|
||||||
.name = "sp2x-lights-brightness",
|
.name = "sp2x-lights-brightness",
|
||||||
|
|||||||
@@ -150,6 +150,8 @@ namespace launcher {
|
|||||||
LoadQKSModule,
|
LoadQKSModule,
|
||||||
LoadMFGModule,
|
LoadMFGModule,
|
||||||
LoadPCModule,
|
LoadPCModule,
|
||||||
|
LoadUDNModule,
|
||||||
|
LoadCardConnectModule,
|
||||||
LoadMusecaModule,
|
LoadMusecaModule,
|
||||||
PathToModules,
|
PathToModules,
|
||||||
ScreenshotFolder,
|
ScreenshotFolder,
|
||||||
@@ -239,6 +241,7 @@ namespace launcher {
|
|||||||
DisableAvsCache,
|
DisableAvsCache,
|
||||||
OutputPEB,
|
OutputPEB,
|
||||||
DumpSystemInfo,
|
DumpSystemInfo,
|
||||||
|
BCArgs,
|
||||||
QKSArgs,
|
QKSArgs,
|
||||||
CCJArgs,
|
CCJArgs,
|
||||||
CCJMouseTrackball,
|
CCJMouseTrackball,
|
||||||
@@ -250,6 +253,16 @@ namespace launcher {
|
|||||||
PCArgs,
|
PCArgs,
|
||||||
PCNoIO,
|
PCNoIO,
|
||||||
PCKnobMode,
|
PCKnobMode,
|
||||||
|
UDNArgs,
|
||||||
|
UDNNoIO,
|
||||||
|
CardConnectArgs,
|
||||||
|
CardConnectNoPrinter,
|
||||||
|
CardConnectPrinterDelay,
|
||||||
|
CardConnectPrinterOutputPath,
|
||||||
|
CardConnectPrinterOutputClear,
|
||||||
|
CardConnectPrinterOutputOverwrite,
|
||||||
|
CardConnectPrinterOutputFormat,
|
||||||
|
CardConnectPrinterJPGQuality,
|
||||||
spice2x_LightsOverallBrightness,
|
spice2x_LightsOverallBrightness,
|
||||||
spice2x_WindowBorder,
|
spice2x_WindowBorder,
|
||||||
spice2x_WindowSize,
|
spice2x_WindowSize,
|
||||||
|
|||||||
@@ -732,8 +732,12 @@ void eamuse_autodetect_game() {
|
|||||||
eamuse_set_game("Mahjong Fight Girl");
|
eamuse_set_game("Mahjong Fight Girl");
|
||||||
else if (avs::game::is_model("XIF"))
|
else if (avs::game::is_model("XIF"))
|
||||||
eamuse_set_game("Polaris Chord");
|
eamuse_set_game("Polaris Chord");
|
||||||
|
else if (avs::game::is_model("UDN"))
|
||||||
|
eamuse_set_game("DANCE aROUND");
|
||||||
else if (avs::game::is_model("NDD"))
|
else if (avs::game::is_model("NDD"))
|
||||||
eamuse_set_game("Silent Scope: Bone Eater");
|
eamuse_set_game("Silent Scope: Bone Eater");
|
||||||
|
else if (avs::game::is_model("TCS"))
|
||||||
|
eamuse_set_game("Card Connect");
|
||||||
else {
|
else {
|
||||||
log_warning("eamuse", "unknown game model: {}", avs::game::MODEL);
|
log_warning("eamuse", "unknown game model: {}", avs::game::MODEL);
|
||||||
eamuse_set_game("unknown");
|
eamuse_set_game("unknown");
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
namespace rawinput {
|
namespace rawinput {
|
||||||
|
|
||||||
static MidiNoteAlgorithm MIDI_NOTE_ALGORITHM = MidiNoteAlgorithm::V2;
|
static MidiNoteAlgorithm MIDI_NOTE_ALGORITHM = MidiNoteAlgorithm::V2;
|
||||||
|
bool DISABLE_MIDI = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rawinput::MidiNoteAlgorithm rawinput::get_midi_algorithm() {
|
rawinput::MidiNoteAlgorithm rawinput::get_midi_algorithm() {
|
||||||
@@ -37,6 +38,10 @@ void rawinput::set_midi_algorithm(rawinput::MidiNoteAlgorithm new_algo) {
|
|||||||
|
|
||||||
void rawinput::RawInputManager::midi_scan_start() {
|
void rawinput::RawInputManager::midi_scan_start() {
|
||||||
|
|
||||||
|
if (rawinput::DISABLE_MIDI) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// single-flight: only one scan runs at a time. if one is already running, set
|
// single-flight: only one scan runs at a time. if one is already running, set
|
||||||
// the pending flag so it rescans once more when it finishes - MIDI hotplug
|
// the pending flag so it rescans once more when it finishes - MIDI hotplug
|
||||||
// events fire while the slow enumeration is still going and must not be lost.
|
// events fire while the slow enumeration is still going and must not be lost.
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace rawinput {
|
|||||||
extern bool DUMP_HID_DEVICES_TO_LOG;
|
extern bool DUMP_HID_DEVICES_TO_LOG;
|
||||||
|
|
||||||
extern uint32_t MIDI_NOTE_SUSTAIN;
|
extern uint32_t MIDI_NOTE_SUSTAIN;
|
||||||
|
extern bool DISABLE_MIDI;
|
||||||
|
|
||||||
extern bool NAIVE_REQUIRE_FOCUS;
|
extern bool NAIVE_REQUIRE_FOCUS;
|
||||||
extern bool RAWINPUT_REQUIRE_FOCUS;
|
extern bool RAWINPUT_REQUIRE_FOCUS;
|
||||||
|
|||||||
@@ -248,6 +248,27 @@ typedef SPICE_SDK_STATUS_CODE (__cdecl spice_sdk_insert_coin_func)(
|
|||||||
uint8_t amount
|
uint8_t amount
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// get_coin_blocker (v0.6 and up)
|
||||||
|
// gets the current shared coin blocker state
|
||||||
|
// insert_coin bypasses the blocker regardless of this state
|
||||||
|
//
|
||||||
|
// blocked: receives true when coins are blocked, false when allowed
|
||||||
|
|
||||||
|
typedef SPICE_SDK_STATUS_CODE (__cdecl spice_sdk_get_coin_blocker_func)(
|
||||||
|
bool *blocked
|
||||||
|
);
|
||||||
|
|
||||||
|
// set_coin_blocker (v0.6 and up)
|
||||||
|
// sets the shared coin blocker state used by normal coin input
|
||||||
|
// this is not a persistent override; the game can change the state again
|
||||||
|
// insert_coin bypasses the blocker regardless of this state
|
||||||
|
//
|
||||||
|
// blocked: true to block coins, false to allow them
|
||||||
|
|
||||||
|
typedef SPICE_SDK_STATUS_CODE (__cdecl spice_sdk_set_coin_blocker_func)(
|
||||||
|
bool blocked
|
||||||
|
);
|
||||||
|
|
||||||
typedef struct SPICE_SDK_MODULE_INFO {
|
typedef struct SPICE_SDK_MODULE_INFO {
|
||||||
uint32_t size; // initialize to sizeof(SPICE_SDK_MODULE_INFO)
|
uint32_t size; // initialize to sizeof(SPICE_SDK_MODULE_INFO)
|
||||||
uintptr_t base; // loaded address, not the preferred PE image base
|
uintptr_t base; // loaded address, not the preferred PE image base
|
||||||
@@ -337,6 +358,18 @@ typedef SPICE_SDK_STATUS_CODE (__cdecl spice_sdk_register_d3d9_func)(
|
|||||||
void *userdata
|
void *userdata
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// hook_library (v0.5 and up)
|
||||||
|
//
|
||||||
|
// maps an exact LoadLibrary name to a module that the plugin has already loaded
|
||||||
|
//
|
||||||
|
// library_name: exact ANSI library name or path used by the target
|
||||||
|
// module: module handle returned by LoadLibrary; keep it loaded until shutdown
|
||||||
|
|
||||||
|
typedef SPICE_SDK_STATUS_CODE (__cdecl spice_sdk_hook_library_func)(
|
||||||
|
const char *library_name,
|
||||||
|
void *module
|
||||||
|
);
|
||||||
|
|
||||||
typedef struct SPICE_SDK_V0 {
|
typedef struct SPICE_SDK_V0 {
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
|
|
||||||
@@ -369,6 +402,11 @@ typedef struct SPICE_SDK_V0 {
|
|||||||
|
|
||||||
spice_sdk_register_d3d9_func *register_d3d9;
|
spice_sdk_register_d3d9_func *register_d3d9;
|
||||||
|
|
||||||
|
spice_sdk_hook_library_func *hook_library;
|
||||||
|
|
||||||
|
spice_sdk_get_coin_blocker_func *get_coin_blocker;
|
||||||
|
spice_sdk_set_coin_blocker_func *set_coin_blocker;
|
||||||
|
|
||||||
} SPICE_SDK_V0;
|
} SPICE_SDK_V0;
|
||||||
|
|
||||||
typedef void (__cdecl spice_sdk_destroy_callback_func)(
|
typedef void (__cdecl spice_sdk_destroy_callback_func)(
|
||||||
|
|||||||
@@ -1899,6 +1899,57 @@ typedef enum SPICE_SDK_POLARIS_CHORD_LIGHTS {
|
|||||||
PC_Light_Button12_B,
|
PC_Light_Button12_B,
|
||||||
} SPICE_SDK_POLARIS_CHORD_LIGHTS;
|
} SPICE_SDK_POLARIS_CHORD_LIGHTS;
|
||||||
|
|
||||||
|
// DANCE aROUND
|
||||||
|
|
||||||
|
typedef enum SPICE_SDK_DANCE_AROUND_BUTTONS {
|
||||||
|
UDN_Button_Service,
|
||||||
|
UDN_Button_Test,
|
||||||
|
UDN_Button_CoinMech,
|
||||||
|
UDN_Button_Start,
|
||||||
|
UDN_Button_Up,
|
||||||
|
UDN_Button_Down,
|
||||||
|
UDN_Button_Left,
|
||||||
|
UDN_Button_Right,
|
||||||
|
} SPICE_SDK_DANCE_AROUND_BUTTONS;
|
||||||
|
|
||||||
|
typedef enum SPICE_SDK_DANCE_AROUND_LIGHTS {
|
||||||
|
UDN_Light_CardReaderR,
|
||||||
|
UDN_Light_CardReaderG,
|
||||||
|
UDN_Light_CardReaderB,
|
||||||
|
UDN_Light_Start,
|
||||||
|
UDN_Light_Up,
|
||||||
|
UDN_Light_Down,
|
||||||
|
UDN_Light_Left,
|
||||||
|
UDN_Light_Right,
|
||||||
|
UDN_Light_TitleR,
|
||||||
|
UDN_Light_TitleG,
|
||||||
|
UDN_Light_TitleB,
|
||||||
|
UDN_Light_PillarRightTopR,
|
||||||
|
UDN_Light_PillarRightTopG,
|
||||||
|
UDN_Light_PillarRightTopB,
|
||||||
|
UDN_Light_PillarRightBottomR,
|
||||||
|
UDN_Light_PillarRightBottomG,
|
||||||
|
UDN_Light_PillarRightBottomB,
|
||||||
|
UDN_Light_StageLeftR,
|
||||||
|
UDN_Light_StageLeftG,
|
||||||
|
UDN_Light_StageLeftB,
|
||||||
|
UDN_Light_CabinetLeftR,
|
||||||
|
UDN_Light_CabinetLeftG,
|
||||||
|
UDN_Light_CabinetLeftB,
|
||||||
|
UDN_Light_PillarLeftTopR,
|
||||||
|
UDN_Light_PillarLeftTopG,
|
||||||
|
UDN_Light_PillarLeftTopB,
|
||||||
|
UDN_Light_PillarLeftBottomR,
|
||||||
|
UDN_Light_PillarLeftBottomG,
|
||||||
|
UDN_Light_PillarLeftBottomB,
|
||||||
|
UDN_Light_StageRightR,
|
||||||
|
UDN_Light_StageRightG,
|
||||||
|
UDN_Light_StageRightB,
|
||||||
|
UDN_Light_CabinetRightR,
|
||||||
|
UDN_Light_CabinetRightG,
|
||||||
|
UDN_Light_CabinetRightB,
|
||||||
|
} SPICE_SDK_DANCE_AROUND_LIGHTS;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "d3d9.h"
|
#include "d3d9.h"
|
||||||
#include "avs/game.h"
|
#include "avs/game.h"
|
||||||
#include "games/io.h"
|
#include "games/io.h"
|
||||||
|
#include "hooks/libraryhook.h"
|
||||||
#include "launcher/launcher.h"
|
#include "launcher/launcher.h"
|
||||||
#include "misc/eamuse.h"
|
#include "misc/eamuse.h"
|
||||||
#include "overlay/notifications.h"
|
#include "overlay/notifications.h"
|
||||||
@@ -35,9 +36,12 @@ static spice_sdk_insert_card_func sdk_insert_card;
|
|||||||
static spice_sdk_set_keypad_func sdk_set_keypad;
|
static spice_sdk_set_keypad_func sdk_set_keypad;
|
||||||
static spice_sdk_add_toast_func sdk_add_toast;
|
static spice_sdk_add_toast_func sdk_add_toast;
|
||||||
static spice_sdk_insert_coin_func sdk_insert_coin;
|
static spice_sdk_insert_coin_func sdk_insert_coin;
|
||||||
|
static spice_sdk_get_coin_blocker_func sdk_get_coin_blocker;
|
||||||
|
static spice_sdk_set_coin_blocker_func sdk_set_coin_blocker;
|
||||||
static spice_sdk_get_module_info_func sdk_get_module_info;
|
static spice_sdk_get_module_info_func sdk_get_module_info;
|
||||||
static spice_sdk_get_plugin_directory_func sdk_get_plugin_directory;
|
static spice_sdk_get_plugin_directory_func sdk_get_plugin_directory;
|
||||||
static spice_sdk_register_d3d9_func sdk_register_d3d9;
|
static spice_sdk_register_d3d9_func sdk_register_d3d9;
|
||||||
|
static spice_sdk_hook_library_func sdk_hook_library;
|
||||||
|
|
||||||
// DLLs
|
// DLLs
|
||||||
static int sdk_modules_count = 0;
|
static int sdk_modules_count = 0;
|
||||||
@@ -204,6 +208,19 @@ sdk_init(
|
|||||||
}
|
}
|
||||||
// end of 0.4
|
// end of 0.4
|
||||||
|
|
||||||
|
if (v0->size >= RTL_SIZEOF_THROUGH_FIELD(SPICE_SDK_V0, hook_library)) {
|
||||||
|
v0->hook_library = sdk_hook_library;
|
||||||
|
}
|
||||||
|
// end of 0.5
|
||||||
|
|
||||||
|
if (v0->size >= RTL_SIZEOF_THROUGH_FIELD(SPICE_SDK_V0, get_coin_blocker)) {
|
||||||
|
v0->get_coin_blocker = sdk_get_coin_blocker;
|
||||||
|
}
|
||||||
|
if (v0->size >= RTL_SIZEOF_THROUGH_FIELD(SPICE_SDK_V0, set_coin_blocker)) {
|
||||||
|
v0->set_coin_blocker = sdk_set_coin_blocker;
|
||||||
|
}
|
||||||
|
// end of 0.6
|
||||||
|
|
||||||
// any newer minor iterations will need to check the size
|
// any newer minor iterations will need to check the size
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -698,6 +715,30 @@ sdk_add_toast(
|
|||||||
return SPICE_SDK_STATUS_SUCCESS;
|
return SPICE_SDK_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SPICE_SDK_STATUS_CODE
|
||||||
|
__cdecl
|
||||||
|
sdk_hook_library(
|
||||||
|
const char *library_name,
|
||||||
|
void *module
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::shared_lock lock(sdk_global_mutex);
|
||||||
|
if (sdk_shutting_down || !sdk_initialized) {
|
||||||
|
return SPICE_SDK_STATUS_TOO_LATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!library_name || !library_name[0]) {
|
||||||
|
return SPICE_SDK_STATUS_INVALID_ARGUMENT_1;
|
||||||
|
}
|
||||||
|
if (!module) {
|
||||||
|
return SPICE_SDK_STATUS_INVALID_ARGUMENT_2;
|
||||||
|
}
|
||||||
|
|
||||||
|
libraryhook_hook_library(library_name, static_cast<HMODULE>(module));
|
||||||
|
// launcher::signal::attach enables library hooks before SDK entry points run.
|
||||||
|
return SPICE_SDK_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
SPICE_SDK_STATUS_CODE
|
SPICE_SDK_STATUS_CODE
|
||||||
__cdecl
|
__cdecl
|
||||||
sdk_insert_coin(
|
sdk_insert_coin(
|
||||||
@@ -715,4 +756,37 @@ sdk_insert_coin(
|
|||||||
return SPICE_SDK_STATUS_SUCCESS;
|
return SPICE_SDK_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SPICE_SDK_STATUS_CODE
|
||||||
|
__cdecl
|
||||||
|
sdk_get_coin_blocker(
|
||||||
|
bool *blocked
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::shared_lock lock(sdk_global_mutex);
|
||||||
|
if (!sdk_initialized) {
|
||||||
|
return SPICE_SDK_STATUS_TOO_LATE;
|
||||||
|
}
|
||||||
|
if (!blocked) {
|
||||||
|
return SPICE_SDK_STATUS_INVALID_ARGUMENT_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*blocked = eamuse_coin_get_block();
|
||||||
|
return SPICE_SDK_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPICE_SDK_STATUS_CODE
|
||||||
|
__cdecl
|
||||||
|
sdk_set_coin_blocker(
|
||||||
|
bool blocked
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::shared_lock lock(sdk_global_mutex);
|
||||||
|
if (!sdk_initialized) {
|
||||||
|
return SPICE_SDK_STATUS_TOO_LATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
eamuse_coin_set_block(blocked);
|
||||||
|
return SPICE_SDK_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sdk
|
} // namespace sdk
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "transform.h"
|
#include "transform.h"
|
||||||
|
|
||||||
|
#include "hooks/graphics/graphics.h"
|
||||||
#include "touch/touch.h"
|
#include "touch/touch.h"
|
||||||
#include "util/logging.h"
|
#include "util/logging.h"
|
||||||
|
|
||||||
@@ -141,6 +142,13 @@ namespace nativetouch::inject {
|
|||||||
end_mouse_contact(window);
|
end_mouse_contact(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SDVX accepts both mouse and touch on its windowed subscreen, causing duplicate input.
|
||||||
|
if (GRAPHICS_WINDOWED &&
|
||||||
|
window == SDVX_SUBSCREEN_WINDOW &&
|
||||||
|
message >= WM_MOUSEFIRST && message <= WM_MOUSELAST) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
#include "execexe.h"
|
#include "execexe.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "avs/game.h"
|
||||||
#include "util/logging.h"
|
#include "util/logging.h"
|
||||||
#include "util/libutils.h"
|
#include "util/libutils.h"
|
||||||
#include "util/utils.h"
|
#include "util/utils.h"
|
||||||
@@ -22,6 +25,23 @@ namespace execexe {
|
|||||||
static bool port_opened = false;
|
static bool port_opened = false;
|
||||||
static std::function<void()> deferred_function = nullptr;
|
static std::function<void()> deferred_function = nullptr;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static T resolve_export_thunk(T entry) {
|
||||||
|
// Some execexe builds expose ordinal-only five-byte near jumps backed
|
||||||
|
// only by INT3 padding. MinHook cannot construct a trampoline from
|
||||||
|
// those tiny export stubs, while the jump destination has a normal
|
||||||
|
// prologue.
|
||||||
|
const auto bytes = reinterpret_cast<const uint8_t *>(entry);
|
||||||
|
if (!bytes || bytes[0] != 0xE9) {
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t displacement = 0;
|
||||||
|
std::memcpy(&displacement, bytes + 1, sizeof(displacement));
|
||||||
|
return reinterpret_cast<T>(
|
||||||
|
const_cast<uint8_t *>(bytes + 5 + displacement));
|
||||||
|
}
|
||||||
|
|
||||||
static HANDLE WINAPI execexe_CreateFileA_hook(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
|
static HANDLE WINAPI execexe_CreateFileA_hook(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
|
||||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
|
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
|
||||||
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) {
|
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) {
|
||||||
@@ -42,7 +62,7 @@ namespace execexe {
|
|||||||
static HANDLE WINAPI execexe_CreateFileW_hook(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
|
static HANDLE WINAPI execexe_CreateFileW_hook(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
|
||||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
|
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
|
||||||
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) {
|
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) {
|
||||||
if (lpFileName == port_name && acio->open(lpFileName)) {
|
if (lpFileName == port_name) {
|
||||||
if (!port_opened) {
|
if (!port_opened) {
|
||||||
port_opened = acio->open(port_name.c_str());
|
port_opened = acio->open(port_name.c_str());
|
||||||
} else {
|
} else {
|
||||||
@@ -92,6 +112,13 @@ namespace execexe {
|
|||||||
execexe_CreateFileW = libutils::get_proc<decltype(&CreateFileW)>(execexe_module, MAKEINTRESOURCE(11));
|
execexe_CreateFileW = libutils::get_proc<decltype(&CreateFileW)>(execexe_module, MAKEINTRESOURCE(11));
|
||||||
execexe_PreLoadLibraries = libutils::get_proc<decltype(execexe_PreLoadLibraries)>(execexe_module, MAKEINTRESOURCE(48));
|
execexe_PreLoadLibraries = libutils::get_proc<decltype(execexe_PreLoadLibraries)>(execexe_module, MAKEINTRESOURCE(48));
|
||||||
|
|
||||||
|
if (avs::game::is_model("UDN")) {
|
||||||
|
execexe_CloseHandle = resolve_export_thunk(execexe_CloseHandle);
|
||||||
|
execexe_CreateFileA = resolve_export_thunk(execexe_CreateFileA);
|
||||||
|
execexe_CreateFileW = resolve_export_thunk(execexe_CreateFileW);
|
||||||
|
execexe_PreLoadLibraries = resolve_export_thunk(execexe_PreLoadLibraries);
|
||||||
|
}
|
||||||
|
|
||||||
auto module_path = libutils::module_file_name(nullptr);
|
auto module_path = libutils::module_file_name(nullptr);
|
||||||
module_path = module_path.replace_extension("");
|
module_path = module_path.replace_extension("");
|
||||||
module_path = module_path.replace_filename(module_path.filename().wstring() + L"_Data");
|
module_path = module_path.replace_filename(module_path.filename().wstring() + L"_Data");
|
||||||
@@ -105,6 +132,30 @@ namespace execexe {
|
|||||||
log_fatal("execexe", "deferred init function is already set");
|
log_fatal("execexe", "deferred init function is already set");
|
||||||
}
|
}
|
||||||
deferred_function = std::move(init_func);
|
deferred_function = std::move(init_func);
|
||||||
|
|
||||||
|
// DANCE aROUND calls PreLoadLibraries through kamunity's ordinal
|
||||||
|
// import. Hook that call site directly: execexe can be loaded in the
|
||||||
|
// low address range immediately next to the AVS heap, where MinHook
|
||||||
|
// may be unable to reserve a nearby trampoline page.
|
||||||
|
if (avs::game::is_model("UDN")) {
|
||||||
|
const auto kamunity_module = GetModuleHandleW(L"kamunity.dll");
|
||||||
|
const auto imported_pre_load_libraries = kamunity_module ? detour::iat_try_ordinal(
|
||||||
|
"execexe.dll",
|
||||||
|
48,
|
||||||
|
execexe_PreLoadLibraries_hook,
|
||||||
|
kamunity_module) : nullptr;
|
||||||
|
if (imported_pre_load_libraries) {
|
||||||
|
execexe_PreLoadLibraries = reinterpret_cast<decltype(execexe_PreLoadLibraries)>(
|
||||||
|
imported_pre_load_libraries);
|
||||||
|
log_info("execexe", "hooked PreLoadLibraries through kamunity import");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
detour::trampoline(execexe_PreLoadLibraries,
|
||||||
|
execexe_PreLoadLibraries_hook, &execexe_PreLoadLibraries);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
detour::trampoline("execexe.dll", MAKEINTRESOURCE(48),
|
detour::trampoline("execexe.dll", MAKEINTRESOURCE(48),
|
||||||
execexe_PreLoadLibraries_hook, &execexe_PreLoadLibraries);
|
execexe_PreLoadLibraries_hook, &execexe_PreLoadLibraries);
|
||||||
}
|
}
|
||||||
@@ -117,6 +168,16 @@ namespace execexe {
|
|||||||
|
|
||||||
port_name = portName;
|
port_name = portName;
|
||||||
acio = acioHandle;
|
acio = acioHandle;
|
||||||
|
if (avs::game::is_model("UDN")) {
|
||||||
|
detour::trampoline_try(execexe_CloseHandle,
|
||||||
|
execexe_CloseHandle_hook, &execexe_CloseHandle);
|
||||||
|
detour::trampoline_try(execexe_CreateFileA,
|
||||||
|
execexe_CreateFileA_hook, &execexe_CreateFileA);
|
||||||
|
detour::trampoline_try(execexe_CreateFileW,
|
||||||
|
execexe_CreateFileW_hook, &execexe_CreateFileW);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
detour::trampoline_try("execexe.dll", MAKEINTRESOURCE(7),
|
detour::trampoline_try("execexe.dll", MAKEINTRESOURCE(7),
|
||||||
execexe_CloseHandle_hook, &execexe_CloseHandle);
|
execexe_CloseHandle_hook, &execexe_CloseHandle);
|
||||||
detour::trampoline_try("execexe.dll", MAKEINTRESOURCE(9),
|
detour::trampoline_try("execexe.dll", MAKEINTRESOURCE(9),
|
||||||
@@ -183,6 +244,10 @@ namespace execexe {
|
|||||||
HMODULE module = get_module(dll);
|
HMODULE module = get_module(dll);
|
||||||
FARPROC proc = get_proc(module, func);
|
FARPROC proc = get_proc(module, func);
|
||||||
|
|
||||||
|
if (avs::game::is_model("UDN")) {
|
||||||
|
// The existing detour helper reads *orig as the target to enable.
|
||||||
|
*orig = reinterpret_cast<void *>(proc);
|
||||||
|
}
|
||||||
return detour::trampoline(
|
return detour::trampoline(
|
||||||
reinterpret_cast<void *>(proc),
|
reinterpret_cast<void *>(proc),
|
||||||
hook,
|
hook,
|
||||||
@@ -201,6 +266,9 @@ namespace execexe {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (avs::game::is_model("UDN")) {
|
||||||
|
*orig = reinterpret_cast<void *>(proc);
|
||||||
|
}
|
||||||
return detour::trampoline(
|
return detour::trampoline(
|
||||||
reinterpret_cast<void *>(proc),
|
reinterpret_cast<void *>(proc),
|
||||||
hook,
|
hook,
|
||||||
|
|||||||
@@ -369,61 +369,102 @@ void libutils::check_duplicate_dlls() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void libutils::warn_if_dll_exists(const std::string &file_name) {
|
bool libutils::warn_if_dll_exists(const std::string &file_name) {
|
||||||
if (fileutils::file_exists(MODULE_PATH / file_name)) {
|
|
||||||
log_info("libutils", "found user-supplied {} in modules directory", file_name);
|
|
||||||
libutils::print_dll_info(MODULE_PATH / file_name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto &spice_bin_path = libutils::module_file_name(nullptr).parent_path();
|
const auto &spice_bin_path = libutils::module_file_name(nullptr).parent_path();
|
||||||
|
bool found = false;
|
||||||
if (fileutils::file_exists(spice_bin_path / file_name)) {
|
if (fileutils::file_exists(spice_bin_path / file_name)) {
|
||||||
log_info("libutils", "found user-supplied {} next to spice executable path", file_name);
|
log_info("libutils", "found user-supplied {} next to spice executable path", file_name);
|
||||||
libutils::print_dll_info(spice_bin_path / file_name);
|
libutils::print_dll_info(spice_bin_path / file_name);
|
||||||
return;
|
found = true;
|
||||||
}
|
}
|
||||||
|
if (MODULE_PATH != spice_bin_path && fileutils::file_exists(MODULE_PATH / file_name)) {
|
||||||
|
log_info("libutils", "found user-supplied {} in modules directory", file_name);
|
||||||
|
libutils::print_dll_info(MODULE_PATH / file_name);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
void libutils::print_dll_info(std::filesystem::path filename) {
|
void libutils::print_dll_info(std::filesystem::path filename) {
|
||||||
DWORD handle;
|
std::string company_name;
|
||||||
|
std::string product_name;
|
||||||
|
std::string version_str;
|
||||||
|
auto print_summary = [&]() {
|
||||||
|
log_info(
|
||||||
|
"libutils",
|
||||||
|
"DLL info for {}: CompanyName = {}, ProductName = {}, Version = {}, Path = {}",
|
||||||
|
filename.filename(),
|
||||||
|
company_name.empty() ? "?" : company_name,
|
||||||
|
product_name.empty() ? "?" : product_name,
|
||||||
|
version_str.empty() ? "?" : version_str,
|
||||||
|
filename);
|
||||||
|
};
|
||||||
|
|
||||||
|
DWORD handle = 0;
|
||||||
const auto size = GetFileVersionInfoSizeW(filename.wstring().c_str(), &handle);
|
const auto size = GetFileVersionInfoSizeW(filename.wstring().c_str(), &handle);
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
log_debug(
|
const auto error = GetLastError();
|
||||||
|
log_misc(
|
||||||
"libutils",
|
"libutils",
|
||||||
"GetFileVersionInfoSizeA failed for {}: {}",
|
"GetFileVersionInfoSizeW failed for {}: Win32 error {}; "
|
||||||
filename.filename(),
|
"DLL may have no version resource",
|
||||||
get_last_error_string());
|
filename,
|
||||||
|
error);
|
||||||
|
print_summary();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = util::make_unique_plain<VOID>(size);
|
auto data = util::make_unique_plain<VOID>(size);
|
||||||
if (!GetFileVersionInfoW(filename.wstring().c_str(), handle, size, data.get())) {
|
if (!GetFileVersionInfoW(filename.wstring().c_str(), handle, size, data.get())) {
|
||||||
log_debug(
|
const auto error = GetLastError();
|
||||||
|
log_misc(
|
||||||
"libutils",
|
"libutils",
|
||||||
"GetFileVersionInfoA failed for {}: {}",
|
"GetFileVersionInfoW failed for {}: Win32 error {}",
|
||||||
filename.filename(),
|
filename,
|
||||||
get_last_error_string());
|
error);
|
||||||
|
print_summary();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VS_FIXEDFILEINFO *fixed_info = nullptr;
|
||||||
|
UINT fixed_size = 0;
|
||||||
|
if (VerQueryValueW(data.get(), L"\\", (LPVOID*)&fixed_info, &fixed_size) &&
|
||||||
|
fixed_info != nullptr && fixed_size >= sizeof(*fixed_info) &&
|
||||||
|
fixed_info->dwSignature == 0xFEEF04BD) {
|
||||||
|
version_str = fmt::format(
|
||||||
|
"{}.{}.{}.{}",
|
||||||
|
HIWORD(fixed_info->dwFileVersionMS),
|
||||||
|
LOWORD(fixed_info->dwFileVersionMS),
|
||||||
|
HIWORD(fixed_info->dwFileVersionLS),
|
||||||
|
LOWORD(fixed_info->dwFileVersionLS));
|
||||||
|
log_info("libutils", "Fixed file version for {}: {}", filename.filename(), version_str);
|
||||||
|
} else {
|
||||||
|
log_misc("libutils", "Missing or invalid fixed version info for {}", filename);
|
||||||
|
}
|
||||||
|
|
||||||
struct LANGANDCODEPAGE {
|
struct LANGANDCODEPAGE {
|
||||||
WORD wLanguage;
|
WORD wLanguage;
|
||||||
WORD wCodePage;
|
WORD wCodePage;
|
||||||
} *lpTranslate = nullptr;
|
} *lpTranslate = nullptr;
|
||||||
|
|
||||||
UINT cbTranslate = 0;
|
UINT cbTranslate = 0;
|
||||||
if (!VerQueryValueA(data.get(), "\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &cbTranslate)) {
|
if (!VerQueryValueW(
|
||||||
log_debug(
|
data.get(), L"\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &cbTranslate)) {
|
||||||
|
log_misc(
|
||||||
"libutils",
|
"libutils",
|
||||||
"VerQueryValueA failed for {}: {}",
|
"VerQueryValueW(\\VarFileInfo\\Translation) failed for {}",
|
||||||
filename.filename(),
|
filename);
|
||||||
get_last_error_string());
|
print_summary();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (cbTranslate == 0 || lpTranslate == nullptr) {
|
if (cbTranslate < sizeof(*lpTranslate) ||
|
||||||
log_debug(
|
cbTranslate % sizeof(*lpTranslate) != 0 || lpTranslate == nullptr) {
|
||||||
|
log_misc(
|
||||||
"libutils",
|
"libutils",
|
||||||
"VerQueryValueA returned invalid results for {}",
|
"Invalid version translation table for {} ({} bytes)",
|
||||||
filename.filename());
|
filename,
|
||||||
|
cbTranslate);
|
||||||
|
print_summary();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,36 +483,46 @@ void libutils::print_dll_info(std::filesystem::path filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StringFileInfo helper
|
// StringFileInfo helper
|
||||||
auto query_string = [&](const char* key) -> std::string {
|
auto query_string = [&](const char* key, WORD language, WORD page) -> std::string {
|
||||||
std::string subBlock = fmt::format(
|
std::string subBlock = fmt::format(
|
||||||
"\\StringFileInfo\\{:04x}{:04x}\\{}",
|
"\\StringFileInfo\\{:04x}{:04x}\\{}",
|
||||||
lang, codepage, key
|
language, page, key
|
||||||
);
|
);
|
||||||
|
|
||||||
char* value = nullptr;
|
wchar_t *value = nullptr;
|
||||||
UINT size_out = 0;
|
UINT size_out = 0;
|
||||||
|
|
||||||
if (VerQueryValueA(data.get(), subBlock.c_str(), (LPVOID*)&value, &size_out) && value) {
|
const auto wide_sub_block = s2ws(subBlock);
|
||||||
return value;
|
if (VerQueryValueW(data.get(), wide_sub_block.c_str(), (LPVOID*)&value, &size_out) &&
|
||||||
|
value != nullptr && size_out > 0 && value[size_out - 1] == L'\0') {
|
||||||
|
return fmt::detail::to_utf8<wchar_t>(
|
||||||
|
std::wstring_view(value, size_out - 1),
|
||||||
|
fmt::detail::to_utf8_error_policy::replace).str();
|
||||||
}
|
}
|
||||||
log_debug(
|
log_misc(
|
||||||
"libutils",
|
"libutils",
|
||||||
"VerQueryValueA({}) failed for {}: {}",
|
"Missing or invalid version string {} for {}",
|
||||||
subBlock,
|
subBlock,
|
||||||
filename.filename(),
|
filename);
|
||||||
get_last_error_string());
|
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto company_name = query_string("CompanyName");
|
auto query_translations = [&](const char *key) {
|
||||||
const auto product_name = query_string("ProductName");
|
auto value = query_string(key, lang, codepage);
|
||||||
const auto version_str = query_string("FileVersion");
|
for (UINT i = 0; value.empty() && i < cbTranslate / sizeof(*lpTranslate); i++) {
|
||||||
|
const auto &translation = lpTranslate[i];
|
||||||
|
if (translation.wLanguage != lang || translation.wCodePage != codepage) {
|
||||||
|
value = query_string(key, translation.wLanguage, translation.wCodePage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
log_info(
|
company_name = query_translations("CompanyName");
|
||||||
"libutils",
|
product_name = query_translations("ProductName");
|
||||||
"DLL info for {}: CompanyName = {}, ProductName = {}, Version = {}",
|
const auto string_version = query_translations("FileVersion");
|
||||||
filename.filename(),
|
if (!string_version.empty()) {
|
||||||
company_name.empty() ? "?" : company_name,
|
version_str = string_version;
|
||||||
product_name.empty() ? "?" : product_name,
|
}
|
||||||
version_str.empty() ? "?" : version_str);
|
print_summary();
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ namespace libutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void check_duplicate_dlls();
|
void check_duplicate_dlls();
|
||||||
void warn_if_dll_exists(const std::string &file_name);
|
bool warn_if_dll_exists(const std::string &file_name);
|
||||||
|
|
||||||
// get module handle helpers
|
// get module handle helpers
|
||||||
HMODULE get_module(const char *module_name);
|
HMODULE get_module(const char *module_name);
|
||||||
|
|||||||
Reference in new issue
Block a user