diff --git a/Dockerfile b/Dockerfile.build similarity index 100% rename from Dockerfile rename to Dockerfile.build diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 00000000..00c51086 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,21 @@ +FROM --platform=amd64 debian:11.6-slim@sha256:f7d141c1ec6af549958a7a2543365a7829c2cdc4476308ec2e182f8a7c59b519 + +LABEL description="Development environment for bemanitools" + +# mingw-w64-gcc has 32-bit and 64-bit toolchains +RUN apt-get update && apt-get install -y --no-install-recommends \ + mingw-w64 \ + mingw-w64-common \ + make \ + zip \ + git \ + clang-format \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +RUN pip3 install mdformat + +RUN mkdir /bemanitools +WORKDIR /bemanitools + +ENV SHELL /bin/bash \ No newline at end of file diff --git a/GNUmakefile b/GNUmakefile index 83289629..9aef0b1b 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -13,8 +13,10 @@ BUILDDIR ?= build builddir_docker := $(BUILDDIR)/docker -docker_container_name := "bemanitools-build" -docker_image_name := "bemanitools-build:latest" +docker_build_container_name := "bemanitools-build" +docker_build_image_name := "bemanitools-build:latest" +docker_dev_container_name := "bemanitools-dev" +docker_dev_image_name := "bemanitools-dev:latest" depdir := $(BUILDDIR)/dep objdir := $(BUILDDIR)/obj @@ -41,6 +43,7 @@ FORCE: .PHONY: \ build-docker \ +dev-docker \ clean \ code-format \ doc-format \ @@ -89,21 +92,38 @@ version: $(V)echo "$(gitrev)" > version build-docker: - $(V)docker rm -f $(docker_container_name) 2> /dev/null || true + $(V)docker rm -f $(docker_build_container_name) 2> /dev/null || true $(V)docker \ build \ - -t $(docker_image_name) \ - -f Dockerfile \ + -t $(docker_build_image_name) \ + -f Dockerfile.build \ . $(V)docker \ run \ --volume $(shell pwd):/bemanitools \ - --name $(docker_container_name) \ - $(docker_image_name) + --name $(docker_build_container_name) \ + $(docker_build_image_name) + +dev-docker: + $(V)docker rm -f $(docker_dev_container_name) 2> /dev/null || true + $(V)docker \ + build \ + -t $(docker_dev_image_name) \ + -f Dockerfile.dev \ + . + $(V)docker \ + run \ + --interactive \ + --tty \ + --volume $(shell pwd):/bemanitools \ + --name $(docker_dev_container_name) \ + $(docker_dev_image_name) clean-docker: - $(V)docker rm -f $(docker_container_name) || true - $(V)docker image rm -f $(docker_image_name) || true + $(V)docker rm -f $(docker_dev_container_name) || true + $(V)docker image rm -f $(docker_dev_image_name) || true + $(V)docker rm -f $(docker_build_container_name) || true + $(V)docker image rm -f $(docker_build_image_name) || true $(V)rm -rf $(BUILDDIR) # diff --git a/Module.mk b/Module.mk index 2a948a8d..41d179a1 100644 --- a/Module.mk +++ b/Module.mk @@ -100,6 +100,7 @@ include src/main/bstio/Module.mk include src/main/camhook/Module.mk include src/main/cconfig/Module.mk include src/main/config/Module.mk +include src/main/core/Module.mk include src/main/d3d9-util/Module.mk include src/main/d3d9exhook/Module.mk include src/main/ddrhook-util/Module.mk @@ -710,6 +711,8 @@ $(zipdir)/ddr-14-to-18.zip: \ build/bin/indep-32/eamio.dll \ build/bin/indep-32/geninput.dll \ dist/ddr/config.bat \ + dist/ddr/gamestart-17.bat \ + dist/ddr/gamestart-18.bat \ dist/ddr/gamestart-14.bat \ dist/ddr/gamestart-15.bat \ dist/ddr/gamestart-16.bat \ @@ -728,6 +731,8 @@ $(zipdir)/ddr-16-to-18-x64.zip: \ build/bin/indep-64/eamio.dll \ build/bin/indep-64/geninput.dll \ dist/ddr/config.bat \ + dist/ddr/gamestart-17.bat \ + dist/ddr/gamestart-18.bat \ dist/ddr/gamestart-16.bat \ dist/ddr/gamestart-17.bat \ dist/ddr/gamestart-18.bat \ diff --git a/src/api/log.h b/src/api/log.h new file mode 100644 index 00000000..638a269a --- /dev/null +++ b/src/api/log.h @@ -0,0 +1,31 @@ +#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 new file mode 100644 index 00000000..0459c9d1 --- /dev/null +++ b/src/api/thread.h @@ -0,0 +1,20 @@ +#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 a2d439ec..ae054e5c 100644 --- a/src/imports/avs.h +++ b/src/imports/avs.h @@ -220,6 +220,9 @@ void property_file_write(struct property *prop, const char *path); int property_set_flag(struct property *prop, int flags, int mask); 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( struct property *prop, struct property_node *root, diff --git a/src/imports/import_32_0_avs.def b/src/imports/import_32_0_avs.def index 273e5be8..9632ecb4 100644 --- a/src/imports/import_32_0_avs.def +++ b/src/imports/import_32_0_avs.def @@ -25,6 +25,8 @@ EXPORTS property_destroy property_file_write property_insert_read + property_clear_error + property_get_error property_mem_write property_read_query_memsize property_search diff --git a/src/imports/import_32_1002_avs.def b/src/imports/import_32_1002_avs.def index e2ff5ae5..cc4ee29c 100644 --- a/src/imports/import_32_1002_avs.def +++ b/src/imports/import_32_1002_avs.def @@ -28,6 +28,8 @@ EXPORTS property_destroy property_file_write property_insert_read + property_clear_error + property_get_error property_mem_write property_read_query_memsize property_search diff --git a/src/imports/import_32_1101_avs.def b/src/imports/import_32_1101_avs.def index 10c59e4f..776dc712 100644 --- a/src/imports/import_32_1101_avs.def +++ b/src/imports/import_32_1101_avs.def @@ -26,6 +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_node_create @266 NONAME property_node_datasize @267 NONAME property_node_name @274 NONAME diff --git a/src/imports/import_32_1304_avs.def b/src/imports/import_32_1304_avs.def index f83d5a5f..18dad23a 100644 --- a/src/imports/import_32_1304_avs.def +++ b/src/imports/import_32_1304_avs.def @@ -25,6 +25,8 @@ EXPORTS 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 diff --git a/src/imports/import_32_1306_avs.def b/src/imports/import_32_1306_avs.def index f963ec88..f6deed72 100644 --- a/src/imports/import_32_1306_avs.def +++ b/src/imports/import_32_1306_avs.def @@ -25,6 +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_node_create @316 NONAME == XC058ba5000143 property_node_datasize @249 NONAME == XC058ba5000100 property_node_name @255 NONAME == XC058ba5000106 diff --git a/src/imports/import_32_1403_avs.def b/src/imports/import_32_1403_avs.def index de171c12..716d0817 100644 --- a/src/imports/import_32_1403_avs.def +++ b/src/imports/import_32_1403_avs.def @@ -24,6 +24,8 @@ EXPORTS property_desc_to_buffer @131 NONAME property_destroy @130 NONAME property_insert_read @133 NONAME + property_clear_error @573 NONAME + property_get_error @573 NONAME property_node_name @573 NONAME == property_node_read @573 NONAME == property_node_remove @148 NONAME diff --git a/src/imports/import_32_1508_avs.def b/src/imports/import_32_1508_avs.def index d1625126..504a303f 100644 --- a/src/imports/import_32_1508_avs.def +++ b/src/imports/import_32_1508_avs.def @@ -26,6 +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_node_create @145 NONAME property_node_name @150 NONAME property_node_read @154 NONAME == XCd229cc0000f3 diff --git a/src/imports/import_32_1601_avs.def b/src/imports/import_32_1601_avs.def index 74332d48..286806bf 100644 --- a/src/imports/import_32_1601_avs.def +++ b/src/imports/import_32_1601_avs.def @@ -19,6 +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_search @141 NONAME property_node_create @142 NONAME property_node_name @147 NONAME == XCnbrep7000092 diff --git a/src/imports/import_32_1603_avs.def b/src/imports/import_32_1603_avs.def index 21f55c1e..93fd07d2 100644 --- a/src/imports/import_32_1603_avs.def +++ b/src/imports/import_32_1603_avs.def @@ -19,6 +19,8 @@ EXPORTS property_destroy @146 NONAME property_desc_to_buffer @147 NONAME property_insert_read @149 NONAME + property_clear_error @158 NONAME == XCnbrep700009d + property_get_error @159 NONAME == XCnbrep700009e property_search @162 NONAME property_node_create @163 NONAME property_node_name @168 NONAME == XCnbrep70000a7 diff --git a/src/imports/import_32_1700_avs.def b/src/imports/import_32_1700_avs.def index 7dc4eaa8..f01bc391 100644 --- a/src/imports/import_32_1700_avs.def +++ b/src/imports/import_32_1700_avs.def @@ -21,6 +21,8 @@ EXPORTS property_destroy @146 NONAME property_desc_to_buffer @147 NONAME property_insert_read @149 NONAME + property_clear_error @158 NONAME == XCgsqzn000009d + property_get_error @159 NONAME == XCgsqzn000009e property_search @162 NONAME property_node_create @163 NONAME property_node_name @168 NONAME == XCgsqzn00000a7 diff --git a/src/imports/import_32_803_avs.def b/src/imports/import_32_803_avs.def index 37f2b3e6..9340dad5 100644 --- a/src/imports/import_32_803_avs.def +++ b/src/imports/import_32_803_avs.def @@ -25,6 +25,8 @@ EXPORTS property_destroy property_file_write property_insert_read + property_clear_error + property_get_error property_mem_write property_read_query_memsize property_search diff --git a/src/imports/import_64_1508_avs.def b/src/imports/import_64_1508_avs.def index 6aeaba1d..1a93e7e5 100644 --- a/src/imports/import_64_1508_avs.def +++ b/src/imports/import_64_1508_avs.def @@ -26,6 +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_node_create @145 NONAME property_node_name @150 NONAME property_node_read @154 NONAME == XCd229cc0000f3 diff --git a/src/imports/import_64_1509_avs.def b/src/imports/import_64_1509_avs.def index fde35d65..a596513a 100644 --- a/src/imports/import_64_1509_avs.def +++ b/src/imports/import_64_1509_avs.def @@ -26,6 +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_node_create @145 NONAME property_node_name @573 NONAME == property_node_read @573 NONAME == diff --git a/src/imports/import_64_1601_avs.def b/src/imports/import_64_1601_avs.def index 418395f7..960fb947 100644 --- a/src/imports/import_64_1601_avs.def +++ b/src/imports/import_64_1601_avs.def @@ -19,6 +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_search @141 NONAME property_node_create @142 NONAME property_node_name @147 NONAME == XCnbrep7000092 diff --git a/src/imports/import_64_1603_avs.def b/src/imports/import_64_1603_avs.def index b106ab1b..14f42b7b 100644 --- a/src/imports/import_64_1603_avs.def +++ b/src/imports/import_64_1603_avs.def @@ -19,12 +19,14 @@ EXPORTS property_destroy @146 NONAME property_desc_to_buffer @147 NONAME property_insert_read @149 NONAME + property_clear_error @158 NONAME == XCnbrep700009d + property_get_error @159 NONAME == XCnbrep700009e property_search @162 NONAME property_node_create @163 NONAME property_node_name @168 NONAME == XCnbrep70000a7 property_node_remove @164 NONAME property_node_type @169 NONAME == XCnbrep70000a8 - property_node_clone @165 NONAME + property_node_clone @165 NONAME == XCnbrep70000a4 property_node_traversal @167 NONAME property_node_refdata @166 NONAME == XCnbrep70000a5 property_node_datasize @171 NONAME == XCnbrep70000aa diff --git a/src/imports/import_64_1700_avs.def b/src/imports/import_64_1700_avs.def index 8cddba8a..3e456b50 100644 --- a/src/imports/import_64_1700_avs.def +++ b/src/imports/import_64_1700_avs.def @@ -21,6 +21,8 @@ EXPORTS property_destroy @146 NONAME property_desc_to_buffer @147 NONAME property_insert_read @149 NONAME + property_clear_error @158 NONAME == XCgsqzn000009d + property_get_error @159 NONAME == XCgsqzn000009e property_search @162 NONAME property_node_create @163 NONAME property_node_name @168 NONAME == XCgsqzn00000a7 diff --git a/src/main/aciodrv-proc/Module.mk b/src/main/aciodrv-proc/Module.mk index e347f778..9fa6b381 100644 --- a/src/main/aciodrv-proc/Module.mk +++ b/src/main/aciodrv-proc/Module.mk @@ -1,6 +1,7 @@ libs += aciodrv-proc libs_aciodrv-proc := \ + core \ src_aciodrv-proc := \ panb.c \ diff --git a/src/main/aciodrv-proc/panb.c b/src/main/aciodrv-proc/panb.c index c054e21f..3f9d5a4f 100644 --- a/src/main/aciodrv-proc/panb.c +++ b/src/main/aciodrv-proc/panb.c @@ -5,8 +5,9 @@ #include "aciodrv/device.h" #include "aciodrv/panb.h" -#include "util/log.h" -#include "util/thread.h" +#include "core/thread.h" + +#include "core/log.h" static int auto_poll_proc(void *auto_poll_param); static int auto_poll_threadid; @@ -50,7 +51,7 @@ bool aciodrv_proc_panb_init(struct aciodrv_device_ctx *device) InitializeCriticalSection(&keypair_lock); InitializeCriticalSection(&auto_poll_stop_lock); auto_poll_threadid = - thread_create(auto_poll_proc, (void *) device, 0x4000, 0); + core_thread_create(auto_poll_proc, (void *) device, 0x4000, 0); return true; } @@ -80,8 +81,8 @@ void aciodrv_proc_panb_fini(struct aciodrv_device_ctx *device) auto_poll_stop = true; LeaveCriticalSection(&auto_poll_stop_lock); - thread_join(auto_poll_threadid, NULL); - thread_destroy(auto_poll_threadid); + core_thread_join(auto_poll_threadid, NULL); + core_thread_destroy(auto_poll_threadid); DeleteCriticalSection(&keypair_lock); DeleteCriticalSection(&auto_poll_stop_lock); diff --git a/src/main/aciodrv/device.c b/src/main/aciodrv/device.c index 39bf8afc..7584968d 100644 --- a/src/main/aciodrv/device.c +++ b/src/main/aciodrv/device.c @@ -7,8 +7,9 @@ #include "aciodrv/port.h" +#include "core/log.h" + #include "util/hex.h" -#include "util/log.h" #include "util/mem.h" /* Enable to dump all data to the logger */ diff --git a/src/main/aciodrv/h44b.c b/src/main/aciodrv/h44b.c index afbab429..19283f64 100644 --- a/src/main/aciodrv/h44b.c +++ b/src/main/aciodrv/h44b.c @@ -7,7 +7,7 @@ #include "aciodrv/device.h" -#include "util/log.h" +#include "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 ac56d0ea..7bec0c77 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 "util/log.h" +#include "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 e21a0b84..88093e4b 100644 --- a/src/main/aciodrv/kfca.c +++ b/src/main/aciodrv/kfca.c @@ -5,7 +5,7 @@ #include "aciodrv/device.h" -#include "util/log.h" +#include "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 1412e160..2dbc85ed 100644 --- a/src/main/aciodrv/panb.c +++ b/src/main/aciodrv/panb.c @@ -5,8 +5,7 @@ #include "aciodrv/device.h" #include "aciodrv/panb.h" -#include "util/log.h" -#include "util/thread.h" +#include "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 b38ad2a7..c3c9c71f 100644 --- a/src/main/aciodrv/port.c +++ b/src/main/aciodrv/port.c @@ -6,7 +6,7 @@ #include -#include "util/log.h" +#include "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 a9e0c36f..ed7c0360 100644 --- a/src/main/aciodrv/rvol.c +++ b/src/main/aciodrv/rvol.c @@ -5,7 +5,7 @@ #include "aciodrv/device.h" -#include "util/log.h" +#include "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 8d85487e..3f52fbb5 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 "util/log.h" +#include "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 11cf35a4..57f74e05 100644 --- a/src/main/acioemu/emu.c +++ b/src/main/acioemu/emu.c @@ -14,9 +14,10 @@ #include "acioemu/emu.h" #include "acioemu/pipe.h" +#include "core/log.h" + #include "hook/iohook.h" -#include "util/log.h" #include "util/str.h" static HRESULT ac_io_emu_open(struct ac_io_emu *emu, struct irp *irp); diff --git a/src/main/acioemu/hdxs.c b/src/main/acioemu/hdxs.c index 9a38beee..01ec19df 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 "util/log.h" +#include "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/pipe.h b/src/main/acioemu/pipe.h index ad442fc2..859c3b6f 100644 --- a/src/main/acioemu/pipe.h +++ b/src/main/acioemu/pipe.h @@ -7,9 +7,10 @@ #include "acio/acio.h" +#include "core/log.h" + #include "util/iobuf.h" #include "util/list.h" -#include "util/log.h" /* This uses the USB convention where OUT and IN are from the host's (game's) perspective. So an OUT transaction comes in to us and vice versa. diff --git a/src/main/aciomgr/Module.mk b/src/main/aciomgr/Module.mk index 0a17e8cd..b87f81b6 100644 --- a/src/main/aciomgr/Module.mk +++ b/src/main/aciomgr/Module.mk @@ -1,6 +1,7 @@ dlls += aciomgr libs_aciomgr := \ + core \ aciodrv \ util \ diff --git a/src/main/aciomgr/manager.c b/src/main/aciomgr/manager.c index e73b18e2..d7f03787 100644 --- a/src/main/aciomgr/manager.c +++ b/src/main/aciomgr/manager.c @@ -5,14 +5,15 @@ #include #include "aciomgr/manager-init.h" - #include "aciomgr/manager.h" #include "acio/acio.h" #include "aciodrv/device.h" + +#include "core/log.h" + #include "util/array.h" -#include "util/log.h" #define MAX_PORT_PATH_LENGTH 256 @@ -90,7 +91,7 @@ void aciomgr_set_loggers( log_formatter_t warning, log_formatter_t fatal) { - log_to_external(misc, info, warning, fatal); + core_log_impl_set(misc, warning, info, fatal); } struct aciomgr_port_dispatcher *aciomgr_port_init(const char *path, int baud) diff --git a/src/main/aciotest/Module.mk b/src/main/aciotest/Module.mk index af04652b..efeb038f 100644 --- a/src/main/aciotest/Module.mk +++ b/src/main/aciotest/Module.mk @@ -1,6 +1,7 @@ exes += aciotest libs_aciotest := \ + core \ bio2drv \ aciodrv \ aciodrv-proc \ diff --git a/src/main/aciotest/main.c b/src/main/aciotest/main.c index 4a301c41..fdf6df48 100644 --- a/src/main/aciotest/main.c +++ b/src/main/aciotest/main.c @@ -15,7 +15,14 @@ #include "aciotest/panb.h" #include "aciotest/rvol.h" -#include "util/log.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.h" static uint8_t aciotest_cnt = 0; static uint8_t bi2a_mode = 255; @@ -112,7 +119,10 @@ int main(int argc, char **argv) } } - log_to_writer(log_writer_stdout, NULL); + core_thread_crt_ext_impl_set(); + core_log_bt_ext_impl_set(); + + core_log_bt_ext_init_with_stdout(); 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 161b13b1..7e058904 100644 --- a/src/main/asio/asio-reghook.c +++ b/src/main/asio/asio-reghook.c @@ -10,13 +10,14 @@ #include +#include "asio/asio-reghook.h" + +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/table.h" -#include "asio/asio-reghook.h" - #include "util/defs.h" -#include "util/log.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 b29f99c8..2a8675d1 100644 --- a/src/main/asio/config-asio.c +++ b/src/main/asio/config-asio.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "asio/config-asio.h" +#include "core/log.h" -#include "util/log.h" +#include "asio/config-asio.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-util/Module.mk b/src/main/avs-util/Module.mk index 8db06918..2e59f579 100644 --- a/src/main/avs-util/Module.mk +++ b/src/main/avs-util/Module.mk @@ -3,4 +3,5 @@ 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 new file mode 100644 index 00000000..555930f1 --- /dev/null +++ b/src/main/avs-util/core-interop.c @@ -0,0 +1,16 @@ +#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 new file mode 100644 index 00000000..51b1e119 --- /dev/null +++ b/src/main/avs-util/core-interop.h @@ -0,0 +1,7 @@ +#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.c b/src/main/avs-util/error.c index ab09c014..d31b2e18 100644 --- a/src/main/avs-util/error.c +++ b/src/main/avs-util/error.c @@ -96,4 +96,14 @@ const char *avs_util_error_str(avs_error error) } return avs_util_error_unknown; +} + +const char *avs_util_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); } \ No newline at end of file diff --git a/src/main/avs-util/error.h b/src/main/avs-util/error.h index 35988515..88d68c5b 100644 --- a/src/main/avs-util/error.h +++ b/src/main/avs-util/error.h @@ -5,4 +5,6 @@ const char *avs_util_error_str(avs_error error); -#endif \ No newline at end of file +const char *avs_util_property_error_get_and_clear(struct property *prop); + +#endif diff --git a/src/main/bio2drv/Module.mk b/src/main/bio2drv/Module.mk index f5bdb568..9e5e92b3 100644 --- a/src/main/bio2drv/Module.mk +++ b/src/main/bio2drv/Module.mk @@ -1,10 +1,11 @@ libs += bio2drv libs_bio2drv := \ - aciodrv + core \ + aciodrv \ src_bio2drv := \ detect.c \ config-bio2.c \ bi2a-iidx.c \ - bi2a-sdvx.c + bi2a-sdvx.c \ diff --git a/src/main/bio2drv/bi2a-iidx.c b/src/main/bio2drv/bi2a-iidx.c index 1119876f..bce8c41e 100644 --- a/src/main/bio2drv/bi2a-iidx.c +++ b/src/main/bio2drv/bi2a-iidx.c @@ -7,7 +7,7 @@ #include "aciodrv/device.h" -#include "util/log.h" +#include "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 93edf496..14e52395 100644 --- a/src/main/bio2drv/bi2a-sdvx.c +++ b/src/main/bio2drv/bi2a-sdvx.c @@ -7,7 +7,7 @@ #include "aciodrv/device.h" -#include "util/log.h" +#include "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 492cdefd..c016fa94 100644 --- a/src/main/bio2drv/config-bio2.c +++ b/src/main/bio2drv/config-bio2.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "bio2drv/config-bio2.h" +#include "core/log.h" -#include "util/log.h" +#include "bio2drv/config-bio2.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 d559175d..dfdf5013 100644 --- a/src/main/bio2drv/detect.c +++ b/src/main/bio2drv/detect.c @@ -8,11 +8,11 @@ #include "bio2drv/detect.h" +#include "core/log.h" + #include #include -#include "util/log.h" - DEFINE_GUID( GUID_COM_BUS_ENUMERATOR, 0x4D36E978, @@ -142,7 +142,7 @@ void bio2drv_set_loggers( log_formatter_t warning, log_formatter_t fatal) { - log_to_external(misc, info, warning, fatal); + core_log_impl_set(misc, warning, info, fatal); } bool bio2drv_detect( diff --git a/src/main/bio2emu/emu.c b/src/main/bio2emu/emu.c index 9fbcb3d8..ea9c7f0d 100644 --- a/src/main/bio2emu/emu.c +++ b/src/main/bio2emu/emu.c @@ -14,6 +14,8 @@ #include "acioemu/addr.h" #include "acioemu/emu.h" +#include "core/log.h" + #include "hook/iohook.h" #include "hooklib/rs232.h" @@ -25,7 +27,6 @@ #include "util/array.h" #include "util/defs.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" static struct array bio2_active_ports; diff --git a/src/main/bio2emu/setupapi.c b/src/main/bio2emu/setupapi.c index 5dbfffc7..bb2f32c3 100644 --- a/src/main/bio2emu/setupapi.c +++ b/src/main/bio2emu/setupapi.c @@ -6,13 +6,14 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "bio2emu/emu.h" #include "bio2emu/setupapi.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" #include "util/time.h" diff --git a/src/main/bsthook/Module.mk b/src/main/bsthook/Module.mk index ef61d283..92ab3b1c 100644 --- a/src/main/bsthook/Module.mk +++ b/src/main/bsthook/Module.mk @@ -4,6 +4,8 @@ deplibs_bsthook := \ avs \ libs_bsthook := \ + avs-util \ + core \ acioemu \ bstio \ hook \ diff --git a/src/main/bsthook/acio.c b/src/main/bsthook/acio.c index fe5f8cc1..500d4c5b 100644 --- a/src/main/bsthook/acio.c +++ b/src/main/bsthook/acio.c @@ -19,13 +19,14 @@ #include "bsthook/acio.h" #include "bsthook/kfca.h" +#include "core/log.h" + #include "hook/iohook.h" #include "imports/avs.h" #include "util/defs.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" static struct ac_io_emu ac_io_emu; diff --git a/src/main/bsthook/dllmain.c b/src/main/bsthook/dllmain.c index 57d38e03..e508057c 100644 --- a/src/main/bsthook/dllmain.c +++ b/src/main/bsthook/dllmain.c @@ -2,9 +2,14 @@ #include +#include "avs-util/core-interop.h" + #include "bemanitools/bstio.h" #include "bemanitools/eamio.h" +#include "core/log.h" +#include "core/thread.h" + #include "hook/iohook.h" #include "hooklib/app.h" @@ -18,7 +23,6 @@ #include "util/cmdline.h" #include "util/defs.h" -#include "util/log.h" static bool my_dll_entry_init(char *sidcode, struct property_node *config); static bool my_dll_entry_main(void); @@ -33,19 +37,23 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config) log_info("Starting up BeatStream IO backend"); - bst_io_set_loggers( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + core_log_impl_assign(bst_io_set_loggers); - ok = bst_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); + ok = bst_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); if (!ok) { goto bst_io_fail; } - eam_io_set_loggers( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + core_log_impl_assign(eam_io_set_loggers); - ok = eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); + ok = eam_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); if (!ok) { goto eam_io_fail; @@ -91,8 +99,9 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) return TRUE; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // Use AVS APIs + avs_util_core_interop_thread_avs_impl_set(); + avs_util_core_interop_log_avs_impl_set(); args_recover(&argc, &argv); diff --git a/src/main/bsthook/gfx.c b/src/main/bsthook/gfx.c index 43d88a2d..23d37e0f 100644 --- a/src/main/bsthook/gfx.c +++ b/src/main/bsthook/gfx.c @@ -3,6 +3,8 @@ #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/pe.h" #include "hook/table.h" @@ -10,7 +12,6 @@ #include "sdvxhook/gfx.h" #include "util/defs.h" -#include "util/log.h" static HRESULT STDCALL my_CreateDevice( IDirect3D9 *self, diff --git a/src/main/bsthook/settings.c b/src/main/bsthook/settings.c index 8f48ea8e..c9fb10ae 100644 --- a/src/main/bsthook/settings.c +++ b/src/main/bsthook/settings.c @@ -7,10 +7,11 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" /* ------------------------------------------------------------------------- */ diff --git a/src/main/camhook/cam.c b/src/main/camhook/cam.c index 4ce92603..169fd020 100644 --- a/src/main/camhook/cam.c +++ b/src/main/camhook/cam.c @@ -15,13 +15,14 @@ #include +#include "camhook/cam.h" + +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/table.h" -#include "camhook/cam.h" - #include "util/defs.h" -#include "util/log.h" #include "util/str.h" #include "util/time.h" diff --git a/src/main/camhook/config-cam.c b/src/main/camhook/config-cam.c index 6a55852e..c6dd1afb 100644 --- a/src/main/camhook/config-cam.c +++ b/src/main/camhook/config-cam.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "camhook/config-cam.h" +#include "core/log.h" -#include "util/log.h" +#include "camhook/config-cam.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 342a9120..342d8dfe 100644 --- a/src/main/cconfig/cconfig-main.c +++ b/src/main/cconfig/cconfig-main.c @@ -6,8 +6,9 @@ #include "cconfig/cconfig-main.h" +#include "core/log.h" + #include "util/cmdline.h" -#include "util/log.h" bool cconfig_main_config_init( struct cconfig *config, @@ -84,7 +85,7 @@ bool cconfig_main_config_init( } log_misc("Config state after file loading:"); - cconfig_util_log(config, log_impl_misc); + cconfig_util_log(config, core_log_misc_impl_get()); } log_misc("Parsing override config parameters from cmd"); @@ -96,7 +97,7 @@ bool cconfig_main_config_init( } log_misc("Config state after cmd parameter overrides:"); - cconfig_util_log(config, log_impl_misc); + cconfig_util_log(config, core_log_misc_impl_get()); goto success; diff --git a/src/main/cconfig/cconfig-util.c b/src/main/cconfig/cconfig-util.c index f4ce05f3..35853574 100644 --- a/src/main/cconfig/cconfig-util.c +++ b/src/main/cconfig/cconfig-util.c @@ -5,8 +5,9 @@ #include "cconfig/cconfig-util.h" +#include "core/log.h" + #include "util/hex.h" -#include "util/log.h" #include "util/mem.h" bool cconfig_util_get_int( @@ -220,10 +221,10 @@ void cconfig_util_set_data( free(str); } -void cconfig_util_log(struct cconfig *config, log_formatter_t log_formatter) +void cconfig_util_log(struct cconfig *config, core_log_message_t log_message) { for (uint32_t i = 0; i < config->nentries; i++) { - log_formatter( + log_message( LOG_MODULE, "%s=%s", config->entries[i].key, diff --git a/src/main/cconfig/cconfig-util.h b/src/main/cconfig/cconfig-util.h index aa9b5004..8f6a3058 100644 --- a/src/main/cconfig/cconfig-util.h +++ b/src/main/cconfig/cconfig-util.h @@ -7,7 +7,7 @@ #include "cconfig/cconfig.h" -#include "util/log.h" +#include "core/log.h" bool cconfig_util_get_int( struct cconfig *config, @@ -57,6 +57,6 @@ void cconfig_util_set_data( size_t len, const char *desc); -void cconfig_util_log(struct cconfig *config, log_formatter_t log_formatter); +void cconfig_util_log(struct cconfig *config, 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 1cfcbedb..6150f66f 100644 --- a/src/main/cconfig/cconfig.c +++ b/src/main/cconfig/cconfig.c @@ -2,7 +2,8 @@ #include "cconfig/cconfig.h" -#include "util/log.h" +#include "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 3d4f32fc..3bb1c247 100644 --- a/src/main/cconfig/cmd.c +++ b/src/main/cconfig/cmd.c @@ -7,8 +7,9 @@ #include "cconfig/cmd.h" +#include "core/log.h" + #include "util/hex.h" -#include "util/log.h" #include "util/str.h" static void diff --git a/src/main/cconfig/conf.c b/src/main/cconfig/conf.c index de21f8b9..b23e9d47 100644 --- a/src/main/cconfig/conf.c +++ b/src/main/cconfig/conf.c @@ -6,8 +6,9 @@ #include "cconfig/conf.h" +#include "core/log.h" + #include "util/fs.h" -#include "util/log.h" #include "util/str.h" enum cconfig_conf_error cconfig_conf_load_from_file( diff --git a/src/main/config/Module.mk b/src/main/config/Module.mk index 2f7bac83..fc37a230 100644 --- a/src/main/config/Module.mk +++ b/src/main/config/Module.mk @@ -3,6 +3,7 @@ rc_config := config.rc cppflags_config := -DUNICODE libs_config := \ + core \ eamio \ geninput \ util \ diff --git a/src/main/config/analogs.c b/src/main/config/analogs.c index 5a7bceeb..d6936670 100644 --- a/src/main/config/analogs.c +++ b/src/main/config/analogs.c @@ -11,13 +11,14 @@ #include "config/schema.h" #include "config/usages.h" +#include "core/log.h" + #include "geninput/hid-mgr.h" #include "geninput/input-config.h" #include "geninput/mapper.h" #include "util/array.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/config/buttons.c b/src/main/config/buttons.c index f4a498b8..e083bf3f 100644 --- a/src/main/config/buttons.c +++ b/src/main/config/buttons.c @@ -15,11 +15,12 @@ #include "config/schema.h" #include "config/usages.h" +#include "core/log.h" + #include "geninput/input-config.h" #include "geninput/mapper.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" #include "util/winres.h" diff --git a/src/main/config/eam.c b/src/main/config/eam.c index e9bb76ce..1d665189 100644 --- a/src/main/config/eam.c +++ b/src/main/config/eam.c @@ -13,6 +13,8 @@ #include "config/resource.h" #include "config/schema.h" +#include "core/log.h" + #include "eamio/eam-config.h" #include "geninput/hid-mgr.h" @@ -21,7 +23,6 @@ #include "util/array.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/config/gametype.c b/src/main/config/gametype.c index e7e7353b..2ec0ea4b 100644 --- a/src/main/config/gametype.c +++ b/src/main/config/gametype.c @@ -6,8 +6,9 @@ #include "config/resource.h" #include "config/schema.h" +#include "core/log.h" + #include "util/defs.h" -#include "util/log.h" static INT_PTR CALLBACK game_type_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); diff --git a/src/main/config/main.c b/src/main/config/main.c index ba515554..8be13700 100644 --- a/src/main/config/main.c +++ b/src/main/config/main.c @@ -14,14 +14,19 @@ #include "config/spinner.h" #include "config/usages.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 "eamio/eam-config.h" #include "geninput/input-config.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" -#include "util/thread.h" #include "util/winres.h" HPROPSHEETPAGE @@ -61,11 +66,22 @@ int main(int argc, char **argv) wchar_t text[1024]; int max_light; size_t i; + struct core_log_sink sink; inst = GetModuleHandle(NULL); - log_to_writer(log_writer_debug, NULL); - log_to_external(log_impl_misc, log_impl_info, log_impl_warning, my_fatal); + core_thread_crt_ext_impl_set(); + + 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_bt_init(&sink); + core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); usages_init(inst); @@ -96,13 +112,17 @@ int main(int argc, char **argv) } } - input_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); - input_init(crt_thread_create, crt_thread_join, crt_thread_destroy); - - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); - eam_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy); + core_log_impl_assign(input_set_loggers); + input_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); + + 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(); // calculate these and check against the loaded config diff --git a/src/main/config/snap.c b/src/main/config/snap.c index 8981c686..6d8547ab 100644 --- a/src/main/config/snap.c +++ b/src/main/config/snap.c @@ -6,10 +6,11 @@ #include "config/snap.h" +#include "core/log.h" + #include "geninput/hid-mgr.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" enum snap_control_heuristic { CONTROL_CENTERING_AXIS, CONTROL_MULTISWITCH }; diff --git a/src/main/config/usages.c b/src/main/config/usages.c index 5e28ad9b..771772cd 100644 --- a/src/main/config/usages.c +++ b/src/main/config/usages.c @@ -9,8 +9,9 @@ #include "config/resource.h" +#include "core/log.h" + #include "util/array.h" -#include "util/log.h" #include "util/str.h" #include "util/winres.h" diff --git a/src/main/core/Module.mk b/src/main/core/Module.mk new file mode 100644 index 00000000..bd35e6d0 --- /dev/null +++ b/src/main/core/Module.mk @@ -0,0 +1,20 @@ +libs += core + +libs_core := \ + util \ + +src_core := \ + log-bt-ext.c \ + log-bt.c \ + log-sink-async.c \ + log-sink-debug.c \ + log-sink-file.c \ + log-sink-list.c \ + log-sink-mutex.c \ + log-sink-null.c \ + log-sink-std.c \ + log.c \ + thread-crt-ext.c \ + thread-crt.c \ + thread.c \ + diff --git a/src/main/core/log-bt-ext.c b/src/main/core/log-bt-ext.c new file mode 100644 index 00000000..b1aa4f46 --- /dev/null +++ b/src/main/core/log-bt-ext.c @@ -0,0 +1,67 @@ +#include + +#include "core/log-bt.h" +#include "core/log-sink-debug.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" + +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_std_out_open(true, &sink); + core_log_bt_init(&sink); +} + +void core_log_bt_ext_init_with_stderr() +{ + struct core_log_sink sink; + + core_log_sink_std_err_open(true, &sink); + core_log_bt_init(&sink); +} + +void core_log_bt_ext_init_with_debug() +{ + struct core_log_sink sink; + + core_log_sink_debug_open(&sink); + core_log_bt_init(&sink); +} + +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_file_open(path, append, rotate, max_rotations, &sink); + core_log_bt_init(&sink); +} + +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_std_out_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 new file mode 100644 index 00000000..dcb9a9a6 --- /dev/null +++ b/src/main/core/log-bt-ext.h @@ -0,0 +1,59 @@ +#ifndef CORE_LOG_BT_EXT_H +#define CORE_LOG_BT_EXT_H + +#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. + */ +void core_log_bt_ext_init_with_stdout(); + +/** + * Helper to setup the bemanitools log implementation with a stderr sink. + */ +void core_log_bt_ext_init_with_stderr(); + +/** + * Helper to setup the bemanitools log implementation with a OutputDebugStr + * sink. + */ +void core_log_bt_ext_init_with_debug(); + +/** + * Helper to setup the bemanitools log implementation with a file sink + * + * @param path Path to the log file to write the log output to + * @param append If true, then append to an existing file, false to overwrite + * any existing file + * @param rotate If true, rotates an existing log file and creates a new one + * for this session + * @param max_rotations Max number of rotations for the log files + */ +void core_log_bt_ext_init_with_file( + const char *path, bool append, bool rotate, uint8_t max_rotations); + +/** + * Helper to setup the bemanitools log implementation with a stdout and file + * sink + * + * Important: This combined sink is guarded by a mutex to avoid data races on + * logging to two different sinks. + * + * @param path Path to the log file to write the log output to + * @param append If true, then append to an existing file, false to overwrite + * any existing file + * @param rotate If true, rotates an existing log file and creates a new one + * for this session + * @param max_rotations Max number of rotations for the log files + */ +void core_log_bt_ext_init_with_stdout_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 new file mode 100644 index 00000000..fd868979 --- /dev/null +++ b/src/main/core/log-bt.c @@ -0,0 +1,129 @@ +#include +#include +#include + +#include "core/log-bt.h" +#include "core/log-sink.h" +#include "core/log.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; + +static void _core_log_bt_vformat_write( + enum core_log_bt_log_level level, + const char *module, + const char *fmt, + va_list ap) +{ + 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]; + int result; + + time_t curtime; + struct tm *tm; + + curtime = 0; + tm = NULL; + + curtime = time(NULL); + tm = localtime(&curtime); + + strftime(timestamp, sizeof(timestamp), "[%Y/%m/%d %H:%M:%S]", tm); + + str_vformat(msg, sizeof(msg), fmt, ap); + + result = str_format( + line, + sizeof(line), + "%s %c:%s: %s\n", + timestamp, + chars[level], + module, + msg); + + _core_log_bt_sink->write(_core_log_bt_sink->ctx, line, result); +} + +void core_log_bt_init(const struct core_log_sink *sink) +{ + if (sink == NULL) { + abort(); + } + + _core_log_bt_sink = xmalloc(sizeof(struct core_log_sink)); + memcpy(_core_log_bt_sink, sink, sizeof(struct core_log_sink)); + + _core_log_bt_log_level = CORE_LOG_BT_LOG_LEVEL_OFF; +} + +void core_log_bt_level_set(enum core_log_bt_log_level level) +{ + _core_log_bt_log_level = level; +} + +void core_log_bt_fini() +{ + log_assert(_core_log_bt_sink); + + _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 new file mode 100644 index 00000000..2a8052f3 --- /dev/null +++ b/src/main/core/log-bt.h @@ -0,0 +1,87 @@ +#ifndef CORE_LOG_BT_H +#define CORE_LOG_BT_H + +#include "core/log-sink.h" + +/** + * Log API implementation for games/applications without AVS + */ + +enum core_log_bt_log_level { + CORE_LOG_BT_LOG_LEVEL_OFF = 0, + CORE_LOG_BT_LOG_LEVEL_FATAL = 1, + CORE_LOG_BT_LOG_LEVEL_WARNING = 2, + CORE_LOG_BT_LOG_LEVEL_INFO = 3, + CORE_LOG_BT_LOG_LEVEL_MISC = 4, +}; + +/** + * Initialize the logging backend + * + * This must be called as early as possible in your application to setup + * a logging sink according to your needs. Until this is finished, no + * log output is available. + * + * By default, logging is turned off entirely and must be enabled by setting + * a desired logging level explicitly. + * + * @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); + +/** + * Set the current logging level. This can be changed at any given time, e.g. + * to increase/decrease verbosity. + * + * @param level The logging level to set. + */ +void core_log_bt_level_set(enum core_log_bt_log_level level); + +/** + * Cleanup the logging backend. + * + * Ensure to call this on application exit and cleanup. + */ +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. + * + * This function must only be called by AVS in an appropriate log callback + * function that is passed to avs_boot. + * + * AVS has it's own logging engine and manages aspects such as async logging, + * log levels and decorating log messages. + * + * Thus, proper interoperability only requires the writer/sink part to be shared + * with AVS. + * + * @param chars Buffer with text data to write to the configured sinks. The + * buffer might contain several log messages separated by newline + * characters. + * @param nchars Number of chars to write to the sink. + */ +void core_log_bt_direct_sink_write(const char *chars, size_t nchars); + +#endif \ No newline at end of file diff --git a/src/main/core/log-sink-async.c b/src/main/core/log-sink-async.c new file mode 100644 index 00000000..f327aad8 --- /dev/null +++ b/src/main/core/log-sink-async.c @@ -0,0 +1,23 @@ +#include + +#include "core/log-sink.h" + +static void +_core_log_sink_file_write(void *ctx, const char *chars, size_t nchars) +{ + // TODO +} + +static void _core_log_sink_file_close(void *ctx) +{ + // TODO +} + +void core_log_sink_async_open(struct core_log_sink *sink) +{ + // TODO + + sink->ctx = NULL; + sink->write = _core_log_sink_file_write; + sink->close = _core_log_sink_file_close; +} \ No newline at end of file diff --git a/src/main/core/log-sink-async.h b/src/main/core/log-sink-async.h new file mode 100644 index 00000000..47aa49e7 --- /dev/null +++ b/src/main/core/log-sink-async.h @@ -0,0 +1,19 @@ +#ifndef CORE_LOG_SINK_ASYNC_H +#define CORE_LOG_SINK_ASYNC_H + +#include +#include + +#include "core/log-sink.h" + +/** + * Open a async log sink + * + * The sink passes data to log to a separate thread which executes the actual + * logging of the data. + * + * @param sink Pointer to allocated memory that receives the opened sink + */ +void core_log_sink_async_open(struct core_log_sink *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 new file mode 100644 index 00000000..c1dd7a20 --- /dev/null +++ b/src/main/core/log-sink-debug.c @@ -0,0 +1,23 @@ +#include + +#include + +#include "core/log-sink.h" + +static void +_core_log_sink_debug_write(void *ctx, const char *chars, size_t nchars) +{ + OutputDebugStringA(chars); +} + +static void _core_log_sink_debug_close(void *ctx) +{ + // noop +} + +void core_log_sink_debug_open(struct core_log_sink *sink) +{ + sink->ctx = NULL; + sink->write = _core_log_sink_debug_write; + sink->close = _core_log_sink_debug_close; +} \ No newline at end of file diff --git a/src/main/core/log-sink-debug.h b/src/main/core/log-sink-debug.h new file mode 100644 index 00000000..4c21d50c --- /dev/null +++ b/src/main/core/log-sink-debug.h @@ -0,0 +1,15 @@ +#ifndef CORE_LOG_SINK_DEBUG_H +#define CORE_LOG_SINK_DEBUG_H + +#include + +#include "core/log-sink.h" + +/** + * Open a log sink that uses OutputDebugStr + * + * @param sink Pointer to allocated memory that receives the opened sink + */ +void core_log_sink_debug_open(struct core_log_sink *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 new file mode 100644 index 00000000..f2ca188e --- /dev/null +++ b/src/main/core/log-sink-file.c @@ -0,0 +1,92 @@ +#include + +#include +#include +#include +#include + +#include "core/log-sink.h" + +#include "util/fs.h" +#include "util/str.h" + +static void _core_log_sink_file_rotate(const char *path, uint8_t max_rotations) +{ + uint8_t i; + char rotate_file[MAX_PATH]; + char rotate_file_next[MAX_PATH]; + char version[8]; + char version_next[8]; + + for (i = max_rotations; i > 0; i++) { + str_cpy(rotate_file, sizeof(rotate_file), path); + str_cpy(rotate_file_next, sizeof(rotate_file_next), path); + + if (i - 1 != 0) { + sprintf(version, ".%d", i); + } else { + memset(version, 0, sizeof(version)); + } + + sprintf(version_next, ".%d", i); + + str_cat(rotate_file, sizeof(rotate_file), version); + str_cat(rotate_file_next, sizeof(rotate_file_next), version_next); + + if (path_exists(rotate_file)) { + CopyFile(rotate_file, rotate_file_next, FALSE); + } + } +} + +static void +_core_log_sink_file_write(void *ctx, const char *chars, size_t nchars) +{ + FILE *file; + + file = (FILE *) ctx; + + fwrite(chars, 1, nchars, file); +} + +static void _core_log_sink_file_close(void *ctx) +{ + FILE *file; + + file = (FILE *) ctx; + + fflush(file); + fclose(file); +} + +void core_log_sink_file_open( + const char *path, + bool append, + bool rotate, + uint8_t max_rotations, + struct core_log_sink *sink) +{ + FILE *file; + + if (rotate) { + _core_log_sink_file_rotate(path, max_rotations); + + // Appending doesn't matter when file is rotated anyway + file = fopen(path, "w+"); + } else { + if (append) { + file = fopen(path, "a+"); + } else { + file = fopen(path, "w+"); + } + } + + if (!file) { + printf("Cannot open log file: %s", path); + abort(); + } + + sink->ctx = (void *) file; + sink->write = _core_log_sink_file_write; + sink->close = _core_log_sink_file_close; +} \ No newline at end of file diff --git a/src/main/core/log-sink-file.h b/src/main/core/log-sink-file.h new file mode 100644 index 00000000..968a1fed --- /dev/null +++ b/src/main/core/log-sink-file.h @@ -0,0 +1,28 @@ +#ifndef CORE_LOG_SINK_FILE_H +#define CORE_LOG_SINK_FILE_H + +#include +#include +#include + +#include "core/log-sink.h" + +/** + * Open a log sink writing data to a file + * + * @param path Path to the log file to write the log output to + * @param append If true, then append to an existing file, false to overwrite + * any existing file + * @param rotate If true, rotates an existing log file and creates a new one + * for this session + * @param max_rotations Max number of rotations for the log files + * @param sink Pointer to allocated memory that receives the opened sink + */ +void core_log_sink_file_open( + const char *path, + bool append, + bool rotate, + uint8_t max_rotations, + struct core_log_sink *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 new file mode 100644 index 00000000..38e32112 --- /dev/null +++ b/src/main/core/log-sink-list.c @@ -0,0 +1,66 @@ +#include +#include + +#include "core/log-sink-list.h" +#include "core/log-sink.h" + +#include "util/mem.h" + +#define MAX_SINKS 8 + +struct core_log_sink_list { + struct core_log_sink entries[MAX_SINKS]; + uint8_t num; +}; + +static void +_core_log_sink_list_write(void *ctx, const char *chars, size_t nchars) +{ + struct core_log_sink_list *sink_list; + int i; + + sink_list = (struct core_log_sink_list *) ctx; + + for (i = 0; i < sink_list->num; i++) { + sink_list->entries[i].write(sink_list->entries[i].ctx, chars, nchars); + } +} + +static void _core_log_sink_list_close(void *ctx) +{ + struct core_log_sink_list *sink_list; + int i; + + sink_list = (struct core_log_sink_list *) ctx; + + for (i = 0; i < sink_list->num; i++) { + sink_list->entries[i].close(sink_list->entries[i].ctx); + } + + free(sink_list); +} + +void core_log_sink_list_open( + const struct core_log_sink *entry, uint8_t num, struct core_log_sink *sink) +{ + struct core_log_sink_list *sink_list; + int i; + + if (num > MAX_SINKS) { + abort(); + } + + sink_list = xmalloc(sizeof(struct core_log_sink_list)); + + for (i = 0; i < num; i++) { + sink_list->entries[i].ctx = entry[i].ctx; + sink_list->entries[i].write = entry[i].write; + sink_list->entries[i].close = entry[i].close; + } + + sink_list->num = num; + + sink->ctx = (void *) sink_list; + sink->write = _core_log_sink_list_write; + sink->close = _core_log_sink_list_close; +} \ No newline at end of file diff --git a/src/main/core/log-sink-list.h b/src/main/core/log-sink-list.h new file mode 100644 index 00000000..f1e99f35 --- /dev/null +++ b/src/main/core/log-sink-list.h @@ -0,0 +1,24 @@ +#ifndef CORE_LOG_SINK_LIST_H +#define CORE_LOG_SINK_LIST_H + +#include +#include + +#include "core/log-sink.h" + +/** + * Combine multiple log sinks into a list of sinks. + * + * Upon invoking a list sink, all sinks contained within the list are + * being invoked in the configured order. + * + * @param entry A pointer to allocated memory with a sequence of opened sinks + * that you want to add to the list. Ownership of these sinks + * is transferred, i.e. closing the list sink closes its children. + * @param num The number of elements in the sequence of opened sinks pointed to. + * @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); + +#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 new file mode 100644 index 00000000..13c8b207 --- /dev/null +++ b/src/main/core/log-sink-mutex.c @@ -0,0 +1,53 @@ +#include + +#include + +#include "core/log-sink.h" + +#include "util/mem.h" + +struct core_log_sink_mutex_ctx { + struct core_log_sink *child; + HANDLE mutex; +}; + +static void +_core_log_sink_mutex_write(void *ctx_, const char *chars, size_t nchars) +{ + struct core_log_sink_mutex_ctx *ctx; + + ctx = (struct core_log_sink_mutex_ctx *) ctx_; + + WaitForSingleObject(ctx->mutex, INFINITE); + + 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; + + ctx = (struct core_log_sink_mutex_ctx *) ctx_; + + CloseHandle(ctx->mutex); + + 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) +{ + struct core_log_sink_mutex_ctx *ctx; + + ctx = xmalloc(sizeof(struct core_log_sink_mutex_ctx)); + + memcpy(ctx->child, child_sink, sizeof(struct core_log_sink)); + ctx->mutex = CreateMutex(NULL, FALSE, NULL); + + sink->ctx = ctx; + sink->write = _core_log_sink_mutex_write; + sink->close = _core_log_sink_mutex_close; +} \ No newline at end of file diff --git a/src/main/core/log-sink-mutex.h b/src/main/core/log-sink-mutex.h new file mode 100644 index 00000000..e30357e4 --- /dev/null +++ b/src/main/core/log-sink-mutex.h @@ -0,0 +1,21 @@ +#ifndef CORE_LOG_SINK_MUTEX_H +#define CORE_LOG_SINK_MUTEX_H + +#include + +#include "core/log-sink.h" + +/** + * Create a sink that surrounds another sink with a mutex. + * + * Use this to make other sink implementations thread-safe. + * + * @param child_sink Another opened sink to surround with the mutex. Ownership + * of the sink is transferred, i.e. closing the mutex sink + * also closes the wrapped child sink. + * @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); + +#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 new file mode 100644 index 00000000..7655a208 --- /dev/null +++ b/src/main/core/log-sink-null.c @@ -0,0 +1,21 @@ +#include + +#include "core/log-sink.h" + +static void +_core_log_sink_null_write(void *ctx, const char *chars, size_t nchars) +{ + // noop +} + +static void _core_log_sink_null_close(void *ctx) +{ + // noop +} + +void core_log_sink_null_open(struct core_log_sink *sink) +{ + sink->ctx = NULL; + sink->write = _core_log_sink_null_write; + sink->close = _core_log_sink_null_close; +} \ No newline at end of file diff --git a/src/main/core/log-sink-null.h b/src/main/core/log-sink-null.h new file mode 100644 index 00000000..ebd2babe --- /dev/null +++ b/src/main/core/log-sink-null.h @@ -0,0 +1,17 @@ +#ifndef CORE_LOG_SINK_NULL_H +#define CORE_LOG_SINK_NULL_H + +#include + +#include "core/log-sink.h" + +/** + * Create a null/dummy sink. + * + * Use this to disable any logging entirely. + * + * @param sink Pointer to allocated memory that receives the opened sink + */ +void core_log_sink_null_open(struct core_log_sink *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 new file mode 100644 index 00000000..197fd12a --- /dev/null +++ b/src/main/core/log-sink-std.c @@ -0,0 +1,193 @@ +#include + +#include + +#include "core/log-sink.h" + +#include "util/mem.h" + +struct core_log_sink_std_ctx { + HANDLE handle; + bool color; +}; + +static char _core_log_sink_std_determine_color(const char *str) +{ + /* Add some color to make spotting warnings/errors easier. + Based on debug output level identifier. */ + + /* Avoids colored output on strings like "Windows" */ + if (str[1] != ':') { + return 15; + } + + switch (str[0]) { + /* green */ + case 'M': + return 10; + /* blue */ + case 'I': + return 9; + /* yellow */ + case 'W': + return 14; + /* red */ + case 'F': + return 12; + /* default console color */ + default: + return 15; + } +} + +static size_t _core_log_sink_std_msg_coloring_len(const char *str) +{ + // Expected format example: "I:boot: my log message" + + const char *ptr; + size_t len; + int colon_count; + + ptr = str; + len = 0; + colon_count = 0; + + while (true) { + // End of string = invalid log format + if (*ptr == '\0') { + return 0; + } + + if (*ptr == ':') { + colon_count++; + } + + if (colon_count == 2) { + // Skip current colon, next char is a space + return len + 1; + } + + len++; + ptr++; + } + + return 0; +} + +static void +_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; + + char color; + size_t color_len; + size_t msg_len; + const char *msg_start; + const char *msg_end; + DWORD written; + DWORD write_pos; + + ctx = (struct core_log_sink_std_ctx *) ctx_; + + if (ctx->color) { + write_pos = 0; + + // Support multiple buffered log messages, e.g. from the AVS logging + // engine + while (write_pos < nchars) { + // Expects the AVS timestamp format + msg_start = chars + timestamp_len + 1; // +1 is the space + + color_len = _core_log_sink_std_msg_coloring_len(msg_start); + + // Check if we could detect which part to color, otherwise just + // write the whole log message without any coloring logic + if (color_len > 0) { + color = _core_log_sink_std_determine_color(msg_start); + + // Timestamp + WriteConsole( + ctx->handle, chars, timestamp_len + 1, &written, NULL); + write_pos += written; + chars += written; + + // Log level + module colored + SetConsoleTextAttribute(ctx->handle, color); + WriteConsole(ctx->handle, chars, color_len, &written, NULL); + write_pos += written; + chars += written; + SetConsoleTextAttribute(ctx->handle, 15); + + msg_end = strchr(chars, '\n'); + + if (msg_end != NULL) { + msg_len = msg_end - chars; + + // Write \n as well + msg_len++; + + // Write actual message non colored + WriteConsole(ctx->handle, chars, msg_len, &written, NULL); + write_pos += written; + chars += written; + } else { + WriteConsole( + ctx->handle, chars, nchars - write_pos, &written, NULL); + write_pos += written; + chars += written; + } + } else { + WriteConsole( + ctx->handle, + chars + write_pos, + nchars - write_pos, + &written, + NULL); + write_pos += written; + } + } + } else { + WriteConsole(ctx->handle, chars, nchars, &written, NULL); + } +} + +static void _core_log_sink_std_close(void *ctx_) +{ + struct core_log_sink_std_ctx *ctx; + + ctx = (struct core_log_sink_std_ctx *) 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) +{ + struct core_log_sink_std_ctx *ctx; + + ctx = xmalloc(sizeof(struct core_log_sink_std_ctx)); + + ctx->handle = GetStdHandle(STD_OUTPUT_HANDLE); + ctx->color = color; + + sink->ctx = (void *) ctx; + sink->write = _core_log_sink_std_write; + sink->close = _core_log_sink_std_close; +} + +void core_log_sink_std_err_open(bool color, struct core_log_sink *sink) +{ + struct core_log_sink_std_ctx *ctx; + + ctx = xmalloc(sizeof(struct core_log_sink_std_ctx)); + + ctx->handle = GetStdHandle(STD_ERROR_HANDLE); + ctx->color = color; + + sink->ctx = (void *) ctx; + sink->write = _core_log_sink_std_write; + sink->close = _core_log_sink_std_close; +} \ No newline at end of file diff --git a/src/main/core/log-sink-std.h b/src/main/core/log-sink-std.h new file mode 100644 index 00000000..e0e006bf --- /dev/null +++ b/src/main/core/log-sink-std.h @@ -0,0 +1,24 @@ +#ifndef CORE_LOG_SINK_STD_H +#define CORE_LOG_SINK_STD_H + +#include + +#include "core/log-sink.h" + +/** + * Create a sink that writes to stdout. + * + * @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); + +/** + * Create a sink that writes to stderr. + * + * @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); + +#endif \ No newline at end of file diff --git a/src/main/core/log-sink.h b/src/main/core/log-sink.h new file mode 100644 index 00000000..7fdd42fb --- /dev/null +++ b/src/main/core/log-sink.h @@ -0,0 +1,45 @@ +#ifndef CORE_LOG_SINK_H +#define CORE_LOG_SINK_H + +#include + +/** + * Write function for a log sink implementation. + * + * Write the given data to your target output destination. + * + * @param ctx Context defined by the implementation when opening the sink. + * @param chars Buffer with text data to log. This can contain partial data of + * a single log line, a full log line terminated by a newline + * character or multiple log lines (each terminated by a newline + * character). + * @param nchars Number of characters to write. + */ +typedef void (*core_log_sink_write_t)( + void *ctx, const char *chars, size_t nchars); + +/** + * Close your log sink and cleanup resources + * + * Depending on your implementation, you might want to flush any + * outstanding/buffered data. + * + * @param ctx Context defined by the implementation when opening the sink. + */ +typedef void (*core_log_sink_close_t)(void *ctx); + +/** + * Log sink structure. + * + * This must be set-up and populated when opening your log sink implementation. + * The ctx field contains any arbitrary data that you need for your log sink + * 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 { + void *ctx; + core_log_sink_write_t write; + core_log_sink_close_t close; +}; + +#endif \ No newline at end of file diff --git a/src/main/core/log.c b/src/main/core/log.c new file mode 100644 index 00000000..9d2d6d76 --- /dev/null +++ b/src/main/core/log.c @@ -0,0 +1,74 @@ +#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/log.h b/src/main/core/log.h new file mode 100644 index 00000000..5b5cd9da --- /dev/null +++ b/src/main/core/log.h @@ -0,0 +1,197 @@ +#ifndef CORE_LOG_H +#define CORE_LOG_H + +#include +#include + +#include "util/defs.h" + +/** + * The core log API of bemanitools. + * + * To a large extent, this reflects the AVS logging 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 logging implementation by configuring it + * in the bootstrapping process. + */ + +/* BUILD_MODULE is passed in as a command-line #define by the makefile */ + +#ifndef LOG_MODULE +#define LOG_MODULE STRINGIFY(BUILD_MODULE) +#endif + +/** + * Log a message on misc level + * + * Always use this interface in your application which hides the currently + * configured implementation. + * + * The macro is required to make things work with varargs. + * The log message is only printed if the log level is set to misc + * + * @param fmt printf format string + * @param ... Additional arguments according to the specified arguments in the + * printf format string + */ +#define log_misc(...) _core_log_misc_impl(LOG_MODULE, __VA_ARGS__) + +/** + * Log a message on info level + * + * Always use this interface in your application which hides the currently + * configured implementation. + * + * The macro is required to make things work with varargs. + * The log message is only printed if the log level is set to info or lower + * + * @param fmt printf format string + * @param ... Additional arguments according to the specified arguments in the + * printf format string + */ +#define log_info(...) _core_log_info_impl(LOG_MODULE, __VA_ARGS__) + +/** + * Log a message on warning level + * + * Always use this interface in your application which hides the currently + * configured implementation. + * + * The macro is required to make things work with varargs. + * The log message is only printed if the log level is set to warning or lower + * + * @param fmt printf format string + * @param ... Additional arguments according to the specified arguments in the + * printf format string + */ +#define log_warning(...) _core_log_warning_impl(LOG_MODULE, __VA_ARGS__) + +/** + * Log a message on fatal level + * + * Always use this interface in your application which hides the currently + * configured implementation. + * + * The macro is required to make things work with varargs. + * The log message is only printed if the log level is set to fatal. + * + * This call will also terminate the application. + * + * @param fmt printf format string + * @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(); \ + } while (0) + +/** + * Log a message and terminate the application if given condition fails + * + * Always use this interface in your application which hides the currently + * configured implementation. + * + * The macro is required to make things work with varargs. + * + * @param x Condition to evaluate. If false, the application terminates + */ +#define log_assert(x) \ + do { \ + if (!(x)) { \ + _core_log_fatal_impl( \ + "assert", \ + "%s:%d: function `%s'", \ + __FILE__, \ + __LINE__, \ + __FUNCTION__); \ + abort(); \ + } \ + } while (0) + +/** + * Log a message in an exception handler + * + * Only use this function in an exception handler, e.g. for stack traces. It + * logs the message on fatal level but does not terminate. + * + * @param fmt printf format string + * @param ... Additional arguments according to the specified arguments in the + * printf format string + */ +#define log_exception_handler(...) \ + _core_log_fatal_impl("exception", __VA_ARGS__) + +typedef void (*core_log_message_t)(const char *module, const char *fmt, ...); + +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; + +#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 new file mode 100644 index 00000000..eb403ade --- /dev/null +++ b/src/main/core/thread-crt-ext.c @@ -0,0 +1,8 @@ +#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 new file mode 100644 index 00000000..a17b29b6 --- /dev/null +++ b/src/main/core/thread-crt-ext.h @@ -0,0 +1,9 @@ +#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 new file mode 100644 index 00000000..0251cf12 --- /dev/null +++ b/src/main/core/thread-crt.c @@ -0,0 +1,62 @@ +#include +#include + +#include +#include + +#include "core/thread-crt.h" +#include "core/thread.h" + +#include "util/defs.h" + +struct shim_ctx { + HANDLE barrier; + int (*proc)(void *); + void *ctx; +}; + +static unsigned int STDCALL crt_thread_shim(void *outer_ctx) +{ + struct shim_ctx *sctx = outer_ctx; + int (*proc)(void *); + void *inner_ctx; + + proc = sctx->proc; + inner_ctx = sctx->ctx; + + SetEvent(sctx->barrier); + + return proc(inner_ctx); +} + +int core_thread_crt_create( + int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority) +{ + struct shim_ctx sctx; + uintptr_t thread_id; + + 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); + + WaitForSingleObject(sctx.barrier, INFINITE); + CloseHandle(sctx.barrier); + + return (int) thread_id; +} + +void core_thread_crt_destroy(int thread_id) +{ + CloseHandle((HANDLE) (uintptr_t) thread_id); +} + +void core_thread_crt_join(int thread_id, int *result) +{ + WaitForSingleObject((HANDLE) (uintptr_t) thread_id, INFINITE); + + if (result) { + GetExitCodeThread((HANDLE) (uintptr_t) thread_id, (DWORD *) result); + } +} diff --git a/src/main/core/thread-crt.h b/src/main/core/thread-crt.h new file mode 100644 index 00000000..e9c1e8c0 --- /dev/null +++ b/src/main/core/thread-crt.h @@ -0,0 +1,15 @@ +#ifndef CORE_THREAD_CRT_H +#define CORE_THREAD_CRT_H + +#include + +/** + * 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); + +#endif diff --git a/src/main/core/thread.c b/src/main/core/thread.c new file mode 100644 index 00000000..f4e5bfeb --- /dev/null +++ b/src/main/core/thread.c @@ -0,0 +1,78 @@ +#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 new file mode 100644 index 00000000..88115665 --- /dev/null +++ b/src/main/core/thread.h @@ -0,0 +1,117 @@ +#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/d3d9exhook/config-gfx.c b/src/main/d3d9exhook/config-gfx.c index 6cf57af0..b4a51973 100644 --- a/src/main/d3d9exhook/config-gfx.c +++ b/src/main/d3d9exhook/config-gfx.c @@ -4,9 +4,9 @@ #include "cconfig/cconfig-util.h" -#include "d3d9exhook/config-gfx.h" +#include "core/log.h" -#include "util/log.h" +#include "d3d9exhook/config-gfx.h" #define D3D9EXHOOK_CONFIG_GFX_FRAMED_KEY "gfx.framed" #define D3D9EXHOOK_CONFIG_GFX_WINDOWED_KEY "gfx.windowed" diff --git a/src/main/d3d9exhook/d3d9ex.c b/src/main/d3d9exhook/d3d9ex.c index 88d95b00..80d958c3 100644 --- a/src/main/d3d9exhook/d3d9ex.c +++ b/src/main/d3d9exhook/d3d9ex.c @@ -9,13 +9,14 @@ #include #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/table.h" #include "d3d9exhook/d3d9ex.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" #include "util/time.h" diff --git a/src/main/ddrhook-util/_com4.c b/src/main/ddrhook-util/_com4.c index 44e01784..4ca08c37 100644 --- a/src/main/ddrhook-util/_com4.c +++ b/src/main/ddrhook-util/_com4.c @@ -19,6 +19,8 @@ #include "bemanitools/ddrio.h" +#include "core/log.h" + #include "ddrhook-util/_com4.h" #include "hook/iohook.h" @@ -27,7 +29,6 @@ #include "util/defs.h" #include "util/iobuf.h" -#include "util/log.h" static struct ac_io_emu com4_ac_io_emu; static struct ac_io_emu_hdxs com4_hdxs; diff --git a/src/main/ddrhook-util/dinput.c b/src/main/ddrhook-util/dinput.c index b0fdc663..949fb1eb 100644 --- a/src/main/ddrhook-util/dinput.c +++ b/src/main/ddrhook-util/dinput.c @@ -5,12 +5,13 @@ #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/pe.h" #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" static HRESULT STDCALL my_DirectInput8Create( HINSTANCE hinst, diff --git a/src/main/ddrhook-util/extio.c b/src/main/ddrhook-util/extio.c index cd2dc84b..661b165f 100644 --- a/src/main/ddrhook-util/extio.c +++ b/src/main/ddrhook-util/extio.c @@ -14,10 +14,11 @@ #include "bemanitools/ddrio.h" +#include "core/log.h" + #include "hook/iohook.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" static HRESULT extio_open(struct irp *irp); diff --git a/src/main/ddrhook-util/gfx.c b/src/main/ddrhook-util/gfx.c index 3f5f7736..0bfd0a5c 100644 --- a/src/main/ddrhook-util/gfx.c +++ b/src/main/ddrhook-util/gfx.c @@ -11,13 +11,14 @@ #include #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/table.h" #include "ddrhook-util/gfx.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" #include "util/time.h" diff --git a/src/main/ddrhook-util/misc.c b/src/main/ddrhook-util/misc.c index b74c8de6..e04390d1 100644 --- a/src/main/ddrhook-util/misc.c +++ b/src/main/ddrhook-util/misc.c @@ -2,13 +2,14 @@ #include +#include "core/log.h" + #include "ddrhook-util/gfx.h" #include "hook/pe.h" #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" static LRESULT(STDCALL *real_SendMessageW)( diff --git a/src/main/ddrhook-util/monitor.c b/src/main/ddrhook-util/monitor.c index 0dfce07f..cba18ccd 100644 --- a/src/main/ddrhook-util/monitor.c +++ b/src/main/ddrhook-util/monitor.c @@ -7,12 +7,13 @@ #include #include +#include "core/log.h" + #include "ddrhook-util/monitor.h" #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" /* Link pointers */ diff --git a/src/main/ddrhook-util/p3io.c b/src/main/ddrhook-util/p3io.c index 09b8c6f5..af0f1a93 100644 --- a/src/main/ddrhook-util/p3io.c +++ b/src/main/ddrhook-util/p3io.c @@ -7,11 +7,11 @@ #include "ddrhook-util/p3io.h" +#include "core/log.h" + #include "p3ioemu/emu.h" #include "p3ioemu/uart.h" -#include "util/log.h" - extern bool _15khz; extern bool standard_def; diff --git a/src/main/ddrhook-util/spike.c b/src/main/ddrhook-util/spike.c index 0e383d20..37cf8887 100644 --- a/src/main/ddrhook-util/spike.c +++ b/src/main/ddrhook-util/spike.c @@ -15,10 +15,11 @@ #include "acioemu/addr.h" #include "acioemu/emu.h" +#include "core/log.h" + #include "hook/iohook.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" static struct ac_io_emu spike_ac_io_emu; diff --git a/src/main/ddrhook-util/usbmem.c b/src/main/ddrhook-util/usbmem.c index f85363f3..c4e12c48 100644 --- a/src/main/ddrhook-util/usbmem.c +++ b/src/main/ddrhook-util/usbmem.c @@ -12,12 +12,13 @@ #include #include +#include "core/log.h" + #include "hook/iohook.h" #include "util/crc.h" #include "util/fs.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" #define USBMEM_DEVICE_COUNT 2 diff --git a/src/main/ddrhook1/Module.mk b/src/main/ddrhook1/Module.mk index 83782ae8..1e9dc240 100644 --- a/src/main/ddrhook1/Module.mk +++ b/src/main/ddrhook1/Module.mk @@ -7,6 +7,8 @@ deplibs_ddrhook1 := \ avs \ libs_ddrhook1 := \ + avs-util \ + core \ acioemu \ cconfig \ ddrhook-util \ diff --git a/src/main/ddrhook1/avs-boot.c b/src/main/ddrhook1/avs-boot.c index 1b7ad41a..db4445b4 100644 --- a/src/main/ddrhook1/avs-boot.c +++ b/src/main/ddrhook1/avs-boot.c @@ -5,6 +5,9 @@ #include #include +#include "core/log-bt.h" +#include "core/log.h" + #include "hook/iohook.h" #include "hook/table.h" @@ -13,7 +16,6 @@ #include "ddrhook1/avs-boot.h" #include "ddrhook1/filesystem.h" -#include "util/log.h" #include "util/str.h" static void (*real_avs_boot)( @@ -50,6 +52,11 @@ static const struct hook_symbol ddrhook1_avs_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_str( struct property_node *node, const char *name, const char *val) { @@ -115,7 +122,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/ddrhook1/config-ddrhook1.c b/src/main/ddrhook1/config-ddrhook1.c index 154f3ae3..a5872bf9 100644 --- a/src/main/ddrhook1/config-ddrhook1.c +++ b/src/main/ddrhook1/config-ddrhook1.c @@ -2,9 +2,9 @@ #include "cconfig/cconfig-util.h" -#include "ddrhook1/config-ddrhook1.h" +#include "core/log.h" -#include "util/log.h" +#include "ddrhook1/config-ddrhook1.h" #define DDRHOOK1_CONFIG_DDRHOOK1_USE_COM4_EMU_KEY "ddrhook1.use_com4_emu" #define DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY "ddrhook1.standard_def" diff --git a/src/main/ddrhook1/config-eamuse.c b/src/main/ddrhook1/config-eamuse.c index 260791d3..dbe44cde 100644 --- a/src/main/ddrhook1/config-eamuse.c +++ b/src/main/ddrhook1/config-eamuse.c @@ -2,9 +2,10 @@ #include "cconfig/cconfig-util.h" +#include "core/log.h" + #include "ddrhook1/config-eamuse.h" -#include "util/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 09ccc0c6..c71e74df 100644 --- a/src/main/ddrhook1/config-gfx.c +++ b/src/main/ddrhook1/config-gfx.c @@ -2,9 +2,9 @@ #include "cconfig/cconfig-util.h" -#include "ddrhook1/config-gfx.h" +#include "core/log.h" -#include "util/log.h" +#include "ddrhook1/config-gfx.h" #define DDRHOOK1_CONFIG_GFX_WINDOWED_KEY "gfx.windowed" diff --git a/src/main/ddrhook1/config-security.c b/src/main/ddrhook1/config-security.c index 9489b0a6..b0b7d2b2 100644 --- a/src/main/ddrhook1/config-security.c +++ b/src/main/ddrhook1/config-security.c @@ -2,11 +2,12 @@ #include "cconfig/cconfig-util.h" +#include "core/log.h" + #include "ddrhook1/config-security.h" #include "security/mcode.h" -#include "util/log.h" #include "util/net.h" #define DDRHOOK1_CONFIG_SECURITY_MCODE_KEY "security.mcode" diff --git a/src/main/ddrhook1/dllmain.c b/src/main/ddrhook1/dllmain.c index 3dcc6c94..3cccb3a7 100644 --- a/src/main/ddrhook1/dllmain.c +++ b/src/main/ddrhook1/dllmain.c @@ -2,11 +2,20 @@ #include +#include "avs-util/core-interop.h" + #include "bemanitools/ddrio.h" #include "bemanitools/eamio.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" #include "ddrhook-util/p3io.h" @@ -37,8 +46,6 @@ #include "util/cmdline.h" #include "util/defs.h" -#include "util/log.h" -#include "util/thread.h" #define DDRHOOK1_INFO_HEADER \ "ddrhook1 for DDR X" \ @@ -68,6 +75,15 @@ static const struct hook_symbol init_hook_syms[] = { }, }; +static void _ddrhook1_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 DWORD STDCALL my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize) { @@ -155,7 +171,12 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize) log_info("Initializing DDR IO backend"); - ok = ddr_io_init(thread_create, thread_join, thread_destroy); + core_log_impl_assign(ddr_io_set_loggers); + + ok = ddr_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); if (!ok) { log_fatal("Couldn't initialize DDR IO backend"); @@ -165,10 +186,12 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize) if (config_ddrhook1.use_com4_emu) { log_info("Initializing card reader backend"); - eam_io_set_loggers( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + core_log_impl_assign(eam_io_set_loggers); - ok = eam_io_init(thread_create, thread_join, thread_destroy); + ok = eam_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); if (!ok) { log_fatal("Couldn't initialize card reader backend"); @@ -185,7 +208,12 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize) BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - log_to_writer(log_writer_debug, NULL); + // 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(); 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 abec921e..9912c4f9 100644 --- a/src/main/ddrhook1/filesystem.c +++ b/src/main/ddrhook1/filesystem.c @@ -6,10 +6,11 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/ddrhook1/master.c b/src/main/ddrhook1/master.c index b30836a5..480d56f7 100644 --- a/src/main/ddrhook1/master.c +++ b/src/main/ddrhook1/master.c @@ -1,3 +1,5 @@ +#include "core/log.h" + #include "ddrhook1/master.h" #include "ddrhook-util/dinput.h" @@ -9,7 +11,6 @@ #include "p3ioemu/devmgr.h" #include "util/defs.h" -#include "util/log.h" static HMODULE(STDCALL *real_LoadLibraryA)(const char *name); static BOOL(STDCALL *real_IsDebuggerPresent)(); diff --git a/src/main/ddrhook2/Module.mk b/src/main/ddrhook2/Module.mk index 0c9fd365..e0416d66 100644 --- a/src/main/ddrhook2/Module.mk +++ b/src/main/ddrhook2/Module.mk @@ -4,6 +4,8 @@ deplibs_ddrhook2 := \ avs \ libs_ddrhook2 := \ + avs-util \ + core \ acioemu \ ddrhook-util \ p3ioemu \ diff --git a/src/main/ddrhook2/dllmain.c b/src/main/ddrhook2/dllmain.c index 90355519..cabbb941 100644 --- a/src/main/ddrhook2/dllmain.c +++ b/src/main/ddrhook2/dllmain.c @@ -2,9 +2,14 @@ #include +#include "avs-util/core-interop.h" + #include "bemanitools/ddrio.h" #include "bemanitools/eamio.h" +#include "core/log.h" +#include "core/thread.h" + #include "ddrhook-util/_com4.h" #include "ddrhook-util/extio.h" #include "ddrhook-util/gfx.h" @@ -25,7 +30,6 @@ #include "util/cmdline.h" #include "util/defs.h" -#include "util/log.h" static bool my_dll_entry_init(char *sidcode, struct property_node *param); static bool my_dll_entry_main(void); @@ -119,10 +123,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info("Initializing DDR IO backend"); - ddr_io_set_loggers( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + core_log_impl_assign(ddr_io_set_loggers); - ok = ddr_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); + ok = ddr_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); if (!ok) { return false; @@ -131,11 +137,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (com4) { log_info("Initializing card reader backend"); - eam_io_set_loggers( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + core_log_impl_assign(eam_io_set_loggers); - ok = - eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); + ok = eam_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); if (!ok) { return false; @@ -174,8 +181,9 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) goto end; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // 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); diff --git a/src/main/ddrhook2/master.c b/src/main/ddrhook2/master.c index 89f874ff..aba5451d 100644 --- a/src/main/ddrhook2/master.c +++ b/src/main/ddrhook2/master.c @@ -1,3 +1,5 @@ +#include "core/log.h" + #include "ddrhook2/master.h" #include "ddrhook-util/dinput.h" @@ -10,7 +12,6 @@ #include "p3ioemu/devmgr.h" #include "util/defs.h" -#include "util/log.h" static HMODULE(STDCALL *real_LoadLibraryA)(const char *name); diff --git a/src/main/ddrio-async/Module.mk b/src/main/ddrio-async/Module.mk index 62006cfe..2eb806dd 100644 --- a/src/main/ddrio-async/Module.mk +++ b/src/main/ddrio-async/Module.mk @@ -3,6 +3,7 @@ dlls += ddrio-async ldflags_ddrio-async:= \ libs_ddrio-async := \ + core \ util \ src_ddrio-async := \ diff --git a/src/main/ddrio-async/ddrio.c b/src/main/ddrio-async/ddrio.c index fe81f68e..998c59a5 100644 --- a/src/main/ddrio-async/ddrio.c +++ b/src/main/ddrio-async/ddrio.c @@ -11,8 +11,9 @@ #include "bemanitools/ddrio.h" -#include "util/log.h" -#include "util/thread.h" +#include "core/log.h" +#include "core/thread.h" + #include "util/time.h" typedef void (*ddr_io_set_loggers_t)( @@ -154,7 +155,7 @@ void ddr_io_set_loggers( _log_formatter_warning = warning; _log_formatter_fatal = fatal; - log_to_external(misc, info, warning, fatal); + core_log_impl_set(misc, info, warning, fatal); } bool ddr_io_init( @@ -164,6 +165,8 @@ bool ddr_io_init( { 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) { diff --git a/src/main/ddrio-mm/Module.mk b/src/main/ddrio-mm/Module.mk index 9368a623..16e3ca87 100644 --- a/src/main/ddrio-mm/Module.mk +++ b/src/main/ddrio-mm/Module.mk @@ -5,6 +5,7 @@ ldflags_ddrio-mm:= \ -lsetupapi \ libs_ddrio-mm := \ + core \ mm \ util \ diff --git a/src/main/ddrio-mm/ddrio.c b/src/main/ddrio-mm/ddrio.c index 08bd1d29..44bdd352 100644 --- a/src/main/ddrio-mm/ddrio.c +++ b/src/main/ddrio-mm/ddrio.c @@ -7,11 +7,12 @@ #include "bemanitools/ddrio.h" +#include "core/log.h" + #include "mm/mm.h" #include "util/cmdline.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" struct ddr_bittrans { @@ -117,7 +118,7 @@ void ddr_io_set_loggers( log_formatter_t warning, log_formatter_t fatal) { - log_to_external(misc, info, warning, fatal); + core_log_impl_set(misc, info, warning, fatal); } bool ddr_io_init( diff --git a/src/main/ddrio-p3io/Module.mk b/src/main/ddrio-p3io/Module.mk index 43e0fd06..2824bf0e 100644 --- a/src/main/ddrio-p3io/Module.mk +++ b/src/main/ddrio-p3io/Module.mk @@ -4,6 +4,7 @@ ldflags_ddrio-p3io:= \ -lsetupapi \ libs_ddrio-p3io := \ + core \ cconfig \ extio \ extiodrv \ diff --git a/src/main/ddrio-p3io/config.c b/src/main/ddrio-p3io/config.c index c45254e1..54591575 100644 --- a/src/main/ddrio-p3io/config.c +++ b/src/main/ddrio-p3io/config.c @@ -1,6 +1,6 @@ #include "cconfig/cconfig-util.h" -#include "util/log.h" +#include "core/log.h" #include "config.h" diff --git a/src/main/ddrio-p3io/ddrio.c b/src/main/ddrio-p3io/ddrio.c index a38ce09d..6ed7e90c 100644 --- a/src/main/ddrio-p3io/ddrio.c +++ b/src/main/ddrio-p3io/ddrio.c @@ -10,15 +10,15 @@ #include "cconfig/cconfig-main.h" +#include "core/log.h" +#include "core/thread.h" + #include "extiodrv/device.h" #include "extiodrv/extio.h" #include "p3iodrv/ddr.h" #include "p3iodrv/device.h" -#include "util/log.h" -#include "util/thread.h" - #include "config.h" static struct ddrio_p3io_config _ddr_io_p3io_config; @@ -255,7 +255,7 @@ void ddr_io_set_loggers( log_formatter_t warning, log_formatter_t fatal) { - log_to_external(misc, info, warning, fatal); + core_log_impl_set(misc, info, warning, fatal); } static void _ddr_io_config_init(struct ddrio_p3io_config *config_ddrio_p3io) diff --git a/src/main/ddrio-smx/Module.mk b/src/main/ddrio-smx/Module.mk index cc0563b2..12fd74de 100644 --- a/src/main/ddrio-smx/Module.mk +++ b/src/main/ddrio-smx/Module.mk @@ -5,6 +5,7 @@ deplibs_ddrio-smx := \ SMX \ libs_ddrio-smx := \ + core \ geninput \ util \ diff --git a/src/main/ddrio-smx/ddrio.c b/src/main/ddrio-smx/ddrio.c index a7cda337..334ccaca 100644 --- a/src/main/ddrio-smx/ddrio.c +++ b/src/main/ddrio-smx/ddrio.c @@ -6,11 +6,12 @@ #include "bemanitools/ddrio.h" #include "bemanitools/input.h" +#include "core/log.h" + #include "imports/SMX.h" #include "imports/avs.h" #include "util/defs.h" -#include "util/log.h" struct ddr_io_smx_pad_map { int pad_no; @@ -99,7 +100,7 @@ void ddr_io_set_loggers( log_formatter_t warning, log_formatter_t fatal) { - log_to_external(misc, info, warning, fatal); + core_log_impl_set(misc, info, warning, fatal); input_set_loggers(misc, info, warning, fatal); /* We would need a log server thread to accept log messages from SMX, since diff --git a/src/main/ddrio/ddrio.c b/src/main/ddrio/ddrio.c index 167b7c6e..5da99348 100644 --- a/src/main/ddrio/ddrio.c +++ b/src/main/ddrio/ddrio.c @@ -4,7 +4,7 @@ #include "bemanitools/input.h" -#include "util/log.h" +#include "core/log.h" void ddr_io_set_loggers( log_formatter_t misc, diff --git a/src/main/ddriotest/Module.mk b/src/main/ddriotest/Module.mk index 569d9736..b6cba5cb 100644 --- a/src/main/ddriotest/Module.mk +++ b/src/main/ddriotest/Module.mk @@ -1,6 +1,7 @@ exes += ddriotest \ libs_ddriotest := \ + core \ ddrio \ util \ diff --git a/src/main/ddriotest/main.c b/src/main/ddriotest/main.c index e03bc0c4..40453ce0 100644 --- a/src/main/ddriotest/main.c +++ b/src/main/ddriotest/main.c @@ -7,32 +7,41 @@ #include "bemanitools/ddrio.h" -#include "util/log.h" -#include "util/thread.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" int main(int argc, char **argv) { - enum log_level log_level; + enum core_log_bt_log_level log_level; - log_level = LOG_LEVEL_FATAL; + log_level = CORE_LOG_BT_LOG_LEVEL_FATAL; for (int i = 0; i < argc; i++) { if (!strcmp(argv[i], "-v")) { - log_level = LOG_LEVEL_WARNING; + log_level = CORE_LOG_BT_LOG_LEVEL_WARNING; } else if (!strcmp(argv[i], "-vv")) { - log_level = LOG_LEVEL_INFO; + log_level = CORE_LOG_BT_LOG_LEVEL_INFO; } else if (!strcmp(argv[i], "-vvv")) { - log_level = LOG_LEVEL_MISC; + log_level = CORE_LOG_BT_LOG_LEVEL_MISC; } } - log_to_writer(log_writer_stderr, NULL); - log_set_level(log_level); + core_thread_crt_ext_impl_set(); + core_log_bt_ext_impl_set(); - ddr_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(log_level); - if (!ddr_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) { + core_log_impl_assign(ddr_io_set_loggers); + + if (!ddr_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { fprintf(stderr, "Initializing ddrio failed\n"); return -1; } diff --git a/src/main/dinput/dinput.c b/src/main/dinput/dinput.c index 248ead4a..e65928f7 100644 --- a/src/main/dinput/dinput.c +++ b/src/main/dinput/dinput.c @@ -8,12 +8,13 @@ #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/pe.h" #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" static HRESULT STDCALL my_DirectInput8Create( HINSTANCE hinst, diff --git a/src/main/eamio-icca/Module.mk b/src/main/eamio-icca/Module.mk index 28c388e5..bcd4be83 100644 --- a/src/main/eamio-icca/Module.mk +++ b/src/main/eamio-icca/Module.mk @@ -2,6 +2,7 @@ dlls += \ eamio-icca \ libs_eamio-icca := \ + core \ aciodrv \ aciomgr \ cconfig \ diff --git a/src/main/eamio-icca/config-icc.c b/src/main/eamio-icca/config-icc.c index 660c0ee1..963f6882 100644 --- a/src/main/eamio-icca/config-icc.c +++ b/src/main/eamio-icca/config-icc.c @@ -2,8 +2,6 @@ #include "eamio-icca/config-icc.h" -#include "util/log.h" - #define EAMIO_ICCA_CONFIG_ICC_PORT_KEY "icc.port" #define EAMIO_ICCA_CONFIG_ICC_BAUD_KEY "icc.baud" diff --git a/src/main/eamio-icca/eamio-icca.c b/src/main/eamio-icca/eamio-icca.c index c681610e..db0215a9 100644 --- a/src/main/eamio-icca/eamio-icca.c +++ b/src/main/eamio-icca/eamio-icca.c @@ -14,11 +14,11 @@ #include "bemanitools/eamio.h" +#include "core/log.h" + #include "cconfig/cconfig-main.h" #include "eamio-icca/config-icc.h" -#include "util/log.h" - #define IDLE_RESPONSES_BETWEEN_FELICA_POLLS 5 #define NUMBER_OF_EMULATED_READERS 2 #define INVALID_NODE_ID -1 @@ -60,7 +60,7 @@ void eam_io_set_loggers( { aciomgr_set_loggers(misc, info, warning, fatal); - log_to_external(misc, info, warning, fatal); + core_log_impl_set(misc, info, warning, fatal); } // all of these are referred to internally as ICCA diff --git a/src/main/eamio/Module.mk b/src/main/eamio/Module.mk index f7a7409c..9cf82ed3 100644 --- a/src/main/eamio/Module.mk +++ b/src/main/eamio/Module.mk @@ -1,5 +1,5 @@ dlls += eamio -libs_eamio := geninput util +libs_eamio := core geninput util 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 03203173..9d2857d9 100644 --- a/src/main/eamio/eam-api.c +++ b/src/main/eamio/eam-api.c @@ -11,14 +11,15 @@ #include "bemanitools/eamio.h" #include "bemanitools/input.h" +#include "core/log.h" +#include "core/thread.h" + #include "eamio/eam-config.h" #include "eamio/eam-impl.h" #include "eamio/eam-s11n.h" #include "util/fs.h" -#include "util/log.h" #include "util/msg-thread.h" -#include "util/thread.h" static void eam_handle_hotplug_msg(WPARAM wparam, const DEV_BROADCAST_HDR *hdr); static FILE *eam_io_config_open(const char *mode); @@ -108,14 +109,14 @@ void eam_io_set_loggers( log_formatter_t warning, log_formatter_t fatal) { - log_to_external(misc, info, warning, fatal); + core_log_impl_set(misc, info, warning, fatal); } bool eam_io_init( thread_create_t create, thread_join_t join, thread_destroy_t destroy) { input_init(create, join, destroy); - thread_api_init(create, join, destroy); + core_thread_impl_set(create, join, destroy); eam_io_config_load(); msg_thread_init(eam_hinst); diff --git a/src/main/eamio/eam-impl.c b/src/main/eamio/eam-impl.c index 0c417094..6aca5898 100644 --- a/src/main/eamio/eam-impl.c +++ b/src/main/eamio/eam-impl.c @@ -9,6 +9,8 @@ #include "bemanitools/eamio.h" +#include "core/log.h" + #include "eamio/eam-impl.h" #include "geninput/hid-mgr.h" @@ -16,7 +18,6 @@ #include "util/defs.h" #include "util/fs.h" #include "util/hex.h" -#include "util/log.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/eamiotest/Module.mk b/src/main/eamiotest/Module.mk index a54384b7..0b9fd4b9 100644 --- a/src/main/eamiotest/Module.mk +++ b/src/main/eamiotest/Module.mk @@ -1,6 +1,7 @@ exes += eamiotest libs_eamiotest := \ + core \ eamio \ util \ diff --git a/src/main/eamiotest/main.c b/src/main/eamiotest/main.c index 9880af4a..a2f410f4 100644 --- a/src/main/eamiotest/main.c +++ b/src/main/eamiotest/main.c @@ -7,20 +7,29 @@ #include "bemanitools/eamio.h" -#include "util/log.h" -#include "util/thread.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" /** * Tool to test your implementations of eamio. */ int main(int argc, char **argv) { - log_to_writer(log_writer_stdout, NULL); + core_thread_crt_ext_impl_set(); + core_log_bt_ext_impl_set(); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_bt_ext_init_with_stdout(); - if (!eam_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) { + 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())) { printf("Initializing eamio failed\n"); return -1; } diff --git a/src/main/extiodrv/device.c b/src/main/extiodrv/device.c index ba14fa7f..e6bc788f 100644 --- a/src/main/extiodrv/device.c +++ b/src/main/extiodrv/device.c @@ -2,7 +2,7 @@ #include "device.h" -#include "util/log.h" +#include "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 8c50de2f..5b1ae6a4 100644 --- a/src/main/extiodrv/extio.c +++ b/src/main/extiodrv/extio.c @@ -2,7 +2,7 @@ #include "extio.h" -#include "util/log.h" +#include "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 73ec1b07..3e05ba08 100644 --- a/src/main/extiotest/Module.mk +++ b/src/main/extiotest/Module.mk @@ -3,6 +3,7 @@ exes += extiotest \ libs_extiotest := \ extiodrv \ extio \ + core \ util \ src_extiotest := \ diff --git a/src/main/extiotest/main.c b/src/main/extiotest/main.c index 3be152b1..c9e48bab 100644 --- a/src/main/extiotest/main.c +++ b/src/main/extiotest/main.c @@ -5,12 +5,15 @@ #include -#include "extiodrv/extio.h" +#include "core/log-bt.h" +#include "core/log-sink-std.h" +#include "core/log.h" -#include "util/log.h" +#include "extiodrv/extio.h" int main(int argc, char **argv) { + struct core_log_sink log_sink; HRESULT hr; const char *port; HANDLE handle; @@ -22,8 +25,9 @@ int main(int argc, char **argv) fprintf(stderr, " COM_PORT: For example COM1\n"); } - log_to_writer(log_writer_stderr, NULL); - log_set_level(LOG_LEVEL_MISC); + 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); port = argv[1]; diff --git a/src/main/ezusb-emu/device.c b/src/main/ezusb-emu/device.c index 9f1eca82..9cf5c98d 100644 --- a/src/main/ezusb-emu/device.c +++ b/src/main/ezusb-emu/device.c @@ -9,6 +9,8 @@ #include +#include "core/log.h" + #include "ezusb/ezusbsys2.h" #include "ezusb/util.h" @@ -25,7 +27,6 @@ #include "util/fs.h" #include "util/hex.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" // The max buffer size in iidx's ezusb client library is 4096 for the initial diff --git a/src/main/ezusb-emu/node-coin.c b/src/main/ezusb-emu/node-coin.c index 87e75037..6b4aed19 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 "util/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 ea6a3fea..f63d866f 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 "util/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 92422c82..8d11c5ff 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 "util/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 2b05a03a..ed57eed8 100644 --- a/src/main/ezusb-emu/node-security-plug.c +++ b/src/main/ezusb-emu/node-security-plug.c @@ -2,6 +2,8 @@ #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" @@ -11,8 +13,6 @@ #include "security/rp2.h" #include "security/util.h" -#include "util/log.h" - static struct security_mcode ezusb_iidx_emu_node_security_plug_boot_version; static uint32_t ezusb_iidx_emu_node_security_plug_boot_seeds[3]; diff --git a/src/main/ezusb-emu/node-sram.c b/src/main/ezusb-emu/node-sram.c index 200f1caf..dc3846b4 100644 --- a/src/main/ezusb-emu/node-sram.c +++ b/src/main/ezusb-emu/node-sram.c @@ -2,12 +2,13 @@ #include +#include "core/log.h" + #include "ezusb-emu/conf.h" #include "ezusb-emu/node-sram.h" #include "ezusb-iidx/sram-cmd.h" #include "util/fs.h" -#include "util/log.h" #define SRAM_NPAGES 12 diff --git a/src/main/ezusb-emu/node-wdt.c b/src/main/ezusb-emu/node-wdt.c index 9185bdde..8c5c5416 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 "util/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 6e2798ae..30edd425 100644 --- a/src/main/ezusb-emu/util.c +++ b/src/main/ezusb-emu/util.c @@ -6,10 +6,11 @@ #include #include +#include "core/log.h" + #include "ezusb-emu/util.h" #include "util/hex.h" -#include "util/log.h" enum ezusb_pipe { /* This is just the NT driver API. Add 1 to get the actual EP number. */ diff --git a/src/main/ezusb-iidx-16seg-emu/node-16seg.c b/src/main/ezusb-iidx-16seg-emu/node-16seg.c index 89bc5070..2121235e 100644 --- a/src/main/ezusb-iidx-16seg-emu/node-16seg.c +++ b/src/main/ezusb-iidx-16seg-emu/node-16seg.c @@ -6,9 +6,9 @@ #include "bemanitools/iidxio.h" -#include "ezusb-iidx/seg16-cmd.h" +#include "core/log.h" -#include "util/log.h" +#include "ezusb-iidx/seg16-cmd.h" uint8_t ezusb_iidx_emu_node_16seg_process_cmd( uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) diff --git a/src/main/ezusb-iidx-emu/Module.mk b/src/main/ezusb-iidx-emu/Module.mk index d6253631..16f2c1dd 100644 --- a/src/main/ezusb-iidx-emu/Module.mk +++ b/src/main/ezusb-iidx-emu/Module.mk @@ -1,6 +1,7 @@ libs += ezusb-iidx-emu libs_ezusb-iidx-emu := \ + core \ ezusb-emu \ ezusb-iidx-16seg-emu \ diff --git a/src/main/ezusb-iidx-emu/card-mag.c b/src/main/ezusb-iidx-emu/card-mag.c index a210fd69..b65414ea 100644 --- a/src/main/ezusb-iidx-emu/card-mag.c +++ b/src/main/ezusb-iidx-emu/card-mag.c @@ -2,10 +2,11 @@ #include +#include "core/log.h" + #include "security/mcode.h" #include "util/crc.h" -#include "util/log.h" static const uint16_t ezusb_iidx_emu_card_mag_checksum_table_payload[256] = { 0x0, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, diff --git a/src/main/ezusb-iidx-emu/msg.c b/src/main/ezusb-iidx-emu/msg.c index bcab6566..76b97423 100644 --- a/src/main/ezusb-iidx-emu/msg.c +++ b/src/main/ezusb-iidx-emu/msg.c @@ -6,6 +6,8 @@ #include "bemanitools/iidxio.h" +#include "core/log.h" + #include "hook/iohook.h" #include "ezusb-emu/msg.h" @@ -21,7 +23,6 @@ #include "ezusb-iidx-16seg-emu/nodes.h" #include "util/hex.h" -#include "util/log.h" /* ------------------------------------------------------------------------ */ diff --git a/src/main/ezusb-iidx-emu/node-fpga.c b/src/main/ezusb-iidx-emu/node-fpga.c index d66c440c..6615b43f 100644 --- a/src/main/ezusb-iidx-emu/node-fpga.c +++ b/src/main/ezusb-iidx-emu/node-fpga.c @@ -2,12 +2,13 @@ #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 "util/fs.h" -#include "util/log.h" static uint16_t ezusb_iidx_emu_node_fpga_write_ptr; static uint16_t ezusb_iidx_emu_node_fpga_prog_size; diff --git a/src/main/ezusb-iidx-emu/node-serial.c b/src/main/ezusb-iidx-emu/node-serial.c index 378ab02f..7dc65193 100644 --- a/src/main/ezusb-iidx-emu/node-serial.c +++ b/src/main/ezusb-iidx-emu/node-serial.c @@ -4,6 +4,9 @@ #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" @@ -11,9 +14,7 @@ #include "security/mcode.h" #include "util/hex.h" -#include "util/log.h" #include "util/mem.h" -#include "util/thread.h" #define CARD_ID_LEN 8 @@ -292,7 +293,7 @@ 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 = thread_create( + ezusb_iidx_emu_node_serial_emu_thread = core_thread_create( ezusb_iidx_emu_node_serial_emu_thread_proc, NULL, 0x4000, 0); } diff --git a/src/main/ezusb-iidx-fpga-flash/Module.mk b/src/main/ezusb-iidx-fpga-flash/Module.mk index c250b35b..320d6f49 100644 --- a/src/main/ezusb-iidx-fpga-flash/Module.mk +++ b/src/main/ezusb-iidx-fpga-flash/Module.mk @@ -4,6 +4,7 @@ ldflags_ezusb-iidx-fpga-flash := \ -lsetupapi \ libs_ezusb-iidx-fpga-flash := \ + core \ ezusb \ ezusb-iidx \ util \ diff --git a/src/main/ezusb-iidx-fpga-flash/main.c b/src/main/ezusb-iidx-fpga-flash/main.c index a8fb6816..f8dacdd3 100644 --- a/src/main/ezusb-iidx-fpga-flash/main.c +++ b/src/main/ezusb-iidx-fpga-flash/main.c @@ -3,11 +3,14 @@ #include +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log.h" + #include "ezusb-iidx/fpga.h" #include "ezusb/ezusb.h" #include "util/fs.h" -#include "util/log.h" int main(int argc, char **argv) { @@ -24,7 +27,8 @@ int main(int argc, char **argv) return -1; } - log_to_writer(log_writer_stderr, NULL); + core_log_bt_ext_impl_set(); + core_log_bt_ext_init_with_stderr(); 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 b6e6a73d..a369b060 100644 --- a/src/main/ezusb-iidx-sram-flash/Module.mk +++ b/src/main/ezusb-iidx-sram-flash/Module.mk @@ -4,6 +4,7 @@ ldflags_ezusb-iidx-sram-flash := \ -lsetupapi \ libs_ezusb-iidx-sram-flash := \ + core \ ezusb \ ezusb-iidx \ util \ diff --git a/src/main/ezusb-iidx-sram-flash/main.c b/src/main/ezusb-iidx-sram-flash/main.c index d22464e0..b4fa94d3 100644 --- a/src/main/ezusb-iidx-sram-flash/main.c +++ b/src/main/ezusb-iidx-sram-flash/main.c @@ -3,11 +3,14 @@ #include +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log.h" + #include "ezusb-iidx/sram.h" #include "ezusb/ezusb.h" #include "util/fs.h" -#include "util/log.h" int main(int argc, char **argv) { @@ -24,7 +27,8 @@ int main(int argc, char **argv) return -1; } - log_to_writer(log_writer_stdout, NULL); + core_log_bt_ext_impl_set(); + core_log_bt_ext_init_with_stdout(); 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 e82e2145..ae035b73 100644 --- a/src/main/ezusb-iidx/ezusb-iidx.c +++ b/src/main/ezusb-iidx/ezusb-iidx.c @@ -1,11 +1,12 @@ #define LOG_MODULE "ezusb-iidx" +#include "core/log.h" + #include "ezusb-iidx/ezusb-iidx.h" #include "ezusb/ezusbsys2.h" #include "util/hex.h" -#include "util/log.h" #include "util/time.h" #include "msg.h" diff --git a/src/main/ezusb-iidx/fpga.c b/src/main/ezusb-iidx/fpga.c index 23d5fd05..b4d25500 100644 --- a/src/main/ezusb-iidx/fpga.c +++ b/src/main/ezusb-iidx/fpga.c @@ -4,7 +4,7 @@ #include -#include "util/log.h" +#include "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 f816b383..fcce3840 100644 --- a/src/main/ezusb-iidx/sram.c +++ b/src/main/ezusb-iidx/sram.c @@ -1,8 +1,8 @@ #define LOG_MODULE "ezusb-iidx-sram" -#include "ezusb-iidx/sram.h" +#include "core/log.h" -#include "util/log.h" +#include "ezusb-iidx/sram.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 349bc089..b5e81588 100644 --- a/src/main/ezusb-tool/Module.mk +++ b/src/main/ezusb-tool/Module.mk @@ -4,6 +4,7 @@ ldflags_ezusb-tool := \ -lsetupapi \ libs_ezusb-tool := \ + core \ ezusb \ util \ diff --git a/src/main/ezusb-tool/main.c b/src/main/ezusb-tool/main.c index 115f79c5..ca847815 100644 --- a/src/main/ezusb-tool/main.c +++ b/src/main/ezusb-tool/main.c @@ -3,11 +3,13 @@ #include #include +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log.h" + #include "ezusb/ezusb.h" #include "ezusb/util.h" -#include "util/log.h" - static int info() { HANDLE handle; @@ -103,7 +105,8 @@ int main(int argc, char **argv) arg_pos = 1; - log_to_writer(log_writer_stderr, NULL); + core_log_bt_ext_impl_set(); + core_log_bt_ext_init_with_stderr(); if (!strcmp(argv[arg_pos], "info")) { return info(); diff --git a/src/main/ezusb/ezusb.c b/src/main/ezusb/ezusb.c index ce1b828e..7204589a 100644 --- a/src/main/ezusb/ezusb.c +++ b/src/main/ezusb/ezusb.c @@ -4,10 +4,11 @@ #include // clang-format on +#include "core/log.h" + #include "ezusb/ezusb.h" #include "ezusb/ezusbsys2.h" -#include "util/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 efc2cd10..5bf18a45 100644 --- a/src/main/ezusb/util.c +++ b/src/main/ezusb/util.c @@ -1,11 +1,12 @@ #include #include +#include "core/log.h" + #include "ezusb/util.h" #include "util/crc.h" #include "util/fs.h" -#include "util/log.h" #include "util/mem.h" struct ezusb_firmware *ezusb_firmware_load(const char *file) diff --git a/src/main/ezusb2-dbg-hook/Module.mk b/src/main/ezusb2-dbg-hook/Module.mk index 4290f5cf..579e9bfb 100644 --- a/src/main/ezusb2-dbg-hook/Module.mk +++ b/src/main/ezusb2-dbg-hook/Module.mk @@ -1,6 +1,7 @@ dlls += ezusb2-dbg-hook libs_ezusb2-dbg-hook := \ + core \ hook \ util \ diff --git a/src/main/ezusb2-dbg-hook/main.c b/src/main/ezusb2-dbg-hook/main.c index e90d3fb0..e1c1bdbb 100644 --- a/src/main/ezusb2-dbg-hook/main.c +++ b/src/main/ezusb2-dbg-hook/main.c @@ -10,13 +10,17 @@ #include #include +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log-sink-file.h" +#include "core/log.h" + #include "ezusb2/cyioctl.h" #include "hook/table.h" #include "util/cmdline.h" #include "util/hex.h" -#include "util/log.h" #include "util/str.h" static HANDLE STDCALL my_CreateFileW( @@ -367,14 +371,13 @@ static void ezusb2_dbg_hook_terminate_process() BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - FILE *file; int argc; char **argv; wchar_t *buffer; uint32_t args_success; - file = fopen("ezusb2_dbg.log", "w+"); - log_to_writer(log_writer_file, file); + core_log_bt_ext_impl_set(); + core_log_bt_ext_init_with_file("ezusb2_dbg.log", false, false, 0); hook_table_apply( NULL, diff --git a/src/main/ezusb2-emu/device.c b/src/main/ezusb2-emu/device.c index f4652798..ecba8163 100644 --- a/src/main/ezusb2-emu/device.c +++ b/src/main/ezusb2-emu/device.c @@ -9,6 +9,8 @@ #include +#include "core/log.h" + #include "ezusb/util.h" #include "ezusb2/cyioctl.h" @@ -27,7 +29,6 @@ #include "util/fs.h" #include "util/hex.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" // The max buffer size in iidx's ezusb client library is 4096 for the initial diff --git a/src/main/ezusb2-emu/util.c b/src/main/ezusb2-emu/util.c index 2abd5134..d5b12b92 100644 --- a/src/main/ezusb2-emu/util.c +++ b/src/main/ezusb2-emu/util.c @@ -6,13 +6,14 @@ #include #include +#include "core/log.h" + #include "ezusb2/cyioctl.h" #include "ezusb2/ezusb2.h" #include "ezusb-emu/util.h" #include "util/hex.h" -#include "util/log.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 1279ea9b..bfc3dce8 100644 --- a/src/main/ezusb2-iidx-emu/msg.c +++ b/src/main/ezusb2-iidx-emu/msg.c @@ -6,6 +6,8 @@ #include "bemanitools/iidxio.h" +#include "core/log.h" + #include "hook/iohook.h" #include "ezusb-emu/msg.h" @@ -15,7 +17,6 @@ #include "ezusb2-iidx/msg.h" #include "util/hex.h" -#include "util/log.h" /* ------------------------------------------------------------------------ */ diff --git a/src/main/ezusb2-popn-emu/msg.c b/src/main/ezusb2-popn-emu/msg.c index 6e83f7ac..d696ecc3 100644 --- a/src/main/ezusb2-popn-emu/msg.c +++ b/src/main/ezusb2-popn-emu/msg.c @@ -6,6 +6,8 @@ #include "bemanitools/popnio.h" +#include "core/log.h" + #include "hook/iohook.h" #include "ezusb-emu/msg.h" @@ -19,7 +21,6 @@ #include "ezusb2-popn/msg.h" #include "util/hex.h" -#include "util/log.h" /* ------------------------------------------------------------------------ */ diff --git a/src/main/ezusb2-popn-shim/Module.mk b/src/main/ezusb2-popn-shim/Module.mk index aefc2d40..f4536c47 100644 --- a/src/main/ezusb2-popn-shim/Module.mk +++ b/src/main/ezusb2-popn-shim/Module.mk @@ -4,6 +4,7 @@ ldflags_ezusb2-popn-shim := \ -lsetupapi \ libs_ezusb2-popn-shim := \ + core \ ezusb2-emu \ hook \ hooklib \ diff --git a/src/main/ezusb2-popn-shim/dllmain.c b/src/main/ezusb2-popn-shim/dllmain.c index c8e16fcf..ec7e18f6 100644 --- a/src/main/ezusb2-popn-shim/dllmain.c +++ b/src/main/ezusb2-popn-shim/dllmain.c @@ -4,6 +4,8 @@ #include +#include "core/log.h" + #include "ezusb2-emu/desc.h" #include "ezusb2-emu/device.h" @@ -13,8 +15,6 @@ #include "ezusb2-popn-shim/proxy.h" -#include "util/log.h" - #define EZUSB_REAL_DLL_FILENAME "ezusb.dll" static DWORD(STDCALL *real_entrypoint)(HMODULE self, DWORD reason, void *ctx); diff --git a/src/main/ezusb2-popn-shim/proxy.c b/src/main/ezusb2-popn-shim/proxy.c index fdf4f9f9..ec47002f 100644 --- a/src/main/ezusb2-popn-shim/proxy.c +++ b/src/main/ezusb2-popn-shim/proxy.c @@ -2,7 +2,7 @@ #include #include -#include "util/log.h" +#include "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 06115652..87e6dff8 100644 --- a/src/main/ezusb2-tool/Module.mk +++ b/src/main/ezusb2-tool/Module.mk @@ -4,6 +4,7 @@ ldflags_ezusb2-tool := \ -lsetupapi \ libs_ezusb2-tool := \ + core \ ezusb2 \ ezusb \ util \ diff --git a/src/main/ezusb2-tool/main.c b/src/main/ezusb2-tool/main.c index cdfd179b..0579c077 100644 --- a/src/main/ezusb2-tool/main.c +++ b/src/main/ezusb2-tool/main.c @@ -3,11 +3,13 @@ #include #include +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log.h" + #include "ezusb/util.h" #include "ezusb2/ezusb2.h" -#include "util/log.h" - static int scan() { char *path; @@ -122,7 +124,8 @@ int main(int argc, char **argv) arg_pos = 1; - log_to_writer(log_writer_stderr, NULL); + core_log_bt_ext_impl_set(); + core_log_bt_ext_init_with_stderr(); if (!strcmp(argv[arg_pos], "scan")) { return scan(); diff --git a/src/main/ezusb2/ezusb2.c b/src/main/ezusb2/ezusb2.c index 61fabd73..2c1b7b97 100644 --- a/src/main/ezusb2/ezusb2.c +++ b/src/main/ezusb2/ezusb2.c @@ -4,6 +4,8 @@ #include // clang-format on +#include "core/log.h" + #include "ezusb/ezusb.h" #include "ezusb2/cyioctl.h" @@ -11,7 +13,6 @@ #include "util/crc.h" #include "util/fs.h" -#include "util/log.h" #include "util/str.h" #define REQ_TYPE_HOST_TO_DEV 0x40 diff --git a/src/main/geninput/Module.mk b/src/main/geninput/Module.mk index 1521d806..3115edf0 100644 --- a/src/main/geninput/Module.mk +++ b/src/main/geninput/Module.mk @@ -5,6 +5,7 @@ ldflags_geninput := \ -lsetupapi \ libs_geninput := \ + core \ util \ src_geninput := \ diff --git a/src/main/geninput/dev-list.c b/src/main/geninput/dev-list.c index 2bfcb4e8..ce6d93ac 100644 --- a/src/main/geninput/dev-list.c +++ b/src/main/geninput/dev-list.c @@ -9,9 +9,10 @@ #include #include +#include "core/log.h" + #include "geninput/dev-list.h" -#include "util/log.h" #include "util/mem.h" void dev_list_init(struct dev_list *devs, const GUID *class_guid) diff --git a/src/main/geninput/hid-generic.c b/src/main/geninput/hid-generic.c index 41e73828..46c2924b 100644 --- a/src/main/geninput/hid-generic.c +++ b/src/main/geninput/hid-generic.c @@ -12,6 +12,8 @@ #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" @@ -19,7 +21,6 @@ #include "geninput/hid.h" #include "util/defs.h" -#include "util/log.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 bbaf44f1..3a324947 100644 --- a/src/main/geninput/hid-meta-in.c +++ b/src/main/geninput/hid-meta-in.c @@ -11,10 +11,11 @@ #include #include +#include "core/log.h" + #include "geninput/hid-meta-in.h" #include "geninput/hid-report-in.h" -#include "util/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 4f87602a..19037851 100644 --- a/src/main/geninput/hid-meta-out.c +++ b/src/main/geninput/hid-meta-out.c @@ -12,10 +12,11 @@ #include #include +#include "core/log.h" + #include "geninput/hid-meta-out.h" #include "geninput/hid-report-out.h" -#include "util/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 f22d3a78..2f8a7c13 100644 --- a/src/main/geninput/hid-mgr.c +++ b/src/main/geninput/hid-mgr.c @@ -2,9 +2,10 @@ #include +#include "core/log.h" + #include "geninput/hid-mgr.h" -#include "util/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 721a721d..aec213de 100644 --- a/src/main/geninput/hid-report-in.c +++ b/src/main/geninput/hid-report-in.c @@ -10,9 +10,10 @@ #include #include +#include "core/log.h" + #include "geninput/hid-report-in.h" -#include "util/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 5469e3a3..892cd13f 100644 --- a/src/main/geninput/hid-report-out.c +++ b/src/main/geninput/hid-report-out.c @@ -11,9 +11,10 @@ #include #include +#include "core/log.h" + #include "geninput/hid-report-out.h" -#include "util/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 57685b02..889ee80f 100644 --- a/src/main/geninput/hid.c +++ b/src/main/geninput/hid.c @@ -1,10 +1,11 @@ #include #include +#include "core/log.h" + #include "geninput/dev-list.h" #include "geninput/hid.h" -#include "util/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 54dad425..d9954d37 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 "util/log.h" - static HDEVNOTIFY hotplug_handle; void hotplug_init(HWND wnd) diff --git a/src/main/geninput/input.c b/src/main/geninput/input.c index 60c94c26..e67df3d7 100644 --- a/src/main/geninput/input.c +++ b/src/main/geninput/input.c @@ -7,6 +7,9 @@ #include "bemanitools/glue.h" #include "bemanitools/input.h" +#include "core/log.h" +#include "core/thread.h" + #include "geninput/hid-mgr.h" #include "geninput/hid.h" #include "geninput/io-thread.h" @@ -14,10 +17,8 @@ #include "geninput/mapper.h" #include "util/fs.h" -#include "util/log.h" #include "util/msg-thread.h" #include "util/str.h" -#include "util/thread.h" static HINSTANCE input_hinst; static volatile long input_init_count; @@ -47,7 +48,7 @@ void input_set_loggers( log_formatter_t warning, log_formatter_t fatal) { - log_to_external(misc, info, warning, fatal); + core_log_impl_set(misc, info, warning, fatal); } void input_init( @@ -63,7 +64,7 @@ void input_init( mapper_inst = mapper_impl_create(); - thread_api_init(create, join, destroy); + core_thread_impl_set(create, join, destroy); msg_thread_init(input_hinst); io_thread_init(); } diff --git a/src/main/geninput/io-thread.c b/src/main/geninput/io-thread.c index ca663ff3..18f5ccca 100644 --- a/src/main/geninput/io-thread.c +++ b/src/main/geninput/io-thread.c @@ -2,6 +2,9 @@ #include +#include "core/log.h" +#include "core/thread.h" + #include "geninput/dev-list.h" #include "geninput/hid-generic.h" #include "geninput/hid-mgr.h" @@ -10,9 +13,7 @@ #include "geninput/pacdrive.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" -#include "util/thread.h" enum io_thread_cmd { IO_THREAD_CMD_STOP, @@ -172,7 +173,7 @@ void io_thread_init(void) barrier = CreateEvent(NULL, TRUE, FALSE, NULL); - io_thread_id = thread_create(io_thread_proc, barrier, 16384, 0); + io_thread_id = core_thread_create(io_thread_proc, barrier, 16384, 0); WaitForSingleObject(barrier, INFINITE); CloseHandle(barrier); @@ -200,6 +201,6 @@ void io_thread_fini(void) PostQueuedCompletionStatus(io_thread_cp, 0, (uintptr_t) &msg, NULL); - thread_join(io_thread_id, NULL); - thread_destroy(io_thread_id); + core_thread_join(io_thread_id, NULL); + core_thread_destroy(io_thread_id); } diff --git a/src/main/geninput/kbd.c b/src/main/geninput/kbd.c index 9ae8e5ed..191890b0 100644 --- a/src/main/geninput/kbd.c +++ b/src/main/geninput/kbd.c @@ -11,12 +11,13 @@ #include #include +#include "core/log.h" + #include "geninput/hid.h" #include "geninput/kbd-data.h" #include "geninput/kbd.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/geninput/mapper.c b/src/main/geninput/mapper.c index c3d02143..3c66c19c 100644 --- a/src/main/geninput/mapper.c +++ b/src/main/geninput/mapper.c @@ -1,11 +1,12 @@ #include #include +#include "core/log.h" + #include "geninput/hid-mgr.h" #include "geninput/mapper.h" #include "util/array.h" -#include "util/log.h" #include "util/mem.h" struct action_iter { diff --git a/src/main/geninput/mouse.c b/src/main/geninput/mouse.c index 2b24d1c8..f1c54bfd 100644 --- a/src/main/geninput/mouse.c +++ b/src/main/geninput/mouse.c @@ -12,11 +12,12 @@ #include #include +#include "core/log.h" + #include "geninput/hid.h" #include "geninput/mouse.h" #include "util/defs.h" -#include "util/log.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 cc21ae06..7ca47f32 100644 --- a/src/main/geninput/msg-thread.c +++ b/src/main/geninput/msg-thread.c @@ -6,10 +6,11 @@ #include +#include "core/log.h" + #include "geninput/hotplug.h" #include "geninput/ri.h" -#include "util/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 2a5ab36f..b388036f 100644 --- a/src/main/geninput/pacdrive.c +++ b/src/main/geninput/pacdrive.c @@ -11,12 +11,13 @@ #include #include +#include "core/log.h" + #include "geninput/hid.h" #include "geninput/io-thread.h" #include "geninput/pacdrive.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" /* The PacDrive appears to have a malformed descriptor for its OUT report. diff --git a/src/main/geninput/ri.c b/src/main/geninput/ri.c index b3befee9..45b6d65b 100644 --- a/src/main/geninput/ri.c +++ b/src/main/geninput/ri.c @@ -1,5 +1,7 @@ #include +#include "core/log.h" + #include "geninput/hid-mgr.h" #include "geninput/hid.h" #include "geninput/kbd.h" @@ -7,7 +9,6 @@ #include "geninput/ri.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" struct ri_handle { diff --git a/src/main/hook/d3d9.c b/src/main/hook/d3d9.c index 45e1fd14..0f09ec68 100644 --- a/src/main/hook/d3d9.c +++ b/src/main/hook/d3d9.c @@ -1,11 +1,11 @@ #define LOG_MODULE "hook-d3d9" -#include "hook/d3d9.h" +#include "core/log.h" + #include "hook/com-proxy.h" +#include "hook/d3d9.h" #include "hook/table.h" -#include "util/log.h" - /* ------------------------------------------------------------------------------------------------------------------ */ diff --git a/src/main/hook/table.c b/src/main/hook/table.c index ed67b3b6..285a43d3 100644 --- a/src/main/hook/table.c +++ b/src/main/hook/table.c @@ -15,12 +15,21 @@ static const size_t apiset_prefix_len = sizeof(apiset_prefix) - 1; static void hook_table_apply_to_all( const char *depname, const struct hook_symbol *syms, size_t nsyms); +static void hook_table_revert_to_all( + const char *depname, const struct hook_symbol *syms, size_t nsyms); + static void hook_table_apply_to_iid( HMODULE target, const pe_iid_t *iid, const struct hook_symbol *syms, size_t nsyms); +static void hook_table_revert_to_iid( + HMODULE target, + const pe_iid_t *iid, + const struct hook_symbol *syms, + size_t nsyms); + static bool hook_table_match_module( HMODULE target, const char *iid_name, const char *depname); @@ -44,6 +53,23 @@ static void hook_table_apply_to_all( } } +static void hook_table_revert_to_all( + const char *depname, const struct hook_symbol *syms, size_t nsyms) +{ + const peb_dll_t *dll; + HMODULE pe; + + for (dll = peb_dll_get_first(); dll != NULL; dll = peb_dll_get_next(dll)) { + pe = peb_dll_get_base(dll); + + if (pe == NULL) { + continue; /* ?? Happens sometimes. */ + } + + hook_table_revert(pe, depname, syms, nsyms); + } +} + void hook_table_apply( HMODULE target, const char *depname, @@ -73,6 +99,35 @@ void hook_table_apply( } } +void hook_table_revert( + HMODULE target, + const char *depname, + const struct hook_symbol *syms, + size_t nsyms) +{ + const pe_iid_t *iid; + const char *iid_name; + + assert(depname != NULL); + assert(syms != NULL || nsyms == 0); + + if (target == NULL) { + /* Call out, which will then call us back repeatedly. Awkward, but + viewed from the outside it's good for usability. */ + + hook_table_revert_to_all(depname, syms, nsyms); + } else { + for (iid = pe_iid_get_first(target); iid != NULL; + iid = pe_iid_get_next(target, iid)) { + iid_name = pe_iid_get_name(target, iid); + + if (hook_table_match_module(target, iid_name, depname)) { + hook_table_revert_to_iid(target, iid, syms, nsyms); + } + } + } +} + static void hook_table_apply_to_iid( HMODULE target, const pe_iid_t *iid, @@ -101,6 +156,34 @@ static void hook_table_apply_to_iid( } } +static void hook_table_revert_to_iid( + HMODULE target, + const pe_iid_t *iid, + const struct hook_symbol *syms, + size_t nsyms) +{ + struct pe_iat_entry iate; + size_t i; + size_t j; + const struct hook_symbol *sym; + + i = 0; + + while (pe_iid_get_iat_entry(target, iid, i++, &iate) == S_OK) { + for (j = 0; j < nsyms; j++) { + sym = &syms[j]; + + if (hook_table_match_proc(&iate, sym)) { + // Only revert-able if the original pointer was stored + // previously + if (sym->link != NULL && *sym->link != NULL) { + pe_patch(iate.ppointer, sym->link, sizeof(*sym->link)); + } + } + } + } +} + static bool hook_table_match_module( HMODULE target, const char *iid_name, const char *depname) { diff --git a/src/main/hooklib/acp.c b/src/main/hooklib/acp.c index 52675b2d..81faa738 100644 --- a/src/main/hooklib/acp.c +++ b/src/main/hooklib/acp.c @@ -6,13 +6,14 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "hooklib/acp.h" #include "util/codepage.h" #include "util/defs.h" -#include "util/log.h" static NTSTATUS NTAPI my_RtlMultiByteToUnicodeN( wchar_t *dest, diff --git a/src/main/hooklib/adapter.c b/src/main/hooklib/adapter.c index 0b94c125..8b3b6d9f 100644 --- a/src/main/hooklib/adapter.c +++ b/src/main/hooklib/adapter.c @@ -6,13 +6,14 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "hooklib/adapter.h" #include "util/codepage.h" #include "util/defs.h" -#include "util/log.h" static DWORD WINAPI my_GetAdaptersInfo(PIP_ADAPTER_INFO adapter_info, PULONG out_buf_len); diff --git a/src/main/hooklib/app.c b/src/main/hooklib/app.c index 7ccd441d..11fb8243 100644 --- a/src/main/hooklib/app.c +++ b/src/main/hooklib/app.c @@ -1,5 +1,7 @@ #include +#include "core/log.h" + #include "hook/table.h" #include "hooklib/app.h" @@ -7,7 +9,6 @@ #include "imports/avs.h" #include "imports/eapki.h" -#include "util/log.h" #include "util/str.h" static dll_entry_init_t hook_dll_entry_init; diff --git a/src/main/hooklib/config-adapter.c b/src/main/hooklib/config-adapter.c index 49c24505..0ddb6806 100644 --- a/src/main/hooklib/config-adapter.c +++ b/src/main/hooklib/config-adapter.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "hooklib/config-adapter.h" +#include "core/log.h" -#include "util/log.h" +#include "hooklib/config-adapter.h" #define HOOKLIB_CONFIG_ADAPTER_OVERRIDE_IP_KEY "adapter.override_ip" diff --git a/src/main/hooklib/memfile.c b/src/main/hooklib/memfile.c index 08dbeba1..09c05878 100644 --- a/src/main/hooklib/memfile.c +++ b/src/main/hooklib/memfile.c @@ -3,12 +3,13 @@ #include #include +#include "core/log.h" + #include "hook/hr.h" #include "hook/iohook.h" #include "hook/table.h" #include "util/array.h" -#include "util/log.h" #include "util/str.h" struct file_entry { diff --git a/src/main/hooklib/rs232.c b/src/main/hooklib/rs232.c index 8d6d371f..591c98f4 100644 --- a/src/main/hooklib/rs232.c +++ b/src/main/hooklib/rs232.c @@ -14,12 +14,13 @@ #include #include +#include "core/log.h" + #include "hook/hr.h" #include "hook/iohook.h" #include "hook/table.h" #include "util/array.h" -#include "util/log.h" /* RS232 API hooks */ diff --git a/src/main/hooklib/setupapi.c b/src/main/hooklib/setupapi.c index 07dc72cf..5363c52a 100644 --- a/src/main/hooklib/setupapi.c +++ b/src/main/hooklib/setupapi.c @@ -4,12 +4,13 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "hooklib/setupapi.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" /* my hooks */ diff --git a/src/main/iidx-bio2-exit-hook/Module.mk b/src/main/iidx-bio2-exit-hook/Module.mk index dcf7289b..085af3a8 100644 --- a/src/main/iidx-bio2-exit-hook/Module.mk +++ b/src/main/iidx-bio2-exit-hook/Module.mk @@ -4,6 +4,7 @@ ldflags_iidx-bio2-exit-hook := \ -lsetupapi \ libs_iidx-bio2-exit-hook := \ + core \ bio2drv \ hook \ util \ diff --git a/src/main/iidx-bio2-exit-hook/main.c b/src/main/iidx-bio2-exit-hook/main.c index 13ac8251..2718717c 100644 --- a/src/main/iidx-bio2-exit-hook/main.c +++ b/src/main/iidx-bio2-exit-hook/main.c @@ -11,10 +11,13 @@ #include "bio2/bi2a-iidx.h" #include "bio2drv/detect.h" +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log.h" + #include "hook/iobuf.h" #include "hook/iohook.h" -#include "util/log.h" #include "util/mem.h" #include "util/proc.h" #include "util/str.h" @@ -224,7 +227,8 @@ static HRESULT _iohook_handler(struct irp *irp) BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { - log_to_writer(log_writer_stdout, NULL); + core_log_bt_ext_impl_set(); + core_log_bt_ext_init_with_stdout(); 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 4050ebe1..500bd156 100644 --- a/src/main/iidx-ezusb-exit-hook/Module.mk +++ b/src/main/iidx-ezusb-exit-hook/Module.mk @@ -1,6 +1,7 @@ dlls += iidx-ezusb-exit-hook libs_iidx-ezusb-exit-hook := \ + core \ ezusb-iidx \ hook \ util \ diff --git a/src/main/iidx-ezusb2-exit-hook/Module.mk b/src/main/iidx-ezusb2-exit-hook/Module.mk index 7828a97b..f449f383 100644 --- a/src/main/iidx-ezusb2-exit-hook/Module.mk +++ b/src/main/iidx-ezusb2-exit-hook/Module.mk @@ -1,6 +1,7 @@ dlls += iidx-ezusb2-exit-hook libs_iidx-ezusb2-exit-hook := \ + core \ hook \ util \ diff --git a/src/main/iidx-irbeat-patch/Module.mk b/src/main/iidx-irbeat-patch/Module.mk index df42cd3d..d01645fa 100644 --- a/src/main/iidx-irbeat-patch/Module.mk +++ b/src/main/iidx-irbeat-patch/Module.mk @@ -2,6 +2,7 @@ exes += iidx-irbeat-patch libs_iidx-irbeat-patch := \ util \ + core \ src_iidx-irbeat-patch := \ main.c \ diff --git a/src/main/iidxhook-d3d9/bb-scale-hd.c b/src/main/iidxhook-d3d9/bb-scale-hd.c index 60dae6be..84afe7c8 100644 --- a/src/main/iidxhook-d3d9/bb-scale-hd.c +++ b/src/main/iidxhook-d3d9/bb-scale-hd.c @@ -2,13 +2,13 @@ #include +#include "core/log.h" + #include "d3d9-util/vertex.h" #include "bb-scale-hd.h" #include "util.h" -#include "util/log.h" - static bool iidxhook_d3d9_bb_scale_initialized; static uint16_t iidxhook_d3d9_bb_scale_hd_width; static uint16_t iidxhook_d3d9_bb_scale_hd_height; diff --git a/src/main/iidxhook-d3d9/util.h b/src/main/iidxhook-d3d9/util.h index 3a77e99b..96b489e0 100644 --- a/src/main/iidxhook-d3d9/util.h +++ b/src/main/iidxhook-d3d9/util.h @@ -3,9 +3,9 @@ #include -#include "d3d9-util/dxerr9.h" +#include "core/log.h" -#include "util/log.h" +#include "d3d9-util/dxerr9.h" inline void iidxhook_d3d9_util_check_and_handle_failure(HRESULT hr, const char *msg) diff --git a/src/main/iidxhook-util/Module.mk b/src/main/iidxhook-util/Module.mk index 92fe44d8..50dd18dc 100644 --- a/src/main/iidxhook-util/Module.mk +++ b/src/main/iidxhook-util/Module.mk @@ -1,6 +1,7 @@ libs += iidxhook-util libs_iidxhook-util := \ + core \ util \ src_iidxhook-util := \ diff --git a/src/main/iidxhook-util/acio.c b/src/main/iidxhook-util/acio.c index 62913361..a52fa766 100644 --- a/src/main/iidxhook-util/acio.c +++ b/src/main/iidxhook-util/acio.c @@ -15,6 +15,8 @@ #include "acioemu/emu.h" #include "acioemu/icca.h" +#include "core/log.h" + #include "hook/iohook.h" #include "hooklib/rs232.h" @@ -24,7 +26,6 @@ #include "util/defs.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" static struct ac_io_emu iidxhook_util_acio_emu; diff --git a/src/main/iidxhook-util/chart-patch.c b/src/main/iidxhook-util/chart-patch.c index 4b2970ec..b6cc290d 100644 --- a/src/main/iidxhook-util/chart-patch.c +++ b/src/main/iidxhook-util/chart-patch.c @@ -4,12 +4,13 @@ #include #include +#include "core/log.h" + #include "hook/iohook.h" #include "util/crc.h" #include "util/defs.h" #include "util/fs.h" -#include "util/log.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/iidxhook-util/clock.c b/src/main/iidxhook-util/clock.c index 8c870fff..dc0e2f2f 100644 --- a/src/main/iidxhook-util/clock.c +++ b/src/main/iidxhook-util/clock.c @@ -2,10 +2,11 @@ #include +#include "core/log.h" + #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" static BOOL STDCALL my_SetLocalTime(const SYSTEMTIME *lpSystemTime); static BOOL(STDCALL *real_SetLocalTime)(const SYSTEMTIME *lpSystemTime); diff --git a/src/main/iidxhook-util/config-eamuse.c b/src/main/iidxhook-util/config-eamuse.c index f59b03e8..c75bd1a7 100644 --- a/src/main/iidxhook-util/config-eamuse.c +++ b/src/main/iidxhook-util/config-eamuse.c @@ -2,12 +2,12 @@ #include "cconfig/cconfig-util.h" +#include "core/log.h" + #include "iidxhook-util/config-eamuse.h" #include "security/mcode.h" -#include "util/log.h" - #define IIDXHOOK_CONFIG_EAMUSE_CARD_TYPE_KEY "eamuse.card_type" #define IIDXHOOK_CONFIG_EAMUSE_SERVER_KEY "eamuse.server" #define IIDXHOOK_CONFIG_EAMUSE_PCBID_KEY "eamuse.pcbid" diff --git a/src/main/iidxhook-util/config-ezusb.c b/src/main/iidxhook-util/config-ezusb.c index e860a1d5..14d953d2 100644 --- a/src/main/iidxhook-util/config-ezusb.c +++ b/src/main/iidxhook-util/config-ezusb.c @@ -3,9 +3,10 @@ #include "cconfig/cconfig-util.h" +#include "core/log.h" + #include "iidxhook-util/config-ezusb.h" -#include "util/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 e591f480..1be281fe 100644 --- a/src/main/iidxhook-util/config-gfx.c +++ b/src/main/iidxhook-util/config-gfx.c @@ -2,9 +2,9 @@ #include "cconfig/cconfig-util.h" -#include "iidxhook-util/config-gfx.h" +#include "core/log.h" -#include "util/log.h" +#include "iidxhook-util/config-gfx.h" #define IIDXHOOK_CONFIG_GFX_BGVIDEO_UV_FIX_KEY "gfx.bgvideo_uv_fix" #define IIDXHOOK_CONFIG_GFX_FRAMED_KEY "gfx.framed" diff --git a/src/main/iidxhook-util/config-io.c b/src/main/iidxhook-util/config-io.c index 3055ac6e..13c59f3c 100644 --- a/src/main/iidxhook-util/config-io.c +++ b/src/main/iidxhook-util/config-io.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "iidxhook-util/config-io.h" +#include "core/log.h" -#include "util/log.h" +#include "iidxhook-util/config-io.h" #define IIDXHOOK_UTIL_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY \ "io.disable_card_reader_emu" diff --git a/src/main/iidxhook-util/config-misc.c b/src/main/iidxhook-util/config-misc.c index 7a18499e..fca5ea5a 100644 --- a/src/main/iidxhook-util/config-misc.c +++ b/src/main/iidxhook-util/config-misc.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "iidxhook-util/config-misc.h" +#include "core/log.h" -#include "util/log.h" +#include "iidxhook-util/config-misc.h" #define IIDXHOOK_CONFIG_MISC_DISABLE_CLOCK_SET_KEY "misc.disable_clock_set" #define IIDXHOOK_CONFIG_MISC_RTEFFECT_STUB_KEY "misc.rteffect_stub" diff --git a/src/main/iidxhook-util/config-sec.c b/src/main/iidxhook-util/config-sec.c index 54cb0eea..a2e9a573 100644 --- a/src/main/iidxhook-util/config-sec.c +++ b/src/main/iidxhook-util/config-sec.c @@ -3,12 +3,13 @@ #include "cconfig/cconfig-util.h" +#include "core/log.h" + #include "iidxhook-util/config-sec.h" #include "security/mcode.h" #include "security/rp.h" -#include "util/log.h" #include "util/mem.h" #define IIDXHOOK_CONFIG_SEC_BOOT_VERSION_KEY "sec.boot_version" diff --git a/src/main/iidxhook-util/d3d9.c b/src/main/iidxhook-util/d3d9.c index 9c877199..eeb5081f 100644 --- a/src/main/iidxhook-util/d3d9.c +++ b/src/main/iidxhook-util/d3d9.c @@ -9,6 +9,8 @@ #include #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/table.h" @@ -16,7 +18,6 @@ #include "iidxhook-util/vertex-shader.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" #include "util/time.h" diff --git a/src/main/iidxhook-util/eamuse.c b/src/main/iidxhook-util/eamuse.c index 15d77da9..6a127bd3 100644 --- a/src/main/iidxhook-util/eamuse.c +++ b/src/main/iidxhook-util/eamuse.c @@ -8,12 +8,13 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "iidxhook-util/eamuse.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" /* ------------------------------------------------------------------------- */ diff --git a/src/main/iidxhook-util/effector.c b/src/main/iidxhook-util/effector.c index 4f30e279..f313c602 100644 --- a/src/main/iidxhook-util/effector.c +++ b/src/main/iidxhook-util/effector.c @@ -2,12 +2,13 @@ #include +#include "core/log.h" + #include "hook/table.h" #include "iidxhook-util/effector.h" #include "util/defs.h" -#include "util/log.h" static BOOL my_EnableEqualizer(int a1); static BOOL my_GetEqualizerStatus(LPVOID buffer); diff --git a/src/main/iidxhook-util/log-server.c b/src/main/iidxhook-util/log-server.c index 1a7f687c..5a2fe3d2 100644 --- a/src/main/iidxhook-util/log-server.c +++ b/src/main/iidxhook-util/log-server.c @@ -5,6 +5,9 @@ #include #include +#include "core/log.h" +#include "core/thread.h" + #include "hook/table.h" #include "iidxhook-util/log-server.h" @@ -12,9 +15,7 @@ #include "imports/avs.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" -#include "util/thread.h" static int log_thread_proc(void *ctx); static void @@ -39,7 +40,7 @@ void log_server_init(void) log_rv_consumer = CreateSemaphore(NULL, 0, 1, NULL); ready = CreateEvent(NULL, TRUE, FALSE, NULL); - log_to_external( + core_log_impl_set( log_post_misc, log_post_info, log_post_warning, log_post_fatal); 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 b4f2ce3f..5402f695 100644 --- a/src/main/iidxhook-util/settings.c +++ b/src/main/iidxhook-util/settings.c @@ -7,12 +7,13 @@ #include #include +#include "core/log.h" + #include "hook/iohook.h" #include "hook/table.h" #include "util/defs.h" #include "util/fs.h" -#include "util/log.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/iidxhook1/Module.mk b/src/main/iidxhook1/Module.mk index fcfad98b..61bb5ff4 100644 --- a/src/main/iidxhook1/Module.mk +++ b/src/main/iidxhook1/Module.mk @@ -5,6 +5,7 @@ ldflags_iidxhook1 := \ -liphlpapi \ libs_iidxhook1 := \ + core \ iidxhook-util \ ezusb-emu \ ezusb-iidx-16seg-emu \ diff --git a/src/main/iidxhook1/config-iidxhook1.c b/src/main/iidxhook1/config-iidxhook1.c index 5a02c95c..b88d4718 100644 --- a/src/main/iidxhook1/config-iidxhook1.c +++ b/src/main/iidxhook1/config-iidxhook1.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "iidxhook1/config-iidxhook1.h" +#include "core/log.h" -#include "util/log.h" +#include "iidxhook1/config-iidxhook1.h" #define IIDXHOOK_CONFIG_MISC_HAPPY_SKY_MS_BG_FIX_KEY "misc.happy_sky_ms_bg_fix" diff --git a/src/main/iidxhook1/dllmain.c b/src/main/iidxhook1/dllmain.c index a3a4a357..60c61a75 100644 --- a/src/main/iidxhook1/dllmain.c +++ b/src/main/iidxhook1/dllmain.c @@ -9,6 +9,14 @@ #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/desc.h" #include "ezusb-emu/device.h" #include "ezusb-emu/node-security-plug.h" @@ -42,8 +50,6 @@ #include "iidxhook1/log-ezusb.h" #include "util/defs.h" -#include "util/log.h" -#include "util/thread.h" #define IIDXHOOK1_INFO_HEADER \ "iidxhook for 9th Style, 10th Style, RED and HAPPY SKY" \ @@ -68,6 +74,14 @@ 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_setup_d3d9_hooks( const struct iidxhook_config_gfx *config_gfx, const struct iidxhook_config_iidxhook1 *config_iidxhook1) @@ -215,20 +229,24 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); - if (!iidx_io_init(thread_create, thread_join, thread_destroy)) { + if (!iidx_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing IIDX IO backend failed"); } /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init(thread_create, thread_join, thread_destroy)) { + if (!eam_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } @@ -261,7 +279,9 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - log_to_writer(log_writer_debug, NULL); + core_thread_crt_ext_impl_set(); + + _iidxhook1_log_init(); /* Bootstrap hook for further init tasks (see above) */ diff --git a/src/main/iidxhook1/ezusb-mon.c b/src/main/iidxhook1/ezusb-mon.c index b76418a6..11f10f9e 100644 --- a/src/main/iidxhook1/ezusb-mon.c +++ b/src/main/iidxhook1/ezusb-mon.c @@ -6,12 +6,13 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "iidxhook1/ezusb-mon.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" /* ------------------------------------------------------------------------- */ diff --git a/src/main/iidxhook1/log-ezusb.c b/src/main/iidxhook1/log-ezusb.c index ac71907b..28a9c6a1 100644 --- a/src/main/iidxhook1/log-ezusb.c +++ b/src/main/iidxhook1/log-ezusb.c @@ -6,12 +6,13 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "iidxhook1/log-ezusb.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" /* ------------------------------------------------------------------------- */ diff --git a/src/main/iidxhook2/Module.mk b/src/main/iidxhook2/Module.mk index c9fd4389..46124426 100644 --- a/src/main/iidxhook2/Module.mk +++ b/src/main/iidxhook2/Module.mk @@ -5,6 +5,7 @@ ldflags_iidxhook2 := \ -liphlpapi \ libs_iidxhook2 := \ + core \ iidxhook-util \ ezusb-emu \ ezusb-iidx-16seg-emu \ diff --git a/src/main/iidxhook2/config-iidxhook2.c b/src/main/iidxhook2/config-iidxhook2.c index 6e3ac6bd..0db10f3b 100644 --- a/src/main/iidxhook2/config-iidxhook2.c +++ b/src/main/iidxhook2/config-iidxhook2.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "iidxhook2/config-iidxhook2.h" +#include "core/log.h" -#include "util/log.h" +#include "iidxhook2/config-iidxhook2.h" #define IIDXHOOK_CONFIG_MISC_DISTORTED_MS_BG_FIX_KEY "misc.distorted_ms_bg_fix" diff --git a/src/main/iidxhook2/dllmain.c b/src/main/iidxhook2/dllmain.c index 25a76ed9..de8a9160 100644 --- a/src/main/iidxhook2/dllmain.c +++ b/src/main/iidxhook2/dllmain.c @@ -9,6 +9,14 @@ #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/desc.h" #include "ezusb-emu/device.h" #include "ezusb-emu/node-security-plug.h" @@ -41,9 +49,6 @@ #include "iidxhook2/config-iidxhook2.h" -#include "util/log.h" -#include "util/thread.h" - #define IIDXHOOK2_INFO_HEADER \ "iidxhook for DistorteD" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) @@ -65,6 +70,14 @@ static const struct hook_symbol init_hook_syms[] = { .link = (void **) &real_OpenProcess}, }; +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_setup_d3d9_hooks( const struct iidxhook_config_gfx *config_gfx, const struct iidxhook_config_iidxhook2 *config_iidxhook2) @@ -207,20 +220,24 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); - if (!iidx_io_init(thread_create, thread_join, thread_destroy)) { + if (!iidx_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing IIDX IO backend failed"); } /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init(thread_create, thread_join, thread_destroy)) { + if (!eam_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } @@ -254,7 +271,9 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - log_to_writer(log_writer_debug, NULL); + core_thread_crt_ext_impl_set(); + + _iidxhook2_log_init(); /* Bootstrap hook for further init tasks (see above) */ diff --git a/src/main/iidxhook3/Module.mk b/src/main/iidxhook3/Module.mk index e328bec3..6ab9a30f 100644 --- a/src/main/iidxhook3/Module.mk +++ b/src/main/iidxhook3/Module.mk @@ -5,6 +5,7 @@ ldflags_iidxhook3 := \ -liphlpapi \ libs_iidxhook3 := \ + core \ iidxhook-util \ ezusb-emu \ ezusb-iidx-16seg-emu \ diff --git a/src/main/iidxhook3/dllmain.c b/src/main/iidxhook3/dllmain.c index b2e0e41d..4927fc32 100644 --- a/src/main/iidxhook3/dllmain.c +++ b/src/main/iidxhook3/dllmain.c @@ -9,6 +9,14 @@ #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" #include "ezusb-iidx-emu/node-serial.h" #include "ezusb-iidx-emu/nodes.h" @@ -40,9 +48,7 @@ #include "security/rp-sign-key.h" -#include "util/log.h" #include "util/str.h" -#include "util/thread.h" #define IIDXHOOK3_INFO_HEADER \ "iidxhook for Gold, DJTroopers, Empress and Sirius" \ @@ -64,6 +70,14 @@ static const struct hook_symbol init_hook_syms[] = { .link = (void **) &real_OpenProcess}, }; +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_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -200,20 +214,24 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); - if (!iidx_io_init(thread_create, thread_join, thread_destroy)) { + if (!iidx_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing IIDX IO backend failed"); } /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init(thread_create, thread_join, thread_destroy)) { + if (!eam_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } @@ -246,7 +264,9 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - log_to_writer(log_writer_debug, NULL); + core_thread_crt_ext_impl_set(); + + _iidxhook3_log_init(); /* Bootstrap hook for further init tasks (see above) */ diff --git a/src/main/iidxhook4-cn/Module.mk b/src/main/iidxhook4-cn/Module.mk index 0f7bceea..8cc34cb1 100644 --- a/src/main/iidxhook4-cn/Module.mk +++ b/src/main/iidxhook4-cn/Module.mk @@ -8,6 +8,8 @@ deplibs_iidxhook4-cn := \ avs \ libs_iidxhook4-cn := \ + avs-util \ + core \ iidxhook-util \ ezusb-emu \ ezusb-iidx-16seg-emu \ diff --git a/src/main/iidxhook4-cn/avs-boot.c b/src/main/iidxhook4-cn/avs-boot.c index 378d80cf..4c498c95 100644 --- a/src/main/iidxhook4-cn/avs-boot.c +++ b/src/main/iidxhook4-cn/avs-boot.c @@ -3,14 +3,15 @@ #include #include +#include "core/log-bt.h" +#include "core/log.h" + #include "hook/table.h" #include "imports/avs.h" #include "iidxhook4-cn/avs-boot.h" -#include "util/log.h" - static void (*real_avs_boot)( struct property_node *config, void *std_heap, @@ -35,6 +36,11 @@ static const struct hook_symbol iidxhook4_cn_log_hook_syms[] = { .link = (void **) &real_avs_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) { @@ -87,7 +93,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/iidxhook4-cn/dllmain.c b/src/main/iidxhook4-cn/dllmain.c index ea2f42ab..9fa61ba3 100644 --- a/src/main/iidxhook4-cn/dllmain.c +++ b/src/main/iidxhook4-cn/dllmain.c @@ -5,10 +5,19 @@ #include #include +#include "avs-util/core-interop.h" + #include "bemanitools/iidxio.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 "ezusb-emu/node-security-plug.h" #include "ezusb2-emu/desc.h" @@ -37,8 +46,6 @@ #include "imports/avs.h" -#include "util/log.h" - #define IIDXHOOK4_CN_INFO_HEADER \ "iidxhook for Resort Anthem CN" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) @@ -61,6 +68,14 @@ static const struct hook_symbol init_hook_syms[] = { static struct iidxhook_config_io config_io; +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_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -183,11 +198,12 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); if (!iidx_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -221,7 +237,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) return TRUE; } - log_to_writer(log_writer_debug, NULL); + // Use AVS APIs + avs_util_core_interop_thread_avs_impl_set(); + + // TODO init debug logging but with avs available? why not use avs logging? + _iidxhook4_cn_log_init(); hook_table_apply( NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms)); diff --git a/src/main/iidxhook4-cn/path.c b/src/main/iidxhook4-cn/path.c index 4ab6c5a3..5d4ef1dd 100644 --- a/src/main/iidxhook4-cn/path.c +++ b/src/main/iidxhook4-cn/path.c @@ -4,11 +4,12 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "iidxhook4-cn/path.h" -#include "util/log.h" #include "util/str.h" #define PATH_A "D:/JDZ-001/contents/" diff --git a/src/main/iidxhook4/Module.mk b/src/main/iidxhook4/Module.mk index 40f40b02..6546ac19 100644 --- a/src/main/iidxhook4/Module.mk +++ b/src/main/iidxhook4/Module.mk @@ -7,6 +7,8 @@ deplibs_iidxhook4 := \ avs \ libs_iidxhook4 := \ + avs-util \ + core \ iidxhook-util \ ezusb-emu \ ezusb-iidx-16seg-emu \ diff --git a/src/main/iidxhook4/dllmain.c b/src/main/iidxhook4/dllmain.c index d7993dd7..c52336f3 100644 --- a/src/main/iidxhook4/dllmain.c +++ b/src/main/iidxhook4/dllmain.c @@ -5,11 +5,16 @@ #include #include +#include "avs-util/core-interop.h" + #include "bemanitools/eamio.h" #include "bemanitools/iidxio.h" #include "cconfig/cconfig-hook.h" +#include "core/log.h" +#include "core/thread.h" + #include "ezusb-iidx-emu/nodes.h" #include "ezusb2-emu/desc.h" @@ -36,9 +41,7 @@ #include "imports/avs.h" -#include "util/log.h" #include "util/str.h" -#include "util/thread.h" #define IIDXHOOK4_INFO_HEADER \ "iidxhook for Resort Anthem" \ @@ -142,11 +145,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); if (!iidx_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -156,11 +160,12 @@ 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"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); if (!eam_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } } else { @@ -227,8 +232,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // 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); diff --git a/src/main/iidxhook5-cn/Module.mk b/src/main/iidxhook5-cn/Module.mk index feea3d48..5addce9b 100644 --- a/src/main/iidxhook5-cn/Module.mk +++ b/src/main/iidxhook5-cn/Module.mk @@ -8,6 +8,8 @@ deplibs_iidxhook5-cn := \ avs \ libs_iidxhook5-cn := \ + avs-util \ + core \ iidxhook-util \ ezusb-emu \ ezusb-iidx-16seg-emu \ diff --git a/src/main/iidxhook5-cn/avs-boot.c b/src/main/iidxhook5-cn/avs-boot.c index 772832ab..eaa1f459 100644 --- a/src/main/iidxhook5-cn/avs-boot.c +++ b/src/main/iidxhook5-cn/avs-boot.c @@ -3,14 +3,15 @@ #include #include +#include "core/log-bt.h" +#include "core/log.h" + #include "hook/table.h" #include "imports/avs.h" #include "iidxhook5-cn/avs-boot.h" -#include "util/log.h" - static void (*real_avs_boot)( struct property_node *config, void *std_heap, @@ -35,6 +36,11 @@ static const struct hook_symbol iidxhook5_cn_log_hook_syms[] = { .link = (void **) &real_avs_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) { @@ -87,7 +93,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/iidxhook5-cn/dllmain.c b/src/main/iidxhook5-cn/dllmain.c index 711c906f..1d327dcf 100644 --- a/src/main/iidxhook5-cn/dllmain.c +++ b/src/main/iidxhook5-cn/dllmain.c @@ -5,10 +5,18 @@ #include #include +#include "avs-util/core-interop.h" + #include "bemanitools/iidxio.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.h" + #include "ezusb-emu/node-security-plug.h" #include "ezusb2-emu/desc.h" @@ -37,8 +45,6 @@ #include "imports/avs.h" -#include "util/log.h" - #define IIDXHOOK5_CN_INFO_HEADER \ "iidxhook for tricoro CN" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) @@ -61,6 +67,14 @@ static const struct hook_symbol init_hook_user32_syms[] = { static struct iidxhook_config_io config_io; +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_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -163,11 +177,12 @@ static ATOM WINAPI my_RegisterClassA(const WNDCLASSA *lpWndClass) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); if (!iidx_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -200,7 +215,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) return TRUE; } - log_to_writer(log_writer_debug, NULL); + // Use AVS APIs + avs_util_core_interop_thread_avs_impl_set(); + + // TODO init debug logging but with avs available? why not use avs logging? + _iidxhook5_cn_log_init(); hook_table_apply( NULL, diff --git a/src/main/iidxhook5-cn/path.c b/src/main/iidxhook5-cn/path.c index d45bf227..bb4f81d1 100644 --- a/src/main/iidxhook5-cn/path.c +++ b/src/main/iidxhook5-cn/path.c @@ -4,11 +4,12 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "iidxhook5-cn/path.h" -#include "util/log.h" #include "util/str.h" #define PATH_A "D:/JDZ-001/contents/" diff --git a/src/main/iidxhook5/Module.mk b/src/main/iidxhook5/Module.mk index 78ea3077..28cb7fe4 100644 --- a/src/main/iidxhook5/Module.mk +++ b/src/main/iidxhook5/Module.mk @@ -7,6 +7,8 @@ deplibs_iidxhook5 := \ avs \ libs_iidxhook5 := \ + avs-util \ + core \ iidxhook-util \ ezusb-emu \ ezusb-iidx-16seg-emu \ diff --git a/src/main/iidxhook5/dllmain.c b/src/main/iidxhook5/dllmain.c index 268bf395..0912c381 100644 --- a/src/main/iidxhook5/dllmain.c +++ b/src/main/iidxhook5/dllmain.c @@ -5,11 +5,16 @@ #include #include +#include "avs-util/core-interop.h" + #include "bemanitools/eamio.h" #include "bemanitools/iidxio.h" #include "cconfig/cconfig-hook.h" +#include "core/log.h" +#include "core/thread.h" + #include "ezusb-iidx-emu/nodes.h" #include "ezusb2-emu/desc.h" @@ -36,9 +41,7 @@ #include "imports/avs.h" -#include "util/log.h" #include "util/str.h" -#include "util/thread.h" #include "ifs-snd-redir.h" @@ -144,11 +147,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); if (!iidx_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -158,11 +162,12 @@ 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"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); if (!eam_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } } else { @@ -228,8 +233,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // 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); diff --git a/src/main/iidxhook5/ifs-snd-redir.c b/src/main/iidxhook5/ifs-snd-redir.c index e73dd5ca..639d16fd 100644 --- a/src/main/iidxhook5/ifs-snd-redir.c +++ b/src/main/iidxhook5/ifs-snd-redir.c @@ -3,13 +3,14 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "imports/avs.h" #include "iidxhook5/ifs-snd-redir.h" -#include "util/log.h" #include "util/str.h" static void *(*real_avs_fs_open)(const char *path, int mode, int flags); diff --git a/src/main/iidxhook6/Module.mk b/src/main/iidxhook6/Module.mk index 7fda87b1..fe7e955e 100644 --- a/src/main/iidxhook6/Module.mk +++ b/src/main/iidxhook6/Module.mk @@ -7,6 +7,8 @@ deplibs_iidxhook6 := \ avs \ libs_iidxhook6 := \ + avs-util \ + core \ iidxhook-d3d9 \ iidxhook-util \ ezusb-emu \ diff --git a/src/main/iidxhook6/dllmain.c b/src/main/iidxhook6/dllmain.c index b4ca65aa..4b614a48 100644 --- a/src/main/iidxhook6/dllmain.c +++ b/src/main/iidxhook6/dllmain.c @@ -5,11 +5,16 @@ #include #include +#include "avs-util/core-interop.h" + #include "bemanitools/eamio.h" #include "bemanitools/iidxio.h" #include "cconfig/cconfig-hook.h" +#include "core/log.h" +#include "core/thread.h" + #include "ezusb-iidx-emu/nodes.h" #include "ezusb2-emu/desc.h" @@ -35,9 +40,7 @@ #include "imports/avs.h" -#include "util/log.h" #include "util/str.h" -#include "util/thread.h" #define IIDXHOOK6_INFO_HEADER \ "iidxhook for Tricoro" \ @@ -121,11 +124,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); if (!iidx_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -135,11 +139,12 @@ 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"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); if (!eam_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } } else { @@ -203,8 +208,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // 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); diff --git a/src/main/iidxhook7/Module.mk b/src/main/iidxhook7/Module.mk index a40366af..b1b6d937 100644 --- a/src/main/iidxhook7/Module.mk +++ b/src/main/iidxhook7/Module.mk @@ -8,6 +8,8 @@ deplibs_iidxhook7 := \ avs \ libs_iidxhook7 := \ + avs-util \ + core \ iidxhook-d3d9 \ iidxhook-util \ cconfig \ diff --git a/src/main/iidxhook7/dllmain.c b/src/main/iidxhook7/dllmain.c index af948f61..0823e854 100644 --- a/src/main/iidxhook7/dllmain.c +++ b/src/main/iidxhook7/dllmain.c @@ -5,11 +5,16 @@ #include #include +#include "avs-util/core-interop.h" + #include "bemanitools/eamio.h" #include "bemanitools/iidxio.h" #include "cconfig/cconfig-hook.h" +#include "core/log.h" +#include "core/thread.h" + #include "ezusb-iidx-emu/nodes.h" #include "ezusb2-emu/desc.h" @@ -35,9 +40,7 @@ #include "imports/avs.h" -#include "util/log.h" #include "util/str.h" -#include "util/thread.h" #define IIDXHOOK7_INFO_HEADER \ "iidxhook for SPADA, PENDUAL, copula and SINOBUZ" \ @@ -121,11 +124,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); if (!iidx_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing IIDX IO backend failed"); } } else { @@ -135,11 +139,12 @@ 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"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); if (!eam_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } } else { @@ -203,8 +208,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // 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); diff --git a/src/main/iidxhook8/Module.mk b/src/main/iidxhook8/Module.mk index e71c8c25..faebbbb9 100644 --- a/src/main/iidxhook8/Module.mk +++ b/src/main/iidxhook8/Module.mk @@ -12,6 +12,8 @@ deplibs_iidxhook8 := \ avs \ libs_iidxhook8 := \ + avs-util \ + core \ iidxhook-d3d9 \ iidxhook-util \ acioemu \ diff --git a/src/main/iidxhook8/config-io.c b/src/main/iidxhook8/config-io.c index 8cbb9b24..9f61e130 100644 --- a/src/main/iidxhook8/config-io.c +++ b/src/main/iidxhook8/config-io.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "iidxhook8/config-io.h" +#include "core/log.h" -#include "util/log.h" +#include "iidxhook8/config-io.h" #define IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY \ "io.disable_card_reader_emu" diff --git a/src/main/iidxhook8/dllmain.c b/src/main/iidxhook8/dllmain.c index 13509be4..bf1f55d9 100644 --- a/src/main/iidxhook8/dllmain.c +++ b/src/main/iidxhook8/dllmain.c @@ -5,11 +5,16 @@ #include #include +#include "avs-util/core-interop.h" + #include "bemanitools/eamio.h" #include "bemanitools/iidxio.h" #include "cconfig/cconfig-hook.h" +#include "core/log.h" +#include "core/thread.h" + #include "hook/d3d9.h" #include "hooklib/acp.h" @@ -34,9 +39,7 @@ #include "imports/avs.h" -#include "util/log.h" #include "util/str.h" -#include "util/thread.h" #define IIDXHOOK8_INFO_HEADER \ "iidxhook for Cannon Ballers/Rootage" \ @@ -131,11 +134,12 @@ 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"); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); if (!iidx_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing IIDX IO backend failed"); } } @@ -143,11 +147,12 @@ 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"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); if (!eam_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } } @@ -217,8 +222,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // 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); diff --git a/src/main/iidxhook9/Module.mk b/src/main/iidxhook9/Module.mk index 30384f11..2328fdc3 100644 --- a/src/main/iidxhook9/Module.mk +++ b/src/main/iidxhook9/Module.mk @@ -12,6 +12,8 @@ deplibs_iidxhook9 := \ avs \ libs_iidxhook9 := \ + avs-util \ + core \ iidxhook-util \ acioemu \ asio \ diff --git a/src/main/iidxhook9/config-io.c b/src/main/iidxhook9/config-io.c index ba7ff45a..34deebfb 100644 --- a/src/main/iidxhook9/config-io.c +++ b/src/main/iidxhook9/config-io.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "iidxhook9/config-io.h" +#include "core/log.h" -#include "util/log.h" +#include "iidxhook9/config-io.h" #define IIDXHOOK9_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY \ "io.disable_card_reader_emu" diff --git a/src/main/iidxhook9/dllmain.c b/src/main/iidxhook9/dllmain.c index b7ae85ac..ad9572d5 100644 --- a/src/main/iidxhook9/dllmain.c +++ b/src/main/iidxhook9/dllmain.c @@ -5,11 +5,18 @@ #include #include +#include "avs-util/core-interop.h" + #include "bemanitools/eamio.h" #include "bemanitools/iidxio.h" #include "cconfig/cconfig-hook.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" #include "hooklib/app.h" @@ -38,9 +45,7 @@ #include "imports/avs.h" #include "util/cmdline.h" -#include "util/log.h" #include "util/str.h" -#include "util/thread.h" #define IIDXHOOK9_INFO_HEADER \ "iidxhook for Heroic Verse" \ @@ -97,6 +102,9 @@ 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(); + // log_server_init is required due to IO occuring in a non avs_thread log_server_init(); @@ -124,11 +132,12 @@ 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"); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); if (!iidx_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing IIDX IO backend failed"); } } @@ -136,11 +145,12 @@ 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"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); if (!eam_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } } @@ -271,8 +281,8 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) // 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 - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + avs_util_core_interop_log_avs_impl_set(); + log_warning("iidxhook9 is designed to be used as a prehook"); log_warning("please ensure that it is being loaded with -B"); log_fatal("cya l8r in the prehook :3"); @@ -280,7 +290,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 - log_to_writer(log_writer_file, stdout); + core_log_bt_ext_impl_set(); } pre_hook(); diff --git a/src/main/iidxio-bio2/Module.mk b/src/main/iidxio-bio2/Module.mk index 09632c21..e91d76a1 100644 --- a/src/main/iidxio-bio2/Module.mk +++ b/src/main/iidxio-bio2/Module.mk @@ -4,6 +4,7 @@ ldflags_iidxio-bio2 := \ -lsetupapi \ libs_iidxio-bio2 := \ + core \ aciodrv \ bio2drv \ cconfig \ diff --git a/src/main/iidxio-ezusb/Module.mk b/src/main/iidxio-ezusb/Module.mk index ce9982c2..cc64914e 100644 --- a/src/main/iidxio-ezusb/Module.mk +++ b/src/main/iidxio-ezusb/Module.mk @@ -5,6 +5,7 @@ ldflags_iidxio-ezusb := \ -lsetupapi \ libs_iidxio-ezusb := \ + core \ ezusb \ ezusb2 \ ezusb-iidx \ diff --git a/src/main/iidxio-ezusb2/Module.mk b/src/main/iidxio-ezusb2/Module.mk index f1f19631..3371a785 100644 --- a/src/main/iidxio-ezusb2/Module.mk +++ b/src/main/iidxio-ezusb2/Module.mk @@ -5,6 +5,7 @@ ldflags_iidxio-ezusb2 := \ -lsetupapi \ libs_iidxio-ezusb2 := \ + core \ ezusb2 \ ezusb \ ezusb2-iidx \ diff --git a/src/main/iidxiotest/Module.mk b/src/main/iidxiotest/Module.mk index ce0536cf..94eca380 100644 --- a/src/main/iidxiotest/Module.mk +++ b/src/main/iidxiotest/Module.mk @@ -1,6 +1,7 @@ exes += iidxiotest \ libs_iidxiotest := \ + core \ iidxio \ util \ diff --git a/src/main/iidxiotest/main.c b/src/main/iidxiotest/main.c index ddd57cf4..a9b7daaa 100644 --- a/src/main/iidxiotest/main.c +++ b/src/main/iidxiotest/main.c @@ -7,8 +7,12 @@ #include "bemanitools/iidxio.h" -#include "util/log.h" -#include "util/thread.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" static uint8_t _fix_top_lamps_order(uint8_t top_lamps) { @@ -55,12 +59,17 @@ static void _all_lights_off_shutdown() */ int main(int argc, char **argv) { - log_to_writer(log_writer_stdout, NULL); + core_thread_crt_ext_impl_set(); + core_log_bt_ext_impl_set(); - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_bt_ext_init_with_stdout(); - if (!iidx_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) { + 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())) { printf("Initializing iidxio failed\n"); return -1; } diff --git a/src/main/jbhook-util-p3io/gfx.c b/src/main/jbhook-util-p3io/gfx.c index 63607fd8..0574b1f0 100644 --- a/src/main/jbhook-util-p3io/gfx.c +++ b/src/main/jbhook-util-p3io/gfx.c @@ -9,6 +9,8 @@ #include #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/table.h" @@ -17,7 +19,6 @@ #include "jbhook-util-p3io/gfx.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" #include "util/time.h" diff --git a/src/main/jbhook-util-p3io/mixer.c b/src/main/jbhook-util-p3io/mixer.c index 30dcace9..ba52a638 100644 --- a/src/main/jbhook-util-p3io/mixer.c +++ b/src/main/jbhook-util-p3io/mixer.c @@ -6,10 +6,11 @@ #include // clang-format on +#include "core/log.h" + #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" MMRESULT STDCALL hook_mixerGetLineControlsA( HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls); diff --git a/src/main/jbhook-util-p3io/p3io.c b/src/main/jbhook-util-p3io/p3io.c index 25b3364f..dd04607a 100644 --- a/src/main/jbhook-util-p3io/p3io.c +++ b/src/main/jbhook-util-p3io/p3io.c @@ -5,6 +5,8 @@ #include "bemanitools/jbio.h" +#include "core/log.h" + #include "jbhook-util-p3io/p3io.h" #include "p3ioemu/emu.h" @@ -13,8 +15,6 @@ #include "security/rp-sign-key.h" #include "security/rp3.h" -#include "util/log.h" - static HRESULT jbhook_p3io_read_jamma(void *ctx, uint32_t *state); static HRESULT jbhook_p3io_get_roundplug( void *ctx, uint8_t plug_id, uint8_t *rom, uint8_t *eeprom); diff --git a/src/main/jbhook-util/acio.c b/src/main/jbhook-util/acio.c index a1f5492e..8a1ed023 100644 --- a/src/main/jbhook-util/acio.c +++ b/src/main/jbhook-util/acio.c @@ -16,6 +16,8 @@ #include "acioemu/h44b.h" #include "acioemu/icca.h" +#include "core/log.h" + #include "hook/iohook.h" #include "jbhook-util/acio.h" @@ -25,7 +27,6 @@ #include "util/defs.h" #include "util/hex.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" static struct ac_io_emu ac_io_emu; diff --git a/src/main/jbhook-util/eamuse.c b/src/main/jbhook-util/eamuse.c index 0a796259..c9d1d906 100644 --- a/src/main/jbhook-util/eamuse.c +++ b/src/main/jbhook-util/eamuse.c @@ -9,10 +9,11 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "util/defs.h" -#include "util/log.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 272bbc64..a6b6d17a 100644 --- a/src/main/jbhook-util/locale.c +++ b/src/main/jbhook-util/locale.c @@ -2,10 +2,11 @@ #include +#include "core/log.h" + #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" // ANSI/OEM Japanese; Japanese (Shift-JIS) #define CODEPAGE_SHIFT_JIS 932 diff --git a/src/main/jbhook-util/p4io.c b/src/main/jbhook-util/p4io.c index ab77d5dc..824ab803 100644 --- a/src/main/jbhook-util/p4io.c +++ b/src/main/jbhook-util/p4io.c @@ -4,14 +4,14 @@ #include "bemanitools/jbio.h" +#include "core/log.h" + #include "imports/avs.h" #include "jbhook-util/p4io.h" #include "p4io/cmd.h" -#include "util/log.h" - static void jbhook_io_jamma2_read(void *resp, uint32_t nbytes); static uint32_t jbhook_command_handle( uint8_t cmd, diff --git a/src/main/jbhook1/Module.mk b/src/main/jbhook1/Module.mk index b5e47776..c434f217 100644 --- a/src/main/jbhook1/Module.mk +++ b/src/main/jbhook1/Module.mk @@ -11,6 +11,7 @@ ldflags_jbhook1 := \ -lopengl32 \ libs_jbhook1 := \ + core \ acioemu \ cconfig \ eamio \ diff --git a/src/main/jbhook1/avs-boot.c b/src/main/jbhook1/avs-boot.c index dccba692..62d67733 100644 --- a/src/main/jbhook1/avs-boot.c +++ b/src/main/jbhook1/avs-boot.c @@ -5,14 +5,15 @@ #include #include +#include "core/log-bt.h" +#include "core/log.h" + #include "hook/table.h" #include "imports/avs.h" #include "jbhook1/avs-boot.h" -#include "util/log.h" - static void (*real_avs_boot)( struct property_node *config, void *std_heap, @@ -52,6 +53,11 @@ static const struct hook_symbol jbhook1_log_gftools_hook_syms2[] = { .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_create_property_str( struct property *config, const char *name, const char *val) { @@ -139,7 +145,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/jbhook1/config-eamuse.c b/src/main/jbhook1/config-eamuse.c index dba512eb..77170e2c 100644 --- a/src/main/jbhook1/config-eamuse.c +++ b/src/main/jbhook1/config-eamuse.c @@ -2,9 +2,10 @@ #include "cconfig/cconfig-util.h" +#include "core/log.h" + #include "jbhook1/config-eamuse.h" -#include "util/log.h" #include "util/net.h" #define JBHOOK1_CONFIG_EAMUSE_SERVER_KEY "eamuse.server" diff --git a/src/main/jbhook1/config-gfx.c b/src/main/jbhook1/config-gfx.c index 5215659c..10102fa7 100644 --- a/src/main/jbhook1/config-gfx.c +++ b/src/main/jbhook1/config-gfx.c @@ -2,9 +2,9 @@ #include "cconfig/cconfig-util.h" -#include "jbhook1/config-gfx.h" +#include "core/log.h" -#include "util/log.h" +#include "jbhook1/config-gfx.h" #define JBHOOK1_CONFIG_GFX_WINDOWED_KEY "gfx.windowed" #define JBHOOK1_CONFIG_GFX_VERTICAL_KEY "gfx.vertical" diff --git a/src/main/jbhook1/config-security.c b/src/main/jbhook1/config-security.c index 565081e4..d6c56b05 100644 --- a/src/main/jbhook1/config-security.c +++ b/src/main/jbhook1/config-security.c @@ -2,11 +2,12 @@ #include "cconfig/cconfig-util.h" +#include "core/log.h" + #include "jbhook1/config-security.h" #include "security/mcode.h" -#include "util/log.h" #include "util/net.h" #define JBHOOK1_CONFIG_SECURITY_MCODE_KEY "security.mcode" diff --git a/src/main/jbhook1/dllmain.c b/src/main/jbhook1/dllmain.c index 42f8dc9d..f058d0f3 100644 --- a/src/main/jbhook1/dllmain.c +++ b/src/main/jbhook1/dllmain.c @@ -10,6 +10,14 @@ #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" #include "hooklib/acp.h" @@ -33,8 +41,6 @@ #include "p3ioemu/emu.h" #include "util/defs.h" -#include "util/log.h" -#include "util/thread.h" #define JBHOOK1_INFO_HEADER \ "jbhook1 for jubeat" \ @@ -89,6 +95,14 @@ static const struct hook_symbol kernel32_hook_syms[] = { // so our CreateProcessA hook can check static bool vertical; +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); +} + /** * This seems to be a good entry point to intercept before the game calls * anything important (very close to the start of WinMain). @@ -153,19 +167,23 @@ static HWND CDECL my_mwindow_create( log_info("Starting up jubeat IO backend"); - jb_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(jb_io_set_loggers); - if (!jb_io_init(thread_create, thread_join, thread_destroy)) { + if (!jb_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing jb IO backend failed"); } log_info("Starting up card reader backend"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init(thread_create, thread_join, thread_destroy)) { + if (!eam_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } @@ -201,7 +219,12 @@ static HWND CDECL my_mwindow_create( BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - log_to_writer(log_writer_debug, NULL); + // TODO why not use AVS threads? + core_thread_crt_ext_impl_set(); + + // TODO init debug logging but with avs available? why not use avs + // logging? + _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 97721736..f0dbf854 100644 --- a/src/main/jbhook1/log-gftools.c +++ b/src/main/jbhook1/log-gftools.c @@ -5,9 +5,9 @@ #include #include -#include "hook/table.h" +#include "core/log.h" -#include "util/log.h" +#include "hook/table.h" static int CDECL my_GFReportPuts( int level, diff --git a/src/main/jbhook2/Module.mk b/src/main/jbhook2/Module.mk index 2573867f..7ecebdb9 100644 --- a/src/main/jbhook2/Module.mk +++ b/src/main/jbhook2/Module.mk @@ -10,6 +10,8 @@ ldflags_jbhook2 := \ -lopengl32 \ libs_jbhook2 := \ + avs-util \ + core \ acioemu \ eamio \ jbio \ diff --git a/src/main/jbhook2/dllmain.c b/src/main/jbhook2/dllmain.c index a8523ad9..4c06e4dc 100644 --- a/src/main/jbhook2/dllmain.c +++ b/src/main/jbhook2/dllmain.c @@ -5,9 +5,14 @@ #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 "hook/iohook.h" #include "hook/table.h" @@ -36,8 +41,6 @@ #include "security/mcode.h" #include "util/defs.h" -#include "util/log.h" -#include "util/thread.h" static struct options options; @@ -80,11 +83,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info("Starting up jubeat IO backend"); - jb_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(jb_io_set_loggers); - jb_io_ok = - jb_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); + jb_io_ok = jb_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); if (!jb_io_ok) { goto fail; @@ -99,11 +103,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info("Starting up card reader backend"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); - eam_io_ok = - eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); + eam_io_ok = eam_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); if (!eam_io_ok) { goto fail; @@ -224,8 +229,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) return TRUE; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // Use AVS APIs + avs_util_core_interop_thread_avs_impl_set(); + avs_util_core_interop_log_avs_impl_set(); options_init_from_cmdline(&options); diff --git a/src/main/jbhook2/options.c b/src/main/jbhook2/options.c index 9e1987e4..63ee6d45 100644 --- a/src/main/jbhook2/options.c +++ b/src/main/jbhook2/options.c @@ -9,7 +9,7 @@ #include "util/cmdline.h" #include "util/defs.h" #include "util/hex.h" -#include "util/log.h" + #include "util/str.h" void options_init_from_cmdline(struct options *options) diff --git a/src/main/jbhook3/Module.mk b/src/main/jbhook3/Module.mk index a82c4cc9..ca36a439 100644 --- a/src/main/jbhook3/Module.mk +++ b/src/main/jbhook3/Module.mk @@ -8,6 +8,8 @@ ldflags_jbhook3 := \ -liphlpapi \ libs_jbhook3 := \ + avs-util \ + core \ acioemu \ eamio \ jbio \ diff --git a/src/main/jbhook3/dllmain.c b/src/main/jbhook3/dllmain.c index b4eada83..30a0eb3d 100644 --- a/src/main/jbhook3/dllmain.c +++ b/src/main/jbhook3/dllmain.c @@ -5,9 +5,14 @@ #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 "hook/iohook.h" #include "hook/table.h" @@ -31,8 +36,6 @@ #include "security/id.h" #include "util/defs.h" -#include "util/log.h" -#include "util/thread.h" static struct options options; @@ -62,11 +65,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!options.disable_p4ioemu) { log_info("Starting up jubeat IO backend"); - jb_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(jb_io_set_loggers); - jb_io_ok = - jb_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); + jb_io_ok = jb_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); if (!jb_io_ok) { goto fail; @@ -79,11 +83,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!options.disable_cardemu) { log_info("Starting up card reader backend"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); - eam_io_ok = - eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); + eam_io_ok = eam_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); if (!eam_io_ok) { goto fail; @@ -143,8 +148,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) return TRUE; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // Use AVS APIs + avs_util_core_interop_thread_avs_impl_set(); + avs_util_core_interop_log_avs_impl_set(); options_init_from_cmdline(&options); diff --git a/src/main/jbhook3/gfx.c b/src/main/jbhook3/gfx.c index ee3b5ff5..827ac55f 100644 --- a/src/main/jbhook3/gfx.c +++ b/src/main/jbhook3/gfx.c @@ -5,12 +5,12 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "jbhook3/options.h" -#include "util/log.h" - static bool jbhook3_gfx_windowed; static bool jbhook3_gfx_show_cursor; diff --git a/src/main/jbhook3/options.c b/src/main/jbhook3/options.c index 59ffc1eb..8bb544b8 100644 --- a/src/main/jbhook3/options.c +++ b/src/main/jbhook3/options.c @@ -6,10 +6,11 @@ #include #include +#include "core/log.h" + #include "util/cmdline.h" #include "util/defs.h" #include "util/hex.h" -#include "util/log.h" #include "util/str.h" void options_init_from_cmdline(struct options *options) diff --git a/src/main/jbio-p4io/Module.mk b/src/main/jbio-p4io/Module.mk index b31604df..ca9895e3 100644 --- a/src/main/jbio-p4io/Module.mk +++ b/src/main/jbio-p4io/Module.mk @@ -9,6 +9,7 @@ src_jbio-p4io := \ jbio.c \ libs_jbio-p4io := \ + core \ aciodrv \ aciomgr \ cconfig \ diff --git a/src/main/jbio-p4io/config-h44b.c b/src/main/jbio-p4io/config-h44b.c index 91d37cb8..98a5f4f2 100644 --- a/src/main/jbio-p4io/config-h44b.c +++ b/src/main/jbio-p4io/config-h44b.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "jbio-p4io/config-h44b.h" +#include "core/log.h" -#include "util/log.h" +#include "jbio-p4io/config-h44b.h" #define JBIO_CONFIG_H44B_PORT_KEY "h44b.port" #define JBIO_CONFIG_H44B_BAUD_KEY "h44b.baud" diff --git a/src/main/jbio-p4io/h44b.c b/src/main/jbio-p4io/h44b.c index 1d9b77a0..f26aa2a1 100644 --- a/src/main/jbio-p4io/h44b.c +++ b/src/main/jbio-p4io/h44b.c @@ -10,7 +10,7 @@ #include "aciomgr/manager.h" -#include "util/log.h" +#include "core/log.h" static int16_t h44b_node_id; diff --git a/src/main/jbio-p4io/jbio.c b/src/main/jbio-p4io/jbio.c index 202187fe..58f4db9a 100644 --- a/src/main/jbio-p4io/jbio.c +++ b/src/main/jbio-p4io/jbio.c @@ -7,17 +7,17 @@ #include "aciomgr/manager.h" +#include "bemanitools/jbio.h" + #include "cconfig/cconfig-main.h" -#include "bemanitools/jbio.h" +#include "core/log.h" #include "jbio-p4io/config-h44b.h" #include "jbio-p4io/h44b.h" #include "p4iodrv/device.h" -#include "util/log.h" - static struct p4iodrv_ctx *p4io_ctx; static uint16_t jb_io_panels; static uint8_t jb_io_sys_buttons; @@ -36,7 +36,7 @@ void jb_io_set_loggers( { aciomgr_set_loggers(misc, info, warning, fatal); - log_to_external(misc, info, warning, fatal); + core_log_impl_set(misc, info, warning, fatal); } bool jb_io_init( diff --git a/src/main/jbiotest/Module.mk b/src/main/jbiotest/Module.mk index f2cf618b..eba9c0b1 100644 --- a/src/main/jbiotest/Module.mk +++ b/src/main/jbiotest/Module.mk @@ -1,6 +1,7 @@ exes += jbiotest \ libs_jbiotest := \ + core \ jbio \ util \ diff --git a/src/main/jbiotest/main.c b/src/main/jbiotest/main.c index 416b3251..0a6270b4 100644 --- a/src/main/jbiotest/main.c +++ b/src/main/jbiotest/main.c @@ -7,8 +7,12 @@ #include "bemanitools/jbio.h" -#include "util/log.h" -#include "util/thread.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" typedef struct { uint8_t r, g, b; @@ -23,12 +27,17 @@ enum jbio_light_mode { LIGHTS_OFF, LIGHTS_ON, LIGHTS_INPUT }; */ int main(int argc, char **argv) { - log_to_writer(log_writer_stdout, NULL); + core_thread_crt_ext_impl_set(); + core_log_bt_ext_impl_set(); - jb_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_bt_ext_init_with_stdout(); - if (!jb_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) { + core_log_impl_assign(jb_io_set_loggers); + + if (!jb_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { printf("Initializing jbio failed\n"); return -1; } diff --git a/src/main/mempatch-hook/Module.mk b/src/main/mempatch-hook/Module.mk index 9785efa9..1dedd43e 100644 --- a/src/main/mempatch-hook/Module.mk +++ b/src/main/mempatch-hook/Module.mk @@ -2,6 +2,7 @@ dlls += mempatch-hook libs_mempatch-hook := \ util \ + core \ src_mempatch-hook := \ main.c \ diff --git a/src/main/mempatch-hook/main.c b/src/main/mempatch-hook/main.c index 43c1dcd9..856b962a 100644 --- a/src/main/mempatch-hook/main.c +++ b/src/main/mempatch-hook/main.c @@ -4,10 +4,13 @@ #include #include +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log.h" + #include "util/cmdline.h" #include "util/fs.h" #include "util/hex.h" -#include "util/log.h" static bool patch_memory_check_data( uintptr_t base_address, @@ -283,12 +286,12 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) int argc; char **argv; char *filepath; - FILE *logfile; bool patched; patched = false; - logfile = fopen("mempatch.log", "w+"); - log_to_writer(log_writer_file, logfile); + + core_log_bt_ext_impl_set(); + core_log_bt_ext_init_with_file("mempatch.log", false, false, 0); args_recover(&argc, &argv); @@ -319,8 +322,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) log_info("Patching done"); } - fflush(logfile); - fclose(logfile); + core_log_bt_fini(); } return TRUE; diff --git a/src/main/mm/mm.c b/src/main/mm/mm.c index db543a62..2c89957d 100644 --- a/src/main/mm/mm.c +++ b/src/main/mm/mm.c @@ -9,11 +9,12 @@ #include #include +#include "core/log.h" + #include "mm/mm.h" #include "util/cmdline.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" DEFINE_GUID( diff --git a/src/main/p3io-ddr-tool/Module.mk b/src/main/p3io-ddr-tool/Module.mk index 2c76b428..f6e3a166 100644 --- a/src/main/p3io-ddr-tool/Module.mk +++ b/src/main/p3io-ddr-tool/Module.mk @@ -4,6 +4,7 @@ ldflags_p3io-ddr-tool := \ -lsetupapi \ libs_p3io-ddr-tool := \ + core \ extiodrv \ extio \ p3iodrv \ diff --git a/src/main/p3io-ddr-tool/main.c b/src/main/p3io-ddr-tool/main.c index 939e1e77..4a9bac3a 100644 --- a/src/main/p3io-ddr-tool/main.c +++ b/src/main/p3io-ddr-tool/main.c @@ -7,15 +7,17 @@ #include #include +#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 "p3io/ddr.h" #include "p3iodrv/ddr.h" #include "p3iodrv/device.h" -#include "util/log.h" -#include "util/thread.h" - #include "mode-test.h" enum mode { @@ -70,7 +72,7 @@ static mode_proc _mode_procs[MODE_TOTAL_COUNT] = { _mode_sensores, }; -static enum log_level _log_level = LOG_LEVEL_FATAL; +static enum core_log_bt_log_level _log_level = CORE_LOG_BT_LOG_LEVEL_FATAL; static bool _extio_enabled = true; static const char *_p3io_device_path = ""; static const char *_extio_com_port = "COM1"; @@ -196,11 +198,11 @@ static bool _process_cmd_args(int argc, char **argv) for (int i = 0; i < argc; i++) { if (!strcmp(argv[i], "-v")) { - _log_level = LOG_LEVEL_WARNING; + _log_level = CORE_LOG_BT_LOG_LEVEL_WARNING; } else if (!strcmp(argv[i], "-vv")) { - _log_level = LOG_LEVEL_INFO; + _log_level = CORE_LOG_BT_LOG_LEVEL_INFO; } else if (!strcmp(argv[i], "-vvv")) { - _log_level = LOG_LEVEL_MISC; + _log_level = CORE_LOG_BT_LOG_LEVEL_MISC; } else if (!strcmp(argv[i], "-noextio")) { _extio_enabled = false; } else if (!strcmp(argv[i], "-p3io")) { @@ -256,8 +258,9 @@ static bool _process_cmd_args(int argc, char **argv) static void _init_logging() { - log_to_writer(log_writer_stderr, NULL); - log_set_level(_log_level); + core_log_bt_ext_impl_set(); + core_log_bt_ext_init_with_stderr(); + core_log_bt_level_set(_log_level); } static bool _mode_invalid(HANDLE handle) diff --git a/src/main/p3io-ddr-tool/mode-test.c b/src/main/p3io-ddr-tool/mode-test.c index 791e6d2c..0c3f5a9d 100644 --- a/src/main/p3io-ddr-tool/mode-test.c +++ b/src/main/p3io-ddr-tool/mode-test.c @@ -3,14 +3,14 @@ #include #include +#include "core/log.h" + #include "extiodrv/extio.h" #include "p3io/ddr.h" #include "p3iodrv/ddr.h" #include "p3iodrv/device.h" -#include "util/log.h" - #include "mode-test.h" struct mode_test_output_state { diff --git a/src/main/p3io/cmd.c b/src/main/p3io/cmd.c index 78c8b020..b62958ff 100644 --- a/src/main/p3io/cmd.c +++ b/src/main/p3io/cmd.c @@ -1,8 +1,8 @@ #include -#include "p3io/cmd.h" +#include "core/log.h" -#include "util/log.h" +#include "p3io/cmd.h" uint8_t p3io_get_full_req_size(const union p3io_req_any *req) { diff --git a/src/main/p3io/frame.c b/src/main/p3io/frame.c index bc50dd45..1fc6d2ce 100644 --- a/src/main/p3io/frame.c +++ b/src/main/p3io/frame.c @@ -3,10 +3,11 @@ #include #include +#include "core/log.h" + #include "p3io/frame.h" #include "util/iobuf.h" -#include "util/log.h" #define P3IO_FRAME_SOF 0xAA #define P3IO_FRAME_ESCAPE 0xFF diff --git a/src/main/p3iodrv/ddr.c b/src/main/p3iodrv/ddr.c index 2cc45261..57ebfab6 100644 --- a/src/main/p3iodrv/ddr.c +++ b/src/main/p3iodrv/ddr.c @@ -2,7 +2,7 @@ #include "p3io/cmd.h" -#include "util/log.h" +#include "core/log.h" #include "ddr.h" #include "device.h" diff --git a/src/main/p3iodrv/device.c b/src/main/p3iodrv/device.c index dbbb04af..afa2c512 100644 --- a/src/main/p3iodrv/device.c +++ b/src/main/p3iodrv/device.c @@ -10,13 +10,14 @@ #include // clang-format on +#include "core/log.h" + #include "p3io/cmd.h" #include "p3io/guid.h" #include "p3io/ioctl.h" #include "p3iodrv/device.h" -#include "util/log.h" #include "util/str.h" #define P3IO_DEVICE_FILENMAME "\\p3io" diff --git a/src/main/p3ioemu/devmgr.c b/src/main/p3ioemu/devmgr.c index fc729b35..ac26233d 100644 --- a/src/main/p3ioemu/devmgr.c +++ b/src/main/p3ioemu/devmgr.c @@ -7,6 +7,8 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "p3io/guid.h" @@ -14,7 +16,6 @@ #include "p3ioemu/devmgr.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" /* Link pointers */ diff --git a/src/main/p3ioemu/emu.c b/src/main/p3ioemu/emu.c index 6486d595..7fc21230 100644 --- a/src/main/p3ioemu/emu.c +++ b/src/main/p3ioemu/emu.c @@ -7,6 +7,8 @@ #include #include +#include "core/log.h" + #include "hook/iohook.h" #include "p3io/cmd.h" @@ -18,7 +20,6 @@ #include "p3ioemu/uart.h" #include "util/iobuf.h" -#include "util/log.h" static HANDLE p3io_emu_fd; static uint8_t p3io_emu_resp_bytes[256]; diff --git a/src/main/p3ioemu/uart.c b/src/main/p3ioemu/uart.c index a4a9f735..cbceb5a2 100644 --- a/src/main/p3ioemu/uart.c +++ b/src/main/p3ioemu/uart.c @@ -10,6 +10,8 @@ #include +#include "core/log.h" + #include "hook/iohook.h" #include "p3io/cmd.h" @@ -17,7 +19,6 @@ #include "p3ioemu/uart.h" #include "util/iobuf.h" -#include "util/log.h" static HRESULT p3io_uart_open(const wchar_t *path, uint32_t baud_rate, HANDLE *fd); diff --git a/src/main/p4iodrv/device.c b/src/main/p4iodrv/device.c index 67dd56e3..da65f7bb 100644 --- a/src/main/p4iodrv/device.c +++ b/src/main/p4iodrv/device.c @@ -2,12 +2,13 @@ #include +#include "core/log.h" + #include "p4io/cmd.h" #include "p4iodrv/device.h" #include "p4iodrv/usb.h" -#include "util/log.h" #include "util/mem.h" struct p4iodrv_ctx { diff --git a/src/main/p4iodrv/usb.c b/src/main/p4iodrv/usb.c index 8c99fc42..243adae5 100644 --- a/src/main/p4iodrv/usb.c +++ b/src/main/p4iodrv/usb.c @@ -10,13 +10,14 @@ #include // clang-format on +#include "core/log.h" + #include "p4io/cmd.h" #include "p4io/guid.h" #include "p4io/ioctl.h" #include "p4iodrv/usb.h" -#include "util/log.h" #include "util/str.h" HANDLE p4io_usb_open(void) diff --git a/src/main/p4ioemu/device.c b/src/main/p4ioemu/device.c index e18e8910..4e7498fc 100644 --- a/src/main/p4ioemu/device.c +++ b/src/main/p4ioemu/device.c @@ -6,11 +6,12 @@ #include #include +#include "core/log.h" + #include "hook/iohook.h" #include "p4io/cmd.h" #include "p4io/ioctl.h" #include "util/hex.h" -#include "util/log.h" #include "util/str.h" // #define P4IOEMU_DEBUG_DUMP diff --git a/src/main/pcbidgen/Module.mk b/src/main/pcbidgen/Module.mk index 852a4d00..612510f4 100644 --- a/src/main/pcbidgen/Module.mk +++ b/src/main/pcbidgen/Module.mk @@ -3,6 +3,7 @@ exes += pcbidgen libs_pcbidgen := \ security \ util \ + core \ src_pcbidgen := \ main.c \ diff --git a/src/main/popnhook-util/acio.c b/src/main/popnhook-util/acio.c index 60d66b84..465bdcdb 100644 --- a/src/main/popnhook-util/acio.c +++ b/src/main/popnhook-util/acio.c @@ -15,6 +15,8 @@ #include "acioemu/emu.h" #include "acioemu/icca.h" +#include "core/log.h" + #include "hook/iohook.h" #include "hooklib/rs232.h" @@ -24,7 +26,6 @@ #include "util/defs.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" static struct ac_io_emu popnhook_acio_emu; diff --git a/src/main/popnhook-util/mixer.c b/src/main/popnhook-util/mixer.c index 91d3c759..904a008f 100644 --- a/src/main/popnhook-util/mixer.c +++ b/src/main/popnhook-util/mixer.c @@ -6,10 +6,11 @@ #include // clang-format on +#include "core/log.h" + #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" MMRESULT STDCALL hook_mixerGetLineControlsA( HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls); diff --git a/src/main/popnhook1/Module.mk b/src/main/popnhook1/Module.mk index c2c15107..f7447737 100644 --- a/src/main/popnhook1/Module.mk +++ b/src/main/popnhook1/Module.mk @@ -8,6 +8,7 @@ ldflags_popnhook1 := \ -liphlpapi \ libs_popnhook1 := \ + core \ iidxhook-util \ ezusb-emu \ ezusb2-popn-emu \ diff --git a/src/main/popnhook1/avs-boot.c b/src/main/popnhook1/avs-boot.c index f9833a7b..aae46167 100644 --- a/src/main/popnhook1/avs-boot.c +++ b/src/main/popnhook1/avs-boot.c @@ -5,14 +5,14 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "imports/avs.h" #include "popnhook1/avs-boot.h" -#include "util/log.h" - static int (*real_ea3_boot_avs)(struct property_node *config); static int (*real_ea3_boot)(struct property_node *config); diff --git a/src/main/popnhook1/config-eamuse.c b/src/main/popnhook1/config-eamuse.c index 98e406b8..14864ba2 100644 --- a/src/main/popnhook1/config-eamuse.c +++ b/src/main/popnhook1/config-eamuse.c @@ -2,12 +2,12 @@ #include "cconfig/cconfig-util.h" +#include "core/log.h" + #include "popnhook1/config-eamuse.h" #include "security/mcode.h" -#include "util/log.h" - #define POPNHOOK1_CONFIG_EAMUSE_SERVER_KEY "eamuse.server" #define POPNHOOK1_CONFIG_EAMUSE_PCBID_KEY "eamuse.pcbid" #define POPNHOOK1_CONFIG_EAMUSE_EAMID_KEY "eamuse.eamid" diff --git a/src/main/popnhook1/config-gfx.c b/src/main/popnhook1/config-gfx.c index 8e231d11..8bc6b100 100644 --- a/src/main/popnhook1/config-gfx.c +++ b/src/main/popnhook1/config-gfx.c @@ -2,9 +2,9 @@ #include "cconfig/cconfig-util.h" -#include "popnhook1/config-gfx.h" +#include "core/log.h" -#include "util/log.h" +#include "popnhook1/config-gfx.h" #define POPNHOOK1_CONFIG_GFX_WINDOWED_KEY "gfx.windowed" #define POPNHOOK1_CONFIG_GFX_FRAMED_KEY "gfx.framed" diff --git a/src/main/popnhook1/config-sec.c b/src/main/popnhook1/config-sec.c index f1555200..99342b28 100644 --- a/src/main/popnhook1/config-sec.c +++ b/src/main/popnhook1/config-sec.c @@ -3,12 +3,13 @@ #include "cconfig/cconfig-util.h" +#include "core/log.h" + #include "popnhook1/config-sec.h" #include "security/mcode.h" #include "security/rp.h" -#include "util/log.h" #include "util/mem.h" #define POPNHOOK1_CONFIG_SEC_BLACK_PLUG_MCODE_KEY "sec.black_plug_mcode" diff --git a/src/main/popnhook1/d3d9.c b/src/main/popnhook1/d3d9.c index 1d67262c..44f9e1c1 100644 --- a/src/main/popnhook1/d3d9.c +++ b/src/main/popnhook1/d3d9.c @@ -5,6 +5,8 @@ #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/pe.h" #include "hook/table.h" @@ -12,7 +14,6 @@ #include "popnhook1/d3d9.h" #include "util/defs.h" -#include "util/log.h" #include "hook/d3d9.h" diff --git a/src/main/popnhook1/dllmain.c b/src/main/popnhook1/dllmain.c index 5995e222..36c232fb 100644 --- a/src/main/popnhook1/dllmain.c +++ b/src/main/popnhook1/dllmain.c @@ -10,6 +10,14 @@ #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" #include "hook/d3d9.h" @@ -29,8 +37,6 @@ #include "util/cmdline.h" #include "util/defs.h" -#include "util/log.h" -#include "util/thread.h" #include "ezusb2-emu/desc.h" #include "ezusb2-emu/device.h" @@ -62,6 +68,14 @@ 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 popnhook_setup_d3d9_hooks( const struct popnhook1_config_gfx *config_gfx, const bool texture_usage_fix) { @@ -145,20 +159,24 @@ static DWORD STDCALL my_GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo) /* Start up POPNIO.DLL */ log_info("Starting pop'n IO backend"); - popn_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(popn_io_set_loggers); - if (!popn_io_init(thread_create, thread_join, thread_destroy)) { + if (!popn_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing pop'n IO backend failed"); } /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); - if (!eam_io_init(thread_create, thread_join, thread_destroy)) { + if (!eam_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } @@ -190,7 +208,9 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) return TRUE; } - log_to_writer(log_writer_debug, NULL); + core_thread_crt_ext_impl_set(); + + _popnhook1_log_init(); hook_table_apply( NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms)); diff --git a/src/main/popnhook1/filesystem.c b/src/main/popnhook1/filesystem.c index 3d7fd09a..d5584864 100644 --- a/src/main/popnhook1/filesystem.c +++ b/src/main/popnhook1/filesystem.c @@ -7,10 +7,11 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/sdvxhook/Module.mk b/src/main/sdvxhook/Module.mk index c1a8c5b0..cc6d31c2 100644 --- a/src/main/sdvxhook/Module.mk +++ b/src/main/sdvxhook/Module.mk @@ -4,6 +4,8 @@ deplibs_sdvxhook := \ avs \ libs_sdvxhook := \ + avs-util \ + core \ acioemu \ hook \ hooklib \ diff --git a/src/main/sdvxhook/acio.c b/src/main/sdvxhook/acio.c index 6596ee41..e8d7dfda 100644 --- a/src/main/sdvxhook/acio.c +++ b/src/main/sdvxhook/acio.c @@ -15,6 +15,8 @@ #include "acioemu/emu.h" #include "acioemu/icca.h" +#include "core/log.h" + #include "hook/iohook.h" #include "imports/avs.h" @@ -24,7 +26,6 @@ #include "util/defs.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" static struct ac_io_emu ac_io_emu; diff --git a/src/main/sdvxhook/dllmain.c b/src/main/sdvxhook/dllmain.c index 391f4c99..50e20637 100644 --- a/src/main/sdvxhook/dllmain.c +++ b/src/main/sdvxhook/dllmain.c @@ -3,9 +3,14 @@ #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 "hook/iohook.h" #include "hooklib/app.h" @@ -17,7 +22,6 @@ #include "util/cmdline.h" #include "util/defs.h" -#include "util/log.h" static bool my_dll_entry_init(char *sidcode, struct property_node *config); static bool my_dll_entry_main(void); @@ -32,10 +36,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config) log_info("Starting up SDVX IO backend"); - sdvx_io_set_loggers( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + core_log_impl_assign(sdvx_io_set_loggers); - ok = sdvx_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); + ok = sdvx_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); if (!ok) { goto sdvx_io_fail; @@ -43,10 +49,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config) log_info("Starting up card reader backend"); - eam_io_set_loggers( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + core_log_impl_assign(eam_io_set_loggers); - ok = eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); + ok = eam_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); /* Set up IO emulation hooks _after_ IO API setup to allow API implementations with real IO devices */ @@ -100,8 +108,9 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) return TRUE; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // Use AVS APIs + avs_util_core_interop_thread_avs_impl_set(); + avs_util_core_interop_log_avs_impl_set(); args_recover(&argc, &argv); diff --git a/src/main/sdvxhook/gfx.c b/src/main/sdvxhook/gfx.c index 16cf7330..2d367590 100644 --- a/src/main/sdvxhook/gfx.c +++ b/src/main/sdvxhook/gfx.c @@ -3,6 +3,8 @@ #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/pe.h" #include "hook/table.h" @@ -10,7 +12,6 @@ #include "sdvxhook/gfx.h" #include "util/defs.h" -#include "util/log.h" static LRESULT CALLBACK my_WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); diff --git a/src/main/sdvxhook/kfca.c b/src/main/sdvxhook/kfca.c index 5c89686e..82ac111f 100644 --- a/src/main/sdvxhook/kfca.c +++ b/src/main/sdvxhook/kfca.c @@ -9,8 +9,9 @@ #include "bemanitools/sdvxio.h" +#include "core/log.h" + #include "util/defs.h" -#include "util/log.h" #include "util/time.h" static void kfca_send_version(const struct ac_io_message *req); diff --git a/src/main/sdvxhook/lcd.c b/src/main/sdvxhook/lcd.c index 06ea1e6c..6d942bbc 100644 --- a/src/main/sdvxhook/lcd.c +++ b/src/main/sdvxhook/lcd.c @@ -12,13 +12,14 @@ #include #include +#include "core/log.h" + #include "hook/iohook.h" #include "sdvxhook/lcd.h" #include "util/hex.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" static HRESULT lcd_open(struct irp *irp); diff --git a/src/main/sdvxhook2-cn/Module.mk b/src/main/sdvxhook2-cn/Module.mk index fd00fc62..2bb715ef 100644 --- a/src/main/sdvxhook2-cn/Module.mk +++ b/src/main/sdvxhook2-cn/Module.mk @@ -12,6 +12,8 @@ deplibs_sdvxhook2-cn := \ avs \ libs_sdvxhook2-cn := \ + avs-util \ + core \ acioemu \ camhook \ d3d9exhook \ diff --git a/src/main/sdvxhook2-cn/acio.c b/src/main/sdvxhook2-cn/acio.c index f7116e28..4507333c 100644 --- a/src/main/sdvxhook2-cn/acio.c +++ b/src/main/sdvxhook2-cn/acio.c @@ -14,6 +14,8 @@ #include "acioemu/addr.h" #include "acioemu/emu.h" +#include "core/log.h" + #include "hook/iohook.h" #include "hooklib/rs232.h" @@ -24,7 +26,6 @@ #include "util/defs.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" static struct ac_io_emu ac_io_emu; diff --git a/src/main/sdvxhook2-cn/config-cn.c b/src/main/sdvxhook2-cn/config-cn.c index c492603e..650b5282 100644 --- a/src/main/sdvxhook2-cn/config-cn.c +++ b/src/main/sdvxhook2-cn/config-cn.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "sdvxhook2-cn/config-cn.h" +#include "core/log.h" -#include "util/log.h" +#include "sdvxhook2-cn/config-cn.h" #define SDVXHOOK2_CN_CONFIG_DISABLE_IO_EMU_KEY "io.disable_io_emu" #define SDVXHOOK2_CN_CONFIG_UNIS_PATH_KEY "cn.unis_path" diff --git a/src/main/sdvxhook2-cn/dllmain.c b/src/main/sdvxhook2-cn/dllmain.c index 3a20217b..07d2de0f 100644 --- a/src/main/sdvxhook2-cn/dllmain.c +++ b/src/main/sdvxhook2-cn/dllmain.c @@ -5,11 +5,16 @@ #include #include +#include "avs-util/core-interop.h" + #include "bemanitools/eamio.h" #include "bemanitools/sdvxio.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" @@ -27,9 +32,7 @@ #include "imports/avs.h" -#include "util/log.h" #include "util/str.h" -#include "util/thread.h" #define SDVXHOOK2_CN_INFO_HEADER \ "sdvxhook for VW CN" \ @@ -75,11 +78,12 @@ 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"); - sdvx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(sdvx_io_set_loggers); if (!sdvx_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing sdvx IO backend failed"); } } @@ -134,8 +138,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // 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); diff --git a/src/main/sdvxhook2-cn/kfca.c b/src/main/sdvxhook2-cn/kfca.c index f4d88948..02c72973 100644 --- a/src/main/sdvxhook2-cn/kfca.c +++ b/src/main/sdvxhook2-cn/kfca.c @@ -9,8 +9,9 @@ #include "bemanitools/sdvxio.h" +#include "core/log.h" + #include "util/defs.h" -#include "util/log.h" #include "util/time.h" static void kfca_send_version(const struct ac_io_message *req); diff --git a/src/main/sdvxhook2-cn/unis-version.c b/src/main/sdvxhook2-cn/unis-version.c index d6609992..3ed7e385 100644 --- a/src/main/sdvxhook2-cn/unis-version.c +++ b/src/main/sdvxhook2-cn/unis-version.c @@ -8,11 +8,12 @@ #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/table.h" #include "util/defs.h" -#include "util/log.h" #include "util/str.h" #include "util/time.h" diff --git a/src/main/sdvxhook2/Module.mk b/src/main/sdvxhook2/Module.mk index aa38c669..f813557b 100644 --- a/src/main/sdvxhook2/Module.mk +++ b/src/main/sdvxhook2/Module.mk @@ -12,6 +12,8 @@ deplibs_sdvxhook2 := \ avs \ libs_sdvxhook2 := \ + avs-util \ + core \ acioemu \ bio2emu \ camhook \ diff --git a/src/main/sdvxhook2/acio.c b/src/main/sdvxhook2/acio.c index 6ac0cdca..8db25df5 100644 --- a/src/main/sdvxhook2/acio.c +++ b/src/main/sdvxhook2/acio.c @@ -15,6 +15,8 @@ #include "acioemu/emu.h" #include "acioemu/icca.h" +#include "core/log.h" + #include "hook/iohook.h" #include "hooklib/rs232.h" @@ -24,7 +26,6 @@ #include "util/defs.h" #include "util/iobuf.h" -#include "util/log.h" #include "util/str.h" static struct ac_io_emu ac_io_emu; diff --git a/src/main/sdvxhook2/config-io.c b/src/main/sdvxhook2/config-io.c index 6d87bc0b..421f3af7 100644 --- a/src/main/sdvxhook2/config-io.c +++ b/src/main/sdvxhook2/config-io.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "sdvxhook2/config-io.h" +#include "core/log.h" -#include "util/log.h" +#include "sdvxhook2/config-io.h" #define SDVXHOOK2_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY \ "io.disable_card_reader_emu" diff --git a/src/main/sdvxhook2/dllmain.c b/src/main/sdvxhook2/dllmain.c index e601e3ab..3c74ab4e 100644 --- a/src/main/sdvxhook2/dllmain.c +++ b/src/main/sdvxhook2/dllmain.c @@ -5,11 +5,16 @@ #include #include +#include "avs-util/core-interop.h" + #include "bemanitools/eamio.h" #include "bemanitools/sdvxio.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" @@ -33,9 +38,7 @@ #include "imports/avs.h" -#include "util/log.h" #include "util/str.h" -#include "util/thread.h" #define SDVXHOOK2_INFO_HEADER \ "sdvxhook for VW" \ @@ -105,11 +108,12 @@ 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"); - sdvx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(sdvx_io_set_loggers); if (!sdvx_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing sdvx IO backend failed"); } } @@ -117,11 +121,12 @@ 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"); - eam_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(eam_io_set_loggers); if (!eam_io_init( - avs_thread_create, avs_thread_join, avs_thread_destroy)) { + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_fatal("Initializing card reader backend failed"); } } @@ -207,8 +212,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); + // 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); diff --git a/src/main/sdvxhook2/nvapi.c b/src/main/sdvxhook2/nvapi.c index fbe14d83..e5f244a4 100644 --- a/src/main/sdvxhook2/nvapi.c +++ b/src/main/sdvxhook2/nvapi.c @@ -10,13 +10,13 @@ #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/table.h" #include "sdvxhook2/nvapi.h" -#include "util/log.h" - static void *my_GetProcAddress(HMODULE dll, const char *name); static void *(*real_GetProcAddress)(HMODULE dll, const char *name); diff --git a/src/main/sdvxhook2/power.c b/src/main/sdvxhook2/power.c index f860c1b9..e6d0d33a 100644 --- a/src/main/sdvxhook2/power.c +++ b/src/main/sdvxhook2/power.c @@ -10,13 +10,13 @@ #include +#include "core/log.h" + #include "hook/com-proxy.h" #include "hook/table.h" #include "sdvxhook2/power.h" -#include "util/log.h" - static DWORD my_PowerSetActiveScheme(HKEY UserRootPowerKey, const GUID *SchemeGuid); static DWORD my_PowerWriteACValueIndex( diff --git a/src/main/sdvxio-bio2/Module.mk b/src/main/sdvxio-bio2/Module.mk index bf16a3be..04ea0fde 100644 --- a/src/main/sdvxio-bio2/Module.mk +++ b/src/main/sdvxio-bio2/Module.mk @@ -4,6 +4,7 @@ ldflags_sdvxio-bio2 := \ -lsetupapi \ libs_sdvxio-bio2 := \ + core \ aciodrv \ bio2drv \ cconfig \ diff --git a/src/main/sdvxio-kfca/Module.mk b/src/main/sdvxio-kfca/Module.mk index cb10b225..5127c16a 100644 --- a/src/main/sdvxio-kfca/Module.mk +++ b/src/main/sdvxio-kfca/Module.mk @@ -1,6 +1,7 @@ dlls += sdvxio-kfca libs_sdvxio-kfca := \ + core \ geninput \ aciodrv \ aciomgr \ diff --git a/src/main/sdvxio-kfca/config-kfca.c b/src/main/sdvxio-kfca/config-kfca.c index 91814e67..6b95e24e 100644 --- a/src/main/sdvxio-kfca/config-kfca.c +++ b/src/main/sdvxio-kfca/config-kfca.c @@ -1,8 +1,8 @@ #include "cconfig/cconfig-util.h" -#include "sdvxio-kfca/config-kfca.h" +#include "core/log.h" -#include "util/log.h" +#include "sdvxio-kfca/config-kfca.h" #define SDVXIO_KFCA_CONFIG_KFCA_PORT_KEY "kfca.port" #define SDVXIO_KFCA_CONFIG_KFCA_BAUD_KEY "kfca.baud" diff --git a/src/main/security/id.c b/src/main/security/id.c index b591fb2d..93699aae 100644 --- a/src/main/security/id.c +++ b/src/main/security/id.c @@ -1,9 +1,10 @@ #include +#include "core/log.h" + #include "security/id.h" #include "util/hex.h" -#include "util/log.h" #include "util/mem.h" const struct security_id security_id_default = { diff --git a/src/main/security/mcode.c b/src/main/security/mcode.c index 5bc93fa9..88176473 100644 --- a/src/main/security/mcode.c +++ b/src/main/security/mcode.c @@ -1,8 +1,9 @@ #include +#include "core/log.h" + #include "security/mcode.h" -#include "util/log.h" #include "util/mem.h" const struct security_mcode security_mcode_eamuse = { diff --git a/src/main/security/rp-blowfish.c b/src/main/security/rp-blowfish.c index 9aeb6965..f45a0a99 100644 --- a/src/main/security/rp-blowfish.c +++ b/src/main/security/rp-blowfish.c @@ -1,10 +1,10 @@ #include +#include "core/log.h" + #include "security/rp-blowfish-table.h" #include "security/rp-blowfish.h" -#include "util/log.h" - static int security_rp_blowfish_enc_sub(int a1) { int result; // eax@1 diff --git a/src/main/security/rp.c b/src/main/security/rp.c index ba828644..5e80670b 100644 --- a/src/main/security/rp.c +++ b/src/main/security/rp.c @@ -1,3 +1,5 @@ +#include "core/log.h" + #include "security/rp.h" #include "security/rp-blowfish.h" @@ -5,7 +7,6 @@ #include "security/util.h" #include "util/crypto.h" -#include "util/log.h" static uint32_t security_rp_get_len_mcode(const struct security_mcode *mcode) { diff --git a/src/main/security/rp2.c b/src/main/security/rp2.c index 51480a69..92b3acb4 100644 --- a/src/main/security/rp2.c +++ b/src/main/security/rp2.c @@ -1,11 +1,12 @@ #include +#include "core/log.h" + #include "security/rp-util.h" #include "security/rp2.h" #include "security/util.h" #include "util/crypto.h" -#include "util/log.h" static uint8_t security_rp2_signature_scramble_table[16] = { 0x0C, diff --git a/src/main/security/rp3.c b/src/main/security/rp3.c index a6dd5bf5..6e83f683 100644 --- a/src/main/security/rp3.c +++ b/src/main/security/rp3.c @@ -1,12 +1,13 @@ #include +#include "core/log.h" + #include "security/rp-util.h" #include "security/rp2.h" #include "security/rp3.h" #include "security/util.h" #include "util/crc.h" -#include "util/log.h" void security_rp3_generate_signed_eeprom_data( enum security_rp_util_rp_type type, diff --git a/src/main/unicorntail/Module.mk b/src/main/unicorntail/Module.mk index bd6d3606..d2d96be1 100644 --- a/src/main/unicorntail/Module.mk +++ b/src/main/unicorntail/Module.mk @@ -4,6 +4,7 @@ deplibs_unicorntail := \ avs \ libs_unicorntail := \ + core \ p3io \ p3ioemu \ hook \ diff --git a/src/main/unicorntail/dllmain.c b/src/main/unicorntail/dllmain.c index 59f862de..b195edf5 100644 --- a/src/main/unicorntail/dllmain.c +++ b/src/main/unicorntail/dllmain.c @@ -2,6 +2,8 @@ #include +#include "core/log.h" + #include "hook/iohook.h" #include "hooklib/app.h" @@ -12,7 +14,6 @@ #include "unicorntail/usbmem.h" #include "util/defs.h" -#include "util/log.h" static bool my_dll_entry_init(char *sidcode, struct property_node *param); static bool my_dll_entry_main(void); @@ -50,7 +51,7 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) goto end; } - log_to_external( + core_log_impl_set( log_body_misc, log_body_info, log_body_warning, log_body_fatal); 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 fd0a85c4..b4a49b17 100644 --- a/src/main/unicorntail/p3io.c +++ b/src/main/unicorntail/p3io.c @@ -3,6 +3,8 @@ #include #include +#include "core/log.h" + #include "p3io/cmd.h" #include "p3io/frame.h" @@ -11,7 +13,6 @@ #include "unicorntail/p3io.h" #include "util/array.h" -#include "util/log.h" #include "util/str.h" static bool p3io_match_irp_locked(const struct irp *irp); diff --git a/src/main/unicorntail/usbmem.c b/src/main/unicorntail/usbmem.c index 50b496e6..ef820699 100644 --- a/src/main/unicorntail/usbmem.c +++ b/src/main/unicorntail/usbmem.c @@ -3,9 +3,10 @@ #include #include +#include "core/log.h" + #include "hook/iohook.h" -#include "util/log.h" #include "util/str.h" static bool usbmem_match_irp(const struct irp *irp); diff --git a/src/main/util/array.c b/src/main/util/array.c index 900fba17..9421fffa 100644 --- a/src/main/util/array.c +++ b/src/main/util/array.c @@ -2,8 +2,9 @@ #include #include +#include "core/log.h" + #include "util/array.h" -#include "util/log.h" #include "util/mem.h" void array_init(struct array *array) diff --git a/src/main/util/crc.c b/src/main/util/crc.c index c49af451..7ab06b84 100644 --- a/src/main/util/crc.c +++ b/src/main/util/crc.c @@ -1,7 +1,7 @@ #include #include -#include "util/log.h" +#include "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 110dd99e..db1702e8 100644 --- a/src/main/util/crypto.c +++ b/src/main/util/crypto.c @@ -1,12 +1,13 @@ #define LOG_MODULE "crypto" -#include "util/crypto.h" -#include "util/log.h" -#include "util/mem.h" - #include #include +#include "core/log.h" + +#include "util/crypto.h" +#include "util/mem.h" + static const char vista_prov[] = "Microsoft Enhanced RSA and AES Cryptographic Provider"; static const char winxp_prov[] = diff --git a/src/main/util/fs.c b/src/main/util/fs.c index 731fdf93..8c4c7c68 100644 --- a/src/main/util/fs.c +++ b/src/main/util/fs.c @@ -6,9 +6,10 @@ #include #include +#include "core/log.h" + #include "util/defs.h" #include "util/fs.h" -#include "util/log.h" #include "util/mem.h" #include "util/str.h" diff --git a/src/main/util/hex.c b/src/main/util/hex.c index 1ac6b4d6..de08286d 100644 --- a/src/main/util/hex.c +++ b/src/main/util/hex.c @@ -2,8 +2,9 @@ #include #include +#include "core/log.h" + #include "util/hex.h" -#include "util/log.h" static bool hex_decode_nibble(char c, uint8_t *nibble) { diff --git a/src/main/util/iobuf.c b/src/main/util/iobuf.c index 45884ead..7638cb50 100644 --- a/src/main/util/iobuf.c +++ b/src/main/util/iobuf.c @@ -1,8 +1,9 @@ #define LOG_MODULE "util-iobuf" -#include "util/iobuf.h" +#include "core/log.h" + #include "util/hex.h" -#include "util/log.h" +#include "util/iobuf.h" #include "util/mem.h" void iobuf_log(struct iobuf *buffer, const char *tag) diff --git a/src/main/util/mem.c b/src/main/util/mem.c index 53e84ffb..f03ebafc 100644 --- a/src/main/util/mem.c +++ b/src/main/util/mem.c @@ -7,7 +7,7 @@ #include #include -#include "util/log.h" +#include "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 6b5623d8..04d498d3 100644 --- a/src/main/util/msg-thread.c +++ b/src/main/util/msg-thread.c @@ -5,9 +5,10 @@ #include #include -#include "util/log.h" +#include "core/log.h" +#include "core/thread.h" + #include "util/msg-thread.h" -#include "util/thread.h" static bool msg_thread_step(HWND hwnd); @@ -102,7 +103,7 @@ void msg_thread_init(HINSTANCE inst) { msg_thread_ready = CreateEvent(NULL, TRUE, FALSE, NULL); msg_thread_stop = CreateEvent(NULL, TRUE, FALSE, NULL); - msg_thread_id = thread_create(msg_thread_proc, inst, 0x4000, 0); + msg_thread_id = core_thread_create(msg_thread_proc, inst, 0x4000, 0); WaitForSingleObject(msg_thread_ready, INFINITE); CloseHandle(msg_thread_ready); @@ -112,8 +113,8 @@ void msg_thread_fini(void) { SetEvent(msg_thread_stop); - thread_join(msg_thread_id, NULL); - thread_destroy(msg_thread_id); + core_thread_join(msg_thread_id, NULL); + core_thread_destroy(msg_thread_id); CloseHandle(msg_thread_stop); } diff --git a/src/main/util/net.c b/src/main/util/net.c index 492e3ef1..d2c9d7d5 100644 --- a/src/main/util/net.c +++ b/src/main/util/net.c @@ -6,7 +6,8 @@ #include #include -#include "util/log.h" +#include "core/log.h" + #include "util/mem.h" #include "util/net.h" #include "util/str.h" diff --git a/src/main/util/os.c b/src/main/util/os.c index c63de00d..e6aad5dc 100644 --- a/src/main/util/os.c +++ b/src/main/util/os.c @@ -6,7 +6,8 @@ #include -#include "util/log.h" +#include "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 84731133..f1905d32 100644 --- a/src/main/util/proc.c +++ b/src/main/util/proc.c @@ -6,7 +6,7 @@ #include #include -#include "util/log.h" +#include "core/log.h" bool proc_is_running_as_admin_user() { diff --git a/src/main/util/signal.c b/src/main/util/signal.c index 4c15acd5..9851c920 100644 --- a/src/main/util/signal.c +++ b/src/main/util/signal.c @@ -1,8 +1,9 @@ #include #include +#include "core/log.h" + #include "util/hex.h" -#include "util/log.h" #include "util/signal.h" static signal_shutdown_handler_t shutdown_handler; diff --git a/src/main/util/time.c b/src/main/util/time.c index 0412b29c..feb29045 100644 --- a/src/main/util/time.c +++ b/src/main/util/time.c @@ -1,6 +1,7 @@ #include -#include "util/log.h" +#include "core/log.h" + #include "util/time.h" static uint64_t counter_freq_ns; diff --git a/src/main/vigem-ddrio/Module.mk b/src/main/vigem-ddrio/Module.mk index 8aae8a25..82e0f51f 100644 --- a/src/main/vigem-ddrio/Module.mk +++ b/src/main/vigem-ddrio/Module.mk @@ -10,6 +10,7 @@ ldflags_vigem-ddrio := \ -lsetupapi \ libs_vigem-ddrio := \ + core \ cconfig \ ddrio \ util \ diff --git a/src/main/vigem-ddrio/config-vigem-ddrio.c b/src/main/vigem-ddrio/config-vigem-ddrio.c index 59e8251f..0ff44f23 100644 --- a/src/main/vigem-ddrio/config-vigem-ddrio.c +++ b/src/main/vigem-ddrio/config-vigem-ddrio.c @@ -1,9 +1,9 @@ #include "cconfig/cconfig-main.h" #include "cconfig/cconfig-util.h" -#include "vigem-ddrio/config-vigem-ddrio.h" +#include "core/log.h" -#include "util/log.h" +#include "vigem-ddrio/config-vigem-ddrio.h" #define VIGEM_DDRIO_CONFIG_ENABLE_REACTIVE_LIGHT_KEY \ "ddrio.enable_reactive_light" diff --git a/src/main/vigem-ddrio/main.c b/src/main/vigem-ddrio/main.c index 62cc7b18..7d7fafa7 100644 --- a/src/main/vigem-ddrio/main.c +++ b/src/main/vigem-ddrio/main.c @@ -8,9 +8,17 @@ #include "ViGEm/Client.h" #include "bemanitools/ddrio.h" -#include "util/log.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 "util/math.h" -#include "util/thread.h" + #include "vigemstub/helper.h" #include "vigem-ddrio/config-vigem-ddrio.h" @@ -112,17 +120,23 @@ void set_reactive_lights(uint32_t input_state) int main(int argc, char **argv) { - log_to_writer(log_writer_stdout, NULL); + core_thread_crt_ext_impl_set(); + core_log_bt_ext_impl_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); } - ddr_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(ddr_io_set_loggers); - if (!ddr_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) { + if (!ddr_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_warning("Initializing ddrio failed"); return -1; } diff --git a/src/main/vigem-iidxio/Module.mk b/src/main/vigem-iidxio/Module.mk index 887a70f0..4fae200c 100644 --- a/src/main/vigem-iidxio/Module.mk +++ b/src/main/vigem-iidxio/Module.mk @@ -10,6 +10,7 @@ ldflags_vigem-iidxio := \ -lsetupapi \ libs_vigem-iidxio := \ + core \ cconfig \ iidxio \ util \ diff --git a/src/main/vigem-iidxio/cab-16seg-sequencer.c b/src/main/vigem-iidxio/cab-16seg-sequencer.c index 01ea12bd..f7e6e05e 100644 --- a/src/main/vigem-iidxio/cab-16seg-sequencer.c +++ b/src/main/vigem-iidxio/cab-16seg-sequencer.c @@ -4,7 +4,8 @@ #include #include -#include "util/log.h" +#include "core/log.h" + #include "util/time.h" static const uint8_t _MAX_LEN_16SEG = 9; diff --git a/src/main/vigem-iidxio/cab-light-sequencer.c b/src/main/vigem-iidxio/cab-light-sequencer.c index 95214f90..6b345b75 100644 --- a/src/main/vigem-iidxio/cab-light-sequencer.c +++ b/src/main/vigem-iidxio/cab-light-sequencer.c @@ -4,9 +4,10 @@ #include #include +#include "core/log.h" + #include "vigem-iidxio/cab-light-sequencer.h" -#include "util/log.h" #include "util/math.h" #include "util/time.h" diff --git a/src/main/vigem-iidxio/config.c b/src/main/vigem-iidxio/config.c index 40eeae56..acf52359 100644 --- a/src/main/vigem-iidxio/config.c +++ b/src/main/vigem-iidxio/config.c @@ -1,9 +1,9 @@ #include "cconfig/cconfig-main.h" #include "cconfig/cconfig-util.h" -#include "vigem-iidxio/config.h" +#include "core/log.h" -#include "util/log.h" +#include "vigem-iidxio/config.h" #define VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_KEY \ "vigem.iidxio.tt.anlog.relative" diff --git a/src/main/vigem-iidxio/main.c b/src/main/vigem-iidxio/main.c index 3527545a..51b0b147 100644 --- a/src/main/vigem-iidxio/main.c +++ b/src/main/vigem-iidxio/main.c @@ -9,9 +9,14 @@ #include "bemanitools/iidxio.h" -#include "util/log.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 "util/math.h" -#include "util/thread.h" #include "util/time.h" #include "vigem-iidxio/cab-16seg-sequencer.h" @@ -259,7 +264,10 @@ static void _all_lights_off() int main(int argc, char **argv) { - log_to_writer(log_writer_stdout, NULL); + core_thread_crt_ext_impl_set(); + core_log_bt_ext_impl_set(); + + core_log_bt_ext_init_with_stdout(); struct vigem_iidxio_config config; @@ -267,10 +275,12 @@ int main(int argc, char **argv) return -1; } - iidx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(iidx_io_set_loggers); - if (!iidx_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) { + if (!iidx_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_warning("Initializing iidxio failed"); return -1; } diff --git a/src/main/vigem-sdvxio/Module.mk b/src/main/vigem-sdvxio/Module.mk index 6907fbf8..523dd69f 100644 --- a/src/main/vigem-sdvxio/Module.mk +++ b/src/main/vigem-sdvxio/Module.mk @@ -10,6 +10,7 @@ ldflags_vigem-sdvxio := \ -lsetupapi \ libs_vigem-sdvxio := \ + core \ cconfig \ sdvxio \ util \ diff --git a/src/main/vigem-sdvxio/config-vigem-sdvxio.c b/src/main/vigem-sdvxio/config-vigem-sdvxio.c index 768a514c..faae9e29 100644 --- a/src/main/vigem-sdvxio/config-vigem-sdvxio.c +++ b/src/main/vigem-sdvxio/config-vigem-sdvxio.c @@ -1,9 +1,9 @@ #include "cconfig/cconfig-main.h" #include "cconfig/cconfig-util.h" -#include "vigem-sdvxio/config-vigem-sdvxio.h" +#include "core/log.h" -#include "util/log.h" +#include "vigem-sdvxio/config-vigem-sdvxio.h" #define VIGEM_SDVXIO_CONFIG_ENABLE_KEYLIGHT_KEY "sdvxio.enable_keylight" #define VIGEM_SDVXIO_CONFIG_RELATIVE_ANALOG_KEY "sdvxio.use_relative_analog" diff --git a/src/main/vigem-sdvxio/main.c b/src/main/vigem-sdvxio/main.c index cf4b4e22..c87a4361 100644 --- a/src/main/vigem-sdvxio/main.c +++ b/src/main/vigem-sdvxio/main.c @@ -8,9 +8,16 @@ #include "ViGEm/Client.h" #include "bemanitools/sdvxio.h" -#include "util/log.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 "util/math.h" -#include "util/thread.h" + #include "vigemstub/helper.h" #include "vigem-sdvxio/config-vigem-sdvxio.h" @@ -129,17 +136,21 @@ void set_pwm_brightness(uint8_t wing_pwm, uint8_t controller_pwm) int main(int argc, char **argv) { - log_to_writer(log_writer_stdout, NULL); + core_thread_crt_ext_impl_set(); + core_log_bt_ext_impl_set(); + core_log_bt_ext_init_with_stdout(); struct vigem_sdvxio_config config; if (!get_vigem_sdvxio_config(&config)) { exit(EXIT_FAILURE); } - sdvx_io_set_loggers( - log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + core_log_impl_assign(sdvx_io_set_loggers); - if (!sdvx_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) { + if (!sdvx_io_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get())) { log_warning("Initializing sdvxio failed"); return -1; } diff --git a/src/main/vigemstub/helper.c b/src/main/vigemstub/helper.c index 4aeb5192..a92510b2 100644 --- a/src/main/vigemstub/helper.c +++ b/src/main/vigemstub/helper.c @@ -2,9 +2,10 @@ #include #include +#include "core/log.h" + #include "ViGEm/Client.h" -#include "util/log.h" #include "vigemstub/helper.h" PVIGEM_CLIENT vigem_helper_setup(void) diff --git a/src/test/cconfig/Module.mk b/src/test/cconfig/Module.mk index a61e8d9b..81433890 100644 --- a/src/test/cconfig/Module.mk +++ b/src/test/cconfig/Module.mk @@ -3,6 +3,7 @@ testexes += cconfig-test srcdir_cconfig-test := src/test/cconfig libs_cconfig-test := \ + core \ cconfig \ test \ util \ @@ -17,6 +18,7 @@ testexes += cconfig-util-test srcdir_cconfig-util-test := src/test/cconfig libs_cconfig-util-test := \ + core \ cconfig \ test \ util \ @@ -31,6 +33,7 @@ testexes += cconfig-cmd-test srcdir_cconfig-cmd-test := src/test/cconfig libs_cconfig-cmd-test := \ + core \ cconfig \ test \ util \ diff --git a/src/test/d3d9hook/Module.mk b/src/test/d3d9hook/Module.mk index 585139c5..3ab336b0 100644 --- a/src/test/d3d9hook/Module.mk +++ b/src/test/d3d9hook/Module.mk @@ -5,6 +5,7 @@ srcdir_d3d9hook := src/test/d3d9hook ldflags_d3d9hook := \ libs_d3d9hook := \ + core \ hook \ test \ util \ @@ -25,6 +26,7 @@ libs_d3d9hook-test := \ hook \ test \ util \ + core \ src_d3d9hook-test := \ main.c \ diff --git a/src/test/d3d9hook/dllmain.c b/src/test/d3d9hook/dllmain.c index 88060bb5..e7052df3 100644 --- a/src/test/d3d9hook/dllmain.c +++ b/src/test/d3d9hook/dllmain.c @@ -2,12 +2,14 @@ #include #include +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log.h" + #include "hook/d3d9.h" #include "test/check.h" -#include "util/log.h" - #define debug_print(...) fprintf(stderr, __VA_ARGS__) static HRESULT my_d3d9_handler(struct hook_d3d9_irp *irp); @@ -298,7 +300,9 @@ static HRESULT my_d3d9_handler(struct hook_d3d9_irp *irp) BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - log_to_writer(log_writer_stderr, NULL); + core_log_bt_ext_init_with_debug(); + core_log_bt_ext_init_with_stderr(); + debug_print("Initializing d3d9 hook module...\n"); hook_d3d9_init(d3d9_handlers, lengthof(d3d9_handlers)); diff --git a/src/test/iidxhook-util/Module.mk b/src/test/iidxhook-util/Module.mk index be4883eb..49fdda92 100644 --- a/src/test/iidxhook-util/Module.mk +++ b/src/test/iidxhook-util/Module.mk @@ -6,6 +6,7 @@ ldflags_iidxhook-util-config-eamuse-test := \ -lws2_32 \ libs_iidxhook-util-config-eamuse-test := \ + core \ security \ iidxhook-util \ cconfig \ @@ -22,6 +23,7 @@ testexes += iidxhook-util-config-gfx-test srcdir_iidxhook-util-config-gfx-test := src/test/iidxhook-util libs_iidxhook-util-config-gfx-test := \ + core \ security \ iidxhook-util \ cconfig \ @@ -38,6 +40,7 @@ testexes += iidxhook-util-config-misc-test srcdir_iidxhook-util-config-misc-test := src/test/iidxhook-util libs_iidxhook-util-config-misc-test := \ + core \ security \ iidxhook-util \ cconfig \ @@ -54,6 +57,7 @@ testexes += iidxhook-util-config-sec-test srcdir_iidxhook-util-config-sec-test := src/test/iidxhook-util libs_iidxhook-util-config-sec-test := \ + core \ security \ iidxhook-util \ cconfig \ diff --git a/src/test/iidxhook/Module.mk b/src/test/iidxhook/Module.mk index 8c086423..9172fa56 100644 --- a/src/test/iidxhook/Module.mk +++ b/src/test/iidxhook/Module.mk @@ -3,6 +3,7 @@ testexes += iidxhook-config-iidxhook1-test srcdir_iidxhook-config-iidxhook1-test := src/test/iidxhook libs_iidxhook-config-iidxhook1-test := \ + core \ cconfig \ iidxhook1 \ test \ @@ -18,6 +19,7 @@ testexes += iidxhook-config-iidxhook2-test srcdir_iidxhook-config-iidxhook2-test := src/test/iidxhook libs_iidxhook-config-iidxhook2-test := \ + core \ iidxhook2 \ cconfig \ test \ diff --git a/src/test/iidxhook8/Module.mk b/src/test/iidxhook8/Module.mk index 57731d54..3cccd421 100644 --- a/src/test/iidxhook8/Module.mk +++ b/src/test/iidxhook8/Module.mk @@ -3,6 +3,7 @@ testexes += iidxhook8-config-cam-test srcdir_iidxhook8-config-cam-test := src/test/iidxhook8 libs_iidxhook8-config-cam-test := \ + core \ camhook \ cconfig \ test \ @@ -18,6 +19,7 @@ testexes += iidxhook8-config-io-test srcdir_iidxhook8-config-io-test := src/test/iidxhook8 libs_iidxhook8-config-io-test := \ + core \ cconfig \ test \ util \ diff --git a/src/test/security/Module.mk b/src/test/security/Module.mk index 3bdef674..7ac51d71 100644 --- a/src/test/security/Module.mk +++ b/src/test/security/Module.mk @@ -3,6 +3,7 @@ testexes += security-id-test srcdir_security-id-test := src/test/security libs_security-id-test := \ + core \ security \ test \ util \ @@ -17,6 +18,7 @@ testexes += security-mcode-test srcdir_security-mcode-test := src/test/security libs_security-mcode-test := \ + core \ security \ test \ util \ @@ -31,6 +33,7 @@ testexes += security-util-test srcdir_security-util-test := src/test/security libs_security-util-test := \ + core \ security \ test \ util \ @@ -45,6 +48,7 @@ testexes += security-rp-test srcdir_security-rp-test := src/test/security libs_security-rp-test := \ + core \ security \ test \ util \ @@ -59,6 +63,7 @@ testexes += security-rp2-test srcdir_security-rp2-test := src/test/security libs_security-rp2-test := \ + core \ security \ test \ util \ @@ -73,6 +78,7 @@ testexes += security-rp3-test srcdir_security-rp3-test := src/test/security libs_security-rp3-test := \ + core \ security \ test \ util \ diff --git a/src/test/test/test.h b/src/test/test/test.h index 91fb01bb..7d0dda04 100644 --- a/src/test/test/test.h +++ b/src/test/test/test.h @@ -3,12 +3,15 @@ #include -#include "util/log.h" +#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) \ - { \ - log_to_writer(log_writer_stderr, NULL); \ +#define TEST_MODULE_BEGIN(name) \ + int main(int argc, char **argv) \ + { \ + core_log_bt_ext_impl_set(); \ + core_log_bt_ext_init_with_stderr(); \ fprintf(stderr, "Executing test module '%s'...\n", #name); #define TEST_MODULE_TEST(func) \ @@ -19,6 +22,8 @@ #define TEST_MODULE_END() \ fprintf(stderr, "Finished execution of test module\n"); \ + core_log_bt_fini(); \ + \ return 0; \ } diff --git a/src/test/util/Module.mk b/src/test/util/Module.mk index ca13ecc6..90f34245 100644 --- a/src/test/util/Module.mk +++ b/src/test/util/Module.mk @@ -7,6 +7,7 @@ ldflags_util-net-test := \ -liphlpapi \ libs_util-net-test := \ + core \ test \ util \