From 312aa619c60bab35ae14600d7cbcc89e3a3ac8b6 Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 22 Feb 2024 23:16:28 +0100 Subject: [PATCH 01/18] fix(dist): Incorrect versioning for ddr distribution packages Apparently forgotten to get updated to reflect the currently supported versions correctly. --- Module.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Module.mk b/Module.mk index 2a948a8..eda489c 100644 --- a/Module.mk +++ b/Module.mk @@ -710,6 +710,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 +730,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 \ From 6b75b33253f9e87eb8e0a8b8108be9768080359b Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 22 Feb 2024 23:17:17 +0100 Subject: [PATCH 02/18] fix(hook): Add missing hook_table_revert impl --- src/main/hook/table.c | 82 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/main/hook/table.c b/src/main/hook/table.c index ed67b3b..067ea75 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,33 @@ 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) { From 560aba3133e25744e809645592609e73e1c7abfc Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 22 Feb 2024 23:18:25 +0100 Subject: [PATCH 03/18] feat(dev): Add a separate docker dev cotainer Improve the development experience by providing an additional docker container that can be started and used as an interactive development environment. It provides all the tools and a stable environment for building (identical to the build container). --- Dockerfile => Dockerfile.build | 0 Dockerfile.dev | 21 +++++++++++++++++++ GNUmakefile | 38 ++++++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 9 deletions(-) rename Dockerfile => Dockerfile.build (100%) create mode 100644 Dockerfile.dev 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 0000000..00c5108 --- /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 8328962..9aef0b1 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) # From 517f8e885f60b33a48fdb76ef3c650b5871357dc Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 11:15:17 +0100 Subject: [PATCH 04/18] feat(avs): Add property get and clear error functions Use these to improve error handling by allowing one to provide additional error information on property related operations. --- src/imports/avs.h | 3 +++ src/imports/import_32_0_avs.def | 2 ++ src/imports/import_32_1002_avs.def | 2 ++ src/imports/import_32_1101_avs.def | 2 ++ src/imports/import_32_1304_avs.def | 2 ++ src/imports/import_32_1306_avs.def | 2 ++ src/imports/import_32_1403_avs.def | 2 ++ src/imports/import_32_1508_avs.def | 2 ++ src/imports/import_32_1601_avs.def | 2 ++ src/imports/import_32_1603_avs.def | 2 ++ src/imports/import_32_1700_avs.def | 2 ++ src/imports/import_32_803_avs.def | 2 ++ src/imports/import_64_1508_avs.def | 2 ++ src/imports/import_64_1509_avs.def | 2 ++ src/imports/import_64_1601_avs.def | 2 ++ src/imports/import_64_1603_avs.def | 4 +++- src/imports/import_64_1700_avs.def | 2 ++ 17 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/imports/avs.h b/src/imports/avs.h index a2d439e..9dce5be 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); +struct property *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 273e5be..9632ecb 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 e2ff5ae..cc4ee29 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 10c59e4..776dc71 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 f83d5a5..18dad23 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 f963ec8..f6deed7 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 de171c1..716d081 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 d162512..504a303 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 74332d4..286806b 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 21f55c1..93fd07d 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 7dc4eaa..f01bc39 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 37f2b3e..9340dad 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 6aeaba1..1a93e7e 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 fde35d6..a596513 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 418395f..960fb94 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 b106ab1..14f42b7 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 8cddba8..3e456b5 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 From 3865e09f065712261e89f4f52731ed8a733aedd0 Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 11:15:17 +0100 Subject: [PATCH 05/18] feat: Add core module This module contains the "core" (API) of bemanitools which includes an abstraction layer for threads and logging at this time. The threads API is very close to what util/thread already was with some structural enhancements which make it easier to understand and work with the API, I hope. Some additional helpers (*-ext module) support in doing common tasks, e.g. setting up the thread API with other modules. The log(ging) part receives a major overhaul to address known limitations and issues with the util/log module: - Cleaner API layer - Separate sinks from actual logging engine - Sinks are composable - Improved and cleaner compatibility layer with AVS logging API Additional "extensions" (*-ext modules) add various helper functions for common tasks like setting up the logging engine with a file and stdout sink. The sinks also improved significantly with the file sink now supporting proper appending and log rotation. Logging to stdout/stderr supports coloring of log messages which works across logging engines. Overall, this refactored foundation is expected to support future developments and removes known limitations at the current scale of bemanitools such as: - Reducing boiler plate code across hooks - Interop of bemanitools and AVS (and setting the foundation for addressing currently missing interop, e.g. for dealing with property structures without AVS) - Addressing performance issues in the logging engine due to incorrect interop with AVS --- Module.mk | 1 + src/main/core/Module.mk | 20 ++++ src/main/core/log-bt-ext.c | 67 +++++++++++ src/main/core/log-bt-ext.h | 59 ++++++++++ src/main/core/log-bt.c | 129 +++++++++++++++++++++ src/main/core/log-bt.h | 87 +++++++++++++++ src/main/core/log-sink-async.c | 23 ++++ src/main/core/log-sink-async.h | 19 ++++ src/main/core/log-sink-debug.c | 23 ++++ src/main/core/log-sink-debug.h | 15 +++ src/main/core/log-sink-file.c | 92 +++++++++++++++ src/main/core/log-sink-file.h | 28 +++++ src/main/core/log-sink-list.c | 66 +++++++++++ src/main/core/log-sink-list.h | 24 ++++ src/main/core/log-sink-mutex.c | 53 +++++++++ src/main/core/log-sink-mutex.h | 21 ++++ src/main/core/log-sink-null.c | 21 ++++ src/main/core/log-sink-null.h | 17 +++ src/main/core/log-sink-std.c | 193 ++++++++++++++++++++++++++++++++ src/main/core/log-sink-std.h | 24 ++++ src/main/core/log-sink.h | 45 ++++++++ src/main/core/log.c | 74 +++++++++++++ src/main/core/log.h | 197 +++++++++++++++++++++++++++++++++ src/main/core/thread-crt-ext.c | 8 ++ src/main/core/thread-crt-ext.h | 9 ++ src/main/core/thread-crt.c | 62 +++++++++++ src/main/core/thread-crt.h | 15 +++ src/main/core/thread.c | 78 +++++++++++++ src/main/core/thread.h | 117 ++++++++++++++++++++ 29 files changed, 1587 insertions(+) create mode 100644 src/main/core/Module.mk create mode 100644 src/main/core/log-bt-ext.c create mode 100644 src/main/core/log-bt-ext.h create mode 100644 src/main/core/log-bt.c create mode 100644 src/main/core/log-bt.h create mode 100644 src/main/core/log-sink-async.c create mode 100644 src/main/core/log-sink-async.h create mode 100644 src/main/core/log-sink-debug.c create mode 100644 src/main/core/log-sink-debug.h create mode 100644 src/main/core/log-sink-file.c create mode 100644 src/main/core/log-sink-file.h create mode 100644 src/main/core/log-sink-list.c create mode 100644 src/main/core/log-sink-list.h create mode 100644 src/main/core/log-sink-mutex.c create mode 100644 src/main/core/log-sink-mutex.h create mode 100644 src/main/core/log-sink-null.c create mode 100644 src/main/core/log-sink-null.h create mode 100644 src/main/core/log-sink-std.c create mode 100644 src/main/core/log-sink-std.h create mode 100644 src/main/core/log-sink.h create mode 100644 src/main/core/log.c create mode 100644 src/main/core/log.h create mode 100644 src/main/core/thread-crt-ext.c create mode 100644 src/main/core/thread-crt-ext.h create mode 100644 src/main/core/thread-crt.c create mode 100644 src/main/core/thread-crt.h create mode 100644 src/main/core/thread.c create mode 100644 src/main/core/thread.h diff --git a/Module.mk b/Module.mk index eda489c..36cda9e 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 diff --git a/src/main/core/Module.mk b/src/main/core/Module.mk new file mode 100644 index 0000000..bd35e6d --- /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 0000000..b1aa4f4 --- /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 0000000..dcb9a9a --- /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 0000000..fd86897 --- /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 0000000..2a8052f --- /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 0000000..f327aad --- /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 0000000..47aa49e --- /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 0000000..c1dd7a2 --- /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 0000000..4c21d50 --- /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 0000000..f2ca188 --- /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 0000000..968a1fe --- /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 0000000..38e3211 --- /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 0000000..f1e99f3 --- /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 0000000..13c8b20 --- /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 0000000..e30357e --- /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 0000000..7655a20 --- /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 0000000..ebd2bab --- /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 0000000..197fd12 --- /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 0000000..e0e006b --- /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 0000000..7fdd42f --- /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 0000000..9d2d6d7 --- /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 0000000..5b5cd9d --- /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 0000000..eb403ad --- /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 0000000..a17b29b --- /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 0000000..0251cf1 --- /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 0000000..e9c1e8c --- /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 0000000..f4e5bfe --- /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 0000000..8811566 --- /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 From dedbdaf7299580dfe1c400ba8b272e0365615900 Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 11:15:17 +0100 Subject: [PATCH 06/18] feat: Add helper to set avs implementations Doesn't really reduce boiler plate but adds clarity with a more meaningful function name what the operation does. --- src/main/avs-util/Module.mk | 1 + src/main/avs-util/core-interop.c | 16 ++++++++++++++++ src/main/avs-util/core-interop.h | 7 +++++++ 3 files changed, 24 insertions(+) create mode 100644 src/main/avs-util/core-interop.c create mode 100644 src/main/avs-util/core-interop.h diff --git a/src/main/avs-util/Module.mk b/src/main/avs-util/Module.mk index 8db0691..2e59f57 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 0000000..555930f --- /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 0000000..51b1e11 --- /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 From 33372f3ef2aa270e6f85474c0ec534443b8eed66 Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 11:15:17 +0100 Subject: [PATCH 07/18] feat(avs-util): Add helper to translate property errors --- src/main/avs-util/error.c | 10 ++++++++++ src/main/avs-util/error.h | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/avs-util/error.c b/src/main/avs-util/error.c index ab09c01..d31b2e1 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 3598851..88d68c5 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 From bc9b8b508e85ff719affea27a91d4020aa19fe98 Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 13:29:52 +0100 Subject: [PATCH 08/18] refactor(api): Thread and log API Split files and add name spacing. --- src/api/log.h | 31 +++++++++++++++++++++++++++++++ src/api/thread.h | 20 ++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/api/log.h create mode 100644 src/api/thread.h diff --git a/src/api/log.h b/src/api/log.h new file mode 100644 index 0000000..638a269 --- /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 0000000..0459c9d --- /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 From 0adec478cc978b7acdacd1e7f5f784dabb8fa838 Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 13:29:52 +0100 Subject: [PATCH 09/18] refactor: Entire code base, thread and log usage Boils down to: - Include headers - Reduce boiler plate with helpers - Swap out explicit usages with core API layer and ensure the right API is configured beforehand --- src/main/aciodrv-proc/Module.mk | 1 + src/main/aciodrv-proc/panb.c | 11 +++--- src/main/aciodrv/device.c | 3 +- src/main/aciodrv/h44b.c | 2 +- src/main/aciodrv/icca.c | 2 +- src/main/aciodrv/kfca.c | 2 +- src/main/aciodrv/panb.c | 3 +- src/main/aciodrv/port.c | 2 +- src/main/aciodrv/rvol.c | 2 +- src/main/acioemu/addr.c | 2 +- src/main/acioemu/emu.c | 3 +- src/main/acioemu/hdxs.c | 2 +- src/main/acioemu/pipe.h | 3 +- src/main/aciomgr/Module.mk | 1 + src/main/aciomgr/manager.c | 7 ++-- src/main/aciotest/Module.mk | 1 + src/main/aciotest/main.c | 14 ++++++- src/main/asio/asio-reghook.c | 7 ++-- src/main/asio/config-asio.c | 4 +- src/main/bio2drv/Module.mk | 5 ++- src/main/bio2drv/bi2a-iidx.c | 2 +- src/main/bio2drv/bi2a-sdvx.c | 2 +- src/main/bio2drv/config-bio2.c | 4 +- src/main/bio2drv/detect.c | 6 +-- src/main/bio2emu/emu.c | 3 +- src/main/bio2emu/setupapi.c | 3 +- src/main/bsthook/Module.mk | 2 + src/main/bsthook/acio.c | 3 +- src/main/bsthook/dllmain.c | 27 ++++++++----- src/main/bsthook/gfx.c | 3 +- src/main/bsthook/settings.c | 3 +- src/main/camhook/cam.c | 7 ++-- src/main/camhook/config-cam.c | 4 +- src/main/cconfig/cconfig-main.c | 7 ++-- src/main/cconfig/cconfig-util.c | 7 ++-- src/main/cconfig/cconfig-util.h | 4 +- src/main/cconfig/cconfig.c | 3 +- src/main/cconfig/cmd.c | 3 +- src/main/cconfig/conf.c | 3 +- src/main/config/Module.mk | 1 + src/main/config/analogs.c | 3 +- src/main/config/buttons.c | 3 +- src/main/config/eam.c | 3 +- src/main/config/gametype.c | 3 +- src/main/config/main.c | 40 +++++++++++++++----- src/main/config/snap.c | 3 +- src/main/config/usages.c | 3 +- src/main/d3d9exhook/config-gfx.c | 4 +- src/main/d3d9exhook/d3d9ex.c | 3 +- src/main/ddrhook-util/_com4.c | 3 +- src/main/ddrhook-util/dinput.c | 3 +- src/main/ddrhook-util/extio.c | 3 +- src/main/ddrhook-util/gfx.c | 3 +- src/main/ddrhook-util/misc.c | 3 +- src/main/ddrhook-util/monitor.c | 3 +- src/main/ddrhook-util/p3io.c | 4 +- src/main/ddrhook-util/spike.c | 3 +- src/main/ddrhook-util/usbmem.c | 3 +- src/main/ddrhook1/Module.mk | 2 + src/main/ddrhook1/avs-boot.c | 11 +++++- src/main/ddrhook1/config-ddrhook1.c | 4 +- src/main/ddrhook1/config-eamuse.c | 3 +- src/main/ddrhook1/config-gfx.c | 4 +- src/main/ddrhook1/config-security.c | 3 +- src/main/ddrhook1/dllmain.c | 42 +++++++++++++++++---- src/main/ddrhook1/filesystem.c | 3 +- src/main/ddrhook1/master.c | 3 +- src/main/ddrhook2/Module.mk | 2 + src/main/ddrhook2/dllmain.c | 28 +++++++++----- src/main/ddrhook2/master.c | 3 +- src/main/ddrio-async/Module.mk | 1 + src/main/ddrio-async/ddrio.c | 9 +++-- src/main/ddrio-mm/Module.mk | 1 + src/main/ddrio-mm/ddrio.c | 5 ++- src/main/ddrio-p3io/Module.mk | 1 + src/main/ddrio-p3io/config.c | 2 +- src/main/ddrio-p3io/ddrio.c | 8 ++-- src/main/ddrio-smx/Module.mk | 1 + src/main/ddrio-smx/ddrio.c | 5 ++- src/main/ddrio/ddrio.c | 2 +- src/main/ddriotest/Module.mk | 1 + src/main/ddriotest/main.c | 33 ++++++++++------ src/main/dinput/dinput.c | 3 +- src/main/eamio-icca/Module.mk | 1 + src/main/eamio-icca/config-icc.c | 2 - src/main/eamio-icca/eamio-icca.c | 6 +-- src/main/eamio/Module.mk | 2 +- src/main/eamio/eam-api.c | 9 +++-- src/main/eamio/eam-impl.c | 3 +- src/main/eamiotest/Module.mk | 1 + src/main/eamiotest/main.c | 21 ++++++++--- src/main/extiodrv/device.c | 2 +- src/main/extiodrv/extio.c | 2 +- src/main/extiotest/Module.mk | 1 + src/main/extiotest/main.c | 12 ++++-- src/main/ezusb-emu/device.c | 3 +- src/main/ezusb-emu/node-coin.c | 4 +- src/main/ezusb-emu/node-eeprom.c | 4 +- src/main/ezusb-emu/node-security-mem.c | 4 +- src/main/ezusb-emu/node-security-plug.c | 4 +- src/main/ezusb-emu/node-sram.c | 3 +- src/main/ezusb-emu/node-wdt.c | 4 +- src/main/ezusb-emu/util.c | 3 +- src/main/ezusb-iidx-16seg-emu/node-16seg.c | 4 +- src/main/ezusb-iidx-emu/Module.mk | 1 + src/main/ezusb-iidx-emu/card-mag.c | 3 +- src/main/ezusb-iidx-emu/msg.c | 3 +- src/main/ezusb-iidx-emu/node-fpga.c | 3 +- src/main/ezusb-iidx-emu/node-serial.c | 7 ++-- src/main/ezusb-iidx-fpga-flash/Module.mk | 1 + src/main/ezusb-iidx-fpga-flash/main.c | 8 +++- src/main/ezusb-iidx-sram-flash/Module.mk | 1 + src/main/ezusb-iidx-sram-flash/main.c | 8 +++- src/main/ezusb-iidx/ezusb-iidx.c | 3 +- src/main/ezusb-iidx/fpga.c | 2 +- src/main/ezusb-iidx/sram.c | 4 +- src/main/ezusb-tool/Module.mk | 1 + src/main/ezusb-tool/main.c | 9 +++-- src/main/ezusb/ezusb.c | 3 +- src/main/ezusb/util.c | 3 +- src/main/ezusb2-dbg-hook/Module.mk | 1 + src/main/ezusb2-dbg-hook/main.c | 11 ++++-- src/main/ezusb2-emu/device.c | 3 +- src/main/ezusb2-emu/util.c | 3 +- src/main/ezusb2-iidx-emu/msg.c | 3 +- src/main/ezusb2-popn-emu/msg.c | 3 +- src/main/ezusb2-popn-shim/Module.mk | 1 + src/main/ezusb2-popn-shim/dllmain.c | 4 +- src/main/ezusb2-popn-shim/proxy.c | 2 +- src/main/ezusb2-tool/Module.mk | 1 + src/main/ezusb2-tool/main.c | 9 +++-- src/main/ezusb2/ezusb2.c | 3 +- src/main/geninput/Module.mk | 1 + src/main/geninput/dev-list.c | 3 +- src/main/geninput/hid-generic.c | 3 +- src/main/geninput/hid-meta-in.c | 3 +- src/main/geninput/hid-meta-out.c | 3 +- src/main/geninput/hid-mgr.c | 3 +- src/main/geninput/hid-report-in.c | 3 +- src/main/geninput/hid-report-out.c | 3 +- src/main/geninput/hid.c | 3 +- src/main/geninput/hotplug.c | 4 +- src/main/geninput/input.c | 9 +++-- src/main/geninput/io-thread.c | 11 +++--- src/main/geninput/kbd.c | 3 +- src/main/geninput/mapper.c | 3 +- src/main/geninput/mouse.c | 3 +- src/main/geninput/msg-thread.c | 3 +- src/main/geninput/pacdrive.c | 3 +- src/main/geninput/ri.c | 3 +- src/main/hook/d3d9.c | 8 ++-- src/main/hook/table.c | 5 ++- src/main/hooklib/acp.c | 3 +- src/main/hooklib/adapter.c | 3 +- src/main/hooklib/app.c | 3 +- src/main/hooklib/config-adapter.c | 4 +- src/main/hooklib/memfile.c | 3 +- src/main/hooklib/rs232.c | 3 +- src/main/hooklib/setupapi.c | 3 +- src/main/iidx-bio2-exit-hook/Module.mk | 1 + src/main/iidx-bio2-exit-hook/main.c | 8 +++- src/main/iidx-ezusb-exit-hook/Module.mk | 1 + src/main/iidx-ezusb2-exit-hook/Module.mk | 1 + src/main/iidx-irbeat-patch/Module.mk | 1 + src/main/iidxhook-d3d9/bb-scale-hd.c | 4 +- src/main/iidxhook-d3d9/util.h | 4 +- src/main/iidxhook-util/Module.mk | 1 + src/main/iidxhook-util/acio.c | 3 +- src/main/iidxhook-util/chart-patch.c | 3 +- src/main/iidxhook-util/clock.c | 3 +- src/main/iidxhook-util/config-eamuse.c | 4 +- src/main/iidxhook-util/config-ezusb.c | 3 +- src/main/iidxhook-util/config-gfx.c | 4 +- src/main/iidxhook-util/config-io.c | 4 +- src/main/iidxhook-util/config-misc.c | 4 +- src/main/iidxhook-util/config-sec.c | 3 +- src/main/iidxhook-util/d3d9.c | 3 +- src/main/iidxhook-util/eamuse.c | 3 +- src/main/iidxhook-util/effector.c | 3 +- src/main/iidxhook-util/log-server.c | 7 ++-- src/main/iidxhook-util/settings.c | 3 +- src/main/iidxhook1/Module.mk | 1 + src/main/iidxhook1/config-iidxhook1.c | 4 +- src/main/iidxhook1/dllmain.c | 38 ++++++++++++++----- src/main/iidxhook1/ezusb-mon.c | 3 +- src/main/iidxhook1/log-ezusb.c | 3 +- src/main/iidxhook2/Module.mk | 1 + src/main/iidxhook2/config-iidxhook2.c | 4 +- src/main/iidxhook2/dllmain.c | 39 ++++++++++++++----- src/main/iidxhook3/Module.mk | 1 + src/main/iidxhook3/dllmain.c | 38 ++++++++++++++----- src/main/iidxhook4-cn/Module.mk | 2 + src/main/iidxhook4-cn/avs-boot.c | 12 ++++-- src/main/iidxhook4-cn/dllmain.c | 32 +++++++++++++--- src/main/iidxhook4-cn/path.c | 3 +- src/main/iidxhook4/Module.mk | 2 + src/main/iidxhook4/dllmain.c | 26 ++++++++----- src/main/iidxhook5-cn/Module.mk | 2 + src/main/iidxhook5-cn/avs-boot.c | 12 ++++-- src/main/iidxhook5-cn/dllmain.c | 31 ++++++++++++--- src/main/iidxhook5-cn/path.c | 3 +- src/main/iidxhook5/Module.mk | 2 + src/main/iidxhook5/dllmain.c | 26 ++++++++----- src/main/iidxhook5/ifs-snd-redir.c | 3 +- src/main/iidxhook6/Module.mk | 2 + src/main/iidxhook6/dllmain.c | 26 ++++++++----- src/main/iidxhook7/Module.mk | 2 + src/main/iidxhook7/dllmain.c | 26 ++++++++----- src/main/iidxhook8/Module.mk | 2 + src/main/iidxhook8/config-io.c | 4 +- src/main/iidxhook8/dllmain.c | 26 ++++++++----- src/main/iidxhook9/Module.mk | 2 + src/main/iidxhook9/config-io.c | 4 +- src/main/iidxhook9/dllmain.c | 32 ++++++++++------ src/main/iidxio-bio2/Module.mk | 1 + src/main/iidxio-ezusb/Module.mk | 1 + src/main/iidxio-ezusb2/Module.mk | 1 + src/main/iidxiotest/Module.mk | 1 + src/main/iidxiotest/main.c | 21 ++++++++--- src/main/jbhook-util-p3io/gfx.c | 3 +- src/main/jbhook-util-p3io/mixer.c | 3 +- src/main/jbhook-util-p3io/p3io.c | 4 +- src/main/jbhook-util/acio.c | 3 +- src/main/jbhook-util/eamuse.c | 3 +- src/main/jbhook-util/locale.c | 3 +- src/main/jbhook-util/p4io.c | 4 +- src/main/jbhook1/Module.mk | 1 + src/main/jbhook1/avs-boot.c | 12 ++++-- src/main/jbhook1/config-eamuse.c | 3 +- src/main/jbhook1/config-gfx.c | 4 +- src/main/jbhook1/config-security.c | 3 +- src/main/jbhook1/dllmain.c | 41 +++++++++++++++----- src/main/jbhook1/log-gftools.c | 4 +- src/main/jbhook2/Module.mk | 2 + src/main/jbhook2/dllmain.c | 30 +++++++++------ src/main/jbhook2/options.c | 2 +- src/main/jbhook3/Module.mk | 2 + src/main/jbhook3/dllmain.c | 30 +++++++++------ src/main/jbhook3/gfx.c | 4 +- src/main/jbhook3/options.c | 3 +- src/main/jbio-p4io/Module.mk | 1 + src/main/jbio-p4io/config-h44b.c | 4 +- src/main/jbio-p4io/h44b.c | 2 +- src/main/jbio-p4io/jbio.c | 8 ++-- src/main/jbiotest/Module.mk | 1 + src/main/jbiotest/main.c | 21 ++++++++--- src/main/mempatch-hook/Module.mk | 1 + src/main/mempatch-hook/main.c | 14 ++++--- src/main/mm/mm.c | 3 +- src/main/p3io-ddr-tool/Module.mk | 1 + src/main/p3io-ddr-tool/main.c | 21 ++++++----- src/main/p3io-ddr-tool/mode-test.c | 4 +- src/main/p3io/cmd.c | 4 +- src/main/p3io/frame.c | 3 +- src/main/p3iodrv/ddr.c | 2 +- src/main/p3iodrv/device.c | 3 +- src/main/p3ioemu/devmgr.c | 3 +- src/main/p3ioemu/emu.c | 3 +- src/main/p3ioemu/uart.c | 3 +- src/main/p4iodrv/device.c | 3 +- src/main/p4iodrv/usb.c | 3 +- src/main/p4ioemu/device.c | 3 +- src/main/pcbidgen/Module.mk | 1 + src/main/popnhook-util/acio.c | 3 +- src/main/popnhook-util/mixer.c | 3 +- src/main/popnhook1/Module.mk | 1 + src/main/popnhook1/avs-boot.c | 4 +- src/main/popnhook1/config-eamuse.c | 4 +- src/main/popnhook1/config-gfx.c | 4 +- src/main/popnhook1/config-sec.c | 3 +- src/main/popnhook1/d3d9.c | 3 +- src/main/popnhook1/dllmain.c | 38 ++++++++++++++----- src/main/popnhook1/filesystem.c | 3 +- src/main/sdvxhook/Module.mk | 2 + src/main/sdvxhook/acio.c | 3 +- src/main/sdvxhook/dllmain.c | 27 ++++++++----- src/main/sdvxhook/gfx.c | 3 +- src/main/sdvxhook/kfca.c | 3 +- src/main/sdvxhook/lcd.c | 3 +- src/main/sdvxhook2-cn/Module.mk | 2 + src/main/sdvxhook2-cn/acio.c | 3 +- src/main/sdvxhook2-cn/config-cn.c | 4 +- src/main/sdvxhook2-cn/dllmain.c | 19 ++++++---- src/main/sdvxhook2-cn/kfca.c | 3 +- src/main/sdvxhook2-cn/unis-version.c | 3 +- src/main/sdvxhook2/Module.mk | 2 + src/main/sdvxhook2/acio.c | 3 +- src/main/sdvxhook2/config-io.c | 4 +- src/main/sdvxhook2/dllmain.c | 26 ++++++++----- src/main/sdvxhook2/nvapi.c | 4 +- src/main/sdvxhook2/power.c | 4 +- src/main/sdvxio-bio2/Module.mk | 1 + src/main/sdvxio-kfca/Module.mk | 1 + src/main/sdvxio-kfca/config-kfca.c | 4 +- src/main/security/id.c | 3 +- src/main/security/mcode.c | 3 +- src/main/security/rp-blowfish.c | 4 +- src/main/security/rp.c | 3 +- src/main/security/rp2.c | 3 +- src/main/security/rp3.c | 3 +- src/main/unicorntail/Module.mk | 1 + src/main/unicorntail/dllmain.c | 5 ++- src/main/unicorntail/p3io.c | 3 +- src/main/unicorntail/usbmem.c | 3 +- src/main/util/array.c | 3 +- src/main/util/crc.c | 2 +- src/main/util/crypto.c | 9 +++-- src/main/util/fs.c | 3 +- src/main/util/hex.c | 3 +- src/main/util/iobuf.c | 5 ++- src/main/util/mem.c | 2 +- src/main/util/msg-thread.c | 11 +++--- src/main/util/net.c | 3 +- src/main/util/os.c | 3 +- src/main/util/proc.c | 2 +- src/main/util/signal.c | 3 +- src/main/util/time.c | 3 +- src/main/vigem-ddrio/Module.mk | 1 + src/main/vigem-ddrio/config-vigem-ddrio.c | 4 +- src/main/vigem-ddrio/main.c | 26 ++++++++++--- src/main/vigem-iidxio/Module.mk | 1 + src/main/vigem-iidxio/cab-16seg-sequencer.c | 3 +- src/main/vigem-iidxio/cab-light-sequencer.c | 3 +- src/main/vigem-iidxio/config.c | 4 +- src/main/vigem-iidxio/main.c | 22 ++++++++--- src/main/vigem-sdvxio/Module.mk | 1 + src/main/vigem-sdvxio/config-vigem-sdvxio.c | 4 +- src/main/vigem-sdvxio/main.c | 23 ++++++++--- src/main/vigemstub/helper.c | 3 +- src/test/cconfig/Module.mk | 3 ++ src/test/d3d9hook/Module.mk | 2 + src/test/d3d9hook/dllmain.c | 10 +++-- src/test/iidxhook-util/Module.mk | 4 ++ src/test/iidxhook/Module.mk | 2 + src/test/iidxhook8/Module.mk | 2 + src/test/security/Module.mk | 6 +++ src/test/test/test.h | 15 +++++--- src/test/util/Module.mk | 1 + 338 files changed, 1307 insertions(+), 640 deletions(-) diff --git a/src/main/aciodrv-proc/Module.mk b/src/main/aciodrv-proc/Module.mk index e347f77..9fa6b38 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 c054e21..3f9d5a4 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 39bf8af..7584968 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 afbab42..19283f6 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 ac56d0e..7bec0c7 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 e21a0b8..88093e4 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 1412e16..2dbc85e 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 b38ad2a..c3c9c71 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 a9e0c36..ed7c036 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 8d85487..3f52fbb 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 11cf35a..57f74e0 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 9a38bee..01ec19d 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 ad442fc..859c3b6 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 0a17e8c..b87f81b 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 e73b18e..d7f0378 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 af04652..efeb038 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 4a301c4..fdf6df4 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 161b13b..7e05890 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 b29f99c..2a8675d 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/bio2drv/Module.mk b/src/main/bio2drv/Module.mk index f5bdb56..9e5e92b 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 1119876..bce8c41 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 93edf49..14e5239 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 492cdef..c016fa9 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 d559175..dfdf501 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 9fbcb3d..ea9c7f0 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 5dbfffc..bb2f32c 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 ef61d28..92ab3b1 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 fe5f8cc..500d4c5 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 57d38e0..e508057 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 43d88a2..23d37e0 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 8f48ea8..c9fb10a 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 4ce9260..169fd02 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 6a55852..c6dd1af 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 342a912..342d8df 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 f4ce05f..3585357 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 aa9b500..8f6a305 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 1cfcbed..6150f66 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 3d4f32f..3bb1c24 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 de21f8b..b23e9d4 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 2f7bac8..fc37a23 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 5a7bcee..d693667 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 f4a498b..e083bf3 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 e9bb76c..1d66518 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 e7e7353..2ec0ea4 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 ba51555..8be1370 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); + core_log_impl_assign(input_set_loggers); + input_init( + core_thread_create_impl_get(), + core_thread_join_impl_get(), + core_thread_destroy_impl_get()); - 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(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 8981c68..6d8547a 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 5e28ad9..771772c 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/d3d9exhook/config-gfx.c b/src/main/d3d9exhook/config-gfx.c index 6cf57af..b4a5197 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 88d95b0..80d958c 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 44e0178..4ca08c3 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 b0fdc66..949fb1e 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 cd2dc84..661b165 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 3f5f773..0bfd0a5 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 b74c8de..e04390d 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 0dfce07..cba18cc 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 09b8c6f..af0f1a9 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 0e383d2..37cf888 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 f85363f..c4e12c4 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 83782ae..1e9dc24 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 1b7ad41..db4445b 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 154f3ae..a5872bf 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 260791d..dbe44cd 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 09ccc0c..c71e74d 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 9489b0a..b0b7d2b 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 3dcc6c9..3cccb3a 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 @@ skip: 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 abec921..9912c4f 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 b30836a..480d56f 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 0c9fd36..e0416d6 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 9035551..cabbb94 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 89f874f..aba5451 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 62006cf..2eb806d 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 fe81f68..998c59a 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 9368a62..16e3ca8 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 08bd1d2..44bdd35 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 43e0fd0..2824bf0 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 c45254e..5459157 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 a38ce09..6ed7e90 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 cc0563b..12fd74d 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 a7cda33..334ccac 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 167b7c6..5da9934 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 569d973..b6cba5c 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 e03bc0c..40453ce 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 248ead4..e65928f 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 28c388e..bcd4be8 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 660c0ee..963f688 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 c681610..db0215a 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 f7a7409..9cf82ed 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 0320317..9d2857d 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 0c41709..6aca589 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 a54384b..0b9fd4b 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 9880af4..a2f410f 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 ba14fa7..e6bc788 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 8c50de2..5b1ae6a 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 73ec1b0..3e05ba0 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 3be152b..c9e48ba 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 9f1eca8..9cf5c98 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 87e7503..6b4aed1 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 ea6a3fe..f63d866 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 92422c8..8d11c5f 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 2b05a03..ed57eed 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 200f1ca..dc3846b 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 9185bdd..8c5c541 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 6e2798a..30edd42 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 89bc507..2121235 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 d625363..16f2c1d 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 a210fd6..b65414e 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 bcab656..76b9742 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 d66c440..6615b43 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 378ab02..7dc6519 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 c250b35..320d6f4 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 a8fb681..f8dacdd 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 b6e6a73..a369b06 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 d22464e..b4fa94d 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 e82e214..ae035b7 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 23d5fd0..b4d2550 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 f816b38..fcce384 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 349bc08..b5e8158 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 115f79c..ca84781 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 ce1b828..7204589 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 efc2cd1..5bf18a4 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 4290f5c..579e9bf 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 e90d3fb..e1c1bdb 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 f465279..ecba816 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 2abd513..d5b12b9 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 1279ea9..bfc3dce 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 6e83f7a..d696ecc 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 aefc2d4..f4536c4 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 c8e16fc..ec7e18f 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 fdf4f9f..ec47002 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 0611565..87e6dff 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 cdfd179..0579c07 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 61fabd7..2c1b7b9 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 1521d80..3115edf 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 2bfcb4e..ce6d93a 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 41e7382..46c2924 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 bbaf44f..3a32494 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 4f87602..1903785 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 f22d3a7..2f8a7c1 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 721a721..aec213d 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 5469e3a..892cd13 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 57685b0..889ee80 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 54dad42..d9954d3 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 60c94c2..e67df3d 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 ca663ff..18f5ccc 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 9ae8e5e..191890b 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 c3d0214..3c66c19 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 2b24d1c..f1c54bf 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 cc21ae0..7ca47f3 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 2a5ab36..b388036 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 b3befee..45b6d65 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 45e1fd1..0f09ec6 100644 --- a/src/main/hook/d3d9.c +++ b/src/main/hook/d3d9.c @@ -1,10 +1,10 @@ #define LOG_MODULE "hook-d3d9" -#include "hook/d3d9.h" -#include "hook/com-proxy.h" -#include "hook/table.h" +#include "core/log.h" -#include "util/log.h" +#include "hook/com-proxy.h" +#include "hook/d3d9.h" +#include "hook/table.h" /* ------------------------------------------------------------------------------------------------------------------ */ diff --git a/src/main/hook/table.c b/src/main/hook/table.c index 067ea75..285a43d 100644 --- a/src/main/hook/table.c +++ b/src/main/hook/table.c @@ -174,10 +174,11 @@ static void hook_table_revert_to_iid( sym = &syms[j]; if (hook_table_match_proc(&iate, sym)) { - // Only revert-able if the original pointer was stored previously + // 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)); - } + } } } } diff --git a/src/main/hooklib/acp.c b/src/main/hooklib/acp.c index 52675b2..81faa73 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 0b94c12..8b3b6d9 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 7ccd441..11fb824 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 49c2450..0ddb680 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 08dbeba..09c0587 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 8d6d371..591c98f 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 07dc72c..5363c52 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 dcf7289..085af3a 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 13ac825..2718717 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 4050ebe..500bd15 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 7828a97..f449f38 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 df42cd3..d01645f 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 60dae6b..84afe7c 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 3a77e99..96b489e 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 92fe44d..50dd18d 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 6291336..a52fa76 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 4b2970e..b6cc290 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 8c870ff..dc0e2f2 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 f59b03e..c75bd1a 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 e860a1d..14d953d 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 e591f48..1be281f 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 3055ac6..13c59f3 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 7a18499..fca5ea5 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 54cb0ee..a2e9a57 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 9c87719..eeb5081 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 15d77da..6a127bd 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 4f30e27..f313c60 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 1a7f687..5a2fe3d 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 b4f2ce3..5402f69 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 fcfad98..61bb5ff 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 5a02c95..b88d471 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 a3a4a35..60c61a7 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 @@ skip: 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 b76418a..11f10f9 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 ac71907..28a9c6a 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 c9fd438..4612442 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 6e3ac6b..0db10f3 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 25a76ed..de8a916 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 @@ skip: 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 e328bec..6ab9a30 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 b2e0e41..4927fc3 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 @@ skip: 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 0f7bcee..8cc34cb 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 378d80c..4c498c9 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 ea2f42a..9fa61ba 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 4ab6c5a..5d4ef1d 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 40f40b0..6546ac1 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 d7993dd..c52336f 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 feea3d4..5addce9 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 772832a..eaa1f45 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 711c906..1d327dc 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 d45bf22..bb4f81d 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 78ea307..28cb7fe 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 268bf39..0912c38 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 e73dd5c..639d16f 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 7fda87b..fe7e955 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 b4ca65a..4b614a4 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 a40366a..b1b6d93 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 af948f6..0823e85 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 e71c8c2..faebbbb 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 8cbb9b2..9f61e13 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 13509be..bf1f55d 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 30384f1..2328fdc 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 ba7ff45..34deebf 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 b7ae85a..ad9572d 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 09632c2..e91d76a 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 ce9982c..cc64914 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 f1f1963..3371a78 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 ce0536c..94eca38 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 ddd57cf..a9b7daa 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 63607fd..0574b1f 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 30dcace..ba52a63 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 25b3364..dd04607 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 a1f5492..8a1ed02 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 0a79625..c9d1d90 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 272bbc6..a6b6d17 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 ab77d5d..824ab80 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 b5e4777..c434f21 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 dccba69..62d6773 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 dba512e..77170e2 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 5215659..10102fa 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 565081e..d6c56b0 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 42f8dc9..f058d0f 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 9772173..f0dbf85 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 2573867..7ecebdb 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 a8523ad..4c06e4d 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 9e1987e..63ee6d4 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 a82c4cc..ca36a43 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 b4eada8..30a0eb3 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 ee3b5ff..827ac55 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 59ffc1e..8bb544b 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 b31604d..ca9895e 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 91d37cb..98a5f4f 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 1d9b77a..f26aa2a 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 202187f..58f4db9 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 f2cf618..eba9c0b 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 416b325..0a6270b 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 9785efa..1dedd43 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 43c1dcd..856b962 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 db543a6..2c89957 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 2c76b42..f6e3a16 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 939e1e7..4a9bac3 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 791e6d2..0c3f5a9 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 78c8b02..b62958f 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 bc50dd4..1fc6d2c 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 2cc4526..57ebfab 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 dbbb04a..afa2c51 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 fc729b3..ac26233 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 6486d59..7fc2123 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 a4a9f73..cbceb5a 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 67dd56e..da65f7b 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 8c99fc4..243adae 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 e18e891..4e7498f 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 852a4d0..612510f 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 60d66b8..465bdcd 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 91d3c75..904a008 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 c2c1510..f744773 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 f9833a7..aae4616 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 98e406b..14864ba 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 8e231d1..8bc6b10 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 f155520..99342b2 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 1d67262..44f9e1c 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 5995e22..36c232f 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 3d7fd09..d558486 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 c1a8c5b..cc6d31c 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 6596ee4..e8d7dfd 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 391f4c9..50e2063 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 16cf733..2d36759 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 5c89686..82ac111 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 06ea1e6..6d942bb 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 fd00fc6..2bb715e 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 f7116e2..4507333 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 c492603..650b528 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 3a20217..07d2de0 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 f4d8894..02c7297 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 d660999..3ed7e38 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 aa38c66..f813557 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 6ac0cdc..8db25df 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 6d87bc0..421f3af 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 e601e3a..3c74ab4 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 fbe14d8..e5f244a 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 f860c1b..e6d0d33 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 bf16a3b..04ea0fd 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 cb10b22..5127c16 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 91814e6..6b95e24 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 b591fb2..93699aa 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 5bc93fa..8817647 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 9aeb696..f45a0a9 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 ba82864..5e80670 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 51480a6..92b3acb 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 a6dd5bf..6e83f68 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 bd6d360..d2d96be 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 59f862d..b195edf 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 fd0a85c..b4a49b1 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 50b496e..ef82069 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 900fba1..9421fff 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 c49af45..7ab06b8 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 110dd99..db1702e 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 731fdf9..8c4c7c6 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 1ac6b4d..de08286 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 45884ea..7638cb5 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 53e84ff..f03ebaf 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 6b5623d..04d498d 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 492e3ef..d2c9d7d 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 c63de00..e6aad5d 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 8473113..f1905d3 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 4c15acd..9851c92 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 0412b29..feb2904 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 8aae8a2..82e0f51 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 59e8251..0ff44f2 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 62cc7b1..7d7fafa 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 887a70f..4fae200 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 01ea12b..f7e6e05 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 95214f9..6b345b7 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 40eeae5..acf5235 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 3527545..51b0b14 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 6907fbf..523dd69 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 768a514..faae9e2 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 cf4b4e2..c87a436 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 4aeb519..a92510b 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 a61e8d9..8143389 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 585139c..3ab336b 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 88060bb..e7052df 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 be4883e..49fdda9 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 8c08642..9172fa5 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 57731d5..3cccd42 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 3bdef67..7ac51d7 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 91fb01b..7d0dda0 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 ca13ecc..90f3424 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 \ From 7e49fad175ed847a82619f08947721736f671734 Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 17:09:15 +0100 Subject: [PATCH 10/18] chore: Delete old log and thread modules in util The log API stopped scaling already a while ago and needs considerable refactoring to consider the various use-cases that emerged since it was first created on alpha versions of bemanitools. --- src/main/util/Module.mk | 2 - src/main/util/log.c | 134 ---------------------------------------- src/main/util/log.h | 90 --------------------------- src/main/util/thread.c | 92 --------------------------- src/main/util/thread.h | 20 ------ 5 files changed, 338 deletions(-) delete mode 100644 src/main/util/log.c delete mode 100644 src/main/util/log.h delete mode 100644 src/main/util/thread.c delete mode 100644 src/main/util/thread.h diff --git a/src/main/util/Module.mk b/src/main/util/Module.mk index ab8d495..e6dc7c4 100644 --- a/src/main/util/Module.mk +++ b/src/main/util/Module.mk @@ -9,7 +9,6 @@ src_util := \ hex.c \ iobuf.c \ list.c \ - log.c \ math.c \ mem.c \ msg-thread.c \ @@ -18,7 +17,6 @@ src_util := \ proc.c \ signal.c \ str.c \ - thread.c \ time.c \ winres.c \ diff --git a/src/main/util/log.c b/src/main/util/log.c deleted file mode 100644 index 7da1d63..0000000 --- a/src/main/util/log.c +++ /dev/null @@ -1,134 +0,0 @@ -#include "util/log.h" -#include "util/str.h" - -#include - -#include -#include -#include -#include - -static log_writer_t log_writer; -static void *log_writer_ctx; -static enum log_level log_level; - -static void log_builtin_fatal(const char *module, const char *fmt, ...); -static void log_builtin_info(const char *module, const char *fmt, ...); -static void log_builtin_misc(const char *module, const char *fmt, ...); -static void log_builtin_warning(const char *module, const char *fmt, ...); -static void log_builtin_format( - enum log_level msg_level, const char *module, const char *fmt, va_list ap); - -#define IMPLEMENT_SINK(name, msg_level) \ - static void name(const char *module, const char *fmt, ...) \ - { \ - va_list ap; \ - \ - va_start(ap, fmt); \ - log_builtin_format(msg_level, module, fmt, ap); \ - va_end(ap); \ - } - -IMPLEMENT_SINK(log_builtin_info, LOG_LEVEL_INFO) -IMPLEMENT_SINK(log_builtin_misc, LOG_LEVEL_MISC) -IMPLEMENT_SINK(log_builtin_warning, LOG_LEVEL_WARNING) - -static void log_builtin_fatal(const char *module, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - log_builtin_format(LOG_LEVEL_FATAL, module, fmt, ap); - va_end(ap); - - DebugBreak(); - ExitProcess(EXIT_FAILURE); -} - -static void log_builtin_format( - enum log_level msg_level, const char *module, const char *fmt, va_list ap) -{ - static const char chars[] = "FWIM"; - - /* 64k so we can log data dumps of rs232 without crashing */ - char line[65536]; - char msg[65536]; - int result; - - if (msg_level <= log_level) { - str_vformat(msg, sizeof(msg), fmt, ap); - result = str_format( - line, sizeof(line), "%c:%s: %s\n", chars[msg_level], module, msg); - - log_writer(log_writer_ctx, line, result); - } -} - -void log_assert_body(const char *file, int line, const char *function) -{ - log_impl_fatal("assert", "%s:%d: function `%s'", file, line, function); -} - -void log_to_external( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) -{ - log_impl_misc = misc; - log_impl_info = info; - log_impl_warning = warning; - log_impl_fatal = fatal; -} - -void log_to_writer(log_writer_t writer, void *ctx) -{ - log_impl_misc = log_builtin_misc; - log_impl_info = log_builtin_info; - log_impl_warning = log_builtin_warning; - log_impl_fatal = log_builtin_fatal; - - if (writer != NULL) { - log_writer = writer; - log_writer_ctx = ctx; - } else { - log_writer = log_writer_null; - } -} - -void log_set_level(enum log_level new_level) -{ - log_level = new_level; -} - -void log_writer_debug(void *ctx, const char *chars, size_t nchars) -{ - OutputDebugStringA(chars); -} - -void log_writer_stdout(void *ctx, const char *chars, size_t nchars) -{ - printf("%s", chars); -} - -void log_writer_stderr(void *ctx, const char *chars, size_t nchars) -{ - fprintf(stderr, "%s", chars); -} - -void log_writer_file(void *ctx, const char *chars, size_t nchars) -{ - fwrite(chars, 1, nchars, (FILE *) ctx); - fflush((FILE *) ctx); -} - -void log_writer_null(void *ctx, const char *chars, size_t nchars) -{ -} - -log_formatter_t log_impl_misc = log_builtin_misc; -log_formatter_t log_impl_info = log_builtin_info; -log_formatter_t log_impl_warning = log_builtin_warning; -log_formatter_t log_impl_fatal = log_builtin_fatal; -static log_writer_t log_writer = log_writer_null; -static enum log_level log_level = LOG_LEVEL_MISC; diff --git a/src/main/util/log.h b/src/main/util/log.h deleted file mode 100644 index 47603fa..0000000 --- a/src/main/util/log.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef UTIL_LOG_H -#define UTIL_LOG_H - -#include -#include - -#include "bemanitools/glue.h" - -#include "util/defs.h" - -/* Dynamically retargetable logging system modeled on (and potentially - integrateable with) the one found in AVS2 */ - -/* BUILD_MODULE is passed in as a command-line #define by the makefile */ - -#ifndef LOG_MODULE -#define LOG_MODULE STRINGIFY(BUILD_MODULE) -#endif - -#ifndef LOG_SUPPRESS - -#define log_misc(...) log_impl_misc(LOG_MODULE, __VA_ARGS__) -#define log_info(...) log_impl_info(LOG_MODULE, __VA_ARGS__) -#define log_warning(...) log_impl_warning(LOG_MODULE, __VA_ARGS__) - -/* This doesn't really belong here, but it's what libavs does so w/e */ - -#define log_assert(x) \ - do { \ - if (!(x)) { \ - log_assert_body(__FILE__, __LINE__, __FUNCTION__); \ - } \ - } while (0) - -#else - -#define log_misc(...) -#define log_info(...) -#define log_warning(...) -#define log_assert(x) \ - do { \ - if (!(x)) { \ - abort(); \ - } \ - } while (0) - -#endif - -#define log_fatal(...) \ - do { \ - log_impl_fatal(LOG_MODULE, __VA_ARGS__); \ - abort(); \ - } while (0) - -typedef void (*log_writer_t)(void *ctx, const char *chars, size_t nchars); - -extern log_formatter_t log_impl_misc; -extern log_formatter_t log_impl_info; -extern log_formatter_t log_impl_warning; -extern log_formatter_t log_impl_fatal; - -enum log_level { - LOG_LEVEL_FATAL = 0, - LOG_LEVEL_WARNING = 1, - LOG_LEVEL_INFO = 2, - LOG_LEVEL_MISC = 3, -}; - -void log_assert_body(const char *file, int line, const char *function); -void log_to_external( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal); -void log_to_writer(log_writer_t writer, void *ctx); - -void log_set_level(enum log_level new_level); - -/* I tried to make this API match the function signature of the AVS log writer - callback, but then the signature changed and the explicit line breaks - being passed to that callback went away. So we don't try to track that API - any more. Launcher defines its own custom writer anyway. */ - -void log_writer_debug(void *ctx, const char *chars, size_t nchars); -void log_writer_stdout(void *ctx, const char *chars, size_t nchars); -void log_writer_stderr(void *ctx, const char *chars, size_t nchars); -void log_writer_file(void *ctx, const char *chars, size_t nchars); -void log_writer_null(void *ctx, const char *chars, size_t nchars); - -#endif diff --git a/src/main/util/thread.c b/src/main/util/thread.c deleted file mode 100644 index daa8267..0000000 --- a/src/main/util/thread.c +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include - -#include -#include - -#include "util/defs.h" -#include "util/thread.h" - -struct shim_ctx { - HANDLE barrier; - int (*proc)(void *); - void *ctx; -}; - -thread_create_t thread_impl_create = crt_thread_create; -thread_join_t thread_impl_join = crt_thread_join; -thread_destroy_t thread_impl_destroy = crt_thread_destroy; - -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 crt_thread_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 crt_thread_destroy(int thread_id) -{ - CloseHandle((HANDLE) (uintptr_t) thread_id); -} - -void crt_thread_join(int thread_id, int *result) -{ - WaitForSingleObject((HANDLE) (uintptr_t) thread_id, INFINITE); - - if (result) { - GetExitCodeThread((HANDLE) (uintptr_t) thread_id, (DWORD *) result); - } -} - -void thread_api_init( - thread_create_t create, thread_join_t join, thread_destroy_t destroy) -{ - if (create == NULL || join == NULL || destroy == NULL) { - abort(); - } - - thread_impl_create = create; - thread_impl_join = join; - thread_impl_destroy = destroy; -} - -int thread_create( - int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority) -{ - return thread_impl_create(proc, ctx, stack_sz, priority); -} - -void thread_join(int thread_id, int *result) -{ - thread_impl_join(thread_id, result); -} - -void thread_destroy(int thread_id) -{ - thread_impl_destroy(thread_id); -} diff --git a/src/main/util/thread.h b/src/main/util/thread.h deleted file mode 100644 index dca396b..0000000 --- a/src/main/util/thread.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef UTIL_THREAD_H -#define UTIL_THREAD_H - -#include - -#include "bemanitools/glue.h" - -int crt_thread_create( - int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority); -void crt_thread_join(int thread_id, int *result); -void crt_thread_destroy(int thread_id); - -void thread_api_init( - thread_create_t create, thread_join_t join, thread_destroy_t destroy); -int thread_create( - int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority); -void thread_join(int thread_id, int *result); -void thread_destroy(int thread_id); - -#endif From 08a72abb5872e4c980eeff7414cab73826c8d818 Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 17:13:51 +0100 Subject: [PATCH 11/18] refactor(inject): Use new core thread and log modules Keep this a separate commit because this also removes inject's own logging engine and replaces it with the streamlined core API. The core API provides all the features of inject's own logging engine which also performed horribly. The entire logging operation was locked which included expensive operations that formatted the log messages and required memory allocations and copying around data. The core API's implementation at least only synchronizes the actual IO operations (though this can be improved further with an actual async logging sink, TBD) --- src/main/inject/Module.mk | 2 +- src/main/inject/logger.c | 217 -------------------------------------- src/main/inject/logger.h | 28 ----- 3 files changed, 1 insertion(+), 246 deletions(-) delete mode 100644 src/main/inject/logger.c delete mode 100644 src/main/inject/logger.h diff --git a/src/main/inject/Module.mk b/src/main/inject/Module.mk index 549f179..fd868ef 100644 --- a/src/main/inject/Module.mk +++ b/src/main/inject/Module.mk @@ -5,12 +5,12 @@ ldflags_inject := \ -lpsapi \ libs_inject := \ + core \ util \ src_inject := \ main.c \ debugger.c \ - logger.c \ options.c \ version.c \ diff --git a/src/main/inject/logger.c b/src/main/inject/logger.c deleted file mode 100644 index 8f63aa9..0000000 --- a/src/main/inject/logger.c +++ /dev/null @@ -1,217 +0,0 @@ -#define LOG_MODULE "inject-logger" - -#include -#include -#include -#include -#include -#include - -#include "inject/logger.h" -#include "inject/version.h" - -#include "util/log.h" - -static FILE *log_file; -static HANDLE log_mutex; - -static const char *logger_get_formatted_timestamp(void) -{ - static char buffer[64]; - time_t cur = 0; - struct tm *tm = NULL; - - cur = time(NULL); - tm = localtime(&cur); - - strftime(buffer, sizeof(buffer), "[%Y/%m/%d %H:%M:%S] ", tm); - - return buffer; -} - -static char logger_console_determine_color(const char *str) -{ - log_assert(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 logger_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 logger_console( - void *ctx, const char *chars, size_t nchars, const char *timestamp_str) -{ - char color; - size_t color_len; - // See "util/log.c", has to align - char buffer[65536]; - char tmp; - - color_len = logger_msg_coloring_len(chars); - - // 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 = logger_console_determine_color(chars); - - strcpy(buffer, chars); - - // Mask start of log message for coloring - tmp = buffer[color_len]; - buffer[color_len] = '\0'; - - printf("%s", timestamp_str); - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color); - printf("%s", buffer); - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15); - - // Write actual message non colored - buffer[color_len] = tmp; - printf("%s", buffer + color_len); - } else { - printf("%s", chars); - } -} - -static void logger_file( - void *ctx, const char *chars, size_t nchars, const char *timestamp_str) -{ - if (ctx) { - fwrite(timestamp_str, 1, strlen(timestamp_str), (FILE *) ctx); - fwrite(chars, 1, nchars, (FILE *) ctx); - fflush((FILE *) ctx); - } -} - -static void logger_writer(void *ctx, const char *chars, size_t nchars) -{ - const char *timestamp_str; - - // Different threads logging the same destination, e.g. debugger thread, - // main thread - - WaitForSingleObject(log_mutex, INFINITE); - - timestamp_str = logger_get_formatted_timestamp(); - - logger_console(ctx, chars, nchars, timestamp_str); - logger_file(ctx, chars, nchars, timestamp_str); - - ReleaseMutex(log_mutex); -} - -static void logger_log_header() -{ - log_info( - "\n" - " _ _ _ \n" - " (_)_ __ (_) ___ ___| |_ \n" - " | | '_ \\ | |/ _ \\/ __| __|\n" - " | | | | || | __/ (__| |_ \n" - " |_|_| |_|/ |\\___|\\___|\\__|\n" - " |__/ "); - - log_info( - "Inject build date %s, gitrev %s", inject_build_date, inject_gitrev); -} - -bool logger_init(const char *log_file_path) -{ - if (log_file_path) { - log_file = fopen(log_file_path, "w+"); - } else { - log_file = NULL; - } - - log_to_writer(logger_writer, log_file); - - logger_log_header(); - - if (log_file_path) { - log_info("Log file: %s", log_file_path); - - if (!log_file) { - log_warning( - "ERROR: Opening log file %s failed: %s", - log_file_path, - strerror(errno)); - return false; - } - } - - log_mutex = CreateMutex(NULL, FALSE, NULL); - - return true; -} - -void logger_log(const char *str) -{ - logger_writer(log_file, str, strlen(str)); -} - -void logger_finit() -{ - log_misc("Logger finit"); - - if (log_file) { - fclose(log_file); - } - - CloseHandle(log_mutex); -} \ No newline at end of file diff --git a/src/main/inject/logger.h b/src/main/inject/logger.h deleted file mode 100644 index 45a8b77..0000000 --- a/src/main/inject/logger.h +++ /dev/null @@ -1,28 +0,0 @@ -#include - -/** - * Initialize inject's logger backend. - * - * This takes care of hooking and merging the different log - * streams, e.g. inject's local logging and inject's debugger - * receiving remote logging events. - * - * @param log_file_path Path to the file to log to or NULL to - * disable. - */ -bool logger_init(const char *log_file_path); - -/** - * Write a message to the logging backend. - * - * This is used by inject's debugger to redirect log messages - * recevied from the remote process. - * - * @param str String to log - */ -void logger_log(const char *str); - -/** - * Shutdown and cleanup the logging backend. - */ -void logger_finit(); \ No newline at end of file From ca91e4c4aef0dcbcd1ccb23b450a386d2782d8fa Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 17:13:51 +0100 Subject: [PATCH 12/18] refactor(launcher): Major re-work of launcher Kudos to Shiz for providing the groundwork for this. Fundamentally re-think how launcher operates and bootstrapping the games is managed and configured. This brings it significantly closer to how the original bootstrap is doing the job: launcher now utilizes the data (structures) provided by the bootstrap.xml configuration file. This creates compatibility with vanilla data dumps and original stock images. Note that bemanitools does not include any code or means to run DRM'd data, only decrypted. But, this allows users to keep decrypted dumps as stock as possible which means: * No copying around of property files anymore * Keep the modules/ folder with the binaries * Have bemanitools binaries separate in the data * No need to edit/customize the original configuration files A list of key features of the "new" launcher: * Boostrap games by following the configuration provided by stock game's bootstrap.xml files * Custom launcher.xml configuration file that adds further launcher configurable features, composability of bootstrap.xml configuration(s) as well as configuration overriding/stacking of selected types of configurations, e.g. eamuse config, avs-config. The latter eliminates the need for modifying stock config files in the prop/ folder * Unified logging system: launcher and AVS logging uses the same logger, all output can now be in a single file * Original features such as various hook types still available Due to the significant architectural changes, this also breaks with any backwards compatibility to existing launcher setups. Thus, users need to migrate by re-applying the new configuration format and migrating their config parameters accordingly. Further migration instructions and updated documentation will be provided upon release. Co-authored-by: Shiz --- src/main/launcher/Module.mk | 19 +- src/main/launcher/avs-config.c | 773 +++++++++++++++++++++++ src/main/launcher/avs-config.h | 57 ++ src/main/launcher/avs-context.c | 72 --- src/main/launcher/avs-context.h | 20 - src/main/launcher/avs.c | 270 ++++++++ src/main/launcher/avs.h | 16 + src/main/launcher/bootstrap-config.c | 548 ++++++++++++++++ src/main/launcher/bootstrap-config.h | 139 +++++ src/main/launcher/bootstrap.c | 347 +++++++++++ src/main/launcher/bootstrap.h | 32 + src/main/launcher/debug.c | 33 + src/main/launcher/debug.h | 6 + src/main/launcher/ea3-config.c | 190 ------ src/main/launcher/ea3-config.h | 46 -- src/main/launcher/ea3-ident-config.c | 104 ++++ src/main/launcher/ea3-ident-config.h | 37 ++ src/main/launcher/eamuse-config.c | 125 ++++ src/main/launcher/eamuse-config.h | 23 + src/main/launcher/eamuse.c | 25 + src/main/launcher/eamuse.h | 9 + src/main/launcher/hook.c | 34 + src/main/launcher/hook.h | 6 + src/main/launcher/launcher-config.c | 371 +++++++++++ src/main/launcher/launcher-config.h | 56 ++ src/main/launcher/launcher.c | 589 ++++++++++++++++++ src/main/launcher/launcher.h | 8 + src/main/launcher/main.c | 323 +--------- src/main/launcher/module.c | 159 ++++- src/main/launcher/module.h | 18 +- src/main/launcher/options.c | 206 +++---- src/main/launcher/options.h | 60 +- src/main/launcher/property-util.c | 891 +++++++++++++++++++++++++++ src/main/launcher/property-util.h | 99 +++ src/main/launcher/property.c | 135 ---- src/main/launcher/property.h | 10 - src/main/launcher/stubs.c | 7 +- 37 files changed, 4920 insertions(+), 943 deletions(-) create mode 100644 src/main/launcher/avs-config.c create mode 100644 src/main/launcher/avs-config.h delete mode 100644 src/main/launcher/avs-context.c delete mode 100644 src/main/launcher/avs-context.h create mode 100644 src/main/launcher/avs.c create mode 100644 src/main/launcher/avs.h create mode 100644 src/main/launcher/bootstrap-config.c create mode 100644 src/main/launcher/bootstrap-config.h create mode 100644 src/main/launcher/bootstrap.c create mode 100644 src/main/launcher/bootstrap.h create mode 100644 src/main/launcher/debug.c create mode 100644 src/main/launcher/debug.h delete mode 100644 src/main/launcher/ea3-config.c delete mode 100644 src/main/launcher/ea3-config.h create mode 100644 src/main/launcher/ea3-ident-config.c create mode 100644 src/main/launcher/ea3-ident-config.h create mode 100644 src/main/launcher/eamuse-config.c create mode 100644 src/main/launcher/eamuse-config.h create mode 100644 src/main/launcher/eamuse.c create mode 100644 src/main/launcher/eamuse.h create mode 100644 src/main/launcher/hook.c create mode 100644 src/main/launcher/hook.h create mode 100644 src/main/launcher/launcher-config.c create mode 100644 src/main/launcher/launcher-config.h create mode 100644 src/main/launcher/launcher.c create mode 100644 src/main/launcher/launcher.h create mode 100644 src/main/launcher/property-util.c create mode 100644 src/main/launcher/property-util.h delete mode 100644 src/main/launcher/property.c delete mode 100644 src/main/launcher/property.h diff --git a/src/main/launcher/Module.mk b/src/main/launcher/Module.mk index c9dfd07..b62aa17 100644 --- a/src/main/launcher/Module.mk +++ b/src/main/launcher/Module.mk @@ -3,22 +3,35 @@ rc_launcher := launcher.rc ldflags_launcher := \ -mconsole \ + -ldbghelp \ deplibs_launcher := \ avs \ avs-ea3 \ libs_launcher := \ + avs-util \ + core \ hook \ util \ + dwarfstack \ src_launcher := \ - avs-context.c \ - ea3-config.c \ + avs-config.c \ + avs.c \ + bootstrap-config.c \ + bootstrap.c \ + debug.c \ + ea3-ident-config.c \ + eamuse-config.c \ + eamuse.c \ + hook.c \ + launcher-config.c \ + launcher.c \ main.c \ module.c \ options.c \ - property.c \ + property-util.c \ stubs.c \ version.c \ diff --git a/src/main/launcher/avs-config.c b/src/main/launcher/avs-config.c new file mode 100644 index 0000000..8669f3d --- /dev/null +++ b/src/main/launcher/avs-config.c @@ -0,0 +1,773 @@ +#define LOG_MODULE "avs-config" + +#include + +#include "avs-util/error.h" + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/avs-config.h" +#include "launcher/property-util.h" + +#include "util/str.h" + +#define AVS_CONFIG_ROOT_NODE "/config" + +static const char *_avs_config_property_mounttable_path = + "/config/fs/mounttable"; + +static void _avs_config_node_vfs_copy( + struct property *parent_property, + struct property_node *parent, + struct property_node *source) +{ + // Use max path size to fit dst and src fs paths + char data[MAX_PATH]; + + // Remark: Using property_node_clone doesn't work here + // Cloning non-deep only clones the vfs node. Cloning deep doesn't seem + // to work with arbitrary attributes that don't follow the general + // design of a property structure. This seems to require clear typing for + // nodes in order to allow property_node_clone to work + + // Ignore errors and default to empty + memset(data, 0, sizeof(data)); + property_node_refer( + NULL, source, "name@", PROPERTY_TYPE_ATTR, data, sizeof(data)); + property_util_node_attribute_replace( + parent_property, parent, "name@", data); + + memset(data, 0, sizeof(data)); + property_node_refer( + NULL, source, "fstype@", PROPERTY_TYPE_ATTR, data, sizeof(data)); + property_util_node_attribute_replace( + parent_property, parent, "fstype@", data); + + memset(data, 0, sizeof(data)); + property_node_refer( + NULL, source, "src@", PROPERTY_TYPE_ATTR, data, sizeof(data)); + property_util_node_attribute_replace(parent_property, parent, "src@", data); + + memset(data, 0, sizeof(data)); + property_node_refer( + NULL, source, "dst@", PROPERTY_TYPE_ATTR, data, sizeof(data)); + property_util_node_attribute_replace(parent_property, parent, "dst@", data); + + memset(data, 0, sizeof(data)); + property_node_refer( + NULL, source, "opt@", PROPERTY_TYPE_ATTR, data, sizeof(data)); + property_util_node_attribute_replace(parent_property, parent, "opt@", data); +} + +static bool _avs_config_mounttable_vfs_nodes_merge_strategy_do( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx, + property_util_node_merge_recursion_do_t node_merge_recursion_do) +{ + struct property_node *parent_child; + struct property_node *source_child; + + char parent_child_name[PROPERTY_NODE_NAME_SIZE_MAX]; + char name_parent[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + char dst_parent[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + + char source_child_name[PROPERTY_NODE_NAME_SIZE_MAX]; + char name_source[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + char dst_source[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + + bool node_consumed; + bool found_parent; + + source_child = property_node_traversal(source, TRAVERSE_FIRST_CHILD); + + node_consumed = false; + + while (source_child) { + property_node_name( + source_child, source_child_name, sizeof(source_child_name)); + + if (str_eq(source_child_name, "vfs")) { + node_consumed = true; + + parent_child = + property_node_traversal(parent, TRAVERSE_FIRST_CHILD); + + found_parent = false; + + while (parent_child) { + property_node_name( + parent_child, parent_child_name, sizeof(parent_child_name)); + + if (str_eq(parent_child_name, "vfs")) { + if (AVS_IS_ERROR(property_node_refer( + NULL, + source_child, + "name@", + PROPERTY_TYPE_ATTR, + name_source, + sizeof(name_source)))) { + log_fatal( + "Missing 'name' attribute on avs config mounttable " + "vfs source node"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + source_child, + "dst@", + PROPERTY_TYPE_ATTR, + dst_source, + sizeof(dst_source)))) { + log_fatal( + "Missing 'dst' attribute on avs config mounttable " + "vfs source node"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + parent_child, + "name@", + PROPERTY_TYPE_ATTR, + name_parent, + sizeof(name_parent)))) { + log_fatal( + "Missing 'name' attribute on avs config mounttable " + "vfs parent node"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + parent_child, + "dst@", + PROPERTY_TYPE_ATTR, + dst_parent, + sizeof(dst_parent)))) { + log_fatal( + "Missing 'dst' attribute on avs config mounttable " + "vfs parent node"); + } + + // Found existing matching node on parent, replace it + if (str_eq(name_source, name_parent) && + str_eq(dst_source, dst_parent)) { + _avs_config_node_vfs_copy( + parent_property, parent_child, source_child); + + found_parent = true; + break; + } + } + + parent_child = property_node_traversal( + parent_child, TRAVERSE_NEXT_SIBLING); + } + + // Not found an existing node that got replaced, insert/merge new + // data + if (!found_parent) { + parent_child = property_node_create( + parent_property, parent, PROPERTY_TYPE_VOID, "vfs"); + + _avs_config_node_vfs_copy( + parent_property, parent_child, source_child); + } + } + + source_child = + property_node_traversal(source_child, TRAVERSE_NEXT_SIBLING); + } + + return node_consumed; +} + +struct property *avs_config_load(const char *filepath) +{ + struct property *property; + + log_assert(filepath); + + log_info("Loading from file path: %s", filepath); + + property = property_util_load(filepath); + + // Check if root node exists, call already errors if not + avs_config_root_get(property); + + return property; +} + +struct property_node *avs_config_root_get(struct property *property) +{ + struct property_node *node; + + log_assert(property); + + node = property_search(property, 0, AVS_CONFIG_ROOT_NODE); + + if (node == NULL) { + log_fatal("Root node " AVS_CONFIG_ROOT_NODE " in AVS config missing"); + } + + return node; +} + +struct property * +avs_config_property_merge(struct property *parent, struct property *source) +{ + struct property_util_node_merge_strategies strategies; + + log_assert(parent); + log_assert(source); + + strategies.num = 2; + + strategies.entry[0].path = _avs_config_property_mounttable_path; + strategies.entry[0].merge_strategy_do = + _avs_config_mounttable_vfs_nodes_merge_strategy_do; + + strategies.entry[1].path = ""; + strategies.entry[1].merge_strategy_do = + property_util_node_merge_default_strategy_do; + + return property_util_merge_with_strategies(parent, source, &strategies); +} + +void avs_config_fs_root_device_get( + struct property_node *node, char *buffer, size_t size) +{ + struct property_node *device_node; + avs_error error; + + log_assert(node); + + device_node = property_search(NULL, node, "fs/root/device"); + + if (device_node == NULL) { + log_fatal("Could not find node fs/root/device AVS config"); + } + + error = property_node_read(device_node, PROPERTY_TYPE_STR, buffer, size); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "fs/root/device, property read failed: %s", + avs_util_error_str(error)); + } +} + +void avs_config_mode_product_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace(NULL, node, "mode/product", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "mode/product", enable); +#endif +} + +void avs_config_net_raw_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace(NULL, node, "net/enable_raw", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "net/enable_raw", enable); +#endif +} + +void avs_config_net_eaudp_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace( + NULL, node, "net/eaudp/enable", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "net/eaudp/enable", enable); +#endif +} + +void avs_config_sntp_ea_set(struct property_node *node, bool on) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace(NULL, node, "sntp/ea_on", on ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "sntp/ea_on", on); +#endif +} + +void avs_config_log_level_set(struct property_node *node, const char *level) +{ + log_assert(node); + log_assert(level); + +#if AVS_VERSION <= 1306 + uint32_t level_value; + + if (str_eq(level, "fatal")) { + level_value = 1; + } else if (str_eq(level, "warning")) { + level_value = 2; + } else if (str_eq(level, "info")) { + level_value = 3; + } else if (str_eq(level, "misc")) { + level_value = 4; + } else if (str_eq(level, "all")) { + level_value = 4; + } else if (str_eq(level, "disable")) { + level_value = 0; + } else if (str_eq(level, "default")) { + level_value = 4; + } else { + log_fatal("Unknown log level string %s", level); + } + + property_util_node_u32_replace(NULL, node, "log/level", level_value); +#else + property_util_node_str_replace(NULL, node, "log/level", level); +#endif +} + +void avs_config_log_name_set(struct property_node *node, const char *name) +{ + log_assert(node); + log_assert(name); + + property_util_node_str_replace(NULL, node, "log/name", name); +} + +void avs_config_log_file_set(struct property_node *node, const char *file) +{ + log_assert(node); + log_assert(file); + + property_util_node_str_replace(NULL, node, "log/file", file); +} + +void avs_config_log_buffer_size_set(struct property_node *node, uint32_t size) +{ + log_assert(node); + + property_util_node_u32_replace(NULL, node, "log/sz_buf", size); +} + +void avs_config_log_output_delay_set( + struct property_node *node, uint16_t delay_ms) +{ + log_assert(node); + + property_util_node_u16_replace(NULL, node, "log/output_delay", delay_ms); +} + +void avs_config_log_enable_console_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace( + NULL, node, "log/enable_console", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/enable_console", enable); +#endif +} + +void avs_config_log_enable_sci_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace( + NULL, node, "log/enable_netsci", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/enable_netsci", enable); +#endif +} + +void avs_config_log_enable_net_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace( + NULL, node, "log/enable_netlog", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/enable_netlog", enable); +#endif +} + +void avs_config_log_enable_file_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace( + NULL, node, "log/enable_file", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/enable_file", enable); +#endif +} + +void avs_config_log_rotate_set(struct property_node *node, bool rotate) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace(NULL, node, "log/rotate", rotate ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/rotate", rotate); +#endif +} + +void avs_config_log_append_set(struct property_node *node, bool append) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace(NULL, node, "log/append", append ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/append", append); +#endif +} + +void avs_config_log_count_set(struct property_node *node, uint16_t count) +{ + log_assert(node); + + property_util_node_u16_replace(NULL, node, "log/gen", count); +} + +void avs_config_set_log_level( + struct property_node *node, enum core_log_bt_log_level loglevel) +{ + const char *str; + + log_assert(node); + + switch (loglevel) { + case CORE_LOG_BT_LOG_LEVEL_OFF: + str = "disable"; + break; + + case CORE_LOG_BT_LOG_LEVEL_FATAL: + str = "fatal"; + break; + + case CORE_LOG_BT_LOG_LEVEL_WARNING: + str = "warn"; + break; + + case CORE_LOG_BT_LOG_LEVEL_INFO: + str = "info"; + break; + + case CORE_LOG_BT_LOG_LEVEL_MISC: + str = "misc"; + break; + + default: + log_fatal("Unsupported log level: %d", loglevel); + break; + } + + avs_config_log_level_set(node, str); +} + +void avs_config_local_fs_path_dev_nvram_and_raw_set( + struct property_node *node, const char *dev_nvram_raw_path) +{ + char path_dev_raw[MAX_PATH]; + char path_dev_nvram[MAX_PATH]; + + struct property_node *fs_node; + struct property_node *mounttable_node; + struct property_node *vfs_node; + + log_assert(node); + log_assert(dev_nvram_raw_path); + + str_cpy(path_dev_raw, sizeof(path_dev_raw), dev_nvram_raw_path); + str_cat(path_dev_raw, sizeof(path_dev_raw), "/dev/raw"); + + str_cpy(path_dev_nvram, sizeof(path_dev_nvram), dev_nvram_raw_path); + str_cat(path_dev_nvram, sizeof(path_dev_nvram), "/dev/nvram"); + + fs_node = property_search(NULL, node, "fs"); + + if (!fs_node) { + log_fatal("Cannot find 'fs' node in avs config"); + } + + // Check if "new" mounttable config is used for dev/nvram and dev/raw or + // legacy config + if (property_search(NULL, fs_node, "mounttable")) { + property_remove(NULL, fs_node, "mounttable"); + + mounttable_node = property_node_create( + NULL, fs_node, PROPERTY_TYPE_VOID, "mounttable"); + + vfs_node = property_node_create( + NULL, mounttable_node, PROPERTY_TYPE_VOID, "vfs"); + + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "name", "boot"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "fstype", "fs"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "src", path_dev_raw); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "dest", "/dev/raw"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "opt", "vf=1,posix=1"); + + vfs_node = property_node_create( + NULL, mounttable_node, PROPERTY_TYPE_VOID, "vfs"); + + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "name", "boot"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "fstype", "fs"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "src", path_dev_nvram); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "dest", "/dev/nvram"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "opt", "vf=1,posix=1"); + } else { + property_util_node_str_replace( + NULL, fs_node, "nvram/device", path_dev_raw); + property_util_node_str_replace(NULL, fs_node, "nvram/fstype", "fs"); + property_util_node_str_replace( + NULL, fs_node, "nvram/option", "vf=1,posix=1"); + + property_util_node_str_replace( + NULL, fs_node, "raw/device", path_dev_nvram); + property_util_node_str_replace(NULL, fs_node, "raw/fstype", "fs"); + property_util_node_str_replace( + NULL, fs_node, "raw/option", "vf=1,posix=1"); + } +} + +void avs_config_vfs_mounttable_get( + struct property_node *node, struct avs_config_vfs_mounttable *mounttable) +{ + struct property_node *fs_node; + struct property_node *mounttable_node; + struct property_node *cur; + char mounttable_selector[128]; + char name[128]; + uint8_t pos; + + log_assert(node); + log_assert(mounttable); + + fs_node = property_search(NULL, node, "fs"); + + if (!fs_node) { + log_fatal("Cannot find 'fs' node in avs config"); + } + + // Check if new mounttable config is used for dev/nvram and dev/raw or + // legacy config + mounttable_node = property_search(NULL, fs_node, "mounttable"); + + memset(mounttable, 0, sizeof(*mounttable)); + pos = 0; + + if (mounttable_node) { + cur = property_search(NULL, fs_node, "mounttable_selector"); + + if (!cur) { + log_fatal("Missing 'mounttable_selector' on mounttable"); + } + + if (AVS_IS_ERROR(property_node_read( + cur, + PROPERTY_TYPE_STR, + mounttable_selector, + sizeof(mounttable_selector)))) { + log_fatal("Reading 'mounttable_selector' failed"); + } + + log_misc("Mounttable selector: %s", mounttable_selector); + + cur = property_node_traversal(mounttable_node, TRAVERSE_FIRST_CHILD); + + while (cur) { + property_node_name(cur, name, sizeof(name)); + + if (str_eq(name, "vfs")) { + if (pos >= AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES) { + log_warning( + "Exceeding max number of supported mounttable entries " + "(%d), ignoring remaining", + pos); + break; + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "name@", + PROPERTY_TYPE_ATTR, + name, + sizeof(name)))) { + log_fatal("Missing 'name' attribute on vfs node"); + } + + if (str_eq(name, mounttable_selector)) { + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "fstype@", + PROPERTY_TYPE_ATTR, + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype)))) { + // default + str_cpy( + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype), + "fs"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "src@", + PROPERTY_TYPE_ATTR, + mounttable->entry[pos].src, + sizeof(mounttable->entry[pos].src)))) { + log_fatal( + "Missing 'src' attribute on vfs node, name: %s", + name); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "dst@", + PROPERTY_TYPE_ATTR, + mounttable->entry[pos].dst, + sizeof(mounttable->entry[pos].dst)))) { + log_fatal( + "Missing 'dst' attribute on vfs node, name: %s", + name); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "opt@", + PROPERTY_TYPE_ATTR, + mounttable->entry[pos].opt, + sizeof(mounttable->entry[pos].opt)))) { + // optional + } + + pos++; + } + } + + cur = property_node_traversal(cur, TRAVERSE_NEXT_SIBLING); + } + } else { + cur = property_search(NULL, fs_node, "nvram"); + + if (cur) { + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "fstype", + PROPERTY_TYPE_STR, + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype)))) { + // default + str_cpy( + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype), + "fs"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "device", + PROPERTY_TYPE_STR, + mounttable->entry[pos].src, + sizeof(mounttable->entry[pos].src)))) { + log_fatal("Missing 'device' attribute on nvram node"); + } + + str_cpy( + mounttable->entry[pos].dst, + sizeof(mounttable->entry[pos].dst), + "/dev/nvram"); + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "opt", + PROPERTY_TYPE_STR, + mounttable->entry[pos].opt, + sizeof(mounttable->entry[pos].opt)))) { + // optional + } + + pos++; + } + + cur = property_search(NULL, fs_node, "raw"); + + if (cur) { + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "fstype", + PROPERTY_TYPE_STR, + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype)))) { + // default + str_cpy( + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype), + "fs"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "device", + PROPERTY_TYPE_STR, + mounttable->entry[pos].src, + sizeof(mounttable->entry[pos].src)))) { + log_fatal("Missing 'device' attribute on raw node"); + } + + str_cpy( + mounttable->entry[pos].dst, + sizeof(mounttable->entry[pos].dst), + "/dev/raw"); + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "opt", + PROPERTY_TYPE_STR, + mounttable->entry[pos].opt, + sizeof(mounttable->entry[pos].opt)))) { + // optional + } + + pos++; + } + } + + mounttable->num_entries = pos; +} \ No newline at end of file diff --git a/src/main/launcher/avs-config.h b/src/main/launcher/avs-config.h new file mode 100644 index 0000000..692643d --- /dev/null +++ b/src/main/launcher/avs-config.h @@ -0,0 +1,57 @@ +#ifndef LAUNCHER_AVS_CONFIG_H +#define LAUNCHER_AVS_CONFIG_H + +#include "core/log-bt.h" + +#include "imports/avs.h" + +#include "launcher/bootstrap-config.h" + +#define AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES 16 + +struct avs_config_vfs_mounttable { + struct { + char fstype[64]; + char src[512]; + char dst[512]; + char opt[256]; + } entry[AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES]; + + uint8_t num_entries; +}; + +struct property *avs_config_load(const char *filepath); +struct property_node *avs_config_root_get(struct property *property); +struct property * +avs_config_property_merge(struct property *parent, struct property *source); + +void avs_config_fs_root_device_get( + struct property_node *node, char *buffer, size_t size); + +void avs_config_mode_product_set(struct property_node *node, bool enable); +void avs_config_net_raw_set(struct property_node *node, bool enable); +void avs_config_net_eaudp_set(struct property_node *node, bool enable); +void avs_config_sntp_ea_set(struct property_node *node, bool on); +void avs_config_log_level_set(struct property_node *node, const char *level); +void avs_config_log_name_set(struct property_node *node, const char *name); +void avs_config_log_file_set(struct property_node *node, const char *file); +void avs_config_log_buffer_size_set(struct property_node *node, uint32_t size); +void avs_config_log_output_delay_set( + struct property_node *node, uint16_t delay_ms); +void avs_config_log_enable_console_set(struct property_node *node, bool enable); +void avs_config_log_enable_sci_set(struct property_node *node, bool enable); +void avs_config_log_enable_net_set(struct property_node *node, bool enable); +void avs_config_log_enable_file_set(struct property_node *node, bool enable); +void avs_config_log_rotate_set(struct property_node *node, bool rotate); +void avs_config_log_append_set(struct property_node *node, bool append); +void avs_config_log_count_set(struct property_node *node, uint16_t count); + +void avs_config_set_log_level( + struct property_node *node, enum core_log_bt_log_level loglevel); +void avs_config_local_fs_path_dev_nvram_and_raw_set( + struct property_node *node, const char *dev_nvram_raw_path); + +void avs_config_vfs_mounttable_get( + struct property_node *node, struct avs_config_vfs_mounttable *mounttable); + +#endif \ No newline at end of file diff --git a/src/main/launcher/avs-context.c b/src/main/launcher/avs-context.c deleted file mode 100644 index 1e391db..0000000 --- a/src/main/launcher/avs-context.c +++ /dev/null @@ -1,72 +0,0 @@ -#include - -#include -#include -#include - -#include "imports/avs.h" - -#include "launcher/avs-context.h" - -#include "util/log.h" - -static void *avs_heap; - -#ifdef AVS_HAS_STD_HEAP -static void *std_heap; -#endif - -void avs_context_init( - struct property_node *config, - uint32_t avs_heap_size, - uint32_t std_heap_size, - avs_log_writer_t log_writer, - void *log_writer_ctx) -{ - avs_heap = VirtualAlloc( - NULL, avs_heap_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); - - if (avs_heap == NULL) { - log_fatal( - "Failed to VirtualAlloc %d byte AVS heap: %08x", - avs_heap_size, - (unsigned int) GetLastError()); - } - -#ifdef AVS_HAS_STD_HEAP - std_heap = VirtualAlloc( - NULL, std_heap_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); - - if (std_heap == NULL) { - log_fatal( - "Failed to VirtualAlloc %d byte \"std\" heap: %08x", - std_heap_size, - (unsigned int) GetLastError()); - } -#endif - -#ifdef AVS_HAS_STD_HEAP - avs_boot( - config, - std_heap, - std_heap_size, - avs_heap, - avs_heap_size, - log_writer, - log_writer_ctx); -#else - /* AVS v2.16.xx and I suppose onward uses a unified heap */ - avs_boot(config, avs_heap, avs_heap_size, NULL, log_writer, log_writer_ctx); -#endif -} - -void avs_context_fini(void) -{ - avs_shutdown(); - -#ifdef AVS_HAS_STD_HEAP - VirtualFree(std_heap, 0, MEM_RELEASE); -#endif - - VirtualFree(avs_heap, 0, MEM_RELEASE); -} diff --git a/src/main/launcher/avs-context.h b/src/main/launcher/avs-context.h deleted file mode 100644 index d4532eb..0000000 --- a/src/main/launcher/avs-context.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef LAUNCHER_AVS_CONTEXT_H -#define LAUNCHER_AVS_CONTEXT_H - -#include - -#include "imports/avs.h" - -#if AVS_VERSION < 1600 -#define AVS_HAS_STD_HEAP -#endif - -void avs_context_init( - struct property_node *config, - uint32_t avs_heap_size, - uint32_t std_heap_size, - avs_log_writer_t log_writer, - void *log_writer_ctx); -void avs_context_fini(void); - -#endif diff --git a/src/main/launcher/avs.c b/src/main/launcher/avs.c new file mode 100644 index 0000000..4ff0730 --- /dev/null +++ b/src/main/launcher/avs.c @@ -0,0 +1,270 @@ +#define LOG_MODULE "avs" + +#include + +#include +#include +#include + +#include "core/log-bt.h" +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/avs-config.h" +#include "launcher/avs.h" +#include "launcher/property-util.h" + +#include "util/codepage.h" +#include "util/fs.h" +#include "util/mem.h" +#include "util/str.h" + +#if AVS_VERSION < 1600 +#define AVS_HAS_STD_HEAP +#endif + +static void *avs_heap; + +#ifdef AVS_HAS_STD_HEAP +static void *std_heap; +#endif + +/* Gratuitous API changes orz */ +static AVS_LOG_WRITER(_avs_context_log_writer, chars, nchars, ctx) +{ + wchar_t *utf16; + char *utf8; + int utf16_len; + int utf8_len; + int result; + + /* Ignore existing NUL terminator */ + + nchars--; + + /* Transcode shit_jis to UTF-8 */ + + utf16_len = MultiByteToWideChar(CP_SHIFT_JIS, 0, chars, nchars, NULL, 0); + + if (utf16_len == 0) { + abort(); + } + + utf16 = xmalloc(sizeof(*utf16) * utf16_len); + result = + MultiByteToWideChar(CP_SHIFT_JIS, 0, chars, nchars, utf16, utf16_len); + + if (result == 0) { + abort(); + } + + utf8_len = + WideCharToMultiByte(CP_UTF8, 0, utf16, utf16_len, NULL, 0, NULL, NULL); + + if (utf8_len == 0) { + abort(); + } + + utf8 = xmalloc(utf8_len + 3); + result = WideCharToMultiByte( + CP_UTF8, 0, utf16, utf16_len, utf8, utf8_len, NULL, NULL); + + if (result == 0) { + abort(); + } + +#if AVS_VERSION >= 1500 + utf8[utf8_len + 0] = '\r'; + utf8[utf8_len + 1] = '\n'; + + utf8_len += 2; +#endif + + // Clean string terminate + utf8[utf8_len] = '\0'; + + // Write to launcher's dedicated logging backend + core_log_bt_direct_sink_write(utf8, utf8_len); + + /* Clean up */ + + free(utf8); + free(utf16); +} + +static void _avs_switch_log_engine() +{ + // Switch the logging backend now that AVS is booted to use a single logging + // engine which avoids concurrency issues as AVS runs it's own async logger + // thread + core_log_impl_set( + log_body_misc, log_body_info, log_body_warning, log_body_fatal); + + log_misc("Switched logging engine to AVS"); +} + +void avs_fs_assert_root_device_exists(struct property_node *node) +{ + char root_device_path[PATH_MAX]; + char cwd_path[PATH_MAX]; + + avs_config_fs_root_device_get( + node, root_device_path, sizeof(root_device_path)); + getcwd(cwd_path, sizeof(cwd_path)); + + if (!path_exists(root_device_path)) { + log_fatal( + "Root device path '%s' does not exist in current working dir '%s'", + root_device_path, + cwd_path); + } +} + +void avs_fs_mountpoints_fs_dirs_create(struct property_node *node) +{ + struct avs_config_vfs_mounttable mounttable; + uint8_t i; + + avs_config_vfs_mounttable_get(node, &mounttable); + + if (mounttable.num_entries == 0) { + log_warning("No mountpoints found in mounttable"); + } + + for (i = 0; i < mounttable.num_entries; i++) { + if (str_eq(mounttable.entry[i].fstype, "fs")) { + log_misc( + "Creating avs fs directory '%s' for destination/device '%s'...", + mounttable.entry[i].src, + mounttable.entry[i].dst); + + if (!path_exists(mounttable.entry[i].src)) { + if (!path_mkdir(mounttable.entry[i].src)) { + log_fatal( + "Creating fs directory %s failed", + mounttable.entry[i].src); + } + } + } + } +} + +void avs_init( + struct property_node *node, uint32_t avs_heap_size, uint32_t std_heap_size) +{ + log_assert(node); + log_assert(avs_heap_size > 0); + // Modern games don't have a separate std heap anymore + log_assert(std_heap_size >= 0); + + log_info("init"); + + log_misc("Allocating avs heap: %d", avs_heap_size); + + avs_heap = VirtualAlloc( + NULL, avs_heap_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + + if (avs_heap == NULL) { + log_fatal( + "Failed to VirtualAlloc %d byte AVS heap: %08x", + avs_heap_size, + (unsigned int) GetLastError()); + } + +#ifdef AVS_HAS_STD_HEAP + log_misc("Allocating std heap: %d", std_heap_size); + + std_heap = VirtualAlloc( + NULL, std_heap_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + + if (std_heap == NULL) { + log_fatal( + "Failed to VirtualAlloc %d byte \"std\" heap: %08x", + std_heap_size, + (unsigned int) GetLastError()); + } +#endif + + log_info("Calling avs_boot"); + +#ifdef AVS_HAS_STD_HEAP + avs_boot( + node, + std_heap, + std_heap_size, + avs_heap, + avs_heap_size, + _avs_context_log_writer, + NULL); +#else + /* AVS v2.16.xx and I suppose onward uses a unified heap */ + avs_boot( + node, avs_heap, avs_heap_size, NULL, _avs_context_log_writer, NULL); +#endif + + _avs_switch_log_engine(); + + log_misc("init done"); +} + +void avs_fs_file_copy(const char *src, const char *dst) +{ + struct avs_stat st; + + log_assert(src); + log_assert(dst); + + log_misc("Copying %s to %s...", src, dst); + + if (!avs_fs_lstat(src, &st)) { + log_fatal("File source %s does not exist or is not accessible", src); + } + + if (avs_fs_copy(src, dst) < 0) { + log_fatal("Failed copying file %s to %s", src, dst); + } +} + +void avs_fs_dir_log(const char *path) +{ + const char *name; + + log_assert(path); + + avs_desc dir = avs_fs_opendir(path); + + if (dir < 0) { + log_warning( + "Opening avs dir %s failed, skipping logging contents", path); + } + + log_misc("Contents of %s:", path); + + do { + name = avs_fs_readdir(dir); + + if (name == NULL) { + break; + } + + log_misc("%s", name); + } while (name != NULL); + + avs_fs_closedir(dir); +} + +void avs_fini(void) +{ + log_info("fini"); + + avs_shutdown(); + +#ifdef AVS_HAS_STD_HEAP + VirtualFree(std_heap, 0, MEM_RELEASE); +#endif + + VirtualFree(avs_heap, 0, MEM_RELEASE); + + log_misc("fini done"); +} diff --git a/src/main/launcher/avs.h b/src/main/launcher/avs.h new file mode 100644 index 0000000..ad2233a --- /dev/null +++ b/src/main/launcher/avs.h @@ -0,0 +1,16 @@ +#ifndef LAUNCHER_AVS_H +#define LAUNCHER_AVS_H + +#include + +#include "imports/avs.h" + +void avs_fs_assert_root_device_exists(struct property_node *node); +void avs_fs_mountpoints_fs_dirs_create(struct property_node *node); +void avs_init( + struct property_node *node, uint32_t avs_heap_size, uint32_t std_heap_size); +void avs_fs_file_copy(const char *src, const char *dst); +void avs_fs_dir_log(const char *path); +void avs_fini(void); + +#endif diff --git a/src/main/launcher/bootstrap-config.c b/src/main/launcher/bootstrap-config.c new file mode 100644 index 0000000..35915c6 --- /dev/null +++ b/src/main/launcher/bootstrap-config.c @@ -0,0 +1,548 @@ +#define LOG_MODULE "bootstrap-config" + +#include + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/avs-config.h" +#include "launcher/bootstrap-config.h" +#include "launcher/property-util.h" + +#include "util/defs.h" +#include "util/hex.h" +#include "util/str.h" + +// clang-format off +PSMAP_BEGIN(bootstrap_startup_boot_psmap) +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct bootstrap_boot_config, config_file, + "boot/file") +PSMAP_REQUIRED(PSMAP_TYPE_U32, struct bootstrap_boot_config, avs_heap_size, + "boot/heap_avs") +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_boot_config, std_heap_size, + "boot/heap_std", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_boot_config, mount_table_selector, + "boot/mounttable_selector", "boot") +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_boot_config, watcher_enable, + "boot/watcher", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_boot_config, timemachine_enable, + "boot/timemachine", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_boot_config, launch_config_file, + "boot/launch_path", "/dev/raw/launch.xml") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_log_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_log_config, level, + "log/level", "all") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_log_config, name, + "log/name", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_log_config, file, + "log/file", "") +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_log_config, bufsz, + "log/sz_buf", 4096) +PSMAP_OPTIONAL(PSMAP_TYPE_U16, struct bootstrap_log_config, output_delay_ms, + "log/output_delay", 10) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_console, + "log/enable_console", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_sci, + "log/enable_netsci", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_net, + "log/enable_netlog", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_file, + "log/enable_file", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, rotate, + "log/rotate", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, append, + "log/append", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_U16, struct bootstrap_log_config, count, + "log/gen", 10) +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_minidump_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_U8, struct bootstrap_minidump_config, count, + "minidump/gen", 10) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_minidump_config, continue_, + "minidump/cont_debug", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_minidump_config, log, + "minidump/echo_log", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_U8, struct bootstrap_minidump_config, type, + "minidump/dump_type", 2) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_minidump_config, path, + "minidump/path", "/dev/raw/minidump") +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_minidump_config, symbufsz, + "minidump/sz_symbuf", 32768) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_minidump_config, search_path, + "minidump/search", ".") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_module_psmap) +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct bootstrap_module_config, file, + "component/file") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_module_config, load_type, + "component/load_type", "MEMORY") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_dlm_psmap) +/* disabled until we implement PSMAP_TYPE_BIN + PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_startup_config, ntdll_digest, + "dlml/ntdll/hash", "") + */ +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, size, + "dlml/ntdll/size", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, ift_table, + "dlml/ntdll/ift_table", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, ift_insert, + "dlml/ntdll/insert_ift", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, ift_remove, + "dlml/ntdll/remove_ift", 0) +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_shield_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_shield_config, enable, + "shield/enable", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_shield_config, verbose, + "shield/verbose", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_shield_config, use_loadlibrary, + "shield/use_loadlibrary", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_shield_config, logger, + "shield/logger", "") +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, sleep_min, + "shield/sleepmin", 10) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, sleep_blur, + "shield/sleepblur", 90) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_shield_config, whitelist_file, + "shield/whitelist", "prop/whitelist.csv") +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, tick_sleep, + "shield/ticksleep", 100) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, tick_error, + "shield/tickerror", 1000) +PSMAP_OPTIONAL(PSMAP_TYPE_U8, struct bootstrap_shield_config, overwork_threshold, + "shield/overwork_threshold", 50) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, overwork_delay, + "shield/overwork_delay", 100) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, pause_delay, + "shield/pause_delay", 1000) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_shield_config, unlimited_key, + "shield/unlimited_key", "") +PSMAP_OPTIONAL(PSMAP_TYPE_U16, struct bootstrap_shield_config, killer_port, + "shield_killer/port", 5001) +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_dongle_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_dongle_config, license_cn, + "dongle/license", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_dongle_config, account_cn, + "dongle/account", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_dongle_config, driver_dll, + "dongle/pkcs11_driver", "eTPKCS11.dll") +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_dongle_config, disable_gc, + "dongle/disable_gc", 0) +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_drm_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, dll, + "drm/dll", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, fstype, + "drm/fstype", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, device, + "drm/device", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, mount, + "drm/dst", "/") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, options, + "drm/option", "") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_lte_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_lte_config, enable, + "lte/enable", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_lte_config, config_file, + "lte/file", "/dev/nvram/lte-config.xml") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_lte_config, unlimited_key, + "lte/unlimited_key", "") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_ssl_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_ssl_config, options, + "ssl/option", "") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_esign_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_esign_config, enable, + "esign/enable", 0) +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_eamuse_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, enable, + "eamuse/enable", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, sync, + "eamuse/sync", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, enable_model, + "eamuse/enable_model", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_eamuse_config, config_file, + "eamuse/file", "/dev/nvram/ea3-config.xml") +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, updatecert_enable, + "eamuse/updatecert_enable", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_eamuse_config, updatecert_interval, + "eamuse/updatecert_interval", 0) +PSMAP_END + +PSMAP_BEGIN(bootstrap_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_config, release_code, "/release_code", "") +PSMAP_END +// clang-format on + +#define ROOT_NODE "/config" +#define MODULE_PATH_PREFIX "modules/" + +#define NODE_MISSING_FATAL(subnode) \ + log_fatal("%s/%s: Node missing", ROOT_NODE, subnode); +#define NODE_STARTUP_MISSING_FATAL(profile) \ + log_fatal("%s/startup/%s: Node missing", ROOT_NODE, profile); +#define NODE_PROFILE_MISSING_FATAL(profile, subnode) \ + log_fatal("%s/%s/%s: Node missing", ROOT_NODE, profile, subnode); +#define NODE_PROFILE_LOADING_FATAL(profile, subnode) \ + log_fatal("%s/startup/%s/%s: Node loading", ROOT_NODE, profile, subnode); + +#define DEFAULT_HEAP_SIZE 16777216 + +const char *const inherited_nodes[] = { + "develop", + "default", + "log", + "minidump", + "boot", + "drm", + "ssl", + "eamuse", + "shield", + "esign", + "dongle", + "lte", +}; + +static void _bootstrap_config_profile_node_verify( + struct property_node *node, const char *profile) +{ + struct property_node *profile_node; + + log_assert(node); + log_assert(profile); + + profile_node = property_search(NULL, node, profile); + + if (!profile_node) { + NODE_STARTUP_MISSING_FATAL(profile); + } +} + +static struct property_node * +_bootstrap_config_root_node_get(struct property *property) +{ + struct property_node *root_node; + + log_assert(property); + + root_node = property_search(property, NULL, ROOT_NODE); + + if (!root_node) { + NODE_MISSING_FATAL(""); + } + + return root_node; +} + +static struct property_node * +_bootstrap_config_startup_node_get(struct property_node *node) +{ + struct property_node *startup_node; + + log_assert(node); + + startup_node = property_search(NULL, node, "startup"); + + if (!startup_node) { + NODE_MISSING_FATAL("startup"); + } + + return startup_node; +} + +static void _bootstrap_config_inheritance_resolve( + struct property_node *startup_node, const char *profile_name) +{ + struct property_node *startup_parent_node; + struct property_node *startup_profile_node; + struct property_node *tmp_node; + + char inherit_name[64]; + avs_error error; + struct property_node *result; + + startup_profile_node = property_search(NULL, startup_node, profile_name); + + if (!startup_profile_node) { + log_fatal(ROOT_NODE "/startup/%s: missing", profile_name); + } + + startup_parent_node = startup_profile_node; + + for (;;) { + error = property_node_refer( + NULL, + startup_parent_node, + "inherit@", + PROPERTY_TYPE_ATTR, + inherit_name, + sizeof(inherit_name)); + + if (AVS_IS_ERROR(error)) { + break; + } + + startup_parent_node = property_search(NULL, startup_node, inherit_name); + + if (!startup_parent_node) { + NODE_STARTUP_MISSING_FATAL(inherit_name); + } + + for (int i = 0; i < _countof(inherited_nodes); i++) { + if (property_search(NULL, startup_node, inherited_nodes[i])) { + continue; + } + + tmp_node = + property_search(NULL, startup_parent_node, inherited_nodes[i]); + + if (tmp_node) { + log_misc( + ROOT_NODE "/startup/%s: merging %s...", + inherit_name, + inherited_nodes[i]); + + result = property_node_clone( + NULL, startup_profile_node, tmp_node, true); + + if (!result) { + log_fatal( + "Merging '%s' into '%s' failed", + inherited_nodes[i], + inherit_name); + } + } + } + } +} + +static void _bootstrap_config_load_bootstrap_module_app_config( + struct property_node *profile_node, struct bootstrap_module_config *config) +{ + struct property_node *app_node; + + log_assert(profile_node); + log_assert(config); + + app_node = property_search(NULL, profile_node, "component/param"); + + config->app_config = property_util_node_extract(app_node); +} + +static void _bootstrap_config_load_bootstrap_default_files_config( + const char *profile_name, + struct property_node *profile_node, + struct bootstrap_default_file_config *config) +{ + int i; + int result; + struct property_node *child; + + log_assert(profile_node); + log_assert(config); + + child = property_search(NULL, profile_node, "default/file"); + i = 0; + + while (child) { + if (i >= DEFAULT_FILE_MAX) { + log_warning( + "Currently not supporting more than %d default files, skipping " + "remaining", + i); + break; + } + + result = property_node_refer( + NULL, + child, + "src@", + PROPERTY_TYPE_ATTR, + &config->file[i].src, + sizeof(config->file[i].src)); + + if (result < 0) { + log_fatal( + "Missing src attribute on default file node of profile %s", + profile_name); + } + + result = property_node_refer( + NULL, + child, + "dst@", + PROPERTY_TYPE_ATTR, + &config->file[i].dst, + sizeof(config->file[i].dst)); + + if (result < 0) { + log_fatal( + "Missing dst attribute on default file node of profile %s", + profile_name); + } + + child = property_node_traversal(child, TRAVERSE_NEXT_SEARCH_RESULT); + i++; + } +} + +static void _bootstrap_config_load_bootstrap( + struct property_node *startup_node, + const char *profile, + struct bootstrap_startup_config *config) +{ + struct property_node *profile_node; + + profile_node = property_search(NULL, startup_node, profile); + + if (!profile_node) { + NODE_PROFILE_LOADING_FATAL(profile, ""); + } + + _bootstrap_config_load_bootstrap_default_files_config( + profile, profile_node, &config->default_file); + + if (!property_psmap_import( + NULL, profile_node, &config->boot, bootstrap_startup_boot_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "boot"); + } + + if (!property_psmap_import( + NULL, profile_node, &config->log, bootstrap_startup_log_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "log"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->minidump, + bootstrap_startup_minidump_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "minidump"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->module, + bootstrap_startup_module_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "component"); + } + + _bootstrap_config_load_bootstrap_module_app_config( + profile_node, &config->module); + + if (!property_psmap_import( + NULL, + profile_node, + &config->dlm_ntdll, + bootstrap_startup_dlm_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "dlm/ntdll"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->shield, + bootstrap_startup_shield_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "shield"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->dongle, + bootstrap_startup_dongle_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "dongle"); + } + + if (!property_psmap_import( + NULL, profile_node, &config->drm, bootstrap_startup_drm_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "drm"); + } + + if (!property_psmap_import( + NULL, profile_node, &config->lte, bootstrap_startup_lte_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "lte"); + } + + if (!property_psmap_import( + NULL, profile_node, &config->ssl, bootstrap_startup_ssl_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "ssl"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->esign, + bootstrap_startup_esign_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "esign"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->eamuse, + bootstrap_startup_eamuse_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "eamuse"); + } +} + +void bootstrap_config_init(struct bootstrap_config *config) +{ + log_assert(config); + + memset(config, 0, sizeof(*config)); +} + +void bootstrap_config_load( + struct property *property, + const char *profile, + struct bootstrap_config *config) +{ + struct property_node *root_node; + struct property_node *startup_node; + + log_assert(property); + log_assert(profile); + log_assert(config); + + log_info(ROOT_NODE ": loading..."); + + root_node = _bootstrap_config_root_node_get(property); + + if (!property_psmap_import(NULL, root_node, config, bootstrap_psmap)) { + log_fatal(ROOT_NODE ": loading failed"); + } + + startup_node = _bootstrap_config_startup_node_get(root_node); + + _bootstrap_config_profile_node_verify(startup_node, profile); + + _bootstrap_config_inheritance_resolve(startup_node, profile); + + log_misc(ROOT_NODE "/startup/%s: loading merged result...", profile); + + property_util_node_log(startup_node); + + _bootstrap_config_load_bootstrap(startup_node, profile, &config->startup); + + log_misc("Loading finished"); +} \ No newline at end of file diff --git a/src/main/launcher/bootstrap-config.h b/src/main/launcher/bootstrap-config.h new file mode 100644 index 0000000..596bf93 --- /dev/null +++ b/src/main/launcher/bootstrap-config.h @@ -0,0 +1,139 @@ +#ifndef LAUNCHER_BOOTSTRAP_CONFIG_H +#define LAUNCHER_BOOTSTRAP_CONFIG_H + +#include +#include + +#include "imports/avs.h" + +// should be enough for a while +#define DEFAULT_FILE_MAX 16 + +struct bootstrap_startup_config { + struct bootstrap_default_file_config { + struct bootstrap_default_file { + char src[64]; + char dst[64]; + } file[DEFAULT_FILE_MAX]; + } default_file; + + struct bootstrap_boot_config { + char config_file[64]; + uint32_t avs_heap_size; + uint32_t std_heap_size; + char launch_config_file[64]; + char mount_table_selector[16]; + bool watcher_enable; + bool timemachine_enable; + } boot; + + struct bootstrap_log_config { + char level[8]; + char name[64]; + char file[64]; + uint32_t bufsz; + uint16_t output_delay_ms; + bool enable_console; + bool enable_sci; + bool enable_net; + bool enable_file; + bool rotate; + bool append; + uint16_t count; + } log; + + struct bootstrap_minidump_config { + uint8_t count; + bool continue_; + bool log; + uint8_t type; + char path[64]; + uint32_t symbufsz; + char search_path[64]; + } minidump; + + struct bootstrap_module_config { + char file[64]; + char load_type[64]; + struct property *app_config; + } module; + + struct bootstrap_dlm_config { + char digest[16]; + uint32_t size; + uint32_t ift_table; + uint32_t ift_insert; + uint32_t ift_remove; + }; + + struct bootstrap_dlm_config dlm_ntdll; + + struct bootstrap_shield_config { + bool enable; + bool verbose; + bool use_loadlibrary; + char logger[64]; + uint32_t sleep_min; + uint32_t sleep_blur; + uint32_t tick_sleep; + uint32_t tick_error; + uint8_t overwork_threshold; + uint32_t overwork_delay; + uint32_t pause_delay; + char whitelist_file[64]; + char unlimited_key[10]; + uint16_t killer_port; + } shield; + + struct bootstrap_dongle_config { + char license_cn[32]; + char account_cn[32]; + char driver_dll[16]; + bool disable_gc; + } dongle; + + struct bootstrap_drm_config { + char dll[64]; + char device[64]; + char mount[64]; + char fstype[64]; + char options[64]; + } drm; + + struct bootstrap_lte_config { + bool enable; + char config_file[64]; + char unlimited_key[10]; + } lte; + + struct bootstrap_ssl_config { + char options[64]; + } ssl; + + struct bootstrap_esign_config { + bool enable; + } esign; + + struct bootstrap_eamuse_config { + bool enable; + bool sync; + bool enable_model; + char config_file[64]; + bool updatecert_enable; + uint32_t updatecert_interval; + } eamuse; +}; + +struct bootstrap_config { + char release_code[16]; + struct bootstrap_startup_config startup; +}; + +void bootstrap_config_init(struct bootstrap_config *config); + +void bootstrap_config_load( + struct property *property, + const char *profile, + struct bootstrap_config *config); + +#endif /* LAUNCHER_BOOTSTRAP_CONFIG_H */ diff --git a/src/main/launcher/bootstrap.c b/src/main/launcher/bootstrap.c new file mode 100644 index 0000000..a9e52bb --- /dev/null +++ b/src/main/launcher/bootstrap.c @@ -0,0 +1,347 @@ +#define LOG_MODULE "bootstrap" + +#include "core/log-bt.h" +#include "core/log-sink-file.h" +#include "core/log-sink-list.h" +#include "core/log-sink-null.h" +#include "core/log-sink-std.h" +#include "core/log.h" + +#include "launcher/avs-config.h" +#include "launcher/avs.h" +#include "launcher/bootstrap-config.h" +#include "launcher/ea3-ident-config.h" +#include "launcher/eamuse-config.h" +#include "launcher/eamuse.h" +#include "launcher/launcher-config.h" +#include "launcher/module.h" +#include "launcher/property-util.h" + +#include "util/str.h" + +static bool _bootstrap_log_property_configs; +static struct module_context _bootstrap_module_context; + +static void _bootstrap_eamuse_ea3_ident_config_inject( + struct property_node *node, const struct ea3_ident_config *ea3_ident_config) +{ + eamuse_config_id_softid_set(node, ea3_ident_config->softid); + eamuse_config_id_hardid_set(node, ea3_ident_config->hardid); + eamuse_config_id_pcbid_set(node, ea3_ident_config->pcbid); + eamuse_config_soft_model_set(node, ea3_ident_config->model); + eamuse_config_soft_dest_set(node, ea3_ident_config->dest); + eamuse_config_soft_spec_set(node, ea3_ident_config->spec); + eamuse_config_soft_rev_set(node, ea3_ident_config->rev); + eamuse_config_soft_ext_set(node, ea3_ident_config->ext); +} + +static void +_bootstrap_avs_config_force_overrides_apply(struct property_node *node) +{ + log_assert(node); + + avs_config_mode_product_set(node, true); + avs_config_net_raw_set(node, true); + avs_config_net_eaudp_set(node, true); + avs_config_sntp_ea_set(node, true); +} + +static void _bootstrap_avs_config_log_overrides_apply( + struct property_node *node, const struct bootstrap_log_config *log_config) +{ + log_assert(node); + log_assert(log_config); + + avs_config_log_level_set(node, log_config->level); + avs_config_log_name_set(node, log_config->name); + avs_config_log_file_set(node, log_config->file); + avs_config_log_buffer_size_set(node, log_config->bufsz); + avs_config_log_output_delay_set(node, log_config->output_delay_ms); + avs_config_log_enable_console_set(node, log_config->enable_console); + avs_config_log_enable_sci_set(node, log_config->enable_sci); + avs_config_log_enable_net_set(node, log_config->enable_net); + avs_config_log_enable_file_set(node, log_config->enable_file); + avs_config_log_rotate_set(node, log_config->rotate); + avs_config_log_append_set(node, log_config->append); + avs_config_log_count_set(node, log_config->count); +} + +static enum core_log_bt_log_level _bootstrap_log_map_level(const char *level) +{ + if (str_eq(level, "fatal")) { + return CORE_LOG_BT_LOG_LEVEL_FATAL; + } else if (str_eq(level, "warning")) { + return CORE_LOG_BT_LOG_LEVEL_WARNING; + } else if (str_eq(level, "info")) { + return CORE_LOG_BT_LOG_LEVEL_INFO; + } else if (str_eq(level, "misc")) { + return CORE_LOG_BT_LOG_LEVEL_MISC; + } else if (str_eq(level, "all")) { + return CORE_LOG_BT_LOG_LEVEL_MISC; + } else if (str_eq(level, "disable")) { + return CORE_LOG_BT_LOG_LEVEL_OFF; + } else if (str_eq(level, "default")) { + return CORE_LOG_BT_LOG_LEVEL_WARNING; + } else { + log_fatal("Unknown log level string %s", level); + } +} + +void bootstrap_init(bool log_property_configs) +{ + log_info("init"); + + _bootstrap_log_property_configs = log_property_configs; + + log_misc("init done"); +} + +void bootstrap_log_init(const struct bootstrap_log_config *config) +{ + struct core_log_sink sinks[2]; + struct core_log_sink sink_composed; + enum core_log_bt_log_level level; + + log_assert(config); + + log_info("log init"); + + // Shutdown old setup + core_log_bt_fini(); + + if (config->enable_file && strlen(config->file) > 0 && + config->enable_console) { + core_log_sink_std_out_open(true, &sinks[0]); + core_log_sink_file_open( + config->file, + config->append, + config->rotate, + config->count, + &sinks[1]); + core_log_sink_list_open(sinks, 2, &sink_composed); + } else if (config->enable_file && strlen(config->file) > 0) { + core_log_sink_file_open( + config->file, + config->append, + config->rotate, + config->count, + &sink_composed); + } else if (config->enable_console) { + core_log_sink_std_out_open(true, &sink_composed); + } else { + core_log_sink_null_open(&sink_composed); + } + + core_log_bt_init(&sink_composed); + + level = _bootstrap_log_map_level(config->level); + core_log_bt_level_set(level); + + log_misc("log init done"); +} + +void bootstrap_default_files_create( + const struct bootstrap_default_file_config *config) +{ + log_assert(config); + + log_info("default files create"); + + for (int i = 0; i < DEFAULT_FILE_MAX; i++) { + if (strlen(config->file[i].src) > 0 && + strlen(config->file[i].dst) > 0) { + avs_fs_file_copy(config->file[i].src, config->file[i].dst); + } + } + + log_misc("default files create done"); +} + +void bootstrap_avs_init( + const struct bootstrap_boot_config *config, + const struct bootstrap_log_config *log_config, + struct property *override_property) +{ + struct property *file_property; + struct property *merged_property; + struct property_node *root_node; + + log_assert(config); + log_assert(log_config); + log_assert(override_property); + + log_info("avs init"); + + file_property = avs_config_load(config->config_file); + + if (_bootstrap_log_property_configs) { + log_misc("avs-config from file: %s", config->config_file); + property_util_log(file_property); + } + + merged_property = + avs_config_property_merge(file_property, override_property); + + property_util_free(file_property); + + if (_bootstrap_log_property_configs) { + log_misc("avs-config merged with overrides"); + property_util_log(merged_property); + } + + root_node = avs_config_root_get(merged_property); + + _bootstrap_avs_config_force_overrides_apply(root_node); + _bootstrap_avs_config_log_overrides_apply(root_node, log_config); + + if (_bootstrap_log_property_configs) { + log_misc("avs-config final"); + property_util_log(merged_property); + } + + avs_fs_assert_root_device_exists(root_node); + + log_misc("Creating AVS file system directories..."); + + avs_fs_mountpoints_fs_dirs_create(root_node); + + avs_init(root_node, config->avs_heap_size, config->std_heap_size); + + property_util_free(merged_property); + + log_misc("avs init done"); +} + +void bootstrap_eamuse_init( + const struct bootstrap_eamuse_config *config, + const struct ea3_ident_config *ea3_ident_config, + struct property *override_property) +{ + struct property *file_property; + struct property *merged_property; + struct property_node *root_node; + + log_assert(config); + log_assert(ea3_ident_config); + log_assert(override_property); + + log_info("eamuse init"); + + if (config->enable) { + file_property = eamuse_config_avs_load(config->config_file); + + if (_bootstrap_log_property_configs) { + log_misc("eamuse-config from file: %s", config->config_file); + property_util_log(file_property); + } + + merged_property = property_util_merge(file_property, override_property); + + property_util_free(file_property); + + if (_bootstrap_log_property_configs) { + log_misc("eamuse-config merged with overrides"); + property_util_log(merged_property); + } + + root_node = eamuse_config_root_get(merged_property); + + _bootstrap_eamuse_ea3_ident_config_inject(root_node, ea3_ident_config); + + if (_bootstrap_log_property_configs) { + log_misc("eamuse-config final"); + property_util_log(merged_property); + } + + eamuse_init(root_node); + + property_util_free(merged_property); + } else { + log_warning("Eamuse disabled"); + } + + log_misc("eamuse init done"); +} + +void bootstrap_module_init( + const struct bootstrap_module_config *module_config, + const struct array *iat_hook_dlls) +{ + log_assert(module_config); + log_assert(iat_hook_dlls); + + log_info("module init"); + + if (iat_hook_dlls->nitems > 0) { + log_info( + "Load game DLL with IAT hooks (%d): %s", + (uint32_t) iat_hook_dlls->nitems, + module_config->file); + + module_with_iat_hooks_init( + &_bootstrap_module_context, module_config->file, iat_hook_dlls); + } else { + log_info("Load game DLL: %s", module_config->file); + + module_init(&_bootstrap_module_context, module_config->file); + } + + log_misc("module init done"); +} + +void bootstrap_module_game_init( + const struct bootstrap_module_config *module_config, + struct ea3_ident_config *ea3_ident_config) +{ + struct property_node *node; + + log_assert(module_config); + log_assert(ea3_ident_config); + + log_info("module game init"); + + node = property_search(module_config->app_config, NULL, "/param"); + + if (!node) { + log_fatal("Missing param node on app-config"); + } + + if (_bootstrap_log_property_configs) { + log_misc("app-config"); + property_util_node_log(node); + } + + module_init_invoke(&_bootstrap_module_context, ea3_ident_config, node); + + log_misc("module game init done"); +} + +void bootstrap_module_game_run() +{ + log_info("module game run"); + + module_main_invoke(&_bootstrap_module_context); +} + +void bootstrap_module_game_fini() +{ + log_info("module game fini"); + + module_fini(&_bootstrap_module_context); +} + +void bootstrap_avs_fini() +{ + log_info("avs fini"); + + avs_fini(); +} + +void bootstrap_eamuse_fini(const struct bootstrap_eamuse_config *config) +{ + log_info("eamuse fini"); + + if (config->enable) { + eamuse_fini(); + } +} \ No newline at end of file diff --git a/src/main/launcher/bootstrap.h b/src/main/launcher/bootstrap.h new file mode 100644 index 0000000..4deab8f --- /dev/null +++ b/src/main/launcher/bootstrap.h @@ -0,0 +1,32 @@ +#ifndef LAUNCHER_BOOTSTRAP_H +#define LAUNCHER_BOOTSTRAP_H + +#include "launcher/bootstrap-config.h" +#include "launcher/ea3-ident-config.h" + +#include "util/array.h" + +void bootstrap_init(bool log_property_configs); +void bootstrap_log_init(const struct bootstrap_log_config *config); +void bootstrap_default_files_create( + const struct bootstrap_default_file_config *config); +void bootstrap_avs_init( + const struct bootstrap_boot_config *config, + const struct bootstrap_log_config *log_config, + struct property *override_property); +void bootstrap_eamuse_init( + const struct bootstrap_eamuse_config *config, + const struct ea3_ident_config *ea3_ident_config, + struct property *override_property); +void bootstrap_module_init( + const struct bootstrap_module_config *module_config, + const struct array *iat_hook_dlls); +void bootstrap_module_game_init( + const struct bootstrap_module_config *module_config, + struct ea3_ident_config *ea3_ident_config); +void bootstrap_module_game_run(); +void bootstrap_module_game_fini(); +void bootstrap_avs_fini(); +void bootstrap_eamuse_fini(const struct bootstrap_eamuse_config *config); + +#endif \ No newline at end of file diff --git a/src/main/launcher/debug.c b/src/main/launcher/debug.c new file mode 100644 index 0000000..2f40e33 --- /dev/null +++ b/src/main/launcher/debug.c @@ -0,0 +1,33 @@ + +#define LOG_MODULE "debug" + +#include +#include + +#include "core/log.h" + +#include "launcher/debug.h" + +void debug_remote_debugger_trap() +{ + BOOL res; + + log_info("Waiting until debugger attaches to remote process..."); + + while (true) { + res = FALSE; + + if (!CheckRemoteDebuggerPresent(GetCurrentProcess(), &res)) { + log_fatal( + "CheckRemoteDebuggerPresent failed: %08x", + (unsigned int) GetLastError()); + } + + if (res) { + log_info("Debugger attached, resuming"); + break; + } + + Sleep(1000); + } +} \ No newline at end of file diff --git a/src/main/launcher/debug.h b/src/main/launcher/debug.h new file mode 100644 index 0000000..f57ca8b --- /dev/null +++ b/src/main/launcher/debug.h @@ -0,0 +1,6 @@ +#ifndef LAUNCHER_DEBUG_H +#define LAUNCHER_DEBUG_H + +void debug_remote_debugger_trap(); + +#endif \ No newline at end of file diff --git a/src/main/launcher/ea3-config.c b/src/main/launcher/ea3-config.c deleted file mode 100644 index 684ba46..0000000 --- a/src/main/launcher/ea3-config.c +++ /dev/null @@ -1,190 +0,0 @@ -#include - -#include "imports/avs.h" - -#include "launcher/ea3-config.h" -#include "launcher/module.h" - -#include "util/defs.h" -#include "util/hex.h" -#include "util/log.h" -#include "util/str.h" - -PSMAP_BEGIN(ea3_ident_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident, softid, "/ea3/id/softid", "") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident, hardid, "/ea3/id/hardid", "") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident, pcbid, "/ea3/id/pcbid", "") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, model, "/ea3/soft/model") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, dest, "/ea3/soft/dest") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, spec, "/ea3/soft/spec") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, rev, "/ea3/soft/rev") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, ext, "/ea3/soft/ext") -PSMAP_END - -void ea3_ident_init(struct ea3_ident *ident) -{ - memset(ident, 0, sizeof(*ident)); -} - -bool ea3_ident_from_property( - struct ea3_ident *ident, struct property *ea3_config) -{ - return property_psmap_import(ea3_config, NULL, ident, ea3_ident_psmap); -} - -void ea3_ident_hardid_from_ethernet(struct ea3_ident *ident) -{ - struct avs_net_interface netif; - int result; - - result = avs_net_ctrl(1, &netif, sizeof(netif)); - - if (result < 0) { - log_fatal( - "avs_net_ctrl call to get MAC address returned error: %d", result); - } - - ident->hardid[0] = '0'; - ident->hardid[1] = '1'; - ident->hardid[2] = '0'; - ident->hardid[3] = '0'; - - hex_encode_uc( - netif.mac_addr, - sizeof(netif.mac_addr), - ident->hardid + 4, - sizeof(ident->hardid) - 4); -} - -bool ea3_ident_invoke_module_init( - struct ea3_ident *ident, - const struct module_context *module, - struct property_node *app_config) -{ - char sidcode_short[17]; - char sidcode_long[21]; - char security_code[9]; - bool ok; - - /* Set up security env vars */ - - str_format( - security_code, - lengthof(security_code), - "G*%s%s%s%s", - ident->model, - ident->dest, - ident->spec, - ident->rev); - - std_setenv("/env/boot/version", "0.0.0"); - std_setenv("/env/profile/security_code", security_code); - std_setenv("/env/profile/system_id", ident->pcbid); - std_setenv("/env/profile/account_id", ident->pcbid); - std_setenv("/env/profile/license_id", ident->softid); - std_setenv("/env/profile/software_id", ident->softid); - std_setenv("/env/profile/hardware_id", ident->hardid); - - /* Set up the short sidcode string, let dll_entry_init mangle it */ - - str_format( - sidcode_short, - lengthof(sidcode_short), - "%s%s%s%s%s", - ident->model, - ident->dest, - ident->spec, - ident->rev, - ident->ext); - - /* Set up long-form sidcode env var */ - - str_format( - sidcode_long, - lengthof(sidcode_long), - "%s:%s:%s:%s:%s", - ident->model, - ident->dest, - ident->spec, - ident->rev, - ident->ext); - - /* Set this up beforehand, as certain games require it in dll_entry_init */ - - std_setenv("/env/profile/soft_id_code", sidcode_long); - - ok = module_context_invoke_init(module, sidcode_short, app_config); - - if (!ok) { - return false; - } - - /* Back-propagate sidcode, as some games modify it during init */ - - memcpy(ident->model, sidcode_short + 0, sizeof(ident->model) - 1); - ident->dest[0] = sidcode_short[3]; - ident->spec[0] = sidcode_short[4]; - ident->rev[0] = sidcode_short[5]; - memcpy(ident->ext, sidcode_short + 6, sizeof(ident->ext)); - - /* Set up long-form sidcode env var again */ - - str_format( - sidcode_long, - lengthof(sidcode_long), - "%s:%s:%s:%s:%s", - ident->model, - ident->dest, - ident->spec, - ident->rev, - ident->ext); - - std_setenv("/env/profile/soft_id_code", sidcode_long); - - return true; -} - -void ea3_ident_to_property( - const struct ea3_ident *ident, struct property *ea3_config) -{ - struct property_node *node; - int i; - - for (i = 0; ea3_ident_psmap[i].type != 0xFF; i++) { - node = property_search(ea3_config, 0, ea3_ident_psmap[i].path); - - if (node != NULL) { - property_node_remove(node); - } - } - - property_psmap_export(ea3_config, NULL, ident, ea3_ident_psmap); -} - -void ea3_ident_replace_property_bool( - struct property_node *node, const char *name, uint8_t val) -{ - struct property_node *tmp; - - tmp = property_search(NULL, node, name); - - if (tmp) { - property_node_remove(tmp); - } - - property_node_create(NULL, node, PROPERTY_TYPE_BOOL, name, val); -} - -void ea3_ident_replace_property_str( - struct property_node *node, const char *name, const char *val) -{ - struct property_node *tmp; - - tmp = property_search(NULL, node, name); - - if (tmp) { - property_node_remove(tmp); - } - - tmp = property_node_create(NULL, node, PROPERTY_TYPE_STR, name, val); -} diff --git a/src/main/launcher/ea3-config.h b/src/main/launcher/ea3-config.h deleted file mode 100644 index ada4400..0000000 --- a/src/main/launcher/ea3-config.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef LAUNCHER_EA3_CONFIG_H -#define LAUNCHER_EA3_CONFIG_H - -#include "imports/avs.h" - -#include "launcher/module.h" - -/* N.B. even though this might look like a Konami ABI, this is purely an - internal data structure. */ - -struct ea3_ident { - /* psmapped structure offset can't be zero for some stupid reason */ - - uint32_t dummy; - - /* Initialized from ea3-config.xml, then fed back from sidcode_short */ - - char model[4]; - char dest[4]; - char spec[4]; - char rev[4]; - char ext[11]; - - /* Initialized from ea3-config.xml (hardware_id defaults to MAC addr) */ - - char softid[24]; - char hardid[24]; - char pcbid[24]; -}; - -void ea3_ident_init(struct ea3_ident *ident); -bool ea3_ident_from_property( - struct ea3_ident *ident, struct property *ea3_config); -void ea3_ident_hardid_from_ethernet(struct ea3_ident *ident); -bool ea3_ident_invoke_module_init( - struct ea3_ident *ident, - const struct module_context *module, - struct property_node *app_config); -void ea3_ident_to_property( - const struct ea3_ident *ident, struct property *ea3_config); -void ea3_ident_replace_property_bool( - struct property_node *node, const char *name, uint8_t val); -void ea3_ident_replace_property_str( - struct property_node *node, const char *name, const char *val); - -#endif diff --git a/src/main/launcher/ea3-ident-config.c b/src/main/launcher/ea3-ident-config.c new file mode 100644 index 0000000..e8c5c4f --- /dev/null +++ b/src/main/launcher/ea3-ident-config.c @@ -0,0 +1,104 @@ +#define LOG_MODULE "ea3-ident-config" + +#include + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/ea3-ident-config.h" +#include "launcher/property-util.h" + +#include "util/defs.h" +#include "util/hex.h" +#include "util/str.h" + +#define ROOT_NODE "/ea3_conf" + +PSMAP_BEGIN(ea3_ident_config_psmap) +PSMAP_OPTIONAL( + PSMAP_TYPE_STR, struct ea3_ident_config, softid, "/id/softid", "") +PSMAP_OPTIONAL( + PSMAP_TYPE_STR, struct ea3_ident_config, hardid, "/id/hardid", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident_config, pcbid, "/id/pcbid", "") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, model, "/soft/model") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, dest, "/soft/dest") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, spec, "/soft/spec") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, rev, "/soft/rev") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, ext, "/soft/ext") +PSMAP_END + +void ea3_ident_config_init(struct ea3_ident_config *config) +{ + memset(config, 0, sizeof(*config)); +} + +void ea3_ident_config_from_file_load( + const char *path, struct ea3_ident_config *config) +{ + struct property *property; + + log_assert(path); + log_assert(config); + + log_info("Loading from file path: %s", path); + + property = property_util_load(path); + + ea3_ident_config_load(property, config); + + property_util_free(property); +} + +void ea3_ident_config_load( + struct property *property, struct ea3_ident_config *config) +{ + struct property_node *node; + + log_assert(property); + log_assert(config); + + node = property_search(property, NULL, ROOT_NODE); + + if (node == NULL) { + log_fatal("Root node '" ROOT_NODE "' missing"); + } + + if (!property_psmap_import( + property, node, config, ea3_ident_config_psmap)) { + log_fatal("Error reading config file"); + } +} + +bool ea3_ident_config_hardid_is_defined(struct ea3_ident_config *config) +{ + log_assert(config); + + return strlen(config->hardid) > 0; +} + +void ea3_ident_config_hardid_from_ethernet_set(struct ea3_ident_config *config) +{ + struct avs_net_interface netif; + int result; + + log_assert(config); + + result = avs_net_ctrl(1, &netif, sizeof(netif)); + + if (result < 0) { + log_fatal( + "avs_net_ctrl call to get MAC address returned error: %d", result); + } + + config->hardid[0] = '0'; + config->hardid[1] = '1'; + config->hardid[2] = '0'; + config->hardid[3] = '0'; + + hex_encode_uc( + netif.mac_addr, + sizeof(netif.mac_addr), + config->hardid + 4, + sizeof(config->hardid) - 4); +} \ No newline at end of file diff --git a/src/main/launcher/ea3-ident-config.h b/src/main/launcher/ea3-ident-config.h new file mode 100644 index 0000000..1a6dc7f --- /dev/null +++ b/src/main/launcher/ea3-ident-config.h @@ -0,0 +1,37 @@ +#ifndef LAUNCHER_EA3_IDENT_CONFIG_H +#define LAUNCHER_EA3_IDENT_CONFIG_H + +#include "imports/avs.h" + +/* N.B. even though this might look like a Konami ABI, this is purely an + internal data structure. */ + +struct ea3_ident_config { + /* psmapped structure offset can't be zero for some stupid reason */ + + uint32_t dummy; + + /* Initialized from ea3-config.xml, then fed back from sidcode_short */ + + char model[4]; + char dest[4]; + char spec[4]; + char rev[4]; + char ext[11]; + + /* Initialized from ea3-config.xml (hardware_id defaults to MAC addr) */ + + char softid[24]; + char hardid[24]; + char pcbid[24]; +}; + +void ea3_ident_config_init(struct ea3_ident_config *config); +void ea3_ident_config_from_file_load( + const char *path, struct ea3_ident_config *config); +void ea3_ident_config_load( + struct property *property, struct ea3_ident_config *config); +bool ea3_ident_config_hardid_is_defined(struct ea3_ident_config *config); +void ea3_ident_config_hardid_from_ethernet_set(struct ea3_ident_config *config); + +#endif diff --git a/src/main/launcher/eamuse-config.c b/src/main/launcher/eamuse-config.c new file mode 100644 index 0000000..020e17a --- /dev/null +++ b/src/main/launcher/eamuse-config.c @@ -0,0 +1,125 @@ +#define LOG_MODULE "eamuse-config" + +#include + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/ea3-ident-config.h" +#include "launcher/eamuse-config.h" +#include "launcher/property-util.h" + +#define EAMUSE_CONFIG_ROOT_NODE "/ea3" + +struct property *eamuse_config_avs_load(const char *path) +{ + struct property *property; + + log_assert(path); + + log_misc("Loading from avs path: %s", path); + + property = property_util_avs_fs_load(path); + + // Check if root node exists, call already errors if not + eamuse_config_root_get(property); + + return property; +} + +struct property_node *eamuse_config_root_get(struct property *property) +{ + struct property_node *node; + + log_assert(property); + + node = property_search(property, 0, EAMUSE_CONFIG_ROOT_NODE); + + if (node == NULL) { + log_fatal("Root node " EAMUSE_CONFIG_ROOT_NODE + " in eamuse config missing"); + } + + return node; +} + +void eamuse_config_id_softid_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "id/softid", value); +} + +void eamuse_config_id_hardid_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "id/hardid", value); +} + +void eamuse_config_id_pcbid_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "id/pcbid", value); +} + +void eamuse_config_soft_model_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "soft/model", value); +} + +void eamuse_config_soft_dest_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "soft/dest", value); +} + +void eamuse_config_soft_spec_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "soft/spec", value); +} + +void eamuse_config_soft_rev_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "soft/rev", value); +} + +void eamuse_config_soft_ext_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "soft/ext", value); +} + +void eamuse_config_network_url_slash_set(struct property_node *node, bool value) +{ + log_assert(node); + + property_util_node_bool_replace(NULL, node, "network/url_slash", value); +} + +void eamuse_config_network_service_url_set( + struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "network/services", value); +} \ No newline at end of file diff --git a/src/main/launcher/eamuse-config.h b/src/main/launcher/eamuse-config.h new file mode 100644 index 0000000..2cba227 --- /dev/null +++ b/src/main/launcher/eamuse-config.h @@ -0,0 +1,23 @@ +#ifndef LAUNCHER_EAMUSE_CONFIG_H +#define LAUNCHER_EAMUSE_CONFIG_H + +#include "imports/avs.h" + +struct property *eamuse_config_avs_load(const char *path); +struct property_node *eamuse_config_root_get(struct property *property); + +void eamuse_config_id_softid_set(struct property_node *node, const char *value); +void eamuse_config_id_hardid_set(struct property_node *node, const char *value); +void eamuse_config_id_pcbid_set(struct property_node *node, const char *value); +void eamuse_config_soft_model_set( + struct property_node *node, const char *value); +void eamuse_config_soft_dest_set(struct property_node *node, const char *value); +void eamuse_config_soft_spec_set(struct property_node *node, const char *value); +void eamuse_config_soft_rev_set(struct property_node *node, const char *value); +void eamuse_config_soft_ext_set(struct property_node *node, const char *value); +void eamuse_config_network_url_slash_set( + struct property_node *node, bool value); +void eamuse_config_network_service_url_set( + struct property_node *node, const char *value); + +#endif \ No newline at end of file diff --git a/src/main/launcher/eamuse.c b/src/main/launcher/eamuse.c new file mode 100644 index 0000000..39e560d --- /dev/null +++ b/src/main/launcher/eamuse.c @@ -0,0 +1,25 @@ +#define LOG_MODULE "eamuse" + +#include "core/log.h" + +#include "imports/avs-ea3.h" + +void eamuse_init(struct property_node *node) +{ + log_assert(node); + + log_info("init"); + + ea3_boot(node); + + log_misc("init done"); +} + +void eamuse_fini() +{ + log_info("fini"); + + ea3_shutdown(); + + log_misc("fini done"); +} \ No newline at end of file diff --git a/src/main/launcher/eamuse.h b/src/main/launcher/eamuse.h new file mode 100644 index 0000000..1cd1f7e --- /dev/null +++ b/src/main/launcher/eamuse.h @@ -0,0 +1,9 @@ +#ifndef LAUNCHER_EAMUSE_H +#define LAUNCHER_EAMUSE_H + +#include "imports/avs.h" + +void eamuse_init(struct property_node *node); +void eamuse_fini(); + +#endif \ No newline at end of file diff --git a/src/main/launcher/hook.c b/src/main/launcher/hook.c new file mode 100644 index 0000000..d7be37a --- /dev/null +++ b/src/main/launcher/hook.c @@ -0,0 +1,34 @@ +#define LOG_MODULE "hook" + +#include + +#include "core/log.h" + +#include "launcher/hook.h" + +void hook_load_dll(const char *path) +{ + log_assert(path); + + log_info("Load hook dll: %s", path); + + if (LoadLibraryA(path) == NULL) { + LPSTR buffer; + + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR) &buffer, + 0, + NULL); + + log_fatal("%s: Failed to load hook DLL: %s", path, buffer); + + LocalFree(buffer); + } + + log_misc("Load hook dll done"); +} \ No newline at end of file diff --git a/src/main/launcher/hook.h b/src/main/launcher/hook.h new file mode 100644 index 0000000..9d0c5d4 --- /dev/null +++ b/src/main/launcher/hook.h @@ -0,0 +1,6 @@ +#ifndef LAUNCHER_HOOK_H +#define LAUNCHER_HOOK_H + +void hook_load_dll(const char *path); + +#endif \ No newline at end of file diff --git a/src/main/launcher/launcher-config.c b/src/main/launcher/launcher-config.c new file mode 100644 index 0000000..c71abe5 --- /dev/null +++ b/src/main/launcher/launcher-config.c @@ -0,0 +1,371 @@ +#define LOG_MODULE "launcher-config" + +#include + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/launcher-config.h" +#include "launcher/property-util.h" + +#include "util/mem.h" +#include "util/str.h" + +// clang-format off +PSMAP_BEGIN(launcher_debug_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, remote_debugger, + "debug/remote_debugger", false) + PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, log_property_configs, + "debug/log_property_configs", false) +PSMAP_END +// clang-format on + +#define ROOT_NODE "/launcher" +#define MAX_LAYER_CONFIG_NODES 8 + +#define NODE_MISSING_FATAL(subnode) \ + log_fatal("%s/%s: Node missing", ROOT_NODE, subnode); +#define NODE_LOADING_FATAL(subnode) \ + log_fatal("%s/%s: Node loading", ROOT_NODE, subnode); + +static struct property * +_launcher_config_layered_config_nodes_load(struct property_node *node) +{ + char kind[64]; + char file[MAX_PATH]; + int res; + int cnt; + + struct property_node *cur; + struct property *config_property[MAX_LAYER_CONFIG_NODES]; + struct property *merged_property; + + log_assert(node); + + cnt = 0; + cur = property_search(NULL, node, "config"); + + while (cur) { + if (cnt >= MAX_LAYER_CONFIG_NODES) { + log_fatal( + "Exceeding max supported config nodes for layering, max is %d", + MAX_LAYER_CONFIG_NODES); + } + + res = property_node_refer( + NULL, cur, "kind@", PROPERTY_TYPE_ATTR, kind, sizeof(kind)); + + if (res < 0) { + log_fatal("Failed reading 'kind' attribute value of config node"); + } + + if (!strcmp(kind, "file")) { + property_node_read(cur, PROPERTY_TYPE_STR, file, sizeof(file)); + + config_property[cnt] = property_util_load(file); + } else if (!strcmp(kind, "inline")) { + // The nested child is the actual root of the inline, not the outer + // node + cur = property_node_traversal(cur, TRAVERSE_FIRST_CHILD); + + config_property[cnt] = property_util_node_extract(cur); + } else { + log_fatal( + "Unsupported 'kind' attribute value '%s' of config node", kind); + } + + cnt++; + cur = property_node_traversal(cur, TRAVERSE_NEXT_SEARCH_RESULT); + } + + if (cnt == 0) { + return NULL; + } + + merged_property = property_util_many_merge(config_property, cnt); + + for (int i = 0; i < cnt; i++) { + property_util_free(config_property[i]); + } + + return merged_property; +} + +static void _launcher_config_hook_dlls_parse( + struct property_node *node, + const char *node_path, + char dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]) +{ + int cnt; + struct property_node *cur; + + cnt = 0; + cur = property_search(NULL, node, node_path); + + while (cur) { + if (cnt >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { + log_warning( + "Currently not supporting more than %d dlls, skipping " + "remaining", + cnt); + break; + } + + property_node_read(cur, PROPERTY_TYPE_STR, dlls[cnt], MAX_PATH); + + cnt++; + cur = property_node_traversal(cur, TRAVERSE_NEXT_SEARCH_RESULT); + } +} + +static void _launcher_config_bootstrap_load( + struct property_node *node, struct launcher_bootstrap_config *config) +{ + int res; + + log_assert(node); + log_assert(config); + + res = property_node_refer( + NULL, + node, + "selector", + PROPERTY_TYPE_STR, + config->selector, + sizeof(config->selector)); + + if (res < 0) { + NODE_MISSING_FATAL("bootstrap/selector"); + } + + config->property = _launcher_config_layered_config_nodes_load(node); + + if (config->property == NULL) { + NODE_MISSING_FATAL("bootstrap/config"); + } +} + +static void _launcher_config_hook_load( + struct property_node *node, struct launcher_hook_config *config) +{ + log_assert(node); + log_assert(config); + + _launcher_config_hook_dlls_parse(node, "hook_dlls/dll", config->hook_dlls); + _launcher_config_hook_dlls_parse( + node, "before_hook_dlls/dll", config->before_hook_dlls); + _launcher_config_hook_dlls_parse( + node, "iat_hook_dlls/dll", config->iat_hook_dlls); +} + +static void _launcher_config_debug_load( + struct property_node *node, struct launcher_debug_config *config) +{ + log_assert(node); + log_assert(config); + + if (!property_psmap_import(NULL, node, config, launcher_debug_psmap)) { + NODE_LOADING_FATAL("debug"); + } +} + +void launcher_config_init(struct launcher_config *config) +{ + log_assert(config); + + memset(config->bootstrap.selector, 0, sizeof(config->bootstrap.selector)); + config->bootstrap.property = NULL; + + config->avs.property = NULL; + + config->ea3_ident.property = NULL; + + config->eamuse.property = NULL; + + memset(config->hook.hook_dlls, 0, sizeof(config->hook.hook_dlls)); + memset( + config->hook.before_hook_dlls, + 0, + sizeof(config->hook.before_hook_dlls)); + memset(config->hook.iat_hook_dlls, 0, sizeof(config->hook.iat_hook_dlls)); + + config->debug.remote_debugger = false; + config->debug.log_property_configs = false; +} + +void launcher_config_load( + struct property *property, struct launcher_config *config) +{ + struct property_node *root_node; + struct property_node *node; + avs_error error; + + log_assert(property); + log_assert(config); + + root_node = property_search(property, NULL, ROOT_NODE); + + if (root_node == NULL) { + NODE_MISSING_FATAL(""); + } + + error = property_node_refer( + NULL, + root_node, + "version@", + PROPERTY_TYPE_ATTR, + &config->version, + sizeof(uint32_t)); + + if (AVS_IS_ERROR(error)) { + log_fatal("Missing version attribute on root node"); + } + + // if (config->version != 1) { + // log_fatal("Unsupported version of launcher configuration: %d", + // config->version); + // } + + node = property_search(NULL, root_node, "bootstrap"); + + if (node == NULL) { + NODE_MISSING_FATAL("bootstrap"); + } + + _launcher_config_bootstrap_load(node, &config->bootstrap); + + node = property_search(NULL, root_node, "avs"); + + if (node) { + config->avs.property = _launcher_config_layered_config_nodes_load(node); + } + + node = property_search(NULL, root_node, "ea3_ident"); + + if (node) { + config->ea3_ident.property = + _launcher_config_layered_config_nodes_load(node); + } + + node = property_search(NULL, root_node, "eamuse"); + + if (node) { + config->eamuse.property = + _launcher_config_layered_config_nodes_load(node); + } + + node = property_search(NULL, root_node, "hook"); + + if (node) { + _launcher_config_hook_load(node, &config->hook); + } + + _launcher_config_debug_load(root_node, &config->debug); +} + +bool launcher_config_add_hook_dll( + struct launcher_config *config, const char *path) +{ + int i; + + log_assert(config); + log_assert(path); + + i = 0; + + while (i < LAUNCHER_CONFIG_MAX_HOOK_DLL) { + if (strlen(config->hook.hook_dlls[i]) == 0) { + break; + } + + i++; + } + + if (i >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { + return false; + } + + str_cpy(config->hook.hook_dlls[i], sizeof(config->hook.hook_dlls[i]), path); + + return true; +} + +bool launcher_config_add_before_hook_dll( + struct launcher_config *config, const char *path) +{ + int i; + + log_assert(config); + log_assert(path); + + i = 0; + + while (i < LAUNCHER_CONFIG_MAX_HOOK_DLL) { + if (strlen(config->hook.before_hook_dlls[i]) == 0) { + break; + } + + i++; + } + + if (i >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { + return false; + } + + str_cpy( + config->hook.before_hook_dlls[i], + sizeof(config->hook.before_hook_dlls[i]), + path); + + return true; +} + +bool launcher_config_add_iat_hook_dll( + struct launcher_config *config, const char *path) +{ + int i; + + log_assert(config); + log_assert(path); + + i = 0; + + while (i < LAUNCHER_CONFIG_MAX_HOOK_DLL) { + if (strlen(config->hook.iat_hook_dlls[i]) == 0) { + break; + } + + i++; + } + + if (i >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { + return false; + } + + str_cpy( + config->hook.iat_hook_dlls[i], + sizeof(config->hook.iat_hook_dlls[i]), + path); + + return true; +} + +void launcher_config_fini(struct launcher_config *config) +{ + log_assert(config); + + property_util_free(config->bootstrap.property); + + if (config->avs.property) { + property_util_free(config->avs.property); + } + + if (config->ea3_ident.property) { + property_util_free(config->ea3_ident.property); + } + + if (config->eamuse.property) { + property_util_free(config->eamuse.property); + } +} \ No newline at end of file diff --git a/src/main/launcher/launcher-config.h b/src/main/launcher/launcher-config.h new file mode 100644 index 0000000..7d6b8a6 --- /dev/null +++ b/src/main/launcher/launcher-config.h @@ -0,0 +1,56 @@ +#ifndef LAUNCHER_CONFIG_H +#define LAUNCHER_CONFIG_H + +#include + +#include "util/array.h" + +#define LAUNCHER_CONFIG_MAX_HOOK_DLL 16 + +struct launcher_config { + uint32_t version; + + struct launcher_bootstrap_config { + char selector[128]; + struct property *property; + } bootstrap; + + struct launcher_avs_config { + struct property *property; + } avs; + + struct launcher_ea3_ident_config { + struct property *property; + } ea3_ident; + + struct launcher_eamuse_config { + struct property *property; + } eamuse; + + struct launcher_hook_config { + char hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]; + char before_hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]; + char iat_hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]; + } hook; + + struct launcher_debug_config { + bool remote_debugger; + bool log_property_configs; + } debug; +}; + +void launcher_config_init(struct launcher_config *config); + +void launcher_config_load( + struct property *property, struct launcher_config *config); + +bool launcher_config_add_hook_dll( + struct launcher_config *config, const char *path); +bool launcher_config_add_before_hook_dll( + struct launcher_config *config, const char *path); +bool launcher_config_add_iat_hook_dll( + struct launcher_config *config, const char *path); + +void launcher_config_fini(struct launcher_config *config); + +#endif \ No newline at end of file diff --git a/src/main/launcher/launcher.c b/src/main/launcher/launcher.c new file mode 100644 index 0000000..9d1324d --- /dev/null +++ b/src/main/launcher/launcher.c @@ -0,0 +1,589 @@ +#define LOG_MODULE "launcher" + +#include + +#include +#include +#include +#include + +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log-sink-file.h" +#include "core/log-sink-list.h" +#include "core/log-sink-std.h" +#include "core/log.h" + +#include "imports/avs-ea3.h" +#include "imports/avs.h" + +#include "launcher/avs-config.h" +#include "launcher/avs.h" +#include "launcher/bootstrap-config.h" +#include "launcher/bootstrap.h" +#include "launcher/debug.h" +#include "launcher/ea3-ident-config.h" +#include "launcher/eamuse-config.h" +#include "launcher/eamuse.h" +#include "launcher/hook.h" +#include "launcher/launcher-config.h" +#include "launcher/module.h" +#include "launcher/options.h" +#include "launcher/property-util.h" +#include "launcher/stubs.h" +#include "launcher/version.h" + +#include "util/debug.h" +#include "util/defs.h" +#include "util/fs.h" +#include "util/os.h" +#include "util/proc.h" +#include "util/signal.h" +#include "util/str.h" + +static void _launcher_log_header() +{ + log_info( + "\n" + " .__ .__ \n" + " | | _____ __ __ ____ ____ | |__ ___________ \n" + " | | \\__ \\ | | \\/ \\_/ ___\\| | \\_/ __ \\_ __ \\ \n" + " | |__/ __ \\| | / | \\ \\___| Y \\ ___/| | \\/ \n" + " |____(____ /____/|___| /\\___ >___| /\\___ >__| \n" + " \\/ \\/ \\/ \\/ \\/ "); + + log_info( + "launcher build date %s, gitrev %s", + launcher_build_date, + launcher_gitrev); +} + +void _launcher_log_init( + const char *log_file_path, enum core_log_bt_log_level level) +{ + struct core_log_sink sinks[2]; + struct core_log_sink sink_composed; + + core_log_bt_ext_impl_set(); + + if (log_file_path) { + core_log_sink_std_out_open(true, &sinks[0]); + core_log_sink_file_open(log_file_path, false, true, 10, &sinks[1]); + core_log_sink_list_open(sinks, 2, &sink_composed); + } else { + core_log_sink_std_out_open(true, &sink_composed); + } + + core_log_bt_init(&sink_composed); + core_log_bt_level_set(level); +} + +static void _launcher_signal_shutdown_handler() +{ + core_log_bt_fini(); + ExitProcess(EXIT_FAILURE); +} + +static void _launcher_env_game_dir_verify() +{ + char cwd[MAX_PATH]; + char modules_dir[MAX_PATH]; + char prop_dir[MAX_PATH]; + + getcwd(cwd, sizeof(cwd)); + + log_info("Current working directory: %s", cwd); + + str_cpy(modules_dir, sizeof(modules_dir), cwd); + str_cpy(prop_dir, sizeof(prop_dir), cwd); + + str_cat(modules_dir, sizeof(modules_dir), "/modules"); + str_cat(prop_dir, sizeof(prop_dir), "/prop"); + + if (!path_exists(modules_dir)) { + log_fatal( + "Cannot find 'modules' directory in current working directory: %s", + cwd); + } + + if (!path_exists(prop_dir)) { + log_fatal( + "Cannot find 'prop' directory in current working directory: %s", + cwd); + } +} + +static void _launcher_bootstrap_config_options_override( + struct launcher_bootstrap_config *config, + const struct options_bootstrap *options) +{ + log_assert(config); + log_assert(options); + + if (options->config_path) { + log_misc( + "Command line override bootstrap configuration from file: %s", + options->config_path); + + property_util_free(config->property); + config->property = property_util_load(options->config_path); + } + + if (options->selector) { + log_misc( + "Command line override bootstrap selector: %s", options->selector); + + str_cpy(config->selector, sizeof(config->selector), options->selector); + } +} + +static void _launcher_ea3_ident_config_options_override( + struct ea3_ident_config *config, const struct options_eamuse *options) +{ + log_assert(config); + log_assert(options); + + if (options->softid) { + str_cpy(config->softid, sizeof(config->softid), options->softid); + } + + if (options->pcbid) { + str_cpy(config->pcbid, sizeof(config->pcbid), options->pcbid); + } +} + +static void _launcher_hook_config_options_override( + struct launcher_config *config, const struct options_hook *options) +{ + size_t i; + const char *dll; + + log_assert(config); + log_assert(options); + + for (i = 0; i < options->hook_dlls.nitems; i++) { + dll = *array_item(const char *, &options->hook_dlls, i); + + if (!launcher_config_add_hook_dll(config, dll)) { + log_warning( + "Adding override hook dll '%s' failed (max supported limit " + "exceeded), ignored", + dll); + } + } + + for (i = 0; i < options->before_hook_dlls.nitems; i++) { + dll = *array_item(const char *, &options->before_hook_dlls, i); + + if (!launcher_config_add_before_hook_dll(config, dll)) { + log_warning( + "Adding override before hook dll '%s' failed (max supported " + "limit exceeded), ignored", + dll); + } + } + + for (i = 0; i < options->iat_hook_dlls.nitems; i++) { + dll = *array_item(const char *, &options->iat_hook_dlls, i); + + if (!launcher_config_add_iat_hook_dll(config, dll)) { + log_warning( + "Adding override iat hook dll '%s' failed (max supported limit " + "exceeded), ignored", + dll); + } + } +} + +static void _launcher_debug_config_options_override( + struct launcher_debug_config *config, const struct options_debug *options) +{ + log_assert(config); + log_assert(options); + + if (options->remote_debugger) { + log_misc("Command line override, enable remote debugger"); + + config->remote_debugger = true; + } + + if (options->log_property_configs) { + log_misc("Command line override, log property configs"); + + config->log_property_configs = true; + } +} + +static void _launcher_config_options_override( + struct launcher_config *config, const struct options *options) +{ + log_assert(config); + log_assert(options); + + // Apply command line overrides on all launcher owned configuration + // parameters + _launcher_bootstrap_config_options_override( + &config->bootstrap, &options->bootstrap); + _launcher_hook_config_options_override(config, &options->hook); + _launcher_debug_config_options_override(&config->debug, &options->debug); +} + +static void +_launcher_config_full_resolved_log(const struct launcher_config *config) +{ + if (config->debug.log_property_configs) { + log_misc("launcher-config resolved properties"); + log_misc("bootstrap-config"); + property_util_log(config->bootstrap.property); + + log_misc("avs-config"); + property_util_log(config->avs.property); + + log_misc("ea3-ident-config"); + property_util_log(config->ea3_ident.property); + + log_misc("eamuse-config"); + property_util_log(config->eamuse.property); + } +} + +static void +_launcher_remote_debugger_trap(const struct launcher_debug_config *config) +{ + log_assert(config); + + /* If enabled, wait for a remote debugger to attach as early as possible. + Spawning launcher with a debugger crashes it for some reason + (e.g. on jubeat08). However, starting the launcher separately and + attaching a remote debugger works */ + + if (config->remote_debugger) { + debug_remote_debugger_trap(); + } +} + +static void _launcher_bootstrap_config_load( + const struct launcher_bootstrap_config *launcher_bootstrap_config, + struct bootstrap_config *config) +{ + bootstrap_config_init(config); + + bootstrap_config_load( + launcher_bootstrap_config->property, + launcher_bootstrap_config->selector, + config); +} + +static void _launcher_bootstrap_log_config_options_override( + struct bootstrap_log_config *config, const struct options_log *options) +{ + log_assert(config); + log_assert(options); + + if (options->level) { + log_misc( + "Command line override bootstrap log level: %d", *(options->level)); + + switch (*(options->level)) { + case CORE_LOG_BT_LOG_LEVEL_OFF: + str_cpy(config->level, sizeof(config->level), "disable"); + break; + + case CORE_LOG_BT_LOG_LEVEL_FATAL: + str_cpy(config->level, sizeof(config->level), "fatal"); + break; + + case CORE_LOG_BT_LOG_LEVEL_WARNING: + str_cpy(config->level, sizeof(config->level), "warn"); + break; + + case CORE_LOG_BT_LOG_LEVEL_INFO: + str_cpy(config->level, sizeof(config->level), "info"); + break; + + case CORE_LOG_BT_LOG_LEVEL_MISC: + str_cpy(config->level, sizeof(config->level), "misc"); + break; + + default: + log_assert(false); + } + } + + if (options->file_path) { + log_misc( + "Command line override bootstrap log file: %s", options->file_path); + str_cpy(config->file, sizeof(config->file), options->file_path); + } +} + +static void _launcher_bootstrap_log_config_verify( + const struct launcher_config *launcher_config, + const struct bootstrap_config *bootstrap_config) +{ + log_assert(launcher_config); + log_assert(bootstrap_config); + + if (!str_eq(bootstrap_config->startup.log.level, "misc")) { + if (launcher_config->debug.log_property_configs) { + log_warning( + "Logging of property configs enabled, but requires misc log " + "level, current log level: %s", + bootstrap_config->startup.log.level); + } + } +} + +static void +_launcher_before_hook_dlls_load(const struct launcher_hook_config *config) +{ + int i; + + log_assert(config); + + log_misc("Loading before hook dlls..."); + + for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) { + if (strlen(config->before_hook_dlls[i]) > 0) { + hook_load_dll(config->before_hook_dlls[i]); + } + } +} + +static void _launcher_ea3_ident_config_load( + const struct launcher_ea3_ident_config *launcher_config, + struct ea3_ident_config *config, + bool log_property_configs) +{ + log_assert(launcher_config); + log_assert(config); + + ea3_ident_config_init(config); + ea3_ident_config_load(launcher_config->property, config); + + if (log_property_configs) { + log_misc("Property ea3-ident-config"); + + property_util_log(launcher_config->property); + } + + if (!ea3_ident_config_hardid_is_defined(config)) { + log_misc( + "No no hardid defined in ea3-ident-config, derive from ethernet"); + + ea3_ident_config_hardid_from_ethernet_set(config); + } +} + +static void _launcher_bootstrap_module_init( + const struct bootstrap_module_config *module_config, + const struct launcher_hook_config *hook_config) +{ + int i; + struct array iat_hook_dlls; + + log_assert(module_config); + log_assert(hook_config); + + array_init(&iat_hook_dlls); + + for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) { + if (strlen(hook_config->before_hook_dlls[i]) > 0) { + *array_append(const char *, &iat_hook_dlls) = + (const char *) &hook_config->before_hook_dlls[i]; + } + } + + bootstrap_module_init(module_config, &iat_hook_dlls); + + array_fini(&iat_hook_dlls); +} + +static void _launcher_hook_dlls_load(const struct launcher_hook_config *config) +{ + int i; + + log_assert(config); + + log_misc("Loading hook dlls..."); + + for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) { + if (strlen(config->hook_dlls[i]) > 0) { + hook_load_dll(config->hook_dlls[i]); + } + } +} + +static void _launcher_dongle_stubs_init() +{ + stubs_init(); +} + +static void _launcher_debugger_break() +{ + /* Opportunity for breakpoint setup etc */ + if (IsDebuggerPresent()) { + DebugBreak(); + } +} + +void _launcher_log_reinit() +{ + core_log_bt_ext_impl_set(); +} + +void _launcher_init( + const struct options *options, + struct launcher_config *launcher_config, + struct bootstrap_config *bootstrap_config, + struct ea3_ident_config *ea3_ident_config) +{ + struct property *launcher_property; + + log_assert(options); + log_assert(launcher_config); + log_assert(bootstrap_config); + log_assert(ea3_ident_config); + + // Early logging pre AVS setup depend entirely on command args + // We don't even have the bootstrap configuration loaded at this point + _launcher_log_init(options->log.file_path, *(options->log.level)); + _launcher_log_header(); + + debug_init(core_log_fatal_impl_get()); + signal_exception_handler_init(_launcher_signal_shutdown_handler); + signal_register_shutdown_handler(&_launcher_signal_shutdown_handler); + + os_version_log(); + _launcher_env_game_dir_verify(); + + if (proc_is_running_as_admin_user()) { + log_warning( + "Not running as admin user. Launcher and games require elevated " + "privileges to run correctly"); + } + + launcher_config_init(launcher_config); + + if (options->launcher.config_path) { + log_info( + "Loading launcher configuration from file: %s", + options->launcher.config_path); + + launcher_property = property_util_load(options->launcher.config_path); + launcher_config_load(launcher_property, launcher_config); + + _launcher_config_options_override(launcher_config, options); + + if (launcher_config->debug.log_property_configs) { + log_misc("launcher-config"); + property_util_log(launcher_property); + } + + property_util_free(launcher_property); + } else { + _launcher_config_options_override(launcher_config, options); + } + + // Not really fully resolved, but have an early debug dump because there are + // still several more steps that can fail before having the entire + // configuration resolved + _launcher_config_full_resolved_log(launcher_config); + + _launcher_remote_debugger_trap(&launcher_config->debug); + + _launcher_bootstrap_config_load( + &launcher_config->bootstrap, bootstrap_config); + _launcher_bootstrap_log_config_options_override( + &bootstrap_config->startup.log, &options->log); + _launcher_bootstrap_log_config_verify(launcher_config, bootstrap_config); + + bootstrap_init(launcher_config->debug.log_property_configs); + bootstrap_log_init(&bootstrap_config->startup.log); + + _launcher_before_hook_dlls_load(&launcher_config->hook); + + bootstrap_avs_init( + &bootstrap_config->startup.boot, + &bootstrap_config->startup.log, + launcher_config->avs.property); + bootstrap_default_files_create(&bootstrap_config->startup.default_file); + + _launcher_ea3_ident_config_load( + &launcher_config->ea3_ident, + ea3_ident_config, + launcher_config->debug.log_property_configs); + _launcher_ea3_ident_config_options_override( + ea3_ident_config, &options->eamuse); + + // Execute another one which is now actually final. No more configuration + // changes from this point on + _launcher_config_full_resolved_log(launcher_config); +} + +void _launcher_run( + const struct launcher_config *launcher_config, + const struct bootstrap_config *bootstrap_config, + struct ea3_ident_config *ea3_ident_config) +{ + log_assert(launcher_config); + log_assert(bootstrap_config); + log_assert(ea3_ident_config); + + _launcher_bootstrap_module_init( + &bootstrap_config->startup.module, &launcher_config->hook); + + _launcher_hook_dlls_load(&launcher_config->hook); + + _launcher_dongle_stubs_init(); + + _launcher_debugger_break(); + + bootstrap_module_game_init( + &bootstrap_config->startup.module, ea3_ident_config); + + bootstrap_eamuse_init( + &bootstrap_config->startup.eamuse, + ea3_ident_config, + launcher_config->eamuse.property); + + bootstrap_module_game_run(); +} + +void _launcher_fini( + struct launcher_config *launcher_config, + const struct bootstrap_config *bootstrap_config) +{ + log_assert(launcher_config); + log_assert(bootstrap_config); + + bootstrap_eamuse_fini(&bootstrap_config->startup.eamuse); + + bootstrap_avs_fini(); + + _launcher_log_reinit(); + + bootstrap_module_game_fini(); + + launcher_config_fini(launcher_config); + + log_info("Shutdown complete"); + + core_log_bt_fini(); +} + +void launcher_main(const struct options *options) +{ + struct launcher_config launcher_config; + struct bootstrap_config bootstrap_config; + struct ea3_ident_config ea3_ident_config; + + log_assert(options); + + _launcher_init( + options, &launcher_config, &bootstrap_config, &ea3_ident_config); + + _launcher_run(&launcher_config, &bootstrap_config, &ea3_ident_config); + + _launcher_fini(&launcher_config, &bootstrap_config); +} \ No newline at end of file diff --git a/src/main/launcher/launcher.h b/src/main/launcher/launcher.h new file mode 100644 index 0000000..da1995c --- /dev/null +++ b/src/main/launcher/launcher.h @@ -0,0 +1,8 @@ +#ifndef LAUNCHER_LAUNCHER_H +#define LAUNCHER_LAUNCHER_H + +#include "launcher/options.h" + +void launcher_main(const struct options *options); + +#endif \ No newline at end of file diff --git a/src/main/launcher/main.c b/src/main/launcher/main.c index 70c5184..4b1b68a 100644 --- a/src/main/launcher/main.c +++ b/src/main/launcher/main.c @@ -1,338 +1,23 @@ -#include - -#include -#include -#include #include -#include "imports/avs-ea3.h" -#include "imports/avs.h" - -#include "launcher/avs-context.h" -#include "launcher/ea3-config.h" -#include "launcher/module.h" +#include "launcher/launcher.h" #include "launcher/options.h" -#include "launcher/property.h" -#include "launcher/stubs.h" -#include "launcher/version.h" - -#include "util/codepage.h" -#include "util/defs.h" -#include "util/fs.h" -#include "util/log.h" -#include "util/mem.h" -#include "util/os.h" -#include "util/str.h" - -/* Gratuitous API changes orz */ -static AVS_LOG_WRITER(log_callback, chars, nchars, ctx) -{ - wchar_t *utf16; - char *utf8; - int utf16_len; - int utf8_len; - int result; - DWORD nwritten; - HANDLE console; - HANDLE file; - - /* Ignore existing NUL terminator */ - - nchars--; - - /* Transcode shit_jis to UTF-8 */ - - utf16_len = MultiByteToWideChar(CP_SHIFT_JIS, 0, chars, nchars, NULL, 0); - - if (utf16_len == 0) { - abort(); - } - - utf16 = xmalloc(sizeof(*utf16) * utf16_len); - result = - MultiByteToWideChar(CP_SHIFT_JIS, 0, chars, nchars, utf16, utf16_len); - - if (result == 0) { - abort(); - } - - utf8_len = - WideCharToMultiByte(CP_UTF8, 0, utf16, utf16_len, NULL, 0, NULL, NULL); - - if (utf8_len == 0) { - abort(); - } - - utf8 = xmalloc(utf8_len + 2); - result = WideCharToMultiByte( - CP_UTF8, 0, utf16, utf16_len, utf8, utf8_len, NULL, NULL); - - if (result == 0) { - abort(); - } - -#if AVS_VERSION >= 1500 - utf8[utf8_len + 0] = '\r'; - utf8[utf8_len + 1] = '\n'; - - utf8_len += 2; -#endif - - /* Write to console and log file */ - - file = (HANDLE) ctx; - console = GetStdHandle(STD_OUTPUT_HANDLE); - - if (ctx != INVALID_HANDLE_VALUE) { - WriteFile(file, utf8, utf8_len, &nwritten, NULL); - } - - WriteFile(console, utf8, utf8_len, &nwritten, NULL); - - /* Clean up */ - - free(utf8); - free(utf16); -} - -static void load_hook_dlls(struct array *hook_dlls) -{ - const char *hook_dll; - - for (size_t i = 0; i < hook_dlls->nitems; i++) { - hook_dll = *array_item(char *, hook_dlls, i); - - if (LoadLibraryA(hook_dll) == NULL) { - LPSTR buffer; - - FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR) &buffer, - 0, - NULL); - - log_fatal("%s: Failed to load hook DLL: %s", hook_dll, buffer); - - LocalFree(buffer); - } - } -} int main(int argc, const char **argv) { - bool ok; - HANDLE logfile; - - struct ea3_ident ea3; - struct module_context module; struct options options; - struct property *app_config; - struct property *avs_config; - struct property *ea3_config; - - struct property_node *app_config_root; - struct property_node *avs_config_root; - struct property_node *ea3_config_root; - - log_to_writer(log_writer_file, stdout); - log_info( - "launcher build date %s, gitrev %s", - launcher_build_date, - launcher_gitrev); - - /* Read command line */ - options_init(&options); if (!options_read_cmdline(&options, argc, argv)) { options_print_usage(); - return EXIT_FAILURE; + exit(EXIT_FAILURE); } - /* If enabled, wait for a remote debugger to attach. Spawning launcher - with a debugger crashes it for some reason (e.g. on jubeat08). However, - starting the launcher separately and attaching a remote debugger works */ + launcher_main(&options); - if (options.remote_debugger) { - log_info("Waiting until debugger attaches to remote process..."); - - while (true) { - BOOL res = FALSE; - if (!CheckRemoteDebuggerPresent(GetCurrentProcess(), &res)) { - log_fatal( - "CheckRemoteDebuggerPresent failed: %08x", - (unsigned int) GetLastError()); - } - - if (res) { - log_info("Debugger attached, resuming"); - break; - } - - Sleep(1000); - } - } - - /* Start up AVS */ - - if (options.logfile != NULL) { - logfile = CreateFileA( - options.logfile, - GENERIC_WRITE, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - 0, - NULL); - } else { - logfile = INVALID_HANDLE_VALUE; - } - - avs_config = boot_property_load(options.avs_config_path); - avs_config_root = property_search(avs_config, 0, "/config"); - - if (avs_config_root == NULL) { - log_fatal("%s: /config missing", options.avs_config_path); - } - - load_hook_dlls(&options.before_hook_dlls); - - avs_context_init( - avs_config_root, - options.avs_heap_size, - options.std_heap_size, - log_callback, - logfile); - - boot_property_free(avs_config); - - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); - - os_version_log(); - - /* Load game DLL */ - - if (options.iat_hook_dlls.nitems > 0) { - module_context_init_with_iat_hooks( - &module, options.module, &options.iat_hook_dlls); - } else { - module_context_init(&module, options.module); - } - - /* Load hook DLLs */ - - load_hook_dlls(&options.hook_dlls); - - /* Inject GetModuleHandle hooks */ - - stubs_init(); - - /* Prepare ea3 config */ - - ea3_config = boot_property_load(options.ea3_config_path); - ea3_config_root = property_search(ea3_config, 0, "/ea3"); - - if (ea3_config_root == NULL) { - log_fatal("%s: /ea3 missing", options.ea3_config_path); - } - - ea3_ident_init(&ea3); - - if (!ea3_ident_from_property(&ea3, ea3_config)) { - log_fatal( - "%s: Error reading IDs from config file", options.ea3_config_path); - } - - if (options.softid != NULL) { - str_cpy(ea3.softid, lengthof(ea3.softid), options.softid); - } - - if (options.pcbid != NULL) { - str_cpy(ea3.pcbid, lengthof(ea3.pcbid), options.pcbid); - } - - if (!ea3.hardid[0]) { - ea3_ident_hardid_from_ethernet(&ea3); - } - - /* Invoke dll_entry_init */ - - if (path_exists(options.app_config_path)) { - app_config = boot_property_load(options.app_config_path); - } else { - log_warning( - "%s: app config file missing, using empty", - options.app_config_path); - app_config = boot_property_load_cstring("dummy"); - } - - app_config_root = property_search(app_config, 0, "/param"); - - if (app_config_root == NULL) { - log_fatal("%s: /param missing", options.app_config_path); - } - - if (IsDebuggerPresent()) { - /* Opportunity for breakpoint setup etc */ - DebugBreak(); - } - - ok = ea3_ident_invoke_module_init(&ea3, &module, app_config_root); - - if (!ok) { - log_fatal("%s: dll_module_init() returned failure", options.module); - } - - boot_property_free(app_config); - - ea3_ident_to_property(&ea3, ea3_config); - - if (options.override_urlslash_enabled) { - log_info( - "Overriding url_slash to: %d", options.override_urlslash_value); - - ea3_ident_replace_property_bool( - ea3_config_root, - "/network/url_slash", - options.override_urlslash_value); - } - - if (options.override_service != NULL) { - log_info("Overriding service url to: %s", options.override_service); - - ea3_ident_replace_property_str( - ea3_config_root, "/network/services", options.override_service); - } - - /* Start up e-Amusement client */ - - ea3_boot(ea3_config_root); - boot_property_free(ea3_config); - - /* Run application */ - - module_context_invoke_main(&module); - - /* Shut down */ - - ea3_shutdown(); - - log_to_writer(log_writer_file, stdout); - avs_context_fini(); - - if (logfile != INVALID_HANDLE_VALUE) { - CloseHandle(logfile); - } - - module_context_fini(&module); options_fini(&options); return EXIT_SUCCESS; -} +} \ No newline at end of file diff --git a/src/main/launcher/module.c b/src/main/launcher/module.c index b3beff2..c0b9ef4 100644 --- a/src/main/launcher/module.c +++ b/src/main/launcher/module.c @@ -1,22 +1,29 @@ +#define LOG_MODULE "module" + #include +#include "core/log.h" + #include "hook/pe.h" #include "imports/avs.h" #include "imports/eapki.h" #include "launcher/module.h" +#include "launcher/property-util.h" -#include "util/log.h" #include "util/str.h" #define MM_ALLOCATION_GRANULARITY 0x10000 -static bool module_replace_dll_iat(HMODULE hModule, struct array *iat_hook_dlls) +static bool +module_replace_dll_iat(HMODULE hModule, const struct array *iat_hook_dlls) { log_assert(hModule); log_assert(iat_hook_dlls); + log_misc("replace dll iat: %p", hModule); + if (iat_hook_dlls->nitems == 0) return true; @@ -127,11 +134,13 @@ inject_fail: return false; } -void module_context_init(struct module_context *module, const char *path) +void module_init(struct module_context *module, const char *path) { log_assert(module != NULL); log_assert(path != NULL); + log_info("init: %s", path); + module->dll = LoadLibrary(path); if (module->dll == NULL) { @@ -159,16 +168,20 @@ void module_context_init(struct module_context *module, const char *path) } module->path = str_dup(path); + + log_misc("init done"); } -void module_context_init_with_iat_hooks( +void module_with_iat_hooks_init( struct module_context *module, const char *path, - struct array *iat_hook_dlls) + const struct array *iat_hook_dlls) { log_assert(module != NULL); log_assert(path != NULL); + log_info("init iat hooks: %s", path); + module->dll = LoadLibraryExA(path, NULL, DONT_RESOLVE_DLL_REFERENCES); if (module->dll == NULL) { @@ -211,16 +224,71 @@ void module_context_init_with_iat_hooks( module->path = str_dup(path); } -bool module_context_invoke_init( +void module_init_invoke( const struct module_context *module, - char *sidcode, - struct property_node *app_config) + struct ea3_ident_config *ea3_ident_config, + struct property_node *app_params_node) { + char sidcode_short[17]; + char sidcode_long[21]; + char security_code[9]; dll_entry_init_t init; + bool ok; - log_assert(module != NULL); - log_assert(sidcode != NULL); - log_assert(app_config != NULL); + log_info("init invoke"); + + /* Set up security env vars */ + + str_format( + security_code, + lengthof(security_code), + "G*%s%s%s%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev); + + log_misc("security code: %s", security_code); + + std_setenv("/env/boot/version", "0.0.0"); + std_setenv("/env/profile/security_code", security_code); + std_setenv("/env/profile/system_id", ea3_ident_config->pcbid); + std_setenv("/env/profile/account_id", ea3_ident_config->pcbid); + std_setenv("/env/profile/license_id", ea3_ident_config->softid); + std_setenv("/env/profile/software_id", ea3_ident_config->softid); + std_setenv("/env/profile/hardware_id", ea3_ident_config->hardid); + + /* Set up the short sidcode string, let dll_entry_init mangle it */ + + str_format( + sidcode_short, + lengthof(sidcode_short), + "%s%s%s%s%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev, + ea3_ident_config->ext); + + log_misc("sidcode short: %s", sidcode_short); + + /* Set up long-form sidcode env var */ + + str_format( + sidcode_long, + lengthof(sidcode_long), + "%s:%s:%s:%s:%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev, + ea3_ident_config->ext); + + log_misc("sidecode long: %s", sidcode_long); + + /* Set this up beforehand, as certain games require it in dll_entry_init */ + + std_setenv("/env/profile/soft_id_code", sidcode_long); init = (void *) GetProcAddress(module->dll, "dll_entry_init"); @@ -229,16 +297,67 @@ bool module_context_invoke_init( "%s: dll_entry_init not found. Is this a game DLL?", module->path); } - return init(sidcode, app_config); + log_info("Invoking game init..."); + + struct property *prop = + property_util_cstring_load("p3io"); + + struct property_node *prop_node = property_search(prop, NULL, "/param"); + + property_util_log(prop); + property_util_node_log(prop_node); + + ok = init(sidcode_short, prop_node); + + if (!ok) { + log_fatal("%s: dll_module_init() returned failure", module->path); + } else { + log_info("Game init done"); + } + + /* Back-propagate sidcode, as some games modify it during init */ + + memcpy( + ea3_ident_config->model, + sidcode_short + 0, + sizeof(ea3_ident_config->model) - 1); + ea3_ident_config->dest[0] = sidcode_short[3]; + ea3_ident_config->spec[0] = sidcode_short[4]; + ea3_ident_config->rev[0] = sidcode_short[5]; + memcpy( + ea3_ident_config->ext, + sidcode_short + 6, + sizeof(ea3_ident_config->ext)); + + /* Set up long-form sidcode env var again */ + + str_format( + sidcode_long, + lengthof(sidcode_long), + "%s:%s:%s:%s:%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev, + ea3_ident_config->ext); + + std_setenv("/env/profile/soft_id_code", sidcode_long); + + log_misc("back-propagated sidcode long: %s", sidcode_long); + + log_misc("init invoke done"); } -bool module_context_invoke_main(const struct module_context *module) +bool module_main_invoke(const struct module_context *module) { /* GCC warns if you call a variable "main" */ dll_entry_main_t main_; + bool result; log_assert(module != NULL); + log_info("main invoke"); + main_ = (void *) GetProcAddress(module->dll, "dll_entry_main"); if (main_ == NULL) { @@ -246,11 +365,19 @@ bool module_context_invoke_main(const struct module_context *module) "%s: dll_entry_main not found. Is this a game DLL?", module->path); } - return main_(); + log_info("Invoking game's main function..."); + + result = main_(); + + log_info("Main terminated, result: %d", result); + + return result; } -void module_context_fini(struct module_context *module) +void module_fini(struct module_context *module) { + log_info("fini"); + if (module == NULL) { return; } @@ -260,4 +387,6 @@ void module_context_fini(struct module_context *module) if (module->dll != NULL) { FreeLibrary(module->dll); } + + log_misc("fini done"); } diff --git a/src/main/launcher/module.h b/src/main/launcher/module.h index f2a851e..ed9b732 100644 --- a/src/main/launcher/module.h +++ b/src/main/launcher/module.h @@ -5,6 +5,8 @@ #include "imports/avs.h" +#include "launcher/ea3-ident-config.h" + #include "util/array.h" struct module_context { @@ -12,16 +14,16 @@ struct module_context { char *path; }; -void module_context_init(struct module_context *module, const char *path); -void module_context_init_with_iat_hooks( +void module_init(struct module_context *module, const char *path); +void module_with_iat_hooks_init( struct module_context *module, const char *path, - struct array *iat_hook_dlls); -bool module_context_invoke_init( + const struct array *iat_hook_dlls); +void module_init_invoke( const struct module_context *module, - char *sidcode, - struct property_node *app_config); -bool module_context_invoke_main(const struct module_context *module); -void module_context_fini(struct module_context *module); + struct ea3_ident_config *ea3_ident_config, + struct property_node *app_params_node); +bool module_main_invoke(const struct module_context *module); +void module_fini(struct module_context *module); #endif diff --git a/src/main/launcher/options.c b/src/main/launcher/options.c index 757555e..e116849 100644 --- a/src/main/launcher/options.c +++ b/src/main/launcher/options.c @@ -1,3 +1,5 @@ +#define LOG_MODULE "options" + #include #include #include @@ -6,62 +8,42 @@ #include "launcher/options.h" -#include "util/array.h" -#include "util/log.h" +#include "util/mem.h" #include "util/str.h" -#define DEFAULT_HEAP_SIZE 16777216 - void options_init(struct options *options) { - options->std_heap_size = DEFAULT_HEAP_SIZE; - options->avs_heap_size = DEFAULT_HEAP_SIZE; - options->app_config_path = "prop/app-config.xml"; - options->avs_config_path = "prop/avs-config.xml"; - options->ea3_config_path = "prop/ea3-config.xml"; - options->softid = NULL; - options->pcbid = NULL; - options->module = NULL; - options->logfile = NULL; - options->remote_debugger = false; - array_init(&options->hook_dlls); - array_init(&options->before_hook_dlls); - array_init(&options->iat_hook_dlls); + memset(options, 0, sizeof(struct options)); - options->override_service = NULL; - options->override_urlslash_enabled = false; - options->override_urlslash_value = false; + array_init(&options->hook.hook_dlls); + array_init(&options->hook.before_hook_dlls); + array_init(&options->hook.iat_hook_dlls); } bool options_read_cmdline(struct options *options, int argc, const char **argv) { + bool got_launcher_config; + + got_launcher_config = false; + for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { - case 'A': + case 'T': if (i + 1 >= argc) { return false; } - options->app_config_path = argv[++i]; + options->bootstrap.config_path = argv[++i]; break; - case 'E': + case 'Z': if (i + 1 >= argc) { return false; } - options->ea3_config_path = argv[++i]; - - break; - - case 'V': - if (i + 1 >= argc) { - return false; - } - - options->avs_config_path = argv[++i]; + options->bootstrap.selector = argv[++i]; break; @@ -70,7 +52,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->pcbid = argv[++i]; + options->eamuse.pcbid = argv[++i]; break; @@ -79,7 +61,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->softid = argv[++i]; + options->eamuse.softid = argv[++i]; break; @@ -88,37 +70,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->avs_heap_size = - (size_t) strtol(argv[++i], NULL, 0); - - if (options->avs_heap_size == 0) { - return false; - } - - break; - -#ifdef AVS_HAS_STD_HEAP - case 'T': - if (i + 1 >= argc) { - return false; - } - - options->std_heap_size = - (size_t) strtol(argv[++i], NULL, 0); - - if (options->std_heap_size == 0) { - return false; - } - - break; -#endif - - case 'K': - if (i + 1 >= argc) { - return false; - } - - *array_append(const char *, &options->hook_dlls) = + *array_append(const char *, &options->hook.hook_dlls) = argv[++i]; break; @@ -128,7 +80,8 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - *array_append(const char *, &options->before_hook_dlls) = + *array_append( + const char *, &options->hook.before_hook_dlls) = argv[++i]; break; @@ -141,17 +94,41 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) const char *dll = argv[++i]; log_assert(strstr(dll, "=") != NULL); - *array_append(const char *, &options->iat_hook_dlls) = dll; + *array_append(const char *, &options->hook.iat_hook_dlls) = + dll; break; } + case 'L': + if (i + 1 >= argc) { + return false; + } + + long tmp = strtol(argv[++i], NULL, 0); + + if (tmp < CORE_LOG_BT_LOG_LEVEL_OFF || + tmp > CORE_LOG_BT_LOG_LEVEL_MISC) { + return false; + } + + options->log.level = + xmalloc(sizeof(enum core_log_bt_log_level)); + *(options->log.level) = (enum core_log_bt_log_level) tmp; + + break; + case 'Y': if (i + 1 >= argc) { return false; } - options->logfile = argv[++i]; + options->log.file_path = argv[++i]; + + break; + + case 'C': + options->debug.log_property_configs = true; break; @@ -160,7 +137,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->override_service = argv[++i]; + options->eamuse.service_url = argv[++i]; break; @@ -169,22 +146,23 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->override_urlslash_enabled = true; + options->eamuse.urlslash = xmalloc(sizeof(bool)); const char *urlslash_value = argv[++i]; - options->override_urlslash_value = false; + *(options->eamuse.urlslash) = false; + if (_stricmp(urlslash_value, "1") == 0) { - options->override_urlslash_value = true; + *(options->eamuse.urlslash) = true; } if (_stricmp(urlslash_value, "true") == 0) { - options->override_urlslash_value = true; + *(options->eamuse.urlslash) = true; } break; case 'D': - options->remote_debugger = true; + options->debug.remote_debugger = true; break; @@ -192,59 +170,71 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) break; } } else { - if (!options->module) { - options->module = argv[i]; + if (!got_launcher_config) { + options->launcher.config_path = argv[i]; + got_launcher_config = true; } } } - if (options->module) { - return true; - } else { - return false; - } + return got_launcher_config; } void options_print_usage(void) { fprintf( stderr, - "Usage: launcher.exe [launcher options...] [hooks " - "options...] \n" + "Usage:\n" + " launcher.exe [launcher options as overrides...] " + "[further options, e.g. for hook libraries to pick up...]\n" "\n" - " The following options can be specified before the app DLL " - "path:\n" + " The following options can be specified before the launcher.xml " + "configuration file:\n" "\n" - " -A [filename] App configuration file (default: " - "prop/app-config.xml)\n" - " -V [filename] AVS configuration file (default: " - "prop/avs-config.xml)\n" - " -E [filename] ea3 configuration file (default: " - "prop/ea3-config.xml)\n" - " -H [bytes] AVS heap size (default: 16777216)\n" -#ifdef AVS_HAS_STD_HEAP - " -T [bytes] 'std' heap size (default 16777216)\n" -#endif - " -P [pcbid] Specify PCBID (default: use ea3 config)\n" - " -R [pcbid] Specify Soft ID (default: use ea3 config)\n" - " -S [url] Specify service url (default: use ea3 config)\n" - " -U [0/1] Specify url_slash (default: use ea3 config)\n" - " -K [filename] Load hook DLL (can be specified multiple " + " Bootstrap\n" + " -T [filename] Bootstrap configuration file\n" + " -Z [selector] Bootstrap selector used in configuration\n" + "\n" + " Eamuse\n" + " -P [pcbid] Specify PCBID\n" + " -R [softid] Specify Soft ID\n" + " -S [url] Specify service url\n" + " -U [0/1] Specify url_slash enabled/disabled\n" + "\n" + " Hook\n" + " -H [filename] Load hook DLL (can be specified multiple " "times)\n" " -B [filename] Load pre-hook DLL loaded before avs boot " "(can be specified multiple times)\n" " -I [filename] Load pre-hook DLL that overrides IAT reference " - "before execution" - "(can be specified multiple times)\n" + "before execution (can be specified multiple times)\n" + "\n" + " Logging\n" + " -L [0/1/2/3] Log level for both console and file with " + "increasing verbosity (0 = fatal, 1 = warn, 2 = info, 3 = misc)\n" " -Y [filename] Log to a file in addition to the console\n" + "\n" + " Debug\n" " -D Halt the launcher before bootstrapping AVS " - "until a" - " remote debugger is attached\n"); + "until a remote debugger is attached\n" + " -C Log all loaded and final (property) " + "configuration that launcher uses for bootstrapping. IMPORTANT: DO NOT " + "ENABLE unless you know what you are doing. This prints sensitive data " + "and credentials to the console and logfile. BE CAUTIOUS not to share " + "this information before redaction."); } void options_fini(struct options *options) { - array_fini(&options->hook_dlls); - array_fini(&options->before_hook_dlls); - array_fini(&options->iat_hook_dlls); + array_fini(&options->hook.hook_dlls); + array_fini(&options->hook.before_hook_dlls); + array_fini(&options->hook.iat_hook_dlls); + + if (options->log.level) { + free(options->log.level); + } + + if (options->eamuse.urlslash) { + free(options->eamuse.urlslash); + } } diff --git a/src/main/launcher/options.h b/src/main/launcher/options.h index 13f1c0f..c0bdfaf 100644 --- a/src/main/launcher/options.h +++ b/src/main/launcher/options.h @@ -4,25 +4,53 @@ #include #include +#include "core/log-bt.h" +#include "core/log.h" + +#include "launcher/bootstrap-config.h" + #include "util/array.h" +// Launcher options (cmd params) are limited to: +// - Options to run a (vanilla) game without additional launcher features, e.g. +// hooking +// - Options that are handy to have for development/debugging purpose, e.g. +// quickly switching on/off +// logging levels +// +// Everything else is driven by a composable configuration file (launcher.xml) struct options { - size_t std_heap_size; - size_t avs_heap_size; - const char *app_config_path; - const char *avs_config_path; - const char *ea3_config_path; - const char *softid; - const char *pcbid; - const char *module; - const char *logfile; - struct array hook_dlls; - struct array before_hook_dlls; - struct array iat_hook_dlls; - bool remote_debugger; - const char *override_service; - bool override_urlslash_enabled; - bool override_urlslash_value; + struct options_launcher { + const char *config_path; + } launcher; + + struct options_bootstrap { + const char *config_path; + const char *selector; + } bootstrap; + + struct options_log { + enum core_log_bt_log_level *level; + const char *file_path; + } log; + + struct options_eamuse { + const char *softid; + const char *pcbid; + const char *service_url; + bool *urlslash; + } eamuse; + + struct options_hook { + struct array hook_dlls; + struct array before_hook_dlls; + struct array iat_hook_dlls; + } hook; + + struct options_debug { + bool remote_debugger; + bool log_property_configs; + } debug; }; void options_init(struct options *options); diff --git a/src/main/launcher/property-util.c b/src/main/launcher/property-util.c new file mode 100644 index 0000000..20a7f91 --- /dev/null +++ b/src/main/launcher/property-util.c @@ -0,0 +1,891 @@ +#define LOG_MODULE "property-util" + +#include + +#include +#include +#include +#include + +#include "avs-util/error.h" + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/property-util.h" + +#include "util/mem.h" +#include "util/str.h" + +#define PROPERTY_STRUCTURE_META_SIZE 576 + +typedef void (*rewinder)(uint32_t context); + +struct cstring_read_handle { + const char *buffer; + size_t buffer_len; + size_t offset; +}; + +struct property_util_node_merge_ctx { + const char *path; + const struct property_util_node_merge_strategies *strategies; +}; + +static struct property *property_util_do_load( + avs_reader_t reader, rewinder rewinder, uint32_t context, const char *name) +{ + struct property *prop; + void *buffer; + int nbytes; + + nbytes = property_read_query_memsize(reader, context, 0, 0); + + if (nbytes < 0) { + log_fatal("%s: Error querying configuration file", name); + } + + buffer = xmalloc(nbytes); + prop = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + nbytes); + + if (!prop) { + log_fatal( + "%s: Creating property failed: %s", + name, + avs_util_property_error_get_and_clear(prop)); + } + + rewinder(context); + + if (!property_insert_read(prop, 0, reader, context)) { + log_fatal( + "%s: Error reading configuration file: %s", + name, + avs_util_property_error_get_and_clear(prop)); + } + + return prop; +} + +static int property_util_fread(uint32_t context, void *bytes, size_t nbytes) +{ + FILE *f; + + f = TlsGetValue(context); + + return fread(bytes, 1, nbytes, f); +} + +static void property_util_frewind(uint32_t context) +{ + FILE *f = TlsGetValue(context); + rewind(f); +} + +static void property_util_log_node_tree_rec( + struct property_node *parent_node, const char *parent_path) +{ + char cur_path[PROPERTY_NODE_PATH_LEN_MAX]; + char cur_node_name[PROPERTY_NODE_NAME_SIZE_MAX]; + + struct property_node *child_node; + enum property_type property_type; + + int8_t value_s8; + int16_t value_s16; + int32_t value_s32; + int64_t value_s64; + uint8_t value_u8; + uint16_t value_u16; + uint32_t value_u32; + uint64_t value_u64; + char value_str[4096]; + bool value_bool; + + avs_error error; + + // Carry on the full root path down the node tree + property_node_name(parent_node, cur_node_name, sizeof(cur_node_name)); + + str_cpy(cur_path, sizeof(cur_path), parent_path); + str_cat(cur_path, sizeof(cur_path), "/"); + str_cat(cur_path, sizeof(cur_path), cur_node_name); + + child_node = property_node_traversal(parent_node, TRAVERSE_FIRST_CHILD); + + // parent node is a leaf node, print all data of it + if (child_node == NULL) { + property_type = property_node_type(parent_node); + + switch (property_type) { + case PROPERTY_TYPE_VOID: + log_misc("%s: ", cur_path); + break; + + case PROPERTY_TYPE_S8: + property_node_read( + parent_node, property_type, &value_s8, sizeof(value_s8)); + log_misc("%s: %" PRId8, cur_path, value_s8); + break; + + case PROPERTY_TYPE_S16: + property_node_read( + parent_node, property_type, &value_s16, sizeof(value_s16)); + log_misc("%s: %" PRId16, cur_path, value_s16); + break; + + case PROPERTY_TYPE_S32: + property_node_read( + parent_node, property_type, &value_s32, sizeof(value_s32)); + log_misc("%s: %" PRId32, cur_path, value_s32); + break; + + case PROPERTY_TYPE_S64: + property_node_read( + parent_node, property_type, &value_s64, sizeof(value_s64)); + log_misc("%s: %" PRId64, cur_path, value_s64); + break; + + case PROPERTY_TYPE_U8: + property_node_read( + parent_node, property_type, &value_u8, sizeof(value_u8)); + log_misc("%s: %" PRIu8, cur_path, value_u8); + break; + + case PROPERTY_TYPE_U16: + property_node_read( + parent_node, property_type, &value_u16, sizeof(value_u16)); + log_misc("%s: %" PRIu16, cur_path, value_u16); + break; + + case PROPERTY_TYPE_U32: + property_node_read( + parent_node, property_type, &value_u32, sizeof(value_u32)); + log_misc("%s: %" PRIu32, cur_path, value_u32); + break; + + case PROPERTY_TYPE_U64: + property_node_read( + parent_node, property_type, &value_u64, sizeof(value_u64)); + log_misc("%s: %" PRIu64, cur_path, value_u64); + break; + + case PROPERTY_TYPE_STR: + property_node_read( + parent_node, property_type, value_str, sizeof(value_str)); + log_misc("%s: %s", cur_path, value_str); + + break; + + case PROPERTY_TYPE_BOOL: + property_node_read( + parent_node, + property_type, + &value_bool, + sizeof(value_bool)); + log_misc("%s: %d", cur_path, value_bool); + + break; + + case PROPERTY_TYPE_BIN: + log_misc("%s: ", cur_path); + break; + + case PROPERTY_TYPE_ATTR: + error = property_node_read( + parent_node, property_type, value_str, sizeof(value_str)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_util_error_str(error)); + } + + log_misc("%s@: %s", cur_path, value_str); + + break; + + case PROPERTY_TYPE_VOID_WITH_ATTRIBUTES: + log_misc("%s: ", cur_path); + + child_node = + property_node_traversal(parent_node, TRAVERSE_FIRST_ATTR); + + while (child_node) { + property_util_log_node_tree_rec(child_node, cur_path); + + child_node = property_node_traversal( + child_node, TRAVERSE_NEXT_SIBLING); + } + + break; + + case PROPERTY_TYPE_STR_WITH_ATTRIBUTES: + error = property_node_read( + parent_node, property_type, value_str, sizeof(value_str)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_util_error_str(error)); + } + + log_misc("%s: %s", cur_path, value_str); + + child_node = + property_node_traversal(parent_node, TRAVERSE_FIRST_ATTR); + + while (child_node) { + property_util_log_node_tree_rec(child_node, cur_path); + + child_node = property_node_traversal( + child_node, TRAVERSE_NEXT_SIBLING); + } + + break; + + default: + log_misc("%s: (%d)", cur_path, property_type); + break; + } + } else { + while (child_node) { + property_util_log_node_tree_rec(child_node, cur_path); + + child_node = + property_node_traversal(child_node, TRAVERSE_NEXT_SIBLING); + } + } +} + +static int +property_util_cstring_read(uint32_t context, void *bytes, size_t nbytes) +{ + int result = 0; + struct cstring_read_handle *h = TlsGetValue(context); + + if (h->offset < h->buffer_len) { + result = min(nbytes, h->buffer_len - h->offset); + memcpy(bytes, (const void *) (h->buffer + h->offset), result); + h->offset += result; + } + return result; +} + +static void property_util_cstring_rewind(uint32_t context) +{ + struct cstring_read_handle *h = TlsGetValue(context); + h->offset = 0; +} + +static int property_util_avs_read(uint32_t context, void *bytes, size_t nbytes) +{ + avs_desc desc = (avs_desc) context; + return avs_fs_read(desc, bytes, nbytes); +} + +static void property_util_avs_rewind(uint32_t context) +{ + avs_desc desc = (avs_desc) context; + avs_fs_lseek(desc, 0, AVS_SEEK_SET); +} + +static void _property_util_node_merge_recursive( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx) +{ + uint8_t i; + bool consumed; + struct property_node *result; + + const struct property_util_node_merge_ctx *ctx_; + struct property_util_node_merge_ctx ctx_next; + + char parent_name[PROPERTY_NODE_NAME_SIZE_MAX]; + char parent_path[PROPERTY_NODE_PATH_LEN_MAX]; + + log_assert(source); + log_assert(ctx); + + ctx_ = (const struct property_util_node_merge_ctx *) ctx; + + log_assert(ctx_->path); + log_assert(ctx_->strategies); + log_assert(ctx_->strategies->num > 0); + + // Default to copying to an empty node + if (!parent) { + result = property_node_clone(parent_property, NULL, source, true); + + if (!result) { + log_fatal("Copying '%s' into empty parent failed", ctx_->path); + } + + return; + } + + property_node_name(parent, parent_name, sizeof(parent_name)); + + str_cpy(parent_path, sizeof(parent_path), ctx_->path); + str_cat(parent_path, sizeof(parent_path), "/"); + str_cat(parent_path, sizeof(parent_path), parent_name); + + ctx_next.path = parent_path; + ctx_next.strategies = ctx_->strategies; + + consumed = false; + + // Apply given strategies, one MUST consume + for (i = 0; i < ctx_->strategies->num; i++) { + log_assert(ctx_->strategies->entry[i].path); + + // path == "" matches everything + if (str_eq(ctx_->strategies->entry[i].path, "") || + str_eq(ctx_->strategies->entry[i].path, parent_path)) { + + consumed = ctx_->strategies->entry[i].merge_strategy_do( + parent_property, + parent, + source, + &ctx_next, + _property_util_node_merge_recursive); + + log_misc( + "Merge strategy for '%s' consumed: %d", + ctx_->strategies->entry[i].path, + consumed); + + if (consumed) { + break; + } + } + } + + log_assert(consumed); +} + +void property_util_log(struct property *property) +{ + property_util_log_node_tree_rec(property_search(property, NULL, "/"), ""); +} + +void property_util_node_log(struct property_node *node) +{ + property_util_log_node_tree_rec(node, ""); +} + +struct property *property_util_load(const char *filename) +{ + FILE *f; + uint32_t f_keyhole; + struct property *prop; + + log_assert(filename); + + /* AVS callbacks are only given a 32-bit context parameter, even in 64-bit + builds of AVS. We allocate a 32-bit TLS key and pass the context in this + manner instead. Inefficient, but it works. */ + + f = fopen(filename, "r"); + + f_keyhole = TlsAlloc(); + TlsSetValue(f_keyhole, f); + + if (f == NULL) { + log_fatal("%s: Error opening configuration file", filename); + } + + prop = property_util_do_load( + property_util_fread, property_util_frewind, f_keyhole, filename); + + TlsFree(f_keyhole); + + fclose(f); + + return prop; +} + +struct property *property_util_avs_fs_load(const char *filename) +{ + avs_desc desc; + struct property *prop; + + log_assert(filename); + + desc = avs_fs_open(filename, AVS_FILE_READ, AVS_FILE_FLAG_SHARE_READ); + + if (!desc) { + log_fatal("%s: Error opening configuration file", filename); + } + + prop = property_util_do_load( + property_util_avs_read, property_util_avs_rewind, desc, filename); + + avs_fs_close(desc); + + return prop; +} + +struct property *property_util_cstring_load(const char *cstring) +{ + uint32_t s_keyhole; + struct property *prop; + + log_assert(cstring); + + // see above + struct cstring_read_handle read_handle; + read_handle.buffer = cstring; + read_handle.buffer_len = strlen(cstring); + read_handle.offset = 0; + + s_keyhole = TlsAlloc(); + TlsSetValue(s_keyhole, &read_handle); + + prop = property_util_do_load( + property_util_cstring_read, + property_util_cstring_rewind, + s_keyhole, + ""); + + TlsFree(s_keyhole); + + return prop; +} + +struct property *property_util_clone(struct property *property) +{ + struct property *clone; + size_t size; + void *buffer; + + struct property_node *node_property; + struct property_node *node_clone; + + log_assert(property); + + size = property_util_property_query_real_size(property); + + buffer = xmalloc(size); + + clone = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + size); + + if (!clone) { + log_fatal("Creating property failed"); + } + + node_property = property_search(property, NULL, "/"); + node_clone = property_search(clone, NULL, "/"); + + if (!property_node_clone(clone, node_clone, node_property, true)) { + log_fatal( + "Cloning property data failed: %s", + avs_util_property_error_get_and_clear(clone)); + } + + return clone; +} + +void property_util_free(struct property *prop) +{ + void *buffer; + + buffer = property_desc_to_buffer(prop); + property_destroy(prop); + free(buffer); +} + +uint32_t property_util_property_query_real_size(struct property *property) +{ + avs_error size; + + log_assert(property); + + // Returns the size of the actual data in the property structure only + // Hence, using that size only, allocating another buffer for a copy + // of this might fail or copying the data will fail because the buffer + // is too small + size = property_query_size(property); + + if (AVS_IS_ERROR(size)) { + log_fatal( + "Querying property size failed: %s", avs_util_error_str(size)); + } + + // Hack: *2 to have enough space and not cut off data when cloning/copying + // property data because...reasons? I haven't figured this one out and + // there doesn't seem to be an actual API call for that to return the + // "true" size that allows the caller to figure out how much memory + // they have to allocate to create a copy of the property structure + // with property_create and + return (PROPERTY_STRUCTURE_META_SIZE + size) * 2; +} + +void property_util_node_u8_replace( + struct property *property, + struct property_node *node, + const char *name, + uint8_t val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_U8, name, val); + + if (!tmp) { + log_fatal( + "Creating node '%s' failed: %s", + name, + property ? avs_util_property_error_get_and_clear(property) : + "unknown"); + } +} + +void property_util_node_u16_replace( + struct property *property, + struct property_node *node, + const char *name, + uint16_t val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_U16, name, val); + + if (!tmp) { + log_fatal( + "Creating node '%s' failed: %s", + name, + property ? avs_util_property_error_get_and_clear(property) : + "unknown"); + } +} + +void property_util_node_u32_replace( + struct property *property, + struct property_node *node, + const char *name, + uint32_t val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_U32, name, val); + + if (!tmp) { + log_fatal( + "Creating node '%s' failed: %s", + name, + property ? avs_util_property_error_get_and_clear(property) : + "unknown"); + } +} + +void property_util_node_str_replace( + struct property *property, + struct property_node *node, + const char *name, + const char *val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_STR, name, val); + + if (!tmp) { + log_fatal( + "Creating node '%s' failed: %s", + name, + property ? avs_util_property_error_get_and_clear(property) : + "unknown"); + } +} + +void property_util_node_bool_replace( + struct property *property, + struct property_node *node, + const char *name, + bool val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_BOOL, name, val); + + if (!tmp) { + log_fatal( + "Creating node '%s' failed: %s", + name, + property ? avs_util_property_error_get_and_clear(property) : + "unknown"); + } +} + +void property_util_node_attribute_replace( + struct property *property, + struct property_node *node, + const char *name, + const char *val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_ATTR, name, val); +} + +struct property * +property_util_many_merge(struct property **properties, size_t count) +{ + struct property *merged_property; + struct property *tmp; + int i; + + log_assert(properties); + log_assert(count > 0); + + merged_property = property_util_clone(properties[0]); + + if (count == 1) { + return merged_property; + } + + for (i = 1; i < count; i++) { + tmp = property_util_merge(merged_property, properties[i]); + + property_util_free(merged_property); + merged_property = tmp; + } + + return merged_property; +} + +struct property *property_util_node_extract(struct property_node *node) +{ + struct property *property; + struct property_node *root_node; + uint32_t size; + void *buffer; + struct property_node *result; + + if (!node) { + return NULL; + } + + // Hack: Is it even possible to get the size of a (sub-) node without + // the property? 256kb should be fine for now, even for larger + // configurations. Obviously, this scales horribly and wastes a lot of + // memory for most smaller sub-nodes + size = 1024 * 256; + + buffer = xmalloc(size); + property = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + size); + root_node = property_search(property, NULL, ""); + + result = property_node_clone(property, root_node, node, true); + + if (!result) { + log_fatal("Cloning node into empty property failed"); + } + + return property; +} + +struct property * +property_util_merge(struct property *parent, struct property *source) +{ + struct property_util_node_merge_strategies strategies; + + log_assert(parent); + log_assert(source); + + strategies.num = 1; + + strategies.entry[0].path = ""; + strategies.entry[0].merge_strategy_do = + property_util_node_merge_default_strategy_do; + + return property_util_merge_with_strategies(parent, source, &strategies); +} + +struct property *property_util_merge_with_strategies( + struct property *parent, + struct property *source, + const struct property_util_node_merge_strategies *strategies) +{ + struct property_util_node_merge_ctx ctx; + size_t total_size; + void *buffer; + struct property *merged; + struct property_node *parent_node; + struct property_node *source_node; + + log_assert(parent); + log_assert(source); + log_assert(strategies); + + // We can't estimate how these two are being merged as in how much new + // data is being inserted from source into parent. Therefore, worse-case + // estimate memory requirement for no overlap + total_size = 0; + total_size += property_util_property_query_real_size(parent); + total_size += property_util_property_query_real_size(source); + + buffer = xmalloc(total_size); + + merged = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + total_size); + + ctx.path = ""; + ctx.strategies = strategies; + + parent_node = property_search(parent, NULL, "/"); + + if (!property_node_clone(merged, NULL, parent_node, true)) { + log_fatal( + "Copying parent base failed: %s", + avs_util_property_error_get_and_clear(merged)); + } + + // Grab parent_node from merged property which is the target one to merge + // into + parent_node = property_search(merged, NULL, "/"); + source_node = property_search(source, NULL, "/"); + + _property_util_node_merge_recursive(merged, parent_node, source_node, &ctx); + + return merged; +} + +bool property_util_node_merge_default_strategy_do( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx, + property_util_node_merge_recursion_do_t node_merge_recursion_do) +{ + struct property_node *result; + + struct property_node *parent_child; + struct property_node *source_child; + struct property_node *source_child_child; + + char child_node_name[PROPERTY_NODE_NAME_SIZE_MAX]; + + log_assert(parent); + log_assert(source); + + source_child = property_node_traversal(source, TRAVERSE_FIRST_CHILD); + + while (source_child) { + property_node_name( + source_child, child_node_name, sizeof(child_node_name)); + + parent_child = property_search(NULL, parent, child_node_name); + + if (parent_child) { + source_child_child = + property_node_traversal(source_child, TRAVERSE_FIRST_CHILD); + + if (source_child_child) { + // Continue recursion if there are actually more children + node_merge_recursion_do( + parent_property, parent_child, source_child, ctx); + } else { + // Found identical leaf node, remove the matching parent's child + // and copy the source child over to the parent and terminate + // the recursion + property_node_remove(parent_child); + result = property_node_clone( + parent_property, parent, source_child, true); + + if (!result) { + log_fatal( + "Replacing leaf node '%s' failed", child_node_name); + } + } + } else { + // Could not find an identical child on parent, copy source + // recursively to parent + result = property_node_clone( + parent_property, parent, source_child, true); + + if (!result) { + log_fatal("Deep copying child '%s' failed", child_node_name); + } + } + + source_child = + property_node_traversal(source_child, TRAVERSE_NEXT_SIBLING); + } + + // Default strategy always consumes + return true; +} diff --git a/src/main/launcher/property-util.h b/src/main/launcher/property-util.h new file mode 100644 index 0000000..ba59479 --- /dev/null +++ b/src/main/launcher/property-util.h @@ -0,0 +1,99 @@ +#ifndef PROPERTY_UTIL_H +#define PROPERTY_UTIL_H + +#include + +#include "imports/avs.h" + +// Guestimate, should be long enough, I hope? +#define PROPERTY_NODE_PATH_LEN_MAX 4096 +// 256 found in AVS code as size used on property_node_name +#define PROPERTY_NODE_NAME_SIZE_MAX 256 +// Guestimate, should be enough, I hope? +#define PROPERTY_NODE_ATTR_NAME_SIZE_MAX 128 + +#define PROPERTY_UTIL_MAX_NODE_NAME_RESOLVERS 4 + +typedef void (*property_util_node_merge_recursion_do_t)( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx); + +typedef bool (*property_util_node_merge_strategy_do_t)( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx, + property_util_node_merge_recursion_do_t node_merge_recursion_do); + +struct property_util_node_merge_strategies { + struct { + const char *path; + property_util_node_merge_strategy_do_t merge_strategy_do; + } entry[PROPERTY_UTIL_MAX_NODE_NAME_RESOLVERS]; + uint8_t num; +}; + +void property_util_log(struct property *property); +void property_util_node_log(struct property_node *node); +struct property *property_util_load(const char *filename); +struct property *property_util_avs_fs_load(const char *filename); +struct property *property_util_cstring_load(const char *cstring); +struct property *property_util_clone(struct property *property); +void property_util_free(struct property *prop); +uint32_t property_util_property_query_real_size(struct property *property); +void property_util_node_u8_replace( + struct property *property, + struct property_node *node, + const char *name, + uint8_t val); +void property_util_node_u16_replace( + struct property *property, + struct property_node *node, + const char *name, + uint16_t val); +void property_util_node_u32_replace( + struct property *property, + struct property_node *node, + const char *name, + uint32_t val); +void property_util_node_str_replace( + struct property *property, + struct property_node *node, + const char *name, + const char *val); +void property_util_node_bool_replace( + struct property *property, + struct property_node *node, + const char *name, + bool val); +void property_util_node_attribute_replace( + struct property *property, + struct property_node *node, + const char *name, + const char *val); + +struct property * +property_util_many_merge(struct property **properties, size_t count); +struct property *property_util_node_extract(struct property_node *node); + +struct property * +property_util_merge(struct property *parent, struct property *source); + +// Strategies are applied in order and first consumer terminates +// applying further strategies Typically, you want to include the default +// strategy after your custom strategies for special cases +struct property *property_util_merge_with_strategies( + struct property *parent, + struct property *source, + const struct property_util_node_merge_strategies *strategies); + +bool property_util_node_merge_default_strategy_do( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx, + property_util_node_merge_recursion_do_t node_merge_recursion_do); + +#endif diff --git a/src/main/launcher/property.c b/src/main/launcher/property.c deleted file mode 100644 index 2f5ded9..0000000 --- a/src/main/launcher/property.c +++ /dev/null @@ -1,135 +0,0 @@ -#include - -#include -#include -#include - -#include "imports/avs.h" - -#include "launcher/property.h" - -#include "util/log.h" -#include "util/mem.h" - -static int boot_property_fread(uint32_t context, void *bytes, size_t nbytes) -{ - FILE *f; - - f = TlsGetValue(context); - - return fread(bytes, 1, nbytes, f); -} - -struct cstring_read_handle { - const char *buffer; - size_t buffer_len; - size_t offset; -}; - -static int -boot_property_cstring_read(uint32_t context, void *bytes, size_t nbytes) -{ - int result = 0; - struct cstring_read_handle *h = TlsGetValue(context); - - if (h->offset < h->buffer_len) { - result = min(nbytes, h->buffer_len - h->offset); - memcpy(bytes, (const void *) (h->buffer + h->offset), result); - h->offset += result; - } - return result; -} - -struct property *boot_property_load(const char *filename) -{ - struct property *prop; - void *buffer; - int nbytes; - FILE *f; - uint32_t f_keyhole; - - /* AVS callbacks are only given a 32-bit context parameter, even in 64-bit - builds of AVS. We allocate a 32-bit TLS key and pass the context in this - manner instead. Inefficient, but it works. */ - - f = fopen(filename, "r"); - - f_keyhole = TlsAlloc(); - TlsSetValue(f_keyhole, f); - - if (f == NULL) { - log_fatal("%s: Error opening configuration file", filename); - } - - nbytes = property_read_query_memsize(boot_property_fread, f_keyhole, 0, 0); - - if (nbytes < 0) { - log_fatal("%s: Error querying configuration file", filename); - } - - buffer = xmalloc(nbytes); - prop = property_create( - PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | - PROPERTY_FLAG_APPEND, - buffer, - nbytes); - rewind(f); - - if (!property_insert_read(prop, 0, boot_property_fread, f_keyhole)) { - log_fatal("%s: Error reading configuration file", filename); - } - - TlsFree(f_keyhole); - - fclose(f); - - return prop; -} -struct property *boot_property_load_cstring(const char *cstring) -{ - struct property *prop; - void *buffer; - int nbytes; - uint32_t s_keyhole; - - // see above - struct cstring_read_handle read_handle; - read_handle.buffer = cstring; - read_handle.buffer_len = strlen(cstring); - read_handle.offset = 0; - - s_keyhole = TlsAlloc(); - TlsSetValue(s_keyhole, &read_handle); - - nbytes = property_read_query_memsize( - boot_property_cstring_read, s_keyhole, 0, 0); - - if (nbytes < 0) { - log_fatal("Error querying configuration string"); - } - - buffer = xmalloc(nbytes); - prop = property_create( - PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | - PROPERTY_FLAG_APPEND, - buffer, - nbytes); - - read_handle.offset = 0; - if (!property_insert_read(prop, 0, boot_property_cstring_read, s_keyhole)) { - log_fatal("Error inserting configuration string"); - } - - TlsFree(s_keyhole); - - return prop; -} - -void boot_property_free(struct property *prop) -{ - void *buffer; - - buffer = property_desc_to_buffer(prop); - property_destroy(prop); - free(buffer); -} diff --git a/src/main/launcher/property.h b/src/main/launcher/property.h deleted file mode 100644 index c3f14d0..0000000 --- a/src/main/launcher/property.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef LAUNCHER_PROPERTY_H -#define LAUNCHER_PROPERTY_H - -#include "imports/avs.h" - -struct property *boot_property_load(const char *filename); -struct property *boot_property_load_cstring(const char *cstring); -void boot_property_free(struct property *prop); - -#endif diff --git a/src/main/launcher/stubs.c b/src/main/launcher/stubs.c index a524273..4c0b253 100644 --- a/src/main/launcher/stubs.c +++ b/src/main/launcher/stubs.c @@ -1,3 +1,5 @@ +#define LOG_MODULE "stubs" + #include #include @@ -5,12 +7,13 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "launcher/stubs.h" #include "util/defs.h" -#include "util/log.h" struct ikey_status { uint32_t field_0; @@ -116,6 +119,8 @@ static void *STDCALL my_GetProcAddress(HMODULE dll, const char *name) void stubs_init(void) { + log_info("Init"); + hook_table_apply( NULL, "kernel32.dll", stub_hook_syms, lengthof(stub_hook_syms)); } From fbadcc9b41767fe7734930159c354af482d423b0 Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 17:17:17 +0100 Subject: [PATCH 13/18] refactor(dist): Config and .bat files Move everything to new launcher.xml configuration files. Adjust the bootstrapping of launcher in the .bat files. Features such as copying the default props/ files to nvram are now handled by launcher. Using the PATH variable, bemanitools binaries can live in their own dedicated bemanitools/ subfolder next to props/ and modules/ now. All original binaries are expected to be kept in a modules/ folder like on stock data. --- Module.mk | 109 +++++++++++++++++++++++++++++++++-- dist/bst/gamestart1.bat | 34 +++++++++-- dist/bst/gamestart2.bat | 34 +++++++++-- dist/bst/launcher-01.xml | 75 ++++++++++++++++++++++++ dist/bst/launcher-02.xml | 75 ++++++++++++++++++++++++ dist/ddr/gamestart-12.bat | 41 +++++++++++-- dist/ddr/gamestart-13.bat | 41 +++++++++++-- dist/ddr/gamestart-14.bat | 46 ++++++++++++--- dist/ddr/gamestart-15.bat | 46 ++++++++++++--- dist/ddr/gamestart-16.bat | 47 ++++++++++++--- dist/ddr/gamestart-17.bat | 47 ++++++++++++--- dist/ddr/gamestart-18.bat | 47 ++++++++++++--- dist/ddr/launcher-12.xml | 75 ++++++++++++++++++++++++ dist/ddr/launcher-13.xml | 75 ++++++++++++++++++++++++ dist/ddr/launcher-14.xml | 75 ++++++++++++++++++++++++ dist/ddr/launcher-15.xml | 75 ++++++++++++++++++++++++ dist/ddr/launcher-16.xml | 76 ++++++++++++++++++++++++ dist/ddr/launcher-17.xml | 76 ++++++++++++++++++++++++ dist/ddr/launcher-18.xml | 76 ++++++++++++++++++++++++ dist/iidx/ea3-ident.xml | 10 ++++ dist/iidx/eamuse-server.xml | 6 ++ dist/iidx/gamestart-18.bat | 36 +++++++++--- dist/iidx/gamestart-19.bat | 36 +++++++++--- dist/iidx/gamestart-20.bat | 34 +++++++++-- dist/iidx/gamestart-21.bat | 34 +++++++++-- dist/iidx/gamestart-22.bat | 34 +++++++++-- dist/iidx/gamestart-23.bat | 34 +++++++++-- dist/iidx/gamestart-24.bat | 34 +++++++++-- dist/iidx/gamestart-25.bat | 40 +++++++++---- dist/iidx/gamestart-26.bat | 40 +++++++++---- dist/iidx/gamestart-27.bat | 40 +++++++++---- dist/iidx/gamestart-28.bat | 40 +++++++++---- dist/iidx/gamestart-29.bat | 40 +++++++++---- dist/iidx/gamestart-30.bat | 40 +++++++++---- dist/iidx/launcher-18.xml | 75 ++++++++++++++++++++++++ dist/iidx/launcher-19.xml | 75 ++++++++++++++++++++++++ dist/iidx/launcher-20.xml | 75 ++++++++++++++++++++++++ dist/iidx/launcher-21.xml | 75 ++++++++++++++++++++++++ dist/iidx/launcher-22.xml | 75 ++++++++++++++++++++++++ dist/iidx/launcher-23.xml | 75 ++++++++++++++++++++++++ dist/iidx/launcher-24.xml | 75 ++++++++++++++++++++++++ dist/iidx/launcher-25.xml | 74 ++++++++++++++++++++++++ dist/iidx/launcher-26.xml | 74 ++++++++++++++++++++++++ dist/iidx/launcher-27.xml | 69 ++++++++++++++++++++++ dist/iidx/launcher-28.xml | 69 ++++++++++++++++++++++ dist/iidx/launcher-29.xml | 69 ++++++++++++++++++++++ dist/iidx/launcher-30.xml | 69 ++++++++++++++++++++++ dist/iidx/pcbid.xml | 7 +++ dist/jb/ea3-ident.xml | 10 ++++ dist/jb/eamuse-server.xml | 6 ++ dist/jb/gamestart-03.bat | 35 +++++++++-- dist/jb/gamestart-04.bat | 35 +++++++++-- dist/jb/launcher-03.xml | 75 ++++++++++++++++++++++++ dist/jb/launcher-04.xml | 75 ++++++++++++++++++++++++ dist/jb/pcbid.xml | 7 +++ dist/sdvx/ea3-ident.xml | 10 ++++ dist/sdvx/eamuse-server.xml | 6 ++ dist/sdvx/gamestart.bat | 35 +++++++++++ dist/sdvx/launcher.xml | 75 ++++++++++++++++++++++++ dist/sdvx/pcbid.xml | 7 +++ dist/sdvx5/ea3-ident.xml | 10 ++++ dist/sdvx5/eamuse-server.xml | 6 ++ dist/sdvx5/gamestart-cn.bat | 41 +++++++++---- dist/sdvx5/gamestart.bat | 40 +++++++++---- dist/sdvx5/launcher-cn.xml | 74 ++++++++++++++++++++++++ dist/sdvx5/launcher.xml | 74 ++++++++++++++++++++++++ dist/sdvx5/pcbid.xml | 7 +++ dist/shared/ea3-ident.xml | 11 ++++ dist/shared/ea3-license.xml | 8 +++ dist/shared/ea3-service.xml | 7 +++ 70 files changed, 3069 insertions(+), 209 deletions(-) create mode 100644 dist/bst/launcher-01.xml create mode 100644 dist/bst/launcher-02.xml create mode 100644 dist/ddr/launcher-12.xml create mode 100644 dist/ddr/launcher-13.xml create mode 100644 dist/ddr/launcher-14.xml create mode 100644 dist/ddr/launcher-15.xml create mode 100644 dist/ddr/launcher-16.xml create mode 100644 dist/ddr/launcher-17.xml create mode 100644 dist/ddr/launcher-18.xml create mode 100644 dist/iidx/ea3-ident.xml create mode 100644 dist/iidx/eamuse-server.xml create mode 100644 dist/iidx/launcher-18.xml create mode 100644 dist/iidx/launcher-19.xml create mode 100644 dist/iidx/launcher-20.xml create mode 100644 dist/iidx/launcher-21.xml create mode 100644 dist/iidx/launcher-22.xml create mode 100644 dist/iidx/launcher-23.xml create mode 100644 dist/iidx/launcher-24.xml create mode 100644 dist/iidx/launcher-25.xml create mode 100644 dist/iidx/launcher-26.xml create mode 100644 dist/iidx/launcher-27.xml create mode 100644 dist/iidx/launcher-28.xml create mode 100644 dist/iidx/launcher-29.xml create mode 100644 dist/iidx/launcher-30.xml create mode 100644 dist/iidx/pcbid.xml create mode 100644 dist/jb/ea3-ident.xml create mode 100644 dist/jb/eamuse-server.xml create mode 100644 dist/jb/launcher-03.xml create mode 100644 dist/jb/launcher-04.xml create mode 100644 dist/jb/pcbid.xml create mode 100644 dist/sdvx/ea3-ident.xml create mode 100644 dist/sdvx/eamuse-server.xml create mode 100644 dist/sdvx/launcher.xml create mode 100644 dist/sdvx/pcbid.xml create mode 100644 dist/sdvx5/ea3-ident.xml create mode 100644 dist/sdvx5/eamuse-server.xml create mode 100644 dist/sdvx5/launcher-cn.xml create mode 100644 dist/sdvx5/launcher.xml create mode 100644 dist/sdvx5/pcbid.xml create mode 100644 dist/shared/ea3-ident.xml create mode 100644 dist/shared/ea3-license.xml create mode 100644 dist/shared/ea3-service.xml diff --git a/Module.mk b/Module.mk index 36cda9e..afd4539 100644 --- a/Module.mk +++ b/Module.mk @@ -325,6 +325,10 @@ $(zipdir)/iidx-18.zip: \ dist/iidx/config.bat \ dist/iidx/gamestart-18.bat \ dist/iidx/iidxhook-18.conf \ + dist/iidx/launcher-18.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -337,6 +341,7 @@ $(zipdir)/iidx-18-cn.zip: \ build/bin/indep-32/iidxio.dll \ build/bin/indep-32/vefxio.dll \ build/bin/indep-32/inject.exe \ + dist/dwarfstack/32/dwarfstack.dll \ dist/iidx/config.bat \ dist/iidx/gamestart-18-cn.bat \ dist/iidx/iidxhook-18-cn.conf \ @@ -353,9 +358,14 @@ $(zipdir)/iidx-19.zip: \ build/bin/indep-32/geninput.dll \ build/bin/indep-32/iidxio.dll \ build/bin/indep-32/vefxio.dll \ + dist/dwarfstack/32/dwarfstack.dll \ dist/iidx/config.bat \ dist/iidx/gamestart-19.bat \ dist/iidx/iidxhook-19.conf \ + dist/iidx/launcher-19.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -369,9 +379,14 @@ $(zipdir)/iidx-20.zip: \ build/bin/indep-32/geninput.dll \ build/bin/indep-32/iidxio.dll \ build/bin/indep-32/vefxio.dll \ + dist/dwarfstack/32/dwarfstack.dll \ dist/iidx/config.bat \ dist/iidx/gamestart-20.bat \ dist/iidx/iidxhook-20.conf \ + dist/iidx/launcher-20.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -384,6 +399,7 @@ $(zipdir)/iidx-20-cn.zip: \ build/bin/indep-32/iidxio.dll \ build/bin/indep-32/vefxio.dll \ build/bin/indep-32/inject.exe \ + dist/dwarfstack/32/dwarfstack.dll \ dist/iidx/config.bat \ dist/iidx/gamestart-20-cn.bat \ dist/iidx/iidxhook-20-cn.conf \ @@ -400,6 +416,7 @@ $(zipdir)/iidx-21-to-24.zip: \ build/bin/indep-32/geninput.dll \ build/bin/indep-32/iidxio.dll \ build/bin/indep-32/vefxio.dll \ + dist/dwarfstack/32/dwarfstack.dll \ dist/iidx/config.bat \ dist/iidx/gamestart-21.bat \ dist/iidx/gamestart-22.bat \ @@ -409,6 +426,13 @@ $(zipdir)/iidx-21-to-24.zip: \ dist/iidx/iidxhook-22.conf \ dist/iidx/iidxhook-23.conf \ dist/iidx/iidxhook-24.conf \ + dist/iidx/launcher-21.xml \ + dist/iidx/launcher-22.xml \ + dist/iidx/launcher-23.xml \ + dist/iidx/launcher-24.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -422,11 +446,17 @@ $(zipdir)/iidx-25-to-26.zip: \ build/bin/indep-64/geninput.dll \ build/bin/indep-64/iidxio.dll \ build/bin/indep-64/vefxio.dll \ + dist/dwarfstack/64/dwarfstack.dll \ dist/iidx/config.bat \ dist/iidx/gamestart-25.bat \ dist/iidx/gamestart-26.bat \ dist/iidx/iidxhook-25.conf \ dist/iidx/iidxhook-26.conf \ + dist/iidx/launcher-25.xml \ + dist/iidx/launcher-26.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -440,6 +470,7 @@ $(zipdir)/iidx-27-to-30.zip: \ build/bin/indep-64/geninput.dll \ build/bin/indep-64/iidxio.dll \ build/bin/indep-64/vefxio.dll \ + dist/dwarfstack/64/dwarfstack.dll \ dist/iidx/config.bat \ dist/iidx/gamestart-27.bat \ dist/iidx/gamestart-28.bat \ @@ -449,6 +480,13 @@ $(zipdir)/iidx-27-to-30.zip: \ dist/iidx/iidxhook-28.conf \ dist/iidx/iidxhook-29.conf \ dist/iidx/iidxhook-30.conf \ + dist/iidx/launcher-27.xml \ + dist/iidx/launcher-28.xml \ + dist/iidx/launcher-29.xml \ + dist/iidx/launcher-30.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -515,8 +553,13 @@ $(zipdir)/jb-03.zip: \ build/bin/indep-32/eamio.dll \ build/bin/indep-32/geninput.dll \ build/bin/indep-32/jbio.dll \ + dist/dwarfstack/32/dwarfstack.dll \ dist/jb/config.bat \ dist/jb/gamestart-03.bat \ + dist/jb/launcher-03.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -528,8 +571,13 @@ $(zipdir)/jb-04.zip: \ build/bin/indep-32/eamio.dll \ build/bin/indep-32/geninput.dll \ build/bin/indep-32/jbio.dll \ + dist/dwarfstack/32/dwarfstack.dll \ dist/jb/config.bat \ dist/jb/gamestart-03.bat \ + dist/jb/launcher-03.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -541,8 +589,13 @@ $(zipdir)/jb-05-to-07.zip: \ build/bin/indep-32/eamio.dll \ build/bin/indep-32/geninput.dll \ build/bin/indep-32/jbio.dll \ + dist/dwarfstack/32/dwarfstack.dll \ dist/jb/config.bat \ dist/jb/gamestart-04.bat \ + dist/jb/launcher-04.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -554,8 +607,13 @@ $(zipdir)/jb-08.zip: \ build/bin/indep-32/eamio.dll \ build/bin/indep-32/geninput.dll \ build/bin/indep-32/jbio.dll \ + dist/dwarfstack/32/dwarfstack.dll \ dist/jb/config.bat \ dist/jb/gamestart-04.bat \ + dist/jb/launcher-04.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -578,8 +636,13 @@ $(zipdir)/sdvx-01-to-04.zip: \ build/bin/indep-32/eamio.dll \ build/bin/indep-32/geninput.dll \ build/bin/indep-32/sdvxio.dll \ + dist/dwarfstack/32/dwarfstack.dll \ dist/sdvx/config.bat \ dist/sdvx/gamestart.bat \ + dist/sdvx/launcher.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -591,9 +654,14 @@ $(zipdir)/sdvx-05-to-06.zip: \ build/bin/indep-64/eamio.dll \ build/bin/indep-64/geninput.dll \ build/bin/indep-64/sdvxio.dll \ + dist/dwarfstack/64/dwarfstack.dll \ dist/sdvx5/config.bat \ dist/sdvx5/gamestart.bat \ dist/sdvx5/sdvxhook2.conf \ + dist/sdvx5/launcher.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -605,9 +673,14 @@ $(zipdir)/sdvx-05-cn.zip: \ build/bin/indep-64/eamio.dll \ build/bin/indep-64/geninput.dll \ build/bin/indep-64/sdvxio.dll \ + dist/dwarfstack/64/dwarfstack.dll \ dist/sdvx5/config.bat \ dist/sdvx5/gamestart-cn.bat \ dist/sdvx5/sdvxhook2-cn.conf \ + dist/sdvx5/launcher-cn.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -680,8 +753,13 @@ $(zipdir)/ddr-12.zip: \ build/bin/indep-32/ddrio-smx.dll \ build/bin/indep-32/eamio.dll \ build/bin/indep-32/geninput.dll \ + dist/dwarfstack/32/dwarfstack.dll \ dist/ddr/config.bat \ dist/ddr/gamestart-12.bat \ + dist/ddr/launcher-12.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -696,8 +774,13 @@ $(zipdir)/ddr-13.zip: \ build/bin/indep-32/ddrio-smx.dll \ build/bin/indep-32/eamio.dll \ build/bin/indep-32/geninput.dll \ + dist/dwarfstack/32/dwarfstack.dll \ dist/ddr/config.bat \ dist/ddr/gamestart-13.bat \ + dist/ddr/launcher-13.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -710,14 +793,21 @@ $(zipdir)/ddr-14-to-18.zip: \ build/bin/indep-32/ddrio.dll \ build/bin/indep-32/eamio.dll \ build/bin/indep-32/geninput.dll \ + dist/dwarfstack/32/dwarfstack.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 \ dist/ddr/gamestart-17.bat \ dist/ddr/gamestart-18.bat \ + dist/ddr/launcher-14.xml \ + dist/ddr/launcher-15.xml \ + dist/ddr/launcher-16.xml \ + dist/ddr/launcher-17.xml \ + dist/ddr/launcher-18.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -730,12 +820,17 @@ $(zipdir)/ddr-16-to-18-x64.zip: \ build/bin/indep-64/ddrio.dll \ build/bin/indep-64/eamio.dll \ build/bin/indep-64/geninput.dll \ + dist/dwarfstack/64/dwarfstack.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 \ + dist/ddr/launcher-16.xml \ + dist/ddr/launcher-17.xml \ + dist/ddr/launcher-18.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -771,9 +866,15 @@ $(zipdir)/bst.zip: \ build/bin/indep-64/config.exe \ build/bin/indep-64/eamio.dll \ build/bin/indep-64/geninput.dll \ + dist/dwarfstack/64/dwarfstack.dll \ dist/bst/config.bat \ dist/bst/gamestart1.bat \ dist/bst/gamestart2.bat \ + dist/bst/launcher-01.xml \ + dist/bst/launcher-02.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ diff --git a/dist/bst/gamestart1.bat b/dist/bst/gamestart1.bat index 5a3a915..5bca8eb 100644 --- a/dist/bst/gamestart1.bat +++ b/dist/bst/gamestart1.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K bsthook.dll -E prop/ea3-config-1.xml beatstream1.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-01.xml %* \ No newline at end of file diff --git a/dist/bst/gamestart2.bat b/dist/bst/gamestart2.bat index 8b6f53f..55340c3 100644 --- a/dist/bst/gamestart2.bat +++ b/dist/bst/gamestart2.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K bsthook.dll -E prop/ea3-config-2.xml beatstream2.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-02.xml %* \ No newline at end of file diff --git a/dist/bst/launcher-01.xml b/dist/bst/launcher-01.xml new file mode 100644 index 0000000..b62630e --- /dev/null +++ b/dist/bst/launcher-01.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + ∂ + + info + + + /dev/nvram/ea3-config.xml + + + beatstream1.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-server.xml + + + + bsthook.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/bst/launcher-02.xml b/dist/bst/launcher-02.xml new file mode 100644 index 0000000..fdad81d --- /dev/null +++ b/dist/bst/launcher-02.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + beatstream2.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + bsthook.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/gamestart-12.bat b/dist/ddr/gamestart-12.bat index 7df3fa3..03daa9c 100644 --- a/dist/ddr/gamestart-12.bat +++ b/dist/ddr/gamestart-12.bat @@ -1,11 +1,42 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s k-clvsd.dll -regsvr32 /s xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll -.\launcher.exe -K .\ddrhook2.dll .\ddr.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-13.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll \ No newline at end of file diff --git a/dist/ddr/gamestart-13.bat b/dist/ddr/gamestart-13.bat index 7df3fa3..03daa9c 100644 --- a/dist/ddr/gamestart-13.bat +++ b/dist/ddr/gamestart-13.bat @@ -1,11 +1,42 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s k-clvsd.dll -regsvr32 /s xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll -.\launcher.exe -K .\ddrhook2.dll .\ddr.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-13.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll \ No newline at end of file diff --git a/dist/ddr/gamestart-14.bat b/dist/ddr/gamestart-14.bat index 2ad5212..2364f52 100644 --- a/dist/ddr/gamestart-14.bat +++ b/dist/ddr/gamestart-14.bat @@ -1,14 +1,44 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\nvram\coin.xml copy prop\coin.xml conf\nvram\coin.xml -if not exist conf\nvram\eacoin.xml copy prop\eacoin.xml conf\nvram\eacoin.xml -if not exist conf\nvram\share-config.xml copy prop\share-config.xml conf\nvram\share-config.xml -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s k-clvsd.dll -regsvr32 /s xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll +regsvr32 /s %COM_DIR%\xactengine2_10.dll -.\launcher.exe -K .\ddrhook2.dll .\mdxja_945.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-14.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll +regsvr32 /u /s %COM_DIR%\xactengine2_10.dll \ No newline at end of file diff --git a/dist/ddr/gamestart-15.bat b/dist/ddr/gamestart-15.bat index 2ad5212..9730117 100644 --- a/dist/ddr/gamestart-15.bat +++ b/dist/ddr/gamestart-15.bat @@ -1,14 +1,44 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\nvram\coin.xml copy prop\coin.xml conf\nvram\coin.xml -if not exist conf\nvram\eacoin.xml copy prop\eacoin.xml conf\nvram\eacoin.xml -if not exist conf\nvram\share-config.xml copy prop\share-config.xml conf\nvram\share-config.xml -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s k-clvsd.dll -regsvr32 /s xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll +regsvr32 /s %COM_DIR%\xactengine2_10.dll -.\launcher.exe -K .\ddrhook2.dll .\mdxja_945.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-15.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll +regsvr32 /u /s %COM_DIR%\xactengine2_10.dll \ No newline at end of file diff --git a/dist/ddr/gamestart-16.bat b/dist/ddr/gamestart-16.bat index d108118..b176cb3 100644 --- a/dist/ddr/gamestart-16.bat +++ b/dist/ddr/gamestart-16.bat @@ -1,15 +1,44 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\nvram\ea3-config.xml copy prop\eamuse-config.xml conf\nvram\ea3-config.xml -if not exist conf\nvram\coin.xml copy prop\coin.xml conf\nvram\coin.xml -if not exist conf\nvram\eacoin.xml copy prop\eacoin.xml conf\nvram\eacoin.xml -if not exist conf\nvram\testmode-v.xml copy prop\testmode-v.xml conf\nvram\testmode-v.xml -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s com\k-clvsd.dll -regsvr32 /s com\xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll +regsvr32 /s %COM_DIR%\xactengine2_10.dll -.\launcher.exe -H 33554432 -K .\ddrhook2.dll .\arkmdxp3.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-17.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll +regsvr32 /u /s %COM_DIR%\xactengine2_10.dll \ No newline at end of file diff --git a/dist/ddr/gamestart-17.bat b/dist/ddr/gamestart-17.bat index d108118..89c15da 100644 --- a/dist/ddr/gamestart-17.bat +++ b/dist/ddr/gamestart-17.bat @@ -1,15 +1,44 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\nvram\ea3-config.xml copy prop\eamuse-config.xml conf\nvram\ea3-config.xml -if not exist conf\nvram\coin.xml copy prop\coin.xml conf\nvram\coin.xml -if not exist conf\nvram\eacoin.xml copy prop\eacoin.xml conf\nvram\eacoin.xml -if not exist conf\nvram\testmode-v.xml copy prop\testmode-v.xml conf\nvram\testmode-v.xml -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s com\k-clvsd.dll -regsvr32 /s com\xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll +regsvr32 /s %COM_DIR%\xactengine2_10.dll -.\launcher.exe -H 33554432 -K .\ddrhook2.dll .\arkmdxp3.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-17.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll +regsvr32 /u /s %COM_DIR%\xactengine2_10.dll diff --git a/dist/ddr/gamestart-18.bat b/dist/ddr/gamestart-18.bat index d108118..d73ddf3 100644 --- a/dist/ddr/gamestart-18.bat +++ b/dist/ddr/gamestart-18.bat @@ -1,15 +1,44 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\nvram\ea3-config.xml copy prop\eamuse-config.xml conf\nvram\ea3-config.xml -if not exist conf\nvram\coin.xml copy prop\coin.xml conf\nvram\coin.xml -if not exist conf\nvram\eacoin.xml copy prop\eacoin.xml conf\nvram\eacoin.xml -if not exist conf\nvram\testmode-v.xml copy prop\testmode-v.xml conf\nvram\testmode-v.xml -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s com\k-clvsd.dll -regsvr32 /s com\xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll +regsvr32 /s %COM_DIR%\xactengine2_10.dll -.\launcher.exe -H 33554432 -K .\ddrhook2.dll .\arkmdxp3.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-18.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll +regsvr32 /u /s %COM_DIR%\xactengine2_10.dll diff --git a/dist/ddr/launcher-12.xml b/dist/ddr/launcher-12.xml new file mode 100644 index 0000000..54c0284 --- /dev/null +++ b/dist/ddr/launcher-12.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 31457280 + 31457280 + + + info + + + /dev/nvram/ea3-config.xml + + + ddr.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-13.xml b/dist/ddr/launcher-13.xml new file mode 100644 index 0000000..54c0284 --- /dev/null +++ b/dist/ddr/launcher-13.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 31457280 + 31457280 + + + info + + + /dev/nvram/ea3-config.xml + + + ddr.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-14.xml b/dist/ddr/launcher-14.xml new file mode 100644 index 0000000..9ae27ac --- /dev/null +++ b/dist/ddr/launcher-14.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 31457280 + 31457280 + + + info + + + /dev/nvram/ea3-config.xml + + + mdxja_945.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-15.xml b/dist/ddr/launcher-15.xml new file mode 100644 index 0000000..9ae27ac --- /dev/null +++ b/dist/ddr/launcher-15.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 31457280 + 31457280 + + + info + + + /dev/nvram/ea3-config.xml + + + mdxja_945.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-16.xml b/dist/ddr/launcher-16.xml new file mode 100644 index 0000000..cdf16d5 --- /dev/null +++ b/dist/ddr/launcher-16.xml @@ -0,0 +1,76 @@ + + + + bemanitools_local_fs + + + + + + + + + + + + prop/avs-config.xml + 33554432 + 1048576 + + + info + + + /dev/nvram/ea3-config.xml + + + arkmdxp3.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-17.xml b/dist/ddr/launcher-17.xml new file mode 100644 index 0000000..cdf16d5 --- /dev/null +++ b/dist/ddr/launcher-17.xml @@ -0,0 +1,76 @@ + + + + bemanitools_local_fs + + + + + + + + + + + + prop/avs-config.xml + 33554432 + 1048576 + + + info + + + /dev/nvram/ea3-config.xml + + + arkmdxp3.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-18.xml b/dist/ddr/launcher-18.xml new file mode 100644 index 0000000..cdf16d5 --- /dev/null +++ b/dist/ddr/launcher-18.xml @@ -0,0 +1,76 @@ + + + + bemanitools_local_fs + + + + + + + + + + + + prop/avs-config.xml + 33554432 + 1048576 + + + info + + + /dev/nvram/ea3-config.xml + + + arkmdxp3.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/ea3-ident.xml b/dist/iidx/ea3-ident.xml new file mode 100644 index 0000000..e24a9b9 --- /dev/null +++ b/dist/iidx/ea3-ident.xml @@ -0,0 +1,10 @@ + + + + LDJ + J + A + A + 2022082400 + + \ No newline at end of file diff --git a/dist/iidx/eamuse-server.xml b/dist/iidx/eamuse-server.xml new file mode 100644 index 0000000..bc70644 --- /dev/null +++ b/dist/iidx/eamuse-server.xml @@ -0,0 +1,6 @@ + + + + http://localhost + + \ No newline at end of file diff --git a/dist/iidx/gamestart-18.bat b/dist/iidx/gamestart-18.bat index cce99b0..4777dd9 100755 --- a/dist/iidx/gamestart-18.bat +++ b/dist/iidx/gamestart-18.bat @@ -1,14 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist d mkdir d -if not exist e mkdir e -if not exist f mkdir f +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% -launcher -K iidxhook4.dll bm2dx.dll --config iidxhook-18.conf %* +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-18.xml --config %BEMANITOOLS_DIR%\iidxhook-18.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-19.bat b/dist/iidx/gamestart-19.bat index 8bfd580..03c22b0 100755 --- a/dist/iidx/gamestart-19.bat +++ b/dist/iidx/gamestart-19.bat @@ -1,14 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist d mkdir d -if not exist e mkdir e -if not exist f mkdir f +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% -launcher -K iidxhook5.dll bm2dx.dll --config iidxhook-19.conf %* +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-19.xml --config %BEMANITOOLS_DIR%\iidxhook-19.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-20.bat b/dist/iidx/gamestart-20.bat index 2dac80e..f579f2e 100755 --- a/dist/iidx/gamestart-20.bat +++ b/dist/iidx/gamestart-20.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K iidxhook6.dll bm2dx.dll --config iidxhook-20.conf %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-20.xml --config %BEMANITOOLS_DIR%\iidxhook-20.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-21.bat b/dist/iidx/gamestart-21.bat index b79d641..9ec039d 100755 --- a/dist/iidx/gamestart-21.bat +++ b/dist/iidx/gamestart-21.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-21.conf %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-21.xml --config %BEMANITOOLS_DIR%\iidxhook-21.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-22.bat b/dist/iidx/gamestart-22.bat index d10a945..d284786 100755 --- a/dist/iidx/gamestart-22.bat +++ b/dist/iidx/gamestart-22.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-22.conf %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-22.xml --config %BEMANITOOLS_DIR%\iidxhook-22.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-23.bat b/dist/iidx/gamestart-23.bat index 656e1fe..33cceb1 100755 --- a/dist/iidx/gamestart-23.bat +++ b/dist/iidx/gamestart-23.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-23.conf %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-23.xml --config %BEMANITOOLS_DIR%\iidxhook-23.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-24.bat b/dist/iidx/gamestart-24.bat index 283020c..94fa8b2 100755 --- a/dist/iidx/gamestart-24.bat +++ b/dist/iidx/gamestart-24.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-24.conf %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-24.xml --config %BEMANITOOLS_DIR%\iidxhook-24.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-25.bat b/dist/iidx/gamestart-25.bat index edff294..2d6b6c7 100644 --- a/dist/iidx/gamestart-25.bat +++ b/dist/iidx/gamestart-25.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 134217728 -K iidxhook8.dll bm2dx.dll --config iidxhook-25.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-25.xml --config %BEMANITOOLS_DIR%\iidxhook-25.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-26.bat b/dist/iidx/gamestart-26.bat index d41b72b..dc06460 100644 --- a/dist/iidx/gamestart-26.bat +++ b/dist/iidx/gamestart-26.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 134217728 -K iidxhook8.dll bm2dx.dll --config iidxhook-26.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-26.xml --config %BEMANITOOLS_DIR%\iidxhook-26.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-27.bat b/dist/iidx/gamestart-27.bat index 04a3909..d034f84 100644 --- a/dist/iidx/gamestart-27.bat +++ b/dist/iidx/gamestart-27.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 134217728 -B iidxhook9.dll bm2dx.dll --config iidxhook-27.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-27.xml --config %BEMANITOOLS_DIR%\iidxhook-27.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-28.bat b/dist/iidx/gamestart-28.bat index 1abb520..cfc18e4 100644 --- a/dist/iidx/gamestart-28.bat +++ b/dist/iidx/gamestart-28.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 134217728 -B iidxhook9.dll bm2dx.dll --config iidxhook-28.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-28.xml --config %BEMANITOOLS_DIR%\iidxhook-28.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-29.bat b/dist/iidx/gamestart-29.bat index 1029b8c..64a02a5 100644 --- a/dist/iidx/gamestart-29.bat +++ b/dist/iidx/gamestart-29.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 134217728 -B iidxhook9.dll bm2dx.dll --config iidxhook-29.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-29.xml --config %BEMANITOOLS_DIR%\iidxhook-29.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-30.bat b/dist/iidx/gamestart-30.bat index 776d7e8..61f7720 100644 --- a/dist/iidx/gamestart-30.bat +++ b/dist/iidx/gamestart-30.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -modules\launcher -H 134217728 -B iidxhook9.dll bm2dx.dll --config iidxhook-30.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-30.xml --config %BEMANITOOLS_DIR%\iidxhook-30.conf %* \ No newline at end of file diff --git a/dist/iidx/launcher-18.xml b/dist/iidx/launcher-18.xml new file mode 100644 index 0000000..74bf35e --- /dev/null +++ b/dist/iidx/launcher-18.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook4.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-19.xml b/dist/iidx/launcher-19.xml new file mode 100644 index 0000000..1749cfb --- /dev/null +++ b/dist/iidx/launcher-19.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook5.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-20.xml b/dist/iidx/launcher-20.xml new file mode 100644 index 0000000..7af7ce4 --- /dev/null +++ b/dist/iidx/launcher-20.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook6.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-21.xml b/dist/iidx/launcher-21.xml new file mode 100644 index 0000000..502407b --- /dev/null +++ b/dist/iidx/launcher-21.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook7.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-22.xml b/dist/iidx/launcher-22.xml new file mode 100644 index 0000000..502407b --- /dev/null +++ b/dist/iidx/launcher-22.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook7.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-23.xml b/dist/iidx/launcher-23.xml new file mode 100644 index 0000000..502407b --- /dev/null +++ b/dist/iidx/launcher-23.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook7.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-24.xml b/dist/iidx/launcher-24.xml new file mode 100644 index 0000000..502407b --- /dev/null +++ b/dist/iidx/launcher-24.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook7.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-25.xml b/dist/iidx/launcher-25.xml new file mode 100644 index 0000000..733a880 --- /dev/null +++ b/dist/iidx/launcher-25.xml @@ -0,0 +1,74 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook8.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-26.xml b/dist/iidx/launcher-26.xml new file mode 100644 index 0000000..733a880 --- /dev/null +++ b/dist/iidx/launcher-26.xml @@ -0,0 +1,74 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook8.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-27.xml b/dist/iidx/launcher-27.xml new file mode 100644 index 0000000..736ee63 --- /dev/null +++ b/dist/iidx/launcher-27.xml @@ -0,0 +1,69 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + boot + + + + + + + + + + bemanitools/ea3-service.xml + + + + + + iidxhook9.dll + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-28.xml b/dist/iidx/launcher-28.xml new file mode 100644 index 0000000..736ee63 --- /dev/null +++ b/dist/iidx/launcher-28.xml @@ -0,0 +1,69 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + boot + + + + + + + + + + bemanitools/ea3-service.xml + + + + + + iidxhook9.dll + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-29.xml b/dist/iidx/launcher-29.xml new file mode 100644 index 0000000..736ee63 --- /dev/null +++ b/dist/iidx/launcher-29.xml @@ -0,0 +1,69 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + boot + + + + + + + + + + bemanitools/ea3-service.xml + + + + + + iidxhook9.dll + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-30.xml b/dist/iidx/launcher-30.xml new file mode 100644 index 0000000..736ee63 --- /dev/null +++ b/dist/iidx/launcher-30.xml @@ -0,0 +1,69 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + boot + + + + + + + + + + bemanitools/ea3-service.xml + + + + + + iidxhook9.dll + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/pcbid.xml b/dist/iidx/pcbid.xml new file mode 100644 index 0000000..bc50cde --- /dev/null +++ b/dist/iidx/pcbid.xml @@ -0,0 +1,7 @@ + + + + 0101020304050607083F + 0101020304050607083F + + \ No newline at end of file diff --git a/dist/jb/ea3-ident.xml b/dist/jb/ea3-ident.xml new file mode 100644 index 0000000..e24a9b9 --- /dev/null +++ b/dist/jb/ea3-ident.xml @@ -0,0 +1,10 @@ + + + + LDJ + J + A + A + 2022082400 + + \ No newline at end of file diff --git a/dist/jb/eamuse-server.xml b/dist/jb/eamuse-server.xml new file mode 100644 index 0000000..bc70644 --- /dev/null +++ b/dist/jb/eamuse-server.xml @@ -0,0 +1,6 @@ + + + + http://localhost + + \ No newline at end of file diff --git a/dist/jb/gamestart-03.bat b/dist/jb/gamestart-03.bat index 76acc78..39e1b8f 100644 --- a/dist/jb/gamestart-03.bat +++ b/dist/jb/gamestart-03.bat @@ -1,11 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\ea3-config.xml copy prop\ea3-config.xml dev\nvram\ea3-config.xml -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -H 33554432 -K jbhook2.dll jubeat.dll -v +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-03.xml -v %* \ No newline at end of file diff --git a/dist/jb/gamestart-04.bat b/dist/jb/gamestart-04.bat index 245e314..14d95e7 100644 --- a/dist/jb/gamestart-04.bat +++ b/dist/jb/gamestart-04.bat @@ -1,11 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\ea3-config.xml copy prop\ea3-config.xml dev\nvram\ea3-config.xml -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -H 33554432 -K jbhook3.dll jubeat.dll +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-04.xml %* \ No newline at end of file diff --git a/dist/jb/launcher-03.xml b/dist/jb/launcher-03.xml new file mode 100644 index 0000000..095b2f6 --- /dev/null +++ b/dist/jb/launcher-03.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 33554432 + 33554432 + + + info + + + /dev/nvram/ea3-config.xml + + + jubeat.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + jbhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/jb/launcher-04.xml b/dist/jb/launcher-04.xml new file mode 100644 index 0000000..1c85a3c --- /dev/null +++ b/dist/jb/launcher-04.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 33554432 + 33554432 + + + info + + + /dev/nvram/ea3-config.xml + + + jubeat.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + jbhook3.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/jb/pcbid.xml b/dist/jb/pcbid.xml new file mode 100644 index 0000000..bc50cde --- /dev/null +++ b/dist/jb/pcbid.xml @@ -0,0 +1,7 @@ + + + + 0101020304050607083F + 0101020304050607083F + + \ No newline at end of file diff --git a/dist/sdvx/ea3-ident.xml b/dist/sdvx/ea3-ident.xml new file mode 100644 index 0000000..e24a9b9 --- /dev/null +++ b/dist/sdvx/ea3-ident.xml @@ -0,0 +1,10 @@ + + + + LDJ + J + A + A + 2022082400 + + \ No newline at end of file diff --git a/dist/sdvx/eamuse-server.xml b/dist/sdvx/eamuse-server.xml new file mode 100644 index 0000000..bc70644 --- /dev/null +++ b/dist/sdvx/eamuse-server.xml @@ -0,0 +1,6 @@ + + + + http://localhost + + \ No newline at end of file diff --git a/dist/sdvx/gamestart.bat b/dist/sdvx/gamestart.bat index a286325..4e97b92 100644 --- a/dist/sdvx/gamestart.bat +++ b/dist/sdvx/gamestart.bat @@ -8,3 +8,38 @@ if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin if not exist dev\raw mkdir dev\raw launcher -K sdvxhook.dll soundvoltex.dll %* + +@echo off + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher.xml %* \ No newline at end of file diff --git a/dist/sdvx/launcher.xml b/dist/sdvx/launcher.xml new file mode 100644 index 0000000..4876ca7 --- /dev/null +++ b/dist/sdvx/launcher.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + soundvoltex.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + sdvxhook.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/sdvx/pcbid.xml b/dist/sdvx/pcbid.xml new file mode 100644 index 0000000..bc50cde --- /dev/null +++ b/dist/sdvx/pcbid.xml @@ -0,0 +1,7 @@ + + + + 0101020304050607083F + 0101020304050607083F + + \ No newline at end of file diff --git a/dist/sdvx5/ea3-ident.xml b/dist/sdvx5/ea3-ident.xml new file mode 100644 index 0000000..e24a9b9 --- /dev/null +++ b/dist/sdvx5/ea3-ident.xml @@ -0,0 +1,10 @@ + + + + LDJ + J + A + A + 2022082400 + + \ No newline at end of file diff --git a/dist/sdvx5/eamuse-server.xml b/dist/sdvx5/eamuse-server.xml new file mode 100644 index 0000000..bc70644 --- /dev/null +++ b/dist/sdvx5/eamuse-server.xml @@ -0,0 +1,6 @@ + + + + http://localhost + + \ No newline at end of file diff --git a/dist/sdvx5/gamestart-cn.bat b/dist/sdvx5/gamestart-cn.bat index 8435bd7..265fce1 100644 --- a/dist/sdvx5/gamestart-cn.bat +++ b/dist/sdvx5/gamestart-cn.bat @@ -1,17 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\c.dest echo $null >> dev\raw\c.dest -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 268435456 -K sdvxhook2-cn.dll soundvoltex.dll --config sdvxhook2-cn.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-cn.xml --config %BEMANITOOLS_DIR%\sdvxhook2-cn.conf %* \ No newline at end of file diff --git a/dist/sdvx5/gamestart.bat b/dist/sdvx5/gamestart.bat index c1b41dd..2db9289 100644 --- a/dist/sdvx5/gamestart.bat +++ b/dist/sdvx5/gamestart.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 268435456 -K sdvxhook2.dll soundvoltex.dll --config sdvxhook2.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher.xml --config %BEMANITOOLS_DIR%\sdvxhook2.conf %* \ No newline at end of file diff --git a/dist/sdvx5/launcher-cn.xml b/dist/sdvx5/launcher-cn.xml new file mode 100644 index 0000000..4ec2939 --- /dev/null +++ b/dist/sdvx5/launcher-cn.xml @@ -0,0 +1,74 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 268435456 + + + info + + + /dev/nvram/ea3-config.xml + + + soundvoltex.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + sdvxhook2-cn.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/sdvx5/launcher.xml b/dist/sdvx5/launcher.xml new file mode 100644 index 0000000..3ae97c1 --- /dev/null +++ b/dist/sdvx5/launcher.xml @@ -0,0 +1,74 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 268435456 + + + info + + + /dev/nvram/ea3-config.xml + + + soundvoltex.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + sdvxhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/sdvx5/pcbid.xml b/dist/sdvx5/pcbid.xml new file mode 100644 index 0000000..bc50cde --- /dev/null +++ b/dist/sdvx5/pcbid.xml @@ -0,0 +1,7 @@ + + + + 0101020304050607083F + 0101020304050607083F + + \ No newline at end of file diff --git a/dist/shared/ea3-ident.xml b/dist/shared/ea3-ident.xml new file mode 100644 index 0000000..ae4161e --- /dev/null +++ b/dist/shared/ea3-ident.xml @@ -0,0 +1,11 @@ + + + + + 000 + A + A + A + 1969032100 + + \ No newline at end of file diff --git a/dist/shared/ea3-license.xml b/dist/shared/ea3-license.xml new file mode 100644 index 0000000..fef3534 --- /dev/null +++ b/dist/shared/ea3-license.xml @@ -0,0 +1,8 @@ + + + + + 0101020304050607083F + 0101020304050607083F + + \ No newline at end of file diff --git a/dist/shared/ea3-service.xml b/dist/shared/ea3-service.xml new file mode 100644 index 0000000..ffaaa43 --- /dev/null +++ b/dist/shared/ea3-service.xml @@ -0,0 +1,7 @@ + + + + + http://localhost + + \ No newline at end of file From 359ab5a54131b045c862e174cb0a3bf026fa0aa8 Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 18:48:21 +0100 Subject: [PATCH 14/18] refactor(inject): Use new core thread and log modules Keep this a separate commit because this also removes inject's own logging engine and replaces it with the streamlined core API. The core API provides all the features of inject's own logging engine which also performed horribly. The entire logging operation was locked which included expensive operations that formatted the log messages and required memory allocations and copying around data. The core API's implementation at least only synchronizes the actual IO operations (though this can be improved further with an actual async logging sink, TBD) --- src/main/inject/Module.mk | 2 +- src/main/inject/debugger.c | 12 +- src/main/inject/logger.c | 217 ------------------------------------- src/main/inject/logger.h | 28 ----- src/main/inject/main.c | 72 ++++++++++-- 5 files changed, 73 insertions(+), 258 deletions(-) delete mode 100644 src/main/inject/logger.c delete mode 100644 src/main/inject/logger.h diff --git a/src/main/inject/Module.mk b/src/main/inject/Module.mk index 549f179..fd868ef 100644 --- a/src/main/inject/Module.mk +++ b/src/main/inject/Module.mk @@ -5,12 +5,12 @@ ldflags_inject := \ -lpsapi \ libs_inject := \ + core \ util \ src_inject := \ main.c \ debugger.c \ - logger.c \ options.c \ version.c \ diff --git a/src/main/inject/debugger.c b/src/main/inject/debugger.c index 724ed9b..e8e7068 100644 --- a/src/main/inject/debugger.c +++ b/src/main/inject/debugger.c @@ -8,10 +8,11 @@ #include #include -#include "inject/debugger.h" -#include "inject/logger.h" +#include "core/log-bt.h" +#include "core/log.h" + +#include "inject/debugger.h" -#include "util/log.h" #include "util/mem.h" #include "util/proc.h" #include "util/signal.h" @@ -178,6 +179,7 @@ static bool log_debug_str(HANDLE process, const OUTPUT_DEBUG_STRING_INFO *odsi) log_assert(odsi); char *debug_str; + size_t debug_str_len; if (odsi->fUnicode) { debug_str = read_debug_wstr(process, odsi); @@ -186,7 +188,9 @@ static bool log_debug_str(HANDLE process, const OUTPUT_DEBUG_STRING_INFO *odsi) } if (debug_str) { - logger_log(debug_str); + debug_str_len = strlen(debug_str); + + core_log_bt_direct_sink_write(debug_str, debug_str_len); free(debug_str); return true; diff --git a/src/main/inject/logger.c b/src/main/inject/logger.c deleted file mode 100644 index 8f63aa9..0000000 --- a/src/main/inject/logger.c +++ /dev/null @@ -1,217 +0,0 @@ -#define LOG_MODULE "inject-logger" - -#include -#include -#include -#include -#include -#include - -#include "inject/logger.h" -#include "inject/version.h" - -#include "util/log.h" - -static FILE *log_file; -static HANDLE log_mutex; - -static const char *logger_get_formatted_timestamp(void) -{ - static char buffer[64]; - time_t cur = 0; - struct tm *tm = NULL; - - cur = time(NULL); - tm = localtime(&cur); - - strftime(buffer, sizeof(buffer), "[%Y/%m/%d %H:%M:%S] ", tm); - - return buffer; -} - -static char logger_console_determine_color(const char *str) -{ - log_assert(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 logger_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 logger_console( - void *ctx, const char *chars, size_t nchars, const char *timestamp_str) -{ - char color; - size_t color_len; - // See "util/log.c", has to align - char buffer[65536]; - char tmp; - - color_len = logger_msg_coloring_len(chars); - - // 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 = logger_console_determine_color(chars); - - strcpy(buffer, chars); - - // Mask start of log message for coloring - tmp = buffer[color_len]; - buffer[color_len] = '\0'; - - printf("%s", timestamp_str); - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color); - printf("%s", buffer); - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15); - - // Write actual message non colored - buffer[color_len] = tmp; - printf("%s", buffer + color_len); - } else { - printf("%s", chars); - } -} - -static void logger_file( - void *ctx, const char *chars, size_t nchars, const char *timestamp_str) -{ - if (ctx) { - fwrite(timestamp_str, 1, strlen(timestamp_str), (FILE *) ctx); - fwrite(chars, 1, nchars, (FILE *) ctx); - fflush((FILE *) ctx); - } -} - -static void logger_writer(void *ctx, const char *chars, size_t nchars) -{ - const char *timestamp_str; - - // Different threads logging the same destination, e.g. debugger thread, - // main thread - - WaitForSingleObject(log_mutex, INFINITE); - - timestamp_str = logger_get_formatted_timestamp(); - - logger_console(ctx, chars, nchars, timestamp_str); - logger_file(ctx, chars, nchars, timestamp_str); - - ReleaseMutex(log_mutex); -} - -static void logger_log_header() -{ - log_info( - "\n" - " _ _ _ \n" - " (_)_ __ (_) ___ ___| |_ \n" - " | | '_ \\ | |/ _ \\/ __| __|\n" - " | | | | || | __/ (__| |_ \n" - " |_|_| |_|/ |\\___|\\___|\\__|\n" - " |__/ "); - - log_info( - "Inject build date %s, gitrev %s", inject_build_date, inject_gitrev); -} - -bool logger_init(const char *log_file_path) -{ - if (log_file_path) { - log_file = fopen(log_file_path, "w+"); - } else { - log_file = NULL; - } - - log_to_writer(logger_writer, log_file); - - logger_log_header(); - - if (log_file_path) { - log_info("Log file: %s", log_file_path); - - if (!log_file) { - log_warning( - "ERROR: Opening log file %s failed: %s", - log_file_path, - strerror(errno)); - return false; - } - } - - log_mutex = CreateMutex(NULL, FALSE, NULL); - - return true; -} - -void logger_log(const char *str) -{ - logger_writer(log_file, str, strlen(str)); -} - -void logger_finit() -{ - log_misc("Logger finit"); - - if (log_file) { - fclose(log_file); - } - - CloseHandle(log_mutex); -} \ No newline at end of file diff --git a/src/main/inject/logger.h b/src/main/inject/logger.h deleted file mode 100644 index 45a8b77..0000000 --- a/src/main/inject/logger.h +++ /dev/null @@ -1,28 +0,0 @@ -#include - -/** - * Initialize inject's logger backend. - * - * This takes care of hooking and merging the different log - * streams, e.g. inject's local logging and inject's debugger - * receiving remote logging events. - * - * @param log_file_path Path to the file to log to or NULL to - * disable. - */ -bool logger_init(const char *log_file_path); - -/** - * Write a message to the logging backend. - * - * This is used by inject's debugger to redirect log messages - * recevied from the remote process. - * - * @param str String to log - */ -void logger_log(const char *str); - -/** - * Shutdown and cleanup the logging backend. - */ -void logger_finit(); \ No newline at end of file diff --git a/src/main/inject/main.c b/src/main/inject/main.c index bfb6c1b..07026dc 100644 --- a/src/main/inject/main.c +++ b/src/main/inject/main.c @@ -1,3 +1,5 @@ +#define LOG_MODULE "inject" + #include #include @@ -10,18 +12,67 @@ #include "cconfig/cconfig-util.h" #include "cconfig/cmd.h" +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log-sink-file.h" +#include "core/log-sink-list.h" +#include "core/log-sink-mutex.h" +#include "core/log-sink-std.h" +#include "core/log.h" +#include "core/thread-crt-ext.h" +#include "core/thread-crt.h" +#include "core/thread.h" + #include "inject/debugger.h" -#include "inject/logger.h" #include "inject/options.h" #include "inject/version.h" #include "util/cmdline.h" -#include "util/log.h" #include "util/mem.h" #include "util/os.h" #include "util/signal.h" #include "util/str.h" +static void _inject_log_header() +{ + log_info( + "\n" + " _ _ _ \n" + " (_)_ __ (_) ___ ___| |_ \n" + " | | '_ \\ | |/ _ \\/ __| __|\n" + " | | | | || | __/ (__| |_ \n" + " |_|_| |_|/ |\\___|\\___|\\__|\n" + " |__/ "); + + log_info( + "inject build date %s, gitrev %s", inject_build_date, inject_gitrev); +} + +void _inject_log_init( + const char *log_file_path, enum core_log_bt_log_level level) +{ + struct core_log_sink sinks[2]; + struct core_log_sink sink_composed; + struct core_log_sink sink_mutex; + + core_log_bt_ext_impl_set(); + + if (log_file_path) { + core_log_sink_std_out_open(true, &sinks[0]); + core_log_sink_file_open(log_file_path, false, true, 10, &sinks[1]); + core_log_sink_list_open(sinks, 2, &sink_composed); + } else { + core_log_sink_std_out_open(true, &sink_composed); + } + + // Different threads logging the same destination, e.g. debugger thread, + // main thread + core_log_sink_mutex_open(&sink_composed, &sink_mutex); + + core_log_bt_init(&sink_mutex); + core_log_bt_level_set(level); +} + static bool init_options(int argc, char **argv, struct options *options) { options_init(options); @@ -145,7 +196,7 @@ static bool inject_hook_dlls(uint32_t hooks, char **argv) static void signal_shutdown_handler() { debugger_finit(true); - logger_finit(); + core_log_bt_fini(); } int main(int argc, char **argv) @@ -160,9 +211,14 @@ int main(int argc, char **argv) goto init_options_fail; } - if (!logger_init(strlen(options.log_file) > 0 ? options.log_file : NULL)) { - goto init_logger_fail; - } + core_thread_crt_ext_impl_set(); + // TODO expose log level + + _inject_log_init( + strlen(options.log_file) > 0 ? options.log_file : NULL, + CORE_LOG_BT_LOG_LEVEL_MISC); + + _inject_log_header(); os_version_log(); @@ -214,7 +270,7 @@ int main(int argc, char **argv) debugger_finit(false); - logger_finit(); + core_log_bt_fini(); return EXIT_SUCCESS; @@ -226,7 +282,7 @@ inject_hook_dlls_fail: debugger_init_fail: verify_2_fail: verify_fail: - logger_finit(); + core_log_bt_fini(); init_logger_fail: init_options_fail: From 2fe21ae6b7028c81bdab0df8963b39f20d810aab Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 18:53:51 +0100 Subject: [PATCH 15/18] refactor(launcher): Major re-work of launcher Kudos to Shiz for providing the groundwork for this. Fundamentally re-think how launcher operates and bootstrapping the games is managed and configured. This brings it significantly closer to how the original bootstrap is doing the job: launcher now utilizes the data (structures) provided by the bootstrap.xml configuration file. This creates compatibility with vanilla data dumps and original stock images. Note that bemanitools does not include any code or means to run DRM'd data, only decrypted. But, this allows users to keep decrypted dumps as stock as possible which means: * No copying around of property files anymore * Keep the modules/ folder with the binaries * Have bemanitools binaries separate in the data * No need to edit/customize the original configuration files A list of key features of the "new" launcher: * Boostrap games by following the configuration provided by stock game's bootstrap.xml files * Custom launcher.xml configuration file that adds further launcher configurable features, composability of bootstrap.xml configuration(s) as well as configuration overriding/stacking of selected types of configurations, e.g. eamuse config, avs-config. The latter eliminates the need for modifying stock config files in the prop/ folder * Unified logging system: launcher and AVS logging uses the same logger, all output can now be in a single file * Original features such as various hook types still available Due to the significant architectural changes, this also breaks with any backwards compatibility to existing launcher setups. Thus, users need to migrate by re-applying the new configuration format and migrating their config parameters accordingly. Further migration instructions and updated documentation will be provided upon release. Co-authored-by: Shiz --- src/main/launcher/Module.mk | 18 +- src/main/launcher/avs-config.c | 773 +++++++++++++++++++++++ src/main/launcher/avs-config.h | 57 ++ src/main/launcher/avs-context.c | 72 --- src/main/launcher/avs-context.h | 20 - src/main/launcher/avs.c | 270 ++++++++ src/main/launcher/avs.h | 16 + src/main/launcher/bootstrap-config.c | 548 ++++++++++++++++ src/main/launcher/bootstrap-config.h | 139 +++++ src/main/launcher/bootstrap.c | 347 +++++++++++ src/main/launcher/bootstrap.h | 32 + src/main/launcher/debug.c | 33 + src/main/launcher/debug.h | 6 + src/main/launcher/ea3-config.c | 190 ------ src/main/launcher/ea3-config.h | 46 -- src/main/launcher/ea3-ident-config.c | 104 ++++ src/main/launcher/ea3-ident-config.h | 37 ++ src/main/launcher/eamuse-config.c | 125 ++++ src/main/launcher/eamuse-config.h | 23 + src/main/launcher/eamuse.c | 25 + src/main/launcher/eamuse.h | 9 + src/main/launcher/hook.c | 34 + src/main/launcher/hook.h | 6 + src/main/launcher/launcher-config.c | 371 +++++++++++ src/main/launcher/launcher-config.h | 56 ++ src/main/launcher/launcher.c | 587 ++++++++++++++++++ src/main/launcher/launcher.h | 8 + src/main/launcher/main.c | 323 +--------- src/main/launcher/module.c | 159 ++++- src/main/launcher/module.h | 18 +- src/main/launcher/options.c | 206 +++---- src/main/launcher/options.h | 60 +- src/main/launcher/property-util.c | 891 +++++++++++++++++++++++++++ src/main/launcher/property-util.h | 99 +++ src/main/launcher/property.c | 135 ---- src/main/launcher/property.h | 10 - src/main/launcher/stubs.c | 7 +- 37 files changed, 4917 insertions(+), 943 deletions(-) create mode 100644 src/main/launcher/avs-config.c create mode 100644 src/main/launcher/avs-config.h delete mode 100644 src/main/launcher/avs-context.c delete mode 100644 src/main/launcher/avs-context.h create mode 100644 src/main/launcher/avs.c create mode 100644 src/main/launcher/avs.h create mode 100644 src/main/launcher/bootstrap-config.c create mode 100644 src/main/launcher/bootstrap-config.h create mode 100644 src/main/launcher/bootstrap.c create mode 100644 src/main/launcher/bootstrap.h create mode 100644 src/main/launcher/debug.c create mode 100644 src/main/launcher/debug.h delete mode 100644 src/main/launcher/ea3-config.c delete mode 100644 src/main/launcher/ea3-config.h create mode 100644 src/main/launcher/ea3-ident-config.c create mode 100644 src/main/launcher/ea3-ident-config.h create mode 100644 src/main/launcher/eamuse-config.c create mode 100644 src/main/launcher/eamuse-config.h create mode 100644 src/main/launcher/eamuse.c create mode 100644 src/main/launcher/eamuse.h create mode 100644 src/main/launcher/hook.c create mode 100644 src/main/launcher/hook.h create mode 100644 src/main/launcher/launcher-config.c create mode 100644 src/main/launcher/launcher-config.h create mode 100644 src/main/launcher/launcher.c create mode 100644 src/main/launcher/launcher.h create mode 100644 src/main/launcher/property-util.c create mode 100644 src/main/launcher/property-util.h delete mode 100644 src/main/launcher/property.c delete mode 100644 src/main/launcher/property.h diff --git a/src/main/launcher/Module.mk b/src/main/launcher/Module.mk index c9dfd07..39daace 100644 --- a/src/main/launcher/Module.mk +++ b/src/main/launcher/Module.mk @@ -3,22 +3,34 @@ rc_launcher := launcher.rc ldflags_launcher := \ -mconsole \ + -ldbghelp \ deplibs_launcher := \ avs \ avs-ea3 \ libs_launcher := \ + avs-util \ + core \ hook \ util \ src_launcher := \ - avs-context.c \ - ea3-config.c \ + avs-config.c \ + avs.c \ + bootstrap-config.c \ + bootstrap.c \ + debug.c \ + ea3-ident-config.c \ + eamuse-config.c \ + eamuse.c \ + hook.c \ + launcher-config.c \ + launcher.c \ main.c \ module.c \ options.c \ - property.c \ + property-util.c \ stubs.c \ version.c \ diff --git a/src/main/launcher/avs-config.c b/src/main/launcher/avs-config.c new file mode 100644 index 0000000..8669f3d --- /dev/null +++ b/src/main/launcher/avs-config.c @@ -0,0 +1,773 @@ +#define LOG_MODULE "avs-config" + +#include + +#include "avs-util/error.h" + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/avs-config.h" +#include "launcher/property-util.h" + +#include "util/str.h" + +#define AVS_CONFIG_ROOT_NODE "/config" + +static const char *_avs_config_property_mounttable_path = + "/config/fs/mounttable"; + +static void _avs_config_node_vfs_copy( + struct property *parent_property, + struct property_node *parent, + struct property_node *source) +{ + // Use max path size to fit dst and src fs paths + char data[MAX_PATH]; + + // Remark: Using property_node_clone doesn't work here + // Cloning non-deep only clones the vfs node. Cloning deep doesn't seem + // to work with arbitrary attributes that don't follow the general + // design of a property structure. This seems to require clear typing for + // nodes in order to allow property_node_clone to work + + // Ignore errors and default to empty + memset(data, 0, sizeof(data)); + property_node_refer( + NULL, source, "name@", PROPERTY_TYPE_ATTR, data, sizeof(data)); + property_util_node_attribute_replace( + parent_property, parent, "name@", data); + + memset(data, 0, sizeof(data)); + property_node_refer( + NULL, source, "fstype@", PROPERTY_TYPE_ATTR, data, sizeof(data)); + property_util_node_attribute_replace( + parent_property, parent, "fstype@", data); + + memset(data, 0, sizeof(data)); + property_node_refer( + NULL, source, "src@", PROPERTY_TYPE_ATTR, data, sizeof(data)); + property_util_node_attribute_replace(parent_property, parent, "src@", data); + + memset(data, 0, sizeof(data)); + property_node_refer( + NULL, source, "dst@", PROPERTY_TYPE_ATTR, data, sizeof(data)); + property_util_node_attribute_replace(parent_property, parent, "dst@", data); + + memset(data, 0, sizeof(data)); + property_node_refer( + NULL, source, "opt@", PROPERTY_TYPE_ATTR, data, sizeof(data)); + property_util_node_attribute_replace(parent_property, parent, "opt@", data); +} + +static bool _avs_config_mounttable_vfs_nodes_merge_strategy_do( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx, + property_util_node_merge_recursion_do_t node_merge_recursion_do) +{ + struct property_node *parent_child; + struct property_node *source_child; + + char parent_child_name[PROPERTY_NODE_NAME_SIZE_MAX]; + char name_parent[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + char dst_parent[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + + char source_child_name[PROPERTY_NODE_NAME_SIZE_MAX]; + char name_source[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + char dst_source[PROPERTY_NODE_ATTR_NAME_SIZE_MAX]; + + bool node_consumed; + bool found_parent; + + source_child = property_node_traversal(source, TRAVERSE_FIRST_CHILD); + + node_consumed = false; + + while (source_child) { + property_node_name( + source_child, source_child_name, sizeof(source_child_name)); + + if (str_eq(source_child_name, "vfs")) { + node_consumed = true; + + parent_child = + property_node_traversal(parent, TRAVERSE_FIRST_CHILD); + + found_parent = false; + + while (parent_child) { + property_node_name( + parent_child, parent_child_name, sizeof(parent_child_name)); + + if (str_eq(parent_child_name, "vfs")) { + if (AVS_IS_ERROR(property_node_refer( + NULL, + source_child, + "name@", + PROPERTY_TYPE_ATTR, + name_source, + sizeof(name_source)))) { + log_fatal( + "Missing 'name' attribute on avs config mounttable " + "vfs source node"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + source_child, + "dst@", + PROPERTY_TYPE_ATTR, + dst_source, + sizeof(dst_source)))) { + log_fatal( + "Missing 'dst' attribute on avs config mounttable " + "vfs source node"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + parent_child, + "name@", + PROPERTY_TYPE_ATTR, + name_parent, + sizeof(name_parent)))) { + log_fatal( + "Missing 'name' attribute on avs config mounttable " + "vfs parent node"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + parent_child, + "dst@", + PROPERTY_TYPE_ATTR, + dst_parent, + sizeof(dst_parent)))) { + log_fatal( + "Missing 'dst' attribute on avs config mounttable " + "vfs parent node"); + } + + // Found existing matching node on parent, replace it + if (str_eq(name_source, name_parent) && + str_eq(dst_source, dst_parent)) { + _avs_config_node_vfs_copy( + parent_property, parent_child, source_child); + + found_parent = true; + break; + } + } + + parent_child = property_node_traversal( + parent_child, TRAVERSE_NEXT_SIBLING); + } + + // Not found an existing node that got replaced, insert/merge new + // data + if (!found_parent) { + parent_child = property_node_create( + parent_property, parent, PROPERTY_TYPE_VOID, "vfs"); + + _avs_config_node_vfs_copy( + parent_property, parent_child, source_child); + } + } + + source_child = + property_node_traversal(source_child, TRAVERSE_NEXT_SIBLING); + } + + return node_consumed; +} + +struct property *avs_config_load(const char *filepath) +{ + struct property *property; + + log_assert(filepath); + + log_info("Loading from file path: %s", filepath); + + property = property_util_load(filepath); + + // Check if root node exists, call already errors if not + avs_config_root_get(property); + + return property; +} + +struct property_node *avs_config_root_get(struct property *property) +{ + struct property_node *node; + + log_assert(property); + + node = property_search(property, 0, AVS_CONFIG_ROOT_NODE); + + if (node == NULL) { + log_fatal("Root node " AVS_CONFIG_ROOT_NODE " in AVS config missing"); + } + + return node; +} + +struct property * +avs_config_property_merge(struct property *parent, struct property *source) +{ + struct property_util_node_merge_strategies strategies; + + log_assert(parent); + log_assert(source); + + strategies.num = 2; + + strategies.entry[0].path = _avs_config_property_mounttable_path; + strategies.entry[0].merge_strategy_do = + _avs_config_mounttable_vfs_nodes_merge_strategy_do; + + strategies.entry[1].path = ""; + strategies.entry[1].merge_strategy_do = + property_util_node_merge_default_strategy_do; + + return property_util_merge_with_strategies(parent, source, &strategies); +} + +void avs_config_fs_root_device_get( + struct property_node *node, char *buffer, size_t size) +{ + struct property_node *device_node; + avs_error error; + + log_assert(node); + + device_node = property_search(NULL, node, "fs/root/device"); + + if (device_node == NULL) { + log_fatal("Could not find node fs/root/device AVS config"); + } + + error = property_node_read(device_node, PROPERTY_TYPE_STR, buffer, size); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "fs/root/device, property read failed: %s", + avs_util_error_str(error)); + } +} + +void avs_config_mode_product_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace(NULL, node, "mode/product", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "mode/product", enable); +#endif +} + +void avs_config_net_raw_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace(NULL, node, "net/enable_raw", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "net/enable_raw", enable); +#endif +} + +void avs_config_net_eaudp_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace( + NULL, node, "net/eaudp/enable", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "net/eaudp/enable", enable); +#endif +} + +void avs_config_sntp_ea_set(struct property_node *node, bool on) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace(NULL, node, "sntp/ea_on", on ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "sntp/ea_on", on); +#endif +} + +void avs_config_log_level_set(struct property_node *node, const char *level) +{ + log_assert(node); + log_assert(level); + +#if AVS_VERSION <= 1306 + uint32_t level_value; + + if (str_eq(level, "fatal")) { + level_value = 1; + } else if (str_eq(level, "warning")) { + level_value = 2; + } else if (str_eq(level, "info")) { + level_value = 3; + } else if (str_eq(level, "misc")) { + level_value = 4; + } else if (str_eq(level, "all")) { + level_value = 4; + } else if (str_eq(level, "disable")) { + level_value = 0; + } else if (str_eq(level, "default")) { + level_value = 4; + } else { + log_fatal("Unknown log level string %s", level); + } + + property_util_node_u32_replace(NULL, node, "log/level", level_value); +#else + property_util_node_str_replace(NULL, node, "log/level", level); +#endif +} + +void avs_config_log_name_set(struct property_node *node, const char *name) +{ + log_assert(node); + log_assert(name); + + property_util_node_str_replace(NULL, node, "log/name", name); +} + +void avs_config_log_file_set(struct property_node *node, const char *file) +{ + log_assert(node); + log_assert(file); + + property_util_node_str_replace(NULL, node, "log/file", file); +} + +void avs_config_log_buffer_size_set(struct property_node *node, uint32_t size) +{ + log_assert(node); + + property_util_node_u32_replace(NULL, node, "log/sz_buf", size); +} + +void avs_config_log_output_delay_set( + struct property_node *node, uint16_t delay_ms) +{ + log_assert(node); + + property_util_node_u16_replace(NULL, node, "log/output_delay", delay_ms); +} + +void avs_config_log_enable_console_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace( + NULL, node, "log/enable_console", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/enable_console", enable); +#endif +} + +void avs_config_log_enable_sci_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace( + NULL, node, "log/enable_netsci", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/enable_netsci", enable); +#endif +} + +void avs_config_log_enable_net_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace( + NULL, node, "log/enable_netlog", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/enable_netlog", enable); +#endif +} + +void avs_config_log_enable_file_set(struct property_node *node, bool enable) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace( + NULL, node, "log/enable_file", enable ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/enable_file", enable); +#endif +} + +void avs_config_log_rotate_set(struct property_node *node, bool rotate) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace(NULL, node, "log/rotate", rotate ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/rotate", rotate); +#endif +} + +void avs_config_log_append_set(struct property_node *node, bool append) +{ + log_assert(node); + +#if AVS_VERSION <= 1306 + property_util_node_u8_replace(NULL, node, "log/append", append ? 1 : 0); +#else + property_util_node_bool_replace(NULL, node, "log/append", append); +#endif +} + +void avs_config_log_count_set(struct property_node *node, uint16_t count) +{ + log_assert(node); + + property_util_node_u16_replace(NULL, node, "log/gen", count); +} + +void avs_config_set_log_level( + struct property_node *node, enum core_log_bt_log_level loglevel) +{ + const char *str; + + log_assert(node); + + switch (loglevel) { + case CORE_LOG_BT_LOG_LEVEL_OFF: + str = "disable"; + break; + + case CORE_LOG_BT_LOG_LEVEL_FATAL: + str = "fatal"; + break; + + case CORE_LOG_BT_LOG_LEVEL_WARNING: + str = "warn"; + break; + + case CORE_LOG_BT_LOG_LEVEL_INFO: + str = "info"; + break; + + case CORE_LOG_BT_LOG_LEVEL_MISC: + str = "misc"; + break; + + default: + log_fatal("Unsupported log level: %d", loglevel); + break; + } + + avs_config_log_level_set(node, str); +} + +void avs_config_local_fs_path_dev_nvram_and_raw_set( + struct property_node *node, const char *dev_nvram_raw_path) +{ + char path_dev_raw[MAX_PATH]; + char path_dev_nvram[MAX_PATH]; + + struct property_node *fs_node; + struct property_node *mounttable_node; + struct property_node *vfs_node; + + log_assert(node); + log_assert(dev_nvram_raw_path); + + str_cpy(path_dev_raw, sizeof(path_dev_raw), dev_nvram_raw_path); + str_cat(path_dev_raw, sizeof(path_dev_raw), "/dev/raw"); + + str_cpy(path_dev_nvram, sizeof(path_dev_nvram), dev_nvram_raw_path); + str_cat(path_dev_nvram, sizeof(path_dev_nvram), "/dev/nvram"); + + fs_node = property_search(NULL, node, "fs"); + + if (!fs_node) { + log_fatal("Cannot find 'fs' node in avs config"); + } + + // Check if "new" mounttable config is used for dev/nvram and dev/raw or + // legacy config + if (property_search(NULL, fs_node, "mounttable")) { + property_remove(NULL, fs_node, "mounttable"); + + mounttable_node = property_node_create( + NULL, fs_node, PROPERTY_TYPE_VOID, "mounttable"); + + vfs_node = property_node_create( + NULL, mounttable_node, PROPERTY_TYPE_VOID, "vfs"); + + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "name", "boot"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "fstype", "fs"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "src", path_dev_raw); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "dest", "/dev/raw"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "opt", "vf=1,posix=1"); + + vfs_node = property_node_create( + NULL, mounttable_node, PROPERTY_TYPE_VOID, "vfs"); + + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "name", "boot"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "fstype", "fs"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "src", path_dev_nvram); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "dest", "/dev/nvram"); + property_node_create( + NULL, vfs_node, PROPERTY_TYPE_ATTR, "opt", "vf=1,posix=1"); + } else { + property_util_node_str_replace( + NULL, fs_node, "nvram/device", path_dev_raw); + property_util_node_str_replace(NULL, fs_node, "nvram/fstype", "fs"); + property_util_node_str_replace( + NULL, fs_node, "nvram/option", "vf=1,posix=1"); + + property_util_node_str_replace( + NULL, fs_node, "raw/device", path_dev_nvram); + property_util_node_str_replace(NULL, fs_node, "raw/fstype", "fs"); + property_util_node_str_replace( + NULL, fs_node, "raw/option", "vf=1,posix=1"); + } +} + +void avs_config_vfs_mounttable_get( + struct property_node *node, struct avs_config_vfs_mounttable *mounttable) +{ + struct property_node *fs_node; + struct property_node *mounttable_node; + struct property_node *cur; + char mounttable_selector[128]; + char name[128]; + uint8_t pos; + + log_assert(node); + log_assert(mounttable); + + fs_node = property_search(NULL, node, "fs"); + + if (!fs_node) { + log_fatal("Cannot find 'fs' node in avs config"); + } + + // Check if new mounttable config is used for dev/nvram and dev/raw or + // legacy config + mounttable_node = property_search(NULL, fs_node, "mounttable"); + + memset(mounttable, 0, sizeof(*mounttable)); + pos = 0; + + if (mounttable_node) { + cur = property_search(NULL, fs_node, "mounttable_selector"); + + if (!cur) { + log_fatal("Missing 'mounttable_selector' on mounttable"); + } + + if (AVS_IS_ERROR(property_node_read( + cur, + PROPERTY_TYPE_STR, + mounttable_selector, + sizeof(mounttable_selector)))) { + log_fatal("Reading 'mounttable_selector' failed"); + } + + log_misc("Mounttable selector: %s", mounttable_selector); + + cur = property_node_traversal(mounttable_node, TRAVERSE_FIRST_CHILD); + + while (cur) { + property_node_name(cur, name, sizeof(name)); + + if (str_eq(name, "vfs")) { + if (pos >= AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES) { + log_warning( + "Exceeding max number of supported mounttable entries " + "(%d), ignoring remaining", + pos); + break; + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "name@", + PROPERTY_TYPE_ATTR, + name, + sizeof(name)))) { + log_fatal("Missing 'name' attribute on vfs node"); + } + + if (str_eq(name, mounttable_selector)) { + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "fstype@", + PROPERTY_TYPE_ATTR, + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype)))) { + // default + str_cpy( + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype), + "fs"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "src@", + PROPERTY_TYPE_ATTR, + mounttable->entry[pos].src, + sizeof(mounttable->entry[pos].src)))) { + log_fatal( + "Missing 'src' attribute on vfs node, name: %s", + name); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "dst@", + PROPERTY_TYPE_ATTR, + mounttable->entry[pos].dst, + sizeof(mounttable->entry[pos].dst)))) { + log_fatal( + "Missing 'dst' attribute on vfs node, name: %s", + name); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "opt@", + PROPERTY_TYPE_ATTR, + mounttable->entry[pos].opt, + sizeof(mounttable->entry[pos].opt)))) { + // optional + } + + pos++; + } + } + + cur = property_node_traversal(cur, TRAVERSE_NEXT_SIBLING); + } + } else { + cur = property_search(NULL, fs_node, "nvram"); + + if (cur) { + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "fstype", + PROPERTY_TYPE_STR, + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype)))) { + // default + str_cpy( + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype), + "fs"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "device", + PROPERTY_TYPE_STR, + mounttable->entry[pos].src, + sizeof(mounttable->entry[pos].src)))) { + log_fatal("Missing 'device' attribute on nvram node"); + } + + str_cpy( + mounttable->entry[pos].dst, + sizeof(mounttable->entry[pos].dst), + "/dev/nvram"); + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "opt", + PROPERTY_TYPE_STR, + mounttable->entry[pos].opt, + sizeof(mounttable->entry[pos].opt)))) { + // optional + } + + pos++; + } + + cur = property_search(NULL, fs_node, "raw"); + + if (cur) { + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "fstype", + PROPERTY_TYPE_STR, + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype)))) { + // default + str_cpy( + mounttable->entry[pos].fstype, + sizeof(mounttable->entry[pos].fstype), + "fs"); + } + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "device", + PROPERTY_TYPE_STR, + mounttable->entry[pos].src, + sizeof(mounttable->entry[pos].src)))) { + log_fatal("Missing 'device' attribute on raw node"); + } + + str_cpy( + mounttable->entry[pos].dst, + sizeof(mounttable->entry[pos].dst), + "/dev/raw"); + + if (AVS_IS_ERROR(property_node_refer( + NULL, + cur, + "opt", + PROPERTY_TYPE_STR, + mounttable->entry[pos].opt, + sizeof(mounttable->entry[pos].opt)))) { + // optional + } + + pos++; + } + } + + mounttable->num_entries = pos; +} \ No newline at end of file diff --git a/src/main/launcher/avs-config.h b/src/main/launcher/avs-config.h new file mode 100644 index 0000000..692643d --- /dev/null +++ b/src/main/launcher/avs-config.h @@ -0,0 +1,57 @@ +#ifndef LAUNCHER_AVS_CONFIG_H +#define LAUNCHER_AVS_CONFIG_H + +#include "core/log-bt.h" + +#include "imports/avs.h" + +#include "launcher/bootstrap-config.h" + +#define AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES 16 + +struct avs_config_vfs_mounttable { + struct { + char fstype[64]; + char src[512]; + char dst[512]; + char opt[256]; + } entry[AVS_CONFIG_MOUNTTABLE_MAX_ENTRIES]; + + uint8_t num_entries; +}; + +struct property *avs_config_load(const char *filepath); +struct property_node *avs_config_root_get(struct property *property); +struct property * +avs_config_property_merge(struct property *parent, struct property *source); + +void avs_config_fs_root_device_get( + struct property_node *node, char *buffer, size_t size); + +void avs_config_mode_product_set(struct property_node *node, bool enable); +void avs_config_net_raw_set(struct property_node *node, bool enable); +void avs_config_net_eaudp_set(struct property_node *node, bool enable); +void avs_config_sntp_ea_set(struct property_node *node, bool on); +void avs_config_log_level_set(struct property_node *node, const char *level); +void avs_config_log_name_set(struct property_node *node, const char *name); +void avs_config_log_file_set(struct property_node *node, const char *file); +void avs_config_log_buffer_size_set(struct property_node *node, uint32_t size); +void avs_config_log_output_delay_set( + struct property_node *node, uint16_t delay_ms); +void avs_config_log_enable_console_set(struct property_node *node, bool enable); +void avs_config_log_enable_sci_set(struct property_node *node, bool enable); +void avs_config_log_enable_net_set(struct property_node *node, bool enable); +void avs_config_log_enable_file_set(struct property_node *node, bool enable); +void avs_config_log_rotate_set(struct property_node *node, bool rotate); +void avs_config_log_append_set(struct property_node *node, bool append); +void avs_config_log_count_set(struct property_node *node, uint16_t count); + +void avs_config_set_log_level( + struct property_node *node, enum core_log_bt_log_level loglevel); +void avs_config_local_fs_path_dev_nvram_and_raw_set( + struct property_node *node, const char *dev_nvram_raw_path); + +void avs_config_vfs_mounttable_get( + struct property_node *node, struct avs_config_vfs_mounttable *mounttable); + +#endif \ No newline at end of file diff --git a/src/main/launcher/avs-context.c b/src/main/launcher/avs-context.c deleted file mode 100644 index 1e391db..0000000 --- a/src/main/launcher/avs-context.c +++ /dev/null @@ -1,72 +0,0 @@ -#include - -#include -#include -#include - -#include "imports/avs.h" - -#include "launcher/avs-context.h" - -#include "util/log.h" - -static void *avs_heap; - -#ifdef AVS_HAS_STD_HEAP -static void *std_heap; -#endif - -void avs_context_init( - struct property_node *config, - uint32_t avs_heap_size, - uint32_t std_heap_size, - avs_log_writer_t log_writer, - void *log_writer_ctx) -{ - avs_heap = VirtualAlloc( - NULL, avs_heap_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); - - if (avs_heap == NULL) { - log_fatal( - "Failed to VirtualAlloc %d byte AVS heap: %08x", - avs_heap_size, - (unsigned int) GetLastError()); - } - -#ifdef AVS_HAS_STD_HEAP - std_heap = VirtualAlloc( - NULL, std_heap_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); - - if (std_heap == NULL) { - log_fatal( - "Failed to VirtualAlloc %d byte \"std\" heap: %08x", - std_heap_size, - (unsigned int) GetLastError()); - } -#endif - -#ifdef AVS_HAS_STD_HEAP - avs_boot( - config, - std_heap, - std_heap_size, - avs_heap, - avs_heap_size, - log_writer, - log_writer_ctx); -#else - /* AVS v2.16.xx and I suppose onward uses a unified heap */ - avs_boot(config, avs_heap, avs_heap_size, NULL, log_writer, log_writer_ctx); -#endif -} - -void avs_context_fini(void) -{ - avs_shutdown(); - -#ifdef AVS_HAS_STD_HEAP - VirtualFree(std_heap, 0, MEM_RELEASE); -#endif - - VirtualFree(avs_heap, 0, MEM_RELEASE); -} diff --git a/src/main/launcher/avs-context.h b/src/main/launcher/avs-context.h deleted file mode 100644 index d4532eb..0000000 --- a/src/main/launcher/avs-context.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef LAUNCHER_AVS_CONTEXT_H -#define LAUNCHER_AVS_CONTEXT_H - -#include - -#include "imports/avs.h" - -#if AVS_VERSION < 1600 -#define AVS_HAS_STD_HEAP -#endif - -void avs_context_init( - struct property_node *config, - uint32_t avs_heap_size, - uint32_t std_heap_size, - avs_log_writer_t log_writer, - void *log_writer_ctx); -void avs_context_fini(void); - -#endif diff --git a/src/main/launcher/avs.c b/src/main/launcher/avs.c new file mode 100644 index 0000000..4ff0730 --- /dev/null +++ b/src/main/launcher/avs.c @@ -0,0 +1,270 @@ +#define LOG_MODULE "avs" + +#include + +#include +#include +#include + +#include "core/log-bt.h" +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/avs-config.h" +#include "launcher/avs.h" +#include "launcher/property-util.h" + +#include "util/codepage.h" +#include "util/fs.h" +#include "util/mem.h" +#include "util/str.h" + +#if AVS_VERSION < 1600 +#define AVS_HAS_STD_HEAP +#endif + +static void *avs_heap; + +#ifdef AVS_HAS_STD_HEAP +static void *std_heap; +#endif + +/* Gratuitous API changes orz */ +static AVS_LOG_WRITER(_avs_context_log_writer, chars, nchars, ctx) +{ + wchar_t *utf16; + char *utf8; + int utf16_len; + int utf8_len; + int result; + + /* Ignore existing NUL terminator */ + + nchars--; + + /* Transcode shit_jis to UTF-8 */ + + utf16_len = MultiByteToWideChar(CP_SHIFT_JIS, 0, chars, nchars, NULL, 0); + + if (utf16_len == 0) { + abort(); + } + + utf16 = xmalloc(sizeof(*utf16) * utf16_len); + result = + MultiByteToWideChar(CP_SHIFT_JIS, 0, chars, nchars, utf16, utf16_len); + + if (result == 0) { + abort(); + } + + utf8_len = + WideCharToMultiByte(CP_UTF8, 0, utf16, utf16_len, NULL, 0, NULL, NULL); + + if (utf8_len == 0) { + abort(); + } + + utf8 = xmalloc(utf8_len + 3); + result = WideCharToMultiByte( + CP_UTF8, 0, utf16, utf16_len, utf8, utf8_len, NULL, NULL); + + if (result == 0) { + abort(); + } + +#if AVS_VERSION >= 1500 + utf8[utf8_len + 0] = '\r'; + utf8[utf8_len + 1] = '\n'; + + utf8_len += 2; +#endif + + // Clean string terminate + utf8[utf8_len] = '\0'; + + // Write to launcher's dedicated logging backend + core_log_bt_direct_sink_write(utf8, utf8_len); + + /* Clean up */ + + free(utf8); + free(utf16); +} + +static void _avs_switch_log_engine() +{ + // Switch the logging backend now that AVS is booted to use a single logging + // engine which avoids concurrency issues as AVS runs it's own async logger + // thread + core_log_impl_set( + log_body_misc, log_body_info, log_body_warning, log_body_fatal); + + log_misc("Switched logging engine to AVS"); +} + +void avs_fs_assert_root_device_exists(struct property_node *node) +{ + char root_device_path[PATH_MAX]; + char cwd_path[PATH_MAX]; + + avs_config_fs_root_device_get( + node, root_device_path, sizeof(root_device_path)); + getcwd(cwd_path, sizeof(cwd_path)); + + if (!path_exists(root_device_path)) { + log_fatal( + "Root device path '%s' does not exist in current working dir '%s'", + root_device_path, + cwd_path); + } +} + +void avs_fs_mountpoints_fs_dirs_create(struct property_node *node) +{ + struct avs_config_vfs_mounttable mounttable; + uint8_t i; + + avs_config_vfs_mounttable_get(node, &mounttable); + + if (mounttable.num_entries == 0) { + log_warning("No mountpoints found in mounttable"); + } + + for (i = 0; i < mounttable.num_entries; i++) { + if (str_eq(mounttable.entry[i].fstype, "fs")) { + log_misc( + "Creating avs fs directory '%s' for destination/device '%s'...", + mounttable.entry[i].src, + mounttable.entry[i].dst); + + if (!path_exists(mounttable.entry[i].src)) { + if (!path_mkdir(mounttable.entry[i].src)) { + log_fatal( + "Creating fs directory %s failed", + mounttable.entry[i].src); + } + } + } + } +} + +void avs_init( + struct property_node *node, uint32_t avs_heap_size, uint32_t std_heap_size) +{ + log_assert(node); + log_assert(avs_heap_size > 0); + // Modern games don't have a separate std heap anymore + log_assert(std_heap_size >= 0); + + log_info("init"); + + log_misc("Allocating avs heap: %d", avs_heap_size); + + avs_heap = VirtualAlloc( + NULL, avs_heap_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + + if (avs_heap == NULL) { + log_fatal( + "Failed to VirtualAlloc %d byte AVS heap: %08x", + avs_heap_size, + (unsigned int) GetLastError()); + } + +#ifdef AVS_HAS_STD_HEAP + log_misc("Allocating std heap: %d", std_heap_size); + + std_heap = VirtualAlloc( + NULL, std_heap_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + + if (std_heap == NULL) { + log_fatal( + "Failed to VirtualAlloc %d byte \"std\" heap: %08x", + std_heap_size, + (unsigned int) GetLastError()); + } +#endif + + log_info("Calling avs_boot"); + +#ifdef AVS_HAS_STD_HEAP + avs_boot( + node, + std_heap, + std_heap_size, + avs_heap, + avs_heap_size, + _avs_context_log_writer, + NULL); +#else + /* AVS v2.16.xx and I suppose onward uses a unified heap */ + avs_boot( + node, avs_heap, avs_heap_size, NULL, _avs_context_log_writer, NULL); +#endif + + _avs_switch_log_engine(); + + log_misc("init done"); +} + +void avs_fs_file_copy(const char *src, const char *dst) +{ + struct avs_stat st; + + log_assert(src); + log_assert(dst); + + log_misc("Copying %s to %s...", src, dst); + + if (!avs_fs_lstat(src, &st)) { + log_fatal("File source %s does not exist or is not accessible", src); + } + + if (avs_fs_copy(src, dst) < 0) { + log_fatal("Failed copying file %s to %s", src, dst); + } +} + +void avs_fs_dir_log(const char *path) +{ + const char *name; + + log_assert(path); + + avs_desc dir = avs_fs_opendir(path); + + if (dir < 0) { + log_warning( + "Opening avs dir %s failed, skipping logging contents", path); + } + + log_misc("Contents of %s:", path); + + do { + name = avs_fs_readdir(dir); + + if (name == NULL) { + break; + } + + log_misc("%s", name); + } while (name != NULL); + + avs_fs_closedir(dir); +} + +void avs_fini(void) +{ + log_info("fini"); + + avs_shutdown(); + +#ifdef AVS_HAS_STD_HEAP + VirtualFree(std_heap, 0, MEM_RELEASE); +#endif + + VirtualFree(avs_heap, 0, MEM_RELEASE); + + log_misc("fini done"); +} diff --git a/src/main/launcher/avs.h b/src/main/launcher/avs.h new file mode 100644 index 0000000..ad2233a --- /dev/null +++ b/src/main/launcher/avs.h @@ -0,0 +1,16 @@ +#ifndef LAUNCHER_AVS_H +#define LAUNCHER_AVS_H + +#include + +#include "imports/avs.h" + +void avs_fs_assert_root_device_exists(struct property_node *node); +void avs_fs_mountpoints_fs_dirs_create(struct property_node *node); +void avs_init( + struct property_node *node, uint32_t avs_heap_size, uint32_t std_heap_size); +void avs_fs_file_copy(const char *src, const char *dst); +void avs_fs_dir_log(const char *path); +void avs_fini(void); + +#endif diff --git a/src/main/launcher/bootstrap-config.c b/src/main/launcher/bootstrap-config.c new file mode 100644 index 0000000..35915c6 --- /dev/null +++ b/src/main/launcher/bootstrap-config.c @@ -0,0 +1,548 @@ +#define LOG_MODULE "bootstrap-config" + +#include + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/avs-config.h" +#include "launcher/bootstrap-config.h" +#include "launcher/property-util.h" + +#include "util/defs.h" +#include "util/hex.h" +#include "util/str.h" + +// clang-format off +PSMAP_BEGIN(bootstrap_startup_boot_psmap) +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct bootstrap_boot_config, config_file, + "boot/file") +PSMAP_REQUIRED(PSMAP_TYPE_U32, struct bootstrap_boot_config, avs_heap_size, + "boot/heap_avs") +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_boot_config, std_heap_size, + "boot/heap_std", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_boot_config, mount_table_selector, + "boot/mounttable_selector", "boot") +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_boot_config, watcher_enable, + "boot/watcher", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_boot_config, timemachine_enable, + "boot/timemachine", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_boot_config, launch_config_file, + "boot/launch_path", "/dev/raw/launch.xml") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_log_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_log_config, level, + "log/level", "all") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_log_config, name, + "log/name", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_log_config, file, + "log/file", "") +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_log_config, bufsz, + "log/sz_buf", 4096) +PSMAP_OPTIONAL(PSMAP_TYPE_U16, struct bootstrap_log_config, output_delay_ms, + "log/output_delay", 10) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_console, + "log/enable_console", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_sci, + "log/enable_netsci", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_net, + "log/enable_netlog", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, enable_file, + "log/enable_file", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, rotate, + "log/rotate", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_log_config, append, + "log/append", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_U16, struct bootstrap_log_config, count, + "log/gen", 10) +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_minidump_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_U8, struct bootstrap_minidump_config, count, + "minidump/gen", 10) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_minidump_config, continue_, + "minidump/cont_debug", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_minidump_config, log, + "minidump/echo_log", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_U8, struct bootstrap_minidump_config, type, + "minidump/dump_type", 2) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_minidump_config, path, + "minidump/path", "/dev/raw/minidump") +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_minidump_config, symbufsz, + "minidump/sz_symbuf", 32768) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_minidump_config, search_path, + "minidump/search", ".") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_module_psmap) +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct bootstrap_module_config, file, + "component/file") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_module_config, load_type, + "component/load_type", "MEMORY") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_dlm_psmap) +/* disabled until we implement PSMAP_TYPE_BIN + PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_startup_config, ntdll_digest, + "dlml/ntdll/hash", "") + */ +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, size, + "dlml/ntdll/size", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, ift_table, + "dlml/ntdll/ift_table", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, ift_insert, + "dlml/ntdll/insert_ift", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_dlm_config, ift_remove, + "dlml/ntdll/remove_ift", 0) +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_shield_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_shield_config, enable, + "shield/enable", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_shield_config, verbose, + "shield/verbose", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_shield_config, use_loadlibrary, + "shield/use_loadlibrary", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_shield_config, logger, + "shield/logger", "") +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, sleep_min, + "shield/sleepmin", 10) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, sleep_blur, + "shield/sleepblur", 90) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_shield_config, whitelist_file, + "shield/whitelist", "prop/whitelist.csv") +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, tick_sleep, + "shield/ticksleep", 100) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, tick_error, + "shield/tickerror", 1000) +PSMAP_OPTIONAL(PSMAP_TYPE_U8, struct bootstrap_shield_config, overwork_threshold, + "shield/overwork_threshold", 50) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, overwork_delay, + "shield/overwork_delay", 100) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_shield_config, pause_delay, + "shield/pause_delay", 1000) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_shield_config, unlimited_key, + "shield/unlimited_key", "") +PSMAP_OPTIONAL(PSMAP_TYPE_U16, struct bootstrap_shield_config, killer_port, + "shield_killer/port", 5001) +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_dongle_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_dongle_config, license_cn, + "dongle/license", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_dongle_config, account_cn, + "dongle/account", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_dongle_config, driver_dll, + "dongle/pkcs11_driver", "eTPKCS11.dll") +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_dongle_config, disable_gc, + "dongle/disable_gc", 0) +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_drm_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, dll, + "drm/dll", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, fstype, + "drm/fstype", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, device, + "drm/device", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, mount, + "drm/dst", "/") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_drm_config, options, + "drm/option", "") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_lte_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_lte_config, enable, + "lte/enable", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_lte_config, config_file, + "lte/file", "/dev/nvram/lte-config.xml") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_lte_config, unlimited_key, + "lte/unlimited_key", "") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_ssl_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_ssl_config, options, + "ssl/option", "") +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_esign_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_esign_config, enable, + "esign/enable", 0) +PSMAP_END + +PSMAP_BEGIN(bootstrap_startup_eamuse_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, enable, + "eamuse/enable", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, sync, + "eamuse/sync", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, enable_model, + "eamuse/enable_model", 0) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_eamuse_config, config_file, + "eamuse/file", "/dev/nvram/ea3-config.xml") +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct bootstrap_eamuse_config, updatecert_enable, + "eamuse/updatecert_enable", 1) +PSMAP_OPTIONAL(PSMAP_TYPE_U32, struct bootstrap_eamuse_config, updatecert_interval, + "eamuse/updatecert_interval", 0) +PSMAP_END + +PSMAP_BEGIN(bootstrap_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct bootstrap_config, release_code, "/release_code", "") +PSMAP_END +// clang-format on + +#define ROOT_NODE "/config" +#define MODULE_PATH_PREFIX "modules/" + +#define NODE_MISSING_FATAL(subnode) \ + log_fatal("%s/%s: Node missing", ROOT_NODE, subnode); +#define NODE_STARTUP_MISSING_FATAL(profile) \ + log_fatal("%s/startup/%s: Node missing", ROOT_NODE, profile); +#define NODE_PROFILE_MISSING_FATAL(profile, subnode) \ + log_fatal("%s/%s/%s: Node missing", ROOT_NODE, profile, subnode); +#define NODE_PROFILE_LOADING_FATAL(profile, subnode) \ + log_fatal("%s/startup/%s/%s: Node loading", ROOT_NODE, profile, subnode); + +#define DEFAULT_HEAP_SIZE 16777216 + +const char *const inherited_nodes[] = { + "develop", + "default", + "log", + "minidump", + "boot", + "drm", + "ssl", + "eamuse", + "shield", + "esign", + "dongle", + "lte", +}; + +static void _bootstrap_config_profile_node_verify( + struct property_node *node, const char *profile) +{ + struct property_node *profile_node; + + log_assert(node); + log_assert(profile); + + profile_node = property_search(NULL, node, profile); + + if (!profile_node) { + NODE_STARTUP_MISSING_FATAL(profile); + } +} + +static struct property_node * +_bootstrap_config_root_node_get(struct property *property) +{ + struct property_node *root_node; + + log_assert(property); + + root_node = property_search(property, NULL, ROOT_NODE); + + if (!root_node) { + NODE_MISSING_FATAL(""); + } + + return root_node; +} + +static struct property_node * +_bootstrap_config_startup_node_get(struct property_node *node) +{ + struct property_node *startup_node; + + log_assert(node); + + startup_node = property_search(NULL, node, "startup"); + + if (!startup_node) { + NODE_MISSING_FATAL("startup"); + } + + return startup_node; +} + +static void _bootstrap_config_inheritance_resolve( + struct property_node *startup_node, const char *profile_name) +{ + struct property_node *startup_parent_node; + struct property_node *startup_profile_node; + struct property_node *tmp_node; + + char inherit_name[64]; + avs_error error; + struct property_node *result; + + startup_profile_node = property_search(NULL, startup_node, profile_name); + + if (!startup_profile_node) { + log_fatal(ROOT_NODE "/startup/%s: missing", profile_name); + } + + startup_parent_node = startup_profile_node; + + for (;;) { + error = property_node_refer( + NULL, + startup_parent_node, + "inherit@", + PROPERTY_TYPE_ATTR, + inherit_name, + sizeof(inherit_name)); + + if (AVS_IS_ERROR(error)) { + break; + } + + startup_parent_node = property_search(NULL, startup_node, inherit_name); + + if (!startup_parent_node) { + NODE_STARTUP_MISSING_FATAL(inherit_name); + } + + for (int i = 0; i < _countof(inherited_nodes); i++) { + if (property_search(NULL, startup_node, inherited_nodes[i])) { + continue; + } + + tmp_node = + property_search(NULL, startup_parent_node, inherited_nodes[i]); + + if (tmp_node) { + log_misc( + ROOT_NODE "/startup/%s: merging %s...", + inherit_name, + inherited_nodes[i]); + + result = property_node_clone( + NULL, startup_profile_node, tmp_node, true); + + if (!result) { + log_fatal( + "Merging '%s' into '%s' failed", + inherited_nodes[i], + inherit_name); + } + } + } + } +} + +static void _bootstrap_config_load_bootstrap_module_app_config( + struct property_node *profile_node, struct bootstrap_module_config *config) +{ + struct property_node *app_node; + + log_assert(profile_node); + log_assert(config); + + app_node = property_search(NULL, profile_node, "component/param"); + + config->app_config = property_util_node_extract(app_node); +} + +static void _bootstrap_config_load_bootstrap_default_files_config( + const char *profile_name, + struct property_node *profile_node, + struct bootstrap_default_file_config *config) +{ + int i; + int result; + struct property_node *child; + + log_assert(profile_node); + log_assert(config); + + child = property_search(NULL, profile_node, "default/file"); + i = 0; + + while (child) { + if (i >= DEFAULT_FILE_MAX) { + log_warning( + "Currently not supporting more than %d default files, skipping " + "remaining", + i); + break; + } + + result = property_node_refer( + NULL, + child, + "src@", + PROPERTY_TYPE_ATTR, + &config->file[i].src, + sizeof(config->file[i].src)); + + if (result < 0) { + log_fatal( + "Missing src attribute on default file node of profile %s", + profile_name); + } + + result = property_node_refer( + NULL, + child, + "dst@", + PROPERTY_TYPE_ATTR, + &config->file[i].dst, + sizeof(config->file[i].dst)); + + if (result < 0) { + log_fatal( + "Missing dst attribute on default file node of profile %s", + profile_name); + } + + child = property_node_traversal(child, TRAVERSE_NEXT_SEARCH_RESULT); + i++; + } +} + +static void _bootstrap_config_load_bootstrap( + struct property_node *startup_node, + const char *profile, + struct bootstrap_startup_config *config) +{ + struct property_node *profile_node; + + profile_node = property_search(NULL, startup_node, profile); + + if (!profile_node) { + NODE_PROFILE_LOADING_FATAL(profile, ""); + } + + _bootstrap_config_load_bootstrap_default_files_config( + profile, profile_node, &config->default_file); + + if (!property_psmap_import( + NULL, profile_node, &config->boot, bootstrap_startup_boot_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "boot"); + } + + if (!property_psmap_import( + NULL, profile_node, &config->log, bootstrap_startup_log_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "log"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->minidump, + bootstrap_startup_minidump_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "minidump"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->module, + bootstrap_startup_module_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "component"); + } + + _bootstrap_config_load_bootstrap_module_app_config( + profile_node, &config->module); + + if (!property_psmap_import( + NULL, + profile_node, + &config->dlm_ntdll, + bootstrap_startup_dlm_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "dlm/ntdll"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->shield, + bootstrap_startup_shield_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "shield"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->dongle, + bootstrap_startup_dongle_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "dongle"); + } + + if (!property_psmap_import( + NULL, profile_node, &config->drm, bootstrap_startup_drm_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "drm"); + } + + if (!property_psmap_import( + NULL, profile_node, &config->lte, bootstrap_startup_lte_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "lte"); + } + + if (!property_psmap_import( + NULL, profile_node, &config->ssl, bootstrap_startup_ssl_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "ssl"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->esign, + bootstrap_startup_esign_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "esign"); + } + + if (!property_psmap_import( + NULL, + profile_node, + &config->eamuse, + bootstrap_startup_eamuse_psmap)) { + NODE_PROFILE_LOADING_FATAL(profile, "eamuse"); + } +} + +void bootstrap_config_init(struct bootstrap_config *config) +{ + log_assert(config); + + memset(config, 0, sizeof(*config)); +} + +void bootstrap_config_load( + struct property *property, + const char *profile, + struct bootstrap_config *config) +{ + struct property_node *root_node; + struct property_node *startup_node; + + log_assert(property); + log_assert(profile); + log_assert(config); + + log_info(ROOT_NODE ": loading..."); + + root_node = _bootstrap_config_root_node_get(property); + + if (!property_psmap_import(NULL, root_node, config, bootstrap_psmap)) { + log_fatal(ROOT_NODE ": loading failed"); + } + + startup_node = _bootstrap_config_startup_node_get(root_node); + + _bootstrap_config_profile_node_verify(startup_node, profile); + + _bootstrap_config_inheritance_resolve(startup_node, profile); + + log_misc(ROOT_NODE "/startup/%s: loading merged result...", profile); + + property_util_node_log(startup_node); + + _bootstrap_config_load_bootstrap(startup_node, profile, &config->startup); + + log_misc("Loading finished"); +} \ No newline at end of file diff --git a/src/main/launcher/bootstrap-config.h b/src/main/launcher/bootstrap-config.h new file mode 100644 index 0000000..596bf93 --- /dev/null +++ b/src/main/launcher/bootstrap-config.h @@ -0,0 +1,139 @@ +#ifndef LAUNCHER_BOOTSTRAP_CONFIG_H +#define LAUNCHER_BOOTSTRAP_CONFIG_H + +#include +#include + +#include "imports/avs.h" + +// should be enough for a while +#define DEFAULT_FILE_MAX 16 + +struct bootstrap_startup_config { + struct bootstrap_default_file_config { + struct bootstrap_default_file { + char src[64]; + char dst[64]; + } file[DEFAULT_FILE_MAX]; + } default_file; + + struct bootstrap_boot_config { + char config_file[64]; + uint32_t avs_heap_size; + uint32_t std_heap_size; + char launch_config_file[64]; + char mount_table_selector[16]; + bool watcher_enable; + bool timemachine_enable; + } boot; + + struct bootstrap_log_config { + char level[8]; + char name[64]; + char file[64]; + uint32_t bufsz; + uint16_t output_delay_ms; + bool enable_console; + bool enable_sci; + bool enable_net; + bool enable_file; + bool rotate; + bool append; + uint16_t count; + } log; + + struct bootstrap_minidump_config { + uint8_t count; + bool continue_; + bool log; + uint8_t type; + char path[64]; + uint32_t symbufsz; + char search_path[64]; + } minidump; + + struct bootstrap_module_config { + char file[64]; + char load_type[64]; + struct property *app_config; + } module; + + struct bootstrap_dlm_config { + char digest[16]; + uint32_t size; + uint32_t ift_table; + uint32_t ift_insert; + uint32_t ift_remove; + }; + + struct bootstrap_dlm_config dlm_ntdll; + + struct bootstrap_shield_config { + bool enable; + bool verbose; + bool use_loadlibrary; + char logger[64]; + uint32_t sleep_min; + uint32_t sleep_blur; + uint32_t tick_sleep; + uint32_t tick_error; + uint8_t overwork_threshold; + uint32_t overwork_delay; + uint32_t pause_delay; + char whitelist_file[64]; + char unlimited_key[10]; + uint16_t killer_port; + } shield; + + struct bootstrap_dongle_config { + char license_cn[32]; + char account_cn[32]; + char driver_dll[16]; + bool disable_gc; + } dongle; + + struct bootstrap_drm_config { + char dll[64]; + char device[64]; + char mount[64]; + char fstype[64]; + char options[64]; + } drm; + + struct bootstrap_lte_config { + bool enable; + char config_file[64]; + char unlimited_key[10]; + } lte; + + struct bootstrap_ssl_config { + char options[64]; + } ssl; + + struct bootstrap_esign_config { + bool enable; + } esign; + + struct bootstrap_eamuse_config { + bool enable; + bool sync; + bool enable_model; + char config_file[64]; + bool updatecert_enable; + uint32_t updatecert_interval; + } eamuse; +}; + +struct bootstrap_config { + char release_code[16]; + struct bootstrap_startup_config startup; +}; + +void bootstrap_config_init(struct bootstrap_config *config); + +void bootstrap_config_load( + struct property *property, + const char *profile, + struct bootstrap_config *config); + +#endif /* LAUNCHER_BOOTSTRAP_CONFIG_H */ diff --git a/src/main/launcher/bootstrap.c b/src/main/launcher/bootstrap.c new file mode 100644 index 0000000..a9e52bb --- /dev/null +++ b/src/main/launcher/bootstrap.c @@ -0,0 +1,347 @@ +#define LOG_MODULE "bootstrap" + +#include "core/log-bt.h" +#include "core/log-sink-file.h" +#include "core/log-sink-list.h" +#include "core/log-sink-null.h" +#include "core/log-sink-std.h" +#include "core/log.h" + +#include "launcher/avs-config.h" +#include "launcher/avs.h" +#include "launcher/bootstrap-config.h" +#include "launcher/ea3-ident-config.h" +#include "launcher/eamuse-config.h" +#include "launcher/eamuse.h" +#include "launcher/launcher-config.h" +#include "launcher/module.h" +#include "launcher/property-util.h" + +#include "util/str.h" + +static bool _bootstrap_log_property_configs; +static struct module_context _bootstrap_module_context; + +static void _bootstrap_eamuse_ea3_ident_config_inject( + struct property_node *node, const struct ea3_ident_config *ea3_ident_config) +{ + eamuse_config_id_softid_set(node, ea3_ident_config->softid); + eamuse_config_id_hardid_set(node, ea3_ident_config->hardid); + eamuse_config_id_pcbid_set(node, ea3_ident_config->pcbid); + eamuse_config_soft_model_set(node, ea3_ident_config->model); + eamuse_config_soft_dest_set(node, ea3_ident_config->dest); + eamuse_config_soft_spec_set(node, ea3_ident_config->spec); + eamuse_config_soft_rev_set(node, ea3_ident_config->rev); + eamuse_config_soft_ext_set(node, ea3_ident_config->ext); +} + +static void +_bootstrap_avs_config_force_overrides_apply(struct property_node *node) +{ + log_assert(node); + + avs_config_mode_product_set(node, true); + avs_config_net_raw_set(node, true); + avs_config_net_eaudp_set(node, true); + avs_config_sntp_ea_set(node, true); +} + +static void _bootstrap_avs_config_log_overrides_apply( + struct property_node *node, const struct bootstrap_log_config *log_config) +{ + log_assert(node); + log_assert(log_config); + + avs_config_log_level_set(node, log_config->level); + avs_config_log_name_set(node, log_config->name); + avs_config_log_file_set(node, log_config->file); + avs_config_log_buffer_size_set(node, log_config->bufsz); + avs_config_log_output_delay_set(node, log_config->output_delay_ms); + avs_config_log_enable_console_set(node, log_config->enable_console); + avs_config_log_enable_sci_set(node, log_config->enable_sci); + avs_config_log_enable_net_set(node, log_config->enable_net); + avs_config_log_enable_file_set(node, log_config->enable_file); + avs_config_log_rotate_set(node, log_config->rotate); + avs_config_log_append_set(node, log_config->append); + avs_config_log_count_set(node, log_config->count); +} + +static enum core_log_bt_log_level _bootstrap_log_map_level(const char *level) +{ + if (str_eq(level, "fatal")) { + return CORE_LOG_BT_LOG_LEVEL_FATAL; + } else if (str_eq(level, "warning")) { + return CORE_LOG_BT_LOG_LEVEL_WARNING; + } else if (str_eq(level, "info")) { + return CORE_LOG_BT_LOG_LEVEL_INFO; + } else if (str_eq(level, "misc")) { + return CORE_LOG_BT_LOG_LEVEL_MISC; + } else if (str_eq(level, "all")) { + return CORE_LOG_BT_LOG_LEVEL_MISC; + } else if (str_eq(level, "disable")) { + return CORE_LOG_BT_LOG_LEVEL_OFF; + } else if (str_eq(level, "default")) { + return CORE_LOG_BT_LOG_LEVEL_WARNING; + } else { + log_fatal("Unknown log level string %s", level); + } +} + +void bootstrap_init(bool log_property_configs) +{ + log_info("init"); + + _bootstrap_log_property_configs = log_property_configs; + + log_misc("init done"); +} + +void bootstrap_log_init(const struct bootstrap_log_config *config) +{ + struct core_log_sink sinks[2]; + struct core_log_sink sink_composed; + enum core_log_bt_log_level level; + + log_assert(config); + + log_info("log init"); + + // Shutdown old setup + core_log_bt_fini(); + + if (config->enable_file && strlen(config->file) > 0 && + config->enable_console) { + core_log_sink_std_out_open(true, &sinks[0]); + core_log_sink_file_open( + config->file, + config->append, + config->rotate, + config->count, + &sinks[1]); + core_log_sink_list_open(sinks, 2, &sink_composed); + } else if (config->enable_file && strlen(config->file) > 0) { + core_log_sink_file_open( + config->file, + config->append, + config->rotate, + config->count, + &sink_composed); + } else if (config->enable_console) { + core_log_sink_std_out_open(true, &sink_composed); + } else { + core_log_sink_null_open(&sink_composed); + } + + core_log_bt_init(&sink_composed); + + level = _bootstrap_log_map_level(config->level); + core_log_bt_level_set(level); + + log_misc("log init done"); +} + +void bootstrap_default_files_create( + const struct bootstrap_default_file_config *config) +{ + log_assert(config); + + log_info("default files create"); + + for (int i = 0; i < DEFAULT_FILE_MAX; i++) { + if (strlen(config->file[i].src) > 0 && + strlen(config->file[i].dst) > 0) { + avs_fs_file_copy(config->file[i].src, config->file[i].dst); + } + } + + log_misc("default files create done"); +} + +void bootstrap_avs_init( + const struct bootstrap_boot_config *config, + const struct bootstrap_log_config *log_config, + struct property *override_property) +{ + struct property *file_property; + struct property *merged_property; + struct property_node *root_node; + + log_assert(config); + log_assert(log_config); + log_assert(override_property); + + log_info("avs init"); + + file_property = avs_config_load(config->config_file); + + if (_bootstrap_log_property_configs) { + log_misc("avs-config from file: %s", config->config_file); + property_util_log(file_property); + } + + merged_property = + avs_config_property_merge(file_property, override_property); + + property_util_free(file_property); + + if (_bootstrap_log_property_configs) { + log_misc("avs-config merged with overrides"); + property_util_log(merged_property); + } + + root_node = avs_config_root_get(merged_property); + + _bootstrap_avs_config_force_overrides_apply(root_node); + _bootstrap_avs_config_log_overrides_apply(root_node, log_config); + + if (_bootstrap_log_property_configs) { + log_misc("avs-config final"); + property_util_log(merged_property); + } + + avs_fs_assert_root_device_exists(root_node); + + log_misc("Creating AVS file system directories..."); + + avs_fs_mountpoints_fs_dirs_create(root_node); + + avs_init(root_node, config->avs_heap_size, config->std_heap_size); + + property_util_free(merged_property); + + log_misc("avs init done"); +} + +void bootstrap_eamuse_init( + const struct bootstrap_eamuse_config *config, + const struct ea3_ident_config *ea3_ident_config, + struct property *override_property) +{ + struct property *file_property; + struct property *merged_property; + struct property_node *root_node; + + log_assert(config); + log_assert(ea3_ident_config); + log_assert(override_property); + + log_info("eamuse init"); + + if (config->enable) { + file_property = eamuse_config_avs_load(config->config_file); + + if (_bootstrap_log_property_configs) { + log_misc("eamuse-config from file: %s", config->config_file); + property_util_log(file_property); + } + + merged_property = property_util_merge(file_property, override_property); + + property_util_free(file_property); + + if (_bootstrap_log_property_configs) { + log_misc("eamuse-config merged with overrides"); + property_util_log(merged_property); + } + + root_node = eamuse_config_root_get(merged_property); + + _bootstrap_eamuse_ea3_ident_config_inject(root_node, ea3_ident_config); + + if (_bootstrap_log_property_configs) { + log_misc("eamuse-config final"); + property_util_log(merged_property); + } + + eamuse_init(root_node); + + property_util_free(merged_property); + } else { + log_warning("Eamuse disabled"); + } + + log_misc("eamuse init done"); +} + +void bootstrap_module_init( + const struct bootstrap_module_config *module_config, + const struct array *iat_hook_dlls) +{ + log_assert(module_config); + log_assert(iat_hook_dlls); + + log_info("module init"); + + if (iat_hook_dlls->nitems > 0) { + log_info( + "Load game DLL with IAT hooks (%d): %s", + (uint32_t) iat_hook_dlls->nitems, + module_config->file); + + module_with_iat_hooks_init( + &_bootstrap_module_context, module_config->file, iat_hook_dlls); + } else { + log_info("Load game DLL: %s", module_config->file); + + module_init(&_bootstrap_module_context, module_config->file); + } + + log_misc("module init done"); +} + +void bootstrap_module_game_init( + const struct bootstrap_module_config *module_config, + struct ea3_ident_config *ea3_ident_config) +{ + struct property_node *node; + + log_assert(module_config); + log_assert(ea3_ident_config); + + log_info("module game init"); + + node = property_search(module_config->app_config, NULL, "/param"); + + if (!node) { + log_fatal("Missing param node on app-config"); + } + + if (_bootstrap_log_property_configs) { + log_misc("app-config"); + property_util_node_log(node); + } + + module_init_invoke(&_bootstrap_module_context, ea3_ident_config, node); + + log_misc("module game init done"); +} + +void bootstrap_module_game_run() +{ + log_info("module game run"); + + module_main_invoke(&_bootstrap_module_context); +} + +void bootstrap_module_game_fini() +{ + log_info("module game fini"); + + module_fini(&_bootstrap_module_context); +} + +void bootstrap_avs_fini() +{ + log_info("avs fini"); + + avs_fini(); +} + +void bootstrap_eamuse_fini(const struct bootstrap_eamuse_config *config) +{ + log_info("eamuse fini"); + + if (config->enable) { + eamuse_fini(); + } +} \ No newline at end of file diff --git a/src/main/launcher/bootstrap.h b/src/main/launcher/bootstrap.h new file mode 100644 index 0000000..4deab8f --- /dev/null +++ b/src/main/launcher/bootstrap.h @@ -0,0 +1,32 @@ +#ifndef LAUNCHER_BOOTSTRAP_H +#define LAUNCHER_BOOTSTRAP_H + +#include "launcher/bootstrap-config.h" +#include "launcher/ea3-ident-config.h" + +#include "util/array.h" + +void bootstrap_init(bool log_property_configs); +void bootstrap_log_init(const struct bootstrap_log_config *config); +void bootstrap_default_files_create( + const struct bootstrap_default_file_config *config); +void bootstrap_avs_init( + const struct bootstrap_boot_config *config, + const struct bootstrap_log_config *log_config, + struct property *override_property); +void bootstrap_eamuse_init( + const struct bootstrap_eamuse_config *config, + const struct ea3_ident_config *ea3_ident_config, + struct property *override_property); +void bootstrap_module_init( + const struct bootstrap_module_config *module_config, + const struct array *iat_hook_dlls); +void bootstrap_module_game_init( + const struct bootstrap_module_config *module_config, + struct ea3_ident_config *ea3_ident_config); +void bootstrap_module_game_run(); +void bootstrap_module_game_fini(); +void bootstrap_avs_fini(); +void bootstrap_eamuse_fini(const struct bootstrap_eamuse_config *config); + +#endif \ No newline at end of file diff --git a/src/main/launcher/debug.c b/src/main/launcher/debug.c new file mode 100644 index 0000000..2f40e33 --- /dev/null +++ b/src/main/launcher/debug.c @@ -0,0 +1,33 @@ + +#define LOG_MODULE "debug" + +#include +#include + +#include "core/log.h" + +#include "launcher/debug.h" + +void debug_remote_debugger_trap() +{ + BOOL res; + + log_info("Waiting until debugger attaches to remote process..."); + + while (true) { + res = FALSE; + + if (!CheckRemoteDebuggerPresent(GetCurrentProcess(), &res)) { + log_fatal( + "CheckRemoteDebuggerPresent failed: %08x", + (unsigned int) GetLastError()); + } + + if (res) { + log_info("Debugger attached, resuming"); + break; + } + + Sleep(1000); + } +} \ No newline at end of file diff --git a/src/main/launcher/debug.h b/src/main/launcher/debug.h new file mode 100644 index 0000000..f57ca8b --- /dev/null +++ b/src/main/launcher/debug.h @@ -0,0 +1,6 @@ +#ifndef LAUNCHER_DEBUG_H +#define LAUNCHER_DEBUG_H + +void debug_remote_debugger_trap(); + +#endif \ No newline at end of file diff --git a/src/main/launcher/ea3-config.c b/src/main/launcher/ea3-config.c deleted file mode 100644 index 684ba46..0000000 --- a/src/main/launcher/ea3-config.c +++ /dev/null @@ -1,190 +0,0 @@ -#include - -#include "imports/avs.h" - -#include "launcher/ea3-config.h" -#include "launcher/module.h" - -#include "util/defs.h" -#include "util/hex.h" -#include "util/log.h" -#include "util/str.h" - -PSMAP_BEGIN(ea3_ident_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident, softid, "/ea3/id/softid", "") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident, hardid, "/ea3/id/hardid", "") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident, pcbid, "/ea3/id/pcbid", "") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, model, "/ea3/soft/model") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, dest, "/ea3/soft/dest") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, spec, "/ea3/soft/spec") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, rev, "/ea3/soft/rev") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, ext, "/ea3/soft/ext") -PSMAP_END - -void ea3_ident_init(struct ea3_ident *ident) -{ - memset(ident, 0, sizeof(*ident)); -} - -bool ea3_ident_from_property( - struct ea3_ident *ident, struct property *ea3_config) -{ - return property_psmap_import(ea3_config, NULL, ident, ea3_ident_psmap); -} - -void ea3_ident_hardid_from_ethernet(struct ea3_ident *ident) -{ - struct avs_net_interface netif; - int result; - - result = avs_net_ctrl(1, &netif, sizeof(netif)); - - if (result < 0) { - log_fatal( - "avs_net_ctrl call to get MAC address returned error: %d", result); - } - - ident->hardid[0] = '0'; - ident->hardid[1] = '1'; - ident->hardid[2] = '0'; - ident->hardid[3] = '0'; - - hex_encode_uc( - netif.mac_addr, - sizeof(netif.mac_addr), - ident->hardid + 4, - sizeof(ident->hardid) - 4); -} - -bool ea3_ident_invoke_module_init( - struct ea3_ident *ident, - const struct module_context *module, - struct property_node *app_config) -{ - char sidcode_short[17]; - char sidcode_long[21]; - char security_code[9]; - bool ok; - - /* Set up security env vars */ - - str_format( - security_code, - lengthof(security_code), - "G*%s%s%s%s", - ident->model, - ident->dest, - ident->spec, - ident->rev); - - std_setenv("/env/boot/version", "0.0.0"); - std_setenv("/env/profile/security_code", security_code); - std_setenv("/env/profile/system_id", ident->pcbid); - std_setenv("/env/profile/account_id", ident->pcbid); - std_setenv("/env/profile/license_id", ident->softid); - std_setenv("/env/profile/software_id", ident->softid); - std_setenv("/env/profile/hardware_id", ident->hardid); - - /* Set up the short sidcode string, let dll_entry_init mangle it */ - - str_format( - sidcode_short, - lengthof(sidcode_short), - "%s%s%s%s%s", - ident->model, - ident->dest, - ident->spec, - ident->rev, - ident->ext); - - /* Set up long-form sidcode env var */ - - str_format( - sidcode_long, - lengthof(sidcode_long), - "%s:%s:%s:%s:%s", - ident->model, - ident->dest, - ident->spec, - ident->rev, - ident->ext); - - /* Set this up beforehand, as certain games require it in dll_entry_init */ - - std_setenv("/env/profile/soft_id_code", sidcode_long); - - ok = module_context_invoke_init(module, sidcode_short, app_config); - - if (!ok) { - return false; - } - - /* Back-propagate sidcode, as some games modify it during init */ - - memcpy(ident->model, sidcode_short + 0, sizeof(ident->model) - 1); - ident->dest[0] = sidcode_short[3]; - ident->spec[0] = sidcode_short[4]; - ident->rev[0] = sidcode_short[5]; - memcpy(ident->ext, sidcode_short + 6, sizeof(ident->ext)); - - /* Set up long-form sidcode env var again */ - - str_format( - sidcode_long, - lengthof(sidcode_long), - "%s:%s:%s:%s:%s", - ident->model, - ident->dest, - ident->spec, - ident->rev, - ident->ext); - - std_setenv("/env/profile/soft_id_code", sidcode_long); - - return true; -} - -void ea3_ident_to_property( - const struct ea3_ident *ident, struct property *ea3_config) -{ - struct property_node *node; - int i; - - for (i = 0; ea3_ident_psmap[i].type != 0xFF; i++) { - node = property_search(ea3_config, 0, ea3_ident_psmap[i].path); - - if (node != NULL) { - property_node_remove(node); - } - } - - property_psmap_export(ea3_config, NULL, ident, ea3_ident_psmap); -} - -void ea3_ident_replace_property_bool( - struct property_node *node, const char *name, uint8_t val) -{ - struct property_node *tmp; - - tmp = property_search(NULL, node, name); - - if (tmp) { - property_node_remove(tmp); - } - - property_node_create(NULL, node, PROPERTY_TYPE_BOOL, name, val); -} - -void ea3_ident_replace_property_str( - struct property_node *node, const char *name, const char *val) -{ - struct property_node *tmp; - - tmp = property_search(NULL, node, name); - - if (tmp) { - property_node_remove(tmp); - } - - tmp = property_node_create(NULL, node, PROPERTY_TYPE_STR, name, val); -} diff --git a/src/main/launcher/ea3-config.h b/src/main/launcher/ea3-config.h deleted file mode 100644 index ada4400..0000000 --- a/src/main/launcher/ea3-config.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef LAUNCHER_EA3_CONFIG_H -#define LAUNCHER_EA3_CONFIG_H - -#include "imports/avs.h" - -#include "launcher/module.h" - -/* N.B. even though this might look like a Konami ABI, this is purely an - internal data structure. */ - -struct ea3_ident { - /* psmapped structure offset can't be zero for some stupid reason */ - - uint32_t dummy; - - /* Initialized from ea3-config.xml, then fed back from sidcode_short */ - - char model[4]; - char dest[4]; - char spec[4]; - char rev[4]; - char ext[11]; - - /* Initialized from ea3-config.xml (hardware_id defaults to MAC addr) */ - - char softid[24]; - char hardid[24]; - char pcbid[24]; -}; - -void ea3_ident_init(struct ea3_ident *ident); -bool ea3_ident_from_property( - struct ea3_ident *ident, struct property *ea3_config); -void ea3_ident_hardid_from_ethernet(struct ea3_ident *ident); -bool ea3_ident_invoke_module_init( - struct ea3_ident *ident, - const struct module_context *module, - struct property_node *app_config); -void ea3_ident_to_property( - const struct ea3_ident *ident, struct property *ea3_config); -void ea3_ident_replace_property_bool( - struct property_node *node, const char *name, uint8_t val); -void ea3_ident_replace_property_str( - struct property_node *node, const char *name, const char *val); - -#endif diff --git a/src/main/launcher/ea3-ident-config.c b/src/main/launcher/ea3-ident-config.c new file mode 100644 index 0000000..e8c5c4f --- /dev/null +++ b/src/main/launcher/ea3-ident-config.c @@ -0,0 +1,104 @@ +#define LOG_MODULE "ea3-ident-config" + +#include + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/ea3-ident-config.h" +#include "launcher/property-util.h" + +#include "util/defs.h" +#include "util/hex.h" +#include "util/str.h" + +#define ROOT_NODE "/ea3_conf" + +PSMAP_BEGIN(ea3_ident_config_psmap) +PSMAP_OPTIONAL( + PSMAP_TYPE_STR, struct ea3_ident_config, softid, "/id/softid", "") +PSMAP_OPTIONAL( + PSMAP_TYPE_STR, struct ea3_ident_config, hardid, "/id/hardid", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident_config, pcbid, "/id/pcbid", "") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, model, "/soft/model") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, dest, "/soft/dest") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, spec, "/soft/spec") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, rev, "/soft/rev") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident_config, ext, "/soft/ext") +PSMAP_END + +void ea3_ident_config_init(struct ea3_ident_config *config) +{ + memset(config, 0, sizeof(*config)); +} + +void ea3_ident_config_from_file_load( + const char *path, struct ea3_ident_config *config) +{ + struct property *property; + + log_assert(path); + log_assert(config); + + log_info("Loading from file path: %s", path); + + property = property_util_load(path); + + ea3_ident_config_load(property, config); + + property_util_free(property); +} + +void ea3_ident_config_load( + struct property *property, struct ea3_ident_config *config) +{ + struct property_node *node; + + log_assert(property); + log_assert(config); + + node = property_search(property, NULL, ROOT_NODE); + + if (node == NULL) { + log_fatal("Root node '" ROOT_NODE "' missing"); + } + + if (!property_psmap_import( + property, node, config, ea3_ident_config_psmap)) { + log_fatal("Error reading config file"); + } +} + +bool ea3_ident_config_hardid_is_defined(struct ea3_ident_config *config) +{ + log_assert(config); + + return strlen(config->hardid) > 0; +} + +void ea3_ident_config_hardid_from_ethernet_set(struct ea3_ident_config *config) +{ + struct avs_net_interface netif; + int result; + + log_assert(config); + + result = avs_net_ctrl(1, &netif, sizeof(netif)); + + if (result < 0) { + log_fatal( + "avs_net_ctrl call to get MAC address returned error: %d", result); + } + + config->hardid[0] = '0'; + config->hardid[1] = '1'; + config->hardid[2] = '0'; + config->hardid[3] = '0'; + + hex_encode_uc( + netif.mac_addr, + sizeof(netif.mac_addr), + config->hardid + 4, + sizeof(config->hardid) - 4); +} \ No newline at end of file diff --git a/src/main/launcher/ea3-ident-config.h b/src/main/launcher/ea3-ident-config.h new file mode 100644 index 0000000..1a6dc7f --- /dev/null +++ b/src/main/launcher/ea3-ident-config.h @@ -0,0 +1,37 @@ +#ifndef LAUNCHER_EA3_IDENT_CONFIG_H +#define LAUNCHER_EA3_IDENT_CONFIG_H + +#include "imports/avs.h" + +/* N.B. even though this might look like a Konami ABI, this is purely an + internal data structure. */ + +struct ea3_ident_config { + /* psmapped structure offset can't be zero for some stupid reason */ + + uint32_t dummy; + + /* Initialized from ea3-config.xml, then fed back from sidcode_short */ + + char model[4]; + char dest[4]; + char spec[4]; + char rev[4]; + char ext[11]; + + /* Initialized from ea3-config.xml (hardware_id defaults to MAC addr) */ + + char softid[24]; + char hardid[24]; + char pcbid[24]; +}; + +void ea3_ident_config_init(struct ea3_ident_config *config); +void ea3_ident_config_from_file_load( + const char *path, struct ea3_ident_config *config); +void ea3_ident_config_load( + struct property *property, struct ea3_ident_config *config); +bool ea3_ident_config_hardid_is_defined(struct ea3_ident_config *config); +void ea3_ident_config_hardid_from_ethernet_set(struct ea3_ident_config *config); + +#endif diff --git a/src/main/launcher/eamuse-config.c b/src/main/launcher/eamuse-config.c new file mode 100644 index 0000000..020e17a --- /dev/null +++ b/src/main/launcher/eamuse-config.c @@ -0,0 +1,125 @@ +#define LOG_MODULE "eamuse-config" + +#include + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/ea3-ident-config.h" +#include "launcher/eamuse-config.h" +#include "launcher/property-util.h" + +#define EAMUSE_CONFIG_ROOT_NODE "/ea3" + +struct property *eamuse_config_avs_load(const char *path) +{ + struct property *property; + + log_assert(path); + + log_misc("Loading from avs path: %s", path); + + property = property_util_avs_fs_load(path); + + // Check if root node exists, call already errors if not + eamuse_config_root_get(property); + + return property; +} + +struct property_node *eamuse_config_root_get(struct property *property) +{ + struct property_node *node; + + log_assert(property); + + node = property_search(property, 0, EAMUSE_CONFIG_ROOT_NODE); + + if (node == NULL) { + log_fatal("Root node " EAMUSE_CONFIG_ROOT_NODE + " in eamuse config missing"); + } + + return node; +} + +void eamuse_config_id_softid_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "id/softid", value); +} + +void eamuse_config_id_hardid_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "id/hardid", value); +} + +void eamuse_config_id_pcbid_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "id/pcbid", value); +} + +void eamuse_config_soft_model_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "soft/model", value); +} + +void eamuse_config_soft_dest_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "soft/dest", value); +} + +void eamuse_config_soft_spec_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "soft/spec", value); +} + +void eamuse_config_soft_rev_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "soft/rev", value); +} + +void eamuse_config_soft_ext_set(struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "soft/ext", value); +} + +void eamuse_config_network_url_slash_set(struct property_node *node, bool value) +{ + log_assert(node); + + property_util_node_bool_replace(NULL, node, "network/url_slash", value); +} + +void eamuse_config_network_service_url_set( + struct property_node *node, const char *value) +{ + log_assert(node); + log_assert(value); + + property_util_node_str_replace(NULL, node, "network/services", value); +} \ No newline at end of file diff --git a/src/main/launcher/eamuse-config.h b/src/main/launcher/eamuse-config.h new file mode 100644 index 0000000..2cba227 --- /dev/null +++ b/src/main/launcher/eamuse-config.h @@ -0,0 +1,23 @@ +#ifndef LAUNCHER_EAMUSE_CONFIG_H +#define LAUNCHER_EAMUSE_CONFIG_H + +#include "imports/avs.h" + +struct property *eamuse_config_avs_load(const char *path); +struct property_node *eamuse_config_root_get(struct property *property); + +void eamuse_config_id_softid_set(struct property_node *node, const char *value); +void eamuse_config_id_hardid_set(struct property_node *node, const char *value); +void eamuse_config_id_pcbid_set(struct property_node *node, const char *value); +void eamuse_config_soft_model_set( + struct property_node *node, const char *value); +void eamuse_config_soft_dest_set(struct property_node *node, const char *value); +void eamuse_config_soft_spec_set(struct property_node *node, const char *value); +void eamuse_config_soft_rev_set(struct property_node *node, const char *value); +void eamuse_config_soft_ext_set(struct property_node *node, const char *value); +void eamuse_config_network_url_slash_set( + struct property_node *node, bool value); +void eamuse_config_network_service_url_set( + struct property_node *node, const char *value); + +#endif \ No newline at end of file diff --git a/src/main/launcher/eamuse.c b/src/main/launcher/eamuse.c new file mode 100644 index 0000000..39e560d --- /dev/null +++ b/src/main/launcher/eamuse.c @@ -0,0 +1,25 @@ +#define LOG_MODULE "eamuse" + +#include "core/log.h" + +#include "imports/avs-ea3.h" + +void eamuse_init(struct property_node *node) +{ + log_assert(node); + + log_info("init"); + + ea3_boot(node); + + log_misc("init done"); +} + +void eamuse_fini() +{ + log_info("fini"); + + ea3_shutdown(); + + log_misc("fini done"); +} \ No newline at end of file diff --git a/src/main/launcher/eamuse.h b/src/main/launcher/eamuse.h new file mode 100644 index 0000000..1cd1f7e --- /dev/null +++ b/src/main/launcher/eamuse.h @@ -0,0 +1,9 @@ +#ifndef LAUNCHER_EAMUSE_H +#define LAUNCHER_EAMUSE_H + +#include "imports/avs.h" + +void eamuse_init(struct property_node *node); +void eamuse_fini(); + +#endif \ No newline at end of file diff --git a/src/main/launcher/hook.c b/src/main/launcher/hook.c new file mode 100644 index 0000000..d7be37a --- /dev/null +++ b/src/main/launcher/hook.c @@ -0,0 +1,34 @@ +#define LOG_MODULE "hook" + +#include + +#include "core/log.h" + +#include "launcher/hook.h" + +void hook_load_dll(const char *path) +{ + log_assert(path); + + log_info("Load hook dll: %s", path); + + if (LoadLibraryA(path) == NULL) { + LPSTR buffer; + + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR) &buffer, + 0, + NULL); + + log_fatal("%s: Failed to load hook DLL: %s", path, buffer); + + LocalFree(buffer); + } + + log_misc("Load hook dll done"); +} \ No newline at end of file diff --git a/src/main/launcher/hook.h b/src/main/launcher/hook.h new file mode 100644 index 0000000..9d0c5d4 --- /dev/null +++ b/src/main/launcher/hook.h @@ -0,0 +1,6 @@ +#ifndef LAUNCHER_HOOK_H +#define LAUNCHER_HOOK_H + +void hook_load_dll(const char *path); + +#endif \ No newline at end of file diff --git a/src/main/launcher/launcher-config.c b/src/main/launcher/launcher-config.c new file mode 100644 index 0000000..c71abe5 --- /dev/null +++ b/src/main/launcher/launcher-config.c @@ -0,0 +1,371 @@ +#define LOG_MODULE "launcher-config" + +#include + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/launcher-config.h" +#include "launcher/property-util.h" + +#include "util/mem.h" +#include "util/str.h" + +// clang-format off +PSMAP_BEGIN(launcher_debug_psmap) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, remote_debugger, + "debug/remote_debugger", false) + PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, log_property_configs, + "debug/log_property_configs", false) +PSMAP_END +// clang-format on + +#define ROOT_NODE "/launcher" +#define MAX_LAYER_CONFIG_NODES 8 + +#define NODE_MISSING_FATAL(subnode) \ + log_fatal("%s/%s: Node missing", ROOT_NODE, subnode); +#define NODE_LOADING_FATAL(subnode) \ + log_fatal("%s/%s: Node loading", ROOT_NODE, subnode); + +static struct property * +_launcher_config_layered_config_nodes_load(struct property_node *node) +{ + char kind[64]; + char file[MAX_PATH]; + int res; + int cnt; + + struct property_node *cur; + struct property *config_property[MAX_LAYER_CONFIG_NODES]; + struct property *merged_property; + + log_assert(node); + + cnt = 0; + cur = property_search(NULL, node, "config"); + + while (cur) { + if (cnt >= MAX_LAYER_CONFIG_NODES) { + log_fatal( + "Exceeding max supported config nodes for layering, max is %d", + MAX_LAYER_CONFIG_NODES); + } + + res = property_node_refer( + NULL, cur, "kind@", PROPERTY_TYPE_ATTR, kind, sizeof(kind)); + + if (res < 0) { + log_fatal("Failed reading 'kind' attribute value of config node"); + } + + if (!strcmp(kind, "file")) { + property_node_read(cur, PROPERTY_TYPE_STR, file, sizeof(file)); + + config_property[cnt] = property_util_load(file); + } else if (!strcmp(kind, "inline")) { + // The nested child is the actual root of the inline, not the outer + // node + cur = property_node_traversal(cur, TRAVERSE_FIRST_CHILD); + + config_property[cnt] = property_util_node_extract(cur); + } else { + log_fatal( + "Unsupported 'kind' attribute value '%s' of config node", kind); + } + + cnt++; + cur = property_node_traversal(cur, TRAVERSE_NEXT_SEARCH_RESULT); + } + + if (cnt == 0) { + return NULL; + } + + merged_property = property_util_many_merge(config_property, cnt); + + for (int i = 0; i < cnt; i++) { + property_util_free(config_property[i]); + } + + return merged_property; +} + +static void _launcher_config_hook_dlls_parse( + struct property_node *node, + const char *node_path, + char dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]) +{ + int cnt; + struct property_node *cur; + + cnt = 0; + cur = property_search(NULL, node, node_path); + + while (cur) { + if (cnt >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { + log_warning( + "Currently not supporting more than %d dlls, skipping " + "remaining", + cnt); + break; + } + + property_node_read(cur, PROPERTY_TYPE_STR, dlls[cnt], MAX_PATH); + + cnt++; + cur = property_node_traversal(cur, TRAVERSE_NEXT_SEARCH_RESULT); + } +} + +static void _launcher_config_bootstrap_load( + struct property_node *node, struct launcher_bootstrap_config *config) +{ + int res; + + log_assert(node); + log_assert(config); + + res = property_node_refer( + NULL, + node, + "selector", + PROPERTY_TYPE_STR, + config->selector, + sizeof(config->selector)); + + if (res < 0) { + NODE_MISSING_FATAL("bootstrap/selector"); + } + + config->property = _launcher_config_layered_config_nodes_load(node); + + if (config->property == NULL) { + NODE_MISSING_FATAL("bootstrap/config"); + } +} + +static void _launcher_config_hook_load( + struct property_node *node, struct launcher_hook_config *config) +{ + log_assert(node); + log_assert(config); + + _launcher_config_hook_dlls_parse(node, "hook_dlls/dll", config->hook_dlls); + _launcher_config_hook_dlls_parse( + node, "before_hook_dlls/dll", config->before_hook_dlls); + _launcher_config_hook_dlls_parse( + node, "iat_hook_dlls/dll", config->iat_hook_dlls); +} + +static void _launcher_config_debug_load( + struct property_node *node, struct launcher_debug_config *config) +{ + log_assert(node); + log_assert(config); + + if (!property_psmap_import(NULL, node, config, launcher_debug_psmap)) { + NODE_LOADING_FATAL("debug"); + } +} + +void launcher_config_init(struct launcher_config *config) +{ + log_assert(config); + + memset(config->bootstrap.selector, 0, sizeof(config->bootstrap.selector)); + config->bootstrap.property = NULL; + + config->avs.property = NULL; + + config->ea3_ident.property = NULL; + + config->eamuse.property = NULL; + + memset(config->hook.hook_dlls, 0, sizeof(config->hook.hook_dlls)); + memset( + config->hook.before_hook_dlls, + 0, + sizeof(config->hook.before_hook_dlls)); + memset(config->hook.iat_hook_dlls, 0, sizeof(config->hook.iat_hook_dlls)); + + config->debug.remote_debugger = false; + config->debug.log_property_configs = false; +} + +void launcher_config_load( + struct property *property, struct launcher_config *config) +{ + struct property_node *root_node; + struct property_node *node; + avs_error error; + + log_assert(property); + log_assert(config); + + root_node = property_search(property, NULL, ROOT_NODE); + + if (root_node == NULL) { + NODE_MISSING_FATAL(""); + } + + error = property_node_refer( + NULL, + root_node, + "version@", + PROPERTY_TYPE_ATTR, + &config->version, + sizeof(uint32_t)); + + if (AVS_IS_ERROR(error)) { + log_fatal("Missing version attribute on root node"); + } + + // if (config->version != 1) { + // log_fatal("Unsupported version of launcher configuration: %d", + // config->version); + // } + + node = property_search(NULL, root_node, "bootstrap"); + + if (node == NULL) { + NODE_MISSING_FATAL("bootstrap"); + } + + _launcher_config_bootstrap_load(node, &config->bootstrap); + + node = property_search(NULL, root_node, "avs"); + + if (node) { + config->avs.property = _launcher_config_layered_config_nodes_load(node); + } + + node = property_search(NULL, root_node, "ea3_ident"); + + if (node) { + config->ea3_ident.property = + _launcher_config_layered_config_nodes_load(node); + } + + node = property_search(NULL, root_node, "eamuse"); + + if (node) { + config->eamuse.property = + _launcher_config_layered_config_nodes_load(node); + } + + node = property_search(NULL, root_node, "hook"); + + if (node) { + _launcher_config_hook_load(node, &config->hook); + } + + _launcher_config_debug_load(root_node, &config->debug); +} + +bool launcher_config_add_hook_dll( + struct launcher_config *config, const char *path) +{ + int i; + + log_assert(config); + log_assert(path); + + i = 0; + + while (i < LAUNCHER_CONFIG_MAX_HOOK_DLL) { + if (strlen(config->hook.hook_dlls[i]) == 0) { + break; + } + + i++; + } + + if (i >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { + return false; + } + + str_cpy(config->hook.hook_dlls[i], sizeof(config->hook.hook_dlls[i]), path); + + return true; +} + +bool launcher_config_add_before_hook_dll( + struct launcher_config *config, const char *path) +{ + int i; + + log_assert(config); + log_assert(path); + + i = 0; + + while (i < LAUNCHER_CONFIG_MAX_HOOK_DLL) { + if (strlen(config->hook.before_hook_dlls[i]) == 0) { + break; + } + + i++; + } + + if (i >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { + return false; + } + + str_cpy( + config->hook.before_hook_dlls[i], + sizeof(config->hook.before_hook_dlls[i]), + path); + + return true; +} + +bool launcher_config_add_iat_hook_dll( + struct launcher_config *config, const char *path) +{ + int i; + + log_assert(config); + log_assert(path); + + i = 0; + + while (i < LAUNCHER_CONFIG_MAX_HOOK_DLL) { + if (strlen(config->hook.iat_hook_dlls[i]) == 0) { + break; + } + + i++; + } + + if (i >= LAUNCHER_CONFIG_MAX_HOOK_DLL) { + return false; + } + + str_cpy( + config->hook.iat_hook_dlls[i], + sizeof(config->hook.iat_hook_dlls[i]), + path); + + return true; +} + +void launcher_config_fini(struct launcher_config *config) +{ + log_assert(config); + + property_util_free(config->bootstrap.property); + + if (config->avs.property) { + property_util_free(config->avs.property); + } + + if (config->ea3_ident.property) { + property_util_free(config->ea3_ident.property); + } + + if (config->eamuse.property) { + property_util_free(config->eamuse.property); + } +} \ No newline at end of file diff --git a/src/main/launcher/launcher-config.h b/src/main/launcher/launcher-config.h new file mode 100644 index 0000000..7d6b8a6 --- /dev/null +++ b/src/main/launcher/launcher-config.h @@ -0,0 +1,56 @@ +#ifndef LAUNCHER_CONFIG_H +#define LAUNCHER_CONFIG_H + +#include + +#include "util/array.h" + +#define LAUNCHER_CONFIG_MAX_HOOK_DLL 16 + +struct launcher_config { + uint32_t version; + + struct launcher_bootstrap_config { + char selector[128]; + struct property *property; + } bootstrap; + + struct launcher_avs_config { + struct property *property; + } avs; + + struct launcher_ea3_ident_config { + struct property *property; + } ea3_ident; + + struct launcher_eamuse_config { + struct property *property; + } eamuse; + + struct launcher_hook_config { + char hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]; + char before_hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]; + char iat_hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH]; + } hook; + + struct launcher_debug_config { + bool remote_debugger; + bool log_property_configs; + } debug; +}; + +void launcher_config_init(struct launcher_config *config); + +void launcher_config_load( + struct property *property, struct launcher_config *config); + +bool launcher_config_add_hook_dll( + struct launcher_config *config, const char *path); +bool launcher_config_add_before_hook_dll( + struct launcher_config *config, const char *path); +bool launcher_config_add_iat_hook_dll( + struct launcher_config *config, const char *path); + +void launcher_config_fini(struct launcher_config *config); + +#endif \ No newline at end of file diff --git a/src/main/launcher/launcher.c b/src/main/launcher/launcher.c new file mode 100644 index 0000000..60f32cf --- /dev/null +++ b/src/main/launcher/launcher.c @@ -0,0 +1,587 @@ +#define LOG_MODULE "launcher" + +#include + +#include +#include +#include +#include + +#include "core/log-bt-ext.h" +#include "core/log-bt.h" +#include "core/log-sink-file.h" +#include "core/log-sink-list.h" +#include "core/log-sink-std.h" +#include "core/log.h" + +#include "imports/avs-ea3.h" +#include "imports/avs.h" + +#include "launcher/avs-config.h" +#include "launcher/avs.h" +#include "launcher/bootstrap-config.h" +#include "launcher/bootstrap.h" +#include "launcher/debug.h" +#include "launcher/ea3-ident-config.h" +#include "launcher/eamuse-config.h" +#include "launcher/eamuse.h" +#include "launcher/hook.h" +#include "launcher/launcher-config.h" +#include "launcher/module.h" +#include "launcher/options.h" +#include "launcher/property-util.h" +#include "launcher/stubs.h" +#include "launcher/version.h" + +#include "util/defs.h" +#include "util/fs.h" +#include "util/os.h" +#include "util/proc.h" +#include "util/signal.h" +#include "util/str.h" + +static void _launcher_log_header() +{ + log_info( + "\n" + " .__ .__ \n" + " | | _____ __ __ ____ ____ | |__ ___________ \n" + " | | \\__ \\ | | \\/ \\_/ ___\\| | \\_/ __ \\_ __ \\ \n" + " | |__/ __ \\| | / | \\ \\___| Y \\ ___/| | \\/ \n" + " |____(____ /____/|___| /\\___ >___| /\\___ >__| \n" + " \\/ \\/ \\/ \\/ \\/ "); + + log_info( + "launcher build date %s, gitrev %s", + launcher_build_date, + launcher_gitrev); +} + +void _launcher_log_init( + const char *log_file_path, enum core_log_bt_log_level level) +{ + struct core_log_sink sinks[2]; + struct core_log_sink sink_composed; + + core_log_bt_ext_impl_set(); + + if (log_file_path) { + core_log_sink_std_out_open(true, &sinks[0]); + core_log_sink_file_open(log_file_path, false, true, 10, &sinks[1]); + core_log_sink_list_open(sinks, 2, &sink_composed); + } else { + core_log_sink_std_out_open(true, &sink_composed); + } + + core_log_bt_init(&sink_composed); + core_log_bt_level_set(level); +} + +static void _launcher_signal_shutdown_handler() +{ + core_log_bt_fini(); + ExitProcess(EXIT_FAILURE); +} + +static void _launcher_env_game_dir_verify() +{ + char cwd[MAX_PATH]; + char modules_dir[MAX_PATH]; + char prop_dir[MAX_PATH]; + + getcwd(cwd, sizeof(cwd)); + + log_info("Current working directory: %s", cwd); + + str_cpy(modules_dir, sizeof(modules_dir), cwd); + str_cpy(prop_dir, sizeof(prop_dir), cwd); + + str_cat(modules_dir, sizeof(modules_dir), "/modules"); + str_cat(prop_dir, sizeof(prop_dir), "/prop"); + + if (!path_exists(modules_dir)) { + log_fatal( + "Cannot find 'modules' directory in current working directory: %s", + cwd); + } + + if (!path_exists(prop_dir)) { + log_fatal( + "Cannot find 'prop' directory in current working directory: %s", + cwd); + } +} + +static void _launcher_bootstrap_config_options_override( + struct launcher_bootstrap_config *config, + const struct options_bootstrap *options) +{ + log_assert(config); + log_assert(options); + + if (options->config_path) { + log_misc( + "Command line override bootstrap configuration from file: %s", + options->config_path); + + property_util_free(config->property); + config->property = property_util_load(options->config_path); + } + + if (options->selector) { + log_misc( + "Command line override bootstrap selector: %s", options->selector); + + str_cpy(config->selector, sizeof(config->selector), options->selector); + } +} + +static void _launcher_ea3_ident_config_options_override( + struct ea3_ident_config *config, const struct options_eamuse *options) +{ + log_assert(config); + log_assert(options); + + if (options->softid) { + str_cpy(config->softid, sizeof(config->softid), options->softid); + } + + if (options->pcbid) { + str_cpy(config->pcbid, sizeof(config->pcbid), options->pcbid); + } +} + +static void _launcher_hook_config_options_override( + struct launcher_config *config, const struct options_hook *options) +{ + size_t i; + const char *dll; + + log_assert(config); + log_assert(options); + + for (i = 0; i < options->hook_dlls.nitems; i++) { + dll = *array_item(const char *, &options->hook_dlls, i); + + if (!launcher_config_add_hook_dll(config, dll)) { + log_warning( + "Adding override hook dll '%s' failed (max supported limit " + "exceeded), ignored", + dll); + } + } + + for (i = 0; i < options->before_hook_dlls.nitems; i++) { + dll = *array_item(const char *, &options->before_hook_dlls, i); + + if (!launcher_config_add_before_hook_dll(config, dll)) { + log_warning( + "Adding override before hook dll '%s' failed (max supported " + "limit exceeded), ignored", + dll); + } + } + + for (i = 0; i < options->iat_hook_dlls.nitems; i++) { + dll = *array_item(const char *, &options->iat_hook_dlls, i); + + if (!launcher_config_add_iat_hook_dll(config, dll)) { + log_warning( + "Adding override iat hook dll '%s' failed (max supported limit " + "exceeded), ignored", + dll); + } + } +} + +static void _launcher_debug_config_options_override( + struct launcher_debug_config *config, const struct options_debug *options) +{ + log_assert(config); + log_assert(options); + + if (options->remote_debugger) { + log_misc("Command line override, enable remote debugger"); + + config->remote_debugger = true; + } + + if (options->log_property_configs) { + log_misc("Command line override, log property configs"); + + config->log_property_configs = true; + } +} + +static void _launcher_config_options_override( + struct launcher_config *config, const struct options *options) +{ + log_assert(config); + log_assert(options); + + // Apply command line overrides on all launcher owned configuration + // parameters + _launcher_bootstrap_config_options_override( + &config->bootstrap, &options->bootstrap); + _launcher_hook_config_options_override(config, &options->hook); + _launcher_debug_config_options_override(&config->debug, &options->debug); +} + +static void +_launcher_config_full_resolved_log(const struct launcher_config *config) +{ + if (config->debug.log_property_configs) { + log_misc("launcher-config resolved properties"); + log_misc("bootstrap-config"); + property_util_log(config->bootstrap.property); + + log_misc("avs-config"); + property_util_log(config->avs.property); + + log_misc("ea3-ident-config"); + property_util_log(config->ea3_ident.property); + + log_misc("eamuse-config"); + property_util_log(config->eamuse.property); + } +} + +static void +_launcher_remote_debugger_trap(const struct launcher_debug_config *config) +{ + log_assert(config); + + /* If enabled, wait for a remote debugger to attach as early as possible. + Spawning launcher with a debugger crashes it for some reason + (e.g. on jubeat08). However, starting the launcher separately and + attaching a remote debugger works */ + + if (config->remote_debugger) { + debug_remote_debugger_trap(); + } +} + +static void _launcher_bootstrap_config_load( + const struct launcher_bootstrap_config *launcher_bootstrap_config, + struct bootstrap_config *config) +{ + bootstrap_config_init(config); + + bootstrap_config_load( + launcher_bootstrap_config->property, + launcher_bootstrap_config->selector, + config); +} + +static void _launcher_bootstrap_log_config_options_override( + struct bootstrap_log_config *config, const struct options_log *options) +{ + log_assert(config); + log_assert(options); + + if (options->level) { + log_misc( + "Command line override bootstrap log level: %d", *(options->level)); + + switch (*(options->level)) { + case CORE_LOG_BT_LOG_LEVEL_OFF: + str_cpy(config->level, sizeof(config->level), "disable"); + break; + + case CORE_LOG_BT_LOG_LEVEL_FATAL: + str_cpy(config->level, sizeof(config->level), "fatal"); + break; + + case CORE_LOG_BT_LOG_LEVEL_WARNING: + str_cpy(config->level, sizeof(config->level), "warn"); + break; + + case CORE_LOG_BT_LOG_LEVEL_INFO: + str_cpy(config->level, sizeof(config->level), "info"); + break; + + case CORE_LOG_BT_LOG_LEVEL_MISC: + str_cpy(config->level, sizeof(config->level), "misc"); + break; + + default: + log_assert(false); + } + } + + if (options->file_path) { + log_misc( + "Command line override bootstrap log file: %s", options->file_path); + str_cpy(config->file, sizeof(config->file), options->file_path); + } +} + +static void _launcher_bootstrap_log_config_verify( + const struct launcher_config *launcher_config, + const struct bootstrap_config *bootstrap_config) +{ + log_assert(launcher_config); + log_assert(bootstrap_config); + + if (!str_eq(bootstrap_config->startup.log.level, "misc")) { + if (launcher_config->debug.log_property_configs) { + log_warning( + "Logging of property configs enabled, but requires misc log " + "level, current log level: %s", + bootstrap_config->startup.log.level); + } + } +} + +static void +_launcher_before_hook_dlls_load(const struct launcher_hook_config *config) +{ + int i; + + log_assert(config); + + log_misc("Loading before hook dlls..."); + + for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) { + if (strlen(config->before_hook_dlls[i]) > 0) { + hook_load_dll(config->before_hook_dlls[i]); + } + } +} + +static void _launcher_ea3_ident_config_load( + const struct launcher_ea3_ident_config *launcher_config, + struct ea3_ident_config *config, + bool log_property_configs) +{ + log_assert(launcher_config); + log_assert(config); + + ea3_ident_config_init(config); + ea3_ident_config_load(launcher_config->property, config); + + if (log_property_configs) { + log_misc("Property ea3-ident-config"); + + property_util_log(launcher_config->property); + } + + if (!ea3_ident_config_hardid_is_defined(config)) { + log_misc( + "No no hardid defined in ea3-ident-config, derive from ethernet"); + + ea3_ident_config_hardid_from_ethernet_set(config); + } +} + +static void _launcher_bootstrap_module_init( + const struct bootstrap_module_config *module_config, + const struct launcher_hook_config *hook_config) +{ + int i; + struct array iat_hook_dlls; + + log_assert(module_config); + log_assert(hook_config); + + array_init(&iat_hook_dlls); + + for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) { + if (strlen(hook_config->before_hook_dlls[i]) > 0) { + *array_append(const char *, &iat_hook_dlls) = + (const char *) &hook_config->before_hook_dlls[i]; + } + } + + bootstrap_module_init(module_config, &iat_hook_dlls); + + array_fini(&iat_hook_dlls); +} + +static void _launcher_hook_dlls_load(const struct launcher_hook_config *config) +{ + int i; + + log_assert(config); + + log_misc("Loading hook dlls..."); + + for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) { + if (strlen(config->hook_dlls[i]) > 0) { + hook_load_dll(config->hook_dlls[i]); + } + } +} + +static void _launcher_dongle_stubs_init() +{ + stubs_init(); +} + +static void _launcher_debugger_break() +{ + /* Opportunity for breakpoint setup etc */ + if (IsDebuggerPresent()) { + DebugBreak(); + } +} + +void _launcher_log_reinit() +{ + core_log_bt_ext_impl_set(); +} + +void _launcher_init( + const struct options *options, + struct launcher_config *launcher_config, + struct bootstrap_config *bootstrap_config, + struct ea3_ident_config *ea3_ident_config) +{ + struct property *launcher_property; + + log_assert(options); + log_assert(launcher_config); + log_assert(bootstrap_config); + log_assert(ea3_ident_config); + + // Early logging pre AVS setup depend entirely on command args + // We don't even have the bootstrap configuration loaded at this point + _launcher_log_init(options->log.file_path, *(options->log.level)); + _launcher_log_header(); + + signal_exception_handler_init(_launcher_signal_shutdown_handler); + signal_register_shutdown_handler(&_launcher_signal_shutdown_handler); + + os_version_log(); + _launcher_env_game_dir_verify(); + + if (proc_is_running_as_admin_user()) { + log_warning( + "Not running as admin user. Launcher and games require elevated " + "privileges to run correctly"); + } + + launcher_config_init(launcher_config); + + if (options->launcher.config_path) { + log_info( + "Loading launcher configuration from file: %s", + options->launcher.config_path); + + launcher_property = property_util_load(options->launcher.config_path); + launcher_config_load(launcher_property, launcher_config); + + _launcher_config_options_override(launcher_config, options); + + if (launcher_config->debug.log_property_configs) { + log_misc("launcher-config"); + property_util_log(launcher_property); + } + + property_util_free(launcher_property); + } else { + _launcher_config_options_override(launcher_config, options); + } + + // Not really fully resolved, but have an early debug dump because there are + // still several more steps that can fail before having the entire + // configuration resolved + _launcher_config_full_resolved_log(launcher_config); + + _launcher_remote_debugger_trap(&launcher_config->debug); + + _launcher_bootstrap_config_load( + &launcher_config->bootstrap, bootstrap_config); + _launcher_bootstrap_log_config_options_override( + &bootstrap_config->startup.log, &options->log); + _launcher_bootstrap_log_config_verify(launcher_config, bootstrap_config); + + bootstrap_init(launcher_config->debug.log_property_configs); + bootstrap_log_init(&bootstrap_config->startup.log); + + _launcher_before_hook_dlls_load(&launcher_config->hook); + + bootstrap_avs_init( + &bootstrap_config->startup.boot, + &bootstrap_config->startup.log, + launcher_config->avs.property); + bootstrap_default_files_create(&bootstrap_config->startup.default_file); + + _launcher_ea3_ident_config_load( + &launcher_config->ea3_ident, + ea3_ident_config, + launcher_config->debug.log_property_configs); + _launcher_ea3_ident_config_options_override( + ea3_ident_config, &options->eamuse); + + // Execute another one which is now actually final. No more configuration + // changes from this point on + _launcher_config_full_resolved_log(launcher_config); +} + +void _launcher_run( + const struct launcher_config *launcher_config, + const struct bootstrap_config *bootstrap_config, + struct ea3_ident_config *ea3_ident_config) +{ + log_assert(launcher_config); + log_assert(bootstrap_config); + log_assert(ea3_ident_config); + + _launcher_bootstrap_module_init( + &bootstrap_config->startup.module, &launcher_config->hook); + + _launcher_hook_dlls_load(&launcher_config->hook); + + _launcher_dongle_stubs_init(); + + _launcher_debugger_break(); + + bootstrap_module_game_init( + &bootstrap_config->startup.module, ea3_ident_config); + + bootstrap_eamuse_init( + &bootstrap_config->startup.eamuse, + ea3_ident_config, + launcher_config->eamuse.property); + + bootstrap_module_game_run(); +} + +void _launcher_fini( + struct launcher_config *launcher_config, + const struct bootstrap_config *bootstrap_config) +{ + log_assert(launcher_config); + log_assert(bootstrap_config); + + bootstrap_eamuse_fini(&bootstrap_config->startup.eamuse); + + bootstrap_avs_fini(); + + _launcher_log_reinit(); + + bootstrap_module_game_fini(); + + launcher_config_fini(launcher_config); + + log_info("Shutdown complete"); + + core_log_bt_fini(); +} + +void launcher_main(const struct options *options) +{ + struct launcher_config launcher_config; + struct bootstrap_config bootstrap_config; + struct ea3_ident_config ea3_ident_config; + + log_assert(options); + + _launcher_init( + options, &launcher_config, &bootstrap_config, &ea3_ident_config); + + _launcher_run(&launcher_config, &bootstrap_config, &ea3_ident_config); + + _launcher_fini(&launcher_config, &bootstrap_config); +} \ No newline at end of file diff --git a/src/main/launcher/launcher.h b/src/main/launcher/launcher.h new file mode 100644 index 0000000..da1995c --- /dev/null +++ b/src/main/launcher/launcher.h @@ -0,0 +1,8 @@ +#ifndef LAUNCHER_LAUNCHER_H +#define LAUNCHER_LAUNCHER_H + +#include "launcher/options.h" + +void launcher_main(const struct options *options); + +#endif \ No newline at end of file diff --git a/src/main/launcher/main.c b/src/main/launcher/main.c index 70c5184..4b1b68a 100644 --- a/src/main/launcher/main.c +++ b/src/main/launcher/main.c @@ -1,338 +1,23 @@ -#include - -#include -#include -#include #include -#include "imports/avs-ea3.h" -#include "imports/avs.h" - -#include "launcher/avs-context.h" -#include "launcher/ea3-config.h" -#include "launcher/module.h" +#include "launcher/launcher.h" #include "launcher/options.h" -#include "launcher/property.h" -#include "launcher/stubs.h" -#include "launcher/version.h" - -#include "util/codepage.h" -#include "util/defs.h" -#include "util/fs.h" -#include "util/log.h" -#include "util/mem.h" -#include "util/os.h" -#include "util/str.h" - -/* Gratuitous API changes orz */ -static AVS_LOG_WRITER(log_callback, chars, nchars, ctx) -{ - wchar_t *utf16; - char *utf8; - int utf16_len; - int utf8_len; - int result; - DWORD nwritten; - HANDLE console; - HANDLE file; - - /* Ignore existing NUL terminator */ - - nchars--; - - /* Transcode shit_jis to UTF-8 */ - - utf16_len = MultiByteToWideChar(CP_SHIFT_JIS, 0, chars, nchars, NULL, 0); - - if (utf16_len == 0) { - abort(); - } - - utf16 = xmalloc(sizeof(*utf16) * utf16_len); - result = - MultiByteToWideChar(CP_SHIFT_JIS, 0, chars, nchars, utf16, utf16_len); - - if (result == 0) { - abort(); - } - - utf8_len = - WideCharToMultiByte(CP_UTF8, 0, utf16, utf16_len, NULL, 0, NULL, NULL); - - if (utf8_len == 0) { - abort(); - } - - utf8 = xmalloc(utf8_len + 2); - result = WideCharToMultiByte( - CP_UTF8, 0, utf16, utf16_len, utf8, utf8_len, NULL, NULL); - - if (result == 0) { - abort(); - } - -#if AVS_VERSION >= 1500 - utf8[utf8_len + 0] = '\r'; - utf8[utf8_len + 1] = '\n'; - - utf8_len += 2; -#endif - - /* Write to console and log file */ - - file = (HANDLE) ctx; - console = GetStdHandle(STD_OUTPUT_HANDLE); - - if (ctx != INVALID_HANDLE_VALUE) { - WriteFile(file, utf8, utf8_len, &nwritten, NULL); - } - - WriteFile(console, utf8, utf8_len, &nwritten, NULL); - - /* Clean up */ - - free(utf8); - free(utf16); -} - -static void load_hook_dlls(struct array *hook_dlls) -{ - const char *hook_dll; - - for (size_t i = 0; i < hook_dlls->nitems; i++) { - hook_dll = *array_item(char *, hook_dlls, i); - - if (LoadLibraryA(hook_dll) == NULL) { - LPSTR buffer; - - FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR) &buffer, - 0, - NULL); - - log_fatal("%s: Failed to load hook DLL: %s", hook_dll, buffer); - - LocalFree(buffer); - } - } -} int main(int argc, const char **argv) { - bool ok; - HANDLE logfile; - - struct ea3_ident ea3; - struct module_context module; struct options options; - struct property *app_config; - struct property *avs_config; - struct property *ea3_config; - - struct property_node *app_config_root; - struct property_node *avs_config_root; - struct property_node *ea3_config_root; - - log_to_writer(log_writer_file, stdout); - log_info( - "launcher build date %s, gitrev %s", - launcher_build_date, - launcher_gitrev); - - /* Read command line */ - options_init(&options); if (!options_read_cmdline(&options, argc, argv)) { options_print_usage(); - return EXIT_FAILURE; + exit(EXIT_FAILURE); } - /* If enabled, wait for a remote debugger to attach. Spawning launcher - with a debugger crashes it for some reason (e.g. on jubeat08). However, - starting the launcher separately and attaching a remote debugger works */ + launcher_main(&options); - if (options.remote_debugger) { - log_info("Waiting until debugger attaches to remote process..."); - - while (true) { - BOOL res = FALSE; - if (!CheckRemoteDebuggerPresent(GetCurrentProcess(), &res)) { - log_fatal( - "CheckRemoteDebuggerPresent failed: %08x", - (unsigned int) GetLastError()); - } - - if (res) { - log_info("Debugger attached, resuming"); - break; - } - - Sleep(1000); - } - } - - /* Start up AVS */ - - if (options.logfile != NULL) { - logfile = CreateFileA( - options.logfile, - GENERIC_WRITE, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - 0, - NULL); - } else { - logfile = INVALID_HANDLE_VALUE; - } - - avs_config = boot_property_load(options.avs_config_path); - avs_config_root = property_search(avs_config, 0, "/config"); - - if (avs_config_root == NULL) { - log_fatal("%s: /config missing", options.avs_config_path); - } - - load_hook_dlls(&options.before_hook_dlls); - - avs_context_init( - avs_config_root, - options.avs_heap_size, - options.std_heap_size, - log_callback, - logfile); - - boot_property_free(avs_config); - - log_to_external( - log_body_misc, log_body_info, log_body_warning, log_body_fatal); - - os_version_log(); - - /* Load game DLL */ - - if (options.iat_hook_dlls.nitems > 0) { - module_context_init_with_iat_hooks( - &module, options.module, &options.iat_hook_dlls); - } else { - module_context_init(&module, options.module); - } - - /* Load hook DLLs */ - - load_hook_dlls(&options.hook_dlls); - - /* Inject GetModuleHandle hooks */ - - stubs_init(); - - /* Prepare ea3 config */ - - ea3_config = boot_property_load(options.ea3_config_path); - ea3_config_root = property_search(ea3_config, 0, "/ea3"); - - if (ea3_config_root == NULL) { - log_fatal("%s: /ea3 missing", options.ea3_config_path); - } - - ea3_ident_init(&ea3); - - if (!ea3_ident_from_property(&ea3, ea3_config)) { - log_fatal( - "%s: Error reading IDs from config file", options.ea3_config_path); - } - - if (options.softid != NULL) { - str_cpy(ea3.softid, lengthof(ea3.softid), options.softid); - } - - if (options.pcbid != NULL) { - str_cpy(ea3.pcbid, lengthof(ea3.pcbid), options.pcbid); - } - - if (!ea3.hardid[0]) { - ea3_ident_hardid_from_ethernet(&ea3); - } - - /* Invoke dll_entry_init */ - - if (path_exists(options.app_config_path)) { - app_config = boot_property_load(options.app_config_path); - } else { - log_warning( - "%s: app config file missing, using empty", - options.app_config_path); - app_config = boot_property_load_cstring("dummy"); - } - - app_config_root = property_search(app_config, 0, "/param"); - - if (app_config_root == NULL) { - log_fatal("%s: /param missing", options.app_config_path); - } - - if (IsDebuggerPresent()) { - /* Opportunity for breakpoint setup etc */ - DebugBreak(); - } - - ok = ea3_ident_invoke_module_init(&ea3, &module, app_config_root); - - if (!ok) { - log_fatal("%s: dll_module_init() returned failure", options.module); - } - - boot_property_free(app_config); - - ea3_ident_to_property(&ea3, ea3_config); - - if (options.override_urlslash_enabled) { - log_info( - "Overriding url_slash to: %d", options.override_urlslash_value); - - ea3_ident_replace_property_bool( - ea3_config_root, - "/network/url_slash", - options.override_urlslash_value); - } - - if (options.override_service != NULL) { - log_info("Overriding service url to: %s", options.override_service); - - ea3_ident_replace_property_str( - ea3_config_root, "/network/services", options.override_service); - } - - /* Start up e-Amusement client */ - - ea3_boot(ea3_config_root); - boot_property_free(ea3_config); - - /* Run application */ - - module_context_invoke_main(&module); - - /* Shut down */ - - ea3_shutdown(); - - log_to_writer(log_writer_file, stdout); - avs_context_fini(); - - if (logfile != INVALID_HANDLE_VALUE) { - CloseHandle(logfile); - } - - module_context_fini(&module); options_fini(&options); return EXIT_SUCCESS; -} +} \ No newline at end of file diff --git a/src/main/launcher/module.c b/src/main/launcher/module.c index b3beff2..c0b9ef4 100644 --- a/src/main/launcher/module.c +++ b/src/main/launcher/module.c @@ -1,22 +1,29 @@ +#define LOG_MODULE "module" + #include +#include "core/log.h" + #include "hook/pe.h" #include "imports/avs.h" #include "imports/eapki.h" #include "launcher/module.h" +#include "launcher/property-util.h" -#include "util/log.h" #include "util/str.h" #define MM_ALLOCATION_GRANULARITY 0x10000 -static bool module_replace_dll_iat(HMODULE hModule, struct array *iat_hook_dlls) +static bool +module_replace_dll_iat(HMODULE hModule, const struct array *iat_hook_dlls) { log_assert(hModule); log_assert(iat_hook_dlls); + log_misc("replace dll iat: %p", hModule); + if (iat_hook_dlls->nitems == 0) return true; @@ -127,11 +134,13 @@ inject_fail: return false; } -void module_context_init(struct module_context *module, const char *path) +void module_init(struct module_context *module, const char *path) { log_assert(module != NULL); log_assert(path != NULL); + log_info("init: %s", path); + module->dll = LoadLibrary(path); if (module->dll == NULL) { @@ -159,16 +168,20 @@ void module_context_init(struct module_context *module, const char *path) } module->path = str_dup(path); + + log_misc("init done"); } -void module_context_init_with_iat_hooks( +void module_with_iat_hooks_init( struct module_context *module, const char *path, - struct array *iat_hook_dlls) + const struct array *iat_hook_dlls) { log_assert(module != NULL); log_assert(path != NULL); + log_info("init iat hooks: %s", path); + module->dll = LoadLibraryExA(path, NULL, DONT_RESOLVE_DLL_REFERENCES); if (module->dll == NULL) { @@ -211,16 +224,71 @@ void module_context_init_with_iat_hooks( module->path = str_dup(path); } -bool module_context_invoke_init( +void module_init_invoke( const struct module_context *module, - char *sidcode, - struct property_node *app_config) + struct ea3_ident_config *ea3_ident_config, + struct property_node *app_params_node) { + char sidcode_short[17]; + char sidcode_long[21]; + char security_code[9]; dll_entry_init_t init; + bool ok; - log_assert(module != NULL); - log_assert(sidcode != NULL); - log_assert(app_config != NULL); + log_info("init invoke"); + + /* Set up security env vars */ + + str_format( + security_code, + lengthof(security_code), + "G*%s%s%s%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev); + + log_misc("security code: %s", security_code); + + std_setenv("/env/boot/version", "0.0.0"); + std_setenv("/env/profile/security_code", security_code); + std_setenv("/env/profile/system_id", ea3_ident_config->pcbid); + std_setenv("/env/profile/account_id", ea3_ident_config->pcbid); + std_setenv("/env/profile/license_id", ea3_ident_config->softid); + std_setenv("/env/profile/software_id", ea3_ident_config->softid); + std_setenv("/env/profile/hardware_id", ea3_ident_config->hardid); + + /* Set up the short sidcode string, let dll_entry_init mangle it */ + + str_format( + sidcode_short, + lengthof(sidcode_short), + "%s%s%s%s%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev, + ea3_ident_config->ext); + + log_misc("sidcode short: %s", sidcode_short); + + /* Set up long-form sidcode env var */ + + str_format( + sidcode_long, + lengthof(sidcode_long), + "%s:%s:%s:%s:%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev, + ea3_ident_config->ext); + + log_misc("sidecode long: %s", sidcode_long); + + /* Set this up beforehand, as certain games require it in dll_entry_init */ + + std_setenv("/env/profile/soft_id_code", sidcode_long); init = (void *) GetProcAddress(module->dll, "dll_entry_init"); @@ -229,16 +297,67 @@ bool module_context_invoke_init( "%s: dll_entry_init not found. Is this a game DLL?", module->path); } - return init(sidcode, app_config); + log_info("Invoking game init..."); + + struct property *prop = + property_util_cstring_load("p3io"); + + struct property_node *prop_node = property_search(prop, NULL, "/param"); + + property_util_log(prop); + property_util_node_log(prop_node); + + ok = init(sidcode_short, prop_node); + + if (!ok) { + log_fatal("%s: dll_module_init() returned failure", module->path); + } else { + log_info("Game init done"); + } + + /* Back-propagate sidcode, as some games modify it during init */ + + memcpy( + ea3_ident_config->model, + sidcode_short + 0, + sizeof(ea3_ident_config->model) - 1); + ea3_ident_config->dest[0] = sidcode_short[3]; + ea3_ident_config->spec[0] = sidcode_short[4]; + ea3_ident_config->rev[0] = sidcode_short[5]; + memcpy( + ea3_ident_config->ext, + sidcode_short + 6, + sizeof(ea3_ident_config->ext)); + + /* Set up long-form sidcode env var again */ + + str_format( + sidcode_long, + lengthof(sidcode_long), + "%s:%s:%s:%s:%s", + ea3_ident_config->model, + ea3_ident_config->dest, + ea3_ident_config->spec, + ea3_ident_config->rev, + ea3_ident_config->ext); + + std_setenv("/env/profile/soft_id_code", sidcode_long); + + log_misc("back-propagated sidcode long: %s", sidcode_long); + + log_misc("init invoke done"); } -bool module_context_invoke_main(const struct module_context *module) +bool module_main_invoke(const struct module_context *module) { /* GCC warns if you call a variable "main" */ dll_entry_main_t main_; + bool result; log_assert(module != NULL); + log_info("main invoke"); + main_ = (void *) GetProcAddress(module->dll, "dll_entry_main"); if (main_ == NULL) { @@ -246,11 +365,19 @@ bool module_context_invoke_main(const struct module_context *module) "%s: dll_entry_main not found. Is this a game DLL?", module->path); } - return main_(); + log_info("Invoking game's main function..."); + + result = main_(); + + log_info("Main terminated, result: %d", result); + + return result; } -void module_context_fini(struct module_context *module) +void module_fini(struct module_context *module) { + log_info("fini"); + if (module == NULL) { return; } @@ -260,4 +387,6 @@ void module_context_fini(struct module_context *module) if (module->dll != NULL) { FreeLibrary(module->dll); } + + log_misc("fini done"); } diff --git a/src/main/launcher/module.h b/src/main/launcher/module.h index f2a851e..ed9b732 100644 --- a/src/main/launcher/module.h +++ b/src/main/launcher/module.h @@ -5,6 +5,8 @@ #include "imports/avs.h" +#include "launcher/ea3-ident-config.h" + #include "util/array.h" struct module_context { @@ -12,16 +14,16 @@ struct module_context { char *path; }; -void module_context_init(struct module_context *module, const char *path); -void module_context_init_with_iat_hooks( +void module_init(struct module_context *module, const char *path); +void module_with_iat_hooks_init( struct module_context *module, const char *path, - struct array *iat_hook_dlls); -bool module_context_invoke_init( + const struct array *iat_hook_dlls); +void module_init_invoke( const struct module_context *module, - char *sidcode, - struct property_node *app_config); -bool module_context_invoke_main(const struct module_context *module); -void module_context_fini(struct module_context *module); + struct ea3_ident_config *ea3_ident_config, + struct property_node *app_params_node); +bool module_main_invoke(const struct module_context *module); +void module_fini(struct module_context *module); #endif diff --git a/src/main/launcher/options.c b/src/main/launcher/options.c index 757555e..e116849 100644 --- a/src/main/launcher/options.c +++ b/src/main/launcher/options.c @@ -1,3 +1,5 @@ +#define LOG_MODULE "options" + #include #include #include @@ -6,62 +8,42 @@ #include "launcher/options.h" -#include "util/array.h" -#include "util/log.h" +#include "util/mem.h" #include "util/str.h" -#define DEFAULT_HEAP_SIZE 16777216 - void options_init(struct options *options) { - options->std_heap_size = DEFAULT_HEAP_SIZE; - options->avs_heap_size = DEFAULT_HEAP_SIZE; - options->app_config_path = "prop/app-config.xml"; - options->avs_config_path = "prop/avs-config.xml"; - options->ea3_config_path = "prop/ea3-config.xml"; - options->softid = NULL; - options->pcbid = NULL; - options->module = NULL; - options->logfile = NULL; - options->remote_debugger = false; - array_init(&options->hook_dlls); - array_init(&options->before_hook_dlls); - array_init(&options->iat_hook_dlls); + memset(options, 0, sizeof(struct options)); - options->override_service = NULL; - options->override_urlslash_enabled = false; - options->override_urlslash_value = false; + array_init(&options->hook.hook_dlls); + array_init(&options->hook.before_hook_dlls); + array_init(&options->hook.iat_hook_dlls); } bool options_read_cmdline(struct options *options, int argc, const char **argv) { + bool got_launcher_config; + + got_launcher_config = false; + for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { - case 'A': + case 'T': if (i + 1 >= argc) { return false; } - options->app_config_path = argv[++i]; + options->bootstrap.config_path = argv[++i]; break; - case 'E': + case 'Z': if (i + 1 >= argc) { return false; } - options->ea3_config_path = argv[++i]; - - break; - - case 'V': - if (i + 1 >= argc) { - return false; - } - - options->avs_config_path = argv[++i]; + options->bootstrap.selector = argv[++i]; break; @@ -70,7 +52,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->pcbid = argv[++i]; + options->eamuse.pcbid = argv[++i]; break; @@ -79,7 +61,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->softid = argv[++i]; + options->eamuse.softid = argv[++i]; break; @@ -88,37 +70,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->avs_heap_size = - (size_t) strtol(argv[++i], NULL, 0); - - if (options->avs_heap_size == 0) { - return false; - } - - break; - -#ifdef AVS_HAS_STD_HEAP - case 'T': - if (i + 1 >= argc) { - return false; - } - - options->std_heap_size = - (size_t) strtol(argv[++i], NULL, 0); - - if (options->std_heap_size == 0) { - return false; - } - - break; -#endif - - case 'K': - if (i + 1 >= argc) { - return false; - } - - *array_append(const char *, &options->hook_dlls) = + *array_append(const char *, &options->hook.hook_dlls) = argv[++i]; break; @@ -128,7 +80,8 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - *array_append(const char *, &options->before_hook_dlls) = + *array_append( + const char *, &options->hook.before_hook_dlls) = argv[++i]; break; @@ -141,17 +94,41 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) const char *dll = argv[++i]; log_assert(strstr(dll, "=") != NULL); - *array_append(const char *, &options->iat_hook_dlls) = dll; + *array_append(const char *, &options->hook.iat_hook_dlls) = + dll; break; } + case 'L': + if (i + 1 >= argc) { + return false; + } + + long tmp = strtol(argv[++i], NULL, 0); + + if (tmp < CORE_LOG_BT_LOG_LEVEL_OFF || + tmp > CORE_LOG_BT_LOG_LEVEL_MISC) { + return false; + } + + options->log.level = + xmalloc(sizeof(enum core_log_bt_log_level)); + *(options->log.level) = (enum core_log_bt_log_level) tmp; + + break; + case 'Y': if (i + 1 >= argc) { return false; } - options->logfile = argv[++i]; + options->log.file_path = argv[++i]; + + break; + + case 'C': + options->debug.log_property_configs = true; break; @@ -160,7 +137,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->override_service = argv[++i]; + options->eamuse.service_url = argv[++i]; break; @@ -169,22 +146,23 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->override_urlslash_enabled = true; + options->eamuse.urlslash = xmalloc(sizeof(bool)); const char *urlslash_value = argv[++i]; - options->override_urlslash_value = false; + *(options->eamuse.urlslash) = false; + if (_stricmp(urlslash_value, "1") == 0) { - options->override_urlslash_value = true; + *(options->eamuse.urlslash) = true; } if (_stricmp(urlslash_value, "true") == 0) { - options->override_urlslash_value = true; + *(options->eamuse.urlslash) = true; } break; case 'D': - options->remote_debugger = true; + options->debug.remote_debugger = true; break; @@ -192,59 +170,71 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) break; } } else { - if (!options->module) { - options->module = argv[i]; + if (!got_launcher_config) { + options->launcher.config_path = argv[i]; + got_launcher_config = true; } } } - if (options->module) { - return true; - } else { - return false; - } + return got_launcher_config; } void options_print_usage(void) { fprintf( stderr, - "Usage: launcher.exe [launcher options...] [hooks " - "options...] \n" + "Usage:\n" + " launcher.exe [launcher options as overrides...] " + "[further options, e.g. for hook libraries to pick up...]\n" "\n" - " The following options can be specified before the app DLL " - "path:\n" + " The following options can be specified before the launcher.xml " + "configuration file:\n" "\n" - " -A [filename] App configuration file (default: " - "prop/app-config.xml)\n" - " -V [filename] AVS configuration file (default: " - "prop/avs-config.xml)\n" - " -E [filename] ea3 configuration file (default: " - "prop/ea3-config.xml)\n" - " -H [bytes] AVS heap size (default: 16777216)\n" -#ifdef AVS_HAS_STD_HEAP - " -T [bytes] 'std' heap size (default 16777216)\n" -#endif - " -P [pcbid] Specify PCBID (default: use ea3 config)\n" - " -R [pcbid] Specify Soft ID (default: use ea3 config)\n" - " -S [url] Specify service url (default: use ea3 config)\n" - " -U [0/1] Specify url_slash (default: use ea3 config)\n" - " -K [filename] Load hook DLL (can be specified multiple " + " Bootstrap\n" + " -T [filename] Bootstrap configuration file\n" + " -Z [selector] Bootstrap selector used in configuration\n" + "\n" + " Eamuse\n" + " -P [pcbid] Specify PCBID\n" + " -R [softid] Specify Soft ID\n" + " -S [url] Specify service url\n" + " -U [0/1] Specify url_slash enabled/disabled\n" + "\n" + " Hook\n" + " -H [filename] Load hook DLL (can be specified multiple " "times)\n" " -B [filename] Load pre-hook DLL loaded before avs boot " "(can be specified multiple times)\n" " -I [filename] Load pre-hook DLL that overrides IAT reference " - "before execution" - "(can be specified multiple times)\n" + "before execution (can be specified multiple times)\n" + "\n" + " Logging\n" + " -L [0/1/2/3] Log level for both console and file with " + "increasing verbosity (0 = fatal, 1 = warn, 2 = info, 3 = misc)\n" " -Y [filename] Log to a file in addition to the console\n" + "\n" + " Debug\n" " -D Halt the launcher before bootstrapping AVS " - "until a" - " remote debugger is attached\n"); + "until a remote debugger is attached\n" + " -C Log all loaded and final (property) " + "configuration that launcher uses for bootstrapping. IMPORTANT: DO NOT " + "ENABLE unless you know what you are doing. This prints sensitive data " + "and credentials to the console and logfile. BE CAUTIOUS not to share " + "this information before redaction."); } void options_fini(struct options *options) { - array_fini(&options->hook_dlls); - array_fini(&options->before_hook_dlls); - array_fini(&options->iat_hook_dlls); + array_fini(&options->hook.hook_dlls); + array_fini(&options->hook.before_hook_dlls); + array_fini(&options->hook.iat_hook_dlls); + + if (options->log.level) { + free(options->log.level); + } + + if (options->eamuse.urlslash) { + free(options->eamuse.urlslash); + } } diff --git a/src/main/launcher/options.h b/src/main/launcher/options.h index 13f1c0f..c0bdfaf 100644 --- a/src/main/launcher/options.h +++ b/src/main/launcher/options.h @@ -4,25 +4,53 @@ #include #include +#include "core/log-bt.h" +#include "core/log.h" + +#include "launcher/bootstrap-config.h" + #include "util/array.h" +// Launcher options (cmd params) are limited to: +// - Options to run a (vanilla) game without additional launcher features, e.g. +// hooking +// - Options that are handy to have for development/debugging purpose, e.g. +// quickly switching on/off +// logging levels +// +// Everything else is driven by a composable configuration file (launcher.xml) struct options { - size_t std_heap_size; - size_t avs_heap_size; - const char *app_config_path; - const char *avs_config_path; - const char *ea3_config_path; - const char *softid; - const char *pcbid; - const char *module; - const char *logfile; - struct array hook_dlls; - struct array before_hook_dlls; - struct array iat_hook_dlls; - bool remote_debugger; - const char *override_service; - bool override_urlslash_enabled; - bool override_urlslash_value; + struct options_launcher { + const char *config_path; + } launcher; + + struct options_bootstrap { + const char *config_path; + const char *selector; + } bootstrap; + + struct options_log { + enum core_log_bt_log_level *level; + const char *file_path; + } log; + + struct options_eamuse { + const char *softid; + const char *pcbid; + const char *service_url; + bool *urlslash; + } eamuse; + + struct options_hook { + struct array hook_dlls; + struct array before_hook_dlls; + struct array iat_hook_dlls; + } hook; + + struct options_debug { + bool remote_debugger; + bool log_property_configs; + } debug; }; void options_init(struct options *options); diff --git a/src/main/launcher/property-util.c b/src/main/launcher/property-util.c new file mode 100644 index 0000000..20a7f91 --- /dev/null +++ b/src/main/launcher/property-util.c @@ -0,0 +1,891 @@ +#define LOG_MODULE "property-util" + +#include + +#include +#include +#include +#include + +#include "avs-util/error.h" + +#include "core/log.h" + +#include "imports/avs.h" + +#include "launcher/property-util.h" + +#include "util/mem.h" +#include "util/str.h" + +#define PROPERTY_STRUCTURE_META_SIZE 576 + +typedef void (*rewinder)(uint32_t context); + +struct cstring_read_handle { + const char *buffer; + size_t buffer_len; + size_t offset; +}; + +struct property_util_node_merge_ctx { + const char *path; + const struct property_util_node_merge_strategies *strategies; +}; + +static struct property *property_util_do_load( + avs_reader_t reader, rewinder rewinder, uint32_t context, const char *name) +{ + struct property *prop; + void *buffer; + int nbytes; + + nbytes = property_read_query_memsize(reader, context, 0, 0); + + if (nbytes < 0) { + log_fatal("%s: Error querying configuration file", name); + } + + buffer = xmalloc(nbytes); + prop = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + nbytes); + + if (!prop) { + log_fatal( + "%s: Creating property failed: %s", + name, + avs_util_property_error_get_and_clear(prop)); + } + + rewinder(context); + + if (!property_insert_read(prop, 0, reader, context)) { + log_fatal( + "%s: Error reading configuration file: %s", + name, + avs_util_property_error_get_and_clear(prop)); + } + + return prop; +} + +static int property_util_fread(uint32_t context, void *bytes, size_t nbytes) +{ + FILE *f; + + f = TlsGetValue(context); + + return fread(bytes, 1, nbytes, f); +} + +static void property_util_frewind(uint32_t context) +{ + FILE *f = TlsGetValue(context); + rewind(f); +} + +static void property_util_log_node_tree_rec( + struct property_node *parent_node, const char *parent_path) +{ + char cur_path[PROPERTY_NODE_PATH_LEN_MAX]; + char cur_node_name[PROPERTY_NODE_NAME_SIZE_MAX]; + + struct property_node *child_node; + enum property_type property_type; + + int8_t value_s8; + int16_t value_s16; + int32_t value_s32; + int64_t value_s64; + uint8_t value_u8; + uint16_t value_u16; + uint32_t value_u32; + uint64_t value_u64; + char value_str[4096]; + bool value_bool; + + avs_error error; + + // Carry on the full root path down the node tree + property_node_name(parent_node, cur_node_name, sizeof(cur_node_name)); + + str_cpy(cur_path, sizeof(cur_path), parent_path); + str_cat(cur_path, sizeof(cur_path), "/"); + str_cat(cur_path, sizeof(cur_path), cur_node_name); + + child_node = property_node_traversal(parent_node, TRAVERSE_FIRST_CHILD); + + // parent node is a leaf node, print all data of it + if (child_node == NULL) { + property_type = property_node_type(parent_node); + + switch (property_type) { + case PROPERTY_TYPE_VOID: + log_misc("%s: ", cur_path); + break; + + case PROPERTY_TYPE_S8: + property_node_read( + parent_node, property_type, &value_s8, sizeof(value_s8)); + log_misc("%s: %" PRId8, cur_path, value_s8); + break; + + case PROPERTY_TYPE_S16: + property_node_read( + parent_node, property_type, &value_s16, sizeof(value_s16)); + log_misc("%s: %" PRId16, cur_path, value_s16); + break; + + case PROPERTY_TYPE_S32: + property_node_read( + parent_node, property_type, &value_s32, sizeof(value_s32)); + log_misc("%s: %" PRId32, cur_path, value_s32); + break; + + case PROPERTY_TYPE_S64: + property_node_read( + parent_node, property_type, &value_s64, sizeof(value_s64)); + log_misc("%s: %" PRId64, cur_path, value_s64); + break; + + case PROPERTY_TYPE_U8: + property_node_read( + parent_node, property_type, &value_u8, sizeof(value_u8)); + log_misc("%s: %" PRIu8, cur_path, value_u8); + break; + + case PROPERTY_TYPE_U16: + property_node_read( + parent_node, property_type, &value_u16, sizeof(value_u16)); + log_misc("%s: %" PRIu16, cur_path, value_u16); + break; + + case PROPERTY_TYPE_U32: + property_node_read( + parent_node, property_type, &value_u32, sizeof(value_u32)); + log_misc("%s: %" PRIu32, cur_path, value_u32); + break; + + case PROPERTY_TYPE_U64: + property_node_read( + parent_node, property_type, &value_u64, sizeof(value_u64)); + log_misc("%s: %" PRIu64, cur_path, value_u64); + break; + + case PROPERTY_TYPE_STR: + property_node_read( + parent_node, property_type, value_str, sizeof(value_str)); + log_misc("%s: %s", cur_path, value_str); + + break; + + case PROPERTY_TYPE_BOOL: + property_node_read( + parent_node, + property_type, + &value_bool, + sizeof(value_bool)); + log_misc("%s: %d", cur_path, value_bool); + + break; + + case PROPERTY_TYPE_BIN: + log_misc("%s: ", cur_path); + break; + + case PROPERTY_TYPE_ATTR: + error = property_node_read( + parent_node, property_type, value_str, sizeof(value_str)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_util_error_str(error)); + } + + log_misc("%s@: %s", cur_path, value_str); + + break; + + case PROPERTY_TYPE_VOID_WITH_ATTRIBUTES: + log_misc("%s: ", cur_path); + + child_node = + property_node_traversal(parent_node, TRAVERSE_FIRST_ATTR); + + while (child_node) { + property_util_log_node_tree_rec(child_node, cur_path); + + child_node = property_node_traversal( + child_node, TRAVERSE_NEXT_SIBLING); + } + + break; + + case PROPERTY_TYPE_STR_WITH_ATTRIBUTES: + error = property_node_read( + parent_node, property_type, value_str, sizeof(value_str)); + + if (AVS_IS_ERROR(error)) { + log_fatal( + "%s, property read failed: %s", + cur_path, + avs_util_error_str(error)); + } + + log_misc("%s: %s", cur_path, value_str); + + child_node = + property_node_traversal(parent_node, TRAVERSE_FIRST_ATTR); + + while (child_node) { + property_util_log_node_tree_rec(child_node, cur_path); + + child_node = property_node_traversal( + child_node, TRAVERSE_NEXT_SIBLING); + } + + break; + + default: + log_misc("%s: (%d)", cur_path, property_type); + break; + } + } else { + while (child_node) { + property_util_log_node_tree_rec(child_node, cur_path); + + child_node = + property_node_traversal(child_node, TRAVERSE_NEXT_SIBLING); + } + } +} + +static int +property_util_cstring_read(uint32_t context, void *bytes, size_t nbytes) +{ + int result = 0; + struct cstring_read_handle *h = TlsGetValue(context); + + if (h->offset < h->buffer_len) { + result = min(nbytes, h->buffer_len - h->offset); + memcpy(bytes, (const void *) (h->buffer + h->offset), result); + h->offset += result; + } + return result; +} + +static void property_util_cstring_rewind(uint32_t context) +{ + struct cstring_read_handle *h = TlsGetValue(context); + h->offset = 0; +} + +static int property_util_avs_read(uint32_t context, void *bytes, size_t nbytes) +{ + avs_desc desc = (avs_desc) context; + return avs_fs_read(desc, bytes, nbytes); +} + +static void property_util_avs_rewind(uint32_t context) +{ + avs_desc desc = (avs_desc) context; + avs_fs_lseek(desc, 0, AVS_SEEK_SET); +} + +static void _property_util_node_merge_recursive( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx) +{ + uint8_t i; + bool consumed; + struct property_node *result; + + const struct property_util_node_merge_ctx *ctx_; + struct property_util_node_merge_ctx ctx_next; + + char parent_name[PROPERTY_NODE_NAME_SIZE_MAX]; + char parent_path[PROPERTY_NODE_PATH_LEN_MAX]; + + log_assert(source); + log_assert(ctx); + + ctx_ = (const struct property_util_node_merge_ctx *) ctx; + + log_assert(ctx_->path); + log_assert(ctx_->strategies); + log_assert(ctx_->strategies->num > 0); + + // Default to copying to an empty node + if (!parent) { + result = property_node_clone(parent_property, NULL, source, true); + + if (!result) { + log_fatal("Copying '%s' into empty parent failed", ctx_->path); + } + + return; + } + + property_node_name(parent, parent_name, sizeof(parent_name)); + + str_cpy(parent_path, sizeof(parent_path), ctx_->path); + str_cat(parent_path, sizeof(parent_path), "/"); + str_cat(parent_path, sizeof(parent_path), parent_name); + + ctx_next.path = parent_path; + ctx_next.strategies = ctx_->strategies; + + consumed = false; + + // Apply given strategies, one MUST consume + for (i = 0; i < ctx_->strategies->num; i++) { + log_assert(ctx_->strategies->entry[i].path); + + // path == "" matches everything + if (str_eq(ctx_->strategies->entry[i].path, "") || + str_eq(ctx_->strategies->entry[i].path, parent_path)) { + + consumed = ctx_->strategies->entry[i].merge_strategy_do( + parent_property, + parent, + source, + &ctx_next, + _property_util_node_merge_recursive); + + log_misc( + "Merge strategy for '%s' consumed: %d", + ctx_->strategies->entry[i].path, + consumed); + + if (consumed) { + break; + } + } + } + + log_assert(consumed); +} + +void property_util_log(struct property *property) +{ + property_util_log_node_tree_rec(property_search(property, NULL, "/"), ""); +} + +void property_util_node_log(struct property_node *node) +{ + property_util_log_node_tree_rec(node, ""); +} + +struct property *property_util_load(const char *filename) +{ + FILE *f; + uint32_t f_keyhole; + struct property *prop; + + log_assert(filename); + + /* AVS callbacks are only given a 32-bit context parameter, even in 64-bit + builds of AVS. We allocate a 32-bit TLS key and pass the context in this + manner instead. Inefficient, but it works. */ + + f = fopen(filename, "r"); + + f_keyhole = TlsAlloc(); + TlsSetValue(f_keyhole, f); + + if (f == NULL) { + log_fatal("%s: Error opening configuration file", filename); + } + + prop = property_util_do_load( + property_util_fread, property_util_frewind, f_keyhole, filename); + + TlsFree(f_keyhole); + + fclose(f); + + return prop; +} + +struct property *property_util_avs_fs_load(const char *filename) +{ + avs_desc desc; + struct property *prop; + + log_assert(filename); + + desc = avs_fs_open(filename, AVS_FILE_READ, AVS_FILE_FLAG_SHARE_READ); + + if (!desc) { + log_fatal("%s: Error opening configuration file", filename); + } + + prop = property_util_do_load( + property_util_avs_read, property_util_avs_rewind, desc, filename); + + avs_fs_close(desc); + + return prop; +} + +struct property *property_util_cstring_load(const char *cstring) +{ + uint32_t s_keyhole; + struct property *prop; + + log_assert(cstring); + + // see above + struct cstring_read_handle read_handle; + read_handle.buffer = cstring; + read_handle.buffer_len = strlen(cstring); + read_handle.offset = 0; + + s_keyhole = TlsAlloc(); + TlsSetValue(s_keyhole, &read_handle); + + prop = property_util_do_load( + property_util_cstring_read, + property_util_cstring_rewind, + s_keyhole, + ""); + + TlsFree(s_keyhole); + + return prop; +} + +struct property *property_util_clone(struct property *property) +{ + struct property *clone; + size_t size; + void *buffer; + + struct property_node *node_property; + struct property_node *node_clone; + + log_assert(property); + + size = property_util_property_query_real_size(property); + + buffer = xmalloc(size); + + clone = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + size); + + if (!clone) { + log_fatal("Creating property failed"); + } + + node_property = property_search(property, NULL, "/"); + node_clone = property_search(clone, NULL, "/"); + + if (!property_node_clone(clone, node_clone, node_property, true)) { + log_fatal( + "Cloning property data failed: %s", + avs_util_property_error_get_and_clear(clone)); + } + + return clone; +} + +void property_util_free(struct property *prop) +{ + void *buffer; + + buffer = property_desc_to_buffer(prop); + property_destroy(prop); + free(buffer); +} + +uint32_t property_util_property_query_real_size(struct property *property) +{ + avs_error size; + + log_assert(property); + + // Returns the size of the actual data in the property structure only + // Hence, using that size only, allocating another buffer for a copy + // of this might fail or copying the data will fail because the buffer + // is too small + size = property_query_size(property); + + if (AVS_IS_ERROR(size)) { + log_fatal( + "Querying property size failed: %s", avs_util_error_str(size)); + } + + // Hack: *2 to have enough space and not cut off data when cloning/copying + // property data because...reasons? I haven't figured this one out and + // there doesn't seem to be an actual API call for that to return the + // "true" size that allows the caller to figure out how much memory + // they have to allocate to create a copy of the property structure + // with property_create and + return (PROPERTY_STRUCTURE_META_SIZE + size) * 2; +} + +void property_util_node_u8_replace( + struct property *property, + struct property_node *node, + const char *name, + uint8_t val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_U8, name, val); + + if (!tmp) { + log_fatal( + "Creating node '%s' failed: %s", + name, + property ? avs_util_property_error_get_and_clear(property) : + "unknown"); + } +} + +void property_util_node_u16_replace( + struct property *property, + struct property_node *node, + const char *name, + uint16_t val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_U16, name, val); + + if (!tmp) { + log_fatal( + "Creating node '%s' failed: %s", + name, + property ? avs_util_property_error_get_and_clear(property) : + "unknown"); + } +} + +void property_util_node_u32_replace( + struct property *property, + struct property_node *node, + const char *name, + uint32_t val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_U32, name, val); + + if (!tmp) { + log_fatal( + "Creating node '%s' failed: %s", + name, + property ? avs_util_property_error_get_and_clear(property) : + "unknown"); + } +} + +void property_util_node_str_replace( + struct property *property, + struct property_node *node, + const char *name, + const char *val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_STR, name, val); + + if (!tmp) { + log_fatal( + "Creating node '%s' failed: %s", + name, + property ? avs_util_property_error_get_and_clear(property) : + "unknown"); + } +} + +void property_util_node_bool_replace( + struct property *property, + struct property_node *node, + const char *name, + bool val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_BOOL, name, val); + + if (!tmp) { + log_fatal( + "Creating node '%s' failed: %s", + name, + property ? avs_util_property_error_get_and_clear(property) : + "unknown"); + } +} + +void property_util_node_attribute_replace( + struct property *property, + struct property_node *node, + const char *name, + const char *val) +{ + struct property_node *tmp; + + log_assert(node); + log_assert(name); + + tmp = property_search(property, node, name); + + if (tmp) { + property_node_remove(tmp); + } + + tmp = property_node_create(property, node, PROPERTY_TYPE_ATTR, name, val); +} + +struct property * +property_util_many_merge(struct property **properties, size_t count) +{ + struct property *merged_property; + struct property *tmp; + int i; + + log_assert(properties); + log_assert(count > 0); + + merged_property = property_util_clone(properties[0]); + + if (count == 1) { + return merged_property; + } + + for (i = 1; i < count; i++) { + tmp = property_util_merge(merged_property, properties[i]); + + property_util_free(merged_property); + merged_property = tmp; + } + + return merged_property; +} + +struct property *property_util_node_extract(struct property_node *node) +{ + struct property *property; + struct property_node *root_node; + uint32_t size; + void *buffer; + struct property_node *result; + + if (!node) { + return NULL; + } + + // Hack: Is it even possible to get the size of a (sub-) node without + // the property? 256kb should be fine for now, even for larger + // configurations. Obviously, this scales horribly and wastes a lot of + // memory for most smaller sub-nodes + size = 1024 * 256; + + buffer = xmalloc(size); + property = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + size); + root_node = property_search(property, NULL, ""); + + result = property_node_clone(property, root_node, node, true); + + if (!result) { + log_fatal("Cloning node into empty property failed"); + } + + return property; +} + +struct property * +property_util_merge(struct property *parent, struct property *source) +{ + struct property_util_node_merge_strategies strategies; + + log_assert(parent); + log_assert(source); + + strategies.num = 1; + + strategies.entry[0].path = ""; + strategies.entry[0].merge_strategy_do = + property_util_node_merge_default_strategy_do; + + return property_util_merge_with_strategies(parent, source, &strategies); +} + +struct property *property_util_merge_with_strategies( + struct property *parent, + struct property *source, + const struct property_util_node_merge_strategies *strategies) +{ + struct property_util_node_merge_ctx ctx; + size_t total_size; + void *buffer; + struct property *merged; + struct property_node *parent_node; + struct property_node *source_node; + + log_assert(parent); + log_assert(source); + log_assert(strategies); + + // We can't estimate how these two are being merged as in how much new + // data is being inserted from source into parent. Therefore, worse-case + // estimate memory requirement for no overlap + total_size = 0; + total_size += property_util_property_query_real_size(parent); + total_size += property_util_property_query_real_size(source); + + buffer = xmalloc(total_size); + + merged = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + total_size); + + ctx.path = ""; + ctx.strategies = strategies; + + parent_node = property_search(parent, NULL, "/"); + + if (!property_node_clone(merged, NULL, parent_node, true)) { + log_fatal( + "Copying parent base failed: %s", + avs_util_property_error_get_and_clear(merged)); + } + + // Grab parent_node from merged property which is the target one to merge + // into + parent_node = property_search(merged, NULL, "/"); + source_node = property_search(source, NULL, "/"); + + _property_util_node_merge_recursive(merged, parent_node, source_node, &ctx); + + return merged; +} + +bool property_util_node_merge_default_strategy_do( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx, + property_util_node_merge_recursion_do_t node_merge_recursion_do) +{ + struct property_node *result; + + struct property_node *parent_child; + struct property_node *source_child; + struct property_node *source_child_child; + + char child_node_name[PROPERTY_NODE_NAME_SIZE_MAX]; + + log_assert(parent); + log_assert(source); + + source_child = property_node_traversal(source, TRAVERSE_FIRST_CHILD); + + while (source_child) { + property_node_name( + source_child, child_node_name, sizeof(child_node_name)); + + parent_child = property_search(NULL, parent, child_node_name); + + if (parent_child) { + source_child_child = + property_node_traversal(source_child, TRAVERSE_FIRST_CHILD); + + if (source_child_child) { + // Continue recursion if there are actually more children + node_merge_recursion_do( + parent_property, parent_child, source_child, ctx); + } else { + // Found identical leaf node, remove the matching parent's child + // and copy the source child over to the parent and terminate + // the recursion + property_node_remove(parent_child); + result = property_node_clone( + parent_property, parent, source_child, true); + + if (!result) { + log_fatal( + "Replacing leaf node '%s' failed", child_node_name); + } + } + } else { + // Could not find an identical child on parent, copy source + // recursively to parent + result = property_node_clone( + parent_property, parent, source_child, true); + + if (!result) { + log_fatal("Deep copying child '%s' failed", child_node_name); + } + } + + source_child = + property_node_traversal(source_child, TRAVERSE_NEXT_SIBLING); + } + + // Default strategy always consumes + return true; +} diff --git a/src/main/launcher/property-util.h b/src/main/launcher/property-util.h new file mode 100644 index 0000000..ba59479 --- /dev/null +++ b/src/main/launcher/property-util.h @@ -0,0 +1,99 @@ +#ifndef PROPERTY_UTIL_H +#define PROPERTY_UTIL_H + +#include + +#include "imports/avs.h" + +// Guestimate, should be long enough, I hope? +#define PROPERTY_NODE_PATH_LEN_MAX 4096 +// 256 found in AVS code as size used on property_node_name +#define PROPERTY_NODE_NAME_SIZE_MAX 256 +// Guestimate, should be enough, I hope? +#define PROPERTY_NODE_ATTR_NAME_SIZE_MAX 128 + +#define PROPERTY_UTIL_MAX_NODE_NAME_RESOLVERS 4 + +typedef void (*property_util_node_merge_recursion_do_t)( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx); + +typedef bool (*property_util_node_merge_strategy_do_t)( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx, + property_util_node_merge_recursion_do_t node_merge_recursion_do); + +struct property_util_node_merge_strategies { + struct { + const char *path; + property_util_node_merge_strategy_do_t merge_strategy_do; + } entry[PROPERTY_UTIL_MAX_NODE_NAME_RESOLVERS]; + uint8_t num; +}; + +void property_util_log(struct property *property); +void property_util_node_log(struct property_node *node); +struct property *property_util_load(const char *filename); +struct property *property_util_avs_fs_load(const char *filename); +struct property *property_util_cstring_load(const char *cstring); +struct property *property_util_clone(struct property *property); +void property_util_free(struct property *prop); +uint32_t property_util_property_query_real_size(struct property *property); +void property_util_node_u8_replace( + struct property *property, + struct property_node *node, + const char *name, + uint8_t val); +void property_util_node_u16_replace( + struct property *property, + struct property_node *node, + const char *name, + uint16_t val); +void property_util_node_u32_replace( + struct property *property, + struct property_node *node, + const char *name, + uint32_t val); +void property_util_node_str_replace( + struct property *property, + struct property_node *node, + const char *name, + const char *val); +void property_util_node_bool_replace( + struct property *property, + struct property_node *node, + const char *name, + bool val); +void property_util_node_attribute_replace( + struct property *property, + struct property_node *node, + const char *name, + const char *val); + +struct property * +property_util_many_merge(struct property **properties, size_t count); +struct property *property_util_node_extract(struct property_node *node); + +struct property * +property_util_merge(struct property *parent, struct property *source); + +// Strategies are applied in order and first consumer terminates +// applying further strategies Typically, you want to include the default +// strategy after your custom strategies for special cases +struct property *property_util_merge_with_strategies( + struct property *parent, + struct property *source, + const struct property_util_node_merge_strategies *strategies); + +bool property_util_node_merge_default_strategy_do( + struct property *parent_property, + struct property_node *parent, + struct property_node *source, + void *ctx, + property_util_node_merge_recursion_do_t node_merge_recursion_do); + +#endif diff --git a/src/main/launcher/property.c b/src/main/launcher/property.c deleted file mode 100644 index 2f5ded9..0000000 --- a/src/main/launcher/property.c +++ /dev/null @@ -1,135 +0,0 @@ -#include - -#include -#include -#include - -#include "imports/avs.h" - -#include "launcher/property.h" - -#include "util/log.h" -#include "util/mem.h" - -static int boot_property_fread(uint32_t context, void *bytes, size_t nbytes) -{ - FILE *f; - - f = TlsGetValue(context); - - return fread(bytes, 1, nbytes, f); -} - -struct cstring_read_handle { - const char *buffer; - size_t buffer_len; - size_t offset; -}; - -static int -boot_property_cstring_read(uint32_t context, void *bytes, size_t nbytes) -{ - int result = 0; - struct cstring_read_handle *h = TlsGetValue(context); - - if (h->offset < h->buffer_len) { - result = min(nbytes, h->buffer_len - h->offset); - memcpy(bytes, (const void *) (h->buffer + h->offset), result); - h->offset += result; - } - return result; -} - -struct property *boot_property_load(const char *filename) -{ - struct property *prop; - void *buffer; - int nbytes; - FILE *f; - uint32_t f_keyhole; - - /* AVS callbacks are only given a 32-bit context parameter, even in 64-bit - builds of AVS. We allocate a 32-bit TLS key and pass the context in this - manner instead. Inefficient, but it works. */ - - f = fopen(filename, "r"); - - f_keyhole = TlsAlloc(); - TlsSetValue(f_keyhole, f); - - if (f == NULL) { - log_fatal("%s: Error opening configuration file", filename); - } - - nbytes = property_read_query_memsize(boot_property_fread, f_keyhole, 0, 0); - - if (nbytes < 0) { - log_fatal("%s: Error querying configuration file", filename); - } - - buffer = xmalloc(nbytes); - prop = property_create( - PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | - PROPERTY_FLAG_APPEND, - buffer, - nbytes); - rewind(f); - - if (!property_insert_read(prop, 0, boot_property_fread, f_keyhole)) { - log_fatal("%s: Error reading configuration file", filename); - } - - TlsFree(f_keyhole); - - fclose(f); - - return prop; -} -struct property *boot_property_load_cstring(const char *cstring) -{ - struct property *prop; - void *buffer; - int nbytes; - uint32_t s_keyhole; - - // see above - struct cstring_read_handle read_handle; - read_handle.buffer = cstring; - read_handle.buffer_len = strlen(cstring); - read_handle.offset = 0; - - s_keyhole = TlsAlloc(); - TlsSetValue(s_keyhole, &read_handle); - - nbytes = property_read_query_memsize( - boot_property_cstring_read, s_keyhole, 0, 0); - - if (nbytes < 0) { - log_fatal("Error querying configuration string"); - } - - buffer = xmalloc(nbytes); - prop = property_create( - PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | - PROPERTY_FLAG_APPEND, - buffer, - nbytes); - - read_handle.offset = 0; - if (!property_insert_read(prop, 0, boot_property_cstring_read, s_keyhole)) { - log_fatal("Error inserting configuration string"); - } - - TlsFree(s_keyhole); - - return prop; -} - -void boot_property_free(struct property *prop) -{ - void *buffer; - - buffer = property_desc_to_buffer(prop); - property_destroy(prop); - free(buffer); -} diff --git a/src/main/launcher/property.h b/src/main/launcher/property.h deleted file mode 100644 index c3f14d0..0000000 --- a/src/main/launcher/property.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef LAUNCHER_PROPERTY_H -#define LAUNCHER_PROPERTY_H - -#include "imports/avs.h" - -struct property *boot_property_load(const char *filename); -struct property *boot_property_load_cstring(const char *cstring); -void boot_property_free(struct property *prop); - -#endif diff --git a/src/main/launcher/stubs.c b/src/main/launcher/stubs.c index a524273..4c0b253 100644 --- a/src/main/launcher/stubs.c +++ b/src/main/launcher/stubs.c @@ -1,3 +1,5 @@ +#define LOG_MODULE "stubs" + #include #include @@ -5,12 +7,13 @@ #include #include +#include "core/log.h" + #include "hook/table.h" #include "launcher/stubs.h" #include "util/defs.h" -#include "util/log.h" struct ikey_status { uint32_t field_0; @@ -116,6 +119,8 @@ static void *STDCALL my_GetProcAddress(HMODULE dll, const char *name) void stubs_init(void) { + log_info("Init"); + hook_table_apply( NULL, "kernel32.dll", stub_hook_syms, lengthof(stub_hook_syms)); } From 2ebfd39beaa33da23f00c22e22fb0677b3316088 Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 18:53:51 +0100 Subject: [PATCH 16/18] refactor(dist): Config and .bat files Move everything to new launcher.xml configuration files. Adjust the bootstrapping of launcher in the .bat files. Features such as copying the default props/ files to nvram are now handled by launcher. Using the PATH variable, bemanitools binaries can live in their own dedicated bemanitools/ subfolder next to props/ and modules/ now. All original binaries are expected to be kept in a modules/ folder like on stock data. --- Module.mk | 90 ++++++++++++++++++++++++++++++++++-- dist/bst/gamestart1.bat | 34 ++++++++++++-- dist/bst/gamestart2.bat | 34 ++++++++++++-- dist/bst/launcher-01.xml | 75 ++++++++++++++++++++++++++++++ dist/bst/launcher-02.xml | 75 ++++++++++++++++++++++++++++++ dist/ddr/gamestart-12.bat | 41 ++++++++++++++-- dist/ddr/gamestart-13.bat | 41 ++++++++++++++-- dist/ddr/gamestart-14.bat | 46 ++++++++++++++---- dist/ddr/gamestart-15.bat | 46 ++++++++++++++---- dist/ddr/gamestart-16.bat | 47 +++++++++++++++---- dist/ddr/gamestart-17.bat | 47 +++++++++++++++---- dist/ddr/gamestart-18.bat | 47 +++++++++++++++---- dist/ddr/launcher-12.xml | 75 ++++++++++++++++++++++++++++++ dist/ddr/launcher-13.xml | 75 ++++++++++++++++++++++++++++++ dist/ddr/launcher-14.xml | 75 ++++++++++++++++++++++++++++++ dist/ddr/launcher-15.xml | 75 ++++++++++++++++++++++++++++++ dist/ddr/launcher-16.xml | 76 ++++++++++++++++++++++++++++++ dist/ddr/launcher-17.xml | 76 ++++++++++++++++++++++++++++++ dist/ddr/launcher-18.xml | 76 ++++++++++++++++++++++++++++++ dist/iidx/ea3-ident.xml | 10 ++++ dist/iidx/eamuse-server.xml | 6 +++ dist/iidx/gamestart-18.bat | 36 +++++++++++---- dist/iidx/gamestart-19.bat | 36 +++++++++++---- dist/iidx/gamestart-20.bat | 34 ++++++++++++-- dist/iidx/gamestart-21.bat | 34 ++++++++++++-- dist/iidx/gamestart-22.bat | 34 ++++++++++++-- dist/iidx/gamestart-23.bat | 34 ++++++++++++-- dist/iidx/gamestart-24.bat | 34 ++++++++++++-- dist/iidx/gamestart-25.bat | 40 +++++++++++----- dist/iidx/gamestart-26.bat | 40 +++++++++++----- dist/iidx/gamestart-27.bat | 40 +++++++++++----- dist/iidx/gamestart-28.bat | 40 +++++++++++----- dist/iidx/gamestart-29.bat | 40 +++++++++++----- dist/iidx/gamestart-30.bat | 40 +++++++++++----- dist/iidx/launcher-18.xml | 75 ++++++++++++++++++++++++++++++ dist/iidx/launcher-19.xml | 75 ++++++++++++++++++++++++++++++ dist/iidx/launcher-20.xml | 75 ++++++++++++++++++++++++++++++ dist/iidx/launcher-21.xml | 75 ++++++++++++++++++++++++++++++ dist/iidx/launcher-22.xml | 75 ++++++++++++++++++++++++++++++ dist/iidx/launcher-23.xml | 75 ++++++++++++++++++++++++++++++ dist/iidx/launcher-24.xml | 75 ++++++++++++++++++++++++++++++ dist/iidx/launcher-25.xml | 74 +++++++++++++++++++++++++++++ dist/iidx/launcher-26.xml | 74 +++++++++++++++++++++++++++++ dist/iidx/launcher-27.xml | 69 +++++++++++++++++++++++++++ dist/iidx/launcher-28.xml | 69 +++++++++++++++++++++++++++ dist/iidx/launcher-29.xml | 69 +++++++++++++++++++++++++++ dist/iidx/launcher-30.xml | 69 +++++++++++++++++++++++++++ dist/iidx/pcbid.xml | 7 +++ dist/jb/ea3-ident.xml | 10 ++++ dist/jb/eamuse-server.xml | 6 +++ dist/jb/gamestart-03.bat | 35 +++++++++++--- dist/jb/gamestart-04.bat | 35 +++++++++++--- dist/jb/launcher-03.xml | 75 ++++++++++++++++++++++++++++++ dist/jb/launcher-04.xml | 75 ++++++++++++++++++++++++++++++ dist/jb/pcbid.xml | 7 +++ dist/sdvx/ea3-ident.xml | 10 ++++ dist/sdvx/eamuse-server.xml | 6 +++ dist/sdvx/gamestart.bat | 35 ++++++++++++++ dist/sdvx/launcher.xml | 75 ++++++++++++++++++++++++++++++ dist/sdvx/pcbid.xml | 7 +++ dist/sdvx5/ea3-ident.xml | 10 ++++ dist/sdvx5/eamuse-server.xml | 6 +++ dist/sdvx5/gamestart-cn.bat | 41 +++++++++++----- dist/sdvx5/gamestart.bat | 40 +++++++++++----- dist/sdvx5/launcher-cn.xml | 74 +++++++++++++++++++++++++++++ dist/sdvx5/launcher.xml | 74 +++++++++++++++++++++++++++++ dist/sdvx5/pcbid.xml | 7 +++ dist/shared/ea3-ident.xml | 11 +++++ dist/shared/ea3-license.xml | 8 ++++ dist/shared/ea3-service.xml | 7 +++ 70 files changed, 3050 insertions(+), 209 deletions(-) create mode 100644 dist/bst/launcher-01.xml create mode 100644 dist/bst/launcher-02.xml create mode 100644 dist/ddr/launcher-12.xml create mode 100644 dist/ddr/launcher-13.xml create mode 100644 dist/ddr/launcher-14.xml create mode 100644 dist/ddr/launcher-15.xml create mode 100644 dist/ddr/launcher-16.xml create mode 100644 dist/ddr/launcher-17.xml create mode 100644 dist/ddr/launcher-18.xml create mode 100644 dist/iidx/ea3-ident.xml create mode 100644 dist/iidx/eamuse-server.xml create mode 100644 dist/iidx/launcher-18.xml create mode 100644 dist/iidx/launcher-19.xml create mode 100644 dist/iidx/launcher-20.xml create mode 100644 dist/iidx/launcher-21.xml create mode 100644 dist/iidx/launcher-22.xml create mode 100644 dist/iidx/launcher-23.xml create mode 100644 dist/iidx/launcher-24.xml create mode 100644 dist/iidx/launcher-25.xml create mode 100644 dist/iidx/launcher-26.xml create mode 100644 dist/iidx/launcher-27.xml create mode 100644 dist/iidx/launcher-28.xml create mode 100644 dist/iidx/launcher-29.xml create mode 100644 dist/iidx/launcher-30.xml create mode 100644 dist/iidx/pcbid.xml create mode 100644 dist/jb/ea3-ident.xml create mode 100644 dist/jb/eamuse-server.xml create mode 100644 dist/jb/launcher-03.xml create mode 100644 dist/jb/launcher-04.xml create mode 100644 dist/jb/pcbid.xml create mode 100644 dist/sdvx/ea3-ident.xml create mode 100644 dist/sdvx/eamuse-server.xml create mode 100644 dist/sdvx/launcher.xml create mode 100644 dist/sdvx/pcbid.xml create mode 100644 dist/sdvx5/ea3-ident.xml create mode 100644 dist/sdvx5/eamuse-server.xml create mode 100644 dist/sdvx5/launcher-cn.xml create mode 100644 dist/sdvx5/launcher.xml create mode 100644 dist/sdvx5/pcbid.xml create mode 100644 dist/shared/ea3-ident.xml create mode 100644 dist/shared/ea3-license.xml create mode 100644 dist/shared/ea3-service.xml diff --git a/Module.mk b/Module.mk index 36cda9e..0d6a8b8 100644 --- a/Module.mk +++ b/Module.mk @@ -325,6 +325,10 @@ $(zipdir)/iidx-18.zip: \ dist/iidx/config.bat \ dist/iidx/gamestart-18.bat \ dist/iidx/iidxhook-18.conf \ + dist/iidx/launcher-18.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -356,6 +360,10 @@ $(zipdir)/iidx-19.zip: \ dist/iidx/config.bat \ dist/iidx/gamestart-19.bat \ dist/iidx/iidxhook-19.conf \ + dist/iidx/launcher-19.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -372,6 +380,10 @@ $(zipdir)/iidx-20.zip: \ dist/iidx/config.bat \ dist/iidx/gamestart-20.bat \ dist/iidx/iidxhook-20.conf \ + dist/iidx/launcher-20.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -409,6 +421,13 @@ $(zipdir)/iidx-21-to-24.zip: \ dist/iidx/iidxhook-22.conf \ dist/iidx/iidxhook-23.conf \ dist/iidx/iidxhook-24.conf \ + dist/iidx/launcher-21.xml \ + dist/iidx/launcher-22.xml \ + dist/iidx/launcher-23.xml \ + dist/iidx/launcher-24.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -427,6 +446,11 @@ $(zipdir)/iidx-25-to-26.zip: \ dist/iidx/gamestart-26.bat \ dist/iidx/iidxhook-25.conf \ dist/iidx/iidxhook-26.conf \ + dist/iidx/launcher-25.xml \ + dist/iidx/launcher-26.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -449,6 +473,13 @@ $(zipdir)/iidx-27-to-30.zip: \ dist/iidx/iidxhook-28.conf \ dist/iidx/iidxhook-29.conf \ dist/iidx/iidxhook-30.conf \ + dist/iidx/launcher-27.xml \ + dist/iidx/launcher-28.xml \ + dist/iidx/launcher-29.xml \ + dist/iidx/launcher-30.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ dist/iidx/vefx.txt \ | $(zipdir)/ $(V)echo ... $@ @@ -517,6 +548,10 @@ $(zipdir)/jb-03.zip: \ build/bin/indep-32/jbio.dll \ dist/jb/config.bat \ dist/jb/gamestart-03.bat \ + dist/jb/launcher-03.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -530,6 +565,10 @@ $(zipdir)/jb-04.zip: \ build/bin/indep-32/jbio.dll \ dist/jb/config.bat \ dist/jb/gamestart-03.bat \ + dist/jb/launcher-03.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -543,6 +582,10 @@ $(zipdir)/jb-05-to-07.zip: \ build/bin/indep-32/jbio.dll \ dist/jb/config.bat \ dist/jb/gamestart-04.bat \ + dist/jb/launcher-04.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -556,6 +599,10 @@ $(zipdir)/jb-08.zip: \ build/bin/indep-32/jbio.dll \ dist/jb/config.bat \ dist/jb/gamestart-04.bat \ + dist/jb/launcher-04.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -580,6 +627,10 @@ $(zipdir)/sdvx-01-to-04.zip: \ build/bin/indep-32/sdvxio.dll \ dist/sdvx/config.bat \ dist/sdvx/gamestart.bat \ + dist/sdvx/launcher.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -594,6 +645,10 @@ $(zipdir)/sdvx-05-to-06.zip: \ dist/sdvx5/config.bat \ dist/sdvx5/gamestart.bat \ dist/sdvx5/sdvxhook2.conf \ + dist/sdvx5/launcher.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -608,6 +663,10 @@ $(zipdir)/sdvx-05-cn.zip: \ dist/sdvx5/config.bat \ dist/sdvx5/gamestart-cn.bat \ dist/sdvx5/sdvxhook2-cn.conf \ + dist/sdvx5/launcher-cn.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -682,6 +741,10 @@ $(zipdir)/ddr-12.zip: \ build/bin/indep-32/geninput.dll \ dist/ddr/config.bat \ dist/ddr/gamestart-12.bat \ + dist/ddr/launcher-12.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -698,6 +761,10 @@ $(zipdir)/ddr-13.zip: \ build/bin/indep-32/geninput.dll \ dist/ddr/config.bat \ dist/ddr/gamestart-13.bat \ + dist/ddr/launcher-13.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -711,13 +778,19 @@ $(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 \ dist/ddr/gamestart-17.bat \ dist/ddr/gamestart-18.bat \ + dist/ddr/launcher-14.xml \ + dist/ddr/launcher-15.xml \ + dist/ddr/launcher-16.xml \ + dist/ddr/launcher-17.xml \ + dist/ddr/launcher-18.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -731,11 +804,15 @@ $(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 \ + dist/ddr/launcher-16.xml \ + dist/ddr/launcher-17.xml \ + dist/ddr/launcher-18.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -774,6 +851,11 @@ $(zipdir)/bst.zip: \ dist/bst/config.bat \ dist/bst/gamestart1.bat \ dist/bst/gamestart2.bat \ + dist/bst/launcher-01.xml \ + dist/bst/launcher-02.xml \ + dist/shared/ea3-ident.xml \ + dist/shared/ea3-license.xml \ + dist/shared/ea3-service.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ diff --git a/dist/bst/gamestart1.bat b/dist/bst/gamestart1.bat index 5a3a915..5bca8eb 100644 --- a/dist/bst/gamestart1.bat +++ b/dist/bst/gamestart1.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K bsthook.dll -E prop/ea3-config-1.xml beatstream1.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-01.xml %* \ No newline at end of file diff --git a/dist/bst/gamestart2.bat b/dist/bst/gamestart2.bat index 8b6f53f..55340c3 100644 --- a/dist/bst/gamestart2.bat +++ b/dist/bst/gamestart2.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K bsthook.dll -E prop/ea3-config-2.xml beatstream2.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-02.xml %* \ No newline at end of file diff --git a/dist/bst/launcher-01.xml b/dist/bst/launcher-01.xml new file mode 100644 index 0000000..b62630e --- /dev/null +++ b/dist/bst/launcher-01.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + ∂ + + info + + + /dev/nvram/ea3-config.xml + + + beatstream1.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-server.xml + + + + bsthook.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/bst/launcher-02.xml b/dist/bst/launcher-02.xml new file mode 100644 index 0000000..fdad81d --- /dev/null +++ b/dist/bst/launcher-02.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + beatstream2.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + bsthook.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/gamestart-12.bat b/dist/ddr/gamestart-12.bat index 7df3fa3..03daa9c 100644 --- a/dist/ddr/gamestart-12.bat +++ b/dist/ddr/gamestart-12.bat @@ -1,11 +1,42 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s k-clvsd.dll -regsvr32 /s xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll -.\launcher.exe -K .\ddrhook2.dll .\ddr.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-13.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll \ No newline at end of file diff --git a/dist/ddr/gamestart-13.bat b/dist/ddr/gamestart-13.bat index 7df3fa3..03daa9c 100644 --- a/dist/ddr/gamestart-13.bat +++ b/dist/ddr/gamestart-13.bat @@ -1,11 +1,42 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s k-clvsd.dll -regsvr32 /s xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll -.\launcher.exe -K .\ddrhook2.dll .\ddr.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-13.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll \ No newline at end of file diff --git a/dist/ddr/gamestart-14.bat b/dist/ddr/gamestart-14.bat index 2ad5212..2364f52 100644 --- a/dist/ddr/gamestart-14.bat +++ b/dist/ddr/gamestart-14.bat @@ -1,14 +1,44 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\nvram\coin.xml copy prop\coin.xml conf\nvram\coin.xml -if not exist conf\nvram\eacoin.xml copy prop\eacoin.xml conf\nvram\eacoin.xml -if not exist conf\nvram\share-config.xml copy prop\share-config.xml conf\nvram\share-config.xml -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s k-clvsd.dll -regsvr32 /s xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll +regsvr32 /s %COM_DIR%\xactengine2_10.dll -.\launcher.exe -K .\ddrhook2.dll .\mdxja_945.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-14.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll +regsvr32 /u /s %COM_DIR%\xactengine2_10.dll \ No newline at end of file diff --git a/dist/ddr/gamestart-15.bat b/dist/ddr/gamestart-15.bat index 2ad5212..9730117 100644 --- a/dist/ddr/gamestart-15.bat +++ b/dist/ddr/gamestart-15.bat @@ -1,14 +1,44 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\nvram\coin.xml copy prop\coin.xml conf\nvram\coin.xml -if not exist conf\nvram\eacoin.xml copy prop\eacoin.xml conf\nvram\eacoin.xml -if not exist conf\nvram\share-config.xml copy prop\share-config.xml conf\nvram\share-config.xml -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s k-clvsd.dll -regsvr32 /s xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll +regsvr32 /s %COM_DIR%\xactengine2_10.dll -.\launcher.exe -K .\ddrhook2.dll .\mdxja_945.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-15.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll +regsvr32 /u /s %COM_DIR%\xactengine2_10.dll \ No newline at end of file diff --git a/dist/ddr/gamestart-16.bat b/dist/ddr/gamestart-16.bat index d108118..b176cb3 100644 --- a/dist/ddr/gamestart-16.bat +++ b/dist/ddr/gamestart-16.bat @@ -1,15 +1,44 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\nvram\ea3-config.xml copy prop\eamuse-config.xml conf\nvram\ea3-config.xml -if not exist conf\nvram\coin.xml copy prop\coin.xml conf\nvram\coin.xml -if not exist conf\nvram\eacoin.xml copy prop\eacoin.xml conf\nvram\eacoin.xml -if not exist conf\nvram\testmode-v.xml copy prop\testmode-v.xml conf\nvram\testmode-v.xml -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s com\k-clvsd.dll -regsvr32 /s com\xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll +regsvr32 /s %COM_DIR%\xactengine2_10.dll -.\launcher.exe -H 33554432 -K .\ddrhook2.dll .\arkmdxp3.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-17.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll +regsvr32 /u /s %COM_DIR%\xactengine2_10.dll \ No newline at end of file diff --git a/dist/ddr/gamestart-17.bat b/dist/ddr/gamestart-17.bat index d108118..89c15da 100644 --- a/dist/ddr/gamestart-17.bat +++ b/dist/ddr/gamestart-17.bat @@ -1,15 +1,44 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\nvram\ea3-config.xml copy prop\eamuse-config.xml conf\nvram\ea3-config.xml -if not exist conf\nvram\coin.xml copy prop\coin.xml conf\nvram\coin.xml -if not exist conf\nvram\eacoin.xml copy prop\eacoin.xml conf\nvram\eacoin.xml -if not exist conf\nvram\testmode-v.xml copy prop\testmode-v.xml conf\nvram\testmode-v.xml -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s com\k-clvsd.dll -regsvr32 /s com\xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll +regsvr32 /s %COM_DIR%\xactengine2_10.dll -.\launcher.exe -H 33554432 -K .\ddrhook2.dll .\arkmdxp3.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-17.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll +regsvr32 /u /s %COM_DIR%\xactengine2_10.dll diff --git a/dist/ddr/gamestart-18.bat b/dist/ddr/gamestart-18.bat index d108118..d73ddf3 100644 --- a/dist/ddr/gamestart-18.bat +++ b/dist/ddr/gamestart-18.bat @@ -1,15 +1,44 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist conf\nvram mkdir conf\nvram -if not exist conf\nvram\ea3-config.xml copy prop\eamuse-config.xml conf\nvram\ea3-config.xml -if not exist conf\nvram\coin.xml copy prop\coin.xml conf\nvram\coin.xml -if not exist conf\nvram\eacoin.xml copy prop\eacoin.xml conf\nvram\eacoin.xml -if not exist conf\nvram\testmode-v.xml copy prop\testmode-v.xml conf\nvram\testmode-v.xml -if not exist conf\raw mkdir conf\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set COM_DIR=%CONTENT_DIR%\com +set MODULES_DIR=%CONTENT_DIR%\modules -regsvr32 /s com\k-clvsd.dll -regsvr32 /s com\xactengine2_10.dll +:: Register video codecs, e.g. required for background videos +regsvr32 /s %COM_DIR%\k-clvsd.dll +regsvr32 /s %COM_DIR%\xactengine2_10.dll -.\launcher.exe -H 33554432 -K .\ddrhook2.dll .\arkmdxp3.dll %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-18.xml %* + +:: Unregister video codec to avoid conflicts with other/older video codecs crashing different +:: game versions, e.g. DDR X +regsvr32 /u /s %COM_DIR%\k-clvsd.dll +regsvr32 /u /s %COM_DIR%\xactengine2_10.dll diff --git a/dist/ddr/launcher-12.xml b/dist/ddr/launcher-12.xml new file mode 100644 index 0000000..54c0284 --- /dev/null +++ b/dist/ddr/launcher-12.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 31457280 + 31457280 + + + info + + + /dev/nvram/ea3-config.xml + + + ddr.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-13.xml b/dist/ddr/launcher-13.xml new file mode 100644 index 0000000..54c0284 --- /dev/null +++ b/dist/ddr/launcher-13.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 31457280 + 31457280 + + + info + + + /dev/nvram/ea3-config.xml + + + ddr.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-14.xml b/dist/ddr/launcher-14.xml new file mode 100644 index 0000000..9ae27ac --- /dev/null +++ b/dist/ddr/launcher-14.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 31457280 + 31457280 + + + info + + + /dev/nvram/ea3-config.xml + + + mdxja_945.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-15.xml b/dist/ddr/launcher-15.xml new file mode 100644 index 0000000..9ae27ac --- /dev/null +++ b/dist/ddr/launcher-15.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 31457280 + 31457280 + + + info + + + /dev/nvram/ea3-config.xml + + + mdxja_945.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-16.xml b/dist/ddr/launcher-16.xml new file mode 100644 index 0000000..cdf16d5 --- /dev/null +++ b/dist/ddr/launcher-16.xml @@ -0,0 +1,76 @@ + + + + bemanitools_local_fs + + + + + + + + + + + + prop/avs-config.xml + 33554432 + 1048576 + + + info + + + /dev/nvram/ea3-config.xml + + + arkmdxp3.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-17.xml b/dist/ddr/launcher-17.xml new file mode 100644 index 0000000..cdf16d5 --- /dev/null +++ b/dist/ddr/launcher-17.xml @@ -0,0 +1,76 @@ + + + + bemanitools_local_fs + + + + + + + + + + + + prop/avs-config.xml + 33554432 + 1048576 + + + info + + + /dev/nvram/ea3-config.xml + + + arkmdxp3.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/ddr/launcher-18.xml b/dist/ddr/launcher-18.xml new file mode 100644 index 0000000..cdf16d5 --- /dev/null +++ b/dist/ddr/launcher-18.xml @@ -0,0 +1,76 @@ + + + + bemanitools_local_fs + + + + + + + + + + + + prop/avs-config.xml + 33554432 + 1048576 + + + info + + + /dev/nvram/ea3-config.xml + + + arkmdxp3.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + ddrhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/ea3-ident.xml b/dist/iidx/ea3-ident.xml new file mode 100644 index 0000000..e24a9b9 --- /dev/null +++ b/dist/iidx/ea3-ident.xml @@ -0,0 +1,10 @@ + + + + LDJ + J + A + A + 2022082400 + + \ No newline at end of file diff --git a/dist/iidx/eamuse-server.xml b/dist/iidx/eamuse-server.xml new file mode 100644 index 0000000..bc70644 --- /dev/null +++ b/dist/iidx/eamuse-server.xml @@ -0,0 +1,6 @@ + + + + http://localhost + + \ No newline at end of file diff --git a/dist/iidx/gamestart-18.bat b/dist/iidx/gamestart-18.bat index cce99b0..4777dd9 100755 --- a/dist/iidx/gamestart-18.bat +++ b/dist/iidx/gamestart-18.bat @@ -1,14 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist d mkdir d -if not exist e mkdir e -if not exist f mkdir f +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% -launcher -K iidxhook4.dll bm2dx.dll --config iidxhook-18.conf %* +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-18.xml --config %BEMANITOOLS_DIR%\iidxhook-18.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-19.bat b/dist/iidx/gamestart-19.bat index 8bfd580..03c22b0 100755 --- a/dist/iidx/gamestart-19.bat +++ b/dist/iidx/gamestart-19.bat @@ -1,14 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist d mkdir d -if not exist e mkdir e -if not exist f mkdir f +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% -launcher -K iidxhook5.dll bm2dx.dll --config iidxhook-19.conf %* +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-19.xml --config %BEMANITOOLS_DIR%\iidxhook-19.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-20.bat b/dist/iidx/gamestart-20.bat index 2dac80e..f579f2e 100755 --- a/dist/iidx/gamestart-20.bat +++ b/dist/iidx/gamestart-20.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K iidxhook6.dll bm2dx.dll --config iidxhook-20.conf %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-20.xml --config %BEMANITOOLS_DIR%\iidxhook-20.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-21.bat b/dist/iidx/gamestart-21.bat index b79d641..9ec039d 100755 --- a/dist/iidx/gamestart-21.bat +++ b/dist/iidx/gamestart-21.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-21.conf %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-21.xml --config %BEMANITOOLS_DIR%\iidxhook-21.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-22.bat b/dist/iidx/gamestart-22.bat index d10a945..d284786 100755 --- a/dist/iidx/gamestart-22.bat +++ b/dist/iidx/gamestart-22.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-22.conf %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-22.xml --config %BEMANITOOLS_DIR%\iidxhook-22.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-23.bat b/dist/iidx/gamestart-23.bat index 656e1fe..33cceb1 100755 --- a/dist/iidx/gamestart-23.bat +++ b/dist/iidx/gamestart-23.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-23.conf %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-23.xml --config %BEMANITOOLS_DIR%\iidxhook-23.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-24.bat b/dist/iidx/gamestart-24.bat index 283020c..94fa8b2 100755 --- a/dist/iidx/gamestart-24.bat +++ b/dist/iidx/gamestart-24.bat @@ -1,10 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-24.conf %* +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-24.xml --config %BEMANITOOLS_DIR%\iidxhook-24.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-25.bat b/dist/iidx/gamestart-25.bat index edff294..2d6b6c7 100644 --- a/dist/iidx/gamestart-25.bat +++ b/dist/iidx/gamestart-25.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 134217728 -K iidxhook8.dll bm2dx.dll --config iidxhook-25.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-25.xml --config %BEMANITOOLS_DIR%\iidxhook-25.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-26.bat b/dist/iidx/gamestart-26.bat index d41b72b..dc06460 100644 --- a/dist/iidx/gamestart-26.bat +++ b/dist/iidx/gamestart-26.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 134217728 -K iidxhook8.dll bm2dx.dll --config iidxhook-26.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-26.xml --config %BEMANITOOLS_DIR%\iidxhook-26.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-27.bat b/dist/iidx/gamestart-27.bat index 04a3909..d034f84 100644 --- a/dist/iidx/gamestart-27.bat +++ b/dist/iidx/gamestart-27.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 134217728 -B iidxhook9.dll bm2dx.dll --config iidxhook-27.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-27.xml --config %BEMANITOOLS_DIR%\iidxhook-27.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-28.bat b/dist/iidx/gamestart-28.bat index 1abb520..cfc18e4 100644 --- a/dist/iidx/gamestart-28.bat +++ b/dist/iidx/gamestart-28.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 134217728 -B iidxhook9.dll bm2dx.dll --config iidxhook-28.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-28.xml --config %BEMANITOOLS_DIR%\iidxhook-28.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-29.bat b/dist/iidx/gamestart-29.bat index 1029b8c..64a02a5 100644 --- a/dist/iidx/gamestart-29.bat +++ b/dist/iidx/gamestart-29.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 134217728 -B iidxhook9.dll bm2dx.dll --config iidxhook-29.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-29.xml --config %BEMANITOOLS_DIR%\iidxhook-29.conf %* \ No newline at end of file diff --git a/dist/iidx/gamestart-30.bat b/dist/iidx/gamestart-30.bat index 776d7e8..61f7720 100644 --- a/dist/iidx/gamestart-30.bat +++ b/dist/iidx/gamestart-30.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -modules\launcher -H 134217728 -B iidxhook9.dll bm2dx.dll --config iidxhook-30.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-30.xml --config %BEMANITOOLS_DIR%\iidxhook-30.conf %* \ No newline at end of file diff --git a/dist/iidx/launcher-18.xml b/dist/iidx/launcher-18.xml new file mode 100644 index 0000000..74bf35e --- /dev/null +++ b/dist/iidx/launcher-18.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook4.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-19.xml b/dist/iidx/launcher-19.xml new file mode 100644 index 0000000..1749cfb --- /dev/null +++ b/dist/iidx/launcher-19.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook5.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-20.xml b/dist/iidx/launcher-20.xml new file mode 100644 index 0000000..7af7ce4 --- /dev/null +++ b/dist/iidx/launcher-20.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook6.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-21.xml b/dist/iidx/launcher-21.xml new file mode 100644 index 0000000..502407b --- /dev/null +++ b/dist/iidx/launcher-21.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook7.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-22.xml b/dist/iidx/launcher-22.xml new file mode 100644 index 0000000..502407b --- /dev/null +++ b/dist/iidx/launcher-22.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook7.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-23.xml b/dist/iidx/launcher-23.xml new file mode 100644 index 0000000..502407b --- /dev/null +++ b/dist/iidx/launcher-23.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook7.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-24.xml b/dist/iidx/launcher-24.xml new file mode 100644 index 0000000..502407b --- /dev/null +++ b/dist/iidx/launcher-24.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook7.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-25.xml b/dist/iidx/launcher-25.xml new file mode 100644 index 0000000..733a880 --- /dev/null +++ b/dist/iidx/launcher-25.xml @@ -0,0 +1,74 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook8.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-26.xml b/dist/iidx/launcher-26.xml new file mode 100644 index 0000000..733a880 --- /dev/null +++ b/dist/iidx/launcher-26.xml @@ -0,0 +1,74 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + iidxhook8.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-27.xml b/dist/iidx/launcher-27.xml new file mode 100644 index 0000000..736ee63 --- /dev/null +++ b/dist/iidx/launcher-27.xml @@ -0,0 +1,69 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + boot + + + + + + + + + + bemanitools/ea3-service.xml + + + + + + iidxhook9.dll + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-28.xml b/dist/iidx/launcher-28.xml new file mode 100644 index 0000000..736ee63 --- /dev/null +++ b/dist/iidx/launcher-28.xml @@ -0,0 +1,69 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + boot + + + + + + + + + + bemanitools/ea3-service.xml + + + + + + iidxhook9.dll + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-29.xml b/dist/iidx/launcher-29.xml new file mode 100644 index 0000000..736ee63 --- /dev/null +++ b/dist/iidx/launcher-29.xml @@ -0,0 +1,69 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + boot + + + + + + + + + + bemanitools/ea3-service.xml + + + + + + iidxhook9.dll + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/launcher-30.xml b/dist/iidx/launcher-30.xml new file mode 100644 index 0000000..736ee63 --- /dev/null +++ b/dist/iidx/launcher-30.xml @@ -0,0 +1,69 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 134217728 + + + info + + + /dev/nvram/ea3-config.xml + + + bm2dx.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + boot + + + + + + + + + + bemanitools/ea3-service.xml + + + + + + iidxhook9.dll + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/iidx/pcbid.xml b/dist/iidx/pcbid.xml new file mode 100644 index 0000000..bc50cde --- /dev/null +++ b/dist/iidx/pcbid.xml @@ -0,0 +1,7 @@ + + + + 0101020304050607083F + 0101020304050607083F + + \ No newline at end of file diff --git a/dist/jb/ea3-ident.xml b/dist/jb/ea3-ident.xml new file mode 100644 index 0000000..e24a9b9 --- /dev/null +++ b/dist/jb/ea3-ident.xml @@ -0,0 +1,10 @@ + + + + LDJ + J + A + A + 2022082400 + + \ No newline at end of file diff --git a/dist/jb/eamuse-server.xml b/dist/jb/eamuse-server.xml new file mode 100644 index 0000000..bc70644 --- /dev/null +++ b/dist/jb/eamuse-server.xml @@ -0,0 +1,6 @@ + + + + http://localhost + + \ No newline at end of file diff --git a/dist/jb/gamestart-03.bat b/dist/jb/gamestart-03.bat index 76acc78..39e1b8f 100644 --- a/dist/jb/gamestart-03.bat +++ b/dist/jb/gamestart-03.bat @@ -1,11 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\ea3-config.xml copy prop\ea3-config.xml dev\nvram\ea3-config.xml -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -H 33554432 -K jbhook2.dll jubeat.dll -v +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-03.xml -v %* \ No newline at end of file diff --git a/dist/jb/gamestart-04.bat b/dist/jb/gamestart-04.bat index 245e314..14d95e7 100644 --- a/dist/jb/gamestart-04.bat +++ b/dist/jb/gamestart-04.bat @@ -1,11 +1,34 @@ @echo off +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. cd /d %~dp0 -if not exist dev\nvram mkdir dev\nvram -if not exist dev\nvram\ea3-config.xml copy prop\ea3-config.xml dev\nvram\ea3-config.xml -if not exist dev\nvram\coin.xml copy prop\defaults\coin.xml dev\nvram\coin.xml -if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin.xml -if not exist dev\raw mkdir dev\raw +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules -launcher -H 33554432 -K jbhook3.dll jubeat.dll +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-04.xml %* \ No newline at end of file diff --git a/dist/jb/launcher-03.xml b/dist/jb/launcher-03.xml new file mode 100644 index 0000000..095b2f6 --- /dev/null +++ b/dist/jb/launcher-03.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 33554432 + 33554432 + + + info + + + /dev/nvram/ea3-config.xml + + + jubeat.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + jbhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/jb/launcher-04.xml b/dist/jb/launcher-04.xml new file mode 100644 index 0000000..1c85a3c --- /dev/null +++ b/dist/jb/launcher-04.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 33554432 + 33554432 + + + info + + + /dev/nvram/ea3-config.xml + + + jubeat.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + jbhook3.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/jb/pcbid.xml b/dist/jb/pcbid.xml new file mode 100644 index 0000000..bc50cde --- /dev/null +++ b/dist/jb/pcbid.xml @@ -0,0 +1,7 @@ + + + + 0101020304050607083F + 0101020304050607083F + + \ No newline at end of file diff --git a/dist/sdvx/ea3-ident.xml b/dist/sdvx/ea3-ident.xml new file mode 100644 index 0000000..e24a9b9 --- /dev/null +++ b/dist/sdvx/ea3-ident.xml @@ -0,0 +1,10 @@ + + + + LDJ + J + A + A + 2022082400 + + \ No newline at end of file diff --git a/dist/sdvx/eamuse-server.xml b/dist/sdvx/eamuse-server.xml new file mode 100644 index 0000000..bc70644 --- /dev/null +++ b/dist/sdvx/eamuse-server.xml @@ -0,0 +1,6 @@ + + + + http://localhost + + \ No newline at end of file diff --git a/dist/sdvx/gamestart.bat b/dist/sdvx/gamestart.bat index a286325..4e97b92 100644 --- a/dist/sdvx/gamestart.bat +++ b/dist/sdvx/gamestart.bat @@ -8,3 +8,38 @@ if not exist dev\nvram\eacoin.xml copy prop\defaults\eacoin.xml dev\nvram\eacoin if not exist dev\raw mkdir dev\raw launcher -K sdvxhook.dll soundvoltex.dll %* + +@echo off + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher.xml %* \ No newline at end of file diff --git a/dist/sdvx/launcher.xml b/dist/sdvx/launcher.xml new file mode 100644 index 0000000..4876ca7 --- /dev/null +++ b/dist/sdvx/launcher.xml @@ -0,0 +1,75 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 16777216 + 16777216 + + + info + + + /dev/nvram/ea3-config.xml + + + soundvoltex.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + sdvxhook.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/sdvx/pcbid.xml b/dist/sdvx/pcbid.xml new file mode 100644 index 0000000..bc50cde --- /dev/null +++ b/dist/sdvx/pcbid.xml @@ -0,0 +1,7 @@ + + + + 0101020304050607083F + 0101020304050607083F + + \ No newline at end of file diff --git a/dist/sdvx5/ea3-ident.xml b/dist/sdvx5/ea3-ident.xml new file mode 100644 index 0000000..e24a9b9 --- /dev/null +++ b/dist/sdvx5/ea3-ident.xml @@ -0,0 +1,10 @@ + + + + LDJ + J + A + A + 2022082400 + + \ No newline at end of file diff --git a/dist/sdvx5/eamuse-server.xml b/dist/sdvx5/eamuse-server.xml new file mode 100644 index 0000000..bc70644 --- /dev/null +++ b/dist/sdvx5/eamuse-server.xml @@ -0,0 +1,6 @@ + + + + http://localhost + + \ No newline at end of file diff --git a/dist/sdvx5/gamestart-cn.bat b/dist/sdvx5/gamestart-cn.bat index 8435bd7..265fce1 100644 --- a/dist/sdvx5/gamestart-cn.bat +++ b/dist/sdvx5/gamestart-cn.bat @@ -1,17 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\c.dest echo $null >> dev\raw\c.dest -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 268435456 -K sdvxhook2-cn.dll soundvoltex.dll --config sdvxhook2-cn.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-cn.xml --config %BEMANITOOLS_DIR%\sdvxhook2-cn.conf %* \ No newline at end of file diff --git a/dist/sdvx5/gamestart.bat b/dist/sdvx5/gamestart.bat index c1b41dd..2db9289 100644 --- a/dist/sdvx5/gamestart.bat +++ b/dist/sdvx5/gamestart.bat @@ -1,16 +1,34 @@ @echo off -cd /d %~dp0 -if not exist dev mkdir dev -if not exist dev\e mkdir dev\e -if not exist dev\g mkdir dev\g -if not exist dev\nvram mkdir dev\nvram -if not exist dev\raw mkdir dev\raw -if not exist dev\raw\log mkdir dev\raw\log -if not exist dev\raw\fscache mkdir dev\raw\fscache +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session -for /R prop\defaults %%D in (*.*) do ( - if not exist dev\nvram\%%~nxD copy /y prop\defaults\%%~nxD dev\nvram +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 ) -launcher -H 268435456 -K sdvxhook2.dll soundvoltex.dll --config sdvxhook2.conf %* +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: (contents/) next to the folders modules, data etc. +cd /d %~dp0 + +:: Script expects to be located in the root folder (contents/) next to the +:: folders modules, data etc. +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set MODULES_DIR=%CONTENT_DIR%\modules + +:: Keep that data vanilla, no need to copy these around anymore +:: Just add them to the env PATH so launcher can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to launcher +set PATH=^ +%MODULES_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the game's root folder +cd /d %CONTENT_DIR% + +%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher.xml --config %BEMANITOOLS_DIR%\sdvxhook2.conf %* \ No newline at end of file diff --git a/dist/sdvx5/launcher-cn.xml b/dist/sdvx5/launcher-cn.xml new file mode 100644 index 0000000..4ec2939 --- /dev/null +++ b/dist/sdvx5/launcher-cn.xml @@ -0,0 +1,74 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 268435456 + + + info + + + /dev/nvram/ea3-config.xml + + + soundvoltex.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + sdvxhook2-cn.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/sdvx5/launcher.xml b/dist/sdvx5/launcher.xml new file mode 100644 index 0000000..3ae97c1 --- /dev/null +++ b/dist/sdvx5/launcher.xml @@ -0,0 +1,74 @@ + + + + bemanitools_local_fs + + + + + + + + + + + prop/avs-config.xml + 268435456 + + + info + + + /dev/nvram/ea3-config.xml + + + soundvoltex.dll + + + + + + + + + bemanitools/ea3-ident.xml + bemanitools/ea3-license.xml + + + + + + + . + + + dev/nvram + fs + + + + dev/raw + fs + + + + + + + + bemanitools/ea3-service.xml + + + + sdvxhook2.dll + + + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/dist/sdvx5/pcbid.xml b/dist/sdvx5/pcbid.xml new file mode 100644 index 0000000..bc50cde --- /dev/null +++ b/dist/sdvx5/pcbid.xml @@ -0,0 +1,7 @@ + + + + 0101020304050607083F + 0101020304050607083F + + \ No newline at end of file diff --git a/dist/shared/ea3-ident.xml b/dist/shared/ea3-ident.xml new file mode 100644 index 0000000..ae4161e --- /dev/null +++ b/dist/shared/ea3-ident.xml @@ -0,0 +1,11 @@ + + + + + 000 + A + A + A + 1969032100 + + \ No newline at end of file diff --git a/dist/shared/ea3-license.xml b/dist/shared/ea3-license.xml new file mode 100644 index 0000000..fef3534 --- /dev/null +++ b/dist/shared/ea3-license.xml @@ -0,0 +1,8 @@ + + + + + 0101020304050607083F + 0101020304050607083F + + \ No newline at end of file diff --git a/dist/shared/ea3-service.xml b/dist/shared/ea3-service.xml new file mode 100644 index 0000000..ffaaa43 --- /dev/null +++ b/dist/shared/ea3-service.xml @@ -0,0 +1,7 @@ + + + + + http://localhost + + \ No newline at end of file From c78639f0946d706bf04143c1796478b41bc67d7d Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 23 Feb 2024 18:53:51 +0100 Subject: [PATCH 17/18] fix(mingw): Version upgrade caused this to error HRESULT not defined fixed by including windows header --- src/main/hook/com-proxy.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/hook/com-proxy.h b/src/main/hook/com-proxy.h index 94671b7..71d2953 100644 --- a/src/main/hook/com-proxy.h +++ b/src/main/hook/com-proxy.h @@ -1,5 +1,7 @@ #pragma once +#include + #include #include From 7a086ea60b19d1107b8131c16d2c204c6e1e4197 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 25 Feb 2024 09:02:35 +0100 Subject: [PATCH 18/18] fix(hook): Add missing hook_table_revert impl Allow hooks to cleanup when they are shut down. --- src/main/hook/table.c | 82 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/main/hook/table.c b/src/main/hook/table.c index ed67b3b..067ea75 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,33 @@ 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) {