Commit Graph

384 Commits

Author SHA1 Message Date
icex2
3f4dab5fd6 feat: Add helpers to easily setup the async logging sink 2024-08-15 11:34:32 +02:00
icex2
a970884873 feat(core): Async log sink
A long awaited solution to address several
long-standing problems:

* Remove the need for log-server band-aid for iidx
   versions using ezusb and the modern AVS logging
   System, i.e. iidx 19 to 24. Any non AVS thread calling
   the AVS log functions will crash due the mutex
   implementation in AVS being not compatible with
   non AVS threads (see the journal entry in the dev docs
   for the whole story).
* Discontinue using the AVS log functions instead of
   bemanitools’s own ones. There was never a technical
   reason to do that, actually. It was neat to share one common
   interface, but that was about it.
* Fixes performance issues on several games such as stuttering
   brief slowdowns and de-syncs

Why not make this an integral part of the logger? There are
situations where async logging is not desired, e.g. ensure
predictiable logging output during debugging/development
tasks, and performance doesn’t matter at this point.

With the decision to implement this as a sink, the async
component can be easily composed arbitrarily with the other
existing log sinks.
2024-08-15 11:34:32 +02:00
icex2
c3d95b0ffd feat(core): Expose message size on logger as parameter
Make this configurable. Normally the buffer size
doesn’t need to be 64k, that’s only required for
very verbose debug/development logging output.

Furthermore, the parameter needs to shared and
aligned with the async logger which has it’s own
buffer size. This avoids tight coupling between
the async sink and the logger.
2024-08-15 11:34:32 +02:00
icex2
903bddddce refactor(config): Use helper to setup logging
Reduces code a little code bloat
2024-08-15 11:34:32 +02:00
icex2
9540e9e115 feat: Use async logger in launcher 2024-08-15 11:34:32 +02:00
icex2
87fb71d769 feat: Add missing macro to check for errors
Other parts of core have this already, align
as these are useful to make the code more
readable.
2024-08-15 11:34:31 +02:00
icex2
71e6b1e29f fix: bootstrapping with logger on extiotest
Missing the core_boot setup and incorrect
order when setting the api. This must come
after initializing the actual logging system.
2024-08-15 11:34:31 +02:00
icex2
3987ef99ac fix: Mutex the std logging sink on colored messages
This is required to ensure colored log messages
are executed as an atomic operation. Otherwise,
the color code information written to the terminal
could interleave with concurrent log messages
which results in “randomly” colored messages or
parts of them.
2024-08-15 11:34:31 +02:00
icex2
e61dfb3977 refactor: Move all hook and IO libraries to use btools log and thread api
Remove usages of AVS threads and logging functions from the bemanitools backend. Use the bemanitools 6 API instead
which propagates interfaces to call thread and log APIs.

Prior design decisions for using these were:
- have a single log stream through the AVS logging system for “neatness”, log output redirection options in launcher, and theoretically logging to an xrpc endpoint
- IIDX 19 to IIDX 24 crash the AVS logging engine in libavs due to IO hook code running in a non AVS thread (threads in ezusb library) causing a stackoverflow when trying to acquire a mutex (see dev journal 2018-02-10-logging-breakdown-avs.md for details)

With a flexible log sink architecture in the core of bemanitools, and a separate writer function that is hooked up as a log writer to AVS, log streams are still unified on a sink level. This takes care of having all log messaged sinked to the same targets no matter how many logging engines are using them.

This avoids going through the AVS logging engine with the IO related hooking code in iidx, which just uses the bemanitools logging engine instead.

Furthermore, this removes any needs to having to switch thread and logging implementations once AVS is booted which significantly simplifies the runtime orchestration during bootstrapping.

The log-server, which was specifically implemented for iidx to solve the threading issue, can also be removed now. Unfortunately, this also caused performance issues such as stuttering due to it’s rather simplistic implementation.
2024-08-15 11:34:31 +02:00
icex2
57e68f928a feat: bemanitools 6 initial refactoring drop, alpha 1
**THIS IS A HIGHLY WORK/DEVELOPMENT IN PROGRESS VERSION**

**THINGS ARE BROKEN AND EVERYTHING IS SUBJECT TO CHANGE**

First cut after massive refactoring with most critical and fundamental changes implemented.
We need to start somewhere, and this might be as good as anything else, so we can get started
with testing, bug fixing and iterating for the next releases.

The following list is non-exhaustive, does not guarantee anything does work, yet, and is supposed
to give a high level idea of what all of this is about. Updated documentation will reflect all of
this at some later point in time in more detail.

* A common "core" now abstracts logging, thread, property and configuration infrastructure and
  provides a common interface. This is used by bemanitools internally as well as all tools, hooks
  and APIs provided and don't depend on the game, version of the game or AVS version available
  anymore
* New bemanitools (public) API
  * Versioned API allowing for handling incremental API changes as well as breaking changes by
    providing a new/different version when necessary
  * Unified interfaces for bemanitools core API, i.e. logging, threads, configuration
  * SDK with examples (TBD)
  * Dogfooding approach: Bemanitools uses its own (public) API to implement and provide fundamental
    features like configurable keyboard implementations for IO or hooks for different games and
    versions
* All bemanitools hooks and IO libraries have been or are about to be re-worked to use the new APIs
* New hook API allows for more fine grained runtime control when stages of the hook are to be
  executed, i.e. pre AVS, before main game, iat hooking instead of relying purely on DllMain
  (which is still a compatible option though)
* launcher as a replacement for bootstrap: Bring it significantly closer to the original bootstrap
  by supporting completely vanilla data and bootstrap.xml configurations to run the games. Note
  that bemanitools does not include any code or means to run DRM'd data, only decrypted
* inject is also being reworked to use as much of the same "infrastructure" as launcher to provide
  a more seamless bootstrapping process for games that keeps pre-eapki data as vanilla as possible
Summary:

Test Plan:
Summary:

Test Plan:
Summary:

Test Plan:
Summary:

Test Plan:
2024-08-15 11:34:31 +02:00
icex2
106b908f17 feat(launcher): Integrate procmon as optional dependency
Integrate this as an optional dependency into launcher and
load it dynamically. Thus, these can be easily loaded/enabled
by developers and end-users.
2024-08-14 17:53:52 +02:00
icex2
fd9f455bf3 feat(procmon): Library to hook and monitor selected system calls
A general debugging tool. 3rd party applications such as
"procmon" (same name) provide these capabilites and even
more. But, they are more difficult to run with bemanitools
and don't provide a unified look at the output in combination
with the log output by bemanitools.

Provide an initial set of system call hooks that have already
supported debugging efforts. More can be added when needed
later.
2024-08-14 17:53:52 +02:00
icex2
aaef2d94c5 feat(launcher): Improve error output when missing vcredist deps
Apply a simple heuristic to provide the user with more
specific information regarding which vcredist package
might not have been found on their system.

This is a common problem as different games require
different versions and different versions of windows
and installations might already come with some versions
already pre-installed.

Also improve the readme regarding that and provide links
to all versions that are required by one game or another
today.
2024-08-14 17:53:52 +02:00
icex2
1b8bf7b245 feat(util): Separate debug module with proper stacktrace printing
Because we are using mingw, we can't just use window's
dbghelp library as the symbols created are in dwarf format.

Fortunately, the dwarfstack library already provides all the
facilities to easily print very descriptive stacktraces,
including function names, file names and line numbers,
when dwarf symbols are available.

This moves the incomplete exception handling portion from
signal to a separate module as well to improve scoping.
2024-08-14 17:53:52 +02:00
icex2
4b352ed080 feat(inject): Use new exception handler with stacktraces
Adjust inject to utilize the new feature. This also
requires including the dwarfstack.dll in all distribution
packages.
2024-08-14 17:53:51 +02:00
icex2
4b38f50a39 fix(mingw): Version upgrade caused this to error
HRESULT not defined fixed by including windows header
2024-08-14 17:53:51 +02:00
icex2
35ca49fe7e refactor(launcher): Major re-work of launcher
Kudos to Shiz for providing the groundwork for this.

Fundamentally re-think how launcher operates and
bootstrapping the games is managed and configured.

This brings it significantly closer to how the original
bootstrap is doing the job: launcher now utilizes the
data (structures) provided by the bootstrap.xml configuration
file. This creates compatibility with vanilla data dumps
and original stock images. Note that bemanitools does not
include any code or means to run DRM'd data, only decrypted.

But, this allows users to keep decrypted dumps as stock as
possible which means:

* No copying around of property files anymore
* Keep the modules/ folder with the binaries
* Have bemanitools binaries separate in the data
* No need to edit/customize the original configuration files

A list of key features of the "new" launcher:

* Boostrap games by following the configuration provided by
  stock game's bootstrap.xml files
* Custom launcher.xml configuration file that adds further
  launcher configurable features, composability of
  bootstrap.xml configuration(s) as well as configuration
  overriding/stacking of selected types of configurations,
  e.g. eamuse config, avs-config. The latter eliminates
  the need for modifying stock config files in the prop/
  folder
* Unified logging system: launcher and AVS logging uses
  the same logger, all output can now be in a single file
* Original features such as various hook types still
  available

Due to the significant architectural changes, this also
breaks with any backwards compatibility to existing
launcher setups. Thus, users need to migrate by re-applying
the new configuration format and migrating their config
parameters accordingly.

Further migration instructions and updated documentation
will be provided upon release.

Co-authored-by: Shiz <hi@shiz.me>
2024-08-14 17:53:51 +02:00
icex2
947050d0c8 refactor(inject): Use new core thread and log modules
Keep this a separate commit because this also removes
inject's own logging engine and replaces it with the
streamlined core API. The core API provides all the
features of inject's own logging engine which also
performed horribly. The entire logging operation
was locked which included expensive operations
that formatted the log messages and required
memory allocations and copying around data.

The core API's implementation at least only
synchronizes the actual IO operations
(though this can be improved further with an
actual async logging sink, TBD)
2024-08-14 17:53:51 +02:00
icex2
1b38c3d346 chore: Delete old log and thread modules in util
The log API stopped scaling already a while ago and needs
considerable refactoring to consider the various use-cases
that emerged since it was first created on alpha versions
of bemanitools.
2024-08-14 17:53:51 +02:00
icex2
93e0a090bc refactor: Entire code base, thread and log usage
Boils down to:
- Include headers
- Reduce boiler plate with helpers
- Swap out explicit usages with core API layer
  and ensure the right API is configured beforehand
2024-08-14 17:53:51 +02:00
icex2
82d1a2df52 refactor(api): Thread and log API
Split files and add name spacing.
2024-08-14 17:52:59 +02:00
icex2
170277100c feat: Add helper to set avs implementations
Doesn't really reduce boiler plate but adds
clarity with a more meaningful function name
what the operation does.
2024-08-14 17:52:59 +02:00
icex2
573840aba6 feat: Add core module
This module contains the "core" (API) of
bemanitools which includes an abstraction
layer for threads and logging at this time.

The threads API is very close to what
util/thread already was with some structural
enhancements which make it easier to understand
and work with the API, I hope. Some additional
helpers (*-ext module) support in doing common
tasks, e.g. setting up the thread API with other
modules.

The log(ging) part receives a major overhaul to
address known limitations and issues with the
util/log module:
- Cleaner API layer
- Separate sinks from actual logging engine
- Sinks are composable
- Improved and cleaner compatibility layer
  with AVS logging API

Additional "extensions" (*-ext modules) add
various helper functions for common tasks like
setting up the logging engine with a file and stdout
sink.

The sinks also improved significantly with the file
sink now supporting proper appending and log rotation.
Logging to stdout/stderr supports coloring of log
messages which works across logging engines.

Overall, this refactored foundation is expected to
support future developments and removes known
limitations at the current scale of bemanitools such as:
- Reducing boiler plate code across hooks
- Interop of bemanitools and AVS (and setting the foundation
  for addressing currently missing interop, e.g. for
  dealing with property structures without AVS)
- Addressing performance issues in the logging engine
  due to incorrect interop with AVS
2024-08-14 17:52:59 +02:00
Will Xyen
48668837a8 camhook: fix camhook for new style camera detection 2024-05-21 22:29:11 -07:00
Will Xyen
8307837995 camhook: split cam-detect code to different file 2024-05-21 22:29:11 -07:00
Will Xyen
a03c4e0d93 iidxhook9: add fs hook for F drive 2024-05-11 17:17:40 -07:00
garbage
ca42257fa2 iidxhook-util: Add domain check to my_gethostbyname func 2024-03-25 14:16:47 +01:00
garbage
f7142df84d iidxhook-util: Remove inet_addr hook 2024-03-25 14:16:47 +01:00
garbage
7d397dc54c iidxhook3: Add hook for ea3_boot func 2024-03-25 14:16:47 +01:00
icex2
2d4d5fa535 feat(avs-util): Add helper to translate property errors 2024-02-25 09:36:24 +01:00
icex2
e81bd6f9cd fix(avs): Incorrect function signature
After getting doubts, I looked this one up again on the
assembly. The decompiled output confused me
and no actual value is being returned there.
2024-02-25 09:35:30 +01:00
icex2
a4b3f92935 feat(avs): Add property get and clear error functions
Use these to improve error handling by allowing
one to provide additional error information on
property related operations.
2024-02-25 09:23:02 +01:00
icex2
5833197b03 fix(hook): Add missing hook_table_revert impl
Allow hooks to cleanup when they are shut down.
2024-02-25 09:09:12 +01:00
icex2
f17a2d2044 feat/fix(avs/ddr): Support AVS 2.13.06
This one was missing and is the actual correct
version used for ddr-13. 2.13.04 was compatible,
thus far, but there isn't any guarantee that they
are actually 100% compatible (only konmai knows...).
2024-01-31 22:47:14 +01:00
icex2
42f09417a0 feat(avs imports): Add lib export definitions of new AVS API functions
Add all functions and their respective ordinals (and mangled names for
documentation purpose) to all currently used AVS version.
2024-01-31 22:47:14 +01:00
icex2
dc16844bbb feat(avs-api): Various improvements
* Improve psmap types, taken from a private
  eamuse server backend which had more complete
  mappings.
* Move psmap terminator to enum
* AVS error type: Supports improving
  expressiveness of the API interface
* Add more property node related functions

Add more AVS file system related functions

These were previously missing and are required for
various file system related tasks such as iterating
directory trees, reading and writing files through
the AVS file system for the upcoming launcher
rework.

Note that the AVS API broke with some mode flags
after version 2.13.06.
2024-01-31 22:47:14 +01:00
icex2
4fedf34d6b feat: Add new module to scope avs related "utility" stuff
Use this to share helpers or other extensions to the
original avs API across modules.

Start with including error codes to readable strings
to improve velocity on AVS API error analysis.
2024-01-31 22:47:14 +01:00
icex2
06317d63e7 feat(util): Add func to check if running as admin user
This has been a source of common error in the past.
It is known that most, or even all, games run into
various issues when not run with elevated privileges.
2024-01-31 22:47:14 +01:00
icex2
e2a6410461 chore: Apply code formatting 2024-01-31 22:47:14 +01:00
ahnada
1379c1e11b New filename (without version string) for the new save files 2024-01-31 21:40:22 +01:00
ahnada
d1525a98dd Mapper serialization versioning
Add a "BTMD" FOURCC + version in the beginning of the mapper data file.
Is backwards compatible with the current data format.
2024-01-31 21:40:22 +01:00
ahnada
329d6a80a3 Properly save/load the new analog invert option 2024-01-31 21:40:22 +01:00
ahnada
f37f216c69 Add invert analog input option 2024-01-31 21:40:22 +01:00
icex2
bec007d52a fix(p3ioemu): Incorrect dispatching of unknown p3io commands
Using ddrhook1, this caused DDR X to crash on startup when the
P3io client sends the currently unknown command 2B. Handling it
with the incorrect p3io command struct, any following reading
attempts from the P3IO by the game fail.

Handle the 2B case explicitly with a generic response that worked
previously before the restructuring of the code. Apply the same
to any further unknown commands with improved logging warning
about this.
2023-11-30 20:33:36 +01:00
icex2
a177913bd6 fix(p3io): Off-by-one error on assert
Buffers are allowed to have the exact size as the max defined
P3IO buffer size. Cutting it short by one byte causes this
to fail incorrectly when using the pure raw buffer structure
2023-11-30 20:33:36 +01:00
ahnada
0fdde8b32d Allow generic HID devices with broken(?) outputs to still work as inputs.
Fixes Sony DualShock 4 not working
2023-11-13 21:35:28 +01:00
ahnada
09b3a6c24a Fix incorrect SetupDiGetClassDevs error checking 2023-11-13 19:37:29 +01:00
icex2
9b2ed6910e feat: ddrio-async wrapper/shim driver for async IO
Wrapper/shim library to drive another ddrio in a dedicated
IO thread. Depending on the other ddrio backend used, this
can significantly improve performance while staying
compatible to the existing ddrio API interface

This turned out to be a good solution to solve performance
problems when running MAME with ddrio-p3io that is
(currently) implemented with synchronous IO calls that are
very costly: ~12 ms for a write over the ACIO protocol, ~4 ms
for a read using an IOCTL. As this already adds up to nearly
a full frame (60 fps) regarding latency, there isn't a lot
of time left to do other stuff in a synchronous update loop.
MAME's performance was unstable and dropped all the time below
100%. The result was a choppy gameplay experience.

Combining ddrio-async with ddrio-p3io, the combined backend
is able to drive inputs/outputs at a rate of ~250hz = ~4
updates per frame. This results in an average input latency
of ~4 ms which is as good as it can get with the p3io
hardware's performance limitations that I measured (see
the 4 ms for the IOCTL mentioned above).

This is more than good enough as as update frequency of
the 573 hardware is slightly less than that (I got told
something ~180 hz?).

tl;dr: Gameplay on MAME is great, smooth frame rate, IO feels
amazing and responsive.
2023-11-03 15:46:11 +01:00
Will Toohey
820036087d Revert "Make roundplug PCBID/EAMID verification fail a hard error"
This reverts commit 67de6639ef.
2023-10-18 23:29:19 +02:00
Will Toohey
ebd80d3749 Make roundplug PCBID/EAMID verification fail a hard error
This was previously a soft error, and also said "reverting to default"
without actually doing so. We should be forcing correct format.
2023-10-18 23:29:19 +02:00