mirror of
https://gitea.tendokyu.moe/Hay1tsme/segatools.git
synced 2026-05-06 13:25:35 -05:00
This adds full support for the Taisen series of games, namely Sangokushi Taisen and Eiketsu Taisen. Games added: * Sangokushi Taisen (SDDD) * Eiketsu Taisen (SDGY) Devices added: * CHC-320 printer (SGT) * "Printer camera" (SGT, unsure what this actually really is) * CX-7000 printer (EKT) * Y3CR BD SIE F720MM (SGT, EKT) Notable changes in the codebase: * Renamed everything printer specific to seperate between CHC and CX. * Many new function and registry hooks were added across the board. * An error is now logged when segatools.ini (or the path in `SEGATOOLS_CONFIG_PATH`) cannot be found. * Netenv now redirects UDP broadcasts targeted at the subnet that is specified in the keychip configuration. The terminal announces it's presence by broadcasting UDP to 192.168.189.255, this will be redirected to 255.255.255.255. * Vfs now seperates between absolute and relative paths in `vfs_fixup_path` via an environment variable called `SEGATOOLS_VFS_RELATIVE_PATH`. This is needed because amcapture accesses files as workingdirectory-relative. * The Y3 board emulation has support for external Y3 I/O dlls. The default implementation (y3ws) that comes with this is a websocket implementation. The docs are available under `doc\y3ws.txt` and a sample card player .html file is under `dist\ekt\card_player.html`. I already know one person that is hosting a massively improved version of it. * For websockets, my own websocket implementation is used as a subproject (MIT license): https://github.com/akechi-haruka/cwinwebsocket * For JSON, cJSON was embedded (MIT license): https://github.com/DaveGamble/cJSON * y3ws reads all printed cards from `DEVICE\print` by default including card back sides. It's up to the client to merge or skip them. Remarks: * SGT takes ~8 minutes to load. This seems to be intentional. * SGT uses some weird TCP network implementation like IDZ. I have not bothered reversing that yet and I have confirmed everything working from the test menu. * EKT will throw a network error if no terminal is found. You must run the terminal on another computer to be able to launch the satellite. * EKT has a very bizzare speed glitch that will speed up the ingame unit movement by several 1000% and also slows down cutscene animations by 90%. When this effect is active, you also take a ton more damage than usual. I do not know what causes this and it seems PC specific. * EKT is very stutter sensitive and will throw error 6401 (I/O timeout) at random when trying to alt+tab or have other things running. * EKT features a livestream system called Enbu (or "Dojo Upload"). While you are in a match, regardless of vs. AI or another player, the game will record your screen and live-stream it to the Enbu server as defined by the game server's startup response. The application responsible for that, "AM Capture" will not limit it's recording to the game window, but also anything that overlays the game window (notifications, popups, alt+tabbed windows, web browsers, etc). Since this is live-streamed, killing the process will have no effect afterwards, as the frames showing unwanted things will already have been transmitted. To make people aware of this, a one-time dialog message will pop up when starting EKT. The flag for that is stored in the DEVICE folder. Closes #25. Co-authored-by: Dniel97 <Dniel97@noreply.gitea.tendokyu.moe> Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/segatools/pulls/85 Co-authored-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> Co-committed-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com>
164 lines
4.2 KiB
C
164 lines
4.2 KiB
C
#include <assert.h>
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <wchar.h>
|
|
|
|
#include "platform/clock.h"
|
|
|
|
#include "hook/table.h"
|
|
#include "hook/procaddr.h"
|
|
#include "hook/iohook.h"
|
|
|
|
#include "hooklib/dll.h"
|
|
#include "hooklib/path.h"
|
|
#include "hooklib/printer_chc.h"
|
|
#include "hooklib/reg.h"
|
|
#include "hooklib/touch.h"
|
|
#include "hooklib/serial.h"
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
#include "doorstop.h"
|
|
#include "hook.h"
|
|
|
|
static bool unity_hook_initted;
|
|
static struct unity_config unity_config;
|
|
|
|
static const wchar_t *target_modules[] = {
|
|
L"mono.dll",
|
|
L"mono-2.0-bdwgc.dll",
|
|
L"cri_ware_unity.dll",
|
|
L"amdaemon_api.dll",
|
|
L"SerialPortAPI.dll",
|
|
L"C300usb.dll",
|
|
L"C300FWDLusb.dll",
|
|
L"apmled.dll",
|
|
L"HKBSys_api.dll",
|
|
L"amptw.dll",
|
|
L"apmmount.dll",
|
|
L"abaasgs.dll",
|
|
L"AVProVideo.dll",
|
|
L"Audio360.dll",
|
|
};
|
|
|
|
static const size_t target_modules_len = _countof(target_modules);
|
|
|
|
static void dll_hook_insert_hooks(HMODULE target);
|
|
|
|
static unity_hook_callback_func hook_load_callback;
|
|
|
|
static HMODULE WINAPI hook_LoadLibraryW(const wchar_t *name);
|
|
static HMODULE (WINAPI *next_LoadLibraryW)(const wchar_t *name);
|
|
static HMODULE WINAPI hook_LoadLibraryExW(const wchar_t *name, HANDLE hFile, DWORD dwFlags);
|
|
static HMODULE (WINAPI *next_LoadLibraryExW)(const wchar_t *name, HANDLE hFile, DWORD dwFlags);
|
|
|
|
static const struct hook_symbol unity_kernel32_syms[] = {
|
|
{
|
|
.name = "LoadLibraryW",
|
|
.patch = hook_LoadLibraryW,
|
|
.link = (void **) &next_LoadLibraryW,
|
|
}, {
|
|
.name = "LoadLibraryExW",
|
|
.patch = hook_LoadLibraryExW,
|
|
.link = (void **) &next_LoadLibraryExW,
|
|
}
|
|
};
|
|
|
|
|
|
void unity_hook_init(const struct unity_config *cfg, HINSTANCE self, unity_hook_callback_func callback) {
|
|
assert(cfg != NULL);
|
|
|
|
if (!cfg->enable) {
|
|
return;
|
|
}
|
|
|
|
if (unity_hook_initted) {
|
|
return;
|
|
}
|
|
|
|
memcpy(&unity_config, cfg, sizeof(*cfg));
|
|
dll_hook_insert_hooks(NULL);
|
|
|
|
hook_load_callback = callback;
|
|
|
|
unity_hook_initted = true;
|
|
dprintf("Unity: Hook enabled.\n");
|
|
}
|
|
|
|
static void dll_hook_insert_hooks(HMODULE target) {
|
|
hook_table_apply(
|
|
target,
|
|
"kernel32.dll",
|
|
unity_kernel32_syms,
|
|
_countof(unity_kernel32_syms));
|
|
}
|
|
|
|
static HMODULE WINAPI hook_LoadLibraryExW(const wchar_t *name, HANDLE hFile, DWORD dwFlags)
|
|
{
|
|
return hook_LoadLibraryW(name);
|
|
}
|
|
|
|
static HMODULE WINAPI hook_LoadLibraryW(const wchar_t *name)
|
|
{
|
|
const wchar_t *name_end;
|
|
const wchar_t *target_module;
|
|
bool already_loaded;
|
|
HMODULE result;
|
|
size_t name_len;
|
|
size_t target_module_len;
|
|
|
|
if (name == NULL) {
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
// Check if the module is already loaded
|
|
already_loaded = GetModuleHandleW(name) != NULL;
|
|
|
|
// Must call the next handler so the DLL reference count is incremented
|
|
result = next_LoadLibraryW(name);
|
|
|
|
if (!already_loaded && result != NULL) {
|
|
name_len = wcslen(name);
|
|
|
|
// mono entrypoint for injecting target_assembly
|
|
if (GetProcAddress(result, "mono_jit_init_version")) {
|
|
doorstop_mono_hook_init(&unity_config, result);
|
|
}
|
|
|
|
for (size_t i = 0; i < target_modules_len; i++) {
|
|
target_module = target_modules[i];
|
|
target_module_len = wcslen(target_module);
|
|
|
|
// Check if the newly loaded library is at least the length of
|
|
// the name of the target module
|
|
if (name_len < target_module_len) {
|
|
continue;
|
|
}
|
|
|
|
name_end = &name[name_len - target_module_len];
|
|
|
|
// Check if the name of the newly loaded library is one of the
|
|
// modules the path hooks should be injected into
|
|
if (_wcsicmp(name_end, target_module) != 0) {
|
|
continue;
|
|
}
|
|
|
|
dprintf("Unity: Loaded %S\n", target_module);
|
|
|
|
dll_hook_insert_hooks(result);
|
|
path_hook_insert_hooks(result);
|
|
|
|
reg_hook_insert_hooks(result);
|
|
clock_hook_insert_hooks(result);
|
|
proc_addr_insert_hooks(result);
|
|
if (hook_load_callback != NULL){
|
|
hook_load_callback(result, target_module);
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|