From 57e68f928aea9a7749202f0757a9352498403a96 Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 15 Aug 2024 11:34:31 +0200 Subject: [PATCH] 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: --- CHANGELOG.md | 52 + GNUmakefile | 8 +- Module.mk | 21 +- README.md | 10 +- btsdk/example/hook-example/hook.c | 42 + btsdk/example/hook/config.c | 0 btsdk/example/hook/dllmain copy.c | 74 + btsdk/example/hook/dllmain-bootstrap.c | 15 + btsdk/example/hook/dllmain-bootstrap.h | 12 + btsdk/example/hook/log.c | 0 btsdk/example/hook/thread.c | 21 + btsdk/example/hook/thread.h | 3 + btsdk/hook-btapi/dllmain.c | 0 btsdk/hook-btapi/hook.c | 30 + btsdk/hook-simple/dllmain.c | 2 + dist/ddr/launcher-12.xml | 14 +- dist/ddr/launcher-13.xml | 14 +- dist/ddr/launcher-14.xml | 14 +- dist/ddr/launcher-15.xml | 14 +- dist/ddr/launcher-16.xml | 14 +- dist/ddr/launcher-17.xml | 14 +- dist/ddr/launcher-18.xml | 14 +- dist/iidx/ea3-ident.xml | 10 - dist/iidx/eamuse-server.xml | 6 - dist/iidx/gamestart-09.bat | 48 +- dist/iidx/gamestart-10.bat | 48 +- dist/iidx/gamestart-11.bat | 48 +- dist/iidx/gamestart-12.bat | 49 +- dist/iidx/gamestart-13.bat | 50 +- dist/iidx/gamestart-14.bat | 50 +- dist/iidx/gamestart-15.bat | 50 +- dist/iidx/gamestart-16.bat | 52 +- dist/iidx/gamestart-17.bat | 50 +- dist/iidx/gamestart-18-cn.bat | 49 +- dist/iidx/gamestart-18.bat | 28 +- dist/iidx/gamestart-19.bat | 20 +- dist/iidx/gamestart-20-cn.bat | 49 +- dist/iidx/gamestart-20.bat | 20 +- dist/iidx/gamestart-21.bat | 20 +- dist/iidx/gamestart-22.bat | 20 +- dist/iidx/gamestart-23.bat | 20 +- dist/iidx/gamestart-24.bat | 20 +- dist/iidx/gamestart-25.bat | 20 +- dist/iidx/gamestart-26.bat | 20 +- dist/iidx/gamestart-27.bat | 20 +- dist/iidx/gamestart-28.bat | 20 +- dist/iidx/gamestart-29.bat | 20 +- dist/iidx/gamestart-30.bat | 20 +- dist/iidx/iidxhook-10.conf | 2 +- dist/iidx/iidxhook-11.conf | 2 +- dist/iidx/iidxhook-12.conf | 2 +- dist/iidx/iidxhook-13.conf | 2 +- dist/iidx/iidxhook-30.xml | 44 + dist/iidx/launcher-18.xml | 20 +- dist/iidx/launcher-19.xml | 20 +- dist/iidx/launcher-20.xml | 20 +- dist/iidx/launcher-21.xml | 20 +- dist/iidx/launcher-22.xml | 20 +- dist/iidx/launcher-23.xml | 20 +- dist/iidx/launcher-24.xml | 20 +- dist/iidx/launcher-25.xml | 18 +- dist/iidx/launcher-26.xml | 18 +- dist/iidx/launcher-27.xml | 18 +- dist/iidx/launcher-28.xml | 18 +- dist/iidx/launcher-29.xml | 18 +- dist/iidx/launcher-30.xml | 22 +- dist/iidx/pcbid.xml | 7 - src/api/acio/mgr.h | 42 + src/api/core/config.h | 51 + src/api/core/log.h | 19 + src/api/core/thread.h | 28 + src/api/hook.h | 41 + src/api/input.h | 28 + src/api/io/bst.h | 30 + src/api/io/ddr.h | 106 ++ src/api/io/eam.h | 88 ++ src/api/io/iidx.h | 122 ++ src/api/io/jb.h | 85 + src/api/io/popn.h | 80 + src/api/io/sdvx.h | 70 + src/api/io/vefx.h | 28 + src/api/log.h | 31 - src/api/thread.h | 20 - src/imports/avs.h | 12 +- src/imports/import_32_1101_avs.def | 8 +- src/imports/import_32_1304_avs.def | 82 +- src/imports/import_32_1306_avs.def | 4 +- src/imports/import_32_1508_avs.def | 10 +- src/imports/import_32_1601_avs.def | 8 +- src/main/acio-mgr/Module.mk | 11 + src/main/acio-mgr/acio-mgr.def | 20 + src/main/{aciomgr => acio-mgr}/dllmain.c | 6 +- src/main/acio-mgr/internal.h | 7 + .../{aciomgr/manager.c => acio-mgr/mgr.c} | 100 +- src/main/aciodrv-proc/panb.c | 22 +- src/main/aciodrv/device.c | 2 +- src/main/aciodrv/h44b.c | 2 +- src/main/aciodrv/icca.c | 2 +- src/main/aciodrv/kfca.c | 2 +- src/main/aciodrv/panb.c | 2 +- src/main/aciodrv/port.c | 2 +- src/main/aciodrv/rvol.c | 2 +- src/main/acioemu/addr.c | 2 +- src/main/acioemu/emu.c | 2 +- src/main/acioemu/h44b.c | 8 +- src/main/acioemu/h44b.h | 4 +- src/main/acioemu/hdxs.c | 2 +- src/main/acioemu/icca.c | 40 +- src/main/acioemu/icca.h | 3 + src/main/acioemu/pipe.h | 2 +- src/main/aciomgr/Module.mk | 10 - src/main/aciomgr/aciomgr.def | 12 - src/main/aciomgr/manager-init.h | 8 - src/main/aciotest/Module.mk | 1 + src/main/aciotest/main.c | 11 +- src/main/asio/asio-reghook.c | 4 +- src/main/asio/config-asio.c | 6 +- src/main/avs-ext/Module.mk | 13 + src/main/{avs-util => avs-ext}/error.c | 26 +- src/main/avs-ext/error.h | 10 + src/main/avs-ext/fs.c | 33 + src/main/avs-ext/fs.h | 9 + src/main/avs-ext/log.c | 27 + src/main/avs-ext/log.h | 8 + src/main/avs-ext/property-ext.c | 71 + src/main/avs-ext/property-ext.h | 9 + src/main/avs-ext/property-internal.h | 26 + src/main/avs-ext/property-node.c | 1374 +++++++++++++++++ src/main/avs-ext/property-node.h | 16 + src/main/avs-ext/property.c | 389 +++++ src/main/avs-ext/property.h | 8 + src/main/avs-ext/thread.c | 56 + src/main/avs-ext/thread.h | 8 + src/main/avs-util/Module.mk | 7 - src/main/avs-util/core-interop.c | 16 - src/main/avs-util/core-interop.h | 7 - src/main/avs-util/error.h | 10 - src/main/bemanitools/bstio.h | 54 - src/main/bemanitools/ddrio.h | 129 -- src/main/bemanitools/eamio.h | 137 -- src/main/bemanitools/glue.h | 47 - src/main/bemanitools/iidxio.h | 174 --- src/main/bemanitools/input.h | 92 -- src/main/bemanitools/jbio.h | 120 -- src/main/bemanitools/popnio.h | 108 -- src/main/bemanitools/sdvxio.h | 108 -- src/main/bemanitools/vefxio.h | 61 - src/main/bio2drv/bi2a-iidx.c | 2 +- src/main/bio2drv/bi2a-sdvx.c | 2 +- src/main/bio2drv/config-bio2.c | 6 +- src/main/bio2drv/detect.c | 17 +- src/main/bio2drv/detect.h | 8 - src/main/bio2emu-iidx/bi2a.c | 83 +- src/main/bio2emu/emu.c | 4 +- src/main/bio2emu/setupapi.c | 6 +- src/main/bsthook/Module.mk | 11 +- src/main/bsthook/acio.c | 2 +- src/main/bsthook/acio.h | 3 + src/main/bsthook/dllmain.c | 82 +- src/main/bsthook/gfx.c | 2 +- src/main/bsthook/kfca.c | 6 +- src/main/bsthook/settings.c | 2 +- src/main/bstio/Module.mk | 6 +- src/main/bstio/bstio.c | 85 +- src/main/bstio/bstio.def | 15 +- src/main/camhook/cam-detect.c | 3 +- src/main/camhook/cam.c | 5 +- src/main/camhook/config-cam.c | 4 +- src/main/cconfig/cconfig-main.c | 6 +- src/main/cconfig/cconfig-util.c | 4 +- src/main/cconfig/cconfig-util.h | 5 +- src/main/cconfig/cconfig.c | 2 +- src/main/cconfig/cmd.c | 2 +- src/main/cconfig/conf.c | 2 +- src/main/config/Module.mk | 4 + src/main/config/analogs.c | 10 +- src/main/config/buttons.c | 2 +- src/main/config/eam.c | 12 +- src/main/config/gametype.c | 2 +- src/main/config/main.c | 96 +- src/main/config/snap.c | 4 +- src/main/config/usages.c | 2 +- src/main/core/Module.mk | 14 +- src/main/core/boot.c | 107 ++ src/main/core/boot.h | 8 + src/main/core/config-property-node.c | 346 +++++ src/main/core/config-property-node.h | 15 + src/main/core/log-bt-ext.c | 42 +- src/main/core/log-bt-ext.h | 9 +- src/main/core/log-bt.c | 174 ++- src/main/core/log-bt.h | 35 +- src/main/core/log-sink-async.c | 10 +- src/main/core/log-sink-async.h | 2 +- src/main/core/log-sink-debug.c | 10 +- src/main/core/log-sink-debug.h | 2 +- src/main/core/log-sink-file.c | 19 +- src/main/core/log-sink-file.h | 2 +- src/main/core/log-sink-list.c | 29 +- src/main/core/log-sink-list.h | 2 +- src/main/core/log-sink-mutex.c | 35 +- src/main/core/log-sink-mutex.h | 2 +- src/main/core/log-sink-null.c | 10 +- src/main/core/log-sink-null.h | 2 +- src/main/core/log-sink-std.c | 36 +- src/main/core/log-sink-std.h | 5 +- src/main/core/log-sink.h | 4 +- src/main/core/log.c | 74 - src/main/core/property-ext.c | 75 + src/main/core/property-ext.h | 14 + src/main/core/property-node-ext.c | 750 +++++++++ src/main/core/property-node-ext.h | 115 ++ src/main/core/property-node-trace.c | 877 +++++++++++ src/main/core/property-node-trace.h | 11 + src/main/core/property-node.c | 605 ++++++++ src/main/core/property-node.h | 347 +++++ src/main/core/property-trace.c | 183 +++ src/main/core/property-trace.h | 10 + src/main/core/property.c | 198 +++ src/main/core/property.h | 91 ++ src/main/core/thread-crt-ext.c | 8 - src/main/core/thread-crt-ext.h | 9 - src/main/core/thread-crt.c | 67 +- src/main/core/thread-crt.h | 11 +- src/main/core/thread.c | 78 - src/main/core/thread.h | 117 -- src/main/d3d9-util/dxerr.c | 5 +- src/main/d3d9-util/dxerr9.c | 5 +- src/main/d3d9exhook/config-gfx.c | 4 +- src/main/d3d9exhook/d3d9ex.c | 4 +- src/main/ddrhook-util/_com4.c | 31 +- src/main/ddrhook-util/dinput.c | 4 +- src/main/ddrhook-util/extio.c | 9 +- src/main/ddrhook-util/gfx.c | 4 +- src/main/ddrhook-util/misc.c | 4 +- src/main/ddrhook-util/monitor.c | 4 +- src/main/ddrhook-util/p3io.c | 9 +- src/main/ddrhook-util/spike.c | 4 +- src/main/ddrhook-util/usbmem.c | 5 +- src/main/ddrhook1/Module.mk | 9 +- src/main/ddrhook1/avs-boot.c | 3 +- src/main/ddrhook1/config-ddrhook1.c | 4 +- src/main/ddrhook1/config-eamuse.c | 4 +- src/main/ddrhook1/config-gfx.c | 4 +- src/main/ddrhook1/config-security.c | 4 +- src/main/ddrhook1/dllmain.c | 62 +- src/main/ddrhook1/filesystem.c | 4 +- src/main/ddrhook1/master.c | 4 +- src/main/ddrhook2/Module.mk | 9 +- src/main/ddrhook2/dllmain.c | 67 +- src/main/ddrhook2/master.c | 4 +- src/main/ddrio-async/Module.mk | 5 + src/main/ddrio-async/ddrio-async.def | 22 +- src/main/ddrio-async/ddrio.c | 218 ++- src/main/ddrio-mm/Module.mk | 1 + src/main/ddrio-mm/ddrio-mm.def | 20 +- src/main/ddrio-mm/ddrio.c | 123 +- src/main/ddrio-p3io/Module.mk | 1 + src/main/ddrio-p3io/config.c | 4 +- src/main/ddrio-p3io/ddrio-p3io.def | 20 +- src/main/ddrio-p3io/ddrio.c | 90 +- src/main/ddrio-smx/Module.mk | 3 + src/main/ddrio-smx/ddrio-smx.def | 20 +- src/main/ddrio-smx/ddrio.c | 143 +- src/main/ddrio/Module.mk | 6 +- src/main/ddrio/ddrio.c | 99 +- src/main/ddrio/ddrio.def | 21 +- src/main/ddriotest/Module.mk | 4 +- src/main/ddriotest/main.c | 228 +-- src/main/dinput/dinput.c | 4 +- src/main/eamio-icca/Module.mk | 4 +- src/main/eamio-icca/eamio-icca.c | 153 +- src/main/eamio-icca/eamio-icca.def | 22 +- src/main/eamio/Module.mk | 2 +- src/main/eamio/eam-api.c | 92 +- src/main/eamio/eam-config.h | 4 +- src/main/eamio/eam-impl.c | 22 +- src/main/eamio/eam-impl.h | 2 +- src/main/eamio/eamio.def | 23 +- src/main/eamiotest/Module.mk | 4 +- src/main/eamiotest/main.c | 116 +- src/main/exceptiontrace/Module.mk | 9 + src/main/exceptiontrace/dllmain.c | 6 + src/main/exceptiontrace/exceptiontrace.c | 138 ++ src/main/exceptiontrace/exceptiontrace.def | 8 + src/main/exceptiontrace/exceptiontrace.h | 8 + src/main/exceptiontrace/hook.c | 41 + src/main/exceptiontrace/hook.h | 20 + src/main/extiodrv/device.c | 2 +- src/main/extiodrv/extio.c | 2 +- src/main/extiotest/Module.mk | 1 + src/main/extiotest/main.c | 7 +- src/main/ezusb-emu/device.c | 4 +- src/main/ezusb-emu/node-coin.c | 4 +- src/main/ezusb-emu/node-eeprom.c | 4 +- src/main/ezusb-emu/node-security-mem.c | 4 +- src/main/ezusb-emu/node-security-plug.c | 4 +- src/main/ezusb-emu/node-sram.c | 4 +- src/main/ezusb-emu/node-wdt.c | 4 +- src/main/ezusb-emu/util.c | 4 +- src/main/ezusb-iidx-16seg-emu/node-16seg.c | 7 +- src/main/ezusb-iidx-emu/card-mag.c | 2 +- src/main/ezusb-iidx-emu/msg.c | 42 +- src/main/ezusb-iidx-emu/node-fpga.c | 4 +- src/main/ezusb-iidx-emu/node-serial.c | 46 +- src/main/ezusb-iidx-fpga-flash/Module.mk | 1 + src/main/ezusb-iidx-fpga-flash/main.c | 8 +- src/main/ezusb-iidx-sram-flash/Module.mk | 1 + src/main/ezusb-iidx-sram-flash/main.c | 14 +- src/main/ezusb-iidx/ezusb-iidx.c | 4 +- src/main/ezusb-iidx/fpga.c | 6 +- src/main/ezusb-iidx/sram.c | 4 +- src/main/ezusb-tool/Module.mk | 1 + src/main/ezusb-tool/main.c | 8 +- src/main/ezusb/ezusb.c | 4 +- src/main/ezusb/util.c | 4 +- src/main/ezusb2-dbg-hook/Module.mk | 1 + src/main/ezusb2-dbg-hook/main.c | 12 +- src/main/ezusb2-emu/device.c | 4 +- src/main/ezusb2-emu/util.c | 4 +- src/main/ezusb2-iidx-emu/msg.c | 39 +- src/main/ezusb2-popn-emu/msg.c | 23 +- src/main/ezusb2-popn-shim/Module.mk | 1 + src/main/ezusb2-popn-shim/dllmain.c | 4 +- src/main/ezusb2-popn-shim/proxy.c | 2 +- src/main/ezusb2-tool/Module.mk | 1 + src/main/ezusb2-tool/main.c | 8 +- src/main/ezusb2/ezusb2.c | 4 +- src/main/geninput/Module.mk | 2 + src/main/geninput/dev-list.c | 4 +- src/main/geninput/geninput.def | 11 +- src/main/geninput/hid-generic.c | 4 +- src/main/geninput/hid-meta-in.c | 4 +- src/main/geninput/hid-meta-out.c | 4 +- src/main/geninput/hid-mgr.c | 4 +- src/main/geninput/hid-report-in.c | 4 +- src/main/geninput/hid-report-out.c | 4 +- src/main/geninput/hid.c | 4 +- src/main/geninput/hotplug.c | 4 +- src/main/geninput/input-config.h | 2 - src/main/geninput/input.c | 56 +- src/main/geninput/io-thread.c | 19 +- src/main/geninput/kbd.c | 4 +- src/main/geninput/mapper-s11n.c | 22 +- src/main/geninput/mapper.c | 8 +- src/main/geninput/mouse.c | 4 +- src/main/geninput/msg-thread.c | 4 +- src/main/geninput/pacdrive.c | 4 +- src/main/geninput/ri.c | 4 +- src/main/hook/d3d9.c | 2 +- src/main/hooklib/acp.c | 2 +- src/main/hooklib/adapter.c | 2 +- src/main/hooklib/app.c | 2 +- src/main/hooklib/config-adapter.c | 2 +- src/main/hooklib/memfile.c | 2 +- src/main/hooklib/rs232.c | 2 +- src/main/hooklib/setupapi.c | 2 +- src/main/iface-acio/Module.mk | 8 + src/main/iface-acio/mgr.c | 135 ++ .../{aciomgr/manager.h => iface-acio/mgr.h} | 56 +- src/main/iface-core/Module.mk | 9 + src/main/iface-core/config.c | 245 +++ src/main/iface-core/config.h | 42 + src/main/iface-core/log.c | 58 + src/main/{core => iface-core}/log.h | 101 +- src/main/iface-core/thread.c | 115 ++ src/main/iface-core/thread.h | 25 + src/main/iface-io/Module.mk | 15 + src/main/iface-io/bst.c | 100 ++ src/main/iface-io/bst.h | 19 + src/main/iface-io/ddr.c | 142 ++ src/main/iface-io/ddr.h | 23 + src/main/iface-io/eam.c | 137 ++ src/main/iface-io/eam.h | 23 + src/main/iface-io/iidx.c | 222 +++ src/main/iface-io/iidx.h | 28 + src/main/iface-io/jb.c | 168 ++ src/main/iface-io/jb.h | 24 + src/main/iface-io/popn.c | 157 ++ src/main/iface-io/popn.h | 23 + src/main/iface-io/sdvx.c | 180 +++ src/main/iface-io/sdvx.h | 26 + src/main/iface-io/vefx.c | 118 ++ src/main/iface-io/vefx.h | 20 + src/main/iface/Module.mk | 10 + src/main/iface/hook.c | 118 ++ src/main/iface/hook.h | 21 + src/main/iface/input.c | 127 ++ src/main/iface/input.h | 21 + src/main/iidx-bio2-exit-hook/Module.mk | 2 + src/main/iidx-bio2-exit-hook/main.c | 10 +- src/main/iidx-ezusb-exit-hook/Module.mk | 4 + src/main/iidx-ezusb-exit-hook/main.c | 9 + src/main/iidx-ezusb2-exit-hook/Module.mk | 4 + src/main/iidx-ezusb2-exit-hook/main.c | 9 + src/main/iidx-irbeat-patch/Module.mk | 1 + src/main/iidx-irbeat-patch/main.c | 10 + src/main/iidxhook-d3d9/bb-scale-hd.c | 4 +- src/main/iidxhook-d3d9/util.h | 4 +- src/main/iidxhook-util/acio.c | 4 +- src/main/iidxhook-util/chart-patch.c | 4 +- src/main/iidxhook-util/clock.c | 4 +- src/main/iidxhook-util/config-eamuse.c | 4 +- src/main/iidxhook-util/config-ezusb.c | 4 +- src/main/iidxhook-util/config-gfx.c | 2 +- src/main/iidxhook-util/config-io.c | 2 +- src/main/iidxhook-util/config-misc.c | 2 +- src/main/iidxhook-util/config-sec.c | 2 +- src/main/iidxhook-util/d3d9.c | 4 +- src/main/iidxhook-util/eamuse.c | 4 +- src/main/iidxhook-util/effector.c | 4 +- src/main/iidxhook-util/log-server.c | 16 +- src/main/iidxhook-util/settings.c | 4 +- src/main/iidxhook1/Module.mk | 9 +- src/main/iidxhook1/config-iidxhook1.c | 2 +- src/main/iidxhook1/dllmain.c | 74 +- src/main/iidxhook1/ezusb-mon.c | 4 +- src/main/iidxhook1/log-ezusb.c | 4 +- src/main/iidxhook2/Module.mk | 9 +- src/main/iidxhook2/config-iidxhook2.c | 2 +- src/main/iidxhook2/dllmain.c | 71 +- src/main/iidxhook3/Module.mk | 8 +- src/main/iidxhook3/avs-boot.c | 13 +- src/main/iidxhook3/dllmain.c | 62 +- src/main/iidxhook4-cn/Module.mk | 10 +- src/main/iidxhook4-cn/avs-boot.c | 3 +- src/main/iidxhook4-cn/dllmain.c | 46 +- src/main/iidxhook4-cn/path.c | 4 +- src/main/iidxhook4/Module.mk | 12 +- src/main/iidxhook4/dllmain.c | 70 +- src/main/iidxhook5-cn/Module.mk | 11 +- src/main/iidxhook5-cn/avs-boot.c | 3 +- src/main/iidxhook5-cn/dllmain.c | 45 +- src/main/iidxhook5-cn/path.c | 4 +- src/main/iidxhook5/Module.mk | 12 +- src/main/iidxhook5/dllmain.c | 70 +- src/main/iidxhook5/ifs-snd-redir.c | 4 +- src/main/iidxhook6/Module.mk | 12 +- src/main/iidxhook6/dllmain.c | 127 +- src/main/iidxhook6/iidxhook6.def | 4 +- src/main/iidxhook7/Module.mk | 12 +- src/main/iidxhook7/dllmain.c | 70 +- src/main/iidxhook8/Module.mk | 10 +- src/main/iidxhook8/config-io.c | 2 +- src/main/iidxhook8/dllmain.c | 73 +- src/main/iidxhook9/Module.mk | 10 +- src/main/iidxhook9/config-io.c | 2 +- src/main/iidxhook9/dllmain.c | 79 +- src/main/iidxhook9/fs-hook.c | 3 +- src/main/iidxio-bio2/Module.mk | 4 + src/main/iidxio-bio2/iidxio-bio2.def | 35 +- src/main/iidxio-bio2/iidxio.c | 176 ++- src/main/iidxio-ezusb/Module.mk | 4 + src/main/iidxio-ezusb/iidxio-ezusb.def | 35 +- src/main/iidxio-ezusb/iidxio.c | 102 +- src/main/iidxio-ezusb2/Module.mk | 4 + src/main/iidxio-ezusb2/iidxio-ezusb2.def | 35 +- src/main/iidxio-ezusb2/iidxio.c | 99 +- src/main/iidxio/Module.mk | 7 +- src/main/iidxio/iidxio.c | 208 +-- src/main/iidxio/iidxio.def | 35 +- src/main/iidxiotest/Module.mk | 4 +- src/main/iidxiotest/main.c | 180 ++- src/main/inject/Module.mk | 1 + src/main/inject/debugger.c | 8 +- src/main/inject/main.c | 29 +- src/main/jbhook-util-p3io/gfx.c | 4 +- src/main/jbhook-util-p3io/mixer.c | 4 +- src/main/jbhook-util-p3io/p3io.c | 27 +- src/main/jbhook-util/acio.c | 4 +- src/main/jbhook-util/eamuse.c | 4 +- src/main/jbhook-util/locale.c | 4 +- src/main/jbhook-util/p4io.c | 27 +- src/main/jbhook1/Module.mk | 6 +- src/main/jbhook1/avs-boot.c | 3 +- src/main/jbhook1/config-eamuse.c | 2 +- src/main/jbhook1/config-gfx.c | 2 +- src/main/jbhook1/config-security.c | 2 +- src/main/jbhook1/dllmain.c | 55 +- src/main/jbhook1/log-gftools.c | 2 +- src/main/jbhook2/Module.mk | 10 +- src/main/jbhook2/dllmain.c | 86 +- src/main/jbhook3/Module.mk | 10 +- src/main/jbhook3/dllmain.c | 86 +- src/main/jbhook3/gfx.c | 4 +- src/main/jbhook3/options.c | 2 +- src/main/jbio-magicbox/Module.mk | 4 + src/main/jbio-magicbox/jbio-magicbox.def | 24 +- src/main/jbio-magicbox/jbio.c | 72 +- src/main/jbio-p4io/Module.mk | 6 +- src/main/jbio-p4io/config-h44b.c | 2 +- src/main/jbio-p4io/h44b.c | 23 +- src/main/jbio-p4io/jbio-p4io.def | 24 +- src/main/jbio-p4io/jbio.c | 103 +- src/main/jbio/Module.mk | 8 +- src/main/jbio/jbio.c | 140 +- src/main/jbio/jbio.def | 25 +- src/main/jbiotest/Module.mk | 4 +- src/main/jbiotest/main.c | 175 ++- src/main/launcher/Module.mk | 17 +- src/main/launcher/app.c | 312 ++++ src/main/launcher/app.h | 30 + src/main/launcher/avs-config.c | 791 ++++++---- src/main/launcher/avs-config.h | 53 +- src/main/launcher/avs.c | 57 +- src/main/launcher/avs.h | 10 +- src/main/launcher/bootstrap-config.c | 813 ++++++---- src/main/launcher/bootstrap-config.h | 6 +- src/main/launcher/bootstrap.c | 152 +- src/main/launcher/bootstrap.h | 18 +- src/main/launcher/debug.c | 2 +- src/main/launcher/ea3-ident-config.c | 87 +- src/main/launcher/ea3-ident-config.h | 4 +- src/main/launcher/eamuse-config.c | 77 +- src/main/launcher/eamuse-config.h | 28 +- src/main/launcher/eamuse.c | 12 +- src/main/launcher/eamuse.h | 4 +- src/main/launcher/hook.c | 34 - src/main/launcher/hook.h | 6 - src/main/launcher/hooks.c | 211 +++ src/main/launcher/hooks.h | 28 + src/main/launcher/launcher-config.c | 566 ++++--- src/main/launcher/launcher-config.h | 50 +- src/main/launcher/launcher.c | 264 ++-- src/main/launcher/main.c | 4 + src/main/launcher/module.c | 428 ----- src/main/launcher/module.h | 29 - src/main/launcher/options.c | 54 +- src/main/launcher/options.h | 11 +- src/main/launcher/property-util.c | 891 ----------- src/main/launcher/property-util.h | 99 -- src/main/launcher/stubs.c | 17 +- src/main/launcher/version.c | 1 + src/main/launcher/version.h | 1 + src/main/mempatch-hook/Module.mk | 1 + src/main/mempatch-hook/main.c | 11 +- src/main/mm/Module.mk | 1 + src/main/mm/Sources | 6 - src/main/mm/mm.c | 2 +- src/main/module/Module.mk | 16 + src/main/module/acio-mgr-ext.c | 15 + src/main/module/acio-mgr-ext.h | 9 + src/main/module/acio-mgr.c | 83 + src/main/module/acio-mgr.h | 21 + src/main/module/core.h | 14 + src/main/module/hook.c | 142 ++ src/main/module/hook.h | 26 + src/main/module/input-ext.c | 18 + src/main/module/input-ext.h | 8 + src/main/module/input.c | 104 ++ src/main/module/input.h | 24 + src/main/module/io-ext.c | 26 + src/main/module/io-ext.h | 9 + src/main/module/io.c | 135 ++ src/main/module/io.h | 26 + src/main/module/module.c | 285 ++++ src/main/module/module.h | 24 + src/main/p3io-ddr-tool/Module.mk | 1 + src/main/p3io-ddr-tool/main.c | 6 +- src/main/p3io-ddr-tool/mode-test.c | 4 +- src/main/p3io/cmd.c | 2 +- src/main/p3io/frame.c | 2 +- src/main/p3iodrv/ddr.c | 4 +- src/main/p3iodrv/device.c | 2 +- src/main/p3ioemu/devmgr.c | 4 +- src/main/p3ioemu/emu.c | 4 +- src/main/p3ioemu/uart.c | 4 +- src/main/p4iodrv/device.c | 2 +- src/main/p4iodrv/usb.c | 2 +- src/main/p4ioemu/device.c | 5 +- src/main/pcbidgen/Module.mk | 3 +- src/main/pcbidgen/main.c | 9 + src/main/popnhook-util/acio.c | 4 +- src/main/popnhook-util/mixer.c | 4 +- src/main/popnhook1/Module.mk | 6 +- src/main/popnhook1/avs-boot.c | 4 +- src/main/popnhook1/config-eamuse.c | 2 +- src/main/popnhook1/config-gfx.c | 2 +- src/main/popnhook1/config-sec.c | 2 +- src/main/popnhook1/d3d9.c | 4 +- src/main/popnhook1/dllmain.c | 60 +- src/main/popnhook1/filesystem.c | 4 +- src/main/popnio/Module.mk | 6 +- src/main/popnio/popnio.c | 120 +- src/main/popnio/popnio.def | 23 +- src/main/procmon-lib/Module.mk | 8 - src/main/procmon-lib/procmon.c | 96 -- src/main/procmon-lib/procmon.h | 37 - src/main/procmon/Module.mk | 4 + src/main/procmon/bt-hook.c | 50 + src/main/procmon/config.c | 39 + src/main/procmon/config.h | 17 + src/main/procmon/dllmain.c | 6 + src/main/procmon/file.c | 4 +- src/main/procmon/module.c | 4 +- src/main/procmon/procmon.c | 79 +- src/main/procmon/procmon.def | 17 +- src/main/procmon/procmon.h | 15 +- src/main/procmon/thread.c | 4 +- src/main/sdvxhook/Module.mk | 10 +- src/main/sdvxhook/acio.c | 4 +- src/main/sdvxhook/dllmain.c | 74 +- src/main/sdvxhook/gfx.c | 4 +- src/main/sdvxhook/kfca.c | 25 +- src/main/sdvxhook/lcd.c | 4 +- src/main/sdvxhook2-cn/Module.mk | 9 +- src/main/sdvxhook2-cn/acio.c | 4 +- src/main/sdvxhook2-cn/config-cn.c | 2 +- src/main/sdvxhook2-cn/dllmain.c | 47 +- src/main/sdvxhook2-cn/kfca.c | 23 +- src/main/sdvxhook2-cn/unis-version.c | 4 +- src/main/sdvxhook2/Module.mk | 10 +- src/main/sdvxhook2/acio.c | 4 +- src/main/sdvxhook2/bi2a.c | 77 +- src/main/sdvxhook2/config-io.c | 2 +- src/main/sdvxhook2/dllmain.c | 73 +- src/main/sdvxhook2/nvapi.c | 4 +- src/main/sdvxhook2/power.c | 4 +- src/main/sdvxio-bio2/Module.mk | 3 +- src/main/sdvxio-bio2/sdvxio-bio2.def | 27 +- src/main/sdvxio-bio2/sdvxio.c | 121 +- src/main/sdvxio-kfca/Module.mk | 8 +- src/main/sdvxio-kfca/config-kfca.c | 2 +- src/main/sdvxio-kfca/sdvxio-kfca.def | 26 +- src/main/sdvxio-kfca/sdvxio.c | 116 +- src/main/sdvxio/Module.mk | 9 +- src/main/sdvxio/sdvxio.c | 122 +- src/main/sdvxio/sdvxio.def | 27 +- src/main/security/id.c | 2 +- src/main/security/mcode.c | 2 +- src/main/security/rp-blowfish.c | 2 +- src/main/security/rp.c | 2 +- src/main/security/rp2.c | 2 +- src/main/security/rp3.c | 2 +- src/main/unicorntail/Module.mk | 4 + src/main/unicorntail/dllmain.c | 9 +- src/main/unicorntail/p3io.c | 2 +- src/main/unicorntail/usbmem.c | 2 +- src/main/util/array.c | 2 +- src/main/util/crc.c | 2 +- src/main/util/crypto.c | 2 +- src/main/util/debug.c | 148 +- src/main/util/debug.h | 4 - src/main/util/fs.c | 2 +- src/main/util/hex.c | 2 +- src/main/util/iobuf.c | 2 +- src/main/util/mem.c | 2 +- src/main/util/msg-thread.c | 22 +- src/main/util/net.c | 2 +- src/main/util/os.c | 2 +- src/main/util/proc.c | 40 +- src/main/util/proc.h | 4 +- src/main/util/signal.c | 2 +- src/main/util/time.c | 2 +- src/main/vefxio/vefxio.c | 70 +- src/main/vefxio/vefxio.def | 15 +- src/main/vigem-ddrio/Module.mk | 4 +- src/main/vigem-ddrio/config-vigem-ddrio.c | 2 +- src/main/vigem-ddrio/main.c | 197 ++- src/main/vigem-iidxio/Module.mk | 6 +- src/main/vigem-iidxio/cab-16seg-sequencer.c | 2 +- src/main/vigem-iidxio/cab-light-sequencer.c | 2 +- src/main/vigem-iidxio/config.c | 2 +- src/main/vigem-iidxio/main.c | 138 +- src/main/vigem-sdvxio/Module.mk | 5 +- src/main/vigem-sdvxio/config-vigem-sdvxio.c | 2 +- src/main/vigem-sdvxio/main.c | 130 +- src/main/vigemstub/helper.c | 2 +- src/sdk/module/acio/mgr.h | 8 + src/sdk/module/core/config.h | 8 + src/sdk/module/core/log.h | 8 + src/sdk/module/core/thread.h | 8 + src/sdk/module/hook.h | 8 + src/sdk/module/input.h | 8 + src/sdk/module/io/bst.h | 8 + src/sdk/module/io/ddr.h | 8 + src/sdk/module/io/eam.h | 8 + src/sdk/module/io/iidx.h | 8 + src/sdk/module/io/jb.h | 8 + src/sdk/module/io/popn.h | 8 + src/sdk/module/io/sdvx.h | 8 + src/sdk/module/io/vefx.h | 8 + src/sdk/version.h | 0 src/test/cconfig/Module.mk | 3 + src/test/d3d9hook/Module.mk | 2 + src/test/d3d9hook/dllmain.c | 8 +- src/test/iidxhook-util/Module.mk | 4 + src/test/iidxhook/Module.mk | 2 + src/test/iidxhook8/Module.mk | 2 + src/test/security/Module.mk | 6 + src/test/test/test.h | 15 +- src/test/util/Module.mk | 1 + todo.md | 104 ++ 692 files changed, 19534 insertions(+), 8278 deletions(-) create mode 100644 btsdk/example/hook-example/hook.c create mode 100644 btsdk/example/hook/config.c create mode 100644 btsdk/example/hook/dllmain copy.c create mode 100644 btsdk/example/hook/dllmain-bootstrap.c create mode 100644 btsdk/example/hook/dllmain-bootstrap.h create mode 100644 btsdk/example/hook/log.c create mode 100644 btsdk/example/hook/thread.c create mode 100644 btsdk/example/hook/thread.h create mode 100644 btsdk/hook-btapi/dllmain.c create mode 100644 btsdk/hook-btapi/hook.c create mode 100644 btsdk/hook-simple/dllmain.c delete mode 100644 dist/iidx/ea3-ident.xml delete mode 100644 dist/iidx/eamuse-server.xml create mode 100644 dist/iidx/iidxhook-30.xml delete mode 100644 dist/iidx/pcbid.xml create mode 100644 src/api/acio/mgr.h create mode 100644 src/api/core/config.h create mode 100644 src/api/core/log.h create mode 100644 src/api/core/thread.h create mode 100644 src/api/hook.h create mode 100644 src/api/input.h create mode 100644 src/api/io/bst.h create mode 100644 src/api/io/ddr.h create mode 100644 src/api/io/eam.h create mode 100644 src/api/io/iidx.h create mode 100644 src/api/io/jb.h create mode 100644 src/api/io/popn.h create mode 100644 src/api/io/sdvx.h create mode 100644 src/api/io/vefx.h delete mode 100644 src/api/log.h delete mode 100644 src/api/thread.h create mode 100644 src/main/acio-mgr/Module.mk create mode 100644 src/main/acio-mgr/acio-mgr.def rename src/main/{aciomgr => acio-mgr}/dllmain.c (69%) create mode 100644 src/main/acio-mgr/internal.h rename src/main/{aciomgr/manager.c => acio-mgr/mgr.c} (59%) delete mode 100644 src/main/aciomgr/Module.mk delete mode 100644 src/main/aciomgr/aciomgr.def delete mode 100644 src/main/aciomgr/manager-init.h create mode 100644 src/main/avs-ext/Module.mk rename src/main/{avs-util => avs-ext}/error.c (83%) create mode 100644 src/main/avs-ext/error.h create mode 100644 src/main/avs-ext/fs.c create mode 100644 src/main/avs-ext/fs.h create mode 100644 src/main/avs-ext/log.c create mode 100644 src/main/avs-ext/log.h create mode 100644 src/main/avs-ext/property-ext.c create mode 100644 src/main/avs-ext/property-ext.h create mode 100644 src/main/avs-ext/property-internal.h create mode 100644 src/main/avs-ext/property-node.c create mode 100644 src/main/avs-ext/property-node.h create mode 100644 src/main/avs-ext/property.c create mode 100644 src/main/avs-ext/property.h create mode 100644 src/main/avs-ext/thread.c create mode 100644 src/main/avs-ext/thread.h delete mode 100644 src/main/avs-util/Module.mk delete mode 100644 src/main/avs-util/core-interop.c delete mode 100644 src/main/avs-util/core-interop.h delete mode 100644 src/main/avs-util/error.h delete mode 100644 src/main/bemanitools/bstio.h delete mode 100644 src/main/bemanitools/ddrio.h delete mode 100644 src/main/bemanitools/eamio.h delete mode 100644 src/main/bemanitools/glue.h delete mode 100644 src/main/bemanitools/iidxio.h delete mode 100644 src/main/bemanitools/input.h delete mode 100644 src/main/bemanitools/jbio.h delete mode 100644 src/main/bemanitools/popnio.h delete mode 100644 src/main/bemanitools/sdvxio.h delete mode 100644 src/main/bemanitools/vefxio.h create mode 100644 src/main/core/boot.c create mode 100644 src/main/core/boot.h create mode 100644 src/main/core/config-property-node.c create mode 100644 src/main/core/config-property-node.h delete mode 100644 src/main/core/log.c create mode 100644 src/main/core/property-ext.c create mode 100644 src/main/core/property-ext.h create mode 100644 src/main/core/property-node-ext.c create mode 100644 src/main/core/property-node-ext.h create mode 100644 src/main/core/property-node-trace.c create mode 100644 src/main/core/property-node-trace.h create mode 100644 src/main/core/property-node.c create mode 100644 src/main/core/property-node.h create mode 100644 src/main/core/property-trace.c create mode 100644 src/main/core/property-trace.h create mode 100644 src/main/core/property.c create mode 100644 src/main/core/property.h delete mode 100644 src/main/core/thread-crt-ext.c delete mode 100644 src/main/core/thread-crt-ext.h delete mode 100644 src/main/core/thread.c delete mode 100644 src/main/core/thread.h create mode 100644 src/main/exceptiontrace/Module.mk create mode 100644 src/main/exceptiontrace/dllmain.c create mode 100644 src/main/exceptiontrace/exceptiontrace.c create mode 100644 src/main/exceptiontrace/exceptiontrace.def create mode 100644 src/main/exceptiontrace/exceptiontrace.h create mode 100644 src/main/exceptiontrace/hook.c create mode 100644 src/main/exceptiontrace/hook.h create mode 100644 src/main/iface-acio/Module.mk create mode 100644 src/main/iface-acio/mgr.c rename src/main/{aciomgr/manager.h => iface-acio/mgr.h} (54%) create mode 100644 src/main/iface-core/Module.mk create mode 100644 src/main/iface-core/config.c create mode 100644 src/main/iface-core/config.h create mode 100644 src/main/iface-core/log.c rename src/main/{core => iface-core}/log.h (54%) create mode 100644 src/main/iface-core/thread.c create mode 100644 src/main/iface-core/thread.h create mode 100644 src/main/iface-io/Module.mk create mode 100644 src/main/iface-io/bst.c create mode 100644 src/main/iface-io/bst.h create mode 100644 src/main/iface-io/ddr.c create mode 100644 src/main/iface-io/ddr.h create mode 100644 src/main/iface-io/eam.c create mode 100644 src/main/iface-io/eam.h create mode 100644 src/main/iface-io/iidx.c create mode 100644 src/main/iface-io/iidx.h create mode 100644 src/main/iface-io/jb.c create mode 100644 src/main/iface-io/jb.h create mode 100644 src/main/iface-io/popn.c create mode 100644 src/main/iface-io/popn.h create mode 100644 src/main/iface-io/sdvx.c create mode 100644 src/main/iface-io/sdvx.h create mode 100644 src/main/iface-io/vefx.c create mode 100644 src/main/iface-io/vefx.h create mode 100644 src/main/iface/Module.mk create mode 100644 src/main/iface/hook.c create mode 100644 src/main/iface/hook.h create mode 100644 src/main/iface/input.c create mode 100644 src/main/iface/input.h create mode 100644 src/main/launcher/app.c create mode 100644 src/main/launcher/app.h delete mode 100644 src/main/launcher/hook.c delete mode 100644 src/main/launcher/hook.h create mode 100644 src/main/launcher/hooks.c create mode 100644 src/main/launcher/hooks.h delete mode 100644 src/main/launcher/module.c delete mode 100644 src/main/launcher/module.h delete mode 100644 src/main/launcher/property-util.c delete mode 100644 src/main/launcher/property-util.h delete mode 100644 src/main/mm/Sources create mode 100644 src/main/module/Module.mk create mode 100644 src/main/module/acio-mgr-ext.c create mode 100644 src/main/module/acio-mgr-ext.h create mode 100644 src/main/module/acio-mgr.c create mode 100644 src/main/module/acio-mgr.h create mode 100644 src/main/module/core.h create mode 100644 src/main/module/hook.c create mode 100644 src/main/module/hook.h create mode 100644 src/main/module/input-ext.c create mode 100644 src/main/module/input-ext.h create mode 100644 src/main/module/input.c create mode 100644 src/main/module/input.h create mode 100644 src/main/module/io-ext.c create mode 100644 src/main/module/io-ext.h create mode 100644 src/main/module/io.c create mode 100644 src/main/module/io.h create mode 100644 src/main/module/module.c create mode 100644 src/main/module/module.h delete mode 100644 src/main/procmon-lib/Module.mk delete mode 100644 src/main/procmon-lib/procmon.c delete mode 100644 src/main/procmon-lib/procmon.h create mode 100644 src/main/procmon/bt-hook.c create mode 100644 src/main/procmon/config.c create mode 100644 src/main/procmon/config.h create mode 100644 src/main/procmon/dllmain.c create mode 100644 src/sdk/module/acio/mgr.h create mode 100644 src/sdk/module/core/config.h create mode 100644 src/sdk/module/core/log.h create mode 100644 src/sdk/module/core/thread.h create mode 100644 src/sdk/module/hook.h create mode 100644 src/sdk/module/input.h create mode 100644 src/sdk/module/io/bst.h create mode 100644 src/sdk/module/io/ddr.h create mode 100644 src/sdk/module/io/eam.h create mode 100644 src/sdk/module/io/iidx.h create mode 100644 src/sdk/module/io/jb.h create mode 100644 src/sdk/module/io/popn.h create mode 100644 src/sdk/module/io/sdvx.h create mode 100644 src/sdk/module/io/vefx.h create mode 100644 src/sdk/version.h create mode 100644 todo.md diff --git a/CHANGELOG.md b/CHANGELOG.md index a8529ba..a0f151e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,58 @@ Note for CI/CD: Ensure the version formatting in the sections is kept identical to the versions given in tags. The pipeline will pick this up and cuts out the relevant section for release notes. +## 6.0.0-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 + +### What works + +* inject: Basic functionality, launches games iidx 09 to 17 with iidxhook1 to iidxhook4 +* launcher: Basic functionality, launches games iidx 09 to 17 with iidxhook5 to iidxhook7 +* iidxhook1: Boots, reaching in-game with keyboard inputs working +* iidxhook2: Boots, reaching in-game with keyboard inputs working +* iidxhook3: Boots, reaching in-game with keyboard inputs working +* iidxhook4: Boots, reaching in-game with keyboard inputs working +* iidxhook5: Boots, reaching in-game with keyboard inputs working +* iidxhook6: Boots, reaching in-game with keyboard inputs working +* iidxhook7: Boots, reaching in-game with keyboard inputs working + +### What's broken + +Since everything else is untested, consider it (very) broken + ## 5.49 ### Features diff --git a/GNUmakefile b/GNUmakefile index bb9b595..d2f8ed5 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -139,13 +139,14 @@ libs := avsdlls := avsexes := +avslibs := testdlls := testexes := include Module.mk -modules := $(dlls) $(exes) $(libs) $(avsdlls) $(avsexes) $(testdlls) $(testexes) +modules := $(dlls) $(exes) $(libs) $(avsdlls) $(avsexes) $(avslibs) $(testdlls) $(testexes) # # $1: Bitness @@ -200,6 +201,7 @@ $$(bindir_$1_$2): $$(eval $$(foreach imp,$(imps),$$(call t_import,$1,$2,$$(imp)))) $$(eval $$(foreach dll,$(avsdlls),$$(call t_linkdll,$1,$2,$$(dll)))) $$(eval $$(foreach exe,$(avsexes),$$(call t_linkexe,$1,$2,$$(exe)))) +$$(eval $$(foreach lib,$(avslibs),$$(call t_archive,$1,$2,$$(lib)))) endef @@ -209,6 +211,7 @@ define t_compile depdir_$1_$2_$3 := $(depdir)/$$(subdir_$1_$2)/$3 abslib_$1_$2_$3 := $$(libs_$3:%=$$(bindir_$1_indep)/lib%.a) +avslib_$1_$2_$3 := $$(avslibs_$3:%=$$(bindir_$1_$2)/lib%.a) absdpl_$1_$2_$3 := $$(deplibs_$3:%=$$(bindir_$1_$2)/lib%.a) objdir_$1_$2_$3 := $(objdir)/$$(subdir_$1_$2)/$3 obj_$1_$2_$3 := $$(src_$3:%.c=$$(objdir_$1_$2_$3)/%.o) \ @@ -260,6 +263,7 @@ dll_$1_$2_$3 := $$(bindir_$1_$2)/$3.dll implib_$1_$2_$3 := $$(bindir_$1_$2)/lib$3.a $$(dll_$1_$2_$3) $$(implib_$1_$2_$3): $$(obj_$1_$2_$3) $$(abslib_$1_$2_$3) \ + $$(avslib_$1_$2_$3) \ $$(absdpl_$1_$2_$3) \ $$(srcdir_$3)/$3.def | $$(bindir_$1_$2) $(V)echo ... $$(dll_$1_$2_$3) @@ -278,7 +282,7 @@ $(t_compile) exe_$1_$2_$3 := $$(bindir_$1_$2)/$3.exe -$$(exe_$1_$2_$3): $$(obj_$1_$2_$3) $$(abslib_$1_$2_$3) $$(absdpl_$1_$2_$3) \ +$$(exe_$1_$2_$3): $$(obj_$1_$2_$3) $$(abslib_$1_$2_$3) $$(avslib_$1_$2_$3) $$(absdpl_$1_$2_$3) \ | $$(bindir_$1_$2) $(V)echo ... $$@ $(V)$$(toolchain_$1)gcc -o $$@ $$^ $$(ldflags_$3) diff --git a/Module.mk b/Module.mk index bc1d3a4..9fc8e59 100644 --- a/Module.mk +++ b/Module.mk @@ -88,10 +88,10 @@ imps += avs avs-ea3 include src/main/aciodrv/Module.mk include src/main/aciodrv-proc/Module.mk include src/main/acioemu/Module.mk -include src/main/aciomgr/Module.mk +include src/main/acio-mgr/Module.mk include src/main/aciotest/Module.mk include src/main/asio/Module.mk -include src/main/avs-util/Module.mk +include src/main/avs-ext/Module.mk include src/main/bio2drv/Module.mk include src/main/bio2emu-iidx/Module.mk include src/main/bio2emu/Module.mk @@ -116,6 +116,7 @@ include src/main/dinput/Module.mk include src/main/eamio-icca/Module.mk include src/main/eamio/Module.mk include src/main/eamiotest/Module.mk +include src/main/exceptiontrace/Module.mk include src/main/extio/Module.mk include src/main/extiodrv/Module.mk include src/main/extiotest/Module.mk @@ -138,6 +139,10 @@ include src/main/ezusb2/Module.mk include src/main/geninput/Module.mk include src/main/hook/Module.mk include src/main/hooklib/Module.mk +include src/main/iface/Module.mk +include src/main/iface-acio/Module.mk +include src/main/iface-core/Module.mk +include src/main/iface-io/Module.mk include src/main/iidx-bio2-exit-hook/Module.mk include src/main/iidx-ezusb-exit-hook/Module.mk include src/main/iidx-ezusb2-exit-hook/Module.mk @@ -173,6 +178,7 @@ include src/main/jbhook3/Module.mk include src/main/launcher/Module.mk include src/main/mempatch-hook/Module.mk include src/main/mm/Module.mk +include src/main/module/Module.mk include src/main/p3io/Module.mk include src/main/p3iodrv/Module.mk include src/main/p3ioemu/Module.mk @@ -183,7 +189,6 @@ include src/main/popnhook-util/Module.mk include src/main/popnhook1/Module.mk include src/main/popnio/Module.mk include src/main/procmon/Module.mk -include src/main/procmon-lib/Module.mk include src/main/pcbidgen/Module.mk include src/main/sdvxhook/Module.mk include src/main/sdvxhook2-cn/Module.mk @@ -493,7 +498,7 @@ $(zipdir)/iidx-27-to-30.zip: \ $(V)zip -j $@ $^ $(zipdir)/iidx-hwio-x86.zip: \ - build/bin/indep-32/aciomgr.dll \ + build/bin/indep-32/acio-mgr.dll \ build/bin/indep-32/eamio-icca.dll \ build/bin/indep-32/iidxio-bio2.dll \ build/bin/indep-32/iidxio-ezusb.dll \ @@ -506,7 +511,7 @@ $(zipdir)/iidx-hwio-x86.zip: \ $(V)zip -j $@ $^ $(zipdir)/iidx-hwio-x64.zip: \ - build/bin/indep-64/aciomgr.dll \ + build/bin/indep-64/acio-mgr.dll \ build/bin/indep-64/eamio-icca.dll \ build/bin/indep-64/iidxio-bio2.dll \ build/bin/indep-64/iidxio-ezusb.dll \ @@ -617,7 +622,7 @@ $(zipdir)/jb-08.zip: \ $(V)zip -j $@ $^ $(zipdir)/jb-hwio.zip: \ - build/bin/indep-32/aciomgr.dll \ + build/bin/indep-32/acio-mgr.dll \ build/bin/indep-32/eamio-icca.dll \ build/bin/indep-32/jbio-magicbox.dll \ build/bin/indep-32/jbio-p4io.dll \ @@ -681,7 +686,7 @@ $(zipdir)/sdvx-05-cn.zip: \ $(V)zip -j $@ $^ $(zipdir)/sdvx-hwio-x86.zip: \ - build/bin/indep-32/aciomgr.dll \ + build/bin/indep-32/acio-mgr.dll \ build/bin/indep-32/eamio-icca.dll \ build/bin/indep-32/sdvxio-kfca.dll \ build/bin/indep-32/sdvxio-bio2.dll \ @@ -691,7 +696,7 @@ $(zipdir)/sdvx-hwio-x86.zip: \ $(V)zip -j $@ $^ $(zipdir)/sdvx-hwio-x64.zip: \ - build/bin/indep-64/aciomgr.dll \ + build/bin/indep-64/acio-mgr.dll \ build/bin/indep-64/eamio-icca.dll \ build/bin/indep-64/sdvxio-kfca.dll \ build/bin/indep-64/sdvxio-bio2.dll \ diff --git a/README.md b/README.md index 4c581a7..6fb5a77 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ -# Bemanitools 5 +# Bemanitools 6 -Version: `5.49` +**THIS IS A HIGHLY WORK/DEVELOPMENT IN PROGRESS VERSION** + +**THINGS ARE BROKEN AND EVERYTHING IS SUBJECT TO CHANGE** + +**ALL DOCUMENTATION IS CONSIDERED OUTDATED AND IS NOT NECESSARILY REVISED UNTIL FURTHER NOTICE** + +Version: `6.0.0-alpha.1` [Changelog](CHANGELOG.md) diff --git a/btsdk/example/hook-example/hook.c b/btsdk/example/hook-example/hook.c new file mode 100644 index 0000000..9a1dc1c --- /dev/null +++ b/btsdk/example/hook-example/hook.c @@ -0,0 +1,42 @@ +#define LOG_MODULE "btsdk-hook-example" + +#include + +#include +#include + +#include "btapi/hook-core.h" +#include "btapi/hook-main.h" + +#include "core/log.h" +#include "core/thread.h" + +void btapi_hook_core_thread_impl_set( + btapi_thread_create_t create, + btapi_thread_join_t join, + btapi_thread_destroy_t destroy) +{ + core_thread_impl_set(create, join, destroy); +} + +void btapi_hook_core_log_impl_set( + btapi_log_formatter_t misc, + btapi_log_formatter_t info, + btapi_log_formatter_t warning, + btapi_log_formatter_t fatal) +{ + core_log_impl_set(misc, info, warning, fatal); +} + +bool btapi_hook_main_init( + HMODULE game_module, struct property_node *property_node_config) +{ + log_info("btapi_hook_main_init"); + + return true; +} + +void btapi_hook_main_fini() +{ + log_info("btapi_hook_main_fini"); +} \ No newline at end of file diff --git a/btsdk/example/hook/config.c b/btsdk/example/hook/config.c new file mode 100644 index 0000000..e69de29 diff --git a/btsdk/example/hook/dllmain copy.c b/btsdk/example/hook/dllmain copy.c new file mode 100644 index 0000000..431306b --- /dev/null +++ b/btsdk/example/hook/dllmain copy.c @@ -0,0 +1,74 @@ +#define LOG_MODULE "procmon-dllmain" + +#include + +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/thread-crt-ext.h" +#include "launcher/property-util.h" + +#include "procmon/config.h" +#include "procmon/procmon.h" + +#include "util/fs.h" + +// TODO move this to a separate "standalone dllmain bootstrap" module in sdk + +BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) +{ + struct property *property; + struct property_node *root_node; + struct procmon_config config; + + // TODO provide compatibility mode here? ctx set to...something? + // to figure out if this is loaded/run by any bemanitools loader + // or not. + + if (reason == DLL_PROCESS_ATTACH) { + core_thread_crt_ext_impl_set(); + core_log_bt_ext_init_with_stderr(); + + // TODO make this somehow configurable? + // have additional stuff on procmon configuration xml + // + // + // have the same log stuff here as with launcher like file, level, rotation etc + // + // + // .... + // + // + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_INFO); + + log_info("DLL_PROCESS_ATTACH"); + + if (path_exists("procmon-config.xml")) { + property = property_util_load("procmon-config.xml"); + + root_node = property_search(NULL, "hook/procmon"); + + if (!root_node) { + // TODO error handling + } + + procmon_config_init(&config); + procmon_config_load(root_node, &config); + + procmon_init(&config); + } else { + log_warning("No configuration file found, defaulting"); + + procmon_config_init(&config); + + procmon_init(&config); + } + + } else if (reason == DLL_PROCESS_DETACH) { + log_info("DLL_PROCESS_DETACH"); + + procmon_fini(); + core_log_bt_fini(); + } + + return TRUE; +} diff --git a/btsdk/example/hook/dllmain-bootstrap.c b/btsdk/example/hook/dllmain-bootstrap.c new file mode 100644 index 0000000..f6200c3 --- /dev/null +++ b/btsdk/example/hook/dllmain-bootstrap.c @@ -0,0 +1,15 @@ + + +void btsdk_dllmain_bootstrap_process_attach() +{ + // TODO have the whole stuff to bootstrap independently of hook API + // with logging setup etc. + // provide stuff via recovering from command line args or env vars? +} + +void btsdk_dllmain_bootstrap_process_detach() +{ + // TODO cleanup + + core_log_bt_fini(); +} \ No newline at end of file diff --git a/btsdk/example/hook/dllmain-bootstrap.h b/btsdk/example/hook/dllmain-bootstrap.h new file mode 100644 index 0000000..8b60248 --- /dev/null +++ b/btsdk/example/hook/dllmain-bootstrap.h @@ -0,0 +1,12 @@ +#ifndef DLLMAIN_BOOTSTRAP_H +#define DLLMAIN_BOOTSTRAP_H + +#include + +#include "imports/avs.h" + +void btsdk_dllmain_bootstrap_process_attach(); + +void btsdk_dllmain_bootstrap_process_detach(); + +#endif \ No newline at end of file diff --git a/btsdk/example/hook/log.c b/btsdk/example/hook/log.c new file mode 100644 index 0000000..e69de29 diff --git a/btsdk/example/hook/thread.c b/btsdk/example/hook/thread.c new file mode 100644 index 0000000..ff58f4d --- /dev/null +++ b/btsdk/example/hook/thread.c @@ -0,0 +1,21 @@ + + +void btapi_thread_impl_set() +{ + +} + +int btapi_thread_create(int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority) +{ + +} + +void btapi_thread_join(int thread_id, int *result) +{ + +} + +void btapi_thread_destroy(int thread_id) +{ + +} \ No newline at end of file diff --git a/btsdk/example/hook/thread.h b/btsdk/example/hook/thread.h new file mode 100644 index 0000000..9e77e3c --- /dev/null +++ b/btsdk/example/hook/thread.h @@ -0,0 +1,3 @@ + + +void btapi_thread_impl_set(); \ No newline at end of file diff --git a/btsdk/hook-btapi/dllmain.c b/btsdk/hook-btapi/dllmain.c new file mode 100644 index 0000000..e69de29 diff --git a/btsdk/hook-btapi/hook.c b/btsdk/hook-btapi/hook.c new file mode 100644 index 0000000..0848499 --- /dev/null +++ b/btsdk/hook-btapi/hook.c @@ -0,0 +1,30 @@ +#include "api/hook.h" + +void btapi_hook_thread_impl_set( + btapi_thread_create_t create, + btapi_thread_join_t join, + btapi_thread_destroy_t destroy) +{ + // TODO some simple example how to use basic functionality of the API +} + +void btapi_hook_log_impl_set( + btapi_log_formatter_t misc, + btapi_log_formatter_t info, + btapi_log_formatter_t warning, + btapi_log_formatter_t fatal) +{ + // TODO some simple example how to use basic functionality of the API +} + +bool btapi_hook_init(struct property_node *config) +{ + // TODO some simple example how to use basic functionality of the API + + return true; +} + +void btapi_hook_fini() +{ + // TODO some simple example how to use basic functionality of the API +} \ No newline at end of file diff --git a/btsdk/hook-simple/dllmain.c b/btsdk/hook-simple/dllmain.c new file mode 100644 index 0000000..069d231 --- /dev/null +++ b/btsdk/hook-simple/dllmain.c @@ -0,0 +1,2 @@ +// TODO simple hook example with DllMain only +// ignoring the BT5 API \ No newline at end of file diff --git a/dist/ddr/launcher-12.xml b/dist/ddr/launcher-12.xml index 54c0284..7aa1a47 100644 --- a/dist/ddr/launcher-12.xml +++ b/dist/ddr/launcher-12.xml @@ -59,15 +59,11 @@ bemanitools/ea3-service.xml - - - ddrhook2.dll - - - - - - + + + ddrhook2.dll + + 0 0 diff --git a/dist/ddr/launcher-13.xml b/dist/ddr/launcher-13.xml index 54c0284..7aa1a47 100644 --- a/dist/ddr/launcher-13.xml +++ b/dist/ddr/launcher-13.xml @@ -59,15 +59,11 @@ bemanitools/ea3-service.xml - - - ddrhook2.dll - - - - - - + + + ddrhook2.dll + + 0 0 diff --git a/dist/ddr/launcher-14.xml b/dist/ddr/launcher-14.xml index 9ae27ac..b6ab267 100644 --- a/dist/ddr/launcher-14.xml +++ b/dist/ddr/launcher-14.xml @@ -59,15 +59,11 @@ bemanitools/ea3-service.xml - - - ddrhook2.dll - - - - - - + + + ddrhook2.dll + + 0 0 diff --git a/dist/ddr/launcher-15.xml b/dist/ddr/launcher-15.xml index 9ae27ac..b6ab267 100644 --- a/dist/ddr/launcher-15.xml +++ b/dist/ddr/launcher-15.xml @@ -59,15 +59,11 @@ bemanitools/ea3-service.xml - - - ddrhook2.dll - - - - - - + + + ddrhook2.dll + + 0 0 diff --git a/dist/ddr/launcher-16.xml b/dist/ddr/launcher-16.xml index cdf16d5..36c8456 100644 --- a/dist/ddr/launcher-16.xml +++ b/dist/ddr/launcher-16.xml @@ -60,15 +60,11 @@ bemanitools/ea3-service.xml - - - ddrhook2.dll - - - - - - + + + ddrhook2.dll + + 0 0 diff --git a/dist/ddr/launcher-17.xml b/dist/ddr/launcher-17.xml index cdf16d5..36c8456 100644 --- a/dist/ddr/launcher-17.xml +++ b/dist/ddr/launcher-17.xml @@ -60,15 +60,11 @@ bemanitools/ea3-service.xml - - - ddrhook2.dll - - - - - - + + + ddrhook2.dll + + 0 0 diff --git a/dist/ddr/launcher-18.xml b/dist/ddr/launcher-18.xml index cdf16d5..36c8456 100644 --- a/dist/ddr/launcher-18.xml +++ b/dist/ddr/launcher-18.xml @@ -60,15 +60,11 @@ bemanitools/ea3-service.xml - - - ddrhook2.dll - - - - - - + + + ddrhook2.dll + + 0 0 diff --git a/dist/iidx/ea3-ident.xml b/dist/iidx/ea3-ident.xml deleted file mode 100644 index e24a9b9..0000000 --- a/dist/iidx/ea3-ident.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - LDJ - J - A - A - 2022082400 - - \ No newline at end of file diff --git a/dist/iidx/eamuse-server.xml b/dist/iidx/eamuse-server.xml deleted file mode 100644 index bc70644..0000000 --- a/dist/iidx/eamuse-server.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - http://localhost - - \ No newline at end of file diff --git a/dist/iidx/gamestart-09.bat b/dist/iidx/gamestart-09.bat index 0913f2f..3f12785 100755 --- a/dist/iidx/gamestart-09.bat +++ b/dist/iidx/gamestart-09.bat @@ -1,6 +1,52 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data, JAA, JAB, etc. cd /d %~dp0 -inject iidxhook1.dll bm2dx.exe -D --config iidxhook-09.conf %* +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\JAG +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_DIR%" does not exist. + pause + exit 1 +) + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\iidxhook1.dll^ + %REVISION_DIR%\bm2dx.exe^ + -D^ + --config %BEMANITOOLS_DIR%\iidxhook-09.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-10.bat b/dist/iidx/gamestart-10.bat index 37736ae..43ffb85 100755 --- a/dist/iidx/gamestart-10.bat +++ b/dist/iidx/gamestart-10.bat @@ -1,6 +1,52 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data, JAA, JAB, etc. cd /d %~dp0 -inject iidxhook1.dll bm2dx.exe -D --config iidxhook-10.conf %* +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\JAE +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_DIR%" does not exist. + pause + exit 1 +) + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\iidxhook1.dll^ + %REVISION_DIR%\bm2dx.exe^ + -D^ + --config %BEMANITOOLS_DIR%\iidxhook-10.conf^ + %* diff --git a/dist/iidx/gamestart-11.bat b/dist/iidx/gamestart-11.bat index a4516f7..9a2005d 100755 --- a/dist/iidx/gamestart-11.bat +++ b/dist/iidx/gamestart-11.bat @@ -1,6 +1,52 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data, JAA, JAB, etc. cd /d %~dp0 -inject iidxhook1.dll bm2dx.exe -D --config iidxhook-11.conf %* +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\JAA +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_DIR%" does not exist. + pause + exit 1 +) + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\iidxhook1.dll^ + %REVISION_DIR%\bm2dx.exe^ + -D^ + --config %BEMANITOOLS_DIR%\iidxhook-11.conf^ + %* diff --git a/dist/iidx/gamestart-12.bat b/dist/iidx/gamestart-12.bat index 91be7f3..6682948 100755 --- a/dist/iidx/gamestart-12.bat +++ b/dist/iidx/gamestart-12.bat @@ -1,5 +1,52 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data, JAA, JAB, etc. cd /d %~dp0 -inject iidxhook1.dll bm2dx.exe -D --config iidxhook-12.conf %* +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\JAD + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_DIR%" does not exist. + pause + exit 1 +) + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\iidxhook1.dll^ + %REVISION_DIR%\bm2dx.exe^ + -D^ + --config %BEMANITOOLS_DIR%\iidxhook-12.conf^ + %* diff --git a/dist/iidx/gamestart-13.bat b/dist/iidx/gamestart-13.bat index 199fc5a..04ec81c 100755 --- a/dist/iidx/gamestart-13.bat +++ b/dist/iidx/gamestart-13.bat @@ -1,7 +1,49 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data, JAA, JAB, etc. cd /d %~dp0 +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\JAG + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_DIR%" does not exist. + pause + exit 1 +) + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + if not exist d mkdir d if not exist e mkdir e if not exist f mkdir f @@ -11,5 +53,9 @@ if not exist e\avs_conf\CONF mkdir e\avs_conf\CONF if not exist e\avs_conf\CONF\NVRAM mkdir e\avs_conf\CONF\NVRAM if not exist e\avs_conf\CONF\RAW mkdir e\avs_conf\CONF\RAW -inject iidxhook2.dll bm2dx.exe -D --config iidxhook-13.conf %* - +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\iidxhook2.dll^ + %REVISION_DIR%\bm2dx.exe^ + -D^ + --config %BEMANITOOLS_DIR%\iidxhook-13.conf^ + %* diff --git a/dist/iidx/gamestart-14.bat b/dist/iidx/gamestart-14.bat index 387ef66..e4ad135 100755 --- a/dist/iidx/gamestart-14.bat +++ b/dist/iidx/gamestart-14.bat @@ -1,7 +1,49 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data, JAA, JAB, etc. cd /d %~dp0 +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\2007072301 + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_DIR%" does not exist. + pause + exit 1 +) + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + if not exist d mkdir d if not exist e mkdir e if not exist f mkdir f @@ -11,5 +53,9 @@ if not exist e\avs_conf\CONF mkdir e\avs_conf\CONF if not exist e\avs_conf\CONF\NVRAM mkdir e\avs_conf\CONF\NVRAM if not exist e\avs_conf\CONF\RAW mkdir e\avs_conf\CONF\RAW -inject iidxhook3.dll bm2dx.exe -D --config iidxhook-14.conf %* - +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\iidxhook3.dll^ + %REVISION_DIR%\bm2dx.exe^ + -D^ + --config %BEMANITOOLS_DIR%\iidxhook-14.conf^ + %* diff --git a/dist/iidx/gamestart-15.bat b/dist/iidx/gamestart-15.bat index 7bac4ec..20ddbdb 100755 --- a/dist/iidx/gamestart-15.bat +++ b/dist/iidx/gamestart-15.bat @@ -1,7 +1,49 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data, JAA, JAB, etc. cd /d %~dp0 +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\2008031100 + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_DIR%" does not exist. + pause + exit 1 +) + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + if not exist d mkdir d if not exist e mkdir e if not exist f mkdir f @@ -11,5 +53,9 @@ if not exist e\avs_conf\CONF mkdir e\avs_conf\CONF if not exist e\avs_conf\CONF\NVRAM mkdir e\avs_conf\CONF\NVRAM if not exist e\avs_conf\CONF\RAW mkdir e\avs_conf\CONF\RAW -inject iidxhook3.dll bm2dx.exe -D --config iidxhook-15.conf %* - +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\iidxhook3.dll^ + %REVISION_DIR%\bm2dx.exe^ + -D^ + --config %BEMANITOOLS_DIR%\iidxhook-15.conf^ + %* diff --git a/dist/iidx/gamestart-16.bat b/dist/iidx/gamestart-16.bat index 9df8f27..2c4793a 100755 --- a/dist/iidx/gamestart-16.bat +++ b/dist/iidx/gamestart-16.bat @@ -1,7 +1,49 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data, JAA, JAB, etc. cd /d %~dp0 +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\2009072200 + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_DIR%" does not exist. + pause + exit 1 +) + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + if not exist d mkdir d if not exist e mkdir e if not exist f mkdir f @@ -9,7 +51,11 @@ if not exist f mkdir f if not exist e\avs_conf mkdir e\avs_conf if not exist e\avs_conf\CONF mkdir e\avs_conf\CONF if not exist e\avs_conf\CONF\NVRAM mkdir e\avs_conf\CONF\NVRAM -if not exist e\avs_conf\CONF\RAW mkdir e\avs_conf\CONF\RAW - -inject iidxhook3.dll bm2dx.exe -D --config iidxhook-16.conf %* +if not exist e\avs_conf\CONF\RAW mkdir e\avs_conf\CONF\RAW +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\iidxhook3.dll^ + %REVISION_DIR%\bm2dx.exe^ + -D^ + --config %BEMANITOOLS_DIR%\iidxhook-16.conf^ + %* diff --git a/dist/iidx/gamestart-17.bat b/dist/iidx/gamestart-17.bat index 027dbfd..23606e4 100755 --- a/dist/iidx/gamestart-17.bat +++ b/dist/iidx/gamestart-17.bat @@ -1,7 +1,49 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data, JAA, JAB, etc. cd /d %~dp0 +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\2010071200 + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_DIR%" does not exist. + pause + exit 1 +) + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + if not exist d mkdir d if not exist e mkdir e if not exist f mkdir f @@ -11,5 +53,9 @@ if not exist e\avs_conf\CONF mkdir e\avs_conf\CONF if not exist e\avs_conf\CONF\NVRAM mkdir e\avs_conf\CONF\NVRAM if not exist e\avs_conf\CONF\RAW mkdir e\avs_conf\CONF\RAW -inject iidxhook3.dll bm2dx.exe -D --config iidxhook-17.conf %* - +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\iidxhook3.dll^ + %REVISION_DIR%\bm2dx.exe^ + -D^ + --config %BEMANITOOLS_DIR%\iidxhook-17.conf^ + %* diff --git a/dist/iidx/gamestart-18-cn.bat b/dist/iidx/gamestart-18-cn.bat index 53d9822..1c82bfb 100644 --- a/dist/iidx/gamestart-18-cn.bat +++ b/dist/iidx/gamestart-18-cn.bat @@ -1,7 +1,49 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data, JAA, JAB, etc. cd /d %~dp0 +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR% + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_DIR%" does not exist. + pause + exit 1 +) + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + if not exist d mkdir d if not exist e mkdir e if not exist f mkdir f @@ -14,4 +56,9 @@ if not exist e\avs_conf\CONF\RAW mkdir e\avs_conf\CONF\RAW if not exist dev\nvram mkdir dev\nvram if not exist dev\raw mkdir dev\raw -inject iidxhook4-cn.dll bm2dx.exe -D --config iidxhook-18-cn.conf %* +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\iidxhook4-cn.dll^ + %REVISION_DIR%\bm2dx.exe^ + -D^ + --config %BEMANITOOLS_DIR%\iidxhook-18-cn.conf^ + %* diff --git a/dist/iidx/gamestart-18.bat b/dist/iidx/gamestart-18.bat index 4777dd9..7606ed8 100755 --- a/dist/iidx/gamestart-18.bat +++ b/dist/iidx/gamestart-18.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,15 +23,30 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore -:: Just add them to the env PATH so launcher can find the libs and game executable -:: Remark: This also requires admin privileges to propage correctly to launcher +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject set PATH=^ -%MODULES_DIR%;^ %BEMANITOOLS_DIR%;^ +%MODULES_DIR%;^ %PATH% -:: Current working dir is the game's root folder +:: Current working dir is the root/content directory of the game cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-18.xml --config %BEMANITOOLS_DIR%\iidxhook-18.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-18.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-18.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-19.bat b/dist/iidx/gamestart-19.bat index 03c22b0..ae3bca2 100755 --- a/dist/iidx/gamestart-19.bat +++ b/dist/iidx/gamestart-19.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-19.xml --config %BEMANITOOLS_DIR%\iidxhook-19.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-19.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-19.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-20-cn.bat b/dist/iidx/gamestart-20-cn.bat index c54d056..77763d2 100644 --- a/dist/iidx/gamestart-20-cn.bat +++ b/dist/iidx/gamestart-20-cn.bat @@ -1,7 +1,49 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data, JAA, JAB, etc. cd /d %~dp0 +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR% + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_DIR%" does not exist. + pause + exit 1 +) + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + if not exist d mkdir d if not exist e mkdir e if not exist f mkdir f @@ -14,4 +56,9 @@ if not exist e\avs_conf\CONF\RAW mkdir e\avs_conf\CONF\RAW if not exist dev\nvram mkdir dev\nvram if not exist dev\raw mkdir dev\raw -inject iidxhook5-cn.dll bm2dx.exe -D --config iidxhook-20-cn.conf %* +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\iidxhook5-cn.dll^ + %REVISION_DIR%\bm2dx.exe^ + -D^ + --config %BEMANITOOLS_DIR%\iidxhook-20-cn.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-20.bat b/dist/iidx/gamestart-20.bat index f579f2e..af45498 100755 --- a/dist/iidx/gamestart-20.bat +++ b/dist/iidx/gamestart-20.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-20.xml --config %BEMANITOOLS_DIR%\iidxhook-20.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-20.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-20.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-21.bat b/dist/iidx/gamestart-21.bat index 9ec039d..a3e30f0 100755 --- a/dist/iidx/gamestart-21.bat +++ b/dist/iidx/gamestart-21.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-21.xml --config %BEMANITOOLS_DIR%\iidxhook-21.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-21.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-21.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-22.bat b/dist/iidx/gamestart-22.bat index d284786..f98a924 100755 --- a/dist/iidx/gamestart-22.bat +++ b/dist/iidx/gamestart-22.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-22.xml --config %BEMANITOOLS_DIR%\iidxhook-22.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-22.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-22.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-23.bat b/dist/iidx/gamestart-23.bat index 33cceb1..d177566 100755 --- a/dist/iidx/gamestart-23.bat +++ b/dist/iidx/gamestart-23.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-23.xml --config %BEMANITOOLS_DIR%\iidxhook-23.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-23.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-23.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-24.bat b/dist/iidx/gamestart-24.bat index 94fa8b2..81e220c 100755 --- a/dist/iidx/gamestart-24.bat +++ b/dist/iidx/gamestart-24.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-24.xml --config %BEMANITOOLS_DIR%\iidxhook-24.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-24.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-24.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-25.bat b/dist/iidx/gamestart-25.bat index 2d6b6c7..9d3b617 100644 --- a/dist/iidx/gamestart-25.bat +++ b/dist/iidx/gamestart-25.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-25.xml --config %BEMANITOOLS_DIR%\iidxhook-25.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-25.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-25.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-26.bat b/dist/iidx/gamestart-26.bat index dc06460..0918808 100644 --- a/dist/iidx/gamestart-26.bat +++ b/dist/iidx/gamestart-26.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-26.xml --config %BEMANITOOLS_DIR%\iidxhook-26.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-26.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-26.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-27.bat b/dist/iidx/gamestart-27.bat index d034f84..a55ff99 100644 --- a/dist/iidx/gamestart-27.bat +++ b/dist/iidx/gamestart-27.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-27.xml --config %BEMANITOOLS_DIR%\iidxhook-27.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-27.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-27.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-28.bat b/dist/iidx/gamestart-28.bat index cfc18e4..49d6da8 100644 --- a/dist/iidx/gamestart-28.bat +++ b/dist/iidx/gamestart-28.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-28.xml --config %BEMANITOOLS_DIR%\iidxhook-28.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-28.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-28.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-29.bat b/dist/iidx/gamestart-29.bat index 64a02a5..8faf09c 100644 --- a/dist/iidx/gamestart-29.bat +++ b/dist/iidx/gamestart-29.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-29.xml --config %BEMANITOOLS_DIR%\iidxhook-29.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-29.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-29.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/gamestart-30.bat b/dist/iidx/gamestart-30.bat index 61f7720..f65db59 100644 --- a/dist/iidx/gamestart-30.bat +++ b/dist/iidx/gamestart-30.bat @@ -1,5 +1,8 @@ @echo off +:: Keep all vars scoped to this script +setlocal + :: Game doesn't work properly when not run with administrator privileges >nul 2>&1 net session @@ -20,6 +23,18 @@ set CONTENT_DIR=%CD%\.. set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools set MODULES_DIR=%CONTENT_DIR%\modules +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%MODULES_DIR%" ( + echo The game modules directory "%MODULES_DIR%" does not exist. + pause + exit 1 +) + :: Keep that data vanilla, no need to copy these around anymore :: Just add them to the env PATH so launcher can find the libs and game executable :: Remark: This also requires admin privileges to propage correctly to launcher @@ -31,4 +46,7 @@ set PATH=^ :: Current working dir is the game's root folder cd /d %CONTENT_DIR% -%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-30.xml --config %BEMANITOOLS_DIR%\iidxhook-30.conf %* \ No newline at end of file +%BEMANITOOLS_DIR%\launcher.exe^ + %BEMANITOOLS_DIR%\launcher-30.xml^ + --config %BEMANITOOLS_DIR%\iidxhook-30.conf^ + %* \ No newline at end of file diff --git a/dist/iidx/iidxhook-10.conf b/dist/iidx/iidxhook-10.conf index a9874ea..328526c 100755 --- a/dist/iidx/iidxhook-10.conf +++ b/dist/iidx/iidxhook-10.conf @@ -56,7 +56,7 @@ ezusb.io_board_type=1 misc.disable_clock_set=false # Stub calls to rteffect.dll (10th to DistorteD) -misc.rteffect_stub=false +misc.rteffect_stub=true # Path to store the settings, e.g. bookkeeping, operator settings. d:, e: and f: drive configuration/settings data misc.settings_path=.\ diff --git a/dist/iidx/iidxhook-11.conf b/dist/iidx/iidxhook-11.conf index e1dc01e..01e0f44 100755 --- a/dist/iidx/iidxhook-11.conf +++ b/dist/iidx/iidxhook-11.conf @@ -56,7 +56,7 @@ ezusb.io_board_type=1 misc.disable_clock_set=false # Stub calls to rteffect.dll (10th to DistorteD) -misc.rteffect_stub=false +misc.rteffect_stub=true # Path to store the settings, e.g. bookkeeping, operator settings. d:, e: and f: drive configuration/settings data misc.settings_path=.\ diff --git a/dist/iidx/iidxhook-12.conf b/dist/iidx/iidxhook-12.conf index a3518e3..ef1e6f2 100755 --- a/dist/iidx/iidxhook-12.conf +++ b/dist/iidx/iidxhook-12.conf @@ -59,7 +59,7 @@ misc.happy_sky_ms_bg_fix=false misc.disable_clock_set=false # Stub calls to rteffect.dll (10th to DistorteD) -misc.rteffect_stub=false +misc.rteffect_stub=true # Path to store the settings, e.g. bookkeeping, operator settings. d:, e: and f: drive configuration/settings data misc.settings_path=.\ diff --git a/dist/iidx/iidxhook-13.conf b/dist/iidx/iidxhook-13.conf index 1f8525f..fd32ad0 100755 --- a/dist/iidx/iidxhook-13.conf +++ b/dist/iidx/iidxhook-13.conf @@ -59,7 +59,7 @@ misc.distorted_ms_bg_fix=false misc.disable_clock_set=false # Stub calls to rteffect.dll (10th to DistorteD) -misc.rteffect_stub=false +misc.rteffect_stub=true # Path to store the settings, e.g. bookkeeping, operator settings. d:, e: and f: drive configuration/settings data misc.settings_path=.\ diff --git a/dist/iidx/iidxhook-30.xml b/dist/iidx/iidxhook-30.xml new file mode 100644 index 0000000..96b2126 --- /dev/null +++ b/dist/iidx/iidxhook-30.xml @@ -0,0 +1,44 @@ + + + 1 + + 0 + 0 + 0 + 0 + 1 + 0 + 1.0 + + + 1 + 1 + 1 + + + + + 1 + 0 + 0 + -1 + -1 + -1 + -1 + -1 + -1 + -1 + + -1 + -1 + + + + + + + 0 + 1 + XONAR SOUND CARD(64) + + diff --git a/dist/iidx/launcher-18.xml b/dist/iidx/launcher-18.xml index 74bf35e..3ad4a11 100644 --- a/dist/iidx/launcher-18.xml +++ b/dist/iidx/launcher-18.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -41,6 +42,8 @@ . + fs + dev/nvram @@ -60,13 +63,14 @@ bemanitools/ea3-service.xml - - iidxhook4.dll - - - - - + + 1 + iidxhook4.dll + + + + + 0 diff --git a/dist/iidx/launcher-19.xml b/dist/iidx/launcher-19.xml index 1749cfb..b70a154 100644 --- a/dist/iidx/launcher-19.xml +++ b/dist/iidx/launcher-19.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -41,6 +42,8 @@ . + fs + dev/nvram @@ -60,13 +63,14 @@ bemanitools/ea3-service.xml - - iidxhook5.dll - - - - - + + 1 + iidxhook5.dll + + + + + 0 diff --git a/dist/iidx/launcher-20.xml b/dist/iidx/launcher-20.xml index 7af7ce4..b11fc40 100644 --- a/dist/iidx/launcher-20.xml +++ b/dist/iidx/launcher-20.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -41,6 +42,8 @@ . + fs + dev/nvram @@ -60,13 +63,14 @@ bemanitools/ea3-service.xml - - iidxhook6.dll - - - - - + + 1 + iidxhook6.dll + + + + + 0 diff --git a/dist/iidx/launcher-21.xml b/dist/iidx/launcher-21.xml index 502407b..beb6458 100644 --- a/dist/iidx/launcher-21.xml +++ b/dist/iidx/launcher-21.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -41,6 +42,8 @@ . + fs + dev/nvram @@ -60,13 +63,14 @@ bemanitools/ea3-service.xml - - iidxhook7.dll - - - - - + + 1 + iidxhook7.dll + + + + + 0 diff --git a/dist/iidx/launcher-22.xml b/dist/iidx/launcher-22.xml index 502407b..beb6458 100644 --- a/dist/iidx/launcher-22.xml +++ b/dist/iidx/launcher-22.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -41,6 +42,8 @@ . + fs + dev/nvram @@ -60,13 +63,14 @@ bemanitools/ea3-service.xml - - iidxhook7.dll - - - - - + + 1 + iidxhook7.dll + + + + + 0 diff --git a/dist/iidx/launcher-23.xml b/dist/iidx/launcher-23.xml index 502407b..beb6458 100644 --- a/dist/iidx/launcher-23.xml +++ b/dist/iidx/launcher-23.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -41,6 +42,8 @@ . + fs + dev/nvram @@ -60,13 +63,14 @@ bemanitools/ea3-service.xml - - iidxhook7.dll - - - - - + + 1 + iidxhook7.dll + + + + + 0 diff --git a/dist/iidx/launcher-24.xml b/dist/iidx/launcher-24.xml index 502407b..beb6458 100644 --- a/dist/iidx/launcher-24.xml +++ b/dist/iidx/launcher-24.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -41,6 +42,8 @@ . + fs + dev/nvram @@ -60,13 +63,14 @@ bemanitools/ea3-service.xml - - iidxhook7.dll - - - - - + + 1 + iidxhook7.dll + + + + + 0 diff --git a/dist/iidx/launcher-25.xml b/dist/iidx/launcher-25.xml index 733a880..7f944ae 100644 --- a/dist/iidx/launcher-25.xml +++ b/dist/iidx/launcher-25.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -59,13 +60,14 @@ bemanitools/ea3-service.xml - - iidxhook8.dll - - - - - + + 1 + iidxhook8.dll + + + + + 0 diff --git a/dist/iidx/launcher-26.xml b/dist/iidx/launcher-26.xml index 733a880..7f944ae 100644 --- a/dist/iidx/launcher-26.xml +++ b/dist/iidx/launcher-26.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -59,13 +60,14 @@ bemanitools/ea3-service.xml - - iidxhook8.dll - - - - - + + 1 + iidxhook8.dll + + + + + 0 diff --git a/dist/iidx/launcher-27.xml b/dist/iidx/launcher-27.xml index 736ee63..281786b 100644 --- a/dist/iidx/launcher-27.xml +++ b/dist/iidx/launcher-27.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -54,13 +55,14 @@ bemanitools/ea3-service.xml - - - - iidxhook9.dll - - - + + 1 + iidxhook9.dll + + + + + 0 diff --git a/dist/iidx/launcher-28.xml b/dist/iidx/launcher-28.xml index 736ee63..281786b 100644 --- a/dist/iidx/launcher-28.xml +++ b/dist/iidx/launcher-28.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -54,13 +55,14 @@ bemanitools/ea3-service.xml - - - - iidxhook9.dll - - - + + 1 + iidxhook9.dll + + + + + 0 diff --git a/dist/iidx/launcher-29.xml b/dist/iidx/launcher-29.xml index 736ee63..281786b 100644 --- a/dist/iidx/launcher-29.xml +++ b/dist/iidx/launcher-29.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -54,13 +55,14 @@ bemanitools/ea3-service.xml - - - - iidxhook9.dll - - - + + 1 + iidxhook9.dll + + + + + 0 diff --git a/dist/iidx/launcher-30.xml b/dist/iidx/launcher-30.xml index 736ee63..4ac9c27 100644 --- a/dist/iidx/launcher-30.xml +++ b/dist/iidx/launcher-30.xml @@ -1,5 +1,6 @@ - + + 1 bemanitools_local_fs @@ -53,15 +54,16 @@ bemanitools/ea3-service.xml - - - - - iidxhook9.dll - - - - + + + 1 + iidxhook9.dll + + + + + + 0 0 diff --git a/dist/iidx/pcbid.xml b/dist/iidx/pcbid.xml deleted file mode 100644 index bc50cde..0000000 --- a/dist/iidx/pcbid.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - 0101020304050607083F - 0101020304050607083F - - \ No newline at end of file diff --git a/src/api/acio/mgr.h b/src/api/acio/mgr.h new file mode 100644 index 0000000..57e2ec8 --- /dev/null +++ b/src/api/acio/mgr.h @@ -0,0 +1,42 @@ +#ifndef BT_API_ACIO_MGR_H +#define BT_API_ACIO_MGR_H + +#include +#include + +#define BT_ACIO_MGR_NODE_PRODUCT_CODE_LEN 4 + +typedef struct ac_io_message bt_acio_message_t; +typedef struct aciodrv_device_ctx bt_acio_drv_device_ctx_t; +typedef struct bt_acio_mgr_port_dispatcher bt_acio_mgr_port_dispatcher_t; + +typedef bt_acio_mgr_port_dispatcher_t *(*bt_acio_mgr_port_init_t)(const char *path, uint32_t baud); +typedef void (*bt_acio_mgr_port_fini_t)(bt_acio_mgr_port_dispatcher_t *dispatcher); +typedef uint8_t (*bt_acio_mgr_node_count_get_t)(const bt_acio_mgr_port_dispatcher_t *dispatcher); +typedef bool (*bt_acio_mgr_node_product_ident_get_t)( + const bt_acio_mgr_port_dispatcher_t *dispatcher, + uint8_t node_id, + char product[BT_ACIO_MGR_NODE_PRODUCT_CODE_LEN]); +typedef bool (*bt_acio_mgr_port_packet_submit_t)( + bt_acio_mgr_port_dispatcher_t *dispatcher, + bt_acio_message_t *msg, + uint32_t max_resp_size); +typedef bt_acio_drv_device_ctx_t *(*bt_acio_mgr_port_checkout_t)(bt_acio_mgr_port_dispatcher_t *dispatcher); +typedef void (*bt_acio_mgr_port_checkin_t)(bt_acio_mgr_port_dispatcher_t *dispatcher); + +typedef struct bt_acio_mgr_api { + uint16_t version; + + struct { + // Required to be implemented + bt_acio_mgr_port_init_t port_init; + bt_acio_mgr_port_fini_t port_fini; + bt_acio_mgr_node_count_get_t node_count_get; + bt_acio_mgr_node_product_ident_get_t node_product_ident_get; + bt_acio_mgr_port_packet_submit_t port_packet_submit; + bt_acio_mgr_port_checkout_t port_checkout; + bt_acio_mgr_port_checkin_t port_checkin; + } v1; +} bt_acio_mgr_api_t; + +#endif diff --git a/src/api/core/config.h b/src/api/core/config.h new file mode 100644 index 0000000..f780c8d --- /dev/null +++ b/src/api/core/config.h @@ -0,0 +1,51 @@ +#ifndef BT_API_CORE_CONFIG_H +#define BT_API_CORE_CONFIG_H + +#include +#include +#include + +typedef struct bt_core_config bt_core_config_t; + +typedef enum bt_core_config_result { + BT_CORE_CONFIG_RESULT_SUCCESS = 0, + BT_CORE_CONFIG_RESULT_ERROR_INTERNAL = 1, + BT_CORE_CONFIG_RESULT_VALUE_NOT_FOUND = 2, + BT_CORE_CONFIG_RESULT_TYPE_MISMATCH = 3, +} bt_core_config_result_t; + +typedef bt_core_config_result_t (*bt_core_config_s8_get_t)(const bt_core_config_t *config, const char *path, int8_t *value); +typedef bt_core_config_result_t (*bt_core_config_u8_get_t)(const bt_core_config_t *config, const char *path, uint8_t *value); +typedef bt_core_config_result_t (*bt_core_config_s16_get_t)(const bt_core_config_t *config, const char *path, int16_t *value); +typedef bt_core_config_result_t (*bt_core_config_u16_get_t)(const bt_core_config_t *config, const char *path, uint16_t *value); +typedef bt_core_config_result_t (*bt_core_config_s32_get_t)(const bt_core_config_t *config, const char *path, int32_t *value); +typedef bt_core_config_result_t (*bt_core_config_u32_get_t)(const bt_core_config_t *config, const char *path, uint32_t *value); +typedef bt_core_config_result_t (*bt_core_config_s64_get_t)(const bt_core_config_t *config, const char *path, int64_t *value); +typedef bt_core_config_result_t (*bt_core_config_u64_get_t)(const bt_core_config_t *config, const char *path, uint64_t *value); +typedef bt_core_config_result_t (*bt_core_config_float_get_t)(const bt_core_config_t *config, const char *path, float *value); +typedef bt_core_config_result_t (*bt_core_config_double_get_t)(const bt_core_config_t *config, const char *path, double *value); +typedef bt_core_config_result_t (*bt_core_config_bool_get_t)(const bt_core_config_t *config, const char *path, bool *value); +typedef bt_core_config_result_t (*bt_core_config_bin_get_t)(const bt_core_config_t *config, const char *path, void *value, size_t len); +typedef bt_core_config_result_t (*bt_core_config_str_get_t)(const bt_core_config_t *config, const char *path, char *value, size_t len); + +typedef struct bt_core_config_api { + uint16_t version; + + struct { + bt_core_config_s8_get_t s8_get; + bt_core_config_u8_get_t u8_get; + bt_core_config_s16_get_t s16_get; + bt_core_config_u16_get_t u16_get; + bt_core_config_s32_get_t s32_get; + bt_core_config_u32_get_t u32_get; + bt_core_config_s64_get_t s64_get; + bt_core_config_u64_get_t u64_get; + bt_core_config_float_get_t float_get; + bt_core_config_double_get_t double_get; + bt_core_config_bool_get_t bool_get; + bt_core_config_bin_get_t bin_get; + bt_core_config_str_get_t str_get; + } v1; +} bt_core_config_api_t; + +#endif \ No newline at end of file diff --git a/src/api/core/log.h b/src/api/core/log.h new file mode 100644 index 0000000..e642968 --- /dev/null +++ b/src/api/core/log.h @@ -0,0 +1,19 @@ +#ifndef BT_API_CORE_LOG_H +#define BT_API_CORE_LOG_H + +#include + +typedef void (*bt_core_log_message_t)(const char *module, const char *fmt, ...); + +typedef struct bt_core_log_api { + uint16_t version; + + struct { + bt_core_log_message_t misc; + bt_core_log_message_t info; + bt_core_log_message_t warning; + bt_core_log_message_t fatal; + } v1; +} bt_core_log_api_t; + +#endif \ No newline at end of file diff --git a/src/api/core/thread.h b/src/api/core/thread.h new file mode 100644 index 0000000..bbd77b5 --- /dev/null +++ b/src/api/core/thread.h @@ -0,0 +1,28 @@ +#ifndef BT_API_CORE_THREAD_H +#define BT_API_CORE_THREAD_H + +#include + +typedef enum bt_core_thread_result { + BT_CORE_THREAD_RESULT_SUCCESS = 0, + BT_CORE_THREAD_RESULT_ERROR_INTERNAL = 1, +} bt_core_thread_result_t; + +typedef int bt_core_thread_id_t; + +typedef bt_core_thread_result_t (*bt_core_thread_create_t)( + int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority, bt_core_thread_id_t *thread_id); +typedef bt_core_thread_result_t (*bt_core_thread_join_t)(bt_core_thread_id_t thread_id, int *result); +typedef bt_core_thread_result_t (*bt_core_thread_destroy_t)(bt_core_thread_id_t thread_id); + +typedef struct bt_core_thread_api { + uint16_t version; + + struct { + bt_core_thread_create_t create; + bt_core_thread_join_t join; + bt_core_thread_destroy_t destroy; + } v1; +} bt_core_thread_api_t; + +#endif \ No newline at end of file diff --git a/src/api/hook.h b/src/api/hook.h new file mode 100644 index 0000000..ff83f7b --- /dev/null +++ b/src/api/hook.h @@ -0,0 +1,41 @@ +#ifndef BT_API_HOOK_H +#define BT_API_HOOK_H + +#include + +#include +#include +#include + +#include "api/core/config.h" + +typedef enum bt_io_bst_gpio_sys_bit { + BT_IO_BST_GPIO_SYS_COIN = 2, + BT_IO_BST_GPIO_SYS_TEST = 4, + BT_IO_BST_GPIO_SYS_SERVICE = 5, +} bt_io_bst_gpio_sys_bit_t; + +typedef void (*bt_hook_iat_dll_name_get_t)(char *buffer, size_t size); +typedef bool (*bt_hook_pre_avs_init_t)(const bt_core_config_t *config); +// game module reference, either the exe or dll. allow for further targeted hooking/patching +// remark: you can't own the memory of the property_node config. whatever you need form that, make sure to copy the data and not just reference it. +// there is no guarantee the data is not free'd/gone after this call returns +// use the property api to iterate the data and parse it into your own custom configuration struct +// it is advised to also validate all parameters +// if no configuration was provided upon loading, the config_node contains an empty root node +typedef bool (*bt_hook_main_init_t)(HMODULE game_module, const bt_core_config_t *config); +typedef void (*bt_hook_main_fini_t)(); + +typedef struct bt_hook_api { + uint16_t version; + + struct { + // Optional + bt_hook_iat_dll_name_get_t iat_dll_name_get; + bt_hook_pre_avs_init_t pre_avs_init; + bt_hook_main_init_t main_init; + bt_hook_main_fini_t main_fini; + } v1; +} bt_hook_api_t; + +#endif \ No newline at end of file diff --git a/src/api/input.h b/src/api/input.h new file mode 100644 index 0000000..a193f7f --- /dev/null +++ b/src/api/input.h @@ -0,0 +1,28 @@ +#ifndef BT_API_INPUT_H +#define BT_API_INPUT_H + +#include +#include + +typedef bool (*bt_input_init_t)(); +typedef void (*bt_input_fini_t)(); +typedef bool (*bt_input_mapper_config_load_t)(const char *game_type); +typedef uint8_t (*bt_input_mapper_analog_read_t)(uint8_t analog); +typedef uint64_t (*bt_input_mapper_update_t)(); +typedef void (*bt_input_mapper_light_write_t)(uint8_t light, uint8_t intensity); + +typedef struct bt_input_api { + uint16_t version; + + struct { + // Required to be implemented + bt_input_init_t init; + bt_input_fini_t fini; + bt_input_mapper_config_load_t mapper_config_load; + bt_input_mapper_analog_read_t mapper_analog_read; + bt_input_mapper_update_t mapper_update; + bt_input_mapper_light_write_t mapper_light_write; + } v1; +} bt_input_api_t; + +#endif diff --git a/src/api/io/bst.h b/src/api/io/bst.h new file mode 100644 index 0000000..752b2d5 --- /dev/null +++ b/src/api/io/bst.h @@ -0,0 +1,30 @@ +#ifndef BT_API_IO_BST_H +#define BT_API_IO_BST_H + +#include +#include + +typedef enum bt_io_bst_gpio_sys_bit { + BT_IO_BST_GPIO_SYS_COIN = 2, + BT_IO_BST_GPIO_SYS_TEST = 4, + BT_IO_BST_GPIO_SYS_SERVICE = 5, +} bt_io_bst_gpio_sys_bit_t; + +typedef bool (*bt_io_bst_init_t)(); +typedef void (*bt_io_bst_fini_t)(); +typedef bool (*bt_io_bst_input_read_t)(); +typedef uint8_t (*bt_io_bst_input_get_t)(); + +typedef struct bt_io_bst_api { + uint16_t version; + + struct { + // Required to be implemented + bt_io_bst_init_t init; + bt_io_bst_fini_t fini; + bt_io_bst_input_read_t input_read; + bt_io_bst_input_get_t input_get; + } v1; +} bt_io_bst_api_t; + +#endif \ No newline at end of file diff --git a/src/api/io/ddr.h b/src/api/io/ddr.h new file mode 100644 index 0000000..e22defe --- /dev/null +++ b/src/api/io/ddr.h @@ -0,0 +1,106 @@ +#ifndef BT_API_IO_DDR_H +#define BT_API_IO_DDR_H + +#include +#include + +typedef enum bt_io_ddr_pad_bit { + BT_IO_DDR_TEST = 0x04, + BT_IO_DDR_COIN = 0x05, + BT_IO_DDR_SERVICE = 0x06, + + BT_IO_DDR_P2_START = 0x08, + BT_IO_DDR_P2_UP = 0x09, + BT_IO_DDR_P2_DOWN = 0x0A, + BT_IO_DDR_P2_LEFT = 0x0B, + BT_IO_DDR_P2_RIGHT = 0x0C, + BT_IO_DDR_P2_MENU_LEFT = 0x0E, + BT_IO_DDR_P2_MENU_RIGHT = 0x0F, + BT_IO_DDR_P2_MENU_UP = 0x02, + BT_IO_DDR_P2_MENU_DOWN = 0x03, + + BT_IO_DDR_P1_START = 0x10, + BT_IO_DDR_P1_UP = 0x11, + BT_IO_DDR_P1_DOWN = 0x12, + BT_IO_DDR_P1_LEFT = 0x13, + BT_IO_DDR_P1_RIGHT = 0x14, + BT_IO_DDR_P1_MENU_LEFT = 0x16, + BT_IO_DDR_P1_MENU_RIGHT = 0x17, + BT_IO_DDR_P1_MENU_UP = 0x00, + BT_IO_DDR_P1_MENU_DOWN = 0x01, +} bt_io_ddr_pad_bit_t; + +// see the functions below for more information + +typedef enum bt_io_ddr_p3io_light_bit { + BT_IO_DDR_P3IO_LIGHT_P1_MENU = 0x00, + BT_IO_DDR_P3IO_LIGHT_P2_MENU = 0x01, + BT_IO_DDR_P3IO_LIGHT_P2_LOWER_LAMP = 0x04, + BT_IO_DDR_P3IO_LIGHT_P2_UPPER_LAMP = 0x05, + BT_IO_DDR_P3IO_LIGHT_P1_LOWER_LAMP = 0x06, + BT_IO_DDR_P3IO_LIGHT_P1_UPPER_LAMP = 0x07, +} bt_io_ddr_p3io_light_bit_t; + +typedef enum bt_io_ddr_hdxs_light_bit { + BT_IO_DDR_HDXS_LIGHT_HD_P1_START = 0x08, + BT_IO_DDR_HDXS_LIGHT_HD_P1_UP_DOWN = 0x09, + BT_IO_DDR_HDXS_LIGHT_HD_P1_LEFT_RIGHT = 0x0A, + BT_IO_DDR_HDXS_LIGHT_HD_P2_START = 0x0B, + BT_IO_DDR_HDXS_LIGHT_HD_P2_UP_DOWN = 0x0C, + BT_IO_DDR_HDXS_LIGHT_HD_P2_LEFT_RIGHT = 0x0D, +} bt_io_ddr_hdxs_light_bit_t; + +// the indexing starts from 0x20 if you're looking in geninput +typedef enum bt_io_ddr_hdxs_rgb_light_idx { + BT_IO_DDR_HDXS_LIGHT_HD_P1_SPEAKER_F_R = 0x00, + BT_IO_DDR_HDXS_LIGHT_HD_P1_SPEAKER_F_G = 0x01, + BT_IO_DDR_HDXS_LIGHT_HD_P1_SPEAKER_F_B = 0x02, + BT_IO_DDR_HDXS_LIGHT_HD_P2_SPEAKER_F_R = 0x03, + BT_IO_DDR_HDXS_LIGHT_HD_P2_SPEAKER_F_G = 0x04, + BT_IO_DDR_HDXS_LIGHT_HD_P2_SPEAKER_F_B = 0x05, + BT_IO_DDR_HDXS_LIGHT_HD_P1_SPEAKER_W_R = 0x06, + BT_IO_DDR_HDXS_LIGHT_HD_P1_SPEAKER_W_G = 0x07, + BT_IO_DDR_HDXS_LIGHT_HD_P1_SPEAKER_W_B = 0x08, + BT_IO_DDR_HDXS_LIGHT_HD_P2_SPEAKER_W_R = 0x09, + BT_IO_DDR_HDXS_LIGHT_HD_P2_SPEAKER_W_G = 0x0A, + BT_IO_DDR_HDXS_LIGHT_HD_P2_SPEAKER_W_B = 0x0B, +} bt_io_ddr_hdxs_rgb_light_idx_t; + +typedef enum bt_io_ddr_extio_light_bit { + BT_IO_DDR_EXTIO_LIGHT_NEONS = 0x0E, + + BT_IO_DDR_EXTIO_LIGHT_P2_RIGHT = 0x13, + BT_IO_DDR_EXTIO_LIGHT_P2_LEFT = 0x14, + BT_IO_DDR_EXTIO_LIGHT_P2_DOWN = 0x15, + BT_IO_DDR_EXTIO_LIGHT_P2_UP = 0x16, + + BT_IO_DDR_EXTIO_LIGHT_P1_RIGHT = 0x1B, + BT_IO_DDR_EXTIO_LIGHT_P1_LEFT = 0x1C, + BT_IO_DDR_EXTIO_LIGHT_P1_DOWN = 0x1D, + BT_IO_DDR_EXTIO_LIGHT_P1_UP = 0x1E +} bt_io_ddr_extio_light_bit_t; + +typedef bool (*bt_io_ddr_init_t)(); +typedef void (*bt_io_ddr_fini_t)(); +typedef uint32_t (*bt_io_ddr_pad_read_t)(); +typedef void (*bt_io_ddr_extio_lights_set_t)(uint32_t extio_lights); +typedef void (*bt_io_ddr_p3io_lights_set_t)(uint32_t p3io_lights); +typedef void (*bt_io_ddr_hdxs_lights_panel_set_t)(uint32_t hdxs_lights); +typedef void (*bt_io_ddr_hdxs_lights_rgb_set_t)(uint8_t idx, uint8_t r, uint8_t g, uint8_t b); + +typedef struct bt_io_ddr_api { + uint16_t version; + + struct { + // Required to be implemented + bt_io_ddr_init_t init; + bt_io_ddr_fini_t fini; + bt_io_ddr_pad_read_t pad_read; + bt_io_ddr_extio_lights_set_t extio_lights_set; + bt_io_ddr_p3io_lights_set_t p3io_lights_set; + bt_io_ddr_hdxs_lights_panel_set_t hdxs_lights_panel_set; + bt_io_ddr_hdxs_lights_rgb_set_t hdxs_lights_rgb_set; + } v1; +} bt_io_ddr_api_t; + +#endif diff --git a/src/api/io/eam.h b/src/api/io/eam.h new file mode 100644 index 0000000..7bd4c45 --- /dev/null +++ b/src/api/io/eam.h @@ -0,0 +1,88 @@ +#ifndef BT_API_IO_EAM_H +#define BT_API_IO_EAM_H + +/* Card reader emulator API. You may replace the stock EAMIO.DLL supplied by + Bemanitools with your own custom implementation, which should implement the + interface contract defined in this header file. */ + +#include +#include + +/* Scan codes for the so-called "10 key" button panel on each card reader. Each + scan code corresponds to a bit position within the 16-bit bitfield that you + return from eam_io_get_keypad_state(). */ + +typedef enum bt_io_eam_keypad_scan_code { + BT_IO_EAM_KEYPAD_SCAN_CODE_0 = 0, + BT_IO_EAM_KEYPAD_SCAN_CODE_1 = 1, + BT_IO_EAM_KEYPAD_SCAN_CODE_4 = 2, + BT_IO_EAM_KEYPAD_SCAN_CODE_7 = 3, + BT_IO_EAM_KEYPAD_SCAN_CODE_00 = 4, + BT_IO_EAM_KEYPAD_SCAN_CODE_2 = 5, + BT_IO_EAM_KEYPAD_SCAN_CODE_5 = 6, + BT_IO_EAM_KEYPAD_SCAN_CODE_8 = 7, + BT_IO_EAM_KEYPAD_SCAN_CODE_DECIMAL = 8, + BT_IO_EAM_KEYPAD_SCAN_CODE_3 = 9, + BT_IO_EAM_KEYPAD_SCAN_CODE_6 = 10, + BT_IO_EAM_KEYPAD_SCAN_CODE_9 = 11, + + BT_IO_EAM_KEYPAD_COUNT = 12, /* Not an actual scan code */ +} bt_io_eam_keypad_scan_code_t; + +/* Emulating the sensors of a slotted card reader. The reader has one + sensor at the front that detects if a card is getting inserted or + if the card is not fully removed. When the back sensor is triggered + the card is locked in the slot and its data is read. */ + +typedef enum bt_io_eam_sensor_state { + BT_IO_EAM_SENSOR_STATE_FRONT = 0, + BT_IO_EAM_SENSOR_STATE_BACK = 1, +} bt_io_eam_sensor_state_t; + +/* Different commands for the (slotted) reader. The game triggers one + of these actions and the card slot as to execute it. When non-slotted + readers are emulated, these states are not used/set. */ + +typedef enum bt_io_eam_card_slot_cmd { + BT_IO_EAM_CARD_SLOT_CMD_CLOSE = 0, + BT_IO_EAM_CARD_SLOT_CMD_OPEN = 1, + BT_IO_EAM_CARD_SLOT_CMD_EJECT = 2, + BT_IO_EAM_CARD_SLOT_CMD_READ = 3, +} bt_io_eam_card_slot_cmd_t; + +/* Emulating of the card type for new readers. */ + +typedef enum bt_io_eam_read_card_result { + BT_IO_EAM_READ_CARD_RESULT_NONE = 0, + BT_IO_EAM_READ_CARD_RESULT_ISO15696 = 1, + BT_IO_EAM_READ_CARD_RESULT_FELICA = 2, +} bt_io_eam_read_card_result_t; + +typedef struct bt_io_eam_config_api bt_io_eam_config_api_t; + +typedef bool (*bt_io_eam_init_t)(); +typedef void (*bt_io_eam_fini_t)(); +typedef uint16_t (*bt_io_eam_keypad_state_get_t)(uint8_t unit_no); +typedef uint8_t (*bt_io_eam_sensor_state_get_t)(uint8_t unit_no); +typedef uint8_t (*bt_io_eam_card_read_t)(uint8_t unit_no, uint8_t *card_id, uint8_t nbytes); +typedef bool (*bt_io_eam_card_slot_cmd_send_t)(uint8_t unit_no, uint8_t cmd); +typedef bool (*bt_io_eam_poll_t)(uint8_t unit_no); +typedef const bt_io_eam_config_api_t *(*bt_io_eam_config_api_get_t)(); + +typedef struct bt_io_eam_api { + uint16_t version; + + struct { + // Required to be implemented + bt_io_eam_init_t init; + bt_io_eam_fini_t fini; + bt_io_eam_keypad_state_get_t keypad_state_get; + bt_io_eam_sensor_state_get_t sensor_state_get; + bt_io_eam_card_read_t card_read; + bt_io_eam_card_slot_cmd_send_t card_slot_cmd_send; + bt_io_eam_poll_t poll; + bt_io_eam_config_api_get_t config_api_get; + } v1; +} bt_io_eam_api_t; + +#endif diff --git a/src/api/io/iidx.h b/src/api/io/iidx.h new file mode 100644 index 0000000..1187f3b --- /dev/null +++ b/src/api/io/iidx.h @@ -0,0 +1,122 @@ +#ifndef BT_API_IO_IIDX_H +#define BT_API_IO_IIDX_H + +/* IO emulation provider for beatmania IIDX. */ + +#include +#include + +/* Bit mapping for the "pad" word */ + +typedef enum bt_io_iidx_sys_bit { + BT_IO_IIDX_SYS_TEST = 0x00, + BT_IO_IIDX_SYS_SERVICE = 0x01, + BT_IO_IIDX_SYS_COIN = 0x02 +} bt_io_iidx_sys_bit_t; + +typedef enum bt_io_iidx_panel_bit { + BT_IO_IIDX_PANEL_P1_START = 0x00, + BT_IO_IIDX_PANEL_P2_START = 0x01, + BT_IO_IIDX_PANEL_VEFX = 0x02, + BT_IO_IIDX_PANEL_EFFECT = 0x03 +} bt_io_iidx_panel_bit_t; + +typedef enum bt_io_iidx_key_bit { + BT_IO_IIDX_KEY_P1_1 = 0x00, + BT_IO_IIDX_KEY_P1_2 = 0x01, + BT_IO_IIDX_KEY_P1_3 = 0x02, + BT_IO_IIDX_KEY_P1_4 = 0x03, + BT_IO_IIDX_KEY_P1_5 = 0x04, + BT_IO_IIDX_KEY_P1_6 = 0x05, + BT_IO_IIDX_KEY_P1_7 = 0x06, + + BT_IO_IIDX_KEY_P2_1 = 0x07, + BT_IO_IIDX_KEY_P2_2 = 0x08, + BT_IO_IIDX_KEY_P2_3 = 0x09, + BT_IO_IIDX_KEY_P2_4 = 0x0A, + BT_IO_IIDX_KEY_P2_5 = 0x0B, + BT_IO_IIDX_KEY_P2_6 = 0x0C, + BT_IO_IIDX_KEY_P2_7 = 0x0D +} bt_io_iidx_key_bit_t; + +/* Bit mapping for the P1 and P2 deck lights */ + +typedef enum bt_io_iidx_deck_light { + BT_IO_IIDX_DECK_LIGHT_P1_1 = 0, + BT_IO_IIDX_DECK_LIGHT_P1_2 = 1, + BT_IO_IIDX_DECK_LIGHT_P1_3 = 2, + BT_IO_IIDX_DECK_LIGHT_P1_4 = 3, + BT_IO_IIDX_DECK_LIGHT_P1_5 = 4, + BT_IO_IIDX_DECK_LIGHT_P1_6 = 5, + BT_IO_IIDX_DECK_LIGHT_P1_7 = 6, + + BT_IO_IIDX_DECK_LIGHT_P2_1 = 8, + BT_IO_IIDX_DECK_LIGHT_P2_2 = 9, + BT_IO_IIDX_DECK_LIGHT_P2_3 = 10, + BT_IO_IIDX_DECK_LIGHT_P2_4 = 11, + BT_IO_IIDX_DECK_LIGHT_P2_5 = 12, + BT_IO_IIDX_DECK_LIGHT_P2_6 = 13, + BT_IO_IIDX_DECK_LIGHT_P2_7 = 14, +} bt_io_iidx_deck_light_t; + +/* Bit mapping for the front panel lights */ + +typedef enum bt_io_iidx_panel_light { + BT_IO_IIDX_PANEL_LIGHT_P1_START = 0, + BT_IO_IIDX_PANEL_LIGHT_P2_START = 1, + BT_IO_IIDX_PANEL_LIGHT_VEFX = 2, + BT_IO_IIDX_PANEL_LIGHT_EFFECT = 3, +} bt_io_iidx_panel_light_t; + +/* Bit mapping for the top lamps from left to right when facing cabinet screen + */ + +typedef enum bt_io_iidx_top_lamp { + BT_IO_IIDX_TOP_LAMP_LEFT_BLUE = 0, + BT_IO_IIDX_TOP_LAMP_LEFT_GREEN = 1, + BT_IO_IIDX_TOP_LAMP_LEFT_YELLOW = 2, + BT_IO_IIDX_TOP_LAMP_LEFT_RED = 3, + BT_IO_IIDX_TOP_LAMP_RIGHT_BLUE = 4, + BT_IO_IIDX_TOP_LAMP_RIGHT_GREEN = 5, + BT_IO_IIDX_TOP_LAMP_RIGHT_YELLOW = 6, + BT_IO_IIDX_TOP_LAMP_RIGHT_RED = 7, +} bt_io_iidx_top_lamp_t; + +typedef bool (*bt_io_iidx_init_t)(); +typedef void (*bt_io_iidx_fini_t)(); +typedef void (*bt_io_iidx_ep1_deck_lights_set_t)(uint16_t deck_lights); +typedef void (*bt_io_iidx_ep1_panel_lights_set_t)(uint8_t panel_lights); +typedef void (*bt_io_iidx_ep1_top_lamps_set_t)(uint8_t top_lamps); +typedef void (*bt_io_iidx_ep1_top_neons_set_t)(bool top_neons); +typedef bool (*bt_io_iidx_ep1_send_t)(); +typedef bool (*bt_io_iidx_ep2_recv_t)(); +typedef uint8_t (*bt_io_iidx_ep2_turntable_get_t)(uint8_t player_no); +typedef uint8_t (*bt_io_iidx_ep2_slider_get_t)(uint8_t slider_no); +typedef uint8_t (*bt_io_iidx_ep2_sys_get_t)(); +typedef uint8_t (*bt_io_iidx_ep2_panel_get_t)(); +typedef uint16_t (*bt_io_iidx_ep2_keys_get_t)(); +typedef bool (*bt_io_iidx_ep3_16seg_send_t)(const char *text); + +typedef struct bt_io_iidx_api { + uint16_t version; + + struct { + // Required to be implemented + bt_io_iidx_init_t init; + bt_io_iidx_fini_t fini; + bt_io_iidx_ep1_deck_lights_set_t ep1_deck_lights_set; + bt_io_iidx_ep1_panel_lights_set_t ep1_panel_lights_set; + bt_io_iidx_ep1_top_lamps_set_t ep1_top_lamps_set; + bt_io_iidx_ep1_top_neons_set_t ep1_top_neons_set; + bt_io_iidx_ep1_send_t ep1_send; + bt_io_iidx_ep2_recv_t ep2_recv; + bt_io_iidx_ep2_turntable_get_t ep2_turntable_get; + bt_io_iidx_ep2_slider_get_t ep2_slider_get; + bt_io_iidx_ep2_sys_get_t ep2_sys_get; + bt_io_iidx_ep2_panel_get_t ep2_panel_get; + bt_io_iidx_ep2_keys_get_t ep2_keys_get; + bt_io_iidx_ep3_16seg_send_t ep3_16seg_send; + } v1; +} bt_io_iidx_api_t; + +#endif diff --git a/src/api/io/jb.h b/src/api/io/jb.h new file mode 100644 index 0000000..5359a2e --- /dev/null +++ b/src/api/io/jb.h @@ -0,0 +1,85 @@ +#ifndef BT_API_IO_JB_H +#define BT_API_IO_JB_H + +/* IO emulation provider for jubeat. */ + +#include +#include + +/* input bit mappings. Panels on the controller are + panel 1 top left corner down to panel 16 bottom right corner */ +typedef enum bt_io_jb_panel_bit { + BT_IO_JB_PANEL_01 = 0x00, + BT_IO_JB_PANEL_02 = 0x01, + BT_IO_JB_PANEL_03 = 0x02, + BT_IO_JB_PANEL_04 = 0x03, + BT_IO_JB_PANEL_05 = 0x04, + BT_IO_JB_PANEL_06 = 0x05, + BT_IO_JB_PANEL_07 = 0x06, + BT_IO_JB_PANEL_08 = 0x07, + BT_IO_JB_PANEL_09 = 0x08, + BT_IO_JB_PANEL_10 = 0x09, + BT_IO_JB_PANEL_11 = 0x0A, + BT_IO_JB_PANEL_12 = 0x0B, + BT_IO_JB_PANEL_13 = 0x0C, + BT_IO_JB_PANEL_14 = 0x0D, + BT_IO_JB_PANEL_15 = 0x0E, + BT_IO_JB_PANEL_16 = 0x0F, +} bt_io_jb_panel_bit_t; + +/* input "single button mode" mappings. Allows you to check each corner of each + button to determine any flaky inputs +*/ +typedef enum bt_io_jb_panel_mode { + BT_IO_JB_PANEL_MODE_ALL = 0, // any of the four corners will trigger a panel + BT_IO_JB_PANEL_MODE_TOP_LEFT = 1, + BT_IO_JB_PANEL_MODE_TOP_RIGHT = 2, + BT_IO_JB_PANEL_MODE_BOTTOM_RIGHT = 3, + BT_IO_JB_PANEL_MODE_BOTTOM_LEFT = 4, +} bt_io_jb_panel_mode_t; + +/* Bit mappings for "system" inputs */ +typedef enum bt_io_jb_sys_bit { + BT_IO_JB_SYS_TEST = 0x00, + BT_IO_JB_SYS_SERVICE = 0x01, + BT_IO_JB_SYS_COIN = 0x02, +} bt_io_jb_sys_bit_t; + +/* RGB led units to address */ +typedef enum bt_io_jb_rgb_led { + BT_IO_JB_RGB_LED_FRONT = 0, + BT_IO_JB_RGB_LED_TOP = 1, + BT_IO_JB_RGB_LED_LEFT = 2, + BT_IO_JB_RGB_LED_RIGHT = 3, + BT_IO_JB_RGB_LED_TITLE = 4, + BT_IO_JB_RGB_LED_WOOFER = 5 +} bt_io_jb_rgb_led_t; + +typedef bool (*bt_io_jb_init_t)(); +typedef void (*bt_io_jb_fini_t)(); +typedef bool (*bt_io_jb_inputs_read_t)(); +typedef uint8_t (*bt_io_jb_sys_inputs_get_t)(); +typedef uint16_t (*bt_io_jb_panel_inputs_get_t)(); +typedef void (*bt_io_jb_rgb_led_set_t)(bt_io_jb_rgb_led_t unit, uint8_t r, uint8_t g, uint8_t b); +typedef bool (*bt_io_jb_lights_write_t)(); +typedef bool (*bt_io_jb_panel_mode_set_t)(bt_io_jb_panel_mode_t mode); +typedef bool (*bt_io_jb_coin_blocker_set_t)(bool blocked); + +typedef struct bt_io_jb_api { + uint16_t version; + + struct { + // Required to be implemented + bt_io_jb_init_t init; + bt_io_jb_fini_t fini; + bt_io_jb_inputs_read_t inputs_read; + bt_io_jb_sys_inputs_get_t sys_inputs_get; + bt_io_jb_panel_inputs_get_t panel_inputs_get; + bt_io_jb_rgb_led_set_t rgb_led_set; + bt_io_jb_lights_write_t lights_write; + bt_io_jb_panel_mode_set_t panel_mode_set; + bt_io_jb_coin_blocker_set_t coin_blocker_set; + } v1; +} bt_io_jb_api_t; + +#endif diff --git a/src/api/io/popn.h b/src/api/io/popn.h new file mode 100644 index 0000000..388f7ea --- /dev/null +++ b/src/api/io/popn.h @@ -0,0 +1,80 @@ +#ifndef BT_API_IO_POPN_H +#define BT_API_IO_POPN_H + +/* IO emulation provider for pop'n music. */ + +#include +#include + +/* Bit mapping for the "buttons" word */ + +typedef enum bt_io_popn_sys_bit { + BT_IO_POPN_SYS_SERVICE = 0x06, + BT_IO_POPN_SYS_TEST = 0x07, +} bt_io_popn_sys_bit_t; + +typedef enum bt_io_popn_button_bit { + BT_IO_POPN_BUTTON_1 = 0x08, + BT_IO_POPN_BUTTON_2 = 0x09, + BT_IO_POPN_BUTTON_3 = 0x0a, + BT_IO_POPN_BUTTON_4 = 0x0b, + BT_IO_POPN_BUTTON_5 = 0x0c, + BT_IO_POPN_BUTTON_6 = 0x0d, + BT_IO_POPN_BUTTON_7 = 0x0e, + BT_IO_POPN_BUTTON_8 = 0x0f, + BT_IO_POPN_BUTTON_9 = 0x10, +} bt_io_popn_button_bit_t; + +typedef enum bt_io_popn_light_top_lamp_bit { + BT_IO_POPN_LIGHT_HI_LAMP1 = 0x00, + BT_IO_POPN_LIGHT_HI_LAMP2 = 0x01, + BT_IO_POPN_LIGHT_HI_LAMP3 = 0x02, + BT_IO_POPN_LIGHT_HI_LAMP4 = 0x03, + BT_IO_POPN_LIGHT_HI_LAMP5 = 0x04, +} bt_io_popn_light_top_lamp_bit_t; + +typedef enum bt_io_popn_light_side_lamp_bit { + BT_IO_POPN_LIGHT_LEFT_LAMP1 = 0x00, + BT_IO_POPN_LIGHT_LEFT_LAMP2 = 0x01, + BT_IO_POPN_LIGHT_RIGHT_LAMP1 = 0x02, + BT_IO_POPN_LIGHT_RIGHT_LAMP2 = 0x03, +} bt_io_popn_light_side_lamp_bit_t; + +typedef enum bt_io_popn_light_switch_lamp_bit { + BT_IO_POPN_LIGHT_SW_LAMP1 = 0x00, // Is actually 4 bits wide + BT_IO_POPN_LIGHT_SW_LAMP2 = 0x04, + BT_IO_POPN_LIGHT_SW_LAMP3 = 0x05, + BT_IO_POPN_LIGHT_SW_LAMP4 = 0x06, + BT_IO_POPN_LIGHT_SW_LAMP5 = 0x07, + BT_IO_POPN_LIGHT_SW_LAMP6 = 0x08, + BT_IO_POPN_LIGHT_SW_LAMP7 = 0x09, + BT_IO_POPN_LIGHT_SW_LAMP8 = 0x0a, + BT_IO_POPN_LIGHT_SW_LAMP9 = 0x0b, +} bt_io_popn_light_switch_lamp_bit_t; + +typedef bool (*bt_io_popn_init_t)(); +typedef void (*bt_io_popn_fini_t)(); +typedef uint32_t (*bt_io_popn_buttons_get_t)(); +typedef void (*bt_io_popn_top_lights_set_t)(uint32_t lights); +typedef void (*bt_io_popn_side_lights_set_t)(uint32_t lights); +typedef void (*bt_io_popn_button_lights_set_t)(uint32_t lights); +typedef void (*bt_io_popn_coin_blocker_light_set_t)(bool enabled); +typedef void (*bt_io_popn_coin_counter_light_set_t)(bool enabled); + +typedef struct bt_io_popn_api { + uint16_t version; + + struct { + // Required to be implemented + bt_io_popn_init_t init; + bt_io_popn_fini_t fini; + bt_io_popn_buttons_get_t buttons_get; + bt_io_popn_top_lights_set_t top_lights_set; + bt_io_popn_side_lights_set_t side_lights_set; + bt_io_popn_button_lights_set_t button_lights_set; + bt_io_popn_coin_blocker_light_set_t coin_blocker_light_set; + bt_io_popn_coin_counter_light_set_t coin_counter_light_set; + } v1; +} bt_io_popn_api_t; + +#endif diff --git a/src/api/io/sdvx.h b/src/api/io/sdvx.h new file mode 100644 index 0000000..a60f248 --- /dev/null +++ b/src/api/io/sdvx.h @@ -0,0 +1,70 @@ +#ifndef BT_API_IO_SDVX_H +#define BT_API_IO_SDVX_H + +/* IO emulation provider for SOUND VOLTEX */ + +#include +#include + +typedef enum bt_io_sdvx_in_gpio_sys_bit { + BT_IO_SDVX_IN_GPIO_SYS_COIN = 2, + BT_IO_SDVX_IN_GPIO_SYS_SERVICE = 4, + BT_IO_SDVX_IN_GPIO_SYS_TEST = 5, +} bt_io_sdvx_in_gpio_sys_bit_t; + +typedef enum bt_io_sdvx_in_gpio_0_bit { + BT_IO_SDVX_IN_GPIO_0_C = 0, + BT_IO_SDVX_IN_GPIO_0_B = 1, + BT_IO_SDVX_IN_GPIO_0_A = 2, + BT_IO_SDVX_IN_GPIO_0_START = 3, + BT_IO_SDVX_IN_GPIO_0_RECORDER = 4, + BT_IO_SDVX_IN_GPIO_0_HEADPHONE = 5, +} bt_io_sdvx_in_gpio_0_bit_t; + +typedef enum bt_io_sdvx_in_gpio_1_bit { + BT_IO_SDVX_IN_GPIO_1_FX_R = 3, + BT_IO_SDVX_IN_GPIO_1_FX_L = 4, + BT_IO_SDVX_IN_GPIO_1_D = 5, +} bt_io_sdvx_in_gpio_1_bit_t; + +typedef enum bt_io_sdvx_out_gpio_bit { + BT_IO_SDVX_OUT_GPIO_D = 0, + BT_IO_SDVX_OUT_GPIO_FX_L = 1, + BT_IO_SDVX_OUT_GPIO_FX_R = 2, + BT_IO_SDVX_OUT_GPIO_GENERATOR_B = 3, + BT_IO_SDVX_OUT_GPIO_START = 12, + BT_IO_SDVX_OUT_GPIO_A = 13, + BT_IO_SDVX_OUT_GPIO_B = 14, + BT_IO_SDVX_OUT_GPIO_C = 15, +} bt_io_sdvx_out_gpio_bit_t; + +typedef bool (*bt_io_sdvx_init_t)(); +typedef void (*bt_io_sdvx_fini_t)(); +typedef void (*bt_io_sdvx_gpio_lights_set_t)(uint32_t gpio_lights); +typedef void (*bt_io_sdvx_pwm_light_set_t)(uint8_t light_no, uint8_t intensity); +typedef bool (*bt_io_sdvx_output_write_t)(); +typedef bool (*bt_io_sdvx_input_read_t)(); +typedef uint8_t (*bt_io_sdvx_input_gpio_sys_get_t)(); +typedef uint16_t (*bt_io_sdvx_input_gpio_get_t)(uint8_t gpio_bank); +typedef uint16_t (*bt_io_sdvx_spinner_pos_get_t)(uint8_t spinner_no); +typedef bool (*bt_io_sdvx_amp_volume_set_t)(uint8_t primary, uint8_t headphone, uint8_t subwoofer); + +typedef struct bt_io_sdvx_api { + uint16_t version; + + struct { + // Required to be implemented + bt_io_sdvx_init_t init; + bt_io_sdvx_fini_t fini; + bt_io_sdvx_gpio_lights_set_t gpio_lights_set; + bt_io_sdvx_pwm_light_set_t pwm_light_set; + bt_io_sdvx_output_write_t output_write; + bt_io_sdvx_input_read_t input_read; + bt_io_sdvx_input_gpio_sys_get_t input_gpio_sys_get; + bt_io_sdvx_input_gpio_get_t input_gpio_get; + bt_io_sdvx_spinner_pos_get_t spinner_pos_get; + bt_io_sdvx_amp_volume_set_t amp_volume_set; + } v1; +} bt_io_sdvx_api_t; + +#endif diff --git a/src/api/io/vefx.h b/src/api/io/vefx.h new file mode 100644 index 0000000..362a3c1 --- /dev/null +++ b/src/api/io/vefx.h @@ -0,0 +1,28 @@ +#ifndef BT_API_IO_VEFX_H +#define BT_API_IO_VEFX_H + +/* IO emulation provider for beatmania IIDX Effector Panel. */ + +#include +#include + +typedef bool (*bt_io_vefx_init_t)(); +typedef void (*bt_io_vefx_fini_t)(); +typedef bool (*bt_io_vefx_recv_t)(uint64_t *ppad); +typedef uint8_t (*bt_io_vefx_slider_get_t)(uint8_t slider_no); +typedef bool (*bt_io_vefx_16seg_send_t)(const char *text); + +typedef struct bt_io_vefx_api { + uint16_t version; + + struct { + // Required to be implemented + bt_io_vefx_init_t init; + bt_io_vefx_fini_t fini; + bt_io_vefx_recv_t recv; + bt_io_vefx_slider_get_t slider_get; + bt_io_vefx_16seg_send_t _16seg_send; + } v1; +} bt_io_vefx_api_t; + +#endif diff --git a/src/api/log.h b/src/api/log.h deleted file mode 100644 index 638a269..0000000 --- a/src/api/log.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef BEMANITOOLS_API_THREAD_H -#define BEMANITOOLS_API_THREAD_H - -#include - -#ifdef __GNUC__ -/* Bemanitools is compiled with GCC (MinGW, specifically) as of version 5 */ -#define LOG_CHECK_FMT __attribute__((format(printf, 2, 3))) -#else -/* Compile it out for MSVC plebs */ -#define LOG_CHECK_FMT -#endif - -/* An AVS-style logger function. Comes in four flavors: misc, info, warning, - and fatal, with increasing severity. Fatal loggers do not return, they - abort the running process after writing their message to the log. - - "module" is an arbitrary short string identifying the source of the log - message. The name of the calling DLL is a good default choice for this - string, although you might want to identify a module within your DLL here - instead. - - "fmt" is a printf-style format string. Depending on the context in which - your DLL is running you might end up calling a logger function exported - from libavs, which has its own printf implementation (including a number of - proprietary extensions), so don't use any overly exotic formats. */ - -typedef void (*btapi_log_formatter_t)(const char *module, const char *fmt, ...) - LOG_CHECK_FMT; - -#endif diff --git a/src/api/thread.h b/src/api/thread.h deleted file mode 100644 index 0459c9d..0000000 --- a/src/api/thread.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef BEMANITOOLS_API_THREAD_H -#define BEMANITOOLS_API_THREAD_H - -#include - -/* An API for spawning threads. This API is defined by libavs, although - Bemanitools itself may supply compatible implementations of these functions - to your DLL, depending on the context in which it runs. - - NOTE: You may only use the logging functions from a thread where Bemanitools - calls you, or a thread that you create using this API. Failure to observe - this restriction will cause the process to crash. This is a limitation of - libavs itself, not Bemanitools. */ - -typedef int (*btapi_thread_create_t)( - int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority); -typedef void (*btapi_thread_join_t)(int thread_id, int *result); -typedef void (*btapi_thread_destroy_t)(int thread_id); - -#endif diff --git a/src/imports/avs.h b/src/imports/avs.h index ae054e5..2e6ddc7 100644 --- a/src/imports/avs.h +++ b/src/imports/avs.h @@ -142,7 +142,7 @@ typedef void (*avs_log_writer_t)(const char *chars, uint32_t nchars, void *ctx); typedef void (*avs_log_writer_t)(void *ctx, const char *chars, uint32_t nchars); #endif -typedef int (*avs_reader_t)(uint32_t context, void *bytes, size_t nbytes); +typedef size_t (*avs_reader_t)(uint32_t context, void *bytes, size_t nbytes); #if AVS_VERSION >= 1600 /* "avs" and "std" heaps have been unified */ @@ -186,7 +186,7 @@ void avs_shutdown(void); typedef uint32_t avs_desc; typedef int avs_error; -#define AVS_IS_ERROR(x) x < 0 +#define AVS_IS_ERROR(x) ((avs_error) x) < 0 void log_body_fatal(const char *module, const char *fmt, ...); void log_body_info(const char *module, const char *fmt, ...); @@ -223,12 +223,12 @@ void property_destroy(struct property *prop); avs_error property_get_error(struct property *prop); void property_clear_error(struct property *prop); -int property_psmap_import( +avs_error property_psmap_import( struct property *prop, struct property_node *root, void *dest, const struct property_psmap *psmap); -int property_psmap_export( +avs_error property_psmap_export( struct property *prop, struct property_node *root, const void *src, @@ -254,7 +254,7 @@ int property_node_refer( enum property_type type, void *bytes, uint32_t nbytes); -void property_node_remove(struct property_node *node); +avs_error property_node_remove(struct property_node *node); enum property_type property_node_type(struct property_node *node); struct property_node *property_node_traversal( struct property_node *node, enum property_node_traversal direction); @@ -315,7 +315,7 @@ enum avs_seek_origin { avs_desc avs_fs_open(const char *path, uint16_t mode, int flags); int avs_fs_close(avs_desc desc); -size_t avs_fs_read(avs_desc desc, char *buf, uint32_t sz); +size_t avs_fs_read(avs_desc desc, void *buf, size_t sz); int avs_fs_lseek(avs_desc desc, long pos, int whence); int avs_fs_lstat(const char *path, struct avs_stat *st); int avs_fs_copy(const char *src, const char *dest); diff --git a/src/imports/import_32_1101_avs.def b/src/imports/import_32_1101_avs.def index 776dc71..332c0f2 100644 --- a/src/imports/import_32_1101_avs.def +++ b/src/imports/import_32_1101_avs.def @@ -26,8 +26,8 @@ EXPORTS property_desc_to_buffer @246 NONAME property_destroy @247 NONAME property_insert_read @255 NONAME - property_clear_error @573 NONAME - property_get_error @573 NONAME + property_clear_error @244 NONAME + property_get_error @253 NONAME property_node_create @266 NONAME property_node_datasize @267 NONAME property_node_name @274 NONAME @@ -35,8 +35,8 @@ EXPORTS property_node_refer @278 NONAME property_node_remove @279 NONAME property_node_type @282 NONAME - property_node_clone @280 NONAME - property_node_traversal @282 NONAME + property_node_clone @265 NONAME + property_node_traversal @281 NONAME property_node_refdata @277 NONAME property_query_size @290 NONAME property_psmap_import @288 NONAME diff --git a/src/imports/import_32_1304_avs.def b/src/imports/import_32_1304_avs.def index 18dad23..cff9b29 100644 --- a/src/imports/import_32_1304_avs.def +++ b/src/imports/import_32_1304_avs.def @@ -1,46 +1,46 @@ LIBRARY libavs-win32 EXPORTS - avs_boot @237 NONAME - avs_fs_close @276 NONAME - avs_fs_copy @283 NONAME - avs_fs_lseek @16 NONAME - avs_fs_lstat @97 NONAME - avs_fs_open @178 NONAME - avs_fs_read @306 NONAME - avs_fs_opendir @216 NONAME - avs_fs_readdir @130 NONAME - avs_fs_closedir @131 NONAME - avs_net_ctrl @15 NONAME - avs_shutdown @333 NONAME - avs_thread_create @183 NONAME - avs_thread_destroy @76 NONAME - avs_thread_exit @147 NONAME - avs_thread_join @92 NONAME - log_body_misc @44 NONAME - log_body_info @339 NONAME - log_body_warning @219 NONAME - log_body_fatal @128 NONAME - property_create @256 NONAME - property_desc_to_buffer @201 NONAME - property_destroy @264 NONAME - property_insert_read @23 NONAME - property_clear_error @573 NONAME - property_get_error @573 NONAME - property_node_create @316 NONAME - property_node_datasize @249 NONAME - property_node_name @255 NONAME - property_node_read @2 NONAME - property_node_refer @268 NONAME - property_node_remove @129 NONAME - property_node_type @329 NONAME - property_node_clone @130 NONAME - property_node_traversal @93 NONAME + avs_boot @237 NONAME == XC058ba50000f4 + avs_fs_close @276 NONAME == XC058ba500011b + avs_fs_copy @283 NONAME == XC058ba5000122 + avs_fs_lseek @16 NONAME == XC058ba500000f + avs_fs_lstat @97 NONAME == XC058ba5000063 + avs_fs_open @178 NONAME == XC058ba50000b6 + avs_fs_read @306 NONAME == XC058ba5000139 + avs_fs_opendir @216 NONAME == XC058ba50000dd + avs_fs_readdir @130 NONAME == XC058ba5000086 + avs_fs_closedir @131 NONAME == XC058ba5000087 + avs_net_ctrl @15 NONAME == XC058ba500000e + avs_shutdown @333 NONAME == XC058ba5000154 + avs_thread_create @183 NONAME == XC058ba50000bb + avs_thread_destroy @76 NONAME == XC058ba500004e + avs_thread_exit @147 NONAME == XC058ba5000097 + avs_thread_join @92 NONAME == XC058ba500005e + log_body_misc @44 NONAME == XC058ba500002d + log_body_info @339 NONAME == XC058ba500015a + log_body_warning @219 NONAME == XC058ba50000e1 + log_body_fatal @128 NONAME == XC058ba5000084 + property_create @256 NONAME == XC058ba5000107 + property_desc_to_buffer @201 NONAME == XC058ba50000cd + property_destroy @264 NONAME == XC058ba500010f + property_insert_read @23 NONAME == XC058ba5000016 + property_clear_error @163 NONAME == XC058ba50000a7 + property_get_error @295 NONAME == XC058ba500012e + property_node_create @316 NONAME == XC058ba5000143 + property_node_datasize @249 NONAME == XC058ba5000100 + property_node_name @255 NONAME == XC058ba5000106 + property_node_read @2 NONAME == XC058ba5000001 + property_node_refer @268 NONAME == XC058ba5000113 + property_node_remove @129 NONAME == XC058ba5000085 + property_node_type @329 NONAME == XC058ba5000150 + property_node_clone @252 NONAME == XC058ba5000103 + property_node_traversal @93 NONAME == XC058ba500005f property_node_refdata @330 NONAME == XC058ba5000151 property_query_size @250 NONAME == XC058ba5000101 - property_psmap_import @102 NONAME - property_psmap_export @110 NONAME - property_read_query_memsize @100 NONAME - property_search @244 NONAME - std_getenv @226 NONAME - std_setenv @114 NONAME + property_psmap_import @102 NONAME == XC058ba5000068 + property_psmap_export @110 NONAME == XC058ba5000071 + property_read_query_memsize @100 NONAME == XC058ba5000066 + property_search @244 NONAME == XC058ba50000fb + std_getenv @226 NONAME == XC058ba50000e8 + std_setenv @114 NONAME == XC058ba5000075 diff --git a/src/imports/import_32_1306_avs.def b/src/imports/import_32_1306_avs.def index f6deed7..cff9b29 100644 --- a/src/imports/import_32_1306_avs.def +++ b/src/imports/import_32_1306_avs.def @@ -25,8 +25,8 @@ EXPORTS property_desc_to_buffer @201 NONAME == XC058ba50000cd property_destroy @264 NONAME == XC058ba500010f property_insert_read @23 NONAME == XC058ba5000016 - property_clear_error @573 NONAME - property_get_error @573 NONAME + property_clear_error @163 NONAME == XC058ba50000a7 + property_get_error @295 NONAME == XC058ba500012e property_node_create @316 NONAME == XC058ba5000143 property_node_datasize @249 NONAME == XC058ba5000100 property_node_name @255 NONAME == XC058ba5000106 diff --git a/src/imports/import_32_1508_avs.def b/src/imports/import_32_1508_avs.def index 504a303..f7a7463 100644 --- a/src/imports/import_32_1508_avs.def +++ b/src/imports/import_32_1508_avs.def @@ -6,8 +6,8 @@ EXPORTS avs_fs_lseek @59 NONAME avs_fs_lseek64 @60 NONAME avs_fs_lstat @79 NONAME - avs_fs_open @58 NONAME - avs_fs_read @61 NONAME + avs_fs_open @58 NONAME == XCd229cc000090 + avs_fs_read @61 NONAME == XCd229cc00010d avs_fs_copy @81 NONAME avs_fs_opendir @72 NONAME == XCd229cc0000f0 avs_fs_readdir @73 NONAME == XCd229cc0000bb @@ -26,8 +26,8 @@ EXPORTS property_desc_to_buffer @129 NONAME property_destroy @128 NONAME property_insert_read @131 NONAME - property_clear_error @573 NONAME - property_get_error @573 NONAME + property_clear_error @140 NONAME == XCd229cc00014b + property_get_error @141 NONAME == XCd229cc0000b5 property_node_create @145 NONAME property_node_name @150 NONAME property_node_read @154 NONAME == XCd229cc0000f3 @@ -41,7 +41,7 @@ EXPORTS property_query_size @142 NONAME == XCd229cc000032 property_psmap_export @162 NONAME property_psmap_import @161 NONAME - property_read_query_memsize @159 NONAME + property_read_query_memsize @159 NONAME == XCd229cc0000ff property_search @144 NONAME std_getenv @207 NONAME std_setenv @208 NONAME diff --git a/src/imports/import_32_1601_avs.def b/src/imports/import_32_1601_avs.def index 286806b..4921e35 100644 --- a/src/imports/import_32_1601_avs.def +++ b/src/imports/import_32_1601_avs.def @@ -5,8 +5,8 @@ EXPORTS avs_fs_copy @81 NONAME avs_fs_lseek @59 NONAME avs_fs_lstat @79 NONAME - avs_fs_open @58 NONAME - avs_fs_read @61 NONAME + avs_fs_open @58 NONAME == XCnbrep7000039 + avs_fs_read @61 NONAME == XCnbrep700003c avs_fs_opendir @72 NONAME == XCnbrep7000047 avs_fs_readdir @73 NONAME == XCnbrep7000048 avs_fs_closedir @74 NONAME == XCnbrep7000049 @@ -19,8 +19,8 @@ EXPORTS property_destroy @125 NONAME property_desc_to_buffer @126 NONAME property_insert_read @128 NONAME - property_clear_error @573 NONAME - property_get_error @573 NONAME + property_clear_error @137 NONAME == XCnbrep7000088 + property_get_error @138 NONAME == XCnbrep7000089 property_search @141 NONAME property_node_create @142 NONAME property_node_name @147 NONAME == XCnbrep7000092 diff --git a/src/main/acio-mgr/Module.mk b/src/main/acio-mgr/Module.mk new file mode 100644 index 0000000..4f02bc8 --- /dev/null +++ b/src/main/acio-mgr/Module.mk @@ -0,0 +1,11 @@ +dlls += acio-mgr + +libs_acio-mgr := \ + aciodrv \ + iface-core \ + core \ + util \ + +src_acio-mgr := \ + dllmain.c \ + mgr.c \ diff --git a/src/main/acio-mgr/acio-mgr.def b/src/main/acio-mgr/acio-mgr.def new file mode 100644 index 0000000..1b99720 --- /dev/null +++ b/src/main/acio-mgr/acio-mgr.def @@ -0,0 +1,20 @@ +LIBRARY acio-mgr + +EXPORTS + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_acio_mgr_api_get + + ; Not exporting as these are called in DllMain + ; bt_acio_mgr_init + ; bt_acio_mgr_fini + DllMain@12 @1 NONAME + + ; Direct API + bt_acio_mgr_port_init + bt_acio_mgr_port_fini + bt_acio_mgr_node_count_get + bt_acio_mgr_node_product_ident_get + bt_acio_mgr_port_packet_submit + bt_acio_mgr_port_checkout + bt_acio_mgr_port_checkin diff --git a/src/main/aciomgr/dllmain.c b/src/main/acio-mgr/dllmain.c similarity index 69% rename from src/main/aciomgr/dllmain.c rename to src/main/acio-mgr/dllmain.c index 9ab5aa9..37cd4df 100644 --- a/src/main/aciomgr/dllmain.c +++ b/src/main/acio-mgr/dllmain.c @@ -1,15 +1,15 @@ #include -#include "manager-init.h" +#include "acio-mgr/internal.h" BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - _aciomgr_init(); + bt_acio_mgr_init(); } if (reason == DLL_PROCESS_DETACH) { - _aciomgr_fini(); + bt_acio_mgr_fini(); } return TRUE; diff --git a/src/main/acio-mgr/internal.h b/src/main/acio-mgr/internal.h new file mode 100644 index 0000000..0a4d7a4 --- /dev/null +++ b/src/main/acio-mgr/internal.h @@ -0,0 +1,7 @@ +#ifndef ACIO_MGR_INTERNAL_T +#define ACIO_MGR_INTERNAL_T + +void bt_acio_mgr_init(); +void bt_acio_mgr_fini(); + +#endif \ No newline at end of file diff --git a/src/main/aciomgr/manager.c b/src/main/acio-mgr/mgr.c similarity index 59% rename from src/main/aciomgr/manager.c rename to src/main/acio-mgr/mgr.c index d7f0378..ea40cfa 100644 --- a/src/main/aciomgr/manager.c +++ b/src/main/acio-mgr/mgr.c @@ -4,40 +4,43 @@ #include -#include "aciomgr/manager-init.h" -#include "aciomgr/manager.h" - #include "acio/acio.h" - #include "aciodrv/device.h" -#include "core/log.h" +#include "acio-mgr/internal.h" + +#include "api/core/log.h" + +#include "iface-core/log.h" + +#include "sdk/module/acio/mgr.h" +#include "sdk/module/core/log.h" #include "util/array.h" #define MAX_PORT_PATH_LENGTH 256 -struct aciomgr_port_dispatcher { +typedef struct bt_acio_mgr_port_dispatcher { CRITICAL_SECTION cs; atomic_size_t references; struct aciodrv_device_ctx *device; char path[MAX_PORT_PATH_LENGTH]; int baud; bool has_failure; -}; +} bt_acio_mgr_port_dispatcher_t; -static void _aciomgr_setup_port_dispatcher( - struct aciomgr_port_dispatcher *dispatcher, const char *path, int baud); +static void _bt_acio_mgr_setup_port_dispatcher( + bt_acio_mgr_port_dispatcher_t *dispatcher, const char *path, int baud); static void -_aciomgr_destroy_port_dispatcher(struct aciomgr_port_dispatcher *dispatcher); +_bt_acio_mgr_destroy_port_dispatcher(bt_acio_mgr_port_dispatcher_t *dispatcher); // DLL-globals static atomic_bool running; static CRITICAL_SECTION mgr_cs; static struct array active_ports; -static void _aciomgr_setup_port_dispatcher( - struct aciomgr_port_dispatcher *dispatcher, const char *path, int baud) +static void _bt_acio_mgr_setup_port_dispatcher( + bt_acio_mgr_port_dispatcher_t *dispatcher, const char *path, int baud) { InitializeCriticalSection(&dispatcher->cs); @@ -56,17 +59,17 @@ static void _aciomgr_setup_port_dispatcher( } static void -_aciomgr_destroy_port_dispatcher(struct aciomgr_port_dispatcher *dispatcher) +_bt_acio_mgr_destroy_port_dispatcher(bt_acio_mgr_port_dispatcher_t *dispatcher) { aciodrv_device_close(dispatcher->device); DeleteCriticalSection(&dispatcher->cs); } -void _aciomgr_init() +void bt_acio_mgr_init() { if (running) { log_warning("_aciomgr_init called when already running"); - _aciomgr_fini(); + bt_acio_mgr_fini(); } InitializeCriticalSection(&mgr_cs); array_init(&active_ports); @@ -74,7 +77,7 @@ void _aciomgr_init() running = true; } -void _aciomgr_fini() +void bt_acio_mgr_fini() { if (!running) { log_warning("_aciomgr_fini called when not running"); @@ -85,16 +88,8 @@ void _aciomgr_fini() array_fini(&active_ports); } -void aciomgr_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - core_log_impl_set(misc, warning, info, fatal); -} - -struct aciomgr_port_dispatcher *aciomgr_port_init(const char *path, int baud) +bt_acio_mgr_port_dispatcher_t * +bt_acio_mgr_port_init(const char *path, uint32_t baud) { if (!running) { log_warning("aciomgr_port_init: called when not running"); @@ -106,12 +101,12 @@ struct aciomgr_port_dispatcher *aciomgr_port_init(const char *path, int baud) return NULL; } - struct aciomgr_port_dispatcher *entry; + bt_acio_mgr_port_dispatcher_t *entry; EnterCriticalSection(&mgr_cs); for (size_t i = 0; i < active_ports.nitems; i++) { - entry = array_item(struct aciomgr_port_dispatcher, &active_ports, i); + entry = array_item(bt_acio_mgr_port_dispatcher_t, &active_ports, i); if (strcmp(entry->path, path) == 0) { // found @@ -126,8 +121,8 @@ struct aciomgr_port_dispatcher *aciomgr_port_init(const char *path, int baud) } } - entry = array_append(struct aciomgr_port_dispatcher, &active_ports); - _aciomgr_setup_port_dispatcher(entry, path, baud); + entry = array_append(bt_acio_mgr_port_dispatcher_t, &active_ports); + _bt_acio_mgr_setup_port_dispatcher(entry, path, baud); done: if (!entry->has_failure) { @@ -143,7 +138,7 @@ done: return entry; } -void aciomgr_port_fini(struct aciomgr_port_dispatcher *dispatcher) +void bt_acio_mgr_port_fini(bt_acio_mgr_port_dispatcher_t *dispatcher) { if (!running) { log_warning("aciomgr_port_fini: called when not running"); @@ -155,30 +150,31 @@ void aciomgr_port_fini(struct aciomgr_port_dispatcher *dispatcher) LeaveCriticalSection(&mgr_cs); if (dispatcher->references == 0) { - _aciomgr_destroy_port_dispatcher(dispatcher); + _bt_acio_mgr_destroy_port_dispatcher(dispatcher); } } // this function don't require the lock -uint8_t aciomgr_get_node_count(struct aciomgr_port_dispatcher *dispatcher) +uint8_t +bt_acio_mgr_node_count_get(const bt_acio_mgr_port_dispatcher_t *dispatcher) { return aciodrv_device_get_node_count(dispatcher->device); } // this function don't require the lock -bool aciomgr_get_node_product_ident( - struct aciomgr_port_dispatcher *dispatcher, +bool bt_acio_mgr_node_product_ident_get( + const bt_acio_mgr_port_dispatcher_t *dispatcher, uint8_t node_id, - char product[ACIOMGR_NODE_PRODUCT_CODE_LEN]) + char product[BT_ACIO_MGR_NODE_PRODUCT_CODE_LEN]) { return aciodrv_device_get_node_product_ident( dispatcher->device, node_id, product); } -bool aciomgr_port_submit_packet( - struct aciomgr_port_dispatcher *dispatcher, - struct ac_io_message *msg, - int max_resp_size) +bool bt_acio_mgr_port_packet_submit( + bt_acio_mgr_port_dispatcher_t *dispatcher, + bt_acio_message_t *msg, + uint32_t max_resp_size) { // CS's although lightweight, may still be a burden, short circuit if (dispatcher->references > 1) { @@ -192,8 +188,8 @@ bool aciomgr_port_submit_packet( return aciodrv_send_and_recv(dispatcher->device, msg, max_resp_size); } -struct aciodrv_device_ctx * -aciomgr_port_checkout(struct aciomgr_port_dispatcher *dispatcher) +bt_acio_drv_device_ctx_t * +bt_acio_mgr_port_checkout(bt_acio_mgr_port_dispatcher_t *dispatcher) { if (dispatcher->references > 1) { EnterCriticalSection(&dispatcher->cs); @@ -202,9 +198,27 @@ aciomgr_port_checkout(struct aciomgr_port_dispatcher *dispatcher) return dispatcher->device; } -void aciomgr_port_checkin(struct aciomgr_port_dispatcher *dispatcher) +void bt_acio_mgr_port_checkin(bt_acio_mgr_port_dispatcher_t *dispatcher) { if (dispatcher->references > 1) { LeaveCriticalSection(&dispatcher->cs); } } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_acio_mgr_api_get(bt_acio_mgr_api_t *api) +{ + api->version = 1; + + api->v1.port_init = bt_acio_mgr_port_init; + api->v1.port_fini = bt_acio_mgr_port_fini; + api->v1.node_count_get = bt_acio_mgr_node_count_get; + api->v1.node_product_ident_get = bt_acio_mgr_node_product_ident_get; + api->v1.port_packet_submit = bt_acio_mgr_port_packet_submit; + api->v1.port_checkout = bt_acio_mgr_port_checkout; + api->v1.port_checkin = bt_acio_mgr_port_checkin; +} \ No newline at end of file diff --git a/src/main/aciodrv-proc/panb.c b/src/main/aciodrv-proc/panb.c index 3f9d5a4..4eda113 100644 --- a/src/main/aciodrv-proc/panb.c +++ b/src/main/aciodrv-proc/panb.c @@ -5,9 +5,8 @@ #include "aciodrv/device.h" #include "aciodrv/panb.h" -#include "core/thread.h" - -#include "core/log.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" static int auto_poll_proc(void *auto_poll_param); static int auto_poll_threadid; @@ -41,6 +40,8 @@ static int auto_poll_proc(void *param) bool aciodrv_proc_panb_init(struct aciodrv_device_ctx *device) { + bt_core_thread_result_t result; + log_assert(device); if (!aciodrv_panb_start_auto_input(device, 0, AC_IO_PANB_NUM_NODES)) { @@ -50,8 +51,10 @@ bool aciodrv_proc_panb_init(struct aciodrv_device_ctx *device) auto_poll_stop = false; InitializeCriticalSection(&keypair_lock); InitializeCriticalSection(&auto_poll_stop_lock); - auto_poll_threadid = - core_thread_create(auto_poll_proc, (void *) device, 0x4000, 0); + + result = bt_core_thread_create( + auto_poll_proc, (void *) device, 0x4000, 0, &auto_poll_threadid); + bt_core_thread_fatal_on_error(result); return true; } @@ -77,12 +80,17 @@ bool aciodrv_proc_panb_get_state(uint8_t *button_state) void aciodrv_proc_panb_fini(struct aciodrv_device_ctx *device) { + bt_core_thread_result_t result; + EnterCriticalSection(&auto_poll_stop_lock); auto_poll_stop = true; LeaveCriticalSection(&auto_poll_stop_lock); - core_thread_join(auto_poll_threadid, NULL); - core_thread_destroy(auto_poll_threadid); + result = bt_core_thread_join(auto_poll_threadid, NULL); + bt_core_thread_fatal_on_error(result); + + result = bt_core_thread_destroy(auto_poll_threadid); + bt_core_thread_fatal_on_error(result); DeleteCriticalSection(&keypair_lock); DeleteCriticalSection(&auto_poll_stop_lock); diff --git a/src/main/aciodrv/device.c b/src/main/aciodrv/device.c index 7584968..0a6751f 100644 --- a/src/main/aciodrv/device.c +++ b/src/main/aciodrv/device.c @@ -7,7 +7,7 @@ #include "aciodrv/port.h" -#include "core/log.h" +#include "iface-core/log.h" #include "util/hex.h" #include "util/mem.h" diff --git a/src/main/aciodrv/h44b.c b/src/main/aciodrv/h44b.c index 19283f6..89df433 100644 --- a/src/main/aciodrv/h44b.c +++ b/src/main/aciodrv/h44b.c @@ -7,7 +7,7 @@ #include "aciodrv/device.h" -#include "core/log.h" +#include "iface-core/log.h" bool aciodrv_h44b_init(struct aciodrv_device_ctx *device, uint8_t node_id) { diff --git a/src/main/aciodrv/icca.c b/src/main/aciodrv/icca.c index 7bec0c7..9ee8599 100644 --- a/src/main/aciodrv/icca.c +++ b/src/main/aciodrv/icca.c @@ -5,7 +5,7 @@ #include "aciodrv/device.h" #include "aciodrv/icca.h" -#include "core/log.h" +#include "iface-core/log.h" static bool aciodrv_icca_queue_loop_start( struct aciodrv_device_ctx *device, uint8_t node_id) diff --git a/src/main/aciodrv/kfca.c b/src/main/aciodrv/kfca.c index 88093e4..f3a00b3 100644 --- a/src/main/aciodrv/kfca.c +++ b/src/main/aciodrv/kfca.c @@ -5,7 +5,7 @@ #include "aciodrv/device.h" -#include "core/log.h" +#include "iface-core/log.h" static bool aciodrv_kfca_watchdog_start(struct aciodrv_device_ctx *device, uint8_t node_id) diff --git a/src/main/aciodrv/panb.c b/src/main/aciodrv/panb.c index 2dbc85e..5d213c3 100644 --- a/src/main/aciodrv/panb.c +++ b/src/main/aciodrv/panb.c @@ -5,7 +5,7 @@ #include "aciodrv/device.h" #include "aciodrv/panb.h" -#include "core/log.h" +#include "iface-core/log.h" bool aciodrv_panb_start_auto_input( struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t node_count) diff --git a/src/main/aciodrv/port.c b/src/main/aciodrv/port.c index c3c9c71..f0fc629 100644 --- a/src/main/aciodrv/port.c +++ b/src/main/aciodrv/port.c @@ -6,7 +6,7 @@ #include -#include "core/log.h" +#include "iface-core/log.h" HANDLE aciodrv_port_open(const char *port_path, int baud) { diff --git a/src/main/aciodrv/rvol.c b/src/main/aciodrv/rvol.c index ed7c036..8591eb3 100644 --- a/src/main/aciodrv/rvol.c +++ b/src/main/aciodrv/rvol.c @@ -5,7 +5,7 @@ #include "aciodrv/device.h" -#include "core/log.h" +#include "iface-core/log.h" static bool aciodrv_rvol_change_expand_mode( struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t mode) diff --git a/src/main/acioemu/addr.c b/src/main/acioemu/addr.c index 3f52fbb..2958fb7 100644 --- a/src/main/acioemu/addr.c +++ b/src/main/acioemu/addr.c @@ -5,7 +5,7 @@ #include "acioemu/addr.h" #include "acioemu/emu.h" -#include "core/log.h" +#include "iface-core/log.h" void ac_io_emu_cmd_assign_addrs( struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t node_count) diff --git a/src/main/acioemu/emu.c b/src/main/acioemu/emu.c index 57f74e0..cff00cb 100644 --- a/src/main/acioemu/emu.c +++ b/src/main/acioemu/emu.c @@ -14,7 +14,7 @@ #include "acioemu/emu.h" #include "acioemu/pipe.h" -#include "core/log.h" +#include "iface-core/log.h" #include "hook/iohook.h" diff --git a/src/main/acioemu/h44b.c b/src/main/acioemu/h44b.c index dde446e..8f87915 100644 --- a/src/main/acioemu/h44b.c +++ b/src/main/acioemu/h44b.c @@ -11,7 +11,7 @@ #include "acioemu/emu.h" -#include "bemanitools/jbio.h" +#include "iface-io/jb.h" #include "util/hex.h" @@ -54,14 +54,14 @@ void ac_io_emu_h44b_dispatch_request( case AC_IO_H44B_CMD_SET_OUTPUTS: /* Not using the struct ac_io_h44b_output here */ for (int i = 0; i < 6; i++) { - jb_io_set_rgb_led( - (enum jb_io_rgb_led) i, + bt_io_jb_rgb_led_set( + (enum bt_io_jb_rgb_led) i, req->cmd.raw[i * 3], req->cmd.raw[i * 3 + 1], req->cmd.raw[i * 3 + 2]); } - jb_io_write_lights(); + bt_io_jb_lights_write(); ac_io_emu_h44b_send_status(h44b, req, 0x00); diff --git a/src/main/acioemu/h44b.h b/src/main/acioemu/h44b.h index cfaafcc..e067a33 100644 --- a/src/main/acioemu/h44b.h +++ b/src/main/acioemu/h44b.h @@ -6,14 +6,14 @@ #include "acioemu/emu.h" +#include "api/io/jb.h" + struct ac_io_emu_h44b { struct ac_io_emu *emu; uint8_t unit_no; // TODO }; -void acioemu_h44b_init(void); - void ac_io_emu_h44b_init( struct ac_io_emu_h44b *h44b, struct ac_io_emu *emu, uint8_t unit_no); diff --git a/src/main/acioemu/hdxs.c b/src/main/acioemu/hdxs.c index 01ec19d..5ce5c53 100644 --- a/src/main/acioemu/hdxs.c +++ b/src/main/acioemu/hdxs.c @@ -6,7 +6,7 @@ #include "acioemu/emu.h" #include "acioemu/hdxs.h" -#include "core/log.h" +#include "iface-core/log.h" static void ac_io_emu_hdxs_cmd_send_version( struct ac_io_emu_hdxs *hdxs, const struct ac_io_message *req); diff --git a/src/main/acioemu/icca.c b/src/main/acioemu/icca.c index e7713e5..a57c100 100644 --- a/src/main/acioemu/icca.c +++ b/src/main/acioemu/icca.c @@ -12,7 +12,7 @@ #include "acioemu/emu.h" #include "acioemu/icca.h" -#include "bemanitools/eamio.h" +#include "iface-io/eam.h" #include "util/crc.h" #include "util/time.h" @@ -58,6 +58,7 @@ void ac_io_emu_icca_init( memset(icca, 0, sizeof(*icca)); icca->emu = emu; icca->unit_no = unit_no; + // queue must be started icca->fault = true; @@ -156,20 +157,20 @@ void ac_io_emu_icca_dispatch_request( switch (misc->subcmd) { case AC_IO_ICCA_SUBCMD_CARD_SLOT_CLOSE: - cmd = EAM_IO_CARD_SLOT_CMD_CLOSE; + cmd = BT_IO_EAM_CARD_SLOT_CMD_CLOSE; break; case AC_IO_ICCA_SUBCMD_CARD_SLOT_OPEN: - cmd = EAM_IO_CARD_SLOT_CMD_OPEN; + cmd = BT_IO_EAM_CARD_SLOT_CMD_OPEN; break; case AC_IO_ICCA_SUBCMD_CARD_SLOT_EJECT: - cmd = EAM_IO_CARD_SLOT_CMD_EJECT; + cmd = BT_IO_EAM_CARD_SLOT_CMD_EJECT; icca->engaged = false; break; case 3: - cmd = EAM_IO_CARD_SLOT_CMD_READ; + cmd = BT_IO_EAM_CARD_SLOT_CMD_READ; break; default: @@ -182,7 +183,7 @@ void ac_io_emu_icca_dispatch_request( } if (cmd != 0xFF) { - if (!eam_io_card_slot_cmd(icca->unit_no, cmd)) { + if (!bt_io_eam_card_slot_cmd_send(icca->unit_no, cmd)) { log_warning( "Eamio failed to handle slot cmd %d for node %d", cmd, @@ -326,33 +327,34 @@ static void ac_io_emu_icca_send_state( uint8_t sensor_state; bool card_full_insert; - if (!eam_io_poll(icca->unit_no)) { + if (!bt_io_eam_poll(icca->unit_no)) { log_warning("Polling eamio failed"); } memset(&resp, 0, sizeof(resp)); - keypad = eam_io_get_keypad_state(icca->unit_no); - sensor_state = eam_io_get_sensor_state(icca->unit_no); + keypad = bt_io_eam_keypad_state_get(icca->unit_no); + sensor_state = bt_io_eam_sensor_state_get(icca->unit_no); keypad_rise = keypad & (icca->last_keypad ^ keypad); - card_full_insert = sensor_state & (1 << EAM_IO_SENSOR_FRONT) && - sensor_state & (1 << EAM_IO_SENSOR_BACK); + card_full_insert = sensor_state & (1 << BT_IO_EAM_SENSOR_STATE_FRONT) && + sensor_state & (1 << BT_IO_EAM_SENSOR_STATE_BACK); if (sensor_state != icca->last_sensor) { if (card_full_insert) { - if (!eam_io_card_slot_cmd( - icca->unit_no, EAM_IO_CARD_SLOT_CMD_READ)) { + if (!bt_io_eam_card_slot_cmd_send( + icca->unit_no, BT_IO_EAM_CARD_SLOT_CMD_READ)) { log_warning( - "EAM_IO_CARD_SLOT_CMD_READ to unit %d failed", + "BT_IO_EAM_CARD_SLOT_CMD_READ to unit %d failed", icca->unit_no); } - icca->card_result = - eam_io_read_card(icca->unit_no, icca->uid, sizeof(icca->uid)); + icca->card_result = bt_io_eam_card_read( + icca->unit_no, icca->uid, sizeof(icca->uid)); // fault if sensor says to read but we got no card - icca->fault = (icca->card_result == EAM_IO_CARD_NONE); + icca->fault = + (icca->card_result == BT_IO_EAM_READ_CARD_RESULT_NONE); } else { icca->fault = false; } @@ -385,11 +387,11 @@ static void ac_io_emu_icca_send_state( body->sensor_state = 0; - if (sensor_state & (1 << EAM_IO_SENSOR_FRONT)) { + if (sensor_state & (1 << BT_IO_EAM_SENSOR_STATE_FRONT)) { body->sensor_state |= AC_IO_ICCA_FLAG_FRONT_SENSOR; } - if (sensor_state & (1 << EAM_IO_SENSOR_BACK)) { + if (sensor_state & (1 << BT_IO_EAM_SENSOR_STATE_BACK)) { body->sensor_state |= AC_IO_ICCA_FLAG_REAR_SENSOR; } diff --git a/src/main/acioemu/icca.h b/src/main/acioemu/icca.h index a182398..b40e3e8 100644 --- a/src/main/acioemu/icca.h +++ b/src/main/acioemu/icca.h @@ -6,6 +6,8 @@ #include "acioemu/emu.h" +#include "api/io/eam.h" + enum ac_io_emu_icca_version { v150 = 0x5, v160 = 0x6, @@ -20,6 +22,7 @@ enum ac_io_emu_icca_version { struct ac_io_emu_icca { struct ac_io_emu *emu; uint8_t unit_no; + bool fault; bool engaged; uint8_t last_sensor; diff --git a/src/main/acioemu/pipe.h b/src/main/acioemu/pipe.h index 859c3b6..5a83bdd 100644 --- a/src/main/acioemu/pipe.h +++ b/src/main/acioemu/pipe.h @@ -7,7 +7,7 @@ #include "acio/acio.h" -#include "core/log.h" +#include "iface-core/log.h" #include "util/iobuf.h" #include "util/list.h" diff --git a/src/main/aciomgr/Module.mk b/src/main/aciomgr/Module.mk deleted file mode 100644 index b87f81b..0000000 --- a/src/main/aciomgr/Module.mk +++ /dev/null @@ -1,10 +0,0 @@ -dlls += aciomgr - -libs_aciomgr := \ - core \ - aciodrv \ - util \ - -src_aciomgr := \ - dllmain.c \ - manager.c \ diff --git a/src/main/aciomgr/aciomgr.def b/src/main/aciomgr/aciomgr.def deleted file mode 100644 index 06bc21f..0000000 --- a/src/main/aciomgr/aciomgr.def +++ /dev/null @@ -1,12 +0,0 @@ -LIBRARY aciomgr - -EXPORTS - aciomgr_set_loggers - aciomgr_port_init - aciomgr_port_fini - aciomgr_get_node_count - aciomgr_get_node_product_ident - aciomgr_port_submit_packet - aciomgr_port_checkout - aciomgr_port_checkin - DllMain@12 @1 NONAME diff --git a/src/main/aciomgr/manager-init.h b/src/main/aciomgr/manager-init.h deleted file mode 100644 index b0b4b1b..0000000 --- a/src/main/aciomgr/manager-init.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef ACIOMGR_MANAGER_INIT_H -#define ACIOMGR_MANAGER_INIT_H - -// internal, used by DllMain -void _aciomgr_init(); -void _aciomgr_fini(); - -#endif diff --git a/src/main/aciotest/Module.mk b/src/main/aciotest/Module.mk index efeb038..d077aa5 100644 --- a/src/main/aciotest/Module.mk +++ b/src/main/aciotest/Module.mk @@ -6,6 +6,7 @@ libs_aciotest := \ aciodrv \ aciodrv-proc \ util \ + iface-core src_aciotest := \ icca.c \ diff --git a/src/main/aciotest/main.c b/src/main/aciotest/main.c index fdf6df4..69ee1b0 100644 --- a/src/main/aciotest/main.c +++ b/src/main/aciotest/main.c @@ -17,12 +17,10 @@ #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" +#include "core/log-sink-std.h" #include "core/thread-crt.h" -#include "core/thread.h" -#include "core/log.h" +#include "iface-core/log.h" static uint8_t aciotest_cnt = 0; static uint8_t bi2a_mode = 255; @@ -119,10 +117,11 @@ int main(int argc, char **argv) } } - core_thread_crt_ext_impl_set(); - core_log_bt_ext_impl_set(); + core_log_bt_core_api_set(); + core_thread_crt_core_api_set(); core_log_bt_ext_init_with_stdout(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); struct aciodrv_device_ctx *device = aciodrv_device_open_path(argv[1], atoi(argv[2])); diff --git a/src/main/asio/asio-reghook.c b/src/main/asio/asio-reghook.c index 7e05890..6f37c90 100644 --- a/src/main/asio/asio-reghook.c +++ b/src/main/asio/asio-reghook.c @@ -12,11 +12,11 @@ #include "asio/asio-reghook.h" -#include "core/log.h" - #include "hook/com-proxy.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/str.h" #include "util/time.h" diff --git a/src/main/asio/config-asio.c b/src/main/asio/config-asio.c index 2a8675d..2207f12 100644 --- a/src/main/asio/config-asio.c +++ b/src/main/asio/config-asio.c @@ -1,8 +1,8 @@ +#include "asio/config-asio.h" + #include "cconfig/cconfig-util.h" -#include "core/log.h" - -#include "asio/config-asio.h" +#include "iface-core/log.h" #define ASIOHOOK_CONFIG_IO_FORCE_ASIO_KEY "asio.force_asio" #define ASIOHOOK_CONFIG_IO_FORCE_WASAPI_KEY "asio.force_wasapi" diff --git a/src/main/avs-ext/Module.mk b/src/main/avs-ext/Module.mk new file mode 100644 index 0000000..e316ba5 --- /dev/null +++ b/src/main/avs-ext/Module.mk @@ -0,0 +1,13 @@ +avslibs += avs-ext + +libs_avs-ext := \ + iface-core \ + +src_avs-ext := \ + fs.c \ + error.c \ + log.c \ + property-ext.c \ + property-node.c \ + property.c \ + thread.c \ diff --git a/src/main/avs-util/error.c b/src/main/avs-ext/error.c similarity index 83% rename from src/main/avs-util/error.c rename to src/main/avs-ext/error.c index d31b2e1..00cec6f 100644 --- a/src/main/avs-util/error.c +++ b/src/main/avs-ext/error.c @@ -1,16 +1,20 @@ -#include "avs-util/error.h" +#include "avs-ext/error.h" #include "util/defs.h" -struct avs_util_avs_error_str { +struct avs_ext_error_str { avs_error error; const char *msg; }; -static const char *avs_util_error_unknown = "unknown error"; +static const char *_avs_ext_error_unknown = "unknown error"; // Source: https://github.com/spicetools/spicetools -static const struct avs_util_avs_error_str AVS_UTIL_ERRORS[] = { +static const struct avs_ext_error_str _avs_ext_errors[] = { + {0x80070002, "cannot find file or directory"}, + {0x80070009, "invalid data type"}, + {0x80070012, "TODO unknown error code"}, + {0x80070016, "invalid parameter"}, {0x80092000, "invalid type"}, {0x80092001, "type cannot use as array"}, {0x80092002, "invalid"}, @@ -85,25 +89,25 @@ static const struct avs_util_avs_error_str AVS_UTIL_ERRORS[] = { {0x80092280, "finger-print differs"}, {0x800922C0, "operation is not supported"}}; -const char *avs_util_error_str(avs_error error) +const char *avs_ext_error_str(avs_error error) { int i; - for (i = 0; i < lengthof(AVS_UTIL_ERRORS); i++) { - if (error == AVS_UTIL_ERRORS[i].error) { - return AVS_UTIL_ERRORS[i].msg; + for (i = 0; i < lengthof(_avs_ext_errors); i++) { + if (error == _avs_ext_errors[i].error) { + return _avs_ext_errors[i].msg; } } - return avs_util_error_unknown; + return _avs_ext_error_unknown; } -const char *avs_util_property_error_get_and_clear(struct property *prop) +const char *avs_ext_property_error_get_and_clear(struct property *prop) { avs_error error; error = property_get_error(prop); property_clear_error(prop); - return avs_util_error_str(error); + return avs_ext_error_str(error); } \ No newline at end of file diff --git a/src/main/avs-ext/error.h b/src/main/avs-ext/error.h new file mode 100644 index 0000000..d659048 --- /dev/null +++ b/src/main/avs-ext/error.h @@ -0,0 +1,10 @@ +#ifndef AVS_EXT_ERROR_H +#define AVS_EXT_ERROR_H + +#include "imports/avs.h" + +const char *avs_ext_error_str(avs_error error); + +const char *avs_ext_error_property_error_get_and_clear(struct property *prop); + +#endif diff --git a/src/main/avs-ext/fs.c b/src/main/avs-ext/fs.c new file mode 100644 index 0000000..3c27799 --- /dev/null +++ b/src/main/avs-ext/fs.c @@ -0,0 +1,33 @@ +#define LOG_MODULE "avs-ext-fs" + +#include "api/core/log.h" + +#include "iface-core/log.h" + +#include "imports/avs.h" + +void avs_ext_fs_dir_list_log( + const char *path, bt_core_log_message_t log_message) +{ + avs_desc desc; + const char *dirent_name; + + desc = avs_fs_opendir(path); + + if (!desc) { + log_warning("Opening directory '%s' failed", path); + return; + } + + log_message(LOG_MODULE, "Directory contents of: %s", path); + + dirent_name = avs_fs_readdir(desc); + + while (dirent_name != NULL) { + log_message(LOG_MODULE, " %s", dirent_name); + + dirent_name = avs_fs_readdir(desc); + } + + avs_fs_closedir(desc); +} \ No newline at end of file diff --git a/src/main/avs-ext/fs.h b/src/main/avs-ext/fs.h new file mode 100644 index 0000000..c582f13 --- /dev/null +++ b/src/main/avs-ext/fs.h @@ -0,0 +1,9 @@ +#ifndef AVS_EXT_FS_H +#define AVS_EXT_FS_H + +#include "api/core/log.h" + +void avs_ext_fs_dir_list_log( + const char *path, bt_core_log_message_t log_message); + +#endif diff --git a/src/main/avs-ext/log.c b/src/main/avs-ext/log.c new file mode 100644 index 0000000..6f3e650 --- /dev/null +++ b/src/main/avs-ext/log.c @@ -0,0 +1,27 @@ +#include "api/core/log.h" + +#include "avs-ext/log.h" + +#include "iface-core/log.h" + +#include "imports/avs.h" + +static void _avs_ext_log_core_api_get(bt_core_log_api_t *api) +{ + log_assert(api); + + api->version = 1; + + api->v1.misc = log_body_misc; + api->v1.info = log_body_info; + api->v1.warning = log_body_warning; + api->v1.fatal = log_body_fatal; +} + +void avs_ext_log_core_api_set() +{ + bt_core_log_api_t api; + + _avs_ext_log_core_api_get(&api); + bt_core_log_api_set(&api); +} \ No newline at end of file diff --git a/src/main/avs-ext/log.h b/src/main/avs-ext/log.h new file mode 100644 index 0000000..d83e649 --- /dev/null +++ b/src/main/avs-ext/log.h @@ -0,0 +1,8 @@ +#ifndef AVS_EXT_LOG_H +#define AVS_EXT_LOG_H + +#include "api/core/log.h" + +void avs_ext_log_core_api_set(); + +#endif diff --git a/src/main/avs-ext/property-ext.c b/src/main/avs-ext/property-ext.c new file mode 100644 index 0000000..917b13d --- /dev/null +++ b/src/main/avs-ext/property-ext.c @@ -0,0 +1,71 @@ +#include "avs-ext/error.h" +#include "avs-ext/property-internal.h" + +#include "imports/avs.h" + +#include "iface-core/log.h" + +#include "main/core/property.h" + +#include "util/mem.h" + +#include "avs-ext/fs.h" + +void avs_ext_property_ext_avs_file_load( + const char *path, core_property_t **property_) +{ + avs_desc desc; + void *buffer; + int nbytes; + avs_error error; + + struct property *prop; + avs_ext_property_internal_property_t *property; + + log_assert(path); + log_assert(property_); + + desc = avs_fs_open(path, AVS_FILE_READ, AVS_FILE_FLAG_SHARE_READ); + + if (AVS_IS_ERROR(desc)) { + log_fatal( + "%s: Error opening avs property file: %s", + path, + avs_ext_error_str(desc)); + } + + nbytes = property_read_query_memsize(avs_fs_read, desc, 0, 0); + + if (AVS_IS_ERROR(nbytes)) { + log_fatal( + "%s: Error querying avs property file: ", + path, + avs_ext_error_str(nbytes)); + } + + buffer = xmalloc(nbytes); + prop = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + nbytes); + + avs_fs_lseek(desc, 0, AVS_SEEK_SET); + + error = property_insert_read(prop, 0, avs_fs_read, desc); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s: Error reading avs property file: %s", + path, + avs_ext_error_str(error)); + } + + avs_fs_close(desc); + + *property_ = xmalloc(sizeof(avs_ext_property_internal_property_t)); + + property = (avs_ext_property_internal_property_t *) *property_; + + property->property = prop; +} \ No newline at end of file diff --git a/src/main/avs-ext/property-ext.h b/src/main/avs-ext/property-ext.h new file mode 100644 index 0000000..6ee10af --- /dev/null +++ b/src/main/avs-ext/property-ext.h @@ -0,0 +1,9 @@ +#ifndef AVS_EXT_PROPERTY_EXT_H +#define AVS_EXT_PROPERTY_EXT_H + +#include "main/core/property.h" + +void avs_ext_property_ext_avs_file_load( + const char *path, core_property_t **property); + +#endif \ No newline at end of file diff --git a/src/main/avs-ext/property-internal.h b/src/main/avs-ext/property-internal.h new file mode 100644 index 0000000..5f441d9 --- /dev/null +++ b/src/main/avs-ext/property-internal.h @@ -0,0 +1,26 @@ +#ifndef AVS_EXT_PROPERTY_INTERNAL_H +#define AVS_EXT_PROPERTY_INTERNAL_H + +#include "core/property-node.h" +#include "core/property.h" + +#include "imports/avs.h" + +typedef struct avs_ext_property_internal_property { + struct property *property; +} avs_ext_property_internal_property_t; + +_Static_assert( + sizeof(avs_ext_property_internal_property_t) <= sizeof(core_property_t), + "Not enough space for stack allocations"); + +typedef struct avs_ext_property_internal_node { + avs_ext_property_internal_property_t *property; + struct property_node *node; +} avs_ext_property_internal_node_t; + +_Static_assert( + sizeof(avs_ext_property_internal_node_t) <= sizeof(core_property_node_t), + "Not enough space for stack allocations"); + +#endif \ No newline at end of file diff --git a/src/main/avs-ext/property-node.c b/src/main/avs-ext/property-node.c new file mode 100644 index 0000000..23ebf2a --- /dev/null +++ b/src/main/avs-ext/property-node.c @@ -0,0 +1,1374 @@ +#define LOG_MODULE "avs-ext-property-node" + +#include + +#include "avs-ext/error.h" +#include "avs-ext/property-internal.h" +#include "avs-ext/property-node.h" + +#include "iface-core/log.h" + +#include "imports/avs.h" + +#include "util/mem.h" +#include "util/str.h" + +#define AVS_PROPERTY_STRUCTURE_META_SIZE 576 + +// Guestimate, should be long enough, I hope? +#define AVS_PROPERTY_NODE_PATH_LEN_MAX 4096 +// 256 found in AVS code as size used on property_node_name +#define AVS_PROPERTY_NODE_NAME_SIZE_MAX 256 +// Guestimate, should be enough, I hope? +#define AVS_PROPERTY_NODE_ATTR_NAME_SIZE_MAX 128 + +static void _avs_ext_property_node_log_rec( + struct property_node *parent_node, + const char *parent_path, + bt_core_log_message_t log_message) +{ + char cur_path[AVS_PROPERTY_NODE_PATH_LEN_MAX]; + char cur_node_name[AVS_PROPERTY_NODE_NAME_SIZE_MAX]; + + struct property_node *child_node; + enum property_type property_type; + + int8_t value_s8; + int16_t value_s16; + int32_t value_s32; + int64_t value_s64; + uint8_t value_u8; + uint16_t value_u16; + uint32_t value_u32; + uint64_t value_u64; + char value_str[4096]; + bool value_bool; + + avs_error error; + + // Carry on the full root path down the node tree + property_node_name(parent_node, cur_node_name, sizeof(cur_node_name)); + + str_cpy(cur_path, sizeof(cur_path), parent_path); + str_cat(cur_path, sizeof(cur_path), "/"); + str_cat(cur_path, sizeof(cur_path), cur_node_name); + + child_node = property_node_traversal(parent_node, TRAVERSE_FIRST_CHILD); + + // parent node is a leaf node, print all data of it + if (child_node == NULL) { + property_type = property_node_type(parent_node); + + switch (property_type) { + case PROPERTY_TYPE_VOID: + log_message(LOG_MODULE, "%s: ", cur_path); + break; + + case PROPERTY_TYPE_S8: + error = property_node_read( + parent_node, property_type, &value_s8, sizeof(value_s8)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } else { + log_message(LOG_MODULE, "%s: %" PRId8, cur_path, value_s8); + } + + break; + + case PROPERTY_TYPE_S16: + error = property_node_read( + parent_node, property_type, &value_s16, sizeof(value_s16)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } else { + log_message( + LOG_MODULE, "%s: %" PRId16, cur_path, value_s16); + } + + break; + + case PROPERTY_TYPE_S32: + error = property_node_read( + parent_node, property_type, &value_s32, sizeof(value_s32)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } else { + log_message( + LOG_MODULE, "%s: %" PRId32, cur_path, value_s32); + } + + break; + + case PROPERTY_TYPE_S64: + error = property_node_read( + parent_node, property_type, &value_s64, sizeof(value_s64)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } else { + log_message( + LOG_MODULE, "%s: %" PRId64, cur_path, value_s64); + } + + break; + + case PROPERTY_TYPE_U8: + error = property_node_read( + parent_node, property_type, &value_u8, sizeof(value_u8)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } else { + log_message(LOG_MODULE, "%s: %" PRIu8, cur_path, value_u8); + } + + break; + + case PROPERTY_TYPE_U16: + error = property_node_read( + parent_node, property_type, &value_u16, sizeof(value_u16)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } else { + log_message( + LOG_MODULE, "%s: %" PRIu16, cur_path, value_u16); + } + + break; + + case PROPERTY_TYPE_U32: + error = property_node_read( + parent_node, property_type, &value_u32, sizeof(value_u32)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } else { + log_message( + LOG_MODULE, "%s: %" PRIu32, cur_path, value_u32); + } + + break; + + case PROPERTY_TYPE_U64: + error = property_node_read( + parent_node, property_type, &value_u64, sizeof(value_u64)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } else { + log_message( + LOG_MODULE, "%s: %" PRIu64, cur_path, value_u64); + } + + break; + + case PROPERTY_TYPE_STR: + error = property_node_read( + parent_node, property_type, value_str, sizeof(value_str)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } else { + log_message(LOG_MODULE, "%s: %s", cur_path, value_str); + } + + break; + + case PROPERTY_TYPE_BOOL: + error = property_node_read( + parent_node, + property_type, + &value_bool, + sizeof(value_bool)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } else { + log_message(LOG_MODULE, "%s: %d", cur_path, value_bool); + } + + break; + + case PROPERTY_TYPE_BIN: + log_message(LOG_MODULE, "%s: ", cur_path); + break; + + case PROPERTY_TYPE_ATTR: + error = property_node_read( + parent_node, property_type, value_str, sizeof(value_str)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } else { + log_message(LOG_MODULE, "%s@: %s", cur_path, value_str); + } + + break; + + case PROPERTY_TYPE_VOID_WITH_ATTRIBUTES: + log_message(LOG_MODULE, "%s: ", cur_path); + + child_node = + property_node_traversal(parent_node, TRAVERSE_FIRST_ATTR); + + while (child_node) { + _avs_ext_property_node_log_rec( + child_node, cur_path, log_message); + + child_node = property_node_traversal( + child_node, TRAVERSE_NEXT_SIBLING); + } + + break; + + case PROPERTY_TYPE_STR_WITH_ATTRIBUTES: + error = property_node_read( + parent_node, property_type, value_str, sizeof(value_str)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_ext_error_str(error)); + } + + log_message(LOG_MODULE, "%s: %s", cur_path, value_str); + + child_node = + property_node_traversal(parent_node, TRAVERSE_FIRST_ATTR); + + while (child_node) { + _avs_ext_property_node_log_rec( + child_node, cur_path, log_message); + + child_node = property_node_traversal( + child_node, TRAVERSE_NEXT_SIBLING); + } + + break; + + default: + log_fatal("%s: (%d)", cur_path, property_type); + break; + } + } else { + while (child_node) { + _avs_ext_property_node_log_rec(child_node, cur_path, log_message); + + child_node = + property_node_traversal(child_node, TRAVERSE_NEXT_SIBLING); + } + } +} + +static void _avs_ext_property_node_log( + const core_property_node_t *node_, bt_core_log_message_t log_messsage) +{ + avs_ext_property_internal_node_t *node; + + node = (avs_ext_property_internal_node_t *) node_; + + _avs_ext_property_node_log_rec(node->node, "", log_messsage); +} + +static core_property_node_result_t _avs_ext_property_node_name_get( + const core_property_node_t *node_, char *name, size_t len) +{ + avs_ext_property_internal_node_t *node; + + node = (avs_ext_property_internal_node_t *) node_; + + property_node_name(node->node, name, len); + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t +_avs_ext_property_node_size(const core_property_node_t *node_, size_t *size) +{ + avs_ext_property_internal_node_t *node; + avs_error error; + + node = (avs_ext_property_internal_node_t *) node_; + + // No idea how to get the size of the memory that this node with all + // subnodes requires. Use the total size of the property it is owned by. + // This potentially wastes a lot of memory, but is considered ok for now + // because the known use-cases are fairly limited regarding usage of this + + // Copy-paste from avs_ext_property_size implementation + + // Returns the size of the actual data in the property structure only + // Hence, using that size only, allocating another buffer for a copy + // of this might fail or copying the data will fail because the buffer + // is too small + error = property_query_size(node->property->property); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_RESULT_ERROR_INTERNAL; + } + + // Hack: *2 to have enough space and not cut off data when cloning/copying + // property data because...reasons? I haven't figured this one out and + // there doesn't seem to be an actual API call for that to return the + // "true" size that allows the caller to figure out how much memory + // they have to allocate to create a copy of the property structure + // with property_create and + *size = (AVS_PROPERTY_STRUCTURE_META_SIZE + error) * 2; + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_search( + const core_property_node_t *node_, + const char *path, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + node = (avs_ext_property_internal_node_t *) node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + tmp = property_search(NULL, node->node, path); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND; + } + + node_out->property = node->property; + node_out->node = tmp; + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_next_result_search( + const core_property_node_t *node_, core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + node = (avs_ext_property_internal_node_t *) node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + tmp = property_node_traversal(node->node, TRAVERSE_NEXT_SEARCH_RESULT); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND; + } + + node_out->property = node->property; + node_out->node = tmp; + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_child_get( + const core_property_node_t *node_, core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + node = (avs_ext_property_internal_node_t *) node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + tmp = property_node_traversal(node->node, TRAVERSE_FIRST_CHILD); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND; + } + + node_out->property = node->property; + node_out->node = tmp; + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_next_sibling_get( + const core_property_node_t *node_, core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + node = (avs_ext_property_internal_node_t *) node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + tmp = property_node_traversal(node->node, TRAVERSE_NEXT_SIBLING); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND; + } + + node_out->property = node->property; + node_out->node = tmp; + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_void_create( + const core_property_node_t *parent_node_, + const char *key, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_VOID, + key); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_s8_create( + const core_property_node_t *parent_node_, + const char *key, + int8_t value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_S8, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_u8_create( + const core_property_node_t *parent_node_, + const char *key, + uint8_t value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_U8, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_s16_create( + const core_property_node_t *parent_node_, + const char *key, + int16_t value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_S16, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_u16_create( + const core_property_node_t *parent_node_, + const char *key, + uint16_t value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_U16, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_s32_create( + const core_property_node_t *parent_node_, + const char *key, + int32_t value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_S32, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_u32_create( + const core_property_node_t *parent_node_, + const char *key, + uint32_t value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_U32, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_s64_create( + const core_property_node_t *parent_node_, + const char *key, + int64_t value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_S64, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_u64_create( + const core_property_node_t *parent_node_, + const char *key, + uint64_t value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_U64, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_bin_create( + const core_property_node_t *parent_node_, + const char *key, + void *data, + size_t len, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_BIN, + key, + data, + len); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_str_create( + const core_property_node_t *parent_node_, + const char *key, + const char *value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_STR, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_ipv4_create( + const core_property_node_t *parent_node_, + const char *key, + uint32_t value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_IP4, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_float_create( + const core_property_node_t *parent_node_, + const char *key, + float value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_FLOAT, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_double_create( + const core_property_node_t *parent_node_, + const char *key, + double value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_DOUBLE, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_attr_create( + const core_property_node_t *parent_node_, + const char *key, + const char *value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_ATTR, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_bool_create( + const core_property_node_t *parent_node_, + const char *key, + bool value, + core_property_node_t *node_out_) +{ + avs_ext_property_internal_node_t *parent_node; + avs_ext_property_internal_node_t *node_out; + struct property_node *tmp; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + node_out = (avs_ext_property_internal_node_t *) node_out_; + + tmp = property_node_create( + parent_node->property->property, + parent_node->node, + PROPERTY_TYPE_BOOL, + key, + value); + + if (!tmp) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + if (node_out) { + memset(node_out, 0, sizeof(avs_ext_property_internal_node_t)); + + node_out->property = parent_node->property; + node_out->node = tmp; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_s8_read( + const core_property_node_t *parent_node_, int8_t *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_S8, value, sizeof(int8_t)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_u8_read( + const core_property_node_t *parent_node_, uint8_t *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_U8, value, sizeof(uint8_t)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_s16_read( + const core_property_node_t *parent_node_, int16_t *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_S16, value, sizeof(int16_t)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_u16_read( + const core_property_node_t *parent_node_, uint16_t *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_U16, value, sizeof(uint16_t)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_s32_read( + const core_property_node_t *parent_node_, int32_t *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_S32, value, sizeof(int32_t)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_u32_read( + const core_property_node_t *parent_node_, uint32_t *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_U32, value, sizeof(uint32_t)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_s64_read( + const core_property_node_t *parent_node_, int64_t *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_S64, value, sizeof(int64_t)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_u64_read( + const core_property_node_t *parent_node_, uint64_t *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_U64, value, sizeof(uint64_t)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_bin_read( + const core_property_node_t *parent_node_, void *value, size_t len) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = + property_node_read(parent_node->node, PROPERTY_TYPE_BIN, value, len); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_str_read( + const core_property_node_t *parent_node_, char *value, size_t len) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = + property_node_read(parent_node->node, PROPERTY_TYPE_STR, value, len); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_ipv4_read( + const core_property_node_t *parent_node_, uint32_t *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_IP4, value, sizeof(uint32_t)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_float_read( + const core_property_node_t *parent_node_, float *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_FLOAT, value, sizeof(float)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_double_read( + const core_property_node_t *parent_node_, double *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_DOUBLE, value, sizeof(double)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_attr_read( + const core_property_node_t *parent_node_, char *value, size_t len) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = + property_node_read(parent_node->node, PROPERTY_TYPE_ATTR, value, len); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_bool_read( + const core_property_node_t *parent_node_, bool *value) +{ + avs_ext_property_internal_node_t *parent_node; + avs_error error; + + parent_node = (avs_ext_property_internal_node_t *) parent_node_; + + error = property_node_read( + parent_node->node, PROPERTY_TYPE_BOOL, value, sizeof(bool)); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t +_avs_ext_property_node_remove(const core_property_node_t *node_) +{ + avs_ext_property_internal_node_t *node; + avs_error error; + + node = (avs_ext_property_internal_node_t *) node_; + + error = property_node_remove(node->node); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +static core_property_node_result_t _avs_ext_property_node_copy( + core_property_node_t *dst_node_, const core_property_node_t *src_node_) +{ + avs_ext_property_internal_node_t *dst_node; + avs_ext_property_internal_node_t *src_node; + + dst_node = (avs_ext_property_internal_node_t *) dst_node_; + src_node = (avs_ext_property_internal_node_t *) src_node_; + + if (!property_node_clone( + dst_node->property->property, + dst_node->node, + src_node->node, + true)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } else { + return CORE_PROPERTY_NODE_RESULT_SUCCESS; + } +} + +void avs_ext_property_node_core_api_get(core_property_node_api_t *api) +{ + log_assert(api); + + api->version = 1; + + api->v1.log = _avs_ext_property_node_log; + api->v1.name_get = _avs_ext_property_node_name_get; + api->v1.size = _avs_ext_property_node_size; + api->v1.search = _avs_ext_property_node_search; + api->v1.next_result_search = _avs_ext_property_node_next_result_search; + api->v1.child_get = _avs_ext_property_node_child_get; + api->v1.next_sibling_get = _avs_ext_property_node_next_sibling_get; + api->v1.void_create = _avs_ext_property_node_void_create; + api->v1.s8_create = _avs_ext_property_node_s8_create; + api->v1.u8_create = _avs_ext_property_node_u8_create; + api->v1.s16_create = _avs_ext_property_node_s16_create; + api->v1.u16_create = _avs_ext_property_node_u16_create; + api->v1.s32_create = _avs_ext_property_node_s32_create; + api->v1.u32_create = _avs_ext_property_node_u32_create; + api->v1.s64_create = _avs_ext_property_node_s64_create; + api->v1.u64_create = _avs_ext_property_node_u64_create; + api->v1.bin_create = _avs_ext_property_node_bin_create; + api->v1.str_create = _avs_ext_property_node_str_create; + api->v1.ipv4_create = _avs_ext_property_node_ipv4_create; + api->v1.float_create = _avs_ext_property_node_float_create; + api->v1.double_create = _avs_ext_property_node_double_create; + api->v1.attr_create = _avs_ext_property_node_attr_create; + api->v1.bool_create = _avs_ext_property_node_bool_create; + api->v1.s8_read = _avs_ext_property_node_s8_read; + api->v1.u8_read = _avs_ext_property_node_u8_read; + api->v1.s16_read = _avs_ext_property_node_s16_read; + api->v1.u16_read = _avs_ext_property_node_u16_read; + api->v1.s32_read = _avs_ext_property_node_s32_read; + api->v1.u32_read = _avs_ext_property_node_u32_read; + api->v1.s64_read = _avs_ext_property_node_s64_read; + api->v1.u64_read = _avs_ext_property_node_u64_read; + api->v1.bin_read = _avs_ext_property_node_bin_read; + api->v1.str_read = _avs_ext_property_node_str_read; + api->v1.ipv4_read = _avs_ext_property_node_ipv4_read; + api->v1.float_read = _avs_ext_property_node_float_read; + api->v1.double_read = _avs_ext_property_node_double_read; + api->v1.attr_read = _avs_ext_property_node_attr_read; + api->v1.bool_read = _avs_ext_property_node_bool_read; + api->v1.remove = _avs_ext_property_node_remove; + api->v1.copy = _avs_ext_property_node_copy; +} + +void avs_ext_property_node_core_api_set() +{ + core_property_node_api_t api; + + avs_ext_property_node_core_api_get(&api); + core_property_node_api_set(&api); +} + +struct property_node * +avs_ext_property_node_avs_property_node_get(const core_property_node_t *node) +{ + avs_ext_property_internal_node_t *internal_node; + + log_assert(node); + + internal_node = (avs_ext_property_internal_node_t *) node; + + return internal_node->node; +} \ No newline at end of file diff --git a/src/main/avs-ext/property-node.h b/src/main/avs-ext/property-node.h new file mode 100644 index 0000000..4863abb --- /dev/null +++ b/src/main/avs-ext/property-node.h @@ -0,0 +1,16 @@ +#ifndef AVS_EXT_PROPERTY_NODE_H +#define AVS_EXT_PROPERTY_NODE_H + +#include "imports/avs.h" + +#include "main/core/property-node.h" + +void avs_ext_property_node_core_api_get(core_property_node_api_t *api); + +void avs_ext_property_node_core_api_set(); + +// Don't use this unless you need to interface directly with avs +struct property_node * +avs_ext_property_node_avs_property_node_get(const core_property_node_t *node); + +#endif \ No newline at end of file diff --git a/src/main/avs-ext/property.c b/src/main/avs-ext/property.c new file mode 100644 index 0000000..0977803 --- /dev/null +++ b/src/main/avs-ext/property.c @@ -0,0 +1,389 @@ +#define LOG_MODULE "avs-ext-property" + +#include + +#include +#include + +#include "avs-ext/error.h" +#include "avs-ext/property-internal.h" +#include "avs-ext/property-node.h" +#include "avs-ext/property.h" + +#include "iface-core/log.h" + +#include "imports/avs.h" + +#include "util/mem.h" + +#define AVS_PROPERTY_STRUCTURE_META_SIZE 576 + +typedef void (*avs_ext_property_rewinder_t)(uint32_t context); + +struct avs_ext_property_str_read_handle { + const char *buffer; + size_t buffer_len; + size_t offset; +}; + +static void _avs_ext_property_free(core_property_t **property_); + +static size_t +_avs_ext_property_str_read(uint32_t context, void *bytes, size_t nbytes) +{ + int result; + struct avs_ext_property_str_read_handle *handle; + + result = 0; + handle = TlsGetValue(context); + + if (handle->offset < handle->buffer_len) { + result = min(nbytes, handle->buffer_len - handle->offset); + memcpy(bytes, (const void *) (handle->buffer + handle->offset), result); + handle->offset += result; + } + + return result; +} + +static void _avs_ext_property_str_rewind(uint32_t context) +{ + struct avs_ext_property_str_read_handle *handle; + + handle = TlsGetValue(context); + handle->offset = 0; +} + +static size_t +_avs_ext_property_fread(uint32_t context, void *bytes, size_t nbytes) +{ + FILE *f; + + f = TlsGetValue(context); + + return fread(bytes, 1, nbytes, f); +} + +static void _avs_ext_property_frewind(uint32_t context) +{ + FILE *f = TlsGetValue(context); + rewind(f); +} + +static core_property_result_t _avs_ext_property_do_load( + avs_reader_t reader, + avs_ext_property_rewinder_t rewinder, + uint32_t context, + const char *name, + avs_ext_property_internal_property_t **property) +{ + struct property *prop; + void *buffer; + int nbytes; + + nbytes = property_read_query_memsize(reader, context, 0, 0); + + if (nbytes < 0) { + return CORE_PROPERTY_RESULT_ERROR_INTERNAL; + } + + buffer = xmalloc(nbytes); + prop = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + nbytes); + + if (!prop) { + free(buffer); + return CORE_PROPERTY_RESULT_ERROR_ALLOC; + } + + rewinder(context); + + if (!property_insert_read(prop, 0, reader, context)) { + property_destroy(prop); + free(buffer); + return CORE_PROPERTY_RESULT_ERROR_READ; + } + + *property = xmalloc(sizeof(avs_ext_property_internal_property_t)); + (*property)->property = prop; + + return CORE_PROPERTY_RESULT_SUCCESS; +} + +static core_property_result_t +_avs_ext_property_create(size_t size, core_property_t **property_) +{ + avs_ext_property_internal_property_t *property; + void *buffer; + struct property *prop; + + if (size > UINT32_MAX) { + return CORE_PROPERTY_RESULT_ERROR_INTERNAL; + } + + buffer = xmalloc(size); + prop = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + (uint32_t) size); + + if (!prop) { + free(buffer); + return CORE_PROPERTY_RESULT_ERROR_ALLOC; + } + + *property_ = xmalloc(sizeof(core_property_t)); + + property = (avs_ext_property_internal_property_t *) (*property_); + property->property = prop; + + return CORE_PROPERTY_RESULT_SUCCESS; +} + +static core_property_result_t +_avs_ext_property_file_load(const char *path, core_property_t **property) +{ + FILE *file; + uint32_t f_keyhole; + core_property_result_t result; + + file = fopen(path, "r"); + + if (!file) { + switch (errno) { + case EACCES: + return CORE_PROPERTY_RESULT_ERROR_PERMISSIONS; + case ENOENT: + return CORE_PROPERTY_RESULT_NOT_FOUND; + default: + return CORE_PROPERTY_RESULT_ERROR_INTERNAL; + } + } + + /* AVS callbacks are only given a 32-bit context parameter, even in 64-bit + builds of AVS. We allocate a 32-bit TLS key and pass the context in this + manner instead. Inefficient, but it works. */ + + f_keyhole = TlsAlloc(); + TlsSetValue(f_keyhole, file); + + result = _avs_ext_property_do_load( + _avs_ext_property_fread, + _avs_ext_property_frewind, + f_keyhole, + path, + (avs_ext_property_internal_property_t **) property); + + TlsFree(f_keyhole); + + fclose(file); + + return result; +} + +static core_property_result_t +_avs_ext_property_str_load(const char *str, core_property_t **property) +{ + struct avs_ext_property_str_read_handle read_handle; + uint32_t s_keyhole; + core_property_result_t result; + + read_handle.buffer = str; + read_handle.buffer_len = strlen(str); + read_handle.offset = 0; + + s_keyhole = TlsAlloc(); + TlsSetValue(s_keyhole, &read_handle); + + result = _avs_ext_property_do_load( + _avs_ext_property_str_read, + _avs_ext_property_str_rewind, + s_keyhole, + "", + (avs_ext_property_internal_property_t **) property); + + TlsFree(s_keyhole); + + return result; +} + +static core_property_result_t +_avs_ext_property_size(const core_property_t *property_, size_t *size) +{ + avs_ext_property_internal_property_t *property; + avs_error error; + + property = (avs_ext_property_internal_property_t *) property_; + + // Returns the size of the actual data in the property structure only + // Hence, using that size only, allocating another buffer for a copy + // of this might fail or copying the data will fail because the buffer + // is too small + error = property_query_size(property->property); + + if (AVS_IS_ERROR(error)) { + return CORE_PROPERTY_RESULT_ERROR_INTERNAL; + } + + // Hack: *2 to have enough space and not cut off data when cloning/copying + // property data because...reasons? I haven't figured this one out and + // there doesn't seem to be an actual API call for that to return the + // "true" size that allows the caller to figure out how much memory + // they have to allocate to create a copy of the property structure + // with property_create and + *size = (AVS_PROPERTY_STRUCTURE_META_SIZE + error) * 2; + + return CORE_PROPERTY_RESULT_SUCCESS; +} + +static core_property_result_t _avs_ext_property_clone( + const core_property_t *property_, core_property_t **property_cloned_) +{ + avs_ext_property_internal_property_t *property; + avs_ext_property_internal_property_t *property_cloned; + + size_t size; + core_property_result_t result; + + struct property_node *node; + avs_error error; + + property = (avs_ext_property_internal_property_t *) property_; + + result = _avs_ext_property_size(property_, &size); + + if (CORE_PROPERTY_RESULT_IS_ERROR(result)) { + return result; + } + + result = _avs_ext_property_create(size, property_cloned_); + + property_cloned = + (avs_ext_property_internal_property_t *) *property_cloned_; + + if (CORE_PROPERTY_RESULT_IS_ERROR(result)) { + return result; + } + + node = property_search(property->property, NULL, "/"); + + if (!node) { + error = property_get_error(property_cloned->property); + + if (AVS_IS_ERROR(error)) { + _avs_ext_property_free(property_cloned_); + return CORE_PROPERTY_RESULT_ERROR_INTERNAL; + } + } + + if (!property_node_clone(property_cloned->property, NULL, node, true)) { + error = property_get_error(property_cloned->property); + + if (AVS_IS_ERROR(error)) { + _avs_ext_property_free(property_cloned_); + return CORE_PROPERTY_RESULT_ERROR_INTERNAL; + } + } + + return CORE_PROPERTY_RESULT_SUCCESS; +} + +static void _avs_ext_property_log( + const core_property_t *property_, bt_core_log_message_t log_message) +{ + avs_ext_property_internal_node_t node; + core_property_node_api_t node_api; + + node.property = (avs_ext_property_internal_property_t *) (property_); + node.node = property_search(node.property->property, NULL, "/"); + + if (node.node == NULL) { + log_message(LOG_MODULE, ""); + return; + } + + avs_ext_property_node_core_api_get(&node_api); + + node_api.v1.log((const core_property_node_t *) &node, log_message); +} + +static core_property_result_t _avs_ext_property_root_node_get( + const core_property_t *property_, core_property_node_t *node_) +{ + avs_ext_property_internal_property_t *property; + avs_ext_property_internal_node_t *node; + + property = (avs_ext_property_internal_property_t *) property_; + node = (avs_ext_property_internal_node_t *) node_; + + memset(node, 0, sizeof(avs_ext_property_internal_node_t)); + + node->property = property; + node->node = property_search(property->property, NULL, "/"); + + if (node->node == NULL) { + return CORE_PROPERTY_RESULT_NOT_FOUND; + } else { + return CORE_PROPERTY_RESULT_SUCCESS; + } +} + +static core_property_result_t _avs_ext_property_other_node_insert( + core_property_t *property_, const core_property_node_t *node_) +{ + avs_ext_property_internal_property_t *property; + avs_ext_property_internal_node_t *node; + + property = (avs_ext_property_internal_property_t *) property_; + node = (avs_ext_property_internal_node_t *) node_; + + if (!property_node_clone(property->property, NULL, node->node, true)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } else { + return CORE_PROPERTY_NODE_RESULT_SUCCESS; + } +} + +static void _avs_ext_property_free(core_property_t **property_) +{ + avs_ext_property_internal_property_t *property; + void *buffer; + + property = (avs_ext_property_internal_property_t *) (*property_); + + buffer = property_desc_to_buffer(property->property); + property_destroy(property->property); + free(buffer); + + free(*property_); + *property_ = NULL; +} + +static void _avs_ext_property_core_api_get(core_property_api_t *api) +{ + log_assert(api); + + api->version = 1; + + api->v1.create = _avs_ext_property_create; + api->v1.file_load = _avs_ext_property_file_load; + api->v1.str_load = _avs_ext_property_str_load; + api->v1.size = _avs_ext_property_size; + api->v1.clone = _avs_ext_property_clone; + api->v1.log = _avs_ext_property_log; + api->v1.root_node_get = _avs_ext_property_root_node_get; + api->v1.other_node_insert = _avs_ext_property_other_node_insert; + api->v1.free = _avs_ext_property_free; +} + +void avs_ext_property_core_api_set() +{ + core_property_api_t api; + + _avs_ext_property_core_api_get(&api); + core_property_api_set(&api); +} diff --git a/src/main/avs-ext/property.h b/src/main/avs-ext/property.h new file mode 100644 index 0000000..041ccd9 --- /dev/null +++ b/src/main/avs-ext/property.h @@ -0,0 +1,8 @@ +#ifndef AVS_EXT_PROPERTY_H +#define AVS_EXT_PROPERTY_H + +#include "main/core/property.h" + +void avs_ext_property_core_api_set(); + +#endif \ No newline at end of file diff --git a/src/main/avs-ext/thread.c b/src/main/avs-ext/thread.c new file mode 100644 index 0000000..7d9d498 --- /dev/null +++ b/src/main/avs-ext/thread.c @@ -0,0 +1,56 @@ +#include "api/core/thread.h" +#include "api/core/log.h" + +#include "avs-ext/thread.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "imports/avs.h" + +static bt_core_thread_result_t _avs_ext_thread_create( + int (*proc)(void *), + void *ctx, + uint32_t stack_sz, + unsigned int priority, + bt_core_thread_id_t *thread_id) +{ + *thread_id = avs_thread_create(proc, ctx, stack_sz, priority); + + return BT_CORE_THREAD_RESULT_SUCCESS; +} + +static bt_core_thread_result_t +_avs_ext_thread_join(bt_core_thread_id_t thread_id, int *result) +{ + avs_thread_join(thread_id, result); + + return BT_CORE_THREAD_RESULT_SUCCESS; +} + +static bt_core_thread_result_t +_avs_ext_thread_destroy(bt_core_thread_id_t thread_id) +{ + avs_thread_destroy(thread_id); + + return BT_CORE_THREAD_RESULT_SUCCESS; +} + +static void _avs_ext_thread_core_api_get(bt_core_thread_api_t *api) +{ + log_assert(api); + + api->version = 1; + + api->v1.create = _avs_ext_thread_create; + api->v1.join = _avs_ext_thread_join; + api->v1.destroy = _avs_ext_thread_destroy; +} + +void avs_ext_thread_core_api_set() +{ + bt_core_thread_api_t api; + + _avs_ext_thread_core_api_get(&api); + bt_core_thread_api_set(&api); +} \ No newline at end of file diff --git a/src/main/avs-ext/thread.h b/src/main/avs-ext/thread.h new file mode 100644 index 0000000..3c567d8 --- /dev/null +++ b/src/main/avs-ext/thread.h @@ -0,0 +1,8 @@ +#ifndef AVS_EXT_THREAD_H +#define AVS_EXT_THREAD_H + +#include "api/core/thread.h" + +void avs_ext_thread_core_api_set(); + +#endif diff --git a/src/main/avs-util/Module.mk b/src/main/avs-util/Module.mk deleted file mode 100644 index 2e59f57..0000000 --- a/src/main/avs-util/Module.mk +++ /dev/null @@ -1,7 +0,0 @@ -libs += avs-util - -libs_avs-util := \ - -src_avs-util := \ - core-interop.c \ - error.c \ diff --git a/src/main/avs-util/core-interop.c b/src/main/avs-util/core-interop.c deleted file mode 100644 index 555930f..0000000 --- a/src/main/avs-util/core-interop.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "core/log.h" -#include "core/thread.h" - -#include "imports/avs.h" - -void avs_util_core_interop_log_avs_impl_set() -{ - core_log_impl_set( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); -} - -void avs_util_core_interop_thread_avs_impl_set() -{ - core_thread_impl_set( - avs_thread_create, avs_thread_join, avs_thread_destroy); -} \ No newline at end of file diff --git a/src/main/avs-util/core-interop.h b/src/main/avs-util/core-interop.h deleted file mode 100644 index 51b1e11..0000000 --- a/src/main/avs-util/core-interop.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef AVS_UTIL_CORE_INTEROP_H -#define AVS_UTIL_CORE_INTEROP_H - -void avs_util_core_interop_log_avs_impl_set(); -void avs_util_core_interop_thread_avs_impl_set(); - -#endif \ No newline at end of file diff --git a/src/main/avs-util/error.h b/src/main/avs-util/error.h deleted file mode 100644 index 88d68c5..0000000 --- a/src/main/avs-util/error.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef AVS_UTIL_ERROR_H -#define AVS_UTIL_ERROR_H - -#include "imports/avs.h" - -const char *avs_util_error_str(avs_error error); - -const char *avs_util_property_error_get_and_clear(struct property *prop); - -#endif diff --git a/src/main/bemanitools/bstio.h b/src/main/bemanitools/bstio.h deleted file mode 100644 index 162e230..0000000 --- a/src/main/bemanitools/bstio.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef BEMANITOOLS_SDVXIO_H -#define BEMANITOOLS_SDVXIO_H - -/* IO emulation provider for BeatStream */ - -#include -#include - -#include "bemanitools/glue.h" - -enum bst_io_in_gpio_sys_bit { - SDVX_IO_IN_GPIO_SYS_COIN = 2, - SDVX_IO_IN_GPIO_SYS_TEST = 4, - SDVX_IO_IN_GPIO_SYS_SERVICE = 5, -}; - -/* The first function that will be called on your DLL. You will be supplied - with four function pointers that may be used to log messages to the game's - log file. See comments in glue.h for further information. */ - -void bst_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); - -/* Initialize your BST IO emulation DLL. Thread management functions are - provided to you; you must use these functions to create your own threads if - you want to make use of the logging functions that are provided to - eam_io_set_loggers(). You will also need to pass these thread management - functions on to geninput if you intend to make use of that library. - - See glue.h and geninput.h for further details. */ - -bool bst_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy); - -/* Shut down your SDVX IO emulation DLL */ - -void bst_io_fini(void); - -/* Read input state. Returns true if successful. */ - -bool bst_io_read_input(void); - -/* Get state of coin, test, service inputs */ - -uint8_t bst_io_get_input(void); - -// TODO: Lighting - -#endif diff --git a/src/main/bemanitools/ddrio.h b/src/main/bemanitools/ddrio.h deleted file mode 100644 index f543797..0000000 --- a/src/main/bemanitools/ddrio.h +++ /dev/null @@ -1,129 +0,0 @@ -#ifndef BEMANITOOLS_DDRIO_H -#define BEMANITOOLS_DDRIO_H - -#include -#include - -#include "bemanitools/glue.h" - -enum ddr_pad_bit { - DDR_TEST = 0x04, - DDR_COIN = 0x05, - DDR_SERVICE = 0x06, - - DDR_P2_START = 0x08, - DDR_P2_UP = 0x09, - DDR_P2_DOWN = 0x0A, - DDR_P2_LEFT = 0x0B, - DDR_P2_RIGHT = 0x0C, - DDR_P2_MENU_LEFT = 0x0E, - DDR_P2_MENU_RIGHT = 0x0F, - DDR_P2_MENU_UP = 0x02, - DDR_P2_MENU_DOWN = 0x03, - - DDR_P1_START = 0x10, - DDR_P1_UP = 0x11, - DDR_P1_DOWN = 0x12, - DDR_P1_LEFT = 0x13, - DDR_P1_RIGHT = 0x14, - DDR_P1_MENU_LEFT = 0x16, - DDR_P1_MENU_RIGHT = 0x17, - DDR_P1_MENU_UP = 0x00, - DDR_P1_MENU_DOWN = 0x01, -}; - -// see the functions below for more information - -enum p3io_light_bit { - LIGHT_P1_MENU = 0x00, - LIGHT_P2_MENU = 0x01, - LIGHT_P2_LOWER_LAMP = 0x04, - LIGHT_P2_UPPER_LAMP = 0x05, - LIGHT_P1_LOWER_LAMP = 0x06, - LIGHT_P1_UPPER_LAMP = 0x07, -}; - -enum hdxs_light_bit { - LIGHT_HD_P1_START = 0x08, - LIGHT_HD_P1_UP_DOWN = 0x09, - LIGHT_HD_P1_LEFT_RIGHT = 0x0A, - LIGHT_HD_P2_START = 0x0B, - LIGHT_HD_P2_UP_DOWN = 0x0C, - LIGHT_HD_P2_LEFT_RIGHT = 0x0D, -}; - -// the indexing starts from 0x20 if you're looking in geninput -enum hdxs_rgb_light_idx { - LIGHT_HD_P1_SPEAKER_F_R = 0x00, - LIGHT_HD_P1_SPEAKER_F_G = 0x01, - LIGHT_HD_P1_SPEAKER_F_B = 0x02, - LIGHT_HD_P2_SPEAKER_F_R = 0x03, - LIGHT_HD_P2_SPEAKER_F_G = 0x04, - LIGHT_HD_P2_SPEAKER_F_B = 0x05, - LIGHT_HD_P1_SPEAKER_W_R = 0x06, - LIGHT_HD_P1_SPEAKER_W_G = 0x07, - LIGHT_HD_P1_SPEAKER_W_B = 0x08, - LIGHT_HD_P2_SPEAKER_W_R = 0x09, - LIGHT_HD_P2_SPEAKER_W_G = 0x0A, - LIGHT_HD_P2_SPEAKER_W_B = 0x0B, -}; - -enum extio_light_bit { - LIGHT_NEONS = 0x0E, - - LIGHT_P2_RIGHT = 0x13, - LIGHT_P2_LEFT = 0x14, - LIGHT_P2_DOWN = 0x15, - LIGHT_P2_UP = 0x16, - - LIGHT_P1_RIGHT = 0x1B, - LIGHT_P1_LEFT = 0x1C, - LIGHT_P1_DOWN = 0x1D, - LIGHT_P1_UP = 0x1E -}; - -/* The first function that will be called on your DLL. You will be supplied - with four function pointers that may be used to log messages to the game's - log file. See comments in glue.h for further information. */ - -void ddr_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); - -/* Initialize your DDR IO emulation DLL. Thread management functions are - provided to you; you must use these functions to create your own threads if - you want to make use of the logging functions that are provided to - eam_io_set_loggers(). You will also need to pass these thread management - functions on to geninput if you intend to make use of that library. - - See glue.h and geninput.h for further details. */ - -bool ddr_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy); - -/* used to poll the IO for input, note that this is also where lights are - flushed to the device for geninput */ -uint32_t ddr_io_read_pad(void); - -/* The following are optional to implement, and allow lights to be set and - emulated as needed */ - -/* used to set pad lights, as well as the bass neon on SD cabs */ -void ddr_io_set_lights_extio(uint32_t extio_lights); - -/* used to set SD panel lights, and HD spot lights */ -void ddr_io_set_lights_p3io(uint32_t p3io_lights); - -/* used to set HD cab front panel lights */ -void ddr_io_set_lights_hdxs_panel(uint32_t hdxs_lights); - -/* used to set HD cab speaker RGB lights */ -void ddr_io_set_lights_hdxs_rgb(uint8_t idx, uint8_t r, uint8_t g, uint8_t b); - -void ddr_io_fini(void); - -#endif diff --git a/src/main/bemanitools/eamio.h b/src/main/bemanitools/eamio.h deleted file mode 100644 index 1c5d9b8..0000000 --- a/src/main/bemanitools/eamio.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef BEMANITOOLS_EAM_H -#define BEMANITOOLS_EAM_H - -/* Card reader emulator API. You may replace the stock EAMIO.DLL supplied by - Bemanitools with your own custom implementation, which should implement the - interface contract defined in this header file. */ - -#include -#include - -#include "bemanitools/glue.h" - -/* Scan codes for the so-called "10 key" button panel on each card reader. Each - scan code corresponds to a bit position within the 16-bit bitfield that you - return from eam_io_get_keypad_state(). */ - -enum eam_io_keypad_scan_code { - EAM_IO_KEYPAD_0 = 0, - EAM_IO_KEYPAD_1 = 1, - EAM_IO_KEYPAD_4 = 2, - EAM_IO_KEYPAD_7 = 3, - EAM_IO_KEYPAD_00 = 4, - EAM_IO_KEYPAD_2 = 5, - EAM_IO_KEYPAD_5 = 6, - EAM_IO_KEYPAD_8 = 7, - EAM_IO_KEYPAD_DECIMAL = 8, - EAM_IO_KEYPAD_3 = 9, - EAM_IO_KEYPAD_6 = 10, - EAM_IO_KEYPAD_9 = 11, - - EAM_IO_KEYPAD_COUNT = 12, /* Not an actual scan code */ -}; - -/* Emulating the sensors of a slotted card reader. The reader has one - sensor at the front that detects if a card is getting inserted or - if the card is not fully removed. When the back sensor is triggered - the card is locked in the slot and its data is read. */ - -enum eam_io_sensor_state { - EAM_IO_SENSOR_FRONT = 0, - EAM_IO_SENSOR_BACK = 1, -}; - -/* Different commands for the (slotted) reader. The game triggers one - of these actions and the card slot as to execute it. When non-slotted - readers are emulated, these states are not used/set. */ - -enum eam_io_card_slot_cmd { - EAM_IO_CARD_SLOT_CMD_CLOSE = 0, - EAM_IO_CARD_SLOT_CMD_OPEN = 1, - EAM_IO_CARD_SLOT_CMD_EJECT = 2, - EAM_IO_CARD_SLOT_CMD_READ = 3, -}; - -/* Emulating of the card type for new readers. */ - -enum eam_io_read_card_result { - EAM_IO_CARD_NONE = 0, - EAM_IO_CARD_ISO15696 = 1, - EAM_IO_CARD_FELICA = 2, -}; - -/* A private function pointer table returned by the stock EAMIO.DLL - implementation and consumed by config.exe. The contents of this table are - undocumented and subject to change without notice. */ - -struct eam_io_config_api; - -/* The first function that will be called on your DLL. You will be supplied - with four function pointers that may be used to log messages to the game's - log file. See comments in glue.h for further information. */ - -void eam_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); - -/* Initialize your card reader emulation DLL. Thread management functions are - provided to you; you must use these functions to create your own threads if - you want to make use of the logging functions that are provided to - eam_io_set_loggers(). You will also need to pass these thread management - functions on to geninput if you intend to make use of that library. - - See glue.h and geninput.h for further details. */ - -bool eam_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy); - -/* Shut down your card reader emulation DLL. */ - -void eam_io_fini(void); - -/* Return the state of the number pad on your reader. This function will be - called frequently. See enum eam_io_keypad_scan_code above for the meaning of - each bit within the return value. - - This function will be called even if the running game does not actually have - a number pad on the real cabinet (e.g. Jubeat). - - unit_no is either 0 or 1. Games with only a single reader (jubeat, popn, - drummania) will only use unit_no 0. */ - -uint16_t eam_io_get_keypad_state(uint8_t unit_no); - -/* Indicate which sensors (front and back) are triggered for a slotted reader - (refer to enum). To emulate non-slotted readers, just set both sensors - to on to indicate the card is in range of the reader. This function - will be called frequently. */ - -uint8_t eam_io_get_sensor_state(uint8_t unit_no); - -/* Read a card ID. This function is only called when the return value of - eam_io_get_sensor_state() changes from false to true, so you may take your - time and perform file I/O etc, within reason. You must return exactly eight - bytes into the buffer pointed to by card_id. */ - -uint8_t eam_io_read_card(uint8_t unit_no, uint8_t *card_id, uint8_t nbytes); - -/* Send a command to the card slot. This is called by the game to execute - certain actions on a slotted reader (refer to enum). When emulating - wave pass readers, this is function is never called. */ - -bool eam_io_card_slot_cmd(uint8_t unit_no, uint8_t cmd); - -/* This function is called frequently. Update your device and states in here */ - -bool eam_io_poll(uint8_t unit_no); - -/* Return a pointer to an internal configuration API for use by config.exe. - Custom implementations should return NULL. */ - -const struct eam_io_config_api *eam_io_get_config_api(void); - -#endif diff --git a/src/main/bemanitools/glue.h b/src/main/bemanitools/glue.h deleted file mode 100644 index 7c9906d..0000000 --- a/src/main/bemanitools/glue.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef BEMANITOOLS_GLUE_H -#define BEMANITOOLS_GLUE_H - -/* Common definitions for integration bindings */ - -#include - -#ifdef __GNUC__ -/* Bemanitools is compiled with GCC (MinGW, specifically) as of version 5 */ -#define LOG_CHECK_FMT __attribute__((format(printf, 2, 3))) -#else -/* Compile it out for MSVC plebs */ -#define LOG_CHECK_FMT -#endif - -/* An AVS-style logger function. Comes in four flavors: misc, info, warning, - and fatal, with increasing severity. Fatal loggers do not return, they - abort the running process after writing their message to the log. - - "module" is an arbitrary short string identifying the source of the log - message. The name of the calling DLL is a good default choice for this - string, although you might want to identify a module within your DLL here - instead. - - "fmt" is a printf-style format string. Depending on the context in which - your DLL is running you might end up calling a logger function exported - from libavs, which has its own printf implementation (including a number of - proprietary extensions), so don't use any overly exotic formats. */ - -typedef void (*log_formatter_t)(const char *module, const char *fmt, ...) - LOG_CHECK_FMT; - -/* An API for spawning threads. This API is defined by libavs, although - Bemanitools itself may supply compatible implementations of these functions - to your DLL, depending on the context in which it runs. - - NOTE: You may only use the logging functions from a thread where Bemanitools - calls you, or a thread that you create using this API. Failure to observe - this restriction will cause the process to crash. This is a limitation of - libavs itself, not Bemanitools. */ - -typedef int (*thread_create_t)( - int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority); -typedef void (*thread_join_t)(int thread_id, int *result); -typedef void (*thread_destroy_t)(int thread_id); - -#endif diff --git a/src/main/bemanitools/iidxio.h b/src/main/bemanitools/iidxio.h deleted file mode 100644 index d18905d..0000000 --- a/src/main/bemanitools/iidxio.h +++ /dev/null @@ -1,174 +0,0 @@ -#ifndef BEMANITOOLS_IIDXIO_H -#define BEMANITOOLS_IIDXIO_H - -/* IO emulation provider for beatmania IIDX. */ - -#include -#include - -#include "bemanitools/glue.h" - -/* Bit mapping for the "pad" word */ - -enum iidx_io_sys_bit { - IIDX_IO_SYS_TEST = 0x00, - IIDX_IO_SYS_SERVICE = 0x01, - IIDX_IO_SYS_COIN = 0x02 -}; - -enum iidx_io_panel_bit { - IIDX_IO_PANEL_P1_START = 0x00, - IIDX_IO_PANEL_P2_START = 0x01, - IIDX_IO_PANEL_VEFX = 0x02, - IIDX_IO_PANEL_EFFECT = 0x03 -}; - -enum iidx_io_key_bit { - IIDX_IO_KEY_P1_1 = 0x00, - IIDX_IO_KEY_P1_2 = 0x01, - IIDX_IO_KEY_P1_3 = 0x02, - IIDX_IO_KEY_P1_4 = 0x03, - IIDX_IO_KEY_P1_5 = 0x04, - IIDX_IO_KEY_P1_6 = 0x05, - IIDX_IO_KEY_P1_7 = 0x06, - - IIDX_IO_KEY_P2_1 = 0x07, - IIDX_IO_KEY_P2_2 = 0x08, - IIDX_IO_KEY_P2_3 = 0x09, - IIDX_IO_KEY_P2_4 = 0x0A, - IIDX_IO_KEY_P2_5 = 0x0B, - IIDX_IO_KEY_P2_6 = 0x0C, - IIDX_IO_KEY_P2_7 = 0x0D -}; - -/* Bit mapping for the P1 and P2 deck lights */ - -enum iidx_io_deck_light { - IIDX_IO_DECK_LIGHT_P1_1 = 0, - IIDX_IO_DECK_LIGHT_P1_2 = 1, - IIDX_IO_DECK_LIGHT_P1_3 = 2, - IIDX_IO_DECK_LIGHT_P1_4 = 3, - IIDX_IO_DECK_LIGHT_P1_5 = 4, - IIDX_IO_DECK_LIGHT_P1_6 = 5, - IIDX_IO_DECK_LIGHT_P1_7 = 6, - - IIDX_IO_DECK_LIGHT_P2_1 = 8, - IIDX_IO_DECK_LIGHT_P2_2 = 9, - IIDX_IO_DECK_LIGHT_P2_3 = 10, - IIDX_IO_DECK_LIGHT_P2_4 = 11, - IIDX_IO_DECK_LIGHT_P2_5 = 12, - IIDX_IO_DECK_LIGHT_P2_6 = 13, - IIDX_IO_DECK_LIGHT_P2_7 = 14, -}; - -/* Bit mapping for the front panel lights */ - -enum iidx_io_panel_light { - IIDX_IO_PANEL_LIGHT_P1_START = 0, - IIDX_IO_PANEL_LIGHT_P2_START = 1, - IIDX_IO_PANEL_LIGHT_VEFX = 2, - IIDX_IO_PANEL_LIGHT_EFFECT = 3, -}; - -/* Bit mapping for the top lamps from left to right when facing cabinet screen - */ - -enum iidx_io_top_lamp { - IIDX_IO_TOP_LAMP_LEFT_BLUE = 0, - IIDX_IO_TOP_LAMP_LEFT_GREEN = 1, - IIDX_IO_TOP_LAMP_LEFT_YELLOW = 2, - IIDX_IO_TOP_LAMP_LEFT_RED = 3, - IIDX_IO_TOP_LAMP_RIGHT_BLUE = 4, - IIDX_IO_TOP_LAMP_RIGHT_GREEN = 5, - IIDX_IO_TOP_LAMP_RIGHT_YELLOW = 6, - IIDX_IO_TOP_LAMP_RIGHT_RED = 7, -}; - -/* The first function that will be called on your DLL. You will be supplied - with four function pointers that may be used to log messages to the game's - log file. See comments in glue.h for further information. */ - -void iidx_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); - -/* Initialize your IIDX IO emulation DLL. Thread management functions are - provided to you; you must use these functions to create your own threads if - you want to make use of the logging functions that are provided to - eam_io_set_loggers(). You will also need to pass these thread management - functions on to geninput if you intend to make use of that library. - - See glue.h and geninput.h for further details. */ - -bool iidx_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy); - -/* Shut down your IIDX IO emulation DLL */ - -void iidx_io_fini(void); - -/* Set the deck lighting state. See enum iidx_io_deck_light above. */ - -void iidx_io_ep1_set_deck_lights(uint16_t deck_lights); - -/* Set front panel lighting state. See enum iidx_io_panel_light above. */ - -void iidx_io_ep1_set_panel_lights(uint8_t panel_lights); - -/* Set state of the eight halogens above the marquee. */ - -void iidx_io_ep1_set_top_lamps(uint8_t top_lamps); - -/* Switch the top neons on or off. */ - -void iidx_io_ep1_set_top_neons(bool top_neons); - -/* Transmit the lighting state to the lighting controller. This function is - called immediately after all of the other iidx_io_ep1_set_*() functions. - - Return false in the event of an IO error. This will lock the game into an - IO error screen. */ - -bool iidx_io_ep1_send(void); - -/* Read input state from the input controller. This function is called - immediately before all of the iidx_io_ep2_get_*() functions. - - Return false in the event of an IO error. This will lock the game into an - IO error screen. */ - -bool iidx_io_ep2_recv(void); - -/* Get absolute turntable position, expressed in 1/256ths of a rotation. - player_no is either 0 or 1. */ - -uint8_t iidx_io_ep2_get_turntable(uint8_t player_no); - -/* Get slider position, where 0 is the bottom position and 15 is the topmost - position. slider_no is a number between 0 (leftmost) and 4 (rightmost). */ - -uint8_t iidx_io_ep2_get_slider(uint8_t slider_no); - -/* Get the state of the system buttons. See enums above. */ - -uint8_t iidx_io_ep2_get_sys(void); - -/* Get the state of the panel buttons. See enums above. */ - -uint8_t iidx_io_ep2_get_panel(void); - -/* Get the state of the 14 key buttons. See enums above. */ - -uint16_t iidx_io_ep2_get_keys(void); - -/* Write a nine-character string to the 16-segment display. This happens on a - different schedule to all of the other IO operations, so you should initiate - the communication as soon as this function is called */ - -bool iidx_io_ep3_write_16seg(const char *text); - -#endif diff --git a/src/main/bemanitools/input.h b/src/main/bemanitools/input.h deleted file mode 100644 index df80903..0000000 --- a/src/main/bemanitools/input.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef BEMANITOOLS_INPUT_H -#define BEMANITOOLS_INPUT_H - -/* Generic input API. This header file defines the public API for geninput.dll. - - You may use geninput to supply generic input mapping services for controls - that your custom IO DLLs do not natively provide. For instance, you might - want to make a custom IIDXIO.DLL that interfaces with your own 16-segment - LCD marquee device while still using the stock IIDXIO.DLL input and lighting - code, which uses the generic services provided by geninput.dll. - - All other exports from geninput.dll are undocumented and subject to change - without notice. */ - -#include -#include - -#include "bemanitools/glue.h" - -/* Supply logging functions to geninput. You should pass on the logging - functions that are supplied to your own custom DLLs. - - This is the only function that can safely be called before input_init(). */ - -void input_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); - -/* Initialize the generic input subsystem. You must pass on the thread - management functions that have been supplied to your DLL. - - Calling any geninput functions other than input_set_loggers() before calling - input_init() will probably crash the running process. - - You will also need to call mapper_config_load() with the appropriate - game_type parameter, otherwise you will not receive any input, and any - attempts to set a light output level will have no effect. */ - -void input_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy); - -/* Shut down the generic input subsystem. After calling this function, no - geninput functions other than input_set_loggers() or input_init() may be - called. */ - -void input_fini(void); - -/* Load input mappings for a particular game, as configured from config.exe. - - Currently recognized game types are: - - ddr: Dance Dance Revolution - dm: Drum Mania - gf: Guitar Freaks - iidx: beatmania IIDX - pnm: pop'n music - sdvx: Sound Voltex - ju: jubeat - - Returns true if a suitable config file was found and successfully loaded. */ - -bool mapper_config_load(const char *game_type); - -/* Return the absolute position of an analog spinner, expressed in 1/256ths of - a complete rotation. */ - -uint8_t mapper_read_analog(uint8_t analog); - -/* Map the current state of all attached input devices to a 64-bit bit field. - The exact layout of this bit field varies between game types, although we - try to approximate the contents of each emulated IO PCB's own state packet - as closely as is reasonably practical. */ - -uint64_t mapper_update(void); - -/* Set the intensity of any light on a controller corresponding to a particular - software-controlled light on an arcade cabinet, where 0 is off and 255 is - full intensity. Consult the header files for the light identifiers used for - each game type. The mappings between these light identifiers and the actual - lights on the user's controller (if any) are configured by the user by means - of the config.exe program. - - Note that any calls to this function do not take effect until the next call - to mapper_update(). */ - -void mapper_write_light(uint8_t light, uint8_t intensity); - -#endif diff --git a/src/main/bemanitools/jbio.h b/src/main/bemanitools/jbio.h deleted file mode 100644 index 1a58617..0000000 --- a/src/main/bemanitools/jbio.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef BEMANITOOLS_JBIO_H -#define BEMANITOOLS_JBIO_H - -/* IO emulation provider for jubeat. */ - -#include -#include - -#include "bemanitools/glue.h" - -/* input bit mappings. Panels on the controller are - panel 1 top left corner down to panel 16 bottom right corner */ -enum jb_io_panel_bit { - JB_IO_PANEL_01 = 0x00, - JB_IO_PANEL_02 = 0x01, - JB_IO_PANEL_03 = 0x02, - JB_IO_PANEL_04 = 0x03, - JB_IO_PANEL_05 = 0x04, - JB_IO_PANEL_06 = 0x05, - JB_IO_PANEL_07 = 0x06, - JB_IO_PANEL_08 = 0x07, - JB_IO_PANEL_09 = 0x08, - JB_IO_PANEL_10 = 0x09, - JB_IO_PANEL_11 = 0x0A, - JB_IO_PANEL_12 = 0x0B, - JB_IO_PANEL_13 = 0x0C, - JB_IO_PANEL_14 = 0x0D, - JB_IO_PANEL_15 = 0x0E, - JB_IO_PANEL_16 = 0x0F, -}; - -/* input "single button mode" mappings. Allows you to check each corner of each - button to determine any flaky inputs -*/ -enum jb_io_panel_mode { - JB_IO_PANEL_MODE_ALL = 0, // any of the four corners will trigger a panel - JB_IO_PANEL_MODE_TOP_LEFT = 1, - JB_IO_PANEL_MODE_TOP_RIGHT = 2, - JB_IO_PANEL_MODE_BOTTOM_RIGHT = 3, - JB_IO_PANEL_MODE_BOTTOM_LEFT = 4, -}; - -/* Bit mappings for "system" inputs */ -enum jb_io_sys_bit { - JB_IO_SYS_TEST = 0x00, - JB_IO_SYS_SERVICE = 0x01, - JB_IO_SYS_COIN = 0x02, -}; - -/* RGB led units to address */ -enum jb_io_rgb_led { - JB_IO_RGB_LED_FRONT = 0, - JB_IO_RGB_LED_TOP = 1, - JB_IO_RGB_LED_LEFT = 2, - JB_IO_RGB_LED_RIGHT = 3, - JB_IO_RGB_LED_TITLE = 4, - JB_IO_RGB_LED_WOOFER = 5 -}; - -/* The first function that will be called on your DLL. You will be supplied - with four function pointers that may be used to log messages to the game's - log file. See comments in glue.h for further information. */ - -void jb_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); - -/* Initialize your JB IO emulation DLL. Thread management functions are - provided to you; you must use these functions to create your own threads if - you want to make use of the logging functions that are provided to - jb_io_set_loggers(). You will also need to pass these thread management - functions on to geninput if you intend to make use of that library. - - See glue.h and geninput.h for further details. */ - -bool jb_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy); - -/* Shut down your JB IO emulation DLL */ - -void jb_io_fini(void); - -/* Read input state */ - -bool jb_io_read_inputs(void); - -/* Get state of coin, test, service inputs */ - -uint8_t jb_io_get_sys_inputs(void); - -/* Get panel button state. Will return either any button being pressed, or a - particular panel corner depending on previous call to jb_io_set_panel_mode */ - -uint16_t jb_io_get_panel_inputs(void); - -/* Set state of a PWM (dimmable) light */ - -void jb_io_set_rgb_led( - enum jb_io_rgb_led unit, uint8_t r, uint8_t g, uint8_t b); - -/* Transmit the light state to the IOPCB */ - -bool jb_io_write_lights(void); - -/* Select operating mode for the panel. Should be immediately sent to the IOPCB - */ - -bool jb_io_set_panel_mode(enum jb_io_panel_mode mode); - -/* Open or close the coin chute - true will redirect all coins to the return - slot. Required for jb_io_set_panel_mode to operate correctly on p4io. - Should be immediately sent to the IOPCB */ - -bool jb_io_set_coin_blocker(bool blocked); - -#endif diff --git a/src/main/bemanitools/popnio.h b/src/main/bemanitools/popnio.h deleted file mode 100644 index 29829ab..0000000 --- a/src/main/bemanitools/popnio.h +++ /dev/null @@ -1,108 +0,0 @@ -#ifndef BEMANITOOLS_POPNIO_H -#define BEMANITOOLS_POPNIO_H - -/* IO emulation provider for pop'n music. */ - -#include -#include - -#include "bemanitools/glue.h" - -/* Bit mapping for the "buttons" word */ - -enum popn_io_sys_bit { - POPN_IO_SYS_SERVICE = 0x06, - POPN_IO_SYS_TEST = 0x07, -}; - -enum popn_io_button_bit { - POPN_IO_BUTTON_1 = 0x08, - POPN_IO_BUTTON_2 = 0x09, - POPN_IO_BUTTON_3 = 0x0a, - POPN_IO_BUTTON_4 = 0x0b, - POPN_IO_BUTTON_5 = 0x0c, - POPN_IO_BUTTON_6 = 0x0d, - POPN_IO_BUTTON_7 = 0x0e, - POPN_IO_BUTTON_8 = 0x0f, - POPN_IO_BUTTON_9 = 0x10, -}; - -enum popn_io_light_top_lamp_bit { - POPN_LIGHT_HI_LAMP1 = 0x00, - POPN_LIGHT_HI_LAMP2 = 0x01, - POPN_LIGHT_HI_LAMP3 = 0x02, - POPN_LIGHT_HI_LAMP4 = 0x03, - POPN_LIGHT_HI_LAMP5 = 0x04, -}; - -enum popn_io_light_side_lamp_bit { - POPN_LIGHT_LEFT_LAMP1 = 0x00, - POPN_LIGHT_LEFT_LAMP2 = 0x01, - POPN_LIGHT_RIGHT_LAMP1 = 0x02, - POPN_LIGHT_RIGHT_LAMP2 = 0x03, -}; - -enum popn_io_light_switch_lamp_bit { - POPN_LIGHT_SW_LAMP1 = 0x00, // Is actually 4 bits wide - POPN_LIGHT_SW_LAMP2 = 0x04, - POPN_LIGHT_SW_LAMP3 = 0x05, - POPN_LIGHT_SW_LAMP4 = 0x06, - POPN_LIGHT_SW_LAMP5 = 0x07, - POPN_LIGHT_SW_LAMP6 = 0x08, - POPN_LIGHT_SW_LAMP7 = 0x09, - POPN_LIGHT_SW_LAMP8 = 0x0a, - POPN_LIGHT_SW_LAMP9 = 0x0b, -}; - -/* The first function that will be called on your DLL. You will be supplied - with four function pointers that may be used to log messages to the game's - log file. See comments in glue.h for further information. */ - -void popn_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); - -/* Initialize your pop'n music IO emulation DLL. Thread management functions are - provided to you; you must use these functions to create your own threads if - you want to make use of the logging functions that are provided to - eam_io_set_loggers(). You will also need to pass these thread management - functions on to geninput if you intend to make use of that library. - - See glue.h and geninput.h for further details. */ - -bool popn_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy); - -/* Shut down your pop'n music IO emulation DLL */ - -void popn_io_fini(void); - -/* Get the state of the buttons. See enums above. */ - -uint32_t popn_io_get_buttons(void); - -/* Set the top light state. See enum popn_io_light_top_lamp_bit above. */ - -void popn_io_set_top_lights(uint32_t lights); - -/* Set the side light state. See enum popn_io_light_side_lamp_bit above. */ - -void popn_io_set_side_lights(uint32_t lights); - -/* Set the button light state. See enum popn_io_light_switch_lamp_bit above. */ - -void popn_io_set_button_lights(uint32_t lights); - -/* Set the coin blocker light state. */ - -void popn_io_set_coin_blocker_light(bool enabled); - -/* Set the coin counter light state. */ - -void popn_io_set_coin_counter_light(bool enabled); - -#endif diff --git a/src/main/bemanitools/sdvxio.h b/src/main/bemanitools/sdvxio.h deleted file mode 100644 index 2ebab7b..0000000 --- a/src/main/bemanitools/sdvxio.h +++ /dev/null @@ -1,108 +0,0 @@ -#ifndef BEMANITOOLS_SDVXIO_H -#define BEMANITOOLS_SDVXIO_H - -/* IO emulation provider for SOUND VOLTEX */ - -#include -#include - -#include "bemanitools/glue.h" - -enum sdvx_io_in_gpio_sys_bit { - SDVX_IO_IN_GPIO_SYS_COIN = 2, - SDVX_IO_IN_GPIO_SYS_SERVICE = 4, - SDVX_IO_IN_GPIO_SYS_TEST = 5, -}; - -enum sdvx_io_in_gpio_0_bit { - SDVX_IO_IN_GPIO_0_C = 0, - SDVX_IO_IN_GPIO_0_B = 1, - SDVX_IO_IN_GPIO_0_A = 2, - SDVX_IO_IN_GPIO_0_START = 3, - SDVX_IO_IN_GPIO_0_RECORDER = 4, - SDVX_IO_IN_GPIO_0_HEADPHONE = 5, -}; - -enum sdvx_io_in_gpio_1_bit { - SDVX_IO_IN_GPIO_1_FX_R = 3, - SDVX_IO_IN_GPIO_1_FX_L = 4, - SDVX_IO_IN_GPIO_1_D = 5, -}; - -enum sdvx_io_out_gpio_bit { - SDVX_IO_OUT_GPIO_D = 0, - SDVX_IO_OUT_GPIO_FX_L = 1, - SDVX_IO_OUT_GPIO_FX_R = 2, - SDVX_IO_OUT_GPIO_GENERATOR_B = 3, - SDVX_IO_OUT_GPIO_START = 12, - SDVX_IO_OUT_GPIO_A = 13, - SDVX_IO_OUT_GPIO_B = 14, - SDVX_IO_OUT_GPIO_C = 15, -}; - -/* The first function that will be called on your DLL. You will be supplied - with four function pointers that may be used to log messages to the game's - log file. See comments in glue.h for further information. */ - -void sdvx_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); - -/* Initialize your SDVX IO emulation DLL. Thread management functions are - provided to you; you must use these functions to create your own threads if - you want to make use of the logging functions that are provided to - eam_io_set_loggers(). You will also need to pass these thread management - functions on to geninput if you intend to make use of that library. - - See glue.h and geninput.h for further details. */ - -bool sdvx_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy); - -/* Shut down your SDVX IO emulation DLL */ - -void sdvx_io_fini(void); - -/* Set state of the GPIO (on/off) lights (see bit definitions above) */ - -void sdvx_io_set_gpio_lights(uint32_t gpio_lights); - -/* Set state of a PWM (dimmable) light channel. These come in groups of three - (red, green, blue). There are a six group of three PWM channels, for a - total of 18 channels (0 through 17). */ - -void sdvx_io_set_pwm_light(uint8_t light_no, uint8_t intensity); - -/* Transmit the light state to the IOPCB */ - -bool sdvx_io_write_output(void); - -/* Read input state */ - -bool sdvx_io_read_input(void); - -/* Get state of coin, test, service inputs */ - -uint8_t sdvx_io_get_input_gpio_sys(void); - -/* Get gameplay button state. Parameter selects GPIO bank 0 or 1. See bit - definitions above for details. */ - -uint16_t sdvx_io_get_input_gpio(uint8_t gpio_bank); - -/* Get a 10-bit (!) spinner position, where spinner_no is 0 or 1. - High six bits are ignored. */ - -uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no); - -/* Sets the volume of the digital amps if possible. - Range is between 0-96, where 0 is MAX and 96 is LOW. */ - -bool sdvx_io_set_amp_volume( - uint8_t primary, uint8_t headphone, uint8_t subwoofer); - -#endif diff --git a/src/main/bemanitools/vefxio.h b/src/main/bemanitools/vefxio.h deleted file mode 100644 index 9bf170e..0000000 --- a/src/main/bemanitools/vefxio.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef BEMANITOOLS_VEFXIO_H -#define BEMANITOOLS_VEFXIO_H - -/* IO emulation provider for beatmania IIDX Effector Panel. */ - -#include -#include - -#include "bemanitools/glue.h" - -/* The first function that will be called on your DLL. You will be supplied - with four function pointers that may be used to log messages to the game's - log file. See comments in glue.h for further information. */ - -void vefx_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); - -/* Initialize your IIDX IO emulation DLL. Thread management functions are - provided to you; you must use these functions to create your own threads if - you want to make use of the logging functions that are provided to - eam_io_set_loggers(). You will also need to pass these thread management - functions on to geninput if you intend to make use of that library. - - See glue.h and geninput.h for further details. */ - -bool vefx_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy); - -/* Shut down your IIDX IO emulation DLL */ - -void vefx_io_fini(void); - -/* Read input state from the input controller. This function is called - immediately before the vefx_io_get_slider() function. - - Return false in the event of an IO error. This will lock the game into an - IO error screen. - - If making a custom driver, ppad can be used to update regular IO if needed - - See iidxio.c for mappings. */ - -bool vefx_io_recv(uint64_t *ppad); - -/* Get slider position, where 0 is the bottom position and 15 is the topmost - position. slider_no is a number between 0 (leftmost) and 4 (rightmost). */ - -uint8_t vefx_io_get_slider(uint8_t slider_no); - -/* Write a nine-character string to the 16-segment display. This happens on a - different schedule to all of the other IO operations, so you should initiate - the communication as soon as this function is called */ - -bool vefx_io_write_16seg(const char *text); - -#endif diff --git a/src/main/bio2drv/bi2a-iidx.c b/src/main/bio2drv/bi2a-iidx.c index bce8c41..ebf119c 100644 --- a/src/main/bio2drv/bi2a-iidx.c +++ b/src/main/bio2drv/bi2a-iidx.c @@ -7,7 +7,7 @@ #include "aciodrv/device.h" -#include "core/log.h" +#include "iface-core/log.h" // Must be provided on init command. Actual meaning unknown right now. // Not providing this will not initialize the IO correctly resulting diff --git a/src/main/bio2drv/bi2a-sdvx.c b/src/main/bio2drv/bi2a-sdvx.c index 14e5239..0d11e30 100644 --- a/src/main/bio2drv/bi2a-sdvx.c +++ b/src/main/bio2drv/bi2a-sdvx.c @@ -7,7 +7,7 @@ #include "aciodrv/device.h" -#include "core/log.h" +#include "iface-core/log.h" static const uint8_t _BIO2DR_BI2A_SDVX_INIT_DATA = 0x3B; diff --git a/src/main/bio2drv/config-bio2.c b/src/main/bio2drv/config-bio2.c index c016fa9..f166476 100644 --- a/src/main/bio2drv/config-bio2.c +++ b/src/main/bio2drv/config-bio2.c @@ -1,8 +1,8 @@ +#include "bio2drv/config-bio2.h" + #include "cconfig/cconfig-util.h" -#include "core/log.h" - -#include "bio2drv/config-bio2.h" +#include "iface-core/log.h" #define BIO2DRV_CONFIG_BIO2_AUTO_KEY "bio2.autodetect" #define BIO2DRV_CONFIG_BIO2_PORT_KEY "bio2.port" diff --git a/src/main/bio2drv/detect.c b/src/main/bio2drv/detect.c index dfdf501..35465a4 100644 --- a/src/main/bio2drv/detect.c +++ b/src/main/bio2drv/detect.c @@ -6,13 +6,13 @@ #include #include -#include "bio2drv/detect.h" - -#include "core/log.h" - #include #include +#include "bio2drv/detect.h" + +#include "iface-core/log.h" + DEFINE_GUID( GUID_COM_BUS_ENUMERATOR, 0x4D36E978, @@ -136,15 +136,6 @@ static bool get_device_by_filter( return false; } -void bio2drv_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - core_log_impl_set(misc, warning, info, fatal); -} - bool bio2drv_detect( enum bio2drv_detect_mode mode, size_t index, char *path, size_t length) { diff --git a/src/main/bio2drv/detect.h b/src/main/bio2drv/detect.h index 21ab725..dd86dae 100644 --- a/src/main/bio2drv/detect.h +++ b/src/main/bio2drv/detect.h @@ -3,20 +3,12 @@ #include -#include "bemanitools/glue.h" - enum bio2drv_detect_mode { DETECT_DEVICEDESC = 0x1, // look for serial devices containing BIO2(VIDEO) DETECT_FRIENDLYNAME = 0x2, // look for serial devices containing BIO2(VIDEO) DETECT_DEVICEID = 0x3, // look for serial devices by vid/pid }; -void bio2drv_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); - bool bio2drv_detect( enum bio2drv_detect_mode mode, size_t devnum, char *path, size_t length); diff --git a/src/main/bio2emu-iidx/bi2a.c b/src/main/bio2emu-iidx/bi2a.c index cd2b56a..bdc05c7 100644 --- a/src/main/bio2emu-iidx/bi2a.c +++ b/src/main/bio2emu-iidx/bi2a.c @@ -10,9 +10,10 @@ #include #include "acioemu/emu.h" -#include "util/math.h" -#include "bemanitools/iidxio.h" +#include "iface-io/iidx.h" + +#include "util/math.h" static int get_default_slider_valid(size_t idx); static void bio2_emu_bi2a_cmd_send_version( @@ -178,7 +179,7 @@ static void bio2_emu_bi2a_send_status( static int16_t tt_mult_delta(size_t tt_no) { - int16_t current_tt = iidx_io_ep2_get_turntable(tt_no); + int16_t current_tt = bt_io_iidx_ep2_turntable_get(tt_no); int16_t delta = get_wrapped_delta_s16(current_tt, tt_last[tt_no], 256); tt_last[tt_no] = current_tt; @@ -233,17 +234,17 @@ bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req) } } - iidx_io_ep1_set_deck_lights(packed_lights.deck_lights); - iidx_io_ep1_set_panel_lights(packed_lights.panel_lights); - iidx_io_ep1_set_top_lamps(packed_lights.top_lamps); - iidx_io_ep1_set_top_neons(req_bi2a->NEONLAMP.l_state); + bt_io_iidx_ep1_deck_lights_set(packed_lights.deck_lights); + bt_io_iidx_ep1_panel_lights_set(packed_lights.panel_lights); + bt_io_iidx_ep1_top_lamps_set(packed_lights.top_lamps); + bt_io_iidx_ep1_top_neons_set(req_bi2a->NEONLAMP.l_state); - if (!iidx_io_ep1_send()) { + if (!bt_io_iidx_ep1_send()) { log_warning("BIO2: iidx_io_ep1_send error"); return bio2_emu_bi2a_send_status(emu, req, 0); } - if (!iidx_io_ep3_write_16seg((const char *) req_bi2a->SEG16)) { + if (!bt_io_iidx_ep3_16seg_send((const char *) req_bi2a->SEG16)) { log_warning("BIO2: iidx_io_ep3_write_16seg error"); return bio2_emu_bi2a_send_status(emu, req, 0); } @@ -256,7 +257,7 @@ bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req) Sleep(1); } - if (!iidx_io_ep2_recv()) { + if (!bt_io_iidx_ep2_recv()) { log_warning("BIO2: iidx_io_ep2_recv error"); return bio2_emu_bi2a_send_status(emu, req, 0); } @@ -268,52 +269,52 @@ bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req) body->TURNTABLE1 = tt_accum[0]; body->TURNTABLE2 = tt_accum[1]; } else { - body->TURNTABLE1 = iidx_io_ep2_get_turntable(0); - body->TURNTABLE2 = iidx_io_ep2_get_turntable(1); + body->TURNTABLE1 = bt_io_iidx_ep2_turntable_get(0); + body->TURNTABLE2 = bt_io_iidx_ep2_turntable_get(1); } body->SLIDER1.s_val = get_default_slider_valid(0) ? default_sliders[0] : - iidx_io_ep2_get_slider(0); + bt_io_iidx_ep2_slider_get(0); body->SLIDER2.s_val = get_default_slider_valid(1) ? default_sliders[1] : - iidx_io_ep2_get_slider(1); + bt_io_iidx_ep2_slider_get(1); body->SLIDER3.s_val = get_default_slider_valid(2) ? default_sliders[2] : - iidx_io_ep2_get_slider(2); + bt_io_iidx_ep2_slider_get(2); body->SLIDER4.s_val = get_default_slider_valid(3) ? default_sliders[3] : - iidx_io_ep2_get_slider(3); + bt_io_iidx_ep2_slider_get(3); body->SLIDER5.s_val = get_default_slider_valid(4) ? default_sliders[4] : - iidx_io_ep2_get_slider(4); + bt_io_iidx_ep2_slider_get(4); - input_keys = iidx_io_ep2_get_keys(); - input_sys = iidx_io_ep2_get_sys(); - input_panel = iidx_io_ep2_get_panel(); - body->P1SW1.b_val = (input_keys >> IIDX_IO_KEY_P1_1) & 1; - body->P1SW2.b_val = (input_keys >> IIDX_IO_KEY_P1_2) & 1; - body->P1SW3.b_val = (input_keys >> IIDX_IO_KEY_P1_3) & 1; - body->P1SW4.b_val = (input_keys >> IIDX_IO_KEY_P1_4) & 1; - body->P1SW5.b_val = (input_keys >> IIDX_IO_KEY_P1_5) & 1; - body->P1SW6.b_val = (input_keys >> IIDX_IO_KEY_P1_6) & 1; - body->P1SW7.b_val = (input_keys >> IIDX_IO_KEY_P1_7) & 1; - body->P2SW1.b_val = (input_keys >> IIDX_IO_KEY_P2_1) & 1; - body->P2SW2.b_val = (input_keys >> IIDX_IO_KEY_P2_2) & 1; - body->P2SW3.b_val = (input_keys >> IIDX_IO_KEY_P2_3) & 1; - body->P2SW4.b_val = (input_keys >> IIDX_IO_KEY_P2_4) & 1; - body->P2SW5.b_val = (input_keys >> IIDX_IO_KEY_P2_5) & 1; - body->P2SW6.b_val = (input_keys >> IIDX_IO_KEY_P2_6) & 1; - body->P2SW7.b_val = (input_keys >> IIDX_IO_KEY_P2_7) & 1; + input_keys = bt_io_iidx_ep2_keys_get(); + input_sys = bt_io_iidx_ep2_sys_get(); + input_panel = bt_io_iidx_ep2_panel_get(); + body->P1SW1.b_val = (input_keys >> BT_IO_IIDX_KEY_P1_1) & 1; + body->P1SW2.b_val = (input_keys >> BT_IO_IIDX_KEY_P1_2) & 1; + body->P1SW3.b_val = (input_keys >> BT_IO_IIDX_KEY_P1_3) & 1; + body->P1SW4.b_val = (input_keys >> BT_IO_IIDX_KEY_P1_4) & 1; + body->P1SW5.b_val = (input_keys >> BT_IO_IIDX_KEY_P1_5) & 1; + body->P1SW6.b_val = (input_keys >> BT_IO_IIDX_KEY_P1_6) & 1; + body->P1SW7.b_val = (input_keys >> BT_IO_IIDX_KEY_P1_7) & 1; + body->P2SW1.b_val = (input_keys >> BT_IO_IIDX_KEY_P2_1) & 1; + body->P2SW2.b_val = (input_keys >> BT_IO_IIDX_KEY_P2_2) & 1; + body->P2SW3.b_val = (input_keys >> BT_IO_IIDX_KEY_P2_3) & 1; + body->P2SW4.b_val = (input_keys >> BT_IO_IIDX_KEY_P2_4) & 1; + body->P2SW5.b_val = (input_keys >> BT_IO_IIDX_KEY_P2_5) & 1; + body->P2SW6.b_val = (input_keys >> BT_IO_IIDX_KEY_P2_6) & 1; + body->P2SW7.b_val = (input_keys >> BT_IO_IIDX_KEY_P2_7) & 1; - body->PANEL.y_start1 = (input_panel >> IIDX_IO_PANEL_P1_START) & 1; - body->PANEL.y_start2 = (input_panel >> IIDX_IO_PANEL_P2_START) & 1; - body->PANEL.y_vefx = (input_panel >> IIDX_IO_PANEL_VEFX) & 1; - body->PANEL.y_effect = (input_panel >> IIDX_IO_PANEL_EFFECT) & 1; + body->PANEL.y_start1 = (input_panel >> BT_IO_IIDX_PANEL_P1_START) & 1; + body->PANEL.y_start2 = (input_panel >> BT_IO_IIDX_PANEL_P2_START) & 1; + body->PANEL.y_vefx = (input_panel >> BT_IO_IIDX_PANEL_VEFX) & 1; + body->PANEL.y_effect = (input_panel >> BT_IO_IIDX_PANEL_EFFECT) & 1; - body->SYSTEM.v_test = (input_sys >> IIDX_IO_SYS_TEST) & 1; - body->SYSTEM.v_service = (input_sys >> IIDX_IO_SYS_SERVICE) & 1; - body->SYSTEM.v_coin = (input_sys >> IIDX_IO_SYS_COIN) & 1; + body->SYSTEM.v_test = (input_sys >> BT_IO_IIDX_SYS_TEST) & 1; + body->SYSTEM.v_service = (input_sys >> BT_IO_IIDX_SYS_SERVICE) & 1; + body->SYSTEM.v_coin = (input_sys >> BT_IO_IIDX_SYS_COIN) & 1; if (body->SYSTEM.v_coin) { if (!coin_latch) { diff --git a/src/main/bio2emu/emu.c b/src/main/bio2emu/emu.c index ea9c7f0..81f73d0 100644 --- a/src/main/bio2emu/emu.c +++ b/src/main/bio2emu/emu.c @@ -14,14 +14,14 @@ #include "acioemu/addr.h" #include "acioemu/emu.h" -#include "core/log.h" - #include "hook/iohook.h" #include "hooklib/rs232.h" #include "bio2emu/emu.h" #include "bio2emu/setupapi.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "util/array.h" diff --git a/src/main/bio2emu/setupapi.c b/src/main/bio2emu/setupapi.c index bb2f32c..cb74bd1 100644 --- a/src/main/bio2emu/setupapi.c +++ b/src/main/bio2emu/setupapi.c @@ -6,12 +6,12 @@ #include #include -#include "core/log.h" +#include "bio2emu/emu.h" +#include "bio2emu/setupapi.h" #include "hook/table.h" -#include "bio2emu/emu.h" -#include "bio2emu/setupapi.h" +#include "iface-core/log.h" #include "util/defs.h" #include "util/str.h" diff --git a/src/main/bsthook/Module.mk b/src/main/bsthook/Module.mk index 92ab3b1..22a7615 100644 --- a/src/main/bsthook/Module.mk +++ b/src/main/bsthook/Module.mk @@ -3,15 +3,18 @@ avsdlls += bsthook deplibs_bsthook := \ avs \ +avslibs_bsthook := \ + avs-ext \ + libs_bsthook := \ - avs-util \ + util \ core \ acioemu \ - bstio \ hook \ hooklib \ - util \ - eamio \ + iface-io \ + module \ + iface-core \ src_bsthook := \ acio.c \ diff --git a/src/main/bsthook/acio.c b/src/main/bsthook/acio.c index 500d4c5..3aa641a 100644 --- a/src/main/bsthook/acio.c +++ b/src/main/bsthook/acio.c @@ -19,7 +19,7 @@ #include "bsthook/acio.h" #include "bsthook/kfca.h" -#include "core/log.h" +#include "iface-core/log.h" #include "hook/iohook.h" diff --git a/src/main/bsthook/acio.h b/src/main/bsthook/acio.h index d6d6ee2..57d7c65 100644 --- a/src/main/bsthook/acio.h +++ b/src/main/bsthook/acio.h @@ -3,6 +3,9 @@ #include +#include "api/io/bst.h" +#include "api/io/eam.h" + #include "hook/iohook.h" void ac_io_bus_init(void); diff --git a/src/main/bsthook/dllmain.c b/src/main/bsthook/dllmain.c index e508057..474ba7b 100644 --- a/src/main/bsthook/dllmain.c +++ b/src/main/bsthook/dllmain.c @@ -2,13 +2,18 @@ #include -#include "avs-util/core-interop.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" -#include "bemanitools/bstio.h" -#include "bemanitools/eamio.h" +#include "bsthook/acio.h" +#include "bsthook/gfx.h" +#include "bsthook/settings.h" -#include "core/log.h" -#include "core/thread.h" +#include "iface-core/config.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface-io/bst.h" +#include "iface-io/eam.h" #include "hook/iohook.h" @@ -17,57 +22,74 @@ #include "imports/avs.h" -#include "bsthook/acio.h" -#include "bsthook/gfx.h" -#include "bsthook/settings.h" +#include "module/io-ext.h" #include "util/cmdline.h" #include "util/defs.h" +static module_io_t *_bsthook_module_io_bst; +static module_io_t *_bsthook_module_io_eam; + static bool my_dll_entry_init(char *sidcode, struct property_node *config); static bool my_dll_entry_main(void); +static void _bsthook_io_bst_init(module_io_t **module) +{ + bt_io_bst_api_t api; + + module_io_ext_load_and_init( + "bstio.dll", "bt_module_io_bst_api_get", module); + module_io_api_get(*module, &api); + bt_io_bst_api_set(&api); +} + +static void _bsthook_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} + static bool my_dll_entry_init(char *sidcode, struct property_node *config) { bool ok; log_info("--- Begin bsthook dll_entry_init ---"); - ac_io_bus_init(); - log_info("Starting up BeatStream IO backend"); - core_log_impl_assign(bst_io_set_loggers); + _bsthook_io_bst_init(&_bsthook_module_io_bst); - ok = bst_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + ok = bt_io_bst_init(); if (!ok) { goto bst_io_fail; } - core_log_impl_assign(eam_io_set_loggers); + _bsthook_io_eam_init(&_bsthook_module_io_eam); - ok = eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + ok = bt_io_eam_init(); if (!ok) { goto eam_io_fail; } + ac_io_bus_init(); + log_info("--- End bsthook dll_entry_init ---"); return app_hook_invoke_init(sidcode, config); eam_io_fail: - bst_io_fini(); + bt_io_bst_fini(); + + bt_io_bst_api_clear(); + module_io_free(&_bsthook_module_io_bst); bst_io_fail: - ac_io_bus_fini(); return false; } @@ -79,10 +101,16 @@ static bool my_dll_entry_main(void) result = app_hook_invoke_main(); log_info("Shutting down card reader backend"); - eam_io_fini(); + bt_io_eam_fini(); - log_info("Shutting down SDVX IO backend"); - bst_io_fini(); + bt_io_eam_api_clear(); + module_io_free(&_bsthook_module_io_eam); + + log_info("Shutting down BeatStream IO backend"); + bt_io_bst_fini(); + + bt_io_bst_api_clear(); + module_io_free(&_bsthook_module_io_bst); ac_io_bus_fini(); @@ -100,8 +128,8 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) } // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); args_recover(&argc, &argv); diff --git a/src/main/bsthook/gfx.c b/src/main/bsthook/gfx.c index 23d37e0..ae98eb0 100644 --- a/src/main/bsthook/gfx.c +++ b/src/main/bsthook/gfx.c @@ -3,7 +3,7 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "hook/com-proxy.h" #include "hook/pe.h" diff --git a/src/main/bsthook/kfca.c b/src/main/bsthook/kfca.c index 0e3ff02..0ff4b5f 100644 --- a/src/main/bsthook/kfca.c +++ b/src/main/bsthook/kfca.c @@ -7,7 +7,7 @@ #include "acioemu/emu.h" -#include "bemanitools/bstio.h" +#include "iface-io/bst.h" #include "util/defs.h" @@ -122,7 +122,7 @@ static void kfca_poll(const struct ac_io_message *req) struct ac_io_message resp; struct ac_io_kfca_poll_in *pin; - bst_io_read_input(); + bt_io_bst_input_read(); pin = &resp.cmd.kfca_poll_in; @@ -133,7 +133,7 @@ static void kfca_poll(const struct ac_io_message *req) memset(pin, 0, sizeof(*pin)); - pin->gpio_sys = ac_io_u16(bst_io_get_input()); + pin->gpio_sys = ac_io_u16(bt_io_bst_input_get()); ac_io_emu_response_push(kfca_ac_io_emu, &resp, 0); } diff --git a/src/main/bsthook/settings.c b/src/main/bsthook/settings.c index c9fb10a..36cac88 100644 --- a/src/main/bsthook/settings.c +++ b/src/main/bsthook/settings.c @@ -7,7 +7,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "hook/table.h" diff --git a/src/main/bstio/Module.mk b/src/main/bstio/Module.mk index 1e37a61..61288b9 100644 --- a/src/main/bstio/Module.mk +++ b/src/main/bstio/Module.mk @@ -1,7 +1,11 @@ dlls += bstio libs_bstio := \ - geninput \ + module \ + iface-core \ + core \ + iface \ + util \ src_bstio := \ bstio.c \ diff --git a/src/main/bstio/bstio.c b/src/main/bstio/bstio.c index c719074..d3e90b4 100644 --- a/src/main/bstio/bstio.c +++ b/src/main/bstio/bstio.c @@ -1,46 +1,83 @@ +#define LOG_MODULE "bstio" + #include #include #include -#include "bemanitools/bstio.h" -#include "bemanitools/glue.h" -#include "bemanitools/input.h" +#include "api/core/log.h" +#include "api/core/thread.h" -static uint8_t bst_io_gpio_sys; +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface/input.h" -void bst_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) +#include "module/input.h" + +#include "main/module/input-ext.h" +#include "main/module/input.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/input.h" +#include "sdk/module/io/bst.h" + +static module_input_t *_bst_io_module_input; +static uint8_t _bst_io_gpio_sys; + +bool bt_io_bst_init() { - input_set_loggers(misc, info, warning, fatal); + bool result; + bt_input_api_t input_api; + + module_input_ext_load_and_init("geninput.dll", &_bst_io_module_input); + module_input_api_get(_bst_io_module_input, &input_api); + bt_input_api_set(&input_api); + + result = bt_input_init(); + + if (!result) { + return false; + } + + return bt_input_mapper_config_load("bst"); } -bool bst_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +void bt_io_bst_fini() { - input_init(thread_create, thread_join, thread_destroy); - mapper_config_load("bst"); + bt_input_fini(); + + bt_input_api_clear(); + module_input_free(&_bst_io_module_input); +} + +bool bt_io_bst_input_read() +{ + _bst_io_gpio_sys = bt_input_mapper_update(); return true; } -void bst_io_fini(void) +uint8_t bt_io_bst_input_get() { - input_fini(); + return _bst_io_gpio_sys; } -bool bst_io_read_input(void) +void bt_module_core_log_api_set(const bt_core_log_api_t *api) { - bst_io_gpio_sys = mapper_update(); - - return true; + bt_core_log_api_set(api); } -uint8_t bst_io_get_input(void) +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) { - return bst_io_gpio_sys; + bt_core_thread_api_set(api); } + +void bt_module_io_bst_api_get(bt_io_bst_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_bst_init; + api->v1.fini = bt_io_bst_fini; + api->v1.input_read = bt_io_bst_input_read; + api->v1.input_get = bt_io_bst_input_get; +} \ No newline at end of file diff --git a/src/main/bstio/bstio.def b/src/main/bstio/bstio.def index 7c85a5f..0cef03d 100644 --- a/src/main/bstio/bstio.def +++ b/src/main/bstio/bstio.def @@ -1,8 +1,13 @@ LIBRARY bstio EXPORTS - bst_io_fini - bst_io_get_input - bst_io_init - bst_io_read_input - bst_io_set_loggers + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_io_bst_api_get + + ; Direct API + bt_io_bst_init + bt_io_bst_fini + bt_io_bst_input_read + bt_io_bst_input_get diff --git a/src/main/camhook/cam-detect.c b/src/main/camhook/cam-detect.c index cbff8be..ccc4155 100644 --- a/src/main/camhook/cam-detect.c +++ b/src/main/camhook/cam-detect.c @@ -17,8 +17,9 @@ #include "camhook/cam-detect.h" +#include "iface-core/log.h" + #include "util/defs.h" -#include "util/log.h" #include "util/str.h" EXTERN_GUID( diff --git a/src/main/camhook/cam.c b/src/main/camhook/cam.c index ab40dde..a0357f9 100644 --- a/src/main/camhook/cam.c +++ b/src/main/camhook/cam.c @@ -19,11 +19,14 @@ #include "camhook/cam.h" -#include "core/log.h" +#include "iface-core/log.h" #include "hook/com-proxy.h" #include "hook/table.h" +#include "camhook/cam.h" +#include "camhook/cam-detect.h" + #include "util/defs.h" #include "util/str.h" diff --git a/src/main/camhook/config-cam.c b/src/main/camhook/config-cam.c index fc77edd..5be2cd7 100644 --- a/src/main/camhook/config-cam.c +++ b/src/main/camhook/config-cam.c @@ -1,9 +1,9 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" - #include "camhook/config-cam.h" +#include "iface-core/log.h" + #define CAMHOOK_CONFIG_CAM_DISABLE_EMU_KEY "cam.disable_emu" #define CAMHOOK_CONFIG_CAM_DEFAULT_DISABLE_EMU_VALUE false diff --git a/src/main/cconfig/cconfig-main.c b/src/main/cconfig/cconfig-main.c index 342d8df..ce806e6 100644 --- a/src/main/cconfig/cconfig-main.c +++ b/src/main/cconfig/cconfig-main.c @@ -6,7 +6,7 @@ #include "cconfig/cconfig-main.h" -#include "core/log.h" +#include "iface-core/log.h" #include "util/cmdline.h" @@ -85,7 +85,7 @@ bool cconfig_main_config_init( } log_misc("Config state after file loading:"); - cconfig_util_log(config, core_log_misc_impl_get()); + cconfig_util_log(config, log_misc_func); } log_misc("Parsing override config parameters from cmd"); @@ -97,7 +97,7 @@ bool cconfig_main_config_init( } log_misc("Config state after cmd parameter overrides:"); - cconfig_util_log(config, core_log_misc_impl_get()); + cconfig_util_log(config, log_misc_func); goto success; diff --git a/src/main/cconfig/cconfig-util.c b/src/main/cconfig/cconfig-util.c index 3585357..4f243cf 100644 --- a/src/main/cconfig/cconfig-util.c +++ b/src/main/cconfig/cconfig-util.c @@ -5,7 +5,7 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "util/hex.h" #include "util/mem.h" @@ -221,7 +221,7 @@ void cconfig_util_set_data( free(str); } -void cconfig_util_log(struct cconfig *config, core_log_message_t log_message) +void cconfig_util_log(struct cconfig *config, bt_core_log_message_t log_message) { for (uint32_t i = 0; i < config->nentries; i++) { log_message( diff --git a/src/main/cconfig/cconfig-util.h b/src/main/cconfig/cconfig-util.h index 8f6a305..ef71a69 100644 --- a/src/main/cconfig/cconfig-util.h +++ b/src/main/cconfig/cconfig-util.h @@ -7,7 +7,7 @@ #include "cconfig/cconfig.h" -#include "core/log.h" +#include "iface-core/log.h" bool cconfig_util_get_int( struct cconfig *config, @@ -57,6 +57,7 @@ void cconfig_util_set_data( size_t len, const char *desc); -void cconfig_util_log(struct cconfig *config, core_log_message_t log_message); +void cconfig_util_log( + struct cconfig *config, bt_core_log_message_t log_message); #endif \ No newline at end of file diff --git a/src/main/cconfig/cconfig.c b/src/main/cconfig/cconfig.c index 6150f66..833f4de 100644 --- a/src/main/cconfig/cconfig.c +++ b/src/main/cconfig/cconfig.c @@ -2,7 +2,7 @@ #include "cconfig/cconfig.h" -#include "core/log.h" +#include "iface-core/log.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/cconfig/cmd.c b/src/main/cconfig/cmd.c index 3bb1c24..2a92d92 100644 --- a/src/main/cconfig/cmd.c +++ b/src/main/cconfig/cmd.c @@ -7,7 +7,7 @@ #include "cconfig/cmd.h" -#include "core/log.h" +#include "iface-core/log.h" #include "util/hex.h" #include "util/str.h" diff --git a/src/main/cconfig/conf.c b/src/main/cconfig/conf.c index b23e9d4..9d1c02c 100644 --- a/src/main/cconfig/conf.c +++ b/src/main/cconfig/conf.c @@ -6,7 +6,7 @@ #include "cconfig/conf.h" -#include "core/log.h" +#include "iface-core/log.h" #include "util/fs.h" #include "util/str.h" diff --git a/src/main/config/Module.mk b/src/main/config/Module.mk index fc37a23..e46e97e 100644 --- a/src/main/config/Module.mk +++ b/src/main/config/Module.mk @@ -4,9 +4,13 @@ cppflags_config := -DUNICODE libs_config := \ core \ + iface-io \ + iface \ + module \ eamio \ geninput \ util \ + iface-core \ ldflags_config := \ -lcomctl32 \ diff --git a/src/main/config/analogs.c b/src/main/config/analogs.c index d693667..d75253c 100644 --- a/src/main/config/analogs.c +++ b/src/main/config/analogs.c @@ -11,7 +11,8 @@ #include "config/schema.h" #include "config/usages.h" -#include "core/log.h" +#include "iface-core/log.h" +#include "iface/input.h" #include "geninput/hid-mgr.h" #include "geninput/input-config.h" @@ -168,7 +169,7 @@ static INT_PTR analogs_ui_handle_tick(HWND hwnd) struct analogs_ui *ui; size_t i; - mapper_update(); + bt_input_mapper_update(); ui = (struct analogs_ui *) GetWindowLongPtr(hwnd, GWLP_USERDATA); @@ -363,7 +364,8 @@ static void analog_ui_handle_init_invert(HWND hwnd) ui = (struct analog_ui *) GetWindowLongPtr(hwnd, GWLP_USERDATA); if (mapper_get_analog_invert(ui->def->tag)) { - SendMessage(GetDlgItem(hwnd, IDC_ANALOG_INVERT), BM_SETCHECK, BST_CHECKED, 0); + SendMessage( + GetDlgItem(hwnd, IDC_ANALOG_INVERT), BM_SETCHECK, BST_CHECKED, 0); } } @@ -566,7 +568,7 @@ static INT_PTR analog_ui_handle_tick(HWND hwnd) ui = (struct analog_ui *) GetWindowLongPtr(hwnd, GWLP_USERDATA); pos_ctl = GetDlgItem(hwnd, IDC_POSITION); - ui->pos = mapper_read_analog(ui->def->tag); + ui->pos = bt_input_mapper_analog_read(ui->def->tag); SendMessage(pos_ctl, WM_USER, 0, (LPARAM) ui->pos); diff --git a/src/main/config/buttons.c b/src/main/config/buttons.c index e083bf3..a058fc1 100644 --- a/src/main/config/buttons.c +++ b/src/main/config/buttons.c @@ -15,7 +15,7 @@ #include "config/schema.h" #include "config/usages.h" -#include "core/log.h" +#include "iface-core/log.h" #include "geninput/input-config.h" #include "geninput/mapper.h" diff --git a/src/main/config/eam.c b/src/main/config/eam.c index 1d66518..12b01ea 100644 --- a/src/main/config/eam.c +++ b/src/main/config/eam.c @@ -13,7 +13,9 @@ #include "config/resource.h" #include "config/schema.h" -#include "core/log.h" +#include "iface-core/log.h" +#include "iface-io/eam.h" +#include "iface/input.h" #include "eamio/eam-config.h" @@ -72,13 +74,13 @@ static INT_PTR eam_unit_ui_handle_change_device(HWND hwnd); static INT_PTR eam_unit_ui_handle_tick(HWND hwnd); static INT_PTR eam_unit_ui_handle_fini(HWND hwnd); -static const struct eam_io_config_api *eam_io_config_api; +static const bt_io_eam_config_api_t *eam_io_config_api; HPROPSHEETPAGE eam_ui_tab_create( HINSTANCE inst, const struct schema *schema, - const struct eam_io_config_api *api) + const bt_io_eam_config_api_t *api) { PROPSHEETPAGE psp; @@ -216,7 +218,7 @@ static INT_PTR eam_ui_handle_tick(HWND hwnd) ui = (struct eam_ui *) GetWindowLongPtr(hwnd, GWLP_USERDATA); - mapper_update(); + bt_input_mapper_update(); for (i = 0; i < ui->children.nitems; i++) { child = *array_item(HWND, &ui->children, i); @@ -462,7 +464,7 @@ static INT_PTR eam_unit_ui_handle_tick(HWND hwnd) wchar_t state_str[9]; ui = (struct eam_unit_ui *) GetWindowLongPtr(hwnd, GWLP_USERDATA); - state = eam_io_get_keypad_state(ui->def->unit_no); + state = bt_io_eam_keypad_state_get(ui->def->unit_no); wstr_format(state_str, lengthof(state_str), L"%04x", state); diff --git a/src/main/config/gametype.c b/src/main/config/gametype.c index 2ec0ea4..506484c 100644 --- a/src/main/config/gametype.c +++ b/src/main/config/gametype.c @@ -6,7 +6,7 @@ #include "config/resource.h" #include "config/schema.h" -#include "core/log.h" +#include "iface-core/log.h" #include "util/defs.h" diff --git a/src/main/config/main.c b/src/main/config/main.c index 8be1370..c40dad6 100644 --- a/src/main/config/main.c +++ b/src/main/config/main.c @@ -14,17 +14,25 @@ #include "config/spinner.h" #include "config/usages.h" +#include "core/boot.h" #include "core/log-bt.h" -#include "core/log-sink-debug.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" +#include "core/log-sink-std.h" #include "core/thread-crt.h" -#include "core/thread.h" #include "eamio/eam-config.h" #include "geninput/input-config.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface-io/eam.h" +#include "iface/input.h" + +#include "module/input-ext.h" +#include "module/input.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "util/defs.h" #include "util/str.h" #include "util/winres.h" @@ -37,7 +45,7 @@ HPROPSHEETPAGE eam_ui_tab_create( HINSTANCE inst, const struct schema *schema, - const struct eam_io_config_api *eam_io_config_api); + const bt_io_eam_config_api_t *eam_io_config_api); static void my_fatal(const char *module, const char *fmt, ...) { @@ -54,6 +62,17 @@ static void my_fatal(const char *module, const char *fmt, ...) ExitProcess(-1); } +static void log_api_set() +{ + bt_core_log_api_t api; + + core_log_bt_core_api_get(&api); + + api.v1.fatal = my_fatal; + + bt_core_log_api_set(&api); +} + int main(int argc, char **argv) { INITCOMMONCONTROLSEX iccx; @@ -61,27 +80,37 @@ int main(int argc, char **argv) HPROPSHEETPAGE psp[4]; PROPSHEETHEADER psh; intptr_t result; - const struct eam_io_config_api *eam_io_config_api; + const bt_io_eam_config_api_t *eam_io_config_api; const struct schema *schema; wchar_t text[1024]; int max_light; size_t i; - struct core_log_sink sink; + core_log_sink_t sink; + bt_input_api_t input_api; + module_input_t *module_input; + bt_io_eam_api_t eam_api; + module_io_t *module_io_eam; - inst = GetModuleHandle(NULL); + // TODO turn this into optional parameters, same for log level and output to + // file + AttachConsole(ATTACH_PARENT_PROCESS); + freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); + freopen("CONIN$", "r", stdin); - core_thread_crt_ext_impl_set(); + core_boot("config"); - core_log_impl_set( - core_log_bt_log_misc, - core_log_bt_log_info, - core_log_bt_log_warning, - my_fatal); - - core_log_sink_debug_open(&sink); + core_log_sink_std_err_open(true, &sink); core_log_bt_init(&sink); core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); + core_log_bt_core_api_set(); + + core_thread_crt_core_api_set(); + + log_api_set(); + + inst = GetModuleHandle(NULL); usages_init(inst); @@ -112,18 +141,16 @@ int main(int argc, char **argv) } } - core_log_impl_assign(input_set_loggers); - input_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + module_input_ext_load_and_init("geninput.dll", &module_input); + module_input_api_get(module_input, &input_api); + bt_input_api_set(&input_api); - core_log_impl_assign(eam_io_set_loggers); - eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); - eam_io_config_api = eam_io_get_config_api(); + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", &module_io_eam); + module_io_api_get(module_io_eam, &eam_api); + bt_io_eam_api_set(&eam_api); + + eam_io_config_api = bt_io_eam_config_api_get(); // calculate these and check against the loaded config max_light = -1; @@ -134,11 +161,14 @@ int main(int argc, char **argv) } } - if (!mapper_config_load(schema->name)) { + if (!bt_input_mapper_config_load(schema->name)) { log_info("Initializing empty config for %s", schema->name); + log_info(">>>>1"); mapper_set_nlights((uint8_t) (max_light + 1)); + log_info(">>>>1"); mapper_set_nanalogs((uint8_t) schema->nanalogs); + log_info(">>>>1"); } else { // make sure that these are right @@ -187,10 +217,16 @@ int main(int argc, char **argv) mapper_config_save(schema->name); } - eam_io_fini(); - input_fini(); + bt_io_eam_fini(); + bt_input_fini(); spinner_fini(inst); usages_fini(); + bt_input_api_clear(); + bt_io_eam_api_clear(); + + module_input_free(&module_input); + module_io_free(&module_io_eam); + return EXIT_SUCCESS; } diff --git a/src/main/config/snap.c b/src/main/config/snap.c index 6d8547a..983fd4b 100644 --- a/src/main/config/snap.c +++ b/src/main/config/snap.c @@ -6,10 +6,10 @@ #include "config/snap.h" -#include "core/log.h" - #include "geninput/hid-mgr.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/mem.h" diff --git a/src/main/config/usages.c b/src/main/config/usages.c index 771772c..6d2691f 100644 --- a/src/main/config/usages.c +++ b/src/main/config/usages.c @@ -9,7 +9,7 @@ #include "config/resource.h" -#include "core/log.h" +#include "iface-core/log.h" #include "util/array.h" #include "util/str.h" diff --git a/src/main/core/Module.mk b/src/main/core/Module.mk index bd35e6d..a052b13 100644 --- a/src/main/core/Module.mk +++ b/src/main/core/Module.mk @@ -4,6 +4,8 @@ libs_core := \ util \ src_core := \ + boot.c \ + config-property-node.c \ log-bt-ext.c \ log-bt.c \ log-sink-async.c \ @@ -13,8 +15,12 @@ src_core := \ log-sink-mutex.c \ log-sink-null.c \ log-sink-std.c \ - log.c \ - thread-crt-ext.c \ + property-ext.c \ + property-mxml.c \ + property-mxml.c \ + property-node-ext.c \ + property-node-trace.c \ + property-node.c \ + property-trace.c \ + property.c \ thread-crt.c \ - thread.c \ - diff --git a/src/main/core/boot.c b/src/main/core/boot.c new file mode 100644 index 0000000..a3d789a --- /dev/null +++ b/src/main/core/boot.c @@ -0,0 +1,107 @@ +#define LOG_MODULE "core-boot" + +#include + +#include + +#include "core/property-mxml.h" +#include "core/property-node-mxml.h" +#include "core/thread-crt.h" + +#include "iface-core/log.h" + +#include "util/str.h" + +#define CORE_BOOT_LOG_MODULE_SIZE_MAX 128 +/* 64k so we can log data dumps of rs232 without crashing */ +#define CORE_BOOT_LOG_MSG_SIZE_MAX 65536 + +static void _core_boot_log_std_msg(const char *module, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + + printf("[%s] ", module); + vprintf(fmt, args); + printf("\n"); + + va_end(args); +} + +static void _core_boot_log_debug_msg(const char *module, const char *fmt, ...) +{ + char module_str[CORE_BOOT_LOG_MODULE_SIZE_MAX]; + char msg[CORE_BOOT_LOG_MSG_SIZE_MAX]; + va_list args; + + va_start(args, fmt); + + str_format(module_str, sizeof(module_str), "[%s] ", module); + str_vformat(msg, sizeof(msg), fmt, args); + OutputDebugStringA(module_str); + OutputDebugStringA(msg); + OutputDebugStringA("\n"); + + va_end(args); +} + +static void _core_boot_minimal_logging_std_env_init() +{ + _core_boot_log_std_msg( + LOG_MODULE, "Init minimal logging environment (std)"); + + // Initialize logging directly to avoid a bootstrapping issue + // with not having any kind of logging to bootstrap the full + // featured logging system + _bt_core_log_api.version = 1; + + _bt_core_log_api.v1.misc = _core_boot_log_std_msg; + _bt_core_log_api.v1.info = _core_boot_log_std_msg; + _bt_core_log_api.v1.warning = _core_boot_log_std_msg; + _bt_core_log_api.v1.fatal = _core_boot_log_std_msg; + + log_info("Init minimal logging environment done"); +} + +static void _core_boot_minimal_logging_debug_env_init() +{ + _core_boot_log_debug_msg( + LOG_MODULE, "Init minimal logging environment (debug)"); + + // Initialize logging directly to avoid a bootstrapping issue + // with not having any kind of logging to bootstrap the full + // featured logging system + _bt_core_log_api.version = 1; + + _bt_core_log_api.v1.misc = _core_boot_log_debug_msg; + _bt_core_log_api.v1.info = _core_boot_log_debug_msg; + _bt_core_log_api.v1.warning = _core_boot_log_debug_msg; + _bt_core_log_api.v1.fatal = _core_boot_log_debug_msg; + + log_info("Init minimal logging environment done"); +} + +void core_boot(const char *name) +{ + _core_boot_log_std_msg(LOG_MODULE, "Boot: %s", name); + + _core_boot_minimal_logging_std_env_init(); + + core_thread_crt_core_api_set(); + + core_property_mxml_core_api_set(); + core_property_node_mxml_core_api_set(); +} + +void core_boot_dll(const char *name) +{ + _core_boot_log_debug_msg(LOG_MODULE, "Boot: %s", name); + + _core_boot_minimal_logging_debug_env_init(); + + core_thread_crt_core_api_set(); + + core_property_mxml_core_api_set(); + core_property_node_mxml_core_api_set(); +} \ No newline at end of file diff --git a/src/main/core/boot.h b/src/main/core/boot.h new file mode 100644 index 0000000..908aa73 --- /dev/null +++ b/src/main/core/boot.h @@ -0,0 +1,8 @@ +#ifndef CORE_BOOT_H +#define CORE_BOOT_H + +void core_boot(const char *name); + +void core_boot_dll(const char *name); + +#endif \ No newline at end of file diff --git a/src/main/core/config-property-node.c b/src/main/core/config-property-node.c new file mode 100644 index 0000000..90ba85d --- /dev/null +++ b/src/main/core/config-property-node.c @@ -0,0 +1,346 @@ +#define LOG_MODULE "core-config-property-node" + +#include "api/core/config.h" + +#include "main/core/config-property-node.h" +#include "main/core/property-node.h" +#include "main/core/property.h" + +#include "iface-core/log.h" + +#include "util/mem.h" + +typedef struct core_config_property_node { + const core_property_node_t *node; +} core_config_property_node_t; + +static bt_core_config_result_t +_core_config_property_node_result_map(core_property_node_result_t result) +{ + switch (result) { + case CORE_PROPERTY_NODE_RESULT_SUCCESS: + return BT_CORE_CONFIG_RESULT_SUCCESS; + case CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL: + return BT_CORE_CONFIG_RESULT_ERROR_INTERNAL; + case CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND: + return BT_CORE_CONFIG_RESULT_VALUE_NOT_FOUND; + default: + return BT_CORE_CONFIG_RESULT_ERROR_INTERNAL; + } +} + +static bt_core_config_result_t _core_config_property_node_s8_get( + const bt_core_config_t *config_, const char *path, int8_t *value) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_s8_read(&node, value); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_u8_get( + const bt_core_config_t *config_, const char *path, uint8_t *value) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_u8_read(&node, value); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_s16_get( + const bt_core_config_t *config_, const char *path, int16_t *value) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_s16_read(&node, value); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_u16_get( + const bt_core_config_t *config_, const char *path, uint16_t *value) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_u16_read(&node, value); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_s32_get( + const bt_core_config_t *config_, const char *path, int32_t *value) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_s32_read(&node, value); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_u32_get( + const bt_core_config_t *config_, const char *path, uint32_t *value) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_u32_read(&node, value); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_s64_get( + const bt_core_config_t *config_, const char *path, int64_t *value) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_s64_read(&node, value); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_u64_get( + const bt_core_config_t *config_, const char *path, uint64_t *value) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_u64_read(&node, value); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_float_get( + const bt_core_config_t *config_, const char *path, float *value) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_float_read(&node, value); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_double_get( + const bt_core_config_t *config_, const char *path, double *value) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_double_read(&node, value); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_bool_get( + const bt_core_config_t *config_, const char *path, bool *value) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_bool_read(&node, value); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_bin_get( + const bt_core_config_t *config_, const char *path, void *value, size_t len) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_bin_read(&node, value, len); + + return _core_config_property_node_result_map(result); +} + +static bt_core_config_result_t _core_config_property_node_str_get( + const bt_core_config_t *config_, const char *path, char *value, size_t len) +{ + const core_config_property_node_t *config; + core_property_node_t node; + core_property_node_result_t result; + + config = (const core_config_property_node_t *) config_; + + result = core_property_node_search(config->node, path, &node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return _core_config_property_node_result_map(result); + } + + result = core_property_node_str_read(&node, value, len); + + return _core_config_property_node_result_map(result); +} + +static void _core_config_property_node_core_api_get(bt_core_config_api_t *api) +{ + log_assert(api); + + api->version = 1; + + api->v1.s8_get = _core_config_property_node_s8_get; + api->v1.u8_get = _core_config_property_node_u8_get; + api->v1.s16_get = _core_config_property_node_s16_get; + api->v1.u16_get = _core_config_property_node_u16_get; + api->v1.s32_get = _core_config_property_node_s32_get; + api->v1.u32_get = _core_config_property_node_u32_get; + api->v1.s64_get = _core_config_property_node_s64_get; + api->v1.u64_get = _core_config_property_node_u64_get; + api->v1.float_get = _core_config_property_node_float_get; + api->v1.double_get = _core_config_property_node_double_get; + api->v1.bool_get = _core_config_property_node_bool_get; + api->v1.bin_get = _core_config_property_node_bin_get; + api->v1.str_get = _core_config_property_node_str_get; +} + +void core_config_property_node_core_api_set() +{ + bt_core_config_api_t api; + + _core_config_property_node_core_api_get(&api); + bt_core_config_api_set(&api); +} + +void core_config_property_node_init( + const core_property_node_t *node, bt_core_config_t **config_) +{ + core_config_property_node_t *config; + + log_assert(node); + log_assert(config_); + + config = xmalloc(sizeof(core_config_property_node_t)); + + config->node = node; + + *config_ = (bt_core_config_t *) config; +} + +void core_config_property_node_free(bt_core_config_t **config_) +{ + core_config_property_node_t **config; + + log_assert(config_); + + config = (core_config_property_node_t **) config_; + + free(*config); + *config = NULL; +} \ No newline at end of file diff --git a/src/main/core/config-property-node.h b/src/main/core/config-property-node.h new file mode 100644 index 0000000..843f7bb --- /dev/null +++ b/src/main/core/config-property-node.h @@ -0,0 +1,15 @@ +#ifndef CORE_CONFIG_PROPERTY_NODE_H +#define CORE_CONFIG_PROPERTY_NODE_H + +#include "iface-core/config.h" + +#include "core/property-node.h" + +void core_config_property_node_core_api_set(); + +void core_config_property_node_init( + const core_property_node_t *node, bt_core_config_t **config); + +void core_config_property_node_free(bt_core_config_t **config); + +#endif \ No newline at end of file diff --git a/src/main/core/log-bt-ext.c b/src/main/core/log-bt-ext.c index b1aa4f4..24cab6e 100644 --- a/src/main/core/log-bt-ext.c +++ b/src/main/core/log-bt-ext.c @@ -1,3 +1,5 @@ +#define LOG_MODULE "core-log-bt-ext" + #include #include "core/log-bt.h" @@ -6,20 +8,10 @@ #include "core/log-sink-list.h" #include "core/log-sink-mutex.h" #include "core/log-sink-std.h" -#include "core/log.h" - -void core_log_bt_ext_impl_set() -{ - core_log_impl_set( - core_log_bt_log_misc, - core_log_bt_log_info, - core_log_bt_log_warning, - core_log_bt_log_fatal); -} void core_log_bt_ext_init_with_stdout() { - struct core_log_sink sink; + core_log_sink_t sink; core_log_sink_std_out_open(true, &sink); core_log_bt_init(&sink); @@ -27,7 +19,7 @@ void core_log_bt_ext_init_with_stdout() void core_log_bt_ext_init_with_stderr() { - struct core_log_sink sink; + core_log_sink_t sink; core_log_sink_std_err_open(true, &sink); core_log_bt_init(&sink); @@ -35,7 +27,7 @@ void core_log_bt_ext_init_with_stderr() void core_log_bt_ext_init_with_debug() { - struct core_log_sink sink; + core_log_sink_t sink; core_log_sink_debug_open(&sink); core_log_bt_init(&sink); @@ -44,7 +36,7 @@ void core_log_bt_ext_init_with_debug() void core_log_bt_ext_init_with_file( const char *path, bool append, bool rotate, uint8_t max_rotations) { - struct core_log_sink sink; + core_log_sink_t sink; core_log_sink_file_open(path, append, rotate, max_rotations, &sink); core_log_bt_init(&sink); @@ -53,9 +45,9 @@ void core_log_bt_ext_init_with_file( void core_log_bt_ext_init_with_stdout_and_file( const char *path, bool append, bool rotate, uint8_t max_rotations) { - struct core_log_sink sinks[2]; - struct core_log_sink sink_composed; - struct core_log_sink sink_mutex; + core_log_sink_t sinks[2]; + core_log_sink_t sink_composed; + core_log_sink_t sink_mutex; core_log_sink_std_out_open(true, &sinks[0]); core_log_sink_file_open(path, append, rotate, max_rotations, &sinks[1]); @@ -63,5 +55,21 @@ void core_log_bt_ext_init_with_stdout_and_file( core_log_sink_mutex_open(&sink_composed, &sink_mutex); + core_log_bt_init(&sink_mutex); +} + +void core_log_bt_ext_init_with_stderr_and_file( + const char *path, bool append, bool rotate, uint8_t max_rotations) +{ + core_log_sink_t sinks[2]; + core_log_sink_t sink_composed; + core_log_sink_t sink_mutex; + + core_log_sink_std_err_open(true, &sinks[0]); + core_log_sink_file_open(path, append, rotate, max_rotations, &sinks[1]); + core_log_sink_list_open(sinks, 2, &sink_composed); + + core_log_sink_mutex_open(&sink_composed, &sink_mutex); + core_log_bt_init(&sink_mutex); } \ No newline at end of file diff --git a/src/main/core/log-bt-ext.h b/src/main/core/log-bt-ext.h index dcb9a9a..320c971 100644 --- a/src/main/core/log-bt-ext.h +++ b/src/main/core/log-bt-ext.h @@ -4,12 +4,6 @@ #include #include -/** - * Set the current thread API implementation to use the bemanitools log - * implementation - */ -void core_log_bt_ext_impl_set(); - /** * Helper to setup the bemanitools log implementation with a stdout sink. */ @@ -56,4 +50,7 @@ void core_log_bt_ext_init_with_file( void core_log_bt_ext_init_with_stdout_and_file( const char *path, bool append, bool rotate, uint8_t max_rotations); +void core_log_bt_ext_init_with_stderr_and_file( + const char *path, bool append, bool rotate, uint8_t max_rotations); + #endif \ No newline at end of file diff --git a/src/main/core/log-bt.c b/src/main/core/log-bt.c index fd86897..325abd5 100644 --- a/src/main/core/log-bt.c +++ b/src/main/core/log-bt.c @@ -1,18 +1,25 @@ +#define LOG_MODULE "core-log-bt" + #include #include #include -#include "core/log-bt.h" -#include "core/log-sink.h" -#include "core/log.h" +#include "iface-core/log.h" + +#include "main/core/log-bt.h" +#include "main/core/log-sink.h" #include "util/mem.h" #include "util/str.h" -static enum core_log_bt_log_level _core_log_bt_log_level; -static struct core_log_sink *_core_log_bt_sink; +/* 64k so we can log data dumps of rs232 without crashing */ +#define CORE_LOG_MSG_SIZE_MAX 65536 +#define CORE_LOG_TIMESTAMP_SIZE_MAX 64 -static void _core_log_bt_vformat_write( +static enum core_log_bt_log_level _core_log_bt_log_level; +static core_log_sink_t *_core_log_bt_sink; + +static void _core_log_bt_vformat_timestamp_log_level_write( enum core_log_bt_log_level level, const char *module, const char *fmt, @@ -20,10 +27,9 @@ static void _core_log_bt_vformat_write( { static const char chars[] = "FFWIM"; - char timestamp[64]; - /* 64k so we can log data dumps of rs232 without crashing */ - char msg[65536]; - char line[65536]; + char timestamp[CORE_LOG_TIMESTAMP_SIZE_MAX]; + char msg[CORE_LOG_MSG_SIZE_MAX]; + char line[CORE_LOG_MSG_SIZE_MAX]; int result; time_t curtime; @@ -51,20 +57,106 @@ static void _core_log_bt_vformat_write( _core_log_bt_sink->write(_core_log_bt_sink->ctx, line, result); } -void core_log_bt_init(const struct core_log_sink *sink) +static void _core_log_bt_log_misc(const char *module, const char *fmt, ...) { - if (sink == NULL) { - abort(); - } + va_list args; - _core_log_bt_sink = xmalloc(sizeof(struct core_log_sink)); - memcpy(_core_log_bt_sink, sink, sizeof(struct core_log_sink)); + if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_MISC) { + va_start(args, fmt); + _core_log_bt_vformat_timestamp_log_level_write( + CORE_LOG_BT_LOG_LEVEL_MISC, module, fmt, args); + va_end(args); + } +} + +static void _core_log_bt_log_info(const char *module, const char *fmt, ...) +{ + va_list args; + + if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_INFO) { + va_start(args, fmt); + _core_log_bt_vformat_timestamp_log_level_write( + CORE_LOG_BT_LOG_LEVEL_INFO, module, fmt, args); + va_end(args); + } +} + +static void _core_log_bt_log_warning(const char *module, const char *fmt, ...) +{ + va_list args; + + if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_WARNING) { + va_start(args, fmt); + _core_log_bt_vformat_timestamp_log_level_write( + CORE_LOG_BT_LOG_LEVEL_WARNING, module, fmt, args); + va_end(args); + } +} + +static void _core_log_bt_log_fatal(const char *module, const char *fmt, ...) +{ + va_list args; + + if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_FATAL) { + va_start(args, fmt); + _core_log_bt_vformat_timestamp_log_level_write( + CORE_LOG_BT_LOG_LEVEL_FATAL, module, fmt, args); + va_end(args); + } +} + +void core_log_bt_core_api_get(bt_core_log_api_t *api) +{ + log_assert(api); + + api->version = 1; + + api->v1.misc = _core_log_bt_log_misc; + api->v1.info = _core_log_bt_log_info; + api->v1.warning = _core_log_bt_log_warning; + api->v1.fatal = _core_log_bt_log_fatal; +} + +void core_log_bt_core_api_set() +{ + bt_core_log_api_t api; + + core_log_bt_core_api_get(&api); + bt_core_log_api_set(&api); +} + +void core_log_bt_init(const core_log_sink_t *sink) +{ + log_assert(sink); + + log_misc("Init"); + + _core_log_bt_sink = xmalloc(sizeof(core_log_sink_t)); + memcpy(_core_log_bt_sink, sink, sizeof(core_log_sink_t)); + + _core_log_bt_log_level = CORE_LOG_BT_LOG_LEVEL_OFF; +} + +void core_log_bt_reinit(const core_log_sink_t *sink) +{ + log_assert(_core_log_bt_sink); + + log_misc("Re-init"); + + _core_log_bt_sink->close(_core_log_bt_sink->ctx); + + free(_core_log_bt_sink); + + _core_log_bt_sink = xmalloc(sizeof(core_log_sink_t)); + memcpy(_core_log_bt_sink, sink, sizeof(core_log_sink_t)); _core_log_bt_log_level = CORE_LOG_BT_LOG_LEVEL_OFF; } void core_log_bt_level_set(enum core_log_bt_log_level level) { + log_misc("Log level change from %d to %d", _core_log_bt_log_level, level); + _core_log_bt_log_level = level; } @@ -72,58 +164,14 @@ void core_log_bt_fini() { log_assert(_core_log_bt_sink); + log_misc("Fini"); + _core_log_bt_sink->close(_core_log_bt_sink->ctx); free(_core_log_bt_sink); } -void core_log_bt_log_fatal(const char *module, const char *fmt, ...) -{ - va_list ap; - - if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_FATAL) { - va_start(ap, fmt); - _core_log_bt_vformat_write( - CORE_LOG_BT_LOG_LEVEL_FATAL, module, fmt, ap); - va_end(ap); - } -} - -void core_log_bt_log_warning(const char *module, const char *fmt, ...) -{ - va_list ap; - - if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_WARNING) { - va_start(ap, fmt); - _core_log_bt_vformat_write( - CORE_LOG_BT_LOG_LEVEL_WARNING, module, fmt, ap); - va_end(ap); - } -} - -void core_log_bt_log_info(const char *module, const char *fmt, ...) -{ - va_list ap; - - if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_INFO) { - va_start(ap, fmt); - _core_log_bt_vformat_write(CORE_LOG_BT_LOG_LEVEL_INFO, module, fmt, ap); - va_end(ap); - } -} - -void core_log_bt_log_misc(const char *module, const char *fmt, ...) -{ - va_list ap; - - if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_MISC) { - va_start(ap, fmt); - _core_log_bt_vformat_write(CORE_LOG_BT_LOG_LEVEL_MISC, module, fmt, ap); - va_end(ap); - } -} - void core_log_bt_direct_sink_write(const char *chars, size_t nchars) { _core_log_bt_sink->write(_core_log_bt_sink->ctx, chars, nchars); -} \ No newline at end of file +} diff --git a/src/main/core/log-bt.h b/src/main/core/log-bt.h index 2a8052f..50157d9 100644 --- a/src/main/core/log-bt.h +++ b/src/main/core/log-bt.h @@ -1,7 +1,9 @@ #ifndef CORE_LOG_BT_H #define CORE_LOG_BT_H -#include "core/log-sink.h" +#include "api/core/log.h" + +#include "main/core/log-sink.h" /** * Log API implementation for games/applications without AVS @@ -15,6 +17,12 @@ enum core_log_bt_log_level { CORE_LOG_BT_LOG_LEVEL_MISC = 4, }; +void core_log_bt_core_api_get(bt_core_log_api_t *api); + +// Note: this logger requires a minimal logger to be set-up beforehand +// (log-mini) +void core_log_bt_core_api_set(); + /** * Initialize the logging backend * @@ -28,7 +36,10 @@ enum core_log_bt_log_level { * @param sink Pointer to a log sink implementation. The caller owns the memory * of this. */ -void core_log_bt_init(const struct core_log_sink *sink); +void core_log_bt_init(const core_log_sink_t *sink); + +// special version to use when switching loggers +void core_log_bt_reinit(const core_log_sink_t *sink); /** * Set the current logging level. This can be changed at any given time, e.g. @@ -45,26 +56,6 @@ void core_log_bt_level_set(enum core_log_bt_log_level level); */ void core_log_bt_fini(); -/** - * Implementation of the log API. - */ -void core_log_bt_log_fatal(const char *module, const char *fmt, ...); - -/** - * Implementation of the log API. - */ -void core_log_bt_log_warning(const char *module, const char *fmt, ...); - -/** - * Implementation of the log API. - */ -void core_log_bt_log_info(const char *module, const char *fmt, ...); - -/** - * Implementation of the log API. - */ -void core_log_bt_log_misc(const char *module, const char *fmt, ...); - /** * Allow AVS to by-pass the core log API/engine. * diff --git a/src/main/core/log-sink-async.c b/src/main/core/log-sink-async.c index f327aad..03959b3 100644 --- a/src/main/core/log-sink-async.c +++ b/src/main/core/log-sink-async.c @@ -1,7 +1,11 @@ +#define LOG_MODULE "core-log-sink-async" + #include #include "core/log-sink.h" +#include "iface-core/log.h" + static void _core_log_sink_file_write(void *ctx, const char *chars, size_t nchars) { @@ -13,10 +17,14 @@ static void _core_log_sink_file_close(void *ctx) // TODO } -void core_log_sink_async_open(struct core_log_sink *sink) +void core_log_sink_async_open(core_log_sink_t *sink) { + log_assert(sink); + // TODO + log_misc("Open"); + sink->ctx = NULL; sink->write = _core_log_sink_file_write; sink->close = _core_log_sink_file_close; diff --git a/src/main/core/log-sink-async.h b/src/main/core/log-sink-async.h index 47aa49e..0ec1388 100644 --- a/src/main/core/log-sink-async.h +++ b/src/main/core/log-sink-async.h @@ -14,6 +14,6 @@ * * @param sink Pointer to allocated memory that receives the opened sink */ -void core_log_sink_async_open(struct core_log_sink *sink); +void core_log_sink_async_open(core_log_sink_t *sink); #endif \ No newline at end of file diff --git a/src/main/core/log-sink-debug.c b/src/main/core/log-sink-debug.c index c1dd7a2..54c622b 100644 --- a/src/main/core/log-sink-debug.c +++ b/src/main/core/log-sink-debug.c @@ -1,9 +1,13 @@ +#define LOG_MODULE "core-log-sink-debug" + #include #include #include "core/log-sink.h" +#include "iface-core/log.h" + static void _core_log_sink_debug_write(void *ctx, const char *chars, size_t nchars) { @@ -15,8 +19,12 @@ static void _core_log_sink_debug_close(void *ctx) // noop } -void core_log_sink_debug_open(struct core_log_sink *sink) +void core_log_sink_debug_open(core_log_sink_t *sink) { + log_assert(sink); + + log_misc("Open"); + sink->ctx = NULL; sink->write = _core_log_sink_debug_write; sink->close = _core_log_sink_debug_close; diff --git a/src/main/core/log-sink-debug.h b/src/main/core/log-sink-debug.h index 4c21d50..6b68dfd 100644 --- a/src/main/core/log-sink-debug.h +++ b/src/main/core/log-sink-debug.h @@ -10,6 +10,6 @@ * * @param sink Pointer to allocated memory that receives the opened sink */ -void core_log_sink_debug_open(struct core_log_sink *sink); +void core_log_sink_debug_open(core_log_sink_t *sink); #endif \ No newline at end of file diff --git a/src/main/core/log-sink-file.c b/src/main/core/log-sink-file.c index f2ca188..fb64208 100644 --- a/src/main/core/log-sink-file.c +++ b/src/main/core/log-sink-file.c @@ -1,3 +1,5 @@ +#define LOG_MODULE "core-log-sink-file" + #include #include @@ -7,6 +9,8 @@ #include "core/log-sink.h" +#include "iface-core/log.h" + #include "util/fs.h" #include "util/str.h" @@ -64,10 +68,20 @@ void core_log_sink_file_open( bool append, bool rotate, uint8_t max_rotations, - struct core_log_sink *sink) + core_log_sink_t *sink) { FILE *file; + log_assert(path); + log_assert(sink); + + log_info( + "Open: %s, append %s, rotate %d, max_rotations %d", + path, + append, + rotate, + max_rotations); + if (rotate) { _core_log_sink_file_rotate(path, max_rotations); @@ -82,8 +96,7 @@ void core_log_sink_file_open( } if (!file) { - printf("Cannot open log file: %s", path); - abort(); + log_fatal("Cannot open log file: %s", path); } sink->ctx = (void *) file; diff --git a/src/main/core/log-sink-file.h b/src/main/core/log-sink-file.h index 968a1fe..488fa37 100644 --- a/src/main/core/log-sink-file.h +++ b/src/main/core/log-sink-file.h @@ -23,6 +23,6 @@ void core_log_sink_file_open( bool append, bool rotate, uint8_t max_rotations, - struct core_log_sink *sink); + core_log_sink_t *sink); #endif \ No newline at end of file diff --git a/src/main/core/log-sink-list.c b/src/main/core/log-sink-list.c index 38e3211..2ba560d 100644 --- a/src/main/core/log-sink-list.c +++ b/src/main/core/log-sink-list.c @@ -1,25 +1,29 @@ +#define LOG_MODULE "core-log-sink-list" + #include #include #include "core/log-sink-list.h" #include "core/log-sink.h" +#include "iface-core/log.h" + #include "util/mem.h" #define MAX_SINKS 8 -struct core_log_sink_list { - struct core_log_sink entries[MAX_SINKS]; +typedef struct core_log_sink_list { + core_log_sink_t entries[MAX_SINKS]; uint8_t num; -}; +} core_log_sink_list_t; static void _core_log_sink_list_write(void *ctx, const char *chars, size_t nchars) { - struct core_log_sink_list *sink_list; + core_log_sink_list_t *sink_list; int i; - sink_list = (struct core_log_sink_list *) ctx; + sink_list = (core_log_sink_list_t *) ctx; for (i = 0; i < sink_list->num; i++) { sink_list->entries[i].write(sink_list->entries[i].ctx, chars, nchars); @@ -28,10 +32,10 @@ _core_log_sink_list_write(void *ctx, const char *chars, size_t nchars) static void _core_log_sink_list_close(void *ctx) { - struct core_log_sink_list *sink_list; + core_log_sink_list_t *sink_list; int i; - sink_list = (struct core_log_sink_list *) ctx; + sink_list = (core_log_sink_list_t *) ctx; for (i = 0; i < sink_list->num; i++) { sink_list->entries[i].close(sink_list->entries[i].ctx); @@ -41,16 +45,21 @@ static void _core_log_sink_list_close(void *ctx) } void core_log_sink_list_open( - const struct core_log_sink *entry, uint8_t num, struct core_log_sink *sink) + const core_log_sink_t *entry, uint8_t num, core_log_sink_t *sink) { - struct core_log_sink_list *sink_list; + core_log_sink_list_t *sink_list; int i; + log_assert(entry); + log_assert(sink); + + log_misc("Open: %d", num); + if (num > MAX_SINKS) { abort(); } - sink_list = xmalloc(sizeof(struct core_log_sink_list)); + sink_list = xmalloc(sizeof(core_log_sink_list_t)); for (i = 0; i < num; i++) { sink_list->entries[i].ctx = entry[i].ctx; diff --git a/src/main/core/log-sink-list.h b/src/main/core/log-sink-list.h index f1e99f3..91db79d 100644 --- a/src/main/core/log-sink-list.h +++ b/src/main/core/log-sink-list.h @@ -19,6 +19,6 @@ * @param sink Pointer to allocated memory that receives the opened sink */ void core_log_sink_list_open( - const struct core_log_sink *entry, uint8_t num, struct core_log_sink *sink); + const core_log_sink_t *entry, uint8_t num, core_log_sink_t *sink); #endif \ No newline at end of file diff --git a/src/main/core/log-sink-mutex.c b/src/main/core/log-sink-mutex.c index 13c8b20..b5fa5f6 100644 --- a/src/main/core/log-sink-mutex.c +++ b/src/main/core/log-sink-mutex.c @@ -1,50 +1,59 @@ +#define LOG_MODULE "core-log-sink-mutex" + #include #include #include "core/log-sink.h" +#include "iface-core/log.h" + #include "util/mem.h" -struct core_log_sink_mutex_ctx { - struct core_log_sink *child; +typedef struct core_log_sink_mutex { + core_log_sink_t child; HANDLE mutex; -}; +} core_log_sink_mutex_t; static void _core_log_sink_mutex_write(void *ctx_, const char *chars, size_t nchars) { - struct core_log_sink_mutex_ctx *ctx; + core_log_sink_mutex_t *ctx; - ctx = (struct core_log_sink_mutex_ctx *) ctx_; + ctx = (core_log_sink_mutex_t *) ctx_; WaitForSingleObject(ctx->mutex, INFINITE); - ctx->child->write(ctx->child->ctx, chars, nchars); + ctx->child.write(ctx->child.ctx, chars, nchars); ReleaseMutex(ctx->mutex); } static void _core_log_sink_mutex_close(void *ctx_) { - struct core_log_sink_mutex_ctx *ctx; + core_log_sink_mutex_t *ctx; - ctx = (struct core_log_sink_mutex_ctx *) ctx_; + ctx = (core_log_sink_mutex_t *) ctx_; CloseHandle(ctx->mutex); - ctx->child->close(ctx->child->ctx); + ctx->child.close(ctx->child.ctx); free(ctx); } void core_log_sink_mutex_open( - const struct core_log_sink *child_sink, struct core_log_sink *sink) + const core_log_sink_t *child_sink, core_log_sink_t *sink) { - struct core_log_sink_mutex_ctx *ctx; + core_log_sink_mutex_t *ctx; - ctx = xmalloc(sizeof(struct core_log_sink_mutex_ctx)); + log_assert(child_sink); + log_assert(sink); - memcpy(ctx->child, child_sink, sizeof(struct core_log_sink)); + log_misc("Open"); + + ctx = xmalloc(sizeof(core_log_sink_mutex_t)); + + memcpy(&ctx->child, child_sink, sizeof(core_log_sink_t)); ctx->mutex = CreateMutex(NULL, FALSE, NULL); sink->ctx = ctx; diff --git a/src/main/core/log-sink-mutex.h b/src/main/core/log-sink-mutex.h index e30357e..dadfff0 100644 --- a/src/main/core/log-sink-mutex.h +++ b/src/main/core/log-sink-mutex.h @@ -16,6 +16,6 @@ * @param sink Pointer to allocated memory that receives the opened sink */ void core_log_sink_mutex_open( - const struct core_log_sink *child_sink, struct core_log_sink *sink); + const core_log_sink_t *child_sink, core_log_sink_t *sink); #endif \ No newline at end of file diff --git a/src/main/core/log-sink-null.c b/src/main/core/log-sink-null.c index 7655a20..a02ea80 100644 --- a/src/main/core/log-sink-null.c +++ b/src/main/core/log-sink-null.c @@ -1,7 +1,11 @@ +#define LOG_MODULE "core-log-sink-null" + #include #include "core/log-sink.h" +#include "iface-core/log.h" + static void _core_log_sink_null_write(void *ctx, const char *chars, size_t nchars) { @@ -13,8 +17,12 @@ static void _core_log_sink_null_close(void *ctx) // noop } -void core_log_sink_null_open(struct core_log_sink *sink) +void core_log_sink_null_open(core_log_sink_t *sink) { + log_assert(sink); + + log_misc("Open"); + sink->ctx = NULL; sink->write = _core_log_sink_null_write; sink->close = _core_log_sink_null_close; diff --git a/src/main/core/log-sink-null.h b/src/main/core/log-sink-null.h index ebd2bab..9bb3f37 100644 --- a/src/main/core/log-sink-null.h +++ b/src/main/core/log-sink-null.h @@ -12,6 +12,6 @@ * * @param sink Pointer to allocated memory that receives the opened sink */ -void core_log_sink_null_open(struct core_log_sink *sink); +void core_log_sink_null_open(core_log_sink_t *sink); #endif \ No newline at end of file diff --git a/src/main/core/log-sink-std.c b/src/main/core/log-sink-std.c index 197fd12..4b6bd7f 100644 --- a/src/main/core/log-sink-std.c +++ b/src/main/core/log-sink-std.c @@ -1,15 +1,19 @@ +#define LOG_MODULE "core-log-sink-std" + #include #include #include "core/log-sink.h" +#include "iface-core/log.h" + #include "util/mem.h" -struct core_log_sink_std_ctx { +typedef struct core_log_sink_std { HANDLE handle; bool color; -}; +} core_log_sink_std_t; static char _core_log_sink_std_determine_color(const char *str) { @@ -79,7 +83,7 @@ _core_log_sink_std_write(void *ctx_, const char *chars, size_t nchars) { static const size_t timestamp_len = strlen("[----/--/-- --:--:--]"); - struct core_log_sink_std_ctx *ctx; + core_log_sink_std_t *ctx; char color; size_t color_len; @@ -89,7 +93,7 @@ _core_log_sink_std_write(void *ctx_, const char *chars, size_t nchars) DWORD written; DWORD write_pos; - ctx = (struct core_log_sink_std_ctx *) ctx_; + ctx = (core_log_sink_std_t *) ctx_; if (ctx->color) { write_pos = 0; @@ -155,20 +159,24 @@ _core_log_sink_std_write(void *ctx_, const char *chars, size_t nchars) static void _core_log_sink_std_close(void *ctx_) { - struct core_log_sink_std_ctx *ctx; + core_log_sink_std_t *ctx; - ctx = (struct core_log_sink_std_ctx *) ctx_; + ctx = (core_log_sink_std_t *) ctx_; // Remark: Don't close the ctx->handle, see win API docs free(ctx); } -void core_log_sink_std_out_open(bool color, struct core_log_sink *sink) +void core_log_sink_std_out_open(bool color, core_log_sink_t *sink) { - struct core_log_sink_std_ctx *ctx; + core_log_sink_std_t *ctx; - ctx = xmalloc(sizeof(struct core_log_sink_std_ctx)); + log_assert(sink); + + log_misc("Open stdout"); + + ctx = xmalloc(sizeof(core_log_sink_std_t)); ctx->handle = GetStdHandle(STD_OUTPUT_HANDLE); ctx->color = color; @@ -178,11 +186,15 @@ void core_log_sink_std_out_open(bool color, struct core_log_sink *sink) sink->close = _core_log_sink_std_close; } -void core_log_sink_std_err_open(bool color, struct core_log_sink *sink) +void core_log_sink_std_err_open(bool color, core_log_sink_t *sink) { - struct core_log_sink_std_ctx *ctx; + core_log_sink_std_t *ctx; - ctx = xmalloc(sizeof(struct core_log_sink_std_ctx)); + log_assert(sink); + + log_misc("Open stderr"); + + ctx = xmalloc(sizeof(core_log_sink_std_t)); ctx->handle = GetStdHandle(STD_ERROR_HANDLE); ctx->color = color; diff --git a/src/main/core/log-sink-std.h b/src/main/core/log-sink-std.h index e0e006b..d91bd9f 100644 --- a/src/main/core/log-sink-std.h +++ b/src/main/core/log-sink-std.h @@ -1,6 +1,7 @@ #ifndef CORE_LOG_SINK_STD_H #define CORE_LOG_SINK_STD_H +#include #include #include "core/log-sink.h" @@ -11,7 +12,7 @@ * @param color If true, messages are colored by log level. * @param sink Pointer to allocated memory that receives the opened sink */ -void core_log_sink_std_out_open(bool color, struct core_log_sink *sink); +void core_log_sink_std_out_open(bool color, core_log_sink_t *sink); /** * Create a sink that writes to stderr. @@ -19,6 +20,6 @@ void core_log_sink_std_out_open(bool color, struct core_log_sink *sink); * @param color If true, messages are colored by log level. * @param sink Pointer to allocated memory that receives the opened sink */ -void core_log_sink_std_err_open(bool color, struct core_log_sink *sink); +void core_log_sink_std_err_open(bool color, core_log_sink_t *sink); #endif \ No newline at end of file diff --git a/src/main/core/log-sink.h b/src/main/core/log-sink.h index 7fdd42f..c2dac05 100644 --- a/src/main/core/log-sink.h +++ b/src/main/core/log-sink.h @@ -36,10 +36,10 @@ typedef void (*core_log_sink_close_t)(void *ctx); * to operate, e.g. a file handle, additional buffers etc. Make sure these * resources are cleaned up upon closing the sink. */ -struct core_log_sink { +typedef struct core_log_sink { void *ctx; core_log_sink_write_t write; core_log_sink_close_t close; -}; +} core_log_sink_t; #endif \ No newline at end of file diff --git a/src/main/core/log.c b/src/main/core/log.c deleted file mode 100644 index 9d2d6d7..0000000 --- a/src/main/core/log.c +++ /dev/null @@ -1,74 +0,0 @@ -#include - -#include "core/log.h" - -core_log_message_t _core_log_misc_impl; -core_log_message_t _core_log_info_impl; -core_log_message_t _core_log_warning_impl; -core_log_message_t _core_log_fatal_impl; - -void core_log_impl_set( - core_log_message_t misc, - core_log_message_t info, - core_log_message_t warning, - core_log_message_t fatal) -{ - if (misc == NULL || info == NULL || warning == NULL || fatal == NULL) { - abort(); - } - - _core_log_misc_impl = misc; - _core_log_info_impl = info; - _core_log_warning_impl = warning; - _core_log_fatal_impl = fatal; -} - -void core_log_impl_assign(core_log_impl_set_t impl_set) -{ - if (_core_log_misc_impl == NULL || _core_log_info_impl == NULL || - _core_log_warning_impl == NULL || _core_log_fatal_impl == NULL) { - abort(); - } - - impl_set( - _core_log_misc_impl, - _core_log_info_impl, - _core_log_warning_impl, - _core_log_fatal_impl); -} - -core_log_message_t core_log_misc_impl_get() -{ - if (_core_log_misc_impl == NULL) { - abort(); - } - - return _core_log_misc_impl; -} - -core_log_message_t core_log_info_impl_get() -{ - if (_core_log_info_impl == NULL) { - abort(); - } - - return _core_log_info_impl; -} - -core_log_message_t core_log_warning_impl_get() -{ - if (_core_log_warning_impl == NULL) { - abort(); - } - - return _core_log_warning_impl; -} - -core_log_message_t core_log_fatal_impl_get() -{ - if (_core_log_fatal_impl == NULL) { - abort(); - } - - return _core_log_fatal_impl; -} \ No newline at end of file diff --git a/src/main/core/property-ext.c b/src/main/core/property-ext.c new file mode 100644 index 0000000..0aecf63 --- /dev/null +++ b/src/main/core/property-ext.c @@ -0,0 +1,75 @@ +#define LOG_MODULE "core-property-ext" + +#include "iface-core/log.h" + +#include "main/core/property-node-ext.h" +#include "main/core/property.h" + +core_property_result_t core_property_ext_many_merge( + const core_property_t **properties, + size_t count, + core_property_t **out_property) +{ + core_property_t *merged_property; + core_property_t *tmp; + core_property_result_t result; + core_property_node_result_t result2; + int i; + + log_assert(properties); + log_assert(count > 0); + log_assert(out_property); + + result = core_property_clone(properties[0], &merged_property); + + if (CORE_PROPERTY_RESULT_IS_ERROR(result)) { + return result; + } + + if (count == 1) { + *out_property = merged_property; + return CORE_PROPERTY_RESULT_SUCCESS; + } + + core_property_log(merged_property, log_misc_func); + + for (i = 0; i < count; i++) { + core_property_log(properties[i], log_misc_func); + } + + for (i = 1; i < count; i++) { + result2 = core_property_node_ext_merge_do( + merged_property, properties[i], &tmp); + + core_property_log(tmp, log_misc_func); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result2)) { + core_property_free(&merged_property); + return CORE_PROPERTY_RESULT_ERROR_INTERNAL; + } + + core_property_free(&merged_property); + merged_property = tmp; + } + + *out_property = merged_property; + + return CORE_PROPERTY_RESULT_SUCCESS; +} + +core_property_result_t core_property_ext_merge( + const core_property_t *property_1, + const core_property_t *property_2, + core_property_t **out_property) +{ + const core_property_t *properties[2]; + + log_assert(property_1); + log_assert(property_2); + log_assert(out_property); + + properties[0] = property_1; + properties[1] = property_2; + + return core_property_ext_many_merge(properties, 2, out_property); +} \ No newline at end of file diff --git a/src/main/core/property-ext.h b/src/main/core/property-ext.h new file mode 100644 index 0000000..58936db --- /dev/null +++ b/src/main/core/property-ext.h @@ -0,0 +1,14 @@ +#ifndef CORE_PROPERTY_EXT_H +#define CORE_PROPERTY_EXT_H + +#include "main/core/property.h" + +core_property_result_t core_property_ext_many_merge( + core_property_t **properties, size_t count, core_property_t **out_property); + +core_property_result_t core_property_ext_merge( + const core_property_t *property_1, + const core_property_t *property_2, + core_property_t **out_property); + +#endif diff --git a/src/main/core/property-node-ext.c b/src/main/core/property-node-ext.c new file mode 100644 index 0000000..76b0286 --- /dev/null +++ b/src/main/core/property-node-ext.c @@ -0,0 +1,750 @@ +#define LOG_MODULE "core-property-node-ext" + +#include "iface-core/log.h" + +#include "core/property-node-ext.h" +#include "core/property-node.h" + +#include "util/str.h" + +struct core_property_node_ext_merge_ctx { + const char *path; + const core_property_node_ext_merge_strategies_t *strategies; +}; + +typedef struct core_property_node_ext_merge_ctx + core_property_node_ext_merge_ctx_t; + +static core_property_node_result_t _core_property_node_ext_merge_recursive_do( + core_property_node_t *parent, + const core_property_node_t *source, + void *ctx_) +{ + const core_property_node_ext_merge_ctx_t *ctx; + core_property_node_ext_merge_ctx_t ctx_next; + + char parent_name[CORE_PROPERTY_NODE_NAME_SIZE_MAX]; + char parent_path[CORE_PROPERTY_NODE_PATH_LEN_MAX]; + + core_property_node_result_t result; + bool consumed; + uint8_t i; + + log_assert(parent); + log_assert(source); + log_assert(ctx_); + + ctx = (const core_property_node_ext_merge_ctx_t *) ctx_; + + log_assert(ctx->path); + log_assert(ctx->strategies); + log_assert(ctx->strategies->num > 0); + + result = + core_property_node_name_get(parent, parent_name, sizeof(parent_name)); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + str_cpy(parent_path, sizeof(parent_path), ctx->path); + str_cat(parent_path, sizeof(parent_path), "/"); + str_cat(parent_path, sizeof(parent_path), parent_name); + + ctx_next.path = parent_path; + ctx_next.strategies = ctx->strategies; + + consumed = false; + + // Apply given strategies, one MUST consume + for (i = 0; i < ctx->strategies->num; i++) { + log_assert(ctx->strategies->entry[i].path); + + // path == "" matches everything + if (str_eq(ctx->strategies->entry[i].path, "") || + str_eq(ctx->strategies->entry[i].path, parent_path)) { + + result = ctx->strategies->entry[i].merge_strategy_do( + parent, + source, + &ctx_next, + &consumed, + _core_property_node_ext_merge_recursive_do); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + log_misc( + "Merge strategy for '%s' consumed: %d", + ctx->strategies->entry[i].path, + consumed); + + if (consumed) { + break; + } + } + } + + log_assert(consumed); + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +core_property_node_result_t core_property_node_ext_u8_read( + const core_property_node_t *node, const char *name, uint8_t *value) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + log_assert(value); + + result = core_property_node_search(node, name, &tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + return core_property_node_u8_read(&tmp, value); +} + +core_property_node_result_t core_property_node_ext_u16_read( + const core_property_node_t *node, const char *name, uint16_t *value) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + log_assert(value); + + result = core_property_node_search(node, name, &tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + return core_property_node_u16_read(&tmp, value); +} + +core_property_node_result_t core_property_node_ext_u32_read( + const core_property_node_t *node, const char *name, uint32_t *value) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + log_assert(value); + + result = core_property_node_search(node, name, &tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + return core_property_node_u32_read(&tmp, value); +} + +core_property_node_result_t core_property_node_ext_bool_read( + const core_property_node_t *node, const char *name, bool *value) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + log_assert(value); + + result = core_property_node_search(node, name, &tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + return core_property_node_bool_read(&tmp, value); +} + +core_property_node_result_t core_property_node_ext_str_read( + const core_property_node_t *node, const char *name, char *value, size_t len) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + log_assert(value); + log_assert(len > 0); + + result = core_property_node_search(node, name, &tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + return core_property_node_str_read(&tmp, value, len); +} + +core_property_node_result_t core_property_node_ext_attr_read( + const core_property_node_t *node, const char *name, char *value, size_t len) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + log_assert(value); + log_assert(len > 0); + + result = core_property_node_search(node, name, &tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + return core_property_node_attr_read(&tmp, value, len); +} + +core_property_node_result_t core_property_node_ext_u8_read_or_default( + const core_property_node_t *node, + const char *name, + uint8_t *value, + uint8_t _default) +{ + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + log_assert(value); + + result = core_property_node_ext_u8_read(node, name, value); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + *value = _default; + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; + } else { + return result; + } +} + +core_property_node_result_t core_property_node_ext_u16_read_or_default( + const core_property_node_t *node, + const char *name, + uint16_t *value, + uint16_t _default) +{ + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + log_assert(value); + + result = core_property_node_ext_u16_read(node, name, value); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + *value = _default; + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; + } else { + return result; + } +} + +core_property_node_result_t core_property_node_ext_u32_read_or_default( + const core_property_node_t *node, + const char *name, + uint32_t *value, + uint32_t _default) +{ + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + log_assert(value); + + result = core_property_node_ext_u32_read(node, name, value); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + *value = _default; + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; + } else { + return result; + } +} + +core_property_node_result_t core_property_node_ext_bool_read_or_default( + const core_property_node_t *node, + const char *name, + bool *value, + bool _default) +{ + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + log_assert(value); + + result = core_property_node_ext_bool_read(node, name, value); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + *value = _default; + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; + } else { + return result; + } +} + +core_property_node_result_t core_property_node_ext_str_read_or_default( + const core_property_node_t *node, + const char *name, + char *value, + size_t len, + const char *_default) +{ + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + log_assert(value); + log_assert(len > 0); + log_assert(_default); + + result = core_property_node_ext_str_read(node, name, value, len); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + str_cpy(value, len, _default); + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; + } else { + return result; + } +} + +core_property_node_result_t core_property_node_ext_u8_replace( + core_property_node_t *node, const char *name, uint8_t val) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + + result = core_property_node_search(node, name, &tmp); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + result = core_property_node_remove(&tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + } + + return core_property_node_u8_create(node, name, val, NULL); +} + +core_property_node_result_t core_property_node_ext_u16_replace( + core_property_node_t *node, const char *name, uint16_t val) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + + result = core_property_node_search(node, name, &tmp); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + result = core_property_node_remove(&tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + } + + return core_property_node_u16_create(node, name, val, NULL); +} + +core_property_node_result_t core_property_node_ext_u32_replace( + core_property_node_t *node, const char *name, uint32_t val) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + + result = core_property_node_search(node, name, &tmp); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + result = core_property_node_remove(&tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + } + + return core_property_node_u32_create(node, name, val, NULL); +} + +core_property_node_result_t core_property_node_ext_str_replace( + core_property_node_t *node, const char *name, const char *val) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + + result = core_property_node_search(node, name, &tmp); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + result = core_property_node_remove(&tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + } + + return core_property_node_str_create(node, name, val, NULL); +} + +core_property_node_result_t core_property_node_ext_bool_replace( + core_property_node_t *node, const char *name, bool val) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + + result = core_property_node_search(node, name, &tmp); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + result = core_property_node_remove(&tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + } + + return core_property_node_bool_create(node, name, val, NULL); +} + +core_property_node_result_t core_property_node_ext_attr_replace( + core_property_node_t *node, const char *name, const char *val) +{ + core_property_node_t tmp; + core_property_node_result_t result; + + log_assert(node); + log_assert(name); + + result = core_property_node_search(node, name, &tmp); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + result = core_property_node_remove(&tmp); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + } + + return core_property_node_attr_create(node, name, val, NULL); +} + +core_property_node_result_t core_property_node_ext_extract( + const core_property_node_t *node, core_property_t **out_property) +{ + size_t size; + core_property_node_result_t result; + core_property_t *property; + core_property_result_t property_result; + + log_assert(node); + log_assert(out_property); + + result = core_property_node_size(node, &size); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + return result; + } + + property_result = core_property_create(size, &property); + + if (CORE_PROPERTY_RESULT_IS_ERROR(property_result)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + result = core_property_other_node_insert(property, node); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + core_property_free(&property); + + return result; + } + + *out_property = property; + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +core_property_node_result_t core_property_node_ext_merge_do( + const core_property_t *parent, + const core_property_t *source, + core_property_t **out_property) +{ + core_property_node_ext_merge_strategies_t strategies; + + log_assert(parent); + log_assert(source); + log_assert(out_property); + + strategies.num = 1; + + strategies.entry[0].path = ""; + strategies.entry[0].merge_strategy_do = + core_property_node_ext_merge_strategy_default_do; + + return core_property_node_ext_merge_with_strategies_do( + parent, source, &strategies, out_property); +} + +core_property_node_result_t core_property_node_ext_merge_with_strategies_do( + const core_property_t *parent, + const core_property_t *source, + const core_property_node_ext_merge_strategies_t *strategies, + core_property_t **merged) +{ + size_t size; + size_t total_size; + core_property_result_t property_result; + core_property_node_result_t property_node_result; + core_property_t *merged_property; + core_property_node_t parent_node; + core_property_node_t merged_node; + core_property_node_t source_node; + core_property_node_ext_merge_ctx_t ctx; + + log_assert(parent); + log_assert(source); + log_assert(strategies); + + // We can't estimate how these two are being merged as in how much new + // data is being inserted from source into parent. Therefore, worse-case + // estimate memory requirement for no overlap + total_size = 0; + + property_result = core_property_size(parent, &size); + + if (CORE_PROPERTY_RESULT_IS_ERROR(property_result)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + total_size += size; + + property_result = core_property_size(source, &size); + + if (CORE_PROPERTY_RESULT_IS_ERROR(property_result)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + total_size += size; + + property_result = core_property_create(total_size, &merged_property); + + if (CORE_PROPERTY_RESULT_IS_ERROR(property_result)) { + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + property_result = core_property_root_node_get(parent, &parent_node); + + if (CORE_PROPERTY_RESULT_IS_ERROR(property_result)) { + core_property_free(&merged_property); + + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + property_result = + core_property_other_node_insert(merged_property, &parent_node); + + if (CORE_PROPERTY_RESULT_IS_ERROR(property_result)) { + core_property_free(&merged_property); + + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + property_result = + core_property_root_node_get(merged_property, &merged_node); + + if (CORE_PROPERTY_RESULT_IS_ERROR(property_result)) { + core_property_free(&merged_property); + + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + property_result = core_property_root_node_get(source, &source_node); + + if (CORE_PROPERTY_RESULT_IS_ERROR(property_result)) { + core_property_free(&merged_property); + + return CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL; + } + + core_property_node_log(&merged_node, log_misc_func); + core_property_node_log(&source_node, log_misc_func); + + ctx.path = ""; + ctx.strategies = strategies; + + property_node_result = _core_property_node_ext_merge_recursive_do( + &merged_node, &source_node, &ctx); + + core_property_node_log(&merged_node, log_misc_func); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(property_node_result)) { + core_property_free(&merged_property); + } + + *merged = merged_property; + + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} + +core_property_node_result_t core_property_node_ext_merge_strategy_default_do( + core_property_node_t *parent, + const core_property_node_t *source, + void *ctx, + bool *consumed, + core_property_node_ext_merge_recursion_do_t node_merge_recursion_do) +{ + core_property_node_t tmp; + core_property_node_t source_child; + core_property_node_result_t result; + char source_child_name[CORE_PROPERTY_NODE_NAME_SIZE_MAX]; + core_property_node_t parent_child; + core_property_node_t source_child_child; + + log_assert(parent); + log_assert(source); + log_assert(consumed); + + result = core_property_node_child_get(source, &source_child); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + *consumed = true; + return CORE_PROPERTY_NODE_RESULT_SUCCESS; + } + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + *consumed = false; + return result; + } + + while (true) { + result = core_property_node_name_get( + &source_child, source_child_name, sizeof(source_child_name)); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + *consumed = false; + return result; + } + + result = + core_property_node_search(parent, source_child_name, &parent_child); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + // Could not find an identical child on parent, copy entire source + // to parent + result = core_property_node_copy(parent, &source_child); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + *consumed = false; + return result; + } + } else if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + *consumed = false; + return result; + } else { + // Go deeper, more levels to traverse + result = core_property_node_child_get( + &source_child, &source_child_child); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + // Found identical leaf node, remove the matching parent's child + // and copy the source child over to the parent and terminate + // the recursion + result = core_property_node_remove(&parent_child); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + *consumed = false; + return result; + } + + result = core_property_node_copy(parent, &source_child); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + *consumed = false; + return result; + } + } else if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + *consumed = false; + return result; + } else { + // Continue recursion if there are actually more children + result = + node_merge_recursion_do(&parent_child, &source_child, ctx); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + *consumed = false; + return result; + } + } + } + + // Iterate siblings on same level + result = core_property_node_next_sibling_get(&source_child, &tmp); + memcpy(&source_child, &tmp, sizeof(core_property_node_t)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + break; + } + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + *consumed = false; + return result; + } + } + + // Default strategy always consumes when successful + *consumed = true; + return CORE_PROPERTY_NODE_RESULT_SUCCESS; +} diff --git a/src/main/core/property-node-ext.h b/src/main/core/property-node-ext.h new file mode 100644 index 0000000..04115c8 --- /dev/null +++ b/src/main/core/property-node-ext.h @@ -0,0 +1,115 @@ +#ifndef CORE_PROPERTY_NODE_EXT_H +#define CORE_PROPERTY_NODE_EXT_H + +#include +#include + +#include "core/property-node.h" + +#define CORE_PROPERTY_NODE_EXT_MAX_NODE_NAME_RESOLVERS 4 + +typedef core_property_node_result_t ( + *core_property_node_ext_merge_recursion_do_t)( + core_property_node_t *parent, + const core_property_node_t *source, + void *ctx); + +typedef core_property_node_result_t ( + *core_property_node_ext_merge_strategy_do_t)( + core_property_node_t *parent, + const core_property_node_t *source, + void *ctx, + bool *consumed, + core_property_node_ext_merge_recursion_do_t node_merge_recursion_do); + +typedef struct core_property_node_ext_merge_strategies { + struct { + const char *path; + core_property_node_ext_merge_strategy_do_t merge_strategy_do; + } entry[CORE_PROPERTY_NODE_EXT_MAX_NODE_NAME_RESOLVERS]; + uint8_t num; +} core_property_node_ext_merge_strategies_t; + +core_property_node_result_t core_property_node_ext_u8_read( + const core_property_node_t *node, const char *name, uint8_t *value); +core_property_node_result_t core_property_node_ext_u16_read( + const core_property_node_t *node, const char *name, uint16_t *value); +core_property_node_result_t core_property_node_ext_u32_read( + const core_property_node_t *node, const char *name, uint32_t *value); +core_property_node_result_t core_property_node_ext_bool_read( + const core_property_node_t *node, const char *name, bool *value); +core_property_node_result_t core_property_node_ext_str_read( + const core_property_node_t *node, + const char *name, + char *value, + size_t len); +core_property_node_result_t core_property_node_ext_attr_read( + const core_property_node_t *node, + const char *name, + char *value, + size_t len); + +core_property_node_result_t core_property_node_ext_u8_read_or_default( + const core_property_node_t *node, + const char *name, + uint8_t *value, + uint8_t _default); +core_property_node_result_t core_property_node_ext_u16_read_or_default( + const core_property_node_t *node, + const char *name, + uint16_t *value, + uint16_t _default); +core_property_node_result_t core_property_node_ext_u32_read_or_default( + const core_property_node_t *node, + const char *name, + uint32_t *value, + uint32_t _default); +core_property_node_result_t core_property_node_ext_bool_read_or_default( + const core_property_node_t *node, + const char *name, + bool *value, + bool _default); +core_property_node_result_t core_property_node_ext_str_read_or_default( + const core_property_node_t *node, + const char *name, + char *value, + size_t len, + const char *_default); + +core_property_node_result_t core_property_node_ext_u8_replace( + core_property_node_t *node, const char *name, uint8_t val); +core_property_node_result_t core_property_node_ext_u16_replace( + core_property_node_t *node, const char *name, uint16_t val); +core_property_node_result_t core_property_node_ext_u32_replace( + core_property_node_t *node, const char *name, uint32_t val); +core_property_node_result_t core_property_node_ext_str_replace( + core_property_node_t *node, const char *name, const char *val); +core_property_node_result_t core_property_node_ext_bool_replace( + core_property_node_t *node, const char *name, bool val); +core_property_node_result_t core_property_node_ext_attr_replace( + core_property_node_t *node, const char *name, const char *val); + +core_property_node_result_t core_property_node_ext_extract( + const core_property_node_t *node, core_property_t **out_property); + +core_property_node_result_t core_property_node_ext_merge_do( + const core_property_t *parent, + const core_property_t *source, + core_property_t **out_property); +// Strategies are applied in order and first consumer terminates +// applying further strategies Typically, you want to include the default +// strategy after your custom strategies for special cases +core_property_node_result_t core_property_node_ext_merge_with_strategies_do( + const core_property_t *parent, + const core_property_t *source, + const core_property_node_ext_merge_strategies_t *strategies, + core_property_t **merged); + +core_property_node_result_t core_property_node_ext_merge_strategy_default_do( + core_property_node_t *parent, + const core_property_node_t *source, + void *ctx, + bool *consumed, + core_property_node_ext_merge_recursion_do_t node_merge_recursion_do); + +#endif \ No newline at end of file diff --git a/src/main/core/property-node-trace.c b/src/main/core/property-node-trace.c new file mode 100644 index 0000000..abb6cdf --- /dev/null +++ b/src/main/core/property-node-trace.c @@ -0,0 +1,877 @@ +#define LOG_MODULE "property-node-trace" + +#include + +#include "core/property-node.h" + +#include "iface-core/log.h" + +static core_property_node_api_t _core_property_node_trace_target_api; + +static void _core_property_node_trace_log( + const core_property_node_t *node, bt_core_log_message_t log_message) +{ + log_misc(">>> log(%p)", node); + + _core_property_node_trace_target_api.v1.log(node, log_message); + + log_misc("<<< log(%p)", node); +} + +static core_property_node_result_t _core_property_node_trace_name_get( + const core_property_node_t *node, char *name, size_t len) +{ + core_property_node_result_t result; + + log_misc(">>> name_get(%p, %p, %d)", node, name, len); + + result = _core_property_node_trace_target_api.v1.name_get(node, name, len); + + log_misc( + "<<< name_get(%p, %s): %s", + node, + name, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t +_core_property_node_trace_size(const core_property_node_t *node, size_t *size) +{ + core_property_node_result_t result; + + log_misc(">>> size(%p)", node); + + result = _core_property_node_trace_target_api.v1.size(node, size); + + log_misc( + "<<< size(%p, %d): %s", + node, + *size, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_search( + const core_property_node_t *node, + const char *path, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc(">>> search(%p, %s, %p)", node, path, node_out); + + result = + _core_property_node_trace_target_api.v1.search(node, path, node_out); + + log_misc( + "<<< search(%p, %s): %s", + node, + path, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_next_result_search( + const core_property_node_t *node, core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc(">>> next_result_search(%p, %p)", node, node_out); + + result = _core_property_node_trace_target_api.v1.next_result_search( + node, node_out); + + log_misc( + "<<< next_result_search(%p): %s", + node, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_child_get( + const core_property_node_t *node, core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc(">>> child_get(%p, %p)", node, node_out); + + result = _core_property_node_trace_target_api.v1.child_get(node, node_out); + + log_misc( + "<<< child_get(%p): %s", + node, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_next_sibling_get( + const core_property_node_t *node, core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc(">>> next_sibling_get(%p, %p)", node, node_out); + + result = _core_property_node_trace_target_api.v1.next_sibling_get( + node, node_out); + + log_misc( + "<<< next_sibling_get(%p): %s", + node, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_void_create( + const core_property_node_t *parent_node, + const char *key, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc(">>> void_create(%p, %s, %p)", parent_node, key, node_out); + + result = _core_property_node_trace_target_api.v1.void_create( + parent_node, key, node_out); + + log_misc( + "<<< void_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_s8_create( + const core_property_node_t *parent_node, + const char *key, + int8_t value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> s8_create(%p, %s, %d, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.s8_create( + parent_node, key, value, node_out); + + log_misc( + "<<< s8_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_u8_create( + const core_property_node_t *parent_node, + const char *key, + uint8_t value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> u8_create(%p, %s, %d, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.u8_create( + parent_node, key, value, node_out); + + log_misc( + "<<< u8_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_s16_create( + const core_property_node_t *parent_node, + const char *key, + int16_t value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> s16_create(%p, %s, %d, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.s16_create( + parent_node, key, value, node_out); + + log_misc( + "<<< s16_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_u16_create( + const core_property_node_t *parent_node, + const char *key, + uint16_t value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> u16_create(%p, %s, %d, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.u16_create( + parent_node, key, value, node_out); + + log_misc( + "<<< u16_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_s32_create( + const core_property_node_t *parent_node, + const char *key, + int32_t value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> s32_create(%p, %s, %d, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.s32_create( + parent_node, key, value, node_out); + + log_misc( + "<<< s32_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_u32_create( + const core_property_node_t *parent_node, + const char *key, + uint32_t value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> u32_create(%p, %s, %d, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.u32_create( + parent_node, key, value, node_out); + + log_misc( + "<<< u32_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_s64_create( + const core_property_node_t *parent_node, + const char *key, + int64_t value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> s64_create(%p, %s, %d, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.s64_create( + parent_node, key, value, node_out); + + log_misc( + "<<< s64_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_u64_create( + const core_property_node_t *parent_node, + const char *key, + uint64_t value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> u64_create(%p, %s, %d, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.u64_create( + parent_node, key, value, node_out); + + log_misc( + "<<< u64_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_bin_create( + const core_property_node_t *parent_node, + const char *key, + void *data, + size_t len, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> bin_create(%p, %s, %p, %d, %p)", + parent_node, + key, + data, + len, + node_out); + + result = _core_property_node_trace_target_api.v1.bin_create( + parent_node, key, data, len, node_out); + + log_misc( + "<<< bin_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_str_create( + const core_property_node_t *parent_node, + const char *key, + const char *value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> str_create(%p, %s, %s, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.str_create( + parent_node, key, value, node_out); + + log_misc( + "<<< str_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_ipv4_create( + const core_property_node_t *parent_node, + const char *key, + uint32_t value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> ipv4_create(%p, %s, %X, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.ipv4_create( + parent_node, key, value, node_out); + + log_misc( + "<<< ipv4_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_float_create( + const core_property_node_t *parent_node, + const char *key, + float value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> float_create(%p, %s, %f, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.float_create( + parent_node, key, value, node_out); + + log_misc( + "<<< float_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_double_create( + const core_property_node_t *parent_node, + const char *key, + double value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> double_create(%p, %s, %f, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.double_create( + parent_node, key, value, node_out); + + log_misc( + "<<< double_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_attr_create( + const core_property_node_t *parent_node, + const char *key, + const char *value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> attr_create(%p, %s, %s, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.attr_create( + parent_node, key, value, node_out); + + log_misc( + "<<< attr_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_bool_create( + const core_property_node_t *parent_node, + const char *key, + bool value, + core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_misc( + ">>> bool_create(%p, %s, %d, %p)", parent_node, key, value, node_out); + + result = _core_property_node_trace_target_api.v1.bool_create( + parent_node, key, value, node_out); + + log_misc( + "<<< bool_create(%p, %s): %s", + parent_node, + key, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_s8_read( + const core_property_node_t *parent_node, int8_t *value) +{ + core_property_node_result_t result; + + log_misc(">>> s8_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.s8_read(parent_node, value); + + log_misc( + "<<< s8_read(%p, %d): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_u8_read( + const core_property_node_t *parent_node, uint8_t *value) +{ + core_property_node_result_t result; + + log_misc(">>> u8_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.u8_read(parent_node, value); + + log_misc( + "<<< u8_read(%p, %d): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_s16_read( + const core_property_node_t *parent_node, int16_t *value) +{ + core_property_node_result_t result; + + log_misc(">>> s16_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.s16_read(parent_node, value); + + log_misc( + "<<< s16_read(%p, %d): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_u16_read( + const core_property_node_t *parent_node, uint16_t *value) +{ + core_property_node_result_t result; + + log_misc(">>> u16_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.u16_read(parent_node, value); + + log_misc( + "<<< u16_read(%p, %d): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_s32_read( + const core_property_node_t *parent_node, int32_t *value) +{ + core_property_node_result_t result; + + log_misc(">>> s32_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.s32_read(parent_node, value); + + log_misc( + "<<< s32_read(%p, %d): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_u32_read( + const core_property_node_t *parent_node, uint32_t *value) +{ + core_property_node_result_t result; + + log_misc(">>> u32_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.u32_read(parent_node, value); + + log_misc( + "<<< u32_read(%p, %d): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_s64_read( + const core_property_node_t *parent_node, int64_t *value) +{ + core_property_node_result_t result; + + log_misc(">>> s64_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.s64_read(parent_node, value); + + log_misc( + "<<< s64_read(%p, %d): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_u64_read( + const core_property_node_t *parent_node, uint64_t *value) +{ + core_property_node_result_t result; + + log_misc(">>> u64_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.u64_read(parent_node, value); + + log_misc( + "<<< u64_read(%p, %d): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_bin_read( + const core_property_node_t *parent_node, void *value, size_t len) +{ + core_property_node_result_t result; + + log_misc(">>> bin_read(%p, %p, %d)", parent_node, value, len); + + result = _core_property_node_trace_target_api.v1.bin_read( + parent_node, value, len); + + log_misc( + "<<< bin_read(%p): %s", + parent_node, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_str_read( + const core_property_node_t *parent_node, char *value, size_t len) +{ + core_property_node_result_t result; + + log_misc(">>> str_read(%p, %p, %d)", parent_node, value, len); + + result = _core_property_node_trace_target_api.v1.str_read( + parent_node, value, len); + + log_misc( + "<<< str_read(%p, %s): %s", + parent_node, + value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_ipv4_read( + const core_property_node_t *parent_node, uint32_t *value) +{ + core_property_node_result_t result; + + log_misc(">>> ipv4_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.ipv4_read(parent_node, value); + + log_misc( + "<<< ipv4_read(%p, %X): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_float_read( + const core_property_node_t *parent_node, float *value) +{ + core_property_node_result_t result; + + log_misc(">>> float_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.float_read(parent_node, value); + + log_misc( + "<<< float_read(%p, %f): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_double_read( + const core_property_node_t *parent_node, double *value) +{ + core_property_node_result_t result; + + log_misc(">>> double_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.double_read(parent_node, value); + + log_misc( + "<<< double_read(%p, %f): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_attr_read( + const core_property_node_t *parent_node, char *value, size_t len) +{ + core_property_node_result_t result; + + log_misc(">>> attr_read(%p, %p, %d)", parent_node, value, len); + + result = _core_property_node_trace_target_api.v1.attr_read( + parent_node, value, len); + + log_misc( + "<<< attr_read(%p, %s): %s", + parent_node, + value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_bool_read( + const core_property_node_t *parent_node, bool *value) +{ + core_property_node_result_t result; + + log_misc(">>> bool_read(%p)", parent_node); + + result = + _core_property_node_trace_target_api.v1.bool_read(parent_node, value); + + log_misc( + "<<< bool_read(%p, %d): %s", + parent_node, + *value, + core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t +_core_property_node_trace_remove(const core_property_node_t *node) +{ + core_property_node_result_t result; + + log_misc(">>> remove(%p)", node); + + result = _core_property_node_trace_target_api.v1.remove(node); + + log_misc( + "<<< remove(%p): %s", node, core_property_node_result_to_str(result)); + + return result; +} + +static core_property_node_result_t _core_property_node_trace_copy( + core_property_node_t *dst_node, const core_property_node_t *src_node) +{ + core_property_node_result_t result; + + log_misc(">>> copy(%p, %p)", dst_node, src_node); + + result = _core_property_node_trace_target_api.v1.copy(dst_node, src_node); + + log_misc( + "<<< copy(%p, %p): %s", + dst_node, + src_node, + core_property_node_result_to_str(result)); + + return result; +} + +void core_property_node_trace_target_api_set( + const core_property_node_api_t *target_api) +{ + log_assert(target_api); + + memcpy( + &_core_property_node_trace_target_api, + target_api, + sizeof(core_property_node_api_t)); +} + +void core_property_node_trace_core_api_get(core_property_node_api_t *api) +{ + log_assert(api); + + api->version = 1; + + api->v1.log = _core_property_node_trace_log; + api->v1.name_get = _core_property_node_trace_name_get; + api->v1.size = _core_property_node_trace_size; + api->v1.search = _core_property_node_trace_search; + api->v1.next_result_search = _core_property_node_trace_next_result_search; + api->v1.child_get = _core_property_node_trace_child_get; + api->v1.next_sibling_get = _core_property_node_trace_next_sibling_get; + api->v1.void_create = _core_property_node_trace_void_create; + api->v1.s8_create = _core_property_node_trace_s8_create; + api->v1.u8_create = _core_property_node_trace_u8_create; + api->v1.s16_create = _core_property_node_trace_s16_create; + api->v1.u16_create = _core_property_node_trace_u16_create; + api->v1.s32_create = _core_property_node_trace_s32_create; + api->v1.u32_create = _core_property_node_trace_u32_create; + api->v1.s64_create = _core_property_node_trace_s64_create; + api->v1.u64_create = _core_property_node_trace_u64_create; + api->v1.bin_create = _core_property_node_trace_bin_create; + api->v1.str_create = _core_property_node_trace_str_create; + api->v1.ipv4_create = _core_property_node_trace_ipv4_create; + api->v1.float_create = _core_property_node_trace_float_create; + api->v1.double_create = _core_property_node_trace_double_create; + api->v1.attr_create = _core_property_node_trace_attr_create; + api->v1.bool_create = _core_property_node_trace_bool_create; + api->v1.s8_read = _core_property_node_trace_s8_read; + api->v1.u8_read = _core_property_node_trace_u8_read; + api->v1.s16_read = _core_property_node_trace_s16_read; + api->v1.u16_read = _core_property_node_trace_u16_read; + api->v1.s32_read = _core_property_node_trace_s32_read; + api->v1.u32_read = _core_property_node_trace_u32_read; + api->v1.s64_read = _core_property_node_trace_s64_read; + api->v1.u64_read = _core_property_node_trace_u64_read; + api->v1.bin_read = _core_property_node_trace_bin_read; + api->v1.str_read = _core_property_node_trace_str_read; + api->v1.ipv4_read = _core_property_node_trace_ipv4_read; + api->v1.float_read = _core_property_node_trace_float_read; + api->v1.double_read = _core_property_node_trace_double_read; + api->v1.attr_read = _core_property_node_trace_attr_read; + api->v1.bool_read = _core_property_node_trace_bool_read; + api->v1.remove = _core_property_node_trace_remove; + api->v1.copy = _core_property_node_trace_copy; +} \ No newline at end of file diff --git a/src/main/core/property-node-trace.h b/src/main/core/property-node-trace.h new file mode 100644 index 0000000..d6a9f36 --- /dev/null +++ b/src/main/core/property-node-trace.h @@ -0,0 +1,11 @@ +#ifndef CORE_PROPERTY_NODE_TRACE_H +#define CORE_PROPERTY_NODE_TRACE_H + +#include "main/core/property-node.h" + +void core_property_node_trace_target_api_set( + const core_property_node_api_t *target_api); + +void core_property_node_trace_core_api_get(core_property_node_api_t *api); + +#endif diff --git a/src/main/core/property-node.c b/src/main/core/property-node.c new file mode 100644 index 0000000..bf53aa7 --- /dev/null +++ b/src/main/core/property-node.c @@ -0,0 +1,605 @@ +#define LOG_MODULE "core-property-node" + +#include + +#include "iface-core/log.h" + +#include "main/core/property-node-trace.h" +#include "main/core/property-node.h" + +#define CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bool _core_property_node_trace_log_enable; +static core_property_node_api_t _core_property_node_api; + +static bool _core_property_node_api_is_valid() +{ + return _core_property_node_api.version > 0; +} + +void core_property_node_trace_log_enable(bool enable) +{ + _core_property_node_trace_log_enable = enable; +} + +void core_property_node_api_set(const core_property_node_api_t *api) +{ + core_property_node_api_t trace_api; + + log_assert(api); + + if (_core_property_node_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.log, log); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.name_get, name_get); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.size, size); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.search, search); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED( + api->v1.next_result_search, next_result_search); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.child_get, child_get); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED( + api->v1.next_sibling_get, next_sibling_get); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.void_create, void_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.s8_create, s8_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.u8_create, u8_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.s16_create, s16_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.u16_create, u16_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.s32_create, s32_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.u32_create, u32_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.s64_create, s64_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.u64_create, u64_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.bin_create, bin_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.str_create, str_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.ipv4_create, ipv4_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED( + api->v1.float_create, float_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED( + api->v1.double_create, double_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.attr_create, attr_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.bool_create, bool_create); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.s8_read, s8_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.u8_read, u8_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.s16_read, s16_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.u16_read, u16_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.s32_read, s32_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.u32_read, u32_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.s64_read, s64_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.u64_read, u64_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.bin_read, bin_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.str_read, str_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.ipv4_read, ipv4_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.float_read, float_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.double_read, double_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.attr_read, attr_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.bool_read, bool_read); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.remove, remove); + CORE_PROPERTY_NODE_ASSERT_IMPLEMENTED(api->v1.copy, copy); + } else { + log_fatal("Unsupported API version: %d", api->version); + } + + if (_core_property_node_trace_log_enable) { + log_info("API trace log enabled"); + + core_property_node_trace_target_api_set(api); + core_property_node_trace_core_api_get(&trace_api); + + memcpy( + &_core_property_node_api, + &trace_api, + sizeof(core_property_node_api_t)); + } else { + memcpy(&_core_property_node_api, api, sizeof(core_property_node_api_t)); + } +} + +void core_property_node_api_get(core_property_node_api_t *api) +{ + log_assert(api); + log_assert(_core_property_node_api_is_valid()); + + memcpy(api, &_core_property_node_api, sizeof(core_property_node_api_t)); +} + +const char *core_property_node_result_to_str(core_property_node_result_t result) +{ + switch (result) { + case CORE_PROPERTY_NODE_RESULT_SUCCESS: + return "Success"; + case CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL: + return "Internal"; + case CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND: + return "Node not found"; + default: + return "Undefined error"; + } +} + +void core_property_node_fatal_on_error(core_property_node_result_t result) +{ + switch (result) { + case CORE_PROPERTY_NODE_RESULT_SUCCESS: + return; + case CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL: + case CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND: + default: + log_fatal( + "Operation on property failed: %s", + core_property_node_result_to_str(result)); + } +} + +void core_property_node_log( + const core_property_node_t *node, bt_core_log_message_t log_message) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(node); + log_assert(log_message); + + _core_property_node_api.v1.log(node, log_message); +} + +core_property_node_result_t core_property_node_name_get( + const core_property_node_t *node, char *name, size_t len) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(node); + log_assert(name); + log_assert(len > 0); + + return _core_property_node_api.v1.name_get(node, name, len); +} + +core_property_node_result_t +core_property_node_size(const core_property_node_t *node, size_t *size) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(node); + log_assert(size); + + return _core_property_node_api.v1.size(node, size); +} + +core_property_node_result_t core_property_node_search( + const core_property_node_t *node, + const char *path, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(node); + log_assert(path); + log_assert(node_out); + + return _core_property_node_api.v1.search(node, path, node_out); +} + +core_property_node_result_t core_property_node_next_result_search( + const core_property_node_t *node, core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(node); + log_assert(node_out); + + return _core_property_node_api.v1.next_result_search(node, node_out); +} + +core_property_node_result_t core_property_node_child_get( + const core_property_node_t *node, core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(node); + log_assert(node_out); + + return _core_property_node_api.v1.child_get(node, node_out); +} + +core_property_node_result_t core_property_node_next_sibling_get( + const core_property_node_t *node, core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(node); + log_assert(node_out); + + return _core_property_node_api.v1.next_sibling_get(node, node_out); +} + +core_property_node_result_t core_property_node_void_create( + const core_property_node_t *parent_node, + const char *key, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.void_create(parent_node, key, node_out); +} + +core_property_node_result_t core_property_node_s8_create( + const core_property_node_t *parent_node, + const char *key, + int8_t value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.s8_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_u8_create( + const core_property_node_t *parent_node, + const char *key, + uint8_t value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.u8_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_s16_create( + const core_property_node_t *parent_node, + const char *key, + int16_t value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.s16_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_u16_create( + const core_property_node_t *parent_node, + const char *key, + uint16_t value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.u16_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_s32_create( + const core_property_node_t *parent_node, + const char *key, + int32_t value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.s32_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_u32_create( + const core_property_node_t *parent_node, + const char *key, + uint32_t value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.u32_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_s64_create( + const core_property_node_t *parent_node, + const char *key, + int64_t value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.s64_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_u64_create( + const core_property_node_t *parent_node, + const char *key, + uint64_t value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.u64_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_bin_create( + const core_property_node_t *parent_node, + const char *key, + void *data, + size_t len, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + log_assert(data); + + return _core_property_node_api.v1.bin_create( + parent_node, key, data, len, node_out); +} + +core_property_node_result_t core_property_node_str_create( + const core_property_node_t *parent_node, + const char *key, + const char *value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + log_assert(value); + + return _core_property_node_api.v1.str_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_ipv4_create( + const core_property_node_t *parent_node, + const char *key, + uint32_t value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.ipv4_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_float_create( + const core_property_node_t *parent_node, + const char *key, + float value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.float_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_double_create( + const core_property_node_t *parent_node, + const char *key, + double value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.double_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_attr_create( + const core_property_node_t *parent_node, + const char *key, + const char *value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + log_assert(value); + + return _core_property_node_api.v1.attr_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_bool_create( + const core_property_node_t *parent_node, + const char *key, + bool value, + core_property_node_t *node_out) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(key); + + return _core_property_node_api.v1.bool_create( + parent_node, key, value, node_out); +} + +core_property_node_result_t core_property_node_s8_read( + const core_property_node_t *parent_node, int8_t *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.s8_read(parent_node, value); +} + +core_property_node_result_t core_property_node_u8_read( + const core_property_node_t *parent_node, uint8_t *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.u8_read(parent_node, value); +} + +core_property_node_result_t core_property_node_s16_read( + const core_property_node_t *parent_node, int16_t *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.s16_read(parent_node, value); +} + +core_property_node_result_t core_property_node_u16_read( + const core_property_node_t *parent_node, uint16_t *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.u16_read(parent_node, value); +} + +core_property_node_result_t core_property_node_s32_read( + const core_property_node_t *parent_node, int32_t *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.s32_read(parent_node, value); +} + +core_property_node_result_t core_property_node_u32_read( + const core_property_node_t *parent_node, uint32_t *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.u32_read(parent_node, value); +} + +core_property_node_result_t core_property_node_s64_read( + const core_property_node_t *parent_node, int64_t *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.s64_read(parent_node, value); +} + +core_property_node_result_t core_property_node_u64_read( + const core_property_node_t *parent_node, uint64_t *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.u64_read(parent_node, value); +} + +core_property_node_result_t core_property_node_bin_read( + const core_property_node_t *parent_node, void *value, size_t len) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.bin_read(parent_node, value, len); +} + +core_property_node_result_t core_property_node_str_read( + const core_property_node_t *parent_node, char *value, size_t len) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.str_read(parent_node, value, len); +} + +core_property_node_result_t core_property_node_ipv4_read( + const core_property_node_t *parent_node, uint32_t *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.ipv4_read(parent_node, value); +} + +core_property_node_result_t core_property_node_float_read( + const core_property_node_t *parent_node, float *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.float_read(parent_node, value); +} + +core_property_node_result_t core_property_node_double_read( + const core_property_node_t *parent_node, double *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.double_read(parent_node, value); +} + +core_property_node_result_t core_property_node_attr_read( + const core_property_node_t *parent_node, char *value, size_t len) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.attr_read(parent_node, value, len); +} + +core_property_node_result_t core_property_node_bool_read( + const core_property_node_t *parent_node, bool *value) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(parent_node); + log_assert(value); + + return _core_property_node_api.v1.bool_read(parent_node, value); +} + +core_property_node_result_t +core_property_node_remove(const core_property_node_t *node) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(node); + + return _core_property_node_api.v1.remove(node); +} + +core_property_node_result_t core_property_node_copy( + core_property_node_t *dst_node, const core_property_node_t *src_node) +{ + log_assert(_core_property_node_api_is_valid()); + log_assert(dst_node); + log_assert(src_node); + + return _core_property_node_api.v1.copy(dst_node, src_node); +} diff --git a/src/main/core/property-node.h b/src/main/core/property-node.h new file mode 100644 index 0000000..7cceaf3 --- /dev/null +++ b/src/main/core/property-node.h @@ -0,0 +1,347 @@ +#ifndef CORE_PROPERTY_NODE_H +#define CORE_PROPERTY_NODE_H + +#include +#include +#include + +#include "api/core/log.h" + +#include "main/core/property.h" + +#define CORE_PROPERTY_NODE_RESULT_IS_ERROR(x) \ + (x > CORE_PROPERTY_NODE_RESULT_SUCCESS) +// Based on actual AVS impl max size +#define CORE_PROPERTY_NODE_NAME_SIZE_MAX 256 +// Guestimate, should be enough, I hope? +#define CORE_PROPERTY_NODE_ATTR_NAME_SIZE_MAX 128 +// Guestimate, should be long enough, I hope? +#define CORE_PROPERTY_NODE_PATH_LEN_MAX 4096 + +typedef struct core_property_node core_property_node_t; + +typedef enum core_property_node_result { + CORE_PROPERTY_NODE_RESULT_SUCCESS = 0, + CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL = 1, + CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND = 2, +} core_property_node_result_t; + +typedef void (*core_property_node_log_t)( + const core_property_node_t *node, bt_core_log_message_t log_message); +typedef core_property_node_result_t (*core_property_node_name_get_t)( + const core_property_node_t *node, char *name, size_t len); +typedef core_property_node_result_t (*core_property_node_size_t)( + const core_property_node_t *node, size_t *size); +typedef core_property_node_result_t (*core_property_node_search_t)( + const core_property_node_t *node, + const char *path, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_next_result_search_t)( + const core_property_node_t *node, core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_child_get_t)( + const core_property_node_t *node, core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_next_sibling_get_t)( + const core_property_node_t *node, core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_void_create_t)( + const core_property_node_t *parent_node, + const char *key, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_s8_create_t)( + const core_property_node_t *parent_node, + const char *key, + int8_t value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_u8_create_t)( + const core_property_node_t *parent_node, + const char *key, + uint8_t value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_s16_create_t)( + const core_property_node_t *parent_node, + const char *key, + int16_t value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_u16_create_t)( + const core_property_node_t *parent_node, + const char *key, + uint16_t value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_s32_create_t)( + const core_property_node_t *parent_node, + const char *key, + int32_t value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_u32_create_t)( + const core_property_node_t *parent_node, + const char *key, + uint32_t value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_s64_create_t)( + const core_property_node_t *parent_node, + const char *key, + int64_t value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_u64_create_t)( + const core_property_node_t *parent_node, + const char *key, + uint64_t value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_bin_create_t)( + const core_property_node_t *parent_node, + const char *key, + void *data, + size_t len, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_str_create_t)( + const core_property_node_t *parent_node, + const char *key, + const char *value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_ipv4_create_t)( + const core_property_node_t *parent_node, + const char *key, + uint32_t value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_float_create_t)( + const core_property_node_t *parent_node, + const char *key, + float value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_double_create_t)( + const core_property_node_t *parent_node, + const char *key, + double value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_attr_create_t)( + const core_property_node_t *parent_node, + const char *key, + const char *value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_bool_create_t)( + const core_property_node_t *parent_node, + const char *key, + bool value, + core_property_node_t *node_out); +typedef core_property_node_result_t (*core_property_node_s8_read_t)( + const core_property_node_t *parent_node, int8_t *value); +typedef core_property_node_result_t (*core_property_node_u8_read_t)( + const core_property_node_t *parent_node, uint8_t *value); +typedef core_property_node_result_t (*core_property_node_s16_read_t)( + const core_property_node_t *parent_node, int16_t *value); +typedef core_property_node_result_t (*core_property_node_u16_read_t)( + const core_property_node_t *parent_node, uint16_t *value); +typedef core_property_node_result_t (*core_property_node_s32_read_t)( + const core_property_node_t *parent_node, int32_t *value); +typedef core_property_node_result_t (*core_property_node_u32_read_t)( + const core_property_node_t *parent_node, uint32_t *value); +typedef core_property_node_result_t (*core_property_node_s64_read_t)( + const core_property_node_t *parent_node, int64_t *value); +typedef core_property_node_result_t (*core_property_node_u64_read_t)( + const core_property_node_t *parent_node, uint64_t *value); +typedef core_property_node_result_t (*core_property_node_bin_read_t)( + const core_property_node_t *parent_node, void *value, size_t len); +typedef core_property_node_result_t (*core_property_node_str_read_t)( + const core_property_node_t *parent_node, char *value, size_t len); +typedef core_property_node_result_t (*core_property_node_ipv4_read_t)( + const core_property_node_t *parent_node, uint32_t *value); +typedef core_property_node_result_t (*core_property_node_float_read_t)( + const core_property_node_t *parent_node, float *value); +typedef core_property_node_result_t (*core_property_node_double_read_t)( + const core_property_node_t *parent_node, double *value); +typedef core_property_node_result_t (*core_property_node_attr_read_t)( + const core_property_node_t *parent_node, char *value, size_t len); +typedef core_property_node_result_t (*core_property_node_bool_read_t)( + const core_property_node_t *parent_node, bool *value); +typedef core_property_node_result_t (*core_property_node_remove_t)( + const core_property_node_t *node); +typedef core_property_node_result_t (*core_property_node_copy_t)( + core_property_node_t *dst_node, const core_property_node_t *src_node); + +typedef struct core_property_node_api { + uint16_t version; + + struct { + core_property_node_log_t log; + core_property_node_name_get_t name_get; + core_property_node_size_t size; + core_property_node_search_t search; + core_property_node_next_result_search_t next_result_search; + core_property_node_child_get_t child_get; + core_property_node_next_sibling_get_t next_sibling_get; + core_property_node_void_create_t void_create; + core_property_node_s8_create_t s8_create; + core_property_node_u8_create_t u8_create; + core_property_node_s16_create_t s16_create; + core_property_node_u16_create_t u16_create; + core_property_node_s32_create_t s32_create; + core_property_node_u32_create_t u32_create; + core_property_node_s64_create_t s64_create; + core_property_node_u64_create_t u64_create; + core_property_node_bin_create_t bin_create; + core_property_node_str_create_t str_create; + core_property_node_ipv4_create_t ipv4_create; + core_property_node_float_create_t float_create; + core_property_node_double_create_t double_create; + core_property_node_attr_create_t attr_create; + core_property_node_bool_create_t bool_create; + core_property_node_s8_read_t s8_read; + core_property_node_u8_read_t u8_read; + core_property_node_s16_read_t s16_read; + core_property_node_u16_read_t u16_read; + core_property_node_s32_read_t s32_read; + core_property_node_u32_read_t u32_read; + core_property_node_s64_read_t s64_read; + core_property_node_u64_read_t u64_read; + core_property_node_bin_read_t bin_read; + core_property_node_str_read_t str_read; + core_property_node_ipv4_read_t ipv4_read; + core_property_node_float_read_t float_read; + core_property_node_double_read_t double_read; + core_property_node_attr_read_t attr_read; + core_property_node_bool_read_t bool_read; + core_property_node_remove_t remove; + core_property_node_copy_t copy; + } v1; +} core_property_node_api_t; + +void core_property_node_trace_log_enable(bool enable); +void core_property_node_api_set(const core_property_node_api_t *impl); +void core_property_node_api_get(core_property_node_api_t *impl); + +const char * +core_property_node_result_to_str(core_property_node_result_t result); +void core_property_node_fatal_on_error(core_property_node_result_t result); + +void core_property_node_log( + const core_property_node_t *node, bt_core_log_message_t log_message); +core_property_node_result_t core_property_node_name_get( + const core_property_node_t *node, char *name, size_t len); +core_property_node_result_t +core_property_node_size(const core_property_node_t *node, size_t *size); +core_property_node_result_t core_property_node_search( + const core_property_node_t *node, + const char *path, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_next_result_search( + const core_property_node_t *node, core_property_node_t *node_out); +core_property_node_result_t core_property_node_child_get( + const core_property_node_t *node, core_property_node_t *node_out); +core_property_node_result_t core_property_node_next_sibling_get( + const core_property_node_t *node, core_property_node_t *node_out); +// Doc remark: node_out is optional here +core_property_node_result_t core_property_node_void_create( + const core_property_node_t *parent_node, + const char *key, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_s8_create( + const core_property_node_t *parent_node, + const char *key, + int8_t value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_u8_create( + const core_property_node_t *parent_node, + const char *key, + uint8_t value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_s16_create( + const core_property_node_t *parent_node, + const char *key, + int16_t value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_u16_create( + const core_property_node_t *parent_node, + const char *key, + uint16_t value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_s32_create( + const core_property_node_t *parent_node, + const char *key, + int32_t value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_u32_create( + const core_property_node_t *parent_node, + const char *key, + uint32_t value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_s64_create( + const core_property_node_t *parent_node, + const char *key, + int64_t value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_u64_create( + const core_property_node_t *parent_node, + const char *key, + uint64_t value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_bin_create( + const core_property_node_t *parent_node, + const char *key, + void *data, + size_t len, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_str_create( + const core_property_node_t *parent_node, + const char *key, + const char *value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_ipv4_create( + const core_property_node_t *parent_node, + const char *key, + uint32_t value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_float_create( + const core_property_node_t *parent_node, + const char *key, + float value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_double_create( + const core_property_node_t *parent_node, + const char *key, + double value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_attr_create( + const core_property_node_t *parent_node, + const char *key, + const char *value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_bool_create( + const core_property_node_t *parent_node, + const char *key, + bool value, + core_property_node_t *node_out); +core_property_node_result_t core_property_node_s8_read( + const core_property_node_t *parent_node, int8_t *value); +core_property_node_result_t core_property_node_u8_read( + const core_property_node_t *parent_node, uint8_t *value); +core_property_node_result_t core_property_node_s16_read( + const core_property_node_t *parent_node, int16_t *value); +core_property_node_result_t core_property_node_u16_read( + const core_property_node_t *parent_node, uint16_t *value); +core_property_node_result_t core_property_node_s32_read( + const core_property_node_t *parent_node, int32_t *value); +core_property_node_result_t core_property_node_u32_read( + const core_property_node_t *parent_node, uint32_t *value); +core_property_node_result_t core_property_node_s64_read( + const core_property_node_t *parent_node, int64_t *value); +core_property_node_result_t core_property_node_u64_read( + const core_property_node_t *parent_node, uint64_t *value); +core_property_node_result_t core_property_node_bin_read( + const core_property_node_t *parent_node, void *value, size_t len); +core_property_node_result_t core_property_node_str_read( + const core_property_node_t *parent_node, char *value, size_t len); +core_property_node_result_t core_property_node_ipv4_read( + const core_property_node_t *parent_node, uint32_t *value); +core_property_node_result_t core_property_node_float_read( + const core_property_node_t *parent_node, float *value); +core_property_node_result_t core_property_node_double_read( + const core_property_node_t *parent_node, double *value); +core_property_node_result_t core_property_node_attr_read( + const core_property_node_t *parent_node, char *value, size_t len); +core_property_node_result_t core_property_node_bool_read( + const core_property_node_t *parent_node, bool *value); +core_property_node_result_t +core_property_node_remove(const core_property_node_t *node); +core_property_node_result_t core_property_node_copy( + core_property_node_t *dst_node, const core_property_node_t *src_node); + +#endif \ No newline at end of file diff --git a/src/main/core/property-trace.c b/src/main/core/property-trace.c new file mode 100644 index 0000000..6c358a8 --- /dev/null +++ b/src/main/core/property-trace.c @@ -0,0 +1,183 @@ +#define LOG_MODULE "property-trace" + +#include + +#include "core/property.h" + +#include "iface-core/log.h" + +static core_property_api_t _core_property_trace_target_api; + +static core_property_result_t +_core_property_trace_create(size_t size, core_property_t **property) +{ + core_property_result_t result; + + log_misc(">>> create(%d)", size); + + result = _core_property_trace_target_api.v1.create(size, property); + + log_misc( + "<<< create(%d, %p): %s", + size, + *property, + core_property_result_to_str(result)); + + return result; +} + +static core_property_result_t +_core_property_trace_file_load(const char *path, core_property_t **property) +{ + core_property_result_t result; + + log_misc(">>> file_load(%s)", path); + + result = _core_property_trace_target_api.v1.file_load(path, property); + + log_misc( + "<<< file_load(%s, %p): %s", + path, + *property, + core_property_result_to_str(result)); + + return result; +} + +static core_property_result_t +_core_property_trace_str_load(const char *str, core_property_t **property) +{ + core_property_result_t result; + + log_misc(">>> str_load(%p)", str); + + result = _core_property_trace_target_api.v1.str_load(str, property); + + log_misc( + "<<< str_load(%p, %p): %s", + str, + *property, + core_property_result_to_str(result)); + + return result; +} + +static core_property_result_t +_core_property_trace_size(const core_property_t *property, size_t *size) +{ + core_property_result_t result; + + log_misc(">>> size(%p)", property); + + result = _core_property_trace_target_api.v1.size(property, size); + + log_misc( + "<<< size(%p, %d): %s", + property, + *size, + core_property_result_to_str(result)); + + return result; +} + +static core_property_result_t _core_property_trace_clone( + const core_property_t *property, core_property_t **property_cloned) +{ + core_property_result_t result; + + log_misc(">>> clone(%p)", property); + + result = + _core_property_trace_target_api.v1.clone(property, property_cloned); + + log_misc( + "<<< clone(%p, %p): %s", + property, + *property_cloned, + core_property_result_to_str(result)); + + return result; +} + +static void _core_property_trace_log( + const core_property_t *property, bt_core_log_message_t log_message) +{ + log_misc(">>> log(%p)", property); + + _core_property_trace_target_api.v1.log(property, log_message); + + log_misc("<<< log(%p)", property); +} + +static core_property_result_t _core_property_trace_root_node_get( + const core_property_t *property, core_property_node_t *node) +{ + core_property_result_t result; + + log_misc(">>> root_node_get(%p)", property); + + result = _core_property_trace_target_api.v1.root_node_get(property, node); + + log_misc( + "<<< root_node_get(%p, %p): %s", + property, + node, + core_property_result_to_str(result)); + + return result; +} + +static core_property_result_t _core_property_trace_other_node_insert( + core_property_t *property, const core_property_node_t *node) +{ + core_property_result_t result; + + log_misc(">>> other_node_insert(%p, %p)", property, node); + + result = + _core_property_trace_target_api.v1.other_node_insert(property, node); + + log_misc( + "<<< other_node_insert(%p, %p): %s", + property, + node, + core_property_result_to_str(result)); + + return result; +} + +static void _core_property_trace_free(core_property_t **property) +{ + log_misc(">>> free(%p)", *property); + + _core_property_trace_target_api.v1.free(property); + + log_misc("<<< free(%p)", *property); +} + +void core_property_trace_target_api_set(const core_property_api_t *target_api) +{ + log_assert(target_api); + + memcpy( + &_core_property_trace_target_api, + target_api, + sizeof(core_property_api_t)); +} + +void core_property_trace_core_api_get(core_property_api_t *api) +{ + log_assert(api); + + api->version = 1; + + api->v1.create = _core_property_trace_create; + api->v1.file_load = _core_property_trace_file_load; + api->v1.str_load = _core_property_trace_str_load; + api->v1.size = _core_property_trace_size; + api->v1.clone = _core_property_trace_clone; + api->v1.log = _core_property_trace_log; + api->v1.root_node_get = _core_property_trace_root_node_get; + api->v1.other_node_insert = _core_property_trace_other_node_insert; + api->v1.free = _core_property_trace_free; +} \ No newline at end of file diff --git a/src/main/core/property-trace.h b/src/main/core/property-trace.h new file mode 100644 index 0000000..3ce2bfb --- /dev/null +++ b/src/main/core/property-trace.h @@ -0,0 +1,10 @@ +#ifndef CORE_PROPERTY_TRACE_H +#define CORE_PROPERTY_TRACE_H + +#include "main/core/property.h" + +void core_property_trace_target_api_set(const core_property_api_t *target_api); + +void core_property_trace_core_api_get(core_property_api_t *api); + +#endif diff --git a/src/main/core/property.c b/src/main/core/property.c new file mode 100644 index 0000000..e20e8be --- /dev/null +++ b/src/main/core/property.c @@ -0,0 +1,198 @@ +#define LOG_MODULE "core-property" + +#include + +#include "core/property-trace.h" +#include "core/property.h" + +#include "iface-core/log.h" + +#include "util/defs.h" + +#define CORE_PROPERTY_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bool _core_property_trace_log_enable; +static core_property_api_t _core_property_api; + +static bool _core_property_api_is_valid() +{ + return _core_property_api.version > 0; +} + +void core_property_trace_log_enable(bool enable) +{ + _core_property_trace_log_enable = enable; +} + +void core_property_api_set(const core_property_api_t *api) +{ + core_property_api_t trace_api; + + log_assert(api); + + if (_core_property_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + CORE_PROPERTY_ASSERT_IMPLEMENTED(api->v1.create, create); + CORE_PROPERTY_ASSERT_IMPLEMENTED(api->v1.file_load, file_load); + CORE_PROPERTY_ASSERT_IMPLEMENTED(api->v1.str_load, str_load); + CORE_PROPERTY_ASSERT_IMPLEMENTED(api->v1.size, size); + CORE_PROPERTY_ASSERT_IMPLEMENTED(api->v1.clone, clone); + CORE_PROPERTY_ASSERT_IMPLEMENTED(api->v1.log, log); + CORE_PROPERTY_ASSERT_IMPLEMENTED(api->v1.root_node_get, root_node_get); + CORE_PROPERTY_ASSERT_IMPLEMENTED( + api->v1.other_node_insert, other_node_insert); + CORE_PROPERTY_ASSERT_IMPLEMENTED(api->v1.free, free); + } else { + log_fatal("Unsupported API version: %d", api->version); + } + + if (_core_property_trace_log_enable) { + log_info("API trace log enabled"); + + core_property_trace_target_api_set(api); + core_property_trace_core_api_get(&trace_api); + + memcpy(&_core_property_api, &trace_api, sizeof(core_property_api_t)); + } else { + memcpy(&_core_property_api, api, sizeof(core_property_api_t)); + } +} + +void core_property_api_get(core_property_api_t *api) +{ + log_assert(api); + log_assert(_core_property_api_is_valid()); + + memcpy(api, &_core_property_api, sizeof(core_property_api_t)); +} + +const char *core_property_result_to_str(core_property_result_t result) +{ + switch (result) { + case CORE_PROPERTY_RESULT_SUCCESS: + return "Success"; + case CORE_PROPERTY_RESULT_ERROR_INTERNAL: + return "Internal"; + case CORE_PROPERTY_RESULT_ERROR_ALLOC: + return "Allocating memory"; + case CORE_PROPERTY_RESULT_NOT_FOUND: + return "File or path not found"; + case CORE_PROPERTY_RESULT_ERROR_PERMISSIONS: + return "Permissions"; + case CORE_PROPERTY_RESULT_ERROR_READ: + return "Read error"; + default: + return "Undefined error"; + } +} + +void core_property_fatal_on_error(core_property_result_t result) +{ + switch (result) { + case CORE_PROPERTY_RESULT_SUCCESS: + return; + case CORE_PROPERTY_RESULT_ERROR_INTERNAL: + case CORE_PROPERTY_RESULT_ERROR_ALLOC: + case CORE_PROPERTY_RESULT_NOT_FOUND: + case CORE_PROPERTY_RESULT_ERROR_PERMISSIONS: + case CORE_PROPERTY_RESULT_ERROR_READ: + default: + log_fatal( + "Operation on property failed: %s", + core_property_result_to_str(result)); + } +} + +core_property_result_t +core_property_create(size_t size, core_property_t **property) +{ + log_assert(_core_property_api_is_valid()); + log_assert(size > 0); + log_assert(property); + + return _core_property_api.v1.create(size, property); +} + +core_property_result_t +core_property_file_load(const char *path, core_property_t **property) +{ + log_assert(_core_property_api_is_valid()); + log_assert(path); + log_assert(property); + + return _core_property_api.v1.file_load(path, property); +} + +core_property_result_t +core_property_str_load(const char *str, core_property_t **property) +{ + log_assert(_core_property_api_is_valid()); + log_assert(str); + log_assert(property); + + return _core_property_api.v1.str_load(str, property); +} + +core_property_result_t +core_property_size(const core_property_t *property, size_t *size) +{ + log_assert(_core_property_api_is_valid()); + log_assert(property); + log_assert(size); + + return _core_property_api.v1.size(property, size); +} + +core_property_result_t core_property_clone( + const core_property_t *property, core_property_t **property_cloned) +{ + log_assert(_core_property_api_is_valid()); + log_assert(property); + log_assert(property_cloned); + + return _core_property_api.v1.clone(property, property_cloned); +} + +void core_property_log( + const core_property_t *property, bt_core_log_message_t log_message) +{ + log_assert(_core_property_api_is_valid()); + log_assert(property); + log_assert(log_message); + + _core_property_api.v1.log(property, log_message); +} + +core_property_result_t core_property_root_node_get( + const core_property_t *property, core_property_node_t *node) +{ + log_assert(_core_property_api_is_valid()); + log_assert(property); + log_assert(node); + + return _core_property_api.v1.root_node_get(property, node); +} + +core_property_result_t core_property_other_node_insert( + core_property_t *property, const core_property_node_t *node) +{ + log_assert(_core_property_api_is_valid()); + log_assert(property); + log_assert(node); + + return _core_property_api.v1.other_node_insert(property, node); +} + +void core_property_free(core_property_t **property) +{ + log_assert(_core_property_api_is_valid()); + log_assert(property); + + _core_property_api.v1.free(property); +} diff --git a/src/main/core/property.h b/src/main/core/property.h new file mode 100644 index 0000000..cf88ffd --- /dev/null +++ b/src/main/core/property.h @@ -0,0 +1,91 @@ +#ifndef CORE_PROPERTY_H +#define CORE_PROPERTY_H + +#include +#include +#include + +#include "api/core/log.h" + +#define CORE_PROPERTY_RESULT_IS_ERROR(x) (x > CORE_PROPERTY_RESULT_SUCCESS) + +typedef struct core_property { + // Have size known, but not contents, to allow for stack allocations + void *v1; +} core_property_t; + +typedef struct core_property_node { + // Have size known, but not contents, to allow for stack allocations + void *v1; + void *v2; +} core_property_node_t; + +typedef enum core_property_result { + CORE_PROPERTY_RESULT_SUCCESS = 0, + CORE_PROPERTY_RESULT_ERROR_INTERNAL = 1, + CORE_PROPERTY_RESULT_ERROR_ALLOC = 2, + CORE_PROPERTY_RESULT_NOT_FOUND = 3, + CORE_PROPERTY_RESULT_ERROR_PERMISSIONS = 4, + CORE_PROPERTY_RESULT_ERROR_READ = 5, +} core_property_result_t; + +typedef core_property_result_t (*core_property_create_t)( + size_t size, core_property_t **result); +typedef core_property_result_t (*core_property_file_load_t)( + const char *path, core_property_t **result); +typedef core_property_result_t (*core_property_str_load_t)( + const char *str, core_property_t **result); +typedef core_property_result_t (*core_property_size_t)( + const core_property_t *property, size_t *size); +typedef core_property_result_t (*core_property_clone_t)( + const core_property_t *property, core_property_t **result); +typedef void (*core_property_log_t)( + const core_property_t *property, bt_core_log_message_t log_message); +typedef core_property_result_t (*core_property_root_node_get_t)( + const core_property_t *property, core_property_node_t *result); +typedef core_property_result_t (*core_property_other_node_insert_t)( + core_property_t *property, const core_property_node_t *node); +typedef void (*core_property_free_t)(core_property_t **property); + +typedef struct core_property_api { + uint16_t version; + + struct { + core_property_create_t create; + core_property_file_load_t file_load; + core_property_str_load_t str_load; + core_property_size_t size; + core_property_clone_t clone; + core_property_log_t log; + core_property_root_node_get_t root_node_get; + core_property_other_node_insert_t other_node_insert; + core_property_free_t free; + } v1; +} core_property_api_t; + +void core_property_trace_log_enable(bool enable); +void core_property_api_set(const core_property_api_t *api); +void core_property_api_get(core_property_api_t *api); + +const char *core_property_result_to_str(core_property_result_t result); +void core_property_fatal_on_error(core_property_result_t result); + +core_property_result_t +core_property_create(size_t size, core_property_t **property); +core_property_result_t +core_property_file_load(const char *path, core_property_t **property); +core_property_result_t +core_property_str_load(const char *str, core_property_t **property); +core_property_result_t +core_property_size(const core_property_t *property, size_t *size); +core_property_result_t core_property_clone( + const core_property_t *property, core_property_t **property_cloned); +void core_property_log( + const core_property_t *property, bt_core_log_message_t log_message); +core_property_result_t core_property_root_node_get( + const core_property_t *property, core_property_node_t *node); +core_property_result_t core_property_other_node_insert( + core_property_t *property, const core_property_node_t *node); +void core_property_free(core_property_t **property); + +#endif \ No newline at end of file diff --git a/src/main/core/thread-crt-ext.c b/src/main/core/thread-crt-ext.c deleted file mode 100644 index eb403ad..0000000 --- a/src/main/core/thread-crt-ext.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "core/thread-crt.h" -#include "core/thread.h" - -void core_thread_crt_ext_impl_set() -{ - core_thread_impl_set( - core_thread_crt_create, core_thread_crt_join, core_thread_crt_destroy); -} \ No newline at end of file diff --git a/src/main/core/thread-crt-ext.h b/src/main/core/thread-crt-ext.h deleted file mode 100644 index a17b29b..0000000 --- a/src/main/core/thread-crt-ext.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef CORE_THREAD_CRT_EXT_H -#define CORE_THREAD_CRT_EXT_H - -/** - * Set the current thread API implementation to use the C runtime thread API - */ -void core_thread_crt_ext_impl_set(); - -#endif \ No newline at end of file diff --git a/src/main/core/thread-crt.c b/src/main/core/thread-crt.c index 0251cf1..fc3196f 100644 --- a/src/main/core/thread-crt.c +++ b/src/main/core/thread-crt.c @@ -4,23 +4,29 @@ #include #include +#include "api/core/thread.h" + #include "core/thread-crt.h" -#include "core/thread.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" #include "util/defs.h" -struct shim_ctx { +struct core_thread_crt_shim_ctx { HANDLE barrier; int (*proc)(void *); void *ctx; }; -static unsigned int STDCALL crt_thread_shim(void *outer_ctx) +static unsigned int STDCALL _core_thread_crt_thread_shim(void *outer_ctx) { - struct shim_ctx *sctx = outer_ctx; + struct core_thread_crt_shim_ctx *sctx; int (*proc)(void *); void *inner_ctx; + sctx = outer_ctx; + proc = sctx->proc; inner_ctx = sctx->ctx; @@ -29,34 +35,63 @@ static unsigned int STDCALL crt_thread_shim(void *outer_ctx) return proc(inner_ctx); } -int core_thread_crt_create( - int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority) +static bt_core_thread_result_t _core_thread_crt_create( + int (*proc)(void *), + void *ctx, + uint32_t stack_sz, + unsigned int priority, + bt_core_thread_id_t *thread_id) { - struct shim_ctx sctx; - uintptr_t thread_id; + struct core_thread_crt_shim_ctx sctx; sctx.barrier = CreateEvent(NULL, TRUE, FALSE, NULL); sctx.proc = proc; sctx.ctx = ctx; - thread_id = _beginthreadex(NULL, stack_sz, crt_thread_shim, &sctx, 0, NULL); + *thread_id = _beginthreadex( + NULL, stack_sz, _core_thread_crt_thread_shim, &sctx, 0, NULL); WaitForSingleObject(sctx.barrier, INFINITE); CloseHandle(sctx.barrier); - return (int) thread_id; + return BT_CORE_THREAD_RESULT_SUCCESS; } -void core_thread_crt_destroy(int thread_id) -{ - CloseHandle((HANDLE) (uintptr_t) thread_id); -} - -void core_thread_crt_join(int thread_id, int *result) +static bt_core_thread_result_t +_core_thread_crt_join(bt_core_thread_id_t thread_id, int *result) { WaitForSingleObject((HANDLE) (uintptr_t) thread_id, INFINITE); if (result) { GetExitCodeThread((HANDLE) (uintptr_t) thread_id, (DWORD *) result); } + + return BT_CORE_THREAD_RESULT_SUCCESS; } + +static bt_core_thread_result_t +_core_thread_crt_destroy(bt_core_thread_id_t thread_id) +{ + CloseHandle((HANDLE) (uintptr_t) thread_id); + + return BT_CORE_THREAD_RESULT_SUCCESS; +} + +static void _core_thread_crt_core_api_get(bt_core_thread_api_t *api) +{ + log_assert(api); + + api->version = 1; + + api->v1.create = _core_thread_crt_create; + api->v1.join = _core_thread_crt_join; + api->v1.destroy = _core_thread_crt_destroy; +} + +void core_thread_crt_core_api_set() +{ + bt_core_thread_api_t api; + + _core_thread_crt_core_api_get(&api); + bt_core_thread_api_set(&api); +} \ No newline at end of file diff --git a/src/main/core/thread-crt.h b/src/main/core/thread-crt.h index e9c1e8c..3249940 100644 --- a/src/main/core/thread-crt.h +++ b/src/main/core/thread-crt.h @@ -1,15 +1,8 @@ #ifndef CORE_THREAD_CRT_H #define CORE_THREAD_CRT_H -#include +#include "api/core/thread.h" -/** - * Thread API implementation using the C runtime API - */ - -int core_thread_crt_create( - int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority); -void core_thread_crt_join(int thread_id, int *result); -void core_thread_crt_destroy(int thread_id); +void core_thread_crt_core_api_set(); #endif diff --git a/src/main/core/thread.c b/src/main/core/thread.c deleted file mode 100644 index f4e5bfe..0000000 --- a/src/main/core/thread.c +++ /dev/null @@ -1,78 +0,0 @@ -#include - -#include "core/log.h" -#include "core/thread.h" - -core_thread_create_t core_thread_create_impl; -core_thread_join_t core_thread_join_impl; -core_thread_destroy_t core_thread_destroy_impl; - -int core_thread_create( - int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority) -{ - log_assert(core_thread_create_impl); - - return core_thread_create_impl(proc, ctx, stack_sz, priority); -} - -void core_thread_join(int thread_id, int *result) -{ - log_assert(core_thread_join_impl); - - core_thread_join_impl(thread_id, result); -} - -void core_thread_destroy(int thread_id) -{ - log_assert(core_thread_destroy_impl); - - core_thread_destroy_impl(thread_id); -} - -void core_thread_impl_set( - core_thread_create_t create, - core_thread_join_t join, - core_thread_destroy_t destroy) -{ - if (create == NULL || join == NULL || destroy == NULL) { - abort(); - } - - core_thread_create_impl = create; - core_thread_join_impl = join; - core_thread_destroy_impl = destroy; -} - -void core_thread_impl_assign(core_thread_impl_set_t impl_set) -{ - if (core_thread_create_impl == NULL || core_thread_join_impl == NULL || - core_thread_destroy_impl == NULL) { - abort(); - } - - impl_set( - core_thread_create_impl, - core_thread_join_impl, - core_thread_destroy_impl); -} - -core_thread_create_t core_thread_create_impl_get() -{ - log_assert(core_thread_create_impl); - - return core_thread_create_impl; -} - -core_thread_join_t core_thread_join_impl_get() -{ - log_assert(core_thread_join_impl); - - return core_thread_join_impl; -} - -core_thread_destroy_t core_thread_destroy_impl_get() -{ - log_assert(core_thread_destroy_impl); - - return core_thread_destroy_impl; -} diff --git a/src/main/core/thread.h b/src/main/core/thread.h deleted file mode 100644 index 8811566..0000000 --- a/src/main/core/thread.h +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef CORE_THREAD_H -#define CORE_THREAD_H - -#include - -/** - * The core thread API of bemanitools. - * - * This essentially reflects the AVS threading API and allows for swapping out - * the backends with different implementations. Most games should have some - * version of the AVS API available while some (legacy) games do not. These - * can use a bemanitools private threading implementation by configuring it - * in the bootstrapping process. - */ - -/** - * Create a thread - * - * Always use this interface in your application which hides the currently - * configured implementation. - * - * @param proc The function to run in a separate thread - * @param ctx Additional data to pass to the function as a parameter - * @param stack_sz The stack size to allocate for the thread in bytes - * @param priority The thread's priority - * @return The ID of the thread once created and started - */ -int core_thread_create( - int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority); - -/** - * Wait for a thread to finish - * - * Always use this interface in your application which hides the currently - * configured implementation. - * - * The caller of this function blocks until the thread has finished executing. - * - * @param thread_id ID of the thread to wait for - * @param result Pointer to a variable to write the return value of the function - * the thread executed to - */ -void core_thread_join(int thread_id, int *result); - -/** - * Destroy a thread - * - * Always use this interface in your application which hides the currently - * configured implementation. - * - * The thread must have finished execution before calling this. It is advised - * to make threads terminate their execution flow, join them and destroy. - * - * @param thread_id The ID of the thread to destroy. - */ -void core_thread_destroy(int thread_id); - -typedef int (*core_thread_create_t)( - int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority); -typedef void (*core_thread_join_t)(int thread_id, int *result); -typedef void (*core_thread_destroy_t)(int thread_id); - -typedef void (*core_thread_impl_set_t)( - core_thread_create_t create, - core_thread_join_t join, - core_thread_destroy_t destroy); - -/** - * Configure the thread API implementations - * - * Advised to do this as early in your application/library module as possible - * as calls to the getter functions below will return the currently configured - * implementations. - * - * @param create Pointer to a function implementing thread creation - * @param join Pointer to a function implementing joining of a thread - * @param destroy Pointer to a function implementing destroying of a thread - */ -void core_thread_impl_set( - core_thread_create_t create, - core_thread_join_t join, - core_thread_destroy_t destroy); - -/** - * Supporting function to inject/assign the currently set implementation - * with the given setter function. - * - * @param impl_set Setter function to call with the currently configured thread - * function implementations - */ -void core_thread_impl_assign(core_thread_impl_set_t impl_set); - -/** - * Get the currently configured implementation for thread_create - * - * @return Pointer to the currently configured implementation of the - * thread_create function - */ -core_thread_create_t core_thread_create_impl_get(); - -/** - * Get the currently configured implementation for thread_join - * - * @return Pointer to the currently configured implementation of the thread_join - * function - */ -core_thread_join_t core_thread_join_impl_get(); - -/** - * Get the currently configured implementation for thread_destroy - * - * @return Pointer to the currently configured implementation of the - * thread_destroy function - */ -core_thread_destroy_t core_thread_destroy_impl_get(); - -#endif diff --git a/src/main/d3d9-util/dxerr.c b/src/main/d3d9-util/dxerr.c index fed1c62..301bf2a 100644 --- a/src/main/d3d9-util/dxerr.c +++ b/src/main/d3d9-util/dxerr.c @@ -18,10 +18,7 @@ #ifndef DXERROR #define DXERROR(v, n, d) {v, TEXT(n), TEXT(d)}, -#define DXERRORLAST(v, n, d) \ - { \ - v, TEXT(n), TEXT(d) \ - } +#define DXERRORLAST(v, n, d) {v, TEXT(n), TEXT(d)} #endif #ifndef DXERROR8 #define DXERROR8(v, n, d) diff --git a/src/main/d3d9-util/dxerr9.c b/src/main/d3d9-util/dxerr9.c index 391c9f3..f27e005 100644 --- a/src/main/d3d9-util/dxerr9.c +++ b/src/main/d3d9-util/dxerr9.c @@ -16,8 +16,5 @@ #define DXGetErrorDescription DXGetErrorDescription9A #define DXTrace DXTraceA #define DXERROR9(v, n, d) {v, n, d}, -#define DXERROR9LAST(v, n, d) \ - { \ - v, n, d \ - } +#define DXERROR9LAST(v, n, d) {v, n, d} #include "dxerr.c" diff --git a/src/main/d3d9exhook/config-gfx.c b/src/main/d3d9exhook/config-gfx.c index b4a5197..4a118f7 100644 --- a/src/main/d3d9exhook/config-gfx.c +++ b/src/main/d3d9exhook/config-gfx.c @@ -4,10 +4,10 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" - #include "d3d9exhook/config-gfx.h" +#include "iface-core/log.h" + #define D3D9EXHOOK_CONFIG_GFX_FRAMED_KEY "gfx.framed" #define D3D9EXHOOK_CONFIG_GFX_WINDOWED_KEY "gfx.windowed" #define D3D9EXHOOK_CONFIG_GFX_CONFINED_KEY "gfx.confined" diff --git a/src/main/d3d9exhook/d3d9ex.c b/src/main/d3d9exhook/d3d9ex.c index 80d958c..dc5ba3a 100644 --- a/src/main/d3d9exhook/d3d9ex.c +++ b/src/main/d3d9exhook/d3d9ex.c @@ -9,12 +9,12 @@ #include #include -#include "core/log.h" +#include "d3d9exhook/d3d9ex.h" #include "hook/com-proxy.h" #include "hook/table.h" -#include "d3d9exhook/d3d9ex.h" +#include "iface-core/log.h" #include "util/defs.h" #include "util/str.h" diff --git a/src/main/ddrhook-util/_com4.c b/src/main/ddrhook-util/_com4.c index 4ca08c3..a616eff 100644 --- a/src/main/ddrhook-util/_com4.c +++ b/src/main/ddrhook-util/_com4.c @@ -17,14 +17,13 @@ #include "acioemu/hdxs.h" #include "acioemu/icca.h" -#include "bemanitools/ddrio.h" - -#include "core/log.h" - #include "ddrhook-util/_com4.h" #include "hook/iohook.h" +#include "iface-core/log.h" +#include "iface-io/ddr.h" + #include "p3ioemu/uart.h" #include "util/defs.h" @@ -60,20 +59,24 @@ lights_dispatcher(struct ac_io_emu_hdxs *emu, const struct ac_io_message *req) const struct ac_io_hdxs_output *output = &req->cmd.hdxs_output; uint32_t lights = 0; - lights |= - check_panel_light(output, AC_IO_HDXS_OUT_P1_START, LIGHT_HD_P1_START); lights |= check_panel_light( - output, AC_IO_HDXS_OUT_P1_UP_DOWN, LIGHT_HD_P1_UP_DOWN); + output, AC_IO_HDXS_OUT_P1_START, BT_IO_DDR_HDXS_LIGHT_HD_P1_START); lights |= check_panel_light( - output, AC_IO_HDXS_OUT_P1_LEFT_RIGHT, LIGHT_HD_P1_LEFT_RIGHT); - lights |= - check_panel_light(output, AC_IO_HDXS_OUT_P2_START, LIGHT_HD_P2_START); + output, AC_IO_HDXS_OUT_P1_UP_DOWN, BT_IO_DDR_HDXS_LIGHT_HD_P1_UP_DOWN); lights |= check_panel_light( - output, AC_IO_HDXS_OUT_P2_UP_DOWN, LIGHT_HD_P2_UP_DOWN); + output, + AC_IO_HDXS_OUT_P1_LEFT_RIGHT, + BT_IO_DDR_HDXS_LIGHT_HD_P1_LEFT_RIGHT); lights |= check_panel_light( - output, AC_IO_HDXS_OUT_P2_LEFT_RIGHT, LIGHT_HD_P2_LEFT_RIGHT); + output, AC_IO_HDXS_OUT_P2_START, BT_IO_DDR_HDXS_LIGHT_HD_P2_START); + lights |= check_panel_light( + output, AC_IO_HDXS_OUT_P2_UP_DOWN, BT_IO_DDR_HDXS_LIGHT_HD_P2_UP_DOWN); + lights |= check_panel_light( + output, + AC_IO_HDXS_OUT_P2_LEFT_RIGHT, + BT_IO_DDR_HDXS_LIGHT_HD_P2_LEFT_RIGHT); - ddr_io_set_lights_hdxs_panel(lights); + bt_io_ddr_hdxs_lights_panel_set(lights); for (uint8_t i = 0; i < 4; ++i) { size_t light_idx = i * 3; @@ -86,7 +89,7 @@ lights_dispatcher(struct ac_io_emu_hdxs *emu, const struct ac_io_message *req) uint8_t b = upscale_light(output->lights[light_idx + AC_IO_HDXS_BLUE].analog); - ddr_io_set_lights_hdxs_rgb(i, r, g, b); + bt_io_ddr_hdxs_lights_rgb_set(i, r, g, b); } } diff --git a/src/main/ddrhook-util/dinput.c b/src/main/ddrhook-util/dinput.c index 949fb1e..08ce026 100644 --- a/src/main/ddrhook-util/dinput.c +++ b/src/main/ddrhook-util/dinput.c @@ -5,12 +5,12 @@ #include -#include "core/log.h" - #include "hook/com-proxy.h" #include "hook/pe.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" static HRESULT STDCALL my_DirectInput8Create( diff --git a/src/main/ddrhook-util/extio.c b/src/main/ddrhook-util/extio.c index 661b165..46afd1b 100644 --- a/src/main/ddrhook-util/extio.c +++ b/src/main/ddrhook-util/extio.c @@ -12,12 +12,11 @@ #include #include -#include "bemanitools/ddrio.h" - -#include "core/log.h" - #include "hook/iohook.h" +#include "iface-core/log.h" +#include "iface-io/ddr.h" + #include "util/iobuf.h" #include "util/str.h" @@ -109,7 +108,7 @@ static HRESULT extio_write(struct irp *irp) if (irp->write.nbytes >= sizeof(lights)) { lights_be = (const uint32_t *) irp->write.bytes; lights = _byteswap_ulong(*lights_be); - ddr_io_set_lights_extio(lights); + bt_io_ddr_extio_lights_set(lights); extio_pending = true; } else { diff --git a/src/main/ddrhook-util/gfx.c b/src/main/ddrhook-util/gfx.c index 0bfd0a5..d88523c 100644 --- a/src/main/ddrhook-util/gfx.c +++ b/src/main/ddrhook-util/gfx.c @@ -11,11 +11,11 @@ #include #include -#include "core/log.h" - #include "hook/com-proxy.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "ddrhook-util/gfx.h" #include "util/defs.h" diff --git a/src/main/ddrhook-util/misc.c b/src/main/ddrhook-util/misc.c index e04390d..edf600c 100644 --- a/src/main/ddrhook-util/misc.c +++ b/src/main/ddrhook-util/misc.c @@ -2,13 +2,13 @@ #include -#include "core/log.h" - #include "ddrhook-util/gfx.h" #include "hook/pe.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/str.h" diff --git a/src/main/ddrhook-util/monitor.c b/src/main/ddrhook-util/monitor.c index cba18cc..a68b67c 100644 --- a/src/main/ddrhook-util/monitor.c +++ b/src/main/ddrhook-util/monitor.c @@ -7,12 +7,12 @@ #include #include -#include "core/log.h" - #include "ddrhook-util/monitor.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/str.h" diff --git a/src/main/ddrhook-util/p3io.c b/src/main/ddrhook-util/p3io.c index af0f1a9..2fc92c1 100644 --- a/src/main/ddrhook-util/p3io.c +++ b/src/main/ddrhook-util/p3io.c @@ -3,11 +3,10 @@ #include #include -#include "bemanitools/ddrio.h" - #include "ddrhook-util/p3io.h" -#include "core/log.h" +#include "iface-core/log.h" +#include "iface-io/ddr.h" #include "p3ioemu/emu.h" #include "p3ioemu/uart.h" @@ -91,14 +90,14 @@ static HRESULT p3io_ddr_read_jamma(void *ctx, uint32_t *state) { log_assert(state != NULL); - *state = ddr_io_read_pad(); + *state = bt_io_ddr_pad_read(); return S_OK; } static HRESULT p3io_ddr_set_outputs(void *ctx, uint32_t outputs) { - ddr_io_set_lights_p3io(outputs); + bt_io_ddr_p3io_lights_set(outputs); return S_OK; } diff --git a/src/main/ddrhook-util/spike.c b/src/main/ddrhook-util/spike.c index 37cf888..b817893 100644 --- a/src/main/ddrhook-util/spike.c +++ b/src/main/ddrhook-util/spike.c @@ -15,10 +15,10 @@ #include "acioemu/addr.h" #include "acioemu/emu.h" -#include "core/log.h" - #include "hook/iohook.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/str.h" diff --git a/src/main/ddrhook-util/usbmem.c b/src/main/ddrhook-util/usbmem.c index c4e12c4..08132c5 100644 --- a/src/main/ddrhook-util/usbmem.c +++ b/src/main/ddrhook-util/usbmem.c @@ -9,13 +9,14 @@ // clang-format on #include +#include #include #include -#include "core/log.h" - #include "hook/iohook.h" +#include "iface-core/log.h" + #include "util/crc.h" #include "util/fs.h" #include "util/iobuf.h" diff --git a/src/main/ddrhook1/Module.mk b/src/main/ddrhook1/Module.mk index 1e9dc24..ad8146f 100644 --- a/src/main/ddrhook1/Module.mk +++ b/src/main/ddrhook1/Module.mk @@ -6,8 +6,10 @@ ldflags_ddrhook1 := \ deplibs_ddrhook1 := \ avs \ +avslibs_ddrhook1 := \ + avs-ext \ + libs_ddrhook1 := \ - avs-util \ core \ acioemu \ cconfig \ @@ -17,9 +19,10 @@ libs_ddrhook1 := \ hook \ hooklib \ util \ - eamio \ - ddrio \ security \ + iface-core \ + iface-io \ + module \ src_ddrhook1 := \ avs-boot.c \ diff --git a/src/main/ddrhook1/avs-boot.c b/src/main/ddrhook1/avs-boot.c index db4445b..6966856 100644 --- a/src/main/ddrhook1/avs-boot.c +++ b/src/main/ddrhook1/avs-boot.c @@ -6,11 +6,12 @@ #include #include "core/log-bt.h" -#include "core/log.h" #include "hook/iohook.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "ddrhook1/avs-boot.h" diff --git a/src/main/ddrhook1/config-ddrhook1.c b/src/main/ddrhook1/config-ddrhook1.c index a5872bf..34105f1 100644 --- a/src/main/ddrhook1/config-ddrhook1.c +++ b/src/main/ddrhook1/config-ddrhook1.c @@ -2,10 +2,10 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" - #include "ddrhook1/config-ddrhook1.h" +#include "iface-core/log.h" + #define DDRHOOK1_CONFIG_DDRHOOK1_USE_COM4_EMU_KEY "ddrhook1.use_com4_emu" #define DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY "ddrhook1.standard_def" #define DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY "ddrhook1.use_15khz" diff --git a/src/main/ddrhook1/config-eamuse.c b/src/main/ddrhook1/config-eamuse.c index dbe44cd..6c41b78 100644 --- a/src/main/ddrhook1/config-eamuse.c +++ b/src/main/ddrhook1/config-eamuse.c @@ -2,10 +2,10 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" - #include "ddrhook1/config-eamuse.h" +#include "iface-core/log.h" + #include "util/net.h" #define DDRHOOK1_CONFIG_EAMUSE_SERVER_KEY "eamuse.server" diff --git a/src/main/ddrhook1/config-gfx.c b/src/main/ddrhook1/config-gfx.c index c71e74d..20f80ee 100644 --- a/src/main/ddrhook1/config-gfx.c +++ b/src/main/ddrhook1/config-gfx.c @@ -2,10 +2,10 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" - #include "ddrhook1/config-gfx.h" +#include "iface-core/log.h" + #define DDRHOOK1_CONFIG_GFX_WINDOWED_KEY "gfx.windowed" #define DDRHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE true diff --git a/src/main/ddrhook1/config-security.c b/src/main/ddrhook1/config-security.c index b0b7d2b..9fe8233 100644 --- a/src/main/ddrhook1/config-security.c +++ b/src/main/ddrhook1/config-security.c @@ -2,10 +2,10 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" - #include "ddrhook1/config-security.h" +#include "iface-core/log.h" + #include "security/mcode.h" #include "util/net.h" diff --git a/src/main/ddrhook1/dllmain.c b/src/main/ddrhook1/dllmain.c index 3cccb3a..d908831 100644 --- a/src/main/ddrhook1/dllmain.c +++ b/src/main/ddrhook1/dllmain.c @@ -2,19 +2,15 @@ #include -#include "avs-util/core-interop.h" - -#include "bemanitools/ddrio.h" -#include "bemanitools/eamio.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "cconfig/cconfig-hook.h" #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-debug.h" -#include "core/log.h" #include "core/thread-crt.h" -#include "core/thread.h" #include "ddrhook-util/_com4.h" #include "ddrhook-util/extio.h" @@ -38,8 +34,17 @@ #include "hooklib/app.h" #include "hooklib/rs232.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/ddr.h" +#include "iface-io/eam.h" + #include "imports/avs.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "p3ioemu/emu.h" #include "security/rp-sign-key.h" @@ -67,6 +72,9 @@ static DWORD(STDCALL *real_GetModuleFileNameA)( static bool ddrhook1_init_check = false; +static module_io_t *_ddrhook1_module_io_ddr; +static module_io_t *_ddrhook1_module_io_eam; + static const struct hook_symbol init_hook_syms[] = { { .name = "GetModuleFileNameA", @@ -75,13 +83,24 @@ static const struct hook_symbol init_hook_syms[] = { }, }; -static void _ddrhook1_log_init() +static void _ddrhook1_io_ddr_init(module_io_t **module) { - core_log_bt_ext_impl_set(); - core_log_bt_ext_init_with_debug(); + bt_io_ddr_api_t api; - // TODO change log level support - core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); + module_io_ext_load_and_init( + "ddrio.dll", "bt_module_io_ddr_api_get", module); + module_io_api_get(*module, &api); + bt_io_ddr_api_set(&api); +} + +static void _ddrhook1_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); } static DWORD STDCALL @@ -171,12 +190,9 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize) log_info("Initializing DDR IO backend"); - core_log_impl_assign(ddr_io_set_loggers); + _ddrhook1_io_ddr_init(&_ddrhook1_module_io_ddr); - ok = ddr_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + ok = bt_io_ddr_init(); if (!ok) { log_fatal("Couldn't initialize DDR IO backend"); @@ -186,12 +202,9 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize) if (config_ddrhook1.use_com4_emu) { log_info("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); + _ddrhook1_io_eam_init(&_ddrhook1_module_io_eam); - ok = eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + ok = bt_io_eam_init(); if (!ok) { log_fatal("Couldn't initialize card reader backend"); @@ -209,11 +222,8 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - - // TODO init debug logging but with avs available? why not use avs - // logging? - _ddrhook1_log_init(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); hook_table_apply( NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms)); diff --git a/src/main/ddrhook1/filesystem.c b/src/main/ddrhook1/filesystem.c index 9912c4f..5599dfb 100644 --- a/src/main/ddrhook1/filesystem.c +++ b/src/main/ddrhook1/filesystem.c @@ -6,10 +6,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/ddrhook1/master.c b/src/main/ddrhook1/master.c index 480d56f..79beb87 100644 --- a/src/main/ddrhook1/master.c +++ b/src/main/ddrhook1/master.c @@ -1,5 +1,3 @@ -#include "core/log.h" - #include "ddrhook1/master.h" #include "ddrhook-util/dinput.h" @@ -8,6 +6,8 @@ #include "hook/table.h" +#include "iface-core/log.h" + #include "p3ioemu/devmgr.h" #include "util/defs.h" diff --git a/src/main/ddrhook2/Module.mk b/src/main/ddrhook2/Module.mk index e0416d6..cb084db 100644 --- a/src/main/ddrhook2/Module.mk +++ b/src/main/ddrhook2/Module.mk @@ -3,8 +3,10 @@ avsdlls += ddrhook2 deplibs_ddrhook2 := \ avs \ +avslibs_ddrhook2 := \ + avs-ext \ + libs_ddrhook2 := \ - avs-util \ core \ acioemu \ ddrhook-util \ @@ -13,9 +15,10 @@ libs_ddrhook2 := \ hook \ hooklib \ util \ - eamio \ - ddrio \ security \ + iface-core \ + iface-io \ + module \ src_ddrhook2 := \ dllmain.c \ diff --git a/src/main/ddrhook2/dllmain.c b/src/main/ddrhook2/dllmain.c index cabbb94..72964c0 100644 --- a/src/main/ddrhook2/dllmain.c +++ b/src/main/ddrhook2/dllmain.c @@ -2,13 +2,8 @@ #include -#include "avs-util/core-interop.h" - -#include "bemanitools/ddrio.h" -#include "bemanitools/eamio.h" - -#include "core/log.h" -#include "core/thread.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "ddrhook-util/_com4.h" #include "ddrhook-util/extio.h" @@ -24,8 +19,17 @@ #include "hooklib/app.h" #include "hooklib/rs232.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/ddr.h" +#include "iface-io/eam.h" + #include "imports/avs.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "p3ioemu/emu.h" #include "util/cmdline.h" @@ -37,6 +41,29 @@ static bool my_dll_entry_main(void); bool standard_def; bool _15khz; +static module_io_t *_ddrhook2_module_io_ddr; +static module_io_t *_ddrhook2_module_io_eam; + +static void _ddrhook2_io_ddr_init(module_io_t **module) +{ + bt_io_ddr_api_t api; + + module_io_ext_load_and_init( + "ddrio.dll", "bt_module_io_ddr_api_get", module); + module_io_api_get(*module, &api); + bt_io_ddr_api_set(&api); +} + +static void _ddrhook2_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} + static bool my_dll_entry_init(char *sidcode, struct property_node *param) { int argc; @@ -123,12 +150,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info("Initializing DDR IO backend"); - core_log_impl_assign(ddr_io_set_loggers); + _ddrhook2_io_ddr_init(&_ddrhook2_module_io_ddr); - ok = ddr_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + ok = bt_io_ddr_init(); if (!ok) { return false; @@ -137,12 +161,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (com4) { log_info("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); + _ddrhook2_io_eam_init(&_ddrhook2_module_io_eam); - ok = eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + ok = bt_io_eam_init(); if (!ok) { return false; @@ -161,10 +182,14 @@ static bool my_dll_entry_main(void) result = app_hook_invoke_main(); log_misc("Shutting down card reader backend"); - eam_io_fini(); + bt_io_eam_fini(); + bt_io_eam_api_clear(); + module_io_free(&_ddrhook2_module_io_eam); log_misc("Shutting down DDR IO backend"); - ddr_io_fini(); + bt_io_ddr_fini(); + bt_io_ddr_api_clear(); + module_io_free(&_ddrhook2_module_io_ddr); com4_fini(); spike_fini(); @@ -182,8 +207,8 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) } // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); app_hook_init(my_dll_entry_init, my_dll_entry_main); diff --git a/src/main/ddrhook2/master.c b/src/main/ddrhook2/master.c index aba5451..5df884c 100644 --- a/src/main/ddrhook2/master.c +++ b/src/main/ddrhook2/master.c @@ -1,5 +1,3 @@ -#include "core/log.h" - #include "ddrhook2/master.h" #include "ddrhook-util/dinput.h" @@ -9,6 +7,8 @@ #include "hook/table.h" +#include "iface-core/log.h" + #include "p3ioemu/devmgr.h" #include "util/defs.h" diff --git a/src/main/ddrio-async/Module.mk b/src/main/ddrio-async/Module.mk index 2eb806d..4480ed1 100644 --- a/src/main/ddrio-async/Module.mk +++ b/src/main/ddrio-async/Module.mk @@ -5,6 +5,11 @@ ldflags_ddrio-async:= \ libs_ddrio-async := \ core \ util \ + iface \ + iface-io \ + iface-core \ + util \ + module \ src_ddrio-async := \ ddrio.c \ diff --git a/src/main/ddrio-async/ddrio-async.def b/src/main/ddrio-async/ddrio-async.def index 9a399dd..08f1916 100644 --- a/src/main/ddrio-async/ddrio-async.def +++ b/src/main/ddrio-async/ddrio-async.def @@ -1,11 +1,17 @@ LIBRARY ddrio-async EXPORTS - ddr_io_set_loggers - ddr_io_fini - ddr_io_init - ddr_io_read_pad - ddr_io_set_lights_extio - ddr_io_set_lights_p3io - ddr_io_set_lights_hdxs_panel - ddr_io_set_lights_hdxs_rgb + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_io_ddr_api_get + + ; Direct API + bt_io_ddr_init = bt_io_ddr_async_init + bt_io_ddr_fini = bt_io_ddr_async_fini + bt_io_ddr_pad_read = bt_io_ddr_async_pad_read + bt_io_ddr_extio_lights_set = bt_io_ddr_async_extio_lights_set + bt_io_ddr_p3io_lights_set = bt_io_ddr_async_p3io_lights_set + bt_io_ddr_hdxs_lights_panel_set = bt_io_ddr_async_hdxs_lights_panel_set + bt_io_ddr_hdxs_lights_rgb_set = bt_io_ddr_async_hdxs_lights_rgb_set + diff --git a/src/main/ddrio-async/ddrio.c b/src/main/ddrio-async/ddrio.c index 998c59a..72d1487 100644 --- a/src/main/ddrio-async/ddrio.c +++ b/src/main/ddrio-async/ddrio.c @@ -9,46 +9,22 @@ #include -#include "bemanitools/ddrio.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface-io/ddr.h" -#include "core/log.h" -#include "core/thread.h" +#include "module/io-ext.h" +#include "module/io.h" #include "util/time.h" -typedef void (*ddr_io_set_loggers_t)( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); -typedef bool (*ddr_io_init_t)( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy); -typedef uint32_t (*ddr_io_read_pad_t)(void); -typedef void (*ddr_io_set_lights_extio_t)(uint32_t extio_lights); -typedef void (*ddr_io_set_lights_p3io_t)(uint32_t p3io_lights); -typedef void (*ddr_io_set_lights_hdxs_panel_t)(uint32_t hdxs_lights); -typedef void (*ddr_io_set_lights_hdxs_rgb_t)( - uint8_t idx, uint8_t r, uint8_t g, uint8_t b); -typedef void (*ddr_io_fini_t)(void); +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/io/ddr.h" -static HMODULE _child_ddr_io_module; - -static ddr_io_set_loggers_t _child_ddr_io_set_loggers; -static ddr_io_init_t _child_ddr_io_init; -static ddr_io_read_pad_t _child_ddr_io_read_pad; -static ddr_io_set_lights_extio_t _child_ddr_io_set_lights_extio; -static ddr_io_set_lights_p3io_t _child_ddr_io_set_lights_p3io; -static ddr_io_set_lights_hdxs_panel_t _child_ddr_io_set_lights_hdxs_panel; -static ddr_io_set_lights_hdxs_rgb_t _child_ddr_io_set_lights_hdxs_rgb; -static ddr_io_fini_t _child_ddr_io_fini; - -static log_formatter_t _log_formatter_misc; -static log_formatter_t _log_formatter_info; -static log_formatter_t _log_formatter_warning; -static log_formatter_t _log_formatter_fatal; +static module_io_t *_ddr_io_async_module_ddr_io; +static bt_core_thread_id_t _io_thread_id; static _Atomic(bool) _io_thread_proc_loop; static _Atomic(bool) _io_thread_proc_running; @@ -81,7 +57,7 @@ static int _io_thread_proc(void *ctx) loop_counter = 0; while (atomic_load_explicit(&_io_thread_proc_loop, memory_order_seq_cst)) { - local_tmp = _child_ddr_io_read_pad(); + local_tmp = bt_io_ddr_pad_read(); atomic_store_explicit( &_child_ddr_io_data_pad, local_tmp, memory_order_relaxed); @@ -96,7 +72,7 @@ static int _io_thread_proc(void *ctx) &_child_ddr_io_data_extio_lights, memory_order_relaxed); if (local_tmp != prev_child_ddr_io_data_extio_lights) { - _child_ddr_io_set_lights_extio(local_tmp); + bt_io_ddr_extio_lights_set(local_tmp); prev_child_ddr_io_data_extio_lights = local_tmp; } @@ -104,7 +80,7 @@ static int _io_thread_proc(void *ctx) &_child_ddr_io_data_p3io_lights, memory_order_relaxed); if (local_tmp != prev_child_ddr_io_data_p3io_lights) { - _child_ddr_io_set_lights_p3io(local_tmp); + bt_io_ddr_p3io_lights_set(local_tmp); prev_child_ddr_io_data_p3io_lights = local_tmp; } @@ -131,86 +107,48 @@ static int _io_thread_proc(void *ctx) return 0; } -static void *_load_function(HMODULE module, const char *name) +static void _ddr_io_async_child_ddr_io_init(module_io_t **module) { - void *ptr; + bt_io_ddr_api_t api; - ptr = GetProcAddress(module, name); - - if (ptr == NULL) { - log_fatal("Could not find function %s in ddr3io child library", name); - } - - return ptr; + module_io_ext_load_and_init( + "ddrio-async-child.dll", "bt_module_io_ddr_api_get", module); + module_io_api_get(*module, &api); + bt_io_ddr_api_set(&api); } -void ddr_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) +bool bt_io_ddr_async_init() { - _log_formatter_misc = misc; - _log_formatter_info = info; - _log_formatter_warning = warning; - _log_formatter_fatal = fatal; + bool result; + bt_core_thread_result_t result2; - core_log_impl_set(misc, info, warning, fatal); -} - -bool ddr_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) -{ log_info("Loading ddrio-async-child.dll as child ddrio library..."); - core_thread_impl_set(thread_create, thread_join, thread_destroy); - - _child_ddr_io_module = LoadLibraryA("ddrio-async-child.dll"); - - if (_child_ddr_io_module == NULL) { - log_warning("Loading ddrio-async-child.dll failed"); - return false; - } - - _child_ddr_io_set_loggers = - _load_function(_child_ddr_io_module, "ddr_io_set_loggers"); - _child_ddr_io_init = _load_function(_child_ddr_io_module, "ddr_io_init"); - _child_ddr_io_read_pad = - _load_function(_child_ddr_io_module, "ddr_io_read_pad"); - _child_ddr_io_set_lights_extio = - _load_function(_child_ddr_io_module, "ddr_io_set_lights_extio"); - _child_ddr_io_set_lights_p3io = - _load_function(_child_ddr_io_module, "ddr_io_set_lights_p3io"); - _child_ddr_io_set_lights_hdxs_panel = - _load_function(_child_ddr_io_module, "ddr_io_set_lights_hdxs_panel"); - _child_ddr_io_set_lights_hdxs_rgb = - _load_function(_child_ddr_io_module, "ddr_io_set_lights_hdxs_rgb"); - _child_ddr_io_fini = _load_function(_child_ddr_io_module, "ddr_io_fini"); - - _child_ddr_io_set_loggers( - _log_formatter_misc, - _log_formatter_info, - _log_formatter_warning, - _log_formatter_fatal); + _ddr_io_async_child_ddr_io_init(&_ddr_io_async_module_ddr_io); log_info("Calling child ddr_io_init..."); - if (!_child_ddr_io_init(thread_create, thread_join, thread_destroy)) { + result = bt_io_ddr_init(); + + if (!result) { log_warning("Child ddr_io_init failed"); - FreeLibrary(_child_ddr_io_module); + module_io_free(&_ddr_io_async_module_ddr_io); return false; } atomic_store_explicit(&_io_thread_proc_loop, true, memory_order_seq_cst); - if (!thread_create(_io_thread_proc, NULL, 16384, 0)) { - log_warning("Creating IO thread failed"); + result2 = + bt_core_thread_create(_io_thread_proc, NULL, 16384, 0, &_io_thread_id); - _child_ddr_io_fini(); - FreeLibrary(_child_ddr_io_module); + if (result2 != BT_CORE_THREAD_RESULT_SUCCESS) { + log_warning( + "Creating IO thread failed: %s", + bt_core_thread_result_to_str(result2)); + + bt_io_ddr_fini(); + module_io_free(&_ddr_io_async_module_ddr_io); return false; } @@ -218,34 +156,7 @@ bool ddr_io_init( return true; } -uint32_t ddr_io_read_pad(void) -{ - return atomic_load_explicit(&_child_ddr_io_data_pad, memory_order_relaxed); -} - -void ddr_io_set_lights_extio(uint32_t extio_lights) -{ - atomic_store_explicit( - &_child_ddr_io_data_extio_lights, extio_lights, memory_order_relaxed); -} - -void ddr_io_set_lights_p3io(uint32_t p3io_lights) -{ - atomic_store_explicit( - &_child_ddr_io_data_p3io_lights, p3io_lights, memory_order_relaxed); -} - -void ddr_io_set_lights_hdxs_panel(uint32_t lights) -{ - // Not implemented for now -} - -void ddr_io_set_lights_hdxs_rgb(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) -{ - // Not implemented for now -} - -void ddr_io_fini(void) +void bt_io_ddr_async_fini(void) { atomic_store_explicit(&_io_thread_proc_loop, false, memory_order_seq_cst); @@ -258,7 +169,58 @@ void ddr_io_fini(void) log_info("IO thread finished"); - _child_ddr_io_fini(); + bt_io_ddr_fini(); - FreeLibrary(_child_ddr_io_module); + module_io_free(&_ddr_io_async_module_ddr_io); } + +uint32_t bt_io_ddr_async_pad_read(void) +{ + return atomic_load_explicit(&_child_ddr_io_data_pad, memory_order_relaxed); +} + +void bt_io_ddr_async_extio_lights_set(uint32_t extio_lights) +{ + atomic_store_explicit( + &_child_ddr_io_data_extio_lights, extio_lights, memory_order_relaxed); +} + +void bt_io_ddr_async_p3io_lights_set(uint32_t p3io_lights) +{ + atomic_store_explicit( + &_child_ddr_io_data_p3io_lights, p3io_lights, memory_order_relaxed); +} + +void bt_io_ddr_async_hdxs_lights_panel_set(uint32_t lights) +{ + // Not implemented for now +} + +void bt_io_ddr_async_hdxs_lights_rgb_set( + uint8_t idx, uint8_t r, uint8_t g, uint8_t b) +{ + // Not implemented for now +} + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_io_ddr_api_get(bt_io_ddr_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_ddr_async_init; + api->v1.fini = bt_io_ddr_async_fini; + api->v1.pad_read = bt_io_ddr_async_pad_read; + api->v1.extio_lights_set = bt_io_ddr_async_extio_lights_set; + api->v1.p3io_lights_set = bt_io_ddr_async_p3io_lights_set; + api->v1.hdxs_lights_panel_set = bt_io_ddr_async_hdxs_lights_panel_set; + api->v1.hdxs_lights_rgb_set = bt_io_ddr_async_hdxs_lights_rgb_set; +} \ No newline at end of file diff --git a/src/main/ddrio-mm/Module.mk b/src/main/ddrio-mm/Module.mk index 16e3ca8..3862159 100644 --- a/src/main/ddrio-mm/Module.mk +++ b/src/main/ddrio-mm/Module.mk @@ -8,6 +8,7 @@ libs_ddrio-mm := \ core \ mm \ util \ + iface-core \ src_ddrio-mm := \ ddrio.c \ diff --git a/src/main/ddrio-mm/ddrio-mm.def b/src/main/ddrio-mm/ddrio-mm.def index 82df833..546c761 100644 --- a/src/main/ddrio-mm/ddrio-mm.def +++ b/src/main/ddrio-mm/ddrio-mm.def @@ -1,11 +1,15 @@ LIBRARY ddrio-mm EXPORTS - ddr_io_set_loggers - ddr_io_fini - ddr_io_init - ddr_io_read_pad - ddr_io_set_lights_extio - ddr_io_set_lights_p3io - ddr_io_set_lights_hdxs_panel - ddr_io_set_lights_hdxs_rgb + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_io_ddr_api_get + + ; Direct API + bt_io_ddr_init + bt_io_ddr_fini + bt_io_ddr_pad_read + bt_io_ddr_extio_lights_set + bt_io_ddr_p3io_lights_set + bt_io_ddr_hdxs_lights_panel_set + bt_io_ddr_hdxs_lights_rgb_set diff --git a/src/main/ddrio-mm/ddrio.c b/src/main/ddrio-mm/ddrio.c index 44bdd35..30caddf 100644 --- a/src/main/ddrio-mm/ddrio.c +++ b/src/main/ddrio-mm/ddrio.c @@ -1,3 +1,5 @@ +#define LOG_MODULE "ddrio-mm" + #include #include @@ -5,12 +7,15 @@ #include #include -#include "bemanitools/ddrio.h" +#include "api/core/log.h" -#include "core/log.h" +#include "iface-core/log.h" #include "mm/mm.h" +#include "sdk/module/core/log.h" +#include "sdk/module/io/ddr.h" + #include "util/cmdline.h" #include "util/defs.h" #include "util/mem.h" @@ -21,49 +26,49 @@ struct ddr_bittrans { }; static const struct ddr_bittrans input_map[] = { - {0x00000001, 1 << DDR_SERVICE}, - {0x00000002, 1 << DDR_TEST}, - {0x00100000, 1 << DDR_P1_MENU_LEFT}, - {0x00400000, 1 << DDR_P1_MENU_RIGHT}, - {0x00000100, 1 << DDR_P1_START}, - {0x00200000, 1 << DDR_P2_MENU_LEFT}, - {0x00800000, 1 << DDR_P2_MENU_RIGHT}, - {0x00000200, 1 << DDR_P2_START}, - {0x00004000, 1 << DDR_P1_LEFT}, - {0x00010000, 1 << DDR_P1_RIGHT}, - {0x00000400, 1 << DDR_P1_UP}, - {0x00001000, 1 << DDR_P1_DOWN}, - {0x00008000, 1 << DDR_P2_LEFT}, - {0x00020000, 1 << DDR_P2_RIGHT}, - {0x00000800, 1 << DDR_P2_UP}, - {0x00002000, 1 << DDR_P2_DOWN}, + {0x00000001, 1 << BT_IO_DDR_SERVICE}, + {0x00000002, 1 << BT_IO_DDR_TEST}, + {0x00100000, 1 << BT_IO_DDR_P1_MENU_LEFT}, + {0x00400000, 1 << BT_IO_DDR_P1_MENU_RIGHT}, + {0x00000100, 1 << BT_IO_DDR_P1_START}, + {0x00200000, 1 << BT_IO_DDR_P2_MENU_LEFT}, + {0x00800000, 1 << BT_IO_DDR_P2_MENU_RIGHT}, + {0x00000200, 1 << BT_IO_DDR_P2_START}, + {0x00004000, 1 << BT_IO_DDR_P1_LEFT}, + {0x00010000, 1 << BT_IO_DDR_P1_RIGHT}, + {0x00000400, 1 << BT_IO_DDR_P1_UP}, + {0x00001000, 1 << BT_IO_DDR_P1_DOWN}, + {0x00008000, 1 << BT_IO_DDR_P2_LEFT}, + {0x00020000, 1 << BT_IO_DDR_P2_RIGHT}, + {0x00000800, 1 << BT_IO_DDR_P2_UP}, + {0x00002000, 1 << BT_IO_DDR_P2_DOWN}, /* Nonstandard */ - {0x01000000, 1 << DDR_P1_MENU_UP}, - {0x04000000, 1 << DDR_P1_MENU_DOWN}, - {0x02000000, 1 << DDR_P2_MENU_UP}, - {0x08000000, 1 << DDR_P2_MENU_DOWN}, + {0x01000000, 1 << BT_IO_DDR_P1_MENU_UP}, + {0x04000000, 1 << BT_IO_DDR_P1_MENU_DOWN}, + {0x02000000, 1 << BT_IO_DDR_P2_MENU_UP}, + {0x08000000, 1 << BT_IO_DDR_P2_MENU_DOWN}, }; static const struct ddr_bittrans extio_light_map[] = { - {0x00000100, 1 << LIGHT_P1_UP}, - {0x00000200, 1 << LIGHT_P1_DOWN}, - {0x00000400, 1 << LIGHT_P1_LEFT}, - {0x00000800, 1 << LIGHT_P1_RIGHT}, - {0x00010000, 1 << LIGHT_P2_UP}, - {0x00020000, 1 << LIGHT_P2_DOWN}, - {0x00040000, 1 << LIGHT_P2_LEFT}, - {0x00080000, 1 << LIGHT_P2_RIGHT}, - {0x01000000, 1 << LIGHT_NEONS}, + {0x00000100, 1 << BT_IO_DDR_EXTIO_LIGHT_P1_UP}, + {0x00000200, 1 << BT_IO_DDR_EXTIO_LIGHT_P1_DOWN}, + {0x00000400, 1 << BT_IO_DDR_EXTIO_LIGHT_P1_LEFT}, + {0x00000800, 1 << BT_IO_DDR_EXTIO_LIGHT_P1_RIGHT}, + {0x00010000, 1 << BT_IO_DDR_EXTIO_LIGHT_P2_UP}, + {0x00020000, 1 << BT_IO_DDR_EXTIO_LIGHT_P2_DOWN}, + {0x00040000, 1 << BT_IO_DDR_EXTIO_LIGHT_P2_LEFT}, + {0x00080000, 1 << BT_IO_DDR_EXTIO_LIGHT_P2_RIGHT}, + {0x01000000, 1 << BT_IO_DDR_EXTIO_LIGHT_NEONS}, }; static const struct ddr_bittrans p3io_light_map[] = { - {0x00000004, 1 << LIGHT_P1_MENU}, - {0x00000008, 1 << LIGHT_P2_MENU}, - {0x00000010, 1 << LIGHT_P2_LOWER_LAMP}, - {0x00000020, 1 << LIGHT_P2_UPPER_LAMP}, - {0x00000040, 1 << LIGHT_P1_LOWER_LAMP}, - {0x00000080, 1 << LIGHT_P1_UPPER_LAMP}, + {0x00000004, 1 << BT_IO_DDR_P3IO_LIGHT_P1_MENU}, + {0x00000008, 1 << BT_IO_DDR_P3IO_LIGHT_P2_MENU}, + {0x00000010, 1 << BT_IO_DDR_P3IO_LIGHT_P2_LOWER_LAMP}, + {0x00000020, 1 << BT_IO_DDR_P3IO_LIGHT_P2_UPPER_LAMP}, + {0x00000040, 1 << BT_IO_DDR_P3IO_LIGHT_P1_LOWER_LAMP}, + {0x00000080, 1 << BT_IO_DDR_P3IO_LIGHT_P1_UPPER_LAMP}, }; static bool initted; @@ -112,19 +117,7 @@ static int ddr_io_get_lag_param(void) return result; } -void ddr_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - core_log_impl_set(misc, info, warning, fatal); -} - -bool ddr_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_ddr_init() { bool ok; @@ -144,7 +137,7 @@ bool ddr_io_init( return true; } -uint32_t ddr_io_read_pad(void) +uint32_t bt_io_ddr_pad_read(void) { struct mm_input in; uint32_t i; @@ -166,7 +159,7 @@ uint32_t ddr_io_read_pad(void) return pad; } -void ddr_io_set_lights_extio(uint32_t extio_lights) +void bt_io_ddr_extio_lights_set(uint32_t extio_lights) { uint32_t clr; uint32_t set; @@ -187,7 +180,7 @@ void ddr_io_set_lights_extio(uint32_t extio_lights) atomic_fetch_and(&out.lights, ~clr); } -void ddr_io_set_lights_p3io(uint32_t p3io_lights) +void bt_io_ddr_p3io_lights_set(uint32_t p3io_lights) { uint32_t clr; uint32_t set; @@ -208,13 +201,13 @@ void ddr_io_set_lights_p3io(uint32_t p3io_lights) atomic_fetch_and(&out.lights, ~clr); } -void ddr_io_set_lights_hdxs_panel(uint32_t lights) +void bt_io_ddr_hdxs_lights_panel_set(uint32_t lights) { (void) lights; // stubbed } -void ddr_io_set_lights_hdxs_rgb(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) +void bt_io_ddr_hdxs_lights_rgb_set(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) { (void) idx; (void) r; @@ -223,7 +216,7 @@ void ddr_io_set_lights_hdxs_rgb(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) // stubbed } -void ddr_io_fini(void) +void bt_io_ddr_fini(void) { if (initted) { mm_fini(); @@ -231,3 +224,21 @@ void ddr_io_fini(void) initted = false; } } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_io_ddr_api_get(bt_io_ddr_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_ddr_init; + api->v1.fini = bt_io_ddr_fini; + api->v1.pad_read = bt_io_ddr_pad_read; + api->v1.extio_lights_set = bt_io_ddr_extio_lights_set; + api->v1.p3io_lights_set = bt_io_ddr_p3io_lights_set; + api->v1.hdxs_lights_panel_set = bt_io_ddr_hdxs_lights_panel_set; + api->v1.hdxs_lights_rgb_set = bt_io_ddr_hdxs_lights_rgb_set; +} \ No newline at end of file diff --git a/src/main/ddrio-p3io/Module.mk b/src/main/ddrio-p3io/Module.mk index 2824bf0..afcccc6 100644 --- a/src/main/ddrio-p3io/Module.mk +++ b/src/main/ddrio-p3io/Module.mk @@ -11,6 +11,7 @@ libs_ddrio-p3io := \ p3io \ p3iodrv \ util \ + iface-core \ src_ddrio-p3io := \ config.c \ diff --git a/src/main/ddrio-p3io/config.c b/src/main/ddrio-p3io/config.c index 5459157..8d8c2e8 100644 --- a/src/main/ddrio-p3io/config.c +++ b/src/main/ddrio-p3io/config.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "ddrio-p3io/config.h" -#include "config.h" +#include "iface-core/log.h" #define DDRIO_P3IO_CONFIG_EXTIO_PORT_KEY "ddrio.p3io.extio_port" diff --git a/src/main/ddrio-p3io/ddrio-p3io.def b/src/main/ddrio-p3io/ddrio-p3io.def index f6e9fbb..06316ef 100644 --- a/src/main/ddrio-p3io/ddrio-p3io.def +++ b/src/main/ddrio-p3io/ddrio-p3io.def @@ -1,11 +1,15 @@ LIBRARY ddrio-p3io EXPORTS - ddr_io_set_loggers - ddr_io_fini - ddr_io_init - ddr_io_read_pad - ddr_io_set_lights_extio - ddr_io_set_lights_p3io - ddr_io_set_lights_hdxs_panel - ddr_io_set_lights_hdxs_rgb + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_io_ddr_api_get + + ; Direct API + bt_io_ddr_init + bt_io_ddr_fini + bt_io_ddr_pad_read + bt_io_ddr_extio_lights_set + bt_io_ddr_p3io_lights_set + bt_io_ddr_hdxs_lights_panel_set + bt_io_ddr_hdxs_lights_rgb_set diff --git a/src/main/ddrio-p3io/ddrio.c b/src/main/ddrio-p3io/ddrio.c index 6ed7e90..8bf6f29 100644 --- a/src/main/ddrio-p3io/ddrio.c +++ b/src/main/ddrio-p3io/ddrio.c @@ -6,20 +6,20 @@ #include #include -#include "bemanitools/ddrio.h" - #include "cconfig/cconfig-main.h" -#include "core/log.h" -#include "core/thread.h" +#include "ddrio-p3io/config.h" #include "extiodrv/device.h" #include "extiodrv/extio.h" +#include "iface-core/log.h" + #include "p3iodrv/ddr.h" #include "p3iodrv/device.h" -#include "config.h" +#include "sdk/module/core/log.h" +#include "sdk/module/io/ddr.h" static struct ddrio_p3io_config _ddr_io_p3io_config; static HANDLE _ddr_io_p3io_handle; @@ -249,15 +249,6 @@ static HRESULT _ddr_io_flush_and_reset(HANDLE p3io_handle, HANDLE extio_handle) return hr; } -void ddr_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - core_log_impl_set(misc, info, warning, fatal); -} - static void _ddr_io_config_init(struct ddrio_p3io_config *config_ddrio_p3io) { struct cconfig *config; @@ -283,10 +274,7 @@ static void _ddr_io_config_init(struct ddrio_p3io_config *config_ddrio_p3io) cconfig_finit(config); } -bool ddr_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_ddr_init() { HRESULT hr; @@ -313,7 +301,7 @@ bool ddr_io_init( return true; } -uint32_t ddr_io_read_pad(void) +uint32_t bt_io_ddr_pad_read(void) { HRESULT hr; struct p3io_ddr_jamma jamma; @@ -328,23 +316,29 @@ uint32_t ddr_io_read_pad(void) return _byteswap_ulong(*((uint32_t *) &jamma)); } -void ddr_io_set_lights_extio(uint32_t extio_lights) +void bt_io_ddr_extio_lights_set(uint32_t extio_lights) { HRESULT hr; struct extiodrv_extio_pad_lights pad_lights[EXTIO_PAD_LIGHT_MAX_PLAYERS]; bool neons; - pad_lights[0].up = (extio_lights & (1 << LIGHT_P1_UP)) > 0; - pad_lights[0].down = (extio_lights & (1 << LIGHT_P1_DOWN)) > 0; - pad_lights[0].left = (extio_lights & (1 << LIGHT_P1_LEFT)) > 0; - pad_lights[0].right = (extio_lights & (1 << LIGHT_P1_RIGHT)) > 0; + pad_lights[0].up = (extio_lights & (1 << BT_IO_DDR_EXTIO_LIGHT_P1_UP)) > 0; + pad_lights[0].down = + (extio_lights & (1 << BT_IO_DDR_EXTIO_LIGHT_P1_DOWN)) > 0; + pad_lights[0].left = + (extio_lights & (1 << BT_IO_DDR_EXTIO_LIGHT_P1_LEFT)) > 0; + pad_lights[0].right = + (extio_lights & (1 << BT_IO_DDR_EXTIO_LIGHT_P1_RIGHT)) > 0; - pad_lights[1].up = (extio_lights & (1 << LIGHT_P2_UP)) > 0; - pad_lights[1].down = (extio_lights & (1 << LIGHT_P2_DOWN)) > 0; - pad_lights[1].left = (extio_lights & (1 << LIGHT_P2_LEFT)) > 0; - pad_lights[1].right = (extio_lights & (1 << LIGHT_P2_RIGHT)) > 0; + pad_lights[1].up = (extio_lights & (1 << BT_IO_DDR_EXTIO_LIGHT_P2_UP)) > 0; + pad_lights[1].down = + (extio_lights & (1 << BT_IO_DDR_EXTIO_LIGHT_P2_DOWN)) > 0; + pad_lights[1].left = + (extio_lights & (1 << BT_IO_DDR_EXTIO_LIGHT_P2_LEFT)) > 0; + pad_lights[1].right = + (extio_lights & (1 << BT_IO_DDR_EXTIO_LIGHT_P2_RIGHT)) > 0; - neons = (extio_lights & (1 << LIGHT_NEONS)) > 0; + neons = (extio_lights & (1 << BT_IO_DDR_EXTIO_LIGHT_NEONS)) > 0; hr = extiodrv_extio_transfer( _ddr_io_extio_handle, @@ -357,24 +351,24 @@ void ddr_io_set_lights_extio(uint32_t extio_lights) } } -void ddr_io_set_lights_p3io(uint32_t p3io_lights) +void bt_io_ddr_p3io_lights_set(uint32_t p3io_lights) { HRESULT hr; struct p3io_ddr_output output; output.cabinet.top_p1_lower = - (p3io_lights & (1 << LIGHT_P1_LOWER_LAMP)) > 0 ? 1 : 0; + (p3io_lights & (1 << BT_IO_DDR_P3IO_LIGHT_P1_LOWER_LAMP)) > 0 ? 1 : 0; output.cabinet.top_p1_upper = - (p3io_lights & (1 << LIGHT_P1_UPPER_LAMP)) > 0 ? 1 : 0; + (p3io_lights & (1 << BT_IO_DDR_P3IO_LIGHT_P1_UPPER_LAMP)) > 0 ? 1 : 0; output.cabinet.top_p2_lower = - (p3io_lights & (1 << LIGHT_P2_LOWER_LAMP)) > 0 ? 1 : 0; + (p3io_lights & (1 << BT_IO_DDR_P3IO_LIGHT_P2_LOWER_LAMP)) > 0 ? 1 : 0; output.cabinet.top_p2_upper = - (p3io_lights & (1 << LIGHT_P2_UPPER_LAMP)) > 0 ? 1 : 0; + (p3io_lights & (1 << BT_IO_DDR_P3IO_LIGHT_P2_UPPER_LAMP)) > 0 ? 1 : 0; output.cabinet.p1_menu_buttons = - (p3io_lights & (1 << LIGHT_P1_MENU)) > 0 ? 1 : 0; + (p3io_lights & (1 << BT_IO_DDR_P3IO_LIGHT_P1_MENU)) > 0 ? 1 : 0; output.cabinet.p2_menu_buttons = - (p3io_lights & (1 << LIGHT_P2_MENU)) > 0 ? 1 : 0; + (p3io_lights & (1 << BT_IO_DDR_P3IO_LIGHT_P2_MENU)) > 0 ? 1 : 0; hr = p3iodrv_ddr_set_outputs(_ddr_io_p3io_handle, &output); @@ -383,14 +377,14 @@ void ddr_io_set_lights_p3io(uint32_t p3io_lights) } } -void ddr_io_set_lights_hdxs_panel(uint32_t lights) +void bt_io_ddr_hdxs_lights_panel_set(uint32_t lights) { // Unused (void) lights; } -void ddr_io_set_lights_hdxs_rgb(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) +void bt_io_ddr_hdxs_lights_rgb_set(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) { // Unused @@ -400,7 +394,7 @@ void ddr_io_set_lights_hdxs_rgb(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) (void) b; } -void ddr_io_fini(void) +void bt_io_ddr_fini(void) { HRESULT hr; @@ -425,3 +419,21 @@ void ddr_io_fini(void) // continue } } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_io_ddr_api_get(bt_io_ddr_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_ddr_init; + api->v1.fini = bt_io_ddr_fini; + api->v1.pad_read = bt_io_ddr_pad_read; + api->v1.extio_lights_set = bt_io_ddr_extio_lights_set; + api->v1.p3io_lights_set = bt_io_ddr_p3io_lights_set; + api->v1.hdxs_lights_panel_set = bt_io_ddr_hdxs_lights_panel_set; + api->v1.hdxs_lights_rgb_set = bt_io_ddr_hdxs_lights_rgb_set; +} \ No newline at end of file diff --git a/src/main/ddrio-smx/Module.mk b/src/main/ddrio-smx/Module.mk index 12fd74d..ba77910 100644 --- a/src/main/ddrio-smx/Module.mk +++ b/src/main/ddrio-smx/Module.mk @@ -8,6 +8,9 @@ libs_ddrio-smx := \ core \ geninput \ util \ + iface-core \ + iface \ + module \ src_ddrio-smx := \ ddrio.c \ diff --git a/src/main/ddrio-smx/ddrio-smx.def b/src/main/ddrio-smx/ddrio-smx.def index 49219de..243faf4 100644 --- a/src/main/ddrio-smx/ddrio-smx.def +++ b/src/main/ddrio-smx/ddrio-smx.def @@ -1,11 +1,15 @@ LIBRARY ddrio-smx EXPORTS - ddr_io_set_loggers - ddr_io_fini - ddr_io_init - ddr_io_read_pad - ddr_io_set_lights_extio - ddr_io_set_lights_p3io - ddr_io_set_lights_hdxs_panel - ddr_io_set_lights_hdxs_rgb + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_io_ddr_api_get + + ; Direct API + bt_io_ddr_init + bt_io_ddr_fini + bt_io_ddr_pad_read + bt_io_ddr_extio_lights_set + bt_io_ddr_p3io_lights_set + bt_io_ddr_hdxs_lights_panel_set + bt_io_ddr_hdxs_lights_rgb_set diff --git a/src/main/ddrio-smx/ddrio.c b/src/main/ddrio-smx/ddrio.c index 334ccac..9fa4679 100644 --- a/src/main/ddrio-smx/ddrio.c +++ b/src/main/ddrio-smx/ddrio.c @@ -1,16 +1,28 @@ +#define LOG_MODULE "ddrio-smx" + #include #include #include -#include "bemanitools/ddrio.h" -#include "bemanitools/input.h" +#include "api/core/log.h" +#include "api/core/thread.h" -#include "core/log.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface/input.h" #include "imports/SMX.h" #include "imports/avs.h" +#include "main/module/input-ext.h" +#include "main/module/input.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/input.h" +#include "sdk/module/io/ddr.h" + #include "util/defs.h" struct ddr_io_smx_pad_map { @@ -31,15 +43,15 @@ static void ddr_io_smx_callback(int pad_no, enum SMXUpdateCallbackReason reason, void *ctx); static const struct ddr_io_smx_pad_map ddr_io_smx_pad_map[] = { - {0, 1 << 1, 1 << DDR_P1_UP}, - {0, 1 << 3, 1 << DDR_P1_LEFT}, - {0, 1 << 5, 1 << DDR_P1_RIGHT}, - {0, 1 << 7, 1 << DDR_P1_DOWN}, + {0, 1 << 1, 1 << BT_IO_DDR_P1_UP}, + {0, 1 << 3, 1 << BT_IO_DDR_P1_LEFT}, + {0, 1 << 5, 1 << BT_IO_DDR_P1_RIGHT}, + {0, 1 << 7, 1 << BT_IO_DDR_P1_DOWN}, - {1, 1 << 1, 1 << DDR_P2_UP}, - {1, 1 << 3, 1 << DDR_P2_LEFT}, - {1, 1 << 5, 1 << DDR_P2_RIGHT}, - {1, 1 << 7, 1 << DDR_P2_DOWN}, + {1, 1 << 1, 1 << BT_IO_DDR_P2_UP}, + {1, 1 << 3, 1 << BT_IO_DDR_P2_LEFT}, + {1, 1 << 5, 1 << BT_IO_DDR_P2_RIGHT}, + {1, 1 << 7, 1 << BT_IO_DDR_P2_DOWN}, }; #define DDR_IO_SMX_LIGHT_VALUES_PER_PANEL 75 @@ -50,39 +62,43 @@ static const struct ddr_io_smx_pad_map ddr_io_smx_pad_map[] = { static const struct ddr_io_smx_light_map ddr_io_smx_light_map[] = { /* Light L/R blue and U/D red to match DDR pad color scheme */ - {1 << LIGHT_P1_UP, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 1, 0xFF, 0x00, 0x00}, - {1 << LIGHT_P1_LEFT, + {1 << BT_IO_DDR_EXTIO_LIGHT_P1_UP, + DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 1, + 0xFF, + 0x00, + 0x00}, + {1 << BT_IO_DDR_EXTIO_LIGHT_P1_LEFT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 3, 0x00, 0x00, 0xFF}, - {1 << LIGHT_P1_RIGHT, + {1 << BT_IO_DDR_EXTIO_LIGHT_P1_RIGHT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 5, 0x00, 0x00, 0xFF}, - {1 << LIGHT_P1_DOWN, + {1 << BT_IO_DDR_EXTIO_LIGHT_P1_DOWN, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 7, 0xFF, 0x00, 0x00}, - {1 << LIGHT_P2_UP, + {1 << BT_IO_DDR_EXTIO_LIGHT_P2_UP, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 10, 0xFF, 0x00, 0x00}, - {1 << LIGHT_P2_LEFT, + {1 << BT_IO_DDR_EXTIO_LIGHT_P2_LEFT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 12, 0x00, 0x00, 0xFF}, - {1 << LIGHT_P2_RIGHT, + {1 << BT_IO_DDR_EXTIO_LIGHT_P2_RIGHT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 14, 0x00, 0x00, 0xFF}, - {1 << LIGHT_P2_DOWN, + {1 << BT_IO_DDR_EXTIO_LIGHT_P2_DOWN, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 16, 0xFF, 0x00, @@ -93,30 +109,24 @@ static _Atomic uint32_t ddr_io_smx_pad_state[2]; static CRITICAL_SECTION ddr_io_smx_lights_lock; static uint8_t ddr_io_smx_lights_counter; static char ddr_io_smx_lights[DDR_IO_SMX_TOTAL_LIGHT_VALUES]; +static module_input_t *_ddr_io_smx_module_input; -void ddr_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) +bool bt_io_ddr_init() { - core_log_impl_set(misc, info, warning, fatal); - input_set_loggers(misc, info, warning, fatal); + bool result; + bt_input_api_t input_api; - /* We would need a log server thread to accept log messages from SMX, since - it uses raw Win32 threads and not AVS threads (only AVS threads are - permitted to use the AVS logging API). So it's not really worth it. */ -} - -bool ddr_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) -{ /* Use geninput for menu/operator btns */ + module_input_ext_load_and_init("geninput.dll", &_ddr_io_smx_module_input); + module_input_api_get(_ddr_io_smx_module_input, &input_api); + bt_input_api_set(&input_api); - input_init(thread_create, thread_join, thread_destroy); - mapper_config_load("ddr"); + result = bt_input_mapper_config_load("ddr"); + + if (!result) { + log_warning("Failed loading input mapper config for ddr"); + return false; + } /* Start up SMX API */ @@ -130,7 +140,7 @@ bool ddr_io_init( return true; } -uint32_t ddr_io_read_pad(void) +uint32_t bt_io_ddr_pad_read(void) { /* SMX pads require a constant stream of lighting updates or they will quickly revert to autonomous lighting control. Here is a hacky way of @@ -161,11 +171,11 @@ uint32_t ddr_io_read_pad(void) /* We don't atomically read both pads, but they are separate USB devices so they don't update in lockstep anyway. */ - return mapper_update() | atomic_load(&ddr_io_smx_pad_state[0]) | + return bt_input_mapper_update() | atomic_load(&ddr_io_smx_pad_state[0]) | atomic_load(&ddr_io_smx_pad_state[1]); } -void ddr_io_set_lights_extio(uint32_t lights) +void bt_io_ddr_extio_lights_set(uint32_t lights) { const struct ddr_io_smx_light_map *map; size_t offset; @@ -194,42 +204,46 @@ void ddr_io_set_lights_extio(uint32_t lights) LeaveCriticalSection(&ddr_io_smx_lights_lock); } -void ddr_io_set_lights_p3io(uint32_t lights) +void bt_io_ddr_p3io_lights_set(uint32_t lights) { uint8_t i; for (i = 0x00; i <= 0x07; i++) { - mapper_write_light(i, lights & (1 << i) ? 255 : 0); + bt_input_mapper_light_write(i, lights & (1 << i) ? 255 : 0); } } -void ddr_io_set_lights_hdxs_panel(uint32_t lights) +void bt_io_ddr_hdxs_lights_panel_set(uint32_t lights) { uint8_t i; for (i = 0x08; i <= 0x0D; i++) { - mapper_write_light(i, lights & (1 << i) ? 255 : 0); + bt_input_mapper_light_write(i, lights & (1 << i) ? 255 : 0); } } -void ddr_io_set_lights_hdxs_rgb(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) +void bt_io_ddr_hdxs_lights_rgb_set(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) { if (idx < 4) { uint8_t base = 0x20 + idx * 3; - mapper_write_light(base + 0, r); - mapper_write_light(base + 1, g); - mapper_write_light(base + 2, b); + bt_input_mapper_light_write(base + 0, r); + bt_input_mapper_light_write(base + 1, g); + bt_input_mapper_light_write(base + 2, b); } } -void ddr_io_fini(void) +void bt_io_ddr_fini(void) { log_info("Stopping SMX.DLL"); SMX_Stop(); log_info("Stopped SMX.DLL"); DeleteCriticalSection(&ddr_io_smx_lights_lock); - input_fini(); + + bt_input_fini(); + + bt_input_api_clear(); + module_input_free(&_ddr_io_smx_module_input); } static void @@ -257,3 +271,30 @@ ddr_io_smx_callback(int pad_no, enum SMXUpdateCallbackReason reason, void *ctx) atomic_store(&ddr_io_smx_pad_state[pad_no], ddr_state); } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); + + /* We would need a log server thread to accept log messages from SMX, since + it uses raw Win32 threads and not AVS threads (only AVS threads are + permitted to use the AVS logging API). So it's not really worth it. */ +} + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_io_ddr_api_get(bt_io_ddr_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_ddr_init; + api->v1.fini = bt_io_ddr_fini; + api->v1.pad_read = bt_io_ddr_pad_read; + api->v1.extio_lights_set = bt_io_ddr_extio_lights_set; + api->v1.p3io_lights_set = bt_io_ddr_p3io_lights_set; + api->v1.hdxs_lights_panel_set = bt_io_ddr_hdxs_lights_panel_set; + api->v1.hdxs_lights_rgb_set = bt_io_ddr_hdxs_lights_rgb_set; +} \ No newline at end of file diff --git a/src/main/ddrio/Module.mk b/src/main/ddrio/Module.mk index 6a25b77..7b83c94 100644 --- a/src/main/ddrio/Module.mk +++ b/src/main/ddrio/Module.mk @@ -1,7 +1,11 @@ dlls += ddrio libs_ddrio := \ - geninput \ + module \ + iface-core \ + core \ + iface \ + util \ src_ddrio := \ ddrio.c \ diff --git a/src/main/ddrio/ddrio.c b/src/main/ddrio/ddrio.c index 5da9934..9403ad2 100644 --- a/src/main/ddrio/ddrio.c +++ b/src/main/ddrio/ddrio.c @@ -1,32 +1,53 @@ +#define LOG_MODULE "ddrio" + #include -#include "imports/avs.h" +#include "api/core/log.h" +#include "api/core/thread.h" -#include "bemanitools/input.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface/input.h" -#include "core/log.h" +#include "module/input.h" -void ddr_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) +#include "main/module/input-ext.h" +#include "main/module/input.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/input.h" +#include "sdk/module/io/ddr.h" + +static module_input_t *_ddr_io_module_input; + +bool bt_io_ddr_init() { - input_set_loggers(misc, info, warning, fatal); + bool result; + bt_input_api_t input_api; + + module_input_ext_load_and_init("geninput.dll", &_ddr_io_module_input); + module_input_api_get(_ddr_io_module_input, &input_api); + bt_input_api_set(&input_api); + + result = bt_input_init(); + + if (!result) { + return false; + } + + return bt_input_mapper_config_load("ddr"); } -bool ddr_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +void bt_io_ddr_fini() { - input_init(thread_create, thread_join, thread_destroy); - mapper_config_load("ddr"); + bt_input_fini(); - return true; + bt_input_api_clear(); + module_input_free(&_ddr_io_module_input); } -uint32_t ddr_io_read_pad(void) +uint32_t bt_io_ddr_pad_read(void) { /* Sleep first: input is timestamped immediately AFTER the ioctl returns. @@ -36,47 +57,65 @@ uint32_t ddr_io_read_pad(void) Sleep(1); - return (uint32_t) mapper_update(); + return (uint32_t) bt_input_mapper_update(); } -void ddr_io_set_lights_extio(uint32_t lights) +void bt_io_ddr_extio_lights_set(uint32_t lights) { uint8_t i; for (i = 0x0E; i <= 0x1E; i++) { - mapper_write_light(i, lights & (1 << i) ? 255 : 0); + bt_input_mapper_light_write(i, lights & (1 << i) ? 255 : 0); } } -void ddr_io_set_lights_p3io(uint32_t lights) +void bt_io_ddr_p3io_lights_set(uint32_t lights) { uint8_t i; for (i = 0x00; i <= 0x07; i++) { - mapper_write_light(i, lights & (1 << i) ? 255 : 0); + bt_input_mapper_light_write(i, lights & (1 << i) ? 255 : 0); } } -void ddr_io_set_lights_hdxs_panel(uint32_t lights) +void bt_io_ddr_hdxs_lights_panel_set(uint32_t lights) { uint8_t i; for (i = 0x08; i <= 0x0D; i++) { - mapper_write_light(i, lights & (1 << i) ? 255 : 0); + bt_input_mapper_light_write(i, lights & (1 << i) ? 255 : 0); } } -void ddr_io_set_lights_hdxs_rgb(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) +void bt_io_ddr_hdxs_lights_rgb_set(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) { if (idx < 4) { uint8_t base = 0x20 + idx * 3; - mapper_write_light(base + 0, r); - mapper_write_light(base + 1, g); - mapper_write_light(base + 2, b); + bt_input_mapper_light_write(base + 0, r); + bt_input_mapper_light_write(base + 1, g); + bt_input_mapper_light_write(base + 2, b); } } -void ddr_io_fini(void) +void bt_module_core_log_api_set(const bt_core_log_api_t *api) { - input_fini(); + bt_core_log_api_set(api); } + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_io_ddr_api_get(bt_io_ddr_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_ddr_init; + api->v1.fini = bt_io_ddr_fini; + api->v1.pad_read = bt_io_ddr_pad_read; + api->v1.extio_lights_set = bt_io_ddr_extio_lights_set; + api->v1.p3io_lights_set = bt_io_ddr_p3io_lights_set; + api->v1.hdxs_lights_panel_set = bt_io_ddr_hdxs_lights_panel_set; + api->v1.hdxs_lights_rgb_set = bt_io_ddr_hdxs_lights_rgb_set; +} \ No newline at end of file diff --git a/src/main/ddrio/ddrio.def b/src/main/ddrio/ddrio.def index bc2129d..6be152d 100644 --- a/src/main/ddrio/ddrio.def +++ b/src/main/ddrio/ddrio.def @@ -1,11 +1,16 @@ LIBRARY ddrio EXPORTS - ddr_io_set_loggers - ddr_io_fini - ddr_io_init - ddr_io_read_pad - ddr_io_set_lights_extio - ddr_io_set_lights_p3io - ddr_io_set_lights_hdxs_panel - ddr_io_set_lights_hdxs_rgb + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_io_ddr_api_get + + ; Direct API + bt_io_ddr_init + bt_io_ddr_fini + bt_io_ddr_pad_read + bt_io_ddr_extio_lights_set + bt_io_ddr_p3io_lights_set + bt_io_ddr_hdxs_lights_panel_set + bt_io_ddr_hdxs_lights_rgb_set diff --git a/src/main/ddriotest/Module.mk b/src/main/ddriotest/Module.mk index b6cba5c..7700697 100644 --- a/src/main/ddriotest/Module.mk +++ b/src/main/ddriotest/Module.mk @@ -2,8 +2,10 @@ exes += ddriotest \ libs_ddriotest := \ core \ - ddrio \ util \ + module \ + iface-core \ + iface-io \ src_ddriotest := \ main.c \ diff --git a/src/main/ddriotest/main.c b/src/main/ddriotest/main.c index 40453ce..17e5167 100644 --- a/src/main/ddriotest/main.c +++ b/src/main/ddriotest/main.c @@ -5,18 +5,31 @@ #include -#include "bemanitools/ddrio.h" - #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" +#include "core/log-sink-std.h" #include "core/thread-crt.h" -#include "core/thread.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface-io/ddr.h" + +#include "module/io-ext.h" + +static void _ddriotest_io_ddr_init(module_io_t **module) +{ + bt_io_ddr_api_t api; + + module_io_ext_load_and_init( + "ddrio.dll", "bt_module_io_ddr_api_get", module); + module_io_api_get(*module, &api); + bt_io_ddr_api_set(&api); +} int main(int argc, char **argv) { enum core_log_bt_log_level log_level; + module_io_t *module_io_ddr; log_level = CORE_LOG_BT_LOG_LEVEL_FATAL; @@ -30,19 +43,20 @@ int main(int argc, char **argv) } } - core_thread_crt_ext_impl_set(); - core_log_bt_ext_impl_set(); + core_log_bt_core_api_set(); + core_thread_crt_core_api_set(); core_log_bt_ext_init_with_stderr(); core_log_bt_level_set(log_level); - core_log_impl_assign(ddr_io_set_loggers); + _ddriotest_io_ddr_init(&module_io_ddr); - if (!ddr_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_ddr_init()) { fprintf(stderr, "Initializing ddrio failed\n"); + + bt_io_ddr_api_clear(); + module_io_free(&module_io_ddr); + return -1; } @@ -51,6 +65,11 @@ int main(int argc, char **argv) ">>> Initializing ddrio successful, press enter to continue <<<\n"); if (getchar() != '\n') { + bt_io_ddr_fini(); + + bt_io_ddr_api_clear(); + module_io_free(&module_io_ddr); + return 0; } @@ -65,10 +84,10 @@ int main(int argc, char **argv) uint8_t cnt = 0; while (loop) { - ddr_io_set_lights_extio(extio_lights); - ddr_io_set_lights_p3io(p3io_lights); + bt_io_ddr_extio_lights_set(extio_lights); + bt_io_ddr_p3io_lights_set(p3io_lights); - pad = ddr_io_read_pad(); + pad = bt_io_ddr_pad_read(); system("cls"); @@ -79,116 +98,116 @@ int main(int argc, char **argv) printf( "Up: %d Up: %d\n", - (pad & (1 << DDR_P1_UP)) > 0, - (pad & (1 << DDR_P2_UP)) > 0); + (pad & (1 << BT_IO_DDR_P1_UP)) > 0, + (pad & (1 << BT_IO_DDR_P2_UP)) > 0); printf( "Down: %d Down: %d\n", - (pad & (1 << DDR_P1_DOWN)) > 0, - (pad & (1 << DDR_P2_DOWN)) > 0); + (pad & (1 << BT_IO_DDR_P1_DOWN)) > 0, + (pad & (1 << BT_IO_DDR_P2_DOWN)) > 0); printf( "Left: %d Left: %d\n", - (pad & (1 << DDR_P1_LEFT)) > 0, - (pad & (1 << DDR_P2_LEFT)) > 0); + (pad & (1 << BT_IO_DDR_P1_LEFT)) > 0, + (pad & (1 << BT_IO_DDR_P2_LEFT)) > 0); printf( "Right: %d Right: %d\n", - (pad & (1 << DDR_P1_RIGHT)) > 0, - (pad & (1 << DDR_P2_RIGHT)) > 0); + (pad & (1 << BT_IO_DDR_P1_RIGHT)) > 0, + (pad & (1 << BT_IO_DDR_P2_RIGHT)) > 0); printf("\n"); printf("Menu\n"); printf( "Start: %d Start: %d\n", - (pad & (1 << DDR_P1_START)) > 0, - (pad & (1 << DDR_P2_START)) > 0); + (pad & (1 << BT_IO_DDR_P1_START)) > 0, + (pad & (1 << BT_IO_DDR_P2_START)) > 0); printf( "Up: %d Up: %d\n", - (pad & (1 << DDR_P1_MENU_UP)) > 0, - (pad & (1 << DDR_P2_MENU_UP)) > 0); + (pad & (1 << BT_IO_DDR_P1_MENU_UP)) > 0, + (pad & (1 << BT_IO_DDR_P2_MENU_UP)) > 0); printf( "Down: %d Down: %d\n", - (pad & (1 << DDR_P1_MENU_DOWN)) > 0, - (pad & (1 << DDR_P2_MENU_DOWN)) > 0); + (pad & (1 << BT_IO_DDR_P1_MENU_DOWN)) > 0, + (pad & (1 << BT_IO_DDR_P2_MENU_DOWN)) > 0); printf( "Left: %d Left: %d\n", - (pad & (1 << DDR_P1_MENU_LEFT)) > 0, - (pad & (1 << DDR_P2_MENU_LEFT)) > 0); + (pad & (1 << BT_IO_DDR_P1_MENU_LEFT)) > 0, + (pad & (1 << BT_IO_DDR_P2_MENU_LEFT)) > 0); printf( "Right: %d Right: %d\n", - (pad & (1 << DDR_P1_MENU_RIGHT)) > 0, - (pad & (1 << DDR_P2_MENU_RIGHT)) > 0); + (pad & (1 << BT_IO_DDR_P1_MENU_RIGHT)) > 0, + (pad & (1 << BT_IO_DDR_P2_MENU_RIGHT)) > 0); printf("\n"); printf("Operator\n"); printf( "Test: %d Service: %d Coin: %d\n", - (pad & (1 << DDR_TEST)) > 0, - (pad & (1 << DDR_SERVICE)) > 0, - (pad & (1 << DDR_COIN)) > 0); + (pad & (1 << BT_IO_DDR_TEST)) > 0, + (pad & (1 << BT_IO_DDR_SERVICE)) > 0, + (pad & (1 << BT_IO_DDR_COIN)) > 0); - if ((pad & (1 << DDR_P1_UP)) > 0) { - extio_lights |= (1 << LIGHT_P1_UP); + if ((pad & (1 << BT_IO_DDR_P1_UP)) > 0) { + extio_lights |= (1 << BT_IO_DDR_EXTIO_LIGHT_P1_UP); } else { - extio_lights &= ~(1 << LIGHT_P1_UP); + extio_lights &= ~(1 << BT_IO_DDR_EXTIO_LIGHT_P1_UP); } - if ((pad & (1 << DDR_P1_DOWN)) > 0) { - extio_lights |= (1 << LIGHT_P1_DOWN); + if ((pad & (1 << BT_IO_DDR_P1_DOWN)) > 0) { + extio_lights |= (1 << BT_IO_DDR_EXTIO_LIGHT_P1_DOWN); } else { - extio_lights &= ~(1 << LIGHT_P1_DOWN); + extio_lights &= ~(1 << BT_IO_DDR_EXTIO_LIGHT_P1_DOWN); } - if ((pad & (1 << DDR_P1_LEFT)) > 0) { - extio_lights |= (1 << LIGHT_P1_LEFT); + if ((pad & (1 << BT_IO_DDR_P1_LEFT)) > 0) { + extio_lights |= (1 << BT_IO_DDR_EXTIO_LIGHT_P1_LEFT); } else { - extio_lights &= ~(1 << LIGHT_P1_LEFT); + extio_lights &= ~(1 << BT_IO_DDR_EXTIO_LIGHT_P1_LEFT); } - if ((pad & (1 << DDR_P1_RIGHT)) > 0) { - extio_lights |= (1 << LIGHT_P1_RIGHT); + if ((pad & (1 << BT_IO_DDR_P1_RIGHT)) > 0) { + extio_lights |= (1 << BT_IO_DDR_EXTIO_LIGHT_P1_RIGHT); } else { - extio_lights &= ~(1 << LIGHT_P1_RIGHT); + extio_lights &= ~(1 << BT_IO_DDR_EXTIO_LIGHT_P1_RIGHT); } - if ((pad & (1 << DDR_P2_UP)) > 0) { - extio_lights |= (1 << LIGHT_P2_UP); + if ((pad & (1 << BT_IO_DDR_P2_UP)) > 0) { + extio_lights |= (1 << BT_IO_DDR_EXTIO_LIGHT_P2_UP); } else { - extio_lights &= ~(1 << LIGHT_P2_UP); + extio_lights &= ~(1 << BT_IO_DDR_EXTIO_LIGHT_P2_UP); } - if ((pad & (1 << DDR_P2_DOWN)) > 0) { - extio_lights |= (1 << LIGHT_P2_DOWN); + if ((pad & (1 << BT_IO_DDR_P2_DOWN)) > 0) { + extio_lights |= (1 << BT_IO_DDR_EXTIO_LIGHT_P2_DOWN); } else { - extio_lights &= ~(1 << LIGHT_P2_DOWN); + extio_lights &= ~(1 << BT_IO_DDR_EXTIO_LIGHT_P2_DOWN); } - if ((pad & (1 << DDR_P2_LEFT)) > 0) { - extio_lights |= (1 << LIGHT_P2_LEFT); + if ((pad & (1 << BT_IO_DDR_P2_LEFT)) > 0) { + extio_lights |= (1 << BT_IO_DDR_EXTIO_LIGHT_P2_LEFT); } else { - extio_lights &= ~(1 << LIGHT_P2_LEFT); + extio_lights &= ~(1 << BT_IO_DDR_EXTIO_LIGHT_P2_LEFT); } - if ((pad & (1 << DDR_P2_RIGHT)) > 0) { - extio_lights |= (1 << LIGHT_P2_RIGHT); + if ((pad & (1 << BT_IO_DDR_P2_RIGHT)) > 0) { + extio_lights |= (1 << BT_IO_DDR_EXTIO_LIGHT_P2_RIGHT); } else { - extio_lights &= ~(1 << LIGHT_P2_RIGHT); + extio_lights &= ~(1 << BT_IO_DDR_EXTIO_LIGHT_P2_RIGHT); } - if ((pad & (1 << DDR_P1_START)) > 0 || - (pad & (1 << DDR_P1_MENU_UP)) > 0 || - (pad & (1 << DDR_P1_MENU_DOWN)) > 0 || - (pad & (1 << DDR_P1_MENU_LEFT)) > 0 || - (pad & (1 << DDR_P1_MENU_RIGHT)) > 0) { - p3io_lights |= (1 << LIGHT_P1_MENU); + if ((pad & (1 << BT_IO_DDR_P1_START)) > 0 || + (pad & (1 << BT_IO_DDR_P1_MENU_UP)) > 0 || + (pad & (1 << BT_IO_DDR_P1_MENU_DOWN)) > 0 || + (pad & (1 << BT_IO_DDR_P1_MENU_LEFT)) > 0 || + (pad & (1 << BT_IO_DDR_P1_MENU_RIGHT)) > 0) { + p3io_lights |= (1 << BT_IO_DDR_P3IO_LIGHT_P1_MENU); } else { - p3io_lights &= ~(1 << LIGHT_P1_MENU); + p3io_lights &= ~(1 << BT_IO_DDR_P3IO_LIGHT_P1_MENU); } - if ((pad & (1 << DDR_P2_START)) > 0 || - (pad & (1 << DDR_P2_MENU_UP)) > 0 || - (pad & (1 << DDR_P2_MENU_DOWN)) > 0 || - (pad & (1 << DDR_P2_MENU_LEFT)) > 0 || - (pad & (1 << DDR_P2_MENU_RIGHT)) > 0) { - p3io_lights |= (1 << LIGHT_P2_MENU); + if ((pad & (1 << BT_IO_DDR_P2_START)) > 0 || + (pad & (1 << BT_IO_DDR_P2_MENU_UP)) > 0 || + (pad & (1 << BT_IO_DDR_P2_MENU_DOWN)) > 0 || + (pad & (1 << BT_IO_DDR_P2_MENU_LEFT)) > 0 || + (pad & (1 << BT_IO_DDR_P2_MENU_RIGHT)) > 0) { + p3io_lights |= (1 << BT_IO_DDR_P3IO_LIGHT_P2_MENU); } else { - p3io_lights &= ~(1 << LIGHT_P2_MENU); + p3io_lights &= ~(1 << BT_IO_DDR_P3IO_LIGHT_P2_MENU); } /* avoid CPU banging */ @@ -226,9 +245,9 @@ int main(int argc, char **argv) n = scanf("%d", &state); if (n > 0) { - extio_lights |= (1 << LIGHT_NEONS); + extio_lights |= (1 << BT_IO_DDR_EXTIO_LIGHT_NEONS); } else { - extio_lights &= ~(1 << LIGHT_NEONS); + extio_lights &= ~(1 << BT_IO_DDR_EXTIO_LIGHT_NEONS); } break; @@ -244,27 +263,35 @@ int main(int argc, char **argv) if (n > 0) { if (buf[0] == '1') { - p3io_lights |= (1 << LIGHT_P1_UPPER_LAMP); + p3io_lights |= + (1 << BT_IO_DDR_P3IO_LIGHT_P1_UPPER_LAMP); } else { - p3io_lights &= ~(1 << LIGHT_P1_UPPER_LAMP); + p3io_lights &= + ~(1 << BT_IO_DDR_P3IO_LIGHT_P1_UPPER_LAMP); } if (buf[1] == '1') { - p3io_lights |= (1 << LIGHT_P1_LOWER_LAMP); + p3io_lights |= + (1 << BT_IO_DDR_P3IO_LIGHT_P1_LOWER_LAMP); } else { - p3io_lights &= ~(1 << LIGHT_P1_LOWER_LAMP); + p3io_lights &= + ~(1 << BT_IO_DDR_P3IO_LIGHT_P1_LOWER_LAMP); } if (buf[2] == '1') { - p3io_lights |= (1 << LIGHT_P2_UPPER_LAMP); + p3io_lights |= + (1 << BT_IO_DDR_P3IO_LIGHT_P2_UPPER_LAMP); } else { - p3io_lights &= ~(1 << LIGHT_P2_UPPER_LAMP); + p3io_lights &= + ~(1 << BT_IO_DDR_P3IO_LIGHT_P2_UPPER_LAMP); } if (buf[3] == '1') { - p3io_lights |= (1 << LIGHT_P2_LOWER_LAMP); + p3io_lights |= + (1 << BT_IO_DDR_P3IO_LIGHT_P2_LOWER_LAMP); } else { - p3io_lights &= ~(1 << LIGHT_P2_LOWER_LAMP); + p3io_lights &= + ~(1 << BT_IO_DDR_P3IO_LIGHT_P2_LOWER_LAMP); } } @@ -272,27 +299,27 @@ int main(int argc, char **argv) } case '4': { - extio_lights |= (1 << LIGHT_NEONS); + extio_lights |= (1 << BT_IO_DDR_EXTIO_LIGHT_NEONS); - p3io_lights |= (1 << LIGHT_P1_MENU); - p3io_lights |= (1 << LIGHT_P2_MENU); - p3io_lights |= (1 << LIGHT_P1_UPPER_LAMP); - p3io_lights |= (1 << LIGHT_P1_LOWER_LAMP); - p3io_lights |= (1 << LIGHT_P2_UPPER_LAMP); - p3io_lights |= (1 << LIGHT_P2_LOWER_LAMP); + p3io_lights |= (1 << BT_IO_DDR_P3IO_LIGHT_P1_MENU); + p3io_lights |= (1 << BT_IO_DDR_P3IO_LIGHT_P2_MENU); + p3io_lights |= (1 << BT_IO_DDR_P3IO_LIGHT_P1_UPPER_LAMP); + p3io_lights |= (1 << BT_IO_DDR_P3IO_LIGHT_P1_LOWER_LAMP); + p3io_lights |= (1 << BT_IO_DDR_P3IO_LIGHT_P2_UPPER_LAMP); + p3io_lights |= (1 << BT_IO_DDR_P3IO_LIGHT_P2_LOWER_LAMP); break; } case '5': { - extio_lights &= ~(1 << LIGHT_NEONS); + extio_lights &= ~(1 << BT_IO_DDR_EXTIO_LIGHT_NEONS); - p3io_lights &= ~(1 << LIGHT_P1_MENU); - p3io_lights &= ~(1 << LIGHT_P2_MENU); - p3io_lights &= ~(1 << LIGHT_P1_UPPER_LAMP); - p3io_lights &= ~(1 << LIGHT_P1_LOWER_LAMP); - p3io_lights &= ~(1 << LIGHT_P2_UPPER_LAMP); - p3io_lights &= ~(1 << LIGHT_P2_LOWER_LAMP); + p3io_lights &= ~(1 << BT_IO_DDR_P3IO_LIGHT_P1_MENU); + p3io_lights &= ~(1 << BT_IO_DDR_P3IO_LIGHT_P2_MENU); + p3io_lights &= ~(1 << BT_IO_DDR_P3IO_LIGHT_P1_UPPER_LAMP); + p3io_lights &= ~(1 << BT_IO_DDR_P3IO_LIGHT_P1_LOWER_LAMP); + p3io_lights &= ~(1 << BT_IO_DDR_P3IO_LIGHT_P2_UPPER_LAMP); + p3io_lights &= ~(1 << BT_IO_DDR_P3IO_LIGHT_P2_LOWER_LAMP); break; } @@ -306,7 +333,10 @@ int main(int argc, char **argv) system("cls"); - ddr_io_fini(); + bt_io_ddr_fini(); + + bt_io_ddr_api_clear(); + module_io_free(&module_io_ddr); return 0; } \ No newline at end of file diff --git a/src/main/dinput/dinput.c b/src/main/dinput/dinput.c index e65928f..5486a6b 100644 --- a/src/main/dinput/dinput.c +++ b/src/main/dinput/dinput.c @@ -8,12 +8,12 @@ #include -#include "core/log.h" - #include "hook/com-proxy.h" #include "hook/pe.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" static HRESULT STDCALL my_DirectInput8Create( diff --git a/src/main/eamio-icca/Module.mk b/src/main/eamio-icca/Module.mk index bcd4be8..347ca2c 100644 --- a/src/main/eamio-icca/Module.mk +++ b/src/main/eamio-icca/Module.mk @@ -4,9 +4,11 @@ dlls += \ libs_eamio-icca := \ core \ aciodrv \ - aciomgr \ cconfig \ util \ + iface-core \ + iface-acio \ + module \ src_eamio-icca := \ config-icc.c \ diff --git a/src/main/eamio-icca/eamio-icca.c b/src/main/eamio-icca/eamio-icca.c index db0215a..50da3bd 100644 --- a/src/main/eamio-icca/eamio-icca.c +++ b/src/main/eamio-icca/eamio-icca.c @@ -10,40 +10,46 @@ #include "aciodrv/device.h" #include "aciodrv/icca.h" -#include "aciomgr/manager.h" -#include "bemanitools/eamio.h" - -#include "core/log.h" +#include "api/core/log.h" #include "cconfig/cconfig-main.h" + #include "eamio-icca/config-icc.h" +#include "iface-acio/mgr.h" +#include "iface-core/log.h" + +#include "module/acio-mgr.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/io/eam.h" + #define IDLE_RESPONSES_BETWEEN_FELICA_POLLS 5 #define NUMBER_OF_EMULATED_READERS 2 #define INVALID_NODE_ID -1 static const uint8_t eam_io_keypad_mappings[16] = { - EAM_IO_KEYPAD_DECIMAL, - EAM_IO_KEYPAD_3, - EAM_IO_KEYPAD_6, - EAM_IO_KEYPAD_9, + BT_IO_EAM_KEYPAD_SCAN_CODE_DECIMAL, + BT_IO_EAM_KEYPAD_SCAN_CODE_3, + BT_IO_EAM_KEYPAD_SCAN_CODE_6, + BT_IO_EAM_KEYPAD_SCAN_CODE_9, 0xFF, 0xFF, 0xFF, 0xFF, - EAM_IO_KEYPAD_0, - EAM_IO_KEYPAD_1, - EAM_IO_KEYPAD_4, - EAM_IO_KEYPAD_7, - EAM_IO_KEYPAD_00, - EAM_IO_KEYPAD_2, - EAM_IO_KEYPAD_5, - EAM_IO_KEYPAD_8}; + BT_IO_EAM_KEYPAD_SCAN_CODE_0, + BT_IO_EAM_KEYPAD_SCAN_CODE_1, + BT_IO_EAM_KEYPAD_SCAN_CODE_4, + BT_IO_EAM_KEYPAD_SCAN_CODE_7, + BT_IO_EAM_KEYPAD_SCAN_CODE_00, + BT_IO_EAM_KEYPAD_SCAN_CODE_2, + BT_IO_EAM_KEYPAD_SCAN_CODE_5, + BT_IO_EAM_KEYPAD_SCAN_CODE_8}; static struct ac_io_icca_state eam_io_icca_state[NUMBER_OF_EMULATED_READERS]; -static struct aciomgr_port_dispatcher *acio_manager_ctx; +static bt_acio_mgr_port_dispatcher_t *acio_manager_ctx; static int32_t icca_node_id[NUMBER_OF_EMULATED_READERS]; @@ -52,38 +58,37 @@ static bool icca_is_slotted[NUMBER_OF_EMULATED_READERS]; static int32_t icca_poll_counter[NUMBER_OF_EMULATED_READERS]; static uint8_t icca_last_nonbusy_state[NUMBER_OF_EMULATED_READERS]; -void eam_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - aciomgr_set_loggers(misc, info, warning, fatal); +static module_acio_mgr_t *_icca_module_acio_mgr; - core_log_impl_set(misc, info, warning, fatal); +static void _bt_io_eam_icca_acio_mgr_init(module_acio_mgr_t **module) +{ + bt_acio_mgr_api_t api; + + module_acio_mgr_load("acio-mgr.dll", module); + module_acio_mgr_api_get(*module, &api); + bt_acio_mgr_api_set(&api); } // all of these are referred to internally as ICCA static bool check_if_icca(int node_id) { - char product[ACIOMGR_NODE_PRODUCT_CODE_LEN]; - aciomgr_get_node_product_ident(acio_manager_ctx, node_id, product); + char product[BT_ACIO_MGR_NODE_PRODUCT_CODE_LEN]; + bt_acio_mgr_node_product_ident_get(acio_manager_ctx, node_id, product); - if (!memcmp(product, "ICCA", ACIOMGR_NODE_PRODUCT_CODE_LEN)) { + if (!memcmp(product, "ICCA", BT_ACIO_MGR_NODE_PRODUCT_CODE_LEN)) { return true; } - if (!memcmp(product, "ICCB", ACIOMGR_NODE_PRODUCT_CODE_LEN)) { + if (!memcmp(product, "ICCB", BT_ACIO_MGR_NODE_PRODUCT_CODE_LEN)) { return true; } - if (!memcmp(product, "ICCC", ACIOMGR_NODE_PRODUCT_CODE_LEN)) { + if (!memcmp(product, "ICCC", BT_ACIO_MGR_NODE_PRODUCT_CODE_LEN)) { return true; } return false; } -bool eam_io_init( - thread_create_t create, thread_join_t join, thread_destroy_t destroy) +bool bt_io_eam_init() { struct cconfig *config; struct icc_config config_icc; @@ -104,23 +109,27 @@ bool eam_io_init( exit(EXIT_FAILURE); } + _bt_io_eam_icca_acio_mgr_init(&_icca_module_acio_mgr); + eamio_icca_config_icc_get(&config_icc, config); cconfig_finit(config); - acio_manager_ctx = aciomgr_port_init(config_icc.port, config_icc.baud); + acio_manager_ctx = bt_acio_mgr_port_init(config_icc.port, config_icc.baud); if (acio_manager_ctx == NULL) { log_warning("Opening acio device on %s failed", config_icc.port); return false; } - struct aciodrv_device_ctx *device = aciomgr_port_checkout(acio_manager_ctx); + bt_acio_drv_device_ctx_t *device = + bt_acio_mgr_port_checkout(acio_manager_ctx); for (uint8_t i = 0; i < NUMBER_OF_EMULATED_READERS; i++) { icca_node_id[i] = INVALID_NODE_ID; - for (uint8_t nid = 0; nid < aciomgr_get_node_count(acio_manager_ctx); + for (uint8_t nid = 0; + nid < bt_acio_mgr_node_count_get(acio_manager_ctx); ++nid) { if (check_if_icca(nid)) { bool existing_reader = false; @@ -160,16 +169,19 @@ bool eam_io_init( return false; } - aciomgr_port_checkin(acio_manager_ctx); + bt_acio_mgr_port_checkin(acio_manager_ctx); return true; } -void eam_io_fini(void) +void bt_io_eam_fini(void) { - aciomgr_port_fini(acio_manager_ctx); + bt_acio_mgr_port_fini(acio_manager_ctx); + + bt_acio_mgr_api_clear(); + module_acio_mgr_free(&_icca_module_acio_mgr); } -uint16_t eam_io_get_keypad_state(uint8_t unit_no) +uint16_t bt_io_eam_keypad_state_get(uint8_t unit_no) { uint16_t keypad_result = 0; @@ -184,18 +196,18 @@ uint16_t eam_io_get_keypad_state(uint8_t unit_no) return keypad_result; } -uint8_t eam_io_get_sensor_state(uint8_t unit_no) +uint8_t bt_io_eam_sensor_state_get(uint8_t unit_no) { uint8_t sensors = 0; if (icca_is_slotted[unit_no]) { if ((eam_io_icca_state[unit_no].sensor_state & AC_IO_ICCA_SENSOR_MASK_BACK_ON) > 0) { - sensors |= (1 << EAM_IO_SENSOR_BACK); + sensors |= (1 << BT_IO_EAM_SENSOR_STATE_BACK); } if ((eam_io_icca_state[unit_no].sensor_state & AC_IO_ICCA_SENSOR_MASK_FRONT_ON) > 0) { - sensors |= (1 << EAM_IO_SENSOR_FRONT); + sensors |= (1 << BT_IO_EAM_SENSOR_STATE_FRONT); } } else { // wavepass readers always report (EAM_IO_SENSOR_BACK + @@ -205,8 +217,8 @@ uint8_t eam_io_get_sensor_state(uint8_t unit_no) // reader so the emulation takes card of it if (eam_io_icca_state[unit_no].status_code == AC_IO_ICCA_STATUS_GOT_UID) { - sensors |= (1 << EAM_IO_SENSOR_BACK); - sensors |= (1 << EAM_IO_SENSOR_FRONT); + sensors |= (1 << BT_IO_EAM_SENSOR_STATE_BACK); + sensors |= (1 << BT_IO_EAM_SENSOR_STATE_FRONT); } // continue reporting last state during busy @@ -221,17 +233,17 @@ uint8_t eam_io_get_sensor_state(uint8_t unit_no) return sensors; } -uint8_t eam_io_read_card(uint8_t unit_no, uint8_t *card_id, uint8_t nbytes) +uint8_t bt_io_eam_card_read(uint8_t unit_no, uint8_t *card_id, uint8_t nbytes) { memcpy(card_id, eam_io_icca_state[unit_no].uid, nbytes); if (card_id[0] == 0xe0 && card_id[1] == 0x04) { - return EAM_IO_CARD_ISO15696; + return BT_IO_EAM_READ_CARD_RESULT_ISO15696; } else { - return EAM_IO_CARD_FELICA; + return BT_IO_EAM_READ_CARD_RESULT_FELICA; } } -bool eam_io_card_slot_cmd(uint8_t unit_no, uint8_t cmd) +bool bt_io_eam_card_slot_cmd_send(uint8_t unit_no, uint8_t cmd) { // this node is not setup, just return "success"" if (icca_node_id[unit_no] == INVALID_NODE_ID) { @@ -243,32 +255,33 @@ bool eam_io_card_slot_cmd(uint8_t unit_no, uint8_t cmd) return true; } - struct aciodrv_device_ctx *device = aciomgr_port_checkout(acio_manager_ctx); + struct aciodrv_device_ctx *device = + bt_acio_mgr_port_checkout(acio_manager_ctx); bool response = false; switch (cmd) { - case EAM_IO_CARD_SLOT_CMD_CLOSE: + case BT_IO_EAM_CARD_SLOT_CMD_CLOSE: response = aciodrv_icca_set_state( device, icca_node_id[unit_no], AC_IO_ICCA_SLOT_STATE_CLOSE, NULL); - case EAM_IO_CARD_SLOT_CMD_OPEN: + case BT_IO_EAM_CARD_SLOT_CMD_OPEN: response = aciodrv_icca_set_state( device, icca_node_id[unit_no], AC_IO_ICCA_SLOT_STATE_OPEN, NULL); - case EAM_IO_CARD_SLOT_CMD_EJECT: + case BT_IO_EAM_CARD_SLOT_CMD_EJECT: response = aciodrv_icca_set_state( device, icca_node_id[unit_no], AC_IO_ICCA_SLOT_STATE_EJECT, NULL); - case EAM_IO_CARD_SLOT_CMD_READ: + case BT_IO_EAM_CARD_SLOT_CMD_READ: response = aciodrv_icca_read_card(device, icca_node_id[unit_no], NULL) && aciodrv_icca_get_state( @@ -277,12 +290,12 @@ bool eam_io_card_slot_cmd(uint8_t unit_no, uint8_t cmd) default: break; } - aciomgr_port_checkin(acio_manager_ctx); + bt_acio_mgr_port_checkin(acio_manager_ctx); return response; } -bool eam_io_poll(uint8_t unit_no) +bool bt_io_eam_poll(uint8_t unit_no) { // this node is not setup, just return "success"" if (icca_node_id[unit_no] == INVALID_NODE_ID) { @@ -290,10 +303,10 @@ bool eam_io_poll(uint8_t unit_no) } bool response = aciodrv_icca_get_state( - aciomgr_port_checkout(acio_manager_ctx), + bt_acio_mgr_port_checkout(acio_manager_ctx), icca_node_id[unit_no], &eam_io_icca_state[unit_no]); - aciomgr_port_checkin(acio_manager_ctx); + bt_acio_mgr_port_checkin(acio_manager_ctx); if (response && !icca_is_slotted[unit_no]) { // we handle wavepass a bit differently to handle polling felica @@ -308,8 +321,9 @@ bool eam_io_poll(uint8_t unit_no) // the last AC_IO_ICCA_STATUS_BUSY_NEW message if (icca_poll_counter[unit_no] >= IDLE_RESPONSES_BETWEEN_FELICA_POLLS) { response = aciodrv_icca_poll_felica( - aciomgr_port_checkout(acio_manager_ctx), icca_node_id[unit_no]); - aciomgr_port_checkin(acio_manager_ctx); + bt_acio_mgr_port_checkout(acio_manager_ctx), + icca_node_id[unit_no]); + bt_acio_mgr_port_checkin(acio_manager_ctx); icca_poll_counter[unit_no] = 0; } @@ -318,11 +332,30 @@ bool eam_io_poll(uint8_t unit_no) return response; } -const struct eam_io_config_api *eam_io_get_config_api(void) +const bt_io_eam_config_api_t *bt_io_eam_config_api_get(void) { return NULL; } +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_io_eam_api_get(bt_io_eam_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_eam_init; + api->v1.fini = bt_io_eam_fini; + api->v1.keypad_state_get = bt_io_eam_keypad_state_get; + api->v1.sensor_state_get = bt_io_eam_sensor_state_get; + api->v1.card_read = bt_io_eam_card_read; + api->v1.card_slot_cmd_send = bt_io_eam_card_slot_cmd_send; + api->v1.poll = bt_io_eam_poll; + api->v1.config_api_get = bt_io_eam_config_api_get; +} + BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *ctx) { return TRUE; diff --git a/src/main/eamio-icca/eamio-icca.def b/src/main/eamio-icca/eamio-icca.def index 38a7030..c37f90a 100644 --- a/src/main/eamio-icca/eamio-icca.def +++ b/src/main/eamio-icca/eamio-icca.def @@ -1,12 +1,16 @@ LIBRARY eamio-icca EXPORTS - eam_io_fini - eam_io_init - eam_io_get_config_api - eam_io_get_keypad_state - eam_io_get_sensor_state - eam_io_read_card - eam_io_card_slot_cmd - eam_io_set_loggers - eam_io_poll + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_io_eam_api_get + + ; Direct API + bt_io_eam_init + bt_io_eam_fini + bt_io_eam_keypad_state_get + bt_io_eam_sensor_state_get + bt_io_eam_card_read + bt_io_eam_card_slot_cmd_send + bt_io_eam_poll + bt_io_eam_config_api_get diff --git a/src/main/eamio/Module.mk b/src/main/eamio/Module.mk index 9cf82ed..89edd19 100644 --- a/src/main/eamio/Module.mk +++ b/src/main/eamio/Module.mk @@ -1,5 +1,5 @@ dlls += eamio -libs_eamio := core geninput util +libs_eamio := iface-core iface core geninput util module src_eamio := \ eam-api.c \ eam-impl.c \ diff --git a/src/main/eamio/eam-api.c b/src/main/eamio/eam-api.c index 9d2857d..5ca6d06 100644 --- a/src/main/eamio/eam-api.c +++ b/src/main/eamio/eam-api.c @@ -8,11 +8,22 @@ #include #include -#include "bemanitools/eamio.h" -#include "bemanitools/input.h" +#include "api/core/log.h" +#include "api/core/thread.h" -#include "core/log.h" -#include "core/thread.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface/input.h" + +#include "module/input.h" + +#include "main/module/input-ext.h" +#include "main/module/input.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/input.h" +#include "sdk/module/io/eam.h" #include "eamio/eam-config.h" #include "eamio/eam-impl.h" @@ -34,10 +45,11 @@ static void eam_io_set_keypad_device(uint8_t unit_no, struct hid_stub *hid); static const char *eam_io_get_card_path(uint8_t unit_no); static void eam_io_set_card_path(uint8_t unit_no, const char *path); +static module_input_t *_eam_io_module_input; static HANDLE eam_hinst; static struct eam *eam_inst; -static const struct eam_io_config_api eam_io_config_api = { +static const struct bt_io_eam_config_api eam_io_config_api = { .config_save = eam_io_config_save, .get_autogen = eam_io_get_autogen, .set_autogen = eam_io_set_autogen, @@ -103,20 +115,21 @@ static FILE *eam_io_config_open(const char *mode) return fopen_appdata("DJHACKERS", "eam_v4_22.bin", mode); } -void eam_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) +bool bt_io_eam_init() { - core_log_impl_set(misc, info, warning, fatal); -} + bool result; + bt_input_api_t input_api; + + module_input_ext_load_and_init("geninput.dll", &_eam_io_module_input); + module_input_api_get(_eam_io_module_input, &input_api); + bt_input_api_set(&input_api); + + result = bt_input_init(); + + if (!result) { + return false; + } -bool eam_io_init( - thread_create_t create, thread_join_t join, thread_destroy_t destroy) -{ - input_init(create, join, destroy); - core_thread_impl_set(create, join, destroy); eam_io_config_load(); msg_thread_init(eam_hinst); @@ -157,14 +170,16 @@ open_fail: eam_inst = eam_impl_create(); } -void eam_io_fini(void) +void bt_io_eam_fini(void) { msg_thread_fini(); eam_impl_destroy(eam_inst); - input_fini(); + + bt_input_api_clear(); + module_input_free(&_eam_io_module_input); } -const struct eam_io_config_api *eam_io_get_config_api(void) +const bt_io_eam_config_api_t *bt_io_eam_config_api_get(void) { return &eam_io_config_api; } @@ -223,37 +238,62 @@ static void eam_io_set_card_path(uint8_t unit_no, const char *path) eam_impl_set_card_path(eam_inst, unit_no, path); } -uint16_t eam_io_get_keypad_state(uint8_t unit_no) +uint16_t bt_io_eam_keypad_state_get(uint8_t unit_no) { return eam_impl_get_keypad_state(eam_inst, unit_no); } -uint8_t eam_io_get_sensor_state(uint8_t unit_no) +uint8_t bt_io_eam_sensor_state_get(uint8_t unit_no) { if (eam_impl_get_sensor_state(eam_inst, unit_no)) { - return (1 << EAM_IO_SENSOR_FRONT) | (1 << EAM_IO_SENSOR_BACK); + return (1 << BT_IO_EAM_SENSOR_STATE_FRONT) | + (1 << BT_IO_EAM_SENSOR_STATE_BACK); } else { return 0x00; } } -uint8_t eam_io_read_card(uint8_t unit_no, uint8_t *card_id, uint8_t nbytes) +uint8_t bt_io_eam_card_read(uint8_t unit_no, uint8_t *card_id, uint8_t nbytes) { return eam_impl_read_card(eam_inst, unit_no, card_id, nbytes); } -bool eam_io_card_slot_cmd(uint8_t unit_no, uint8_t cmd) +bool bt_io_eam_card_slot_cmd_send(uint8_t unit_no, uint8_t cmd) { // ignored return true; } -bool eam_io_poll(uint8_t unit_no) +bool bt_io_eam_poll(uint8_t unit_no) { // ignored return true; } +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_io_eam_api_get(bt_io_eam_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_eam_init; + api->v1.fini = bt_io_eam_fini; + api->v1.keypad_state_get = bt_io_eam_keypad_state_get; + api->v1.sensor_state_get = bt_io_eam_sensor_state_get; + api->v1.card_read = bt_io_eam_card_read; + api->v1.card_slot_cmd_send = bt_io_eam_card_slot_cmd_send; + api->v1.poll = bt_io_eam_poll; + api->v1.config_api_get = bt_io_eam_config_api_get; +} + BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { diff --git a/src/main/eamio/eam-config.h b/src/main/eamio/eam-config.h index ebf4812..ad7c5fe 100644 --- a/src/main/eamio/eam-config.h +++ b/src/main/eamio/eam-config.h @@ -1,9 +1,9 @@ #ifndef EAMIO_CONFIG_H #define EAMIO_CONFIG_H -#include "bemanitools/eamio.h" +#include "api/io/eam.h" -struct eam_io_config_api { +struct bt_io_eam_config_api { void (*config_save)(void); bool (*get_autogen)(void); void (*set_autogen)(bool autogen); diff --git a/src/main/eamio/eam-impl.c b/src/main/eamio/eam-impl.c index 6aca589..3e44a28 100644 --- a/src/main/eamio/eam-impl.c +++ b/src/main/eamio/eam-impl.c @@ -7,14 +7,14 @@ #include #include -#include "bemanitools/eamio.h" - -#include "core/log.h" +#include "api/io/eam.h" #include "eamio/eam-impl.h" #include "geninput/hid-mgr.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/fs.h" #include "util/hex.h" @@ -26,7 +26,7 @@ struct eam_unit { char *card_path; struct hid_stub *hid; - size_t keypad_ctls[EAM_IO_KEYPAD_COUNT]; + size_t keypad_ctls[BT_IO_EAM_KEYPAD_COUNT]; size_t sensor_ctl; bool bound_ctls; uint8_t drive_no; @@ -46,7 +46,7 @@ struct eam { bool mux; }; -static const uint32_t eam_keypad_usages[EAM_IO_KEYPAD_COUNT + 1] = { +static const uint32_t eam_keypad_usages[BT_IO_EAM_KEYPAD_COUNT + 1] = { /* [EAM_KEYPAD_0] = */ 0x00070062, /* [EAM_KEYPAD_1] = */ 0x00070059, /* [EAM_KEYPAD_4] = */ 0x0007005C, @@ -61,7 +61,7 @@ static const uint32_t eam_keypad_usages[EAM_IO_KEYPAD_COUNT + 1] = { /* [EAM_KEYPAD_9] = */ 0x00070061, /* Sensor = */ 0x00070057}; -static const uint32_t eam_keypad_usages_alt[EAM_IO_KEYPAD_COUNT + 1] = { +static const uint32_t eam_keypad_usages_alt[BT_IO_EAM_KEYPAD_COUNT + 1] = { /* [EAM_KEYPAD_0] = */ 0x00070027, /* [EAM_KEYPAD_1] = */ 0x0007001E, /* [EAM_KEYPAD_4] = */ 0x00070021, @@ -271,13 +271,13 @@ static void eam_impl_bind_keypad(struct eam *eam, uint8_t unit_no) } for (control_no = 0; control_no < ncontrols; control_no++) { - for (btn_no = 0; btn_no < EAM_IO_KEYPAD_COUNT; btn_no++) { + for (btn_no = 0; btn_no < BT_IO_EAM_KEYPAD_COUNT; btn_no++) { if (controls[control_no].usage == usages[btn_no]) { unit->keypad_ctls[btn_no] = control_no; } } - if (controls[control_no].usage == usages[EAM_IO_KEYPAD_COUNT]) { + if (controls[control_no].usage == usages[BT_IO_EAM_KEYPAD_COUNT]) { unit->sensor_ctl = control_no; } } @@ -425,9 +425,9 @@ uint8_t eam_impl_read_card( fclose(f); if (card_id[0] == 0xe0 && card_id[1] == 0x04) { - return EAM_IO_CARD_ISO15696; + return BT_IO_EAM_READ_CARD_RESULT_ISO15696; } else { - return EAM_IO_CARD_FELICA; + return BT_IO_EAM_READ_CARD_RESULT_FELICA; } decode_fail: @@ -437,7 +437,7 @@ fgets_fail: fopen_fail: path_fail: - return EAM_IO_CARD_NONE; + return BT_IO_EAM_READ_CARD_RESULT_NONE; } static bool eam_impl_autogen(struct eam_unit *unit, uint8_t *card_id) diff --git a/src/main/eamio/eam-impl.h b/src/main/eamio/eam-impl.h index 486314d..231935d 100644 --- a/src/main/eamio/eam-impl.h +++ b/src/main/eamio/eam-impl.h @@ -5,7 +5,7 @@ #include #include -#include "bemanitools/eamio.h" +#include "api/io/eam.h" #include "geninput/hid-mgr.h" diff --git a/src/main/eamio/eamio.def b/src/main/eamio/eamio.def index 7bfca97..3a7e353 100644 --- a/src/main/eamio/eamio.def +++ b/src/main/eamio/eamio.def @@ -1,12 +1,17 @@ LIBRARY eamio EXPORTS - eam_io_fini - eam_io_init - eam_io_get_config_api - eam_io_get_keypad_state - eam_io_get_sensor_state - eam_io_read_card - eam_io_card_slot_cmd - eam_io_set_loggers - eam_io_poll + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_io_eam_api_get + + ; Direct API + bt_io_eam_init + bt_io_eam_fini + bt_io_eam_keypad_state_get + bt_io_eam_sensor_state_get + bt_io_eam_card_read + bt_io_eam_card_slot_cmd_send + bt_io_eam_poll + bt_io_eam_config_api_get diff --git a/src/main/eamiotest/Module.mk b/src/main/eamiotest/Module.mk index 0b9fd4b..124fc95 100644 --- a/src/main/eamiotest/Module.mk +++ b/src/main/eamiotest/Module.mk @@ -2,8 +2,10 @@ exes += eamiotest libs_eamiotest := \ core \ - eamio \ util \ + module \ + iface-core \ + iface-io \ src_eamiotest := \ main.c \ diff --git a/src/main/eamiotest/main.c b/src/main/eamiotest/main.c index a2f410f..ce621ab 100644 --- a/src/main/eamiotest/main.c +++ b/src/main/eamiotest/main.c @@ -1,42 +1,60 @@ +#include + #include #include #include #include -#include - -#include "bemanitools/eamio.h" - #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" -#include "core/thread-crt.h" -#include "core/thread.h" +#include "core/log-sink-std.h" + +#include "iface-core/log.h" +#include "iface-io/eam.h" + +#include "module/io-ext.h" + +static void _eamiotest_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} /** * Tool to test your implementations of eamio. */ int main(int argc, char **argv) { - core_thread_crt_ext_impl_set(); - core_log_bt_ext_impl_set(); + module_io_t *module_io_eam; - core_log_bt_ext_init_with_stdout(); + core_log_bt_core_api_set(); - core_log_impl_assign(eam_io_set_loggers); + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _eamiotest_io_eam_init(&module_io_eam); + + if (!bt_io_eam_init()) { printf("Initializing eamio failed\n"); + + bt_io_eam_api_clear(); + module_io_free(&module_io_eam); + return -1; } printf(">>> Initializing eamio successful, press enter to continue <<<\n"); if (getchar() != '\n') { + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&module_io_eam); + return 0; } @@ -54,15 +72,15 @@ int main(int argc, char **argv) } for (uint8_t node = 0; node < 2; ++node) { - if (!eam_io_poll(node)) { + if (!bt_io_eam_poll(node)) { printf("ERROR: Polling node %d failed", node); return -2; } - uint16_t keypad = eam_io_get_keypad_state(node); + uint16_t keypad = bt_io_eam_keypad_state_get(node); uint16_t keypad_rise = ~keypad_prev[node] & keypad; - uint8_t sensors = eam_io_get_sensor_state(node); + uint8_t sensors = bt_io_eam_sensor_state_get(node); printf( "Press escape to quit\n" @@ -78,20 +96,20 @@ int main(int argc, char **argv) "|%02X%02X%02X%02X%02X%02X%02X%02X|\n" "------------------\n", node, - (keypad & (1 << EAM_IO_KEYPAD_7)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_8)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_9)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_4)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_5)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_6)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_1)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_2)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_3)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_0)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_00)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_DECIMAL)) > 0, - (sensors & (1 << EAM_IO_SENSOR_FRONT)) > 0, - (sensors & (1 << EAM_IO_SENSOR_BACK)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_7)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_8)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_9)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_4)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_5)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_6)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_1)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_2)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_3)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_0)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_00)) > 0, + (keypad & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_DECIMAL)) > 0, + (sensors & (1 << BT_IO_EAM_SENSOR_STATE_FRONT)) > 0, + (sensors & (1 << BT_IO_EAM_SENSOR_STATE_BACK)) > 0, card[node][0], card[node][1], card[node][2], @@ -101,24 +119,29 @@ int main(int argc, char **argv) card[node][6], card[node][7]); - if (sensors & (1 << EAM_IO_SENSOR_BACK)) { - eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_CLOSE); - eam_io_poll(node); - eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_READ); - eam_io_poll(node); - eam_io_read_card(node, card[node], 8); + if (sensors & (1 << BT_IO_EAM_SENSOR_STATE_BACK)) { + bt_io_eam_card_slot_cmd_send( + node, BT_IO_EAM_CARD_SLOT_CMD_CLOSE); + bt_io_eam_poll(node); + bt_io_eam_card_slot_cmd_send( + node, BT_IO_EAM_CARD_SLOT_CMD_READ); + bt_io_eam_poll(node); + bt_io_eam_card_read(node, card[node], 8); } if (sensors == 0) { memset(card[node], 0, 8); - eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_CLOSE); - eam_io_poll(node); - eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_OPEN); + bt_io_eam_card_slot_cmd_send( + node, BT_IO_EAM_CARD_SLOT_CMD_CLOSE); + bt_io_eam_poll(node); + bt_io_eam_card_slot_cmd_send( + node, BT_IO_EAM_CARD_SLOT_CMD_OPEN); } - if (keypad_rise & (1 << EAM_IO_KEYPAD_DECIMAL)) { - eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_EJECT); + if (keypad_rise & (1 << BT_IO_EAM_KEYPAD_SCAN_CODE_DECIMAL)) { + bt_io_eam_card_slot_cmd_send( + node, BT_IO_EAM_CARD_SLOT_CMD_EJECT); } keypad_prev[node] = keypad; @@ -128,7 +151,10 @@ int main(int argc, char **argv) Sleep(5); } - eam_io_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&module_io_eam); return 0; } \ No newline at end of file diff --git a/src/main/exceptiontrace/Module.mk b/src/main/exceptiontrace/Module.mk new file mode 100644 index 0000000..6396594 --- /dev/null +++ b/src/main/exceptiontrace/Module.mk @@ -0,0 +1,9 @@ +dlls += exceptiontrace + +libs_exceptiontrace := \ + core \ + hook \ + util \ + +src_exceptiontrace := \ + dllmain.c \ diff --git a/src/main/exceptiontrace/dllmain.c b/src/main/exceptiontrace/dllmain.c new file mode 100644 index 0000000..71f1a58 --- /dev/null +++ b/src/main/exceptiontrace/dllmain.c @@ -0,0 +1,6 @@ +#include + +BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) +{ + return TRUE; +} diff --git a/src/main/exceptiontrace/exceptiontrace.c b/src/main/exceptiontrace/exceptiontrace.c new file mode 100644 index 0000000..84eb298 --- /dev/null +++ b/src/main/exceptiontrace/exceptiontrace.c @@ -0,0 +1,138 @@ +#define LOG_MODULE "exceptiontrace" + +#include + +#include + +#include "core/log.h" + +#include "imports/dwarfstack.h" + +#include "util/debug.h" + +#define log_exception(...) _debug_exception_msg("exception", __VA_ARGS__) + +static core_log_message_t _debug_exception_msg; + +static void _debug_stacktrace_printer( + uint64_t addr, + const char *filename, + int lineno, + const char *funcname, + void *context, + int columnno) +{ + int *count; + const char *delim; + void *ptr; + char buffer[512]; + char *buffer_ptr; + + count = context; + delim = strrchr(filename, '/'); + + if (delim) { + filename = delim + 1; + } + + delim = strrchr(filename, '\\'); + + if (delim) { + filename = delim + 1; + } + + ptr = (void *) (uintptr_t) addr; + + switch (lineno) { + case DWST_BASE_ADDR: + log_exception("base address: 0x%p (%s)", ptr, filename); + break; + + case DWST_NOT_FOUND: + case DWST_NO_DBG_SYM: + case DWST_NO_SRC_FILE: + log_exception( + " stack %02d: 0x%p (%s)", (*count)++, ptr, filename); + break; + + default: + buffer_ptr = buffer; + memset(buffer, 0, sizeof(buffer)); + + if (ptr) { + buffer_ptr += sprintf( + buffer_ptr, " stack %02d: 0x%p", (*count)++, ptr); + } else { + buffer_ptr += sprintf( + buffer_ptr, + " %*s", + (int) sizeof(void *) * 2, + ""); + } + + buffer_ptr += sprintf(buffer_ptr, " (%s:%d", filename, lineno); + + if (columnno > 0) { + buffer_ptr += sprintf(buffer_ptr, ":%d", columnno); + } + + buffer_ptr += sprintf(buffer_ptr, ")"); + + if (funcname) { + buffer_ptr += sprintf(buffer_ptr, " [%s]", funcname); + } + + log_exception(buffer); + + break; + } +} + +static LONG WINAPI _debug_unhandled_exception_filter(LPEXCEPTION_POINTERS ep) +{ + DWORD code; + const char *desc; + ULONG_PTR flag; + ULONG_PTR addr; + int count; + + log_exception("=========================================================="); + log_exception("The application has crashed due to an unhandled exception!"); + + code = ep->ExceptionRecord->ExceptionCode; + desc = debug_exception_code_to_str(code); + + log_exception("code: 0x%08lX", code); + log_exception("desc: %s", desc); + + if (code == EXCEPTION_ACCESS_VIOLATION && + ep->ExceptionRecord->NumberParameters == 2) { + flag = ep->ExceptionRecord->ExceptionInformation[0]; + addr = ep->ExceptionRecord->ExceptionInformation[1]; + + log_exception( + "%s violation at 0x%p", + flag == 8 ? "data execution prevention" : + (flag ? "write access" : "read access"), + (void *) addr); + } + + log_exception("stacktrace:"); + + count = 0; + + dwstOfException(ep->ContextRecord, &_debug_stacktrace_printer, &count); + + log_exception("End of stacktrace"); + log_exception("=========================================================="); + + return EXCEPTION_EXECUTE_HANDLER; +} + +void debug_init(core_log_message_t exception_msg) +{ + _debug_exception_msg = exception_msg; + SetUnhandledExceptionFilter(_debug_unhandled_exception_filter); + + log_info("Initialized"); +} diff --git a/src/main/exceptiontrace/exceptiontrace.def b/src/main/exceptiontrace/exceptiontrace.def new file mode 100644 index 0000000..734cfc9 --- /dev/null +++ b/src/main/exceptiontrace/exceptiontrace.def @@ -0,0 +1,8 @@ +LIBRARY exceptiontrace + +EXPORTS + DllMain@12 @1 NONAME + btapi_hook_core_thread_impl_set + btapi_hook_core_log_impl_set + btapi_hook_main_init + btapi_hook_main_fini diff --git a/src/main/exceptiontrace/exceptiontrace.h b/src/main/exceptiontrace/exceptiontrace.h new file mode 100644 index 0000000..5718d63 --- /dev/null +++ b/src/main/exceptiontrace/exceptiontrace.h @@ -0,0 +1,8 @@ +#ifndef EXCEPTIONTRACE_EXCEPTIONTRACE_H +#define EXCEPTIONTRACE_EXCEPTIONTRACE_H + +#include "core/log.h" + +void exceptiontrace_init(core_log_message_t exception_msg); + +#endif \ No newline at end of file diff --git a/src/main/exceptiontrace/hook.c b/src/main/exceptiontrace/hook.c new file mode 100644 index 0000000..a810d8f --- /dev/null +++ b/src/main/exceptiontrace/hook.c @@ -0,0 +1,41 @@ +#define LOG_MODULE "exceptiontrance-hook" + +#include + +#include +#include + +#include "core/log.h" +#include "core/thread.h" + +#include "exceptiontrace/exceptiontrace.h" + +void btapi_hook_core_thread_impl_set( + btapi_thread_create_t create, + btapi_thread_join_t join, + btapi_thread_destroy_t destroy) +{ + core_thread_impl_set(create, join, destroy); +} + +void btapi_hook_core_log_impl_set( + btapi_log_formatter_t misc, + btapi_log_formatter_t info, + btapi_log_formatter_t warning, + btapi_log_formatter_t fatal) +{ + core_log_impl_set(misc, info, warning, fatal); +} + +bool btapi_hook_main_init( + HMODULE game_module, struct property_node *property_node_config) +{ + exceptiontrace_init(core_log_fatal_impl_get()); + + return true; +} + +void btapi_hook_main_fini() +{ + // noop +} \ No newline at end of file diff --git a/src/main/exceptiontrace/hook.h b/src/main/exceptiontrace/hook.h new file mode 100644 index 0000000..45f212e --- /dev/null +++ b/src/main/exceptiontrace/hook.h @@ -0,0 +1,20 @@ +#ifndef EXCEPTIONTRACE_HOOK_H +#define EXCEPTIONTRACE_HOOK_H + +#include "btapi/hook-core.h" +#include "btapi/hook-main.h" + +void btapi_hook_core_thread_impl_set( + btapi_thread_create_t create, + btapi_thread_join_t join, + btapi_thread_destroy_t destroy); +void btapi_hook_core_log_impl_set( + btapi_log_formatter_t misc, + btapi_log_formatter_t info, + btapi_log_formatter_t warning, + btapi_log_formatter_t fatal); +bool btapi_hook_main_init( + HMODULE game_module, struct property_node *property_node_config); +void btapi_hook_main_fini(); + +#endif \ No newline at end of file diff --git a/src/main/extiodrv/device.c b/src/main/extiodrv/device.c index e6bc788..9f32f9d 100644 --- a/src/main/extiodrv/device.c +++ b/src/main/extiodrv/device.c @@ -2,7 +2,7 @@ #include "device.h" -#include "core/log.h" +#include "iface-core/log.h" HRESULT extiodrv_device_open(const char *port, HANDLE *handle) { diff --git a/src/main/extiodrv/extio.c b/src/main/extiodrv/extio.c index 5b1ae6a..ef01183 100644 --- a/src/main/extiodrv/extio.c +++ b/src/main/extiodrv/extio.c @@ -2,7 +2,7 @@ #include "extio.h" -#include "core/log.h" +#include "iface-core/log.h" // static uint8_t _extiodrv_extio_sensor_read_mode_map[5] = { // 1, // all diff --git a/src/main/extiotest/Module.mk b/src/main/extiotest/Module.mk index 3e05ba0..bcb245f 100644 --- a/src/main/extiotest/Module.mk +++ b/src/main/extiotest/Module.mk @@ -5,6 +5,7 @@ libs_extiotest := \ extio \ core \ util \ + iface-core \ src_extiotest := \ main.c \ diff --git a/src/main/extiotest/main.c b/src/main/extiotest/main.c index c9e48ba..533b826 100644 --- a/src/main/extiotest/main.c +++ b/src/main/extiotest/main.c @@ -7,13 +7,14 @@ #include "core/log-bt.h" #include "core/log-sink-std.h" -#include "core/log.h" + +#include "iface-core/log.h" #include "extiodrv/extio.h" int main(int argc, char **argv) { - struct core_log_sink log_sink; + core_log_sink_t log_sink; HRESULT hr; const char *port; HANDLE handle; @@ -25,6 +26,8 @@ int main(int argc, char **argv) fprintf(stderr, " COM_PORT: For example COM1\n"); } + core_log_bt_core_api_set(); + core_log_sink_std_err_open(true, &log_sink); core_log_bt_init(&log_sink); core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); diff --git a/src/main/ezusb-emu/device.c b/src/main/ezusb-emu/device.c index 9cf5c98..a2a7578 100644 --- a/src/main/ezusb-emu/device.c +++ b/src/main/ezusb-emu/device.c @@ -9,8 +9,6 @@ #include -#include "core/log.h" - #include "ezusb/ezusbsys2.h" #include "ezusb/util.h" @@ -22,6 +20,8 @@ #include "hook/iohook.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "util/fs.h" diff --git a/src/main/ezusb-emu/node-coin.c b/src/main/ezusb-emu/node-coin.c index 6b4aed1..6b39275 100644 --- a/src/main/ezusb-emu/node-coin.c +++ b/src/main/ezusb-emu/node-coin.c @@ -1,11 +1,11 @@ #define LOG_MODULE "ezusb-emu-node-coin" -#include "core/log.h" - #include "ezusb-emu/node-coin.h" #include "ezusb-iidx/coin-cmd.h" +#include "iface-core/log.h" + static uint8_t ezusb_iidx_emu_node_coin_mode = 0; uint8_t ezusb_iidx_emu_node_coin_process_cmd( diff --git a/src/main/ezusb-emu/node-eeprom.c b/src/main/ezusb-emu/node-eeprom.c index f63d866..de066c2 100644 --- a/src/main/ezusb-emu/node-eeprom.c +++ b/src/main/ezusb-emu/node-eeprom.c @@ -2,12 +2,12 @@ #include -#include "core/log.h" - #include "ezusb-emu/node-eeprom.h" #include "ezusb-iidx/eeprom-cmd.h" +#include "iface-core/log.h" + /* not verified, but we got calls with 3 pages only so far */ #define EEPROM_NPAGES 3 diff --git a/src/main/ezusb-emu/node-security-mem.c b/src/main/ezusb-emu/node-security-mem.c index 8d11c5f..d213d3c 100644 --- a/src/main/ezusb-emu/node-security-mem.c +++ b/src/main/ezusb-emu/node-security-mem.c @@ -2,11 +2,11 @@ #include -#include "core/log.h" - #include "ezusb-emu/node-security-mem.h" #include "ezusb-iidx/secmem-cmd.h" +#include "iface-core/log.h" + #define SECURITY2_NPAGES 5 /* Starting GOLD with the new IO2 (C02 is not affected), the game does not diff --git a/src/main/ezusb-emu/node-security-plug.c b/src/main/ezusb-emu/node-security-plug.c index ed57eed..4dde254 100644 --- a/src/main/ezusb-emu/node-security-plug.c +++ b/src/main/ezusb-emu/node-security-plug.c @@ -2,13 +2,13 @@ #include -#include "core/log.h" - #include "ezusb-emu/node-eeprom.h" #include "ezusb-emu/node-security-mem.h" #include "ezusb-emu/node-security-plug.h" #include "ezusb-iidx/secplug-cmd.h" +#include "iface-core/log.h" + #include "security/rp.h" #include "security/rp2.h" #include "security/util.h" diff --git a/src/main/ezusb-emu/node-sram.c b/src/main/ezusb-emu/node-sram.c index dc3846b..c1e4cfa 100644 --- a/src/main/ezusb-emu/node-sram.c +++ b/src/main/ezusb-emu/node-sram.c @@ -2,12 +2,12 @@ #include -#include "core/log.h" - #include "ezusb-emu/conf.h" #include "ezusb-emu/node-sram.h" #include "ezusb-iidx/sram-cmd.h" +#include "iface-core/log.h" + #include "util/fs.h" #define SRAM_NPAGES 12 diff --git a/src/main/ezusb-emu/node-wdt.c b/src/main/ezusb-emu/node-wdt.c index 8c5c541..971db1f 100644 --- a/src/main/ezusb-emu/node-wdt.c +++ b/src/main/ezusb-emu/node-wdt.c @@ -1,10 +1,10 @@ #define LOG_MODULE "ezusb-emu-node-wdt" -#include "core/log.h" - #include "ezusb-emu/node-wdt.h" #include "ezusb-iidx/wdt-cmd.h" +#include "iface-core/log.h" + uint8_t ezusb_iidx_emu_node_wdt_process_cmd( uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { diff --git a/src/main/ezusb-emu/util.c b/src/main/ezusb-emu/util.c index 30edd42..a82d1a0 100644 --- a/src/main/ezusb-emu/util.c +++ b/src/main/ezusb-emu/util.c @@ -6,10 +6,10 @@ #include #include -#include "core/log.h" - #include "ezusb-emu/util.h" +#include "iface-core/log.h" + #include "util/hex.h" enum ezusb_pipe { diff --git a/src/main/ezusb-iidx-16seg-emu/node-16seg.c b/src/main/ezusb-iidx-16seg-emu/node-16seg.c index 2121235..e823d47 100644 --- a/src/main/ezusb-iidx-16seg-emu/node-16seg.c +++ b/src/main/ezusb-iidx-16seg-emu/node-16seg.c @@ -4,9 +4,8 @@ #include -#include "bemanitools/iidxio.h" - -#include "core/log.h" +#include "iface-core/log.h" +#include "iface-io/iidx.h" #include "ezusb-iidx/seg16-cmd.h" @@ -38,5 +37,5 @@ bool ezusb_iidx_emu_node_16seg_write_packet( memcpy(_16seg, pkg->payload, 9); _16seg[9] = '\0'; - return iidx_io_ep3_write_16seg(_16seg); + return bt_io_iidx_ep3_16seg_send(_16seg); } \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/card-mag.c b/src/main/ezusb-iidx-emu/card-mag.c index b65414e..d87f2a0 100644 --- a/src/main/ezusb-iidx-emu/card-mag.c +++ b/src/main/ezusb-iidx-emu/card-mag.c @@ -2,7 +2,7 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "security/mcode.h" diff --git a/src/main/ezusb-iidx-emu/msg.c b/src/main/ezusb-iidx-emu/msg.c index 76b9742..88e8d20 100644 --- a/src/main/ezusb-iidx-emu/msg.c +++ b/src/main/ezusb-iidx-emu/msg.c @@ -4,12 +4,6 @@ #include #include -#include "bemanitools/iidxio.h" - -#include "core/log.h" - -#include "hook/iohook.h" - #include "ezusb-emu/msg.h" #include "ezusb-emu/node-coin.h" #include "ezusb-emu/nodes.h" @@ -22,8 +16,12 @@ #include "ezusb-iidx-16seg-emu/nodes.h" -#include "util/hex.h" +#include "hook/iohook.h" +#include "iface-core/log.h" +#include "iface-io/iidx.h" + +#include "util/hex.h" /* ------------------------------------------------------------------------ */ static HRESULT ezusb_iidx_emu_msg_interrupt_read(struct iobuf *read); @@ -122,25 +120,25 @@ static HRESULT ezusb_iidx_emu_msg_interrupt_read(struct iobuf *read) struct ezusb_iidx_msg_interrupt_read_packet *msg_resp = (struct ezusb_iidx_msg_interrupt_read_packet *) read->bytes; - if (!iidx_io_ep2_recv()) { + if (!bt_io_iidx_ep2_recv()) { return E_FAIL; } - msg_resp->p1_turntable = iidx_io_ep2_get_turntable(0); - msg_resp->p2_turntable = iidx_io_ep2_get_turntable(1); + msg_resp->p1_turntable = bt_io_iidx_ep2_turntable_get(0); + msg_resp->p2_turntable = bt_io_iidx_ep2_turntable_get(1); msg_resp->sliders[0] = - iidx_io_ep2_get_slider(0) | (iidx_io_ep2_get_slider(1) << 4); + bt_io_iidx_ep2_slider_get(0) | (bt_io_iidx_ep2_slider_get(1) << 4); msg_resp->sliders[1] = - iidx_io_ep2_get_slider(2) | (iidx_io_ep2_get_slider(3) << 4); + bt_io_iidx_ep2_slider_get(2) | (bt_io_iidx_ep2_slider_get(3) << 4); - msg_resp->sliders[2] = iidx_io_ep2_get_slider(4); + msg_resp->sliders[2] = bt_io_iidx_ep2_slider_get(4); - msg_resp->inverted_pad = ((iidx_io_ep2_get_keys() & 0x3FFF) << 8) | - ((iidx_io_ep2_get_panel() & 0x0F) << 24) | - ((iidx_io_ep2_get_sys() & 0x07) << 28) | - (((iidx_io_ep2_get_sys() >> 2) & 0x01) << 22); + msg_resp->inverted_pad = ((bt_io_iidx_ep2_keys_get() & 0x3FFF) << 8) | + ((bt_io_iidx_ep2_panel_get() & 0x0F) << 24) | + ((bt_io_iidx_ep2_sys_get() & 0x07) << 28) | + (((bt_io_iidx_ep2_sys_get() >> 2) & 0x01) << 22); /* make sure to update the current coin mode state, otherwise the game will bang the IO and try to enforce the coin state it wants to @@ -209,12 +207,12 @@ static HRESULT ezusb_iidx_emu_msg_interrupt_write(struct const_iobuf *write) return E_INVALIDARG; } - iidx_io_ep1_set_deck_lights(msg_req->deck_lights); - iidx_io_ep1_set_panel_lights(msg_req->panel_lights); - iidx_io_ep1_set_top_lamps(msg_req->top_lamps); - iidx_io_ep1_set_top_neons(msg_req->top_neons); + bt_io_iidx_ep1_deck_lights_set(msg_req->deck_lights); + bt_io_iidx_ep1_panel_lights_set(msg_req->panel_lights); + bt_io_iidx_ep1_top_lamps_set(msg_req->top_lamps); + bt_io_iidx_ep1_top_neons_set(msg_req->top_neons); - if (!iidx_io_ep1_send()) { + if (!bt_io_iidx_ep1_send()) { return E_FAIL; } diff --git a/src/main/ezusb-iidx-emu/node-fpga.c b/src/main/ezusb-iidx-emu/node-fpga.c index 6615b43..a3ec6ac 100644 --- a/src/main/ezusb-iidx-emu/node-fpga.c +++ b/src/main/ezusb-iidx-emu/node-fpga.c @@ -2,12 +2,12 @@ #include -#include "core/log.h" - #include "ezusb-iidx-emu/conf.h" #include "ezusb-iidx-emu/node-fpga.h" #include "ezusb-iidx/fpga-cmd.h" +#include "iface-core/log.h" + #include "util/fs.h" static uint16_t ezusb_iidx_emu_node_fpga_write_ptr; diff --git a/src/main/ezusb-iidx-emu/node-serial.c b/src/main/ezusb-iidx-emu/node-serial.c index 7dc6519..3b81220 100644 --- a/src/main/ezusb-iidx-emu/node-serial.c +++ b/src/main/ezusb-iidx-emu/node-serial.c @@ -2,15 +2,14 @@ #include -#include "bemanitools/eamio.h" - -#include "core/log.h" -#include "core/thread.h" - #include "ezusb-iidx-emu/card-mag.c" #include "ezusb-iidx-emu/node-serial.h" #include "ezusb-iidx/serial-cmd.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface-io/eam.h" + #include "security/mcode.h" #include "util/hex.h" @@ -228,7 +227,7 @@ struct ezusb_iidx_emu_node_serial_emulation_state { /* ------------------------------------------------------------------------- */ static const char - ezusb_iidx_emu_node_serial_eamio_mapping[EAM_IO_KEYPAD_COUNT] = { + ezusb_iidx_emu_node_serial_eamio_mapping[BT_IO_EAM_KEYPAD_COUNT] = { '0', '1', '4', '7', 'O', '2', '5', '8', 'E', '3', '6', '9'}; static const uint8_t HEADER_BYTE = 0xAA; @@ -268,6 +267,8 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void *ctx); void ezusb_iidx_emu_node_serial_init(void) { + bt_core_thread_result_t result; + ezusb_iidx_emu_node_serial_read_buf_busy = false; ezusb_iidx_emu_node_serial_write_buf_busy = false; memset( @@ -293,8 +294,13 @@ void ezusb_iidx_emu_node_serial_init(void) &ezusb_iidx_emu_node_serial_emulation_state[i].card_cs); } - ezusb_iidx_emu_node_serial_emu_thread = core_thread_create( - ezusb_iidx_emu_node_serial_emu_thread_proc, NULL, 0x4000, 0); + result = bt_core_thread_create( + ezusb_iidx_emu_node_serial_emu_thread_proc, + NULL, + 0x4000, + 0, + &ezusb_iidx_emu_node_serial_emu_thread); + bt_core_thread_fatal_on_error(result); } uint8_t ezusb_iidx_emu_node_serial_process_cmd( @@ -1253,15 +1259,15 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void *ctx) uint16_t keyboard_state_prev[2] = {0, 0}; while (true) { for (uint8_t node = 0; node < 2; node++) { - if (!eam_io_poll(node)) { + if (!bt_io_eam_poll(node)) { log_warning("Polling eamio, node %d failed", node); continue; } /* read card slot sensors */ - uint8_t sensors = eam_io_get_sensor_state(node); - if (sensors & (1 << EAM_IO_SENSOR_FRONT)) { + uint8_t sensors = bt_io_eam_sensor_state_get(node); + if (sensors & (1 << BT_IO_EAM_SENSOR_STATE_FRONT)) { ezusb_iidx_emu_node_serial_emulation_state[node] .card_slot_sensor_front = true; } else { @@ -1269,7 +1275,7 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void *ctx) .card_slot_sensor_front = false; } - if (sensors & (1 << EAM_IO_SENSOR_BACK)) { + if (sensors & (1 << BT_IO_EAM_SENSOR_STATE_BACK)) { ezusb_iidx_emu_node_serial_emulation_state[node] .card_slot_sensor_back = true; } else { @@ -1279,7 +1285,7 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void *ctx) /* handle keypad */ - uint16_t keypad = eam_io_get_keypad_state(node); + uint16_t keypad = bt_io_eam_keypad_state_get(node); uint16_t keypad_rise = ~keyboard_state_prev[node] & keypad; for (uint8_t i = 0; @@ -1297,11 +1303,13 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void *ctx) switch (ezusb_iidx_emu_node_serial_emulation_state[node] .ezusb_iidx_emu_node_serial_card_slot_state) { case EMU_CARD_SLOT_STATE_CLOSE: - eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_CLOSE); + bt_io_eam_card_slot_cmd_send( + node, BT_IO_EAM_CARD_SLOT_CMD_CLOSE); break; case EMU_CARD_SLOT_STATE_EJECT: - eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_EJECT); + bt_io_eam_card_slot_cmd_send( + node, BT_IO_EAM_CARD_SLOT_CMD_EJECT); EnterCriticalSection( &ezusb_iidx_emu_node_serial_emulation_state[node] @@ -1320,11 +1328,13 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void *ctx) break; case EMU_CARD_SLOT_STATE_OPEN: - eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_OPEN); + bt_io_eam_card_slot_cmd_send( + node, BT_IO_EAM_CARD_SLOT_CMD_OPEN); break; case EMU_CARD_SLOT_STATE_READ: - eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_READ); + bt_io_eam_card_slot_cmd_send( + node, BT_IO_EAM_CARD_SLOT_CMD_READ); /* read once */ if (ezusb_iidx_emu_node_serial_emulation_state[node] @@ -1333,7 +1343,7 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void *ctx) &ezusb_iidx_emu_node_serial_emulation_state[node] .card_cs); - if (!eam_io_read_card( + if (!bt_io_eam_card_read( node, ezusb_iidx_emu_node_serial_emulation_state[node] .card_id, diff --git a/src/main/ezusb-iidx-fpga-flash/Module.mk b/src/main/ezusb-iidx-fpga-flash/Module.mk index 320d6f4..ad7ee8c 100644 --- a/src/main/ezusb-iidx-fpga-flash/Module.mk +++ b/src/main/ezusb-iidx-fpga-flash/Module.mk @@ -8,6 +8,7 @@ libs_ezusb-iidx-fpga-flash := \ ezusb \ ezusb-iidx \ util \ + iface-core \ src_ezusb-iidx-fpga-flash := \ main.c \ diff --git a/src/main/ezusb-iidx-fpga-flash/main.c b/src/main/ezusb-iidx-fpga-flash/main.c index f8dacdd..e153f18 100644 --- a/src/main/ezusb-iidx-fpga-flash/main.c +++ b/src/main/ezusb-iidx-fpga-flash/main.c @@ -5,7 +5,9 @@ #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" +#include "core/log-sink-std.h" + +#include "iface-core/log.h" #include "ezusb-iidx/fpga.h" #include "ezusb/ezusb.h" @@ -27,8 +29,10 @@ int main(int argc, char **argv) return -1; } - core_log_bt_ext_impl_set(); + core_log_bt_core_api_set(); + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); log_info("Opening ezusb '%s'...", EZUSB_DEVICE_PATH); diff --git a/src/main/ezusb-iidx-sram-flash/Module.mk b/src/main/ezusb-iidx-sram-flash/Module.mk index a369b06..327841c 100644 --- a/src/main/ezusb-iidx-sram-flash/Module.mk +++ b/src/main/ezusb-iidx-sram-flash/Module.mk @@ -8,6 +8,7 @@ libs_ezusb-iidx-sram-flash := \ ezusb \ ezusb-iidx \ util \ + iface-core \ src_ezusb-iidx-sram-flash := \ main.c \ diff --git a/src/main/ezusb-iidx-sram-flash/main.c b/src/main/ezusb-iidx-sram-flash/main.c index b4fa94d..5c71568 100644 --- a/src/main/ezusb-iidx-sram-flash/main.c +++ b/src/main/ezusb-iidx-sram-flash/main.c @@ -1,11 +1,13 @@ +#include + #include #include -#include - #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" +#include "core/log-sink-std.h" + +#include "iface-core/log.h" #include "ezusb-iidx/sram.h" #include "ezusb/ezusb.h" @@ -27,8 +29,10 @@ int main(int argc, char **argv) return -1; } - core_log_bt_ext_impl_set(); - core_log_bt_ext_init_with_stdout(); + core_log_bt_core_api_set(); + + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); log_info("Opening ezusb '%s'...", argv[1]); diff --git a/src/main/ezusb-iidx/ezusb-iidx.c b/src/main/ezusb-iidx/ezusb-iidx.c index ae035b7..b9b4ae4 100644 --- a/src/main/ezusb-iidx/ezusb-iidx.c +++ b/src/main/ezusb-iidx/ezusb-iidx.c @@ -1,11 +1,11 @@ #define LOG_MODULE "ezusb-iidx" -#include "core/log.h" - #include "ezusb-iidx/ezusb-iidx.h" #include "ezusb/ezusbsys2.h" +#include "iface-core/log.h" + #include "util/hex.h" #include "util/time.h" diff --git a/src/main/ezusb-iidx/fpga.c b/src/main/ezusb-iidx/fpga.c index b4d2550..7eafa0c 100644 --- a/src/main/ezusb-iidx/fpga.c +++ b/src/main/ezusb-iidx/fpga.c @@ -1,10 +1,10 @@ #define LOG_MODULE "ezusb-iidx-fpga" -#include "ezusb-iidx/fpga.h" - #include -#include "core/log.h" +#include "ezusb-iidx/fpga.h" + +#include "iface-core/log.h" #include "ezusb-iidx.h" #include "fpga-cmd.h" diff --git a/src/main/ezusb-iidx/sram.c b/src/main/ezusb-iidx/sram.c index fcce384..0ad056e 100644 --- a/src/main/ezusb-iidx/sram.c +++ b/src/main/ezusb-iidx/sram.c @@ -1,9 +1,9 @@ #define LOG_MODULE "ezusb-iidx-sram" -#include "core/log.h" - #include "ezusb-iidx/sram.h" +#include "iface-core/log.h" + #include "ezusb-iidx.h" #include "sram-cmd.h" diff --git a/src/main/ezusb-tool/Module.mk b/src/main/ezusb-tool/Module.mk index b5e8158..dd304ae 100644 --- a/src/main/ezusb-tool/Module.mk +++ b/src/main/ezusb-tool/Module.mk @@ -7,6 +7,7 @@ libs_ezusb-tool := \ core \ ezusb \ util \ + iface-core \ src_ezusb-tool := \ main.c \ diff --git a/src/main/ezusb-tool/main.c b/src/main/ezusb-tool/main.c index ca84781..9e96865 100644 --- a/src/main/ezusb-tool/main.c +++ b/src/main/ezusb-tool/main.c @@ -5,7 +5,9 @@ #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" +#include "core/log-sink-std.h" + +#include "iface-core/log.h" #include "ezusb/ezusb.h" #include "ezusb/util.h" @@ -105,8 +107,10 @@ int main(int argc, char **argv) arg_pos = 1; - core_log_bt_ext_impl_set(); + core_log_bt_core_api_set(); + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); if (!strcmp(argv[arg_pos], "info")) { return info(); diff --git a/src/main/ezusb/ezusb.c b/src/main/ezusb/ezusb.c index 7204589..95915b7 100644 --- a/src/main/ezusb/ezusb.c +++ b/src/main/ezusb/ezusb.c @@ -4,11 +4,11 @@ #include // clang-format on -#include "core/log.h" - #include "ezusb/ezusb.h" #include "ezusb/ezusbsys2.h" +#include "iface-core/log.h" + #include "util/str.h" static bool ezusb_reset(HANDLE handle, bool hold) diff --git a/src/main/ezusb/util.c b/src/main/ezusb/util.c index 5bf18a4..e356166 100644 --- a/src/main/ezusb/util.c +++ b/src/main/ezusb/util.c @@ -1,10 +1,10 @@ #include #include -#include "core/log.h" - #include "ezusb/util.h" +#include "iface-core/log.h" + #include "util/crc.h" #include "util/fs.h" #include "util/mem.h" diff --git a/src/main/ezusb2-dbg-hook/Module.mk b/src/main/ezusb2-dbg-hook/Module.mk index 579e9bf..ab483ec 100644 --- a/src/main/ezusb2-dbg-hook/Module.mk +++ b/src/main/ezusb2-dbg-hook/Module.mk @@ -4,6 +4,7 @@ libs_ezusb2-dbg-hook := \ core \ hook \ util \ + iface-core \ src_ezusb2-dbg-hook := \ main.c \ diff --git a/src/main/ezusb2-dbg-hook/main.c b/src/main/ezusb2-dbg-hook/main.c index e1c1bdb..d4a66bb 100644 --- a/src/main/ezusb2-dbg-hook/main.c +++ b/src/main/ezusb2-dbg-hook/main.c @@ -12,13 +12,14 @@ #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log-sink-file.h" -#include "core/log.h" +#include "core/log-sink-std.h" #include "ezusb2/cyioctl.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "util/cmdline.h" #include "util/hex.h" #include "util/str.h" @@ -376,8 +377,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) wchar_t *buffer; uint32_t args_success; - core_log_bt_ext_impl_set(); - core_log_bt_ext_init_with_file("ezusb2_dbg.log", false, false, 0); + core_log_bt_core_api_set(); + + core_log_bt_ext_init_with_stderr_and_file( + "ezusb2_dbg.log", false, false, 0); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); hook_table_apply( NULL, diff --git a/src/main/ezusb2-emu/device.c b/src/main/ezusb2-emu/device.c index ecba816..df12232 100644 --- a/src/main/ezusb2-emu/device.c +++ b/src/main/ezusb2-emu/device.c @@ -9,8 +9,6 @@ #include -#include "core/log.h" - #include "ezusb/util.h" #include "ezusb2/cyioctl.h" @@ -24,6 +22,8 @@ #include "hook/iohook.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "util/fs.h" diff --git a/src/main/ezusb2-emu/util.c b/src/main/ezusb2-emu/util.c index d5b12b9..ed4904f 100644 --- a/src/main/ezusb2-emu/util.c +++ b/src/main/ezusb2-emu/util.c @@ -6,13 +6,13 @@ #include #include -#include "core/log.h" - #include "ezusb2/cyioctl.h" #include "ezusb2/ezusb2.h" #include "ezusb-emu/util.h" +#include "iface-core/log.h" + #include "util/hex.h" void ezusb2_emu_util_log_usb_msg(const char *prefix, const struct irp *irp) diff --git a/src/main/ezusb2-iidx-emu/msg.c b/src/main/ezusb2-iidx-emu/msg.c index bfc3dce..12e8bed 100644 --- a/src/main/ezusb2-iidx-emu/msg.c +++ b/src/main/ezusb2-iidx-emu/msg.c @@ -4,10 +4,6 @@ #include #include -#include "bemanitools/iidxio.h" - -#include "core/log.h" - #include "hook/iohook.h" #include "ezusb-emu/msg.h" @@ -16,6 +12,9 @@ #include "ezusb2-iidx/msg.h" +#include "iface-core/log.h" +#include "iface-io/iidx.h" + #include "util/hex.h" /* ------------------------------------------------------------------------ */ @@ -67,27 +66,27 @@ static HRESULT ezusb2_iidx_emu_msg_interrupt_read(struct iobuf *read) { struct ezusb2_iidx_msg_interrupt_read_packet msg_resp; - if (!iidx_io_ep2_recv()) { + if (!bt_io_iidx_ep2_recv()) { return E_FAIL; } memset(&msg_resp, 0, sizeof(msg_resp)); - msg_resp.p1_turntable = iidx_io_ep2_get_turntable(0); - msg_resp.p2_turntable = iidx_io_ep2_get_turntable(1); + msg_resp.p1_turntable = bt_io_iidx_ep2_turntable_get(0); + msg_resp.p2_turntable = bt_io_iidx_ep2_turntable_get(1); msg_resp.sliders[0] = - iidx_io_ep2_get_slider(0) | (iidx_io_ep2_get_slider(1) << 4); + bt_io_iidx_ep2_slider_get(0) | (bt_io_iidx_ep2_slider_get(1) << 4); msg_resp.sliders[1] = - iidx_io_ep2_get_slider(2) | (iidx_io_ep2_get_slider(3) << 4); + bt_io_iidx_ep2_slider_get(2) | (bt_io_iidx_ep2_slider_get(3) << 4); - msg_resp.sliders[2] = iidx_io_ep2_get_slider(4); + msg_resp.sliders[2] = bt_io_iidx_ep2_slider_get(4); - msg_resp.inverted_pad = ((iidx_io_ep2_get_keys() & 0x3FFF) << 16) | - (iidx_io_ep2_get_panel() & 0x0F) | - ((iidx_io_ep2_get_sys() & 0x07) << 4) | - (((iidx_io_ep2_get_sys() >> 2) & 0x01) << 30); + msg_resp.inverted_pad = ((bt_io_iidx_ep2_keys_get() & 0x3FFF) << 16) | + (bt_io_iidx_ep2_panel_get() & 0x0F) | + ((bt_io_iidx_ep2_sys_get() & 0x07) << 4) | + (((bt_io_iidx_ep2_sys_get() >> 2) & 0x01) << 30); msg_resp.inverted_pad = ~msg_resp.inverted_pad; @@ -127,19 +126,19 @@ static HRESULT ezusb2_iidx_emu_msg_interrupt_write(struct const_iobuf *write) return E_INVALIDARG; } - iidx_io_ep1_set_deck_lights(msg_req.deck_lights); - iidx_io_ep1_set_panel_lights(msg_req.panel_lights); - iidx_io_ep1_set_top_lamps(msg_req.top_lamps); - iidx_io_ep1_set_top_neons(msg_req.top_neons); + bt_io_iidx_ep1_deck_lights_set(msg_req.deck_lights); + bt_io_iidx_ep1_panel_lights_set(msg_req.panel_lights); + bt_io_iidx_ep1_top_lamps_set(msg_req.top_lamps); + bt_io_iidx_ep1_top_neons_set(msg_req.top_neons); - if (!iidx_io_ep1_send()) { + if (!bt_io_iidx_ep1_send()) { return E_FAIL; } /* 16seg data is provided with the request and not handled using a separate bulk endpoint like on the C02 IO board */ - if (!iidx_io_ep3_write_16seg((const char *) msg_req.seg16)) { + if (!bt_io_iidx_ep3_16seg_send((const char *) msg_req.seg16)) { return E_FAIL; } diff --git a/src/main/ezusb2-popn-emu/msg.c b/src/main/ezusb2-popn-emu/msg.c index d696ecc..7a2c357 100644 --- a/src/main/ezusb2-popn-emu/msg.c +++ b/src/main/ezusb2-popn-emu/msg.c @@ -4,12 +4,6 @@ #include #include -#include "bemanitools/popnio.h" - -#include "core/log.h" - -#include "hook/iohook.h" - #include "ezusb-emu/msg.h" #include "ezusb-emu/node-coin.h" @@ -20,6 +14,11 @@ #include "ezusb2-popn/msg.h" +#include "hook/iohook.h" + +#include "iface-core/log.h" +#include "iface-io/popn.h" + #include "util/hex.h" /* ------------------------------------------------------------------------ */ @@ -90,7 +89,7 @@ static HRESULT ezusb2_popn_emu_msg_interrupt_read(struct iobuf *read) msg_resp.coin_count = 0; msg_resp.unk4 = 0xfd; - msg_resp.io.inverted_pad = ~popn_io_get_buttons(); + msg_resp.io.inverted_pad = ~bt_io_popn_buttons_get(); msg_resp.unk5 = 0x00; msg_resp.unk6 = 0x7d; @@ -138,12 +137,12 @@ static HRESULT ezusb2_popn_emu_msg_interrupt_write(struct const_iobuf *write) return E_INVALIDARG; } - popn_io_set_top_lights(msg_req.lamp & 0x1f); - popn_io_set_side_lights((msg_req.lamp >> 8) & 0xf); - popn_io_set_button_lights((msg_req.lamp >> 20) & 0xfff); - popn_io_set_coin_counter_light( + bt_io_popn_top_lights_set(msg_req.lamp & 0x1f); + bt_io_popn_side_lights_set((msg_req.lamp >> 8) & 0xf); + bt_io_popn_button_lights_set((msg_req.lamp >> 20) & 0xfff); + bt_io_popn_coin_counter_light_set( ((msg_req.lamp >> 12) & 0xf) == 0); // Active low - popn_io_set_coin_blocker_light(((msg_req.lamp >> 16) & 0xf) == 0xf); + bt_io_popn_coin_blocker_light_set(((msg_req.lamp >> 16) & 0xf) == 0xf); /* Remember node for next bulk read */ diff --git a/src/main/ezusb2-popn-shim/Module.mk b/src/main/ezusb2-popn-shim/Module.mk index f4536c4..64e348b 100644 --- a/src/main/ezusb2-popn-shim/Module.mk +++ b/src/main/ezusb2-popn-shim/Module.mk @@ -9,6 +9,7 @@ libs_ezusb2-popn-shim := \ hook \ hooklib \ util \ + iface-core \ src_ezusb2-popn-shim := \ dllmain.c \ diff --git a/src/main/ezusb2-popn-shim/dllmain.c b/src/main/ezusb2-popn-shim/dllmain.c index ec7e18f..1fd4efd 100644 --- a/src/main/ezusb2-popn-shim/dllmain.c +++ b/src/main/ezusb2-popn-shim/dllmain.c @@ -4,8 +4,6 @@ #include -#include "core/log.h" - #include "ezusb2-emu/desc.h" #include "ezusb2-emu/device.h" @@ -13,6 +11,8 @@ #include "hooklib/setupapi.h" +#include "iface-core/log.h" + #include "ezusb2-popn-shim/proxy.h" #define EZUSB_REAL_DLL_FILENAME "ezusb.dll" diff --git a/src/main/ezusb2-popn-shim/proxy.c b/src/main/ezusb2-popn-shim/proxy.c index ec47002..439fa91 100644 --- a/src/main/ezusb2-popn-shim/proxy.c +++ b/src/main/ezusb2-popn-shim/proxy.c @@ -2,7 +2,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" struct CoinParam; struct EEP_HISTORY; diff --git a/src/main/ezusb2-tool/Module.mk b/src/main/ezusb2-tool/Module.mk index 87e6dff..dbed8d5 100644 --- a/src/main/ezusb2-tool/Module.mk +++ b/src/main/ezusb2-tool/Module.mk @@ -8,6 +8,7 @@ libs_ezusb2-tool := \ ezusb2 \ ezusb \ util \ + iface-core \ src_ezusb2-tool := \ main.c \ diff --git a/src/main/ezusb2-tool/main.c b/src/main/ezusb2-tool/main.c index 0579c07..6f0f5e5 100644 --- a/src/main/ezusb2-tool/main.c +++ b/src/main/ezusb2-tool/main.c @@ -5,7 +5,9 @@ #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" +#include "core/log-sink-std.h" + +#include "iface-core/log.h" #include "ezusb/util.h" #include "ezusb2/ezusb2.h" @@ -124,8 +126,10 @@ int main(int argc, char **argv) arg_pos = 1; - core_log_bt_ext_impl_set(); + core_log_bt_core_api_set(); + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); if (!strcmp(argv[arg_pos], "scan")) { return scan(); diff --git a/src/main/ezusb2/ezusb2.c b/src/main/ezusb2/ezusb2.c index 2c1b7b9..1e0b952 100644 --- a/src/main/ezusb2/ezusb2.c +++ b/src/main/ezusb2/ezusb2.c @@ -4,13 +4,13 @@ #include // clang-format on -#include "core/log.h" - #include "ezusb/ezusb.h" #include "ezusb2/cyioctl.h" #include "ezusb2/ezusb2.h" +#include "iface-core/log.h" + #include "util/crc.h" #include "util/fs.h" #include "util/str.h" diff --git a/src/main/geninput/Module.mk b/src/main/geninput/Module.mk index 3115edf..05f3755 100644 --- a/src/main/geninput/Module.mk +++ b/src/main/geninput/Module.mk @@ -7,6 +7,8 @@ ldflags_geninput := \ libs_geninput := \ core \ util \ + iface-core \ + iface \ src_geninput := \ dev-list.c \ diff --git a/src/main/geninput/dev-list.c b/src/main/geninput/dev-list.c index ce6d93a..da14b94 100644 --- a/src/main/geninput/dev-list.c +++ b/src/main/geninput/dev-list.c @@ -9,10 +9,10 @@ #include #include -#include "core/log.h" - #include "geninput/dev-list.h" +#include "iface-core/log.h" + #include "util/mem.h" void dev_list_init(struct dev_list *devs, const GUID *class_guid) diff --git a/src/main/geninput/geninput.def b/src/main/geninput/geninput.def index 6ef4cf3..e392cc8 100644 --- a/src/main/geninput/geninput.def +++ b/src/main/geninput/geninput.def @@ -1,6 +1,12 @@ LIBRARY geninput EXPORTS + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_input_api_get + + ; Direct API action_iter_get_mapping action_iter_get_action action_iter_get_page @@ -22,7 +28,6 @@ EXPORTS hid_stub_set_light input_fini input_init - input_set_loggers light_iter_get_mapping light_iter_get_game_light light_iter_is_valid @@ -49,6 +54,6 @@ EXPORTS mapper_set_light_map mapper_set_nanalogs mapper_set_nlights - mapper_read_analog + mapper_analog_read mapper_update - mapper_write_light + mapper_light_write diff --git a/src/main/geninput/hid-generic.c b/src/main/geninput/hid-generic.c index 46c2924..b621642 100644 --- a/src/main/geninput/hid-generic.c +++ b/src/main/geninput/hid-generic.c @@ -12,14 +12,14 @@ #include // clang-format on -#include "core/log.h" - #include "geninput/hid-generic-strings.h" #include "geninput/hid-generic.h" #include "geninput/hid-meta-in.h" #include "geninput/hid-meta-out.h" #include "geninput/hid.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/geninput/hid-meta-in.c b/src/main/geninput/hid-meta-in.c index 3a32494..8b8fa9f 100644 --- a/src/main/geninput/hid-meta-in.c +++ b/src/main/geninput/hid-meta-in.c @@ -11,11 +11,11 @@ #include #include -#include "core/log.h" - #include "geninput/hid-meta-in.h" #include "geninput/hid-report-in.h" +#include "iface-core/log.h" + #include "util/mem.h" static bool diff --git a/src/main/geninput/hid-meta-out.c b/src/main/geninput/hid-meta-out.c index 1903785..7aac137 100644 --- a/src/main/geninput/hid-meta-out.c +++ b/src/main/geninput/hid-meta-out.c @@ -12,11 +12,11 @@ #include #include -#include "core/log.h" - #include "geninput/hid-meta-out.h" #include "geninput/hid-report-out.h" +#include "iface-core/log.h" + #include "util/mem.h" static bool diff --git a/src/main/geninput/hid-mgr.c b/src/main/geninput/hid-mgr.c index 2f8a7c1..af8fb46 100644 --- a/src/main/geninput/hid-mgr.c +++ b/src/main/geninput/hid-mgr.c @@ -2,10 +2,10 @@ #include -#include "core/log.h" - #include "geninput/hid-mgr.h" +#include "iface-core/log.h" + #include "util/mem.h" #include "util/str.h" diff --git a/src/main/geninput/hid-report-in.c b/src/main/geninput/hid-report-in.c index aec213d..a35e7d1 100644 --- a/src/main/geninput/hid-report-in.c +++ b/src/main/geninput/hid-report-in.c @@ -10,10 +10,10 @@ #include #include -#include "core/log.h" - #include "geninput/hid-report-in.h" +#include "iface-core/log.h" + #include "util/mem.h" void hid_report_in_init( diff --git a/src/main/geninput/hid-report-out.c b/src/main/geninput/hid-report-out.c index 892cd13..ad84f66 100644 --- a/src/main/geninput/hid-report-out.c +++ b/src/main/geninput/hid-report-out.c @@ -11,10 +11,10 @@ #include #include -#include "core/log.h" - #include "geninput/hid-report-out.h" +#include "iface-core/log.h" + #include "util/mem.h" bool hid_report_out_init( diff --git a/src/main/geninput/hid.c b/src/main/geninput/hid.c index 889ee80..58c6566 100644 --- a/src/main/geninput/hid.c +++ b/src/main/geninput/hid.c @@ -1,11 +1,11 @@ #include #include -#include "core/log.h" - #include "geninput/dev-list.h" #include "geninput/hid.h" +#include "iface-core/log.h" + #include "util/str.h" wchar_t *hid_ri_init_name(const GUID *class_guid, const char *dev_node) diff --git a/src/main/geninput/hotplug.c b/src/main/geninput/hotplug.c index d9954d3..bf8d77e 100644 --- a/src/main/geninput/hotplug.c +++ b/src/main/geninput/hotplug.c @@ -6,13 +6,13 @@ #include -#include "core/log.h" - #include "geninput/hid.h" #include "geninput/hotplug.h" #include "geninput/io-thread.h" #include "geninput/ri.h" +#include "iface-core/log.h" + static HDEVNOTIFY hotplug_handle; void hotplug_init(HWND wnd) diff --git a/src/main/geninput/input-config.h b/src/main/geninput/input-config.h index d7fe181..6f33eca 100644 --- a/src/main/geninput/input-config.h +++ b/src/main/geninput/input-config.h @@ -4,8 +4,6 @@ #include #include -#include "bemanitools/input.h" - #include "geninput/mapper.h" void mapper_config_save(const char *game_type); diff --git a/src/main/geninput/input.c b/src/main/geninput/input.c index e67df3d..39ae155 100644 --- a/src/main/geninput/input.c +++ b/src/main/geninput/input.c @@ -4,11 +4,13 @@ #include -#include "bemanitools/glue.h" -#include "bemanitools/input.h" +#include "api/core/log.h" +#include "api/core/thread.h" -#include "core/log.h" -#include "core/thread.h" +#include "api/input.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" #include "geninput/hid-mgr.h" #include "geninput/hid.h" @@ -34,28 +36,19 @@ static FILE *mapper_config_open(const char *game_type, const char *mode) // Try to load the old save file only if we're loading if (f == NULL) { if (strchr(mode, 'r') != NULL) { + log_misc("Fallback to old save file"); str_format(path, sizeof(path), "%s_v5_00a07.bin", game_type); f = fopen_appdata("DJHACKERS", path, mode); } } - + return f; } -void input_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - core_log_impl_set(misc, info, warning, fatal); -} - -void input_init( - thread_create_t create, thread_join_t join, thread_destroy_t destroy) +bool input_init() { if (InterlockedIncrement(&input_init_count) != 1) { - return; + return true; } log_info("Generic input subsystem is starting up"); @@ -64,9 +57,10 @@ void input_init( mapper_inst = mapper_impl_create(); - core_thread_impl_set(create, join, destroy); msg_thread_init(input_hinst); io_thread_init(); + + return true; } void input_fini(void) @@ -226,7 +220,7 @@ void mapper_set_nlights(uint8_t nlights) mapper_impl_set_nlights(mapper_inst, nlights); } -uint8_t mapper_read_analog(uint8_t analog) +uint8_t mapper_analog_read(uint8_t analog) { return mapper_impl_read_analog(mapper_inst, analog); } @@ -236,11 +230,33 @@ uint64_t mapper_update(void) return mapper_impl_update(mapper_inst); } -void mapper_write_light(uint8_t light, uint8_t intensity) +void mapper_light_write(uint8_t light, uint8_t intensity) { mapper_impl_write_light(mapper_inst, light, intensity); } +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_input_api_get(bt_input_api_t *api) +{ + api->version = 1; + + api->v1.init = input_init; + api->v1.fini = input_fini; + api->v1.mapper_config_load = mapper_config_load; + api->v1.mapper_analog_read = mapper_analog_read; + api->v1.mapper_update = mapper_update; + api->v1.mapper_light_write = mapper_light_write; +} + BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { diff --git a/src/main/geninput/io-thread.c b/src/main/geninput/io-thread.c index 18f5ccc..cc064fb 100644 --- a/src/main/geninput/io-thread.c +++ b/src/main/geninput/io-thread.c @@ -2,8 +2,8 @@ #include -#include "core/log.h" -#include "core/thread.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" #include "geninput/dev-list.h" #include "geninput/hid-generic.h" @@ -27,7 +27,7 @@ struct io_thread_msg { }; static HANDLE io_thread_cp; -static int io_thread_id; +static bt_core_thread_id_t io_thread_id; static void io_thread_proc_add_device(const char *dev_node); static void io_thread_proc_init(void); @@ -170,10 +170,13 @@ static int io_thread_proc(void *param) void io_thread_init(void) { HANDLE barrier; + bt_core_thread_result_t result; barrier = CreateEvent(NULL, TRUE, FALSE, NULL); - io_thread_id = core_thread_create(io_thread_proc, barrier, 16384, 0); + result = + bt_core_thread_create(io_thread_proc, barrier, 16384, 0, &io_thread_id); + bt_core_thread_fatal_on_error(result); WaitForSingleObject(barrier, INFINITE); CloseHandle(barrier); @@ -196,11 +199,15 @@ void io_thread_add_device(const char *dev_node) void io_thread_fini(void) { struct io_thread_msg msg; + bt_core_thread_result_t result; msg.cmd = IO_THREAD_CMD_STOP; PostQueuedCompletionStatus(io_thread_cp, 0, (uintptr_t) &msg, NULL); - core_thread_join(io_thread_id, NULL); - core_thread_destroy(io_thread_id); + result = bt_core_thread_join(io_thread_id, NULL); + bt_core_thread_fatal_on_error(result); + + result = bt_core_thread_destroy(io_thread_id); + bt_core_thread_fatal_on_error(result); } diff --git a/src/main/geninput/kbd.c b/src/main/geninput/kbd.c index 191890b..6e69ab3 100644 --- a/src/main/geninput/kbd.c +++ b/src/main/geninput/kbd.c @@ -11,12 +11,12 @@ #include #include -#include "core/log.h" - #include "geninput/hid.h" #include "geninput/kbd-data.h" #include "geninput/kbd.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/geninput/mapper-s11n.c b/src/main/geninput/mapper-s11n.c index 3dba127..b93b125 100644 --- a/src/main/geninput/mapper-s11n.c +++ b/src/main/geninput/mapper-s11n.c @@ -22,9 +22,12 @@ enum mapper_config_version { static const uint32_t mapper_fourcc = FOURCC('B', 'T', 'M', 'D'); static uint32_t mapper_impl_config_load_version(FILE *f); -static bool mapper_impl_config_load_actions(struct mapper *m, FILE *f, uint32_t version); -static bool mapper_impl_config_load_analogs(struct mapper *m, FILE *f, uint32_t version); -static bool mapper_impl_config_load_lights(struct mapper *m, FILE *f, uint32_t version); +static bool +mapper_impl_config_load_actions(struct mapper *m, FILE *f, uint32_t version); +static bool +mapper_impl_config_load_analogs(struct mapper *m, FILE *f, uint32_t version); +static bool +mapper_impl_config_load_lights(struct mapper *m, FILE *f, uint32_t version); static void mapper_impl_config_save_actions(struct mapper *m, FILE *f); static void mapper_impl_config_save_analogs(struct mapper *m, FILE *f); static void mapper_impl_config_save_lights(struct mapper *m, FILE *f); @@ -60,9 +63,9 @@ static uint32_t mapper_impl_config_load_version(FILE *f) if (!read_u32(f, &fourcc)) { return 0; } - + if (fourcc == mapper_fourcc) { - + if (!read_u32(f, &version)) { fseek(f, -4, SEEK_CUR); } @@ -74,7 +77,8 @@ static uint32_t mapper_impl_config_load_version(FILE *f) return version; } -static bool mapper_impl_config_load_actions(struct mapper *m, FILE *f, uint32_t version) +static bool +mapper_impl_config_load_actions(struct mapper *m, FILE *f, uint32_t version) { char *dev_node; struct mapped_action ma; @@ -110,7 +114,8 @@ static bool mapper_impl_config_load_actions(struct mapper *m, FILE *f, uint32_t return true; } -static bool mapper_impl_config_load_analogs(struct mapper *m, FILE *f, uint32_t version) +static bool +mapper_impl_config_load_analogs(struct mapper *m, FILE *f, uint32_t version) { char *dev_node; struct mapped_analog ma; @@ -164,7 +169,8 @@ static bool mapper_impl_config_load_analogs(struct mapper *m, FILE *f, uint32_t return true; } -static bool mapper_impl_config_load_lights(struct mapper *m, FILE *f, uint32_t version) +static bool +mapper_impl_config_load_lights(struct mapper *m, FILE *f, uint32_t version) { char *dev_node; struct mapped_light ml; diff --git a/src/main/geninput/mapper.c b/src/main/geninput/mapper.c index 3c66c19..875f59b 100644 --- a/src/main/geninput/mapper.c +++ b/src/main/geninput/mapper.c @@ -1,11 +1,11 @@ #include #include -#include "core/log.h" - #include "geninput/hid-mgr.h" #include "geninput/mapper.h" +#include "iface-core/log.h" + #include "util/array.h" #include "util/mem.h" @@ -174,7 +174,7 @@ static void analog_mapping_bind(struct analog_mapping *am) am->analog_min = ctl->value_min; am->analog_max = ctl->value_max; - am->inv_analog_range = 1.0 / ((int64_t)ctl->value_max - ctl->value_min); + am->inv_analog_range = 1.0 / ((int64_t) ctl->value_max - ctl->value_min); am->absolute = !(ctl->flags & HID_FLAG_RELATIVE); am->valid = true; @@ -425,7 +425,7 @@ int32_t mapper_impl_get_analog_sensitivity(struct mapper *m, uint8_t analog) return m->analogs[analog].sensitivity; } -bool mapper_impl_get_analog_invert(struct mapper* m, uint8_t analog) +bool mapper_impl_get_analog_invert(struct mapper *m, uint8_t analog) { if (analog >= m->nanalogs) { return 0; diff --git a/src/main/geninput/mouse.c b/src/main/geninput/mouse.c index f1c54bf..d1cb9f4 100644 --- a/src/main/geninput/mouse.c +++ b/src/main/geninput/mouse.c @@ -12,11 +12,11 @@ #include #include -#include "core/log.h" - #include "geninput/hid.h" #include "geninput/mouse.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/geninput/msg-thread.c b/src/main/geninput/msg-thread.c index 7ca47f3..89bbfd2 100644 --- a/src/main/geninput/msg-thread.c +++ b/src/main/geninput/msg-thread.c @@ -6,11 +6,11 @@ #include -#include "core/log.h" - #include "geninput/hotplug.h" #include "geninput/ri.h" +#include "iface-core/log.h" + #include "util/msg-thread.h" void msg_window_setup(HWND hwnd) diff --git a/src/main/geninput/pacdrive.c b/src/main/geninput/pacdrive.c index b388036..603860b 100644 --- a/src/main/geninput/pacdrive.c +++ b/src/main/geninput/pacdrive.c @@ -11,12 +11,12 @@ #include #include -#include "core/log.h" - #include "geninput/hid.h" #include "geninput/io-thread.h" #include "geninput/pacdrive.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/mem.h" diff --git a/src/main/geninput/ri.c b/src/main/geninput/ri.c index 45b6d65..1415e27 100644 --- a/src/main/geninput/ri.c +++ b/src/main/geninput/ri.c @@ -1,13 +1,13 @@ #include -#include "core/log.h" - #include "geninput/hid-mgr.h" #include "geninput/hid.h" #include "geninput/kbd.h" #include "geninput/mouse.h" #include "geninput/ri.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/mem.h" diff --git a/src/main/hook/d3d9.c b/src/main/hook/d3d9.c index 0f09ec6..89b8e07 100644 --- a/src/main/hook/d3d9.c +++ b/src/main/hook/d3d9.c @@ -1,6 +1,6 @@ #define LOG_MODULE "hook-d3d9" -#include "core/log.h" +#include "iface-core/log.h" #include "hook/com-proxy.h" #include "hook/d3d9.h" diff --git a/src/main/hooklib/acp.c b/src/main/hooklib/acp.c index 81faa73..1729a2c 100644 --- a/src/main/hooklib/acp.c +++ b/src/main/hooklib/acp.c @@ -6,7 +6,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "hook/table.h" diff --git a/src/main/hooklib/adapter.c b/src/main/hooklib/adapter.c index 8b3b6d9..2fe1466 100644 --- a/src/main/hooklib/adapter.c +++ b/src/main/hooklib/adapter.c @@ -6,7 +6,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "hook/table.h" diff --git a/src/main/hooklib/app.c b/src/main/hooklib/app.c index 11fb824..4c545f0 100644 --- a/src/main/hooklib/app.c +++ b/src/main/hooklib/app.c @@ -1,6 +1,6 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "hook/table.h" diff --git a/src/main/hooklib/config-adapter.c b/src/main/hooklib/config-adapter.c index 0ddb680..633de74 100644 --- a/src/main/hooklib/config-adapter.c +++ b/src/main/hooklib/config-adapter.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "hooklib/config-adapter.h" diff --git a/src/main/hooklib/memfile.c b/src/main/hooklib/memfile.c index 09c0587..1b08efe 100644 --- a/src/main/hooklib/memfile.c +++ b/src/main/hooklib/memfile.c @@ -3,7 +3,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "hook/hr.h" #include "hook/iohook.h" diff --git a/src/main/hooklib/rs232.c b/src/main/hooklib/rs232.c index 591c98f..5913fe7 100644 --- a/src/main/hooklib/rs232.c +++ b/src/main/hooklib/rs232.c @@ -14,7 +14,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "hook/hr.h" #include "hook/iohook.h" diff --git a/src/main/hooklib/setupapi.c b/src/main/hooklib/setupapi.c index 5363c52..4239d62 100644 --- a/src/main/hooklib/setupapi.c +++ b/src/main/hooklib/setupapi.c @@ -4,7 +4,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "hook/table.h" diff --git a/src/main/iface-acio/Module.mk b/src/main/iface-acio/Module.mk new file mode 100644 index 0000000..2ade27f --- /dev/null +++ b/src/main/iface-acio/Module.mk @@ -0,0 +1,8 @@ +libs += iface-acio + +libs_iface-acio := \ + iface-core \ + util \ + +src_iface-acio := \ + mgr.c \ diff --git a/src/main/iface-acio/mgr.c b/src/main/iface-acio/mgr.c new file mode 100644 index 0000000..bd1e8c5 --- /dev/null +++ b/src/main/iface-acio/mgr.c @@ -0,0 +1,135 @@ +#define LOG_MODULE "bt-acio-mgr" + +#include + +#include "api/acio/mgr.h" + +#include "iface-core/log.h" + +#define BT_ACIO_MGR_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_acio_mgr_api_t _bt_acio_mgr_api; + +static bool _bt_acio_mgr_api_is_valid() +{ + return _bt_acio_mgr_api.version > 0; +} + +void bt_acio_mgr_api_set(const bt_acio_mgr_api_t *api) +{ + log_assert(api); + + if (_bt_acio_mgr_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + BT_ACIO_MGR_ASSERT_IMPLEMENTED( + api->v1.port_init, "bt_acio_mgr_port_init"); + BT_ACIO_MGR_ASSERT_IMPLEMENTED( + api->v1.port_fini, "bt_acio_mgr_port_fini"); + BT_ACIO_MGR_ASSERT_IMPLEMENTED( + api->v1.node_count_get, "bt_acio_mgr_node_count_get"); + BT_ACIO_MGR_ASSERT_IMPLEMENTED( + api->v1.node_product_ident_get, + "bt_acio_mgr_node_product_ident_get"); + BT_ACIO_MGR_ASSERT_IMPLEMENTED( + api->v1.port_packet_submit, "bt_acio_mgr_port_packet_submit"); + BT_ACIO_MGR_ASSERT_IMPLEMENTED( + api->v1.port_checkout, "bt_acio_mgr_port_checkout"); + BT_ACIO_MGR_ASSERT_IMPLEMENTED( + api->v1.port_checkin, "bt_acio_mgr_port_checkin"); + + memcpy(&_bt_acio_mgr_api, api, sizeof(bt_acio_mgr_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_acio_mgr_api_get(bt_acio_mgr_api_t *api) +{ + log_assert(api); + log_assert(_bt_acio_mgr_api_is_valid()); + + memcpy(api, &_bt_acio_mgr_api, sizeof(bt_acio_mgr_api_t)); +} + +void bt_acio_mgr_api_clear() +{ + log_assert(_bt_acio_mgr_api_is_valid()); + + memset(&_bt_acio_mgr_api, 0, sizeof(bt_acio_mgr_api_t)); + + log_misc("api cleared"); +} + +bt_acio_mgr_port_dispatcher_t * +bt_acio_mgr_port_init(const char *path, uint32_t baud) +{ + log_assert(_bt_acio_mgr_api_is_valid()); + + log_misc("port init: %s, %d", path, baud); + + return _bt_acio_mgr_api.v1.port_init(path, baud); +} + +void bt_acio_mgr_port_fini(bt_acio_mgr_port_dispatcher_t *dispatcher) +{ + log_assert(_bt_acio_mgr_api_is_valid()); + + log_misc(">>> port fini"); + + _bt_acio_mgr_api.v1.port_fini(dispatcher); + + log_misc("<<< port fini"); +} + +uint8_t +bt_acio_mgr_node_count_get(const bt_acio_mgr_port_dispatcher_t *dispatcher) +{ + log_assert(_bt_acio_mgr_api_is_valid()); + + return _bt_acio_mgr_api.v1.node_count_get(dispatcher); +} + +bool bt_acio_mgr_node_product_ident_get( + const bt_acio_mgr_port_dispatcher_t *dispatcher, + uint8_t node_id, + char product[BT_ACIO_MGR_NODE_PRODUCT_CODE_LEN]) +{ + log_assert(_bt_acio_mgr_api_is_valid()); + + return _bt_acio_mgr_api.v1.node_product_ident_get( + dispatcher, node_id, product); +} + +bool bt_acio_mgr_port_packet_submit( + bt_acio_mgr_port_dispatcher_t *dispatcher, + bt_acio_message_t *msg, + uint32_t max_resp_size) +{ + log_assert(_bt_acio_mgr_api_is_valid()); + + return _bt_acio_mgr_api.v1.port_packet_submit( + dispatcher, msg, max_resp_size); +} + +bt_acio_drv_device_ctx_t * +bt_acio_mgr_port_checkout(bt_acio_mgr_port_dispatcher_t *dispatcher) +{ + log_assert(_bt_acio_mgr_api_is_valid()); + + return _bt_acio_mgr_api.v1.port_checkout(dispatcher); +} + +void bt_acio_mgr_port_checkin(bt_acio_mgr_port_dispatcher_t *dispatcher) +{ + log_assert(_bt_acio_mgr_api_is_valid()); + + _bt_acio_mgr_api.v1.port_checkin(dispatcher); +} diff --git a/src/main/aciomgr/manager.h b/src/main/iface-acio/mgr.h similarity index 54% rename from src/main/aciomgr/manager.h rename to src/main/iface-acio/mgr.h index d2127a8..f235467 100644 --- a/src/main/aciomgr/manager.h +++ b/src/main/iface-acio/mgr.h @@ -1,26 +1,14 @@ -#ifndef ACIOMGR_MANAGER_H -#define ACIOMGR_MANAGER_H +#ifndef BT_ACIO_MGR_H +#define BT_ACIO_MGR_H #include +#include -#include "bemanitools/glue.h" +#include "api/acio/mgr.h" -#define ACIOMGR_NODE_PRODUCT_CODE_LEN 4 - -struct ac_io_message; -struct aciodrv_device_ctx; -struct aciomgr_port_dispatcher; - -/** - * The first function that will be called on your DLL. You will be supplied - * with four function pointers that may be used to log messages to the game's - * log file. See comments in glue.h for further information. - */ -void aciomgr_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); +void bt_acio_mgr_api_set(const bt_acio_mgr_api_t *api); +void bt_acio_mgr_api_get(bt_acio_mgr_api_t *api); +void bt_acio_mgr_api_clear(); /** * Init and open, or return the existing handle to an acio port @@ -28,9 +16,10 @@ void aciomgr_set_loggers( * @param path Port the device is connected to (e.g. "COM1") * @return opened port dispatcher context, NULL on error */ -struct aciomgr_port_dispatcher *aciomgr_port_init(const char *path, int baud); +bt_acio_mgr_port_dispatcher_t * +bt_acio_mgr_port_init(const char *path, uint32_t baud); -void aciomgr_port_fini(struct aciomgr_port_dispatcher *dispatcher); +void bt_acio_mgr_port_fini(bt_acio_mgr_port_dispatcher_t *dispatcher); /** * Get the node count on the opened device. @@ -38,7 +27,8 @@ void aciomgr_port_fini(struct aciomgr_port_dispatcher *dispatcher); * @param dispatcher dispatcher context from aciomgr_port_init * @return Total num of nodes enumerated on the ACIO device. */ -uint8_t aciomgr_get_node_count(struct aciomgr_port_dispatcher *dispatcher); +uint8_t +bt_acio_mgr_node_count_get(const bt_acio_mgr_port_dispatcher_t *dispatcher); /** * Get the product identifier of an enumerated node. @@ -49,10 +39,10 @@ uint8_t aciomgr_get_node_count(struct aciomgr_port_dispatcher *dispatcher); * @return True on success, false on error. If True the variable product * contains the identifier of the queried node. */ -bool aciomgr_get_node_product_ident( - struct aciomgr_port_dispatcher *dispatcher, +bool bt_acio_mgr_node_product_ident_get( + const bt_acio_mgr_port_dispatcher_t *dispatcher, uint8_t node_id, - char product[ACIOMGR_NODE_PRODUCT_CODE_LEN]); + char product[BT_ACIO_MGR_NODE_PRODUCT_CODE_LEN]); /** * Submit and wait for the response of the specified packet @@ -62,10 +52,10 @@ bool aciomgr_get_node_product_ident( * @param max_resp_size pointer to the max size response we expect * @return false on error */ -bool aciomgr_port_submit_packet( - struct aciomgr_port_dispatcher *dispatcher, - struct ac_io_message *msg, - int max_resp_size); +bool bt_acio_mgr_port_packet_submit( + const bt_acio_mgr_port_dispatcher_t *dispatcher, + const bt_acio_message_t *msg, + uint32_t max_resp_size); /** * Checkout the device handler for this port dispatcher on this thread @@ -73,14 +63,14 @@ bool aciomgr_port_submit_packet( * @param dispatcher dispatcher context from aciomgr_port_init * @return the device context */ -struct aciodrv_device_ctx * -aciomgr_port_checkout(struct aciomgr_port_dispatcher *dispatcher); +bt_acio_drv_device_ctx_t * +bt_acio_mgr_port_checkout(const bt_acio_mgr_port_dispatcher_t *dispatcher); /** * Checkin the device handler that this thread holds * * @param dispatcher dispatcher context from aciomgr_port_init */ -void aciomgr_port_checkin(struct aciomgr_port_dispatcher *dispatcher); +void bt_acio_mgr_port_checkin(const bt_acio_mgr_port_dispatcher_t *dispatcher); -#endif +#endif \ No newline at end of file diff --git a/src/main/iface-core/Module.mk b/src/main/iface-core/Module.mk new file mode 100644 index 0000000..ddcbcd0 --- /dev/null +++ b/src/main/iface-core/Module.mk @@ -0,0 +1,9 @@ +libs += iface-core + +libs_iface-core := \ + util \ + +src_iface-core := \ + config.c \ + log.c \ + thread.c \ diff --git a/src/main/iface-core/config.c b/src/main/iface-core/config.c new file mode 100644 index 0000000..e5a4e31 --- /dev/null +++ b/src/main/iface-core/config.c @@ -0,0 +1,245 @@ +#define LOG_MODULE "bt-core-config" + +#include +#include +#include + +#include "api/core/config.h" + +#include "iface-core/log.h" + +#define BT_CORE_CONFIG_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_core_config_api_t _bt_core_config_api; + +static bool _bt_core_config_api_is_valid() +{ + return _bt_core_config_api.version > 0; +} + +void bt_core_config_api_set(const bt_core_config_api_t *api) +{ + log_assert(api); + + if (_bt_core_config_api_is_valid()) { + log_info("Re-initialize"); + } + + if (api->version == 1) { + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.s8_get, s8_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.u8_get, u8_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.s16_get, s16_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.u16_get, u16_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.s32_get, s32_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.u32_get, u32_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.s64_get, s64_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.u64_get, u64_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.float_get, float_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.double_get, double_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.bool_get, bool_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.bin_get, bin_get); + BT_CORE_CONFIG_ASSERT_IMPLEMENTED(api->v1.str_get, str_get); + + memcpy(&_bt_core_config_api, api, sizeof(bt_core_config_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_core_config_api_get(bt_core_config_api_t *api) +{ + log_assert(api); + log_assert(_bt_core_config_api_is_valid()); + + memcpy(api, &_bt_core_config_api, sizeof(bt_core_config_api_t)); +} + +void bt_core_config_api_clear() +{ + log_assert(_bt_core_config_api_is_valid()); + + memset(&_bt_core_config_api, 0, sizeof(bt_core_config_api_t)); + + log_misc("api cleared"); +} + +const char *bt_core_config_result_to_str(bt_core_config_result_t result) +{ + switch (result) { + case BT_CORE_CONFIG_RESULT_SUCCESS: + return "Success"; + case BT_CORE_CONFIG_RESULT_ERROR_INTERNAL: + return "Internal"; + case BT_CORE_CONFIG_RESULT_VALUE_NOT_FOUND: + return "Value not found"; + case BT_CORE_CONFIG_RESULT_TYPE_MISMATCH: + return "Type mismatch"; + default: + return "Undefined error"; + } +} + +void br_core_config_fatal_on_error(bt_core_config_result_t result) +{ + switch (result) { + case BT_CORE_CONFIG_RESULT_SUCCESS: + return; + case BT_CORE_CONFIG_RESULT_ERROR_INTERNAL: + case BT_CORE_CONFIG_RESULT_VALUE_NOT_FOUND: + case BT_CORE_CONFIG_RESULT_TYPE_MISMATCH: + default: + log_fatal( + "Operation on config failed: %s", + bt_core_config_result_to_str(result)); + } +} + +bt_core_config_result_t bt_core_config_s8_get( + const bt_core_config_t *config, const char *path, int8_t *value) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + + return _bt_core_config_api.v1.s8_get(config, path, value); +} + +bt_core_config_result_t bt_core_config_u8_get( + const bt_core_config_t *config, const char *path, uint8_t *value) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + + return _bt_core_config_api.v1.u8_get(config, path, value); +} + +bt_core_config_result_t bt_core_config_s16_get( + const bt_core_config_t *config, const char *path, int16_t *value) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + + return _bt_core_config_api.v1.s16_get(config, path, value); +} + +bt_core_config_result_t bt_core_config_u16_get( + const bt_core_config_t *config, const char *path, uint16_t *value) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + + return _bt_core_config_api.v1.u16_get(config, path, value); +} + +bt_core_config_result_t bt_core_config_s32_get( + const bt_core_config_t *config, const char *path, int32_t *value) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + + return _bt_core_config_api.v1.s32_get(config, path, value); +} + +bt_core_config_result_t bt_core_config_u32_get( + const bt_core_config_t *config, const char *path, uint32_t *value) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + + return _bt_core_config_api.v1.u32_get(config, path, value); +} + +bt_core_config_result_t bt_core_config_s64_get( + const bt_core_config_t *config, const char *path, int64_t *value) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + + return _bt_core_config_api.v1.s64_get(config, path, value); +} + +bt_core_config_result_t bt_core_config_u64_get( + const bt_core_config_t *config, const char *path, uint64_t *value) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + + return _bt_core_config_api.v1.u64_get(config, path, value); +} + +bt_core_config_result_t bt_core_config_float_get( + const bt_core_config_t *config, const char *path, float *value) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + + return _bt_core_config_api.v1.float_get(config, path, value); +} + +bt_core_config_result_t bt_core_config_double_get( + const bt_core_config_t *config, const char *path, double *value) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + + return _bt_core_config_api.v1.double_get(config, path, value); +} + +bt_core_config_result_t bt_core_config_bool_get( + const bt_core_config_t *config, const char *path, bool *value) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + + return _bt_core_config_api.v1.bool_get(config, path, value); +} + +bt_core_config_result_t bt_core_config_bin_get( + const bt_core_config_t *config, const char *path, void *value, size_t len) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + log_assert(len > 0); + + return _bt_core_config_api.v1.bin_get(config, path, value, len); +} + +bt_core_config_result_t bt_core_config_str_get( + const bt_core_config_t *config, const char *path, char *value, size_t len) +{ + log_assert(_bt_core_config_api_is_valid()); + log_assert(config); + log_assert(path); + log_assert(value); + log_assert(len > 0); + + return _bt_core_config_api.v1.str_get(config, path, value, len); +} \ No newline at end of file diff --git a/src/main/iface-core/config.h b/src/main/iface-core/config.h new file mode 100644 index 0000000..6d30267 --- /dev/null +++ b/src/main/iface-core/config.h @@ -0,0 +1,42 @@ +#ifndef BT_CORE_CONFIG_H +#define BT_CORE_CONFIG_H + +#include + +#include "api/core/config.h" + +void bt_core_config_api_set(const bt_core_config_api_t *api); +void bt_core_config_api_get(bt_core_config_api_t *api); +void bt_core_config_api_clear(); + +const char *bt_core_config_result_to_str(bt_core_config_result_t result); +void bt_core_config_fatal_on_error(bt_core_config_result_t result); + +bt_core_config_result_t bt_core_config_s8_get( + const bt_core_config_t *config, const char *path, int8_t *value); +bt_core_config_result_t bt_core_config_u8_get( + const bt_core_config_t *config, const char *path, uint8_t *value); +bt_core_config_result_t bt_core_config_s16_get( + const bt_core_config_t *config, const char *path, int16_t *value); +bt_core_config_result_t bt_core_config_u16_get( + const bt_core_config_t *config, const char *path, uint16_t *value); +bt_core_config_result_t bt_core_config_s32_get( + const bt_core_config_t *config, const char *path, int32_t *value); +bt_core_config_result_t bt_core_config_u32_get( + const bt_core_config_t *config, const char *path, uint32_t *value); +bt_core_config_result_t bt_core_config_s64_get( + const bt_core_config_t *config, const char *path, int64_t *value); +bt_core_config_result_t bt_core_config_u64_get( + const bt_core_config_t *config, const char *path, uint64_t *value); +bt_core_config_result_t bt_core_config_float_get( + const bt_core_config_t *config, const char *path, float *value); +bt_core_config_result_t bt_core_config_double_get( + const bt_core_config_t *config, const char *path, double *value); +bt_core_config_result_t bt_core_config_bool_get( + const bt_core_config_t *config, const char *path, bool *value); +bt_core_config_result_t bt_core_config_bin_get( + const bt_core_config_t *config, const char *path, void *value, size_t len); +bt_core_config_result_t bt_core_config_str_get( + const bt_core_config_t *config, const char *path, char *value, size_t len); + +#endif \ No newline at end of file diff --git a/src/main/iface-core/log.c b/src/main/iface-core/log.c new file mode 100644 index 0000000..97a987b --- /dev/null +++ b/src/main/iface-core/log.c @@ -0,0 +1,58 @@ +#define LOG_MODULE "bt-core-log" + +#include +#include +#include + +#include "iface-core/log.h" + +#define BT_CORE_LOG_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +bt_core_log_api_t _bt_core_log_api; + +static bool _bt_core_log_api_is_valid() +{ + return _bt_core_log_api.version > 0; +} + +void bt_core_log_api_set(const bt_core_log_api_t *api) +{ + log_assert(api); + + if (_bt_core_log_api_is_valid()) { + log_info("Re-initialize"); + } + + if (api->version == 1) { + BT_CORE_LOG_ASSERT_IMPLEMENTED(api->v1.misc, misc); + BT_CORE_LOG_ASSERT_IMPLEMENTED(api->v1.info, info); + BT_CORE_LOG_ASSERT_IMPLEMENTED(api->v1.warning, warning); + BT_CORE_LOG_ASSERT_IMPLEMENTED(api->v1.fatal, fatal); + + memcpy(&_bt_core_log_api, api, sizeof(bt_core_log_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_core_log_api_get(bt_core_log_api_t *api) +{ + log_assert(api); + log_assert(_bt_core_log_api_is_valid()); + + memcpy(api, &_bt_core_log_api, sizeof(bt_core_log_api_t)); +} + +void bt_core_log_api_clear() +{ + log_assert(_bt_core_log_api_is_valid()); + + memset(&_bt_core_log_api, 0, sizeof(bt_core_log_api_t)); + + log_misc("api cleared"); +} \ No newline at end of file diff --git a/src/main/core/log.h b/src/main/iface-core/log.h similarity index 54% rename from src/main/core/log.h rename to src/main/iface-core/log.h index 5b5cd9d..1858add 100644 --- a/src/main/core/log.h +++ b/src/main/iface-core/log.h @@ -1,11 +1,14 @@ -#ifndef CORE_LOG_H -#define CORE_LOG_H +#ifndef BT_CORE_LOG_H +#define BT_CORE_LOG_H +#include #include #include #include "util/defs.h" +#include "api/core/log.h" + /** * The core log API of bemanitools. * @@ -35,7 +38,8 @@ * @param ... Additional arguments according to the specified arguments in the * printf format string */ -#define log_misc(...) _core_log_misc_impl(LOG_MODULE, __VA_ARGS__) +#define log_misc_func _bt_core_log_api.v1.misc +#define log_misc(...) log_misc_func(LOG_MODULE, __VA_ARGS__) /** * Log a message on info level @@ -50,7 +54,7 @@ * @param ... Additional arguments according to the specified arguments in the * printf format string */ -#define log_info(...) _core_log_info_impl(LOG_MODULE, __VA_ARGS__) +#define log_info(...) _bt_core_log_api.v1.info(LOG_MODULE, __VA_ARGS__) /** * Log a message on warning level @@ -65,7 +69,7 @@ * @param ... Additional arguments according to the specified arguments in the * printf format string */ -#define log_warning(...) _core_log_warning_impl(LOG_MODULE, __VA_ARGS__) +#define log_warning(...) _bt_core_log_api.v1.warning(LOG_MODULE, __VA_ARGS__) /** * Log a message on fatal level @@ -82,10 +86,10 @@ * @param ... Additional arguments according to the specified arguments in the * printf format string */ -#define log_fatal(...) \ - do { \ - _core_log_fatal_impl(LOG_MODULE, __VA_ARGS__); \ - abort(); \ +#define log_fatal(...) \ + do { \ + _bt_core_log_api.v1.fatal(LOG_MODULE, __VA_ARGS__); \ + abort(); \ } while (0) /** @@ -101,7 +105,7 @@ #define log_assert(x) \ do { \ if (!(x)) { \ - _core_log_fatal_impl( \ + _bt_core_log_api.v1.fatal( \ "assert", \ "%s:%d: function `%s'", \ __FILE__, \ @@ -122,76 +126,15 @@ * printf format string */ #define log_exception_handler(...) \ - _core_log_fatal_impl("exception", __VA_ARGS__) + _bt_core_log_api.v1.fatal("exception", __VA_ARGS__) -typedef void (*core_log_message_t)(const char *module, const char *fmt, ...); +void bt_core_log_api_set(const bt_core_log_api_t *api); +void bt_core_log_api_get(bt_core_log_api_t *api); +void bt_core_log_api_clear(); -typedef void (*core_log_impl_set_t)( - core_log_message_t misc, - core_log_message_t info, - core_log_message_t warning, - core_log_message_t fatal); - -/** - * Configure the log API implementations - * - * Advised to do this as early in your application/library module as possible - * as calls to the getter functions below will return the currently configured - * implementations. - * - * @param misc Pointer to a function implementing logging on misc level - * @param info Pointer to a function implementing logging on info level - * @param warning Pointer to a function implementing logging on warning level - * @param fatal Pointer to a function implementing logging on fatal level - */ -void core_log_impl_set( - core_log_message_t misc, - core_log_message_t info, - core_log_message_t warning, - core_log_message_t fatal); - -/** - * Supporting function to inject/assign the currently set implementation - * with the given setter function. - * - * @param impl_set Setter function to call with the currently configured log - * function implementations - */ -void core_log_impl_assign(core_log_impl_set_t impl_set); - -/** - * Get the currently configured implementation of the misc level log function - * - * @return Pointer to the currently configured implementation of the function - */ -core_log_message_t core_log_misc_impl_get(); - -/** - * Get the currently configured implementation of the info level log function - * - * @return Pointer to the currently configured implementation of the function - */ -core_log_message_t core_log_info_impl_get(); - -/** - * Get the currently configured implementation of the warning level log function - * - * @return Pointer to the currently configured implementation of the function - */ -core_log_message_t core_log_warning_impl_get(); - -/** - * Get the currently configured implementation of the fatal level log function - * - * @return Pointer to the currently configured implementation of the function - */ -core_log_message_t core_log_fatal_impl_get(); - -// Do not use these directly. -// These are only here to allow usage in the macros above. -extern core_log_message_t _core_log_misc_impl; -extern core_log_message_t _core_log_info_impl; -extern core_log_message_t _core_log_warning_impl; -extern core_log_message_t _core_log_fatal_impl; +// Do not use this directly. This is required to work around requiring the +// interface to use var args. Use the macros above to invoke the logging +// functions +extern bt_core_log_api_t _bt_core_log_api; #endif \ No newline at end of file diff --git a/src/main/iface-core/thread.c b/src/main/iface-core/thread.c new file mode 100644 index 0000000..093d77e --- /dev/null +++ b/src/main/iface-core/thread.c @@ -0,0 +1,115 @@ +#define LOG_MODULE "bt-core-thread" + +#include +#include +#include + +#include "api/core/thread.h" + +#include "iface-core/log.h" + +#define BT_CORE_THREAD_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_core_thread_api_t _bt_core_thread_api; + +static bool _bt_core_thread_api_is_valid() +{ + return _bt_core_thread_api.version > 0; +} + +void bt_core_thread_api_set(const bt_core_thread_api_t *api) +{ + log_assert(api); + + if (_bt_core_thread_api_is_valid()) { + log_info("Re-initialize"); + } + + if (api->version == 1) { + BT_CORE_THREAD_ASSERT_IMPLEMENTED(api->v1.create, create); + BT_CORE_THREAD_ASSERT_IMPLEMENTED(api->v1.join, join); + BT_CORE_THREAD_ASSERT_IMPLEMENTED(api->v1.destroy, destroy); + + memcpy(&_bt_core_thread_api, api, sizeof(bt_core_thread_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_core_thread_api_get(bt_core_thread_api_t *api) +{ + log_assert(api); + log_assert(_bt_core_thread_api_is_valid()); + + memcpy(api, &_bt_core_thread_api, sizeof(bt_core_thread_api_t)); +} + +void bt_core_thread_api_clear() +{ + log_assert(_bt_core_thread_api_is_valid()); + + memset(&_bt_core_thread_api, 0, sizeof(bt_core_thread_api_t)); + + log_misc("api cleared"); +} + +const char *bt_core_thread_result_to_str(bt_core_thread_result_t result) +{ + switch (result) { + case BT_CORE_THREAD_RESULT_SUCCESS: + return "Success"; + case BT_CORE_THREAD_RESULT_ERROR_INTERNAL: + return "Internal"; + default: + return "Undefined error"; + } +} + +void bt_core_thread_fatal_on_error(bt_core_thread_result_t result) +{ + switch (result) { + case BT_CORE_THREAD_RESULT_SUCCESS: + return; + case BT_CORE_THREAD_RESULT_ERROR_INTERNAL: + default: + log_fatal( + "Operation on thread failed: %s", + bt_core_thread_result_to_str(result)); + } +} + +bt_core_thread_result_t bt_core_thread_create( + int (*proc)(void *), + void *ctx, + uint32_t stack_sz, + unsigned int priority, + bt_core_thread_id_t *thread_id) +{ + log_assert(_bt_core_thread_api_is_valid()); + log_assert(proc); + log_assert(stack_sz > 0); + log_assert(thread_id); + + return _bt_core_thread_api.v1.create( + proc, ctx, stack_sz, priority, thread_id); +} + +bt_core_thread_result_t +bt_core_thread_join(bt_core_thread_id_t thread_id, int *result) +{ + log_assert(_bt_core_thread_api_is_valid()); + + return _bt_core_thread_api.v1.join(thread_id, result); +} + +bt_core_thread_result_t bt_core_thread_destroy(bt_core_thread_id_t thread_id) +{ + log_assert(_bt_core_thread_api_is_valid()); + + return _bt_core_thread_api.v1.destroy(thread_id); +} diff --git a/src/main/iface-core/thread.h b/src/main/iface-core/thread.h new file mode 100644 index 0000000..2bf1d46 --- /dev/null +++ b/src/main/iface-core/thread.h @@ -0,0 +1,25 @@ +#ifndef BT_CORE_THREAD_H +#define BT_CORE_THREAD_H + +#include + +#include "api/core/thread.h" + +void bt_core_thread_api_set(const bt_core_thread_api_t *api); +void bt_core_thread_api_get(bt_core_thread_api_t *api); +void bt_core_thread_api_clear(); + +const char *bt_core_thread_result_to_str(bt_core_thread_result_t result); +void bt_core_thread_fatal_on_error(bt_core_thread_result_t result); + +bt_core_thread_result_t bt_core_thread_create( + int (*proc)(void *), + void *ctx, + uint32_t stack_sz, + unsigned int priority, + bt_core_thread_id_t *thread_id); +bt_core_thread_result_t +bt_core_thread_join(bt_core_thread_id_t thread_id, int *result); +bt_core_thread_result_t bt_core_thread_destroy(bt_core_thread_id_t thread_id); + +#endif diff --git a/src/main/iface-io/Module.mk b/src/main/iface-io/Module.mk new file mode 100644 index 0000000..33f8122 --- /dev/null +++ b/src/main/iface-io/Module.mk @@ -0,0 +1,15 @@ +libs += iface-io + +libs_iface-io := \ + util \ + +src_iface-io := \ + bst.c \ + eam.c \ + ddr.c \ + eam.c \ + iidx.c \ + jb.c \ + popn.c \ + sdvx.c \ + vefx.c \ diff --git a/src/main/iface-io/bst.c b/src/main/iface-io/bst.c new file mode 100644 index 0000000..87c7be3 --- /dev/null +++ b/src/main/iface-io/bst.c @@ -0,0 +1,100 @@ +#define LOG_MODULE "bt-io-bst" + +#include + +#include "api/io/bst.h" + +#include "iface-core/log.h" + +#define BT_IO_BST_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_io_bst_api_t _bt_io_bst_api; + +static bool _bt_io_bst_api_is_valid() +{ + return _bt_io_bst_api.version > 0; +} + +void bt_io_bst_api_set(const bt_io_bst_api_t *api) +{ + log_assert(api); + + if (_bt_io_bst_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + BT_IO_BST_ASSERT_IMPLEMENTED(api->v1.init, "bt_io_bst_init"); + BT_IO_BST_ASSERT_IMPLEMENTED(api->v1.fini, "bt_io_bst_fini"); + + BT_IO_BST_ASSERT_IMPLEMENTED( + api->v1.input_read, "bt_io_bst_input_read"); + BT_IO_BST_ASSERT_IMPLEMENTED(api->v1.input_get, "bt_io_bst_input_get"); + + memcpy(&_bt_io_bst_api, api, sizeof(bt_io_bst_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_io_bst_api_get(bt_io_bst_api_t *api) +{ + log_assert(api); + log_assert(_bt_io_bst_api_is_valid()); + + memcpy(api, &_bt_io_bst_api, sizeof(bt_io_bst_api_t)); +} + +void bt_io_bst_api_clear() +{ + log_assert(_bt_io_bst_api_is_valid()); + + memset(&_bt_io_bst_api, 0, sizeof(bt_io_bst_api_t)); + + log_misc("api cleared"); +} + +bool bt_io_bst_init() +{ + bool result; + + log_assert(_bt_io_bst_api_is_valid()); + + log_misc(">>> init"); + + result = _bt_io_bst_api.v1.init(); + + log_misc("<<< init: %d", result); + + return result; +} + +void bt_io_bst_fini() +{ + log_assert(_bt_io_bst_api_is_valid()); + + log_misc(">>> fini"); + + _bt_io_bst_api.v1.fini(); + + log_misc("<<< fini"); +} + +bool bt_io_bst_input_read() +{ + log_assert(_bt_io_bst_api_is_valid()); + + return _bt_io_bst_api.v1.input_read(); +} + +uint8_t bt_io_bst_input_get() +{ + log_assert(_bt_io_bst_api_is_valid()); + + return _bt_io_bst_api.v1.input_get(); +} \ No newline at end of file diff --git a/src/main/iface-io/bst.h b/src/main/iface-io/bst.h new file mode 100644 index 0000000..41845fd --- /dev/null +++ b/src/main/iface-io/bst.h @@ -0,0 +1,19 @@ +#ifndef API_IO_BST_H +#define API_IO_BST_H + +#include +#include + +#include "api/io/bst.h" + +void bt_io_bst_api_set(const bt_io_bst_api_t *api); +void bt_io_bst_api_get(bt_io_bst_api_t *api); +void bt_io_bst_api_clear(); + +bool bt_io_bst_init(); +void bt_io_bst_fini(); + +bool bt_io_bst_input_read(); +uint8_t bt_io_bst_input_get(); + +#endif \ No newline at end of file diff --git a/src/main/iface-io/ddr.c b/src/main/iface-io/ddr.c new file mode 100644 index 0000000..f448689 --- /dev/null +++ b/src/main/iface-io/ddr.c @@ -0,0 +1,142 @@ +#define LOG_MODULE "bt-io-ddr" + +#include + +#include "api/io/ddr.h" + +#include "iface-core/log.h" + +#define BT_IO_DDR_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_io_ddr_api_t _bt_io_ddr_api; + +static bool _bt_io_ddr_api_is_valid() +{ + return _bt_io_ddr_api.version > 0; +} + +void bt_io_ddr_api_set(const bt_io_ddr_api_t *api) +{ + log_assert(api); + + if (_bt_io_ddr_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + BT_IO_DDR_ASSERT_IMPLEMENTED(api->v1.init, "bt_io_ddr_init"); + BT_IO_DDR_ASSERT_IMPLEMENTED(api->v1.fini, "bt_io_ddr_fini"); + + BT_IO_DDR_ASSERT_IMPLEMENTED(api->v1.pad_read, "bt_io_ddr_pad_read"); + BT_IO_DDR_ASSERT_IMPLEMENTED( + api->v1.extio_lights_set, "bt_io_ddr_extio_lights_set"); + BT_IO_DDR_ASSERT_IMPLEMENTED( + api->v1.p3io_lights_set, "bt_io_ddr_p3io_lights_set"); + BT_IO_DDR_ASSERT_IMPLEMENTED( + api->v1.hdxs_lights_panel_set, "bt_io_ddr_hdxs_lights_panel_set"); + BT_IO_DDR_ASSERT_IMPLEMENTED( + api->v1.hdxs_lights_rgb_set, "bt_io_ddr_hdxs_lights_rgb_set"); + + memcpy(&_bt_io_ddr_api, api, sizeof(bt_io_ddr_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_io_ddr_api_get(bt_io_ddr_api_t *api) +{ + log_assert(api); + log_assert(_bt_io_ddr_api_is_valid()); + + memcpy(api, &_bt_io_ddr_api, sizeof(bt_io_ddr_api_t)); +} + +void bt_io_ddr_api_clear() +{ + log_assert(_bt_io_ddr_api_is_valid()); + + memset(&_bt_io_ddr_api, 0, sizeof(bt_io_ddr_api_t)); + + log_misc("api cleared"); +} + +bool bt_io_ddr_init() +{ + bool result; + + log_assert(_bt_io_ddr_api_is_valid()); + + log_misc(">>> init"); + + result = _bt_io_ddr_api.v1.init(); + + log_misc("<<< init: %d", result); + + return result; +} + +void bt_io_ddr_fini() +{ + log_assert(_bt_io_ddr_api_is_valid()); + + log_misc(">>> fini"); + + _bt_io_ddr_api.v1.fini(); + + log_misc("<<< fini"); +} + +uint32_t bt_io_ddr_pad_read() +{ + log_assert(_bt_io_ddr_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_ddr_api.v1.pad_read(); +} + +void bt_io_ddr_extio_lights_set(uint32_t extio_lights) +{ + log_assert(_bt_io_ddr_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + _bt_io_ddr_api.v1.extio_lights_set(extio_lights); +} + +void bt_io_ddr_p3io_lights_set(uint32_t p3io_lights) +{ + log_assert(_bt_io_ddr_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + _bt_io_ddr_api.v1.p3io_lights_set(p3io_lights); +} + +void bt_io_ddr_hdxs_lights_panel_set(uint32_t hdxs_lights) +{ + log_assert(_bt_io_ddr_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_ddr_api.v1.hdxs_lights_panel_set(hdxs_lights); +} + +void bt_io_ddr_hdxs_lights_rgb_set(uint8_t idx, uint8_t r, uint8_t g, uint8_t b) +{ + log_assert(_bt_io_ddr_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_ddr_api.v1.hdxs_lights_rgb_set(idx, r, g, b); +} diff --git a/src/main/iface-io/ddr.h b/src/main/iface-io/ddr.h new file mode 100644 index 0000000..f04ef11 --- /dev/null +++ b/src/main/iface-io/ddr.h @@ -0,0 +1,23 @@ +#ifndef API_IO_DDR_H +#define API_IO_DDR_H + +#include +#include + +#include "api/io/ddr.h" + +void bt_io_ddr_api_set(const bt_io_ddr_api_t *api); +void bt_io_ddr_api_get(bt_io_ddr_api_t *api); +void bt_io_ddr_api_clear(); + +bool bt_io_ddr_init(); +void bt_io_ddr_fini(); + +uint32_t bt_io_ddr_pad_read(); +void bt_io_ddr_extio_lights_set(uint32_t extio_lights); +void bt_io_ddr_p3io_lights_set(uint32_t p3io_lights); +void bt_io_ddr_hdxs_lights_panel_set(uint32_t hdxs_lights); +void bt_io_ddr_hdxs_lights_rgb_set( + uint8_t idx, uint8_t r, uint8_t g, uint8_t b); + +#endif \ No newline at end of file diff --git a/src/main/iface-io/eam.c b/src/main/iface-io/eam.c new file mode 100644 index 0000000..6abe5d4 --- /dev/null +++ b/src/main/iface-io/eam.c @@ -0,0 +1,137 @@ +#define LOG_MODULE "bt-io-eam" + +#include + +#include "api/io/eam.h" + +#include "iface-core/log.h" + +#define BT_IO_EAM_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_io_eam_api_t _bt_io_eam_api; + +static bool _bt_io_eam_api_is_valid() +{ + return _bt_io_eam_api.version > 0; +} + +void bt_io_eam_api_set(const bt_io_eam_api_t *api) +{ + log_assert(api); + + if (_bt_io_eam_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + BT_IO_EAM_ASSERT_IMPLEMENTED(api->v1.init, "bt_io_eam_init"); + BT_IO_EAM_ASSERT_IMPLEMENTED(api->v1.fini, "bt_io_eam_fini"); + + BT_IO_EAM_ASSERT_IMPLEMENTED( + api->v1.keypad_state_get, "bt_io_eam_keypad_state_get"); + BT_IO_EAM_ASSERT_IMPLEMENTED( + api->v1.sensor_state_get, "bt_io_eam_sensor_state_get"); + BT_IO_EAM_ASSERT_IMPLEMENTED(api->v1.card_read, "bt_io_eam_card_read"); + BT_IO_EAM_ASSERT_IMPLEMENTED( + api->v1.card_slot_cmd_send, "bt_io_eam_card_slot_cmd_send"); + BT_IO_EAM_ASSERT_IMPLEMENTED(api->v1.poll, "bt_io_eam_poll"); + + BT_IO_EAM_ASSERT_IMPLEMENTED( + api->v1.config_api_get, "bt_io_eam_config_api_get"); + + memcpy(&_bt_io_eam_api, api, sizeof(bt_io_eam_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_io_eam_api_get(bt_io_eam_api_t *api) +{ + log_assert(api); + log_assert(_bt_io_eam_api_is_valid()); + + memcpy(api, &_bt_io_eam_api, sizeof(bt_io_eam_api_t)); +} + +void bt_io_eam_api_clear() +{ + log_assert(_bt_io_eam_api_is_valid()); + + memset(&_bt_io_eam_api, 0, sizeof(bt_io_eam_api_t)); + + log_misc("api cleared"); +} + +bool bt_io_eam_init() +{ + bool result; + + log_assert(_bt_io_eam_api_is_valid()); + + log_misc(">>> init"); + + result = _bt_io_eam_api.v1.init(); + + log_misc("<<< init: %d", result); + + return result; +} + +void bt_io_eam_fini() +{ + log_assert(_bt_io_eam_api_is_valid()); + + log_misc(">>> fini"); + + _bt_io_eam_api.v1.fini(); + + log_misc("<<< fini"); +} + +uint16_t bt_io_eam_keypad_state_get(uint8_t unit_no) +{ + log_assert(_bt_io_eam_api_is_valid()); + + return _bt_io_eam_api.v1.keypad_state_get(unit_no); +} + +uint8_t bt_io_eam_sensor_state_get(uint8_t unit_no) +{ + log_assert(_bt_io_eam_api_is_valid()); + + return _bt_io_eam_api.v1.sensor_state_get(unit_no); +} + +uint8_t bt_io_eam_card_read(uint8_t unit_no, uint8_t *card_id, uint8_t nbytes) +{ + log_assert(_bt_io_eam_api_is_valid()); + log_assert(card_id); + + return _bt_io_eam_api.v1.card_read(unit_no, card_id, nbytes); +} + +bool bt_io_eam_card_slot_cmd_send(uint8_t unit_no, uint8_t cmd) +{ + log_assert(_bt_io_eam_api_is_valid()); + + return _bt_io_eam_api.v1.card_slot_cmd_send(unit_no, cmd); +} + +bool bt_io_eam_poll(uint8_t unit_no) +{ + log_assert(_bt_io_eam_api_is_valid()); + + return _bt_io_eam_api.v1.poll(unit_no); +} + +const bt_io_eam_config_api_t *bt_io_eam_config_api_get() +{ + log_assert(_bt_io_eam_api_is_valid()); + + return _bt_io_eam_api.v1.config_api_get(); +} \ No newline at end of file diff --git a/src/main/iface-io/eam.h b/src/main/iface-io/eam.h new file mode 100644 index 0000000..0ebc866 --- /dev/null +++ b/src/main/iface-io/eam.h @@ -0,0 +1,23 @@ +#ifndef API_IO_EAM_H +#define API_IO_EAM_H + +#include +#include + +#include "api/io/eam.h" + +void bt_io_eam_api_set(const bt_io_eam_api_t *api); +void bt_io_eam_api_get(bt_io_eam_api_t *api); +void bt_io_eam_api_clear(); + +bool bt_io_eam_init(); +void bt_io_eam_fini(); + +uint16_t bt_io_eam_keypad_state_get(uint8_t unit_no); +uint8_t bt_io_eam_sensor_state_get(uint8_t unit_no); +uint8_t bt_io_eam_card_read(uint8_t unit_no, uint8_t *card_id, uint8_t nbytes); +bool bt_io_eam_card_slot_cmd_send(uint8_t unit_no, uint8_t cmd); +bool bt_io_eam_poll(uint8_t unit_no); +const bt_io_eam_config_api_t *bt_io_eam_config_api_get(); + +#endif \ No newline at end of file diff --git a/src/main/iface-io/iidx.c b/src/main/iface-io/iidx.c new file mode 100644 index 0000000..87f23cf --- /dev/null +++ b/src/main/iface-io/iidx.c @@ -0,0 +1,222 @@ +#define LOG_MODULE "bt-io-iidx" + +#include + +#include "api/io/iidx.h" + +#include "iface-core/log.h" + +#define BT_IO_IIDX_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_io_iidx_api_t _bt_io_iidx_api; + +static bool _bt_io_iidx_api_is_valid() +{ + return _bt_io_iidx_api.version > 0; +} + +void bt_io_iidx_api_set(const bt_io_iidx_api_t *api) +{ + log_assert(api); + + if (_bt_io_iidx_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + BT_IO_IIDX_ASSERT_IMPLEMENTED( + api->v1.ep1_deck_lights_set, "bt_io_iidx_ep1_deck_lights_set"); + BT_IO_IIDX_ASSERT_IMPLEMENTED( + api->v1.ep1_panel_lights_set, "bt_io_iidx_ep1_panel_lights_set"); + BT_IO_IIDX_ASSERT_IMPLEMENTED( + api->v1.ep1_top_lamps_set, "bt_io_iidx_ep1_top_lamps_set"); + BT_IO_IIDX_ASSERT_IMPLEMENTED( + api->v1.ep1_top_neons_set, "bt_io_iidx_ep1_top_neons_set"); + BT_IO_IIDX_ASSERT_IMPLEMENTED(api->v1.ep1_send, "bt_io_iidx_ep1_send"); + BT_IO_IIDX_ASSERT_IMPLEMENTED(api->v1.ep2_recv, "bt_io_iidx_ep2_recv"); + BT_IO_IIDX_ASSERT_IMPLEMENTED( + api->v1.ep2_turntable_get, "bt_io_iidx_ep2_turntable_get"); + BT_IO_IIDX_ASSERT_IMPLEMENTED( + api->v1.ep2_slider_get, "bt_io_iidx_ep2_slider_get"); + BT_IO_IIDX_ASSERT_IMPLEMENTED( + api->v1.ep2_sys_get, "bt_io_iidx_ep2_sys_get"); + BT_IO_IIDX_ASSERT_IMPLEMENTED( + api->v1.ep2_panel_get, "bt_io_iidx_ep2_panel_get"); + BT_IO_IIDX_ASSERT_IMPLEMENTED( + api->v1.ep2_keys_get, "bt_io_iidx_ep2_keys_get"); + BT_IO_IIDX_ASSERT_IMPLEMENTED( + api->v1.ep3_16seg_send, "bt_io_iidx_ep3_16seg_send"); + + memcpy(&_bt_io_iidx_api, api, sizeof(bt_io_iidx_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_io_iidx_api_get(bt_io_iidx_api_t *api) +{ + log_assert(api); + log_assert(_bt_io_iidx_api_is_valid()); + + memcpy(api, &_bt_io_iidx_api, sizeof(bt_io_iidx_api_t)); +} + +void bt_io_iidx_api_clear() +{ + log_assert(_bt_io_iidx_api_is_valid()); + + memset(&_bt_io_iidx_api, 0, sizeof(bt_io_iidx_api_t)); + + log_misc("api cleared"); +} + +bool bt_io_iidx_init() +{ + bool result; + + log_assert(_bt_io_iidx_api_is_valid()); + + log_misc(">>> init"); + + result = _bt_io_iidx_api.v1.init(); + + log_misc("<<< init: %d", result); + + return result; +} + +void bt_io_iidx_fini() +{ + log_assert(_bt_io_iidx_api_is_valid()); + + log_misc(">>> fini"); + + _bt_io_iidx_api.v1.fini(); + + log_misc("<<< fini"); +} + +void bt_io_iidx_ep1_deck_lights_set(uint16_t deck_lights) +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + _bt_io_iidx_api.v1.ep1_deck_lights_set(deck_lights); +} + +void bt_io_iidx_ep1_panel_lights_set(uint8_t panel_lights) +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + _bt_io_iidx_api.v1.ep1_panel_lights_set(panel_lights); +} + +void bt_io_iidx_ep1_top_lamps_set(uint8_t top_lamps) +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + _bt_io_iidx_api.v1.ep1_top_lamps_set(top_lamps); +} + +void bt_io_iidx_ep1_top_neons_set(bool top_neons) +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + _bt_io_iidx_api.v1.ep1_top_neons_set(top_neons); +} + +bool bt_io_iidx_ep1_send() +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_iidx_api.v1.ep1_send(); +} + +bool bt_io_iidx_ep2_recv() +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_iidx_api.v1.ep2_recv(); +} + +uint8_t bt_io_iidx_ep2_turntable_get(uint8_t player_no) +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_iidx_api.v1.ep2_turntable_get(player_no); +} + +uint8_t bt_io_iidx_ep2_slider_get(uint8_t slider_no) +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_iidx_api.v1.ep2_slider_get(slider_no); +} + +uint8_t bt_io_iidx_ep2_sys_get() +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_iidx_api.v1.ep2_sys_get(); +} + +uint8_t bt_io_iidx_ep2_panel_get() +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_iidx_api.v1.ep2_panel_get(); +} + +uint16_t bt_io_iidx_ep2_keys_get() +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_iidx_api.v1.ep2_keys_get(); +} + +bool bt_io_iidx_ep3_16seg_send(const char *text) +{ + log_assert(_bt_io_iidx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_iidx_api.v1.ep3_16seg_send(text); +} diff --git a/src/main/iface-io/iidx.h b/src/main/iface-io/iidx.h new file mode 100644 index 0000000..a7ebbc0 --- /dev/null +++ b/src/main/iface-io/iidx.h @@ -0,0 +1,28 @@ +#ifndef API_IO_IIDX_H +#define API_IO_IIDX_H + +#include +#include + +#include "api/io/iidx.h" + +void bt_io_iidx_api_set(const bt_io_iidx_api_t *api); +void bt_io_iidx_api_get(bt_io_iidx_api_t *api); +void bt_io_iidx_api_clear(); + +bool bt_io_iidx_init(); +void bt_io_iidx_fini(); +void bt_io_iidx_ep1_deck_lights_set(uint16_t deck_lights); +void bt_io_iidx_ep1_panel_lights_set(uint8_t panel_lights); +void bt_io_iidx_ep1_top_lamps_set(uint8_t top_lamps); +void bt_io_iidx_ep1_top_neons_set(bool top_neons); +bool bt_io_iidx_ep1_send(); +bool bt_io_iidx_ep2_recv(); +uint8_t bt_io_iidx_ep2_turntable_get(uint8_t player_no); +uint8_t bt_io_iidx_ep2_slider_get(uint8_t slider_no); +uint8_t bt_io_iidx_ep2_sys_get(); +uint8_t bt_io_iidx_ep2_panel_get(); +uint16_t bt_io_iidx_ep2_keys_get(); +bool bt_io_iidx_ep3_16seg_send(const char *text); + +#endif \ No newline at end of file diff --git a/src/main/iface-io/jb.c b/src/main/iface-io/jb.c new file mode 100644 index 0000000..7ae1823 --- /dev/null +++ b/src/main/iface-io/jb.c @@ -0,0 +1,168 @@ +#define LOG_MODULE "bt-io-jb" + +#include + +#include "api/io/jb.h" + +#include "iface-core/log.h" + +#define BT_IO_JB_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_io_jb_api_t _bt_io_jb_api; + +static bool _bt_io_jb_api_is_valid() +{ + return _bt_io_jb_api.version > 0; +} + +void bt_io_jb_api_set(const bt_io_jb_api_t *api) +{ + log_assert(api); + + if (_bt_io_jb_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + BT_IO_JB_ASSERT_IMPLEMENTED(api->v1.init, "bt_io_jb_init"); + BT_IO_JB_ASSERT_IMPLEMENTED(api->v1.fini, "bt_io_jb_fini"); + + BT_IO_JB_ASSERT_IMPLEMENTED( + api->v1.inputs_read, "bt_io_jb_inputs_read"); + BT_IO_JB_ASSERT_IMPLEMENTED( + api->v1.sys_inputs_get, "bt_io_jb_sys_inputs_get"); + BT_IO_JB_ASSERT_IMPLEMENTED( + api->v1.panel_inputs_get, "bt_io_jb_panel_inputs_get"); + BT_IO_JB_ASSERT_IMPLEMENTED( + api->v1.rgb_led_set, "bt_io_jb_rgb_led_set"); + BT_IO_JB_ASSERT_IMPLEMENTED( + api->v1.lights_write, "bt_io_jb_lights_write"); + BT_IO_JB_ASSERT_IMPLEMENTED( + api->v1.panel_mode_set, "bt_io_jb_panel_mode_set"); + BT_IO_JB_ASSERT_IMPLEMENTED( + api->v1.coin_blocker_set, "bt_io_jb_coin_blocker_set"); + + memcpy(&_bt_io_jb_api, api, sizeof(bt_io_jb_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_io_jb_api_get(bt_io_jb_api_t *api) +{ + log_assert(api); + log_assert(_bt_io_jb_api_is_valid()); + + memcpy(api, &_bt_io_jb_api, sizeof(bt_io_jb_api_t)); +} + +void bt_io_jb_api_clear() +{ + log_assert(_bt_io_jb_api_is_valid()); + + memset(&_bt_io_jb_api, 0, sizeof(bt_io_jb_api_t)); + + log_misc("api cleared"); +} + +bool bt_io_jb_init() +{ + bool result; + + log_assert(_bt_io_jb_api_is_valid()); + + log_misc(">>> init"); + + result = _bt_io_jb_api.v1.init(); + + log_misc("<<< init: %d", result); + + return result; +} + +void bt_io_jb_fini() +{ + log_assert(_bt_io_jb_api_is_valid()); + + log_misc(">>> fini"); + + _bt_io_jb_api.v1.fini(); + + log_misc("<<< fini"); +} + +bool bt_io_jb_inputs_read() +{ + log_assert(_bt_io_jb_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_jb_api.v1.inputs_read(); +} + +uint8_t bt_io_jb_sys_inputs_get() +{ + log_assert(_bt_io_jb_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_jb_api.v1.sys_inputs_get(); +} + +uint16_t bt_io_jb_panel_inputs_get() +{ + log_assert(_bt_io_jb_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_jb_api.v1.panel_inputs_get(); +} + +void bt_io_jb_rgb_led_set( + bt_io_jb_rgb_led_t unit, uint8_t r, uint8_t g, uint8_t b) +{ + log_assert(_bt_io_jb_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + _bt_io_jb_api.v1.rgb_led_set(unit, r, g, b); +} + +bool bt_io_jb_lights_write() +{ + log_assert(_bt_io_jb_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_jb_api.v1.lights_write(); +} + +bool bt_io_jb_panel_mode_set(bt_io_jb_panel_mode_t mode) +{ + log_assert(_bt_io_jb_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_jb_api.v1.panel_mode_set(mode); +} + +bool bt_io_jb_coin_blocker_set(bool blocked) +{ + log_assert(_bt_io_jb_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_jb_api.v1.coin_blocker_set(blocked); +} diff --git a/src/main/iface-io/jb.h b/src/main/iface-io/jb.h new file mode 100644 index 0000000..a698353 --- /dev/null +++ b/src/main/iface-io/jb.h @@ -0,0 +1,24 @@ +#ifndef API_IO_JB_H +#define API_IO_JB_H + +#include +#include + +#include "api/io/jb.h" + +void bt_io_jb_api_set(const bt_io_jb_api_t *api); +void bt_io_jb_api_get(bt_io_jb_api_t *api); +void bt_io_jb_api_clear(); + +bool bt_io_jb_init(); +void bt_io_jb_fini(); +bool bt_io_jb_inputs_read(); +uint8_t bt_io_jb_sys_inputs_get(); +uint16_t bt_io_jb_panel_inputs_get(); +void bt_io_jb_rgb_led_set( + bt_io_jb_rgb_led_t unit, uint8_t r, uint8_t g, uint8_t b); +bool bt_io_jb_lights_write(); +bool bt_io_jb_panel_mode_set(bt_io_jb_panel_mode_t mode); +bool bt_io_jb_coin_blocker_set(bool blocked); + +#endif \ No newline at end of file diff --git a/src/main/iface-io/popn.c b/src/main/iface-io/popn.c new file mode 100644 index 0000000..9be62fd --- /dev/null +++ b/src/main/iface-io/popn.c @@ -0,0 +1,157 @@ +#define LOG_MODULE "bt-io-popn" + +#include + +#include "api/io/popn.h" + +#include "iface-core/log.h" + +#define BT_IO_POPN_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_io_popn_api_t _bt_io_popn_api; + +static bool _bt_io_popn_api_is_valid() +{ + return _bt_io_popn_api.version > 0; +} + +void bt_io_popn_api_set(const bt_io_popn_api_t *api) +{ + log_assert(api); + + if (_bt_io_popn_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + BT_IO_POPN_ASSERT_IMPLEMENTED(api->v1.init, "bt_io_popn_init"); + BT_IO_POPN_ASSERT_IMPLEMENTED(api->v1.fini, "bt_io_popn_fini"); + + BT_IO_POPN_ASSERT_IMPLEMENTED( + api->v1.buttons_get, "bt_io_popn_buttons_get"); + BT_IO_POPN_ASSERT_IMPLEMENTED( + api->v1.top_lights_set, "bt_io_popn_top_lights_set"); + BT_IO_POPN_ASSERT_IMPLEMENTED( + api->v1.side_lights_set, "bt_io_popn_side_lights_set"); + BT_IO_POPN_ASSERT_IMPLEMENTED( + api->v1.button_lights_set, "bt_io_popn_button_lights_set"); + BT_IO_POPN_ASSERT_IMPLEMENTED( + api->v1.coin_blocker_light_set, + "bt_io_popn_coin_blocker_light_set"); + BT_IO_POPN_ASSERT_IMPLEMENTED( + api->v1.coin_counter_light_set, + "bt_io_popn_coin_counter_light_set"); + + memcpy(&_bt_io_popn_api, api, sizeof(bt_io_popn_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_io_popn_api_get(bt_io_popn_api_t *api) +{ + log_assert(api); + log_assert(_bt_io_popn_api_is_valid()); + + memcpy(api, &_bt_io_popn_api, sizeof(bt_io_popn_api_t)); +} + +void bt_io_popn_api_clear() +{ + log_assert(_bt_io_popn_api_is_valid()); + + memset(&_bt_io_popn_api, 0, sizeof(bt_io_popn_api_t)); + + log_misc("api cleared"); +} + +bool bt_io_popn_init() +{ + bool result; + + log_assert(_bt_io_popn_api_is_valid()); + + log_misc(">>> init"); + + result = _bt_io_popn_api.v1.init(); + + log_misc("<<< init: %d", result); + + return result; +} + +void bt_io_popn_fini() +{ + log_assert(_bt_io_popn_api_is_valid()); + + log_misc(">>> fini"); + + _bt_io_popn_api.v1.fini(); + + log_misc("<<< fini"); +} + +uint32_t bt_io_popn_buttons_get() +{ + log_assert(_bt_io_popn_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_popn_api.v1.buttons_get(); +} + +void bt_io_popn_top_lights_set(uint32_t lights) +{ + log_assert(_bt_io_popn_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_popn_api.v1.top_lights_set(lights); +} + +void bt_io_popn_side_lights_set(uint32_t lights) +{ + log_assert(_bt_io_popn_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_popn_api.v1.side_lights_set(lights); +} + +void bt_io_popn_button_lights_set(uint32_t lights) +{ + log_assert(_bt_io_popn_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_popn_api.v1.button_lights_set(lights); +} + +void bt_io_popn_coin_blocker_light_set(bool enabled) +{ + log_assert(_bt_io_popn_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_popn_api.v1.coin_blocker_light_set(enabled); +} + +void bt_io_popn_coin_counter_light_set(bool enabled) +{ + log_assert(_bt_io_popn_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_popn_api.v1.coin_counter_light_set(enabled); +} diff --git a/src/main/iface-io/popn.h b/src/main/iface-io/popn.h new file mode 100644 index 0000000..6256ec7 --- /dev/null +++ b/src/main/iface-io/popn.h @@ -0,0 +1,23 @@ +#ifndef API_IO_POPN_H +#define API_IO_POPN_H + +#include +#include + +#include "api/io/popn.h" + +void bt_io_popn_api_set(const bt_io_popn_api_t *api); +void bt_io_popn_api_get(bt_io_popn_api_t *api); +void bt_io_popn_api_clear(); + +bool bt_io_popn_init(); +void bt_io_popn_fini(); + +uint32_t bt_io_popn_buttons_get(); +void bt_io_popn_top_lights_set(uint32_t lights); +void bt_io_popn_side_lights_set(uint32_t lights); +void bt_io_popn_button_lights_set(uint32_t lights); +void bt_io_popn_coin_blocker_light_set(bool enabled); +void bt_io_popn_coin_counter_light_set(bool enabled); + +#endif \ No newline at end of file diff --git a/src/main/iface-io/sdvx.c b/src/main/iface-io/sdvx.c new file mode 100644 index 0000000..9d133e7 --- /dev/null +++ b/src/main/iface-io/sdvx.c @@ -0,0 +1,180 @@ +#define LOG_MODULE "bt-io-sdvx" + +#include + +#include "api/io/sdvx.h" + +#include "iface-core/log.h" + +#define BT_IO_SDVX_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_io_sdvx_api_t _bt_io_sdvx_api; + +static bool _bt_io_sdvx_api_is_valid() +{ + return _bt_io_sdvx_api.version > 0; +} + +void bt_io_sdvx_api_set(const bt_io_sdvx_api_t *api) +{ + log_assert(api); + + if (_bt_io_sdvx_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + BT_IO_SDVX_ASSERT_IMPLEMENTED(api->v1.init, "bt_io_sdvx_init"); + BT_IO_SDVX_ASSERT_IMPLEMENTED(api->v1.fini, "bt_io_sdvx_fini"); + + BT_IO_SDVX_ASSERT_IMPLEMENTED( + api->v1.gpio_lights_set, "bt_io_sdvx_gpio_lights_set"); + BT_IO_SDVX_ASSERT_IMPLEMENTED( + api->v1.pwm_light_set, "bt_io_sdvx_pwm_light_set"); + BT_IO_SDVX_ASSERT_IMPLEMENTED( + api->v1.output_write, "bt_io_sdvx_output_write"); + BT_IO_SDVX_ASSERT_IMPLEMENTED( + api->v1.input_read, "bt_io_sdvx_input_read"); + BT_IO_SDVX_ASSERT_IMPLEMENTED( + api->v1.input_gpio_sys_get, "bt_io_sdvx_input_gpio_sys_get"); + BT_IO_SDVX_ASSERT_IMPLEMENTED( + api->v1.input_gpio_get, "bt_io_sdvx_input_gpio_get"); + BT_IO_SDVX_ASSERT_IMPLEMENTED( + api->v1.spinner_pos_get, "bt_io_sdvx_spinner_pos_get"); + BT_IO_SDVX_ASSERT_IMPLEMENTED( + api->v1.amp_volume_set, "bt_io_sdvx_amp_volume_set"); + + memcpy(&_bt_io_sdvx_api, api, sizeof(bt_io_sdvx_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_io_sdvx_api_get(bt_io_sdvx_api_t *api) +{ + log_assert(api); + log_assert(_bt_io_sdvx_api_is_valid()); + + memcpy(api, &_bt_io_sdvx_api, sizeof(bt_io_sdvx_api_t)); +} + +void bt_io_sdvx_api_clear() +{ + log_assert(_bt_io_sdvx_api_is_valid()); + + memset(&_bt_io_sdvx_api, 0, sizeof(bt_io_sdvx_api_t)); + + log_misc("api cleared"); +} + +bool bt_io_sdvx_init() +{ + bool result; + + log_assert(_bt_io_sdvx_api_is_valid()); + + log_misc(">>> init"); + + result = _bt_io_sdvx_api.v1.init(); + + log_misc("<<< init: %d", result); + + return result; +} + +void bt_io_sdvx_fini() +{ + log_assert(_bt_io_sdvx_api_is_valid()); + + log_misc(">>> fini"); + + _bt_io_sdvx_api.v1.fini(); + + log_misc("<<< fini"); +} + +void bt_io_sdvx_gpio_lights_set(uint32_t gpio_lights) +{ + log_assert(_bt_io_sdvx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + _bt_io_sdvx_api.v1.gpio_lights_set(gpio_lights); +} + +void bt_io_sdvx_pwm_light_set(uint8_t light_no, uint8_t intensity) +{ + log_assert(_bt_io_sdvx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + _bt_io_sdvx_api.v1.pwm_light_set(light_no, intensity); +} + +bool bt_io_sdvx_output_write() +{ + log_assert(_bt_io_sdvx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_sdvx_api.v1.output_write(); +} + +bool bt_io_sdvx_input_read() +{ + log_assert(_bt_io_sdvx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_sdvx_api.v1.input_read(); +} + +uint8_t bt_io_sdvx_input_gpio_sys_get() +{ + log_assert(_bt_io_sdvx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_sdvx_api.v1.input_gpio_sys_get(); +} + +uint16_t bt_io_sdvx_input_gpio_get(uint8_t gpio_bank) +{ + log_assert(_bt_io_sdvx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_sdvx_api.v1.input_gpio_get(gpio_bank); +} + +uint16_t bt_io_sdvx_spinner_pos_get(uint8_t spinner_no) +{ + log_assert(_bt_io_sdvx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_sdvx_api.v1.spinner_pos_get(spinner_no); +} + +bool bt_io_sdvx_amp_volume_set( + uint8_t primary, uint8_t headphone, uint8_t subwoofer) +{ + log_assert(_bt_io_sdvx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_sdvx_api.v1.amp_volume_set(primary, headphone, subwoofer); +} diff --git a/src/main/iface-io/sdvx.h b/src/main/iface-io/sdvx.h new file mode 100644 index 0000000..a803313 --- /dev/null +++ b/src/main/iface-io/sdvx.h @@ -0,0 +1,26 @@ +#ifndef API_IO_SDVX_H +#define API_IO_SDVX_H + +#include +#include + +#include "api/io/sdvx.h" + +void bt_io_sdvx_api_set(const bt_io_sdvx_api_t *api); +void bt_io_sdvx_api_get(bt_io_sdvx_api_t *api); +void bt_io_sdvx_api_clear(); + +bool bt_io_sdvx_init(); +void bt_io_sdvx_fini(); + +void bt_io_sdvx_gpio_lights_set(uint32_t gpio_lights); +void bt_io_sdvx_pwm_light_set(uint8_t light_no, uint8_t intensity); +bool bt_io_sdvx_output_write(); +bool bt_io_sdvx_input_read(); +uint8_t bt_io_sdvx_input_gpio_sys_get(); +uint16_t bt_io_sdvx_input_gpio_get(uint8_t gpio_bank); +uint16_t bt_io_sdvx_spinner_pos_get(uint8_t spinner_no); +bool bt_io_sdvx_amp_volume_set( + uint8_t primary, uint8_t headphone, uint8_t subwoofer); + +#endif \ No newline at end of file diff --git a/src/main/iface-io/vefx.c b/src/main/iface-io/vefx.c new file mode 100644 index 0000000..07834ef --- /dev/null +++ b/src/main/iface-io/vefx.c @@ -0,0 +1,118 @@ +#define LOG_MODULE "bt-io-vefx" + +#include + +#include "api/io/vefx.h" + +#include "iface-core/log.h" + +#define BT_IO_VEFX_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_io_vefx_api_t _bt_io_vefx_api; + +static bool _bt_io_vefx_api_is_valid() +{ + return _bt_io_vefx_api.version > 0; +} + +void bt_io_vefx_api_set(const bt_io_vefx_api_t *api) +{ + log_assert(api); + + if (_bt_io_vefx_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + BT_IO_VEFX_ASSERT_IMPLEMENTED(api->v1.init, "bt_io_vefx_init"); + BT_IO_VEFX_ASSERT_IMPLEMENTED(api->v1.fini, "bt_io_vefx_fini"); + + BT_IO_VEFX_ASSERT_IMPLEMENTED(api->v1.recv, "bt_io_vefx_recv"); + BT_IO_VEFX_ASSERT_IMPLEMENTED( + api->v1.slider_get, "bt_io_vefx_slider_get"); + BT_IO_VEFX_ASSERT_IMPLEMENTED( + api->v1._16seg_send, "bt_io_vefx_16seg_send"); + + memcpy(&_bt_io_vefx_api, api, sizeof(bt_io_vefx_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_io_vefx_api_get(bt_io_vefx_api_t *api) +{ + log_assert(api); + log_assert(_bt_io_vefx_api_is_valid()); + + memcpy(api, &_bt_io_vefx_api, sizeof(bt_io_vefx_api_t)); +} + +void bt_io_vefx_api_clear() +{ + log_assert(_bt_io_vefx_api_is_valid()); + + memset(&_bt_io_vefx_api, 0, sizeof(bt_io_vefx_api_t)); + + log_misc("api cleared"); +} + +bool bt_io_vefx_init() +{ + bool result; + + log_assert(_bt_io_vefx_api_is_valid()); + + log_misc(">>> init"); + + result = _bt_io_vefx_api.v1.init(); + + log_misc("<<< init: %d", result); + + return result; +} + +void bt_io_vefx_fini() +{ + log_assert(_bt_io_vefx_api_is_valid()); + + log_misc(">>> fini"); + + _bt_io_vefx_api.v1.fini(); + + log_misc("<<< fini"); +} + +bool bt_io_vefx_recv(uint64_t *ppad) +{ + log_assert(_bt_io_vefx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_vefx_api.v1.recv(ppad); +} + +uint8_t bt_io_vefx_slider_get(uint8_t slider_no) +{ + log_assert(_bt_io_vefx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_vefx_api.v1.slider_get(slider_no); +} + +bool bt_io_vefx_16seg_send(const char *text) +{ + log_assert(_bt_io_vefx_api_is_valid()); + + // Do not log on frequently invoked calls to avoid negative performance + // impact and log spam + + return _bt_io_vefx_api.v1._16seg_send(text); +} diff --git a/src/main/iface-io/vefx.h b/src/main/iface-io/vefx.h new file mode 100644 index 0000000..0444de4 --- /dev/null +++ b/src/main/iface-io/vefx.h @@ -0,0 +1,20 @@ +#ifndef API_IO_VEFX_H +#define API_IO_VEFX_H + +#include +#include + +#include "api/io/vefx.h" + +void bt_io_vefx_api_set(const bt_io_vefx_api_t *api); +void bt_io_vefx_api_get(bt_io_vefx_api_t *api); +void bt_io_vefx_api_clear(); + +bool bt_io_vefx_init(); +void bt_io_vefx_fini(); + +bool bt_io_vefx_recv(uint64_t *ppad); +uint8_t bt_io_vefx_slider_get(uint8_t slider_no); +bool bt_io_vefx_16seg_send(const char *text); + +#endif \ No newline at end of file diff --git a/src/main/iface/Module.mk b/src/main/iface/Module.mk new file mode 100644 index 0000000..4c64b3d --- /dev/null +++ b/src/main/iface/Module.mk @@ -0,0 +1,10 @@ +libs += iface + +libs_iface := \ + iface-core \ + iface-io \ + util \ + +src_iface := \ + hook.c \ + input.c \ diff --git a/src/main/iface/hook.c b/src/main/iface/hook.c new file mode 100644 index 0000000..51ae565 --- /dev/null +++ b/src/main/iface/hook.c @@ -0,0 +1,118 @@ +#define LOG_MODULE "bt-hook" + +#include + +#include "api/hook.h" + +#include "iface-core/log.h" +#include "iface/hook.h" + +#include "util/mem.h" +#include "util/str.h" + +struct bt_hook { + bt_hook_api_t api; + char name[512]; +}; + +void bt_hook_init(const bt_hook_api_t *api, const char *name, bt_hook_t **hook) +{ + log_assert(api); + log_assert(name); + log_assert(hook); + + if (api->version == 1) { + // all functions optional, no need for asserting them + + *hook = xmalloc(sizeof(bt_hook_t)); + + memcpy(&(*hook)->api, api, sizeof(bt_hook_api_t)); + str_cpy((*hook)->name, sizeof((*hook)->name), name); + + log_misc("[%s] api v1 detected", (*hook)->name); + } else { + log_fatal("[%s] Unsupported API version: %d", name, api->version); + } +} + +void bt_hook_fini(bt_hook_t **hook) +{ + log_assert(hook); + + free(*hook); + memset(*hook, 0, sizeof(bt_hook_t)); +} + +bool bt_hook_pre_avs_init(const bt_hook_t *hook, const bt_core_config_t *config) +{ + bool result; + + log_assert(hook); + log_assert(config); + log_assert(hook->api.version > 0); + + if (hook->api.v1.pre_avs_init) { + log_misc("[%s] >>> pre_avs_init", hook->name); + + result = hook->api.v1.pre_avs_init(config); + + log_misc("[%s] <<< pre_avs_init: %d", hook->name, result); + } else { + result = true; + } + + return result; +} + +void bt_hook_iat_dll_name_get(const bt_hook_t *hook, char *buffer, size_t size) +{ + log_assert(hook); + log_assert(hook->api.version > 0); + log_assert(buffer); + log_assert(size > 0); + + if (hook->api.v1.iat_dll_name_get) { + log_misc("[%s] >>> iat_dll_name_get", hook->name); + + hook->api.v1.iat_dll_name_get(buffer, size); + + log_misc("[%s] <<< iat_dll_name_get: %s", hook->name, buffer); + } +} + +bool bt_hook_main_init( + const bt_hook_t *hook, HMODULE game_module, const bt_core_config_t *config) +{ + bool result; + + log_assert(hook); + log_assert(game_module); + log_assert(hook->api.version > 0); + log_assert(config); + + if (hook->api.v1.main_init) { + log_misc("[%s] >>> main_init", hook->name); + + result = hook->api.v1.main_init(game_module, config); + + log_misc("[%s] <<< main_init: %d", hook->name, result); + } else { + result = true; + } + + return result; +} + +void bt_hook_main_fini(const bt_hook_t *hook) +{ + log_assert(hook); + log_assert(hook->api.version > 0); + + if (hook->api.v1.main_fini) { + log_misc("[%s] >>> main_fini", hook->name); + + hook->api.v1.main_fini(); + + log_misc("[%s] <<< main_fini", hook->name); + } +} diff --git a/src/main/iface/hook.h b/src/main/iface/hook.h new file mode 100644 index 0000000..30d13ed --- /dev/null +++ b/src/main/iface/hook.h @@ -0,0 +1,21 @@ +#ifndef BT_HOOK_H +#define BT_HOOK_H + +#include +#include + +#include "api/hook.h" + +typedef struct bt_hook bt_hook_t; + +void bt_hook_init(const bt_hook_api_t *api, const char *name, bt_hook_t **hook); +void bt_hook_fini(bt_hook_t **hook); + +bool bt_hook_pre_avs_init( + const bt_hook_t *hook, const bt_core_config_t *config); +void bt_hook_iat_dll_name_get(const bt_hook_t *hook, char *buffer, size_t size); +bool bt_hook_main_init( + const bt_hook_t *hook, HMODULE game_module, const bt_core_config_t *config); +void bt_hook_main_fini(const bt_hook_t *hook); + +#endif \ No newline at end of file diff --git a/src/main/iface/input.c b/src/main/iface/input.c new file mode 100644 index 0000000..61efeca --- /dev/null +++ b/src/main/iface/input.c @@ -0,0 +1,127 @@ +#define LOG_MODULE "bt-input" + +#include + +#include "api/input.h" + +#include "iface-core/log.h" + +#define BT_INPUT_ASSERT_IMPLEMENTED(func, name) \ + if (!func) { \ + log_fatal("Function %s not implemented", STRINGIFY(name)); \ + } + +static bt_input_api_t _bt_input_api; + +static bool _bt_input_api_is_valid() +{ + return _bt_input_api.version > 0; +} + +void bt_input_api_set(const bt_input_api_t *api) +{ + log_assert(api); + + if (_bt_input_api_is_valid()) { + log_warning("Re-initialize"); + } + + if (api->version == 1) { + BT_INPUT_ASSERT_IMPLEMENTED(api->v1.init, "bt_input_init"); + BT_INPUT_ASSERT_IMPLEMENTED(api->v1.fini, "bt_input_fini"); + + BT_INPUT_ASSERT_IMPLEMENTED( + api->v1.mapper_config_load, "bt_input_mapper_config_load"); + BT_INPUT_ASSERT_IMPLEMENTED( + api->v1.mapper_analog_read, "bt_input_mapper_analog_read"); + BT_INPUT_ASSERT_IMPLEMENTED( + api->v1.mapper_update, "bt_input_mapper_update"); + BT_INPUT_ASSERT_IMPLEMENTED( + api->v1.mapper_light_write, "bt_input_mapper_light_write"); + + memcpy(&_bt_input_api, api, sizeof(bt_input_api_t)); + + log_misc("api v1 set"); + } else { + log_fatal("Unsupported API version: %d", api->version); + } +} + +void bt_input_api_get(bt_input_api_t *api) +{ + log_assert(api); + log_assert(_bt_input_api_is_valid()); + + memcpy(api, &_bt_input_api, sizeof(bt_input_api_t)); +} + +void bt_input_api_clear() +{ + log_assert(_bt_input_api_is_valid()); + + memset(&_bt_input_api, 0, sizeof(bt_input_api_t)); + + log_misc("api cleared"); +} + +bool bt_input_init() +{ + bool result; + + log_assert(_bt_input_api_is_valid()); + + log_misc(">>> init"); + + result = _bt_input_api.v1.init(); + + log_misc("<<< init: %d", result); + + return result; +} + +void bt_input_fini() +{ + log_assert(_bt_input_api_is_valid()); + + log_misc(">>> fini"); + + _bt_input_api.v1.fini(); + + log_misc("<<< fini"); +} + +bool bt_input_mapper_config_load(const char *game_type) +{ + bool result; + + log_assert(_bt_input_api_is_valid()); + + log_misc(">>> mapper_config_load: %s", game_type); + + result = _bt_input_api.v1.mapper_config_load(game_type); + + log_misc("<<< mapper_config_load: %d", result); + + return result; +} + +uint8_t bt_input_mapper_analog_read(uint8_t analog) +{ + log_assert(_bt_input_api_is_valid()); + + return _bt_input_api.v1.mapper_analog_read(analog); +} + +uint64_t bt_input_mapper_update() +{ + log_assert(_bt_input_api_is_valid()); + + return _bt_input_api.v1.mapper_update(); +} + +void bt_input_mapper_light_write(uint8_t light, uint8_t intensity) +{ + log_assert(_bt_input_api_is_valid()); + + return _bt_input_api.v1.mapper_light_write(light, intensity); +} diff --git a/src/main/iface/input.h b/src/main/iface/input.h new file mode 100644 index 0000000..d6d5b45 --- /dev/null +++ b/src/main/iface/input.h @@ -0,0 +1,21 @@ +#ifndef BT_INPUT_H +#define BT_INPUT_H + +#include +#include + +#include "api/input.h" + +void bt_input_api_set(const bt_input_api_t *api); +void bt_input_api_get(bt_input_api_t *api); +void bt_input_api_clear(); + +bool bt_input_init(); +void bt_input_fini(); + +bool bt_input_mapper_config_load(const char *game_type); +uint8_t bt_input_mapper_analog_read(uint8_t analog); +uint64_t bt_input_mapper_update(); +void bt_input_mapper_light_write(uint8_t light, uint8_t intensity); + +#endif \ No newline at end of file diff --git a/src/main/iidx-bio2-exit-hook/Module.mk b/src/main/iidx-bio2-exit-hook/Module.mk index 085af3a..701fa06 100644 --- a/src/main/iidx-bio2-exit-hook/Module.mk +++ b/src/main/iidx-bio2-exit-hook/Module.mk @@ -2,12 +2,14 @@ dlls += iidx-bio2-exit-hook ldflags_iidx-bio2-exit-hook := \ -lsetupapi \ + -lpsapi \ libs_iidx-bio2-exit-hook := \ core \ bio2drv \ hook \ util \ + iface-core \ src_iidx-bio2-exit-hook := \ main.c \ diff --git a/src/main/iidx-bio2-exit-hook/main.c b/src/main/iidx-bio2-exit-hook/main.c index 2718717..4faf4ba 100644 --- a/src/main/iidx-bio2-exit-hook/main.c +++ b/src/main/iidx-bio2-exit-hook/main.c @@ -13,11 +13,13 @@ #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" +#include "core/log-sink-std.h" #include "hook/iobuf.h" #include "hook/iohook.h" +#include "iface-core/log.h" + #include "util/mem.h" #include "util/proc.h" #include "util/str.h" @@ -227,8 +229,10 @@ static HRESULT _iohook_handler(struct irp *irp) BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { - core_log_bt_ext_impl_set(); - core_log_bt_ext_init_with_stdout(); + core_log_bt_core_api_set(); + + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); if (reason != DLL_PROCESS_ATTACH) { return TRUE; diff --git a/src/main/iidx-ezusb-exit-hook/Module.mk b/src/main/iidx-ezusb-exit-hook/Module.mk index 500bd15..084841c 100644 --- a/src/main/iidx-ezusb-exit-hook/Module.mk +++ b/src/main/iidx-ezusb-exit-hook/Module.mk @@ -1,10 +1,14 @@ dlls += iidx-ezusb-exit-hook +ldflags_iidx-ezusb-exit-hook := \ + -lpsapi \ + libs_iidx-ezusb-exit-hook := \ core \ ezusb-iidx \ hook \ util \ + iface-core \ src_iidx-ezusb-exit-hook := \ main.c \ diff --git a/src/main/iidx-ezusb-exit-hook/main.c b/src/main/iidx-ezusb-exit-hook/main.c index 1c34d66..162664a 100644 --- a/src/main/iidx-ezusb-exit-hook/main.c +++ b/src/main/iidx-ezusb-exit-hook/main.c @@ -7,6 +7,10 @@ #include #include +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log-sink-std.h" + #include "ezusb/ezusbsys2.h" #include "ezusb-iidx/msg.h" @@ -176,6 +180,11 @@ static BOOL STDCALL my_DeviceIoControl( BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { + core_log_bt_core_api_set(); + + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); + hook_table_apply( NULL, "kernel32.dll", iidxfx_hook_syms, lengthof(iidxfx_hook_syms)); } diff --git a/src/main/iidx-ezusb2-exit-hook/Module.mk b/src/main/iidx-ezusb2-exit-hook/Module.mk index f449f38..091939c 100644 --- a/src/main/iidx-ezusb2-exit-hook/Module.mk +++ b/src/main/iidx-ezusb2-exit-hook/Module.mk @@ -1,9 +1,13 @@ dlls += iidx-ezusb2-exit-hook +ldflags_iidx-ezusb2-exit-hook := \ + -lpsapi \ + libs_iidx-ezusb2-exit-hook := \ core \ hook \ util \ + iface-core \ src_iidx-ezusb2-exit-hook := \ main.c \ diff --git a/src/main/iidx-ezusb2-exit-hook/main.c b/src/main/iidx-ezusb2-exit-hook/main.c index 85b61bd..4346c9a 100644 --- a/src/main/iidx-ezusb2-exit-hook/main.c +++ b/src/main/iidx-ezusb2-exit-hook/main.c @@ -7,6 +7,10 @@ #include #include +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log-sink-std.h" + #include "ezusb2/cyioctl.h" #include "ezusb2-iidx/msg.h" @@ -136,6 +140,11 @@ static BOOL STDCALL my_DeviceIoControl( BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { + core_log_bt_core_api_set(); + + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); + hook_table_apply( NULL, "kernel32.dll", exit_hook_syms, lengthof(exit_hook_syms)); } diff --git a/src/main/iidx-irbeat-patch/Module.mk b/src/main/iidx-irbeat-patch/Module.mk index d01645f..62f9bb6 100644 --- a/src/main/iidx-irbeat-patch/Module.mk +++ b/src/main/iidx-irbeat-patch/Module.mk @@ -3,6 +3,7 @@ exes += iidx-irbeat-patch libs_iidx-irbeat-patch := \ util \ core \ + iface-core \ src_iidx-irbeat-patch := \ main.c \ diff --git a/src/main/iidx-irbeat-patch/main.c b/src/main/iidx-irbeat-patch/main.c index 9c2f58a..da07956 100644 --- a/src/main/iidx-irbeat-patch/main.c +++ b/src/main/iidx-irbeat-patch/main.c @@ -3,6 +3,11 @@ #include #include +#include "core/log-bt-ext.h" +#include "core/log-bt.h" + +#include "iface-core/log.h" + #include "util/fs.h" static const uint32_t offset_size_data_area = 4; @@ -170,6 +175,11 @@ int main(int argc, char **argv) return -1; } + core_log_bt_core_api_set(); + + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); + version = atoi(argv[1]); irbeat = atoi(argv[2]); settings = argv[3]; diff --git a/src/main/iidxhook-d3d9/bb-scale-hd.c b/src/main/iidxhook-d3d9/bb-scale-hd.c index 84afe7c..d41242a 100644 --- a/src/main/iidxhook-d3d9/bb-scale-hd.c +++ b/src/main/iidxhook-d3d9/bb-scale-hd.c @@ -2,10 +2,10 @@ #include -#include "core/log.h" - #include "d3d9-util/vertex.h" +#include "iface-core/log.h" + #include "bb-scale-hd.h" #include "util.h" diff --git a/src/main/iidxhook-d3d9/util.h b/src/main/iidxhook-d3d9/util.h index 96b489e..f315e4b 100644 --- a/src/main/iidxhook-d3d9/util.h +++ b/src/main/iidxhook-d3d9/util.h @@ -3,10 +3,10 @@ #include -#include "core/log.h" - #include "d3d9-util/dxerr9.h" +#include "iface-core/log.h" + inline void iidxhook_d3d9_util_check_and_handle_failure(HRESULT hr, const char *msg) { diff --git a/src/main/iidxhook-util/acio.c b/src/main/iidxhook-util/acio.c index a52fa76..fa26e0c 100644 --- a/src/main/iidxhook-util/acio.c +++ b/src/main/iidxhook-util/acio.c @@ -15,11 +15,11 @@ #include "acioemu/emu.h" #include "acioemu/icca.h" -#include "core/log.h" - #include "hook/iohook.h" #include "hooklib/rs232.h" +#include "iface-core/log.h" + #include "iidxhook-util/acio.h" #include "imports/avs.h" diff --git a/src/main/iidxhook-util/chart-patch.c b/src/main/iidxhook-util/chart-patch.c index b6cc290..9b14dd0 100644 --- a/src/main/iidxhook-util/chart-patch.c +++ b/src/main/iidxhook-util/chart-patch.c @@ -4,10 +4,10 @@ #include #include -#include "core/log.h" - #include "hook/iohook.h" +#include "iface-core/log.h" + #include "util/crc.h" #include "util/defs.h" #include "util/fs.h" diff --git a/src/main/iidxhook-util/clock.c b/src/main/iidxhook-util/clock.c index dc0e2f2..3a9399b 100644 --- a/src/main/iidxhook-util/clock.c +++ b/src/main/iidxhook-util/clock.c @@ -2,10 +2,10 @@ #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" static BOOL STDCALL my_SetLocalTime(const SYSTEMTIME *lpSystemTime); diff --git a/src/main/iidxhook-util/config-eamuse.c b/src/main/iidxhook-util/config-eamuse.c index c75bd1a..239d875 100644 --- a/src/main/iidxhook-util/config-eamuse.c +++ b/src/main/iidxhook-util/config-eamuse.c @@ -2,10 +2,10 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" - #include "iidxhook-util/config-eamuse.h" +#include "iface-core/log.h" + #include "security/mcode.h" #define IIDXHOOK_CONFIG_EAMUSE_CARD_TYPE_KEY "eamuse.card_type" diff --git a/src/main/iidxhook-util/config-ezusb.c b/src/main/iidxhook-util/config-ezusb.c index 14d953d..e4568e4 100644 --- a/src/main/iidxhook-util/config-ezusb.c +++ b/src/main/iidxhook-util/config-ezusb.c @@ -3,10 +3,10 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" - #include "iidxhook-util/config-ezusb.h" +#include "iface-core/log.h" + #include "util/mem.h" #define IIDXHOOK_UTIL_CONFIG_EZUSB_API_CALL_MONITORING_KEY \ diff --git a/src/main/iidxhook-util/config-gfx.c b/src/main/iidxhook-util/config-gfx.c index 1be281f..039778c 100644 --- a/src/main/iidxhook-util/config-gfx.c +++ b/src/main/iidxhook-util/config-gfx.c @@ -2,7 +2,7 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "iidxhook-util/config-gfx.h" diff --git a/src/main/iidxhook-util/config-io.c b/src/main/iidxhook-util/config-io.c index 13c59f3..d8f8543 100644 --- a/src/main/iidxhook-util/config-io.c +++ b/src/main/iidxhook-util/config-io.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "iidxhook-util/config-io.h" diff --git a/src/main/iidxhook-util/config-misc.c b/src/main/iidxhook-util/config-misc.c index fca5ea5..308912a 100644 --- a/src/main/iidxhook-util/config-misc.c +++ b/src/main/iidxhook-util/config-misc.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "iidxhook-util/config-misc.h" diff --git a/src/main/iidxhook-util/config-sec.c b/src/main/iidxhook-util/config-sec.c index a2e9a57..80aa27a 100644 --- a/src/main/iidxhook-util/config-sec.c +++ b/src/main/iidxhook-util/config-sec.c @@ -3,7 +3,7 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "iidxhook-util/config-sec.h" diff --git a/src/main/iidxhook-util/d3d9.c b/src/main/iidxhook-util/d3d9.c index eeb5081..77a24b4 100644 --- a/src/main/iidxhook-util/d3d9.c +++ b/src/main/iidxhook-util/d3d9.c @@ -9,11 +9,11 @@ #include #include -#include "core/log.h" - #include "hook/com-proxy.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "iidxhook-util/d3d9.h" #include "iidxhook-util/vertex-shader.h" diff --git a/src/main/iidxhook-util/eamuse.c b/src/main/iidxhook-util/eamuse.c index bbdcbe1..3105a18 100644 --- a/src/main/iidxhook-util/eamuse.c +++ b/src/main/iidxhook-util/eamuse.c @@ -8,10 +8,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "iidxhook-util/eamuse.h" #include "util/defs.h" diff --git a/src/main/iidxhook-util/effector.c b/src/main/iidxhook-util/effector.c index f313c60..442e582 100644 --- a/src/main/iidxhook-util/effector.c +++ b/src/main/iidxhook-util/effector.c @@ -2,10 +2,10 @@ #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "iidxhook-util/effector.h" #include "util/defs.h" diff --git a/src/main/iidxhook-util/log-server.c b/src/main/iidxhook-util/log-server.c index 5a2fe3d..c55d95f 100644 --- a/src/main/iidxhook-util/log-server.c +++ b/src/main/iidxhook-util/log-server.c @@ -5,11 +5,11 @@ #include #include -#include "core/log.h" -#include "core/thread.h" - #include "hook/table.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + #include "iidxhook-util/log-server.h" #include "imports/avs.h" @@ -35,13 +35,19 @@ static char log_rv_buffer[8192]; void log_server_init(void) { HANDLE ready; + bt_core_log_api_t api; log_rv_producer = CreateSemaphore(NULL, 1, 1, NULL); log_rv_consumer = CreateSemaphore(NULL, 0, 1, NULL); ready = CreateEvent(NULL, TRUE, FALSE, NULL); - core_log_impl_set( - log_post_misc, log_post_info, log_post_warning, log_post_fatal); + api.version = 1; + api.v1.fatal = log_post_fatal; + api.v1.warning = log_post_warning; + api.v1.info = log_post_info; + api.v1.misc = log_post_misc; + + bt_core_log_api_set(&api); log_thread_id = avs_thread_create(log_thread_proc, ready, 16384, 0); diff --git a/src/main/iidxhook-util/settings.c b/src/main/iidxhook-util/settings.c index 5402f69..dce5013 100644 --- a/src/main/iidxhook-util/settings.c +++ b/src/main/iidxhook-util/settings.c @@ -7,11 +7,11 @@ #include #include -#include "core/log.h" - #include "hook/iohook.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/fs.h" #include "util/mem.h" diff --git a/src/main/iidxhook1/Module.mk b/src/main/iidxhook1/Module.mk index 61bb5ff..e6e813e 100644 --- a/src/main/iidxhook1/Module.mk +++ b/src/main/iidxhook1/Module.mk @@ -3,6 +3,7 @@ dlls += iidxhook1 ldflags_iidxhook1 := \ -lws2_32 \ -liphlpapi \ + -lpsapi \ libs_iidxhook1 := \ core \ @@ -11,14 +12,16 @@ libs_iidxhook1 := \ ezusb-iidx-16seg-emu \ ezusb-iidx-emu \ security \ - eamio \ acioemu \ hook \ hooklib \ - iidxio \ cconfig \ - util \ + module \ ezusb \ + iface \ + iface-io \ + iface-core \ + util \ src_iidxhook1 := \ config-iidxhook1.c \ diff --git a/src/main/iidxhook1/config-iidxhook1.c b/src/main/iidxhook1/config-iidxhook1.c index b88d471..6df2f42 100644 --- a/src/main/iidxhook1/config-iidxhook1.c +++ b/src/main/iidxhook1/config-iidxhook1.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "iidxhook1/config-iidxhook1.h" diff --git a/src/main/iidxhook1/dllmain.c b/src/main/iidxhook1/dllmain.c index 60c61a7..74995ed 100644 --- a/src/main/iidxhook1/dllmain.c +++ b/src/main/iidxhook1/dllmain.c @@ -4,18 +4,13 @@ #include #include -#include "bemanitools/eamio.h" -#include "bemanitools/iidxio.h" - #include "cconfig/cconfig-hook.h" +#include "core/boot.h" #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-debug.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" #include "core/thread-crt.h" -#include "core/thread.h" #include "ezusb-emu/desc.h" #include "ezusb-emu/device.h" @@ -33,6 +28,12 @@ #include "hooklib/adapter.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/iidx.h" + #include "iidxhook-util/chart-patch.h" #include "iidxhook-util/clock.h" #include "iidxhook-util/config-eamuse.h" @@ -49,7 +50,11 @@ #include "iidxhook1/ezusb-mon.h" #include "iidxhook1/log-ezusb.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "util/defs.h" +#include "util/proc.h" #define IIDXHOOK1_INFO_HEADER \ "iidxhook for 9th Style, 10th Style, RED and HAPPY SKY" \ @@ -65,6 +70,8 @@ static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD); static HANDLE(STDCALL *real_OpenProcess)(DWORD, BOOL, DWORD); static bool iidxhook_init_check; +static module_io_t *iidxhook_module_io_iidx; +static module_io_t *iidxhook_module_io_eam; static const struct hook_symbol init_hook_syms[] = { { @@ -76,21 +83,42 @@ static const struct hook_symbol init_hook_syms[] = { static void _iidxhook1_log_init() { - core_log_bt_ext_impl_set(); core_log_bt_ext_init_with_debug(); // TODO change log level support core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); } +static void _iidxhook1_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + +static void _iidxhook1_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} + static void iidxhook1_setup_d3d9_hooks( const struct iidxhook_config_gfx *config_gfx, const struct iidxhook_config_iidxhook1 *config_iidxhook1) { struct iidxhook_util_d3d9_config d3d9_config; - log_warning( - "d3d8 hook module deprecated, using d3d9 hook modules requiring " - "d3d8to9 to work!"); + if (!proc_is_module_loaded("d3d9.dll")) { + log_fatal( + "d3d8 hook module deprecated, using d3d9 hook modules requires " + "d3d8to9 to work! Could not detect loaded d3d9.dll"); + } iidxhook_util_d3d9_init_config(&d3d9_config); @@ -206,6 +234,10 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) /* Patch rteffect.dll calls */ + // TODO this doesn't work, because it's too late to apply this here + // this needs to be launched before bm2dx.exe even loads the rteffect.dll + // and runs DllMain of it (see also how this is done with the proxy + // ezusb.dll) if (config_misc.rteffect_stub) { effector_hook_init(); } @@ -229,24 +261,20 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - core_log_impl_assign(iidx_io_set_loggers); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _iidxhook1_io_iidx_init(&iidxhook_module_io_iidx); + + if (!bt_io_iidx_init()) { log_fatal("Initializing IIDX IO backend failed"); } /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _iidxhook1_io_eam_init(&iidxhook_module_io_eam); + + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } @@ -279,10 +307,14 @@ skip: BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - core_thread_crt_ext_impl_set(); + core_boot_dll("iidxhook1"); _iidxhook1_log_init(); + // Use bemanitools core APIs + core_log_bt_core_api_set(); + core_thread_crt_core_api_set(); + /* Bootstrap hook for further init tasks (see above) */ hook_table_apply( diff --git a/src/main/iidxhook1/ezusb-mon.c b/src/main/iidxhook1/ezusb-mon.c index 11f10f9..3b78689 100644 --- a/src/main/iidxhook1/ezusb-mon.c +++ b/src/main/iidxhook1/ezusb-mon.c @@ -6,10 +6,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "iidxhook1/ezusb-mon.h" #include "util/defs.h" diff --git a/src/main/iidxhook1/log-ezusb.c b/src/main/iidxhook1/log-ezusb.c index 28a9c6a..8533683 100644 --- a/src/main/iidxhook1/log-ezusb.c +++ b/src/main/iidxhook1/log-ezusb.c @@ -6,10 +6,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "iidxhook1/log-ezusb.h" #include "util/defs.h" diff --git a/src/main/iidxhook2/Module.mk b/src/main/iidxhook2/Module.mk index 4612442..9fd9f6b 100644 --- a/src/main/iidxhook2/Module.mk +++ b/src/main/iidxhook2/Module.mk @@ -3,6 +3,7 @@ avsdlls += iidxhook2 ldflags_iidxhook2 := \ -lws2_32 \ -liphlpapi \ + -lpsapi \ libs_iidxhook2 := \ core \ @@ -11,14 +12,16 @@ libs_iidxhook2 := \ ezusb-iidx-16seg-emu \ ezusb-iidx-emu \ security \ - eamio \ acioemu \ hook \ hooklib \ - iidxio \ cconfig \ - util \ ezusb \ + iface \ + iface-io \ + iface-core \ + module \ + util \ src_iidxhook2 := \ config-iidxhook2.c \ diff --git a/src/main/iidxhook2/config-iidxhook2.c b/src/main/iidxhook2/config-iidxhook2.c index 0db10f3..9dca3dc 100644 --- a/src/main/iidxhook2/config-iidxhook2.c +++ b/src/main/iidxhook2/config-iidxhook2.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "iidxhook2/config-iidxhook2.h" diff --git a/src/main/iidxhook2/dllmain.c b/src/main/iidxhook2/dllmain.c index de8a916..f96e388 100644 --- a/src/main/iidxhook2/dllmain.c +++ b/src/main/iidxhook2/dllmain.c @@ -4,18 +4,13 @@ #include #include -#include "bemanitools/eamio.h" -#include "bemanitools/iidxio.h" - #include "cconfig/cconfig-hook.h" +#include "core/boot.h" #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-debug.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" #include "core/thread-crt.h" -#include "core/thread.h" #include "ezusb-emu/desc.h" #include "ezusb-emu/device.h" @@ -34,6 +29,12 @@ #include "hooklib/rs232.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/iidx.h" + #include "iidxhook-util/acio.h" #include "iidxhook-util/chart-patch.h" #include "iidxhook-util/clock.h" @@ -47,8 +48,13 @@ #include "iidxhook-util/effector.h" #include "iidxhook-util/settings.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "iidxhook2/config-iidxhook2.h" +#include "util/proc.h" + #define IIDXHOOK2_INFO_HEADER \ "iidxhook for DistorteD" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) @@ -63,6 +69,8 @@ static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD); static HANDLE(STDCALL *real_OpenProcess)(DWORD, BOOL, DWORD); static bool iidxhook_init_check; +static module_io_t *iidxhook_module_io_iidx; +static module_io_t *iidxhook_module_io_eam; static const struct hook_symbol init_hook_syms[] = { {.name = "OpenProcess", @@ -72,21 +80,42 @@ static const struct hook_symbol init_hook_syms[] = { static void _iidxhook2_log_init() { - core_log_bt_ext_impl_set(); core_log_bt_ext_init_with_debug(); // TODO change log level support core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); } +static void _iidxhook2_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + +static void _iidxhook2_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} + static void iidxhook2_setup_d3d9_hooks( const struct iidxhook_config_gfx *config_gfx, const struct iidxhook_config_iidxhook2 *config_iidxhook2) { struct iidxhook_util_d3d9_config d3d9_config; - log_warning( - "d3d8 hook module deprecated, using d3d9 hook modules requiring " - "d3d8to9 to work!"); + if (!proc_is_module_loaded("d3d9.dll")) { + log_fatal( + "d3d8 hook module deprecated, using d3d9 hook modules requires " + "d3d8to9 to work! Could not detect loaded d3d9.dll"); + } iidxhook_util_d3d9_init_config(&d3d9_config); @@ -220,24 +249,20 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - core_log_impl_assign(iidx_io_set_loggers); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _iidxhook2_io_iidx_init(&iidxhook_module_io_iidx); + + if (!bt_io_iidx_init()) { log_fatal("Initializing IIDX IO backend failed"); } /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _iidxhook2_io_eam_init(&iidxhook_module_io_eam); + + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } @@ -271,7 +296,11 @@ skip: BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - core_thread_crt_ext_impl_set(); + core_boot_dll("iidxhook3"); + + // Use bemanitools core APIs + core_log_bt_core_api_set(); + core_thread_crt_core_api_set(); _iidxhook2_log_init(); diff --git a/src/main/iidxhook3/Module.mk b/src/main/iidxhook3/Module.mk index ff698f2..7272d48 100644 --- a/src/main/iidxhook3/Module.mk +++ b/src/main/iidxhook3/Module.mk @@ -17,13 +17,15 @@ libs_iidxhook3 := \ ezusb-iidx-emu \ security \ acioemu \ - eamio \ hook \ hooklib \ - iidxio \ cconfig \ - util \ ezusb \ + iface \ + iface-io \ + iface-core \ + module \ + util \ src_iidxhook3 := \ avs-boot.c \ diff --git a/src/main/iidxhook3/avs-boot.c b/src/main/iidxhook3/avs-boot.c index 196439f..77ab800 100644 --- a/src/main/iidxhook3/avs-boot.c +++ b/src/main/iidxhook3/avs-boot.c @@ -3,14 +3,16 @@ #include #include +#include "core/log-bt.h" + #include "hook/table.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "iidxhook3/avs-boot.h" -#include "util/log.h" - static void (*real_avs_boot)( struct property_node *config, void *std_heap, @@ -50,6 +52,11 @@ static const struct hook_symbol iidxhook3_ea3_hook_syms[] = { .link = (void **) &real_ea3_boot}, }; +static AVS_LOG_WRITER(_avs_boot_log_writer, chars, nchars, ctx) +{ + core_log_bt_direct_sink_write(chars, nchars); +} + static void avs_boot_replace_property_uint32( struct property_node *node, const char *name, uint32_t val) { @@ -103,7 +110,7 @@ static void my_avs_boot( sz_std_heap, avs_heap, sz_avs_heap, - log_writer_debug, + _avs_boot_log_writer, NULL); } diff --git a/src/main/iidxhook3/dllmain.c b/src/main/iidxhook3/dllmain.c index a62b4e3..39f6d59 100644 --- a/src/main/iidxhook3/dllmain.c +++ b/src/main/iidxhook3/dllmain.c @@ -4,18 +4,13 @@ #include #include -#include "bemanitools/eamio.h" -#include "bemanitools/iidxio.h" - #include "cconfig/cconfig-hook.h" +#include "core/boot.h" #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-debug.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" #include "core/thread-crt.h" -#include "core/thread.h" #include "ezusb-emu/node-security-plug.h" #include "ezusb-iidx-emu/node-serial.h" @@ -35,6 +30,12 @@ #include "hooklib/rs232.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/iidx.h" + #include "iidxhook3/avs-boot.h" #include "iidxhook-util/acio.h" @@ -47,6 +48,9 @@ #include "iidxhook-util/d3d9.h" #include "iidxhook-util/settings.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "security/rp-sign-key.h" #include "util/str.h" @@ -63,7 +67,10 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD); static HANDLE(STDCALL *real_OpenProcess)(DWORD, BOOL, DWORD); + static bool iidxhook_init_check; +static module_io_t *iidxhook_module_io_iidx; +static module_io_t *iidxhook_module_io_eam; static const struct hook_symbol init_hook_syms[] = { {.name = "OpenProcess", @@ -73,12 +80,31 @@ static const struct hook_symbol init_hook_syms[] = { static void _iidxhook3_log_init() { - core_log_bt_ext_impl_set(); core_log_bt_ext_init_with_debug(); // TODO change log level support core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); } +static void _iidxhook3_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + +static void _iidxhook3_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} + static void iidxhook3_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -213,24 +239,20 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - core_log_impl_assign(iidx_io_set_loggers); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _iidxhook3_io_iidx_init(&iidxhook_module_io_iidx); + + if (!bt_io_iidx_init()) { log_fatal("Initializing IIDX IO backend failed"); } /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _iidxhook3_io_eam_init(&iidxhook_module_io_eam); + + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } @@ -263,7 +285,11 @@ skip: BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - core_thread_crt_ext_impl_set(); + core_boot_dll("iidxhook3"); + + // Use bemanitools core APIs + core_log_bt_core_api_set(); + core_thread_crt_core_api_set(); _iidxhook3_log_init(); diff --git a/src/main/iidxhook4-cn/Module.mk b/src/main/iidxhook4-cn/Module.mk index 8cc34cb..f20905d 100644 --- a/src/main/iidxhook4-cn/Module.mk +++ b/src/main/iidxhook4-cn/Module.mk @@ -7,8 +7,10 @@ ldflags_iidxhook4-cn := \ deplibs_iidxhook4-cn := \ avs \ +avslibs_iidxhook4-cn := \ + avs-ext \ + libs_iidxhook4-cn := \ - avs-util \ core \ iidxhook-util \ ezusb-emu \ @@ -18,10 +20,14 @@ libs_iidxhook4-cn := \ security \ hook \ hooklib \ - iidxio \ cconfig \ util \ ezusb \ + iface \ + iface-io \ + iface-core \ + module \ + util \ src_iidxhook4-cn := \ avs-boot.c \ diff --git a/src/main/iidxhook4-cn/avs-boot.c b/src/main/iidxhook4-cn/avs-boot.c index 4c498c9..be94783 100644 --- a/src/main/iidxhook4-cn/avs-boot.c +++ b/src/main/iidxhook4-cn/avs-boot.c @@ -4,10 +4,11 @@ #include #include "core/log-bt.h" -#include "core/log.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "iidxhook4-cn/avs-boot.h" diff --git a/src/main/iidxhook4-cn/dllmain.c b/src/main/iidxhook4-cn/dllmain.c index 9fa61ba..5a68cc1 100644 --- a/src/main/iidxhook4-cn/dllmain.c +++ b/src/main/iidxhook4-cn/dllmain.c @@ -5,18 +5,14 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/iidxio.h" +#include "avs-ext/thread.h" #include "cconfig/cconfig-hook.h" +#include "core/boot.h" #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-debug.h" -#include "core/log.h" -#include "core/thread-crt.h" -#include "core/thread.h" #include "ezusb-emu/node-security-plug.h" @@ -30,6 +26,11 @@ #include "hooklib/acp.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/iidx.h" + #include "iidxhook4-cn/avs-boot.h" #include "iidxhook4-cn/path.h" @@ -42,10 +43,13 @@ #include "iidxhook-util/d3d9.h" #include "iidxhook-util/settings.h" -#include "security/rp-sign-key.h" - #include "imports/avs.h" +#include "module/io-ext.h" +#include "module/io.h" + +#include "security/rp-sign-key.h" + #define IIDXHOOK4_CN_INFO_HEADER \ "iidxhook for Resort Anthem CN" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) @@ -67,15 +71,25 @@ static const struct hook_symbol init_hook_syms[] = { }; static struct iidxhook_config_io config_io; +static module_io_t *iidxhook_module_io_iidx; static void _iidxhook4_cn_log_init() { - core_log_bt_ext_impl_set(); core_log_bt_ext_init_with_debug(); // TODO change log level support core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); } +static void _iidxhook4_cn_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + static void iidxhook4_cn_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -198,12 +212,9 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - core_log_impl_assign(iidx_io_set_loggers); + _iidxhook4_cn_io_iidx_init(&iidxhook_module_io_iidx); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_iidx_init()) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -237,8 +248,13 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) return TRUE; } + core_boot_dll("iidxhook4-cn"); + + // Use bemanitools core APIs + core_log_bt_core_api_set(); + // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); + avs_ext_thread_core_api_set(); // TODO init debug logging but with avs available? why not use avs logging? _iidxhook4_cn_log_init(); diff --git a/src/main/iidxhook4-cn/path.c b/src/main/iidxhook4-cn/path.c index 5d4ef1d..c9bf474 100644 --- a/src/main/iidxhook4-cn/path.c +++ b/src/main/iidxhook4-cn/path.c @@ -4,10 +4,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "iidxhook4-cn/path.h" #include "util/str.h" diff --git a/src/main/iidxhook4/Module.mk b/src/main/iidxhook4/Module.mk index 6546ac1..bffd153 100644 --- a/src/main/iidxhook4/Module.mk +++ b/src/main/iidxhook4/Module.mk @@ -6,8 +6,10 @@ ldflags_iidxhook4 := \ deplibs_iidxhook4 := \ avs \ +avslibs_iidxhook4 := \ + avs-ext \ + libs_iidxhook4 := \ - avs-util \ core \ iidxhook-util \ ezusb-emu \ @@ -16,14 +18,16 @@ libs_iidxhook4 := \ ezusb2-iidx-emu \ ezusb-iidx-emu \ security \ - eamio \ acioemu \ hook \ hooklib \ - iidxio \ cconfig \ - util \ ezusb \ + iface \ + iface-io \ + iface-core \ + module \ + util \ src_iidxhook4 := \ dllmain.c \ diff --git a/src/main/iidxhook4/dllmain.c b/src/main/iidxhook4/dllmain.c index c52336f..049da27 100644 --- a/src/main/iidxhook4/dllmain.c +++ b/src/main/iidxhook4/dllmain.c @@ -5,15 +5,12 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/eamio.h" -#include "bemanitools/iidxio.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "cconfig/cconfig-hook.h" -#include "core/log.h" -#include "core/thread.h" +#include "core/boot.h" #include "ezusb-iidx-emu/nodes.h" @@ -30,6 +27,12 @@ #include "hooklib/rs232.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/iidx.h" + #include "iidxhook-util/acio.h" #include "iidxhook-util/chart-patch.h" #include "iidxhook-util/config-gfx.h" @@ -41,6 +44,9 @@ #include "imports/avs.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "util/str.h" #define IIDXHOOK4_INFO_HEADER \ @@ -54,6 +60,28 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { }; static struct iidxhook_config_io config_io; +static module_io_t *iidxhook_module_io_iidx; +static module_io_t *iidxhook_module_io_eam; + +static void _iidxhook4_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + +static void _iidxhook4_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} static void iidxhook4_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) @@ -145,12 +173,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - core_log_impl_assign(iidx_io_set_loggers); + _iidxhook4_io_iidx_init(&iidxhook_module_io_iidx); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_iidx_init()) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -160,12 +185,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_card_reader_emu) { log_misc("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); + _iidxhook4_io_eam_init(&iidxhook_module_io_eam); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } } else { @@ -210,12 +232,18 @@ static bool my_dll_entry_main(void) if (!config_io.disable_card_reader_emu) { log_misc("Shutting down card reader backend"); - eam_io_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&iidxhook_module_io_eam); } if (!config_io.disable_io_emu) { log_misc("Shutting down IIDX IO backend"); - iidx_io_fini(); + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&iidxhook_module_io_iidx); } log_server_fini(); @@ -232,9 +260,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } + core_boot("iidxhook4"); + // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); app_hook_init(my_dll_entry_init, my_dll_entry_main); diff --git a/src/main/iidxhook5-cn/Module.mk b/src/main/iidxhook5-cn/Module.mk index 5addce9..5eaaeba 100644 --- a/src/main/iidxhook5-cn/Module.mk +++ b/src/main/iidxhook5-cn/Module.mk @@ -7,8 +7,10 @@ ldflags_iidxhook5-cn := \ deplibs_iidxhook5-cn := \ avs \ +avslibs_iidxhook5-cn := \ + avs-ext \ + libs_iidxhook5-cn := \ - avs-util \ core \ iidxhook-util \ ezusb-emu \ @@ -18,10 +20,13 @@ libs_iidxhook5-cn := \ security \ hook \ hooklib \ - iidxio \ cconfig \ - util \ ezusb \ + iface \ + iface-io \ + iface-core \ + module \ + util \ src_iidxhook5-cn := \ avs-boot.c \ diff --git a/src/main/iidxhook5-cn/avs-boot.c b/src/main/iidxhook5-cn/avs-boot.c index eaa1f45..13cca83 100644 --- a/src/main/iidxhook5-cn/avs-boot.c +++ b/src/main/iidxhook5-cn/avs-boot.c @@ -4,10 +4,11 @@ #include #include "core/log-bt.h" -#include "core/log.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "iidxhook5-cn/avs-boot.h" diff --git a/src/main/iidxhook5-cn/dllmain.c b/src/main/iidxhook5-cn/dllmain.c index 1d327dc..e286af9 100644 --- a/src/main/iidxhook5-cn/dllmain.c +++ b/src/main/iidxhook5-cn/dllmain.c @@ -5,17 +5,14 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/iidxio.h" +#include "avs-ext/thread.h" #include "cconfig/cconfig-hook.h" +#include "core/boot.h" #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-debug.h" -#include "core/log.h" -#include "core/thread.h" #include "ezusb-emu/node-security-plug.h" @@ -30,6 +27,11 @@ #include "hooklib/acp.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/iidx.h" + #include "iidxhook5-cn/avs-boot.h" #include "iidxhook5-cn/path.h" @@ -41,10 +43,13 @@ #include "iidxhook-util/d3d9.h" #include "iidxhook-util/settings.h" -#include "security/rp-sign-key.h" - #include "imports/avs.h" +#include "module/io-ext.h" +#include "module/io.h" + +#include "security/rp-sign-key.h" + #define IIDXHOOK5_CN_INFO_HEADER \ "iidxhook for tricoro CN" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) @@ -66,15 +71,25 @@ static const struct hook_symbol init_hook_user32_syms[] = { }; static struct iidxhook_config_io config_io; +static module_io_t *iidxhook_module_io_iidx; static void _iidxhook5_cn_log_init() { - core_log_bt_ext_impl_set(); core_log_bt_ext_init_with_debug(); // TODO change log level support core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); } +static void _iidxhook5_cn_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + static void iidxhook5_cn_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -177,12 +192,9 @@ static ATOM WINAPI my_RegisterClassA(const WNDCLASSA *lpWndClass) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - core_log_impl_assign(iidx_io_set_loggers); + _iidxhook5_cn_io_iidx_init(&iidxhook_module_io_iidx); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_iidx_init()) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -215,8 +227,13 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) return TRUE; } + core_boot_dll("iidxhook5-cn"); + + // Use bemanitools core APIs + core_log_bt_core_api_set(); + // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); + avs_ext_thread_core_api_set(); // TODO init debug logging but with avs available? why not use avs logging? _iidxhook5_cn_log_init(); diff --git a/src/main/iidxhook5-cn/path.c b/src/main/iidxhook5-cn/path.c index bb4f81d..2357e92 100644 --- a/src/main/iidxhook5-cn/path.c +++ b/src/main/iidxhook5-cn/path.c @@ -4,10 +4,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "iidxhook5-cn/path.h" #include "util/str.h" diff --git a/src/main/iidxhook5/Module.mk b/src/main/iidxhook5/Module.mk index 28cb7fe..f88ef25 100644 --- a/src/main/iidxhook5/Module.mk +++ b/src/main/iidxhook5/Module.mk @@ -6,8 +6,10 @@ ldflags_iidxhook5 := \ deplibs_iidxhook5 := \ avs \ +avslibs_iidxhook5 := \ + avs-ext \ + libs_iidxhook5 := \ - avs-util \ core \ iidxhook-util \ ezusb-emu \ @@ -16,14 +18,16 @@ libs_iidxhook5 := \ ezusb2-iidx-emu \ ezusb-iidx-emu \ security \ - eamio \ acioemu \ hook \ hooklib \ - iidxio \ cconfig \ - util \ ezusb \ + iface \ + iface-io \ + iface-core \ + module \ + util \ src_iidxhook5 := \ dllmain.c \ diff --git a/src/main/iidxhook5/dllmain.c b/src/main/iidxhook5/dllmain.c index 0912c38..7ed6290 100644 --- a/src/main/iidxhook5/dllmain.c +++ b/src/main/iidxhook5/dllmain.c @@ -5,15 +5,12 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/eamio.h" -#include "bemanitools/iidxio.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "cconfig/cconfig-hook.h" -#include "core/log.h" -#include "core/thread.h" +#include "core/boot.h" #include "ezusb-iidx-emu/nodes.h" @@ -30,6 +27,12 @@ #include "hooklib/rs232.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/iidx.h" + #include "iidxhook-util/acio.h" #include "iidxhook-util/chart-patch.h" #include "iidxhook-util/config-gfx.h" @@ -41,6 +44,9 @@ #include "imports/avs.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "util/str.h" #include "ifs-snd-redir.h" @@ -56,6 +62,28 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { }; static struct iidxhook_config_io config_io; +static module_io_t *iidxhook_module_io_iidx; +static module_io_t *iidxhook_module_io_eam; + +static void _iidxhook5_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + +static void _iidxhook5_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} static void iidxhook5_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) @@ -147,12 +175,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - core_log_impl_assign(iidx_io_set_loggers); + _iidxhook5_io_iidx_init(&iidxhook_module_io_iidx); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_iidx_init()) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -162,12 +187,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_card_reader_emu) { log_misc("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); + _iidxhook5_io_eam_init(&iidxhook_module_io_eam); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } } else { @@ -211,12 +233,18 @@ static bool my_dll_entry_main(void) if (!config_io.disable_card_reader_emu) { log_misc("Shutting down card reader backend"); - eam_io_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&iidxhook_module_io_eam); } if (!config_io.disable_io_emu) { log_misc("Shutting down IIDX IO backend"); - iidx_io_fini(); + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&iidxhook_module_io_iidx); } log_server_fini(); @@ -233,9 +261,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } + core_boot("iidxhook5"); + // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); app_hook_init(my_dll_entry_init, my_dll_entry_main); diff --git a/src/main/iidxhook5/ifs-snd-redir.c b/src/main/iidxhook5/ifs-snd-redir.c index 639d16f..64fff9d 100644 --- a/src/main/iidxhook5/ifs-snd-redir.c +++ b/src/main/iidxhook5/ifs-snd-redir.c @@ -3,12 +3,12 @@ #include #include -#include "core/log.h" - #include "hook/table.h" #include "imports/avs.h" +#include "iface-core/log.h" + #include "iidxhook5/ifs-snd-redir.h" #include "util/str.h" diff --git a/src/main/iidxhook6/Module.mk b/src/main/iidxhook6/Module.mk index fe7e955..b0e591c 100644 --- a/src/main/iidxhook6/Module.mk +++ b/src/main/iidxhook6/Module.mk @@ -6,8 +6,10 @@ ldflags_iidxhook6 := \ deplibs_iidxhook6 := \ avs \ +avslibs_iidxhook6 := \ + avs-ext \ + libs_iidxhook6 := \ - avs-util \ core \ iidxhook-d3d9 \ iidxhook-util \ @@ -17,14 +19,16 @@ libs_iidxhook6 := \ ezusb2-iidx-emu \ ezusb-iidx-emu \ security \ - eamio \ acioemu \ hook \ hooklib \ - iidxio \ cconfig \ - util \ ezusb \ + iface \ + iface-io \ + iface-core \ + module \ + util \ src_iidxhook6 := \ dllmain.c \ diff --git a/src/main/iidxhook6/dllmain.c b/src/main/iidxhook6/dllmain.c index 4b614a4..1e0a299 100644 --- a/src/main/iidxhook6/dllmain.c +++ b/src/main/iidxhook6/dllmain.c @@ -5,15 +5,12 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/eamio.h" -#include "bemanitools/iidxio.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "cconfig/cconfig-hook.h" -#include "core/log.h" -#include "core/thread.h" +#include "core/boot.h" #include "ezusb-iidx-emu/nodes.h" @@ -26,10 +23,15 @@ #include "hooklib/acp.h" #include "hooklib/adapter.h" -#include "hooklib/app.h" #include "hooklib/rs232.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/iidx.h" + #include "iidxhook-d3d9/bb-scale-hd.h" #include "iidxhook-util/acio.h" @@ -38,7 +40,10 @@ #include "iidxhook-util/d3d9.h" #include "iidxhook-util/log-server.h" -#include "imports/avs.h" +#include "module/io-ext.h" +#include "module/io.h" + +#include "sdk/module/hook.h" #include "util/str.h" @@ -54,6 +59,28 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { }; static struct iidxhook_config_io config_io; +static module_io_t *iidxhook_module_io_iidx; +static module_io_t *iidxhook_module_io_eam; + +static void _iidxhook6_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + +static void _iidxhook6_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} static void iidxhook6_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) @@ -86,17 +113,17 @@ iidxhook6_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) hook_d3d9_init(iidxhook_d3d9_handlers, lengthof(iidxhook_d3d9_handlers)); } -static bool my_dll_entry_init(char *sidcode, struct property_node *param) +static bool +_iidxhook6_main_init(HMODULE game_module, const bt_core_config_t *config_) { + // Use AVS APIs + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); + struct cconfig *config; struct iidxhook_config_gfx config_gfx; - log_server_init(); - log_info("-------------------------------------------------------------"); - log_info("--------------- Begin iidxhook dll_entry_init ---------------"); - log_info("-------------------------------------------------------------"); - config = cconfig_init(); iidxhook_config_gfx_init(config); @@ -107,7 +134,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) IIDXHOOK6_INFO_HEADER "\n" IIDXHOOK6_CMD_USAGE, CCONFIG_CMD_USAGE_OUT_DBG)) { cconfig_finit(config); - log_server_fini(); + + // log_server_fini(); exit(EXIT_FAILURE); } @@ -117,19 +145,20 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) cconfig_finit(config); log_info(IIDXHOOK6_INFO_HEADER); - log_info("Initializing iidxhook..."); + + log_server_init(); + + acp_hook_init(); + adapter_hook_init(); iidxhook6_setup_d3d9_hooks(&config_gfx); if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - core_log_impl_assign(iidx_io_set_loggers); + _iidxhook6_io_iidx_init(&iidxhook_module_io_iidx); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_iidx_init()) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -139,12 +168,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_card_reader_emu) { log_misc("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); + _iidxhook6_io_eam_init(&iidxhook_module_io_eam); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } } else { @@ -171,52 +197,39 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) iidxhook_util_acio_init(false); } - log_info("-------------------------------------------------------------"); - log_info("---------------- End iidxhook dll_entry_init ----------------"); - log_info("-------------------------------------------------------------"); - - return app_hook_invoke_init(sidcode, param); + return true; } -static bool my_dll_entry_main(void) +static void _iidxhook6_main_fini() { - bool result; - - result = app_hook_invoke_main(); - if (!config_io.disable_card_reader_emu) { log_misc("Shutting down card reader backend"); - eam_io_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&iidxhook_module_io_eam); } if (!config_io.disable_io_emu) { log_misc("Shutting down IIDX IO backend"); - iidx_io_fini(); + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&iidxhook_module_io_iidx); } log_server_fini(); - - return result; } -/** - * Hook library for Tricoro - */ +void bt_module_hook_api_get(bt_hook_api_t *api) +{ + api->version = 1; + + api->v1.main_init = _iidxhook6_main_init; + api->v1.main_fini = _iidxhook6_main_fini; +} + BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { - if (reason != DLL_PROCESS_ATTACH) { - goto end; - } - - // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); - - app_hook_init(my_dll_entry_init, my_dll_entry_main); - - acp_hook_init(); - adapter_hook_init(); - -end: return TRUE; } diff --git a/src/main/iidxhook6/iidxhook6.def b/src/main/iidxhook6/iidxhook6.def index a0da401..44317f7 100644 --- a/src/main/iidxhook6/iidxhook6.def +++ b/src/main/iidxhook6/iidxhook6.def @@ -2,4 +2,6 @@ LIBRARY iidxhook6 EXPORTS DllMain@12 @1 NONAME - \ No newline at end of file + + ; Bemanitools 6 API + bt_module_hook_api_get \ No newline at end of file diff --git a/src/main/iidxhook7/Module.mk b/src/main/iidxhook7/Module.mk index b1b6d93..f086078 100644 --- a/src/main/iidxhook7/Module.mk +++ b/src/main/iidxhook7/Module.mk @@ -7,8 +7,10 @@ ldflags_iidxhook7 := \ deplibs_iidxhook7 := \ avs \ +avslibs_iidxhook7 := \ + avs-ext \ + libs_iidxhook7 := \ - avs-util \ core \ iidxhook-d3d9 \ iidxhook-util \ @@ -19,13 +21,15 @@ libs_iidxhook7 := \ ezusb2-iidx-emu \ ezusb-iidx-emu \ security \ - eamio \ acioemu \ hook \ hooklib \ - iidxio \ - util \ ezusb \ + iface \ + iface-io \ + iface-core \ + module \ + util \ src_iidxhook7 := \ dllmain.c \ diff --git a/src/main/iidxhook7/dllmain.c b/src/main/iidxhook7/dllmain.c index 0823e85..6c7c628 100644 --- a/src/main/iidxhook7/dllmain.c +++ b/src/main/iidxhook7/dllmain.c @@ -5,15 +5,12 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/eamio.h" -#include "bemanitools/iidxio.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "cconfig/cconfig-hook.h" -#include "core/log.h" -#include "core/thread.h" +#include "core/boot.h" #include "ezusb-iidx-emu/nodes.h" @@ -30,6 +27,12 @@ #include "hooklib/rs232.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/iidx.h" + #include "iidxhook-d3d9/bb-scale-hd.h" #include "iidxhook-util/acio.h" @@ -40,6 +43,9 @@ #include "imports/avs.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "util/str.h" #define IIDXHOOK7_INFO_HEADER \ @@ -54,6 +60,28 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { }; static struct iidxhook_config_io config_io; +static module_io_t *iidxhook_module_io_iidx; +static module_io_t *iidxhook_module_io_eam; + +static void _iidxhook7_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + +static void _iidxhook7_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} static void iidxhook7_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) @@ -124,12 +152,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - core_log_impl_assign(iidx_io_set_loggers); + _iidxhook7_io_iidx_init(&iidxhook_module_io_iidx); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_iidx_init()) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -139,12 +164,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_card_reader_emu) { log_misc("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); + _iidxhook7_io_eam_init(&iidxhook_module_io_eam); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } } else { @@ -186,12 +208,18 @@ static bool my_dll_entry_main(void) if (!config_io.disable_card_reader_emu) { log_misc("Shutting down card reader backend"); - eam_io_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&iidxhook_module_io_eam); } if (!config_io.disable_io_emu) { log_misc("Shutting down IIDX IO backend"); - iidx_io_fini(); + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&iidxhook_module_io_iidx); } log_server_fini(); @@ -208,9 +236,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } + core_boot("iidxhook7"); + // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); app_hook_init(my_dll_entry_init, my_dll_entry_main); diff --git a/src/main/iidxhook8/Module.mk b/src/main/iidxhook8/Module.mk index faebbbb..ccf6423 100644 --- a/src/main/iidxhook8/Module.mk +++ b/src/main/iidxhook8/Module.mk @@ -11,8 +11,10 @@ ldflags_iidxhook8 := \ deplibs_iidxhook8 := \ avs \ +avslibs_iidxhook8 := \ + avs-ext \ + libs_iidxhook8 := \ - avs-util \ core \ iidxhook-d3d9 \ iidxhook-util \ @@ -20,12 +22,14 @@ libs_iidxhook8 := \ bio2emu \ bio2emu-iidx \ camhook \ - iidxio \ hook \ hooklib \ cconfig \ + iface \ + iface-io \ + iface-core \ + module \ util \ - eamio \ src_iidxhook8 := \ config-io.c \ diff --git a/src/main/iidxhook8/config-io.c b/src/main/iidxhook8/config-io.c index 9f61e13..7aca5fa 100644 --- a/src/main/iidxhook8/config-io.c +++ b/src/main/iidxhook8/config-io.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "iidxhook8/config-io.h" diff --git a/src/main/iidxhook8/dllmain.c b/src/main/iidxhook8/dllmain.c index 64b8a0e..6ff9e78 100644 --- a/src/main/iidxhook8/dllmain.c +++ b/src/main/iidxhook8/dllmain.c @@ -5,15 +5,12 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/eamio.h" -#include "bemanitools/iidxio.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "cconfig/cconfig-hook.h" -#include "core/log.h" -#include "core/thread.h" +#include "core/boot.h" #include "hook/d3d9.h" @@ -23,6 +20,12 @@ #include "hooklib/rs232.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/iidx.h" + #include "iidxhook-d3d9/bb-scale-hd.h" #include "iidxhook-util/acio.h" @@ -39,6 +42,9 @@ #include "imports/avs.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "util/str.h" #define IIDXHOOK8_INFO_HEADER \ @@ -52,6 +58,29 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, }; +static module_io_t *iidxhook_module_io_iidx; +static module_io_t *iidxhook_module_io_eam; + +static void _iidxhook8_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + +static void _iidxhook8_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} + static void iidxhook8_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -134,12 +163,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up IIDXIO.DLL */ if (!iidxhook8_config_io.disable_bio2_emu) { log_info("Starting IIDX IO backend"); - core_log_impl_assign(iidx_io_set_loggers); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _iidxhook8_io_iidx_init(&iidxhook_module_io_iidx); + + if (!bt_io_iidx_init()) { log_fatal("Initializing IIDX IO backend failed"); } } @@ -147,12 +174,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up EAMIO.DLL */ if (!iidxhook8_config_io.disable_card_reader_emu) { log_misc("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _iidxhook8_io_eam_init(&iidxhook_module_io_eam); + + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } } @@ -200,12 +225,18 @@ static bool my_dll_entry_main(void) if (!iidxhook8_config_io.disable_card_reader_emu) { log_misc("Shutting down card reader backend"); - eam_io_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&iidxhook_module_io_eam); } if (!iidxhook8_config_io.disable_bio2_emu) { log_misc("Shutting down IIDX IO backend"); - iidx_io_fini(); + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&iidxhook_module_io_iidx); } log_server_fini(); @@ -222,9 +253,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } + core_boot("iidxhook8"); + // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); app_hook_init(my_dll_entry_init, my_dll_entry_main); diff --git a/src/main/iidxhook9/Module.mk b/src/main/iidxhook9/Module.mk index 33cd195..80eb9b6 100644 --- a/src/main/iidxhook9/Module.mk +++ b/src/main/iidxhook9/Module.mk @@ -11,8 +11,10 @@ ldflags_iidxhook9 := \ deplibs_iidxhook9 := \ avs \ +avslibs_iidxhook9 := \ + avs-ext \ + libs_iidxhook9 := \ - avs-util \ core \ iidxhook-util \ acioemu \ @@ -22,12 +24,14 @@ libs_iidxhook9 := \ camhook \ d3d9exhook \ dinput \ - iidxio \ hook \ hooklib \ cconfig \ + iface \ + iface-io \ + iface-core \ + module \ util \ - eamio \ src_iidxhook9 := \ config-io.c \ diff --git a/src/main/iidxhook9/config-io.c b/src/main/iidxhook9/config-io.c index 34deebf..b46d212 100644 --- a/src/main/iidxhook9/config-io.c +++ b/src/main/iidxhook9/config-io.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "iidxhook9/config-io.h" diff --git a/src/main/iidxhook9/dllmain.c b/src/main/iidxhook9/dllmain.c index e93d1b4..7448b78 100644 --- a/src/main/iidxhook9/dllmain.c +++ b/src/main/iidxhook9/dllmain.c @@ -5,17 +5,15 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/eamio.h" -#include "bemanitools/iidxio.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "cconfig/cconfig-hook.h" +#include "core/boot.h" + #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" -#include "core/thread.h" #include "hooklib/acp.h" #include "hooklib/adapter.h" @@ -25,6 +23,12 @@ #include "hooklib/rs232.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/iidx.h" + #include "iidxhook-util/acio.h" #include "iidxhook-util/log-server.h" @@ -45,6 +49,9 @@ #include "imports/avs.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "util/cmdline.h" #include "util/str.h" @@ -67,6 +74,29 @@ static struct bio2emu_port bio2_emu = { .dispatcher = bio2_emu_bi2a_dispatch_request, }; +static module_io_t *iidxhook_module_io_iidx; +static module_io_t *iidxhook_module_io_eam; + +static void _iidxhook9_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + +static void _iidxhook9_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} + static bool load_configs() { struct cconfig *config; @@ -104,9 +134,10 @@ static bool load_configs() static bool my_dll_entry_init(char *sidcode, struct property_node *param) { // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); - // log_server_init is required due to IO occuring in a non avs_thread + // log_server_init is required due to IO occurring in a non avs_thread log_server_init(); log_info("-------------------------------------------------------------"); @@ -133,12 +164,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up IIDXIO.DLL */ if (!iidxhook9_config_io.disable_bio2_emu) { log_info("Starting IIDX IO backend"); - core_log_impl_assign(iidx_io_set_loggers); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _iidxhook9_io_iidx_init(&iidxhook_module_io_iidx); + + if (!bt_io_iidx_init()) { log_fatal("Initializing IIDX IO backend failed"); } } @@ -146,12 +175,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up EAMIO.DLL */ if (!iidxhook9_config_io.disable_card_reader_emu) { log_misc("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _iidxhook9_io_eam_init(&iidxhook_module_io_eam); + + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } } @@ -228,12 +255,18 @@ static bool my_dll_entry_main(void) if (!iidxhook9_config_io.disable_card_reader_emu) { log_misc("Shutting down card reader backend"); - eam_io_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&iidxhook_module_io_eam); } if (!iidxhook9_config_io.disable_bio2_emu) { log_misc("Shutting down IIDX IO backend"); - iidx_io_fini(); + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&iidxhook_module_io_iidx); } if (!iidxhook9_config_io.disable_file_hooks) { @@ -282,11 +315,13 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } + core_boot("iidxhook9"); + if (avs_is_active()) { // if AVS is loaded, we're likely too late to be a prehook // so we warn the user // and switch the current logging context to AVS so it shows up in logs - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); log_warning("iidxhook9 is designed to be used as a prehook"); log_warning("please ensure that it is being loaded with -B"); @@ -295,7 +330,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) // we can't log to external in DllMain (AVS) as we're a prehook // later during my_dll_entry_init, log_server_init is called // which sets swaps the main log write to that instead - core_log_bt_ext_impl_set(); + core_log_bt_ext_init_with_stderr(); } pre_hook(); diff --git a/src/main/iidxhook9/fs-hook.c b/src/main/iidxhook9/fs-hook.c index b7e0df2..cca7a7c 100644 --- a/src/main/iidxhook9/fs-hook.c +++ b/src/main/iidxhook9/fs-hook.c @@ -5,11 +5,12 @@ #include "hook/table.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "iidxhook9/fs-hook.h" -#include "util/log.h" #include "util/str.h" static void *(*real_avs_fs_mount)(const char *dest, const char *src, const char *fs_type, const char *options); diff --git a/src/main/iidxio-bio2/Module.mk b/src/main/iidxio-bio2/Module.mk index e91d76a..c374a13 100644 --- a/src/main/iidxio-bio2/Module.mk +++ b/src/main/iidxio-bio2/Module.mk @@ -9,6 +9,10 @@ libs_iidxio-bio2 := \ bio2drv \ cconfig \ util \ + iface \ + module \ + iface-io \ + iface-core \ src_iidxio-bio2 := \ iidxio.c \ diff --git a/src/main/iidxio-bio2/iidxio-bio2.def b/src/main/iidxio-bio2/iidxio-bio2.def index 403900d..848c574 100644 --- a/src/main/iidxio-bio2/iidxio-bio2.def +++ b/src/main/iidxio-bio2/iidxio-bio2.def @@ -1,18 +1,23 @@ LIBRARY iidxio EXPORTS - iidx_io_ep1_send - iidx_io_ep1_set_deck_lights - iidx_io_ep1_set_panel_lights - iidx_io_ep1_set_top_lamps - iidx_io_ep1_set_top_neons - iidx_io_ep2_get_keys - iidx_io_ep2_get_panel - iidx_io_ep2_get_sys - iidx_io_ep2_get_slider - iidx_io_ep2_get_turntable - iidx_io_ep2_recv - iidx_io_ep3_write_16seg - iidx_io_fini - iidx_io_init - iidx_io_set_loggers + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_io_iidx_api_get + + ; Direct API + bt_io_iidx_init + bt_io_iidx_fini + bt_io_iidx_ep1_deck_lights_set + bt_io_iidx_ep1_panel_lights_set + bt_io_iidx_ep1_top_lamps_set + bt_io_iidx_ep1_top_neons_set + bt_io_iidx_ep1_send + bt_io_iidx_ep2_recv + bt_io_iidx_ep2_turntable_get + bt_io_iidx_ep2_slider_get + bt_io_iidx_ep2_sys_get + bt_io_iidx_ep2_panel_get + bt_io_iidx_ep2_keys_get + bt_io_iidx_ep3_16seg_send diff --git a/src/main/iidxio-bio2/iidxio.c b/src/main/iidxio-bio2/iidxio.c index 2bca0dc..f1dbb63 100644 --- a/src/main/iidxio-bio2/iidxio.c +++ b/src/main/iidxio-bio2/iidxio.c @@ -1,32 +1,30 @@ -#include - #define LOG_MODULE "iidxio-bio2" +#include + #include #include #include #include #include -#include "bemanitools/glue.h" -#include "bemanitools/iidxio.h" - -#include "cconfig/cconfig-main.h" - #include "aciodrv/device.h" + +#include "api/core/log.h" +#include "api/core/thread.h" + #include "bio2drv/bi2a-iidx.h" #include "bio2drv/config-bio2.h" #include "bio2drv/detect.h" -#define log_misc(...) iidx_io_log_misc(LOG_MODULE, __VA_ARGS__) -#define log_info(...) iidx_io_log_info(LOG_MODULE, __VA_ARGS__) -#define log_warning(...) iidx_io_log_warning(LOG_MODULE, __VA_ARGS__) -#define log_fatal(...) iidx_io_log_fatal(LOG_MODULE, __VA_ARGS__) +#include "iface-core/log.h" +#include "iface-core/thread.h" -static log_formatter_t iidx_io_log_misc; -static log_formatter_t iidx_io_log_info; -static log_formatter_t iidx_io_log_warning; -static log_formatter_t iidx_io_log_fatal; +#include "cconfig/cconfig-main.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/io/iidx.h" static char autodetect_buffer[512]; @@ -40,6 +38,9 @@ static struct bi2a_iidx_state_out pout_ready; static struct aciodrv_device_ctx *bio2_device_ctx; +bool bt_io_iidx_ep1_send(void); +bool bt_io_iidx_ep2_recv(void); + static bool _bio2_iidx_io_poll( const struct bi2a_iidx_state_out *pout, struct bi2a_iidx_state_in *pin) { @@ -58,24 +59,7 @@ static bool _bio2_iidx_io_poll( return true; } -void iidx_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - iidx_io_log_misc = misc; - iidx_io_log_info = info; - iidx_io_log_warning = warning; - iidx_io_log_fatal = fatal; - - bio2drv_set_loggers(misc, info, warning, fatal); -} - -bool iidx_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_iidx_init() { struct cconfig *config; struct bio2drv_config_bio2 config_bio2; @@ -169,14 +153,14 @@ bool iidx_io_init( return running; } -void iidx_io_fini(void) +void bt_io_iidx_fini(void) { // Pushing some final state before closing the IO to the actual outputs, // e.g. lights on/off can be a bit finicky. Do a few polls to // "enforce"/flush this final state for (uint8_t i = 0; i < 3; i++) { - iidx_io_ep1_send(); - iidx_io_ep2_recv(); + bt_io_iidx_ep1_send(); + bt_io_iidx_ep2_recv(); Sleep(10); } @@ -191,59 +175,59 @@ void iidx_io_fini(void) aciodrv_device_close(bio2_device_ctx); } -void iidx_io_ep1_set_deck_lights(uint16_t deck_lights) +void bt_io_iidx_ep1_deck_lights_set(uint16_t deck_lights) { for (uint8_t i = 0; i < sizeof(pout_staging.DECKSW); i++) { pout_staging.DECKSW[i].l_state = (deck_lights & (1 << i)) > 0; } } -void iidx_io_ep1_set_panel_lights(uint8_t panel_lights) +void bt_io_iidx_ep1_panel_lights_set(uint8_t panel_lights) { pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_START_P1].l_state = - (panel_lights & (1 << IIDX_IO_PANEL_P1_START)) > 0; + (panel_lights & (1 << BT_IO_IIDX_PANEL_P1_START)) > 0; pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_START_P2].l_state = - (panel_lights & (1 << IIDX_IO_PANEL_P2_START)) > 0; + (panel_lights & (1 << BT_IO_IIDX_PANEL_P2_START)) > 0; pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_VEFX].l_state = - (panel_lights & (1 << IIDX_IO_PANEL_VEFX)) > 0; + (panel_lights & (1 << BT_IO_IIDX_PANEL_VEFX)) > 0; pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_EFFECT].l_state = - (panel_lights & (1 << IIDX_IO_PANEL_EFFECT)) > 0; + (panel_lights & (1 << BT_IO_IIDX_PANEL_EFFECT)) > 0; } -void iidx_io_ep1_set_top_lamps(uint8_t top_lamps) +void bt_io_iidx_ep1_top_lamps_set(uint8_t top_lamps) { pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_RED].l_state = - (top_lamps & (1 << IIDX_IO_TOP_LAMP_RIGHT_RED)) > 0; + (top_lamps & (1 << BT_IO_IIDX_TOP_LAMP_RIGHT_RED)) > 0; pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_YELLOW].l_state = - (top_lamps & (1 << IIDX_IO_TOP_LAMP_RIGHT_YELLOW)) > 0; + (top_lamps & (1 << BT_IO_IIDX_TOP_LAMP_RIGHT_YELLOW)) > 0; pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_GREEN].l_state = - (top_lamps & (1 << IIDX_IO_TOP_LAMP_RIGHT_GREEN)) > 0; + (top_lamps & (1 << BT_IO_IIDX_TOP_LAMP_RIGHT_GREEN)) > 0; pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_BLUE].l_state = - (top_lamps & (1 << IIDX_IO_TOP_LAMP_RIGHT_BLUE)) > 0; + (top_lamps & (1 << BT_IO_IIDX_TOP_LAMP_RIGHT_BLUE)) > 0; pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_RED].l_state = - (top_lamps & (1 << IIDX_IO_TOP_LAMP_LEFT_RED)) > 0; + (top_lamps & (1 << BT_IO_IIDX_TOP_LAMP_LEFT_RED)) > 0; pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_YELLOW].l_state = - (top_lamps & (1 << IIDX_IO_TOP_LAMP_LEFT_YELLOW)) > 0; + (top_lamps & (1 << BT_IO_IIDX_TOP_LAMP_LEFT_YELLOW)) > 0; pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_GREEN].l_state = - (top_lamps & (1 << IIDX_IO_TOP_LAMP_LEFT_GREEN)) > 0; + (top_lamps & (1 << BT_IO_IIDX_TOP_LAMP_LEFT_GREEN)) > 0; pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_BLUE].l_state = - (top_lamps & (1 << IIDX_IO_TOP_LAMP_LEFT_BLUE)) > 0; + (top_lamps & (1 << BT_IO_IIDX_TOP_LAMP_LEFT_BLUE)) > 0; } -void iidx_io_ep1_set_top_neons(bool top_neons) +void bt_io_iidx_ep1_top_neons_set(bool top_neons) { pout_staging.NEONLAMP.l_state = top_neons; } -bool iidx_io_ep1_send(void) +bool bt_io_iidx_ep1_send(void) { memcpy(&pout_ready, &pout_staging, sizeof(struct bi2a_iidx_state_out)); return true; } -bool iidx_io_ep2_recv(void) +bool bt_io_iidx_ep2_recv(void) { if (!_bio2_iidx_io_poll(&pout_ready, &pin_cur)) { return false; @@ -252,7 +236,7 @@ bool iidx_io_ep2_recv(void) return true; } -uint8_t iidx_io_ep2_get_turntable(uint8_t player_no) +uint8_t bt_io_iidx_ep2_turntable_get(uint8_t player_no) { switch (player_no) { case 0: @@ -264,7 +248,7 @@ uint8_t iidx_io_ep2_get_turntable(uint8_t player_no) } } -uint8_t iidx_io_ep2_get_slider(uint8_t slider_no) +uint8_t bt_io_iidx_ep2_slider_get(uint8_t slider_no) { switch (slider_no) { case 0: @@ -282,80 +266,110 @@ uint8_t iidx_io_ep2_get_slider(uint8_t slider_no) } } -uint8_t iidx_io_ep2_get_sys(void) +uint8_t bt_io_iidx_ep2_sys_get(void) { uint8_t state; state = 0; if (pin_cur.SYSTEM.v_test) { - state |= (1 << IIDX_IO_SYS_TEST); + state |= (1 << BT_IO_IIDX_SYS_TEST); } if (pin_cur.SYSTEM.v_service) { - state |= (1 << IIDX_IO_SYS_SERVICE); + state |= (1 << BT_IO_IIDX_SYS_SERVICE); } if (pin_cur.SYSTEM.v_coin) { - state |= (1 << IIDX_IO_SYS_COIN); + state |= (1 << BT_IO_IIDX_SYS_COIN); } return state; } -uint8_t iidx_io_ep2_get_panel(void) +uint8_t bt_io_iidx_ep2_panel_get(void) { uint8_t state; state = 0; if (pin_cur.PANEL.y_start1) { - state |= (1 << IIDX_IO_PANEL_P1_START); + state |= (1 << BT_IO_IIDX_PANEL_P1_START); } if (pin_cur.PANEL.y_start2) { - state |= (1 << IIDX_IO_PANEL_P2_START); + state |= (1 << BT_IO_IIDX_PANEL_P2_START); } if (pin_cur.PANEL.y_vefx) { - state |= (1 << IIDX_IO_PANEL_VEFX); + state |= (1 << BT_IO_IIDX_PANEL_VEFX); } if (pin_cur.PANEL.y_effect) { - state |= (1 << IIDX_IO_PANEL_EFFECT); + state |= (1 << BT_IO_IIDX_PANEL_EFFECT); } return state; } -uint16_t iidx_io_ep2_get_keys(void) +uint16_t bt_io_iidx_ep2_keys_get(void) { uint16_t state; state = 0; - state |= ((pin_cur.P1SW1.b_val > 0) << IIDX_IO_KEY_P1_1); - state |= ((pin_cur.P1SW2.b_val > 0) << IIDX_IO_KEY_P1_2); - state |= ((pin_cur.P1SW3.b_val > 0) << IIDX_IO_KEY_P1_3); - state |= ((pin_cur.P1SW4.b_val > 0) << IIDX_IO_KEY_P1_4); - state |= ((pin_cur.P1SW5.b_val > 0) << IIDX_IO_KEY_P1_5); - state |= ((pin_cur.P1SW6.b_val > 0) << IIDX_IO_KEY_P1_6); - state |= ((pin_cur.P1SW7.b_val > 0) << IIDX_IO_KEY_P1_7); + state |= ((pin_cur.P1SW1.b_val > 0) << BT_IO_IIDX_KEY_P1_1); + state |= ((pin_cur.P1SW2.b_val > 0) << BT_IO_IIDX_KEY_P1_2); + state |= ((pin_cur.P1SW3.b_val > 0) << BT_IO_IIDX_KEY_P1_3); + state |= ((pin_cur.P1SW4.b_val > 0) << BT_IO_IIDX_KEY_P1_4); + state |= ((pin_cur.P1SW5.b_val > 0) << BT_IO_IIDX_KEY_P1_5); + state |= ((pin_cur.P1SW6.b_val > 0) << BT_IO_IIDX_KEY_P1_6); + state |= ((pin_cur.P1SW7.b_val > 0) << BT_IO_IIDX_KEY_P1_7); - state |= ((pin_cur.P2SW1.b_val > 0) << IIDX_IO_KEY_P2_1); - state |= ((pin_cur.P2SW2.b_val > 0) << IIDX_IO_KEY_P2_2); - state |= ((pin_cur.P2SW3.b_val > 0) << IIDX_IO_KEY_P2_3); - state |= ((pin_cur.P2SW4.b_val > 0) << IIDX_IO_KEY_P2_4); - state |= ((pin_cur.P2SW5.b_val > 0) << IIDX_IO_KEY_P2_5); - state |= ((pin_cur.P2SW6.b_val > 0) << IIDX_IO_KEY_P2_6); - state |= ((pin_cur.P2SW7.b_val > 0) << IIDX_IO_KEY_P2_7); + state |= ((pin_cur.P2SW1.b_val > 0) << BT_IO_IIDX_KEY_P2_1); + state |= ((pin_cur.P2SW2.b_val > 0) << BT_IO_IIDX_KEY_P2_2); + state |= ((pin_cur.P2SW3.b_val > 0) << BT_IO_IIDX_KEY_P2_3); + state |= ((pin_cur.P2SW4.b_val > 0) << BT_IO_IIDX_KEY_P2_4); + state |= ((pin_cur.P2SW5.b_val > 0) << BT_IO_IIDX_KEY_P2_5); + state |= ((pin_cur.P2SW6.b_val > 0) << BT_IO_IIDX_KEY_P2_6); + state |= ((pin_cur.P2SW7.b_val > 0) << BT_IO_IIDX_KEY_P2_7); return state; } -bool iidx_io_ep3_write_16seg(const char *text) +bool bt_io_iidx_ep3_16seg_send(const char *text) { memcpy(pout_staging.SEG16, text, sizeof(pout_staging.SEG16)); return true; } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_io_iidx_api_get(bt_io_iidx_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_iidx_init; + api->v1.fini = bt_io_iidx_fini; + api->v1.ep1_deck_lights_set = bt_io_iidx_ep1_deck_lights_set; + api->v1.ep1_panel_lights_set = bt_io_iidx_ep1_panel_lights_set; + api->v1.ep1_top_lamps_set = bt_io_iidx_ep1_top_lamps_set; + api->v1.ep1_top_neons_set = bt_io_iidx_ep1_top_neons_set; + api->v1.ep1_send = bt_io_iidx_ep1_send; + api->v1.ep2_recv = bt_io_iidx_ep2_recv; + api->v1.ep2_turntable_get = bt_io_iidx_ep2_turntable_get; + api->v1.ep2_slider_get = bt_io_iidx_ep2_slider_get; + api->v1.ep2_sys_get = bt_io_iidx_ep2_sys_get; + api->v1.ep2_panel_get = bt_io_iidx_ep2_panel_get; + api->v1.ep2_keys_get = bt_io_iidx_ep2_keys_get; + api->v1.ep3_16seg_send = bt_io_iidx_ep3_16seg_send; +} diff --git a/src/main/iidxio-ezusb/Module.mk b/src/main/iidxio-ezusb/Module.mk index cc64914..7f69a14 100644 --- a/src/main/iidxio-ezusb/Module.mk +++ b/src/main/iidxio-ezusb/Module.mk @@ -10,6 +10,10 @@ libs_iidxio-ezusb := \ ezusb2 \ ezusb-iidx \ util \ + iface \ + module \ + iface-io \ + iface-core \ src_iidxio-ezusb := \ iidxio.c \ diff --git a/src/main/iidxio-ezusb/iidxio-ezusb.def b/src/main/iidxio-ezusb/iidxio-ezusb.def index 403900d..848c574 100644 --- a/src/main/iidxio-ezusb/iidxio-ezusb.def +++ b/src/main/iidxio-ezusb/iidxio-ezusb.def @@ -1,18 +1,23 @@ LIBRARY iidxio EXPORTS - iidx_io_ep1_send - iidx_io_ep1_set_deck_lights - iidx_io_ep1_set_panel_lights - iidx_io_ep1_set_top_lamps - iidx_io_ep1_set_top_neons - iidx_io_ep2_get_keys - iidx_io_ep2_get_panel - iidx_io_ep2_get_sys - iidx_io_ep2_get_slider - iidx_io_ep2_get_turntable - iidx_io_ep2_recv - iidx_io_ep3_write_16seg - iidx_io_fini - iidx_io_init - iidx_io_set_loggers + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_io_iidx_api_get + + ; Direct API + bt_io_iidx_init + bt_io_iidx_fini + bt_io_iidx_ep1_deck_lights_set + bt_io_iidx_ep1_panel_lights_set + bt_io_iidx_ep1_top_lamps_set + bt_io_iidx_ep1_top_neons_set + bt_io_iidx_ep1_send + bt_io_iidx_ep2_recv + bt_io_iidx_ep2_turntable_get + bt_io_iidx_ep2_slider_get + bt_io_iidx_ep2_sys_get + bt_io_iidx_ep2_panel_get + bt_io_iidx_ep2_keys_get + bt_io_iidx_ep3_16seg_send diff --git a/src/main/iidxio-ezusb/iidxio.c b/src/main/iidxio-ezusb/iidxio.c index a6a2059..e1e9195 100644 --- a/src/main/iidxio-ezusb/iidxio.c +++ b/src/main/iidxio-ezusb/iidxio.c @@ -1,3 +1,5 @@ +#define LOG_MODULE "iidxio-ezusb" + // clang-format off // Don't format because the order is important here #include @@ -8,7 +10,8 @@ #include #include -#include "bemanitools/iidxio.h" +#include "api/core/log.h" +#include "api/core/thread.h" #include "ezusb/ezusb.h" #include "ezusb/ezusbsys2.h" @@ -17,41 +20,26 @@ #include "ezusb-iidx/fpga.h" #include "ezusb-iidx/seg16-cmd.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/io/iidx.h" + #include "util/fs.h" #include "util/time.h" -#define log_misc(...) iidx_io_log_misc("iidxio-ezusb", __VA_ARGS__) -#define log_info(...) iidx_io_log_info("iidxio-ezusb", __VA_ARGS__) -#define log_warning(...) iidx_io_log_warning("iidxio-ezusb", __VA_ARGS__) -#define log_fatal(...) iidx_io_log_fatal("iidxio-ezusb", __VA_ARGS__) - -static log_formatter_t iidx_io_log_misc; -static log_formatter_t iidx_io_log_info; -static log_formatter_t iidx_io_log_warning; -static log_formatter_t iidx_io_log_fatal; - static HANDLE iidx_io_ezusb_handle; static struct ezusb_iidx_msg_interrupt_read_packet iidx_io_ezusb_read_packet; static struct ezusb_iidx_msg_interrupt_write_packet iidx_io_ezusb_write_packet; static bool iidxio_io_ezusb_16seg_rts; -void iidx_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - iidx_io_log_misc = misc; - iidx_io_log_info = info; - iidx_io_log_warning = warning; - iidx_io_log_fatal = fatal; -} +bool bt_io_iidx_ep1_send(void); +bool bt_io_iidx_ep2_recv(void); -bool iidx_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_iidx_init() { struct ezusb_ident ident; @@ -81,20 +69,20 @@ bool iidx_io_init( // Random data returned by device, likely not properly initalized on device // side Triggers random inputs and lights Flush that by execute a few polls for (int i = 0; i < 10; i++) { - iidx_io_ep2_recv(); + bt_io_iidx_ep2_recv(); } return true; } -void iidx_io_fini(void) +void bt_io_iidx_fini(void) { // Pushing some final state before closing the IO to the actual outputs, // e.g. lights on/off can be a bit finicky. Do a few polls to // "enforce"/flush this final state for (uint8_t i = 0; i < 5; i++) { - iidx_io_ep1_send(); - iidx_io_ep2_recv(); + bt_io_iidx_ep1_send(); + bt_io_iidx_ep2_recv(); Sleep(10); } @@ -107,27 +95,27 @@ void iidx_io_fini(void) the neons bit into an unused start btns light. The entire 32-bit word is then sent to geninput for output light mapping. */ -void iidx_io_ep1_set_deck_lights(uint16_t deck_lights) +void bt_io_iidx_ep1_deck_lights_set(uint16_t deck_lights) { iidx_io_ezusb_write_packet.deck_lights = deck_lights; } -void iidx_io_ep1_set_panel_lights(uint8_t panel_lights) +void bt_io_iidx_ep1_panel_lights_set(uint8_t panel_lights) { iidx_io_ezusb_write_packet.panel_lights = panel_lights; } -void iidx_io_ep1_set_top_lamps(uint8_t top_lamps) +void bt_io_iidx_ep1_top_lamps_set(uint8_t top_lamps) { iidx_io_ezusb_write_packet.top_lamps = top_lamps; } -void iidx_io_ep1_set_top_neons(bool top_neons) +void bt_io_iidx_ep1_top_neons_set(bool top_neons) { iidx_io_ezusb_write_packet.top_neons = top_neons ? 1 : 0; } -bool iidx_io_ep1_send(void) +bool bt_io_iidx_ep1_send(void) { BULK_TRANSFER_CONTROL transfer; uint32_t outpkt; @@ -154,7 +142,7 @@ bool iidx_io_ep1_send(void) } } -bool iidx_io_ep2_recv(void) +bool bt_io_iidx_ep2_recv(void) { if (!ezusb_iidx_interrupt_read( iidx_io_ezusb_handle, &iidx_io_ezusb_read_packet)) { @@ -177,7 +165,7 @@ bool iidx_io_ep2_recv(void) return true; } -uint8_t iidx_io_ep2_get_turntable(uint8_t player_no) +uint8_t bt_io_iidx_ep2_turntable_get(uint8_t player_no) { switch (player_no) { case 0: @@ -189,7 +177,7 @@ uint8_t iidx_io_ep2_get_turntable(uint8_t player_no) } } -uint8_t iidx_io_ep2_get_slider(uint8_t slider_no) +uint8_t bt_io_iidx_ep2_slider_get(uint8_t slider_no) { switch (slider_no) { case 0: @@ -207,23 +195,23 @@ uint8_t iidx_io_ep2_get_slider(uint8_t slider_no) } } -uint8_t iidx_io_ep2_get_sys(void) +uint8_t bt_io_iidx_ep2_sys_get(void) { return (((~iidx_io_ezusb_read_packet.inverted_pad) >> 28) & 0x03) | ((((~iidx_io_ezusb_read_packet.inverted_pad) >> 22) & 0x01) << 2); } -uint8_t iidx_io_ep2_get_panel(void) +uint8_t bt_io_iidx_ep2_panel_get(void) { return ((~iidx_io_ezusb_read_packet.inverted_pad) >> 24) & 0x0F; } -uint16_t iidx_io_ep2_get_keys(void) +uint16_t bt_io_iidx_ep2_keys_get(void) { return ((~iidx_io_ezusb_read_packet.inverted_pad) >> 8) & 0x3FFF; } -bool iidx_io_ep3_write_16seg(const char *text) +bool bt_io_iidx_ep3_16seg_send(const char *text) { struct ezusb_iidx_msg_bulk_packet pkg; @@ -245,3 +233,33 @@ bool iidx_io_ep3_write_16seg(const char *text) return true; } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_io_iidx_api_get(bt_io_iidx_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_iidx_init; + api->v1.fini = bt_io_iidx_fini; + api->v1.ep1_deck_lights_set = bt_io_iidx_ep1_deck_lights_set; + api->v1.ep1_panel_lights_set = bt_io_iidx_ep1_panel_lights_set; + api->v1.ep1_top_lamps_set = bt_io_iidx_ep1_top_lamps_set; + api->v1.ep1_top_neons_set = bt_io_iidx_ep1_top_neons_set; + api->v1.ep1_send = bt_io_iidx_ep1_send; + api->v1.ep2_recv = bt_io_iidx_ep2_recv; + api->v1.ep2_turntable_get = bt_io_iidx_ep2_turntable_get; + api->v1.ep2_slider_get = bt_io_iidx_ep2_slider_get; + api->v1.ep2_sys_get = bt_io_iidx_ep2_sys_get; + api->v1.ep2_panel_get = bt_io_iidx_ep2_panel_get; + api->v1.ep2_keys_get = bt_io_iidx_ep2_keys_get; + api->v1.ep3_16seg_send = bt_io_iidx_ep3_16seg_send; +} diff --git a/src/main/iidxio-ezusb2/Module.mk b/src/main/iidxio-ezusb2/Module.mk index 3371a78..15c79e8 100644 --- a/src/main/iidxio-ezusb2/Module.mk +++ b/src/main/iidxio-ezusb2/Module.mk @@ -10,6 +10,10 @@ libs_iidxio-ezusb2 := \ ezusb \ ezusb2-iidx \ util \ + iface \ + module \ + iface-io \ + iface-core \ src_iidxio-ezusb2 := \ iidxio.c \ diff --git a/src/main/iidxio-ezusb2/iidxio-ezusb2.def b/src/main/iidxio-ezusb2/iidxio-ezusb2.def index 403900d..848c574 100644 --- a/src/main/iidxio-ezusb2/iidxio-ezusb2.def +++ b/src/main/iidxio-ezusb2/iidxio-ezusb2.def @@ -1,18 +1,23 @@ LIBRARY iidxio EXPORTS - iidx_io_ep1_send - iidx_io_ep1_set_deck_lights - iidx_io_ep1_set_panel_lights - iidx_io_ep1_set_top_lamps - iidx_io_ep1_set_top_neons - iidx_io_ep2_get_keys - iidx_io_ep2_get_panel - iidx_io_ep2_get_sys - iidx_io_ep2_get_slider - iidx_io_ep2_get_turntable - iidx_io_ep2_recv - iidx_io_ep3_write_16seg - iidx_io_fini - iidx_io_init - iidx_io_set_loggers + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_io_iidx_api_get + + ; Direct API + bt_io_iidx_init + bt_io_iidx_fini + bt_io_iidx_ep1_deck_lights_set + bt_io_iidx_ep1_panel_lights_set + bt_io_iidx_ep1_top_lamps_set + bt_io_iidx_ep1_top_neons_set + bt_io_iidx_ep1_send + bt_io_iidx_ep2_recv + bt_io_iidx_ep2_turntable_get + bt_io_iidx_ep2_slider_get + bt_io_iidx_ep2_sys_get + bt_io_iidx_ep2_panel_get + bt_io_iidx_ep2_keys_get + bt_io_iidx_ep3_16seg_send diff --git a/src/main/iidxio-ezusb2/iidxio.c b/src/main/iidxio-ezusb2/iidxio.c index e629272..a2ff729 100644 --- a/src/main/iidxio-ezusb2/iidxio.c +++ b/src/main/iidxio-ezusb2/iidxio.c @@ -1,51 +1,36 @@ +#define LOG_MODULE "iidxio-ezusb2" + #include #include #include -#include "bemanitools/iidxio.h" +#include "api/core/log.h" +#include "api/core/thread.h" #include "ezusb/util.h" #include "ezusb2/ezusb2.h" #include "ezusb2-iidx/ezusb2-iidx.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/io/iidx.h" + #include "util/fs.h" #include "util/time.h" #define EZUSB2_FIND_TIMEOUT_MS 10000 -#define log_misc(...) iidx_io_log_misc("iidxio-ezusb2", __VA_ARGS__) -#define log_info(...) iidx_io_log_info("iidxio-ezusb2", __VA_ARGS__) -#define log_warning(...) iidx_io_log_warning("iidxio-ezusb2", __VA_ARGS__) -#define log_fatal(...) iidx_io_log_fatal("iidxio-ezusb2", __VA_ARGS__) - -static log_formatter_t iidx_io_log_misc; -static log_formatter_t iidx_io_log_info; -static log_formatter_t iidx_io_log_warning; -static log_formatter_t iidx_io_log_fatal; - static HANDLE iidx_io_ezusb2_handle; static struct ezusb2_iidx_msg_interrupt_read_packet iidx_io_ezusb2_read_packet; static struct ezusb2_iidx_msg_interrupt_write_packet iidx_io_ezusb2_write_packet; -void iidx_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - iidx_io_log_misc = misc; - iidx_io_log_info = info; - iidx_io_log_warning = warning; - iidx_io_log_fatal = fatal; -} - -bool iidx_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_iidx_init() { struct ezusb_ident ident; char *device_path; @@ -100,37 +85,33 @@ bool iidx_io_init( } } -void iidx_io_fini(void) +void bt_io_iidx_fini(void) { ezusb2_close(iidx_io_ezusb2_handle); iidx_io_ezusb2_handle = INVALID_HANDLE_VALUE; } -/* Total number of light bits is 33. That's slightly annoying. So, we pack - the neons bit into an unused start btns light. The entire 32-bit word is - then sent to geninput for output light mapping. */ - -void iidx_io_ep1_set_deck_lights(uint16_t deck_lights) +void bt_io_iidx_ep1_deck_lights_set(uint16_t deck_lights) { iidx_io_ezusb2_write_packet.deck_lights = deck_lights; } -void iidx_io_ep1_set_panel_lights(uint8_t panel_lights) +void bt_io_iidx_ep1_panel_lights_set(uint8_t panel_lights) { iidx_io_ezusb2_write_packet.panel_lights = panel_lights; } -void iidx_io_ep1_set_top_lamps(uint8_t top_lamps) +void bt_io_iidx_ep1_top_lamps_set(uint8_t top_lamps) { iidx_io_ezusb2_write_packet.top_lamps = top_lamps; } -void iidx_io_ep1_set_top_neons(bool top_neons) +void bt_io_iidx_ep1_top_neons_set(bool top_neons) { iidx_io_ezusb2_write_packet.top_neons = top_neons ? 1 : 0; } -bool iidx_io_ep1_send(void) +bool bt_io_iidx_ep1_send(void) { if (!ezusb2_iidx_interrupt_write( iidx_io_ezusb2_handle, &iidx_io_ezusb2_write_packet)) { @@ -141,7 +122,7 @@ bool iidx_io_ep1_send(void) } } -bool iidx_io_ep2_recv(void) +bool bt_io_iidx_ep2_recv(void) { if (!ezusb2_iidx_interrupt_read( iidx_io_ezusb2_handle, &iidx_io_ezusb2_read_packet)) { @@ -152,7 +133,7 @@ bool iidx_io_ep2_recv(void) } } -uint8_t iidx_io_ep2_get_turntable(uint8_t player_no) +uint8_t bt_io_iidx_ep2_turntable_get(uint8_t player_no) { switch (player_no) { case 0: @@ -164,7 +145,7 @@ uint8_t iidx_io_ep2_get_turntable(uint8_t player_no) } } -uint8_t iidx_io_ep2_get_slider(uint8_t slider_no) +uint8_t bt_io_iidx_ep2_slider_get(uint8_t slider_no) { switch (slider_no) { case 0: @@ -182,25 +163,55 @@ uint8_t iidx_io_ep2_get_slider(uint8_t slider_no) } } -uint8_t iidx_io_ep2_get_sys(void) +uint8_t bt_io_iidx_ep2_sys_get(void) { return (((~iidx_io_ezusb2_read_packet.inverted_pad) >> 4) & 0x03) | ((((~iidx_io_ezusb2_read_packet.inverted_pad) >> 30) & 1) << 2); } -uint8_t iidx_io_ep2_get_panel(void) +uint8_t bt_io_iidx_ep2_panel_get(void) { return ((~iidx_io_ezusb2_read_packet.inverted_pad) >> 0) & 0x0F; } -uint16_t iidx_io_ep2_get_keys(void) +uint16_t bt_io_iidx_ep2_keys_get(void) { return ((~iidx_io_ezusb2_read_packet.inverted_pad) >> 16) & 0x3FFF; } -bool iidx_io_ep3_write_16seg(const char *text) +bool bt_io_iidx_ep3_16seg_send(const char *text) { /* 16seg writing to device done in ep2 */ memcpy(iidx_io_ezusb2_write_packet.seg16, text, 9); return true; } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_io_iidx_api_get(bt_io_iidx_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_iidx_init; + api->v1.fini = bt_io_iidx_fini; + api->v1.ep1_deck_lights_set = bt_io_iidx_ep1_deck_lights_set; + api->v1.ep1_panel_lights_set = bt_io_iidx_ep1_panel_lights_set; + api->v1.ep1_top_lamps_set = bt_io_iidx_ep1_top_lamps_set; + api->v1.ep1_top_neons_set = bt_io_iidx_ep1_top_neons_set; + api->v1.ep1_send = bt_io_iidx_ep1_send; + api->v1.ep2_recv = bt_io_iidx_ep2_recv; + api->v1.ep2_turntable_get = bt_io_iidx_ep2_turntable_get; + api->v1.ep2_slider_get = bt_io_iidx_ep2_slider_get; + api->v1.ep2_sys_get = bt_io_iidx_ep2_sys_get; + api->v1.ep2_panel_get = bt_io_iidx_ep2_panel_get; + api->v1.ep2_keys_get = bt_io_iidx_ep2_keys_get; + api->v1.ep3_16seg_send = bt_io_iidx_ep3_16seg_send; +} diff --git a/src/main/iidxio/Module.mk b/src/main/iidxio/Module.mk index 33aa7e2..8e66b14 100644 --- a/src/main/iidxio/Module.mk +++ b/src/main/iidxio/Module.mk @@ -4,8 +4,11 @@ ldflags_iidxio := \ -lwinmm libs_iidxio := \ - geninput \ - vefxio \ + iface \ + module \ + iface-io \ + iface-core \ + util \ src_iidxio := \ iidxio.c \ diff --git a/src/main/iidxio/iidxio.c b/src/main/iidxio/iidxio.c index 901c1ba..71bd11c 100644 --- a/src/main/iidxio/iidxio.c +++ b/src/main/iidxio/iidxio.c @@ -1,12 +1,4 @@ -/* This is the source code for the IIDXIO.DLL that ships with Bemanitools 5. - - If you want to add on some minor functionality like a custom 16seg display - or a customer slider board then see vefxio. - - If you want to make a completely custom IO board that handles all input and - lighting then you'd be better off writing your own from scratch. Consult - the "bemanitools" header files included by this source file for detailed - information about the API you'll need to implement. */ +#define LOG_MODULE "iidxio" // clang-format off // Don't format because the order is important here @@ -17,9 +9,23 @@ #include #include -#include "bemanitools/iidxio.h" -#include "bemanitools/input.h" -#include "bemanitools/vefxio.h" +#include "api/core/log.h" +#include "api/core/thread.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface-io/vefx.h" +#include "iface/input.h" + +#include "main/module/input-ext.h" +#include "main/module/input.h" +#include "main/module/io-ext.h" +#include "main/module/io.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/input.h" +#include "sdk/module/io/iidx.h" #define MSEC_PER_NOTCH 8 @@ -92,126 +98,114 @@ static const struct iidx_io_tt_inputs iidx_io_tt_inputs[2] = { IIDX_IO_P2_START}, }; +static module_input_t *_iidx_io_module_input; +static module_io_t *_iidx_io_module_vefx; + static struct iidx_io_tt iidx_io_tt[2]; static uint8_t iidx_io_sys; static uint8_t iidx_io_panel; static uint16_t iidx_io_keys; -/* Uncomment these if you need them. */ - -#if 0 -static log_formatter_t iidx_io_log_misc; -static log_formatter_t iidx_io_log_info; -static log_formatter_t iidx_io_log_warning; -static log_formatter_t iidx_io_log_fatal; -#endif - -void iidx_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) +static void _bt_io_iidx_module_input_init(module_input_t **module) { - /* Pass logger functions on to geninput so that it has somewhere to write - its own log output. */ + bt_input_api_t api; - input_set_loggers(misc, info, warning, fatal); - - /* Pass logger functions on to vefx_io so that it has somewhere to write - its own log output. */ - - vefx_io_set_loggers(misc, info, warning, fatal); - - /* Uncomment this block if you have something you'd like to log. - - You should probably return false from the appropriate function instead - of calling the fatal logger yourself though. */ - -#if 0 - iidx_io_log_misc = misc; - iidx_io_log_info = info; - iidx_io_log_warning = warning; - iidx_io_log_fatal = fatal; -#endif + module_input_ext_load_and_init("geninput.dll", module); + module_input_api_get(*module, &api); + bt_input_api_set(&api); } -bool iidx_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +static void _bt_io_iidx_module_vefx_init(module_io_t **module) { - vefx_io_init(thread_create, thread_join, thread_destroy); + bt_io_vefx_api_t api; + + module_io_ext_load_and_init( + "vefxio.dll", "bt_module_io_vefx_api_get", module); + module_io_api_get(*module, &api); + bt_io_vefx_api_set(&api); +} + +bool bt_io_iidx_init() +{ + bool result; + + _bt_io_iidx_module_input_init(&_iidx_io_module_input); + _bt_io_iidx_module_vefx_init(&_iidx_io_module_vefx); + + result = bt_io_vefx_init(); + + if (!result) { + log_warning("Initializing vefx failed"); + return false; + } + timeBeginPeriod(1); - input_init(thread_create, thread_join, thread_destroy); - mapper_config_load("iidx"); + result = bt_input_init(); + + if (!result) { + log_warning("Initializing input failed"); + return false; + } iidx_io_tt[0].stab_dir = +1; iidx_io_tt[1].stab_dir = +1; - /* Initialize your own IO devices here. Log something and then return - false if the initialization fails. */ - - return true; + return bt_input_mapper_config_load("iidx"); } -void iidx_io_fini(void) +void bt_io_iidx_fini(void) { - /* This function gets called as IIDX shuts down after an Alt-F4. Close your - connections to your IO devices here. */ + bt_input_fini(); + bt_input_api_clear(); + module_input_free(&_iidx_io_module_input); + + bt_io_vefx_fini(); + bt_io_vefx_api_clear(); + module_io_free(&_iidx_io_module_vefx); - input_fini(); - vefx_io_fini(); timeEndPeriod(1); } -/* Total number of light bits is 33. That's slightly annoying. So, we pack - the neons bit into an unused start btns light. The entire 32-bit word is - then sent to geninput for output light mapping. */ - -void iidx_io_ep1_set_deck_lights(uint16_t deck_lights) +void bt_io_iidx_ep1_deck_lights_set(uint16_t deck_lights) { uint8_t i; for (i = 0x00; i < 0x0E; i++) { - mapper_write_light(i, deck_lights & (1 << i) ? 255 : 0); + bt_input_mapper_light_write(i, deck_lights & (1 << i) ? 255 : 0); } } -void iidx_io_ep1_set_panel_lights(uint8_t panel_lights) +void bt_io_iidx_ep1_panel_lights_set(uint8_t panel_lights) { uint8_t i; for (i = 0x00; i < 0x04; i++) { - mapper_write_light(0x18 + i, panel_lights & (1 << i) ? 255 : 0); + bt_input_mapper_light_write( + 0x18 + i, panel_lights & (1 << i) ? 255 : 0); } } -void iidx_io_ep1_set_top_lamps(uint8_t top_lamps) +void bt_io_iidx_ep1_top_lamps_set(uint8_t top_lamps) { uint8_t i; for (i = 0x00; i < 0x08; i++) { - mapper_write_light(0x10 + i, top_lamps & (1 << i) ? 255 : 0); + bt_input_mapper_light_write(0x10 + i, top_lamps & (1 << i) ? 255 : 0); } } -void iidx_io_ep1_set_top_neons(bool top_neons) +void bt_io_iidx_ep1_top_neons_set(bool top_neons) { - mapper_write_light(0x1F, top_neons ? 255 : 0); + bt_input_mapper_light_write(0x1F, top_neons ? 255 : 0); } -bool iidx_io_ep1_send(void) +bool bt_io_iidx_ep1_send(void) { - /* The generic input stack currently initiates lighting sends and input - reads simultaneously, though this might change later. Perform all of our - I/O immediately before reading out the inputs so that the input state is - as fresh as possible. */ - return true; } -bool iidx_io_ep2_recv(void) +bool bt_io_iidx_ep2_recv(void) { uint32_t now; uint64_t pad; @@ -220,8 +214,8 @@ bool iidx_io_ep2_recv(void) /* Update all of our input state here. */ now = timeGetTime(); - pad = (uint64_t) mapper_update(); - vefx_io_recv(&pad); + pad = (uint64_t) bt_input_mapper_update(); + bt_io_vefx_recv(&pad); for (i = 0; i < 2; i++) { iidx_io_tt_update(now, pad, i); @@ -292,10 +286,10 @@ static void iidx_io_tt_update(uint32_t now, uint64_t pad, int i) /* Snapshot analog spinner state as well. */ - iidx_io_tt[i].analog_pos = mapper_read_analog(i); + iidx_io_tt[i].analog_pos = bt_input_mapper_analog_read(i); } -uint8_t iidx_io_ep2_get_turntable(uint8_t player_no) +uint8_t bt_io_iidx_ep2_turntable_get(uint8_t player_no) { if (player_no > 1) { return 0; @@ -304,27 +298,57 @@ uint8_t iidx_io_ep2_get_turntable(uint8_t player_no) return iidx_io_tt[player_no].pos + iidx_io_tt[player_no].analog_pos; } -uint8_t iidx_io_ep2_get_slider(uint8_t slider_no) +uint8_t bt_io_iidx_ep2_slider_get(uint8_t slider_no) { - return vefx_io_get_slider(slider_no); + return bt_io_vefx_slider_get(slider_no); } -uint8_t iidx_io_ep2_get_sys(void) +uint8_t bt_io_iidx_ep2_sys_get(void) { return iidx_io_sys; } -uint8_t iidx_io_ep2_get_panel(void) +uint8_t bt_io_iidx_ep2_panel_get(void) { return iidx_io_panel; } -uint16_t iidx_io_ep2_get_keys(void) +uint16_t bt_io_iidx_ep2_keys_get(void) { return iidx_io_keys; } -bool iidx_io_ep3_write_16seg(const char *text) +bool bt_io_iidx_ep3_16seg_send(const char *text) { - return vefx_io_write_16seg(text); + return bt_io_vefx_16seg_send(text); } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_io_iidx_api_get(bt_io_iidx_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_iidx_init; + api->v1.fini = bt_io_iidx_fini; + api->v1.ep1_deck_lights_set = bt_io_iidx_ep1_deck_lights_set; + api->v1.ep1_panel_lights_set = bt_io_iidx_ep1_panel_lights_set; + api->v1.ep1_top_lamps_set = bt_io_iidx_ep1_top_lamps_set; + api->v1.ep1_top_neons_set = bt_io_iidx_ep1_top_neons_set; + api->v1.ep1_send = bt_io_iidx_ep1_send; + api->v1.ep2_recv = bt_io_iidx_ep2_recv; + api->v1.ep2_turntable_get = bt_io_iidx_ep2_turntable_get; + api->v1.ep2_slider_get = bt_io_iidx_ep2_slider_get; + api->v1.ep2_sys_get = bt_io_iidx_ep2_sys_get; + api->v1.ep2_panel_get = bt_io_iidx_ep2_panel_get; + api->v1.ep2_keys_get = bt_io_iidx_ep2_keys_get; + api->v1.ep3_16seg_send = bt_io_iidx_ep3_16seg_send; +} \ No newline at end of file diff --git a/src/main/iidxio/iidxio.def b/src/main/iidxio/iidxio.def index 403900d..848c574 100644 --- a/src/main/iidxio/iidxio.def +++ b/src/main/iidxio/iidxio.def @@ -1,18 +1,23 @@ LIBRARY iidxio EXPORTS - iidx_io_ep1_send - iidx_io_ep1_set_deck_lights - iidx_io_ep1_set_panel_lights - iidx_io_ep1_set_top_lamps - iidx_io_ep1_set_top_neons - iidx_io_ep2_get_keys - iidx_io_ep2_get_panel - iidx_io_ep2_get_sys - iidx_io_ep2_get_slider - iidx_io_ep2_get_turntable - iidx_io_ep2_recv - iidx_io_ep3_write_16seg - iidx_io_fini - iidx_io_init - iidx_io_set_loggers + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_io_iidx_api_get + + ; Direct API + bt_io_iidx_init + bt_io_iidx_fini + bt_io_iidx_ep1_deck_lights_set + bt_io_iidx_ep1_panel_lights_set + bt_io_iidx_ep1_top_lamps_set + bt_io_iidx_ep1_top_neons_set + bt_io_iidx_ep1_send + bt_io_iidx_ep2_recv + bt_io_iidx_ep2_turntable_get + bt_io_iidx_ep2_slider_get + bt_io_iidx_ep2_sys_get + bt_io_iidx_ep2_panel_get + bt_io_iidx_ep2_keys_get + bt_io_iidx_ep3_16seg_send diff --git a/src/main/iidxiotest/Module.mk b/src/main/iidxiotest/Module.mk index 94eca38..74870e5 100644 --- a/src/main/iidxiotest/Module.mk +++ b/src/main/iidxiotest/Module.mk @@ -2,8 +2,10 @@ exes += iidxiotest \ libs_iidxiotest := \ core \ - iidxio \ util \ + module \ + iface-core \ + iface-io \ src_iidxiotest := \ main.c \ diff --git a/src/main/iidxiotest/main.c b/src/main/iidxiotest/main.c index a9b7daa..d37ddd6 100644 --- a/src/main/iidxiotest/main.c +++ b/src/main/iidxiotest/main.c @@ -1,18 +1,18 @@ +#include + #include #include #include #include -#include - -#include "bemanitools/iidxio.h" - #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" -#include "core/thread-crt.h" -#include "core/thread.h" +#include "core/log-sink-std.h" + +#include "iface-core/log.h" +#include "iface-io/iidx.h" + +#include "module/io-ext.h" static uint8_t _fix_top_lamps_order(uint8_t top_lamps) { @@ -20,63 +20,88 @@ static uint8_t _fix_top_lamps_order(uint8_t top_lamps) out = 0; - out |= ((1 << 0) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_LEFT_RED) : 0; - out |= ((1 << 1) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_LEFT_YELLOW) : 0; - out |= ((1 << 2) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_LEFT_GREEN) : 0; - out |= ((1 << 3) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_LEFT_BLUE) : 0; - - out |= ((1 << 4) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_BLUE) : 0; - out |= ((1 << 5) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_GREEN) : 0; + out |= ((1 << 0) & top_lamps) > 0 ? (1 << BT_IO_IIDX_TOP_LAMP_LEFT_RED) : 0; out |= - ((1 << 6) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_YELLOW) : 0; - out |= ((1 << 7) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_RED) : 0; + ((1 << 1) & top_lamps) > 0 ? (1 << BT_IO_IIDX_TOP_LAMP_LEFT_YELLOW) : 0; + out |= + ((1 << 2) & top_lamps) > 0 ? (1 << BT_IO_IIDX_TOP_LAMP_LEFT_GREEN) : 0; + out |= + ((1 << 3) & top_lamps) > 0 ? (1 << BT_IO_IIDX_TOP_LAMP_LEFT_BLUE) : 0; + + out |= + ((1 << 4) & top_lamps) > 0 ? (1 << BT_IO_IIDX_TOP_LAMP_RIGHT_BLUE) : 0; + out |= + ((1 << 5) & top_lamps) > 0 ? (1 << BT_IO_IIDX_TOP_LAMP_RIGHT_GREEN) : 0; + out |= ((1 << 6) & top_lamps) > 0 ? + (1 << BT_IO_IIDX_TOP_LAMP_RIGHT_YELLOW) : + 0; + out |= + ((1 << 7) & top_lamps) > 0 ? (1 << BT_IO_IIDX_TOP_LAMP_RIGHT_RED) : 0; return out; } static void _all_lights_off_shutdown() { - iidx_io_ep1_set_deck_lights(0); - iidx_io_ep1_set_panel_lights(0); - iidx_io_ep1_set_top_lamps(0); - iidx_io_ep1_set_top_neons(false); + bt_io_iidx_ep1_deck_lights_set(0); + bt_io_iidx_ep1_panel_lights_set(0); + bt_io_iidx_ep1_top_lamps_set(0); + bt_io_iidx_ep1_top_neons_set(false); // Depending on the IO, pushing the state to the actual outputs, e.g. lights // on/off can be a bit finicky. Do a few times to "enforce" the state for (uint8_t i = 0; i < 3; i++) { - iidx_io_ep1_send(); + bt_io_iidx_ep1_send(); // Required to handle iidxio-ezusb specific quirks with flushing 16seg // text - iidx_io_ep2_recv(); - iidx_io_ep3_write_16seg(" "); + bt_io_iidx_ep2_recv(); + bt_io_iidx_ep3_16seg_send(" "); Sleep(10); } } +static void _iidxiotest_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + /** * Tool to test your implementations of iidxio. */ int main(int argc, char **argv) { - core_thread_crt_ext_impl_set(); - core_log_bt_ext_impl_set(); + module_io_t *module_io_iidx; - core_log_bt_ext_init_with_stdout(); + core_log_bt_core_api_set(); - core_log_impl_assign(iidx_io_set_loggers); + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _iidxiotest_io_iidx_init(&module_io_iidx); + + if (!bt_io_iidx_init()) { printf("Initializing iidxio failed\n"); + + bt_io_iidx_api_clear(); + module_io_free(&module_io_iidx); + return -1; } printf(">>> Initializing iidxio successful, press enter to continue <<<\n"); if (getchar() != '\n') { + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&module_io_iidx); + return 0; } @@ -98,19 +123,25 @@ int main(int argc, char **argv) uint8_t cnt = 0; bool all_on = false; while (loop) { - if (!iidx_io_ep2_recv()) { + if (!bt_io_iidx_ep2_recv()) { printf("ERROR: Receive ep2 failed\n"); + + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&module_io_iidx); + return -2; } /* get inputs */ - input_sys = iidx_io_ep2_get_sys(); - input_panel = iidx_io_ep2_get_panel(); - input_keys = iidx_io_ep2_get_keys(); - turn_table[0] = iidx_io_ep2_get_turntable(0); - turn_table[1] = iidx_io_ep2_get_turntable(1); + input_sys = bt_io_iidx_ep2_sys_get(); + input_panel = bt_io_iidx_ep2_panel_get(); + input_keys = bt_io_iidx_ep2_keys_get(); + turn_table[0] = bt_io_iidx_ep2_turntable_get(0); + turn_table[1] = bt_io_iidx_ep2_turntable_get(1); for (uint8_t i = 0; i < 5; ++i) { - slider[i] = iidx_io_ep2_get_slider(i); + slider[i] = bt_io_iidx_ep2_slider_get(i); } system("cls"); @@ -155,38 +186,38 @@ int main(int argc, char **argv) text_16seg[6], text_16seg[7], text_16seg[8], - (input_panel >> IIDX_IO_PANEL_EFFECT) & 1, - (input_sys >> IIDX_IO_SYS_TEST) & 1, + (input_panel >> BT_IO_IIDX_PANEL_EFFECT) & 1, + (input_sys >> BT_IO_IIDX_SYS_TEST) & 1, - (input_panel >> IIDX_IO_PANEL_P1_START) & 1, + (input_panel >> BT_IO_IIDX_PANEL_P1_START) & 1, slider[0], slider[1], slider[2], slider[3], slider[4], - (input_panel >> IIDX_IO_PANEL_P2_START) & 1, + (input_panel >> BT_IO_IIDX_PANEL_P2_START) & 1, - (input_panel >> IIDX_IO_PANEL_VEFX) & 1, - (input_sys >> IIDX_IO_SYS_SERVICE) & 1, + (input_panel >> BT_IO_IIDX_PANEL_VEFX) & 1, + (input_sys >> BT_IO_IIDX_SYS_SERVICE) & 1, turn_table[0], - (input_keys >> IIDX_IO_KEY_P1_2) & 1, - (input_keys >> IIDX_IO_KEY_P1_4) & 1, - (input_keys >> IIDX_IO_KEY_P1_6) & 1, - (input_sys >> IIDX_IO_SYS_COIN), - (input_keys >> IIDX_IO_KEY_P2_2) & 1, - (input_keys >> IIDX_IO_KEY_P2_4) & 1, - (input_keys >> IIDX_IO_KEY_P2_6) & 1, + (input_keys >> BT_IO_IIDX_KEY_P1_2) & 1, + (input_keys >> BT_IO_IIDX_KEY_P1_4) & 1, + (input_keys >> BT_IO_IIDX_KEY_P1_6) & 1, + (input_sys >> BT_IO_IIDX_SYS_COIN), + (input_keys >> BT_IO_IIDX_KEY_P2_2) & 1, + (input_keys >> BT_IO_IIDX_KEY_P2_4) & 1, + (input_keys >> BT_IO_IIDX_KEY_P2_6) & 1, turn_table[1], - (input_keys >> IIDX_IO_KEY_P1_1) & 1, - (input_keys >> IIDX_IO_KEY_P1_3) & 1, - (input_keys >> IIDX_IO_KEY_P1_5) & 1, - (input_keys >> IIDX_IO_KEY_P1_7) & 1, + (input_keys >> BT_IO_IIDX_KEY_P1_1) & 1, + (input_keys >> BT_IO_IIDX_KEY_P1_3) & 1, + (input_keys >> BT_IO_IIDX_KEY_P1_5) & 1, + (input_keys >> BT_IO_IIDX_KEY_P1_7) & 1, - (input_keys >> IIDX_IO_KEY_P2_1) & 1, - (input_keys >> IIDX_IO_KEY_P2_3) & 1, - (input_keys >> IIDX_IO_KEY_P2_5) & 1, - (input_keys >> IIDX_IO_KEY_P2_7) & 1); + (input_keys >> BT_IO_IIDX_KEY_P2_1) & 1, + (input_keys >> BT_IO_IIDX_KEY_P2_3) & 1, + (input_keys >> BT_IO_IIDX_KEY_P2_5) & 1, + (input_keys >> BT_IO_IIDX_KEY_P2_7) & 1); /* set outputs */ if (all_on) { @@ -197,10 +228,10 @@ int main(int argc, char **argv) memset(text_16seg, '*', 9); } - iidx_io_ep1_set_deck_lights(deck_lights); - iidx_io_ep1_set_panel_lights(panel_lights); - iidx_io_ep1_set_top_lamps(_fix_top_lamps_order(top_lamps)); - iidx_io_ep1_set_top_neons(top_neons); + bt_io_iidx_ep1_deck_lights_set(deck_lights); + bt_io_iidx_ep1_panel_lights_set(panel_lights); + bt_io_iidx_ep1_top_lamps_set(_fix_top_lamps_order(top_lamps)); + bt_io_iidx_ep1_top_neons_set(top_neons); /* light up keys when pressed */ if (!all_on) { @@ -218,13 +249,25 @@ int main(int argc, char **argv) } } - if (!iidx_io_ep1_send()) { + if (!bt_io_iidx_ep1_send()) { printf("ERROR: Sending ep1 failed\n"); + + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&module_io_iidx); + return -4; } - if (!iidx_io_ep3_write_16seg(text_16seg)) { + if (!bt_io_iidx_ep3_16seg_send(text_16seg)) { printf("ERROR: Sending ep3 failed\n"); + + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&module_io_iidx); + return -3; } @@ -324,7 +367,10 @@ int main(int argc, char **argv) _all_lights_off_shutdown(); - iidx_io_fini(); + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&module_io_iidx); return 0; } \ No newline at end of file diff --git a/src/main/inject/Module.mk b/src/main/inject/Module.mk index 5fb93dc..4286960 100644 --- a/src/main/inject/Module.mk +++ b/src/main/inject/Module.mk @@ -10,6 +10,7 @@ libs_inject := \ core \ util \ dwarfstack \ + iface-core \ src_inject := \ main.c \ diff --git a/src/main/inject/debugger.c b/src/main/inject/debugger.c index 69f0a74..d9296bb 100644 --- a/src/main/inject/debugger.c +++ b/src/main/inject/debugger.c @@ -9,12 +9,12 @@ #include #include "core/log-bt.h" -#include "core/log.h" + +#include "iface-core/log.h" #include "inject/debugger.h" #include "util/debug.h" -#include "util/log.h" #include "util/mem.h" #include "util/proc.h" #include "util/str.h" @@ -226,6 +226,10 @@ static bool debugger_create_process( // didn't understand the documentation properly or it and various blog // posts I read are not explaining things well enough or are even wrong. flags |= DEBUG_PROCESS; + + log_info("Local debugger enabled"); + } else { + log_info("Local debugger disabled, no log output from remote process"); } log_misc("Creating remote process %s...", app_name); diff --git a/src/main/inject/main.c b/src/main/inject/main.c index da80a8b..9f73fb7 100644 --- a/src/main/inject/main.c +++ b/src/main/inject/main.c @@ -12,16 +12,17 @@ #include "cconfig/cconfig-util.h" #include "cconfig/cmd.h" +#include "core/boot.h" #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-file.h" #include "core/log-sink-list.h" #include "core/log-sink-mutex.h" #include "core/log-sink-std.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" #include "core/thread-crt.h" -#include "core/thread.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" #include "inject/debugger.h" #include "inject/options.h" @@ -29,7 +30,6 @@ #include "util/cmdline.h" #include "util/debug.h" -#include "util/log.h" #include "util/mem.h" #include "util/os.h" #include "util/signal.h" @@ -53,11 +53,9 @@ static void _inject_log_header() void _inject_log_init( const char *log_file_path, enum core_log_bt_log_level level) { - struct core_log_sink sinks[2]; - struct core_log_sink sink_composed; - struct core_log_sink sink_mutex; - - core_log_bt_ext_impl_set(); + core_log_sink_t sinks[2]; + core_log_sink_t sink_composed; + core_log_sink_t sink_mutex; if (log_file_path) { core_log_sink_std_out_open(true, &sinks[0]); @@ -69,9 +67,13 @@ void _inject_log_init( // Different threads logging the same destination, e.g. debugger thread, // main thread + // TODO this needs to be de-coupled with async logging to fix latency + // issues for any game related threads logging core_log_sink_mutex_open(&sink_composed, &sink_mutex); core_log_bt_init(&sink_mutex); + core_log_bt_core_api_set(); + core_log_bt_level_set(level); } @@ -209,22 +211,22 @@ int main(int argc, char **argv) char *cmd_line; bool local_debugger; + core_boot("inject"); + if (!init_options(argc, argv, &options)) { goto init_options_fail; } - core_thread_crt_ext_impl_set(); // TODO expose log level - _inject_log_init( strlen(options.log_file) > 0 ? options.log_file : NULL, CORE_LOG_BT_LOG_LEVEL_MISC); _inject_log_header(); - os_version_log(); - debug_init(); + core_thread_crt_core_api_set(); + signal_exception_handler_init(); // Cleanup remote process on CTRL+C signal_register_shutdown_handler(signal_shutdown_handler); @@ -287,7 +289,6 @@ verify_2_fail: verify_fail: core_log_bt_fini(); -init_logger_fail: init_options_fail: return EXIT_FAILURE; } diff --git a/src/main/jbhook-util-p3io/gfx.c b/src/main/jbhook-util-p3io/gfx.c index 0574b1f..4772eab 100644 --- a/src/main/jbhook-util-p3io/gfx.c +++ b/src/main/jbhook-util-p3io/gfx.c @@ -9,11 +9,11 @@ #include #include -#include "core/log.h" - #include "hook/com-proxy.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "imports/glhelper.h" #include "jbhook-util-p3io/gfx.h" diff --git a/src/main/jbhook-util-p3io/mixer.c b/src/main/jbhook-util-p3io/mixer.c index ba52a63..89c48d5 100644 --- a/src/main/jbhook-util-p3io/mixer.c +++ b/src/main/jbhook-util-p3io/mixer.c @@ -6,10 +6,10 @@ #include // clang-format on -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" MMRESULT STDCALL hook_mixerGetLineControlsA( diff --git a/src/main/jbhook-util-p3io/p3io.c b/src/main/jbhook-util-p3io/p3io.c index dd04607..cfded20 100644 --- a/src/main/jbhook-util-p3io/p3io.c +++ b/src/main/jbhook-util-p3io/p3io.c @@ -3,9 +3,8 @@ #include #include -#include "bemanitools/jbio.h" - -#include "core/log.h" +#include "iface-core/log.h" +#include "iface-io/jb.h" #include "jbhook-util-p3io/p3io.h" @@ -119,13 +118,13 @@ static HRESULT jbhook_p3io_read_jamma(void *ctx, uint32_t *state) state_tmp = 0; - if (!jb_io_read_inputs()) { + if (!bt_io_jb_inputs_read()) { log_warning("Reading inputs from jbio failed"); return E_FAIL; } - panels = jb_io_get_panel_inputs(); - buttons = jb_io_get_sys_inputs(); + panels = bt_io_jb_panel_inputs_get(); + buttons = bt_io_jb_sys_inputs_get(); for (uint8_t i = 0; i < 16; i++) { // panels are active-low @@ -189,30 +188,30 @@ static HRESULT jbhook_p3io_set_outputs(void *ctx, uint32_t state) uint8_t p3io_panel = (state & 0x00FF00) >> 8; uint8_t p3io_coinblocker = (state & 0xFF0000) >> 16; - enum jb_io_panel_mode panel_mode; + bt_io_jb_panel_mode_t panel_mode; switch (p3io_panel) { case 5: - panel_mode = JB_IO_PANEL_MODE_TOP_LEFT; + panel_mode = BT_IO_JB_PANEL_MODE_TOP_LEFT; break; case 4: - panel_mode = JB_IO_PANEL_MODE_TOP_RIGHT; + panel_mode = BT_IO_JB_PANEL_MODE_TOP_RIGHT; break; case 6: - panel_mode = JB_IO_PANEL_MODE_BOTTOM_RIGHT; + panel_mode = BT_IO_JB_PANEL_MODE_BOTTOM_RIGHT; break; case 7: - panel_mode = JB_IO_PANEL_MODE_BOTTOM_LEFT; + panel_mode = BT_IO_JB_PANEL_MODE_BOTTOM_LEFT; break; default: - panel_mode = JB_IO_PANEL_MODE_ALL; + panel_mode = BT_IO_JB_PANEL_MODE_ALL; break; } - jb_io_set_panel_mode(panel_mode); + bt_io_jb_panel_mode_set(panel_mode); // 0x40 has been seen to unblock, no other values observed - jb_io_set_coin_blocker(p3io_coinblocker == 0x00); + bt_io_jb_coin_blocker_set(p3io_coinblocker == 0x00); return S_OK; } diff --git a/src/main/jbhook-util/acio.c b/src/main/jbhook-util/acio.c index 8a1ed02..197d32e 100644 --- a/src/main/jbhook-util/acio.c +++ b/src/main/jbhook-util/acio.c @@ -16,10 +16,10 @@ #include "acioemu/h44b.h" #include "acioemu/icca.h" -#include "core/log.h" - #include "hook/iohook.h" +#include "iface-core/log.h" + #include "jbhook-util/acio.h" #include "imports/avs.h" diff --git a/src/main/jbhook-util/eamuse.c b/src/main/jbhook-util/eamuse.c index c9d1d90..364c151 100644 --- a/src/main/jbhook-util/eamuse.c +++ b/src/main/jbhook-util/eamuse.c @@ -9,10 +9,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/net.h" #include "util/str.h" diff --git a/src/main/jbhook-util/locale.c b/src/main/jbhook-util/locale.c index a6b6d17..5c6255f 100644 --- a/src/main/jbhook-util/locale.c +++ b/src/main/jbhook-util/locale.c @@ -2,10 +2,10 @@ #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" // ANSI/OEM Japanese; Japanese (Shift-JIS) diff --git a/src/main/jbhook-util/p4io.c b/src/main/jbhook-util/p4io.c index 824ab80..6a7b765 100644 --- a/src/main/jbhook-util/p4io.c +++ b/src/main/jbhook-util/p4io.c @@ -2,9 +2,8 @@ #include -#include "bemanitools/jbio.h" - -#include "core/log.h" +#include "iface-core/log.h" +#include "iface-io/jb.h" #include "imports/avs.h" @@ -97,13 +96,13 @@ static void jbhook_io_jamma2_read(void *resp, uint32_t nbytes) /* lower three bytes low active, highest byte high active */ inputs_out = 0x00FFFFFF; - if (!jb_io_read_inputs()) { + if (!bt_io_jb_inputs_read()) { log_warning("Reading inputs from jbio failed"); return; } - panels = jb_io_get_panel_inputs(); - buttons = jb_io_get_sys_inputs(); + panels = bt_io_jb_panel_inputs_get(); + buttons = bt_io_jb_sys_inputs_get(); for (uint8_t i = 0; i < 16; i++) { if (panels & (1 << i)) { @@ -134,7 +133,7 @@ static uint32_t jbhook_command_handle( // on is 0x00, off is either 0x10 or 0x20 depending on whether it's // during gameplay (0x10) or test menu (0x20). Both seem to have the // same effect - jb_io_set_coin_blocker(*(uint8_t *) payload == 0x00); + bt_io_jb_coin_blocker_set(*(uint8_t *) payload == 0x00); // this actually returns the coinstock, don't care for it memset(resp, 0, 4); @@ -147,33 +146,33 @@ static uint32_t jbhook_command_handle( (const struct p4io_req_panel_mode *) payload; // always fallback to ALL if input is unknown - enum jb_io_panel_mode mode = JB_IO_PANEL_MODE_ALL; + bt_io_jb_panel_mode_t mode = BT_IO_JB_PANEL_MODE_ALL; if (req->is_single) { switch (req->mode) { case 0x0001: - mode = JB_IO_PANEL_MODE_TOP_LEFT; + mode = BT_IO_JB_PANEL_MODE_TOP_LEFT; break; case 0x0000: - mode = JB_IO_PANEL_MODE_TOP_RIGHT; + mode = BT_IO_JB_PANEL_MODE_TOP_RIGHT; break; case 0x0101: - mode = JB_IO_PANEL_MODE_BOTTOM_LEFT; + mode = BT_IO_JB_PANEL_MODE_BOTTOM_LEFT; break; case 0x0100: - mode = JB_IO_PANEL_MODE_BOTTOM_RIGHT; + mode = BT_IO_JB_PANEL_MODE_BOTTOM_RIGHT; break; default: - mode = JB_IO_PANEL_MODE_ALL; + mode = BT_IO_JB_PANEL_MODE_ALL; break; } } - jb_io_set_panel_mode(mode); + bt_io_jb_panel_mode_set(mode); memset(resp, 0, 1); diff --git a/src/main/jbhook1/Module.mk b/src/main/jbhook1/Module.mk index c434f21..fa21940 100644 --- a/src/main/jbhook1/Module.mk +++ b/src/main/jbhook1/Module.mk @@ -14,8 +14,6 @@ libs_jbhook1 := \ core \ acioemu \ cconfig \ - eamio \ - jbio \ jbhook-util \ jbhook-util-p3io \ p3ioemu \ @@ -24,6 +22,10 @@ libs_jbhook1 := \ hooklib \ security \ util \ + iface \ + iface-io \ + iface-core \ + module \ src_jbhook1 := \ avs-boot.c \ diff --git a/src/main/jbhook1/avs-boot.c b/src/main/jbhook1/avs-boot.c index 62d6773..0dc3c24 100644 --- a/src/main/jbhook1/avs-boot.c +++ b/src/main/jbhook1/avs-boot.c @@ -6,10 +6,11 @@ #include #include "core/log-bt.h" -#include "core/log.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "jbhook1/avs-boot.h" diff --git a/src/main/jbhook1/config-eamuse.c b/src/main/jbhook1/config-eamuse.c index 77170e2..5257915 100644 --- a/src/main/jbhook1/config-eamuse.c +++ b/src/main/jbhook1/config-eamuse.c @@ -2,7 +2,7 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "jbhook1/config-eamuse.h" diff --git a/src/main/jbhook1/config-gfx.c b/src/main/jbhook1/config-gfx.c index 10102fa..5108bfa 100644 --- a/src/main/jbhook1/config-gfx.c +++ b/src/main/jbhook1/config-gfx.c @@ -2,7 +2,7 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "jbhook1/config-gfx.h" diff --git a/src/main/jbhook1/config-security.c b/src/main/jbhook1/config-security.c index d6c56b0..debb5f6 100644 --- a/src/main/jbhook1/config-security.c +++ b/src/main/jbhook1/config-security.c @@ -2,7 +2,7 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "jbhook1/config-security.h" diff --git a/src/main/jbhook1/dllmain.c b/src/main/jbhook1/dllmain.c index f058d0f..1ffe5e6 100644 --- a/src/main/jbhook1/dllmain.c +++ b/src/main/jbhook1/dllmain.c @@ -5,18 +5,12 @@ #include #include -#include "bemanitools/eamio.h" -#include "bemanitools/jbio.h" - #include "cconfig/cconfig-hook.h" #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-debug.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" #include "core/thread-crt.h" -#include "core/thread.h" #include "hook/table.h" @@ -24,6 +18,12 @@ #include "hooklib/adapter.h" #include "hooklib/rs232.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/jb.h" + #include "jbhook1/avs-boot.h" #include "jbhook1/config-eamuse.h" #include "jbhook1/config-gfx.h" @@ -37,6 +37,9 @@ #include "jbhook-util-p3io/mixer.h" #include "jbhook-util-p3io/p3io.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "p3ioemu/devmgr.h" #include "p3ioemu/emu.h" @@ -95,14 +98,35 @@ static const struct hook_symbol kernel32_hook_syms[] = { // so our CreateProcessA hook can check static bool vertical; +static module_io_t *jbhook_module_io_jb; +static module_io_t *jbhook_module_io_eam; + static void _jbhook1_log_init() { - core_log_bt_ext_impl_set(); core_log_bt_ext_init_with_debug(); // TODO change log level support core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); } +static void _jbhook1_io_jb_init(module_io_t **module) +{ + bt_io_jb_api_t api; + + module_io_ext_load_and_init("jbio.dll", "bt_module_io_jb_api_get", module); + module_io_api_get(*module, &api); + bt_io_jb_api_set(&api); +} + +static void _jbhook1_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} + /** * This seems to be a good entry point to intercept before the game calls * anything important (very close to the start of WinMain). @@ -167,23 +191,17 @@ static HWND CDECL my_mwindow_create( log_info("Starting up jubeat IO backend"); - core_log_impl_assign(jb_io_set_loggers); + _jbhook1_io_jb_init(&jbhook_module_io_jb); - if (!jb_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_jb_init()) { log_fatal("Initializing jb IO backend failed"); } log_info("Starting up card reader backend"); - core_log_impl_assign(eam_io_set_loggers); + _jbhook1_io_eam_init(&jbhook_module_io_eam); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } @@ -220,10 +238,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { // TODO why not use AVS threads? - core_thread_crt_ext_impl_set(); + core_thread_crt_core_api_set(); // TODO init debug logging but with avs available? why not use avs // logging? + core_log_bt_core_api_set(); _jbhook1_log_init(); /* Bootstrap hook for further init tasks (see above) */ diff --git a/src/main/jbhook1/log-gftools.c b/src/main/jbhook1/log-gftools.c index f0dbf85..dd5622b 100644 --- a/src/main/jbhook1/log-gftools.c +++ b/src/main/jbhook1/log-gftools.c @@ -5,7 +5,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "hook/table.h" diff --git a/src/main/jbhook2/Module.mk b/src/main/jbhook2/Module.mk index 7ecebdb..4a88a30 100644 --- a/src/main/jbhook2/Module.mk +++ b/src/main/jbhook2/Module.mk @@ -9,12 +9,12 @@ ldflags_jbhook2 := \ -liphlpapi \ -lopengl32 \ +avslibs_jbhook2 := \ + avs-ext \ + libs_jbhook2 := \ - avs-util \ core \ acioemu \ - eamio \ - jbio \ jbhook-util \ jbhook-util-p3io \ p3ioemu \ @@ -24,6 +24,10 @@ libs_jbhook2 := \ hooklib \ security \ util \ + iface \ + iface-io \ + iface-core \ + module \ src_jbhook2 := \ dllmain.c \ diff --git a/src/main/jbhook2/dllmain.c b/src/main/jbhook2/dllmain.c index 4c06e4d..d10789e 100644 --- a/src/main/jbhook2/dllmain.c +++ b/src/main/jbhook2/dllmain.c @@ -5,13 +5,8 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/eamio.h" -#include "bemanitools/jbio.h" - -#include "core/log.h" -#include "core/thread.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "hook/iohook.h" #include "hook/table.h" @@ -21,6 +16,12 @@ #include "hooklib/rs232.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/jb.h" + #include "imports/avs.h" #include "jbhook2/options.h" @@ -31,6 +32,9 @@ #include "jbhook-util-p3io/gfx.h" #include "jbhook-util-p3io/p3io.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "p3ioemu/devmgr.h" #include "p3ioemu/emu.h" @@ -43,6 +47,27 @@ #include "util/defs.h" static struct options options; +static module_io_t *jbhook_module_io_jb; +static module_io_t *jbhook_module_io_eam; + +static void _jbhook2_io_jb_init(module_io_t **module) +{ + bt_io_jb_api_t api; + + module_io_ext_load_and_init("jbio.dll", "bt_module_io_jb_api_get", module); + module_io_api_get(*module, &api); + bt_io_jb_api_set(&api); +} + +static void _jbhook2_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} static bool my_dll_entry_init(char *sidcode, struct property_node *param) { @@ -83,12 +108,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info("Starting up jubeat IO backend"); - core_log_impl_assign(jb_io_set_loggers); + _jbhook2_io_jb_init(&jbhook_module_io_jb); - jb_io_ok = jb_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + jb_io_ok = bt_io_jb_init(); if (!jb_io_ok) { goto fail; @@ -103,12 +125,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info("Starting up card reader backend"); - core_log_impl_assign(eam_io_set_loggers); + _jbhook2_io_eam_init(&jbhook_module_io_eam); - eam_io_ok = eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + eam_io_ok = bt_io_eam_init(); if (!eam_io_ok) { goto fail; @@ -142,11 +161,17 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) fail: if (eam_io_ok) { - eam_io_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&jbhook_module_io_eam); } if (jb_io_ok) { - jb_io_fini(); + bt_io_jb_fini(); + + bt_io_jb_api_clear(); + module_io_free(&jbhook_module_io_jb); } return false; @@ -158,18 +183,25 @@ static bool my_dll_entry_main(void) result = app_hook_invoke_main(); - log_info("Shutting down card reader backend"); - eam_io_fini(); - - log_info("Shutting down Jubeat IO backend"); - jb_io_fini(); - if (!options.disable_cardemu) { + log_info("Shutting down card reader backend"); + jbhook_util_ac_io_port_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&jbhook_module_io_eam); } if (!options.disable_p3ioemu) { + log_info("Shutting down Jubeat IO backend"); + jbhook_util_p3io_fini(); + + bt_io_jb_fini(); + + bt_io_jb_api_clear(); + module_io_free(&jbhook_module_io_jb); } options_fini(&options); @@ -230,8 +262,8 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) } // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); options_init_from_cmdline(&options); diff --git a/src/main/jbhook3/Module.mk b/src/main/jbhook3/Module.mk index ca36a43..51330d0 100644 --- a/src/main/jbhook3/Module.mk +++ b/src/main/jbhook3/Module.mk @@ -7,12 +7,12 @@ ldflags_jbhook3 := \ -lws2_32 \ -liphlpapi \ +avslibs_jbhook3 := \ + avs-ext \ + libs_jbhook3 := \ - avs-util \ core \ acioemu \ - eamio \ - jbio \ jbhook-util \ p3ioemu \ p3io \ @@ -21,6 +21,10 @@ libs_jbhook3 := \ hooklib \ security \ util \ + iface \ + iface-io \ + iface-core \ + module \ src_jbhook3 := \ dllmain.c \ diff --git a/src/main/jbhook3/dllmain.c b/src/main/jbhook3/dllmain.c index 30a0eb3..dc1f3c4 100644 --- a/src/main/jbhook3/dllmain.c +++ b/src/main/jbhook3/dllmain.c @@ -5,13 +5,8 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/eamio.h" -#include "bemanitools/jbio.h" - -#include "core/log.h" -#include "core/thread.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "hook/iohook.h" #include "hook/table.h" @@ -21,6 +16,12 @@ #include "hooklib/rs232.h" #include "hooklib/setupapi.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/jb.h" + #include "imports/avs.h" #include "jbhook3/gfx.h" @@ -30,6 +31,9 @@ #include "jbhook-util/eamuse.h" #include "jbhook-util/p4io.h" +#include "module/io-ext.h" +#include "module/io.h" + #include "p4ioemu/device.h" #include "p4ioemu/setupapi.h" @@ -38,6 +42,27 @@ #include "util/defs.h" static struct options options; +static module_io_t *jbhook_module_io_jb; +static module_io_t *jbhook_module_io_eam; + +static void _jbhook3_io_jb_init(module_io_t **module) +{ + bt_io_jb_api_t api; + + module_io_ext_load_and_init("jbio.dll", "bt_module_io_jb_api_get", module); + module_io_api_get(*module, &api); + bt_io_jb_api_set(&api); +} + +static void _jbhook3_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} static bool my_dll_entry_init(char *sidcode, struct property_node *param) { @@ -65,12 +90,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!options.disable_p4ioemu) { log_info("Starting up jubeat IO backend"); - core_log_impl_assign(jb_io_set_loggers); + _jbhook3_io_jb_init(&jbhook_module_io_jb); - jb_io_ok = jb_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + jb_io_ok = bt_io_jb_init(); if (!jb_io_ok) { goto fail; @@ -83,12 +105,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!options.disable_cardemu) { log_info("Starting up card reader backend"); - core_log_impl_assign(eam_io_set_loggers); + _jbhook3_io_eam_init(&jbhook_module_io_eam); - eam_io_ok = eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + eam_io_ok = bt_io_eam_init(); if (!eam_io_ok) { goto fail; @@ -107,11 +126,17 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) fail: if (eam_io_ok) { - eam_io_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&jbhook_module_io_eam); } if (jb_io_ok) { - jb_io_fini(); + bt_io_jb_fini(); + + bt_io_jb_api_clear(); + module_io_free(&jbhook_module_io_jb); } return false; @@ -123,18 +148,25 @@ static bool my_dll_entry_main(void) result = app_hook_invoke_main(); - log_info("Shutting down card reader backend"); - eam_io_fini(); - - log_info("Shutting down Jubeat IO backend"); - jb_io_fini(); - if (!options.disable_cardemu) { + log_info("Shutting down card reader backend"); + jbhook_util_ac_io_port_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&jbhook_module_io_eam); } if (!options.disable_p4ioemu) { + log_info("Shutting down Jubeat IO backend"); + p4ioemu_fini(); + + bt_io_jb_fini(); + + bt_io_jb_api_clear(); + module_io_free(&jbhook_module_io_jb); } options_fini(&options); @@ -149,8 +181,8 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) } // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); options_init_from_cmdline(&options); diff --git a/src/main/jbhook3/gfx.c b/src/main/jbhook3/gfx.c index 827ac55..055a8c0 100644 --- a/src/main/jbhook3/gfx.c +++ b/src/main/jbhook3/gfx.c @@ -5,10 +5,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "jbhook3/options.h" static bool jbhook3_gfx_windowed; diff --git a/src/main/jbhook3/options.c b/src/main/jbhook3/options.c index 8bb544b..bab5f27 100644 --- a/src/main/jbhook3/options.c +++ b/src/main/jbhook3/options.c @@ -6,7 +6,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "util/cmdline.h" #include "util/defs.h" diff --git a/src/main/jbio-magicbox/Module.mk b/src/main/jbio-magicbox/Module.mk index 1d24eb4..fcdd648 100644 --- a/src/main/jbio-magicbox/Module.mk +++ b/src/main/jbio-magicbox/Module.mk @@ -3,6 +3,10 @@ imps += ch341 deplibs_jbio-magicbox := \ ch341 \ + iface \ + module \ + iface-core \ + util \ src_jbio-magicbox := \ jbio.c \ diff --git a/src/main/jbio-magicbox/jbio-magicbox.def b/src/main/jbio-magicbox/jbio-magicbox.def index 4920f40..c665b51 100644 --- a/src/main/jbio-magicbox/jbio-magicbox.def +++ b/src/main/jbio-magicbox/jbio-magicbox.def @@ -1,13 +1,17 @@ LIBRARY jbio EXPORTS - jb_io_fini - jb_io_get_panel_inputs - jb_io_get_sys_inputs - jb_io_init - jb_io_read_inputs - jb_io_set_loggers - jb_io_set_rgb_led - jb_io_set_coin_blocker - jb_io_set_panel_mode - jb_io_write_lights + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_io_jb_api_get + + ; Direct API + bt_io_jb_init + bt_io_jb_fini + bt_io_jb_inputs_read + bt_io_jb_sys_inputs_get + bt_io_jb_panel_inputs_get + bt_io_jb_rgb_led_set + bt_io_jb_lights_write + bt_io_jb_panel_mode_set + bt_io_jb_coin_blocker_set diff --git a/src/main/jbio-magicbox/jbio.c b/src/main/jbio-magicbox/jbio.c index 3aa02be..a265ffb 100644 --- a/src/main/jbio-magicbox/jbio.c +++ b/src/main/jbio-magicbox/jbio.c @@ -1,10 +1,19 @@ +#define LOG_MODULE "jbio-magicbox" + // This implementation is ported from the device.dll source graciously // provided by zyp #include -#include "bemanitools/jbio.h" +#include "api/core/log.h" + +#include "iface-core/log.h" + #include "imports/ch341.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/io/jb.h" + #include "util/defs.h" static uint16_t jb_io_panels; @@ -12,35 +21,15 @@ static uint8_t jb_io_sys_buttons; static bool is_initialized = false; -static log_formatter_t jb_io_log_misc; -static log_formatter_t jb_io_log_info; -static log_formatter_t jb_io_log_warning; -static log_formatter_t jb_io_log_fatal; - union magicbox_input { uint32_t dword; uint8_t bytes[4]; }; -void jb_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - jb_io_log_misc = misc; - jb_io_log_info = info; - jb_io_log_warning = warning; - jb_io_log_fatal = fatal; -} - -bool jb_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_jb_init() { if (CH341OpenDevice(0) < 0) { - jb_io_log_warning("jbio", "Can't open CH341 device.\n"); + log_warning("jbio", "Can't open CH341 device.\n"); return false; } @@ -49,7 +38,7 @@ bool jb_io_init( return true; } -void jb_io_fini(void) +void bt_io_jb_fini() { CH341CloseDevice(0); } @@ -79,7 +68,7 @@ static const uint32_t magic_sys_mappings[] = { (1 << 0x13), // COIN }; -bool jb_io_read_inputs(void) +bool bt_io_jb_inputs_read() { // Read IO board unsigned long size; @@ -119,34 +108,55 @@ bool jb_io_read_inputs(void) return true; } -bool jb_io_write_lights(void) +bool bt_io_jb_lights_write() { return true; } -uint8_t jb_io_get_sys_inputs(void) +uint8_t bt_io_jb_sys_inputs_get() { return jb_io_sys_buttons; } -uint16_t jb_io_get_panel_inputs(void) +uint16_t bt_io_jb_panel_inputs_get() { return jb_io_panels; } -void jb_io_set_rgb_led(enum jb_io_rgb_led unit, uint8_t r, uint8_t g, uint8_t b) +void bt_io_jb_rgb_led_set( + bt_io_jb_rgb_led_t unit, uint8_t r, uint8_t g, uint8_t b) { // I mean I guess there's reactive LEDs on the sides? I'm not going to the // effort to work out if they're controllable or not } -bool jb_io_set_panel_mode(enum jb_io_panel_mode mode) +bool bt_io_jb_panel_mode_set(bt_io_jb_panel_mode_t mode) { // panel always returns merged input state, no corner support return true; } -bool jb_io_set_coin_blocker(bool blocked) +bool bt_io_jb_coin_blocker_set(bool blocked) { return true; } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_io_jb_api_get(bt_io_jb_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_jb_init; + api->v1.fini = bt_io_jb_fini; + api->v1.inputs_read = bt_io_jb_inputs_read; + api->v1.sys_inputs_get = bt_io_jb_sys_inputs_get; + api->v1.panel_inputs_get = bt_io_jb_panel_inputs_get; + api->v1.rgb_led_set = bt_io_jb_rgb_led_set; + api->v1.lights_write = bt_io_jb_lights_write; + api->v1.panel_mode_set = bt_io_jb_panel_mode_set; + api->v1.coin_blocker_set = bt_io_jb_coin_blocker_set; +} \ No newline at end of file diff --git a/src/main/jbio-p4io/Module.mk b/src/main/jbio-p4io/Module.mk index ca9895e..7a85788 100644 --- a/src/main/jbio-p4io/Module.mk +++ b/src/main/jbio-p4io/Module.mk @@ -9,9 +9,11 @@ src_jbio-p4io := \ jbio.c \ libs_jbio-p4io := \ - core \ aciodrv \ - aciomgr \ cconfig \ p4iodrv \ util \ + iface \ + module \ + iface-core \ + iface-acio \ diff --git a/src/main/jbio-p4io/config-h44b.c b/src/main/jbio-p4io/config-h44b.c index 98a5f4f..842a0ff 100644 --- a/src/main/jbio-p4io/config-h44b.c +++ b/src/main/jbio-p4io/config-h44b.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "jbio-p4io/config-h44b.h" diff --git a/src/main/jbio-p4io/h44b.c b/src/main/jbio-p4io/h44b.c index f26aa2a..585f13d 100644 --- a/src/main/jbio-p4io/h44b.c +++ b/src/main/jbio-p4io/h44b.c @@ -8,19 +8,18 @@ #include "aciodrv/h44b.h" -#include "aciomgr/manager.h" - -#include "core/log.h" +#include "iface-acio/mgr.h" +#include "iface-core/log.h" static int16_t h44b_node_id; static atomic_bool running; -static struct aciomgr_port_dispatcher *acio_manager_ctx; +static bt_acio_mgr_port_dispatcher_t *acio_manager_ctx; bool jb_io_h44b_init(const char *port, int32_t baud) { - acio_manager_ctx = aciomgr_port_init(port, baud); + acio_manager_ctx = bt_acio_mgr_port_init(port, baud); if (acio_manager_ctx == NULL) { log_info("Opening acio device on [%s] failed", port); @@ -29,14 +28,14 @@ bool jb_io_h44b_init(const char *port, int32_t baud) log_info("Opening acio device successful"); - uint8_t node_count = aciomgr_get_node_count(acio_manager_ctx); + uint8_t node_count = bt_acio_mgr_node_count_get(acio_manager_ctx); log_info("Enumerated %d nodes", node_count); h44b_node_id = -1; for (uint8_t i = 0; i < node_count; i++) { char product[4]; - aciomgr_get_node_product_ident(acio_manager_ctx, i, product); + bt_acio_mgr_node_product_ident_get(acio_manager_ctx, i, product); log_info( "> %d: %c%c%c%c", i, @@ -57,8 +56,8 @@ bool jb_io_h44b_init(const char *port, int32_t baud) log_warning("Using H44B on node: %d", h44b_node_id); bool init_result = aciodrv_h44b_init( - aciomgr_port_checkout(acio_manager_ctx), h44b_node_id); - aciomgr_port_checkin(acio_manager_ctx); + bt_acio_mgr_port_checkout(acio_manager_ctx), h44b_node_id); + bt_acio_mgr_port_checkin(acio_manager_ctx); if (!init_result) { log_warning("Unable to start H44B on node: %d", h44b_node_id); @@ -76,7 +75,7 @@ bool jb_io_h44b_init(const char *port, int32_t baud) bool jb_io_h44b_fini(void) { - aciomgr_port_fini(acio_manager_ctx); + bt_acio_mgr_port_fini(acio_manager_ctx); return true; } @@ -88,8 +87,8 @@ bool jb_io_h44b_write_lights(struct ac_io_h44b_output *lights) } bool amp_result = aciodrv_h44b_lights( - aciomgr_port_checkout(acio_manager_ctx), h44b_node_id, lights); - aciomgr_port_checkin(acio_manager_ctx); + bt_acio_mgr_port_checkout(acio_manager_ctx), h44b_node_id, lights); + bt_acio_mgr_port_checkin(acio_manager_ctx); if (!amp_result) { return false; diff --git a/src/main/jbio-p4io/jbio-p4io.def b/src/main/jbio-p4io/jbio-p4io.def index e923ef7..c665b51 100644 --- a/src/main/jbio-p4io/jbio-p4io.def +++ b/src/main/jbio-p4io/jbio-p4io.def @@ -1,13 +1,17 @@ LIBRARY jbio EXPORTS - jb_io_fini - jb_io_get_panel_inputs - jb_io_get_sys_inputs - jb_io_init - jb_io_read_inputs - jb_io_set_loggers - jb_io_set_rgb_led - jb_io_set_panel_mode - jb_io_set_coin_blocker - jb_io_write_lights + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_io_jb_api_get + + ; Direct API + bt_io_jb_init + bt_io_jb_fini + bt_io_jb_inputs_read + bt_io_jb_sys_inputs_get + bt_io_jb_panel_inputs_get + bt_io_jb_rgb_led_set + bt_io_jb_lights_write + bt_io_jb_panel_mode_set + bt_io_jb_coin_blocker_set diff --git a/src/main/jbio-p4io/jbio.c b/src/main/jbio-p4io/jbio.c index 58f4db9..97e4162 100644 --- a/src/main/jbio-p4io/jbio.c +++ b/src/main/jbio-p4io/jbio.c @@ -1,3 +1,5 @@ +#define LOG_MODULE "jbio-p4io" + // clang-format off // Don't format because the order is important here #include @@ -5,19 +7,23 @@ #include // clang-format on -#include "aciomgr/manager.h" - -#include "bemanitools/jbio.h" +#include "api/core/log.h" #include "cconfig/cconfig-main.h" -#include "core/log.h" +#include "iface-acio/mgr.h" +#include "iface-core/log.h" #include "jbio-p4io/config-h44b.h" #include "jbio-p4io/h44b.h" +#include "main/module/acio-mgr-ext.h" + #include "p4iodrv/device.h" +#include "sdk/module/core/log.h" +#include "sdk/module/io/jb.h" + static struct p4iodrv_ctx *p4io_ctx; static uint16_t jb_io_panels; static uint8_t jb_io_sys_buttons; @@ -28,21 +34,18 @@ static struct ac_io_h44b_output jb_io_new_lights; static bool coin_blocked; -void jb_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - aciomgr_set_loggers(misc, info, warning, fatal); +static module_acio_mgr_t *acio_mgr_module; - core_log_impl_set(misc, info, warning, fatal); +static void _bt_io_jb_module_acio_mgr_init(module_acio_mgr_t **module) +{ + bt_acio_mgr_api_t api; + + module_acio_mgr_ext_load_and_init("acio-mgr.dll", module); + module_acio_mgr_api_get(*module, &api); + bt_acio_mgr_api_set(&api); } -bool jb_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_jb_init() { struct cconfig *config; struct h44b_config config_h44b; @@ -67,13 +70,15 @@ bool jb_io_init( cconfig_finit(config); + _bt_io_jb_module_acio_mgr_init(&acio_mgr_module); + p4io_ctx = p4iodrv_open(); if (!p4io_ctx) { return false; } - // some people use p4io just for inputs and have no lights. Soft fail when - // h44b is not able to be connected instead of returning false + // some people use p4io just for acio_mgrs and have no lights. Soft fail + // when h44b is not able to be connected instead of returning false lights_present = jb_io_h44b_init(config_h44b.port, config_h44b.baud); if (!lights_present) { log_warning("Could not connect to H44B, lights disabled"); @@ -82,9 +87,12 @@ bool jb_io_init( return true; } -void jb_io_fini(void) +void bt_io_jb_fini() { p4iodrv_close(p4io_ctx); + + bt_acio_mgr_api_clear(); + module_acio_mgr_free(&acio_mgr_module); } static const uint32_t jb_io_panel_mappings[] = { @@ -111,7 +119,7 @@ static const uint32_t jb_io_sys_button_mappings[] = { (1 << 25), }; -bool jb_io_read_inputs(void) +bool bt_io_jb_inputs_read() { uint32_t jamma[4]; if (!p4iodrv_read_jamma(p4io_ctx, jamma)) { @@ -140,7 +148,7 @@ bool jb_io_read_inputs(void) return true; } -bool jb_io_write_lights(void) +bool bt_io_jb_lights_write() { if (lights_present && memcmp(&jb_io_lights, &jb_io_new_lights, sizeof(jb_io_lights))) { @@ -151,37 +159,37 @@ bool jb_io_write_lights(void) return true; } -uint8_t jb_io_get_sys_inputs(void) +uint8_t bt_io_jb_sys_inputs_get() { return jb_io_sys_buttons; } -uint16_t jb_io_get_panel_inputs(void) +uint16_t bt_io_jb_panel_inputs_get() { return jb_io_panels; } -bool jb_io_set_panel_mode(enum jb_io_panel_mode mode) +bool bt_io_jb_panel_mode_set(bt_io_jb_panel_mode_t mode) { struct p4io_req_panel_mode panel_mode = {0}; panel_mode.is_single = 1; switch (mode) { - case JB_IO_PANEL_MODE_ALL: + case BT_IO_JB_PANEL_MODE_ALL: panel_mode.is_single = 0; panel_mode.mode = 0; break; - case JB_IO_PANEL_MODE_TOP_LEFT: + case BT_IO_JB_PANEL_MODE_TOP_LEFT: panel_mode.mode = 0x0001; break; - case JB_IO_PANEL_MODE_TOP_RIGHT: + case BT_IO_JB_PANEL_MODE_TOP_RIGHT: panel_mode.mode = 0x0000; break; - case JB_IO_PANEL_MODE_BOTTOM_LEFT: + case BT_IO_JB_PANEL_MODE_BOTTOM_LEFT: panel_mode.mode = 0x0101; break; - case JB_IO_PANEL_MODE_BOTTOM_RIGHT: + case BT_IO_JB_PANEL_MODE_BOTTOM_RIGHT: panel_mode.mode = 0x0100; break; } @@ -189,27 +197,28 @@ bool jb_io_set_panel_mode(enum jb_io_panel_mode mode) return p4iodrv_cmd_portout(p4io_ctx, (uint8_t *) &panel_mode); } -void jb_io_set_rgb_led(enum jb_io_rgb_led unit, uint8_t r, uint8_t g, uint8_t b) +void bt_io_jb_rgb_led_set( + bt_io_jb_rgb_led_t unit, uint8_t r, uint8_t g, uint8_t b) { uint8_t *light; switch (unit) { - case JB_IO_RGB_LED_FRONT: + case BT_IO_JB_RGB_LED_FRONT: light = jb_io_new_lights.front_rgb; break; - case JB_IO_RGB_LED_TOP: + case BT_IO_JB_RGB_LED_TOP: light = jb_io_new_lights.top_rgb; break; - case JB_IO_RGB_LED_LEFT: + case BT_IO_JB_RGB_LED_LEFT: light = jb_io_new_lights.left_rgb; break; - case JB_IO_RGB_LED_RIGHT: + case BT_IO_JB_RGB_LED_RIGHT: light = jb_io_new_lights.right_rgb; break; - case JB_IO_RGB_LED_TITLE: + case BT_IO_JB_RGB_LED_TITLE: light = jb_io_new_lights.title_rgb; break; - case JB_IO_RGB_LED_WOOFER: + case BT_IO_JB_RGB_LED_WOOFER: light = jb_io_new_lights.woofer_rgb; break; default: @@ -221,7 +230,7 @@ void jb_io_set_rgb_led(enum jb_io_rgb_led unit, uint8_t r, uint8_t g, uint8_t b) light[2] = b; } -bool jb_io_set_coin_blocker(bool blocked) +bool bt_io_jb_coin_blocker_set(bool blocked) { coin_blocked = blocked; @@ -229,3 +238,23 @@ bool jb_io_set_coin_blocker(bool blocked) coin[0] = coin_blocked ? 0x00 : 0x20; return p4iodrv_cmd_coinstock(p4io_ctx, coin); } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_io_jb_api_get(bt_io_jb_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_jb_init; + api->v1.fini = bt_io_jb_fini; + api->v1.inputs_read = bt_io_jb_inputs_read; + api->v1.sys_inputs_get = bt_io_jb_sys_inputs_get; + api->v1.panel_inputs_get = bt_io_jb_panel_inputs_get; + api->v1.rgb_led_set = bt_io_jb_rgb_led_set; + api->v1.lights_write = bt_io_jb_lights_write; + api->v1.panel_mode_set = bt_io_jb_panel_mode_set; + api->v1.coin_blocker_set = bt_io_jb_coin_blocker_set; +} diff --git a/src/main/jbio/Module.mk b/src/main/jbio/Module.mk index e859879..57db809 100644 --- a/src/main/jbio/Module.mk +++ b/src/main/jbio/Module.mk @@ -4,8 +4,12 @@ ldflags_jbio := \ -lwinmm libs_jbio := \ - geninput - + iface \ + module \ + iface-io \ + iface-core \ + util \ + src_jbio := \ jbio.c \ diff --git a/src/main/jbio/jbio.c b/src/main/jbio/jbio.c index 96a9049..8a05d22 100644 --- a/src/main/jbio/jbio.c +++ b/src/main/jbio/jbio.c @@ -1,12 +1,4 @@ -/* This is the source code for the JBIO.DLL that ships with Bemanitools 5. - - If you want to add on some minor functionality like a custom RGB LED setup - then feel free to extend this code with support for your custom device. - - If you want to make a completely custom IO board that handles all input and - lighting then you'd be better off writing your own from scratch. Consult - the "bemanitools" header files included by this source file for detailed - information about the API you'll need to implement. */ +#define LOG_MODULE "jbio" // clang-format off // Don't format because the order is important here @@ -14,71 +6,65 @@ #include // clang-format on -#include "bemanitools/jbio.h" -#include "bemanitools/input.h" +#include "api/core/log.h" +#include "api/core/thread.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface/input.h" + +#include "main/module/input-ext.h" +#include "main/module/input.h" +#include "main/module/io-ext.h" +#include "main/module/io.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/input.h" +#include "sdk/module/io/jb.h" + +static module_input_t *_jb_io_module_input; static uint16_t jb_io_panels; static uint8_t jb_io_sys_buttons; -/* Uncomment these if you need them. */ - -#if 0 -static log_formatter_t jb_io_log_misc; -static log_formatter_t jb_io_log_info; -static log_formatter_t jb_io_log_warning; -static log_formatter_t jb_io_log_fatal; -#endif - -void jb_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) +static void _bt_io_jb_module_input_init(module_input_t **module) { - /* Pass logger functions on to geninput so that it has somewhere to write - its own log output. */ + bt_input_api_t api; - input_set_loggers(misc, info, warning, fatal); - - /* Uncomment this block if you have something you'd like to log. - - You should probably return false from the appropriate function instead - of calling the fatal logger yourself though. */ - -#if 0 - jb_io_log_misc = misc; - jb_io_log_info = info; - jb_io_log_warning = warning; - jb_io_log_fatal = fatal; -#endif + module_input_ext_load_and_init("geninput.dll", module); + module_input_api_get(*module, &api); + bt_input_api_set(&api); } -bool jb_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_jb_init() { + bool result; + timeBeginPeriod(1); - input_init(thread_create, thread_join, thread_destroy); - mapper_config_load("jb"); + _bt_io_jb_module_input_init(&_jb_io_module_input); - /* Initialize your own IO devices here. Log something and then return - false if the initialization fails. */ + result = bt_input_init(); - return true; + if (!result) { + log_warning("Initializing input failed"); + return false; + } + + return bt_input_mapper_config_load("jb"); } -void jb_io_fini(void) +void bt_io_jb_fini() { - /* This function gets called as JB shuts down after an Alt-F4. Close your - connections to your IO devices here. */ + bt_input_fini(); + bt_input_api_clear(); + module_input_free(&_jb_io_module_input); - input_fini(); timeEndPeriod(1); } -bool jb_io_read_inputs(void) +bool bt_io_jb_inputs_read() { uint32_t buttons; /* Sleep first: input is timestamped immediately AFTER the ioctl returns. @@ -91,7 +77,7 @@ bool jb_io_read_inputs(void) /* Update all of our input state here. */ - buttons = (uint32_t) mapper_update(); + buttons = (uint32_t) bt_input_mapper_update(); /* Mask out the stuff provided by geninput and store the panel/button state for later retrieval via jb_io_get_buttons() */ @@ -102,7 +88,7 @@ bool jb_io_read_inputs(void) return true; } -bool jb_io_write_lights(void) +bool bt_io_jb_lights_write() { /* The generic input stack currently initiates lighting sends and input reads simultaneously, though this might change later. Perform all of our @@ -112,30 +98,56 @@ bool jb_io_write_lights(void) return true; } -uint8_t jb_io_get_sys_inputs(void) +uint8_t bt_io_jb_sys_inputs_get() { return jb_io_sys_buttons; } -uint16_t jb_io_get_panel_inputs(void) +uint16_t bt_io_jb_panel_inputs_get() { return jb_io_panels; } -bool jb_io_set_panel_mode(enum jb_io_panel_mode mode) +bool bt_io_jb_panel_mode_set(bt_io_jb_panel_mode_t mode) { // geninput only uses 1 switch per panel, so ignore alternate modes return true; } -bool jb_io_set_coin_blocker(bool blocked) +bool bt_io_jb_coin_blocker_set(bool blocked) { return true; } -void jb_io_set_rgb_led(enum jb_io_rgb_led unit, uint8_t r, uint8_t g, uint8_t b) +void bt_io_jb_rgb_led_set( + bt_io_jb_rgb_led_t unit, uint8_t r, uint8_t g, uint8_t b) { - mapper_write_light(unit * 3, r); - mapper_write_light(unit * 3 + 1, g); - mapper_write_light(unit * 3 + 2, b); + bt_input_mapper_light_write(unit * 3, r); + bt_input_mapper_light_write(unit * 3 + 1, g); + bt_input_mapper_light_write(unit * 3 + 2, b); } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_io_jb_api_get(bt_io_jb_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_jb_init; + api->v1.fini = bt_io_jb_fini; + api->v1.inputs_read = bt_io_jb_inputs_read; + api->v1.sys_inputs_get = bt_io_jb_sys_inputs_get; + api->v1.panel_inputs_get = bt_io_jb_panel_inputs_get; + api->v1.rgb_led_set = bt_io_jb_rgb_led_set; + api->v1.lights_write = bt_io_jb_lights_write; + api->v1.panel_mode_set = bt_io_jb_panel_mode_set; + api->v1.coin_blocker_set = bt_io_jb_coin_blocker_set; +} \ No newline at end of file diff --git a/src/main/jbio/jbio.def b/src/main/jbio/jbio.def index aecc228..09d9d49 100644 --- a/src/main/jbio/jbio.def +++ b/src/main/jbio/jbio.def @@ -1,13 +1,18 @@ LIBRARY jbio EXPORTS - jb_io_fini - jb_io_get_panel_inputs - jb_io_get_sys_inputs - jb_io_init - jb_io_read_inputs - jb_io_set_loggers - jb_io_set_panel_mode - jb_io_set_rgb_led - jb_io_set_coin_blocker - jb_io_write_lights + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_io_jb_api_get + + ; Direct API + bt_io_jb_init + bt_io_jb_fini + bt_io_jb_inputs_read + bt_io_jb_sys_inputs_get + bt_io_jb_panel_inputs_get + bt_io_jb_rgb_led_set + bt_io_jb_lights_write + bt_io_jb_panel_mode_set + bt_io_jb_coin_blocker_set diff --git a/src/main/jbiotest/Module.mk b/src/main/jbiotest/Module.mk index eba9c0b..b55298e 100644 --- a/src/main/jbiotest/Module.mk +++ b/src/main/jbiotest/Module.mk @@ -2,8 +2,10 @@ exes += jbiotest \ libs_jbiotest := \ core \ - jbio \ util \ + module \ + iface-core \ + iface-io \ src_jbiotest := \ main.c \ diff --git a/src/main/jbiotest/main.c b/src/main/jbiotest/main.c index 0a6270b..43ec913 100644 --- a/src/main/jbiotest/main.c +++ b/src/main/jbiotest/main.c @@ -1,18 +1,18 @@ +#include + #include #include #include #include -#include - -#include "bemanitools/jbio.h" - #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" -#include "core/thread-crt.h" -#include "core/thread.h" +#include "core/log-sink-std.h" + +#include "iface-core/log.h" +#include "iface-io/jb.h" + +#include "module/io-ext.h" typedef struct { uint8_t r, g, b; @@ -22,29 +22,46 @@ enum jbio_light_mode { LIGHTS_OFF, LIGHTS_ON, LIGHTS_INPUT }; #define IS_BIT_SET(var, bit) ((((var) >> (bit)) & 1) > 0) +static void _jbiotest_io_jb_init(module_io_t **module) +{ + bt_io_jb_api_t api; + + module_io_ext_load_and_init("jbio.dll", "bt_module_io_jb_api_get", module); + module_io_api_get(*module, &api); + bt_io_jb_api_set(&api); +} + /** * Tool to test your implementations of jbio. */ int main(int argc, char **argv) { - core_thread_crt_ext_impl_set(); - core_log_bt_ext_impl_set(); + module_io_t *module_io_jb; - core_log_bt_ext_init_with_stdout(); + core_log_bt_core_api_set(); - core_log_impl_assign(jb_io_set_loggers); + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); - if (!jb_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _jbiotest_io_jb_init(&module_io_jb); + + if (!bt_io_jb_init()) { printf("Initializing jbio failed\n"); + + bt_io_jb_api_clear(); + module_io_free(&module_io_jb); + return -1; } printf(">>> Initializing jbio successful, press enter to continue <<<\n"); if (getchar() != '\n') { + bt_io_jb_fini(); + + bt_io_jb_api_clear(); + module_io_free(&module_io_jb); + return 0; } @@ -58,15 +75,21 @@ int main(int argc, char **argv) bool loop = true; uint16_t cnt = 0; enum jbio_light_mode light_mode = LIGHTS_OFF; - enum jb_io_panel_mode panel_mode = JB_IO_PANEL_MODE_ALL; + bt_io_jb_panel_mode_t panel_mode = BT_IO_JB_PANEL_MODE_ALL; bool panel_corners_animate = false; char *all_text; char top_left, top_right, bottom_left, bottom_right; while (loop) { - if (!jb_io_read_inputs()) { + if (!bt_io_jb_inputs_read()) { printf("ERROR: Input read fail\n"); + + bt_io_jb_fini(); + + bt_io_jb_api_clear(); + module_io_free(&module_io_jb); + return -2; } @@ -75,37 +98,37 @@ int main(int argc, char **argv) panel_mode %= 5; // skip the all state - if (panel_mode == JB_IO_PANEL_MODE_ALL) { + if (panel_mode == BT_IO_JB_PANEL_MODE_ALL) { panel_mode++; } - jb_io_set_panel_mode(panel_mode); + bt_io_jb_panel_mode_set(panel_mode); } all_text = " "; top_left = top_right = bottom_left = bottom_right = ' '; switch (panel_mode) { - case JB_IO_PANEL_MODE_ALL: + case BT_IO_JB_PANEL_MODE_ALL: all_text = "ALL"; top_left = top_right = bottom_left = bottom_right = '*'; break; - case JB_IO_PANEL_MODE_TOP_LEFT: + case BT_IO_JB_PANEL_MODE_TOP_LEFT: top_left = '*'; break; - case JB_IO_PANEL_MODE_TOP_RIGHT: + case BT_IO_JB_PANEL_MODE_TOP_RIGHT: top_right = '*'; break; - case JB_IO_PANEL_MODE_BOTTOM_LEFT: + case BT_IO_JB_PANEL_MODE_BOTTOM_LEFT: bottom_left = '*'; break; - case JB_IO_PANEL_MODE_BOTTOM_RIGHT: + case BT_IO_JB_PANEL_MODE_BOTTOM_RIGHT: bottom_right = '*'; break; } /* get inputs */ - input_sys = jb_io_get_sys_inputs(); - input_panel = jb_io_get_panel_inputs(); + input_sys = bt_io_jb_sys_inputs_get(); + input_panel = bt_io_jb_panel_inputs_get(); system("cls"); printf( @@ -138,54 +161,54 @@ int main(int argc, char **argv) " `---`---`---`---`\n", cnt, - lights[JB_IO_RGB_LED_TOP].r, - lights[JB_IO_RGB_LED_TOP].g, - lights[JB_IO_RGB_LED_TOP].b, - lights[JB_IO_RGB_LED_FRONT].r, - lights[JB_IO_RGB_LED_FRONT].g, - lights[JB_IO_RGB_LED_FRONT].b, - lights[JB_IO_RGB_LED_LEFT].r, - lights[JB_IO_RGB_LED_RIGHT].r, - lights[JB_IO_RGB_LED_LEFT].g, - lights[JB_IO_RGB_LED_RIGHT].g, - lights[JB_IO_RGB_LED_LEFT].b, - lights[JB_IO_RGB_LED_TITLE].r, - lights[JB_IO_RGB_LED_TITLE].g, - lights[JB_IO_RGB_LED_TITLE].b, - lights[JB_IO_RGB_LED_RIGHT].b, - lights[JB_IO_RGB_LED_WOOFER].r, - lights[JB_IO_RGB_LED_WOOFER].g, - lights[JB_IO_RGB_LED_WOOFER].b, + lights[BT_IO_JB_RGB_LED_TOP].r, + lights[BT_IO_JB_RGB_LED_TOP].g, + lights[BT_IO_JB_RGB_LED_TOP].b, + lights[BT_IO_JB_RGB_LED_FRONT].r, + lights[BT_IO_JB_RGB_LED_FRONT].g, + lights[BT_IO_JB_RGB_LED_FRONT].b, + lights[BT_IO_JB_RGB_LED_LEFT].r, + lights[BT_IO_JB_RGB_LED_RIGHT].r, + lights[BT_IO_JB_RGB_LED_LEFT].g, + lights[BT_IO_JB_RGB_LED_RIGHT].g, + lights[BT_IO_JB_RGB_LED_LEFT].b, + lights[BT_IO_JB_RGB_LED_TITLE].r, + lights[BT_IO_JB_RGB_LED_TITLE].g, + lights[BT_IO_JB_RGB_LED_TITLE].b, + lights[BT_IO_JB_RGB_LED_RIGHT].b, + lights[BT_IO_JB_RGB_LED_WOOFER].r, + lights[BT_IO_JB_RGB_LED_WOOFER].g, + lights[BT_IO_JB_RGB_LED_WOOFER].b, - IS_BIT_SET(input_sys, JB_IO_SYS_TEST), - IS_BIT_SET(input_sys, JB_IO_SYS_SERVICE), - IS_BIT_SET(input_sys, JB_IO_SYS_COIN), + IS_BIT_SET(input_sys, BT_IO_JB_SYS_TEST), + IS_BIT_SET(input_sys, BT_IO_JB_SYS_SERVICE), + IS_BIT_SET(input_sys, BT_IO_JB_SYS_COIN), - IS_BIT_SET(input_panel, JB_IO_PANEL_01), - IS_BIT_SET(input_panel, JB_IO_PANEL_02), - IS_BIT_SET(input_panel, JB_IO_PANEL_03), - IS_BIT_SET(input_panel, JB_IO_PANEL_04), - IS_BIT_SET(input_panel, JB_IO_PANEL_05), - IS_BIT_SET(input_panel, JB_IO_PANEL_06), - IS_BIT_SET(input_panel, JB_IO_PANEL_07), - IS_BIT_SET(input_panel, JB_IO_PANEL_08), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_01), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_02), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_03), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_04), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_05), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_06), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_07), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_08), top_left, top_right, all_text, - IS_BIT_SET(input_panel, JB_IO_PANEL_09), - IS_BIT_SET(input_panel, JB_IO_PANEL_10), - IS_BIT_SET(input_panel, JB_IO_PANEL_11), - IS_BIT_SET(input_panel, JB_IO_PANEL_12), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_09), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_10), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_11), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_12), bottom_left, bottom_right, - IS_BIT_SET(input_panel, JB_IO_PANEL_13), - IS_BIT_SET(input_panel, JB_IO_PANEL_14), - IS_BIT_SET(input_panel, JB_IO_PANEL_15), - IS_BIT_SET(input_panel, JB_IO_PANEL_16)); + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_13), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_14), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_15), + IS_BIT_SET(input_panel, BT_IO_JB_PANEL_16)); /* set outputs */ switch (light_mode) { @@ -214,11 +237,17 @@ int main(int argc, char **argv) } for (int i = 0; i < 6; i++) { - jb_io_set_rgb_led(i, lights[i].r, lights[i].g, lights[i].b); + bt_io_jb_rgb_led_set(i, lights[i].r, lights[i].g, lights[i].b); } - if (!jb_io_write_lights()) { + if (!bt_io_jb_lights_write()) { printf("ERROR: Writing outputs failed\n"); + + bt_io_jb_fini(); + + bt_io_jb_api_clear(); + module_io_free(&module_io_jb); + return -4; } @@ -245,10 +274,10 @@ int main(int argc, char **argv) case '1': { /* one last update to turn off the lights */ for (int i = 0; i < 6; i++) { - jb_io_set_rgb_led(i, 0, 0, 0); + bt_io_jb_rgb_led_set(i, 0, 0, 0); } - if (!jb_io_write_lights()) { + if (!bt_io_jb_lights_write()) { printf("ERROR: Writing outputs failed\n"); return -4; } @@ -275,8 +304,8 @@ int main(int argc, char **argv) case '5': { panel_corners_animate = !panel_corners_animate; if (!panel_corners_animate) { - panel_mode = JB_IO_PANEL_MODE_ALL; - jb_io_set_panel_mode(panel_mode); + panel_mode = BT_IO_JB_PANEL_MODE_ALL; + bt_io_jb_panel_mode_set(panel_mode); } break; } @@ -289,7 +318,11 @@ int main(int argc, char **argv) } system("cls"); - jb_io_fini(); + + bt_io_jb_fini(); + + bt_io_jb_api_clear(); + module_io_free(&module_io_jb); return 0; } diff --git a/src/main/launcher/Module.mk b/src/main/launcher/Module.mk index 32afa4c..5eceaca 100644 --- a/src/main/launcher/Module.mk +++ b/src/main/launcher/Module.mk @@ -4,20 +4,25 @@ rc_launcher := launcher.rc ldflags_launcher := \ -mconsole \ -ldbghelp \ + -lpsapi \ deplibs_launcher := \ avs \ avs-ea3 \ +avslibs_launcher := \ + avs-ext \ + libs_launcher := \ - avs-util \ - core \ hook \ util \ - dwarfstack \ - procmon-lib \ + iface-core \ + iface \ + module \ + core \ src_launcher := \ + app.c \ avs-config.c \ avs.c \ bootstrap-config.c \ @@ -26,13 +31,11 @@ src_launcher := \ ea3-ident-config.c \ eamuse-config.c \ eamuse.c \ - hook.c \ + hooks.c \ launcher-config.c \ launcher.c \ main.c \ - module.c \ options.c \ - property-util.c \ stubs.c \ version.c \ diff --git a/src/main/launcher/app.c b/src/main/launcher/app.c new file mode 100644 index 0000000..b1d9db5 --- /dev/null +++ b/src/main/launcher/app.c @@ -0,0 +1,312 @@ +#define LOG_MODULE "app" + +#include + +#include "avs-ext/property-node.h" + +#include "hook/pe.h" + +#include "iface-core/log.h" + +#include "launcher/app.h" + +#include "util/str.h" + +static bool _app_dependency_available(const char *lib) +{ + HMODULE module; + + module = LoadLibraryA(lib); + + if (module == NULL) { + return false; + } else { + FreeLibrary(module); + return true; + } +} + +HMODULE _app_load(const char *path, bool resolve_references) +{ + HMODULE module; + LPSTR buffer; + DWORD err; + + log_misc("Loading app module: %s", path); + + if (resolve_references) { + module = LoadLibraryA(path); + } else { + module = LoadLibraryExA(path, NULL, DONT_RESOLVE_DLL_REFERENCES); + } + + if (module == NULL) { + err = GetLastError(); + + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR) &buffer, + 0, + NULL); + + if (err == ERROR_MOD_NOT_FOUND) { + log_warning("%s is likely missing dependencies", path); + log_warning("Do you have vcredist/directx runtimes installed?"); + log_warning( + "Ensure the installed dependencies match the architecture, " + "32-bit/64-bit, of the game"); + log_warning( + "Running heuristic for commonly used libraries (actual " + "requirements depend on game)..."); + + if (_app_dependency_available("d3d9.dll")) { + log_warning("Could not find directx9 runtime"); + } + + if (_app_dependency_available("msvcr100.dll")) { + log_warning("Could not find vcredist 2010 runtime"); + } + + if (_app_dependency_available("msvcr120.dll")) { + log_warning("Could not find vcredist 2013 runtime"); + } + + if (_app_dependency_available("msvcp140.dll")) { + log_warning("Could not find vcredist 2015 runtime"); + } + } + + log_fatal("%s: Failed to load app module: %s", path, buffer); + + LocalFree(buffer); + } + + log_misc("Loading app module done"); + + return module; +} + +static void _app_api_resolve(app_t *app) +{ + log_assert(app); + + app->init = + (dll_entry_init_t) GetProcAddress(app->module, "dll_entry_init"); + + if (!app->init) { + log_fatal( + "%s (%p): 'dll_entry_init' not found. Is this a game DLL?", + app->path, + app->module); + } + + app->main = + (dll_entry_main_t) GetProcAddress(app->module, "dll_entry_main"); + + if (!app->main) { + log_fatal( + "%s (%p): dll_entry_main not found. Is this a game DLL?", + app->path, + app->module); + } +} + +void app_load(const char *path, app_t *app) +{ + log_assert(path != NULL); + log_assert(app != NULL); + + log_info("%s: load", path); + + str_cpy(app->path, sizeof(app->path), path); + app->module = _app_load(path, true); + + _app_api_resolve(app); + + log_misc("%s (%p): loaded", app->path, app->module); +} + +void app_unresolved_load(const char *path, app_t *app) +{ + log_assert(path != NULL); + log_assert(app != NULL); + + log_info("%s: unresolved load", path); + + str_cpy(app->path, sizeof(app->path), path); + app->module = _app_load(path, false); + _app_api_resolve(app); + + log_misc("%s (%p): unresolved loaded", app->path, app->module); +} + +HMODULE app_module_handle_get(const app_t *app) +{ + log_assert(app); + + return app->module; +} + +void app_resolve(const app_t *app) +{ + log_assert(app); + + log_info("%s (%p) resolving", app->path, app->module); + // Resolve all imports like a normally loaded DLL + pe_resolve_imports(app->module); + + dll_entry_t orig_entry = pe_get_entry_point(app->module); + + log_misc("%s (%p): >>> DllMain"); + + orig_entry(app->module, DLL_PROCESS_ATTACH, NULL); + + log_misc("%s (%p): <<< DllMain"); + + log_misc("%s (%p) resolved", app->path, app->module); +} + +void app_init_invoke( + const app_t *app, + struct ea3_ident_config *ea3_ident_config, + const core_property_node_t *app_params_node) +{ + char sidcode_short[17]; + char sidcode_long[21]; + char security_code[9]; + struct property_node *app_params_node_avs; + bool ok; + + log_info("%s (%p): init invoke", app->path, app->module); + + /* Set up security env vars */ + + str_format( + security_code, + lengthof(security_code), + "G*%s%s%s%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev); + + log_misc("security code: %s", security_code); + + std_setenv("/env/boot/version", "0.0.0"); + std_setenv("/env/profile/security_code", security_code); + std_setenv("/env/profile/system_id", ea3_ident_config->pcbid); + std_setenv("/env/profile/account_id", ea3_ident_config->pcbid); + std_setenv("/env/profile/license_id", ea3_ident_config->softid); + std_setenv("/env/profile/software_id", ea3_ident_config->softid); + std_setenv("/env/profile/hardware_id", ea3_ident_config->hardid); + + /* Set up the short sidcode string, let dll_entry_init mangle it */ + + str_format( + sidcode_short, + lengthof(sidcode_short), + "%s%s%s%s%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev, + ea3_ident_config->ext); + + log_misc("sidcode short: %s", sidcode_short); + + /* Set up long-form sidcode env var */ + + str_format( + sidcode_long, + lengthof(sidcode_long), + "%s:%s:%s:%s:%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev, + ea3_ident_config->ext); + + log_misc("sidecode long: %s", sidcode_long); + + /* Set this up beforehand, as certain games require it in dll_entry_init */ + + std_setenv("/env/profile/soft_id_code", sidcode_long); + + log_info("Invoking game init..."); + + log_misc("%s (%p) >>> init", app->path, app->module); + + app_params_node_avs = + avs_ext_property_node_avs_property_node_get(app_params_node); + + ok = app->init(sidcode_short, app_params_node_avs); + + log_misc("%s (%p) <<< init: %d", app->path, app->module, ok); + + if (!ok) { + log_fatal("%s: dll_entry_init_t() returned failure", app->path); + } + + /* Back-propagate sidcode, as some games modify it during init */ + + memcpy( + ea3_ident_config->model, + sidcode_short + 0, + sizeof(ea3_ident_config->model) - 1); + ea3_ident_config->dest[0] = sidcode_short[3]; + ea3_ident_config->spec[0] = sidcode_short[4]; + ea3_ident_config->rev[0] = sidcode_short[5]; + memcpy( + ea3_ident_config->ext, + sidcode_short + 6, + sizeof(ea3_ident_config->ext)); + + /* Set up long-form sidcode env var again */ + + str_format( + sidcode_long, + lengthof(sidcode_long), + "%s:%s:%s:%s:%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev, + ea3_ident_config->ext); + + std_setenv("/env/profile/soft_id_code", sidcode_long); + + log_misc("back-propagated sidcode long: %s", sidcode_long); + + log_misc("%s (%p): init invoked", app->path, app->module); +} + +bool app_main_invoke(const app_t *app) +{ + bool result; + + log_assert(app != NULL); + + log_info("%s (%p): main invoke", app->path, app->module); + + log_misc("%s (%p) >>> main", app->path, app->module); + + result = app->main(); + + log_misc("%s (%p) <<< main: %d", app->path, app->module, result); + + return result; +} + +void app_free(app_t *app) +{ + log_assert(app); + + log_misc("%s (%p): free", app->path, app->module); + + FreeLibrary(app->module); + memset(app, 0, sizeof(app_t)); +} diff --git a/src/main/launcher/app.h b/src/main/launcher/app.h new file mode 100644 index 0000000..c97fee7 --- /dev/null +++ b/src/main/launcher/app.h @@ -0,0 +1,30 @@ +#ifndef LAUNCHER_APP_H +#define LAUNCHER_APP_H + +#include + +#include "core/property-node.h" + +#include "imports/eapki.h" + +#include "launcher/ea3-ident-config.h" + +typedef struct app { + char path[MAX_PATH]; + HMODULE module; + dll_entry_init_t init; + dll_entry_main_t main; +} app_t; + +void app_load(const char *path, app_t *app); +void app_unresolved_load(const char *path, app_t *app); +HMODULE app_module_handle_get(const app_t *app); +void app_resolve(const app_t *app); +void app_init_invoke( + const app_t *app, + struct ea3_ident_config *ea3_ident_config, + const core_property_node_t *app_params_node); +bool app_main_invoke(const app_t *app); +void app_free(app_t *app); + +#endif diff --git a/src/main/launcher/avs-config.c b/src/main/launcher/avs-config.c index 8669f3d..ed89020 100644 --- a/src/main/launcher/avs-config.c +++ b/src/main/launcher/avs-config.c @@ -2,14 +2,15 @@ #include -#include "avs-util/error.h" +#include "avs-ext/error.h" -#include "core/log.h" +#include "iface-core/log.h" -#include "imports/avs.h" +#include "core/property-node-ext.h" +#include "core/property-node.h" +#include "core/property.h" #include "launcher/avs-config.h" -#include "launcher/property-util.h" #include "util/str.h" @@ -19,9 +20,7 @@ static const char *_avs_config_property_mounttable_path = "/config/fs/mounttable"; static void _avs_config_node_vfs_copy( - struct property *parent_property, - struct property_node *parent, - struct property_node *source) + core_property_node_t *parent, const core_property_node_t *source) { // Use max path size to fit dst and src fs paths char data[MAX_PATH]; @@ -34,118 +33,123 @@ static void _avs_config_node_vfs_copy( // Ignore errors and default to empty memset(data, 0, sizeof(data)); - property_node_refer( - NULL, source, "name@", PROPERTY_TYPE_ATTR, data, sizeof(data)); - property_util_node_attribute_replace( - parent_property, parent, "name@", data); + core_property_node_ext_attr_read(source, "name@", data, sizeof(data)); + core_property_node_ext_attr_replace(parent, "name@", data); memset(data, 0, sizeof(data)); - property_node_refer( - NULL, source, "fstype@", PROPERTY_TYPE_ATTR, data, sizeof(data)); - property_util_node_attribute_replace( - parent_property, parent, "fstype@", data); + core_property_node_ext_attr_read(source, "fstype@", data, sizeof(data)); + core_property_node_ext_attr_replace(parent, "fstype@", data); memset(data, 0, sizeof(data)); - property_node_refer( - NULL, source, "src@", PROPERTY_TYPE_ATTR, data, sizeof(data)); - property_util_node_attribute_replace(parent_property, parent, "src@", data); + core_property_node_ext_attr_read(source, "src@", data, sizeof(data)); + core_property_node_ext_attr_replace(parent, "src@", data); memset(data, 0, sizeof(data)); - property_node_refer( - NULL, source, "dst@", PROPERTY_TYPE_ATTR, data, sizeof(data)); - property_util_node_attribute_replace(parent_property, parent, "dst@", data); + core_property_node_ext_attr_read(source, "dst@", data, sizeof(data)); + core_property_node_ext_attr_replace(parent, "dst@", data); memset(data, 0, sizeof(data)); - property_node_refer( - NULL, source, "opt@", PROPERTY_TYPE_ATTR, data, sizeof(data)); - property_util_node_attribute_replace(parent_property, parent, "opt@", data); + core_property_node_ext_attr_read(source, "opt@", data, sizeof(data)); + core_property_node_ext_attr_replace(parent, "opt@", data); } -static bool _avs_config_mounttable_vfs_nodes_merge_strategy_do( - struct property *parent_property, - struct property_node *parent, - struct property_node *source, +static core_property_node_result_t +_avs_config_mounttable_vfs_nodes_merge_strategy_do( + core_property_node_t *parent, + const core_property_node_t *source, void *ctx, - property_util_node_merge_recursion_do_t node_merge_recursion_do) + bool *consumed, + core_property_node_ext_merge_recursion_do_t node_merge_recursion_do) { - struct property_node *parent_child; - struct property_node *source_child; + core_property_node_t parent_child; + core_property_node_t tmp; + core_property_node_t source_child; + core_property_node_result_t result; - char parent_child_name[PROPERTY_NODE_NAME_SIZE_MAX]; - char name_parent[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; - char dst_parent[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + char parent_child_name[CORE_PROPERTY_NODE_NAME_SIZE_MAX]; + char name_parent[CORE_PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + char dst_parent[CORE_PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; - char source_child_name[PROPERTY_NODE_NAME_SIZE_MAX]; - char name_source[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; - char dst_source[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + char source_child_name[CORE_PROPERTY_NODE_NAME_SIZE_MAX]; + char name_source[CORE_PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + char dst_source[CORE_PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; - bool node_consumed; bool found_parent; - source_child = property_node_traversal(source, TRAVERSE_FIRST_CHILD); + result = core_property_node_child_get(source, &source_child); - node_consumed = false; + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + return CORE_PROPERTY_NODE_RESULT_SUCCESS; + } - while (source_child) { - property_node_name( - source_child, source_child_name, sizeof(source_child_name)); + if (result != CORE_PROPERTY_NODE_RESULT_SUCCESS) { + core_property_node_fatal_on_error(result); + } + + *consumed = false; + + while (result == CORE_PROPERTY_NODE_RESULT_SUCCESS) { + result = core_property_node_name_get( + &source_child, source_child_name, sizeof(source_child_name)); + core_property_node_fatal_on_error(result); if (str_eq(source_child_name, "vfs")) { - node_consumed = true; + *consumed = true; - parent_child = - property_node_traversal(parent, TRAVERSE_FIRST_CHILD); + result = core_property_node_child_get(parent, &parent_child); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND || + result != CORE_PROPERTY_NODE_RESULT_SUCCESS) { + core_property_node_fatal_on_error(result); + } found_parent = false; - while (parent_child) { - property_node_name( - parent_child, parent_child_name, sizeof(parent_child_name)); + while (result == CORE_PROPERTY_NODE_RESULT_SUCCESS) { + result = core_property_node_name_get( + &parent_child, + parent_child_name, + sizeof(parent_child_name)); + core_property_node_fatal_on_error(result); if (str_eq(parent_child_name, "vfs")) { - if (AVS_IS_ERROR(property_node_refer( - NULL, - source_child, - "name@", - PROPERTY_TYPE_ATTR, - name_source, - sizeof(name_source)))) { + result = core_property_node_ext_attr_read( + &source_child, + "name@", + name_source, + sizeof(name_source)); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { log_fatal( "Missing 'name' attribute on avs config mounttable " "vfs source node"); } - if (AVS_IS_ERROR(property_node_refer( - NULL, - source_child, - "dst@", - PROPERTY_TYPE_ATTR, - dst_source, - sizeof(dst_source)))) { + result = core_property_node_ext_attr_read( + &source_child, "dst@", dst_source, sizeof(dst_source)); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { log_fatal( "Missing 'dst' attribute on avs config mounttable " "vfs source node"); } - if (AVS_IS_ERROR(property_node_refer( - NULL, - parent_child, - "name@", - PROPERTY_TYPE_ATTR, - name_parent, - sizeof(name_parent)))) { + result = core_property_node_ext_attr_read( + &parent_child, + "name@", + name_parent, + sizeof(name_parent)); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { log_fatal( "Missing 'name' attribute on avs config mounttable " "vfs parent node"); } - if (AVS_IS_ERROR(property_node_refer( - NULL, - parent_child, - "dst@", - PROPERTY_TYPE_ATTR, - dst_parent, - sizeof(dst_parent)))) { + result = core_property_node_ext_attr_read( + &parent_child, "dst@", dst_parent, sizeof(dst_parent)); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { log_fatal( "Missing 'dst' attribute on avs config mounttable " "vfs parent node"); @@ -154,71 +158,91 @@ static bool _avs_config_mounttable_vfs_nodes_merge_strategy_do( // Found existing matching node on parent, replace it if (str_eq(name_source, name_parent) && str_eq(dst_source, dst_parent)) { - _avs_config_node_vfs_copy( - parent_property, parent_child, source_child); + _avs_config_node_vfs_copy(&parent_child, &source_child); found_parent = true; break; } } - parent_child = property_node_traversal( - parent_child, TRAVERSE_NEXT_SIBLING); + result = + core_property_node_next_sibling_get(&parent_child, &tmp); + memcpy(&parent_child, &tmp, sizeof(core_property_node_t)); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } } // Not found an existing node that got replaced, insert/merge new // data if (!found_parent) { - parent_child = property_node_create( - parent_property, parent, PROPERTY_TYPE_VOID, "vfs"); + result = core_property_node_void_create( + parent, "vfs", &parent_child); + core_property_node_fatal_on_error(result); - _avs_config_node_vfs_copy( - parent_property, parent_child, source_child); + _avs_config_node_vfs_copy(&parent_child, &source_child); } } - source_child = - property_node_traversal(source_child, TRAVERSE_NEXT_SIBLING); + result = core_property_node_next_sibling_get(&source_child, &tmp); + memcpy(&source_child, &tmp, sizeof(core_property_node_t)); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } } - return node_consumed; + return CORE_PROPERTY_NODE_RESULT_SUCCESS; } -struct property *avs_config_load(const char *filepath) +core_property_t *avs_config_load(const char *filepath) { - struct property *property; + core_property_t *property; + core_property_result_t result; + core_property_node_t node; log_assert(filepath); log_info("Loading from file path: %s", filepath); - property = property_util_load(filepath); + result = core_property_file_load(filepath, &property); + core_property_fatal_on_error(result); // Check if root node exists, call already errors if not - avs_config_root_get(property); + avs_config_root_get(property, &node); return property; } -struct property_node *avs_config_root_get(struct property *property) +void avs_config_root_get( + const core_property_t *property, core_property_node_t *node) { - struct property_node *node; + core_property_node_result_t result; + char node_name[128]; log_assert(property); + log_assert(node); - node = property_search(property, 0, AVS_CONFIG_ROOT_NODE); + result = core_property_root_node_get(property, node); + core_property_fatal_on_error(result); - if (node == NULL) { + result = core_property_node_name_get(node, node_name, sizeof(node_name)); + core_property_node_fatal_on_error(result); + + if (!str_eq(node_name, "config")) { log_fatal("Root node " AVS_CONFIG_ROOT_NODE " in AVS config missing"); + } else { + core_property_node_fatal_on_error(result); } - - return node; } -struct property * -avs_config_property_merge(struct property *parent, struct property *source) +core_property_t *avs_config_property_merge( + const core_property_t *parent, const core_property_t *source) { - struct property_util_node_merge_strategies strategies; + core_property_node_ext_merge_strategies_t strategies; + core_property_t *merged; + core_property_node_result_t result; log_assert(parent); log_assert(source); @@ -231,81 +255,111 @@ avs_config_property_merge(struct property *parent, struct property *source) strategies.entry[1].path = ""; strategies.entry[1].merge_strategy_do = - property_util_node_merge_default_strategy_do; + core_property_node_ext_merge_strategy_default_do; - return property_util_merge_with_strategies(parent, source, &strategies); + result = core_property_node_ext_merge_with_strategies_do( + parent, source, &strategies, &merged); + core_property_node_fatal_on_error(result); + + return merged; } void avs_config_fs_root_device_get( - struct property_node *node, char *buffer, size_t size) + const core_property_node_t *node, char *buffer, size_t size) { - struct property_node *device_node; - avs_error error; + core_property_node_t device_node; + core_property_node_result_t result; log_assert(node); + log_assert(buffer); + log_assert(size > 0); - device_node = property_search(NULL, node, "fs/root/device"); + result = core_property_node_search(node, "fs/root/device", &device_node); - if (device_node == NULL) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal("Could not find node fs/root/device AVS config"); + } else { + core_property_node_fatal_on_error(result); } - error = property_node_read(device_node, PROPERTY_TYPE_STR, buffer, size); + result = core_property_node_str_read(&device_node, buffer, size); - if (AVS_IS_ERROR(error)) { + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { log_fatal( "fs/root/device, property read failed: %s", - avs_util_error_str(error)); + core_property_node_result_to_str(result)); } } -void avs_config_mode_product_set(struct property_node *node, bool enable) +void avs_config_mode_product_set(core_property_node_t *node, bool enable) { + core_property_node_result_t result; + log_assert(node); #if AVS_VERSION <= 1306 - property_util_node_u8_replace(NULL, node, "mode/product", enable ? 1 : 0); + result = + core_property_node_ext_u8_replace(node, "mode/product", enable ? 1 : 0); + core_property_node_fatal_on_error(result); #else - property_util_node_bool_replace(NULL, node, "mode/product", enable); + result = core_property_node_ext_bool_replace(node, "mode/product", enable); + core_property_node_fatal_on_error(result); #endif } -void avs_config_net_raw_set(struct property_node *node, bool enable) +void avs_config_net_raw_set(core_property_node_t *node, bool enable) { + core_property_node_result_t result; + log_assert(node); #if AVS_VERSION <= 1306 - property_util_node_u8_replace(NULL, node, "net/enable_raw", enable ? 1 : 0); + result = core_property_node_ext_u8_replace( + node, "net/enable_raw", enable ? 1 : 0); + core_property_node_fatal_on_error(result); #else - property_util_node_bool_replace(NULL, node, "net/enable_raw", enable); + result = + core_property_node_ext_bool_replace(node, "net/enable_raw", enable); + core_property_node_fatal_on_error(result); #endif } -void avs_config_net_eaudp_set(struct property_node *node, bool enable) +void avs_config_net_eaudp_set(core_property_node_t *node, bool enable) { + core_property_node_result_t result; + log_assert(node); #if AVS_VERSION <= 1306 - property_util_node_u8_replace( - NULL, node, "net/eaudp/enable", enable ? 1 : 0); + result = core_property_node_ext_u8_replace( + node, "net/eaudp/enable", enable ? 1 : 0); + core_property_node_fatal_on_error(result); #else - property_util_node_bool_replace(NULL, node, "net/eaudp/enable", enable); + result = + core_property_node_ext_bool_replace(node, "net/eaudp/enable", enable); + core_property_node_fatal_on_error(result); #endif } -void avs_config_sntp_ea_set(struct property_node *node, bool on) +void avs_config_sntp_ea_set(core_property_node_t *node, bool on) { + core_property_node_result_t result; + log_assert(node); #if AVS_VERSION <= 1306 - property_util_node_u8_replace(NULL, node, "sntp/ea_on", on ? 1 : 0); + result = core_property_node_ext_u8_replace(node, "sntp/ea_on", on ? 1 : 0); + core_property_node_fatal_on_error(result); #else - property_util_node_bool_replace(NULL, node, "sntp/ea_on", on); + result = core_property_node_ext_bool_replace(node, "sntp/ea_on", on); + core_property_node_fatal_on_error(result); #endif } -void avs_config_log_level_set(struct property_node *node, const char *level) +void avs_config_log_level_set(core_property_node_t *node, const char *level) { + core_property_node_result_t result; + log_assert(node); log_assert(level); @@ -330,122 +384,170 @@ void avs_config_log_level_set(struct property_node *node, const char *level) log_fatal("Unknown log level string %s", level); } - property_util_node_u32_replace(NULL, node, "log/level", level_value); + result = core_property_node_ext_u32_replace(node, "log/level", level_value); + core_property_node_fatal_on_error(result); #else - property_util_node_str_replace(NULL, node, "log/level", level); + result = core_property_node_ext_str_replace(node, "log/level", level); + core_property_node_fatal_on_error(result); #endif } -void avs_config_log_name_set(struct property_node *node, const char *name) +void avs_config_log_name_set(core_property_node_t *node, const char *name) { + core_property_node_result_t result; + log_assert(node); log_assert(name); - property_util_node_str_replace(NULL, node, "log/name", name); + result = core_property_node_ext_str_replace(node, "log/name", name); + core_property_node_fatal_on_error(result); } -void avs_config_log_file_set(struct property_node *node, const char *file) +void avs_config_log_file_set(core_property_node_t *node, const char *file) { + core_property_node_result_t result; + log_assert(node); log_assert(file); - property_util_node_str_replace(NULL, node, "log/file", file); + result = core_property_node_ext_str_replace(node, "log/file", file); + core_property_node_fatal_on_error(result); } -void avs_config_log_buffer_size_set(struct property_node *node, uint32_t size) +void avs_config_log_buffer_size_set(core_property_node_t *node, uint32_t size) { + core_property_node_result_t result; + log_assert(node); - property_util_node_u32_replace(NULL, node, "log/sz_buf", size); + result = core_property_node_ext_u32_replace(node, "log/sz_buf", size); + core_property_node_fatal_on_error(result); } void avs_config_log_output_delay_set( - struct property_node *node, uint16_t delay_ms) + core_property_node_t *node, uint16_t delay_ms) { + core_property_node_result_t result; + log_assert(node); - property_util_node_u16_replace(NULL, node, "log/output_delay", delay_ms); + result = + core_property_node_ext_u16_replace(node, "log/output_delay", delay_ms); + core_property_node_fatal_on_error(result); } -void avs_config_log_enable_console_set(struct property_node *node, bool enable) +void avs_config_log_enable_console_set(core_property_node_t *node, bool enable) { + core_property_node_result_t result; + log_assert(node); #if AVS_VERSION <= 1306 - property_util_node_u8_replace( - NULL, node, "log/enable_console", enable ? 1 : 0); + result = core_property_node_ext_u8_replace( + node, "log/enable_console", enable ? 1 : 0); + core_property_node_fatal_on_error(result); #else - property_util_node_bool_replace(NULL, node, "log/enable_console", enable); + result = + core_property_node_ext_bool_replace(node, "log/enable_console", enable); + core_property_node_fatal_on_error(result); #endif } -void avs_config_log_enable_sci_set(struct property_node *node, bool enable) +void avs_config_log_enable_sci_set(core_property_node_t *node, bool enable) { + core_property_node_result_t result; + log_assert(node); #if AVS_VERSION <= 1306 - property_util_node_u8_replace( - NULL, node, "log/enable_netsci", enable ? 1 : 0); + result = core_property_node_ext_u8_replace( + node, "log/enable_netsci", enable ? 1 : 0); + core_property_node_fatal_on_error(result); #else - property_util_node_bool_replace(NULL, node, "log/enable_netsci", enable); + result = + core_property_node_ext_bool_replace(node, "log/enable_netsci", enable); + core_property_node_fatal_on_error(result); #endif } -void avs_config_log_enable_net_set(struct property_node *node, bool enable) +void avs_config_log_enable_net_set(core_property_node_t *node, bool enable) { + core_property_node_result_t result; + log_assert(node); #if AVS_VERSION <= 1306 - property_util_node_u8_replace( - NULL, node, "log/enable_netlog", enable ? 1 : 0); + result = core_property_node_ext_u8_replace( + node, "log/enable_netlog", enable ? 1 : 0); + core_property_node_fatal_on_error(result); #else - property_util_node_bool_replace(NULL, node, "log/enable_netlog", enable); + result = + core_property_node_ext_bool_replace(node, "log/enable_netlog", enable); + core_property_node_fatal_on_error(result); #endif } -void avs_config_log_enable_file_set(struct property_node *node, bool enable) +void avs_config_log_enable_file_set(core_property_node_t *node, bool enable) { + core_property_node_result_t result; + log_assert(node); #if AVS_VERSION <= 1306 - property_util_node_u8_replace( - NULL, node, "log/enable_file", enable ? 1 : 0); + result = core_property_node_ext_u8_replace( + node, "log/enable_file", enable ? 1 : 0); + core_property_node_fatal_on_error(result); #else - property_util_node_bool_replace(NULL, node, "log/enable_file", enable); + result = + core_property_node_ext_bool_replace(node, "log/enable_file", enable); + core_property_node_fatal_on_error(result); #endif } -void avs_config_log_rotate_set(struct property_node *node, bool rotate) +void avs_config_log_rotate_set(core_property_node_t *node, bool rotate) { + core_property_node_result_t result; + log_assert(node); #if AVS_VERSION <= 1306 - property_util_node_u8_replace(NULL, node, "log/rotate", rotate ? 1 : 0); + result = + core_property_node_ext_u8_replace(node, "log/rotate", rotate ? 1 : 0); + core_property_node_fatal_on_error(result); #else - property_util_node_bool_replace(NULL, node, "log/rotate", rotate); + result = core_property_node_ext_bool_replace(node, "log/rotate", rotate); + core_property_node_fatal_on_error(result); #endif } -void avs_config_log_append_set(struct property_node *node, bool append) +void avs_config_log_append_set(core_property_node_t *node, bool append) { + core_property_node_result_t result; + log_assert(node); #if AVS_VERSION <= 1306 - property_util_node_u8_replace(NULL, node, "log/append", append ? 1 : 0); + result = + core_property_node_ext_u8_replace(node, "log/append", append ? 1 : 0); + core_property_node_fatal_on_error(result); #else - property_util_node_bool_replace(NULL, node, "log/append", append); + result = core_property_node_ext_bool_replace(node, "log/append", append); + core_property_node_fatal_on_error(result); #endif } -void avs_config_log_count_set(struct property_node *node, uint16_t count) +void avs_config_log_count_set(core_property_node_t *node, uint16_t count) { + core_property_node_result_t result; + log_assert(node); - property_util_node_u16_replace(NULL, node, "log/gen", count); + result = core_property_node_ext_u16_replace(node, "log/gen", count); + core_property_node_fatal_on_error(result); } void avs_config_set_log_level( - struct property_node *node, enum core_log_bt_log_level loglevel) + core_property_node_t *node, enum core_log_bt_log_level loglevel) { const char *str; @@ -481,14 +583,16 @@ void avs_config_set_log_level( } void avs_config_local_fs_path_dev_nvram_and_raw_set( - struct property_node *node, const char *dev_nvram_raw_path) + core_property_node_t *node, const char *dev_nvram_raw_path) { char path_dev_raw[MAX_PATH]; char path_dev_nvram[MAX_PATH]; - struct property_node *fs_node; - struct property_node *mounttable_node; - struct property_node *vfs_node; + core_property_node_t fs_node; + core_property_node_t mounttable_node; + core_property_node_t vfs_node; + core_property_node_t tmp_node; + core_property_node_result_t result; log_assert(node); log_assert(dev_nvram_raw_path); @@ -499,68 +603,101 @@ void avs_config_local_fs_path_dev_nvram_and_raw_set( str_cpy(path_dev_nvram, sizeof(path_dev_nvram), dev_nvram_raw_path); str_cat(path_dev_nvram, sizeof(path_dev_nvram), "/dev/nvram"); - fs_node = property_search(NULL, node, "fs"); + result = core_property_node_search(node, "fs", &fs_node); - if (!fs_node) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal("Cannot find 'fs' node in avs config"); + } else { + core_property_node_fatal_on_error(result); } // Check if "new" mounttable config is used for dev/nvram and dev/raw or // legacy config - if (property_search(NULL, fs_node, "mounttable")) { - property_remove(NULL, fs_node, "mounttable"); + result = + core_property_node_search(&fs_node, "mounttable", &mounttable_node); - mounttable_node = property_node_create( - NULL, fs_node, PROPERTY_TYPE_VOID, "mounttable"); + if (result == CORE_PROPERTY_NODE_RESULT_SUCCESS) { + result = core_property_node_remove(&mounttable_node); + core_property_node_fatal_on_error(result); - vfs_node = property_node_create( - NULL, mounttable_node, PROPERTY_TYPE_VOID, "vfs"); + result = core_property_node_void_create( + &fs_node, "mounttable", &mounttable_node); + core_property_node_fatal_on_error(result); - property_node_create( - NULL, vfs_node, PROPERTY_TYPE_ATTR, "name", "boot"); - property_node_create( - NULL, vfs_node, PROPERTY_TYPE_ATTR, "fstype", "fs"); - property_node_create( - NULL, vfs_node, PROPERTY_TYPE_ATTR, "src", path_dev_raw); - property_node_create( - NULL, vfs_node, PROPERTY_TYPE_ATTR, "dest", "/dev/raw"); - property_node_create( - NULL, vfs_node, PROPERTY_TYPE_ATTR, "opt", "vf=1,posix=1"); + result = + core_property_node_void_create(&mounttable_node, "vfs", &vfs_node); + core_property_node_fatal_on_error(result); - vfs_node = property_node_create( - NULL, mounttable_node, PROPERTY_TYPE_VOID, "vfs"); + result = core_property_node_attr_create( + &vfs_node, "name", "boot", &tmp_node); + core_property_node_fatal_on_error(result); + result = core_property_node_attr_create( + &vfs_node, "fstype", "fs", &tmp_node); + core_property_node_fatal_on_error(result); + result = core_property_node_attr_create( + &vfs_node, "src", path_dev_raw, &tmp_node); + core_property_node_fatal_on_error(result); + result = core_property_node_attr_create( + &vfs_node, "dest", "/dev/raw", &tmp_node); + core_property_node_fatal_on_error(result); + result = core_property_node_attr_create( + &vfs_node, "opt", "vf=1,posix=1", &tmp_node); + core_property_node_fatal_on_error(result); - property_node_create( - NULL, vfs_node, PROPERTY_TYPE_ATTR, "name", "boot"); - property_node_create( - NULL, vfs_node, PROPERTY_TYPE_ATTR, "fstype", "fs"); - property_node_create( - NULL, vfs_node, PROPERTY_TYPE_ATTR, "src", path_dev_nvram); - property_node_create( - NULL, vfs_node, PROPERTY_TYPE_ATTR, "dest", "/dev/nvram"); - property_node_create( - NULL, vfs_node, PROPERTY_TYPE_ATTR, "opt", "vf=1,posix=1"); + result = + core_property_node_void_create(&mounttable_node, "vfs", &vfs_node); + core_property_node_fatal_on_error(result); + + result = core_property_node_attr_create( + &vfs_node, "name", "boot", &tmp_node); + core_property_node_fatal_on_error(result); + result = core_property_node_attr_create( + &vfs_node, "fstype", "fs", &tmp_node); + core_property_node_fatal_on_error(result); + result = core_property_node_attr_create( + &vfs_node, "src", path_dev_nvram, &tmp_node); + core_property_node_fatal_on_error(result); + result = core_property_node_attr_create( + &vfs_node, "dest", "/dev/nvram", &tmp_node); + core_property_node_fatal_on_error(result); + result = core_property_node_attr_create( + &vfs_node, "opt", "vf=1,posix=1", &tmp_node); + core_property_node_fatal_on_error(result); + } else if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + result = core_property_node_ext_str_replace( + &fs_node, "nvram/device", path_dev_nvram); + core_property_node_fatal_on_error(result); + result = + core_property_node_ext_str_replace(&fs_node, "nvram/fstype", "fs"); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_replace( + &fs_node, "nvram/option", "vf=1,posix=1"); + core_property_node_fatal_on_error(result); + + result = core_property_node_ext_str_replace( + &fs_node, "raw/device", path_dev_raw); + core_property_node_fatal_on_error(result); + result = + core_property_node_ext_str_replace(&fs_node, "raw/fstype", "fs"); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_replace( + &fs_node, "raw/option", "vf=1,posix=1"); + core_property_node_fatal_on_error(result); } else { - property_util_node_str_replace( - NULL, fs_node, "nvram/device", path_dev_raw); - property_util_node_str_replace(NULL, fs_node, "nvram/fstype", "fs"); - property_util_node_str_replace( - NULL, fs_node, "nvram/option", "vf=1,posix=1"); - - property_util_node_str_replace( - NULL, fs_node, "raw/device", path_dev_nvram); - property_util_node_str_replace(NULL, fs_node, "raw/fstype", "fs"); - property_util_node_str_replace( - NULL, fs_node, "raw/option", "vf=1,posix=1"); + core_property_node_fatal_on_error(result); } } void avs_config_vfs_mounttable_get( - struct property_node *node, struct avs_config_vfs_mounttable *mounttable) + const core_property_node_t *node, + struct avs_config_vfs_mounttable *mounttable) { - struct property_node *fs_node; - struct property_node *mounttable_node; - struct property_node *cur; + core_property_node_t fs_node; + core_property_node_t mounttable_node; + core_property_node_t cur; + core_property_node_t tmp; + core_property_node_result_t result; + char mounttable_selector[128]; char name[128]; uint8_t pos; @@ -568,40 +705,50 @@ void avs_config_vfs_mounttable_get( log_assert(node); log_assert(mounttable); - fs_node = property_search(NULL, node, "fs"); + result = core_property_node_search(node, "fs", &fs_node); - if (!fs_node) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal("Cannot find 'fs' node in avs config"); + } else { + core_property_node_fatal_on_error(result); } // Check if new mounttable config is used for dev/nvram and dev/raw or // legacy config - mounttable_node = property_search(NULL, fs_node, "mounttable"); + result = + core_property_node_search(&fs_node, "mounttable", &mounttable_node); memset(mounttable, 0, sizeof(*mounttable)); pos = 0; - if (mounttable_node) { - cur = property_search(NULL, fs_node, "mounttable_selector"); + if (result == CORE_PROPERTY_NODE_RESULT_SUCCESS) { + result = + core_property_node_search(&fs_node, "mounttable_selector", &cur); - if (!cur) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal("Missing 'mounttable_selector' on mounttable"); + } else { + core_property_node_fatal_on_error(result); } - if (AVS_IS_ERROR(property_node_read( - cur, - PROPERTY_TYPE_STR, - mounttable_selector, - sizeof(mounttable_selector)))) { + result = core_property_node_str_read( + &cur, mounttable_selector, sizeof(mounttable_selector)); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { log_fatal("Reading 'mounttable_selector' failed"); } log_misc("Mounttable selector: %s", mounttable_selector); - cur = property_node_traversal(mounttable_node, TRAVERSE_FIRST_CHILD); + result = core_property_node_child_get(&mounttable_node, &cur); - while (cur) { - property_node_name(cur, name, sizeof(name)); + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } + + while (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + result = core_property_node_name_get(&cur, name, sizeof(name)); + core_property_node_fatal_on_error(result); if (str_eq(name, "vfs")) { if (pos >= AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES) { @@ -612,97 +759,113 @@ void avs_config_vfs_mounttable_get( break; } - if (AVS_IS_ERROR(property_node_refer( - NULL, - cur, - "name@", - PROPERTY_TYPE_ATTR, - name, - sizeof(name)))) { + result = core_property_node_ext_attr_read( + &cur, "name@", name, sizeof(name)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal("Missing 'name' attribute on vfs node"); + } else { + core_property_node_fatal_on_error(result); } if (str_eq(name, mounttable_selector)) { - if (AVS_IS_ERROR(property_node_refer( - NULL, - cur, - "fstype@", - PROPERTY_TYPE_ATTR, - mounttable->entry[pos].fstype, - sizeof(mounttable->entry[pos].fstype)))) { + result = core_property_node_ext_attr_read( + &cur, + "fstype@", + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { // default str_cpy( mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype), "fs"); + } else { + core_property_node_fatal_on_error(result); } - if (AVS_IS_ERROR(property_node_refer( - NULL, - cur, - "src@", - PROPERTY_TYPE_ATTR, - mounttable->entry[pos].src, - sizeof(mounttable->entry[pos].src)))) { + result = core_property_node_ext_attr_read( + &cur, + "src@", + mounttable->entry[pos].src, + sizeof(mounttable->entry[pos].src)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal( "Missing 'src' attribute on vfs node, name: %s", name); + } else { + core_property_node_fatal_on_error(result); } - if (AVS_IS_ERROR(property_node_refer( - NULL, - cur, - "dst@", - PROPERTY_TYPE_ATTR, - mounttable->entry[pos].dst, - sizeof(mounttable->entry[pos].dst)))) { + result = core_property_node_ext_attr_read( + &cur, + "dst@", + mounttable->entry[pos].dst, + sizeof(mounttable->entry[pos].dst)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal( "Missing 'dst' attribute on vfs node, name: %s", name); + } else { + core_property_node_fatal_on_error(result); } - if (AVS_IS_ERROR(property_node_refer( - NULL, - cur, - "opt@", - PROPERTY_TYPE_ATTR, - mounttable->entry[pos].opt, - sizeof(mounttable->entry[pos].opt)))) { + result = core_property_node_ext_attr_read( + &cur, + "opt@", + mounttable->entry[pos].opt, + sizeof(mounttable->entry[pos].opt)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { // optional + } else { + core_property_node_fatal_on_error(result); } pos++; } } - cur = property_node_traversal(cur, TRAVERSE_NEXT_SIBLING); - } - } else { - cur = property_search(NULL, fs_node, "nvram"); + result = core_property_node_next_sibling_get(&cur, &tmp); + memcpy(&cur, &tmp, sizeof(core_property_node_t)); - if (cur) { - if (AVS_IS_ERROR(property_node_refer( - NULL, - cur, - "fstype", - PROPERTY_TYPE_STR, - mounttable->entry[pos].fstype, - sizeof(mounttable->entry[pos].fstype)))) { + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } + } + } else if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + result = core_property_node_search(&fs_node, "nvram", &cur); + + if (result == CORE_PROPERTY_NODE_RESULT_SUCCESS) { + result = core_property_node_ext_str_read( + &cur, + "fstype", + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { // default str_cpy( mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype), "fs"); + } else { + core_property_node_fatal_on_error(result); } - if (AVS_IS_ERROR(property_node_refer( - NULL, - cur, - "device", - PROPERTY_TYPE_STR, - mounttable->entry[pos].src, - sizeof(mounttable->entry[pos].src)))) { + result = core_property_node_ext_str_read( + &cur, + "device", + mounttable->entry[pos].src, + sizeof(mounttable->entry[pos].src)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal("Missing 'device' attribute on nvram node"); + } else { + core_property_node_fatal_on_error(result); } str_cpy( @@ -710,44 +873,52 @@ void avs_config_vfs_mounttable_get( sizeof(mounttable->entry[pos].dst), "/dev/nvram"); - if (AVS_IS_ERROR(property_node_refer( - NULL, - cur, - "opt", - PROPERTY_TYPE_STR, - mounttable->entry[pos].opt, - sizeof(mounttable->entry[pos].opt)))) { + result = core_property_node_ext_str_read( + &cur, + "opt", + mounttable->entry[pos].opt, + sizeof(mounttable->entry[pos].opt)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { // optional + } else { + core_property_node_fatal_on_error(result); } pos++; + } else if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); } - cur = property_search(NULL, fs_node, "raw"); + result = core_property_node_search(&fs_node, "raw", &cur); - if (cur) { - if (AVS_IS_ERROR(property_node_refer( - NULL, - cur, - "fstype", - PROPERTY_TYPE_STR, - mounttable->entry[pos].fstype, - sizeof(mounttable->entry[pos].fstype)))) { + if (result == CORE_PROPERTY_NODE_RESULT_SUCCESS) { + result = core_property_node_ext_str_read( + &cur, + "fstype", + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { // default str_cpy( mounttable->entry[pos].fstype, sizeof(mounttable->entry[pos].fstype), "fs"); + } else { + core_property_node_fatal_on_error(result); } - if (AVS_IS_ERROR(property_node_refer( - NULL, - cur, - "device", - PROPERTY_TYPE_STR, - mounttable->entry[pos].src, - sizeof(mounttable->entry[pos].src)))) { + result = core_property_node_ext_str_read( + &cur, + "device", + mounttable->entry[pos].src, + sizeof(mounttable->entry[pos].src)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal("Missing 'device' attribute on raw node"); + } else { + core_property_node_fatal_on_error(result); } str_cpy( @@ -755,18 +926,24 @@ void avs_config_vfs_mounttable_get( sizeof(mounttable->entry[pos].dst), "/dev/raw"); - if (AVS_IS_ERROR(property_node_refer( - NULL, - cur, - "opt", - PROPERTY_TYPE_STR, - mounttable->entry[pos].opt, - sizeof(mounttable->entry[pos].opt)))) { + result = core_property_node_ext_str_read( + &cur, + "opt", + mounttable->entry[pos].opt, + sizeof(mounttable->entry[pos].opt)); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { // optional + } else { + core_property_node_fatal_on_error(result); } pos++; + } else if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); } + } else { + core_property_node_fatal_on_error(result); } mounttable->num_entries = pos; diff --git a/src/main/launcher/avs-config.h b/src/main/launcher/avs-config.h index 692643d..4916fa6 100644 --- a/src/main/launcher/avs-config.h +++ b/src/main/launcher/avs-config.h @@ -3,7 +3,8 @@ #include "core/log-bt.h" -#include "imports/avs.h" +#include "core/property-node.h" +#include "core/property.h" #include "launcher/bootstrap-config.h" @@ -20,38 +21,40 @@ struct avs_config_vfs_mounttable { uint8_t num_entries; }; -struct property *avs_config_load(const char *filepath); -struct property_node *avs_config_root_get(struct property *property); -struct property * -avs_config_property_merge(struct property *parent, struct property *source); +core_property_t *avs_config_load(const char *filepath); +void avs_config_root_get( + const core_property_t *property, core_property_node_t *node); +core_property_t *avs_config_property_merge( + const core_property_t *parent, const core_property_t *source); void avs_config_fs_root_device_get( - struct property_node *node, char *buffer, size_t size); + const core_property_node_t *node, char *buffer, size_t size); -void avs_config_mode_product_set(struct property_node *node, bool enable); -void avs_config_net_raw_set(struct property_node *node, bool enable); -void avs_config_net_eaudp_set(struct property_node *node, bool enable); -void avs_config_sntp_ea_set(struct property_node *node, bool on); -void avs_config_log_level_set(struct property_node *node, const char *level); -void avs_config_log_name_set(struct property_node *node, const char *name); -void avs_config_log_file_set(struct property_node *node, const char *file); -void avs_config_log_buffer_size_set(struct property_node *node, uint32_t size); +void avs_config_mode_product_set(core_property_node_t *node, bool enable); +void avs_config_net_raw_set(core_property_node_t *node, bool enable); +void avs_config_net_eaudp_set(core_property_node_t *node, bool enable); +void avs_config_sntp_ea_set(core_property_node_t *node, bool on); +void avs_config_log_level_set(core_property_node_t *node, const char *level); +void avs_config_log_name_set(core_property_node_t *node, const char *name); +void avs_config_log_file_set(core_property_node_t *node, const char *file); +void avs_config_log_buffer_size_set(core_property_node_t *node, uint32_t size); void avs_config_log_output_delay_set( - struct property_node *node, uint16_t delay_ms); -void avs_config_log_enable_console_set(struct property_node *node, bool enable); -void avs_config_log_enable_sci_set(struct property_node *node, bool enable); -void avs_config_log_enable_net_set(struct property_node *node, bool enable); -void avs_config_log_enable_file_set(struct property_node *node, bool enable); -void avs_config_log_rotate_set(struct property_node *node, bool rotate); -void avs_config_log_append_set(struct property_node *node, bool append); -void avs_config_log_count_set(struct property_node *node, uint16_t count); + core_property_node_t *node, uint16_t delay_ms); +void avs_config_log_enable_console_set(core_property_node_t *node, bool enable); +void avs_config_log_enable_sci_set(core_property_node_t *node, bool enable); +void avs_config_log_enable_net_set(core_property_node_t *node, bool enable); +void avs_config_log_enable_file_set(core_property_node_t *node, bool enable); +void avs_config_log_rotate_set(core_property_node_t *node, bool rotate); +void avs_config_log_append_set(core_property_node_t *node, bool append); +void avs_config_log_count_set(core_property_node_t *node, uint16_t count); void avs_config_set_log_level( - struct property_node *node, enum core_log_bt_log_level loglevel); + core_property_node_t *node, enum core_log_bt_log_level loglevel); void avs_config_local_fs_path_dev_nvram_and_raw_set( - struct property_node *node, const char *dev_nvram_raw_path); + core_property_node_t *node, const char *dev_nvram_raw_path); void avs_config_vfs_mounttable_get( - struct property_node *node, struct avs_config_vfs_mounttable *mounttable); + const core_property_node_t *node, + struct avs_config_vfs_mounttable *mounttable); #endif \ No newline at end of file diff --git a/src/main/launcher/avs.c b/src/main/launcher/avs.c index 4ff0730..58fa2b1 100644 --- a/src/main/launcher/avs.c +++ b/src/main/launcher/avs.c @@ -6,14 +6,19 @@ #include #include +#include "avs-ext/error.h" +#include "avs-ext/log.h" +#include "avs-ext/property-node.h" + #include "core/log-bt.h" -#include "core/log.h" +#include "core/property-node.h" + +#include "iface-core/log.h" #include "imports/avs.h" #include "launcher/avs-config.h" #include "launcher/avs.h" -#include "launcher/property-util.h" #include "util/codepage.h" #include "util/fs.h" @@ -98,13 +103,12 @@ static void _avs_switch_log_engine() // Switch the logging backend now that AVS is booted to use a single logging // engine which avoids concurrency issues as AVS runs it's own async logger // thread - core_log_impl_set( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + avs_ext_log_core_api_set(); log_misc("Switched logging engine to AVS"); } -void avs_fs_assert_root_device_exists(struct property_node *node) +void avs_fs_assert_root_device_exists(const core_property_node_t *node) { char root_device_path[PATH_MAX]; char cwd_path[PATH_MAX]; @@ -121,7 +125,7 @@ void avs_fs_assert_root_device_exists(struct property_node *node) } } -void avs_fs_mountpoints_fs_dirs_create(struct property_node *node) +void avs_fs_mountpoints_fs_dirs_create(const core_property_node_t *node) { struct avs_config_vfs_mounttable mounttable; uint8_t i; @@ -151,8 +155,12 @@ void avs_fs_mountpoints_fs_dirs_create(struct property_node *node) } void avs_init( - struct property_node *node, uint32_t avs_heap_size, uint32_t std_heap_size) + const core_property_node_t *node, + uint32_t avs_heap_size, + uint32_t std_heap_size) { + struct property_node *avs_node; + log_assert(node); log_assert(avs_heap_size > 0); // Modern games don't have a separate std heap anymore @@ -188,9 +196,11 @@ void avs_init( log_info("Calling avs_boot"); + avs_node = avs_ext_property_node_avs_property_node_get(node); + #ifdef AVS_HAS_STD_HEAP avs_boot( - node, + avs_node, std_heap, std_heap_size, avs_heap, @@ -200,7 +210,7 @@ void avs_init( #else /* AVS v2.16.xx and I suppose onward uses a unified heap */ avs_boot( - node, avs_heap, avs_heap_size, NULL, _avs_context_log_writer, NULL); + avs_node, avs_heap, avs_heap_size, NULL, _avs_context_log_writer, NULL); #endif _avs_switch_log_engine(); @@ -211,32 +221,47 @@ void avs_init( void avs_fs_file_copy(const char *src, const char *dst) { struct avs_stat st; + avs_error error; log_assert(src); log_assert(dst); log_misc("Copying %s to %s...", src, dst); - if (!avs_fs_lstat(src, &st)) { - log_fatal("File source %s does not exist or is not accessible", src); + error = avs_fs_lstat(src, &st); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "File source %s does not exist or is not accessible: %s", + src, + avs_ext_error_str(error)); } - if (avs_fs_copy(src, dst) < 0) { - log_fatal("Failed copying file %s to %s", src, dst); + error = avs_fs_copy(src, dst); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "Failed copying file %s to %s: %s", + src, + dst, + avs_ext_error_str(error)); } } void avs_fs_dir_log(const char *path) { const char *name; + avs_desc dir; log_assert(path); - avs_desc dir = avs_fs_opendir(path); + dir = avs_fs_opendir(path); - if (dir < 0) { + if (AVS_IS_ERROR(dir)) { log_warning( - "Opening avs dir %s failed, skipping logging contents", path); + "Opening avs dir %s failed, skipping logging contents: %s", + path, + avs_ext_error_str(dir)); } log_misc("Contents of %s:", path); diff --git a/src/main/launcher/avs.h b/src/main/launcher/avs.h index ad2233a..7d2fc2e 100644 --- a/src/main/launcher/avs.h +++ b/src/main/launcher/avs.h @@ -3,12 +3,14 @@ #include -#include "imports/avs.h" +#include "core/property-node.h" -void avs_fs_assert_root_device_exists(struct property_node *node); -void avs_fs_mountpoints_fs_dirs_create(struct property_node *node); +void avs_fs_assert_root_device_exists(const core_property_node_t *node); +void avs_fs_mountpoints_fs_dirs_create(const core_property_node_t *node); void avs_init( - struct property_node *node, uint32_t avs_heap_size, uint32_t std_heap_size); + const core_property_node_t *node, + uint32_t avs_heap_size, + uint32_t std_heap_size); void avs_fs_file_copy(const char *src, const char *dst); void avs_fs_dir_log(const char *path); void avs_fini(void); diff --git a/src/main/launcher/bootstrap-config.c b/src/main/launcher/bootstrap-config.c index 35915c6..8796048 100644 --- a/src/main/launcher/bootstrap-config.c +++ b/src/main/launcher/bootstrap-config.c @@ -2,196 +2,20 @@ #include -#include "core/log.h" +#include "core/property-node-ext.h" +#include "core/property-node.h" + +#include "iface-core/log.h" #include "imports/avs.h" #include "launcher/avs-config.h" #include "launcher/bootstrap-config.h" -#include "launcher/property-util.h" #include "util/defs.h" #include "util/hex.h" #include "util/str.h" -// clang-format off -PSMAP_BEGIN(bootstrap_startup_boot_psmap) -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct bootstrap_boot_config, config_file, - "boot/file") -PSMAP_REQUIRED(PSMAP_TYPE_U32, struct bootstrap_boot_config, avs_heap_size, - "boot/heap_avs") -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_boot_config, std_heap_size, - "boot/heap_std", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_boot_config, mount_table_selector, - "boot/mounttable_selector", "boot") -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_boot_config, watcher_enable, - "boot/watcher", 1) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_boot_config, timemachine_enable, - "boot/timemachine", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_boot_config, launch_config_file, - "boot/launch_path", "/dev/raw/launch.xml") -PSMAP_END - -PSMAP_BEGIN(bootstrap_startup_log_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_log_config, level, - "log/level", "all") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_log_config, name, - "log/name", "") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_log_config, file, - "log/file", "") -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_log_config, bufsz, - "log/sz_buf", 4096) -PSMAP_OPTIONAL(PSMAP_TYPE_U16, struct bootstrap_log_config, output_delay_ms, - "log/output_delay", 10) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_console, - "log/enable_console", 1) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_sci, - "log/enable_netsci", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_net, - "log/enable_netlog", 1) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_file, - "log/enable_file", 1) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, rotate, - "log/rotate", 1) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, append, - "log/append", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_U16, struct bootstrap_log_config, count, - "log/gen", 10) -PSMAP_END - -PSMAP_BEGIN(bootstrap_startup_minidump_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_U8, struct bootstrap_minidump_config, count, - "minidump/gen", 10) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_minidump_config, continue_, - "minidump/cont_debug", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_minidump_config, log, - "minidump/echo_log", 1) -PSMAP_OPTIONAL(PSMAP_TYPE_U8, struct bootstrap_minidump_config, type, - "minidump/dump_type", 2) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_minidump_config, path, - "minidump/path", "/dev/raw/minidump") -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_minidump_config, symbufsz, - "minidump/sz_symbuf", 32768) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_minidump_config, search_path, - "minidump/search", ".") -PSMAP_END - -PSMAP_BEGIN(bootstrap_startup_module_psmap) -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct bootstrap_module_config, file, - "component/file") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_module_config, load_type, - "component/load_type", "MEMORY") -PSMAP_END - -PSMAP_BEGIN(bootstrap_startup_dlm_psmap) -/* disabled until we implement PSMAP_TYPE_BIN - PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_startup_config, ntdll_digest, - "dlml/ntdll/hash", "") - */ -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, size, - "dlml/ntdll/size", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, ift_table, - "dlml/ntdll/ift_table", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, ift_insert, - "dlml/ntdll/insert_ift", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, ift_remove, - "dlml/ntdll/remove_ift", 0) -PSMAP_END - -PSMAP_BEGIN(bootstrap_startup_shield_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_shield_config, enable, - "shield/enable", 1) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_shield_config, verbose, - "shield/verbose", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_shield_config, use_loadlibrary, - "shield/use_loadlibrary", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_shield_config, logger, - "shield/logger", "") -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, sleep_min, - "shield/sleepmin", 10) -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, sleep_blur, - "shield/sleepblur", 90) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_shield_config, whitelist_file, - "shield/whitelist", "prop/whitelist.csv") -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, tick_sleep, - "shield/ticksleep", 100) -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, tick_error, - "shield/tickerror", 1000) -PSMAP_OPTIONAL(PSMAP_TYPE_U8, struct bootstrap_shield_config, overwork_threshold, - "shield/overwork_threshold", 50) -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, overwork_delay, - "shield/overwork_delay", 100) -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, pause_delay, - "shield/pause_delay", 1000) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_shield_config, unlimited_key, - "shield/unlimited_key", "") -PSMAP_OPTIONAL(PSMAP_TYPE_U16, struct bootstrap_shield_config, killer_port, - "shield_killer/port", 5001) -PSMAP_END - -PSMAP_BEGIN(bootstrap_startup_dongle_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_dongle_config, license_cn, - "dongle/license", "") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_dongle_config, account_cn, - "dongle/account", "") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_dongle_config, driver_dll, - "dongle/pkcs11_driver", "eTPKCS11.dll") -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_dongle_config, disable_gc, - "dongle/disable_gc", 0) -PSMAP_END - -PSMAP_BEGIN(bootstrap_startup_drm_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, dll, - "drm/dll", "") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, fstype, - "drm/fstype", "") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, device, - "drm/device", "") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, mount, - "drm/dst", "/") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, options, - "drm/option", "") -PSMAP_END - -PSMAP_BEGIN(bootstrap_startup_lte_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_lte_config, enable, - "lte/enable", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_lte_config, config_file, - "lte/file", "/dev/nvram/lte-config.xml") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_lte_config, unlimited_key, - "lte/unlimited_key", "") -PSMAP_END - -PSMAP_BEGIN(bootstrap_startup_ssl_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_ssl_config, options, - "ssl/option", "") -PSMAP_END - -PSMAP_BEGIN(bootstrap_startup_esign_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_esign_config, enable, - "esign/enable", 0) -PSMAP_END - -PSMAP_BEGIN(bootstrap_startup_eamuse_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, enable, - "eamuse/enable", 1) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, sync, - "eamuse/sync", 1) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, enable_model, - "eamuse/enable_model", 0) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_eamuse_config, config_file, - "eamuse/file", "/dev/nvram/ea3-config.xml") -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, updatecert_enable, - "eamuse/updatecert_enable", 1) -PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_eamuse_config, updatecert_interval, - "eamuse/updatecert_interval", 0) -PSMAP_END - -PSMAP_BEGIN(bootstrap_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_config, release_code, "/release_code", "") -PSMAP_END -// clang-format on - #define ROOT_NODE "/config" #define MODULE_PATH_PREFIX "modules/" @@ -222,147 +46,185 @@ const char *const inherited_nodes[] = { }; static void _bootstrap_config_profile_node_verify( - struct property_node *node, const char *profile) + const core_property_node_t *node, const char *profile) { - struct property_node *profile_node; + core_property_node_t profile_node; + core_property_node_result_t result; log_assert(node); log_assert(profile); - profile_node = property_search(NULL, node, profile); + result = core_property_node_search(node, profile, &profile_node); - if (!profile_node) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { NODE_STARTUP_MISSING_FATAL(profile); + } else { + core_property_node_fatal_on_error(result); } } -static struct property_node * -_bootstrap_config_root_node_get(struct property *property) +static void _bootstrap_config_root_node_get( + const core_property_t *property, core_property_node_t *node) { - struct property_node *root_node; + core_property_node_result_t result; + char node_name[128]; log_assert(property); - - root_node = property_search(property, NULL, ROOT_NODE); - - if (!root_node) { - NODE_MISSING_FATAL(""); - } - - return root_node; -} - -static struct property_node * -_bootstrap_config_startup_node_get(struct property_node *node) -{ - struct property_node *startup_node; - log_assert(node); - startup_node = property_search(NULL, node, "startup"); + result = core_property_root_node_get(property, node); + core_property_node_fatal_on_error(result); - if (!startup_node) { - NODE_MISSING_FATAL("startup"); + result = core_property_node_name_get(node, node_name, sizeof(node_name)); + core_property_node_fatal_on_error(result); + + if (!str_eq(node_name, "config")) { + NODE_MISSING_FATAL(""); + } else { + core_property_node_fatal_on_error(result); } +} - return startup_node; +static void _bootstrap_config_startup_node_get( + const core_property_node_t *node, core_property_node_t *node_out) +{ + core_property_node_result_t result; + + log_assert(node); + log_assert(node_out); + + result = core_property_node_search(node, "startup", node_out); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + NODE_MISSING_FATAL("startup"); + } else { + core_property_node_fatal_on_error(result); + } } static void _bootstrap_config_inheritance_resolve( - struct property_node *startup_node, const char *profile_name) + const core_property_node_t *startup_node, const char *profile_name) { - struct property_node *startup_parent_node; - struct property_node *startup_profile_node; - struct property_node *tmp_node; + core_property_node_t startup_parent_node; + core_property_node_t startup_profile_node; + core_property_node_t tmp_node; + core_property_node_result_t result; char inherit_name[64]; - avs_error error; - struct property_node *result; + int i; - startup_profile_node = property_search(NULL, startup_node, profile_name); + result = core_property_node_search( + startup_node, profile_name, &startup_profile_node); - if (!startup_profile_node) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal(ROOT_NODE "/startup/%s: missing", profile_name); + } else { + core_property_node_fatal_on_error(result); } - startup_parent_node = startup_profile_node; + memcpy( + &startup_parent_node, + &startup_profile_node, + sizeof(core_property_node_t)); - for (;;) { - error = property_node_refer( - NULL, - startup_parent_node, + while (true) { + result = core_property_node_ext_attr_read( + &startup_parent_node, "inherit@", - PROPERTY_TYPE_ATTR, inherit_name, sizeof(inherit_name)); - if (AVS_IS_ERROR(error)) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { break; + } else { + core_property_node_fatal_on_error(result); } - startup_parent_node = property_search(NULL, startup_node, inherit_name); + result = core_property_node_search( + startup_node, inherit_name, &startup_parent_node); - if (!startup_parent_node) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { NODE_STARTUP_MISSING_FATAL(inherit_name); + } else { + core_property_node_fatal_on_error(result); } - for (int i = 0; i < _countof(inherited_nodes); i++) { - if (property_search(NULL, startup_node, inherited_nodes[i])) { + for (i = 0; i < _countof(inherited_nodes); i++) { + result = core_property_node_search( + startup_node, inherited_nodes[i], &tmp_node); + + // if found, then continue; if not found, skip this, any other + // errors go fatal + if (result == CORE_PROPERTY_NODE_RESULT_SUCCESS) { continue; + } else if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); } - tmp_node = - property_search(NULL, startup_parent_node, inherited_nodes[i]); + result = core_property_node_search( + &startup_parent_node, inherited_nodes[i], &tmp_node); - if (tmp_node) { + if (result == CORE_PROPERTY_NODE_RESULT_SUCCESS) { log_misc( ROOT_NODE "/startup/%s: merging %s...", inherit_name, inherited_nodes[i]); - result = property_node_clone( - NULL, startup_profile_node, tmp_node, true); + result = + core_property_node_copy(&startup_profile_node, &tmp_node); - if (!result) { + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { log_fatal( "Merging '%s' into '%s' failed", inherited_nodes[i], inherit_name); } + } else if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); } } } } static void _bootstrap_config_load_bootstrap_module_app_config( - struct property_node *profile_node, struct bootstrap_module_config *config) + const core_property_node_t *profile_node, + struct bootstrap_module_config *config) { - struct property_node *app_node; + core_property_node_t app_node; + core_property_node_result_t result; log_assert(profile_node); log_assert(config); - app_node = property_search(NULL, profile_node, "component/param"); + result = + core_property_node_search(profile_node, "component/param", &app_node); + core_property_node_fatal_on_error(result); - config->app_config = property_util_node_extract(app_node); + result = core_property_node_ext_extract(&app_node, &config->app_config); + core_property_node_fatal_on_error(result); } static void _bootstrap_config_load_bootstrap_default_files_config( const char *profile_name, - struct property_node *profile_node, + const core_property_node_t *profile_node, struct bootstrap_default_file_config *config) { int i; - int result; - struct property_node *child; + core_property_node_t tmp; + core_property_node_t child; + core_property_node_result_t result; log_assert(profile_node); log_assert(config); - child = property_search(NULL, profile_node, "default/file"); + result = core_property_node_search(profile_node, "default/file", &child); i = 0; - while (child) { + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } + + while (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { if (i >= DEFAULT_FILE_MAX) { log_warning( "Currently not supporting more than %d default files, skipping " @@ -371,138 +233,397 @@ static void _bootstrap_config_load_bootstrap_default_files_config( break; } - result = property_node_refer( - NULL, - child, - "src@", - PROPERTY_TYPE_ATTR, - &config->file[i].src, - sizeof(config->file[i].src)); + result = core_property_node_ext_attr_read( + &child, "src@", config->file[i].src, sizeof(config->file[i].src)); - if (result < 0) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal( "Missing src attribute on default file node of profile %s", profile_name); + } else { + core_property_node_fatal_on_error(result); } - result = property_node_refer( - NULL, - child, - "dst@", - PROPERTY_TYPE_ATTR, - &config->file[i].dst, - sizeof(config->file[i].dst)); + result = core_property_node_ext_attr_read( + &child, "dst@", config->file[i].dst, sizeof(config->file[i].dst)); - if (result < 0) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { log_fatal( "Missing dst attribute on default file node of profile %s", profile_name); + } else { + core_property_node_fatal_on_error(result); } - child = property_node_traversal(child, TRAVERSE_NEXT_SEARCH_RESULT); + result = core_property_node_next_result_search(&child, &tmp); + memcpy(&child, &tmp, sizeof(core_property_node_t)); i++; + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } } } static void _bootstrap_config_load_bootstrap( - struct property_node *startup_node, + const core_property_node_t *startup_node, const char *profile, struct bootstrap_startup_config *config) { - struct property_node *profile_node; + core_property_node_t profile_node; + core_property_node_result_t result; - profile_node = property_search(NULL, startup_node, profile); + result = core_property_node_search(startup_node, profile, &profile_node); - if (!profile_node) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { NODE_PROFILE_LOADING_FATAL(profile, ""); + } else { + core_property_node_fatal_on_error(result); } _bootstrap_config_load_bootstrap_default_files_config( - profile, profile_node, &config->default_file); + profile, &profile_node, &config->default_file); - if (!property_psmap_import( - NULL, profile_node, &config->boot, bootstrap_startup_boot_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "boot"); - } + result = core_property_node_ext_str_read( + &profile_node, + "boot/file", + config->boot.config_file, + sizeof(config->boot.config_file)); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read( + &profile_node, "boot/heap_avs", &config->boot.avs_heap_size); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, "boot/heap_std", &config->boot.std_heap_size, 0); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "boot/mounttable_selector", + config->boot.mount_table_selector, + sizeof(config->boot.mount_table_selector), + "boot"); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, "boot/watcher", &config->boot.watcher_enable, true); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, + "boot/timemachine", + &config->boot.timemachine_enable, + false); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "boot/launch_path", + config->boot.launch_config_file, + sizeof(config->boot.launch_config_file), + "/dev/raw/launch.xml"); + core_property_node_fatal_on_error(result); - if (!property_psmap_import( - NULL, profile_node, &config->log, bootstrap_startup_log_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "log"); - } + result = core_property_node_ext_str_read_or_default( + &profile_node, + "log/level", + config->log.level, + sizeof(config->log.level), + "all"); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "log/name", + config->log.name, + sizeof(config->log.name), + ""); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "log/file", + config->log.file, + sizeof(config->log.file), + ""); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, "log/sz_buf", &config->log.bufsz, 4096); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u16_read_or_default( + &profile_node, "log/output_delay", &config->log.output_delay_ms, 10); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, "log/enable_console", &config->log.enable_console, true); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, "log/enable_netsci", &config->log.enable_sci, false); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, "log/enable_netlog", &config->log.enable_net, true); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, "log/enable_file", &config->log.enable_file, true); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, "log/rotate", &config->log.rotate, true); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, "log/append", &config->log.append, false); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u16_read_or_default( + &profile_node, "log/gen", &config->log.count, 10); + core_property_node_fatal_on_error(result); - if (!property_psmap_import( - NULL, - profile_node, - &config->minidump, - bootstrap_startup_minidump_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "minidump"); - } + result = core_property_node_ext_u8_read_or_default( + &profile_node, "minidump/gen", &config->minidump.count, 10); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, + "minidump/cont_debug", + &config->minidump.continue_, + false); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, "minidump/echo_log", &config->minidump.log, true); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u8_read_or_default( + &profile_node, "minidump/dump_type", &config->minidump.type, 2); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "minidump/path", + config->minidump.path, + sizeof(config->minidump.path), + "/dev/raw/minidump"); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, "minidump/sz_symbuf", &config->minidump.symbufsz, 32768); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "minidump/search", + config->minidump.search_path, + sizeof(config->minidump.search_path), + "."); + core_property_node_fatal_on_error(result); - if (!property_psmap_import( - NULL, - profile_node, - &config->module, - bootstrap_startup_module_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "component"); - } + result = core_property_node_ext_str_read( + &profile_node, + "component/file", + config->module.file, + sizeof(config->module.file)); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "component/load_type", + config->module.load_type, + sizeof(config->module.load_type), + "MEMORY"); + core_property_node_fatal_on_error(result); _bootstrap_config_load_bootstrap_module_app_config( - profile_node, &config->module); + &profile_node, &config->module); - if (!property_psmap_import( - NULL, - profile_node, - &config->dlm_ntdll, - bootstrap_startup_dlm_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "dlm/ntdll"); - } + /* disabled until we implement PSMAP_TYPE_BIN + PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_startup_config, + ntdll_digest, "dlml/ntdll/hash", "") + */ + result = core_property_node_ext_u32_read_or_default( + &profile_node, "dlml/ntdll/size", &config->dlm_ntdll.size, 0); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, "dlml/ntdll/ift_table", &config->dlm_ntdll.ift_table, 0); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, + "dlml/ntdll/insert_ift", + &config->dlm_ntdll.ift_insert, + 0); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, + "dlml/ntdll/remove_ift", + &config->dlm_ntdll.ift_remove, + 0); + core_property_node_fatal_on_error(result); - if (!property_psmap_import( - NULL, - profile_node, - &config->shield, - bootstrap_startup_shield_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "shield"); - } + result = core_property_node_ext_bool_read_or_default( + &profile_node, "shield/enable", &config->shield.enable, true); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, "shield/verbose", &config->shield.verbose, false); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, + "shield/use_loadlibrary", + &config->shield.use_loadlibrary, + false); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "shield/use_loadlibrary", + config->shield.logger, + sizeof(config->shield.logger), + ""); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, "shield/sleepmin", &config->shield.sleep_min, 10); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, "shield/sleepblur", &config->shield.sleep_blur, 90); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "shield/whitelist", + config->shield.whitelist_file, + sizeof(config->shield.whitelist_file), + "prop/whitelist.csv"); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, "shield/ticksleep", &config->shield.tick_sleep, 100); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, "shield/tickerror", &config->shield.tick_error, 1000); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u8_read_or_default( + &profile_node, + "shield/overwork_threshold", + &config->shield.overwork_threshold, + 50); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, + "shield/overwork_delay", + &config->shield.overwork_delay, + 100); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, "shield/pause_delay", &config->shield.pause_delay, 1000); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "shield/unlimited_key", + config->shield.unlimited_key, + sizeof(config->shield.unlimited_key), + ""); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u16_read_or_default( + &profile_node, "shield_killer/port", &config->shield.killer_port, 5001); + core_property_node_fatal_on_error(result); - if (!property_psmap_import( - NULL, - profile_node, - &config->dongle, - bootstrap_startup_dongle_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "dongle"); - } + result = core_property_node_ext_str_read_or_default( + &profile_node, + "dongle/license", + config->dongle.license_cn, + sizeof(config->dongle.license_cn), + ""); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "dongle/account", + config->dongle.account_cn, + sizeof(config->dongle.account_cn), + ""); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "dongle/pkcs11_driver", + config->dongle.driver_dll, + sizeof(config->dongle.driver_dll), + "eTPKCS11.dll"); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, "dongle/disable_gc", &config->dongle.disable_gc, false); + core_property_node_fatal_on_error(result); - if (!property_psmap_import( - NULL, profile_node, &config->drm, bootstrap_startup_drm_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "drm"); - } + result = core_property_node_ext_str_read_or_default( + &profile_node, "drm/dll", config->drm.dll, sizeof(config->drm.dll), ""); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "drm/fstype", + config->drm.fstype, + sizeof(config->drm.fstype), + ""); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "drm/device", + config->drm.device, + sizeof(config->drm.device), + ""); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "drm/dst", + config->drm.mount, + sizeof(config->drm.mount), + "/"); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "drm/option", + config->drm.options, + sizeof(config->drm.options), + ""); + core_property_node_fatal_on_error(result); - if (!property_psmap_import( - NULL, profile_node, &config->lte, bootstrap_startup_lte_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "lte"); - } + result = core_property_node_ext_bool_read_or_default( + &profile_node, "lte/enable", &config->lte.enable, false); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "lte/file", + config->lte.config_file, + sizeof(config->lte.config_file), + "/dev/nvram/lte-config.xml"); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "lte/unlimited_key", + config->lte.unlimited_key, + sizeof(config->lte.unlimited_key), + ""); + core_property_node_fatal_on_error(result); - if (!property_psmap_import( - NULL, profile_node, &config->ssl, bootstrap_startup_ssl_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "ssl"); - } + result = core_property_node_ext_str_read_or_default( + &profile_node, + "ssl/option", + config->ssl.options, + sizeof(config->ssl.options), + ""); + core_property_node_fatal_on_error(result); - if (!property_psmap_import( - NULL, - profile_node, - &config->esign, - bootstrap_startup_esign_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "esign"); - } + result = core_property_node_ext_bool_read_or_default( + &profile_node, "esign/enable", &config->esign.enable, false); + core_property_node_fatal_on_error(result); - if (!property_psmap_import( - NULL, - profile_node, - &config->eamuse, - bootstrap_startup_eamuse_psmap)) { - NODE_PROFILE_LOADING_FATAL(profile, "eamuse"); - } + result = core_property_node_ext_bool_read_or_default( + &profile_node, "eamuse/enable", &config->eamuse.enable, true); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, "eamuse/sync", &config->eamuse.sync, true); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, + "eamuse/enable_model", + &config->eamuse.enable_model, + false); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_str_read_or_default( + &profile_node, + "eamuse/file", + config->eamuse.config_file, + sizeof(config->eamuse.config_file), + "/dev/nvram/ea3-config.xml"); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_bool_read_or_default( + &profile_node, + "eamuse/updatecert_enable", + &config->eamuse.updatecert_enable, + true); + core_property_node_fatal_on_error(result); + result = core_property_node_ext_u32_read_or_default( + &profile_node, + "eamuse/updatecert_interval", + &config->eamuse.updatecert_interval, + 0); + core_property_node_fatal_on_error(result); } void bootstrap_config_init(struct bootstrap_config *config) @@ -513,12 +634,13 @@ void bootstrap_config_init(struct bootstrap_config *config) } void bootstrap_config_load( - struct property *property, + const core_property_t *property, const char *profile, struct bootstrap_config *config) { - struct property_node *root_node; - struct property_node *startup_node; + core_property_node_t root_node; + core_property_node_t startup_node; + core_property_node_result_t result; log_assert(property); log_assert(profile); @@ -526,23 +648,30 @@ void bootstrap_config_load( log_info(ROOT_NODE ": loading..."); - root_node = _bootstrap_config_root_node_get(property); + _bootstrap_config_root_node_get(property, &root_node); - if (!property_psmap_import(NULL, root_node, config, bootstrap_psmap)) { + result = core_property_node_ext_str_read_or_default( + &root_node, + "/release_code", + config->release_code, + sizeof(config->release_code), + ""); + + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { log_fatal(ROOT_NODE ": loading failed"); } - startup_node = _bootstrap_config_startup_node_get(root_node); + _bootstrap_config_startup_node_get(&root_node, &startup_node); - _bootstrap_config_profile_node_verify(startup_node, profile); + _bootstrap_config_profile_node_verify(&startup_node, profile); - _bootstrap_config_inheritance_resolve(startup_node, profile); + _bootstrap_config_inheritance_resolve(&startup_node, profile); log_misc(ROOT_NODE "/startup/%s: loading merged result...", profile); - property_util_node_log(startup_node); + core_property_node_log(&startup_node, log_misc_func); - _bootstrap_config_load_bootstrap(startup_node, profile, &config->startup); + _bootstrap_config_load_bootstrap(&startup_node, profile, &config->startup); log_misc("Loading finished"); } \ No newline at end of file diff --git a/src/main/launcher/bootstrap-config.h b/src/main/launcher/bootstrap-config.h index 596bf93..b911765 100644 --- a/src/main/launcher/bootstrap-config.h +++ b/src/main/launcher/bootstrap-config.h @@ -4,7 +4,7 @@ #include #include -#include "imports/avs.h" +#include "core/property.h" // should be enough for a while #define DEFAULT_FILE_MAX 16 @@ -55,7 +55,7 @@ struct bootstrap_startup_config { struct bootstrap_module_config { char file[64]; char load_type[64]; - struct property *app_config; + core_property_t *app_config; } module; struct bootstrap_dlm_config { @@ -132,7 +132,7 @@ struct bootstrap_config { void bootstrap_config_init(struct bootstrap_config *config); void bootstrap_config_load( - struct property *property, + const core_property_t *property, const char *profile, struct bootstrap_config *config); diff --git a/src/main/launcher/bootstrap.c b/src/main/launcher/bootstrap.c index a9e52bb..5906476 100644 --- a/src/main/launcher/bootstrap.c +++ b/src/main/launcher/bootstrap.c @@ -5,8 +5,14 @@ #include "core/log-sink-list.h" #include "core/log-sink-null.h" #include "core/log-sink-std.h" -#include "core/log.h" +#include "core/property-ext.h" +#include "core/property-node.h" +#include "core/property.h" + +#include "iface-core/log.h" + +#include "launcher/app.h" #include "launcher/avs-config.h" #include "launcher/avs.h" #include "launcher/bootstrap-config.h" @@ -14,16 +20,14 @@ #include "launcher/eamuse-config.h" #include "launcher/eamuse.h" #include "launcher/launcher-config.h" -#include "launcher/module.h" -#include "launcher/property-util.h" #include "util/str.h" static bool _bootstrap_log_property_configs; -static struct module_context _bootstrap_module_context; +static app_t _bootstrap_app; static void _bootstrap_eamuse_ea3_ident_config_inject( - struct property_node *node, const struct ea3_ident_config *ea3_ident_config) + core_property_node_t *node, const struct ea3_ident_config *ea3_ident_config) { eamuse_config_id_softid_set(node, ea3_ident_config->softid); eamuse_config_id_hardid_set(node, ea3_ident_config->hardid); @@ -36,7 +40,7 @@ static void _bootstrap_eamuse_ea3_ident_config_inject( } static void -_bootstrap_avs_config_force_overrides_apply(struct property_node *node) +_bootstrap_avs_config_force_overrides_apply(core_property_node_t *node) { log_assert(node); @@ -47,7 +51,7 @@ _bootstrap_avs_config_force_overrides_apply(struct property_node *node) } static void _bootstrap_avs_config_log_overrides_apply( - struct property_node *node, const struct bootstrap_log_config *log_config) + core_property_node_t *node, const struct bootstrap_log_config *log_config) { log_assert(node); log_assert(log_config); @@ -98,17 +102,14 @@ void bootstrap_init(bool log_property_configs) void bootstrap_log_init(const struct bootstrap_log_config *config) { - struct core_log_sink sinks[2]; - struct core_log_sink sink_composed; + core_log_sink_t sinks[2]; + core_log_sink_t sink_composed; enum core_log_bt_log_level level; log_assert(config); log_info("log init"); - // Shutdown old setup - core_log_bt_fini(); - if (config->enable_file && strlen(config->file) > 0 && config->enable_console) { core_log_sink_std_out_open(true, &sinks[0]); @@ -132,7 +133,7 @@ void bootstrap_log_init(const struct bootstrap_log_config *config) core_log_sink_null_open(&sink_composed); } - core_log_bt_init(&sink_composed); + core_log_bt_reinit(&sink_composed); level = _bootstrap_log_map_level(config->level); core_log_bt_level_set(level); @@ -160,11 +161,11 @@ void bootstrap_default_files_create( void bootstrap_avs_init( const struct bootstrap_boot_config *config, const struct bootstrap_log_config *log_config, - struct property *override_property) + const core_property_t *override_property) { - struct property *file_property; - struct property *merged_property; - struct property_node *root_node; + core_property_t *file_property; + core_property_t *merged_property; + core_property_node_t root_node; log_assert(config); log_assert(log_config); @@ -176,38 +177,38 @@ void bootstrap_avs_init( if (_bootstrap_log_property_configs) { log_misc("avs-config from file: %s", config->config_file); - property_util_log(file_property); + core_property_log(file_property, log_misc_func); } merged_property = avs_config_property_merge(file_property, override_property); - property_util_free(file_property); + core_property_free(&file_property); if (_bootstrap_log_property_configs) { log_misc("avs-config merged with overrides"); - property_util_log(merged_property); + core_property_log(merged_property, log_misc_func); } - root_node = avs_config_root_get(merged_property); + avs_config_root_get(merged_property, &root_node); - _bootstrap_avs_config_force_overrides_apply(root_node); - _bootstrap_avs_config_log_overrides_apply(root_node, log_config); + _bootstrap_avs_config_force_overrides_apply(&root_node); + _bootstrap_avs_config_log_overrides_apply(&root_node, log_config); if (_bootstrap_log_property_configs) { log_misc("avs-config final"); - property_util_log(merged_property); + core_property_log(merged_property, log_misc_func); } - avs_fs_assert_root_device_exists(root_node); + avs_fs_assert_root_device_exists(&root_node); log_misc("Creating AVS file system directories..."); - avs_fs_mountpoints_fs_dirs_create(root_node); + avs_fs_mountpoints_fs_dirs_create(&root_node); - avs_init(root_node, config->avs_heap_size, config->std_heap_size); + avs_init(&root_node, config->avs_heap_size, config->std_heap_size); - property_util_free(merged_property); + core_property_free(&merged_property); log_misc("avs init done"); } @@ -215,11 +216,12 @@ void bootstrap_avs_init( void bootstrap_eamuse_init( const struct bootstrap_eamuse_config *config, const struct ea3_ident_config *ea3_ident_config, - struct property *override_property) + const core_property_t *override_property) { - struct property *file_property; - struct property *merged_property; - struct property_node *root_node; + core_property_t *file_property; + core_property_t *merged_property; + core_property_node_t root_node; + core_property_result_t prop_result; log_assert(config); log_assert(ea3_ident_config); @@ -232,30 +234,32 @@ void bootstrap_eamuse_init( if (_bootstrap_log_property_configs) { log_misc("eamuse-config from file: %s", config->config_file); - property_util_log(file_property); + core_property_log(file_property, log_misc_func); } - merged_property = property_util_merge(file_property, override_property); + prop_result = core_property_ext_merge( + file_property, override_property, &merged_property); + core_property_fatal_on_error(prop_result); - property_util_free(file_property); + core_property_free(&file_property); if (_bootstrap_log_property_configs) { log_misc("eamuse-config merged with overrides"); - property_util_log(merged_property); + core_property_log(merged_property, log_misc_func); } - root_node = eamuse_config_root_get(merged_property); + eamuse_config_root_get(merged_property, &root_node); - _bootstrap_eamuse_ea3_ident_config_inject(root_node, ea3_ident_config); + _bootstrap_eamuse_ea3_ident_config_inject(&root_node, ea3_ident_config); if (_bootstrap_log_property_configs) { log_misc("eamuse-config final"); - property_util_log(merged_property); + core_property_log(merged_property, log_misc_func); } - eamuse_init(root_node); + eamuse_init(&root_node); - property_util_free(merged_property); + core_property_free(&merged_property); } else { log_warning("Eamuse disabled"); } @@ -263,71 +267,65 @@ void bootstrap_eamuse_init( log_misc("eamuse init done"); } -void bootstrap_module_init( - const struct bootstrap_module_config *module_config, - const struct array *iat_hook_dlls) +HMODULE bootstrap_app_unresolved_init( + const struct bootstrap_module_config *module_config) { log_assert(module_config); - log_assert(iat_hook_dlls); - log_info("module init"); + app_unresolved_load(module_config->file, &_bootstrap_app); - if (iat_hook_dlls->nitems > 0) { - log_info( - "Load game DLL with IAT hooks (%d): %s", - (uint32_t) iat_hook_dlls->nitems, - module_config->file); - - module_with_iat_hooks_init( - &_bootstrap_module_context, module_config->file, iat_hook_dlls); - } else { - log_info("Load game DLL: %s", module_config->file); - - module_init(&_bootstrap_module_context, module_config->file); - } - - log_misc("module init done"); + return app_module_handle_get(&_bootstrap_app); } -void bootstrap_module_game_init( +void bootstrap_app_resolve_init() +{ + app_resolve(&_bootstrap_app); +} + +void bootstrap_app_init( const struct bootstrap_module_config *module_config, struct ea3_ident_config *ea3_ident_config) { - struct property_node *node; + core_property_node_t node; + core_property_result_t prop_result; + core_property_node_result_t result; + char node_name[128]; log_assert(module_config); log_assert(ea3_ident_config); - log_info("module game init"); + log_info("app init"); - node = property_search(module_config->app_config, NULL, "/param"); + prop_result = core_property_root_node_get(module_config->app_config, &node); + core_property_fatal_on_error(prop_result); - if (!node) { + result = core_property_node_name_get(&node, node_name, sizeof(node_name)); + core_property_node_fatal_on_error(result); + + if (!str_eq(node_name, "param")) { log_fatal("Missing param node on app-config"); + } else { + core_property_node_fatal_on_error(result); } if (_bootstrap_log_property_configs) { log_misc("app-config"); - property_util_node_log(node); + core_property_node_log(&node, log_misc_func); } - module_init_invoke(&_bootstrap_module_context, ea3_ident_config, node); + app_init_invoke(&_bootstrap_app, ea3_ident_config, &node); - log_misc("module game init done"); + log_misc("app init done"); } -void bootstrap_module_game_run() +void bootstrap_app_run() { - log_info("module game run"); - - module_main_invoke(&_bootstrap_module_context); + app_main_invoke(&_bootstrap_app); } -void bootstrap_module_game_fini() +void bootstrap_app_fini() { - log_info("module game fini"); - - module_fini(&_bootstrap_module_context); + app_free(&_bootstrap_app); } void bootstrap_avs_fini() diff --git a/src/main/launcher/bootstrap.h b/src/main/launcher/bootstrap.h index 4deab8f..4285366 100644 --- a/src/main/launcher/bootstrap.h +++ b/src/main/launcher/bootstrap.h @@ -1,6 +1,8 @@ #ifndef LAUNCHER_BOOTSTRAP_H #define LAUNCHER_BOOTSTRAP_H +#include "core/property.h" + #include "launcher/bootstrap-config.h" #include "launcher/ea3-ident-config.h" @@ -13,19 +15,19 @@ void bootstrap_default_files_create( void bootstrap_avs_init( const struct bootstrap_boot_config *config, const struct bootstrap_log_config *log_config, - struct property *override_property); + const core_property_t *override_property); void bootstrap_eamuse_init( const struct bootstrap_eamuse_config *config, const struct ea3_ident_config *ea3_ident_config, - struct property *override_property); -void bootstrap_module_init( - const struct bootstrap_module_config *module_config, - const struct array *iat_hook_dlls); -void bootstrap_module_game_init( + const core_property_t *override_property); +HMODULE bootstrap_app_unresolved_init( + const struct bootstrap_module_config *module_config); +void bootstrap_app_resolve_init(); +void bootstrap_app_init( const struct bootstrap_module_config *module_config, struct ea3_ident_config *ea3_ident_config); -void bootstrap_module_game_run(); -void bootstrap_module_game_fini(); +void bootstrap_app_run(); +void bootstrap_app_fini(); void bootstrap_avs_fini(); void bootstrap_eamuse_fini(const struct bootstrap_eamuse_config *config); diff --git a/src/main/launcher/debug.c b/src/main/launcher/debug.c index 2f40e33..8f28121 100644 --- a/src/main/launcher/debug.c +++ b/src/main/launcher/debug.c @@ -4,7 +4,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "launcher/debug.h" diff --git a/src/main/launcher/ea3-ident-config.c b/src/main/launcher/ea3-ident-config.c index e8c5c4f..822de9e 100644 --- a/src/main/launcher/ea3-ident-config.c +++ b/src/main/launcher/ea3-ident-config.c @@ -2,12 +2,14 @@ #include -#include "core/log.h" +#include "core/property-node-ext.h" +#include "core/property-node.h" + +#include "iface-core/log.h" #include "imports/avs.h" #include "launcher/ea3-ident-config.h" -#include "launcher/property-util.h" #include "util/defs.h" #include "util/hex.h" @@ -15,18 +17,27 @@ #define ROOT_NODE "/ea3_conf" -PSMAP_BEGIN(ea3_ident_config_psmap) -PSMAP_OPTIONAL( - PSMAP_TYPE_STR, struct ea3_ident_config, softid, "/id/softid", "") -PSMAP_OPTIONAL( - PSMAP_TYPE_STR, struct ea3_ident_config, hardid, "/id/hardid", "") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident_config, pcbid, "/id/pcbid", "") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, model, "/soft/model") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, dest, "/soft/dest") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, spec, "/soft/spec") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, rev, "/soft/rev") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, ext, "/soft/ext") -PSMAP_END +static void _ea3_ident_config_root_get( + const core_property_t *property, core_property_node_t *node) +{ + core_property_node_result_t result; + char node_name[128]; + + log_assert(property); + log_assert(node); + + result = core_property_root_node_get(property, node); + core_property_fatal_on_error(result); + + result = core_property_node_name_get(node, node_name, sizeof(node_name)); + core_property_node_fatal_on_error(result); + + if (!str_eq(node_name, "ea3_conf")) { + log_fatal("Root node " ROOT_NODE " in ea3-ident config missing"); + } else { + core_property_node_fatal_on_error(result); + } +} void ea3_ident_config_init(struct ea3_ident_config *config) { @@ -36,38 +47,60 @@ void ea3_ident_config_init(struct ea3_ident_config *config) void ea3_ident_config_from_file_load( const char *path, struct ea3_ident_config *config) { - struct property *property; + core_property_t *property; + core_property_result_t result; log_assert(path); log_assert(config); log_info("Loading from file path: %s", path); - property = property_util_load(path); + result = core_property_file_load(path, &property); + core_property_fatal_on_error(result); ea3_ident_config_load(property, config); - property_util_free(property); + core_property_free(&property); } void ea3_ident_config_load( - struct property *property, struct ea3_ident_config *config) + const core_property_t *property, struct ea3_ident_config *config) { - struct property_node *node; + core_property_node_t node; + core_property_node_result_t result; log_assert(property); log_assert(config); - node = property_search(property, NULL, ROOT_NODE); + _ea3_ident_config_root_get(property, &node); - if (node == NULL) { - log_fatal("Root node '" ROOT_NODE "' missing"); - } + result = core_property_node_ext_str_read_or_default( + &node, "id/softid", config->softid, sizeof(config->softid), ""); + core_property_node_fatal_on_error(result); - if (!property_psmap_import( - property, node, config, ea3_ident_config_psmap)) { - log_fatal("Error reading config file"); - } + result = core_property_node_ext_str_read_or_default( + &node, "id/pcbid", config->pcbid, sizeof(config->pcbid), ""); + core_property_node_fatal_on_error(result); + + result = core_property_node_ext_str_read_or_default( + &node, "soft/model", config->model, sizeof(config->model), ""); + core_property_node_fatal_on_error(result); + + result = core_property_node_ext_str_read_or_default( + &node, "soft/dest", config->dest, sizeof(config->dest), ""); + core_property_node_fatal_on_error(result); + + result = core_property_node_ext_str_read_or_default( + &node, "soft/spec", config->spec, sizeof(config->spec), ""); + core_property_node_fatal_on_error(result); + + result = core_property_node_ext_str_read_or_default( + &node, "soft/rev", config->rev, sizeof(config->rev), ""); + core_property_node_fatal_on_error(result); + + result = core_property_node_ext_str_read_or_default( + &node, "soft/ext", config->ext, sizeof(config->ext), ""); + core_property_node_fatal_on_error(result); } bool ea3_ident_config_hardid_is_defined(struct ea3_ident_config *config) diff --git a/src/main/launcher/ea3-ident-config.h b/src/main/launcher/ea3-ident-config.h index 1a6dc7f..44d3d92 100644 --- a/src/main/launcher/ea3-ident-config.h +++ b/src/main/launcher/ea3-ident-config.h @@ -1,7 +1,7 @@ #ifndef LAUNCHER_EA3_IDENT_CONFIG_H #define LAUNCHER_EA3_IDENT_CONFIG_H -#include "imports/avs.h" +#include "core/property.h" /* N.B. even though this might look like a Konami ABI, this is purely an internal data structure. */ @@ -30,7 +30,7 @@ void ea3_ident_config_init(struct ea3_ident_config *config); void ea3_ident_config_from_file_load( const char *path, struct ea3_ident_config *config); void ea3_ident_config_load( - struct property *property, struct ea3_ident_config *config); + const core_property_t *property, struct ea3_ident_config *config); bool ea3_ident_config_hardid_is_defined(struct ea3_ident_config *config); void ea3_ident_config_hardid_from_ethernet_set(struct ea3_ident_config *config); diff --git a/src/main/launcher/eamuse-config.c b/src/main/launcher/eamuse-config.c index 020e17a..9a10aef 100644 --- a/src/main/launcher/eamuse-config.c +++ b/src/main/launcher/eamuse-config.c @@ -2,124 +2,135 @@ #include -#include "core/log.h" +#include "avs-ext/property-ext.h" -#include "imports/avs.h" +#include "core/property-node-ext.h" + +#include "iface-core/log.h" #include "launcher/ea3-ident-config.h" #include "launcher/eamuse-config.h" -#include "launcher/property-util.h" + +#include "util/str.h" #define EAMUSE_CONFIG_ROOT_NODE "/ea3" -struct property *eamuse_config_avs_load(const char *path) +core_property_t *eamuse_config_avs_load(const char *path) { - struct property *property; + core_property_t *property; + core_property_node_t node; log_assert(path); log_misc("Loading from avs path: %s", path); - property = property_util_avs_fs_load(path); + avs_ext_property_ext_avs_file_load(path, &property); // Check if root node exists, call already errors if not - eamuse_config_root_get(property); + eamuse_config_root_get(property, &node); return property; } -struct property_node *eamuse_config_root_get(struct property *property) +void eamuse_config_root_get( + core_property_t *property, core_property_node_t *node) { - struct property_node *node; + core_property_node_result_t result; + char node_name[128]; log_assert(property); + log_assert(node); - node = property_search(property, 0, EAMUSE_CONFIG_ROOT_NODE); + result = core_property_root_node_get(property, node); + core_property_node_fatal_on_error(result); - if (node == NULL) { + result = core_property_node_name_get(node, node_name, sizeof(node_name)); + core_property_node_fatal_on_error(result); + + if (!str_eq(node_name, "ea3")) { log_fatal("Root node " EAMUSE_CONFIG_ROOT_NODE " in eamuse config missing"); + } else { + core_property_node_fatal_on_error(result); } - - return node; } -void eamuse_config_id_softid_set(struct property_node *node, const char *value) +void eamuse_config_id_softid_set(core_property_node_t *node, const char *value) { log_assert(node); log_assert(value); - property_util_node_str_replace(NULL, node, "id/softid", value); + core_property_node_ext_str_replace(node, "id/softid", value); } -void eamuse_config_id_hardid_set(struct property_node *node, const char *value) +void eamuse_config_id_hardid_set(core_property_node_t *node, const char *value) { log_assert(node); log_assert(value); - property_util_node_str_replace(NULL, node, "id/hardid", value); + core_property_node_ext_str_replace(node, "id/hardid", value); } -void eamuse_config_id_pcbid_set(struct property_node *node, const char *value) +void eamuse_config_id_pcbid_set(core_property_node_t *node, const char *value) { log_assert(node); log_assert(value); - property_util_node_str_replace(NULL, node, "id/pcbid", value); + core_property_node_ext_str_replace(node, "id/pcbid", value); } -void eamuse_config_soft_model_set(struct property_node *node, const char *value) +void eamuse_config_soft_model_set(core_property_node_t *node, const char *value) { log_assert(node); log_assert(value); - property_util_node_str_replace(NULL, node, "soft/model", value); + core_property_node_ext_str_replace(node, "soft/model", value); } -void eamuse_config_soft_dest_set(struct property_node *node, const char *value) +void eamuse_config_soft_dest_set(core_property_node_t *node, const char *value) { log_assert(node); log_assert(value); - property_util_node_str_replace(NULL, node, "soft/dest", value); + core_property_node_ext_str_replace(node, "soft/dest", value); } -void eamuse_config_soft_spec_set(struct property_node *node, const char *value) +void eamuse_config_soft_spec_set(core_property_node_t *node, const char *value) { log_assert(node); log_assert(value); - property_util_node_str_replace(NULL, node, "soft/spec", value); + core_property_node_ext_str_replace(node, "soft/spec", value); } -void eamuse_config_soft_rev_set(struct property_node *node, const char *value) +void eamuse_config_soft_rev_set(core_property_node_t *node, const char *value) { log_assert(node); log_assert(value); - property_util_node_str_replace(NULL, node, "soft/rev", value); + core_property_node_ext_str_replace(node, "soft/rev", value); } -void eamuse_config_soft_ext_set(struct property_node *node, const char *value) +void eamuse_config_soft_ext_set(core_property_node_t *node, const char *value) { log_assert(node); log_assert(value); - property_util_node_str_replace(NULL, node, "soft/ext", value); + core_property_node_ext_str_replace(node, "soft/ext", value); } -void eamuse_config_network_url_slash_set(struct property_node *node, bool value) +void eamuse_config_network_url_slash_set(core_property_node_t *node, bool value) { log_assert(node); - property_util_node_bool_replace(NULL, node, "network/url_slash", value); + core_property_node_ext_bool_replace(node, "network/url_slash", value); } void eamuse_config_network_service_url_set( - struct property_node *node, const char *value) + core_property_node_t *node, const char *value) { log_assert(node); log_assert(value); - property_util_node_str_replace(NULL, node, "network/services", value); + core_property_node_ext_str_replace(node, "network/services", value); } \ No newline at end of file diff --git a/src/main/launcher/eamuse-config.h b/src/main/launcher/eamuse-config.h index 2cba227..d5e45ab 100644 --- a/src/main/launcher/eamuse-config.h +++ b/src/main/launcher/eamuse-config.h @@ -1,23 +1,25 @@ #ifndef LAUNCHER_EAMUSE_CONFIG_H #define LAUNCHER_EAMUSE_CONFIG_H -#include "imports/avs.h" +#include "core/property-node.h" +#include "core/property.h" -struct property *eamuse_config_avs_load(const char *path); -struct property_node *eamuse_config_root_get(struct property *property); +core_property_t *eamuse_config_avs_load(const char *path); +void eamuse_config_root_get( + core_property_t *property, core_property_node_t *node); -void eamuse_config_id_softid_set(struct property_node *node, const char *value); -void eamuse_config_id_hardid_set(struct property_node *node, const char *value); -void eamuse_config_id_pcbid_set(struct property_node *node, const char *value); +void eamuse_config_id_softid_set(core_property_node_t *node, const char *value); +void eamuse_config_id_hardid_set(core_property_node_t *node, const char *value); +void eamuse_config_id_pcbid_set(core_property_node_t *node, const char *value); void eamuse_config_soft_model_set( - struct property_node *node, const char *value); -void eamuse_config_soft_dest_set(struct property_node *node, const char *value); -void eamuse_config_soft_spec_set(struct property_node *node, const char *value); -void eamuse_config_soft_rev_set(struct property_node *node, const char *value); -void eamuse_config_soft_ext_set(struct property_node *node, const char *value); + core_property_node_t *node, const char *value); +void eamuse_config_soft_dest_set(core_property_node_t *node, const char *value); +void eamuse_config_soft_spec_set(core_property_node_t *node, const char *value); +void eamuse_config_soft_rev_set(core_property_node_t *node, const char *value); +void eamuse_config_soft_ext_set(core_property_node_t *node, const char *value); void eamuse_config_network_url_slash_set( - struct property_node *node, bool value); + core_property_node_t *node, bool value); void eamuse_config_network_service_url_set( - struct property_node *node, const char *value); + core_property_node_t *node, const char *value); #endif \ No newline at end of file diff --git a/src/main/launcher/eamuse.c b/src/main/launcher/eamuse.c index 39e560d..b71cf6c 100644 --- a/src/main/launcher/eamuse.c +++ b/src/main/launcher/eamuse.c @@ -1,16 +1,22 @@ #define LOG_MODULE "eamuse" -#include "core/log.h" +#include "avs-ext/property-node.h" + +#include "iface-core/log.h" #include "imports/avs-ea3.h" -void eamuse_init(struct property_node *node) +void eamuse_init(const core_property_node_t *node) { + struct property_node *node_avs; + log_assert(node); log_info("init"); - ea3_boot(node); + node_avs = avs_ext_property_node_avs_property_node_get(node); + + ea3_boot(node_avs); log_misc("init done"); } diff --git a/src/main/launcher/eamuse.h b/src/main/launcher/eamuse.h index 1cd1f7e..eb5eb47 100644 --- a/src/main/launcher/eamuse.h +++ b/src/main/launcher/eamuse.h @@ -1,9 +1,9 @@ #ifndef LAUNCHER_EAMUSE_H #define LAUNCHER_EAMUSE_H -#include "imports/avs.h" +#include "core/property-node.h" -void eamuse_init(struct property_node *node); +void eamuse_init(const core_property_node_t *node); void eamuse_fini(); #endif \ No newline at end of file diff --git a/src/main/launcher/hook.c b/src/main/launcher/hook.c deleted file mode 100644 index d7be37a..0000000 --- a/src/main/launcher/hook.c +++ /dev/null @@ -1,34 +0,0 @@ -#define LOG_MODULE "hook" - -#include - -#include "core/log.h" - -#include "launcher/hook.h" - -void hook_load_dll(const char *path) -{ - log_assert(path); - - log_info("Load hook dll: %s", path); - - if (LoadLibraryA(path) == NULL) { - LPSTR buffer; - - FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR) &buffer, - 0, - NULL); - - log_fatal("%s: Failed to load hook DLL: %s", path, buffer); - - LocalFree(buffer); - } - - log_misc("Load hook dll done"); -} \ No newline at end of file diff --git a/src/main/launcher/hook.h b/src/main/launcher/hook.h deleted file mode 100644 index 9d0c5d4..0000000 --- a/src/main/launcher/hook.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef LAUNCHER_HOOK_H -#define LAUNCHER_HOOK_H - -void hook_load_dll(const char *path); - -#endif \ No newline at end of file diff --git a/src/main/launcher/hooks.c b/src/main/launcher/hooks.c new file mode 100644 index 0000000..cbc9d8e --- /dev/null +++ b/src/main/launcher/hooks.c @@ -0,0 +1,211 @@ +#define LOG_MODULE "hooks" + +#include "core/config-property-node.h" +#include "core/property-node.h" + +#include "iface-core/config.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface/hook.h" + +#include "module/hook.h" + +#define MAX_HOOKS 64 + +typedef struct hooks_hook { + module_hook_t *module; + bt_hook_t *hook; + const core_property_node_t *node; +} hooks_hook_t; + +static hooks_hook_t _module_hooks[MAX_HOOKS]; +static uint32_t _hooks_count; + +void hooks_init() +{ + log_info("init"); + + memset(_module_hooks, 0, sizeof(_module_hooks)); + _hooks_count = 0; + + log_misc("init done"); +} + +void hooks_hook_load(const char *path, const core_property_node_t *node) +{ + module_hook_t *module; + bt_hook_api_t api; + bt_hook_t *hook; + + log_assert(path); + log_assert(node); + + log_misc("load: %s", path); + + if (_hooks_count >= MAX_HOOKS) { + log_fatal("Cannot load more hooks, max supported capacity reached"); + } + + module_hook_load(path, &module); + module_hook_api_get(module, &api); + bt_hook_init(&api, path, &hook); + + _module_hooks[_hooks_count].module = module; + _module_hooks[_hooks_count].hook = hook; + _module_hooks[_hooks_count].node = node; + _hooks_count++; +} + +void hooks_core_config_api_set() +{ + bt_core_config_api_t api; + uint32_t i; + + bt_core_config_api_get(&api); + + log_info("core_config_api_set"); + + for (i = 0; i < _hooks_count; i++) { + module_hook_core_config_api_set(_module_hooks[i].module, &api); + } + + log_misc("core_config_api_set done"); +} + +void hooks_core_log_api_set() +{ + bt_core_log_api_t api; + uint32_t i; + + bt_core_log_api_get(&api); + + log_info("core_log_api_set"); + + for (i = 0; i < _hooks_count; i++) { + module_hook_core_log_api_set(_module_hooks[i].module, &api); + } + + log_misc("core_log_api_set done"); +} + +void hooks_core_thread_api_set() +{ + bt_core_thread_api_t api; + uint32_t i; + + bt_core_thread_api_get(&api); + + log_info("core_thread_api_set"); + + for (i = 0; i < _hooks_count; i++) { + module_hook_core_thread_api_set(_module_hooks[i].module, &api); + } + + log_misc("core_thread_api_set done"); +} + +void hooks_pre_avs_init() +{ + uint32_t i; + bt_core_config_t *config; + bool result; + + log_info("pre_avs_init"); + + for (i = 0; i < _hooks_count; i++) { + core_config_property_node_init(_module_hooks[i].node, &config); + + result = bt_hook_pre_avs_init(_module_hooks[i].hook, config); + + core_config_property_node_free(&config); + + if (!result) { + log_fatal( + "%s: pre avs initializing hook failed", + module_hook_path_get(_module_hooks[i].module)); + } + } + + log_misc("pre_avs_init done"); +} + +void hooks_iat_apply(HMODULE game_module) +{ + uint32_t i; + char iat_dll_name[PATH_MAX]; + + log_info("iat_apply"); + + for (i = 0; i < _hooks_count; i++) { + bt_hook_iat_dll_name_get( + _module_hooks[i].hook, iat_dll_name, sizeof(iat_dll_name)); + + // TODO fix iat hooking + // module_hook_iat_apply(game_module, "source_dll?", iat_dll_name); + + // static void _module_hook_dll_iat( + // HMODULE hModule, const char *source_dll, const char *iat_hook) + + // (&, game_module); + } + + log_misc("iat_apply done"); +} + +void hooks_main_init(HMODULE game_module) +{ + uint32_t i; + bt_core_config_t *config; + bool result; + + log_assert(game_module); + + log_info("main_init"); + + for (i = 0; i < _hooks_count; i++) { + core_config_property_node_init(_module_hooks[i].node, &config); + + result = bt_hook_main_init(_module_hooks[i].hook, game_module, config); + + core_config_property_node_free(&config); + + if (!result) { + log_fatal( + "%s: Initializing hook failed", + module_hook_path_get(_module_hooks[i].module)); + } + } + + log_misc("main_init done"); +} + +void hooks_main_fini() +{ + uint32_t i; + + log_info("main_fini"); + + for (i = 0; i < _hooks_count; i++) { + bt_hook_main_fini(_module_hooks[i].hook); + } + + log_misc("main_fini done"); +} + +void hooks_fini() +{ + uint32_t i; + + log_info("fini"); + + for (i = 0; i < _hooks_count; i++) { + bt_hook_fini(&_module_hooks[i].hook); + module_hook_free(&_module_hooks[i].module); + } + + // node is just a reference to the property which is managed externally + + memset(_module_hooks, 0, sizeof(_module_hooks)); + + log_misc("fini done"); +} \ No newline at end of file diff --git a/src/main/launcher/hooks.h b/src/main/launcher/hooks.h new file mode 100644 index 0000000..5623513 --- /dev/null +++ b/src/main/launcher/hooks.h @@ -0,0 +1,28 @@ +#ifndef LAUNCHER_HOOKS_H +#define LAUNCHER_HOOKS_H + +#include + +#include "core/property-node.h" + +void hooks_init(); + +void hooks_hook_load(const char *path, const core_property_node_t *node); + +void hooks_core_config_api_set(); + +void hooks_core_log_api_set(); + +void hooks_core_thread_api_set(); + +void hooks_pre_avs_init(); + +void hooks_iat_apply(HMODULE game_module); + +void hooks_main_init(HMODULE game_module); + +void hooks_main_fini(); + +void hooks_fini(); + +#endif \ No newline at end of file diff --git a/src/main/launcher/launcher-config.c b/src/main/launcher/launcher-config.c index 6f278e0..4ae831a 100644 --- a/src/main/launcher/launcher-config.c +++ b/src/main/launcher/launcher-config.c @@ -2,31 +2,18 @@ #include -#include "core/log.h" +#include "core/property-ext.h" +#include "core/property-node-ext.h" +#include "core/property-node.h" +#include "core/property.h" -#include "imports/avs.h" +#include "iface-core/log.h" #include "launcher/launcher-config.h" -#include "launcher/property-util.h" #include "util/mem.h" #include "util/str.h" -// clang-format off -PSMAP_BEGIN(launcher_debug_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, remote_debugger, - "debug/remote_debugger", false) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, log_property_configs, - "debug/log_property_configs", false) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, procmon_file, - "debug/procmon/file", false) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, procmon_module, - "debug/procmon/module", false) -PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, procmon_thread, - "debug/procmon/thread", false) -PSMAP_END -// clang-format on - #define ROOT_NODE "/launcher" #define MAX_LAYER_CONFIG_NODES 8 @@ -35,114 +22,105 @@ PSMAP_END #define NODE_LOADING_FATAL(subnode) \ log_fatal("%s/%s: Node loading", ROOT_NODE, subnode); -static struct property * -_launcher_config_layered_config_nodes_load(struct property_node *node) +static core_property_t * +_launcher_config_layered_config_nodes_load(const core_property_node_t *node) { char kind[64]; char file[MAX_PATH]; - int res; int cnt; - struct property_node *cur; - struct property *config_property[MAX_LAYER_CONFIG_NODES]; - struct property *merged_property; + core_property_node_t cur; + core_property_node_t tmp; + core_property_t *config_property[MAX_LAYER_CONFIG_NODES]; + core_property_t *merged_property; + core_property_node_result_t result; + core_property_result_t prop_result; log_assert(node); cnt = 0; - cur = property_search(NULL, node, "config"); + result = core_property_node_search(node, "config", &cur); - while (cur) { + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } + + while (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { if (cnt >= MAX_LAYER_CONFIG_NODES) { log_fatal( "Exceeding max supported config nodes for layering, max is %d", MAX_LAYER_CONFIG_NODES); } - res = property_node_refer( - NULL, cur, "kind@", PROPERTY_TYPE_ATTR, kind, sizeof(kind)); + result = + core_property_node_ext_attr_read(&cur, "kind@", kind, sizeof(kind)); - if (res < 0) { + if (CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { log_fatal("Failed reading 'kind' attribute value of config node"); } if (!strcmp(kind, "file")) { - property_node_read(cur, PROPERTY_TYPE_STR, file, sizeof(file)); + core_property_node_str_read(&cur, file, sizeof(file)); - config_property[cnt] = property_util_load(file); + prop_result = core_property_file_load(file, &config_property[cnt]); + core_property_fatal_on_error(prop_result); } else if (!strcmp(kind, "inline")) { // The nested child is the actual root of the inline, not the outer // node - cur = property_node_traversal(cur, TRAVERSE_FIRST_CHILD); + result = core_property_node_child_get(&cur, &tmp); + memcpy(&cur, &tmp, sizeof(core_property_node_t)); - config_property[cnt] = property_util_node_extract(cur); + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } + + result = + core_property_node_ext_extract(&cur, &config_property[cnt]); + core_property_node_fatal_on_error(result); } else { log_fatal( "Unsupported 'kind' attribute value '%s' of config node", kind); } cnt++; - cur = property_node_traversal(cur, TRAVERSE_NEXT_SEARCH_RESULT); + result = core_property_node_next_result_search(&cur, &tmp); + memcpy(&cur, &tmp, sizeof(core_property_node_t)); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } } if (cnt == 0) { return NULL; } - merged_property = property_util_many_merge(config_property, cnt); + prop_result = + core_property_ext_many_merge(config_property, cnt, &merged_property); + core_property_fatal_on_error(prop_result); for (int i = 0; i < cnt; i++) { - property_util_free(config_property[i]); + core_property_free(&config_property[i]); } return merged_property; } -static void _launcher_config_hook_dlls_parse( - struct property_node *node, - const char *node_path, - char dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]) -{ - int cnt; - struct property_node *cur; - - cnt = 0; - cur = property_search(NULL, node, node_path); - - while (cur) { - if (cnt >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { - log_warning( - "Currently not supporting more than %d dlls, skipping " - "remaining", - cnt); - break; - } - - property_node_read(cur, PROPERTY_TYPE_STR, dlls[cnt], MAX_PATH); - - cnt++; - cur = property_node_traversal(cur, TRAVERSE_NEXT_SEARCH_RESULT); - } -} - static void _launcher_config_bootstrap_load( - struct property_node *node, struct launcher_bootstrap_config *config) + const core_property_node_t *node, struct launcher_bootstrap_config *config) { - int res; + core_property_node_result_t result; log_assert(node); log_assert(config); - res = property_node_refer( - NULL, - node, - "selector", - PROPERTY_TYPE_STR, - config->selector, - sizeof(config->selector)); + result = core_property_node_ext_str_read( + node, "selector", config->selector, sizeof(config->selector)); - if (res < 0) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { NODE_MISSING_FATAL("bootstrap/selector"); + } else { + core_property_node_fatal_on_error(result); } config->property = _launcher_config_layered_config_nodes_load(node); @@ -152,28 +130,229 @@ static void _launcher_config_bootstrap_load( } } -static void _launcher_config_hook_load( - struct property_node *node, struct launcher_hook_config *config) +static void _launcher_config_hook_hook_load( + const core_property_node_t *node, struct launcher_hook_config_hook *config) +{ + core_property_node_result_t result; + core_property_result_t prop_result; + + result = core_property_node_ext_bool_read(node, "enable", &config->enable); + core_property_node_fatal_on_error(result); + + result = core_property_node_ext_str_read( + node, "path", config->path, sizeof(config->path)); + core_property_node_fatal_on_error(result); + + config->property = _launcher_config_layered_config_nodes_load(node); + + // Default empty config + if (!config->property) { + prop_result = core_property_str_load( + "1", + &config->property); + core_property_fatal_on_error(prop_result); + } +} + +static void _launcher_config_hook_pre_avs_load( + const core_property_node_t *node, + struct launcher_hook_config_pre_avs *config) +{ + core_property_node_result_t result; + core_property_result_t prop_result; + + result = core_property_node_ext_bool_read(node, "enable", &config->enable); + core_property_node_fatal_on_error(result); + + result = core_property_node_ext_str_read( + node, "path", config->path, sizeof(config->path)); + core_property_node_fatal_on_error(result); + + config->property = _launcher_config_layered_config_nodes_load(node); + + // Default empty config + if (!config->property) { + prop_result = core_property_str_load( + "1", + &config->property); + core_property_fatal_on_error(prop_result); + } +} + +static void _launcher_config_hook_iat_load( + const core_property_node_t *node, struct launcher_hook_config_iat *config) +{ + core_property_node_result_t result; + core_property_result_t prop_result; + + result = core_property_node_ext_bool_read(node, "enable", &config->enable); + core_property_node_fatal_on_error(result); + + result = core_property_node_ext_str_read( + node, "source_name", config->source_name, sizeof(config->source_name)); + core_property_node_fatal_on_error(result); + + result = core_property_node_ext_str_read( + node, "path", config->path, sizeof(config->path)); + core_property_node_fatal_on_error(result); + + config->property = _launcher_config_layered_config_nodes_load(node); + + // Default empty config + if (!config->property) { + prop_result = core_property_str_load( + "1", + &config->property); + core_property_fatal_on_error(prop_result); + } +} + +static void _launcher_config_hooks_hook_load( + const core_property_node_t *node, struct launcher_hook_config *config) +{ + int cnt; + core_property_node_t tmp; + core_property_node_t cur; + core_property_node_result_t result; + + log_assert(node); + log_assert(config); + + cnt = 0; + result = core_property_node_search(node, "hook", &cur); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } + + while (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + if (cnt >= LAUNCHER_CONFIG_MAX_HOOKS) { + log_warning( + "Currently not supporting more than %d hooks, skipping " + "remaining", + cnt); + break; + } + + _launcher_config_hook_hook_load(&cur, &config->hook[cnt]); + + cnt++; + result = core_property_node_next_result_search(&cur, &tmp); + memcpy(&cur, &tmp, sizeof(core_property_node_t)); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } + } +} + +static void _launcher_config_hooks_pre_avs_load( + const core_property_node_t *node, struct launcher_hook_config *config) +{ + int cnt; + core_property_node_t tmp; + core_property_node_t cur; + core_property_node_result_t result; + + log_assert(node); + log_assert(config); + + cnt = 0; + result = core_property_node_search(node, "pre_avs", &cur); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } + + while (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + if (cnt >= LAUNCHER_CONFIG_MAX_HOOKS) { + log_warning( + "Currently not supporting more than %d hooks, skipping " + "remaining", + cnt); + break; + } + + _launcher_config_hook_pre_avs_load(&cur, &config->pre_avs[cnt]); + + cnt++; + result = core_property_node_next_result_search(&cur, &tmp); + memcpy(&cur, &tmp, sizeof(core_property_node_t)); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } + } +} + +static void _launcher_config_hooks_iat_load( + const core_property_node_t *node, struct launcher_hook_config *config) +{ + int cnt; + core_property_node_t tmp; + core_property_node_t cur; + core_property_node_result_t result; + + log_assert(node); + log_assert(config); + + cnt = 0; + result = core_property_node_search(node, "iat", &cur); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } + + while (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + if (cnt >= LAUNCHER_CONFIG_MAX_HOOKS) { + log_warning( + "Currently not supporting more than %d hooks, skipping " + "remaining", + cnt); + break; + } + + _launcher_config_hook_iat_load(&cur, &config->iat[cnt]); + + cnt++; + result = core_property_node_next_result_search(&cur, &tmp); + memcpy(&cur, &tmp, sizeof(core_property_node_t)); + + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } + } +} + +static void _launcher_config_hooks_load( + const core_property_node_t *node, struct launcher_hook_config *config) { log_assert(node); log_assert(config); - _launcher_config_hook_dlls_parse(node, "hook_dlls/dll", config->hook_dlls); - _launcher_config_hook_dlls_parse( - node, "before_hook_dlls/dll", config->before_hook_dlls); - _launcher_config_hook_dlls_parse( - node, "iat_hook_dlls/dll", config->iat_hook_dlls); + _launcher_config_hooks_hook_load(node, config); + _launcher_config_hooks_pre_avs_load(node, config); + _launcher_config_hooks_iat_load(node, config); } static void _launcher_config_debug_load( - struct property_node *node, struct launcher_debug_config *config) + const core_property_node_t *node, struct launcher_debug_config *config) { + core_property_node_result_t result; + log_assert(node); log_assert(config); - if (!property_psmap_import(NULL, node, config, launcher_debug_psmap)) { - NODE_LOADING_FATAL("debug"); - } + result = core_property_node_ext_bool_read_or_default( + node, "debug/remote_debugger", &config->remote_debugger, false); + core_property_node_fatal_on_error(result); + + result = core_property_node_ext_bool_read_or_default( + node, + "debug/log_property_configs", + &config->log_property_configs, + false); + core_property_node_fatal_on_error(result); } void launcher_config_init(struct launcher_config *config) @@ -189,192 +368,205 @@ void launcher_config_init(struct launcher_config *config) config->eamuse.property = NULL; - memset(config->hook.hook_dlls, 0, sizeof(config->hook.hook_dlls)); - memset( - config->hook.before_hook_dlls, - 0, - sizeof(config->hook.before_hook_dlls)); - memset(config->hook.iat_hook_dlls, 0, sizeof(config->hook.iat_hook_dlls)); + memset(&config->hook, 0, sizeof(config->hook)); config->debug.remote_debugger = false; config->debug.log_property_configs = false; - config->debug.procmon_file = false; - config->debug.procmon_module = false; - config->debug.procmon_thread = false; } void launcher_config_load( - struct property *property, struct launcher_config *config) + const core_property_t *property, struct launcher_config *config) { - struct property_node *root_node; - struct property_node *node; - avs_error error; + core_property_node_t root_node; + core_property_node_t node; + core_property_node_result_t result; + core_property_result_t result_prop; log_assert(property); log_assert(config); - root_node = property_search(property, NULL, ROOT_NODE); + result_prop = core_property_root_node_get(property, &root_node); + core_property_fatal_on_error(result_prop); - if (root_node == NULL) { - NODE_MISSING_FATAL(""); + result = core_property_node_search(&root_node, "version", &node); + + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + NODE_MISSING_FATAL("version"); + } else { + core_property_node_fatal_on_error(result); } - error = property_node_refer( - NULL, - root_node, - "version@", - PROPERTY_TYPE_ATTR, - &config->version, - sizeof(uint32_t)); + result = core_property_node_u32_read(&node, &config->version); - if (AVS_IS_ERROR(error)) { - log_fatal("Missing version attribute on root node"); + core_property_node_fatal_on_error(result); + + if (config->version != 1) { + log_fatal( + "Unsupported version of launcher configuration: %d", + config->version); } - // if (config->version != 1) { - // log_fatal("Unsupported version of launcher configuration: %d", - // config->version); - // } + result = core_property_node_search(&root_node, "bootstrap", &node); - node = property_search(NULL, root_node, "bootstrap"); - - if (node == NULL) { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { NODE_MISSING_FATAL("bootstrap"); + } else { + core_property_node_fatal_on_error(result); } - _launcher_config_bootstrap_load(node, &config->bootstrap); + _launcher_config_bootstrap_load(&node, &config->bootstrap); - node = property_search(NULL, root_node, "avs"); + result = core_property_node_search(&root_node, "avs", &node); - if (node) { - config->avs.property = _launcher_config_layered_config_nodes_load(node); + if (!CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + config->avs.property = + _launcher_config_layered_config_nodes_load(&node); + } else { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + result_prop = core_property_str_load( + "", &config->avs.property); + core_property_fatal_on_error(result_prop); + } else { + core_property_node_fatal_on_error(result); + } } - node = property_search(NULL, root_node, "ea3_ident"); + result = core_property_node_search(&root_node, "ea3_ident", &node); - if (node) { + if (!CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { config->ea3_ident.property = - _launcher_config_layered_config_nodes_load(node); + _launcher_config_layered_config_nodes_load(&node); + } else { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + result_prop = core_property_str_load( + "", &config->ea3_ident.property); + core_property_fatal_on_error(result_prop); + } else { + core_property_node_fatal_on_error(result); + } } - node = property_search(NULL, root_node, "eamuse"); + result = core_property_node_search(&root_node, "eamuse", &node); - if (node) { + if (!CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { config->eamuse.property = - _launcher_config_layered_config_nodes_load(node); + _launcher_config_layered_config_nodes_load(&node); + } else { + if (result == CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + result_prop = + core_property_str_load("", &config->eamuse.property); + core_property_fatal_on_error(result_prop); + } else { + core_property_node_fatal_on_error(result); + } } - node = property_search(NULL, root_node, "hook"); + result = core_property_node_search(&root_node, "hook", &node); - if (node) { - _launcher_config_hook_load(node, &config->hook); + if (!CORE_PROPERTY_NODE_RESULT_IS_ERROR(result)) { + _launcher_config_hooks_load(&node, &config->hook); + } else { + if (result != CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND) { + core_property_node_fatal_on_error(result); + } } + // No defaults - _launcher_config_debug_load(root_node, &config->debug); + _launcher_config_debug_load(&root_node, &config->debug); } -bool launcher_config_add_hook_dll( +bool launcher_config_hooks_hook_add( struct launcher_config *config, const char *path) { int i; + core_property_result_t result; log_assert(config); log_assert(path); i = 0; - while (i < LAUNCHER_CONFIG_MAX_HOOK_DLL) { - if (strlen(config->hook.hook_dlls[i]) == 0) { + while (i < LAUNCHER_CONFIG_MAX_HOOKS) { + if (!launcher_config_hooks_hook_available(&config->hook.hook[i])) { break; } i++; } - if (i >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { + if (i >= LAUNCHER_CONFIG_MAX_HOOKS) { return false; } - str_cpy(config->hook.hook_dlls[i], sizeof(config->hook.hook_dlls[i]), path); + config->hook.hook[i].enable = true; + str_cpy(config->hook.hook[i].path, sizeof(config->hook.hook[i].path), path); + result = core_property_str_load( + "1", + &config->hook.hook[i].property); + core_property_fatal_on_error(result); return true; } -bool launcher_config_add_before_hook_dll( - struct launcher_config *config, const char *path) +bool launcher_config_hooks_hook_available( + const struct launcher_hook_config_hook *config) { - int i; - log_assert(config); - log_assert(path); - i = 0; - - while (i < LAUNCHER_CONFIG_MAX_HOOK_DLL) { - if (strlen(config->hook.before_hook_dlls[i]) == 0) { - break; - } - - i++; - } - - if (i >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { - return false; - } - - str_cpy( - config->hook.before_hook_dlls[i], - sizeof(config->hook.before_hook_dlls[i]), - path); - - return true; + return strlen(config->path) > 0; } -bool launcher_config_add_iat_hook_dll( - struct launcher_config *config, const char *path) +bool launcher_config_hooks_pre_avs_hook_available( + const struct launcher_hook_config_pre_avs *config) { - int i; - log_assert(config); - log_assert(path); - i = 0; + return strlen(config->path) > 0; +} - while (i < LAUNCHER_CONFIG_MAX_HOOK_DLL) { - if (strlen(config->hook.iat_hook_dlls[i]) == 0) { - break; - } +bool launcher_config_hooks_iat_hook_available( + const struct launcher_hook_config_iat *config) +{ + log_assert(config); - i++; - } - - if (i >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { - return false; - } - - str_cpy( - config->hook.iat_hook_dlls[i], - sizeof(config->hook.iat_hook_dlls[i]), - path); - - return true; + return strlen(config->path) > 0; } void launcher_config_fini(struct launcher_config *config) { + int i; + log_assert(config); - property_util_free(config->bootstrap.property); + core_property_free(&config->bootstrap.property); if (config->avs.property) { - property_util_free(config->avs.property); + core_property_free(&config->avs.property); } if (config->ea3_ident.property) { - property_util_free(config->ea3_ident.property); + core_property_free(&config->ea3_ident.property); } if (config->eamuse.property) { - property_util_free(config->eamuse.property); + core_property_free(&config->eamuse.property); + } + + for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOKS; i++) { + if (config->hook.hook[i].property) { + core_property_free(&config->hook.hook[i].property); + } + } + + for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOKS; i++) { + if (config->hook.pre_avs[i].property) { + core_property_free(&config->hook.pre_avs[i].property); + } + } + + for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOKS; i++) { + if (config->hook.iat[i].property) { + core_property_free(&config->hook.iat[i].property); + } } } \ No newline at end of file diff --git a/src/main/launcher/launcher-config.h b/src/main/launcher/launcher-config.h index 2747a70..11bdb62 100644 --- a/src/main/launcher/launcher-config.h +++ b/src/main/launcher/launcher-config.h @@ -3,34 +3,49 @@ #include -#include "util/array.h" +#include "core/property.h" -#define LAUNCHER_CONFIG_MAX_HOOK_DLL 16 +#define LAUNCHER_CONFIG_MAX_HOOKS 16 struct launcher_config { uint32_t version; struct launcher_bootstrap_config { char selector[128]; - struct property *property; + core_property_t *property; } bootstrap; struct launcher_avs_config { - struct property *property; + core_property_t *property; } avs; struct launcher_ea3_ident_config { - struct property *property; + core_property_t *property; } ea3_ident; struct launcher_eamuse_config { - struct property *property; + core_property_t *property; } eamuse; struct launcher_hook_config { - char hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]; - char before_hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]; - char iat_hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]; + struct launcher_hook_config_hook { + bool enable; + char path[MAX_PATH]; + core_property_t *property; + } hook[LAUNCHER_CONFIG_MAX_HOOKS]; + + struct launcher_hook_config_pre_avs { + bool enable; + char path[MAX_PATH]; + core_property_t *property; + } pre_avs[LAUNCHER_CONFIG_MAX_HOOKS]; + + struct launcher_hook_config_iat { + bool enable; + char source_name[MAX_PATH]; + char path[MAX_PATH]; + core_property_t *property; + } iat[LAUNCHER_CONFIG_MAX_HOOKS]; } hook; struct launcher_debug_config { @@ -45,15 +60,20 @@ struct launcher_config { void launcher_config_init(struct launcher_config *config); void launcher_config_load( - struct property *property, struct launcher_config *config); + const core_property_t *property, struct launcher_config *config); -bool launcher_config_add_hook_dll( - struct launcher_config *config, const char *path); -bool launcher_config_add_before_hook_dll( - struct launcher_config *config, const char *path); -bool launcher_config_add_iat_hook_dll( +bool launcher_config_hooks_hook_add( struct launcher_config *config, const char *path); +bool launcher_config_hooks_hook_available( + const struct launcher_hook_config_hook *config); + +bool launcher_config_hooks_pre_avs_hook_available( + const struct launcher_hook_config_pre_avs *config); + +bool launcher_config_hooks_iat_hook_available( + const struct launcher_hook_config_iat *config); + void launcher_config_fini(struct launcher_config *config); #endif \ No newline at end of file diff --git a/src/main/launcher/launcher.c b/src/main/launcher/launcher.c index 388e054..a798703 100644 --- a/src/main/launcher/launcher.c +++ b/src/main/launcher/launcher.c @@ -7,16 +7,24 @@ #include #include +#include "avs-ext/property-node.h" +#include "avs-ext/property.h" + +#include "core/config-property-node.h" #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-file.h" #include "core/log-sink-list.h" #include "core/log-sink-std.h" -#include "core/log.h" +#include "core/thread-crt.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" #include "imports/avs-ea3.h" #include "imports/avs.h" +#include "launcher/app.h" #include "launcher/avs-config.h" #include "launcher/avs.h" #include "launcher/bootstrap-config.h" @@ -25,16 +33,12 @@ #include "launcher/ea3-ident-config.h" #include "launcher/eamuse-config.h" #include "launcher/eamuse.h" -#include "launcher/hook.h" +#include "launcher/hooks.h" #include "launcher/launcher-config.h" -#include "launcher/module.h" #include "launcher/options.h" -#include "launcher/property-util.h" #include "launcher/stubs.h" #include "launcher/version.h" -#include "procmon-lib/procmon.h" - #include "util/debug.h" #include "util/defs.h" #include "util/fs.h" @@ -58,15 +62,14 @@ static void _launcher_log_header() "launcher build date %s, gitrev %s", launcher_build_date, launcher_gitrev); + log_info("Linked AVS version %s", launcher_linked_avs_version); } void _launcher_log_init( const char *log_file_path, enum core_log_bt_log_level level) { - struct core_log_sink sinks[2]; - struct core_log_sink sink_composed; - - core_log_bt_ext_impl_set(); + core_log_sink_t sinks[2]; + core_log_sink_t sink_composed; if (log_file_path) { core_log_sink_std_out_open(true, &sinks[0]); @@ -77,6 +80,9 @@ void _launcher_log_init( } core_log_bt_init(&sink_composed); + + core_log_bt_core_api_set(); + core_log_bt_level_set(level); } @@ -119,6 +125,8 @@ static void _launcher_bootstrap_config_options_override( struct launcher_bootstrap_config *config, const struct options_bootstrap *options) { + core_property_result_t result; + log_assert(config); log_assert(options); @@ -127,8 +135,10 @@ static void _launcher_bootstrap_config_options_override( "Command line override bootstrap configuration from file: %s", options->config_path); - property_util_free(config->property); - config->property = property_util_load(options->config_path); + core_property_free(&config->property); + result = + core_property_file_load(options->config_path, &config->property); + core_property_node_fatal_on_error(result); } if (options->selector) { @@ -155,44 +165,22 @@ static void _launcher_ea3_ident_config_options_override( } static void _launcher_hook_config_options_override( - struct launcher_config *config, const struct options_hook *options) + struct launcher_config *config, const struct options_hooks *options) { size_t i; - const char *dll; + const char *path; log_assert(config); log_assert(options); - for (i = 0; i < options->hook_dlls.nitems; i++) { - dll = *array_item(const char *, &options->hook_dlls, i); + for (i = 0; i < options->paths.nitems; i++) { + path = *array_item(const char *, &options->paths, i); - if (!launcher_config_add_hook_dll(config, dll)) { + if (!launcher_config_hooks_hook_add(config, path)) { log_warning( "Adding override hook dll '%s' failed (max supported limit " "exceeded), ignored", - dll); - } - } - - for (i = 0; i < options->before_hook_dlls.nitems; i++) { - dll = *array_item(const char *, &options->before_hook_dlls, i); - - if (!launcher_config_add_before_hook_dll(config, dll)) { - log_warning( - "Adding override before hook dll '%s' failed (max supported " - "limit exceeded), ignored", - dll); - } - } - - for (i = 0; i < options->iat_hook_dlls.nitems; i++) { - dll = *array_item(const char *, &options->iat_hook_dlls, i); - - if (!launcher_config_add_iat_hook_dll(config, dll)) { - log_warning( - "Adding override iat hook dll '%s' failed (max supported limit " - "exceeded), ignored", - dll); + path); } } } @@ -226,7 +214,7 @@ static void _launcher_config_options_override( // parameters _launcher_bootstrap_config_options_override( &config->bootstrap, &options->bootstrap); - _launcher_hook_config_options_override(config, &options->hook); + _launcher_hook_config_options_override(config, &options->hooks); _launcher_debug_config_options_override(&config->debug, &options->debug); } @@ -236,16 +224,16 @@ _launcher_config_full_resolved_log(const struct launcher_config *config) if (config->debug.log_property_configs) { log_misc("launcher-config resolved properties"); log_misc("bootstrap-config"); - property_util_log(config->bootstrap.property); + core_property_log(config->bootstrap.property, log_misc_func); log_misc("avs-config"); - property_util_log(config->avs.property); + core_property_log(config->avs.property, log_misc_func); log_misc("ea3-ident-config"); - property_util_log(config->ea3_ident.property); + core_property_log(config->ea3_ident.property, log_misc_func); log_misc("eamuse-config"); - property_util_log(config->eamuse.property); + core_property_log(config->eamuse.property, log_misc_func); } } @@ -264,32 +252,6 @@ _launcher_remote_debugger_trap(const struct launcher_debug_config *config) } } -static void _launcher_procmon_init( - const struct launcher_debug_config *config, - struct procmon *procmon) -{ - procmon_init(procmon); - - if (procmon_available()) { - procmon_load(procmon); - - procmon->set_loggers(log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); - procmon->init(); - - if (config->procmon_file) { - procmon->file_mon_enable(); - } - - if (config->procmon_module) { - procmon->module_mon_enable(); - } - - if (config->procmon_thread) { - procmon->thread_mon_enable(); - } - } -} - static void _launcher_bootstrap_config_load( const struct launcher_bootstrap_config *launcher_bootstrap_config, struct bootstrap_config *config) @@ -310,9 +272,9 @@ static void _launcher_bootstrap_log_config_options_override( if (options->level) { log_misc( - "Command line override bootstrap log level: %d", *(options->level)); + "Command line override bootstrap log level: %d", options->level); - switch (*(options->level)) { + switch (options->level) { case CORE_LOG_BT_LOG_LEVEL_OFF: str_cpy(config->level, sizeof(config->level), "disable"); break; @@ -362,18 +324,32 @@ static void _launcher_bootstrap_log_config_verify( } } -static void -_launcher_before_hook_dlls_load(const struct launcher_hook_config *config) +void _launcher_hooks_load( + const struct launcher_hook_config *config, bool debug_log_property_configs) { int i; + core_property_node_t root_node; + core_property_result_t result_prop; log_assert(config); - log_misc("Loading before hook dlls..."); + for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOKS; i++) { + if (launcher_config_hooks_hook_available(&config->hook[i])) { + if (config->hook[i].enable) { + if (debug_log_property_configs) { + log_misc("Property hook config: %s", config->hook[i].path); - for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) { - if (strlen(config->before_hook_dlls[i]) > 0) { - hook_load_dll(config->before_hook_dlls[i]); + core_property_log(config->hook[i].property, log_misc_func); + } + + result_prop = core_property_root_node_get( + config->hook[i].property, &root_node); + core_property_fatal_on_error(result_prop); + + hooks_hook_load(config->hook[i].path, &root_node); + } else { + log_misc("Hook disabled: %s", config->hook[i].path); + } } } } @@ -392,7 +368,7 @@ static void _launcher_ea3_ident_config_load( if (log_property_configs) { log_misc("Property ea3-ident-config"); - property_util_log(launcher_config->property); + core_property_log(launcher_config->property, log_misc_func); } if (!ea3_ident_config_hardid_is_defined(config)) { @@ -403,45 +379,6 @@ static void _launcher_ea3_ident_config_load( } } -static void _launcher_bootstrap_module_init( - const struct bootstrap_module_config *module_config, - const struct launcher_hook_config *hook_config) -{ - int i; - struct array iat_hook_dlls; - - log_assert(module_config); - log_assert(hook_config); - - array_init(&iat_hook_dlls); - - for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) { - if (strlen(hook_config->before_hook_dlls[i]) > 0) { - *array_append(const char *, &iat_hook_dlls) = - (const char *) &hook_config->before_hook_dlls[i]; - } - } - - bootstrap_module_init(module_config, &iat_hook_dlls); - - array_fini(&iat_hook_dlls); -} - -static void _launcher_hook_dlls_load(const struct launcher_hook_config *config) -{ - int i; - - log_assert(config); - - log_misc("Loading hook dlls..."); - - for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) { - if (strlen(config->hook_dlls[i]) > 0) { - hook_load_dll(config->hook_dlls[i]); - } - } -} - static void _launcher_dongle_stubs_init() { stubs_init(); @@ -457,17 +394,17 @@ static void _launcher_debugger_break() void _launcher_log_reinit() { - core_log_bt_ext_impl_set(); + core_log_bt_core_api_set(); } void _launcher_init( const struct options *options, struct launcher_config *launcher_config, struct bootstrap_config *bootstrap_config, - struct ea3_ident_config *ea3_ident_config, - struct procmon *procmon) + struct ea3_ident_config *ea3_ident_config) { - struct property *launcher_property; + core_property_t *launcher_property; + core_property_result_t result; log_assert(options); log_assert(launcher_config); @@ -476,9 +413,23 @@ void _launcher_init( // Early logging pre AVS setup depend entirely on command args // We don't even have the bootstrap configuration loaded at this point - _launcher_log_init(options->log.file_path, *(options->log.level)); + _launcher_log_init(options->log.file_path, options->log.level); _launcher_log_header(); + core_thread_crt_core_api_set(); + + // TODO make this configurable, e.g. command line args/env vars? + core_property_trace_log_enable(true); + core_property_node_trace_log_enable(true); + + // This is already available without AVS being actually booted + // and we need this to read our configuration files + avs_ext_property_core_api_set(); + avs_ext_property_node_core_api_set(); + + // Run our configuration API always through the property API + core_config_property_node_core_api_set(); + signal_exception_handler_init(_launcher_signal_shutdown_handler); signal_register_shutdown_handler(&_launcher_signal_shutdown_handler); @@ -498,17 +449,20 @@ void _launcher_init( "Loading launcher configuration from file: %s", options->launcher.config_path); - launcher_property = property_util_load(options->launcher.config_path); + result = core_property_file_load( + options->launcher.config_path, &launcher_property); + core_property_fatal_on_error(result); + launcher_config_load(launcher_property, launcher_config); _launcher_config_options_override(launcher_config, options); if (launcher_config->debug.log_property_configs) { log_misc("launcher-config"); - property_util_log(launcher_property); + core_property_log(launcher_property, log_misc_func); } - property_util_free(launcher_property); + core_property_free(&launcher_property); } else { _launcher_config_options_override(launcher_config, options); } @@ -520,8 +474,6 @@ void _launcher_init( _launcher_remote_debugger_trap(&launcher_config->debug); - _launcher_procmon_init(&launcher_config->debug, procmon); - _launcher_bootstrap_config_load( &launcher_config->bootstrap, bootstrap_config); _launcher_bootstrap_log_config_options_override( @@ -531,12 +483,26 @@ void _launcher_init( bootstrap_init(launcher_config->debug.log_property_configs); bootstrap_log_init(&bootstrap_config->startup.log); - _launcher_before_hook_dlls_load(&launcher_config->hook); + hooks_init(); + _launcher_hooks_load( + &launcher_config->hook, launcher_config->debug.log_property_configs); + + hooks_core_log_api_set(); + hooks_core_thread_api_set(); + hooks_core_config_api_set(); + + hooks_pre_avs_init(); bootstrap_avs_init( &bootstrap_config->startup.boot, &bootstrap_config->startup.log, launcher_config->avs.property); + + // Set APIs again because these have changed with AVS being initialized + hooks_core_log_api_set(); + hooks_core_thread_api_set(); + hooks_core_config_api_set(); + bootstrap_default_files_create(&bootstrap_config->startup.default_file); _launcher_ea3_ident_config_load( @@ -556,51 +522,54 @@ void _launcher_run( const struct bootstrap_config *bootstrap_config, struct ea3_ident_config *ea3_ident_config) { + HMODULE game_module; + log_assert(launcher_config); log_assert(bootstrap_config); log_assert(ea3_ident_config); - _launcher_bootstrap_module_init( - &bootstrap_config->startup.module, &launcher_config->hook); + game_module = + bootstrap_app_unresolved_init(&bootstrap_config->startup.module); - _launcher_hook_dlls_load(&launcher_config->hook); + hooks_iat_apply(game_module); + + bootstrap_app_resolve_init(); _launcher_dongle_stubs_init(); _launcher_debugger_break(); - bootstrap_module_game_init( - &bootstrap_config->startup.module, ea3_ident_config); + hooks_main_init(game_module); + + bootstrap_app_init(&bootstrap_config->startup.module, ea3_ident_config); bootstrap_eamuse_init( &bootstrap_config->startup.eamuse, ea3_ident_config, launcher_config->eamuse.property); - bootstrap_module_game_run(); + bootstrap_app_run(); + + hooks_main_fini(); } void _launcher_fini( struct launcher_config *launcher_config, - const struct bootstrap_config *bootstrap_config, - struct procmon *procmon) + const struct bootstrap_config *bootstrap_config) { log_assert(launcher_config); log_assert(bootstrap_config); - log_assert(procmon); bootstrap_eamuse_fini(&bootstrap_config->startup.eamuse); + bootstrap_app_fini(); + + hooks_fini(); + bootstrap_avs_fini(); _launcher_log_reinit(); - bootstrap_module_game_fini(); - - if (procmon->module != NULL) { - procmon_free(procmon); - } - launcher_config_fini(launcher_config); log_info("Shutdown complete"); @@ -613,14 +582,13 @@ void launcher_main(const struct options *options) struct launcher_config launcher_config; struct bootstrap_config bootstrap_config; struct ea3_ident_config ea3_ident_config; - struct procmon procmon; log_assert(options); _launcher_init( - options, &launcher_config, &bootstrap_config, &ea3_ident_config, &procmon); + options, &launcher_config, &bootstrap_config, &ea3_ident_config); _launcher_run(&launcher_config, &bootstrap_config, &ea3_ident_config); - _launcher_fini(&launcher_config, &bootstrap_config, &procmon); + _launcher_fini(&launcher_config, &bootstrap_config); } \ No newline at end of file diff --git a/src/main/launcher/main.c b/src/main/launcher/main.c index 4b1b68a..cdae112 100644 --- a/src/main/launcher/main.c +++ b/src/main/launcher/main.c @@ -1,5 +1,7 @@ #include +#include "core/boot.h" + #include "launcher/launcher.h" #include "launcher/options.h" @@ -7,6 +9,8 @@ int main(int argc, const char **argv) { struct options options; + core_boot("launcher"); + options_init(&options); if (!options_read_cmdline(&options, argc, argv)) { diff --git a/src/main/launcher/module.c b/src/main/launcher/module.c deleted file mode 100644 index ff291ff..0000000 --- a/src/main/launcher/module.c +++ /dev/null @@ -1,428 +0,0 @@ -#define LOG_MODULE "module" - -#include - -#include "core/log.h" - -#include "hook/pe.h" - -#include "imports/avs.h" -#include "imports/eapki.h" - -#include "launcher/module.h" -#include "launcher/property-util.h" - -#include "util/str.h" - -#define MM_ALLOCATION_GRANULARITY 0x10000 - -static bool _module_dependency_available(const char *lib) -{ - HMODULE module; - - module = LoadLibraryA(lib); - - if (module == NULL) { - return false; - } else { - FreeLibrary(module); - return true; - } -} - -static bool -module_replace_dll_iat(HMODULE hModule, const struct array *iat_hook_dlls) -{ - log_assert(hModule); - log_assert(iat_hook_dlls); - - log_misc("replace dll iat: %p", hModule); - - if (iat_hook_dlls->nitems == 0) - return true; - - PBYTE pbModule = (PBYTE) hModule; - - // Find EXE base in process memory - IMAGE_DOS_HEADER *idh = (IMAGE_DOS_HEADER *) pbModule; - IMAGE_NT_HEADERS *inh = (IMAGE_NT_HEADERS *) (pbModule + idh->e_lfanew); - - // Search through import table if it exists and replace the target DLL with - // our DLL filename - PIMAGE_SECTION_HEADER pRemoteSectionHeaders = - (PIMAGE_SECTION_HEADER) ((PBYTE) pbModule + sizeof(inh->Signature) + - sizeof(inh->FileHeader) + - inh->FileHeader.SizeOfOptionalHeader); - size_t total_size = inh->OptionalHeader.SizeOfHeaders; - - for (DWORD n = 0; n < inh->FileHeader.NumberOfSections; ++n) { - IMAGE_SECTION_HEADER *header = - (IMAGE_SECTION_HEADER *) (pRemoteSectionHeaders + n); - size_t new_total_size = - header->VirtualAddress + header->Misc.VirtualSize; - if (new_total_size > total_size) - total_size = new_total_size; - } - - void *remote_addr = NULL; - size_t remote_addr_ptr = 0; - - for (size_t i = 0; i < 10000 && remote_addr == NULL; i++) { - remote_addr = VirtualAlloc( - pbModule + total_size + (MM_ALLOCATION_GRANULARITY * (i + 1)), - (MAX_PATH + 1) * iat_hook_dlls->nitems, - MEM_RESERVE | MEM_COMMIT, - PAGE_READWRITE); - } - - log_assert(remote_addr != NULL); - - if (inh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] - .VirtualAddress != 0) { - PIMAGE_IMPORT_DESCRIPTOR pImageImport = - (PIMAGE_IMPORT_DESCRIPTOR) (pbModule + - inh->OptionalHeader - .DataDirectory - [IMAGE_DIRECTORY_ENTRY_IMPORT] - .VirtualAddress); - - DWORD size = 0; - while (inh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] - .Size == 0 || - size < inh->OptionalHeader - .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] - .Size) { - IMAGE_IMPORT_DESCRIPTOR *ImageImport = - (IMAGE_IMPORT_DESCRIPTOR *) pImageImport; - - if (ImageImport->Name == 0) { - break; - } - - const char *name = (const char *) (pbModule + ImageImport->Name); - - for (size_t i = 0; i < iat_hook_dlls->nitems; i++) { - const char *iat_hook_dll = - *array_item(char *, iat_hook_dlls, i); - - char *iat_hook_replacement = strstr(iat_hook_dll, "="); - - if (!iat_hook_replacement) - continue; - - *iat_hook_replacement = '\0'; - - const char *expected_dll = iat_hook_dll; - const char *replacement_path_dll = iat_hook_replacement + 1; - - if (strcmp(name, expected_dll) == 0) { - pe_patch( - (PBYTE) remote_addr + remote_addr_ptr, - replacement_path_dll, - strlen(replacement_path_dll)); - - log_misc( - "Replacing %s with %s", name, replacement_path_dll); - - DWORD val = (DWORD) ((PBYTE) remote_addr - pbModule); - pe_patch(&ImageImport->Name, &val, sizeof(DWORD)); - pe_patch(pImageImport, &ImageImport, sizeof(ImageImport)); - - remote_addr_ptr += strlen(replacement_path_dll) + 1; - } - - *iat_hook_replacement = '='; - } - - pImageImport++; - size += sizeof(IMAGE_IMPORT_DESCRIPTOR); - } - } else { - log_misc("Couldn't find import table, can't hook DLL\n"); - goto inject_fail; - } - - return true; - -inject_fail: - return false; -} - -void module_init(struct module_context *module, const char *path) -{ - log_assert(module != NULL); - log_assert(path != NULL); - - log_info("init: %s", path); - - module->dll = LoadLibraryA(path); - - if (module->dll == NULL) { - LPSTR buffer; - DWORD err = GetLastError(); - - FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR) &buffer, - 0, - NULL); - - if (err == ERROR_MOD_NOT_FOUND) { - log_warning("%s is likely missing dependencies", path); - log_warning("Do you have vcredist/directx runtimes installed?"); - log_warning( - "Ensure the installed dependencies match the architecture, " - "32-bit/64-bit, of the game"); - log_warning( - "Running heuristic for commonly used libraries (actual " - "requirements depend on game)..."); - - if (_module_dependency_available("d3d9.dll")) { - log_warning("Could not find directx9 runtime"); - } - - if (_module_dependency_available("msvcr100.dll")) { - log_warning("Could not find vcredist 2010 runtime"); - } - - if (_module_dependency_available("msvcr120.dll")) { - log_warning("Could not find vcredist 2013 runtime"); - } - - if (_module_dependency_available("msvcp140.dll")) { - log_warning("Could not find vcredist 2015 runtime"); - } - } - - log_fatal("%s: Failed to load game DLL: %s", path, buffer); - - LocalFree(buffer); - } - - module->path = str_dup(path); - - log_misc("init done"); -} - -void module_with_iat_hooks_init( - struct module_context *module, - const char *path, - const struct array *iat_hook_dlls) -{ - log_assert(module != NULL); - log_assert(path != NULL); - - log_info("init iat hooks: %s", path); - - module->dll = LoadLibraryExA(path, NULL, DONT_RESOLVE_DLL_REFERENCES); - - if (module->dll == NULL) { - LPSTR buffer; - DWORD err = GetLastError(); - - FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR) &buffer, - 0, - NULL); - - if (err == ERROR_MOD_NOT_FOUND) { - log_warning("%s is likely missing dependencies", path); - log_warning("Do you have vcredist/directx runtimes installed?"); - } - - log_fatal("%s: Failed to load game DLL: %s", path, buffer); - - LocalFree(buffer); - } - - // Add IAT hooks - module_replace_dll_iat(module->dll, iat_hook_dlls); - - log_misc("Finished processing IAT hooks"); - - // Resolve all imports like a normally loaded DLL - pe_resolve_imports(module->dll); - - dll_entry_t orig_entry = pe_get_entry_point(module->dll); - orig_entry(module->dll, DLL_PROCESS_ATTACH, NULL); - - log_misc("Finished resolving imports"); - - module->path = str_dup(path); -} - -void module_init_invoke( - const struct module_context *module, - struct ea3_ident_config *ea3_ident_config, - struct property_node *app_params_node) -{ - char sidcode_short[17]; - char sidcode_long[21]; - char security_code[9]; - dll_entry_init_t init; - bool ok; - - log_info("init invoke"); - - /* Set up security env vars */ - - str_format( - security_code, - lengthof(security_code), - "G*%s%s%s%s", - ea3_ident_config->model, - ea3_ident_config->dest, - ea3_ident_config->spec, - ea3_ident_config->rev); - - log_misc("security code: %s", security_code); - - std_setenv("/env/boot/version", "0.0.0"); - std_setenv("/env/profile/security_code", security_code); - std_setenv("/env/profile/system_id", ea3_ident_config->pcbid); - std_setenv("/env/profile/account_id", ea3_ident_config->pcbid); - std_setenv("/env/profile/license_id", ea3_ident_config->softid); - std_setenv("/env/profile/software_id", ea3_ident_config->softid); - std_setenv("/env/profile/hardware_id", ea3_ident_config->hardid); - - /* Set up the short sidcode string, let dll_entry_init mangle it */ - - str_format( - sidcode_short, - lengthof(sidcode_short), - "%s%s%s%s%s", - ea3_ident_config->model, - ea3_ident_config->dest, - ea3_ident_config->spec, - ea3_ident_config->rev, - ea3_ident_config->ext); - - log_misc("sidcode short: %s", sidcode_short); - - /* Set up long-form sidcode env var */ - - str_format( - sidcode_long, - lengthof(sidcode_long), - "%s:%s:%s:%s:%s", - ea3_ident_config->model, - ea3_ident_config->dest, - ea3_ident_config->spec, - ea3_ident_config->rev, - ea3_ident_config->ext); - - log_misc("sidecode long: %s", sidcode_long); - - /* Set this up beforehand, as certain games require it in dll_entry_init */ - - std_setenv("/env/profile/soft_id_code", sidcode_long); - - init = (void *) GetProcAddress(module->dll, "dll_entry_init"); - - if (init == NULL) { - log_fatal( - "%s: dll_entry_init not found. Is this a game DLL?", module->path); - } - - log_info("Invoking game init..."); - - struct property *prop = - property_util_cstring_load("p3io"); - - struct property_node *prop_node = property_search(prop, NULL, "/param"); - - property_util_log(prop); - property_util_node_log(prop_node); - - ok = init(sidcode_short, prop_node); - - if (!ok) { - log_fatal("%s: dll_module_init() returned failure", module->path); - } else { - log_info("Game init done"); - } - - /* Back-propagate sidcode, as some games modify it during init */ - - memcpy( - ea3_ident_config->model, - sidcode_short + 0, - sizeof(ea3_ident_config->model) - 1); - ea3_ident_config->dest[0] = sidcode_short[3]; - ea3_ident_config->spec[0] = sidcode_short[4]; - ea3_ident_config->rev[0] = sidcode_short[5]; - memcpy( - ea3_ident_config->ext, - sidcode_short + 6, - sizeof(ea3_ident_config->ext)); - - /* Set up long-form sidcode env var again */ - - str_format( - sidcode_long, - lengthof(sidcode_long), - "%s:%s:%s:%s:%s", - ea3_ident_config->model, - ea3_ident_config->dest, - ea3_ident_config->spec, - ea3_ident_config->rev, - ea3_ident_config->ext); - - std_setenv("/env/profile/soft_id_code", sidcode_long); - - log_misc("back-propagated sidcode long: %s", sidcode_long); - - log_misc("init invoke done"); -} - -bool module_main_invoke(const struct module_context *module) -{ - /* GCC warns if you call a variable "main" */ - dll_entry_main_t main_; - bool result; - - log_assert(module != NULL); - - log_info("main invoke"); - - main_ = (void *) GetProcAddress(module->dll, "dll_entry_main"); - - if (main_ == NULL) { - log_fatal( - "%s: dll_entry_main not found. Is this a game DLL?", module->path); - } - - log_info("Invoking game's main function..."); - - result = main_(); - - log_info("Main terminated, result: %d", result); - - return result; -} - -void module_fini(struct module_context *module) -{ - log_info("fini"); - - if (module == NULL) { - return; - } - - free(module->path); - - if (module->dll != NULL) { - FreeLibrary(module->dll); - } - - log_misc("fini done"); -} diff --git a/src/main/launcher/module.h b/src/main/launcher/module.h deleted file mode 100644 index ed9b732..0000000 --- a/src/main/launcher/module.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef LAUNCHER_MODULE_H -#define LAUNCHER_MODULE_H - -#include - -#include "imports/avs.h" - -#include "launcher/ea3-ident-config.h" - -#include "util/array.h" - -struct module_context { - HMODULE dll; - char *path; -}; - -void module_init(struct module_context *module, const char *path); -void module_with_iat_hooks_init( - struct module_context *module, - const char *path, - const struct array *iat_hook_dlls); -void module_init_invoke( - const struct module_context *module, - struct ea3_ident_config *ea3_ident_config, - struct property_node *app_params_node); -bool module_main_invoke(const struct module_context *module); -void module_fini(struct module_context *module); - -#endif diff --git a/src/main/launcher/options.c b/src/main/launcher/options.c index e116849..a9d4212 100644 --- a/src/main/launcher/options.c +++ b/src/main/launcher/options.c @@ -15,9 +15,9 @@ void options_init(struct options *options) { memset(options, 0, sizeof(struct options)); - array_init(&options->hook.hook_dlls); - array_init(&options->hook.before_hook_dlls); - array_init(&options->hook.iat_hook_dlls); + array_init(&options->hooks.paths); + + options->log.level = CORE_LOG_BT_LOG_LEVEL_INFO; } bool options_read_cmdline(struct options *options, int argc, const char **argv) @@ -29,7 +29,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { - case 'T': + case 'B': if (i + 1 >= argc) { return false; } @@ -70,36 +70,11 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - *array_append(const char *, &options->hook.hook_dlls) = + *array_append(const char *, &options->hooks.paths) = argv[++i]; break; - case 'B': - if (i + 1 >= argc) { - return false; - } - - *array_append( - const char *, &options->hook.before_hook_dlls) = - argv[++i]; - - break; - - case 'I': { - if (i + 1 >= argc) { - return false; - } - - const char *dll = argv[++i]; - log_assert(strstr(dll, "=") != NULL); - - *array_append(const char *, &options->hook.iat_hook_dlls) = - dll; - - break; - } - case 'L': if (i + 1 >= argc) { return false; @@ -112,9 +87,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->log.level = - xmalloc(sizeof(enum core_log_bt_log_level)); - *(options->log.level) = (enum core_log_bt_log_level) tmp; + options->log.level = (enum core_log_bt_log_level) tmp; break; @@ -192,7 +165,7 @@ void options_print_usage(void) "configuration file:\n" "\n" " Bootstrap\n" - " -T [filename] Bootstrap configuration file\n" + " -B [filename] Bootstrap configuration file\n" " -Z [selector] Bootstrap selector used in configuration\n" "\n" " Eamuse\n" @@ -203,11 +176,6 @@ void options_print_usage(void) "\n" " Hook\n" " -H [filename] Load hook DLL (can be specified multiple " - "times)\n" - " -B [filename] Load pre-hook DLL loaded before avs boot " - "(can be specified multiple times)\n" - " -I [filename] Load pre-hook DLL that overrides IAT reference " - "before execution (can be specified multiple times)\n" "\n" " Logging\n" " -L [0/1/2/3] Log level for both console and file with " @@ -226,13 +194,7 @@ void options_print_usage(void) void options_fini(struct options *options) { - array_fini(&options->hook.hook_dlls); - array_fini(&options->hook.before_hook_dlls); - array_fini(&options->hook.iat_hook_dlls); - - if (options->log.level) { - free(options->log.level); - } + array_fini(&options->hooks.paths); if (options->eamuse.urlslash) { free(options->eamuse.urlslash); diff --git a/src/main/launcher/options.h b/src/main/launcher/options.h index c0bdfaf..3d23b0d 100644 --- a/src/main/launcher/options.h +++ b/src/main/launcher/options.h @@ -5,7 +5,6 @@ #include #include "core/log-bt.h" -#include "core/log.h" #include "launcher/bootstrap-config.h" @@ -30,7 +29,7 @@ struct options { } bootstrap; struct options_log { - enum core_log_bt_log_level *level; + enum core_log_bt_log_level level; const char *file_path; } log; @@ -41,11 +40,9 @@ struct options { bool *urlslash; } eamuse; - struct options_hook { - struct array hook_dlls; - struct array before_hook_dlls; - struct array iat_hook_dlls; - } hook; + struct options_hooks { + struct array paths; + } hooks; struct options_debug { bool remote_debugger; diff --git a/src/main/launcher/property-util.c b/src/main/launcher/property-util.c deleted file mode 100644 index 20a7f91..0000000 --- a/src/main/launcher/property-util.c +++ /dev/null @@ -1,891 +0,0 @@ -#define LOG_MODULE "property-util" - -#include - -#include -#include -#include -#include - -#include "avs-util/error.h" - -#include "core/log.h" - -#include "imports/avs.h" - -#include "launcher/property-util.h" - -#include "util/mem.h" -#include "util/str.h" - -#define PROPERTY_STRUCTURE_META_SIZE 576 - -typedef void (*rewinder)(uint32_t context); - -struct cstring_read_handle { - const char *buffer; - size_t buffer_len; - size_t offset; -}; - -struct property_util_node_merge_ctx { - const char *path; - const struct property_util_node_merge_strategies *strategies; -}; - -static struct property *property_util_do_load( - avs_reader_t reader, rewinder rewinder, uint32_t context, const char *name) -{ - struct property *prop; - void *buffer; - int nbytes; - - nbytes = property_read_query_memsize(reader, context, 0, 0); - - if (nbytes < 0) { - log_fatal("%s: Error querying configuration file", name); - } - - buffer = xmalloc(nbytes); - prop = property_create( - PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | - PROPERTY_FLAG_APPEND, - buffer, - nbytes); - - if (!prop) { - log_fatal( - "%s: Creating property failed: %s", - name, - avs_util_property_error_get_and_clear(prop)); - } - - rewinder(context); - - if (!property_insert_read(prop, 0, reader, context)) { - log_fatal( - "%s: Error reading configuration file: %s", - name, - avs_util_property_error_get_and_clear(prop)); - } - - return prop; -} - -static int property_util_fread(uint32_t context, void *bytes, size_t nbytes) -{ - FILE *f; - - f = TlsGetValue(context); - - return fread(bytes, 1, nbytes, f); -} - -static void property_util_frewind(uint32_t context) -{ - FILE *f = TlsGetValue(context); - rewind(f); -} - -static void property_util_log_node_tree_rec( - struct property_node *parent_node, const char *parent_path) -{ - char cur_path[PROPERTY_NODE_PATH_LEN_MAX]; - char cur_node_name[PROPERTY_NODE_NAME_SIZE_MAX]; - - struct property_node *child_node; - enum property_type property_type; - - int8_t value_s8; - int16_t value_s16; - int32_t value_s32; - int64_t value_s64; - uint8_t value_u8; - uint16_t value_u16; - uint32_t value_u32; - uint64_t value_u64; - char value_str[4096]; - bool value_bool; - - avs_error error; - - // Carry on the full root path down the node tree - property_node_name(parent_node, cur_node_name, sizeof(cur_node_name)); - - str_cpy(cur_path, sizeof(cur_path), parent_path); - str_cat(cur_path, sizeof(cur_path), "/"); - str_cat(cur_path, sizeof(cur_path), cur_node_name); - - child_node = property_node_traversal(parent_node, TRAVERSE_FIRST_CHILD); - - // parent node is a leaf node, print all data of it - if (child_node == NULL) { - property_type = property_node_type(parent_node); - - switch (property_type) { - case PROPERTY_TYPE_VOID: - log_misc("%s: ", cur_path); - break; - - case PROPERTY_TYPE_S8: - property_node_read( - parent_node, property_type, &value_s8, sizeof(value_s8)); - log_misc("%s: %" PRId8, cur_path, value_s8); - break; - - case PROPERTY_TYPE_S16: - property_node_read( - parent_node, property_type, &value_s16, sizeof(value_s16)); - log_misc("%s: %" PRId16, cur_path, value_s16); - break; - - case PROPERTY_TYPE_S32: - property_node_read( - parent_node, property_type, &value_s32, sizeof(value_s32)); - log_misc("%s: %" PRId32, cur_path, value_s32); - break; - - case PROPERTY_TYPE_S64: - property_node_read( - parent_node, property_type, &value_s64, sizeof(value_s64)); - log_misc("%s: %" PRId64, cur_path, value_s64); - break; - - case PROPERTY_TYPE_U8: - property_node_read( - parent_node, property_type, &value_u8, sizeof(value_u8)); - log_misc("%s: %" PRIu8, cur_path, value_u8); - break; - - case PROPERTY_TYPE_U16: - property_node_read( - parent_node, property_type, &value_u16, sizeof(value_u16)); - log_misc("%s: %" PRIu16, cur_path, value_u16); - break; - - case PROPERTY_TYPE_U32: - property_node_read( - parent_node, property_type, &value_u32, sizeof(value_u32)); - log_misc("%s: %" PRIu32, cur_path, value_u32); - break; - - case PROPERTY_TYPE_U64: - property_node_read( - parent_node, property_type, &value_u64, sizeof(value_u64)); - log_misc("%s: %" PRIu64, cur_path, value_u64); - break; - - case PROPERTY_TYPE_STR: - property_node_read( - parent_node, property_type, value_str, sizeof(value_str)); - log_misc("%s: %s", cur_path, value_str); - - break; - - case PROPERTY_TYPE_BOOL: - property_node_read( - parent_node, - property_type, - &value_bool, - sizeof(value_bool)); - log_misc("%s: %d", cur_path, value_bool); - - break; - - case PROPERTY_TYPE_BIN: - log_misc("%s: ", cur_path); - break; - - case PROPERTY_TYPE_ATTR: - error = property_node_read( - parent_node, property_type, value_str, sizeof(value_str)); - - if (AVS_IS_ERROR(error)) { - log_fatal( - "%s, property read failed: %s", - cur_path, - avs_util_error_str(error)); - } - - log_misc("%s@: %s", cur_path, value_str); - - break; - - case PROPERTY_TYPE_VOID_WITH_ATTRIBUTES: - log_misc("%s: ", cur_path); - - child_node = - property_node_traversal(parent_node, TRAVERSE_FIRST_ATTR); - - while (child_node) { - property_util_log_node_tree_rec(child_node, cur_path); - - child_node = property_node_traversal( - child_node, TRAVERSE_NEXT_SIBLING); - } - - break; - - case PROPERTY_TYPE_STR_WITH_ATTRIBUTES: - error = property_node_read( - parent_node, property_type, value_str, sizeof(value_str)); - - if (AVS_IS_ERROR(error)) { - log_fatal( - "%s, property read failed: %s", - cur_path, - avs_util_error_str(error)); - } - - log_misc("%s: %s", cur_path, value_str); - - child_node = - property_node_traversal(parent_node, TRAVERSE_FIRST_ATTR); - - while (child_node) { - property_util_log_node_tree_rec(child_node, cur_path); - - child_node = property_node_traversal( - child_node, TRAVERSE_NEXT_SIBLING); - } - - break; - - default: - log_misc("%s: (%d)", cur_path, property_type); - break; - } - } else { - while (child_node) { - property_util_log_node_tree_rec(child_node, cur_path); - - child_node = - property_node_traversal(child_node, TRAVERSE_NEXT_SIBLING); - } - } -} - -static int -property_util_cstring_read(uint32_t context, void *bytes, size_t nbytes) -{ - int result = 0; - struct cstring_read_handle *h = TlsGetValue(context); - - if (h->offset < h->buffer_len) { - result = min(nbytes, h->buffer_len - h->offset); - memcpy(bytes, (const void *) (h->buffer + h->offset), result); - h->offset += result; - } - return result; -} - -static void property_util_cstring_rewind(uint32_t context) -{ - struct cstring_read_handle *h = TlsGetValue(context); - h->offset = 0; -} - -static int property_util_avs_read(uint32_t context, void *bytes, size_t nbytes) -{ - avs_desc desc = (avs_desc) context; - return avs_fs_read(desc, bytes, nbytes); -} - -static void property_util_avs_rewind(uint32_t context) -{ - avs_desc desc = (avs_desc) context; - avs_fs_lseek(desc, 0, AVS_SEEK_SET); -} - -static void _property_util_node_merge_recursive( - struct property *parent_property, - struct property_node *parent, - struct property_node *source, - void *ctx) -{ - uint8_t i; - bool consumed; - struct property_node *result; - - const struct property_util_node_merge_ctx *ctx_; - struct property_util_node_merge_ctx ctx_next; - - char parent_name[PROPERTY_NODE_NAME_SIZE_MAX]; - char parent_path[PROPERTY_NODE_PATH_LEN_MAX]; - - log_assert(source); - log_assert(ctx); - - ctx_ = (const struct property_util_node_merge_ctx *) ctx; - - log_assert(ctx_->path); - log_assert(ctx_->strategies); - log_assert(ctx_->strategies->num > 0); - - // Default to copying to an empty node - if (!parent) { - result = property_node_clone(parent_property, NULL, source, true); - - if (!result) { - log_fatal("Copying '%s' into empty parent failed", ctx_->path); - } - - return; - } - - property_node_name(parent, parent_name, sizeof(parent_name)); - - str_cpy(parent_path, sizeof(parent_path), ctx_->path); - str_cat(parent_path, sizeof(parent_path), "/"); - str_cat(parent_path, sizeof(parent_path), parent_name); - - ctx_next.path = parent_path; - ctx_next.strategies = ctx_->strategies; - - consumed = false; - - // Apply given strategies, one MUST consume - for (i = 0; i < ctx_->strategies->num; i++) { - log_assert(ctx_->strategies->entry[i].path); - - // path == "" matches everything - if (str_eq(ctx_->strategies->entry[i].path, "") || - str_eq(ctx_->strategies->entry[i].path, parent_path)) { - - consumed = ctx_->strategies->entry[i].merge_strategy_do( - parent_property, - parent, - source, - &ctx_next, - _property_util_node_merge_recursive); - - log_misc( - "Merge strategy for '%s' consumed: %d", - ctx_->strategies->entry[i].path, - consumed); - - if (consumed) { - break; - } - } - } - - log_assert(consumed); -} - -void property_util_log(struct property *property) -{ - property_util_log_node_tree_rec(property_search(property, NULL, "/"), ""); -} - -void property_util_node_log(struct property_node *node) -{ - property_util_log_node_tree_rec(node, ""); -} - -struct property *property_util_load(const char *filename) -{ - FILE *f; - uint32_t f_keyhole; - struct property *prop; - - log_assert(filename); - - /* AVS callbacks are only given a 32-bit context parameter, even in 64-bit - builds of AVS. We allocate a 32-bit TLS key and pass the context in this - manner instead. Inefficient, but it works. */ - - f = fopen(filename, "r"); - - f_keyhole = TlsAlloc(); - TlsSetValue(f_keyhole, f); - - if (f == NULL) { - log_fatal("%s: Error opening configuration file", filename); - } - - prop = property_util_do_load( - property_util_fread, property_util_frewind, f_keyhole, filename); - - TlsFree(f_keyhole); - - fclose(f); - - return prop; -} - -struct property *property_util_avs_fs_load(const char *filename) -{ - avs_desc desc; - struct property *prop; - - log_assert(filename); - - desc = avs_fs_open(filename, AVS_FILE_READ, AVS_FILE_FLAG_SHARE_READ); - - if (!desc) { - log_fatal("%s: Error opening configuration file", filename); - } - - prop = property_util_do_load( - property_util_avs_read, property_util_avs_rewind, desc, filename); - - avs_fs_close(desc); - - return prop; -} - -struct property *property_util_cstring_load(const char *cstring) -{ - uint32_t s_keyhole; - struct property *prop; - - log_assert(cstring); - - // see above - struct cstring_read_handle read_handle; - read_handle.buffer = cstring; - read_handle.buffer_len = strlen(cstring); - read_handle.offset = 0; - - s_keyhole = TlsAlloc(); - TlsSetValue(s_keyhole, &read_handle); - - prop = property_util_do_load( - property_util_cstring_read, - property_util_cstring_rewind, - s_keyhole, - ""); - - TlsFree(s_keyhole); - - return prop; -} - -struct property *property_util_clone(struct property *property) -{ - struct property *clone; - size_t size; - void *buffer; - - struct property_node *node_property; - struct property_node *node_clone; - - log_assert(property); - - size = property_util_property_query_real_size(property); - - buffer = xmalloc(size); - - clone = property_create( - PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | - PROPERTY_FLAG_APPEND, - buffer, - size); - - if (!clone) { - log_fatal("Creating property failed"); - } - - node_property = property_search(property, NULL, "/"); - node_clone = property_search(clone, NULL, "/"); - - if (!property_node_clone(clone, node_clone, node_property, true)) { - log_fatal( - "Cloning property data failed: %s", - avs_util_property_error_get_and_clear(clone)); - } - - return clone; -} - -void property_util_free(struct property *prop) -{ - void *buffer; - - buffer = property_desc_to_buffer(prop); - property_destroy(prop); - free(buffer); -} - -uint32_t property_util_property_query_real_size(struct property *property) -{ - avs_error size; - - log_assert(property); - - // Returns the size of the actual data in the property structure only - // Hence, using that size only, allocating another buffer for a copy - // of this might fail or copying the data will fail because the buffer - // is too small - size = property_query_size(property); - - if (AVS_IS_ERROR(size)) { - log_fatal( - "Querying property size failed: %s", avs_util_error_str(size)); - } - - // Hack: *2 to have enough space and not cut off data when cloning/copying - // property data because...reasons? I haven't figured this one out and - // there doesn't seem to be an actual API call for that to return the - // "true" size that allows the caller to figure out how much memory - // they have to allocate to create a copy of the property structure - // with property_create and - return (PROPERTY_STRUCTURE_META_SIZE + size) * 2; -} - -void property_util_node_u8_replace( - struct property *property, - struct property_node *node, - const char *name, - uint8_t val) -{ - struct property_node *tmp; - - log_assert(node); - log_assert(name); - - tmp = property_search(property, node, name); - - if (tmp) { - property_node_remove(tmp); - } - - tmp = property_node_create(property, node, PROPERTY_TYPE_U8, name, val); - - if (!tmp) { - log_fatal( - "Creating node '%s' failed: %s", - name, - property ? avs_util_property_error_get_and_clear(property) : - "unknown"); - } -} - -void property_util_node_u16_replace( - struct property *property, - struct property_node *node, - const char *name, - uint16_t val) -{ - struct property_node *tmp; - - log_assert(node); - log_assert(name); - - tmp = property_search(property, node, name); - - if (tmp) { - property_node_remove(tmp); - } - - tmp = property_node_create(property, node, PROPERTY_TYPE_U16, name, val); - - if (!tmp) { - log_fatal( - "Creating node '%s' failed: %s", - name, - property ? avs_util_property_error_get_and_clear(property) : - "unknown"); - } -} - -void property_util_node_u32_replace( - struct property *property, - struct property_node *node, - const char *name, - uint32_t val) -{ - struct property_node *tmp; - - log_assert(node); - log_assert(name); - - tmp = property_search(property, node, name); - - if (tmp) { - property_node_remove(tmp); - } - - tmp = property_node_create(property, node, PROPERTY_TYPE_U32, name, val); - - if (!tmp) { - log_fatal( - "Creating node '%s' failed: %s", - name, - property ? avs_util_property_error_get_and_clear(property) : - "unknown"); - } -} - -void property_util_node_str_replace( - struct property *property, - struct property_node *node, - const char *name, - const char *val) -{ - struct property_node *tmp; - - log_assert(node); - log_assert(name); - - tmp = property_search(property, node, name); - - if (tmp) { - property_node_remove(tmp); - } - - tmp = property_node_create(property, node, PROPERTY_TYPE_STR, name, val); - - if (!tmp) { - log_fatal( - "Creating node '%s' failed: %s", - name, - property ? avs_util_property_error_get_and_clear(property) : - "unknown"); - } -} - -void property_util_node_bool_replace( - struct property *property, - struct property_node *node, - const char *name, - bool val) -{ - struct property_node *tmp; - - log_assert(node); - log_assert(name); - - tmp = property_search(property, node, name); - - if (tmp) { - property_node_remove(tmp); - } - - tmp = property_node_create(property, node, PROPERTY_TYPE_BOOL, name, val); - - if (!tmp) { - log_fatal( - "Creating node '%s' failed: %s", - name, - property ? avs_util_property_error_get_and_clear(property) : - "unknown"); - } -} - -void property_util_node_attribute_replace( - struct property *property, - struct property_node *node, - const char *name, - const char *val) -{ - struct property_node *tmp; - - log_assert(node); - log_assert(name); - - tmp = property_search(property, node, name); - - if (tmp) { - property_node_remove(tmp); - } - - tmp = property_node_create(property, node, PROPERTY_TYPE_ATTR, name, val); -} - -struct property * -property_util_many_merge(struct property **properties, size_t count) -{ - struct property *merged_property; - struct property *tmp; - int i; - - log_assert(properties); - log_assert(count > 0); - - merged_property = property_util_clone(properties[0]); - - if (count == 1) { - return merged_property; - } - - for (i = 1; i < count; i++) { - tmp = property_util_merge(merged_property, properties[i]); - - property_util_free(merged_property); - merged_property = tmp; - } - - return merged_property; -} - -struct property *property_util_node_extract(struct property_node *node) -{ - struct property *property; - struct property_node *root_node; - uint32_t size; - void *buffer; - struct property_node *result; - - if (!node) { - return NULL; - } - - // Hack: Is it even possible to get the size of a (sub-) node without - // the property? 256kb should be fine for now, even for larger - // configurations. Obviously, this scales horribly and wastes a lot of - // memory for most smaller sub-nodes - size = 1024 * 256; - - buffer = xmalloc(size); - property = property_create( - PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | - PROPERTY_FLAG_APPEND, - buffer, - size); - root_node = property_search(property, NULL, ""); - - result = property_node_clone(property, root_node, node, true); - - if (!result) { - log_fatal("Cloning node into empty property failed"); - } - - return property; -} - -struct property * -property_util_merge(struct property *parent, struct property *source) -{ - struct property_util_node_merge_strategies strategies; - - log_assert(parent); - log_assert(source); - - strategies.num = 1; - - strategies.entry[0].path = ""; - strategies.entry[0].merge_strategy_do = - property_util_node_merge_default_strategy_do; - - return property_util_merge_with_strategies(parent, source, &strategies); -} - -struct property *property_util_merge_with_strategies( - struct property *parent, - struct property *source, - const struct property_util_node_merge_strategies *strategies) -{ - struct property_util_node_merge_ctx ctx; - size_t total_size; - void *buffer; - struct property *merged; - struct property_node *parent_node; - struct property_node *source_node; - - log_assert(parent); - log_assert(source); - log_assert(strategies); - - // We can't estimate how these two are being merged as in how much new - // data is being inserted from source into parent. Therefore, worse-case - // estimate memory requirement for no overlap - total_size = 0; - total_size += property_util_property_query_real_size(parent); - total_size += property_util_property_query_real_size(source); - - buffer = xmalloc(total_size); - - merged = property_create( - PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | - PROPERTY_FLAG_APPEND, - buffer, - total_size); - - ctx.path = ""; - ctx.strategies = strategies; - - parent_node = property_search(parent, NULL, "/"); - - if (!property_node_clone(merged, NULL, parent_node, true)) { - log_fatal( - "Copying parent base failed: %s", - avs_util_property_error_get_and_clear(merged)); - } - - // Grab parent_node from merged property which is the target one to merge - // into - parent_node = property_search(merged, NULL, "/"); - source_node = property_search(source, NULL, "/"); - - _property_util_node_merge_recursive(merged, parent_node, source_node, &ctx); - - return merged; -} - -bool property_util_node_merge_default_strategy_do( - struct property *parent_property, - struct property_node *parent, - struct property_node *source, - void *ctx, - property_util_node_merge_recursion_do_t node_merge_recursion_do) -{ - struct property_node *result; - - struct property_node *parent_child; - struct property_node *source_child; - struct property_node *source_child_child; - - char child_node_name[PROPERTY_NODE_NAME_SIZE_MAX]; - - log_assert(parent); - log_assert(source); - - source_child = property_node_traversal(source, TRAVERSE_FIRST_CHILD); - - while (source_child) { - property_node_name( - source_child, child_node_name, sizeof(child_node_name)); - - parent_child = property_search(NULL, parent, child_node_name); - - if (parent_child) { - source_child_child = - property_node_traversal(source_child, TRAVERSE_FIRST_CHILD); - - if (source_child_child) { - // Continue recursion if there are actually more children - node_merge_recursion_do( - parent_property, parent_child, source_child, ctx); - } else { - // Found identical leaf node, remove the matching parent's child - // and copy the source child over to the parent and terminate - // the recursion - property_node_remove(parent_child); - result = property_node_clone( - parent_property, parent, source_child, true); - - if (!result) { - log_fatal( - "Replacing leaf node '%s' failed", child_node_name); - } - } - } else { - // Could not find an identical child on parent, copy source - // recursively to parent - result = property_node_clone( - parent_property, parent, source_child, true); - - if (!result) { - log_fatal("Deep copying child '%s' failed", child_node_name); - } - } - - source_child = - property_node_traversal(source_child, TRAVERSE_NEXT_SIBLING); - } - - // Default strategy always consumes - return true; -} diff --git a/src/main/launcher/property-util.h b/src/main/launcher/property-util.h deleted file mode 100644 index ba59479..0000000 --- a/src/main/launcher/property-util.h +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef PROPERTY_UTIL_H -#define PROPERTY_UTIL_H - -#include - -#include "imports/avs.h" - -// Guestimate, should be long enough, I hope? -#define PROPERTY_NODE_PATH_LEN_MAX 4096 -// 256 found in AVS code as size used on property_node_name -#define PROPERTY_NODE_NAME_SIZE_MAX 256 -// Guestimate, should be enough, I hope? -#define PROPERTY_NODE_ATTR_NAME_SIZE_MAX 128 - -#define PROPERTY_UTIL_MAX_NODE_NAME_RESOLVERS 4 - -typedef void (*property_util_node_merge_recursion_do_t)( - struct property *parent_property, - struct property_node *parent, - struct property_node *source, - void *ctx); - -typedef bool (*property_util_node_merge_strategy_do_t)( - struct property *parent_property, - struct property_node *parent, - struct property_node *source, - void *ctx, - property_util_node_merge_recursion_do_t node_merge_recursion_do); - -struct property_util_node_merge_strategies { - struct { - const char *path; - property_util_node_merge_strategy_do_t merge_strategy_do; - } entry[PROPERTY_UTIL_MAX_NODE_NAME_RESOLVERS]; - uint8_t num; -}; - -void property_util_log(struct property *property); -void property_util_node_log(struct property_node *node); -struct property *property_util_load(const char *filename); -struct property *property_util_avs_fs_load(const char *filename); -struct property *property_util_cstring_load(const char *cstring); -struct property *property_util_clone(struct property *property); -void property_util_free(struct property *prop); -uint32_t property_util_property_query_real_size(struct property *property); -void property_util_node_u8_replace( - struct property *property, - struct property_node *node, - const char *name, - uint8_t val); -void property_util_node_u16_replace( - struct property *property, - struct property_node *node, - const char *name, - uint16_t val); -void property_util_node_u32_replace( - struct property *property, - struct property_node *node, - const char *name, - uint32_t val); -void property_util_node_str_replace( - struct property *property, - struct property_node *node, - const char *name, - const char *val); -void property_util_node_bool_replace( - struct property *property, - struct property_node *node, - const char *name, - bool val); -void property_util_node_attribute_replace( - struct property *property, - struct property_node *node, - const char *name, - const char *val); - -struct property * -property_util_many_merge(struct property **properties, size_t count); -struct property *property_util_node_extract(struct property_node *node); - -struct property * -property_util_merge(struct property *parent, struct property *source); - -// Strategies are applied in order and first consumer terminates -// applying further strategies Typically, you want to include the default -// strategy after your custom strategies for special cases -struct property *property_util_merge_with_strategies( - struct property *parent, - struct property *source, - const struct property_util_node_merge_strategies *strategies); - -bool property_util_node_merge_default_strategy_do( - struct property *parent_property, - struct property_node *parent, - struct property_node *source, - void *ctx, - property_util_node_merge_recursion_do_t node_merge_recursion_do); - -#endif diff --git a/src/main/launcher/stubs.c b/src/main/launcher/stubs.c index 4c0b253..81acdf1 100644 --- a/src/main/launcher/stubs.c +++ b/src/main/launcher/stubs.c @@ -7,10 +7,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "launcher/stubs.h" #include "util/defs.h" @@ -30,7 +30,7 @@ struct stub { void *proc; }; -typedef void (*bt_get_fucked_t)(uint32_t /* even in 64-bit */ context); +typedef void(__cdecl *bt_get_fucked_t)(void *context); static HMODULE STDCALL my_GetModuleHandleA(const char *name); static HMODULE STDCALL my_GetModuleHandleW(const wchar_t *name); @@ -39,7 +39,7 @@ static void *STDCALL my_GetProcAddress(HMODULE dll, const char *name); static void bt_get_ikey_status(struct ikey_status *ik); #if AVS_VERSION >= 1509 -static void bt_get_fucked(bt_get_fucked_t callback, uint32_t ctx); +static void bt_get_fucked(bt_get_fucked_t callback, void *ctx); #endif static void bt_fcheck_init(void); @@ -140,10 +140,15 @@ static void bt_get_ikey_status(struct ikey_status *ik) } #if AVS_VERSION >= 1509 -static void bt_get_fucked(bt_get_fucked_t callback, uint32_t ctx) +static void bt_get_fucked(bt_get_fucked_t callback, void *ctx) { log_info(">>> k_bt0002"); - callback(ctx); + + if (callback != NULL) { + log_misc("callback(%p): %p", callback, ctx); + callback(ctx); + } + log_info("<<< k_bt0002"); } #endif diff --git a/src/main/launcher/version.c b/src/main/launcher/version.c index c71d5ff..f2b2f22 100644 --- a/src/main/launcher/version.c +++ b/src/main/launcher/version.c @@ -2,3 +2,4 @@ const char *launcher_build_date = __DATE__ " " __TIME__; const char *launcher_gitrev = STRINGIFY(GITREV); +const char *launcher_linked_avs_version = STRINGIFY(AVS_VERSION); \ No newline at end of file diff --git a/src/main/launcher/version.h b/src/main/launcher/version.h index fe7f0d3..9764563 100644 --- a/src/main/launcher/version.h +++ b/src/main/launcher/version.h @@ -2,3 +2,4 @@ extern const char *launcher_build_date; extern const char *launcher_gitrev; +extern const char *launcher_linked_avs_version; diff --git a/src/main/mempatch-hook/Module.mk b/src/main/mempatch-hook/Module.mk index 1dedd43..6f58ff6 100644 --- a/src/main/mempatch-hook/Module.mk +++ b/src/main/mempatch-hook/Module.mk @@ -3,6 +3,7 @@ dlls += mempatch-hook libs_mempatch-hook := \ util \ core \ + iface-core \ src_mempatch-hook := \ main.c \ diff --git a/src/main/mempatch-hook/main.c b/src/main/mempatch-hook/main.c index 856b962..2d6d4f4 100644 --- a/src/main/mempatch-hook/main.c +++ b/src/main/mempatch-hook/main.c @@ -6,7 +6,9 @@ #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" +#include "core/log-sink-std.h" + +#include "iface-core/log.h" #include "util/cmdline.h" #include "util/fs.h" @@ -290,8 +292,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) patched = false; - core_log_bt_ext_impl_set(); - core_log_bt_ext_init_with_file("mempatch.log", false, false, 0); + core_log_bt_core_api_set(); + + core_log_bt_ext_init_with_stderr_and_file( + "mempatch.log", false, false, 0); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); args_recover(&argc, &argv); diff --git a/src/main/mm/Module.mk b/src/main/mm/Module.mk index 5ffd406..877007c 100644 --- a/src/main/mm/Module.mk +++ b/src/main/mm/Module.mk @@ -6,6 +6,7 @@ ldflags_mm := \ libs_mm := \ util \ + iface-core \ src_mm := \ mm.c \ diff --git a/src/main/mm/Sources b/src/main/mm/Sources deleted file mode 100644 index 7062a2f..0000000 --- a/src/main/mm/Sources +++ /dev/null @@ -1,6 +0,0 @@ -!include ../Common.inc - -TARGETNAME = libmm -TARGETTYPE = LIBRARY -SOURCES = mm.c - diff --git a/src/main/mm/mm.c b/src/main/mm/mm.c index 2c89957..1518904 100644 --- a/src/main/mm/mm.c +++ b/src/main/mm/mm.c @@ -9,7 +9,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "mm/mm.h" diff --git a/src/main/module/Module.mk b/src/main/module/Module.mk new file mode 100644 index 0000000..b2a5f5c --- /dev/null +++ b/src/main/module/Module.mk @@ -0,0 +1,16 @@ +libs += module + +libs_module := \ + core \ + hook \ + util \ + +src_module := \ + acio-mgr-ext.c \ + acio-mgr.c \ + hook.c \ + input-ext.c \ + input.c \ + io-ext.c \ + io.c \ + module.c \ diff --git a/src/main/module/acio-mgr-ext.c b/src/main/module/acio-mgr-ext.c new file mode 100644 index 0000000..f213f57 --- /dev/null +++ b/src/main/module/acio-mgr-ext.c @@ -0,0 +1,15 @@ +#include "iface-core/log.h" + +#include "module/acio-mgr.h" + +void module_acio_mgr_ext_load_and_init( + const char *path, module_acio_mgr_t **module) +{ + bt_core_log_api_t core_log_api; + + module_acio_mgr_load(path, module); + + bt_core_log_api_get(&core_log_api); + + module_acio_mgr_core_log_api_set(*module, &core_log_api); +} \ No newline at end of file diff --git a/src/main/module/acio-mgr-ext.h b/src/main/module/acio-mgr-ext.h new file mode 100644 index 0000000..b8e0803 --- /dev/null +++ b/src/main/module/acio-mgr-ext.h @@ -0,0 +1,9 @@ +#ifndef MODULE_ACIO_MGR_EXT_H +#define MODULE_ACIO_MGR_EXT_H + +#include "module/acio-mgr.h" + +void module_acio_mgr_ext_load_and_init( + const char *path, module_acio_mgr_t **module); + +#endif \ No newline at end of file diff --git a/src/main/module/acio-mgr.c b/src/main/module/acio-mgr.c new file mode 100644 index 0000000..08f55dd --- /dev/null +++ b/src/main/module/acio-mgr.c @@ -0,0 +1,83 @@ +#define LOG_MODULE "module-acio_mgr" + +#include "api/acio/mgr.h" +#include "api/core/log.h" + +#include "iface-core/log.h" + +#include "main/module/acio-mgr.h" +#include "main/module/core.h" +#include "main/module/module.h" + +#include "util/mem.h" + +typedef void (*module_acio_mgr_api_get_t)(bt_acio_mgr_api_t *api); + +struct module_acio_mgr { + module_t *module; + + bt_module_core_log_api_set_t core_log_api_set; + + module_acio_mgr_api_get_t api_get; +}; + +static void _module_acio_mgr_resolve(module_acio_mgr_t *module) +{ + module->core_log_api_set = + (bt_module_core_log_api_set_t) module_func_optional_resolve( + module->module, "bt_module_core_log_api_set"); + + module->api_get = (module_acio_mgr_api_get_t) module_func_required_resolve( + module->module, "bt_acio_mgr_api_get"); +} + +void module_acio_mgr_load(const char *path, module_acio_mgr_t **module) +{ + log_assert(path); + log_assert(module); + + *module = xmalloc(sizeof(module_acio_mgr_t)); + memset(*module, 0, sizeof(module_acio_mgr_t)); + + module_load(path, &(*module)->module); + + _module_acio_mgr_resolve(*module); +} + +void module_acio_mgr_free(module_acio_mgr_t **module) +{ + log_assert(module); + + module_free(&(*module)->module); + memset(*module, 0, sizeof(module_acio_mgr_t)); +} + +void module_acio_mgr_core_log_api_set( + const module_acio_mgr_t *module, const bt_core_log_api_t *api) +{ + log_assert(module); + log_assert(api); + + if (module->core_log_api_set) { + module_func_pre_invoke_log( + module->module, "bt_module_core_log_api_set"); + + module->core_log_api_set(api); + + module_func_post_invoke_log( + module->module, "bt_module_core_log_api_set"); + } +} + +void module_acio_mgr_api_get( + const module_acio_mgr_t *module, bt_acio_mgr_api_t *api) +{ + log_assert(module); + log_assert(api); + + module_func_pre_invoke_log(module->module, "bt_acio_mgr_api_get"); + + module->api_get(api); + + module_func_post_invoke_log(module->module, "bt_acio_mgr_api_get"); +} \ No newline at end of file diff --git a/src/main/module/acio-mgr.h b/src/main/module/acio-mgr.h new file mode 100644 index 0000000..be93067 --- /dev/null +++ b/src/main/module/acio-mgr.h @@ -0,0 +1,21 @@ +#ifndef MODULE_ACIO_MGR_H +#define MODULE_ACIO_MGR_H + +#include +#include + +#include "api/acio/mgr.h" +#include "api/core/log.h" + +typedef struct module_acio_mgr module_acio_mgr_t; + +void module_acio_mgr_load(const char *path, module_acio_mgr_t **module); +void module_acio_mgr_free(module_acio_mgr_t **module); + +void module_acio_mgr_core_log_api_set( + const module_acio_mgr_t *module, const bt_core_log_api_t *api); + +void module_acio_mgr_api_get( + const module_acio_mgr_t *module, bt_acio_mgr_api_t *api); + +#endif \ No newline at end of file diff --git a/src/main/module/core.h b/src/main/module/core.h new file mode 100644 index 0000000..936e0a2 --- /dev/null +++ b/src/main/module/core.h @@ -0,0 +1,14 @@ +#ifndef MODULE_CORE_H +#define MODULE_CORE_H + +#include "api/core/config.h" +#include "api/core/log.h" +#include "api/core/thread.h" + +typedef void (*bt_module_core_config_api_set_t)( + const bt_core_config_api_t *api); +typedef void (*bt_module_core_log_api_set_t)(const bt_core_log_api_t *api); +typedef void (*bt_module_core_thread_api_set_t)( + const bt_core_thread_api_t *api); + +#endif \ No newline at end of file diff --git a/src/main/module/hook.c b/src/main/module/hook.c new file mode 100644 index 0000000..013bd11 --- /dev/null +++ b/src/main/module/hook.c @@ -0,0 +1,142 @@ +#define LOG_MODULE "module-hook" + +#include + +#include "iface-core/config.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "main/module/core.h" +#include "main/module/hook.h" +#include "main/module/module.h" + +#include "util/mem.h" +#include "util/str.h" + +typedef void (*module_hook_api_get_t)(bt_hook_api_t *api); + +struct module_hook { + module_t *module; + + bt_module_core_config_api_set_t core_config_api_set; + bt_module_core_log_api_set_t core_log_api_set; + bt_module_core_thread_api_set_t core_thread_api_set; + + module_hook_api_get_t api_get; +}; + +static void _module_hook_resolve(module_hook_t *module) +{ + module->core_config_api_set = + (bt_module_core_config_api_set_t) module_func_optional_resolve( + module->module, "bt_module_core_config_api_set"); + module->core_log_api_set = + (bt_module_core_log_api_set_t) module_func_optional_resolve( + module->module, "bt_module_core_log_api_set"); + module->core_thread_api_set = + (bt_module_core_thread_api_set_t) module_func_optional_resolve( + module->module, "bt_module_core_thread_api_set"); + + module->api_get = (module_hook_api_get_t) module_func_optional_resolve( + module->module, "bt_module_hook_api_get"); +} + +void module_hook_load(const char *path, module_hook_t **module) +{ + log_assert(path); + log_assert(module); + + *module = xmalloc(sizeof(module_hook_t)); + memset(*module, 0, sizeof(module_hook_t)); + + module_load(path, &(*module)->module); + + _module_hook_resolve(*module); +} + +const char *module_hook_path_get(const module_hook_t *module) +{ + log_assert(module); + + return module_path_get(module->module); +} + +void module_hook_free(module_hook_t **module) +{ + log_assert(module); + + module_free(&(*module)->module); + memset(*module, 0, sizeof(module_hook_t)); +} + +void module_hook_core_config_api_set( + const module_hook_t *module, const bt_core_config_api_t *api) +{ + log_assert(module); + log_assert(api); + + if (module->core_config_api_set) { + module_func_pre_invoke_log( + module->module, "bt_module_core_config_api_set"); + + module->core_config_api_set(api); + + module_func_post_invoke_log( + module->module, "bt_module_core_config_api_set"); + } +} + +void module_hook_core_log_api_set( + const module_hook_t *module, const bt_core_log_api_t *api) +{ + log_assert(module); + log_assert(api); + + if (module->core_log_api_set) { + module_func_pre_invoke_log( + module->module, "bt_module_core_log_api_set"); + + module->core_log_api_set(api); + + module_func_post_invoke_log( + module->module, "bt_module_core_log_api_set"); + } +} + +void module_hook_core_thread_api_set( + const module_hook_t *module, const bt_core_thread_api_t *api) +{ + log_assert(module); + log_assert(api); + + if (module->core_thread_api_set) { + module_func_pre_invoke_log( + module->module, "bt_module_core_thread_api_set"); + + module->core_thread_api_set(api); + + module_func_post_invoke_log( + module->module, "bt_module_core_thread_api_set"); + } +} + +void module_hook_api_get(const module_hook_t *module, bt_hook_api_t *api) +{ + log_assert(module); + log_assert(api); + + memset(api, 0, sizeof(bt_hook_api_t)); + + if (module->api_get) { + module_func_pre_invoke_log(module->module, "bt_hook_api_get"); + + module->api_get(api); + + module_func_post_invoke_log(module->module, "bt_hook_api_get"); + } else { + // Consider this still v1 as all functions are optional + // This allows for creating rather simple and even bemanitools + // independent hook libraries that only use DllMain + api->version = 1; + } +} diff --git a/src/main/module/hook.h b/src/main/module/hook.h new file mode 100644 index 0000000..f657f26 --- /dev/null +++ b/src/main/module/hook.h @@ -0,0 +1,26 @@ +#ifndef MODULE_HOOK_H +#define MODULE_HOOK_H + +#include + +#include +#include + +#include "api/hook.h" + +typedef struct module_hook module_hook_t; + +void module_hook_load(const char *path, module_hook_t **module); +const char *module_hook_path_get(const module_hook_t *module); +void module_hook_free(module_hook_t **module); + +void module_hook_core_config_api_set( + const module_hook_t *module, const bt_core_config_api_t *api); +void module_hook_core_log_api_set( + const module_hook_t *module, const bt_core_log_api_t *api); +void module_hook_core_thread_api_set( + const module_hook_t *module, const bt_core_thread_api_t *api); + +void module_hook_api_get(const module_hook_t *module, bt_hook_api_t *api); + +#endif \ No newline at end of file diff --git a/src/main/module/input-ext.c b/src/main/module/input-ext.c new file mode 100644 index 0000000..5022faa --- /dev/null +++ b/src/main/module/input-ext.c @@ -0,0 +1,18 @@ +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "module/input.h" + +void module_input_ext_load_and_init(const char *path, module_input_t **module) +{ + bt_core_log_api_t core_log_api; + bt_core_thread_api_t core_thread_api; + + module_input_load(path, module); + + bt_core_log_api_get(&core_log_api); + bt_core_thread_api_get(&core_thread_api); + + module_input_core_log_api_set(*module, &core_log_api); + module_input_core_thread_api_set(*module, &core_thread_api); +} \ No newline at end of file diff --git a/src/main/module/input-ext.h b/src/main/module/input-ext.h new file mode 100644 index 0000000..0967b45 --- /dev/null +++ b/src/main/module/input-ext.h @@ -0,0 +1,8 @@ +#ifndef MODULE_INPUT_EXT_H +#define MODULE_INPUT_EXT_H + +#include "module/input.h" + +void module_input_ext_load_and_init(const char *path, module_input_t **module); + +#endif \ No newline at end of file diff --git a/src/main/module/input.c b/src/main/module/input.c new file mode 100644 index 0000000..cde728a --- /dev/null +++ b/src/main/module/input.c @@ -0,0 +1,104 @@ +#define LOG_MODULE "module-input" + +#include "api/input.h" +#include "api/core/log.h" +#include "api/core/thread.h" + +#include "iface-core/log.h" + +#include "main/module/core.h" +#include "main/module/input.h" +#include "main/module/module.h" + +#include "util/mem.h" + +typedef void (*module_input_api_get_t)(bt_input_api_t *api); + +struct module_input { + module_t *module; + + bt_module_core_log_api_set_t core_log_api_set; + bt_module_core_thread_api_set_t core_thread_api_set; + + module_input_api_get_t api_get; +}; + +static void _module_input_resolve(module_input_t *module) +{ + module->core_log_api_set = + (bt_module_core_log_api_set_t) module_func_optional_resolve( + module->module, "bt_module_core_log_api_set"); + module->core_thread_api_set = + (bt_module_core_thread_api_set_t) module_func_optional_resolve( + module->module, "bt_module_core_thread_api_set"); + + module->api_get = (module_input_api_get_t) module_func_required_resolve( + module->module, "bt_module_input_api_get"); +} + +void module_input_load(const char *path, module_input_t **module) +{ + log_assert(path); + log_assert(module); + + *module = xmalloc(sizeof(module_input_t)); + memset(*module, 0, sizeof(module_input_t)); + + module_load(path, &(*module)->module); + + _module_input_resolve(*module); +} + +void module_input_free(module_input_t **module) +{ + log_assert(module); + + module_free(&(*module)->module); + memset(*module, 0, sizeof(module_input_t)); +} + +void module_input_core_log_api_set( + const module_input_t *module, const bt_core_log_api_t *api) +{ + log_assert(module); + log_assert(api); + + if (module->core_log_api_set) { + module_func_pre_invoke_log( + module->module, "bt_module_core_log_api_set"); + + module->core_log_api_set(api); + + module_func_post_invoke_log( + module->module, "bt_module_core_log_api_set"); + } +} + +void module_input_core_thread_api_set( + const module_input_t *module, const bt_core_thread_api_t *api) +{ + log_assert(module); + log_assert(api); + + if (module->core_thread_api_set) { + module_func_pre_invoke_log( + module->module, "bt_module_core_thread_api_set"); + + module->core_thread_api_set(api); + + module_func_post_invoke_log( + module->module, "bt_module_core_thread_api_set"); + } +} + +void module_input_api_get(const module_input_t *module, bt_input_api_t *api) +{ + log_assert(module); + log_assert(api); + + module_func_pre_invoke_log(module->module, "bt_module_input_api_get"); + + module->api_get(api); + + module_func_post_invoke_log(module->module, "bt_module_input_api_get"); +} \ No newline at end of file diff --git a/src/main/module/input.h b/src/main/module/input.h new file mode 100644 index 0000000..0529c5c --- /dev/null +++ b/src/main/module/input.h @@ -0,0 +1,24 @@ +#ifndef MODULE_INPUT_H +#define MODULE_INPUT_H + +#include +#include + +#include "api/core/log.h" +#include "api/core/thread.h" + +#include "api/input.h" + +typedef struct module_input module_input_t; + +void module_input_load(const char *path, module_input_t **module); +void module_input_free(module_input_t **module); + +void module_input_core_log_api_set( + const module_input_t *module, const bt_core_log_api_t *api); +void module_input_core_thread_api_set( + const module_input_t *module, const bt_core_thread_api_t *api); + +void module_input_api_get(const module_input_t *module, bt_input_api_t *api); + +#endif \ No newline at end of file diff --git a/src/main/module/io-ext.c b/src/main/module/io-ext.c new file mode 100644 index 0000000..a3cc32d --- /dev/null +++ b/src/main/module/io-ext.c @@ -0,0 +1,26 @@ +#include "iface-core/config.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "module/io.h" + +void module_io_ext_load_and_init( + const char *path, const char *api_get_func_name, module_io_t **module) +{ + // TODO currently not supported + // bt_core_config_api_t core_config_api; + bt_core_log_api_t core_log_api; + bt_core_thread_api_t core_thread_api; + + module_io_load(path, api_get_func_name, module); + + // TODO currently not supported + // bt_core_config_api_get(&core_config_api); + bt_core_log_api_get(&core_log_api); + bt_core_thread_api_get(&core_thread_api); + + // TODO currently not supported + // module_io_core_config_api_set(*module, &core_config_api); + module_io_core_log_api_set(*module, &core_log_api); + module_io_core_thread_api_set(*module, &core_thread_api); +} \ No newline at end of file diff --git a/src/main/module/io-ext.h b/src/main/module/io-ext.h new file mode 100644 index 0000000..993794f --- /dev/null +++ b/src/main/module/io-ext.h @@ -0,0 +1,9 @@ +#ifndef MODULE_IO_EXT_H +#define MODULE_IO_EXT_H + +#include "module/io.h" + +void module_io_ext_load_and_init( + const char *path, const char *api_get_func_name, module_io_t **module); + +#endif \ No newline at end of file diff --git a/src/main/module/io.c b/src/main/module/io.c new file mode 100644 index 0000000..11ef1ec --- /dev/null +++ b/src/main/module/io.c @@ -0,0 +1,135 @@ + +#define LOG_MODULE "module-io" + +#include "api/core/config.h" +#include "api/core/thread.h" + +#include "iface-core/log.h" + +#include "main/module/core.h" +#include "main/module/io.h" +#include "main/module/module.h" + +#include "util/mem.h" +#include "util/str.h" + +typedef void (*module_io_api_get_t)(void *api); + +struct module_io { + module_t *module; + + bt_module_core_config_api_set_t core_config_api_set; + bt_module_core_log_api_set_t core_log_api_set; + bt_module_core_thread_api_set_t core_thread_api_set; + + module_io_api_get_t api_get; + // Keep for debug logging + char api_get_func_name[4096]; +}; + +static void +_module_io_resolve(module_io_t *module, const char *api_get_func_name) +{ + module->core_config_api_set = + (bt_module_core_config_api_set_t) module_func_optional_resolve( + module->module, "bt_module_core_config_api_set"); + module->core_log_api_set = + (bt_module_core_log_api_set_t) module_func_optional_resolve( + module->module, "bt_module_core_log_api_set"); + module->core_thread_api_set = + (bt_module_core_thread_api_set_t) module_func_optional_resolve( + module->module, "bt_module_core_thread_api_set"); + + module->api_get = (module_io_api_get_t) module_func_required_resolve( + module->module, api_get_func_name); + str_cpy( + module->api_get_func_name, + sizeof(module->api_get_func_name), + api_get_func_name); +} + +void module_io_load( + const char *path, const char *api_get_func_name, module_io_t **module) +{ + log_assert(path); + log_assert(api_get_func_name); + log_assert(module); + + *module = xmalloc(sizeof(module_io_t)); + memset(*module, 0, sizeof(module_io_t)); + + module_load(path, &(*module)->module); + + _module_io_resolve(*module, api_get_func_name); +} + +void module_io_free(module_io_t **module) +{ + log_assert(module); + + module_free(&(*module)->module); + memset(*module, 0, sizeof(module_io_t)); +} + +void module_io_core_config_api_set( + const module_io_t *module, const bt_core_config_api_t *api) +{ + log_assert(module); + log_assert(api); + + if (module->core_config_api_set) { + module_func_pre_invoke_log( + module->module, "bt_module_core_config_api_set"); + + module->core_config_api_set(api); + + module_func_post_invoke_log( + module->module, "bt_module_core_config_api_set"); + } +} + +void module_io_core_log_api_set( + const module_io_t *module, const bt_core_log_api_t *api) +{ + log_assert(module); + log_assert(api); + + if (module->core_log_api_set) { + module_func_pre_invoke_log( + module->module, "bt_module_core_log_api_set"); + + module->core_log_api_set(api); + + module_func_post_invoke_log( + module->module, "bt_module_core_log_api_set"); + } +} + +void module_io_core_thread_api_set( + const module_io_t *module, const bt_core_thread_api_t *api) +{ + log_assert(module); + log_assert(api); + + if (module->core_thread_api_set) { + module_func_pre_invoke_log( + module->module, "bt_module_core_thread_api_set"); + + module->core_thread_api_set(api); + + module_func_post_invoke_log( + module->module, "bt_module_core_thread_api_set"); + } +} + +void module_io_api_get(const module_io_t *module, void *api) +{ + log_assert(module); + log_assert(api); + + module_func_pre_invoke_log(module->module, module->api_get_func_name); + + module->api_get(api); + + module_func_post_invoke_log(module->module, module->api_get_func_name); +} \ No newline at end of file diff --git a/src/main/module/io.h b/src/main/module/io.h new file mode 100644 index 0000000..5329513 --- /dev/null +++ b/src/main/module/io.h @@ -0,0 +1,26 @@ +#ifndef MODULE_IO_H +#define MODULE_IO_H + +#include +#include + +#include "api/core/config.h" +#include "api/core/log.h" +#include "api/core/thread.h" + +typedef struct module_io module_io_t; + +void module_io_load( + const char *path, const char *api_get_func_name, module_io_t **module); +void module_io_free(module_io_t **module); + +void module_io_core_config_api_set( + const module_io_t *module, const bt_core_config_api_t *api); +void module_io_core_log_api_set( + const module_io_t *module, const bt_core_log_api_t *api); +void module_io_core_thread_api_set( + const module_io_t *module, const bt_core_thread_api_t *api); + +void module_io_api_get(const module_io_t *module, void *api); + +#endif \ No newline at end of file diff --git a/src/main/module/module.c b/src/main/module/module.c new file mode 100644 index 0000000..22832bb --- /dev/null +++ b/src/main/module/module.c @@ -0,0 +1,285 @@ +#define LOG_MODULE "module" + +#include + +#include +#include + +#include "hook/pe.h" + +#include "iface-core/log.h" + +#include "module/module.h" + +#include "util/mem.h" +#include "util/str.h" + +#define MM_ALLOCATION_GRANULARITY 0x10000 +#define MODULE_FUNC_NAME_MAX_LEN 256 + +struct module { + char path[MAX_PATH]; + HMODULE handle; +}; + +static void _module_hook_dll_iat( + HMODULE hModule, const char *source_dll, const char *iat_hook) +{ + log_assert(hModule); + log_assert(source_dll); + log_assert(iat_hook); + + log_misc( + "replace dll iat of module %p, %s -> %s", + hModule, + source_dll, + iat_hook); + + PBYTE pbModule = (PBYTE) hModule; + + // Find EXE base in process memory + IMAGE_DOS_HEADER *idh = (IMAGE_DOS_HEADER *) pbModule; + IMAGE_NT_HEADERS *inh = (IMAGE_NT_HEADERS *) (pbModule + idh->e_lfanew); + + // Search through import table if it exists and replace the target DLL with + // our DLL filename + PIMAGE_SECTION_HEADER pRemoteSectionHeaders = + (PIMAGE_SECTION_HEADER) ((PBYTE) pbModule + sizeof(inh->Signature) + + sizeof(inh->FileHeader) + + inh->FileHeader.SizeOfOptionalHeader); + size_t total_size = inh->OptionalHeader.SizeOfHeaders; + + for (DWORD n = 0; n < inh->FileHeader.NumberOfSections; ++n) { + IMAGE_SECTION_HEADER *header = + (IMAGE_SECTION_HEADER *) (pRemoteSectionHeaders + n); + size_t new_total_size = + header->VirtualAddress + header->Misc.VirtualSize; + if (new_total_size > total_size) + total_size = new_total_size; + } + + void *remote_addr = NULL; + size_t remote_addr_ptr = 0; + + for (size_t i = 0; i < 10000 && remote_addr == NULL; i++) { + remote_addr = VirtualAlloc( + pbModule + total_size + (MM_ALLOCATION_GRANULARITY * (i + 1)), + MAX_PATH + 1, + MEM_RESERVE | MEM_COMMIT, + PAGE_READWRITE); + } + + log_assert(remote_addr != NULL); + + if (inh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] + .VirtualAddress != 0) { + PIMAGE_IMPORT_DESCRIPTOR pImageImport = + (PIMAGE_IMPORT_DESCRIPTOR) (pbModule + + inh->OptionalHeader + .DataDirectory + [IMAGE_DIRECTORY_ENTRY_IMPORT] + .VirtualAddress); + + DWORD size = 0; + while (inh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] + .Size == 0 || + size < inh->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] + .Size) { + IMAGE_IMPORT_DESCRIPTOR *ImageImport = + (IMAGE_IMPORT_DESCRIPTOR *) pImageImport; + + if (ImageImport->Name == 0) { + break; + } + + const char *name = (const char *) (pbModule + ImageImport->Name); + const char *expected_dll = source_dll; + const char *replacement_path_dll = iat_hook; + + if (strcmp(name, expected_dll) == 0) { + pe_patch( + (PBYTE) remote_addr + remote_addr_ptr, + replacement_path_dll, + strlen(replacement_path_dll)); + + log_misc("Replacing %s with %s", name, replacement_path_dll); + + DWORD val = (DWORD) ((PBYTE) remote_addr - pbModule); + + pe_patch(&ImageImport->Name, &val, sizeof(DWORD)); + pe_patch(pImageImport, &ImageImport, sizeof(ImageImport)); + + remote_addr_ptr += strlen(replacement_path_dll) + 1; + } + + pImageImport++; + size += sizeof(IMAGE_IMPORT_DESCRIPTOR); + } + } else { + log_fatal("Couldn't find import table, can't hook DLL: %s", iat_hook); + } +} + +static HMODULE _module_load(const char *path, bool resolve_references) +{ + HMODULE module; + LPSTR buffer; + DWORD err; + + log_misc("%s: loading", path); + + if (resolve_references) { + module = LoadLibraryA(path); + } else { + module = LoadLibraryExA(path, NULL, DONT_RESOLVE_DLL_REFERENCES); + } + + if (module == NULL) { + err = GetLastError(); + + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR) &buffer, + 0, + NULL); + + if (err == ERROR_MOD_NOT_FOUND) { + log_warning("%s is likely missing dependencies", path); + } + + log_fatal("Failed to load module %s: %s", path, buffer); + + LocalFree(buffer); + } + + log_misc("%s (%p): loaded", path, module); + + return module; +} + +void module_load(const char *path, module_t **module) +{ + log_assert(path); + log_assert(module); + + *module = xmalloc(sizeof(module_t)); + memset(*module, 0, sizeof(module_t)); + + log_info("%s: load", path); + + str_cpy((*module)->path, sizeof((*module)->path), path); + (*module)->handle = _module_load(path, true); + + log_misc("%s (%p): loaded", (*module)->path, (*module)->handle); +} + +HMODULE module_handle_get(const module_t *module) +{ + log_assert(module); + + return module->handle; +} + +const char *module_path_get(const module_t *module) +{ + log_assert(module); + + return module->path; +} + +void *module_func_required_resolve(const module_t *module, const char *name) +{ + void *func; + + log_assert(module); + log_assert(name); + + func = GetProcAddress(module->handle, name); + + module_func_required_verify(module, func, name); + + return func; +} + +void *module_func_optional_resolve(const module_t *module, const char *name) +{ + void *func; + + log_assert(module); + log_assert(name); + + func = GetProcAddress(module->handle, name); + + module_func_optional_verify(module, func, name); + + return func; +} + +void module_func_required_verify( + const module_t *module, void *func, const char *name) +{ + log_assert(module); + log_assert(name); + + if (!func) { + log_fatal( + "%s (%p): Missing required function '%s'", + module->path, + module->handle, + name); + } + + log_misc( + "%s (%p): required function '%s' at %p", + module->path, + module->handle, + name, + func); +} + +void module_func_optional_verify( + const module_t *module, void *func, const char *name) +{ + log_assert(module); + log_assert(name); + + if (!func) { + log_misc( + "%s (%p): optional function '%s' NOT IMPLEMENTED", + module->path, + module->handle, + name); + } else { + log_misc( + "%s (%p): optional function '%s' at %p", + module->path, + module->handle, + name, + func); + } +} + +void module_func_pre_invoke_log(const module_t *module, const char *name) +{ + log_misc("%s (%p): >>> %s", module->path, module->handle, name); +} + +void module_func_post_invoke_log(const module_t *module, const char *name) +{ + log_misc("%s (%p): <<< %s", module->path, module->handle, name); +} + +void module_free(module_t **module) +{ + log_assert(module); + + log_misc("%s (%p): free", (*module)->path, (*module)->handle); + + FreeLibrary((*module)->handle); + memset(*module, 0, sizeof(module_t)); +} diff --git a/src/main/module/module.h b/src/main/module/module.h new file mode 100644 index 0000000..8d71339 --- /dev/null +++ b/src/main/module/module.h @@ -0,0 +1,24 @@ +#ifndef MODULE_H +#define MODULE_H + +#include + +#include +#include + +typedef struct module module_t; + +void module_load(const char *path, module_t **module); +HMODULE module_handle_get(const module_t *module); +const char *module_path_get(const module_t *module); +void *module_func_required_resolve(const module_t *module, const char *name); +void *module_func_optional_resolve(const module_t *module, const char *name); +void module_func_required_verify( + const module_t *module, void *func, const char *name); +void module_func_optional_verify( + const module_t *module, void *func, const char *name); +void module_func_pre_invoke_log(const module_t *module, const char *name); +void module_func_post_invoke_log(const module_t *module, const char *name); +void module_free(module_t **module); + +#endif \ No newline at end of file diff --git a/src/main/p3io-ddr-tool/Module.mk b/src/main/p3io-ddr-tool/Module.mk index f6e3a16..7873a59 100644 --- a/src/main/p3io-ddr-tool/Module.mk +++ b/src/main/p3io-ddr-tool/Module.mk @@ -11,6 +11,7 @@ libs_p3io-ddr-tool := \ p3io \ hook \ util \ + iface-core \ src_p3io-ddr-tool := \ main.c \ diff --git a/src/main/p3io-ddr-tool/main.c b/src/main/p3io-ddr-tool/main.c index 4a9bac3..0bac662 100644 --- a/src/main/p3io-ddr-tool/main.c +++ b/src/main/p3io-ddr-tool/main.c @@ -10,10 +10,11 @@ #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-std.h" -#include "core/log.h" #include "extiodrv/extio.h" +#include "iface-core/log.h" + #include "p3io/ddr.h" #include "p3iodrv/ddr.h" #include "p3iodrv/device.h" @@ -258,7 +259,8 @@ static bool _process_cmd_args(int argc, char **argv) static void _init_logging() { - core_log_bt_ext_impl_set(); + core_log_bt_core_api_set(); + core_log_bt_ext_init_with_stderr(); core_log_bt_level_set(_log_level); } diff --git a/src/main/p3io-ddr-tool/mode-test.c b/src/main/p3io-ddr-tool/mode-test.c index 0c3f5a9..2de712b 100644 --- a/src/main/p3io-ddr-tool/mode-test.c +++ b/src/main/p3io-ddr-tool/mode-test.c @@ -3,10 +3,10 @@ #include #include -#include "core/log.h" - #include "extiodrv/extio.h" +#include "iface-core/log.h" + #include "p3io/ddr.h" #include "p3iodrv/ddr.h" #include "p3iodrv/device.h" diff --git a/src/main/p3io/cmd.c b/src/main/p3io/cmd.c index b62958f..db7ae7c 100644 --- a/src/main/p3io/cmd.c +++ b/src/main/p3io/cmd.c @@ -1,6 +1,6 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "p3io/cmd.h" diff --git a/src/main/p3io/frame.c b/src/main/p3io/frame.c index 1fc6d2c..b595427 100644 --- a/src/main/p3io/frame.c +++ b/src/main/p3io/frame.c @@ -3,7 +3,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "p3io/frame.h" diff --git a/src/main/p3iodrv/ddr.c b/src/main/p3iodrv/ddr.c index 57ebfab..039ee83 100644 --- a/src/main/p3iodrv/ddr.c +++ b/src/main/p3iodrv/ddr.c @@ -1,8 +1,8 @@ #define LOG_MODULE "p3iodrv-ddr" -#include "p3io/cmd.h" +#include "iface-core/log.h" -#include "core/log.h" +#include "p3io/cmd.h" #include "ddr.h" #include "device.h" diff --git a/src/main/p3iodrv/device.c b/src/main/p3iodrv/device.c index afa2c51..27096a7 100644 --- a/src/main/p3iodrv/device.c +++ b/src/main/p3iodrv/device.c @@ -10,7 +10,7 @@ #include // clang-format on -#include "core/log.h" +#include "iface-core/log.h" #include "p3io/cmd.h" #include "p3io/guid.h" diff --git a/src/main/p3ioemu/devmgr.c b/src/main/p3ioemu/devmgr.c index ac26233..fe30141 100644 --- a/src/main/p3ioemu/devmgr.c +++ b/src/main/p3ioemu/devmgr.c @@ -7,10 +7,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "p3io/guid.h" #include "p3ioemu/devmgr.h" diff --git a/src/main/p3ioemu/emu.c b/src/main/p3ioemu/emu.c index 7fc2123..d436c47 100644 --- a/src/main/p3ioemu/emu.c +++ b/src/main/p3ioemu/emu.c @@ -7,10 +7,10 @@ #include #include -#include "core/log.h" - #include "hook/iohook.h" +#include "iface-core/log.h" + #include "p3io/cmd.h" #include "p3io/frame.h" #include "p3io/ioctl.h" diff --git a/src/main/p3ioemu/uart.c b/src/main/p3ioemu/uart.c index cbceb5a..f4bc696 100644 --- a/src/main/p3ioemu/uart.c +++ b/src/main/p3ioemu/uart.c @@ -10,10 +10,10 @@ #include -#include "core/log.h" - #include "hook/iohook.h" +#include "iface-core/log.h" + #include "p3io/cmd.h" #include "p3ioemu/uart.h" diff --git a/src/main/p4iodrv/device.c b/src/main/p4iodrv/device.c index da65f7b..d809991 100644 --- a/src/main/p4iodrv/device.c +++ b/src/main/p4iodrv/device.c @@ -2,7 +2,7 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "p4io/cmd.h" diff --git a/src/main/p4iodrv/usb.c b/src/main/p4iodrv/usb.c index 243adae..25cec64 100644 --- a/src/main/p4iodrv/usb.c +++ b/src/main/p4iodrv/usb.c @@ -10,7 +10,7 @@ #include // clang-format on -#include "core/log.h" +#include "iface-core/log.h" #include "p4io/cmd.h" #include "p4io/guid.h" diff --git a/src/main/p4ioemu/device.c b/src/main/p4ioemu/device.c index 4e7498f..94fb17d 100644 --- a/src/main/p4ioemu/device.c +++ b/src/main/p4ioemu/device.c @@ -6,9 +6,10 @@ #include #include -#include "core/log.h" - #include "hook/iohook.h" + +#include "iface-core/log.h" + #include "p4io/cmd.h" #include "p4io/ioctl.h" #include "util/hex.h" diff --git a/src/main/pcbidgen/Module.mk b/src/main/pcbidgen/Module.mk index 612510f..15fd810 100644 --- a/src/main/pcbidgen/Module.mk +++ b/src/main/pcbidgen/Module.mk @@ -2,8 +2,9 @@ exes += pcbidgen libs_pcbidgen := \ security \ - util \ core \ + iface-core \ + util \ src_pcbidgen := \ main.c \ diff --git a/src/main/pcbidgen/main.c b/src/main/pcbidgen/main.c index 3e9182b..d92d1a5 100644 --- a/src/main/pcbidgen/main.c +++ b/src/main/pcbidgen/main.c @@ -5,6 +5,10 @@ #include #include +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log-sink-std.h" + #include "security/id.h" #include "util/hex.h" @@ -30,6 +34,11 @@ int main(int argc, char **argv) return -1; } + core_log_bt_core_api_set(); + + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); + if (!strcmp(argv[1], "gen")) { srand(time(NULL)); diff --git a/src/main/popnhook-util/acio.c b/src/main/popnhook-util/acio.c index 465bdcd..3b150be 100644 --- a/src/main/popnhook-util/acio.c +++ b/src/main/popnhook-util/acio.c @@ -15,11 +15,11 @@ #include "acioemu/emu.h" #include "acioemu/icca.h" -#include "core/log.h" - #include "hook/iohook.h" #include "hooklib/rs232.h" +#include "iface-core/log.h" + #include "popnhook-util/acio.h" #include "imports/avs.h" diff --git a/src/main/popnhook-util/mixer.c b/src/main/popnhook-util/mixer.c index 904a008..e957d8c 100644 --- a/src/main/popnhook-util/mixer.c +++ b/src/main/popnhook-util/mixer.c @@ -6,10 +6,10 @@ #include // clang-format on -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" MMRESULT STDCALL hook_mixerGetLineControlsA( diff --git a/src/main/popnhook1/Module.mk b/src/main/popnhook1/Module.mk index f744773..15128ab 100644 --- a/src/main/popnhook1/Module.mk +++ b/src/main/popnhook1/Module.mk @@ -17,13 +17,15 @@ libs_popnhook1 := \ acioemu \ hook \ hooklib \ - eamio \ - popnio \ cconfig \ util \ ezusb \ security \ popnhook-util \ + iface \ + iface-io \ + iface-core \ + module \ src_popnhook1 := \ avs-boot.c \ diff --git a/src/main/popnhook1/avs-boot.c b/src/main/popnhook1/avs-boot.c index aae4616..b2c6aa3 100644 --- a/src/main/popnhook1/avs-boot.c +++ b/src/main/popnhook1/avs-boot.c @@ -5,10 +5,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "popnhook1/avs-boot.h" diff --git a/src/main/popnhook1/config-eamuse.c b/src/main/popnhook1/config-eamuse.c index 14864ba..c860333 100644 --- a/src/main/popnhook1/config-eamuse.c +++ b/src/main/popnhook1/config-eamuse.c @@ -2,7 +2,7 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "popnhook1/config-eamuse.h" diff --git a/src/main/popnhook1/config-gfx.c b/src/main/popnhook1/config-gfx.c index 8bc6b10..c95fc11 100644 --- a/src/main/popnhook1/config-gfx.c +++ b/src/main/popnhook1/config-gfx.c @@ -2,7 +2,7 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "popnhook1/config-gfx.h" diff --git a/src/main/popnhook1/config-sec.c b/src/main/popnhook1/config-sec.c index 99342b2..61749b3 100644 --- a/src/main/popnhook1/config-sec.c +++ b/src/main/popnhook1/config-sec.c @@ -3,7 +3,7 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "popnhook1/config-sec.h" diff --git a/src/main/popnhook1/d3d9.c b/src/main/popnhook1/d3d9.c index 44f9e1c..c6830ba 100644 --- a/src/main/popnhook1/d3d9.c +++ b/src/main/popnhook1/d3d9.c @@ -5,12 +5,12 @@ #include -#include "core/log.h" - #include "hook/com-proxy.h" #include "hook/pe.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "popnhook1/d3d9.h" #include "util/defs.h" diff --git a/src/main/popnhook1/dllmain.c b/src/main/popnhook1/dllmain.c index 36c232f..dab99ca 100644 --- a/src/main/popnhook1/dllmain.c +++ b/src/main/popnhook1/dllmain.c @@ -5,18 +5,12 @@ #include #include -#include "bemanitools/eamio.h" -#include "bemanitools/popnio.h" - #include "cconfig/cconfig-hook.h" #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-debug.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" #include "core/thread-crt.h" -#include "core/thread.h" #include "ezusb-emu/node-security-plug.h" @@ -25,6 +19,15 @@ #include "hooklib/adapter.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/popn.h" + +#include "module/io-ext.h" +#include "module/io.h" + #include "popnhook1/avs-boot.h" #include "popnhook1/config-eamuse.h" #include "popnhook1/config-gfx.h" @@ -41,7 +44,7 @@ #include "ezusb2-emu/desc.h" #include "ezusb2-emu/device.h" -#include "iidxhook-util/acio.h" +#include "popnhook-util/acio.h" #include "ezusb2-popn-emu/msg.h" @@ -59,6 +62,8 @@ static DWORD STDCALL my_GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo); static DWORD(STDCALL *real_GetStartupInfoA)(LPSTARTUPINFOA lpStartupInfo); static bool popnhook1_init_check; +static module_io_t *popnhook_module_io_popn; +static module_io_t *popnhook_module_io_eam; static const struct hook_symbol init_hook_syms[] = { { @@ -70,12 +75,31 @@ static const struct hook_symbol init_hook_syms[] = { static void _popnhook1_log_init() { - core_log_bt_ext_impl_set(); core_log_bt_ext_init_with_debug(); // TODO change log level support core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); } +static void _popnhook1_io_popn_init(module_io_t **module) +{ + bt_io_popn_api_t api; + + module_io_ext_load_and_init( + "popnio.dll", "bt_module_io_popn_api_get", module); + module_io_api_get(*module, &api); + bt_io_popn_api_set(&api); +} + +static void _popnhook1_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} + static void popnhook_setup_d3d9_hooks( const struct popnhook1_config_gfx *config_gfx, const bool texture_usage_fix) { @@ -159,24 +183,20 @@ static DWORD STDCALL my_GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo) /* Start up POPNIO.DLL */ log_info("Starting pop'n IO backend"); - core_log_impl_assign(popn_io_set_loggers); - if (!popn_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _popnhook1_io_popn_init(&popnhook_module_io_popn); + + if (!bt_io_popn_init()) { log_fatal("Initializing pop'n IO backend failed"); } /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _popnhook1_io_eam_init(&popnhook_module_io_eam); + + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } @@ -208,7 +228,9 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) return TRUE; } - core_thread_crt_ext_impl_set(); + // Use bemanitools core APIs + core_log_bt_core_api_set(); + core_thread_crt_core_api_set(); _popnhook1_log_init(); diff --git a/src/main/popnhook1/filesystem.c b/src/main/popnhook1/filesystem.c index d558486..48cb859 100644 --- a/src/main/popnhook1/filesystem.c +++ b/src/main/popnhook1/filesystem.c @@ -7,10 +7,10 @@ #include #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/popnio/Module.mk b/src/main/popnio/Module.mk index 3894413..83664d3 100644 --- a/src/main/popnio/Module.mk +++ b/src/main/popnio/Module.mk @@ -4,7 +4,11 @@ ldflags_popnio := \ -lwinmm libs_popnio := \ - geninput \ + iface \ + module \ + iface-io \ + iface-core \ + util \ src_popnio := \ popnio.c \ diff --git a/src/main/popnio/popnio.c b/src/main/popnio/popnio.c index d5389cd..c083797 100644 --- a/src/main/popnio/popnio.c +++ b/src/main/popnio/popnio.c @@ -1,76 +1,136 @@ +#define LOG_MODULE "popnio" + +// clang-format off +// Don't format because the order is important here +#include +#include +// clang-format on + #include #include #include -#include "bemanitools/input.h" -#include "bemanitools/popnio.h" +#include "api/core/log.h" +#include "api/core/thread.h" -void popn_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface/input.h" + +#include "main/module/input-ext.h" +#include "main/module/input.h" +#include "main/module/io-ext.h" +#include "main/module/io.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/input.h" +#include "sdk/module/io/popn.h" + +static module_input_t *_popn_io_module_input; + +static void _bt_io_popn_module_input_init(module_input_t **module) { - input_set_loggers(misc, info, warning, fatal); + bt_input_api_t api; + + module_input_ext_load_and_init("geninput.dll", module); + module_input_api_get(*module, &api); + bt_input_api_set(&api); } -bool popn_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_popn_init() { - input_init(thread_create, thread_join, thread_destroy); - mapper_config_load("pnm"); + bool result; - return true; + _bt_io_popn_module_input_init(&_popn_io_module_input); + + timeBeginPeriod(1); + + result = bt_input_init(); + + if (!result) { + log_warning("Initializing input failed"); + return false; + } + + return bt_input_mapper_config_load("pnm"); } -void popn_io_fini(void) +void bt_io_popn_fini(void) { - input_fini(); + bt_input_fini(); + bt_input_api_clear(); + module_input_free(&_popn_io_module_input); + + timeEndPeriod(1); } -uint32_t popn_io_get_buttons(void) +uint32_t bt_io_popn_buttons_get(void) { - return (uint32_t) mapper_update(); + return (uint32_t) bt_input_mapper_update(); } -void popn_io_set_top_lights(uint32_t lights) +void bt_io_popn_top_lights_set(uint32_t lights) { uint8_t i; for (i = 0; i < 5; i++) { - mapper_write_light(0x20 + i, lights & (1 << i) ? 255 : 0); + bt_input_mapper_light_write(0x20 + i, lights & (1 << i) ? 255 : 0); } } -void popn_io_set_side_lights(uint32_t lights) +void bt_io_popn_side_lights_set(uint32_t lights) { uint8_t i; for (i = 0; i < 4; i++) { - mapper_write_light(0x25 + i, lights & (1 << i) ? 255 : 0); + bt_input_mapper_light_write(0x25 + i, lights & (1 << i) ? 255 : 0); } } -void popn_io_set_button_lights(uint32_t lights) +void bt_io_popn_button_lights_set(uint32_t lights) { uint8_t i; // Special case for POPN_LIGHT_SW_LAMP1 which is 4 bits wide - mapper_write_light(0x17, lights & 0xf ? 255 : 0); + bt_input_mapper_light_write(0x17, lights & 0xf ? 255 : 0); for (i = 0; i < 8; i++) { - mapper_write_light(0x18 + i, lights & (1 << (i + 4)) ? 255 : 0); + bt_input_mapper_light_write( + 0x18 + i, lights & (1 << (i + 4)) ? 255 : 0); } } -void popn_io_set_coin_blocker_light(bool enabled) +void bt_io_popn_coin_blocker_light_set(bool enabled) { - // mapper_write_light(x, enabled ? 255 : 0); + // bt_input_mapper_light_write(x, enabled ? 255 : 0); } -void popn_io_set_coin_counter_light(bool enabled) +void bt_io_popn_coin_counter_light_set(bool enabled) { - // mapper_write_light(x, enabled ? 255 : 0); + // bt_input_mapper_light_write(x, enabled ? 255 : 0); } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_io_popn_api_get(bt_io_popn_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_popn_init; + api->v1.fini = bt_io_popn_fini; + api->v1.buttons_get = bt_io_popn_buttons_get; + api->v1.top_lights_set = bt_io_popn_top_lights_set; + api->v1.side_lights_set = bt_io_popn_side_lights_set; + api->v1.button_lights_set = bt_io_popn_button_lights_set; + api->v1.coin_blocker_light_set = bt_io_popn_coin_blocker_light_set; + api->v1.coin_counter_light_set = bt_io_popn_coin_counter_light_set; +} \ No newline at end of file diff --git a/src/main/popnio/popnio.def b/src/main/popnio/popnio.def index f35a595..4302ac2 100644 --- a/src/main/popnio/popnio.def +++ b/src/main/popnio/popnio.def @@ -1,12 +1,17 @@ LIBRARY popnio EXPORTS - popn_io_get_buttons - popn_io_set_top_lights - popn_io_set_side_lights - popn_io_set_button_lights - popn_io_set_coin_blocker_light - popn_io_set_coin_counter_light - popn_io_fini - popn_io_init - popn_io_set_loggers + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_io_popn_api_get + + ; Direct API + bt_io_popn_init + bt_io_popn_fini + bt_io_popn_buttons_get + bt_io_popn_top_lights_set + bt_io_popn_side_lights_set + bt_io_popn_button_lights_set + bt_io_popn_coin_blocker_light_set + bt_io_popn_coin_counter_light_set diff --git a/src/main/procmon-lib/Module.mk b/src/main/procmon-lib/Module.mk deleted file mode 100644 index 994dd69..0000000 --- a/src/main/procmon-lib/Module.mk +++ /dev/null @@ -1,8 +0,0 @@ -libs += procmon-lib - -libs_procmon-lib := \ - util \ - -src_procmon-lib := \ - procmon.c \ - diff --git a/src/main/procmon-lib/procmon.c b/src/main/procmon-lib/procmon.c deleted file mode 100644 index 787aa2e..0000000 --- a/src/main/procmon-lib/procmon.c +++ /dev/null @@ -1,96 +0,0 @@ -#define LOG_MODULE "procmon-lib" - -#include - -#include "core/log.h" - -#include "procmon-lib/procmon.h" - -#define PROCMON_LIB "procmon.dll" -#define CONCAT(x, y) x##y -#define LOAD_FUNC(lib_func, module, path, func_name) \ - lib_func = (CONCAT(func_name, _t)) GetProcAddress(module, #func_name); \ - if (lib_func == NULL) { \ - log_fatal("Failed to load function '%s' from '%s'", #func_name, path); \ - } - -bool procmon_available() -{ - HMODULE module; - - module = LoadLibraryExA(PROCMON_LIB, NULL, DONT_RESOLVE_DLL_REFERENCES); - - if (module == NULL) { - return false; - } else { - FreeLibrary(module); - return true; - } -} - -void procmon_init(struct procmon *procmon) -{ - log_assert(procmon); - - memset(procmon, 0, sizeof(*procmon)); -} - -void procmon_load(struct procmon *procmon) -{ - HMODULE module; - uint32_t api_version; - - log_assert(procmon); - - module = LoadLibraryA(PROCMON_LIB); - - if (module == NULL) { - LPSTR buffer; - - FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR) &buffer, - 0, - NULL); - - log_fatal("Failed to load library %s: %s", PROCMON_LIB, buffer); - - LocalFree(buffer); - } - - procmon->module = module; - - LOAD_FUNC(procmon->api_version, module, PROCMON_LIB, procmon_api_version); - - api_version = procmon->api_version(); - - if (api_version != 0) { - log_fatal("Unsupported API version %d of %s", api_version, PROCMON_LIB); - } - - LOAD_FUNC(procmon->set_loggers, module, PROCMON_LIB, procmon_set_loggers); - LOAD_FUNC(procmon->init, module, PROCMON_LIB, procmon_init); - LOAD_FUNC( - procmon->file_mon_enable, module, PROCMON_LIB, procmon_file_mon_enable); - LOAD_FUNC( - procmon->module_mon_enable, - module, - PROCMON_LIB, - procmon_module_mon_enable); - LOAD_FUNC( - procmon->thread_mon_enable, - module, - PROCMON_LIB, - procmon_thread_mon_enable); -} - -void procmon_free(struct procmon *procmon) -{ - log_assert(procmon); - - FreeLibrary(procmon->module); -} \ No newline at end of file diff --git a/src/main/procmon-lib/procmon.h b/src/main/procmon-lib/procmon.h deleted file mode 100644 index 135a4b8..0000000 --- a/src/main/procmon-lib/procmon.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef PROCMON_LIB_PROCMON_H -#define PROCMON_LIB_PROCMON_H - -#include - -#include -#include - -#include "core/log.h" - -typedef uint32_t (*procmon_api_version_t)(); -typedef void (*procmon_set_loggers_t)( - core_log_message_t misc, - core_log_message_t info, - core_log_message_t warning, - core_log_message_t fatal); -typedef void (*procmon_file_mon_enable_t)(); -typedef void (*procmon_module_mon_enable_t)(); -typedef void (*procmon_thread_mon_enable_t)(); -typedef void (*procmon_init_t)(); - -struct procmon { - HMODULE module; - procmon_api_version_t api_version; - procmon_set_loggers_t set_loggers; - procmon_file_mon_enable_t file_mon_enable; - procmon_module_mon_enable_t module_mon_enable; - procmon_thread_mon_enable_t thread_mon_enable; - procmon_init_t init; -}; - -void procmon_init(struct procmon *procmon); -bool procmon_available(); -void procmon_load(struct procmon *procmon); -void procmon_free(struct procmon *procmon); - -#endif \ No newline at end of file diff --git a/src/main/procmon/Module.mk b/src/main/procmon/Module.mk index f1e355d..1e1d8b2 100644 --- a/src/main/procmon/Module.mk +++ b/src/main/procmon/Module.mk @@ -4,8 +4,12 @@ libs_procmon := \ core \ hook \ util \ + iface-core \ src_procmon := \ + bt-hook.c \ + config.c \ + dllmain.c \ file.c \ module.c \ procmon.c \ diff --git a/src/main/procmon/bt-hook.c b/src/main/procmon/bt-hook.c new file mode 100644 index 0000000..3dd4414 --- /dev/null +++ b/src/main/procmon/bt-hook.c @@ -0,0 +1,50 @@ +#define LOG_MODULE "procmon-hook" + +#include + +#include +#include + +#include "iface-core/config.h" +#include "iface-core/log.h" + +#include "sdk/module/core/config.h" +#include "sdk/module/core/log.h" +#include "sdk/module/hook.h" + +#include "procmon/config.h" +#include "procmon/procmon.h" + +bool bt_hook_main_init(HMODULE game_module, const bt_core_config_t *config) +{ + procmon_config_t procmon_config; + + procmon_config_load(config, &procmon_config); + + procmon_init(&procmon_config); + + return true; +} + +void bt_hook_main_fini() +{ + procmon_fini(); +} + +void bt_module_core_config_api_set(const bt_core_config_api_t *api) +{ + bt_core_config_api_set(api); +} + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_hook_api_get(bt_hook_api_t *api) +{ + api->version = 1; + + api->v1.main_init = bt_hook_main_init; + api->v1.main_fini = bt_hook_main_fini; +} \ No newline at end of file diff --git a/src/main/procmon/config.c b/src/main/procmon/config.c new file mode 100644 index 0000000..51cd8bf --- /dev/null +++ b/src/main/procmon/config.c @@ -0,0 +1,39 @@ +#define LOG_MODULE "procmon-config" + +#include "iface-core/config.h" +#include "iface-core/log.h" + +#include "procmon/config.h" + +static void _procmon_config_init_default(procmon_config_t *config) +{ + config->file_enable = false; + config->module_enable = false; + config->thread_enable = false; +} + +void procmon_config_load( + const bt_core_config_t *config, procmon_config_t *procmon_config) +{ + uint32_t version; + + log_assert(config); + log_assert(procmon_config); + + _procmon_config_init_default(procmon_config); + + version = 0; + + bt_core_config_u32_get(config, "/version", &version); + + if (version != 1) { + log_fatal("Unsupported configuration version: %d", version); + } + + bt_core_config_bool_get( + config, "/file/enable", &procmon_config->file_enable); + bt_core_config_bool_get( + config, "/module/enable", &procmon_config->module_enable); + bt_core_config_bool_get( + config, "/thread/enable", &procmon_config->thread_enable); +} \ No newline at end of file diff --git a/src/main/procmon/config.h b/src/main/procmon/config.h new file mode 100644 index 0000000..3a6bab8 --- /dev/null +++ b/src/main/procmon/config.h @@ -0,0 +1,17 @@ +#ifndef PROCMON_CONFIG_H +#define PROCMON_CONFIG_H + +#include + +#include "api/core/config.h" + +typedef struct procmon_config { + bool file_enable; + bool module_enable; + bool thread_enable; +} procmon_config_t; + +void procmon_config_load( + const bt_core_config_t *config, procmon_config_t *procmon_config); + +#endif \ No newline at end of file diff --git a/src/main/procmon/dllmain.c b/src/main/procmon/dllmain.c new file mode 100644 index 0000000..71f1a58 --- /dev/null +++ b/src/main/procmon/dllmain.c @@ -0,0 +1,6 @@ +#include + +BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) +{ + return TRUE; +} diff --git a/src/main/procmon/file.c b/src/main/procmon/file.c index 229455d..ac86451 100644 --- a/src/main/procmon/file.c +++ b/src/main/procmon/file.c @@ -2,10 +2,10 @@ #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "util/str.h" static HANDLE(STDCALL *real_CreateFileW)( diff --git a/src/main/procmon/module.c b/src/main/procmon/module.c index 3a130ac..0d36b39 100644 --- a/src/main/procmon/module.c +++ b/src/main/procmon/module.c @@ -2,10 +2,10 @@ #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #include "util/str.h" static HMODULE(STDCALL *real_GetModuleHandleA)(LPCSTR lpModuleName); diff --git a/src/main/procmon/procmon.c b/src/main/procmon/procmon.c index 6120ae9..cbbf900 100644 --- a/src/main/procmon/procmon.c +++ b/src/main/procmon/procmon.c @@ -1,73 +1,46 @@ -#define LOG_MODULE "procmon" - -#include -#include - -#include "core/log.h" +#include "iface-core/log.h" #include "procmon/file.h" #include "procmon/module.h" #include "procmon/procmon.h" #include "procmon/thread.h" -static bool _procmon_file_mon_enabled; -static bool _procmon_module_mon_enabled; -static bool _procmon_thread_mon_enabled; +static bool _procmon_file_monitor_enabled; +static bool _procmon_module_monitor_enabled; +static bool _procmon_thread_monitor_enabled; -uint32_t procmon_api_version() +void procmon_init(const procmon_config_t *config) { - return 0; -} + log_assert(config); -void procmon_set_loggers( - core_log_message_t misc, - core_log_message_t info, - core_log_message_t warning, - core_log_message_t fatal) -{ - core_log_impl_set(misc, info, warning, fatal); -} + _procmon_file_monitor_enabled = config->file_enable; + _procmon_module_monitor_enabled = config->module_enable; + _procmon_thread_monitor_enabled = config->thread_enable; -void procmon_init() -{ - _procmon_file_mon_enabled = false; - _procmon_module_mon_enabled = false; - _procmon_thread_mon_enabled = false; + if (_procmon_file_monitor_enabled) { + procmon_file_init(); + } - log_info("init"); -} + if (_procmon_module_monitor_enabled) { + procmon_module_init(); + } -void procmon_file_mon_enable() -{ - procmon_file_init(); - _procmon_file_mon_enabled = true; -} - -void procmon_module_mon_enable() -{ - procmon_module_init(); - _procmon_module_mon_enabled = true; -} - -void procmon_thread_mon_enable() -{ - procmon_thread_init(); - _procmon_thread_mon_enabled = true; + if (_procmon_thread_monitor_enabled) { + procmon_thread_init(); + } } void procmon_fini() { - if (_procmon_file_mon_enabled) { - procmon_file_fini(); - } - - if (_procmon_module_mon_enabled) { - procmon_module_fini(); - } - - if (_procmon_thread_mon_enabled) { + if (_procmon_thread_monitor_enabled) { procmon_thread_fini(); } - log_info("fini"); + if (_procmon_module_monitor_enabled) { + procmon_module_fini(); + } + + if (_procmon_file_monitor_enabled) { + procmon_file_fini(); + } } \ No newline at end of file diff --git a/src/main/procmon/procmon.def b/src/main/procmon/procmon.def index 1dfb0d3..5e78a59 100644 --- a/src/main/procmon/procmon.def +++ b/src/main/procmon/procmon.def @@ -1,10 +1,13 @@ LIBRARY procmon EXPORTS - procmon_api_version - procmon_set_loggers - procmon_init - procmon_file_mon_enable - procmon_module_mon_enable - procmon_thread_mon_enable - procmon_fini + ; Bemanitools 6 API + bt_module_core_config_api_set + bt_module_core_log_api_set + bt_module_hook_api_get + + DllMain@12 @1 NONAME + + ; Direct API + bt_hook_main_init + bt_hook_main_fini diff --git a/src/main/procmon/procmon.h b/src/main/procmon/procmon.h index 0d485fb..8f6df21 100644 --- a/src/main/procmon/procmon.h +++ b/src/main/procmon/procmon.h @@ -1,21 +1,10 @@ #ifndef PROCMON_PROCMON_H #define PROCMON_PROCMON_H -#include -#include +#include "procmon/config.h" -#include "core/log.h" +void procmon_init(const procmon_config_t *config); -uint32_t procmon_api_version(); -void procmon_set_loggers( - core_log_message_t misc, - core_log_message_t info, - core_log_message_t warning, - core_log_message_t fatal); -void procmon_init(); -void procmon_file_mon_enable(); -void procmon_module_mon_enable(); -void procmon_thread_mon_enable(); void procmon_fini(); #endif \ No newline at end of file diff --git a/src/main/procmon/thread.c b/src/main/procmon/thread.c index 790925f..27888df 100644 --- a/src/main/procmon/thread.c +++ b/src/main/procmon/thread.c @@ -2,10 +2,10 @@ #include -#include "core/log.h" - #include "hook/table.h" +#include "iface-core/log.h" + #ifdef _WIN64 #define SIZE_T_FORMAT_SPECIFIER "llu" #else diff --git a/src/main/sdvxhook/Module.mk b/src/main/sdvxhook/Module.mk index cc6d31c..926c42f 100644 --- a/src/main/sdvxhook/Module.mk +++ b/src/main/sdvxhook/Module.mk @@ -3,15 +3,19 @@ avsdlls += sdvxhook deplibs_sdvxhook := \ avs \ +avslibs_sdvxhook := \ + avs-ext \ + libs_sdvxhook := \ - avs-util \ core \ acioemu \ hook \ hooklib \ util \ - eamio \ - sdvxio \ + iface \ + iface-io \ + iface-core \ + module \ src_sdvxhook := \ acio.c \ diff --git a/src/main/sdvxhook/acio.c b/src/main/sdvxhook/acio.c index e8d7dfd..02d23e6 100644 --- a/src/main/sdvxhook/acio.c +++ b/src/main/sdvxhook/acio.c @@ -15,10 +15,10 @@ #include "acioemu/emu.h" #include "acioemu/icca.h" -#include "core/log.h" - #include "hook/iohook.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "sdvxhook/acio.h" diff --git a/src/main/sdvxhook/dllmain.c b/src/main/sdvxhook/dllmain.c index 50e2063..9e3508f 100644 --- a/src/main/sdvxhook/dllmain.c +++ b/src/main/sdvxhook/dllmain.c @@ -3,19 +3,23 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/eamio.h" -#include "bemanitools/sdvxio.h" - -#include "core/log.h" -#include "core/thread.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "hook/iohook.h" #include "hooklib/app.h" #include "hooklib/rs232.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/sdvx.h" + +#include "module/io-ext.h" +#include "module/io.h" + #include "sdvxhook/acio.h" #include "sdvxhook/gfx.h" #include "sdvxhook/lcd.h" @@ -26,6 +30,29 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config); static bool my_dll_entry_main(void); +static module_io_t *_sdvxhook_module_io_sdvx; +static module_io_t *_sdvxhook_module_io_eam; + +static void _sdvxhook_io_sdvx_init(module_io_t **module) +{ + bt_io_sdvx_api_t api; + + module_io_ext_load_and_init( + "sdvxio.dll", "bt_module_io_sdvx_api_get", module); + module_io_api_get(*module, &api); + bt_io_sdvx_api_set(&api); +} + +static void _sdvxhook_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} + static bool my_dll_entry_init(char *sidcode, struct property_node *config) { bool ok; @@ -36,12 +63,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config) log_info("Starting up SDVX IO backend"); - core_log_impl_assign(sdvx_io_set_loggers); + _sdvxhook_io_sdvx_init(&_sdvxhook_module_io_sdvx); - ok = sdvx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + ok = bt_io_sdvx_init(); if (!ok) { goto sdvx_io_fail; @@ -49,12 +73,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config) log_info("Starting up card reader backend"); - core_log_impl_assign(eam_io_set_loggers); + _sdvxhook_io_eam_init(&_sdvxhook_module_io_eam); - ok = eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get()); + ok = bt_io_eam_init(); /* Set up IO emulation hooks _after_ IO API setup to allow API implementations with real IO devices */ @@ -73,7 +94,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config) return app_hook_invoke_init(sidcode, config); eam_io_fail: - sdvx_io_fini(); + bt_io_sdvx_fini(); + + bt_io_sdvx_api_clear(); + module_io_free(&_sdvxhook_module_io_sdvx); sdvx_io_fail: ac_io_bus_fini(); @@ -88,10 +112,16 @@ static bool my_dll_entry_main(void) result = app_hook_invoke_main(); log_info("Shutting down card reader backend"); - eam_io_fini(); + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&_sdvxhook_module_io_eam); log_info("Shutting down SDVX IO backend"); - sdvx_io_fini(); + bt_io_sdvx_fini(); + + bt_io_sdvx_api_clear(); + module_io_free(&_sdvxhook_module_io_sdvx); ac_io_bus_fini(); @@ -109,8 +139,8 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) } // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); args_recover(&argc, &argv); diff --git a/src/main/sdvxhook/gfx.c b/src/main/sdvxhook/gfx.c index 2d36759..e7090ed 100644 --- a/src/main/sdvxhook/gfx.c +++ b/src/main/sdvxhook/gfx.c @@ -3,12 +3,12 @@ #include -#include "core/log.h" - #include "hook/com-proxy.h" #include "hook/pe.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "sdvxhook/gfx.h" #include "util/defs.h" diff --git a/src/main/sdvxhook/kfca.c b/src/main/sdvxhook/kfca.c index 82ac111..3980cb6 100644 --- a/src/main/sdvxhook/kfca.c +++ b/src/main/sdvxhook/kfca.c @@ -7,9 +7,8 @@ #include "acioemu/emu.h" -#include "bemanitools/sdvxio.h" - -#include "core/log.h" +#include "iface-core/log.h" +#include "iface-io/sdvx.h" #include "util/defs.h" #include "util/time.h" @@ -123,7 +122,7 @@ static void kfca_amp_control(const struct ac_io_message *req) // bytes 0-4: main, headphone, unused, subwoofer - if (!sdvx_io_set_amp_volume( + if (!bt_io_sdvx_amp_volume_set( req->cmd.raw[0], req->cmd.raw[1], req->cmd.raw[3])) { log_warning("Unable to set amp volume?"); } @@ -143,13 +142,13 @@ static void kfca_poll(const struct ac_io_message *req) pout = &req->cmd.kfca_poll_out; - sdvx_io_set_gpio_lights(ac_io_u32(pout->gpio)); + bt_io_sdvx_gpio_lights_set(ac_io_u32(pout->gpio)); for (i = 0; i < lengthof(pout->pwm); i++) { - sdvx_io_set_pwm_light(i, pout->pwm[i]); + bt_io_sdvx_pwm_light_set(i, pout->pwm[i]); } - sdvx_io_write_output(); + bt_io_sdvx_output_write(); /* SDVX expects only one poll response per frame. @@ -188,17 +187,17 @@ static void kfca_poll_thunk(void *ctx_ptr, struct ac_io_message *resp) resp->cmd.seq_no = req_seq_no; resp->cmd.nbytes = sizeof(*pin); - sdvx_io_read_input(); + bt_io_sdvx_input_read(); memset(pin, 0, sizeof(*pin)); - pin->adc[0] = sdvx_io_get_spinner_pos(0) << 6; - pin->adc[1] = sdvx_io_get_spinner_pos(1) << 6; + pin->adc[0] = bt_io_sdvx_spinner_pos_get(0) << 6; + pin->adc[1] = bt_io_sdvx_spinner_pos_get(1) << 6; - pin->gpio_sys |= sdvx_io_get_input_gpio_sys() & 0x3F; + pin->gpio_sys |= bt_io_sdvx_input_gpio_sys_get() & 0x3F; pin->adc[0] = ac_io_u16(pin->adc[0]); pin->adc[1] = ac_io_u16(pin->adc[1]); - pin->gpio[0] = ac_io_u16(sdvx_io_get_input_gpio(0)); - pin->gpio[1] = ac_io_u16(sdvx_io_get_input_gpio(1)); + pin->gpio[0] = ac_io_u16(bt_io_sdvx_input_gpio_get(0)); + pin->gpio[1] = ac_io_u16(bt_io_sdvx_input_gpio_get(1)); } diff --git a/src/main/sdvxhook/lcd.c b/src/main/sdvxhook/lcd.c index 6d942bb..b279e4f 100644 --- a/src/main/sdvxhook/lcd.c +++ b/src/main/sdvxhook/lcd.c @@ -12,10 +12,10 @@ #include #include -#include "core/log.h" - #include "hook/iohook.h" +#include "iface-core/log.h" + #include "sdvxhook/lcd.h" #include "util/hex.h" diff --git a/src/main/sdvxhook2-cn/Module.mk b/src/main/sdvxhook2-cn/Module.mk index 2bb715e..0ca1e30 100644 --- a/src/main/sdvxhook2-cn/Module.mk +++ b/src/main/sdvxhook2-cn/Module.mk @@ -11,17 +11,22 @@ ldflags_sdvxhook2-cn := \ deplibs_sdvxhook2-cn := \ avs \ +avslibs_sdvxhook2-cn:= \ + avs-ext \ + libs_sdvxhook2-cn := \ - avs-util \ core \ acioemu \ camhook \ d3d9exhook \ - sdvxio \ hook \ hooklib \ cconfig \ util \ + iface \ + iface-io \ + iface-core \ + module \ src_sdvxhook2-cn := \ acio.c \ diff --git a/src/main/sdvxhook2-cn/acio.c b/src/main/sdvxhook2-cn/acio.c index 4507333..2d45a97 100644 --- a/src/main/sdvxhook2-cn/acio.c +++ b/src/main/sdvxhook2-cn/acio.c @@ -14,11 +14,11 @@ #include "acioemu/addr.h" #include "acioemu/emu.h" -#include "core/log.h" - #include "hook/iohook.h" #include "hooklib/rs232.h" +#include "iface-core/log.h" + #include "sdvxhook2-cn/acio.h" #include "sdvxhook2-cn/kfca.h" diff --git a/src/main/sdvxhook2-cn/config-cn.c b/src/main/sdvxhook2-cn/config-cn.c index 650b528..f1233a5 100644 --- a/src/main/sdvxhook2-cn/config-cn.c +++ b/src/main/sdvxhook2-cn/config-cn.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "sdvxhook2-cn/config-cn.h" diff --git a/src/main/sdvxhook2-cn/dllmain.c b/src/main/sdvxhook2-cn/dllmain.c index ffcb36a..17970b9 100644 --- a/src/main/sdvxhook2-cn/dllmain.c +++ b/src/main/sdvxhook2-cn/dllmain.c @@ -5,21 +5,24 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/eamio.h" -#include "bemanitools/sdvxio.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "cconfig/cconfig-hook.h" -#include "core/log.h" -#include "core/thread.h" - #include "hooklib/acp.h" #include "hooklib/adapter.h" #include "hooklib/app.h" #include "hooklib/rs232.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/sdvx.h" + +#include "module/io-ext.h" +#include "module/io.h" + #include "sdvxhook2-cn/acio.h" #include "sdvxhook2-cn/config-cn.h" #include "sdvxhook2-cn/unis-version.h" @@ -44,6 +47,18 @@ struct sdvxhook2_cn_config config_cn; struct camhook_config_cam config_cam; struct d3d9exhook_config_gfx config_gfx; +static module_io_t *_sdvxhook2_cn_module_io_sdvx; + +static void _sdvxhook2_cn_io_sdvx_init(module_io_t **module) +{ + bt_io_sdvx_api_t api; + + module_io_ext_load_and_init( + "sdvxio.dll", "bt_module_io_sdvx_api_get", module); + module_io_api_get(*module, &api); + bt_io_sdvx_api_set(&api); +} + static bool my_dll_entry_init(char *sidcode, struct property_node *param) { struct cconfig *config; @@ -78,12 +93,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up sdvxio.DLL */ if (!config_cn.disable_io_emu) { log_info("Starting sdvx IO backend"); - core_log_impl_assign(sdvx_io_set_loggers); - if (!sdvx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _sdvxhook2_cn_io_sdvx_init(&_sdvxhook2_cn_module_io_sdvx); + + if (!bt_io_sdvx_init()) { log_fatal("Initializing sdvx IO backend failed"); } } @@ -123,7 +136,11 @@ static bool my_dll_entry_main(void) if (!config_cn.disable_io_emu) { log_misc("Shutting down sdvx IO backend"); - sdvx_io_fini(); + + bt_io_sdvx_fini(); + + bt_io_sdvx_api_clear(); + module_io_free(&_sdvxhook2_cn_module_io_sdvx); } return result; @@ -139,8 +156,8 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) } // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); app_hook_init(my_dll_entry_init, my_dll_entry_main); diff --git a/src/main/sdvxhook2-cn/kfca.c b/src/main/sdvxhook2-cn/kfca.c index 02c7297..b14476d 100644 --- a/src/main/sdvxhook2-cn/kfca.c +++ b/src/main/sdvxhook2-cn/kfca.c @@ -7,9 +7,8 @@ #include "acioemu/emu.h" -#include "bemanitools/sdvxio.h" - -#include "core/log.h" +#include "iface-core/log.h" +#include "iface-io/sdvx.h" #include "util/defs.h" #include "util/time.h" @@ -136,13 +135,13 @@ static void kfca_poll(const struct ac_io_message *req) pout = &req->cmd.kfca_poll_out; - sdvx_io_set_gpio_lights(ac_io_u32(pout->gpio)); + bt_io_sdvx_gpio_lights_set(ac_io_u32(pout->gpio)); for (i = 0; i < lengthof(pout->pwm); i++) { - sdvx_io_set_pwm_light(i, pout->pwm[i]); + bt_io_sdvx_pwm_light_set(i, pout->pwm[i]); } - sdvx_io_write_output(); + bt_io_sdvx_output_write(); /* SDVX expects only one poll response per frame. @@ -181,17 +180,17 @@ static void kfca_poll_thunk(void *ctx_ptr, struct ac_io_message *resp) resp->cmd.seq_no = req_seq_no; resp->cmd.nbytes = sizeof(*pin); - sdvx_io_read_input(); + bt_io_sdvx_input_read(); memset(pin, 0, sizeof(*pin)); - pin->adc[0] = sdvx_io_get_spinner_pos(0) << 6; - pin->adc[1] = sdvx_io_get_spinner_pos(1) << 6; + pin->adc[0] = bt_io_sdvx_spinner_pos_get(0) << 6; + pin->adc[1] = bt_io_sdvx_spinner_pos_get(1) << 6; - pin->gpio_sys |= sdvx_io_get_input_gpio_sys() & 0x3F; + pin->gpio_sys |= bt_io_sdvx_input_gpio_sys_get() & 0x3F; pin->adc[0] = ac_io_u16(pin->adc[0]); pin->adc[1] = ac_io_u16(pin->adc[1]); - pin->gpio[0] = ac_io_u16(sdvx_io_get_input_gpio(0)); - pin->gpio[1] = ac_io_u16(sdvx_io_get_input_gpio(1)); + pin->gpio[0] = ac_io_u16(bt_io_sdvx_input_gpio_get(0)); + pin->gpio[1] = ac_io_u16(bt_io_sdvx_input_gpio_get(1)); } diff --git a/src/main/sdvxhook2-cn/unis-version.c b/src/main/sdvxhook2-cn/unis-version.c index 3ed7e38..f88d618 100644 --- a/src/main/sdvxhook2-cn/unis-version.c +++ b/src/main/sdvxhook2-cn/unis-version.c @@ -8,11 +8,11 @@ #include -#include "core/log.h" - #include "hook/com-proxy.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "util/defs.h" #include "util/str.h" #include "util/time.h" diff --git a/src/main/sdvxhook2/Module.mk b/src/main/sdvxhook2/Module.mk index f813557..3f4e1bb 100644 --- a/src/main/sdvxhook2/Module.mk +++ b/src/main/sdvxhook2/Module.mk @@ -11,19 +11,23 @@ ldflags_sdvxhook2 := \ deplibs_sdvxhook2 := \ avs \ +avslibs_sdvxhook2 := \ + avs-ext \ + libs_sdvxhook2 := \ - avs-util \ core \ acioemu \ bio2emu \ camhook \ d3d9exhook \ - sdvxio \ hook \ hooklib \ cconfig \ util \ - eamio \ + iface \ + iface-io \ + iface-core \ + module \ src_sdvxhook2 := \ acio.c \ diff --git a/src/main/sdvxhook2/acio.c b/src/main/sdvxhook2/acio.c index 8db25df..564b17b 100644 --- a/src/main/sdvxhook2/acio.c +++ b/src/main/sdvxhook2/acio.c @@ -15,11 +15,11 @@ #include "acioemu/emu.h" #include "acioemu/icca.h" -#include "core/log.h" - #include "hook/iohook.h" #include "hooklib/rs232.h" +#include "iface-core/log.h" + #include "sdvxhook2/acio.h" #include "imports/avs.h" diff --git a/src/main/sdvxhook2/bi2a.c b/src/main/sdvxhook2/bi2a.c index f71230c..ac4f025 100644 --- a/src/main/sdvxhook2/bi2a.c +++ b/src/main/sdvxhook2/bi2a.c @@ -10,7 +10,7 @@ #include "bio2emu/emu.h" #include "sdvxhook2/bi2a.h" -#include "bemanitools/sdvxio.h" +#include "iface-io/sdvx.h" static void bio2_emu_bi2a_cmd_send_version( struct ac_io_emu *emu, const struct ac_io_message *req); @@ -209,44 +209,44 @@ bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req) gpio |= assign_light(0x01, pout->gpio[5]); gpio |= assign_light(0x02, pout->gpio[6]); - sdvx_io_set_gpio_lights(gpio); + bt_io_sdvx_gpio_lights_set(gpio); - sdvx_io_set_pwm_light(0x0, pout->wingUpper[0]); - sdvx_io_set_pwm_light(0x1, pout->wingUpper[1]); - sdvx_io_set_pwm_light(0x2, pout->wingUpper[2]); - sdvx_io_set_pwm_light(0x3, pout->wingUpper[0]); - sdvx_io_set_pwm_light(0x4, pout->wingUpper[1]); - sdvx_io_set_pwm_light(0x5, pout->wingUpper[2]); + bt_io_sdvx_pwm_light_set(0x0, pout->wingUpper[0]); + bt_io_sdvx_pwm_light_set(0x1, pout->wingUpper[1]); + bt_io_sdvx_pwm_light_set(0x2, pout->wingUpper[2]); + bt_io_sdvx_pwm_light_set(0x3, pout->wingUpper[0]); + bt_io_sdvx_pwm_light_set(0x4, pout->wingUpper[1]); + bt_io_sdvx_pwm_light_set(0x5, pout->wingUpper[2]); - sdvx_io_set_pwm_light(0x6, pout->wingLower[0]); - sdvx_io_set_pwm_light(0x7, pout->wingLower[1]); - sdvx_io_set_pwm_light(0x8, pout->wingLower[2]); - sdvx_io_set_pwm_light(0x9, pout->wingLower[0]); - sdvx_io_set_pwm_light(0xA, pout->wingLower[1]); - sdvx_io_set_pwm_light(0xB, pout->wingLower[2]); + bt_io_sdvx_pwm_light_set(0x6, pout->wingLower[0]); + bt_io_sdvx_pwm_light_set(0x7, pout->wingLower[1]); + bt_io_sdvx_pwm_light_set(0x8, pout->wingLower[2]); + bt_io_sdvx_pwm_light_set(0x9, pout->wingLower[0]); + bt_io_sdvx_pwm_light_set(0xA, pout->wingLower[1]); + bt_io_sdvx_pwm_light_set(0xB, pout->wingLower[2]); - sdvx_io_set_pwm_light(0xC, pout->woof_r); - sdvx_io_set_pwm_light(0xD, pout->woof_g); - sdvx_io_set_pwm_light(0xE, pout->woof_b); + bt_io_sdvx_pwm_light_set(0xC, pout->woof_r); + bt_io_sdvx_pwm_light_set(0xD, pout->woof_g); + bt_io_sdvx_pwm_light_set(0xE, pout->woof_b); - sdvx_io_set_pwm_light(0xF, pout->controller[0]); - sdvx_io_set_pwm_light(0x10, pout->controller[1]); - sdvx_io_set_pwm_light(0x11, pout->controller[2]); + bt_io_sdvx_pwm_light_set(0xF, pout->controller[0]); + bt_io_sdvx_pwm_light_set(0x10, pout->controller[1]); + bt_io_sdvx_pwm_light_set(0x11, pout->controller[2]); - sdvx_io_write_output(); + bt_io_sdvx_output_write(); - sdvx_io_read_input(); - uint8_t sys = sdvx_io_get_input_gpio_sys(); - uint16_t gpio0 = sdvx_io_get_input_gpio(0); - uint16_t gpio1 = sdvx_io_get_input_gpio(1); + bt_io_sdvx_input_read(); + uint8_t sys = bt_io_sdvx_input_gpio_sys_get(); + uint16_t gpio0 = bt_io_sdvx_input_gpio_get(0); + uint16_t gpio1 = bt_io_sdvx_input_gpio_get(1); // TODO: Make a counter or smth to counteract the accuracy lost in *4 - pin->analogs[0].a_val = sdvx_io_get_spinner_pos(0); - pin->analogs[1].a_val = sdvx_io_get_spinner_pos(1); + pin->analogs[0].a_val = bt_io_sdvx_spinner_pos_get(0); + pin->analogs[1].a_val = bt_io_sdvx_spinner_pos_get(1); - pin->analogs[0].a_test = check_pin(sys, SDVX_IO_IN_GPIO_SYS_TEST); - pin->analogs[0].a_service = check_pin(sys, SDVX_IO_IN_GPIO_SYS_SERVICE); - pin->analogs[0].a_coin = check_pin(sys, SDVX_IO_IN_GPIO_SYS_COIN); + pin->analogs[0].a_test = check_pin(sys, BT_IO_SDVX_IN_GPIO_SYS_TEST); + pin->analogs[0].a_service = check_pin(sys, BT_IO_SDVX_IN_GPIO_SYS_SERVICE); + pin->analogs[0].a_coin = check_pin(sys, BT_IO_SDVX_IN_GPIO_SYS_COIN); if (pin->analogs[0].a_coin) { if (!coin_latch) { @@ -263,17 +263,18 @@ bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req) pin->raw[0] = ac_io_u16(pin->raw[0]); pin->raw[1] = ac_io_u16(pin->raw[1]); - pin->buttons_1.b_start = check_pin(gpio0, SDVX_IO_IN_GPIO_0_START); - pin->buttons_1.b_headphone = check_pin(gpio0, SDVX_IO_IN_GPIO_0_HEADPHONE); + pin->buttons_1.b_start = check_pin(gpio0, BT_IO_SDVX_IN_GPIO_0_START); + pin->buttons_1.b_headphone = + check_pin(gpio0, BT_IO_SDVX_IN_GPIO_0_HEADPHONE); if (force_headphones_on) { pin->buttons_1.b_headphone = 1; } - pin->buttons_1.b_a = check_pin(gpio0, SDVX_IO_IN_GPIO_0_A); - pin->buttons_1.b_b = check_pin(gpio0, SDVX_IO_IN_GPIO_0_B); - pin->buttons_1.b_c = check_pin(gpio0, SDVX_IO_IN_GPIO_0_C); - pin->buttons_1.b_d = check_pin(gpio1, SDVX_IO_IN_GPIO_1_D); - pin->buttons_1.b_fxl = check_pin(gpio1, SDVX_IO_IN_GPIO_1_FX_L); - pin->buttons_2.b_fxr = check_pin(gpio1, SDVX_IO_IN_GPIO_1_FX_R); + pin->buttons_1.b_a = check_pin(gpio0, BT_IO_SDVX_IN_GPIO_0_A); + pin->buttons_1.b_b = check_pin(gpio0, BT_IO_SDVX_IN_GPIO_0_B); + pin->buttons_1.b_c = check_pin(gpio0, BT_IO_SDVX_IN_GPIO_0_C); + pin->buttons_1.b_d = check_pin(gpio1, BT_IO_SDVX_IN_GPIO_1_D); + pin->buttons_1.b_fxl = check_pin(gpio1, BT_IO_SDVX_IN_GPIO_1_FX_L); + pin->buttons_2.b_fxr = check_pin(gpio1, BT_IO_SDVX_IN_GPIO_1_FX_R); ac_io_emu_response_push(emu, &resp, 0); } diff --git a/src/main/sdvxhook2/config-io.c b/src/main/sdvxhook2/config-io.c index 421f3af..ee91cdf 100644 --- a/src/main/sdvxhook2/config-io.c +++ b/src/main/sdvxhook2/config-io.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "sdvxhook2/config-io.h" diff --git a/src/main/sdvxhook2/dllmain.c b/src/main/sdvxhook2/dllmain.c index bcf29ac..f486413 100644 --- a/src/main/sdvxhook2/dllmain.c +++ b/src/main/sdvxhook2/dllmain.c @@ -5,16 +5,11 @@ #include #include -#include "avs-util/core-interop.h" - -#include "bemanitools/eamio.h" -#include "bemanitools/sdvxio.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "cconfig/cconfig-hook.h" -#include "core/log.h" -#include "core/thread.h" - #include "hooklib/acp.h" #include "hooklib/adapter.h" #include "hooklib/app.h" @@ -22,6 +17,15 @@ #include "hooklib/memfile.h" #include "hooklib/rs232.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/sdvx.h" + +#include "module/io-ext.h" +#include "module/io.h" + #include "bio2emu/emu.h" #include "sdvxhook2/acio.h" @@ -51,6 +55,9 @@ struct camhook_config_cam config_cam; struct d3d9exhook_config_gfx config_gfx; struct hooklib_config_adapter config_adapter; +static module_io_t *_sdvxhook2_module_io_sdvx; +static module_io_t *_sdvxhook2_module_io_eam; + static struct bio2emu_port bio2_emu = { .port = "COM4", .wport = L"\\\\.\\COM4", @@ -72,6 +79,26 @@ static void attach_dest_fd_intercept(const char *sidcode) memfile_hook_add_fd(target_file, ENDING_MATCH, NULL, 0); } +static void _sdvxhook2_io_sdvx_init(module_io_t **module) +{ + bt_io_sdvx_api_t api; + + module_io_ext_load_and_init( + "sdvxio.dll", "bt_module_io_sdvx_api_get", module); + module_io_api_get(*module, &api); + bt_io_sdvx_api_set(&api); +} + +static void _sdvxhook2_io_eam_init(module_io_t **module) +{ + bt_io_eam_api_t api; + + module_io_ext_load_and_init( + "eamio.dll", "bt_module_io_eam_api_get", module); + module_io_api_get(*module, &api); + bt_io_eam_api_set(&api); +} + static bool my_dll_entry_init(char *sidcode, struct property_node *param) { struct cconfig *config; @@ -108,12 +135,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up sdvxio.DLL */ if (!config_io.disable_bio2_emu) { log_info("Starting sdvx IO backend"); - core_log_impl_assign(sdvx_io_set_loggers); - if (!sdvx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _sdvxhook2_io_sdvx_init(&_sdvxhook2_module_io_sdvx); + + if (!bt_io_sdvx_init()) { log_fatal("Initializing sdvx IO backend failed"); } } @@ -121,12 +146,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up EAMIO.DLL */ if (!config_io.disable_card_reader_emu) { log_misc("Initializing card reader backend"); - core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + _sdvxhook2_io_eam_init(&_sdvxhook2_module_io_eam); + + if (!bt_io_eam_init()) { log_fatal("Initializing card reader backend failed"); } } @@ -188,12 +211,20 @@ static bool my_dll_entry_main(void) if (!config_io.disable_card_reader_emu) { log_misc("Shutting down card reader backend"); - eam_io_fini(); + + bt_io_eam_fini(); + + bt_io_eam_api_clear(); + module_io_free(&_sdvxhook2_module_io_eam); } if (!config_io.disable_bio2_emu) { log_misc("Shutting down sdvx IO backend"); - sdvx_io_fini(); + + bt_io_sdvx_fini(); + + bt_io_sdvx_api_clear(); + module_io_free(&_sdvxhook2_module_io_sdvx); } if (!config_io.disable_file_hooks) { @@ -213,8 +244,8 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) } // Use AVS APIs - avs_util_core_interop_thread_avs_impl_set(); - avs_util_core_interop_log_avs_impl_set(); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); app_hook_init(my_dll_entry_init, my_dll_entry_main); diff --git a/src/main/sdvxhook2/nvapi.c b/src/main/sdvxhook2/nvapi.c index e5f244a..004104e 100644 --- a/src/main/sdvxhook2/nvapi.c +++ b/src/main/sdvxhook2/nvapi.c @@ -10,11 +10,11 @@ #include -#include "core/log.h" - #include "hook/com-proxy.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "sdvxhook2/nvapi.h" static void *my_GetProcAddress(HMODULE dll, const char *name); diff --git a/src/main/sdvxhook2/power.c b/src/main/sdvxhook2/power.c index e6d0d33..803c368 100644 --- a/src/main/sdvxhook2/power.c +++ b/src/main/sdvxhook2/power.c @@ -10,11 +10,11 @@ #include -#include "core/log.h" - #include "hook/com-proxy.h" #include "hook/table.h" +#include "iface-core/log.h" + #include "sdvxhook2/power.h" static DWORD diff --git a/src/main/sdvxio-bio2/Module.mk b/src/main/sdvxio-bio2/Module.mk index 04ea0fd..17a550d 100644 --- a/src/main/sdvxio-bio2/Module.mk +++ b/src/main/sdvxio-bio2/Module.mk @@ -4,11 +4,12 @@ ldflags_sdvxio-bio2 := \ -lsetupapi \ libs_sdvxio-bio2 := \ - core \ aciodrv \ bio2drv \ cconfig \ util \ + iface-core \ + util \ src_sdvxio-bio2 := \ sdvxio.c \ diff --git a/src/main/sdvxio-bio2/sdvxio-bio2.def b/src/main/sdvxio-bio2/sdvxio-bio2.def index 7b14921..71e237e 100644 --- a/src/main/sdvxio-bio2/sdvxio-bio2.def +++ b/src/main/sdvxio-bio2/sdvxio-bio2.def @@ -1,15 +1,18 @@ LIBRARY sdvxio-bio2 EXPORTS - sdvx_io_fini - sdvx_io_get_input_gpio - sdvx_io_get_input_gpio_sys - sdvx_io_get_spinner_pos - sdvx_io_init - sdvx_io_read_input - sdvx_io_set_gpio_lights - sdvx_io_set_loggers - sdvx_io_set_pwm_light - sdvx_io_write_output - sdvx_io_set_amp_volume - _bio2_sdvx_io_poll + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_io_sdvx_api_get + + ; Direct API + bt_io_sdvx_init + bt_io_sdvx_fini + bt_io_sdvx_gpio_lights_set + bt_io_sdvx_pwm_light_set + bt_io_sdvx_output_write + bt_io_sdvx_input_read + bt_io_sdvx_input_gpio_sys_get + bt_io_sdvx_input_gpio_get + bt_io_sdvx_spinner_pos_get + bt_io_sdvx_amp_volume_set diff --git a/src/main/sdvxio-bio2/sdvxio.c b/src/main/sdvxio-bio2/sdvxio.c index e4dcb6a..d11bb1d 100644 --- a/src/main/sdvxio-bio2/sdvxio.c +++ b/src/main/sdvxio-bio2/sdvxio.c @@ -1,31 +1,25 @@ +#define LOG_MODULE "sdvxio-bio2" + #include #include #include #include #include -#include "bemanitools/glue.h" -#include "bemanitools/sdvxio.h" +#include "api/core/log.h" #include "cconfig/cconfig-main.h" +#include "iface-core/log.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/io/sdvx.h" + #include "aciodrv/device.h" #include "bio2drv/bi2a-sdvx.h" #include "bio2drv/config-bio2.h" #include "bio2drv/detect.h" -#define LOG_MODULE "sdvxio-bio2" - -#define log_misc(...) sdvx_io_log_misc(LOG_MODULE, __VA_ARGS__) -#define log_info(...) sdvx_io_log_info(LOG_MODULE, __VA_ARGS__) -#define log_warning(...) sdvx_io_log_warning(LOG_MODULE, __VA_ARGS__) -#define log_fatal(...) sdvx_io_log_fatal(LOG_MODULE, __VA_ARGS__) - -static log_formatter_t sdvx_io_log_misc; -static log_formatter_t sdvx_io_log_info; -static log_formatter_t sdvx_io_log_warning; -static log_formatter_t sdvx_io_log_fatal; - static uint16_t sdvx_io_gpio[2]; static uint8_t sdvx_io_gpio_sys; static uint16_t sdvx_io_analog[2]; @@ -42,26 +36,8 @@ struct bi2a_sdvx_state_out pout_ready; static struct aciodrv_device_ctx *bio2_device_ctx; -void sdvx_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) +bool bt_io_sdvx_init() { - sdvx_io_log_misc = misc; - sdvx_io_log_info = info; - sdvx_io_log_warning = warning; - sdvx_io_log_fatal = fatal; - - bio2drv_set_loggers(misc, info, warning, fatal); -} - -bool sdvx_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) -{ - struct cconfig *config; struct bio2drv_config_bio2 config_bio2; @@ -152,7 +128,7 @@ bool sdvx_io_init( return running; } -void sdvx_io_fini(void) +void bt_io_sdvx_fini(void) { running = false; while (processing_io) { @@ -175,20 +151,20 @@ static uint8_t assign_light(uint32_t gpio_lights, uint32_t shift) /* Blue generator lights are gpio, while the red and green are pwm on the KFCA. Tested this on a gen 1 sdvx pcb, and indeed the blue lights are only on/off, while the red & green can fade. */ -void sdvx_io_set_gpio_lights(uint32_t gpio_lights) +void bt_io_sdvx_gpio_lights_set(uint32_t gpio_lights) { - pout_staging.gpio[0] = assign_light(gpio_lights, SDVX_IO_OUT_GPIO_START); - pout_staging.gpio[1] = assign_light(gpio_lights, SDVX_IO_OUT_GPIO_A); - pout_staging.gpio[2] = assign_light(gpio_lights, SDVX_IO_OUT_GPIO_B); - pout_staging.gpio[3] = assign_light(gpio_lights, SDVX_IO_OUT_GPIO_C); - pout_staging.gpio[4] = assign_light(gpio_lights, SDVX_IO_OUT_GPIO_D); - pout_staging.gpio[5] = assign_light(gpio_lights, SDVX_IO_OUT_GPIO_FX_L); - pout_staging.gpio[6] = assign_light(gpio_lights, SDVX_IO_OUT_GPIO_FX_R); + pout_staging.gpio[0] = assign_light(gpio_lights, BT_IO_SDVX_OUT_GPIO_START); + pout_staging.gpio[1] = assign_light(gpio_lights, BT_IO_SDVX_OUT_GPIO_A); + pout_staging.gpio[2] = assign_light(gpio_lights, BT_IO_SDVX_OUT_GPIO_B); + pout_staging.gpio[3] = assign_light(gpio_lights, BT_IO_SDVX_OUT_GPIO_C); + pout_staging.gpio[4] = assign_light(gpio_lights, BT_IO_SDVX_OUT_GPIO_D); + pout_staging.gpio[5] = assign_light(gpio_lights, BT_IO_SDVX_OUT_GPIO_FX_L); + pout_staging.gpio[6] = assign_light(gpio_lights, BT_IO_SDVX_OUT_GPIO_FX_R); pout_staging.generator[2] = - assign_light(gpio_lights, SDVX_IO_OUT_GPIO_GENERATOR_B); + assign_light(gpio_lights, BT_IO_SDVX_OUT_GPIO_GENERATOR_B); } -void sdvx_io_set_pwm_light(uint8_t light_no, uint8_t intensity) +void bt_io_sdvx_pwm_light_set(uint8_t light_no, uint8_t intensity) { if (light_no < 12) { wing_staging[light_no] = intensity; @@ -224,7 +200,7 @@ void sdvx_io_set_pwm_light(uint8_t light_no, uint8_t intensity) } } -bool sdvx_io_write_output(void) +bool bt_io_sdvx_output_write(void) { memcpy(&pout_ready, &pout_staging, sizeof(struct bi2a_sdvx_state_out)); pout_ready.wingUpper[0] = wing_staging[0] / 2 + wing_staging[3] / 2; @@ -269,7 +245,7 @@ bool _bio2_sdvx_io_poll( return true; } -bool sdvx_io_read_input(void) +bool bt_io_sdvx_input_read(void) { struct bi2a_sdvx_state_in pin; @@ -285,35 +261,37 @@ bool sdvx_io_read_input(void) sdvx_io_gpio_sys = 0; sdvx_io_gpio_sys |= - shift_pin(pin.analogs[0].a_coin, SDVX_IO_IN_GPIO_SYS_COIN); + shift_pin(pin.analogs[0].a_coin, BT_IO_SDVX_IN_GPIO_SYS_COIN); sdvx_io_gpio_sys |= - shift_pin(pin.analogs[0].a_test, SDVX_IO_IN_GPIO_SYS_TEST); + shift_pin(pin.analogs[0].a_test, BT_IO_SDVX_IN_GPIO_SYS_TEST); sdvx_io_gpio_sys |= - shift_pin(pin.analogs[0].a_service, SDVX_IO_IN_GPIO_SYS_SERVICE); + shift_pin(pin.analogs[0].a_service, BT_IO_SDVX_IN_GPIO_SYS_SERVICE); sdvx_io_gpio[0] = 0; sdvx_io_gpio[1] = 0; sdvx_io_gpio[0] |= - shift_pin(pin.buttons_1.b_start, SDVX_IO_IN_GPIO_0_START); + shift_pin(pin.buttons_1.b_start, BT_IO_SDVX_IN_GPIO_0_START); sdvx_io_gpio[0] |= - shift_pin(pin.buttons_1.b_headphone, SDVX_IO_IN_GPIO_0_HEADPHONE); - sdvx_io_gpio[0] |= shift_pin(pin.buttons_1.b_a, SDVX_IO_IN_GPIO_0_A); - sdvx_io_gpio[0] |= shift_pin(pin.buttons_1.b_b, SDVX_IO_IN_GPIO_0_B); - sdvx_io_gpio[0] |= shift_pin(pin.buttons_1.b_c, SDVX_IO_IN_GPIO_0_C); - sdvx_io_gpio[1] |= shift_pin(pin.buttons_1.b_d, SDVX_IO_IN_GPIO_1_D); - sdvx_io_gpio[1] |= shift_pin(pin.buttons_1.b_fxl, SDVX_IO_IN_GPIO_1_FX_L); - sdvx_io_gpio[1] |= shift_pin(pin.buttons_2.b_fxr, SDVX_IO_IN_GPIO_1_FX_R); + shift_pin(pin.buttons_1.b_headphone, BT_IO_SDVX_IN_GPIO_0_HEADPHONE); + sdvx_io_gpio[0] |= shift_pin(pin.buttons_1.b_a, BT_IO_SDVX_IN_GPIO_0_A); + sdvx_io_gpio[0] |= shift_pin(pin.buttons_1.b_b, BT_IO_SDVX_IN_GPIO_0_B); + sdvx_io_gpio[0] |= shift_pin(pin.buttons_1.b_c, BT_IO_SDVX_IN_GPIO_0_C); + sdvx_io_gpio[1] |= shift_pin(pin.buttons_1.b_d, BT_IO_SDVX_IN_GPIO_1_D); + sdvx_io_gpio[1] |= + shift_pin(pin.buttons_1.b_fxl, BT_IO_SDVX_IN_GPIO_1_FX_L); + sdvx_io_gpio[1] |= + shift_pin(pin.buttons_2.b_fxr, BT_IO_SDVX_IN_GPIO_1_FX_R); return true; } -uint8_t sdvx_io_get_input_gpio_sys(void) +uint8_t bt_io_sdvx_input_gpio_sys_get(void) { return sdvx_io_gpio_sys; } -uint16_t sdvx_io_get_input_gpio(uint8_t gpio_bank) +uint16_t bt_io_sdvx_input_gpio_get(uint8_t gpio_bank) { if (gpio_bank > 1) { return 0; @@ -322,7 +300,7 @@ uint16_t sdvx_io_get_input_gpio(uint8_t gpio_bank) return sdvx_io_gpio[gpio_bank]; } -uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no) +uint16_t bt_io_sdvx_spinner_pos_get(uint8_t spinner_no) { if (spinner_no >= 2) { return 0; @@ -330,7 +308,7 @@ uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no) return sdvx_io_analog[spinner_no]; } -bool sdvx_io_set_amp_volume( +bool bt_io_sdvx_amp_volume_set( uint8_t primary, uint8_t headphone, uint8_t subwoofer) { if (!running) { @@ -346,3 +324,24 @@ bool sdvx_io_set_amp_volume( return true; } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_io_sdvx_api_get(bt_io_sdvx_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_sdvx_init; + api->v1.fini = bt_io_sdvx_fini; + api->v1.gpio_lights_set = bt_io_sdvx_gpio_lights_set; + api->v1.pwm_light_set = bt_io_sdvx_pwm_light_set; + api->v1.output_write = bt_io_sdvx_output_write; + api->v1.input_read = bt_io_sdvx_input_read; + api->v1.input_gpio_sys_get = bt_io_sdvx_input_gpio_sys_get; + api->v1.input_gpio_get = bt_io_sdvx_input_gpio_get; + api->v1.spinner_pos_get = bt_io_sdvx_spinner_pos_get; + api->v1.amp_volume_set = bt_io_sdvx_amp_volume_set; +} \ No newline at end of file diff --git a/src/main/sdvxio-kfca/Module.mk b/src/main/sdvxio-kfca/Module.mk index 5127c16..38d034a 100644 --- a/src/main/sdvxio-kfca/Module.mk +++ b/src/main/sdvxio-kfca/Module.mk @@ -1,12 +1,14 @@ dlls += sdvxio-kfca libs_sdvxio-kfca := \ - core \ - geninput \ aciodrv \ - aciomgr \ cconfig \ util \ + iface \ + module \ + iface-acio \ + iface-core \ + util \ src_sdvxio-kfca := \ sdvxio.c \ diff --git a/src/main/sdvxio-kfca/config-kfca.c b/src/main/sdvxio-kfca/config-kfca.c index 6b95e24..d5d6b34 100644 --- a/src/main/sdvxio-kfca/config-kfca.c +++ b/src/main/sdvxio-kfca/config-kfca.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "sdvxio-kfca/config-kfca.h" diff --git a/src/main/sdvxio-kfca/sdvxio-kfca.def b/src/main/sdvxio-kfca/sdvxio-kfca.def index 8d6e632..31142d8 100644 --- a/src/main/sdvxio-kfca/sdvxio-kfca.def +++ b/src/main/sdvxio-kfca/sdvxio-kfca.def @@ -1,14 +1,18 @@ LIBRARY sdvxio EXPORTS - sdvx_io_fini - sdvx_io_get_input_gpio - sdvx_io_get_input_gpio_sys - sdvx_io_get_spinner_pos - sdvx_io_init - sdvx_io_read_input - sdvx_io_set_gpio_lights - sdvx_io_set_loggers - sdvx_io_set_pwm_light - sdvx_io_write_output - sdvx_io_set_amp_volume + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_io_sdvx_api_get + + ; Direct API + bt_io_sdvx_init + bt_io_sdvx_fini + bt_io_sdvx_gpio_lights_set + bt_io_sdvx_pwm_light_set + bt_io_sdvx_output_write + bt_io_sdvx_input_read + bt_io_sdvx_input_gpio_sys_get + bt_io_sdvx_input_gpio_get + bt_io_sdvx_spinner_pos_get + bt_io_sdvx_amp_volume_set diff --git a/src/main/sdvxio-kfca/sdvxio.c b/src/main/sdvxio-kfca/sdvxio.c index e230449..16a0243 100644 --- a/src/main/sdvxio-kfca/sdvxio.c +++ b/src/main/sdvxio-kfca/sdvxio.c @@ -1,33 +1,29 @@ +#define LOG_MODULE "sdvxio-kfca" + #include #include #include #include #include -#include "bemanitools/glue.h" -#include "bemanitools/sdvxio.h" +#include "acio/acio.h" + +#include "api/core/log.h" #include "cconfig/cconfig-main.h" -#include "acio/acio.h" +#include "iface-acio/mgr.h" +#include "iface-core/log.h" + +#include "main/module/acio-mgr-ext.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/io/sdvx.h" #include "aciodrv/kfca.h" -#include "aciomgr/manager.h" #include "sdvxio-kfca/config-kfca.h" -#define LOG_MODULE "sdvxio-kfca" - -#define log_misc(...) sdvx_io_log_misc(LOG_MODULE, __VA_ARGS__) -#define log_info(...) sdvx_io_log_info(LOG_MODULE, __VA_ARGS__) -#define log_warning(...) sdvx_io_log_warning(LOG_MODULE, __VA_ARGS__) -#define log_fatal(...) sdvx_io_log_fatal(LOG_MODULE, __VA_ARGS__) - -static log_formatter_t sdvx_io_log_misc; -static log_formatter_t sdvx_io_log_info; -static log_formatter_t sdvx_io_log_warning; -static log_formatter_t sdvx_io_log_fatal; - static uint16_t sdvx_io_gpio[2]; static uint8_t sdvx_io_gpio_sys; static uint16_t sdvx_io_analog[2]; @@ -39,28 +35,21 @@ static int16_t kfca_node_id; struct ac_io_kfca_poll_out pout_staging; struct ac_io_kfca_poll_out pout_ready; -static struct aciomgr_port_dispatcher *acio_manager_ctx; +static bt_acio_mgr_port_dispatcher_t *acio_manager_ctx; -void sdvx_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) +static module_acio_mgr_t *acio_mgr_module; + +static void _bt_io_jb_module_acio_mgr_init(module_acio_mgr_t **module) { - aciomgr_set_loggers(misc, info, warning, fatal); + bt_acio_mgr_api_t api; - sdvx_io_log_misc = misc; - sdvx_io_log_info = info; - sdvx_io_log_warning = warning; - sdvx_io_log_fatal = fatal; + module_acio_mgr_ext_load_and_init("acio-mgr.dll", module); + module_acio_mgr_api_get(*module, &api); + bt_acio_mgr_api_set(&api); } -bool sdvx_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_sdvx_init() { - struct cconfig *config; struct sdvxio_kfca_config_kfca config_kfca; @@ -84,7 +73,10 @@ bool sdvx_io_init( cconfig_finit(config); - acio_manager_ctx = aciomgr_port_init(config_kfca.port, config_kfca.baud); + _bt_io_jb_module_acio_mgr_init(&acio_mgr_module); + + acio_manager_ctx = + bt_acio_mgr_port_init(config_kfca.port, config_kfca.baud); if (acio_manager_ctx == NULL) { log_info("Opening acio device on [%s] failed", config_kfca.port); @@ -93,14 +85,14 @@ bool sdvx_io_init( log_info("Opening acio device successful"); - uint8_t node_count = aciomgr_get_node_count(acio_manager_ctx); + uint8_t node_count = bt_acio_mgr_node_count_get(acio_manager_ctx); log_info("Enumerated %d nodes", node_count); kfca_node_id = -1; for (uint8_t i = 0; i < node_count; i++) { char product[4]; - aciomgr_get_node_product_ident(acio_manager_ctx, i, product); + bt_acio_mgr_node_product_ident_get(acio_manager_ctx, i, product); log_info( "> %d: %c%c%c%c\n", i, @@ -135,13 +127,13 @@ bool sdvx_io_init( } bool init_result = aciodrv_kfca_amp( - aciomgr_port_checkout(acio_manager_ctx), + bt_acio_mgr_port_checkout(acio_manager_ctx), kfca_node_id, primary, headphone, 0, subwoofer); - aciomgr_port_checkin(acio_manager_ctx); + bt_acio_mgr_port_checkin(acio_manager_ctx); if (!init_result) { log_warning("Unable to start KFCA on node: %d", kfca_node_id); @@ -157,16 +149,19 @@ bool sdvx_io_init( return running; } -void sdvx_io_fini(void) +void bt_io_sdvx_fini(void) { running = false; while (processing_io) { // avoid banging Sleep(1); } + + bt_acio_mgr_api_clear(); + module_acio_mgr_free(&acio_mgr_module); } -void sdvx_io_set_gpio_lights(uint32_t gpio_lights) +void bt_io_sdvx_gpio_lights_set(uint32_t gpio_lights) { pout_staging.gpio = gpio_lights; pout_staging.gpio |= 1 << 0x16; @@ -174,18 +169,18 @@ void sdvx_io_set_gpio_lights(uint32_t gpio_lights) pout_staging.gpio = ac_io_u32(pout_staging.gpio); } -void sdvx_io_set_pwm_light(uint8_t light_no, uint8_t intensity) +void bt_io_sdvx_pwm_light_set(uint8_t light_no, uint8_t intensity) { pout_staging.pwm[light_no] = intensity; } -bool sdvx_io_write_output(void) +bool bt_io_sdvx_output_write(void) { memcpy(&pout_ready, &pout_staging, sizeof(struct ac_io_kfca_poll_out)); return true; } -bool sdvx_io_read_input(void) +bool bt_io_sdvx_input_read(void) { struct ac_io_kfca_poll_in pin; @@ -195,11 +190,11 @@ bool sdvx_io_read_input(void) processing_io = true; bool poll_result = aciodrv_kfca_poll( - aciomgr_port_checkout(acio_manager_ctx), + bt_acio_mgr_port_checkout(acio_manager_ctx), kfca_node_id, &pout_ready, &pin); - aciomgr_port_checkin(acio_manager_ctx); + bt_acio_mgr_port_checkin(acio_manager_ctx); if (!poll_result) { return false; @@ -224,12 +219,12 @@ bool sdvx_io_read_input(void) return true; } -uint8_t sdvx_io_get_input_gpio_sys(void) +uint8_t bt_io_sdvx_input_gpio_sys_get(void) { return sdvx_io_gpio_sys; } -uint16_t sdvx_io_get_input_gpio(uint8_t gpio_bank) +uint16_t bt_io_sdvx_input_gpio_get(uint8_t gpio_bank) { if (gpio_bank > 1) { return 0; @@ -238,7 +233,7 @@ uint16_t sdvx_io_get_input_gpio(uint8_t gpio_bank) return sdvx_io_gpio[gpio_bank]; } -uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no) +uint16_t bt_io_sdvx_spinner_pos_get(uint8_t spinner_no) { if (spinner_no >= 2) { return 0; @@ -246,7 +241,7 @@ uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no) return sdvx_io_analog[spinner_no]; } -bool sdvx_io_set_amp_volume( +bool bt_io_sdvx_amp_volume_set( uint8_t primary, uint8_t headphone, uint8_t subwoofer) { if (!running) { @@ -254,13 +249,13 @@ bool sdvx_io_set_amp_volume( } bool amp_result = aciodrv_kfca_amp( - aciomgr_port_checkout(acio_manager_ctx), + bt_acio_mgr_port_checkout(acio_manager_ctx), kfca_node_id, primary, headphone, 96, subwoofer); - aciomgr_port_checkin(acio_manager_ctx); + bt_acio_mgr_port_checkin(acio_manager_ctx); if (!amp_result) { return false; @@ -268,3 +263,24 @@ bool sdvx_io_set_amp_volume( return true; } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_io_sdvx_api_get(bt_io_sdvx_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_sdvx_init; + api->v1.fini = bt_io_sdvx_fini; + api->v1.gpio_lights_set = bt_io_sdvx_gpio_lights_set; + api->v1.pwm_light_set = bt_io_sdvx_pwm_light_set; + api->v1.output_write = bt_io_sdvx_output_write; + api->v1.input_read = bt_io_sdvx_input_read; + api->v1.input_gpio_sys_get = bt_io_sdvx_input_gpio_sys_get; + api->v1.input_gpio_get = bt_io_sdvx_input_gpio_get; + api->v1.spinner_pos_get = bt_io_sdvx_spinner_pos_get; + api->v1.amp_volume_set = bt_io_sdvx_amp_volume_set; +} \ No newline at end of file diff --git a/src/main/sdvxio/Module.mk b/src/main/sdvxio/Module.mk index ffeca72..3eecfe2 100644 --- a/src/main/sdvxio/Module.mk +++ b/src/main/sdvxio/Module.mk @@ -1,7 +1,14 @@ dlls += sdvxio +ldflags_sdvxio := \ + -lwinmm + libs_sdvxio := \ - geninput \ + iface \ + module \ + iface-io \ + iface-core \ + util \ src_sdvxio := \ sdvxio.c \ diff --git a/src/main/sdvxio/sdvxio.c b/src/main/sdvxio/sdvxio.c index 5478c73..1858157 100644 --- a/src/main/sdvxio/sdvxio.c +++ b/src/main/sdvxio/sdvxio.c @@ -1,67 +1,101 @@ +#define LOG_MODULE "sdvxio" + +// clang-format off +// Don't format because the order is important here +#include +#include +// clang-format on + #include #include #include -#include "bemanitools/glue.h" -#include "bemanitools/input.h" -#include "bemanitools/sdvxio.h" +#include "api/core/log.h" +#include "api/core/thread.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface/input.h" + +#include "main/module/input-ext.h" +#include "main/module/input.h" +#include "main/module/io-ext.h" +#include "main/module/io.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/input.h" +#include "sdk/module/io/sdvx.h" static uint16_t sdvx_io_gpio[2]; static uint8_t sdvx_io_gpio_sys; -void sdvx_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) +static module_input_t *_sdvx_io_module_input; + +static void _bt_io_sdvx_module_input_init(module_input_t **module) { - input_set_loggers(misc, info, warning, fatal); + bt_input_api_t api; + + module_input_ext_load_and_init("geninput.dll", module); + module_input_api_get(*module, &api); + bt_input_api_set(&api); } -bool sdvx_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_sdvx_init() { - input_init(thread_create, thread_join, thread_destroy); - mapper_config_load("sdvx"); + bool result; - return true; + _bt_io_sdvx_module_input_init(&_sdvx_io_module_input); + + timeBeginPeriod(1); + + result = bt_input_init(); + + if (!result) { + log_warning("Initializing input failed"); + return false; + } + + return bt_input_mapper_config_load("sdvx"); } -void sdvx_io_fini(void) +void bt_io_sdvx_fini(void) { - input_fini(); + bt_input_fini(); + bt_input_api_clear(); + module_input_free(&_sdvx_io_module_input); + + timeEndPeriod(1); } -void sdvx_io_set_gpio_lights(uint32_t gpio_lights) +void bt_io_sdvx_gpio_lights_set(uint32_t gpio_lights) { size_t i; for (i = 0; i < 16; i++) { if (gpio_lights & (1 << i)) { - mapper_write_light(i, 255); + bt_input_mapper_light_write(i, 255); } else { - mapper_write_light(i, 0); + bt_input_mapper_light_write(i, 0); } } } -void sdvx_io_set_pwm_light(uint8_t light_no, uint8_t intensity) +void bt_io_sdvx_pwm_light_set(uint8_t light_no, uint8_t intensity) { - mapper_write_light(light_no + 0x10, intensity); + bt_input_mapper_light_write(light_no + 0x10, intensity); } -bool sdvx_io_write_output(void) +bool bt_io_sdvx_output_write(void) { return true; } -bool sdvx_io_read_input(void) +bool bt_io_sdvx_input_read(void) { uint32_t pack; - pack = mapper_update(); + pack = bt_input_mapper_update(); sdvx_io_gpio_sys = pack & 0xFF; sdvx_io_gpio[0] = (pack >> 8) & 0x00FF; @@ -70,12 +104,12 @@ bool sdvx_io_read_input(void) return true; } -uint8_t sdvx_io_get_input_gpio_sys(void) +uint8_t bt_io_sdvx_input_gpio_sys_get(void) { return sdvx_io_gpio_sys; } -uint16_t sdvx_io_get_input_gpio(uint8_t gpio_bank) +uint16_t bt_io_sdvx_input_gpio_get(uint8_t gpio_bank) { if (gpio_bank > 1) { return 0; @@ -84,13 +118,39 @@ uint16_t sdvx_io_get_input_gpio(uint8_t gpio_bank) return sdvx_io_gpio[gpio_bank]; } -uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no) +uint16_t bt_io_sdvx_spinner_pos_get(uint8_t spinner_no) { - return mapper_read_analog(spinner_no) * 4; + return bt_input_mapper_analog_read(spinner_no) * 4; } -bool sdvx_io_set_amp_volume( +bool bt_io_sdvx_amp_volume_set( uint8_t primary, uint8_t headphone, uint8_t subwoofer) { return true; } + +void bt_module_core_log_api_set(const bt_core_log_api_t *api) +{ + bt_core_log_api_set(api); +} + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) +{ + bt_core_thread_api_set(api); +} + +void bt_module_io_sdvx_api_get(bt_io_sdvx_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_sdvx_init; + api->v1.fini = bt_io_sdvx_fini; + api->v1.gpio_lights_set = bt_io_sdvx_gpio_lights_set; + api->v1.pwm_light_set = bt_io_sdvx_pwm_light_set; + api->v1.output_write = bt_io_sdvx_output_write; + api->v1.input_read = bt_io_sdvx_input_read; + api->v1.input_gpio_sys_get = bt_io_sdvx_input_gpio_sys_get; + api->v1.input_gpio_get = bt_io_sdvx_input_gpio_get; + api->v1.spinner_pos_get = bt_io_sdvx_spinner_pos_get; + api->v1.amp_volume_set = bt_io_sdvx_amp_volume_set; +} diff --git a/src/main/sdvxio/sdvxio.def b/src/main/sdvxio/sdvxio.def index 8d6e632..e9b62af 100644 --- a/src/main/sdvxio/sdvxio.def +++ b/src/main/sdvxio/sdvxio.def @@ -1,14 +1,19 @@ LIBRARY sdvxio EXPORTS - sdvx_io_fini - sdvx_io_get_input_gpio - sdvx_io_get_input_gpio_sys - sdvx_io_get_spinner_pos - sdvx_io_init - sdvx_io_read_input - sdvx_io_set_gpio_lights - sdvx_io_set_loggers - sdvx_io_set_pwm_light - sdvx_io_write_output - sdvx_io_set_amp_volume + ; Bemanitools 6 API + bt_module_core_log_api_set + bt_module_core_thread_api_set + bt_module_io_sdvx_api_get + + ; Direct API + bt_io_sdvx_init + bt_io_sdvx_fini + bt_io_sdvx_gpio_lights_set + bt_io_sdvx_pwm_light_set + bt_io_sdvx_output_write + bt_io_sdvx_input_read + bt_io_sdvx_input_gpio_sys_get + bt_io_sdvx_input_gpio_get + bt_io_sdvx_spinner_pos_get + bt_io_sdvx_amp_volume_set diff --git a/src/main/security/id.c b/src/main/security/id.c index 93699aa..1d949f5 100644 --- a/src/main/security/id.c +++ b/src/main/security/id.c @@ -1,6 +1,6 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "security/id.h" diff --git a/src/main/security/mcode.c b/src/main/security/mcode.c index 8817647..2245d5e 100644 --- a/src/main/security/mcode.c +++ b/src/main/security/mcode.c @@ -1,6 +1,6 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "security/mcode.h" diff --git a/src/main/security/rp-blowfish.c b/src/main/security/rp-blowfish.c index f45a0a9..5570ba2 100644 --- a/src/main/security/rp-blowfish.c +++ b/src/main/security/rp-blowfish.c @@ -1,6 +1,6 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "security/rp-blowfish-table.h" #include "security/rp-blowfish.h" diff --git a/src/main/security/rp.c b/src/main/security/rp.c index 5e80670..f401193 100644 --- a/src/main/security/rp.c +++ b/src/main/security/rp.c @@ -1,4 +1,4 @@ -#include "core/log.h" +#include "iface-core/log.h" #include "security/rp.h" diff --git a/src/main/security/rp2.c b/src/main/security/rp2.c index 92b3acb..92a35d1 100644 --- a/src/main/security/rp2.c +++ b/src/main/security/rp2.c @@ -1,6 +1,6 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "security/rp-util.h" #include "security/rp2.h" diff --git a/src/main/security/rp3.c b/src/main/security/rp3.c index 6e83f68..b43e113 100644 --- a/src/main/security/rp3.c +++ b/src/main/security/rp3.c @@ -1,6 +1,6 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "security/rp-util.h" #include "security/rp2.h" diff --git a/src/main/unicorntail/Module.mk b/src/main/unicorntail/Module.mk index d2d96be..e08b7d9 100644 --- a/src/main/unicorntail/Module.mk +++ b/src/main/unicorntail/Module.mk @@ -3,6 +3,9 @@ avsdlls += unicorntail deplibs_unicorntail := \ avs \ +avslibs_unicorntail := \ + avs-ext \ + libs_unicorntail := \ core \ p3io \ @@ -10,6 +13,7 @@ libs_unicorntail := \ hook \ hooklib \ util \ + iface-core \ src_unicorntail := \ dllmain.c \ diff --git a/src/main/unicorntail/dllmain.c b/src/main/unicorntail/dllmain.c index b195edf..b52a4f4 100644 --- a/src/main/unicorntail/dllmain.c +++ b/src/main/unicorntail/dllmain.c @@ -2,12 +2,15 @@ #include -#include "core/log.h" +#include "avs-ext/log.h" +#include "avs-ext/thread.h" #include "hook/iohook.h" #include "hooklib/app.h" +#include "iface-core/log.h" + #include "imports/avs.h" #include "unicorntail/p3io.h" @@ -51,8 +54,8 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) goto end; } - core_log_impl_set( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + avs_ext_log_core_api_set(); + avs_ext_thread_core_api_set(); app_hook_init(my_dll_entry_init, my_dll_entry_main); diff --git a/src/main/unicorntail/p3io.c b/src/main/unicorntail/p3io.c index b4a49b1..bc68b04 100644 --- a/src/main/unicorntail/p3io.c +++ b/src/main/unicorntail/p3io.c @@ -3,7 +3,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "p3io/cmd.h" #include "p3io/frame.h" diff --git a/src/main/unicorntail/usbmem.c b/src/main/unicorntail/usbmem.c index ef82069..b143b03 100644 --- a/src/main/unicorntail/usbmem.c +++ b/src/main/unicorntail/usbmem.c @@ -3,7 +3,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "hook/iohook.h" diff --git a/src/main/util/array.c b/src/main/util/array.c index 9421fff..5a9d52f 100644 --- a/src/main/util/array.c +++ b/src/main/util/array.c @@ -2,7 +2,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "util/array.h" #include "util/mem.h" diff --git a/src/main/util/crc.c b/src/main/util/crc.c index 7ab06b8..4c163a9 100644 --- a/src/main/util/crc.c +++ b/src/main/util/crc.c @@ -1,7 +1,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" uint8_t crc8(const void *ptr, size_t nbytes, uint8_t in) { diff --git a/src/main/util/crypto.c b/src/main/util/crypto.c index db1702e..6ca2009 100644 --- a/src/main/util/crypto.c +++ b/src/main/util/crypto.c @@ -3,7 +3,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "util/crypto.h" #include "util/mem.h" diff --git a/src/main/util/debug.c b/src/main/util/debug.c index 7702505..6709156 100644 --- a/src/main/util/debug.c +++ b/src/main/util/debug.c @@ -4,159 +4,13 @@ #include -#include "core/log.h" - -#include "imports/dwarfstack.h" - -#include "util/debug.h" +#include "iface-core/log.h" #define EX_DESC(name) \ case EXCEPTION_##name: \ desc = " (" #name ")"; \ break -#define log_exception(...) _debug_exception_msg("exception", __VA_ARGS__) - -static core_log_message_t _debug_exception_msg; - -static void _debug_stacktrace_printer( - uint64_t addr, - const char *filename, - int lineno, - const char *funcname, - void *context, - int columnno) -{ - int *count; - const char *delim; - void *ptr; - char buffer[512]; - char *buffer_ptr; - - count = context; - delim = strrchr(filename, '/'); - - if (delim) { - filename = delim + 1; - } - - delim = strrchr(filename, '\\'); - - if (delim) { - filename = delim + 1; - } - - ptr = (void *) (uintptr_t) addr; - - switch (lineno) { - case DWST_BASE_ADDR: - log_exception("base address: 0x%p (%s)", ptr, filename); - break; - - case DWST_NOT_FOUND: - case DWST_NO_DBG_SYM: - case DWST_NO_SRC_FILE: - log_exception( - " stack %02d: 0x%p (%s)", (*count)++, ptr, filename); - break; - - default: - buffer_ptr = buffer; - memset(buffer, 0, sizeof(buffer)); - - if (ptr) { - buffer_ptr += sprintf( - buffer_ptr, " stack %02d: 0x%p", (*count)++, ptr); - } else { - buffer_ptr += sprintf( - buffer_ptr, - " %*s", - (int) sizeof(void *) * 2, - ""); - } - - buffer_ptr += sprintf(buffer_ptr, " (%s:%d", filename, lineno); - - if (columnno > 0) { - buffer_ptr += sprintf(buffer_ptr, ":%d", columnno); - } - - buffer_ptr += sprintf(buffer_ptr, ")"); - - if (funcname) { - buffer_ptr += sprintf(buffer_ptr, " [%s]", funcname); - } - - log_exception(buffer); - - break; - } -} - -static LONG WINAPI _debug_unhandled_exception_filter(LPEXCEPTION_POINTERS ep) -{ - DWORD code; - const char *desc; - ULONG_PTR flag; - ULONG_PTR addr; - int count; - - log_exception("=========================================================="); - log_exception("The application has crashed due to an unhandled exception!"); - - code = ep->ExceptionRecord->ExceptionCode; - desc = debug_exception_code_to_str(code); - - log_exception("code: 0x%08lX", code); - log_exception("desc: %s", desc); - - if (code == EXCEPTION_ACCESS_VIOLATION && - ep->ExceptionRecord->NumberParameters == 2) { - flag = ep->ExceptionRecord->ExceptionInformation[0]; - addr = ep->ExceptionRecord->ExceptionInformation[1]; - - log_exception( - "%s violation at 0x%p", - flag == 8 ? "data execution prevention" : - (flag ? "write access" : "read access"), - (void *) addr); - } - - log_exception("stacktrace:"); - - count = 0; - - dwstOfException(ep->ContextRecord, &_debug_stacktrace_printer, &count); - - log_exception("End of stacktrace"); - log_exception("=========================================================="); - - return EXCEPTION_EXECUTE_HANDLER; -} - -void debug_init(core_log_message_t exception_msg) -{ - _debug_exception_msg = exception_msg; - SetUnhandledExceptionFilter(_debug_unhandled_exception_filter); - - log_info("Initialized"); -} - -void debug_print_stacktrace() -{ - int count; - - count = 0; - - log_exception("=========================================================="); - log_exception("Debug stacktrace"); - - dwstOfLocation(&_debug_stacktrace_printer, &count); - - log_exception("End of debug stacktrace"); - log_exception("=========================================================="); -} - const char *debug_exception_code_to_str(DWORD code) { const char *desc = ""; diff --git a/src/main/util/debug.h b/src/main/util/debug.h index c69c31c..8467ead 100644 --- a/src/main/util/debug.h +++ b/src/main/util/debug.h @@ -3,10 +3,6 @@ #include -#include "core/log.h" - -void debug_init(core_log_message_t exception_msg); -void debug_print_stacktrace(); const char *debug_exception_code_to_str(DWORD code); #endif \ No newline at end of file diff --git a/src/main/util/fs.c b/src/main/util/fs.c index 8c4c7c6..b40dd64 100644 --- a/src/main/util/fs.c +++ b/src/main/util/fs.c @@ -6,7 +6,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "util/defs.h" #include "util/fs.h" diff --git a/src/main/util/hex.c b/src/main/util/hex.c index de08286..da45a3c 100644 --- a/src/main/util/hex.c +++ b/src/main/util/hex.c @@ -2,7 +2,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "util/hex.h" diff --git a/src/main/util/iobuf.c b/src/main/util/iobuf.c index 7638cb5..31ad8d1 100644 --- a/src/main/util/iobuf.c +++ b/src/main/util/iobuf.c @@ -1,6 +1,6 @@ #define LOG_MODULE "util-iobuf" -#include "core/log.h" +#include "iface-core/log.h" #include "util/hex.h" #include "util/iobuf.h" diff --git a/src/main/util/mem.c b/src/main/util/mem.c index f03ebaf..8a1053f 100644 --- a/src/main/util/mem.c +++ b/src/main/util/mem.c @@ -7,7 +7,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" void *xcalloc(size_t nbytes) { diff --git a/src/main/util/msg-thread.c b/src/main/util/msg-thread.c index 04d498d..8b9dd2e 100644 --- a/src/main/util/msg-thread.c +++ b/src/main/util/msg-thread.c @@ -5,8 +5,8 @@ #include #include -#include "core/log.h" -#include "core/thread.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" #include "util/msg-thread.h" @@ -14,7 +14,7 @@ static bool msg_thread_step(HWND hwnd); static const char msg_wndclass_name[] = "msg-thread"; -static int msg_thread_id; +static bt_core_thread_id_t msg_thread_id; static HANDLE msg_thread_ready; static HANDLE msg_thread_stop; static HWND msg_window; @@ -101,9 +101,14 @@ static bool msg_thread_step(HWND hwnd) void msg_thread_init(HINSTANCE inst) { + bt_core_thread_result_t result; + msg_thread_ready = CreateEvent(NULL, TRUE, FALSE, NULL); msg_thread_stop = CreateEvent(NULL, TRUE, FALSE, NULL); - msg_thread_id = core_thread_create(msg_thread_proc, inst, 0x4000, 0); + result = + bt_core_thread_create(msg_thread_proc, inst, 0x4000, 0, &msg_thread_id); + + bt_core_thread_fatal_on_error(result); WaitForSingleObject(msg_thread_ready, INFINITE); CloseHandle(msg_thread_ready); @@ -111,10 +116,15 @@ void msg_thread_init(HINSTANCE inst) void msg_thread_fini(void) { + bt_core_thread_result_t result; + SetEvent(msg_thread_stop); - core_thread_join(msg_thread_id, NULL); - core_thread_destroy(msg_thread_id); + result = bt_core_thread_join(msg_thread_id, NULL); + bt_core_thread_fatal_on_error(result); + + result = bt_core_thread_destroy(msg_thread_id); + bt_core_thread_fatal_on_error(result); CloseHandle(msg_thread_stop); } diff --git a/src/main/util/net.c b/src/main/util/net.c index d2c9d7d..b62952c 100644 --- a/src/main/util/net.c +++ b/src/main/util/net.c @@ -6,7 +6,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "util/mem.h" #include "util/net.h" diff --git a/src/main/util/os.c b/src/main/util/os.c index e6aad5d..10e50bd 100644 --- a/src/main/util/os.c +++ b/src/main/util/os.c @@ -6,7 +6,7 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "util/os.h" #include "util/str.h" diff --git a/src/main/util/proc.c b/src/main/util/proc.c index f1905d3..8ee2ec9 100644 --- a/src/main/util/proc.c +++ b/src/main/util/proc.c @@ -1,12 +1,16 @@ #define LOG_MODULE "util-proc" +// clang-format off +// Don't format because the order is important here #include +#include #include +// clang-format on #include #include -#include "core/log.h" +#include "iface-core/log.h" bool proc_is_running_as_admin_user() { @@ -58,4 +62,38 @@ void proc_terminate_current_process(uint32_t exit_code) SYNCHRONIZE | PROCESS_TERMINATE, TRUE, GetCurrentProcessId()); TerminateProcess(hnd, exit_code); +} + +bool proc_is_module_loaded(const char *name) +{ + HMODULE modules[1024]; + HANDLE process; + DWORD size; + char module_name[MAX_PATH]; + + process = GetCurrentProcess(); + + if (EnumProcessModules(process, modules, sizeof(modules), &size)) { + for (int i = 0; i < (size / sizeof(HMODULE)); i++) { + if (GetModuleFileNameEx( + process, + modules[i], + module_name, + sizeof(module_name) / sizeof(char))) { + const char *p = strrchr(module_name, '\\'); + + if (p != NULL) { + p++; + } else { + p = module_name; + } + + if (_stricmp(p, name) == 0) { + return true; + } + } + } + } + + return false; } \ No newline at end of file diff --git a/src/main/util/proc.h b/src/main/util/proc.h index be47a40..e86a42e 100644 --- a/src/main/util/proc.h +++ b/src/main/util/proc.h @@ -5,4 +5,6 @@ bool proc_is_running_as_admin_user(); -void proc_terminate_current_process(uint32_t exit_code); \ No newline at end of file +void proc_terminate_current_process(uint32_t exit_code); + +bool proc_is_module_loaded(const char *name); \ No newline at end of file diff --git a/src/main/util/signal.c b/src/main/util/signal.c index 4007d01..563ff6e 100644 --- a/src/main/util/signal.c +++ b/src/main/util/signal.c @@ -1,6 +1,6 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "util/hex.h" #include "util/signal.h" diff --git a/src/main/util/time.c b/src/main/util/time.c index feb2904..d875978 100644 --- a/src/main/util/time.c +++ b/src/main/util/time.c @@ -1,6 +1,6 @@ #include -#include "core/log.h" +#include "iface-core/log.h" #include "util/time.h" diff --git a/src/main/vefxio/vefxio.c b/src/main/vefxio/vefxio.c index 5d43056..7761b72 100644 --- a/src/main/vefxio/vefxio.c +++ b/src/main/vefxio/vefxio.c @@ -1,13 +1,4 @@ -/* This is the source code for the VEFXIO.DLL that ships with Bemanitools 5. - - If you want to add on some minor functionality like a custom 16seg display - or a customer slider board then feel free to extend this code with support - for your custom device. - - This DLL is only used by the generic input variant of IIDXIO.DLL that ships - with Bemanitools by default. If you want to create a custom IO board that - provides all of the inputs for IIDX then you should replace IIDXIO.DLL - instead and not call into this DLL at all. */ +#define LOG_MODULE "vefxio" // clang-format off // Don't format because the order is important here @@ -18,8 +9,9 @@ #include #include -#include "bemanitools/input.h" -#include "bemanitools/vefxio.h" +#include "iface-io/vefx.h" + +#include "sdk/module/io/vefx.h" #define MSEC_PER_NOTCH 128 @@ -63,37 +55,7 @@ static struct vefx_io_slider vefx_io_slider[5]; static void vefx_io_slider_update(uint64_t *ppad); -/* Uncomment these if you need them. */ - -#if 0 -static log_formatter_t vefx_io_log_misc; -static log_formatter_t vefx_io_log_info; -static log_formatter_t vefx_io_log_warning; -static log_formatter_t vefx_io_log_fatal; -#endif - -void vefx_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - /* Uncomment this block if you have something you'd like to log. - - You should probably return false from the appropriate function instead - of calling the fatal logger yourself though. */ -#if 0 - vefx_io_log_misc = misc; - vefx_io_log_info = info; - vefx_io_log_warning = warning; - vefx_io_log_fatal = fatal; -#endif -} - -bool vefx_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bt_io_vefx_init() { /* geninput should have already been initted be now so we don't do it */ vefx_io_slider[0].pos = 8; @@ -108,17 +70,16 @@ bool vefx_io_init( return true; } -bool vefx_io_recv(uint64_t *ppad) +bool bt_io_vefx_recv(uint64_t *ppad) { vefx_io_slider_update(ppad); return true; } -void vefx_io_fini(void) +void bt_io_vefx_fini(void) { - /* This function gets called as IIDX shuts down after an Alt-F4. Close your - connections to your IO devices here. */ + // noop } static void vefx_io_slider_update(uint64_t *ppad) @@ -170,7 +131,7 @@ static void vefx_io_slider_update(uint64_t *ppad) } } -uint8_t vefx_io_get_slider(uint8_t slider_no) +uint8_t bt_io_vefx_slider_get(uint8_t slider_no) { if (slider_no > 4) { return 0; @@ -179,10 +140,21 @@ uint8_t vefx_io_get_slider(uint8_t slider_no) return vefx_io_slider[slider_no].pos; } -bool vefx_io_write_16seg(const char *text) +bool bt_io_vefx_16seg_send(const char *text) { /* Insert code to write to your 16seg display here. Log something and return false if you encounter an IO error. */ return true; } + +void bt_module_io_vefx_api_get(bt_io_vefx_api_t *api) +{ + api->version = 1; + + api->v1.init = bt_io_vefx_init; + api->v1.fini = bt_io_vefx_fini; + api->v1.recv = bt_io_vefx_recv; + api->v1.slider_get = bt_io_vefx_slider_get; + api->v1._16seg_send = bt_io_vefx_16seg_send; +} \ No newline at end of file diff --git a/src/main/vefxio/vefxio.def b/src/main/vefxio/vefxio.def index 550384e..13e1082 100644 --- a/src/main/vefxio/vefxio.def +++ b/src/main/vefxio/vefxio.def @@ -1,9 +1,12 @@ LIBRARY vefxio EXPORTS - vefx_io_get_slider - vefx_io_recv - vefx_io_write_16seg - vefx_io_fini - vefx_io_init - vefx_io_set_loggers + ; Bemanitools 6 API + bt_module_io_vefx_api_get + + ; Direct API + bt_io_vefx_init + bt_io_vefx_fini + bt_io_vefx_recv + bt_io_vefx_slider_get + bt_io_vefx_16seg_send diff --git a/src/main/vigem-ddrio/Module.mk b/src/main/vigem-ddrio/Module.mk index 82e0f51..ca92790 100644 --- a/src/main/vigem-ddrio/Module.mk +++ b/src/main/vigem-ddrio/Module.mk @@ -12,9 +12,11 @@ ldflags_vigem-ddrio := \ libs_vigem-ddrio := \ core \ cconfig \ - ddrio \ util \ vigemstub \ + module \ + iface-io \ + iface-core \ src_vigem-ddrio := \ main.c \ diff --git a/src/main/vigem-ddrio/config-vigem-ddrio.c b/src/main/vigem-ddrio/config-vigem-ddrio.c index 0ff44f2..71d1a87 100644 --- a/src/main/vigem-ddrio/config-vigem-ddrio.c +++ b/src/main/vigem-ddrio/config-vigem-ddrio.c @@ -1,7 +1,7 @@ #include "cconfig/cconfig-main.h" #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "vigem-ddrio/config-vigem-ddrio.h" diff --git a/src/main/vigem-ddrio/main.c b/src/main/vigem-ddrio/main.c index 7d7fafa..d230d55 100644 --- a/src/main/vigem-ddrio/main.c +++ b/src/main/vigem-ddrio/main.c @@ -7,15 +7,17 @@ #include "ViGEm/Client.h" -#include "bemanitools/ddrio.h" - #include "core/log-bt-ext.h" #include "core/log-bt.h" #include "core/log-sink-std.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" #include "core/thread-crt.h" -#include "core/thread.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" +#include "iface-io/ddr.h" + +#include "module/io-ext.h" +#include "module/io.h" #include "util/math.h" @@ -25,6 +27,8 @@ #define NUM_PADS 2 +static module_io_t *_module_io_ddr; + bool check_key(uint32_t input, size_t idx_in) { if ((input >> idx_in) & 1) { @@ -54,13 +58,13 @@ uint32_t check_assign_light(uint32_t input, size_t idx_in, size_t gpio_out) void set_all_lights(bool on) { - ddr_io_set_lights_extio(on ? UINT32_MAX : 0); - ddr_io_set_lights_p3io(on ? UINT32_MAX : 0); - ddr_io_set_lights_hdxs_panel(on ? UINT32_MAX : 0); + bt_io_ddr_extio_lights_set(on ? UINT32_MAX : 0); + bt_io_ddr_p3io_lights_set(on ? UINT32_MAX : 0); + bt_io_ddr_hdxs_lights_panel_set(on ? UINT32_MAX : 0); for (int i = 0; i < 4; i++) { uint8_t val = on ? UINT8_MAX : 0; - ddr_io_set_lights_hdxs_rgb(i, val, val, val); + bt_io_ddr_hdxs_lights_rgb_set(i, val, val, val); } } @@ -70,73 +74,95 @@ void set_reactive_lights(uint32_t input_state) uint32_t new_p3io_state = 0; uint32_t new_hdxs_state = 0; - new_extio_state |= check_assign_light(input_state, DDR_P1_UP, LIGHT_P1_UP); - new_extio_state |= - check_assign_light(input_state, DDR_P1_DOWN, LIGHT_P1_DOWN); - new_extio_state |= - check_assign_light(input_state, DDR_P1_LEFT, LIGHT_P1_LEFT); - new_extio_state |= - check_assign_light(input_state, DDR_P1_RIGHT, LIGHT_P1_RIGHT); + new_extio_state |= check_assign_light( + input_state, BT_IO_DDR_P1_UP, BT_IO_DDR_EXTIO_LIGHT_P1_UP); + new_extio_state |= check_assign_light( + input_state, BT_IO_DDR_P1_DOWN, BT_IO_DDR_EXTIO_LIGHT_P1_DOWN); + new_extio_state |= check_assign_light( + input_state, BT_IO_DDR_P1_LEFT, BT_IO_DDR_EXTIO_LIGHT_P1_LEFT); + new_extio_state |= check_assign_light( + input_state, BT_IO_DDR_P1_RIGHT, BT_IO_DDR_EXTIO_LIGHT_P1_RIGHT); - new_extio_state |= check_assign_light(input_state, DDR_P2_UP, LIGHT_P2_UP); - new_extio_state |= - check_assign_light(input_state, DDR_P2_DOWN, LIGHT_P2_DOWN); - new_extio_state |= - check_assign_light(input_state, DDR_P2_LEFT, LIGHT_P2_LEFT); - new_extio_state |= - check_assign_light(input_state, DDR_P2_RIGHT, LIGHT_P2_RIGHT); + new_extio_state |= check_assign_light( + input_state, BT_IO_DDR_P2_UP, BT_IO_DDR_EXTIO_LIGHT_P2_UP); + new_extio_state |= check_assign_light( + input_state, BT_IO_DDR_P2_DOWN, BT_IO_DDR_EXTIO_LIGHT_P2_DOWN); + new_extio_state |= check_assign_light( + input_state, BT_IO_DDR_P2_LEFT, BT_IO_DDR_EXTIO_LIGHT_P2_LEFT); + new_extio_state |= check_assign_light( + input_state, BT_IO_DDR_P2_RIGHT, BT_IO_DDR_EXTIO_LIGHT_P2_RIGHT); - new_p3io_state |= - check_assign_light(input_state, DDR_P1_START, LIGHT_P1_MENU); - new_p3io_state |= - check_assign_light(input_state, DDR_P2_START, LIGHT_P2_MENU); + new_p3io_state |= check_assign_light( + input_state, BT_IO_DDR_P1_START, BT_IO_DDR_P3IO_LIGHT_P1_MENU); + new_p3io_state |= check_assign_light( + input_state, BT_IO_DDR_P2_START, BT_IO_DDR_P3IO_LIGHT_P2_MENU); - new_hdxs_state |= - check_assign_light(input_state, DDR_P1_START, LIGHT_HD_P1_START); - new_hdxs_state |= - check_assign_light(input_state, DDR_P1_MENU_UP, LIGHT_HD_P1_UP_DOWN); - new_hdxs_state |= - check_assign_light(input_state, DDR_P1_MENU_DOWN, LIGHT_HD_P1_UP_DOWN); new_hdxs_state |= check_assign_light( - input_state, DDR_P1_MENU_LEFT, LIGHT_HD_P1_LEFT_RIGHT); + input_state, BT_IO_DDR_P1_START, BT_IO_DDR_HDXS_LIGHT_HD_P1_START); new_hdxs_state |= check_assign_light( - input_state, DDR_P1_MENU_RIGHT, LIGHT_HD_P1_LEFT_RIGHT); + input_state, BT_IO_DDR_P1_MENU_UP, BT_IO_DDR_HDXS_LIGHT_HD_P1_UP_DOWN); + new_hdxs_state |= check_assign_light( + input_state, + BT_IO_DDR_P1_MENU_DOWN, + BT_IO_DDR_HDXS_LIGHT_HD_P1_UP_DOWN); + new_hdxs_state |= check_assign_light( + input_state, + BT_IO_DDR_P1_MENU_LEFT, + BT_IO_DDR_HDXS_LIGHT_HD_P1_LEFT_RIGHT); + new_hdxs_state |= check_assign_light( + input_state, + BT_IO_DDR_P1_MENU_RIGHT, + BT_IO_DDR_HDXS_LIGHT_HD_P1_LEFT_RIGHT); - new_hdxs_state |= - check_assign_light(input_state, DDR_P2_START, LIGHT_HD_P2_START); - new_hdxs_state |= - check_assign_light(input_state, DDR_P2_MENU_UP, LIGHT_HD_P2_UP_DOWN); - new_hdxs_state |= - check_assign_light(input_state, DDR_P2_MENU_DOWN, LIGHT_HD_P2_UP_DOWN); new_hdxs_state |= check_assign_light( - input_state, DDR_P2_MENU_LEFT, LIGHT_HD_P2_LEFT_RIGHT); + input_state, BT_IO_DDR_P2_START, BT_IO_DDR_HDXS_LIGHT_HD_P2_START); new_hdxs_state |= check_assign_light( - input_state, DDR_P2_MENU_RIGHT, LIGHT_HD_P2_LEFT_RIGHT); + input_state, BT_IO_DDR_P2_MENU_UP, BT_IO_DDR_HDXS_LIGHT_HD_P2_UP_DOWN); + new_hdxs_state |= check_assign_light( + input_state, + BT_IO_DDR_P2_MENU_DOWN, + BT_IO_DDR_HDXS_LIGHT_HD_P2_UP_DOWN); + new_hdxs_state |= check_assign_light( + input_state, + BT_IO_DDR_P2_MENU_LEFT, + BT_IO_DDR_HDXS_LIGHT_HD_P2_LEFT_RIGHT); + new_hdxs_state |= check_assign_light( + input_state, + BT_IO_DDR_P2_MENU_RIGHT, + BT_IO_DDR_HDXS_LIGHT_HD_P2_LEFT_RIGHT); - ddr_io_set_lights_extio(new_extio_state); - ddr_io_set_lights_p3io(new_p3io_state); - ddr_io_set_lights_hdxs_panel(new_hdxs_state); + bt_io_ddr_extio_lights_set(new_extio_state); + bt_io_ddr_p3io_lights_set(new_p3io_state); + bt_io_ddr_hdxs_lights_panel_set(new_hdxs_state); +} + +static void _module_io_ddr_init(module_io_t **module) +{ + bt_io_ddr_api_t api; + + module_io_ext_load_and_init( + "ddrio.dll", "bt_module_io_ddr_api_get", module); + module_io_api_get(*module, &api); + bt_io_ddr_api_set(&api); } int main(int argc, char **argv) { - core_thread_crt_ext_impl_set(); - core_log_bt_ext_impl_set(); + core_log_bt_core_api_set(); + core_thread_crt_core_api_set(); core_log_bt_ext_init_with_stdout(); core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_INFO); struct vigem_ddrio_config config; + if (!get_vigem_ddrio_config(&config)) { exit(EXIT_FAILURE); } - core_log_impl_assign(ddr_io_set_loggers); + _module_io_ddr_init(&_module_io_ddr); - if (!ddr_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_ddr_init()) { log_warning("Initializing ddrio failed"); return -1; } @@ -164,7 +190,9 @@ int main(int argc, char **argv) } if (failed) { - ddr_io_fini(); + bt_io_ddr_fini(); + bt_io_ddr_api_clear(); + module_io_free(&_module_io_ddr); return -1; } @@ -175,59 +203,59 @@ int main(int argc, char **argv) log_info("vigem init succeeded, beginning poll loop"); while (loop) { - pad_state = ddr_io_read_pad(); + pad_state = bt_io_ddr_pad_read(); for (uint8_t i = 0; i < NUM_PADS; i++) { memset(&state[i], 0, sizeof(state[i])); } + state[0].wButtons |= check_assign_key( + pad_state, BT_IO_DDR_TEST, XUSB_GAMEPAD_LEFT_THUMB); + state[0].wButtons |= check_assign_key( + pad_state, BT_IO_DDR_SERVICE, XUSB_GAMEPAD_RIGHT_THUMB); state[0].wButtons |= - check_assign_key(pad_state, DDR_TEST, XUSB_GAMEPAD_LEFT_THUMB); - state[0].wButtons |= - check_assign_key(pad_state, DDR_SERVICE, XUSB_GAMEPAD_RIGHT_THUMB); - state[0].wButtons |= - check_assign_key(pad_state, DDR_COIN, XUSB_GAMEPAD_BACK); + check_assign_key(pad_state, BT_IO_DDR_COIN, XUSB_GAMEPAD_BACK); // assign arrows to face buttons due to jumps / hat interpretation state[0].wButtons |= - check_assign_key(pad_state, DDR_P1_UP, XUSB_GAMEPAD_Y); + check_assign_key(pad_state, BT_IO_DDR_P1_UP, XUSB_GAMEPAD_Y); state[0].wButtons |= - check_assign_key(pad_state, DDR_P1_DOWN, XUSB_GAMEPAD_A); + check_assign_key(pad_state, BT_IO_DDR_P1_DOWN, XUSB_GAMEPAD_A); state[0].wButtons |= - check_assign_key(pad_state, DDR_P1_LEFT, XUSB_GAMEPAD_X); + check_assign_key(pad_state, BT_IO_DDR_P1_LEFT, XUSB_GAMEPAD_X); state[0].wButtons |= - check_assign_key(pad_state, DDR_P1_RIGHT, XUSB_GAMEPAD_B); + check_assign_key(pad_state, BT_IO_DDR_P1_RIGHT, XUSB_GAMEPAD_B); state[0].wButtons |= - check_assign_key(pad_state, DDR_P1_START, XUSB_GAMEPAD_START); - state[0].wButtons |= - check_assign_key(pad_state, DDR_P1_MENU_UP, XUSB_GAMEPAD_DPAD_UP); + check_assign_key(pad_state, BT_IO_DDR_P1_START, XUSB_GAMEPAD_START); state[0].wButtons |= check_assign_key( - pad_state, DDR_P1_MENU_DOWN, XUSB_GAMEPAD_DPAD_DOWN); + pad_state, BT_IO_DDR_P1_MENU_UP, XUSB_GAMEPAD_DPAD_UP); state[0].wButtons |= check_assign_key( - pad_state, DDR_P1_MENU_LEFT, XUSB_GAMEPAD_DPAD_LEFT); + pad_state, BT_IO_DDR_P1_MENU_DOWN, XUSB_GAMEPAD_DPAD_DOWN); state[0].wButtons |= check_assign_key( - pad_state, DDR_P1_MENU_RIGHT, XUSB_GAMEPAD_DPAD_RIGHT); + pad_state, BT_IO_DDR_P1_MENU_LEFT, XUSB_GAMEPAD_DPAD_LEFT); + state[0].wButtons |= check_assign_key( + pad_state, BT_IO_DDR_P1_MENU_RIGHT, XUSB_GAMEPAD_DPAD_RIGHT); state[1].wButtons |= - check_assign_key(pad_state, DDR_P2_UP, XUSB_GAMEPAD_Y); + check_assign_key(pad_state, BT_IO_DDR_P2_UP, XUSB_GAMEPAD_Y); state[1].wButtons |= - check_assign_key(pad_state, DDR_P2_DOWN, XUSB_GAMEPAD_A); + check_assign_key(pad_state, BT_IO_DDR_P2_DOWN, XUSB_GAMEPAD_A); state[1].wButtons |= - check_assign_key(pad_state, DDR_P2_LEFT, XUSB_GAMEPAD_X); + check_assign_key(pad_state, BT_IO_DDR_P2_LEFT, XUSB_GAMEPAD_X); state[1].wButtons |= - check_assign_key(pad_state, DDR_P2_RIGHT, XUSB_GAMEPAD_B); + check_assign_key(pad_state, BT_IO_DDR_P2_RIGHT, XUSB_GAMEPAD_B); state[1].wButtons |= - check_assign_key(pad_state, DDR_P2_START, XUSB_GAMEPAD_START); - state[1].wButtons |= - check_assign_key(pad_state, DDR_P2_MENU_UP, XUSB_GAMEPAD_DPAD_UP); + check_assign_key(pad_state, BT_IO_DDR_P2_START, XUSB_GAMEPAD_START); state[1].wButtons |= check_assign_key( - pad_state, DDR_P2_MENU_DOWN, XUSB_GAMEPAD_DPAD_DOWN); + pad_state, BT_IO_DDR_P2_MENU_UP, XUSB_GAMEPAD_DPAD_UP); state[1].wButtons |= check_assign_key( - pad_state, DDR_P2_MENU_LEFT, XUSB_GAMEPAD_DPAD_LEFT); + pad_state, BT_IO_DDR_P2_MENU_DOWN, XUSB_GAMEPAD_DPAD_DOWN); state[1].wButtons |= check_assign_key( - pad_state, DDR_P2_MENU_RIGHT, XUSB_GAMEPAD_DPAD_RIGHT); + pad_state, BT_IO_DDR_P2_MENU_LEFT, XUSB_GAMEPAD_DPAD_LEFT); + state[1].wButtons |= check_assign_key( + pad_state, BT_IO_DDR_P2_MENU_RIGHT, XUSB_GAMEPAD_DPAD_RIGHT); for (uint8_t i = 0; i < NUM_PADS; i++) { vigem_target_x360_update(client, pad[i], state[i]); @@ -237,8 +265,8 @@ int main(int argc, char **argv) set_reactive_lights(pad_state); } - if (check_key(pad_state, DDR_TEST) && - check_key(pad_state, DDR_SERVICE)) { + if (check_key(pad_state, BT_IO_DDR_TEST) && + check_key(pad_state, BT_IO_DDR_SERVICE)) { loop = false; } @@ -252,7 +280,10 @@ int main(int argc, char **argv) } vigem_free(client); - ddr_io_fini(); + + bt_io_ddr_fini(); + bt_io_ddr_api_clear(); + module_io_free(&_module_io_ddr); return 0; } diff --git a/src/main/vigem-iidxio/Module.mk b/src/main/vigem-iidxio/Module.mk index 4fae200..656fc77 100644 --- a/src/main/vigem-iidxio/Module.mk +++ b/src/main/vigem-iidxio/Module.mk @@ -12,9 +12,13 @@ ldflags_vigem-iidxio := \ libs_vigem-iidxio := \ core \ cconfig \ - iidxio \ util \ vigemstub \ + module \ + ezusb \ + iface \ + iface-io \ + iface-core \ src_vigem-iidxio := \ cab-16seg-sequencer.c \ diff --git a/src/main/vigem-iidxio/cab-16seg-sequencer.c b/src/main/vigem-iidxio/cab-16seg-sequencer.c index f7e6e05..14e2c8f 100644 --- a/src/main/vigem-iidxio/cab-16seg-sequencer.c +++ b/src/main/vigem-iidxio/cab-16seg-sequencer.c @@ -4,7 +4,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "util/time.h" diff --git a/src/main/vigem-iidxio/cab-light-sequencer.c b/src/main/vigem-iidxio/cab-light-sequencer.c index 6b345b7..99a2fa9 100644 --- a/src/main/vigem-iidxio/cab-light-sequencer.c +++ b/src/main/vigem-iidxio/cab-light-sequencer.c @@ -4,7 +4,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "vigem-iidxio/cab-light-sequencer.h" diff --git a/src/main/vigem-iidxio/config.c b/src/main/vigem-iidxio/config.c index acf5235..89a61c7 100644 --- a/src/main/vigem-iidxio/config.c +++ b/src/main/vigem-iidxio/config.c @@ -1,7 +1,7 @@ #include "cconfig/cconfig-main.h" #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "vigem-iidxio/config.h" diff --git a/src/main/vigem-iidxio/main.c b/src/main/vigem-iidxio/main.c index 51b0b14..1d26d01 100644 --- a/src/main/vigem-iidxio/main.c +++ b/src/main/vigem-iidxio/main.c @@ -7,14 +7,17 @@ #include -#include "bemanitools/iidxio.h" - #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" #include "core/thread-crt.h" -#include "core/thread.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/iidx.h" + +#include "module/io-ext.h" +#include "module/io.h" #include "util/math.h" #include "util/time.h" @@ -28,6 +31,8 @@ #define JOYSTICKS_NUM 3 #define TURNTABLE_NUM 2 +static module_io_t *_module_io_iidx; + static uint8_t _tt_last_raw[TURNTABLE_NUM]; static int32_t _tt_state_for_analog[TURNTABLE_NUM]; static int16_t _tt_state_for_btn[TURNTABLE_NUM]; @@ -200,72 +205,82 @@ static void _handle_turntable( static void _handle_buttons_14keys(uint16_t keys, XUSB_REPORT *state) { state[0].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P1_1, XUSB_GAMEPAD_A); + _check_assign_key(keys, BT_IO_IIDX_KEY_P1_1, XUSB_GAMEPAD_A); state[0].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P1_2, XUSB_GAMEPAD_B); + _check_assign_key(keys, BT_IO_IIDX_KEY_P1_2, XUSB_GAMEPAD_B); state[0].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P1_3, XUSB_GAMEPAD_X); + _check_assign_key(keys, BT_IO_IIDX_KEY_P1_3, XUSB_GAMEPAD_X); state[0].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P1_4, XUSB_GAMEPAD_Y); + _check_assign_key(keys, BT_IO_IIDX_KEY_P1_4, XUSB_GAMEPAD_Y); + state[0].wButtons |= _check_assign_key( + keys, BT_IO_IIDX_KEY_P1_5, XUSB_GAMEPAD_LEFT_SHOULDER); + state[0].wButtons |= _check_assign_key( + keys, BT_IO_IIDX_KEY_P1_6, XUSB_GAMEPAD_RIGHT_SHOULDER); state[0].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P1_5, XUSB_GAMEPAD_LEFT_SHOULDER); - state[0].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P1_6, XUSB_GAMEPAD_RIGHT_SHOULDER); - state[0].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P1_7, XUSB_GAMEPAD_BACK); + _check_assign_key(keys, BT_IO_IIDX_KEY_P1_7, XUSB_GAMEPAD_BACK); state[1].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P2_1, XUSB_GAMEPAD_A); + _check_assign_key(keys, BT_IO_IIDX_KEY_P2_1, XUSB_GAMEPAD_A); state[1].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P2_2, XUSB_GAMEPAD_B); + _check_assign_key(keys, BT_IO_IIDX_KEY_P2_2, XUSB_GAMEPAD_B); state[1].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P2_3, XUSB_GAMEPAD_X); + _check_assign_key(keys, BT_IO_IIDX_KEY_P2_3, XUSB_GAMEPAD_X); state[1].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P2_4, XUSB_GAMEPAD_Y); + _check_assign_key(keys, BT_IO_IIDX_KEY_P2_4, XUSB_GAMEPAD_Y); + state[1].wButtons |= _check_assign_key( + keys, BT_IO_IIDX_KEY_P2_5, XUSB_GAMEPAD_LEFT_SHOULDER); + state[1].wButtons |= _check_assign_key( + keys, BT_IO_IIDX_KEY_P2_6, XUSB_GAMEPAD_RIGHT_SHOULDER); state[1].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P2_5, XUSB_GAMEPAD_LEFT_SHOULDER); - state[1].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P2_6, XUSB_GAMEPAD_RIGHT_SHOULDER); - state[1].wButtons |= - _check_assign_key(keys, IIDX_IO_KEY_P2_7, XUSB_GAMEPAD_BACK); + _check_assign_key(keys, BT_IO_IIDX_KEY_P2_7, XUSB_GAMEPAD_BACK); } static void _handle_buttons_panel(uint8_t panel, XUSB_REPORT *state) { state[0].wButtons |= _check_assign_key( - panel, IIDX_IO_PANEL_LIGHT_P1_START, XUSB_GAMEPAD_START); + panel, BT_IO_IIDX_PANEL_LIGHT_P1_START, XUSB_GAMEPAD_START); state[1].wButtons |= _check_assign_key( - panel, IIDX_IO_PANEL_LIGHT_P2_START, XUSB_GAMEPAD_START); + panel, BT_IO_IIDX_PANEL_LIGHT_P2_START, XUSB_GAMEPAD_START); state[2].wButtons |= - _check_assign_key(panel, IIDX_IO_PANEL_LIGHT_VEFX, XUSB_GAMEPAD_B); + _check_assign_key(panel, BT_IO_IIDX_PANEL_LIGHT_VEFX, XUSB_GAMEPAD_B); state[2].wButtons |= - _check_assign_key(panel, IIDX_IO_PANEL_LIGHT_EFFECT, XUSB_GAMEPAD_A); + _check_assign_key(panel, BT_IO_IIDX_PANEL_LIGHT_EFFECT, XUSB_GAMEPAD_A); } static void _handle_buttons_system(uint8_t system, XUSB_REPORT *state) { state[2].wButtons |= - _check_assign_key(system, IIDX_IO_SYS_TEST, XUSB_GAMEPAD_X); + _check_assign_key(system, BT_IO_IIDX_SYS_TEST, XUSB_GAMEPAD_X); state[2].wButtons |= - _check_assign_key(system, IIDX_IO_SYS_SERVICE, XUSB_GAMEPAD_Y); + _check_assign_key(system, BT_IO_IIDX_SYS_SERVICE, XUSB_GAMEPAD_Y); state[2].wButtons |= - _check_assign_key(system, IIDX_IO_SYS_COIN, XUSB_GAMEPAD_START); + _check_assign_key(system, BT_IO_IIDX_SYS_COIN, XUSB_GAMEPAD_START); } static void _all_lights_off() { - iidx_io_ep1_set_deck_lights(0); - iidx_io_ep1_set_panel_lights(0); - iidx_io_ep1_set_top_lamps(0); - iidx_io_ep1_set_top_neons(false); - iidx_io_ep3_write_16seg(" "); + bt_io_iidx_ep1_deck_lights_set(0); + bt_io_iidx_ep1_panel_lights_set(0); + bt_io_iidx_ep1_top_lamps_set(0); + bt_io_iidx_ep1_top_neons_set(false); + bt_io_iidx_ep3_16seg_send(" "); +} + +static void _io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); } int main(int argc, char **argv) { - core_thread_crt_ext_impl_set(); - core_log_bt_ext_impl_set(); + core_thread_crt_core_api_set(); + core_log_bt_core_api_set(); core_log_bt_ext_init_with_stdout(); @@ -275,12 +290,9 @@ int main(int argc, char **argv) return -1; } - core_log_impl_assign(iidx_io_set_loggers); + _io_iidx_init(&_module_io_iidx); - if (!iidx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_iidx_init()) { log_warning("Initializing iidxio failed"); return -1; } @@ -290,7 +302,10 @@ int main(int argc, char **argv) if (!client) { log_warning("VIGEM client failed to connect"); - iidx_io_fini(); + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&_module_io_iidx); return -1; } @@ -310,7 +325,11 @@ int main(int argc, char **argv) } if (failed) { - iidx_io_fini(); + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&_module_io_iidx); + return -1; } @@ -336,16 +355,16 @@ int main(int argc, char **argv) memset(&state[i], 0, sizeof(state[i])); } - if (!iidx_io_ep2_recv()) { + if (!bt_io_iidx_ep2_recv()) { log_warning("iidxio receiving failed"); break; } // Keys/buttons - uint16_t keys = iidx_io_ep2_get_keys(); - uint8_t panel = iidx_io_ep2_get_panel(); - uint8_t system = iidx_io_ep2_get_sys(); + uint16_t keys = bt_io_iidx_ep2_keys_get(); + uint8_t panel = bt_io_iidx_ep2_panel_get(); + uint8_t system = bt_io_iidx_ep2_sys_get(); _handle_buttons_14keys(keys, state); _handle_buttons_panel(panel, state); @@ -356,7 +375,7 @@ int main(int argc, char **argv) uint8_t turntable[TURNTABLE_NUM]; for (uint8_t i = 0; i < TURNTABLE_NUM; i++) { - turntable[i] = iidx_io_ep2_get_turntable(i); + turntable[i] = bt_io_iidx_ep2_turntable_get(i); } _handle_turntable(&config, turntable, state); @@ -372,8 +391,8 @@ int main(int argc, char **argv) // Light related outputs if (config.cab_light.enable_keylight) { - iidx_io_ep1_set_deck_lights(keys); - iidx_io_ep1_set_panel_lights(panel); + bt_io_iidx_ep1_deck_lights_set(keys); + bt_io_iidx_ep1_panel_lights_set(panel); } if (config.cab_light.light_mode != LIGHT_SEQ_MODE_OFF) { @@ -386,24 +405,24 @@ int main(int argc, char **argv) vigem_iidxio_cab_light_sequencer_update( keys, turntable[0], turntable[1], &neon, &spots); - iidx_io_ep1_set_top_neons(neon); - iidx_io_ep1_set_top_lamps(spots); + bt_io_iidx_ep1_top_neons_set(neon); + bt_io_iidx_ep1_top_lamps_set(spots); } if (config.cab_light.text_16seg[0] != '\0') { char buffer_16seg[9]; vigem_iidxio_cab_16seg_sequencer_update(buffer_16seg); - iidx_io_ep3_write_16seg(buffer_16seg); + bt_io_iidx_ep3_16seg_send(buffer_16seg); } - if (!iidx_io_ep1_send()) { + if (!bt_io_iidx_ep1_send()) { log_warning("iidxio sending failed"); break; } - if (_check_key(system, IIDX_IO_SYS_TEST) && - _check_key(system, IIDX_IO_SYS_SERVICE)) { + if (_check_key(system, BT_IO_IIDX_SYS_TEST) && + _check_key(system, BT_IO_IIDX_SYS_SERVICE)) { log_info("Test + service pressed, exiting..."); loop = false; } @@ -423,7 +442,10 @@ int main(int argc, char **argv) _all_lights_off(); - iidx_io_fini(); + bt_io_iidx_fini(); + + bt_io_iidx_api_clear(); + module_io_free(&_module_io_iidx); return 0; } diff --git a/src/main/vigem-sdvxio/Module.mk b/src/main/vigem-sdvxio/Module.mk index 523dd69..7c3e08e 100644 --- a/src/main/vigem-sdvxio/Module.mk +++ b/src/main/vigem-sdvxio/Module.mk @@ -12,9 +12,12 @@ ldflags_vigem-sdvxio := \ libs_vigem-sdvxio := \ core \ cconfig \ - sdvxio \ util \ vigemstub \ + module \ + iface \ + iface-io \ + iface-core \ src_vigem-sdvxio := \ main.c \ diff --git a/src/main/vigem-sdvxio/config-vigem-sdvxio.c b/src/main/vigem-sdvxio/config-vigem-sdvxio.c index faae9e2..7cc3233 100644 --- a/src/main/vigem-sdvxio/config-vigem-sdvxio.c +++ b/src/main/vigem-sdvxio/config-vigem-sdvxio.c @@ -1,7 +1,7 @@ #include "cconfig/cconfig-main.h" #include "cconfig/cconfig-util.h" -#include "core/log.h" +#include "iface-core/log.h" #include "vigem-sdvxio/config-vigem-sdvxio.h" diff --git a/src/main/vigem-sdvxio/main.c b/src/main/vigem-sdvxio/main.c index c87a436..b578c1b 100644 --- a/src/main/vigem-sdvxio/main.c +++ b/src/main/vigem-sdvxio/main.c @@ -1,20 +1,23 @@ +#include + #include #include #include #include -#include - #include "ViGEm/Client.h" -#include "bemanitools/sdvxio.h" - #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" -#include "core/thread-crt-ext.h" #include "core/thread-crt.h" -#include "core/thread.h" + +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/sdvx.h" + +#include "module/io-ext.h" +#include "module/io.h" #include "util/math.h" @@ -24,6 +27,8 @@ #define ANALOG_FIXED_SENSITIVITY 1024 +static module_io_t *_module_io_sdvx; + int16_t convert_analog_to_s16(uint16_t val) { // val is 10 bit @@ -105,39 +110,50 @@ void gpio_keylight(uint16_t gpio0, uint16_t gpio1) uint16_t gpio_lights = 0; gpio_lights |= check_assign_gpio( - gpio0, SDVX_IO_IN_GPIO_0_START, SDVX_IO_OUT_GPIO_START); + gpio0, BT_IO_SDVX_IN_GPIO_0_START, BT_IO_SDVX_OUT_GPIO_START); gpio_lights |= - check_assign_gpio(gpio0, SDVX_IO_IN_GPIO_0_A, SDVX_IO_OUT_GPIO_A); + check_assign_gpio(gpio0, BT_IO_SDVX_IN_GPIO_0_A, BT_IO_SDVX_OUT_GPIO_A); gpio_lights |= - check_assign_gpio(gpio0, SDVX_IO_IN_GPIO_0_B, SDVX_IO_OUT_GPIO_B); + check_assign_gpio(gpio0, BT_IO_SDVX_IN_GPIO_0_B, BT_IO_SDVX_OUT_GPIO_B); gpio_lights |= - check_assign_gpio(gpio0, SDVX_IO_IN_GPIO_0_C, SDVX_IO_OUT_GPIO_C); + check_assign_gpio(gpio0, BT_IO_SDVX_IN_GPIO_0_C, BT_IO_SDVX_OUT_GPIO_C); gpio_lights |= - check_assign_gpio(gpio1, SDVX_IO_IN_GPIO_1_D, SDVX_IO_OUT_GPIO_D); - gpio_lights |= - check_assign_gpio(gpio1, SDVX_IO_IN_GPIO_1_FX_L, SDVX_IO_OUT_GPIO_FX_L); - gpio_lights |= - check_assign_gpio(gpio1, SDVX_IO_IN_GPIO_1_FX_R, SDVX_IO_OUT_GPIO_FX_R); + check_assign_gpio(gpio1, BT_IO_SDVX_IN_GPIO_1_D, BT_IO_SDVX_OUT_GPIO_D); + gpio_lights |= check_assign_gpio( + gpio1, BT_IO_SDVX_IN_GPIO_1_FX_L, BT_IO_SDVX_OUT_GPIO_FX_L); + gpio_lights |= check_assign_gpio( + gpio1, BT_IO_SDVX_IN_GPIO_1_FX_R, BT_IO_SDVX_OUT_GPIO_FX_R); - sdvx_io_set_gpio_lights(gpio_lights); + bt_io_sdvx_gpio_lights_set(gpio_lights); } void set_pwm_brightness(uint8_t wing_pwm, uint8_t controller_pwm) { // 0-11 are the 4 wings for (size_t i = 0; i < 12; ++i) { - sdvx_io_set_pwm_light(i, wing_pwm); + bt_io_sdvx_pwm_light_set(i, wing_pwm); } // 12-17 are the woofer / control deck for (size_t i = 12; i < 18; ++i) { - sdvx_io_set_pwm_light(i, controller_pwm); + bt_io_sdvx_pwm_light_set(i, controller_pwm); } } +static void _io_sdvx_init(module_io_t **module) +{ + bt_io_sdvx_api_t api; + + module_io_ext_load_and_init( + "sdvxio.dll", "bt_module_io_sdvx_api_get", module); + module_io_api_get(*module, &api); + bt_io_sdvx_api_set(&api); +} + int main(int argc, char **argv) { - core_thread_crt_ext_impl_set(); - core_log_bt_ext_impl_set(); + core_thread_crt_core_api_set(); + core_log_bt_core_api_set(); + core_log_bt_ext_init_with_stdout(); struct vigem_sdvxio_config config; @@ -145,23 +161,26 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - core_log_impl_assign(sdvx_io_set_loggers); + _io_sdvx_init(&_module_io_sdvx); - if (!sdvx_io_init( - core_thread_create_impl_get(), - core_thread_join_impl_get(), - core_thread_destroy_impl_get())) { + if (!bt_io_sdvx_init()) { log_warning("Initializing sdvxio failed"); return -1; } - sdvx_io_set_amp_volume( + bt_io_sdvx_amp_volume_set( config.amp_volume, config.amp_volume, config.amp_volume); PVIGEM_CLIENT client = vigem_helper_setup(); if (!client) { log_warning("client failed to connect failed"); + + bt_io_sdvx_fini(); + + bt_io_sdvx_api_clear(); + module_io_free(&_module_io_sdvx); + return -1; } @@ -169,6 +188,12 @@ int main(int argc, char **argv) if (!pad) { log_warning("vigem_alloc pad 1 failed"); + + bt_io_sdvx_fini(); + + bt_io_sdvx_api_clear(); + module_io_free(&_module_io_sdvx); + return -1; } @@ -187,14 +212,14 @@ int main(int argc, char **argv) log_info("vigem init succeeded, beginning poll loop"); while (loop) { - sdvx_io_read_input(); + bt_io_sdvx_input_read(); - sys = sdvx_io_get_input_gpio_sys(); - gpio0 = sdvx_io_get_input_gpio(0); - gpio1 = sdvx_io_get_input_gpio(1); + sys = bt_io_sdvx_input_gpio_sys_get(); + gpio0 = bt_io_sdvx_input_gpio_get(0); + gpio1 = bt_io_sdvx_input_gpio_get(1); - vol[0] = sdvx_io_get_spinner_pos(0); - vol[1] = sdvx_io_get_spinner_pos(1); + vol[0] = bt_io_sdvx_spinner_pos_get(0); + vol[1] = bt_io_sdvx_spinner_pos_get(1); memset(&state, 0, sizeof(state)); @@ -217,21 +242,21 @@ int main(int argc, char **argv) } state.wButtons |= check_assign_key( - gpio0, SDVX_IO_IN_GPIO_0_START, XUSB_GAMEPAD_START); - state.wButtons |= - check_assign_key(sys, SDVX_IO_IN_GPIO_SYS_TEST, XUSB_GAMEPAD_BACK); - state.wButtons |= - check_assign_key(gpio0, SDVX_IO_IN_GPIO_0_A, XUSB_GAMEPAD_A); - state.wButtons |= - check_assign_key(gpio0, SDVX_IO_IN_GPIO_0_B, XUSB_GAMEPAD_B); - state.wButtons |= - check_assign_key(gpio0, SDVX_IO_IN_GPIO_0_C, XUSB_GAMEPAD_X); - state.wButtons |= - check_assign_key(gpio1, SDVX_IO_IN_GPIO_1_D, XUSB_GAMEPAD_Y); + gpio0, BT_IO_SDVX_IN_GPIO_0_START, XUSB_GAMEPAD_START); state.wButtons |= check_assign_key( - gpio1, SDVX_IO_IN_GPIO_1_FX_L, XUSB_GAMEPAD_LEFT_SHOULDER); + sys, BT_IO_SDVX_IN_GPIO_SYS_TEST, XUSB_GAMEPAD_BACK); + state.wButtons |= + check_assign_key(gpio0, BT_IO_SDVX_IN_GPIO_0_A, XUSB_GAMEPAD_A); + state.wButtons |= + check_assign_key(gpio0, BT_IO_SDVX_IN_GPIO_0_B, XUSB_GAMEPAD_B); + state.wButtons |= + check_assign_key(gpio0, BT_IO_SDVX_IN_GPIO_0_C, XUSB_GAMEPAD_X); + state.wButtons |= + check_assign_key(gpio1, BT_IO_SDVX_IN_GPIO_1_D, XUSB_GAMEPAD_Y); state.wButtons |= check_assign_key( - gpio1, SDVX_IO_IN_GPIO_1_FX_R, XUSB_GAMEPAD_RIGHT_SHOULDER); + gpio1, BT_IO_SDVX_IN_GPIO_1_FX_L, XUSB_GAMEPAD_LEFT_SHOULDER); + state.wButtons |= check_assign_key( + gpio1, BT_IO_SDVX_IN_GPIO_1_FX_R, XUSB_GAMEPAD_RIGHT_SHOULDER); vigem_target_x360_update(client, pad, state); @@ -240,10 +265,10 @@ int main(int argc, char **argv) } set_pwm_brightness(config.pwm_wings, config.pwm_controller); - sdvx_io_write_output(); + bt_io_sdvx_output_write(); - if (check_key(sys, SDVX_IO_IN_GPIO_SYS_TEST) && - check_key(sys, SDVX_IO_IN_GPIO_SYS_SERVICE)) { + if (check_key(sys, BT_IO_SDVX_IN_GPIO_SYS_TEST) && + check_key(sys, BT_IO_SDVX_IN_GPIO_SYS_SERVICE)) { loop = false; } @@ -256,10 +281,13 @@ int main(int argc, char **argv) vigem_free(client); - sdvx_io_set_amp_volume(96, 96, 96); + bt_io_sdvx_amp_volume_set(96, 96, 96); Sleep(1000); - sdvx_io_fini(); + bt_io_sdvx_fini(); + + bt_io_sdvx_api_clear(); + module_io_free(&_module_io_sdvx); return 0; } diff --git a/src/main/vigemstub/helper.c b/src/main/vigemstub/helper.c index a92510b..791237f 100644 --- a/src/main/vigemstub/helper.c +++ b/src/main/vigemstub/helper.c @@ -2,7 +2,7 @@ #include #include -#include "core/log.h" +#include "iface-core/log.h" #include "ViGEm/Client.h" diff --git a/src/sdk/module/acio/mgr.h b/src/sdk/module/acio/mgr.h new file mode 100644 index 0000000..adab65d --- /dev/null +++ b/src/sdk/module/acio/mgr.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_ACIO_MGR_H +#define BT_SDK_ACIO_MGR_H + +#include "api/acio/mgr.h" + +void bt_module_acio_mgr_api_get(bt_acio_mgr_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/core/config.h b/src/sdk/module/core/config.h new file mode 100644 index 0000000..ac94176 --- /dev/null +++ b/src/sdk/module/core/config.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_CORE_CONFIG_H +#define BT_SDK_MODULE_CORE_CONFIG_H + +#include "api/core/config.h" + +void bt_module_core_config_api_set(const bt_core_config_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/core/log.h b/src/sdk/module/core/log.h new file mode 100644 index 0000000..9224b2e --- /dev/null +++ b/src/sdk/module/core/log.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_CORE_LOG_H +#define BT_SDK_MODULE_CORE_LOG_H + +#include "api/core/log.h" + +void bt_module_core_log_api_set(const bt_core_log_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/core/thread.h b/src/sdk/module/core/thread.h new file mode 100644 index 0000000..b719263 --- /dev/null +++ b/src/sdk/module/core/thread.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_CORE_THREAD_H +#define BT_SDK_MODULE_CORE_THREAD_H + +#include "api/core/thread.h" + +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/hook.h b/src/sdk/module/hook.h new file mode 100644 index 0000000..56cd519 --- /dev/null +++ b/src/sdk/module/hook.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_HOOK_H +#define BT_SDK_MODULE_HOOK_H + +#include "api/hook.h" + +void bt_module_hook_api_get(bt_hook_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/input.h b/src/sdk/module/input.h new file mode 100644 index 0000000..96fd14b --- /dev/null +++ b/src/sdk/module/input.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_INPUT_H +#define BT_SDK_MODULE_INPUT_H + +#include "api/input.h" + +void bt_module_input_api_set(const bt_input_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/io/bst.h b/src/sdk/module/io/bst.h new file mode 100644 index 0000000..5592196 --- /dev/null +++ b/src/sdk/module/io/bst.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_IO_BST_H +#define BT_SDK_MODULE_IO_BST_H + +#include "api/io/bst.h" + +void bt_module_io_bst_api_get(bt_io_bst_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/io/ddr.h b/src/sdk/module/io/ddr.h new file mode 100644 index 0000000..d006df5 --- /dev/null +++ b/src/sdk/module/io/ddr.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_IO_DDR_H +#define BT_SDK_MODULE_IO_DDR_H + +#include "api/io/ddr.h" + +void bt_module_io_ddr_api_get(bt_io_ddr_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/io/eam.h b/src/sdk/module/io/eam.h new file mode 100644 index 0000000..89ae6ce --- /dev/null +++ b/src/sdk/module/io/eam.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_IO_EAM_H +#define BT_SDK_MODULE_IO_EAM_H + +#include "api/io/eam.h" + +void bt_module_io_eam_api_get(bt_io_eam_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/io/iidx.h b/src/sdk/module/io/iidx.h new file mode 100644 index 0000000..cb8fb34 --- /dev/null +++ b/src/sdk/module/io/iidx.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_IO_IIDX_H +#define BT_SDK_MODULE_IO_IIDX_H + +#include "api/io/iidx.h" + +void bt_module_io_iidx_api_get(bt_io_iidx_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/io/jb.h b/src/sdk/module/io/jb.h new file mode 100644 index 0000000..709851b --- /dev/null +++ b/src/sdk/module/io/jb.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_IO_JB_H +#define BT_SDK_MODULE_IO_JB_H + +#include "api/io/jb.h" + +void bt_module_io_jb_api_get(bt_io_jb_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/io/popn.h b/src/sdk/module/io/popn.h new file mode 100644 index 0000000..ac09b0d --- /dev/null +++ b/src/sdk/module/io/popn.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_IO_POPN_H +#define BT_SDK_MODULE_IO_POPN_H + +#include "api/io/popn.h" + +void bt_module_io_popn_api_get(bt_io_popn_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/io/sdvx.h b/src/sdk/module/io/sdvx.h new file mode 100644 index 0000000..648e640 --- /dev/null +++ b/src/sdk/module/io/sdvx.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_IO_SDVX_H +#define BT_SDK_MODULE_IO_SDVX_H + +#include "api/io/sdvx.h" + +void bt_module_io_sdvx_api_get(bt_io_sdvx_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/module/io/vefx.h b/src/sdk/module/io/vefx.h new file mode 100644 index 0000000..4e63601 --- /dev/null +++ b/src/sdk/module/io/vefx.h @@ -0,0 +1,8 @@ +#ifndef BT_SDK_MODULE_IO_VEFX_H +#define BT_SDK_MODULE_IO_VEFX_H + +#include "api/io/vefx.h" + +void bt_module_io_vefx_api_get(bt_io_vefx_api_t *api); + +#endif \ No newline at end of file diff --git a/src/sdk/version.h b/src/sdk/version.h new file mode 100644 index 0000000..e69de29 diff --git a/src/test/cconfig/Module.mk b/src/test/cconfig/Module.mk index 8143389..6d80a61 100644 --- a/src/test/cconfig/Module.mk +++ b/src/test/cconfig/Module.mk @@ -7,6 +7,7 @@ libs_cconfig-test := \ cconfig \ test \ util \ + iface-core \ src_cconfig-test := \ cconfig-test.c \ @@ -22,6 +23,7 @@ libs_cconfig-util-test := \ cconfig \ test \ util \ + iface-core \ src_cconfig-util-test := \ cconfig-util-test.c \ @@ -37,6 +39,7 @@ libs_cconfig-cmd-test := \ cconfig \ test \ util \ + iface-core \ src_cconfig-cmd-test := \ cconfig-cmd-test.c \ diff --git a/src/test/d3d9hook/Module.mk b/src/test/d3d9hook/Module.mk index 3ab336b..eac964f 100644 --- a/src/test/d3d9hook/Module.mk +++ b/src/test/d3d9hook/Module.mk @@ -9,6 +9,7 @@ libs_d3d9hook := \ hook \ test \ util \ + iface-core \ src_d3d9hook := \ dllmain.c \ @@ -27,6 +28,7 @@ libs_d3d9hook-test := \ test \ util \ core \ + iface-core \ src_d3d9hook-test := \ main.c \ diff --git a/src/test/d3d9hook/dllmain.c b/src/test/d3d9hook/dllmain.c index e7052df..5253975 100644 --- a/src/test/d3d9hook/dllmain.c +++ b/src/test/d3d9hook/dllmain.c @@ -4,7 +4,9 @@ #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" +#include "core/log-sink-std.h" + +#include "iface-core/log.h" #include "hook/d3d9.h" @@ -300,8 +302,10 @@ static HRESULT my_d3d9_handler(struct hook_d3d9_irp *irp) BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - core_log_bt_ext_init_with_debug(); + core_log_bt_core_api_set(); + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); debug_print("Initializing d3d9 hook module...\n"); diff --git a/src/test/iidxhook-util/Module.mk b/src/test/iidxhook-util/Module.mk index 49fdda9..db92ede 100644 --- a/src/test/iidxhook-util/Module.mk +++ b/src/test/iidxhook-util/Module.mk @@ -12,6 +12,7 @@ libs_iidxhook-util-config-eamuse-test := \ cconfig \ test \ util \ + iface-core \ src_iidxhook-util-config-eamuse-test := \ iidxhook-util-config-eamuse-test.c \ @@ -29,6 +30,7 @@ libs_iidxhook-util-config-gfx-test := \ cconfig \ test \ util \ + iface-core \ src_iidxhook-util-config-gfx-test := \ iidxhook-util-config-gfx-test.c \ @@ -46,6 +48,7 @@ libs_iidxhook-util-config-misc-test := \ cconfig \ test \ util \ + iface-core \ src_iidxhook-util-config-misc-test := \ iidxhook-util-config-misc-test.c \ @@ -63,6 +66,7 @@ libs_iidxhook-util-config-sec-test := \ cconfig \ test \ util \ + iface-core \ src_iidxhook-util-config-sec-test := \ iidxhook-util-config-sec-test.c \ diff --git a/src/test/iidxhook/Module.mk b/src/test/iidxhook/Module.mk index 9172fa5..df8f12d 100644 --- a/src/test/iidxhook/Module.mk +++ b/src/test/iidxhook/Module.mk @@ -8,6 +8,7 @@ libs_iidxhook-config-iidxhook1-test := \ iidxhook1 \ test \ util \ + iface-core \ src_iidxhook-config-iidxhook1-test := \ iidxhook-config-iidxhook1-test.c \ @@ -24,6 +25,7 @@ libs_iidxhook-config-iidxhook2-test := \ cconfig \ test \ util \ + iface-core \ src_iidxhook-config-iidxhook2-test := \ iidxhook-config-iidxhook2-test.c \ diff --git a/src/test/iidxhook8/Module.mk b/src/test/iidxhook8/Module.mk index 3cccd42..3de16a8 100644 --- a/src/test/iidxhook8/Module.mk +++ b/src/test/iidxhook8/Module.mk @@ -8,6 +8,7 @@ libs_iidxhook8-config-cam-test := \ cconfig \ test \ util \ + iface-core \ src_iidxhook8-config-cam-test := \ iidxhook8-config-cam-test.c \ @@ -23,6 +24,7 @@ libs_iidxhook8-config-io-test := \ cconfig \ test \ util \ + iface-core \ src_iidxhook8-config-io-test := \ iidxhook8-config-io-test.c \ diff --git a/src/test/security/Module.mk b/src/test/security/Module.mk index 7ac51d7..18867a4 100644 --- a/src/test/security/Module.mk +++ b/src/test/security/Module.mk @@ -7,6 +7,7 @@ libs_security-id-test := \ security \ test \ util \ + iface-core \ src_security-id-test := \ security-id-test.c \ @@ -22,6 +23,7 @@ libs_security-mcode-test := \ security \ test \ util \ + iface-core \ src_security-mcode-test := \ security-mcode-test.c \ @@ -37,6 +39,7 @@ libs_security-util-test := \ security \ test \ util \ + iface-core \ src_security-util-test := \ security-util-test.c \ @@ -52,6 +55,7 @@ libs_security-rp-test := \ security \ test \ util \ + iface-core \ src_security-rp-test := \ security-rp-test.c \ @@ -67,6 +71,7 @@ libs_security-rp2-test := \ security \ test \ util \ + iface-core \ src_security-rp2-test := \ security-rp2-test.c \ @@ -82,6 +87,7 @@ libs_security-rp3-test := \ security \ test \ util \ + iface-core \ src_security-rp3-test := \ security-rp3-test.c \ diff --git a/src/test/test/test.h b/src/test/test/test.h index 7d0dda0..e9b48e3 100644 --- a/src/test/test/test.h +++ b/src/test/test/test.h @@ -5,13 +5,16 @@ #include "core/log-bt-ext.h" #include "core/log-bt.h" -#include "core/log.h" -#define TEST_MODULE_BEGIN(name) \ - int main(int argc, char **argv) \ - { \ - core_log_bt_ext_impl_set(); \ - core_log_bt_ext_init_with_stderr(); \ +#include "iface-core/log.h" + +#define TEST_MODULE_BEGIN(name) \ + int main(int argc, char **argv) \ + { \ + core_log_bt_core_api_set(); \ + \ + core_log_bt_ext_init_with_stderr(); \ + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); \ fprintf(stderr, "Executing test module '%s'...\n", #name); #define TEST_MODULE_TEST(func) \ diff --git a/src/test/util/Module.mk b/src/test/util/Module.mk index 90f3424..1b65d0d 100644 --- a/src/test/util/Module.mk +++ b/src/test/util/Module.mk @@ -10,6 +10,7 @@ libs_util-net-test := \ core \ test \ util \ + iface-core \ src_util-net-test := \ util-net-test.c \ diff --git a/todo.md b/todo.md new file mode 100644 index 0000000..4f7e82e --- /dev/null +++ b/todo.md @@ -0,0 +1,104 @@ +# Bemanitools 6 TODOs + +Lose list of TODOs/notes/thoughts that might or might not need to worked on. Some of these are +already sorted and moved to separate sub-sections outlining some kind of "roadmap". + +## Alpha 2 + +goal: fix inefficient logging causing stuttering and unify across launcher/inject + +new plan: +* bt-log as its own async logging engine with ring buffer +* don't use AVS loggers anymore, don't need to use AVS threads either then +* gets rid of log-server in iidx since all logging in btools goes through bt-log engine +* log sink needs to be setup with a mutex to ensure log messages aren't split + * since AVS and btools log engines are async then, this is fine +* can also simplify the whole logging API stuff since there is only one API impl + needed + +* avs log server in iidx-utils (and also for other games where needed?) + move to bt-core and make it a generic and improved async log sink +* replace inject logging through debug api with unified logging through bemanitools 6 api + * also solves issue with blocking logging on OutputDebugStr that needs synchronized + +## Alpha 3 + +goal: migrate and cleanup iidxhooks + +* use new bemanitools hook api in iidxhooks +* iat hook impl in launcher not complete and working, yet + +## Alpha 4 + +goal: configuration unification and cleanup, iidxhooks + +* deprecate cconfig and replace with core-config everywhere, e.g. in IO libs +* command line tooling unification: command arg parsing, common command args like setting log level/enabling/disabling log file +* Support config api, required implementation for modules such as IO once being used, see modules/io-ext -> TODOs next to api inits +* command line overrides for hook (and other?) configurations managed in + inject and launcher, transparent to hook which just gets the final config +* improve command line tool/usage docs by following the man page style format with sections name, synopsis description, options etc. +* improve config defaults, e.g. on old iidx games: have various gfx fixes enabled by default, cause disabling is rather the exception, e.g. running on actual old hardware that doesn't have these issues +* have a library that provides global options for any + command line tool such as setting log level, log file etc. + and have a piece of code allowing for quick and simply usage everywhere -> unify command line args +* support command lines with paths, i.e. -P launcher.hooks.bla.gfx.windowed + as well as allowing hooks and other things to define arbitrary short versions + e.g. -w for windowed + +## TBD/unsorted + +* dynamically load AVS to get rid of all the static linking and different AVS + version builds -> cleans up build process significantly and also makes + switching to a new/different build system easier +* document life cycle of hooks, when they happen, what gets called, what to do and what not to do -> document this in the API + overview with references from some sdk docs + * dll load: DllMain + * ... refer to hook API calls +* documentation as a rendered page on bemanitools.github.io domain + * Design and style like sapling documentation +* think about splitting mono hooks into smaller ones. iidx is probably a good + example because stuff is being re-used everywhere, e.g. gfx stuff? +* group all hooks in its own subfolder -> name them all with a "hook" postfix? +* procmon: lib avs monitor +* make vtables for core thread and log +* for io api + * use structs with bit fields everywhere to avoid all the bit shifting etc + * align several IO interfaces regarding separate polling (read/write) calls etc + * make them work closer to the actual device IOs, e.g. ddr with different sensor modes polling vs individual + * have all IO APIs in the style of + * setters + getters: modify internal state, but don't transfer to hardware/device, yet + * transactional functions: read/write (or send/recv) or update to execute a transaction to the hardware. this also can be a stubbed function that doesn't do anything if the backend is async driven but the API is not exposing that and looks like a sync API + * split iidxio into vefx and control deck parts -> have this as a separate library that loads two libs and composes them to the iidxio one? +* btapi design choice: have return types always be a status code and use parameter pointers to return actual data, e.g. for getting IO values +* io/popn: doesn't have read/write (poll) calls to explicitly drive the hardware +* have command in build script/justfile to create a package that can be used as a standalone project + to develop for bemanitools using the sdk +* Have a version.h/version.c for every dll/exe in bemanitools, see launcher. Print these at the first possible occasion when logging is available to console +* have shim dlls in sdk (?) that create backward compatibility with + BT5 equivalent DLLs but only support the api v1 of BT6 +* make vefx.dll optional in iidxio.dll with geninput.dll +* iidx io emulation is not getting values "atomic" from iidxio API + see the various msg implementations which hook the API + for example + msg_resp.inverted_pad = ((iidx_io_ep2_get_keys() & 0x3FFF) << 16) | + (iidx_io_ep2_get_panel() & 0x0F) | + ((iidx_io_ep2_get_sys() & 0x07) << 4) | + (((iidx_io_ep2_get_sys() >> 2) & 0x01) << 30); + -> iidx_io_ep2_get_sys is called twice +* notes for migration guide from bemanitools 5 to 6 + * Delete config.exe configurations in appdata: C:\Users\\AppData\Roaming\DJHACKERS\iidx.bin + * incompatibility list to BT5 + * All IO libs + * hooks? + * configuration files .conf + * previous setups with eapki data, keep stuff stock now and use bootstrap.xml provided by btools or stock bootstrap.xml +* config tool broken -> various functions from geninput need + to be loaded in addition to the input interface +* rteffects stubs don't seem to work, iidxhook1+2 +* split all games and versions for distribution files to distribution packages for each game version. avoids having a mixed bag of multiple versions with different startup scripts and sometimes oneofs, e.g. one specific lib for one version. +* for iidx e,f settings folders (old games), have default configuration values allocate them outside of the revision dirs, e.g. under settings/save next to the bemanitools folder to keep revision folders clean +* similar to trace wrapper for core api, have performance measuring around IO api +* reverse engineer NvDisplayConfigLDJ and make bemanitools version of that +* bemanitools performance monitoring of IO and rendering loops, measure and expose metrics alert on flaky performance +* tool to easily read and change xml properties configs from command line, similar to jq, but a lot simpler. no query language, just simple get and put +* moving build system to meson once AVS libs are dynamically loaded \ No newline at end of file