1
0
mirror of synced 2025-02-17 11:18:32 +01:00

add mercuryio

This commit is contained in:
xpeng 2022-07-29 20:17:22 +02:00
parent 9919fabcf6
commit 593fe01d13
5 changed files with 283 additions and 3 deletions

View File

@ -8,21 +8,26 @@ A VR arcade emulator
- Successfully initialized touch
- Successfully send touch signal
- Successfully enabled Freeplay and tested the touch signal in game
- Successfully got led data from game
## Current issue
- capture display white screen issue (set game priority in taskmanager to real-time may solve)
## Quick guide
- Port binding is same as my other repo MaiDXR
- Port binding is same as my other repo [MaiDXR](https://github.com/xiaopeng12138/MaiDXR)
- add "[touch] enable=0" to ini file
- The led requiere a special fork of the tools. Currently it's under my fork of the tools and it's not in the github! You need to build by your self and replace the things inside mercuryio folder whit the one under this repo.
## Configuration
A ``config.json`` is automatically created in the WACVR root on startup
- ``useSkybox``: Enable Skybox and hide the room (Default: false)
- ``Skybox``: the current skybox selected for use (Default: 0)
- ``Height``: the offset from default height that the player is moved (Default: 0.0)
- ``HandSize``: the size of hands (Default: 7.0)
- ``HandPosition``: the offset of hand position (Default: [1.0, 1.0, -3.0],)
- ``ThirdPerson``: whether or not the camera is in third person (Default: true)
- ``CaptureMode``: the method uWindowCapture will use for window capture
- ``0``: PrintScreen
@ -32,7 +37,12 @@ A ``config.json`` is automatically created in the WACVR root on startup
- ``CaptureFramerate``: the framerate to capture the game at (Default: 60)
- ``CaptureDesktop``: whether to capture the specific window or a full monitor
- ``CaptureDesktopNumber``: the monitor to capture if you're capturing a full monitor
- ``PhysicFPS``: the unity physic interval, lower value can prevent false touch but will also cause higher latency (Default: 90)
- ``useIPC``: the touch panle LED light mode, requiere mercuryio and new tools (Default: true)
## Why this repo now?
## When release?
- currently you can get the latest build in actions (in artifacts)
- the first release version will release after 8.31
I don't have much time and enough skills to make this project by myself. I'm not familiar with Unreal Engine etc. So I want this project to be a community project.
Huge thanks to everyone that helped this project!
If you want to add any function pls commit PR, I will accept it as soon as possible!

164
mercuryio/mercuryio.c Normal file
View File

@ -0,0 +1,164 @@
#include <windows.h>
#include <process.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <process.h>
#include "mercuryio/mercuryio.h"
#include "mercuryio/config.h"
#include "mercuryhook/elisabeth.h"
#include "util/dprintf.h"
static unsigned int __stdcall mercury_io_touch_thread_proc(void *ctx);
static uint8_t mercury_opbtn;
static uint8_t mercury_gamebtn;
static struct mercury_io_config mercury_io_cfg;
static bool mercury_io_touch_stop_flag;
static HANDLE mercury_io_touch_thread;
struct IPCMemoryInfo
{
uint8_t testBtn;
uint8_t serviceBtn;
uint8_t coinBtn;
uint8_t cardRead;
uint8_t TouchIoStatus[240];
uint8_t RGBAData[480 * 4];
};
typedef struct IPCMemoryInfo IPCMemoryInfo;
static HANDLE FileMappingHandle;
IPCMemoryInfo* FileMapping;
void initSharedMemory()
{
dprintf("initSharedMemory\n");
dprintf("SharedMemory Size: %d\n", (char)sizeof(IPCMemoryInfo));
if (FileMapping)
return;
if ((FileMappingHandle = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, sizeof(IPCMemoryInfo), "Local\\WACVR_SHARED_BUFFER")) == 0)
{
dprintf("FileMappingHandle Error\n");
return;
}
if ((FileMapping = (IPCMemoryInfo*)MapViewOfFile(FileMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(IPCMemoryInfo))) == 0)
{
dprintf("FileMapping Error\n");
return;
}
memset(FileMapping, 0, sizeof(IPCMemoryInfo));
SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_CONTINUOUS);
}
uint16_t mercury_io_get_api_version(void)
{
return 0x0100;
}
HRESULT mercury_io_init(void)
{
mercury_io_config_load(&mercury_io_cfg, L".\\segatools.ini");
initSharedMemory();
return S_OK;
}
HRESULT mercury_io_poll(void)
{
mercury_opbtn = 0;
mercury_gamebtn = 0;
if ((FileMapping && FileMapping->testBtn) || GetAsyncKeyState(mercury_io_cfg.vk_test)) {
mercury_opbtn |= MERCURY_IO_OPBTN_TEST;
}
if ((FileMapping && FileMapping->serviceBtn) || GetAsyncKeyState(mercury_io_cfg.vk_service)) {
mercury_opbtn |= MERCURY_IO_OPBTN_SERVICE;
}
if ((FileMapping && FileMapping->coinBtn) || GetAsyncKeyState(mercury_io_cfg.vk_coin)) {
mercury_opbtn |= MERCURY_IO_OPBTN_COIN;
}
if (GetAsyncKeyState(mercury_io_cfg.vk_vol_up)) {
mercury_gamebtn |= MERCURY_IO_GAMEBTN_VOL_UP;
}
if (GetAsyncKeyState(mercury_io_cfg.vk_vol_down)) {
mercury_gamebtn |= MERCURY_IO_GAMEBTN_VOL_DOWN;
}
return S_OK;
}
void mercury_io_get_opbtns(uint8_t *opbtn)
{
if (opbtn != NULL) {
*opbtn = mercury_opbtn;
}
}
void mercury_io_get_gamebtns(uint8_t *gamebtn)
{
if (gamebtn != NULL) {
*gamebtn = mercury_gamebtn;
}
}
HRESULT mercury_io_touch_init(void)
{
return S_OK;
}
void mercury_io_touch_start(mercury_io_touch_callback_t callback)
{
if (mercury_io_touch_thread != NULL) {
return;
}
mercury_io_touch_thread = (HANDLE) _beginthreadex(
NULL,
0,
mercury_io_touch_thread_proc,
callback,
0,
NULL
);
}
void mercury_io_touch_set_leds(struct led_data data)
{
if (FileMapping)
{
memcpy(FileMapping->RGBAData, data.rgba, 480 * 4);
}
//for (size_t i = 0; i < 32; i++)
// dprintf("LED.R: %d\n", data.rgba[i].red);
}
static unsigned int __stdcall mercury_io_touch_thread_proc(void *ctx)
{
mercury_io_touch_callback_t callback;
bool cellPressed[240];
callback = ctx;
while (!mercury_io_touch_stop_flag) {
if (FileMapping) {
memcpy(cellPressed, FileMapping->TouchIoStatus, 240);
}
callback(cellPressed);
Sleep(1);
}
return 0;
}

11
mercuryio/mercuryio.def Normal file
View File

@ -0,0 +1,11 @@
LIBRARY mercuryio
EXPORTS
mercury_io_get_api_version
mercury_io_init
mercury_io_poll
mercury_io_get_opbtns
mercury_io_get_gamebtns
mercury_io_touch_init
mercury_io_touch_start
mercury_io_touch_set_leds

70
mercuryio/mercuryio.h Normal file
View File

@ -0,0 +1,70 @@
#pragma once
#include <windows.h>
#include <stdint.h>
#include "mercuryhook/elisabeth.h"
enum {
MERCURY_IO_OPBTN_TEST = 0x01,
MERCURY_IO_OPBTN_SERVICE = 0x02,
MERCURY_IO_OPBTN_COIN = 0x04,
};
enum {
MERCURY_IO_GAMEBTN_VOL_UP = 0x01,
MERCURY_IO_GAMEBTN_VOL_DOWN = 0x02,
};
typedef void (*mercury_io_touch_callback_t)(const bool *state);
/* Get the version of the Wacca IO API that this DLL supports. This
function should return a positive 16-bit integer, where the high byte is
the major version and the low byte is the minor version (as defined by the
Semantic Versioning standard).
The latest API version as of this writing is 0x0100. */
uint16_t mercury_io_get_api_version(void);
/* Initialize the IO DLL. This is the second function that will be called on
your DLL, after mercury_io_get_api_version.
All subsequent calls to this API may originate from arbitrary threads.
Minimum API version: 0x0100 */
HRESULT mercury_io_init(void);
/* Send any queued outputs (of which there are currently none, though this may
change in subsequent API versions) and retrieve any new inputs.
Minimum API version: 0x0100 */
HRESULT mercury_io_poll(void);
/* Get the state of the cabinet's operator buttons as of the last poll. See
MERCURY_IO_OPBTN enum above: this contains bit mask definitions for button
states returned in *opbtn. All buttons are active-high.
Minimum API version: 0x0100 */
void mercury_io_get_opbtns(uint8_t *opbtn);
/* Get the state of the cabinet's gameplay buttons as of the last poll. See
MERCURY_IO_GAMEBTN enum above for bit mask definitions. Inputs are split into
a left hand side set of inputs and a right hand side set of inputs: the bit
mappings are the same in both cases.
All buttons are active-high, even though some buttons' electrical signals
on a real cabinet are active-low.
Minimum API version: 0x0100 */
void mercury_io_get_gamebtns(uint8_t *gamebtn);
HRESULT mercury_io_touch_init(void);
void mercury_io_touch_start(mercury_io_touch_callback_t callback);
void mercury_io_touch_set_leds(struct led_data data);

25
mercuryio/meson.build Normal file
View File

@ -0,0 +1,25 @@
mercuryio_lib = static_library(
'mercuryio',
name_prefix : '',
include_directories : inc,
implicit_include_directories : false,
c_pch : '../precompiled.h',
link_with : [
util_lib,
],
sources : [
'mercuryio.c',
'mercuryio.h',
'config.c',
'config.h',
],
)
shared_library(
'mercuryio',
name_prefix : '',
vs_module_defs : 'mercuryio.def',
link_with : [
mercuryio_lib,
],
)