diff --git a/Dockerfile b/Dockerfile.build
similarity index 100%
rename from Dockerfile
rename to Dockerfile.build
diff --git a/Dockerfile.dev b/Dockerfile.dev
new file mode 100644
index 00000000..00c51086
--- /dev/null
+++ b/Dockerfile.dev
@@ -0,0 +1,21 @@
+FROM --platform=amd64 debian:11.6-slim@sha256:f7d141c1ec6af549958a7a2543365a7829c2cdc4476308ec2e182f8a7c59b519
+
+LABEL description="Development environment for bemanitools"
+
+# mingw-w64-gcc has 32-bit and 64-bit toolchains
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ mingw-w64 \
+ mingw-w64-common \
+ make \
+ zip \
+ git \
+ clang-format \
+ python3-pip \
+ && rm -rf /var/lib/apt/lists/*
+
+RUN pip3 install mdformat
+
+RUN mkdir /bemanitools
+WORKDIR /bemanitools
+
+ENV SHELL /bin/bash
\ No newline at end of file
diff --git a/GNUmakefile b/GNUmakefile
index 83289629..9aef0b1b 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -13,8 +13,10 @@ BUILDDIR ?= build
builddir_docker := $(BUILDDIR)/docker
-docker_container_name := "bemanitools-build"
-docker_image_name := "bemanitools-build:latest"
+docker_build_container_name := "bemanitools-build"
+docker_build_image_name := "bemanitools-build:latest"
+docker_dev_container_name := "bemanitools-dev"
+docker_dev_image_name := "bemanitools-dev:latest"
depdir := $(BUILDDIR)/dep
objdir := $(BUILDDIR)/obj
@@ -41,6 +43,7 @@ FORCE:
.PHONY: \
build-docker \
+dev-docker \
clean \
code-format \
doc-format \
@@ -89,21 +92,38 @@ version:
$(V)echo "$(gitrev)" > version
build-docker:
- $(V)docker rm -f $(docker_container_name) 2> /dev/null || true
+ $(V)docker rm -f $(docker_build_container_name) 2> /dev/null || true
$(V)docker \
build \
- -t $(docker_image_name) \
- -f Dockerfile \
+ -t $(docker_build_image_name) \
+ -f Dockerfile.build \
.
$(V)docker \
run \
--volume $(shell pwd):/bemanitools \
- --name $(docker_container_name) \
- $(docker_image_name)
+ --name $(docker_build_container_name) \
+ $(docker_build_image_name)
+
+dev-docker:
+ $(V)docker rm -f $(docker_dev_container_name) 2> /dev/null || true
+ $(V)docker \
+ build \
+ -t $(docker_dev_image_name) \
+ -f Dockerfile.dev \
+ .
+ $(V)docker \
+ run \
+ --interactive \
+ --tty \
+ --volume $(shell pwd):/bemanitools \
+ --name $(docker_dev_container_name) \
+ $(docker_dev_image_name)
clean-docker:
- $(V)docker rm -f $(docker_container_name) || true
- $(V)docker image rm -f $(docker_image_name) || true
+ $(V)docker rm -f $(docker_dev_container_name) || true
+ $(V)docker image rm -f $(docker_dev_image_name) || true
+ $(V)docker rm -f $(docker_build_container_name) || true
+ $(V)docker image rm -f $(docker_build_image_name) || true
$(V)rm -rf $(BUILDDIR)
#
diff --git a/Module.mk b/Module.mk
index 2a948a8d..beef6986 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
@@ -324,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 ... $@
@@ -355,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 ... $@
@@ -371,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 ... $@
@@ -408,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 ... $@
@@ -426,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 ... $@
@@ -448,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 ... $@
@@ -516,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 $@ $^
@@ -529,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 $@ $^
@@ -542,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 $@ $^
@@ -555,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 $@ $^
@@ -579,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 $@ $^
@@ -593,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 $@ $^
@@ -607,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 $@ $^
@@ -681,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 $@ $^
@@ -697,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 $@ $^
@@ -710,11 +778,21 @@ $(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 $@ $^
@@ -728,9 +806,17 @@ $(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 $@ $^
@@ -769,6 +855,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 5a3a9155..5bca8eb1 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
+
+:: 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%
-launcher -K bsthook.dll -E prop/ea3-config-1.xml beatstream1.dll %*
+%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 8b6f53f8..55340c37 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
+
+:: 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%
-launcher -K bsthook.dll -E prop/ea3-config-2.xml beatstream2.dll %*
+%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 00000000..b62630ef
--- /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 00000000..fdad81d9
--- /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 7df3fa33..03daa9c3 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
+
+:: Register video codecs, e.g. required for background videos
+regsvr32 /s %COM_DIR%\k-clvsd.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%
-regsvr32 /s k-clvsd.dll
-regsvr32 /s xactengine2_10.dll
+%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-13.xml %*
-.\launcher.exe -K .\ddrhook2.dll .\ddr.dll %*
+:: 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 7df3fa33..03daa9c3 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
+
+:: Register video codecs, e.g. required for background videos
+regsvr32 /s %COM_DIR%\k-clvsd.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%
-regsvr32 /s k-clvsd.dll
-regsvr32 /s xactengine2_10.dll
+%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-13.xml %*
-.\launcher.exe -K .\ddrhook2.dll .\ddr.dll %*
+:: 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 2ad52121..2364f521 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
+
+:: Register video codecs, e.g. required for background videos
+regsvr32 /s %COM_DIR%\k-clvsd.dll
+regsvr32 /s %COM_DIR%\xactengine2_10.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%
-regsvr32 /s k-clvsd.dll
-regsvr32 /s xactengine2_10.dll
+%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-14.xml %*
-.\launcher.exe -K .\ddrhook2.dll .\mdxja_945.dll %*
+:: 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 2ad52121..97301177 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
+
+:: Register video codecs, e.g. required for background videos
+regsvr32 /s %COM_DIR%\k-clvsd.dll
+regsvr32 /s %COM_DIR%\xactengine2_10.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%
-regsvr32 /s k-clvsd.dll
-regsvr32 /s xactengine2_10.dll
+%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-15.xml %*
-.\launcher.exe -K .\ddrhook2.dll .\mdxja_945.dll %*
+:: 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 d108118b..b176cb3a 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
+
+:: Register video codecs, e.g. required for background videos
+regsvr32 /s %COM_DIR%\k-clvsd.dll
+regsvr32 /s %COM_DIR%\xactengine2_10.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%
-regsvr32 /s com\k-clvsd.dll
-regsvr32 /s com\xactengine2_10.dll
+%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-17.xml %*
-.\launcher.exe -H 33554432 -K .\ddrhook2.dll .\arkmdxp3.dll %*
+:: 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 d108118b..89c15da0 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
+
+:: Register video codecs, e.g. required for background videos
+regsvr32 /s %COM_DIR%\k-clvsd.dll
+regsvr32 /s %COM_DIR%\xactengine2_10.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%
-regsvr32 /s com\k-clvsd.dll
-regsvr32 /s com\xactengine2_10.dll
+%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-17.xml %*
-.\launcher.exe -H 33554432 -K .\ddrhook2.dll .\arkmdxp3.dll %*
+:: 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 d108118b..d73ddf34 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
+
+:: Register video codecs, e.g. required for background videos
+regsvr32 /s %COM_DIR%\k-clvsd.dll
+regsvr32 /s %COM_DIR%\xactengine2_10.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%
-regsvr32 /s com\k-clvsd.dll
-regsvr32 /s com\xactengine2_10.dll
+%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher-18.xml %*
-.\launcher.exe -H 33554432 -K .\ddrhook2.dll .\arkmdxp3.dll %*
+:: 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 00000000..54c0284b
--- /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 00000000..54c0284b
--- /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 00000000..9ae27ac3
--- /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 00000000..9ae27ac3
--- /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 00000000..cdf16d55
--- /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 00000000..cdf16d55
--- /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 00000000..cdf16d55
--- /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 00000000..e24a9b92
--- /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 00000000..bc706444
--- /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 cce99b03..4777dd9c 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
+
+:: 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%
-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
+:: Current working dir is the game's root folder
+cd /d %CONTENT_DIR%
-launcher -K iidxhook4.dll bm2dx.dll --config iidxhook-18.conf %*
+%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 8bfd5803..03c22b08 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
+
+:: 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%
-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
+:: Current working dir is the game's root folder
+cd /d %CONTENT_DIR%
-launcher -K iidxhook5.dll bm2dx.dll --config iidxhook-19.conf %*
+%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 2dac80ea..f579f2ef 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
+
+:: 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%
-launcher -K iidxhook6.dll bm2dx.dll --config iidxhook-20.conf %*
+%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 b79d6416..9ec039dd 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
+
+:: 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%
-launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-21.conf %*
+%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 d10a945a..d2847863 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
+
+:: 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%
-launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-22.conf %*
+%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 656e1fe2..33cceb12 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
+
+:: 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%
-launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-23.conf %*
+%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 283020c4..94fa8b2b 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
+
+:: 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%
-launcher -K iidxhook7.dll bm2dx.dll --config iidxhook-24.conf %*
+%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 edff2940..2d6b6c7c 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 d41b72b3..dc06460f 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 04a39091..d034f84f 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 1abb520d..cfc18e45 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 1029b8c5..64a02a5b 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 776d7e84..61f77205 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 00000000..74bf35e3
--- /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 00000000..1749cfbd
--- /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 00000000..7af7ce4f
--- /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 00000000..502407b7
--- /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 00000000..502407b7
--- /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 00000000..502407b7
--- /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 00000000..502407b7
--- /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 00000000..733a8807
--- /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 00000000..733a8807
--- /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 00000000..736ee635
--- /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 00000000..736ee635
--- /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 00000000..736ee635
--- /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 00000000..736ee635
--- /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 00000000..bc50cdee
--- /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 00000000..e24a9b92
--- /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 00000000..bc706444
--- /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 76acc782..39e1b8fd 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
+
+:: 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%
-launcher -H 33554432 -K jbhook2.dll jubeat.dll -v
+%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 245e314d..14d95e78 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
+
+:: 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%
-launcher -H 33554432 -K jbhook3.dll jubeat.dll
+%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 00000000..095b2f62
--- /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 00000000..1c85a3c8
--- /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 00000000..bc50cdee
--- /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 00000000..e24a9b92
--- /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 00000000..bc706444
--- /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 a286325c..4e97b924 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 00000000..4876ca76
--- /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 00000000..bc50cdee
--- /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 00000000..e24a9b92
--- /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 00000000..bc706444
--- /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 8435bd73..265fce19 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 c1b41ddd..2db92894 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 00000000..4ec2939f
--- /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 00000000..3ae97c1e
--- /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 00000000..bc50cdee
--- /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 00000000..ae4161ef
--- /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 00000000..fef35346
--- /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 00000000..ffaaa437
--- /dev/null
+++ b/dist/shared/ea3-service.xml
@@ -0,0 +1,7 @@
+
+
+
+
+ http://localhost
+
+
\ No newline at end of file
diff --git a/src/api/log.h b/src/api/log.h
new file mode 100644
index 00000000..638a269a
--- /dev/null
+++ b/src/api/log.h
@@ -0,0 +1,31 @@
+#ifndef BEMANITOOLS_API_THREAD_H
+#define BEMANITOOLS_API_THREAD_H
+
+#include
+
+#ifdef __GNUC__
+/* Bemanitools is compiled with GCC (MinGW, specifically) as of version 5 */
+#define LOG_CHECK_FMT __attribute__((format(printf, 2, 3)))
+#else
+/* Compile it out for MSVC plebs */
+#define LOG_CHECK_FMT
+#endif
+
+/* An AVS-style logger function. Comes in four flavors: misc, info, warning,
+ and fatal, with increasing severity. Fatal loggers do not return, they
+ abort the running process after writing their message to the log.
+
+ "module" is an arbitrary short string identifying the source of the log
+ message. The name of the calling DLL is a good default choice for this
+ string, although you might want to identify a module within your DLL here
+ instead.
+
+ "fmt" is a printf-style format string. Depending on the context in which
+ your DLL is running you might end up calling a logger function exported
+ from libavs, which has its own printf implementation (including a number of
+ proprietary extensions), so don't use any overly exotic formats. */
+
+typedef void (*btapi_log_formatter_t)(const char *module, const char *fmt, ...)
+ LOG_CHECK_FMT;
+
+#endif
diff --git a/src/api/thread.h b/src/api/thread.h
new file mode 100644
index 00000000..0459c9d1
--- /dev/null
+++ b/src/api/thread.h
@@ -0,0 +1,20 @@
+#ifndef BEMANITOOLS_API_THREAD_H
+#define BEMANITOOLS_API_THREAD_H
+
+#include
+
+/* An API for spawning threads. This API is defined by libavs, although
+ Bemanitools itself may supply compatible implementations of these functions
+ to your DLL, depending on the context in which it runs.
+
+ NOTE: You may only use the logging functions from a thread where Bemanitools
+ calls you, or a thread that you create using this API. Failure to observe
+ this restriction will cause the process to crash. This is a limitation of
+ libavs itself, not Bemanitools. */
+
+typedef int (*btapi_thread_create_t)(
+ int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority);
+typedef void (*btapi_thread_join_t)(int thread_id, int *result);
+typedef void (*btapi_thread_destroy_t)(int thread_id);
+
+#endif
diff --git a/src/imports/avs.h b/src/imports/avs.h
index a2d439ec..ae054e5c 100644
--- a/src/imports/avs.h
+++ b/src/imports/avs.h
@@ -220,6 +220,9 @@ void property_file_write(struct property *prop, const char *path);
int property_set_flag(struct property *prop, int flags, int mask);
void property_destroy(struct property *prop);
+avs_error property_get_error(struct property *prop);
+void property_clear_error(struct property *prop);
+
int property_psmap_import(
struct property *prop,
struct property_node *root,
diff --git a/src/imports/import_32_0_avs.def b/src/imports/import_32_0_avs.def
index 273e5be8..9632ecb4 100644
--- a/src/imports/import_32_0_avs.def
+++ b/src/imports/import_32_0_avs.def
@@ -25,6 +25,8 @@ EXPORTS
property_destroy
property_file_write
property_insert_read
+ property_clear_error
+ property_get_error
property_mem_write
property_read_query_memsize
property_search
diff --git a/src/imports/import_32_1002_avs.def b/src/imports/import_32_1002_avs.def
index e2ff5ae5..cc4ee29c 100644
--- a/src/imports/import_32_1002_avs.def
+++ b/src/imports/import_32_1002_avs.def
@@ -28,6 +28,8 @@ EXPORTS
property_destroy
property_file_write
property_insert_read
+ property_clear_error
+ property_get_error
property_mem_write
property_read_query_memsize
property_search
diff --git a/src/imports/import_32_1101_avs.def b/src/imports/import_32_1101_avs.def
index 10c59e4f..776dc712 100644
--- a/src/imports/import_32_1101_avs.def
+++ b/src/imports/import_32_1101_avs.def
@@ -26,6 +26,8 @@ EXPORTS
property_desc_to_buffer @246 NONAME
property_destroy @247 NONAME
property_insert_read @255 NONAME
+ property_clear_error @573 NONAME
+ property_get_error @573 NONAME
property_node_create @266 NONAME
property_node_datasize @267 NONAME
property_node_name @274 NONAME
diff --git a/src/imports/import_32_1304_avs.def b/src/imports/import_32_1304_avs.def
index f83d5a5f..18dad23a 100644
--- a/src/imports/import_32_1304_avs.def
+++ b/src/imports/import_32_1304_avs.def
@@ -25,6 +25,8 @@ EXPORTS
property_desc_to_buffer @201 NONAME
property_destroy @264 NONAME
property_insert_read @23 NONAME
+ property_clear_error @573 NONAME
+ property_get_error @573 NONAME
property_node_create @316 NONAME
property_node_datasize @249 NONAME
property_node_name @255 NONAME
diff --git a/src/imports/import_32_1306_avs.def b/src/imports/import_32_1306_avs.def
index f963ec88..f6deed72 100644
--- a/src/imports/import_32_1306_avs.def
+++ b/src/imports/import_32_1306_avs.def
@@ -25,6 +25,8 @@ EXPORTS
property_desc_to_buffer @201 NONAME == XC058ba50000cd
property_destroy @264 NONAME == XC058ba500010f
property_insert_read @23 NONAME == XC058ba5000016
+ property_clear_error @573 NONAME
+ property_get_error @573 NONAME
property_node_create @316 NONAME == XC058ba5000143
property_node_datasize @249 NONAME == XC058ba5000100
property_node_name @255 NONAME == XC058ba5000106
diff --git a/src/imports/import_32_1403_avs.def b/src/imports/import_32_1403_avs.def
index de171c12..716d0817 100644
--- a/src/imports/import_32_1403_avs.def
+++ b/src/imports/import_32_1403_avs.def
@@ -24,6 +24,8 @@ EXPORTS
property_desc_to_buffer @131 NONAME
property_destroy @130 NONAME
property_insert_read @133 NONAME
+ property_clear_error @573 NONAME
+ property_get_error @573 NONAME
property_node_name @573 NONAME ==
property_node_read @573 NONAME ==
property_node_remove @148 NONAME
diff --git a/src/imports/import_32_1508_avs.def b/src/imports/import_32_1508_avs.def
index d1625126..504a303f 100644
--- a/src/imports/import_32_1508_avs.def
+++ b/src/imports/import_32_1508_avs.def
@@ -26,6 +26,8 @@ EXPORTS
property_desc_to_buffer @129 NONAME
property_destroy @128 NONAME
property_insert_read @131 NONAME
+ property_clear_error @573 NONAME
+ property_get_error @573 NONAME
property_node_create @145 NONAME
property_node_name @150 NONAME
property_node_read @154 NONAME == XCd229cc0000f3
diff --git a/src/imports/import_32_1601_avs.def b/src/imports/import_32_1601_avs.def
index 74332d48..286806bf 100644
--- a/src/imports/import_32_1601_avs.def
+++ b/src/imports/import_32_1601_avs.def
@@ -19,6 +19,8 @@ EXPORTS
property_destroy @125 NONAME
property_desc_to_buffer @126 NONAME
property_insert_read @128 NONAME
+ property_clear_error @573 NONAME
+ property_get_error @573 NONAME
property_search @141 NONAME
property_node_create @142 NONAME
property_node_name @147 NONAME == XCnbrep7000092
diff --git a/src/imports/import_32_1603_avs.def b/src/imports/import_32_1603_avs.def
index 21f55c1e..93fd07d2 100644
--- a/src/imports/import_32_1603_avs.def
+++ b/src/imports/import_32_1603_avs.def
@@ -19,6 +19,8 @@ EXPORTS
property_destroy @146 NONAME
property_desc_to_buffer @147 NONAME
property_insert_read @149 NONAME
+ property_clear_error @158 NONAME == XCnbrep700009d
+ property_get_error @159 NONAME == XCnbrep700009e
property_search @162 NONAME
property_node_create @163 NONAME
property_node_name @168 NONAME == XCnbrep70000a7
diff --git a/src/imports/import_32_1700_avs.def b/src/imports/import_32_1700_avs.def
index 7dc4eaa8..f01bc391 100644
--- a/src/imports/import_32_1700_avs.def
+++ b/src/imports/import_32_1700_avs.def
@@ -21,6 +21,8 @@ EXPORTS
property_destroy @146 NONAME
property_desc_to_buffer @147 NONAME
property_insert_read @149 NONAME
+ property_clear_error @158 NONAME == XCgsqzn000009d
+ property_get_error @159 NONAME == XCgsqzn000009e
property_search @162 NONAME
property_node_create @163 NONAME
property_node_name @168 NONAME == XCgsqzn00000a7
diff --git a/src/imports/import_32_803_avs.def b/src/imports/import_32_803_avs.def
index 37f2b3e6..9340dad5 100644
--- a/src/imports/import_32_803_avs.def
+++ b/src/imports/import_32_803_avs.def
@@ -25,6 +25,8 @@ EXPORTS
property_destroy
property_file_write
property_insert_read
+ property_clear_error
+ property_get_error
property_mem_write
property_read_query_memsize
property_search
diff --git a/src/imports/import_64_1508_avs.def b/src/imports/import_64_1508_avs.def
index 6aeaba1d..1a93e7e5 100644
--- a/src/imports/import_64_1508_avs.def
+++ b/src/imports/import_64_1508_avs.def
@@ -26,6 +26,8 @@ EXPORTS
property_desc_to_buffer @129 NONAME
property_destroy @128 NONAME
property_insert_read @131 NONAME
+ property_clear_error @573 NONAME
+ property_get_error @573 NONAME
property_node_create @145 NONAME
property_node_name @150 NONAME
property_node_read @154 NONAME == XCd229cc0000f3
diff --git a/src/imports/import_64_1509_avs.def b/src/imports/import_64_1509_avs.def
index fde35d65..a596513a 100644
--- a/src/imports/import_64_1509_avs.def
+++ b/src/imports/import_64_1509_avs.def
@@ -26,6 +26,8 @@ EXPORTS
property_desc_to_buffer @129 NONAME
property_destroy @128 NONAME
property_insert_read @131 NONAME
+ property_clear_error @573 NONAME
+ property_get_error @573 NONAME
property_node_create @145 NONAME
property_node_name @573 NONAME ==
property_node_read @573 NONAME ==
diff --git a/src/imports/import_64_1601_avs.def b/src/imports/import_64_1601_avs.def
index 418395f7..960fb947 100644
--- a/src/imports/import_64_1601_avs.def
+++ b/src/imports/import_64_1601_avs.def
@@ -19,6 +19,8 @@ EXPORTS
property_destroy @125 NONAME
property_desc_to_buffer @126 NONAME
property_insert_read @128 NONAME
+ property_clear_error @573 NONAME
+ property_get_error @573 NONAME
property_search @141 NONAME
property_node_create @142 NONAME
property_node_name @147 NONAME == XCnbrep7000092
diff --git a/src/imports/import_64_1603_avs.def b/src/imports/import_64_1603_avs.def
index b106ab1b..14f42b7b 100644
--- a/src/imports/import_64_1603_avs.def
+++ b/src/imports/import_64_1603_avs.def
@@ -19,12 +19,14 @@ EXPORTS
property_destroy @146 NONAME
property_desc_to_buffer @147 NONAME
property_insert_read @149 NONAME
+ property_clear_error @158 NONAME == XCnbrep700009d
+ property_get_error @159 NONAME == XCnbrep700009e
property_search @162 NONAME
property_node_create @163 NONAME
property_node_name @168 NONAME == XCnbrep70000a7
property_node_remove @164 NONAME
property_node_type @169 NONAME == XCnbrep70000a8
- property_node_clone @165 NONAME
+ property_node_clone @165 NONAME == XCnbrep70000a4
property_node_traversal @167 NONAME
property_node_refdata @166 NONAME == XCnbrep70000a5
property_node_datasize @171 NONAME == XCnbrep70000aa
diff --git a/src/imports/import_64_1700_avs.def b/src/imports/import_64_1700_avs.def
index 8cddba8a..3e456b50 100644
--- a/src/imports/import_64_1700_avs.def
+++ b/src/imports/import_64_1700_avs.def
@@ -21,6 +21,8 @@ EXPORTS
property_destroy @146 NONAME
property_desc_to_buffer @147 NONAME
property_insert_read @149 NONAME
+ property_clear_error @158 NONAME == XCgsqzn000009d
+ property_get_error @159 NONAME == XCgsqzn000009e
property_search @162 NONAME
property_node_create @163 NONAME
property_node_name @168 NONAME == XCgsqzn00000a7
diff --git a/src/main/aciodrv-proc/Module.mk b/src/main/aciodrv-proc/Module.mk
index e347f778..9fa6b381 100644
--- a/src/main/aciodrv-proc/Module.mk
+++ b/src/main/aciodrv-proc/Module.mk
@@ -1,6 +1,7 @@
libs += aciodrv-proc
libs_aciodrv-proc := \
+ core \
src_aciodrv-proc := \
panb.c \
diff --git a/src/main/aciodrv-proc/panb.c b/src/main/aciodrv-proc/panb.c
index c054e21f..3f9d5a4f 100644
--- a/src/main/aciodrv-proc/panb.c
+++ b/src/main/aciodrv-proc/panb.c
@@ -5,8 +5,9 @@
#include "aciodrv/device.h"
#include "aciodrv/panb.h"
-#include "util/log.h"
-#include "util/thread.h"
+#include "core/thread.h"
+
+#include "core/log.h"
static int auto_poll_proc(void *auto_poll_param);
static int auto_poll_threadid;
@@ -50,7 +51,7 @@ bool aciodrv_proc_panb_init(struct aciodrv_device_ctx *device)
InitializeCriticalSection(&keypair_lock);
InitializeCriticalSection(&auto_poll_stop_lock);
auto_poll_threadid =
- thread_create(auto_poll_proc, (void *) device, 0x4000, 0);
+ core_thread_create(auto_poll_proc, (void *) device, 0x4000, 0);
return true;
}
@@ -80,8 +81,8 @@ void aciodrv_proc_panb_fini(struct aciodrv_device_ctx *device)
auto_poll_stop = true;
LeaveCriticalSection(&auto_poll_stop_lock);
- thread_join(auto_poll_threadid, NULL);
- thread_destroy(auto_poll_threadid);
+ core_thread_join(auto_poll_threadid, NULL);
+ core_thread_destroy(auto_poll_threadid);
DeleteCriticalSection(&keypair_lock);
DeleteCriticalSection(&auto_poll_stop_lock);
diff --git a/src/main/aciodrv/device.c b/src/main/aciodrv/device.c
index 39bf8afc..7584968d 100644
--- a/src/main/aciodrv/device.c
+++ b/src/main/aciodrv/device.c
@@ -7,8 +7,9 @@
#include "aciodrv/port.h"
+#include "core/log.h"
+
#include "util/hex.h"
-#include "util/log.h"
#include "util/mem.h"
/* Enable to dump all data to the logger */
diff --git a/src/main/aciodrv/h44b.c b/src/main/aciodrv/h44b.c
index afbab429..19283f64 100644
--- a/src/main/aciodrv/h44b.c
+++ b/src/main/aciodrv/h44b.c
@@ -7,7 +7,7 @@
#include "aciodrv/device.h"
-#include "util/log.h"
+#include "core/log.h"
bool aciodrv_h44b_init(struct aciodrv_device_ctx *device, uint8_t node_id)
{
diff --git a/src/main/aciodrv/icca.c b/src/main/aciodrv/icca.c
index ac56d0ea..7bec0c77 100644
--- a/src/main/aciodrv/icca.c
+++ b/src/main/aciodrv/icca.c
@@ -5,7 +5,7 @@
#include "aciodrv/device.h"
#include "aciodrv/icca.h"
-#include "util/log.h"
+#include "core/log.h"
static bool aciodrv_icca_queue_loop_start(
struct aciodrv_device_ctx *device, uint8_t node_id)
diff --git a/src/main/aciodrv/kfca.c b/src/main/aciodrv/kfca.c
index e21a0b84..88093e4b 100644
--- a/src/main/aciodrv/kfca.c
+++ b/src/main/aciodrv/kfca.c
@@ -5,7 +5,7 @@
#include "aciodrv/device.h"
-#include "util/log.h"
+#include "core/log.h"
static bool
aciodrv_kfca_watchdog_start(struct aciodrv_device_ctx *device, uint8_t node_id)
diff --git a/src/main/aciodrv/panb.c b/src/main/aciodrv/panb.c
index 1412e160..2dbc85ed 100644
--- a/src/main/aciodrv/panb.c
+++ b/src/main/aciodrv/panb.c
@@ -5,8 +5,7 @@
#include "aciodrv/device.h"
#include "aciodrv/panb.h"
-#include "util/log.h"
-#include "util/thread.h"
+#include "core/log.h"
bool aciodrv_panb_start_auto_input(
struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t node_count)
diff --git a/src/main/aciodrv/port.c b/src/main/aciodrv/port.c
index b38ad2a7..c3c9c71f 100644
--- a/src/main/aciodrv/port.c
+++ b/src/main/aciodrv/port.c
@@ -6,7 +6,7 @@
#include
-#include "util/log.h"
+#include "core/log.h"
HANDLE aciodrv_port_open(const char *port_path, int baud)
{
diff --git a/src/main/aciodrv/rvol.c b/src/main/aciodrv/rvol.c
index a9e0c36f..ed7c0360 100644
--- a/src/main/aciodrv/rvol.c
+++ b/src/main/aciodrv/rvol.c
@@ -5,7 +5,7 @@
#include "aciodrv/device.h"
-#include "util/log.h"
+#include "core/log.h"
static bool aciodrv_rvol_change_expand_mode(
struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t mode)
diff --git a/src/main/acioemu/addr.c b/src/main/acioemu/addr.c
index 8d85487e..3f52fbb5 100644
--- a/src/main/acioemu/addr.c
+++ b/src/main/acioemu/addr.c
@@ -5,7 +5,7 @@
#include "acioemu/addr.h"
#include "acioemu/emu.h"
-#include "util/log.h"
+#include "core/log.h"
void ac_io_emu_cmd_assign_addrs(
struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t node_count)
diff --git a/src/main/acioemu/emu.c b/src/main/acioemu/emu.c
index 11cf35a4..57f74e05 100644
--- a/src/main/acioemu/emu.c
+++ b/src/main/acioemu/emu.c
@@ -14,9 +14,10 @@
#include "acioemu/emu.h"
#include "acioemu/pipe.h"
+#include "core/log.h"
+
#include "hook/iohook.h"
-#include "util/log.h"
#include "util/str.h"
static HRESULT ac_io_emu_open(struct ac_io_emu *emu, struct irp *irp);
diff --git a/src/main/acioemu/hdxs.c b/src/main/acioemu/hdxs.c
index 9a38beee..01ec19df 100644
--- a/src/main/acioemu/hdxs.c
+++ b/src/main/acioemu/hdxs.c
@@ -6,7 +6,7 @@
#include "acioemu/emu.h"
#include "acioemu/hdxs.h"
-#include "util/log.h"
+#include "core/log.h"
static void ac_io_emu_hdxs_cmd_send_version(
struct ac_io_emu_hdxs *hdxs, const struct ac_io_message *req);
diff --git a/src/main/acioemu/pipe.h b/src/main/acioemu/pipe.h
index ad442fc2..859c3b6f 100644
--- a/src/main/acioemu/pipe.h
+++ b/src/main/acioemu/pipe.h
@@ -7,9 +7,10 @@
#include "acio/acio.h"
+#include "core/log.h"
+
#include "util/iobuf.h"
#include "util/list.h"
-#include "util/log.h"
/* This uses the USB convention where OUT and IN are from the host's (game's)
perspective. So an OUT transaction comes in to us and vice versa.
diff --git a/src/main/aciomgr/Module.mk b/src/main/aciomgr/Module.mk
index 0a17e8cd..b87f81b6 100644
--- a/src/main/aciomgr/Module.mk
+++ b/src/main/aciomgr/Module.mk
@@ -1,6 +1,7 @@
dlls += aciomgr
libs_aciomgr := \
+ core \
aciodrv \
util \
diff --git a/src/main/aciomgr/manager.c b/src/main/aciomgr/manager.c
index e73b18e2..d7f03787 100644
--- a/src/main/aciomgr/manager.c
+++ b/src/main/aciomgr/manager.c
@@ -5,14 +5,15 @@
#include
#include "aciomgr/manager-init.h"
-
#include "aciomgr/manager.h"
#include "acio/acio.h"
#include "aciodrv/device.h"
+
+#include "core/log.h"
+
#include "util/array.h"
-#include "util/log.h"
#define MAX_PORT_PATH_LENGTH 256
@@ -90,7 +91,7 @@ void aciomgr_set_loggers(
log_formatter_t warning,
log_formatter_t fatal)
{
- log_to_external(misc, info, warning, fatal);
+ core_log_impl_set(misc, warning, info, fatal);
}
struct aciomgr_port_dispatcher *aciomgr_port_init(const char *path, int baud)
diff --git a/src/main/aciotest/Module.mk b/src/main/aciotest/Module.mk
index af04652b..efeb038f 100644
--- a/src/main/aciotest/Module.mk
+++ b/src/main/aciotest/Module.mk
@@ -1,6 +1,7 @@
exes += aciotest
libs_aciotest := \
+ core \
bio2drv \
aciodrv \
aciodrv-proc \
diff --git a/src/main/aciotest/main.c b/src/main/aciotest/main.c
index 4a301c41..fdf6df48 100644
--- a/src/main/aciotest/main.c
+++ b/src/main/aciotest/main.c
@@ -15,7 +15,14 @@
#include "aciotest/panb.h"
#include "aciotest/rvol.h"
-#include "util/log.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log.h"
+#include "core/thread-crt-ext.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
+
+#include "core/log.h"
static uint8_t aciotest_cnt = 0;
static uint8_t bi2a_mode = 255;
@@ -112,7 +119,10 @@ int main(int argc, char **argv)
}
}
- log_to_writer(log_writer_stdout, NULL);
+ core_thread_crt_ext_impl_set();
+ core_log_bt_ext_impl_set();
+
+ core_log_bt_ext_init_with_stdout();
struct aciodrv_device_ctx *device =
aciodrv_device_open_path(argv[1], atoi(argv[2]));
diff --git a/src/main/asio/asio-reghook.c b/src/main/asio/asio-reghook.c
index 161b13b1..7e058904 100644
--- a/src/main/asio/asio-reghook.c
+++ b/src/main/asio/asio-reghook.c
@@ -10,13 +10,14 @@
#include
+#include "asio/asio-reghook.h"
+
+#include "core/log.h"
+
#include "hook/com-proxy.h"
#include "hook/table.h"
-#include "asio/asio-reghook.h"
-
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
#include "util/time.h"
diff --git a/src/main/asio/config-asio.c b/src/main/asio/config-asio.c
index b29f99c8..2a8675d1 100644
--- a/src/main/asio/config-asio.c
+++ b/src/main/asio/config-asio.c
@@ -1,8 +1,8 @@
#include "cconfig/cconfig-util.h"
-#include "asio/config-asio.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "asio/config-asio.h"
#define ASIOHOOK_CONFIG_IO_FORCE_ASIO_KEY "asio.force_asio"
#define ASIOHOOK_CONFIG_IO_FORCE_WASAPI_KEY "asio.force_wasapi"
diff --git a/src/main/avs-util/Module.mk b/src/main/avs-util/Module.mk
index 8db06918..2e59f579 100644
--- a/src/main/avs-util/Module.mk
+++ b/src/main/avs-util/Module.mk
@@ -3,4 +3,5 @@ libs += avs-util
libs_avs-util := \
src_avs-util := \
+ core-interop.c \
error.c \
diff --git a/src/main/avs-util/core-interop.c b/src/main/avs-util/core-interop.c
new file mode 100644
index 00000000..555930f1
--- /dev/null
+++ b/src/main/avs-util/core-interop.c
@@ -0,0 +1,16 @@
+#include "core/log.h"
+#include "core/thread.h"
+
+#include "imports/avs.h"
+
+void avs_util_core_interop_log_avs_impl_set()
+{
+ core_log_impl_set(
+ log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+}
+
+void avs_util_core_interop_thread_avs_impl_set()
+{
+ core_thread_impl_set(
+ avs_thread_create, avs_thread_join, avs_thread_destroy);
+}
\ No newline at end of file
diff --git a/src/main/avs-util/core-interop.h b/src/main/avs-util/core-interop.h
new file mode 100644
index 00000000..51b1e119
--- /dev/null
+++ b/src/main/avs-util/core-interop.h
@@ -0,0 +1,7 @@
+#ifndef AVS_UTIL_CORE_INTEROP_H
+#define AVS_UTIL_CORE_INTEROP_H
+
+void avs_util_core_interop_log_avs_impl_set();
+void avs_util_core_interop_thread_avs_impl_set();
+
+#endif
\ No newline at end of file
diff --git a/src/main/avs-util/error.c b/src/main/avs-util/error.c
index ab09c014..d31b2e18 100644
--- a/src/main/avs-util/error.c
+++ b/src/main/avs-util/error.c
@@ -96,4 +96,14 @@ const char *avs_util_error_str(avs_error error)
}
return avs_util_error_unknown;
+}
+
+const char *avs_util_property_error_get_and_clear(struct property *prop)
+{
+ avs_error error;
+
+ error = property_get_error(prop);
+ property_clear_error(prop);
+
+ return avs_util_error_str(error);
}
\ No newline at end of file
diff --git a/src/main/avs-util/error.h b/src/main/avs-util/error.h
index 35988515..88d68c5b 100644
--- a/src/main/avs-util/error.h
+++ b/src/main/avs-util/error.h
@@ -5,4 +5,6 @@
const char *avs_util_error_str(avs_error error);
-#endif
\ No newline at end of file
+const char *avs_util_property_error_get_and_clear(struct property *prop);
+
+#endif
diff --git a/src/main/bio2drv/Module.mk b/src/main/bio2drv/Module.mk
index f5bdb568..9e5e92b3 100644
--- a/src/main/bio2drv/Module.mk
+++ b/src/main/bio2drv/Module.mk
@@ -1,10 +1,11 @@
libs += bio2drv
libs_bio2drv := \
- aciodrv
+ core \
+ aciodrv \
src_bio2drv := \
detect.c \
config-bio2.c \
bi2a-iidx.c \
- bi2a-sdvx.c
+ bi2a-sdvx.c \
diff --git a/src/main/bio2drv/bi2a-iidx.c b/src/main/bio2drv/bi2a-iidx.c
index 1119876f..bce8c41e 100644
--- a/src/main/bio2drv/bi2a-iidx.c
+++ b/src/main/bio2drv/bi2a-iidx.c
@@ -7,7 +7,7 @@
#include "aciodrv/device.h"
-#include "util/log.h"
+#include "core/log.h"
// Must be provided on init command. Actual meaning unknown right now.
// Not providing this will not initialize the IO correctly resulting
diff --git a/src/main/bio2drv/bi2a-sdvx.c b/src/main/bio2drv/bi2a-sdvx.c
index 93edf496..14e52395 100644
--- a/src/main/bio2drv/bi2a-sdvx.c
+++ b/src/main/bio2drv/bi2a-sdvx.c
@@ -7,7 +7,7 @@
#include "aciodrv/device.h"
-#include "util/log.h"
+#include "core/log.h"
static const uint8_t _BIO2DR_BI2A_SDVX_INIT_DATA = 0x3B;
diff --git a/src/main/bio2drv/config-bio2.c b/src/main/bio2drv/config-bio2.c
index 492cdefd..c016fa94 100644
--- a/src/main/bio2drv/config-bio2.c
+++ b/src/main/bio2drv/config-bio2.c
@@ -1,8 +1,8 @@
#include "cconfig/cconfig-util.h"
-#include "bio2drv/config-bio2.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "bio2drv/config-bio2.h"
#define BIO2DRV_CONFIG_BIO2_AUTO_KEY "bio2.autodetect"
#define BIO2DRV_CONFIG_BIO2_PORT_KEY "bio2.port"
diff --git a/src/main/bio2drv/detect.c b/src/main/bio2drv/detect.c
index d559175d..dfdf5013 100644
--- a/src/main/bio2drv/detect.c
+++ b/src/main/bio2drv/detect.c
@@ -8,11 +8,11 @@
#include "bio2drv/detect.h"
+#include "core/log.h"
+
#include
#include
-#include "util/log.h"
-
DEFINE_GUID(
GUID_COM_BUS_ENUMERATOR,
0x4D36E978,
@@ -142,7 +142,7 @@ void bio2drv_set_loggers(
log_formatter_t warning,
log_formatter_t fatal)
{
- log_to_external(misc, info, warning, fatal);
+ core_log_impl_set(misc, warning, info, fatal);
}
bool bio2drv_detect(
diff --git a/src/main/bio2emu/emu.c b/src/main/bio2emu/emu.c
index 9fbcb3d8..ea9c7f0d 100644
--- a/src/main/bio2emu/emu.c
+++ b/src/main/bio2emu/emu.c
@@ -14,6 +14,8 @@
#include "acioemu/addr.h"
#include "acioemu/emu.h"
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "hooklib/rs232.h"
@@ -25,7 +27,6 @@
#include "util/array.h"
#include "util/defs.h"
#include "util/iobuf.h"
-#include "util/log.h"
#include "util/str.h"
static struct array bio2_active_ports;
diff --git a/src/main/bio2emu/setupapi.c b/src/main/bio2emu/setupapi.c
index 5dbfffc7..bb2f32c3 100644
--- a/src/main/bio2emu/setupapi.c
+++ b/src/main/bio2emu/setupapi.c
@@ -6,13 +6,14 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "bio2emu/emu.h"
#include "bio2emu/setupapi.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
#include "util/time.h"
diff --git a/src/main/bsthook/Module.mk b/src/main/bsthook/Module.mk
index ef61d283..92ab3b1c 100644
--- a/src/main/bsthook/Module.mk
+++ b/src/main/bsthook/Module.mk
@@ -4,6 +4,8 @@ deplibs_bsthook := \
avs \
libs_bsthook := \
+ avs-util \
+ core \
acioemu \
bstio \
hook \
diff --git a/src/main/bsthook/acio.c b/src/main/bsthook/acio.c
index fe5f8cc1..500d4c5b 100644
--- a/src/main/bsthook/acio.c
+++ b/src/main/bsthook/acio.c
@@ -19,13 +19,14 @@
#include "bsthook/acio.h"
#include "bsthook/kfca.h"
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "imports/avs.h"
#include "util/defs.h"
#include "util/iobuf.h"
-#include "util/log.h"
#include "util/str.h"
static struct ac_io_emu ac_io_emu;
diff --git a/src/main/bsthook/dllmain.c b/src/main/bsthook/dllmain.c
index 57d38e03..e508057c 100644
--- a/src/main/bsthook/dllmain.c
+++ b/src/main/bsthook/dllmain.c
@@ -2,9 +2,14 @@
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/bstio.h"
#include "bemanitools/eamio.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "hook/iohook.h"
#include "hooklib/app.h"
@@ -18,7 +23,6 @@
#include "util/cmdline.h"
#include "util/defs.h"
-#include "util/log.h"
static bool my_dll_entry_init(char *sidcode, struct property_node *config);
static bool my_dll_entry_main(void);
@@ -33,19 +37,23 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config)
log_info("Starting up BeatStream IO backend");
- bst_io_set_loggers(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ core_log_impl_assign(bst_io_set_loggers);
- ok = bst_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
+ ok = bst_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
if (!ok) {
goto bst_io_fail;
}
- eam_io_set_loggers(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
- ok = eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
+ ok = eam_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
if (!ok) {
goto eam_io_fail;
@@ -91,8 +99,9 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx)
return TRUE;
}
- log_to_external(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+ avs_util_core_interop_log_avs_impl_set();
args_recover(&argc, &argv);
diff --git a/src/main/bsthook/gfx.c b/src/main/bsthook/gfx.c
index 43d88a2d..23d37e0f 100644
--- a/src/main/bsthook/gfx.c
+++ b/src/main/bsthook/gfx.c
@@ -3,6 +3,8 @@
#include
+#include "core/log.h"
+
#include "hook/com-proxy.h"
#include "hook/pe.h"
#include "hook/table.h"
@@ -10,7 +12,6 @@
#include "sdvxhook/gfx.h"
#include "util/defs.h"
-#include "util/log.h"
static HRESULT STDCALL my_CreateDevice(
IDirect3D9 *self,
diff --git a/src/main/bsthook/settings.c b/src/main/bsthook/settings.c
index 8f48ea8e..c9fb10ae 100644
--- a/src/main/bsthook/settings.c
+++ b/src/main/bsthook/settings.c
@@ -7,10 +7,11 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
/* ------------------------------------------------------------------------- */
diff --git a/src/main/camhook/cam.c b/src/main/camhook/cam.c
index 4ce92603..169fd020 100644
--- a/src/main/camhook/cam.c
+++ b/src/main/camhook/cam.c
@@ -15,13 +15,14 @@
#include
+#include "camhook/cam.h"
+
+#include "core/log.h"
+
#include "hook/com-proxy.h"
#include "hook/table.h"
-#include "camhook/cam.h"
-
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
#include "util/time.h"
diff --git a/src/main/camhook/config-cam.c b/src/main/camhook/config-cam.c
index 6a55852e..c6dd1afb 100644
--- a/src/main/camhook/config-cam.c
+++ b/src/main/camhook/config-cam.c
@@ -1,8 +1,8 @@
#include "cconfig/cconfig-util.h"
-#include "camhook/config-cam.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "camhook/config-cam.h"
#define CAMHOOK_CONFIG_CAM_DISABLE_EMU_KEY "cam.disable_emu"
#define CAMHOOK_CONFIG_CAM_DEFAULT_DISABLE_EMU_VALUE false
diff --git a/src/main/cconfig/cconfig-main.c b/src/main/cconfig/cconfig-main.c
index 342a9120..342d8dfe 100644
--- a/src/main/cconfig/cconfig-main.c
+++ b/src/main/cconfig/cconfig-main.c
@@ -6,8 +6,9 @@
#include "cconfig/cconfig-main.h"
+#include "core/log.h"
+
#include "util/cmdline.h"
-#include "util/log.h"
bool cconfig_main_config_init(
struct cconfig *config,
@@ -84,7 +85,7 @@ bool cconfig_main_config_init(
}
log_misc("Config state after file loading:");
- cconfig_util_log(config, log_impl_misc);
+ cconfig_util_log(config, core_log_misc_impl_get());
}
log_misc("Parsing override config parameters from cmd");
@@ -96,7 +97,7 @@ bool cconfig_main_config_init(
}
log_misc("Config state after cmd parameter overrides:");
- cconfig_util_log(config, log_impl_misc);
+ cconfig_util_log(config, core_log_misc_impl_get());
goto success;
diff --git a/src/main/cconfig/cconfig-util.c b/src/main/cconfig/cconfig-util.c
index f4ce05f3..35853574 100644
--- a/src/main/cconfig/cconfig-util.c
+++ b/src/main/cconfig/cconfig-util.c
@@ -5,8 +5,9 @@
#include "cconfig/cconfig-util.h"
+#include "core/log.h"
+
#include "util/hex.h"
-#include "util/log.h"
#include "util/mem.h"
bool cconfig_util_get_int(
@@ -220,10 +221,10 @@ void cconfig_util_set_data(
free(str);
}
-void cconfig_util_log(struct cconfig *config, log_formatter_t log_formatter)
+void cconfig_util_log(struct cconfig *config, core_log_message_t log_message)
{
for (uint32_t i = 0; i < config->nentries; i++) {
- log_formatter(
+ log_message(
LOG_MODULE,
"%s=%s",
config->entries[i].key,
diff --git a/src/main/cconfig/cconfig-util.h b/src/main/cconfig/cconfig-util.h
index aa9b5004..8f6a3058 100644
--- a/src/main/cconfig/cconfig-util.h
+++ b/src/main/cconfig/cconfig-util.h
@@ -7,7 +7,7 @@
#include "cconfig/cconfig.h"
-#include "util/log.h"
+#include "core/log.h"
bool cconfig_util_get_int(
struct cconfig *config,
@@ -57,6 +57,6 @@ void cconfig_util_set_data(
size_t len,
const char *desc);
-void cconfig_util_log(struct cconfig *config, log_formatter_t log_formatter);
+void cconfig_util_log(struct cconfig *config, core_log_message_t log_message);
#endif
\ No newline at end of file
diff --git a/src/main/cconfig/cconfig.c b/src/main/cconfig/cconfig.c
index 1cfcbedb..6150f66f 100644
--- a/src/main/cconfig/cconfig.c
+++ b/src/main/cconfig/cconfig.c
@@ -2,7 +2,8 @@
#include "cconfig/cconfig.h"
-#include "util/log.h"
+#include "core/log.h"
+
#include "util/mem.h"
#include "util/str.h"
diff --git a/src/main/cconfig/cmd.c b/src/main/cconfig/cmd.c
index 3d4f32fc..3bb1c247 100644
--- a/src/main/cconfig/cmd.c
+++ b/src/main/cconfig/cmd.c
@@ -7,8 +7,9 @@
#include "cconfig/cmd.h"
+#include "core/log.h"
+
#include "util/hex.h"
-#include "util/log.h"
#include "util/str.h"
static void
diff --git a/src/main/cconfig/conf.c b/src/main/cconfig/conf.c
index de21f8b9..b23e9d47 100644
--- a/src/main/cconfig/conf.c
+++ b/src/main/cconfig/conf.c
@@ -6,8 +6,9 @@
#include "cconfig/conf.h"
+#include "core/log.h"
+
#include "util/fs.h"
-#include "util/log.h"
#include "util/str.h"
enum cconfig_conf_error cconfig_conf_load_from_file(
diff --git a/src/main/config/Module.mk b/src/main/config/Module.mk
index 2f7bac83..fc37a230 100644
--- a/src/main/config/Module.mk
+++ b/src/main/config/Module.mk
@@ -3,6 +3,7 @@ rc_config := config.rc
cppflags_config := -DUNICODE
libs_config := \
+ core \
eamio \
geninput \
util \
diff --git a/src/main/config/analogs.c b/src/main/config/analogs.c
index 5a7bceeb..d6936670 100644
--- a/src/main/config/analogs.c
+++ b/src/main/config/analogs.c
@@ -11,13 +11,14 @@
#include "config/schema.h"
#include "config/usages.h"
+#include "core/log.h"
+
#include "geninput/hid-mgr.h"
#include "geninput/input-config.h"
#include "geninput/mapper.h"
#include "util/array.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/str.h"
diff --git a/src/main/config/buttons.c b/src/main/config/buttons.c
index f4a498b8..e083bf3f 100644
--- a/src/main/config/buttons.c
+++ b/src/main/config/buttons.c
@@ -15,11 +15,12 @@
#include "config/schema.h"
#include "config/usages.h"
+#include "core/log.h"
+
#include "geninput/input-config.h"
#include "geninput/mapper.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/winres.h"
diff --git a/src/main/config/eam.c b/src/main/config/eam.c
index e9bb76ce..1d665189 100644
--- a/src/main/config/eam.c
+++ b/src/main/config/eam.c
@@ -13,6 +13,8 @@
#include "config/resource.h"
#include "config/schema.h"
+#include "core/log.h"
+
#include "eamio/eam-config.h"
#include "geninput/hid-mgr.h"
@@ -21,7 +23,6 @@
#include "util/array.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/str.h"
diff --git a/src/main/config/gametype.c b/src/main/config/gametype.c
index e7e7353b..2ec0ea4b 100644
--- a/src/main/config/gametype.c
+++ b/src/main/config/gametype.c
@@ -6,8 +6,9 @@
#include "config/resource.h"
#include "config/schema.h"
+#include "core/log.h"
+
#include "util/defs.h"
-#include "util/log.h"
static INT_PTR CALLBACK
game_type_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
diff --git a/src/main/config/main.c b/src/main/config/main.c
index ba515554..8be13700 100644
--- a/src/main/config/main.c
+++ b/src/main/config/main.c
@@ -14,14 +14,19 @@
#include "config/spinner.h"
#include "config/usages.h"
+#include "core/log-bt.h"
+#include "core/log-sink-debug.h"
+#include "core/log.h"
+#include "core/thread-crt-ext.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
+
#include "eamio/eam-config.h"
#include "geninput/input-config.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
-#include "util/thread.h"
#include "util/winres.h"
HPROPSHEETPAGE
@@ -61,11 +66,22 @@ int main(int argc, char **argv)
wchar_t text[1024];
int max_light;
size_t i;
+ struct core_log_sink sink;
inst = GetModuleHandle(NULL);
- log_to_writer(log_writer_debug, NULL);
- log_to_external(log_impl_misc, log_impl_info, log_impl_warning, my_fatal);
+ core_thread_crt_ext_impl_set();
+
+ core_log_impl_set(
+ core_log_bt_log_misc,
+ core_log_bt_log_info,
+ core_log_bt_log_warning,
+ my_fatal);
+
+ core_log_sink_debug_open(&sink);
+
+ core_log_bt_init(&sink);
+ core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC);
usages_init(inst);
@@ -96,13 +112,17 @@ int main(int argc, char **argv)
}
}
- input_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
- input_init(crt_thread_create, crt_thread_join, crt_thread_destroy);
-
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
- eam_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy);
+ core_log_impl_assign(input_set_loggers);
+ input_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
+
+ core_log_impl_assign(eam_io_set_loggers);
+ eam_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
eam_io_config_api = eam_io_get_config_api();
// calculate these and check against the loaded config
diff --git a/src/main/config/snap.c b/src/main/config/snap.c
index 8981c686..6d8547ab 100644
--- a/src/main/config/snap.c
+++ b/src/main/config/snap.c
@@ -6,10 +6,11 @@
#include "config/snap.h"
+#include "core/log.h"
+
#include "geninput/hid-mgr.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
enum snap_control_heuristic { CONTROL_CENTERING_AXIS, CONTROL_MULTISWITCH };
diff --git a/src/main/config/usages.c b/src/main/config/usages.c
index 5e28ad9b..771772cd 100644
--- a/src/main/config/usages.c
+++ b/src/main/config/usages.c
@@ -9,8 +9,9 @@
#include "config/resource.h"
+#include "core/log.h"
+
#include "util/array.h"
-#include "util/log.h"
#include "util/str.h"
#include "util/winres.h"
diff --git a/src/main/core/Module.mk b/src/main/core/Module.mk
new file mode 100644
index 00000000..bd35e6d0
--- /dev/null
+++ b/src/main/core/Module.mk
@@ -0,0 +1,20 @@
+libs += core
+
+libs_core := \
+ util \
+
+src_core := \
+ log-bt-ext.c \
+ log-bt.c \
+ log-sink-async.c \
+ log-sink-debug.c \
+ log-sink-file.c \
+ log-sink-list.c \
+ log-sink-mutex.c \
+ log-sink-null.c \
+ log-sink-std.c \
+ log.c \
+ thread-crt-ext.c \
+ thread-crt.c \
+ thread.c \
+
diff --git a/src/main/core/log-bt-ext.c b/src/main/core/log-bt-ext.c
new file mode 100644
index 00000000..b1aa4f46
--- /dev/null
+++ b/src/main/core/log-bt-ext.c
@@ -0,0 +1,67 @@
+#include
+
+#include "core/log-bt.h"
+#include "core/log-sink-debug.h"
+#include "core/log-sink-file.h"
+#include "core/log-sink-list.h"
+#include "core/log-sink-mutex.h"
+#include "core/log-sink-std.h"
+#include "core/log.h"
+
+void core_log_bt_ext_impl_set()
+{
+ core_log_impl_set(
+ core_log_bt_log_misc,
+ core_log_bt_log_info,
+ core_log_bt_log_warning,
+ core_log_bt_log_fatal);
+}
+
+void core_log_bt_ext_init_with_stdout()
+{
+ struct core_log_sink sink;
+
+ core_log_sink_std_out_open(true, &sink);
+ core_log_bt_init(&sink);
+}
+
+void core_log_bt_ext_init_with_stderr()
+{
+ struct core_log_sink sink;
+
+ core_log_sink_std_err_open(true, &sink);
+ core_log_bt_init(&sink);
+}
+
+void core_log_bt_ext_init_with_debug()
+{
+ struct core_log_sink sink;
+
+ core_log_sink_debug_open(&sink);
+ core_log_bt_init(&sink);
+}
+
+void core_log_bt_ext_init_with_file(
+ const char *path, bool append, bool rotate, uint8_t max_rotations)
+{
+ struct core_log_sink sink;
+
+ core_log_sink_file_open(path, append, rotate, max_rotations, &sink);
+ core_log_bt_init(&sink);
+}
+
+void core_log_bt_ext_init_with_stdout_and_file(
+ const char *path, bool append, bool rotate, uint8_t max_rotations)
+{
+ struct core_log_sink sinks[2];
+ struct core_log_sink sink_composed;
+ struct core_log_sink sink_mutex;
+
+ core_log_sink_std_out_open(true, &sinks[0]);
+ core_log_sink_file_open(path, append, rotate, max_rotations, &sinks[1]);
+ core_log_sink_list_open(sinks, 2, &sink_composed);
+
+ core_log_sink_mutex_open(&sink_composed, &sink_mutex);
+
+ core_log_bt_init(&sink_mutex);
+}
\ No newline at end of file
diff --git a/src/main/core/log-bt-ext.h b/src/main/core/log-bt-ext.h
new file mode 100644
index 00000000..dcb9a9a6
--- /dev/null
+++ b/src/main/core/log-bt-ext.h
@@ -0,0 +1,59 @@
+#ifndef CORE_LOG_BT_EXT_H
+#define CORE_LOG_BT_EXT_H
+
+#include
+#include
+
+/**
+ * Set the current thread API implementation to use the bemanitools log
+ * implementation
+ */
+void core_log_bt_ext_impl_set();
+
+/**
+ * Helper to setup the bemanitools log implementation with a stdout sink.
+ */
+void core_log_bt_ext_init_with_stdout();
+
+/**
+ * Helper to setup the bemanitools log implementation with a stderr sink.
+ */
+void core_log_bt_ext_init_with_stderr();
+
+/**
+ * Helper to setup the bemanitools log implementation with a OutputDebugStr
+ * sink.
+ */
+void core_log_bt_ext_init_with_debug();
+
+/**
+ * Helper to setup the bemanitools log implementation with a file sink
+ *
+ * @param path Path to the log file to write the log output to
+ * @param append If true, then append to an existing file, false to overwrite
+ * any existing file
+ * @param rotate If true, rotates an existing log file and creates a new one
+ * for this session
+ * @param max_rotations Max number of rotations for the log files
+ */
+void core_log_bt_ext_init_with_file(
+ const char *path, bool append, bool rotate, uint8_t max_rotations);
+
+/**
+ * Helper to setup the bemanitools log implementation with a stdout and file
+ * sink
+ *
+ * Important: This combined sink is guarded by a mutex to avoid data races on
+ * logging to two different sinks.
+ *
+ * @param path Path to the log file to write the log output to
+ * @param append If true, then append to an existing file, false to overwrite
+ * any existing file
+ * @param rotate If true, rotates an existing log file and creates a new one
+ * for this session
+ * @param max_rotations Max number of rotations for the log files
+ */
+void core_log_bt_ext_init_with_stdout_and_file(
+ const char *path, bool append, bool rotate, uint8_t max_rotations);
+
+#endif
\ No newline at end of file
diff --git a/src/main/core/log-bt.c b/src/main/core/log-bt.c
new file mode 100644
index 00000000..fd868979
--- /dev/null
+++ b/src/main/core/log-bt.c
@@ -0,0 +1,129 @@
+#include
+#include
+#include
+
+#include "core/log-bt.h"
+#include "core/log-sink.h"
+#include "core/log.h"
+
+#include "util/mem.h"
+#include "util/str.h"
+
+static enum core_log_bt_log_level _core_log_bt_log_level;
+static struct core_log_sink *_core_log_bt_sink;
+
+static void _core_log_bt_vformat_write(
+ enum core_log_bt_log_level level,
+ const char *module,
+ const char *fmt,
+ va_list ap)
+{
+ static const char chars[] = "FFWIM";
+
+ char timestamp[64];
+ /* 64k so we can log data dumps of rs232 without crashing */
+ char msg[65536];
+ char line[65536];
+ int result;
+
+ time_t curtime;
+ struct tm *tm;
+
+ curtime = 0;
+ tm = NULL;
+
+ curtime = time(NULL);
+ tm = localtime(&curtime);
+
+ strftime(timestamp, sizeof(timestamp), "[%Y/%m/%d %H:%M:%S]", tm);
+
+ str_vformat(msg, sizeof(msg), fmt, ap);
+
+ result = str_format(
+ line,
+ sizeof(line),
+ "%s %c:%s: %s\n",
+ timestamp,
+ chars[level],
+ module,
+ msg);
+
+ _core_log_bt_sink->write(_core_log_bt_sink->ctx, line, result);
+}
+
+void core_log_bt_init(const struct core_log_sink *sink)
+{
+ if (sink == NULL) {
+ abort();
+ }
+
+ _core_log_bt_sink = xmalloc(sizeof(struct core_log_sink));
+ memcpy(_core_log_bt_sink, sink, sizeof(struct core_log_sink));
+
+ _core_log_bt_log_level = CORE_LOG_BT_LOG_LEVEL_OFF;
+}
+
+void core_log_bt_level_set(enum core_log_bt_log_level level)
+{
+ _core_log_bt_log_level = level;
+}
+
+void core_log_bt_fini()
+{
+ log_assert(_core_log_bt_sink);
+
+ _core_log_bt_sink->close(_core_log_bt_sink->ctx);
+
+ free(_core_log_bt_sink);
+}
+
+void core_log_bt_log_fatal(const char *module, const char *fmt, ...)
+{
+ va_list ap;
+
+ if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_FATAL) {
+ va_start(ap, fmt);
+ _core_log_bt_vformat_write(
+ CORE_LOG_BT_LOG_LEVEL_FATAL, module, fmt, ap);
+ va_end(ap);
+ }
+}
+
+void core_log_bt_log_warning(const char *module, const char *fmt, ...)
+{
+ va_list ap;
+
+ if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_WARNING) {
+ va_start(ap, fmt);
+ _core_log_bt_vformat_write(
+ CORE_LOG_BT_LOG_LEVEL_WARNING, module, fmt, ap);
+ va_end(ap);
+ }
+}
+
+void core_log_bt_log_info(const char *module, const char *fmt, ...)
+{
+ va_list ap;
+
+ if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_INFO) {
+ va_start(ap, fmt);
+ _core_log_bt_vformat_write(CORE_LOG_BT_LOG_LEVEL_INFO, module, fmt, ap);
+ va_end(ap);
+ }
+}
+
+void core_log_bt_log_misc(const char *module, const char *fmt, ...)
+{
+ va_list ap;
+
+ if (_core_log_bt_log_level >= CORE_LOG_BT_LOG_LEVEL_MISC) {
+ va_start(ap, fmt);
+ _core_log_bt_vformat_write(CORE_LOG_BT_LOG_LEVEL_MISC, module, fmt, ap);
+ va_end(ap);
+ }
+}
+
+void core_log_bt_direct_sink_write(const char *chars, size_t nchars)
+{
+ _core_log_bt_sink->write(_core_log_bt_sink->ctx, chars, nchars);
+}
\ No newline at end of file
diff --git a/src/main/core/log-bt.h b/src/main/core/log-bt.h
new file mode 100644
index 00000000..2a8052f3
--- /dev/null
+++ b/src/main/core/log-bt.h
@@ -0,0 +1,87 @@
+#ifndef CORE_LOG_BT_H
+#define CORE_LOG_BT_H
+
+#include "core/log-sink.h"
+
+/**
+ * Log API implementation for games/applications without AVS
+ */
+
+enum core_log_bt_log_level {
+ CORE_LOG_BT_LOG_LEVEL_OFF = 0,
+ CORE_LOG_BT_LOG_LEVEL_FATAL = 1,
+ CORE_LOG_BT_LOG_LEVEL_WARNING = 2,
+ CORE_LOG_BT_LOG_LEVEL_INFO = 3,
+ CORE_LOG_BT_LOG_LEVEL_MISC = 4,
+};
+
+/**
+ * Initialize the logging backend
+ *
+ * This must be called as early as possible in your application to setup
+ * a logging sink according to your needs. Until this is finished, no
+ * log output is available.
+ *
+ * By default, logging is turned off entirely and must be enabled by setting
+ * a desired logging level explicitly.
+ *
+ * @param sink Pointer to a log sink implementation. The caller owns the memory
+ * of this.
+ */
+void core_log_bt_init(const struct core_log_sink *sink);
+
+/**
+ * Set the current logging level. This can be changed at any given time, e.g.
+ * to increase/decrease verbosity.
+ *
+ * @param level The logging level to set.
+ */
+void core_log_bt_level_set(enum core_log_bt_log_level level);
+
+/**
+ * Cleanup the logging backend.
+ *
+ * Ensure to call this on application exit and cleanup.
+ */
+void core_log_bt_fini();
+
+/**
+ * Implementation of the log API.
+ */
+void core_log_bt_log_fatal(const char *module, const char *fmt, ...);
+
+/**
+ * Implementation of the log API.
+ */
+void core_log_bt_log_warning(const char *module, const char *fmt, ...);
+
+/**
+ * Implementation of the log API.
+ */
+void core_log_bt_log_info(const char *module, const char *fmt, ...);
+
+/**
+ * Implementation of the log API.
+ */
+void core_log_bt_log_misc(const char *module, const char *fmt, ...);
+
+/**
+ * Allow AVS to by-pass the core log API/engine.
+ *
+ * This function must only be called by AVS in an appropriate log callback
+ * function that is passed to avs_boot.
+ *
+ * AVS has it's own logging engine and manages aspects such as async logging,
+ * log levels and decorating log messages.
+ *
+ * Thus, proper interoperability only requires the writer/sink part to be shared
+ * with AVS.
+ *
+ * @param chars Buffer with text data to write to the configured sinks. The
+ * buffer might contain several log messages separated by newline
+ * characters.
+ * @param nchars Number of chars to write to the sink.
+ */
+void core_log_bt_direct_sink_write(const char *chars, size_t nchars);
+
+#endif
\ No newline at end of file
diff --git a/src/main/core/log-sink-async.c b/src/main/core/log-sink-async.c
new file mode 100644
index 00000000..f327aad8
--- /dev/null
+++ b/src/main/core/log-sink-async.c
@@ -0,0 +1,23 @@
+#include
+
+#include "core/log-sink.h"
+
+static void
+_core_log_sink_file_write(void *ctx, const char *chars, size_t nchars)
+{
+ // TODO
+}
+
+static void _core_log_sink_file_close(void *ctx)
+{
+ // TODO
+}
+
+void core_log_sink_async_open(struct core_log_sink *sink)
+{
+ // TODO
+
+ sink->ctx = NULL;
+ sink->write = _core_log_sink_file_write;
+ sink->close = _core_log_sink_file_close;
+}
\ No newline at end of file
diff --git a/src/main/core/log-sink-async.h b/src/main/core/log-sink-async.h
new file mode 100644
index 00000000..47aa49e7
--- /dev/null
+++ b/src/main/core/log-sink-async.h
@@ -0,0 +1,19 @@
+#ifndef CORE_LOG_SINK_ASYNC_H
+#define CORE_LOG_SINK_ASYNC_H
+
+#include
+#include
+
+#include "core/log-sink.h"
+
+/**
+ * Open a async log sink
+ *
+ * The sink passes data to log to a separate thread which executes the actual
+ * logging of the data.
+ *
+ * @param sink Pointer to allocated memory that receives the opened sink
+ */
+void core_log_sink_async_open(struct core_log_sink *sink);
+
+#endif
\ No newline at end of file
diff --git a/src/main/core/log-sink-debug.c b/src/main/core/log-sink-debug.c
new file mode 100644
index 00000000..c1dd7a20
--- /dev/null
+++ b/src/main/core/log-sink-debug.c
@@ -0,0 +1,23 @@
+#include
+
+#include
+
+#include "core/log-sink.h"
+
+static void
+_core_log_sink_debug_write(void *ctx, const char *chars, size_t nchars)
+{
+ OutputDebugStringA(chars);
+}
+
+static void _core_log_sink_debug_close(void *ctx)
+{
+ // noop
+}
+
+void core_log_sink_debug_open(struct core_log_sink *sink)
+{
+ sink->ctx = NULL;
+ sink->write = _core_log_sink_debug_write;
+ sink->close = _core_log_sink_debug_close;
+}
\ No newline at end of file
diff --git a/src/main/core/log-sink-debug.h b/src/main/core/log-sink-debug.h
new file mode 100644
index 00000000..4c21d50c
--- /dev/null
+++ b/src/main/core/log-sink-debug.h
@@ -0,0 +1,15 @@
+#ifndef CORE_LOG_SINK_DEBUG_H
+#define CORE_LOG_SINK_DEBUG_H
+
+#include
+
+#include "core/log-sink.h"
+
+/**
+ * Open a log sink that uses OutputDebugStr
+ *
+ * @param sink Pointer to allocated memory that receives the opened sink
+ */
+void core_log_sink_debug_open(struct core_log_sink *sink);
+
+#endif
\ No newline at end of file
diff --git a/src/main/core/log-sink-file.c b/src/main/core/log-sink-file.c
new file mode 100644
index 00000000..f2ca188e
--- /dev/null
+++ b/src/main/core/log-sink-file.c
@@ -0,0 +1,92 @@
+#include
+
+#include
+#include
+#include
+#include
+
+#include "core/log-sink.h"
+
+#include "util/fs.h"
+#include "util/str.h"
+
+static void _core_log_sink_file_rotate(const char *path, uint8_t max_rotations)
+{
+ uint8_t i;
+ char rotate_file[MAX_PATH];
+ char rotate_file_next[MAX_PATH];
+ char version[8];
+ char version_next[8];
+
+ for (i = max_rotations; i > 0; i++) {
+ str_cpy(rotate_file, sizeof(rotate_file), path);
+ str_cpy(rotate_file_next, sizeof(rotate_file_next), path);
+
+ if (i - 1 != 0) {
+ sprintf(version, ".%d", i);
+ } else {
+ memset(version, 0, sizeof(version));
+ }
+
+ sprintf(version_next, ".%d", i);
+
+ str_cat(rotate_file, sizeof(rotate_file), version);
+ str_cat(rotate_file_next, sizeof(rotate_file_next), version_next);
+
+ if (path_exists(rotate_file)) {
+ CopyFile(rotate_file, rotate_file_next, FALSE);
+ }
+ }
+}
+
+static void
+_core_log_sink_file_write(void *ctx, const char *chars, size_t nchars)
+{
+ FILE *file;
+
+ file = (FILE *) ctx;
+
+ fwrite(chars, 1, nchars, file);
+}
+
+static void _core_log_sink_file_close(void *ctx)
+{
+ FILE *file;
+
+ file = (FILE *) ctx;
+
+ fflush(file);
+ fclose(file);
+}
+
+void core_log_sink_file_open(
+ const char *path,
+ bool append,
+ bool rotate,
+ uint8_t max_rotations,
+ struct core_log_sink *sink)
+{
+ FILE *file;
+
+ if (rotate) {
+ _core_log_sink_file_rotate(path, max_rotations);
+
+ // Appending doesn't matter when file is rotated anyway
+ file = fopen(path, "w+");
+ } else {
+ if (append) {
+ file = fopen(path, "a+");
+ } else {
+ file = fopen(path, "w+");
+ }
+ }
+
+ if (!file) {
+ printf("Cannot open log file: %s", path);
+ abort();
+ }
+
+ sink->ctx = (void *) file;
+ sink->write = _core_log_sink_file_write;
+ sink->close = _core_log_sink_file_close;
+}
\ No newline at end of file
diff --git a/src/main/core/log-sink-file.h b/src/main/core/log-sink-file.h
new file mode 100644
index 00000000..968a1fed
--- /dev/null
+++ b/src/main/core/log-sink-file.h
@@ -0,0 +1,28 @@
+#ifndef CORE_LOG_SINK_FILE_H
+#define CORE_LOG_SINK_FILE_H
+
+#include
+#include
+#include
+
+#include "core/log-sink.h"
+
+/**
+ * Open a log sink writing data to a file
+ *
+ * @param path Path to the log file to write the log output to
+ * @param append If true, then append to an existing file, false to overwrite
+ * any existing file
+ * @param rotate If true, rotates an existing log file and creates a new one
+ * for this session
+ * @param max_rotations Max number of rotations for the log files
+ * @param sink Pointer to allocated memory that receives the opened sink
+ */
+void core_log_sink_file_open(
+ const char *path,
+ bool append,
+ bool rotate,
+ uint8_t max_rotations,
+ struct core_log_sink *sink);
+
+#endif
\ No newline at end of file
diff --git a/src/main/core/log-sink-list.c b/src/main/core/log-sink-list.c
new file mode 100644
index 00000000..38e32112
--- /dev/null
+++ b/src/main/core/log-sink-list.c
@@ -0,0 +1,66 @@
+#include
+#include
+
+#include "core/log-sink-list.h"
+#include "core/log-sink.h"
+
+#include "util/mem.h"
+
+#define MAX_SINKS 8
+
+struct core_log_sink_list {
+ struct core_log_sink entries[MAX_SINKS];
+ uint8_t num;
+};
+
+static void
+_core_log_sink_list_write(void *ctx, const char *chars, size_t nchars)
+{
+ struct core_log_sink_list *sink_list;
+ int i;
+
+ sink_list = (struct core_log_sink_list *) ctx;
+
+ for (i = 0; i < sink_list->num; i++) {
+ sink_list->entries[i].write(sink_list->entries[i].ctx, chars, nchars);
+ }
+}
+
+static void _core_log_sink_list_close(void *ctx)
+{
+ struct core_log_sink_list *sink_list;
+ int i;
+
+ sink_list = (struct core_log_sink_list *) ctx;
+
+ for (i = 0; i < sink_list->num; i++) {
+ sink_list->entries[i].close(sink_list->entries[i].ctx);
+ }
+
+ free(sink_list);
+}
+
+void core_log_sink_list_open(
+ const struct core_log_sink *entry, uint8_t num, struct core_log_sink *sink)
+{
+ struct core_log_sink_list *sink_list;
+ int i;
+
+ if (num > MAX_SINKS) {
+ abort();
+ }
+
+ sink_list = xmalloc(sizeof(struct core_log_sink_list));
+
+ for (i = 0; i < num; i++) {
+ sink_list->entries[i].ctx = entry[i].ctx;
+ sink_list->entries[i].write = entry[i].write;
+ sink_list->entries[i].close = entry[i].close;
+ }
+
+ sink_list->num = num;
+
+ sink->ctx = (void *) sink_list;
+ sink->write = _core_log_sink_list_write;
+ sink->close = _core_log_sink_list_close;
+}
\ No newline at end of file
diff --git a/src/main/core/log-sink-list.h b/src/main/core/log-sink-list.h
new file mode 100644
index 00000000..f1e99f35
--- /dev/null
+++ b/src/main/core/log-sink-list.h
@@ -0,0 +1,24 @@
+#ifndef CORE_LOG_SINK_LIST_H
+#define CORE_LOG_SINK_LIST_H
+
+#include
+#include
+
+#include "core/log-sink.h"
+
+/**
+ * Combine multiple log sinks into a list of sinks.
+ *
+ * Upon invoking a list sink, all sinks contained within the list are
+ * being invoked in the configured order.
+ *
+ * @param entry A pointer to allocated memory with a sequence of opened sinks
+ * that you want to add to the list. Ownership of these sinks
+ * is transferred, i.e. closing the list sink closes its children.
+ * @param num The number of elements in the sequence of opened sinks pointed to.
+ * @param sink Pointer to allocated memory that receives the opened sink
+ */
+void core_log_sink_list_open(
+ const struct core_log_sink *entry, uint8_t num, struct core_log_sink *sink);
+
+#endif
\ No newline at end of file
diff --git a/src/main/core/log-sink-mutex.c b/src/main/core/log-sink-mutex.c
new file mode 100644
index 00000000..13c8b207
--- /dev/null
+++ b/src/main/core/log-sink-mutex.c
@@ -0,0 +1,53 @@
+#include
+
+#include
+
+#include "core/log-sink.h"
+
+#include "util/mem.h"
+
+struct core_log_sink_mutex_ctx {
+ struct core_log_sink *child;
+ HANDLE mutex;
+};
+
+static void
+_core_log_sink_mutex_write(void *ctx_, const char *chars, size_t nchars)
+{
+ struct core_log_sink_mutex_ctx *ctx;
+
+ ctx = (struct core_log_sink_mutex_ctx *) ctx_;
+
+ WaitForSingleObject(ctx->mutex, INFINITE);
+
+ ctx->child->write(ctx->child->ctx, chars, nchars);
+
+ ReleaseMutex(ctx->mutex);
+}
+
+static void _core_log_sink_mutex_close(void *ctx_)
+{
+ struct core_log_sink_mutex_ctx *ctx;
+
+ ctx = (struct core_log_sink_mutex_ctx *) ctx_;
+
+ CloseHandle(ctx->mutex);
+
+ ctx->child->close(ctx->child->ctx);
+ free(ctx);
+}
+
+void core_log_sink_mutex_open(
+ const struct core_log_sink *child_sink, struct core_log_sink *sink)
+{
+ struct core_log_sink_mutex_ctx *ctx;
+
+ ctx = xmalloc(sizeof(struct core_log_sink_mutex_ctx));
+
+ memcpy(ctx->child, child_sink, sizeof(struct core_log_sink));
+ ctx->mutex = CreateMutex(NULL, FALSE, NULL);
+
+ sink->ctx = ctx;
+ sink->write = _core_log_sink_mutex_write;
+ sink->close = _core_log_sink_mutex_close;
+}
\ No newline at end of file
diff --git a/src/main/core/log-sink-mutex.h b/src/main/core/log-sink-mutex.h
new file mode 100644
index 00000000..e30357e4
--- /dev/null
+++ b/src/main/core/log-sink-mutex.h
@@ -0,0 +1,21 @@
+#ifndef CORE_LOG_SINK_MUTEX_H
+#define CORE_LOG_SINK_MUTEX_H
+
+#include
+
+#include "core/log-sink.h"
+
+/**
+ * Create a sink that surrounds another sink with a mutex.
+ *
+ * Use this to make other sink implementations thread-safe.
+ *
+ * @param child_sink Another opened sink to surround with the mutex. Ownership
+ * of the sink is transferred, i.e. closing the mutex sink
+ * also closes the wrapped child sink.
+ * @param sink Pointer to allocated memory that receives the opened sink
+ */
+void core_log_sink_mutex_open(
+ const struct core_log_sink *child_sink, struct core_log_sink *sink);
+
+#endif
\ No newline at end of file
diff --git a/src/main/core/log-sink-null.c b/src/main/core/log-sink-null.c
new file mode 100644
index 00000000..7655a208
--- /dev/null
+++ b/src/main/core/log-sink-null.c
@@ -0,0 +1,21 @@
+#include
+
+#include "core/log-sink.h"
+
+static void
+_core_log_sink_null_write(void *ctx, const char *chars, size_t nchars)
+{
+ // noop
+}
+
+static void _core_log_sink_null_close(void *ctx)
+{
+ // noop
+}
+
+void core_log_sink_null_open(struct core_log_sink *sink)
+{
+ sink->ctx = NULL;
+ sink->write = _core_log_sink_null_write;
+ sink->close = _core_log_sink_null_close;
+}
\ No newline at end of file
diff --git a/src/main/core/log-sink-null.h b/src/main/core/log-sink-null.h
new file mode 100644
index 00000000..ebd2babe
--- /dev/null
+++ b/src/main/core/log-sink-null.h
@@ -0,0 +1,17 @@
+#ifndef CORE_LOG_SINK_NULL_H
+#define CORE_LOG_SINK_NULL_H
+
+#include
+
+#include "core/log-sink.h"
+
+/**
+ * Create a null/dummy sink.
+ *
+ * Use this to disable any logging entirely.
+ *
+ * @param sink Pointer to allocated memory that receives the opened sink
+ */
+void core_log_sink_null_open(struct core_log_sink *sink);
+
+#endif
\ No newline at end of file
diff --git a/src/main/core/log-sink-std.c b/src/main/core/log-sink-std.c
new file mode 100644
index 00000000..197fd12a
--- /dev/null
+++ b/src/main/core/log-sink-std.c
@@ -0,0 +1,193 @@
+#include
+
+#include
+
+#include "core/log-sink.h"
+
+#include "util/mem.h"
+
+struct core_log_sink_std_ctx {
+ HANDLE handle;
+ bool color;
+};
+
+static char _core_log_sink_std_determine_color(const char *str)
+{
+ /* Add some color to make spotting warnings/errors easier.
+ Based on debug output level identifier. */
+
+ /* Avoids colored output on strings like "Windows" */
+ if (str[1] != ':') {
+ return 15;
+ }
+
+ switch (str[0]) {
+ /* green */
+ case 'M':
+ return 10;
+ /* blue */
+ case 'I':
+ return 9;
+ /* yellow */
+ case 'W':
+ return 14;
+ /* red */
+ case 'F':
+ return 12;
+ /* default console color */
+ default:
+ return 15;
+ }
+}
+
+static size_t _core_log_sink_std_msg_coloring_len(const char *str)
+{
+ // Expected format example: "I:boot: my log message"
+
+ const char *ptr;
+ size_t len;
+ int colon_count;
+
+ ptr = str;
+ len = 0;
+ colon_count = 0;
+
+ while (true) {
+ // End of string = invalid log format
+ if (*ptr == '\0') {
+ return 0;
+ }
+
+ if (*ptr == ':') {
+ colon_count++;
+ }
+
+ if (colon_count == 2) {
+ // Skip current colon, next char is a space
+ return len + 1;
+ }
+
+ len++;
+ ptr++;
+ }
+
+ return 0;
+}
+
+static void
+_core_log_sink_std_write(void *ctx_, const char *chars, size_t nchars)
+{
+ static const size_t timestamp_len = strlen("[----/--/-- --:--:--]");
+
+ struct core_log_sink_std_ctx *ctx;
+
+ char color;
+ size_t color_len;
+ size_t msg_len;
+ const char *msg_start;
+ const char *msg_end;
+ DWORD written;
+ DWORD write_pos;
+
+ ctx = (struct core_log_sink_std_ctx *) ctx_;
+
+ if (ctx->color) {
+ write_pos = 0;
+
+ // Support multiple buffered log messages, e.g. from the AVS logging
+ // engine
+ while (write_pos < nchars) {
+ // Expects the AVS timestamp format
+ msg_start = chars + timestamp_len + 1; // +1 is the space
+
+ color_len = _core_log_sink_std_msg_coloring_len(msg_start);
+
+ // Check if we could detect which part to color, otherwise just
+ // write the whole log message without any coloring logic
+ if (color_len > 0) {
+ color = _core_log_sink_std_determine_color(msg_start);
+
+ // Timestamp
+ WriteConsole(
+ ctx->handle, chars, timestamp_len + 1, &written, NULL);
+ write_pos += written;
+ chars += written;
+
+ // Log level + module colored
+ SetConsoleTextAttribute(ctx->handle, color);
+ WriteConsole(ctx->handle, chars, color_len, &written, NULL);
+ write_pos += written;
+ chars += written;
+ SetConsoleTextAttribute(ctx->handle, 15);
+
+ msg_end = strchr(chars, '\n');
+
+ if (msg_end != NULL) {
+ msg_len = msg_end - chars;
+
+ // Write \n as well
+ msg_len++;
+
+ // Write actual message non colored
+ WriteConsole(ctx->handle, chars, msg_len, &written, NULL);
+ write_pos += written;
+ chars += written;
+ } else {
+ WriteConsole(
+ ctx->handle, chars, nchars - write_pos, &written, NULL);
+ write_pos += written;
+ chars += written;
+ }
+ } else {
+ WriteConsole(
+ ctx->handle,
+ chars + write_pos,
+ nchars - write_pos,
+ &written,
+ NULL);
+ write_pos += written;
+ }
+ }
+ } else {
+ WriteConsole(ctx->handle, chars, nchars, &written, NULL);
+ }
+}
+
+static void _core_log_sink_std_close(void *ctx_)
+{
+ struct core_log_sink_std_ctx *ctx;
+
+ ctx = (struct core_log_sink_std_ctx *) ctx_;
+
+ // Remark: Don't close the ctx->handle, see win API docs
+
+ free(ctx);
+}
+
+void core_log_sink_std_out_open(bool color, struct core_log_sink *sink)
+{
+ struct core_log_sink_std_ctx *ctx;
+
+ ctx = xmalloc(sizeof(struct core_log_sink_std_ctx));
+
+ ctx->handle = GetStdHandle(STD_OUTPUT_HANDLE);
+ ctx->color = color;
+
+ sink->ctx = (void *) ctx;
+ sink->write = _core_log_sink_std_write;
+ sink->close = _core_log_sink_std_close;
+}
+
+void core_log_sink_std_err_open(bool color, struct core_log_sink *sink)
+{
+ struct core_log_sink_std_ctx *ctx;
+
+ ctx = xmalloc(sizeof(struct core_log_sink_std_ctx));
+
+ ctx->handle = GetStdHandle(STD_ERROR_HANDLE);
+ ctx->color = color;
+
+ sink->ctx = (void *) ctx;
+ sink->write = _core_log_sink_std_write;
+ sink->close = _core_log_sink_std_close;
+}
\ No newline at end of file
diff --git a/src/main/core/log-sink-std.h b/src/main/core/log-sink-std.h
new file mode 100644
index 00000000..e0e006bf
--- /dev/null
+++ b/src/main/core/log-sink-std.h
@@ -0,0 +1,24 @@
+#ifndef CORE_LOG_SINK_STD_H
+#define CORE_LOG_SINK_STD_H
+
+#include
+
+#include "core/log-sink.h"
+
+/**
+ * Create a sink that writes to stdout.
+ *
+ * @param color If true, messages are colored by log level.
+ * @param sink Pointer to allocated memory that receives the opened sink
+ */
+void core_log_sink_std_out_open(bool color, struct core_log_sink *sink);
+
+/**
+ * Create a sink that writes to stderr.
+ *
+ * @param color If true, messages are colored by log level.
+ * @param sink Pointer to allocated memory that receives the opened sink
+ */
+void core_log_sink_std_err_open(bool color, struct core_log_sink *sink);
+
+#endif
\ No newline at end of file
diff --git a/src/main/core/log-sink.h b/src/main/core/log-sink.h
new file mode 100644
index 00000000..7fdd42fb
--- /dev/null
+++ b/src/main/core/log-sink.h
@@ -0,0 +1,45 @@
+#ifndef CORE_LOG_SINK_H
+#define CORE_LOG_SINK_H
+
+#include
+
+/**
+ * Write function for a log sink implementation.
+ *
+ * Write the given data to your target output destination.
+ *
+ * @param ctx Context defined by the implementation when opening the sink.
+ * @param chars Buffer with text data to log. This can contain partial data of
+ * a single log line, a full log line terminated by a newline
+ * character or multiple log lines (each terminated by a newline
+ * character).
+ * @param nchars Number of characters to write.
+ */
+typedef void (*core_log_sink_write_t)(
+ void *ctx, const char *chars, size_t nchars);
+
+/**
+ * Close your log sink and cleanup resources
+ *
+ * Depending on your implementation, you might want to flush any
+ * outstanding/buffered data.
+ *
+ * @param ctx Context defined by the implementation when opening the sink.
+ */
+typedef void (*core_log_sink_close_t)(void *ctx);
+
+/**
+ * Log sink structure.
+ *
+ * This must be set-up and populated when opening your log sink implementation.
+ * The ctx field contains any arbitrary data that you need for your log sink
+ * to operate, e.g. a file handle, additional buffers etc. Make sure these
+ * resources are cleaned up upon closing the sink.
+ */
+struct core_log_sink {
+ void *ctx;
+ core_log_sink_write_t write;
+ core_log_sink_close_t close;
+};
+
+#endif
\ No newline at end of file
diff --git a/src/main/core/log.c b/src/main/core/log.c
new file mode 100644
index 00000000..9d2d6d76
--- /dev/null
+++ b/src/main/core/log.c
@@ -0,0 +1,74 @@
+#include
+
+#include "core/log.h"
+
+core_log_message_t _core_log_misc_impl;
+core_log_message_t _core_log_info_impl;
+core_log_message_t _core_log_warning_impl;
+core_log_message_t _core_log_fatal_impl;
+
+void core_log_impl_set(
+ core_log_message_t misc,
+ core_log_message_t info,
+ core_log_message_t warning,
+ core_log_message_t fatal)
+{
+ if (misc == NULL || info == NULL || warning == NULL || fatal == NULL) {
+ abort();
+ }
+
+ _core_log_misc_impl = misc;
+ _core_log_info_impl = info;
+ _core_log_warning_impl = warning;
+ _core_log_fatal_impl = fatal;
+}
+
+void core_log_impl_assign(core_log_impl_set_t impl_set)
+{
+ if (_core_log_misc_impl == NULL || _core_log_info_impl == NULL ||
+ _core_log_warning_impl == NULL || _core_log_fatal_impl == NULL) {
+ abort();
+ }
+
+ impl_set(
+ _core_log_misc_impl,
+ _core_log_info_impl,
+ _core_log_warning_impl,
+ _core_log_fatal_impl);
+}
+
+core_log_message_t core_log_misc_impl_get()
+{
+ if (_core_log_misc_impl == NULL) {
+ abort();
+ }
+
+ return _core_log_misc_impl;
+}
+
+core_log_message_t core_log_info_impl_get()
+{
+ if (_core_log_info_impl == NULL) {
+ abort();
+ }
+
+ return _core_log_info_impl;
+}
+
+core_log_message_t core_log_warning_impl_get()
+{
+ if (_core_log_warning_impl == NULL) {
+ abort();
+ }
+
+ return _core_log_warning_impl;
+}
+
+core_log_message_t core_log_fatal_impl_get()
+{
+ if (_core_log_fatal_impl == NULL) {
+ abort();
+ }
+
+ return _core_log_fatal_impl;
+}
\ No newline at end of file
diff --git a/src/main/core/log.h b/src/main/core/log.h
new file mode 100644
index 00000000..5b5cd9da
--- /dev/null
+++ b/src/main/core/log.h
@@ -0,0 +1,197 @@
+#ifndef CORE_LOG_H
+#define CORE_LOG_H
+
+#include
+#include
+
+#include "util/defs.h"
+
+/**
+ * The core log API of bemanitools.
+ *
+ * To a large extent, this reflects the AVS logging API and allows for swapping
+ * out the backends with different implementations. Most games should have some
+ * version of the AVS API available while some (legacy) games do not. These
+ * can use a bemanitools private logging implementation by configuring it
+ * in the bootstrapping process.
+ */
+
+/* BUILD_MODULE is passed in as a command-line #define by the makefile */
+
+#ifndef LOG_MODULE
+#define LOG_MODULE STRINGIFY(BUILD_MODULE)
+#endif
+
+/**
+ * Log a message on misc level
+ *
+ * Always use this interface in your application which hides the currently
+ * configured implementation.
+ *
+ * The macro is required to make things work with varargs.
+ * The log message is only printed if the log level is set to misc
+ *
+ * @param fmt printf format string
+ * @param ... Additional arguments according to the specified arguments in the
+ * printf format string
+ */
+#define log_misc(...) _core_log_misc_impl(LOG_MODULE, __VA_ARGS__)
+
+/**
+ * Log a message on info level
+ *
+ * Always use this interface in your application which hides the currently
+ * configured implementation.
+ *
+ * The macro is required to make things work with varargs.
+ * The log message is only printed if the log level is set to info or lower
+ *
+ * @param fmt printf format string
+ * @param ... Additional arguments according to the specified arguments in the
+ * printf format string
+ */
+#define log_info(...) _core_log_info_impl(LOG_MODULE, __VA_ARGS__)
+
+/**
+ * Log a message on warning level
+ *
+ * Always use this interface in your application which hides the currently
+ * configured implementation.
+ *
+ * The macro is required to make things work with varargs.
+ * The log message is only printed if the log level is set to warning or lower
+ *
+ * @param fmt printf format string
+ * @param ... Additional arguments according to the specified arguments in the
+ * printf format string
+ */
+#define log_warning(...) _core_log_warning_impl(LOG_MODULE, __VA_ARGS__)
+
+/**
+ * Log a message on fatal level
+ *
+ * Always use this interface in your application which hides the currently
+ * configured implementation.
+ *
+ * The macro is required to make things work with varargs.
+ * The log message is only printed if the log level is set to fatal.
+ *
+ * This call will also terminate the application.
+ *
+ * @param fmt printf format string
+ * @param ... Additional arguments according to the specified arguments in the
+ * printf format string
+ */
+#define log_fatal(...) \
+ do { \
+ _core_log_fatal_impl(LOG_MODULE, __VA_ARGS__); \
+ abort(); \
+ } while (0)
+
+/**
+ * Log a message and terminate the application if given condition fails
+ *
+ * Always use this interface in your application which hides the currently
+ * configured implementation.
+ *
+ * The macro is required to make things work with varargs.
+ *
+ * @param x Condition to evaluate. If false, the application terminates
+ */
+#define log_assert(x) \
+ do { \
+ if (!(x)) { \
+ _core_log_fatal_impl( \
+ "assert", \
+ "%s:%d: function `%s'", \
+ __FILE__, \
+ __LINE__, \
+ __FUNCTION__); \
+ abort(); \
+ } \
+ } while (0)
+
+/**
+ * Log a message in an exception handler
+ *
+ * Only use this function in an exception handler, e.g. for stack traces. It
+ * logs the message on fatal level but does not terminate.
+ *
+ * @param fmt printf format string
+ * @param ... Additional arguments according to the specified arguments in the
+ * printf format string
+ */
+#define log_exception_handler(...) \
+ _core_log_fatal_impl("exception", __VA_ARGS__)
+
+typedef void (*core_log_message_t)(const char *module, const char *fmt, ...);
+
+typedef void (*core_log_impl_set_t)(
+ core_log_message_t misc,
+ core_log_message_t info,
+ core_log_message_t warning,
+ core_log_message_t fatal);
+
+/**
+ * Configure the log API implementations
+ *
+ * Advised to do this as early in your application/library module as possible
+ * as calls to the getter functions below will return the currently configured
+ * implementations.
+ *
+ * @param misc Pointer to a function implementing logging on misc level
+ * @param info Pointer to a function implementing logging on info level
+ * @param warning Pointer to a function implementing logging on warning level
+ * @param fatal Pointer to a function implementing logging on fatal level
+ */
+void core_log_impl_set(
+ core_log_message_t misc,
+ core_log_message_t info,
+ core_log_message_t warning,
+ core_log_message_t fatal);
+
+/**
+ * Supporting function to inject/assign the currently set implementation
+ * with the given setter function.
+ *
+ * @param impl_set Setter function to call with the currently configured log
+ * function implementations
+ */
+void core_log_impl_assign(core_log_impl_set_t impl_set);
+
+/**
+ * Get the currently configured implementation of the misc level log function
+ *
+ * @return Pointer to the currently configured implementation of the function
+ */
+core_log_message_t core_log_misc_impl_get();
+
+/**
+ * Get the currently configured implementation of the info level log function
+ *
+ * @return Pointer to the currently configured implementation of the function
+ */
+core_log_message_t core_log_info_impl_get();
+
+/**
+ * Get the currently configured implementation of the warning level log function
+ *
+ * @return Pointer to the currently configured implementation of the function
+ */
+core_log_message_t core_log_warning_impl_get();
+
+/**
+ * Get the currently configured implementation of the fatal level log function
+ *
+ * @return Pointer to the currently configured implementation of the function
+ */
+core_log_message_t core_log_fatal_impl_get();
+
+// Do not use these directly.
+// These are only here to allow usage in the macros above.
+extern core_log_message_t _core_log_misc_impl;
+extern core_log_message_t _core_log_info_impl;
+extern core_log_message_t _core_log_warning_impl;
+extern core_log_message_t _core_log_fatal_impl;
+
+#endif
\ No newline at end of file
diff --git a/src/main/core/thread-crt-ext.c b/src/main/core/thread-crt-ext.c
new file mode 100644
index 00000000..eb403ade
--- /dev/null
+++ b/src/main/core/thread-crt-ext.c
@@ -0,0 +1,8 @@
+#include "core/thread-crt.h"
+#include "core/thread.h"
+
+void core_thread_crt_ext_impl_set()
+{
+ core_thread_impl_set(
+ core_thread_crt_create, core_thread_crt_join, core_thread_crt_destroy);
+}
\ No newline at end of file
diff --git a/src/main/core/thread-crt-ext.h b/src/main/core/thread-crt-ext.h
new file mode 100644
index 00000000..a17b29b6
--- /dev/null
+++ b/src/main/core/thread-crt-ext.h
@@ -0,0 +1,9 @@
+#ifndef CORE_THREAD_CRT_EXT_H
+#define CORE_THREAD_CRT_EXT_H
+
+/**
+ * Set the current thread API implementation to use the C runtime thread API
+ */
+void core_thread_crt_ext_impl_set();
+
+#endif
\ No newline at end of file
diff --git a/src/main/util/thread.c b/src/main/core/thread-crt.c
similarity index 54%
rename from src/main/util/thread.c
rename to src/main/core/thread-crt.c
index daa82677..0251cf12 100644
--- a/src/main/util/thread.c
+++ b/src/main/core/thread-crt.c
@@ -4,8 +4,10 @@
#include
#include
+#include "core/thread-crt.h"
+#include "core/thread.h"
+
#include "util/defs.h"
-#include "util/thread.h"
struct shim_ctx {
HANDLE barrier;
@@ -13,10 +15,6 @@ struct shim_ctx {
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;
@@ -31,7 +29,7 @@ static unsigned int STDCALL crt_thread_shim(void *outer_ctx)
return proc(inner_ctx);
}
-int crt_thread_create(
+int core_thread_crt_create(
int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority)
{
struct shim_ctx sctx;
@@ -49,12 +47,12 @@ int crt_thread_create(
return (int) thread_id;
}
-void crt_thread_destroy(int thread_id)
+void core_thread_crt_destroy(int thread_id)
{
CloseHandle((HANDLE) (uintptr_t) thread_id);
}
-void crt_thread_join(int thread_id, int *result)
+void core_thread_crt_join(int thread_id, int *result)
{
WaitForSingleObject((HANDLE) (uintptr_t) thread_id, INFINITE);
@@ -62,31 +60,3 @@ void crt_thread_join(int thread_id, int *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/core/thread-crt.h b/src/main/core/thread-crt.h
new file mode 100644
index 00000000..e9c1e8c0
--- /dev/null
+++ b/src/main/core/thread-crt.h
@@ -0,0 +1,15 @@
+#ifndef CORE_THREAD_CRT_H
+#define CORE_THREAD_CRT_H
+
+#include
+
+/**
+ * Thread API implementation using the C runtime API
+ */
+
+int core_thread_crt_create(
+ int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority);
+void core_thread_crt_join(int thread_id, int *result);
+void core_thread_crt_destroy(int thread_id);
+
+#endif
diff --git a/src/main/core/thread.c b/src/main/core/thread.c
new file mode 100644
index 00000000..f4e5bfeb
--- /dev/null
+++ b/src/main/core/thread.c
@@ -0,0 +1,78 @@
+#include
+
+#include "core/log.h"
+#include "core/thread.h"
+
+core_thread_create_t core_thread_create_impl;
+core_thread_join_t core_thread_join_impl;
+core_thread_destroy_t core_thread_destroy_impl;
+
+int core_thread_create(
+ int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority)
+{
+ log_assert(core_thread_create_impl);
+
+ return core_thread_create_impl(proc, ctx, stack_sz, priority);
+}
+
+void core_thread_join(int thread_id, int *result)
+{
+ log_assert(core_thread_join_impl);
+
+ core_thread_join_impl(thread_id, result);
+}
+
+void core_thread_destroy(int thread_id)
+{
+ log_assert(core_thread_destroy_impl);
+
+ core_thread_destroy_impl(thread_id);
+}
+
+void core_thread_impl_set(
+ core_thread_create_t create,
+ core_thread_join_t join,
+ core_thread_destroy_t destroy)
+{
+ if (create == NULL || join == NULL || destroy == NULL) {
+ abort();
+ }
+
+ core_thread_create_impl = create;
+ core_thread_join_impl = join;
+ core_thread_destroy_impl = destroy;
+}
+
+void core_thread_impl_assign(core_thread_impl_set_t impl_set)
+{
+ if (core_thread_create_impl == NULL || core_thread_join_impl == NULL ||
+ core_thread_destroy_impl == NULL) {
+ abort();
+ }
+
+ impl_set(
+ core_thread_create_impl,
+ core_thread_join_impl,
+ core_thread_destroy_impl);
+}
+
+core_thread_create_t core_thread_create_impl_get()
+{
+ log_assert(core_thread_create_impl);
+
+ return core_thread_create_impl;
+}
+
+core_thread_join_t core_thread_join_impl_get()
+{
+ log_assert(core_thread_join_impl);
+
+ return core_thread_join_impl;
+}
+
+core_thread_destroy_t core_thread_destroy_impl_get()
+{
+ log_assert(core_thread_destroy_impl);
+
+ return core_thread_destroy_impl;
+}
diff --git a/src/main/core/thread.h b/src/main/core/thread.h
new file mode 100644
index 00000000..88115665
--- /dev/null
+++ b/src/main/core/thread.h
@@ -0,0 +1,117 @@
+#ifndef CORE_THREAD_H
+#define CORE_THREAD_H
+
+#include
+
+/**
+ * The core thread API of bemanitools.
+ *
+ * This essentially reflects the AVS threading API and allows for swapping out
+ * the backends with different implementations. Most games should have some
+ * version of the AVS API available while some (legacy) games do not. These
+ * can use a bemanitools private threading implementation by configuring it
+ * in the bootstrapping process.
+ */
+
+/**
+ * Create a thread
+ *
+ * Always use this interface in your application which hides the currently
+ * configured implementation.
+ *
+ * @param proc The function to run in a separate thread
+ * @param ctx Additional data to pass to the function as a parameter
+ * @param stack_sz The stack size to allocate for the thread in bytes
+ * @param priority The thread's priority
+ * @return The ID of the thread once created and started
+ */
+int core_thread_create(
+ int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority);
+
+/**
+ * Wait for a thread to finish
+ *
+ * Always use this interface in your application which hides the currently
+ * configured implementation.
+ *
+ * The caller of this function blocks until the thread has finished executing.
+ *
+ * @param thread_id ID of the thread to wait for
+ * @param result Pointer to a variable to write the return value of the function
+ * the thread executed to
+ */
+void core_thread_join(int thread_id, int *result);
+
+/**
+ * Destroy a thread
+ *
+ * Always use this interface in your application which hides the currently
+ * configured implementation.
+ *
+ * The thread must have finished execution before calling this. It is advised
+ * to make threads terminate their execution flow, join them and destroy.
+ *
+ * @param thread_id The ID of the thread to destroy.
+ */
+void core_thread_destroy(int thread_id);
+
+typedef int (*core_thread_create_t)(
+ int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority);
+typedef void (*core_thread_join_t)(int thread_id, int *result);
+typedef void (*core_thread_destroy_t)(int thread_id);
+
+typedef void (*core_thread_impl_set_t)(
+ core_thread_create_t create,
+ core_thread_join_t join,
+ core_thread_destroy_t destroy);
+
+/**
+ * Configure the thread API implementations
+ *
+ * Advised to do this as early in your application/library module as possible
+ * as calls to the getter functions below will return the currently configured
+ * implementations.
+ *
+ * @param create Pointer to a function implementing thread creation
+ * @param join Pointer to a function implementing joining of a thread
+ * @param destroy Pointer to a function implementing destroying of a thread
+ */
+void core_thread_impl_set(
+ core_thread_create_t create,
+ core_thread_join_t join,
+ core_thread_destroy_t destroy);
+
+/**
+ * Supporting function to inject/assign the currently set implementation
+ * with the given setter function.
+ *
+ * @param impl_set Setter function to call with the currently configured thread
+ * function implementations
+ */
+void core_thread_impl_assign(core_thread_impl_set_t impl_set);
+
+/**
+ * Get the currently configured implementation for thread_create
+ *
+ * @return Pointer to the currently configured implementation of the
+ * thread_create function
+ */
+core_thread_create_t core_thread_create_impl_get();
+
+/**
+ * Get the currently configured implementation for thread_join
+ *
+ * @return Pointer to the currently configured implementation of the thread_join
+ * function
+ */
+core_thread_join_t core_thread_join_impl_get();
+
+/**
+ * Get the currently configured implementation for thread_destroy
+ *
+ * @return Pointer to the currently configured implementation of the
+ * thread_destroy function
+ */
+core_thread_destroy_t core_thread_destroy_impl_get();
+
+#endif
diff --git a/src/main/d3d9exhook/config-gfx.c b/src/main/d3d9exhook/config-gfx.c
index 6cf57af0..b4a51973 100644
--- a/src/main/d3d9exhook/config-gfx.c
+++ b/src/main/d3d9exhook/config-gfx.c
@@ -4,9 +4,9 @@
#include "cconfig/cconfig-util.h"
-#include "d3d9exhook/config-gfx.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "d3d9exhook/config-gfx.h"
#define D3D9EXHOOK_CONFIG_GFX_FRAMED_KEY "gfx.framed"
#define D3D9EXHOOK_CONFIG_GFX_WINDOWED_KEY "gfx.windowed"
diff --git a/src/main/d3d9exhook/d3d9ex.c b/src/main/d3d9exhook/d3d9ex.c
index 88d95b00..80d958c3 100644
--- a/src/main/d3d9exhook/d3d9ex.c
+++ b/src/main/d3d9exhook/d3d9ex.c
@@ -9,13 +9,14 @@
#include
#include
+#include "core/log.h"
+
#include "hook/com-proxy.h"
#include "hook/table.h"
#include "d3d9exhook/d3d9ex.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
#include "util/time.h"
diff --git a/src/main/ddrhook-util/_com4.c b/src/main/ddrhook-util/_com4.c
index 44e01784..4ca08c37 100644
--- a/src/main/ddrhook-util/_com4.c
+++ b/src/main/ddrhook-util/_com4.c
@@ -19,6 +19,8 @@
#include "bemanitools/ddrio.h"
+#include "core/log.h"
+
#include "ddrhook-util/_com4.h"
#include "hook/iohook.h"
@@ -27,7 +29,6 @@
#include "util/defs.h"
#include "util/iobuf.h"
-#include "util/log.h"
static struct ac_io_emu com4_ac_io_emu;
static struct ac_io_emu_hdxs com4_hdxs;
diff --git a/src/main/ddrhook-util/dinput.c b/src/main/ddrhook-util/dinput.c
index b0fdc663..949fb1eb 100644
--- a/src/main/ddrhook-util/dinput.c
+++ b/src/main/ddrhook-util/dinput.c
@@ -5,12 +5,13 @@
#include
+#include "core/log.h"
+
#include "hook/com-proxy.h"
#include "hook/pe.h"
#include "hook/table.h"
#include "util/defs.h"
-#include "util/log.h"
static HRESULT STDCALL my_DirectInput8Create(
HINSTANCE hinst,
diff --git a/src/main/ddrhook-util/extio.c b/src/main/ddrhook-util/extio.c
index cd2dc84b..661b165f 100644
--- a/src/main/ddrhook-util/extio.c
+++ b/src/main/ddrhook-util/extio.c
@@ -14,10 +14,11 @@
#include "bemanitools/ddrio.h"
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "util/iobuf.h"
-#include "util/log.h"
#include "util/str.h"
static HRESULT extio_open(struct irp *irp);
diff --git a/src/main/ddrhook-util/gfx.c b/src/main/ddrhook-util/gfx.c
index 3f5f7736..0bfd0a5c 100644
--- a/src/main/ddrhook-util/gfx.c
+++ b/src/main/ddrhook-util/gfx.c
@@ -11,13 +11,14 @@
#include
#include
+#include "core/log.h"
+
#include "hook/com-proxy.h"
#include "hook/table.h"
#include "ddrhook-util/gfx.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
#include "util/time.h"
diff --git a/src/main/ddrhook-util/misc.c b/src/main/ddrhook-util/misc.c
index b74c8de6..e04390d1 100644
--- a/src/main/ddrhook-util/misc.c
+++ b/src/main/ddrhook-util/misc.c
@@ -2,13 +2,14 @@
#include
+#include "core/log.h"
+
#include "ddrhook-util/gfx.h"
#include "hook/pe.h"
#include "hook/table.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
static LRESULT(STDCALL *real_SendMessageW)(
diff --git a/src/main/ddrhook-util/monitor.c b/src/main/ddrhook-util/monitor.c
index 0dfce07f..cba18ccd 100644
--- a/src/main/ddrhook-util/monitor.c
+++ b/src/main/ddrhook-util/monitor.c
@@ -7,12 +7,13 @@
#include
#include
+#include "core/log.h"
+
#include "ddrhook-util/monitor.h"
#include "hook/table.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
/* Link pointers */
diff --git a/src/main/ddrhook-util/p3io.c b/src/main/ddrhook-util/p3io.c
index 09b8c6f5..af0f1a93 100644
--- a/src/main/ddrhook-util/p3io.c
+++ b/src/main/ddrhook-util/p3io.c
@@ -7,11 +7,11 @@
#include "ddrhook-util/p3io.h"
+#include "core/log.h"
+
#include "p3ioemu/emu.h"
#include "p3ioemu/uart.h"
-#include "util/log.h"
-
extern bool _15khz;
extern bool standard_def;
diff --git a/src/main/ddrhook-util/spike.c b/src/main/ddrhook-util/spike.c
index 0e383d20..37cf8887 100644
--- a/src/main/ddrhook-util/spike.c
+++ b/src/main/ddrhook-util/spike.c
@@ -15,10 +15,11 @@
#include "acioemu/addr.h"
#include "acioemu/emu.h"
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
static struct ac_io_emu spike_ac_io_emu;
diff --git a/src/main/ddrhook-util/usbmem.c b/src/main/ddrhook-util/usbmem.c
index f85363f3..c4e12c48 100644
--- a/src/main/ddrhook-util/usbmem.c
+++ b/src/main/ddrhook-util/usbmem.c
@@ -12,12 +12,13 @@
#include
#include
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "util/crc.h"
#include "util/fs.h"
#include "util/iobuf.h"
-#include "util/log.h"
#include "util/str.h"
#define USBMEM_DEVICE_COUNT 2
diff --git a/src/main/ddrhook1/Module.mk b/src/main/ddrhook1/Module.mk
index 83782ae8..1e9dc240 100644
--- a/src/main/ddrhook1/Module.mk
+++ b/src/main/ddrhook1/Module.mk
@@ -7,6 +7,8 @@ deplibs_ddrhook1 := \
avs \
libs_ddrhook1 := \
+ avs-util \
+ core \
acioemu \
cconfig \
ddrhook-util \
diff --git a/src/main/ddrhook1/avs-boot.c b/src/main/ddrhook1/avs-boot.c
index 1b7ad41a..db4445b4 100644
--- a/src/main/ddrhook1/avs-boot.c
+++ b/src/main/ddrhook1/avs-boot.c
@@ -5,6 +5,9 @@
#include
#include
+#include "core/log-bt.h"
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "hook/table.h"
@@ -13,7 +16,6 @@
#include "ddrhook1/avs-boot.h"
#include "ddrhook1/filesystem.h"
-#include "util/log.h"
#include "util/str.h"
static void (*real_avs_boot)(
@@ -50,6 +52,11 @@ static const struct hook_symbol ddrhook1_avs_ea3_hook_syms[] = {
.link = (void **) &real_ea3_boot},
};
+static AVS_LOG_WRITER(_avs_boot_log_writer, chars, nchars, ctx)
+{
+ core_log_bt_direct_sink_write(chars, nchars);
+}
+
static void avs_boot_replace_property_str(
struct property_node *node, const char *name, const char *val)
{
@@ -115,7 +122,7 @@ static void my_avs_boot(
sz_std_heap,
avs_heap,
sz_avs_heap,
- log_writer_debug,
+ _avs_boot_log_writer,
NULL);
}
diff --git a/src/main/ddrhook1/config-ddrhook1.c b/src/main/ddrhook1/config-ddrhook1.c
index 154f3ae3..a5872bf9 100644
--- a/src/main/ddrhook1/config-ddrhook1.c
+++ b/src/main/ddrhook1/config-ddrhook1.c
@@ -2,9 +2,9 @@
#include "cconfig/cconfig-util.h"
-#include "ddrhook1/config-ddrhook1.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "ddrhook1/config-ddrhook1.h"
#define DDRHOOK1_CONFIG_DDRHOOK1_USE_COM4_EMU_KEY "ddrhook1.use_com4_emu"
#define DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY "ddrhook1.standard_def"
diff --git a/src/main/ddrhook1/config-eamuse.c b/src/main/ddrhook1/config-eamuse.c
index 260791d3..dbe44cde 100644
--- a/src/main/ddrhook1/config-eamuse.c
+++ b/src/main/ddrhook1/config-eamuse.c
@@ -2,9 +2,10 @@
#include "cconfig/cconfig-util.h"
+#include "core/log.h"
+
#include "ddrhook1/config-eamuse.h"
-#include "util/log.h"
#include "util/net.h"
#define DDRHOOK1_CONFIG_EAMUSE_SERVER_KEY "eamuse.server"
diff --git a/src/main/ddrhook1/config-gfx.c b/src/main/ddrhook1/config-gfx.c
index 09ccc0c6..c71e74df 100644
--- a/src/main/ddrhook1/config-gfx.c
+++ b/src/main/ddrhook1/config-gfx.c
@@ -2,9 +2,9 @@
#include "cconfig/cconfig-util.h"
-#include "ddrhook1/config-gfx.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "ddrhook1/config-gfx.h"
#define DDRHOOK1_CONFIG_GFX_WINDOWED_KEY "gfx.windowed"
diff --git a/src/main/ddrhook1/config-security.c b/src/main/ddrhook1/config-security.c
index 9489b0a6..b0b7d2b2 100644
--- a/src/main/ddrhook1/config-security.c
+++ b/src/main/ddrhook1/config-security.c
@@ -2,11 +2,12 @@
#include "cconfig/cconfig-util.h"
+#include "core/log.h"
+
#include "ddrhook1/config-security.h"
#include "security/mcode.h"
-#include "util/log.h"
#include "util/net.h"
#define DDRHOOK1_CONFIG_SECURITY_MCODE_KEY "security.mcode"
diff --git a/src/main/ddrhook1/dllmain.c b/src/main/ddrhook1/dllmain.c
index 3dcc6c94..3cccb3a7 100644
--- a/src/main/ddrhook1/dllmain.c
+++ b/src/main/ddrhook1/dllmain.c
@@ -2,11 +2,20 @@
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/ddrio.h"
#include "bemanitools/eamio.h"
#include "cconfig/cconfig-hook.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log-sink-debug.h"
+#include "core/log.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
+
#include "ddrhook-util/_com4.h"
#include "ddrhook-util/extio.h"
#include "ddrhook-util/p3io.h"
@@ -37,8 +46,6 @@
#include "util/cmdline.h"
#include "util/defs.h"
-#include "util/log.h"
-#include "util/thread.h"
#define DDRHOOK1_INFO_HEADER \
"ddrhook1 for DDR X" \
@@ -68,6 +75,15 @@ static const struct hook_symbol init_hook_syms[] = {
},
};
+static void _ddrhook1_log_init()
+{
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_debug();
+
+ // TODO change log level support
+ core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC);
+}
+
static DWORD STDCALL
my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
{
@@ -155,7 +171,12 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
log_info("Initializing DDR IO backend");
- ok = ddr_io_init(thread_create, thread_join, thread_destroy);
+ core_log_impl_assign(ddr_io_set_loggers);
+
+ ok = ddr_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
if (!ok) {
log_fatal("Couldn't initialize DDR IO backend");
@@ -165,10 +186,12 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
if (config_ddrhook1.use_com4_emu) {
log_info("Initializing card reader backend");
- eam_io_set_loggers(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
- ok = eam_io_init(thread_create, thread_join, thread_destroy);
+ ok = eam_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
if (!ok) {
log_fatal("Couldn't initialize card reader backend");
@@ -185,7 +208,12 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx)
{
if (reason == DLL_PROCESS_ATTACH) {
- log_to_writer(log_writer_debug, NULL);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+
+ // TODO init debug logging but with avs available? why not use avs
+ // logging?
+ _ddrhook1_log_init();
hook_table_apply(
NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms));
diff --git a/src/main/ddrhook1/filesystem.c b/src/main/ddrhook1/filesystem.c
index abec921e..9912c4f9 100644
--- a/src/main/ddrhook1/filesystem.c
+++ b/src/main/ddrhook1/filesystem.c
@@ -6,10 +6,11 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/str.h"
diff --git a/src/main/ddrhook1/master.c b/src/main/ddrhook1/master.c
index b30836a5..480d56f7 100644
--- a/src/main/ddrhook1/master.c
+++ b/src/main/ddrhook1/master.c
@@ -1,3 +1,5 @@
+#include "core/log.h"
+
#include "ddrhook1/master.h"
#include "ddrhook-util/dinput.h"
@@ -9,7 +11,6 @@
#include "p3ioemu/devmgr.h"
#include "util/defs.h"
-#include "util/log.h"
static HMODULE(STDCALL *real_LoadLibraryA)(const char *name);
static BOOL(STDCALL *real_IsDebuggerPresent)();
diff --git a/src/main/ddrhook2/Module.mk b/src/main/ddrhook2/Module.mk
index 0c9fd365..e0416d66 100644
--- a/src/main/ddrhook2/Module.mk
+++ b/src/main/ddrhook2/Module.mk
@@ -4,6 +4,8 @@ deplibs_ddrhook2 := \
avs \
libs_ddrhook2 := \
+ avs-util \
+ core \
acioemu \
ddrhook-util \
p3ioemu \
diff --git a/src/main/ddrhook2/dllmain.c b/src/main/ddrhook2/dllmain.c
index 90355519..cabbb941 100644
--- a/src/main/ddrhook2/dllmain.c
+++ b/src/main/ddrhook2/dllmain.c
@@ -2,9 +2,14 @@
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/ddrio.h"
#include "bemanitools/eamio.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "ddrhook-util/_com4.h"
#include "ddrhook-util/extio.h"
#include "ddrhook-util/gfx.h"
@@ -25,7 +30,6 @@
#include "util/cmdline.h"
#include "util/defs.h"
-#include "util/log.h"
static bool my_dll_entry_init(char *sidcode, struct property_node *param);
static bool my_dll_entry_main(void);
@@ -119,10 +123,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
log_info("Initializing DDR IO backend");
- ddr_io_set_loggers(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ core_log_impl_assign(ddr_io_set_loggers);
- ok = ddr_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
+ ok = ddr_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
if (!ok) {
return false;
@@ -131,11 +137,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (com4) {
log_info("Initializing card reader backend");
- eam_io_set_loggers(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
- ok =
- eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
+ ok = eam_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
if (!ok) {
return false;
@@ -174,8 +181,9 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx)
goto end;
}
- log_to_external(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+ avs_util_core_interop_log_avs_impl_set();
app_hook_init(my_dll_entry_init, my_dll_entry_main);
diff --git a/src/main/ddrhook2/master.c b/src/main/ddrhook2/master.c
index 89f874ff..aba5451d 100644
--- a/src/main/ddrhook2/master.c
+++ b/src/main/ddrhook2/master.c
@@ -1,3 +1,5 @@
+#include "core/log.h"
+
#include "ddrhook2/master.h"
#include "ddrhook-util/dinput.h"
@@ -10,7 +12,6 @@
#include "p3ioemu/devmgr.h"
#include "util/defs.h"
-#include "util/log.h"
static HMODULE(STDCALL *real_LoadLibraryA)(const char *name);
diff --git a/src/main/ddrio-async/Module.mk b/src/main/ddrio-async/Module.mk
index 62006cfe..2eb806dd 100644
--- a/src/main/ddrio-async/Module.mk
+++ b/src/main/ddrio-async/Module.mk
@@ -3,6 +3,7 @@ dlls += ddrio-async
ldflags_ddrio-async:= \
libs_ddrio-async := \
+ core \
util \
src_ddrio-async := \
diff --git a/src/main/ddrio-async/ddrio.c b/src/main/ddrio-async/ddrio.c
index fe81f68e..998c59a5 100644
--- a/src/main/ddrio-async/ddrio.c
+++ b/src/main/ddrio-async/ddrio.c
@@ -11,8 +11,9 @@
#include "bemanitools/ddrio.h"
-#include "util/log.h"
-#include "util/thread.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "util/time.h"
typedef void (*ddr_io_set_loggers_t)(
@@ -154,7 +155,7 @@ void ddr_io_set_loggers(
_log_formatter_warning = warning;
_log_formatter_fatal = fatal;
- log_to_external(misc, info, warning, fatal);
+ core_log_impl_set(misc, info, warning, fatal);
}
bool ddr_io_init(
@@ -164,6 +165,8 @@ bool ddr_io_init(
{
log_info("Loading ddrio-async-child.dll as child ddrio library...");
+ core_thread_impl_set(thread_create, thread_join, thread_destroy);
+
_child_ddr_io_module = LoadLibraryA("ddrio-async-child.dll");
if (_child_ddr_io_module == NULL) {
diff --git a/src/main/ddrio-mm/Module.mk b/src/main/ddrio-mm/Module.mk
index 9368a623..16e3ca87 100644
--- a/src/main/ddrio-mm/Module.mk
+++ b/src/main/ddrio-mm/Module.mk
@@ -5,6 +5,7 @@ ldflags_ddrio-mm:= \
-lsetupapi \
libs_ddrio-mm := \
+ core \
mm \
util \
diff --git a/src/main/ddrio-mm/ddrio.c b/src/main/ddrio-mm/ddrio.c
index 08bd1d29..44bdd352 100644
--- a/src/main/ddrio-mm/ddrio.c
+++ b/src/main/ddrio-mm/ddrio.c
@@ -7,11 +7,12 @@
#include "bemanitools/ddrio.h"
+#include "core/log.h"
+
#include "mm/mm.h"
#include "util/cmdline.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
struct ddr_bittrans {
@@ -117,7 +118,7 @@ void ddr_io_set_loggers(
log_formatter_t warning,
log_formatter_t fatal)
{
- log_to_external(misc, info, warning, fatal);
+ core_log_impl_set(misc, info, warning, fatal);
}
bool ddr_io_init(
diff --git a/src/main/ddrio-p3io/Module.mk b/src/main/ddrio-p3io/Module.mk
index 43e0fd06..2824bf0e 100644
--- a/src/main/ddrio-p3io/Module.mk
+++ b/src/main/ddrio-p3io/Module.mk
@@ -4,6 +4,7 @@ ldflags_ddrio-p3io:= \
-lsetupapi \
libs_ddrio-p3io := \
+ core \
cconfig \
extio \
extiodrv \
diff --git a/src/main/ddrio-p3io/config.c b/src/main/ddrio-p3io/config.c
index c45254e1..54591575 100644
--- a/src/main/ddrio-p3io/config.c
+++ b/src/main/ddrio-p3io/config.c
@@ -1,6 +1,6 @@
#include "cconfig/cconfig-util.h"
-#include "util/log.h"
+#include "core/log.h"
#include "config.h"
diff --git a/src/main/ddrio-p3io/ddrio.c b/src/main/ddrio-p3io/ddrio.c
index a38ce09d..6ed7e90c 100644
--- a/src/main/ddrio-p3io/ddrio.c
+++ b/src/main/ddrio-p3io/ddrio.c
@@ -10,15 +10,15 @@
#include "cconfig/cconfig-main.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "extiodrv/device.h"
#include "extiodrv/extio.h"
#include "p3iodrv/ddr.h"
#include "p3iodrv/device.h"
-#include "util/log.h"
-#include "util/thread.h"
-
#include "config.h"
static struct ddrio_p3io_config _ddr_io_p3io_config;
@@ -255,7 +255,7 @@ void ddr_io_set_loggers(
log_formatter_t warning,
log_formatter_t fatal)
{
- log_to_external(misc, info, warning, fatal);
+ core_log_impl_set(misc, info, warning, fatal);
}
static void _ddr_io_config_init(struct ddrio_p3io_config *config_ddrio_p3io)
diff --git a/src/main/ddrio-smx/Module.mk b/src/main/ddrio-smx/Module.mk
index cc0563b2..12fd74de 100644
--- a/src/main/ddrio-smx/Module.mk
+++ b/src/main/ddrio-smx/Module.mk
@@ -5,6 +5,7 @@ deplibs_ddrio-smx := \
SMX \
libs_ddrio-smx := \
+ core \
geninput \
util \
diff --git a/src/main/ddrio-smx/ddrio.c b/src/main/ddrio-smx/ddrio.c
index a7cda337..334ccaca 100644
--- a/src/main/ddrio-smx/ddrio.c
+++ b/src/main/ddrio-smx/ddrio.c
@@ -6,11 +6,12 @@
#include "bemanitools/ddrio.h"
#include "bemanitools/input.h"
+#include "core/log.h"
+
#include "imports/SMX.h"
#include "imports/avs.h"
#include "util/defs.h"
-#include "util/log.h"
struct ddr_io_smx_pad_map {
int pad_no;
@@ -99,7 +100,7 @@ void ddr_io_set_loggers(
log_formatter_t warning,
log_formatter_t fatal)
{
- log_to_external(misc, info, warning, fatal);
+ core_log_impl_set(misc, info, warning, fatal);
input_set_loggers(misc, info, warning, fatal);
/* We would need a log server thread to accept log messages from SMX, since
diff --git a/src/main/ddrio/ddrio.c b/src/main/ddrio/ddrio.c
index 167b7c6e..5da99348 100644
--- a/src/main/ddrio/ddrio.c
+++ b/src/main/ddrio/ddrio.c
@@ -4,7 +4,7 @@
#include "bemanitools/input.h"
-#include "util/log.h"
+#include "core/log.h"
void ddr_io_set_loggers(
log_formatter_t misc,
diff --git a/src/main/ddriotest/Module.mk b/src/main/ddriotest/Module.mk
index 569d9736..b6cba5cb 100644
--- a/src/main/ddriotest/Module.mk
+++ b/src/main/ddriotest/Module.mk
@@ -1,6 +1,7 @@
exes += ddriotest \
libs_ddriotest := \
+ core \
ddrio \
util \
diff --git a/src/main/ddriotest/main.c b/src/main/ddriotest/main.c
index e03bc0c4..40453ce0 100644
--- a/src/main/ddriotest/main.c
+++ b/src/main/ddriotest/main.c
@@ -7,32 +7,41 @@
#include "bemanitools/ddrio.h"
-#include "util/log.h"
-#include "util/thread.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log.h"
+#include "core/thread-crt-ext.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
int main(int argc, char **argv)
{
- enum log_level log_level;
+ enum core_log_bt_log_level log_level;
- log_level = LOG_LEVEL_FATAL;
+ log_level = CORE_LOG_BT_LOG_LEVEL_FATAL;
for (int i = 0; i < argc; i++) {
if (!strcmp(argv[i], "-v")) {
- log_level = LOG_LEVEL_WARNING;
+ log_level = CORE_LOG_BT_LOG_LEVEL_WARNING;
} else if (!strcmp(argv[i], "-vv")) {
- log_level = LOG_LEVEL_INFO;
+ log_level = CORE_LOG_BT_LOG_LEVEL_INFO;
} else if (!strcmp(argv[i], "-vvv")) {
- log_level = LOG_LEVEL_MISC;
+ log_level = CORE_LOG_BT_LOG_LEVEL_MISC;
}
}
- log_to_writer(log_writer_stderr, NULL);
- log_set_level(log_level);
+ core_thread_crt_ext_impl_set();
+ core_log_bt_ext_impl_set();
- ddr_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_bt_ext_init_with_stderr();
+ core_log_bt_level_set(log_level);
- if (!ddr_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) {
+ core_log_impl_assign(ddr_io_set_loggers);
+
+ if (!ddr_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
fprintf(stderr, "Initializing ddrio failed\n");
return -1;
}
diff --git a/src/main/dinput/dinput.c b/src/main/dinput/dinput.c
index 248ead4a..e65928f7 100644
--- a/src/main/dinput/dinput.c
+++ b/src/main/dinput/dinput.c
@@ -8,12 +8,13 @@
#include
+#include "core/log.h"
+
#include "hook/com-proxy.h"
#include "hook/pe.h"
#include "hook/table.h"
#include "util/defs.h"
-#include "util/log.h"
static HRESULT STDCALL my_DirectInput8Create(
HINSTANCE hinst,
diff --git a/src/main/eamio-icca/Module.mk b/src/main/eamio-icca/Module.mk
index 28c388e5..bcd4be83 100644
--- a/src/main/eamio-icca/Module.mk
+++ b/src/main/eamio-icca/Module.mk
@@ -2,6 +2,7 @@ dlls += \
eamio-icca \
libs_eamio-icca := \
+ core \
aciodrv \
aciomgr \
cconfig \
diff --git a/src/main/eamio-icca/config-icc.c b/src/main/eamio-icca/config-icc.c
index 660c0ee1..963f6882 100644
--- a/src/main/eamio-icca/config-icc.c
+++ b/src/main/eamio-icca/config-icc.c
@@ -2,8 +2,6 @@
#include "eamio-icca/config-icc.h"
-#include "util/log.h"
-
#define EAMIO_ICCA_CONFIG_ICC_PORT_KEY "icc.port"
#define EAMIO_ICCA_CONFIG_ICC_BAUD_KEY "icc.baud"
diff --git a/src/main/eamio-icca/eamio-icca.c b/src/main/eamio-icca/eamio-icca.c
index c681610e..db0215a9 100644
--- a/src/main/eamio-icca/eamio-icca.c
+++ b/src/main/eamio-icca/eamio-icca.c
@@ -14,11 +14,11 @@
#include "bemanitools/eamio.h"
+#include "core/log.h"
+
#include "cconfig/cconfig-main.h"
#include "eamio-icca/config-icc.h"
-#include "util/log.h"
-
#define IDLE_RESPONSES_BETWEEN_FELICA_POLLS 5
#define NUMBER_OF_EMULATED_READERS 2
#define INVALID_NODE_ID -1
@@ -60,7 +60,7 @@ void eam_io_set_loggers(
{
aciomgr_set_loggers(misc, info, warning, fatal);
- log_to_external(misc, info, warning, fatal);
+ core_log_impl_set(misc, info, warning, fatal);
}
// all of these are referred to internally as ICCA
diff --git a/src/main/eamio/Module.mk b/src/main/eamio/Module.mk
index f7a7409c..9cf82ed3 100644
--- a/src/main/eamio/Module.mk
+++ b/src/main/eamio/Module.mk
@@ -1,5 +1,5 @@
dlls += eamio
-libs_eamio := geninput util
+libs_eamio := core geninput util
src_eamio := \
eam-api.c \
eam-impl.c \
diff --git a/src/main/eamio/eam-api.c b/src/main/eamio/eam-api.c
index 03203173..9d2857d9 100644
--- a/src/main/eamio/eam-api.c
+++ b/src/main/eamio/eam-api.c
@@ -11,14 +11,15 @@
#include "bemanitools/eamio.h"
#include "bemanitools/input.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "eamio/eam-config.h"
#include "eamio/eam-impl.h"
#include "eamio/eam-s11n.h"
#include "util/fs.h"
-#include "util/log.h"
#include "util/msg-thread.h"
-#include "util/thread.h"
static void eam_handle_hotplug_msg(WPARAM wparam, const DEV_BROADCAST_HDR *hdr);
static FILE *eam_io_config_open(const char *mode);
@@ -108,14 +109,14 @@ void eam_io_set_loggers(
log_formatter_t warning,
log_formatter_t fatal)
{
- log_to_external(misc, info, warning, fatal);
+ core_log_impl_set(misc, info, warning, fatal);
}
bool eam_io_init(
thread_create_t create, thread_join_t join, thread_destroy_t destroy)
{
input_init(create, join, destroy);
- thread_api_init(create, join, destroy);
+ core_thread_impl_set(create, join, destroy);
eam_io_config_load();
msg_thread_init(eam_hinst);
diff --git a/src/main/eamio/eam-impl.c b/src/main/eamio/eam-impl.c
index 0c417094..6aca5898 100644
--- a/src/main/eamio/eam-impl.c
+++ b/src/main/eamio/eam-impl.c
@@ -9,6 +9,8 @@
#include "bemanitools/eamio.h"
+#include "core/log.h"
+
#include "eamio/eam-impl.h"
#include "geninput/hid-mgr.h"
@@ -16,7 +18,6 @@
#include "util/defs.h"
#include "util/fs.h"
#include "util/hex.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/str.h"
diff --git a/src/main/eamiotest/Module.mk b/src/main/eamiotest/Module.mk
index a54384b7..0b9fd4b9 100644
--- a/src/main/eamiotest/Module.mk
+++ b/src/main/eamiotest/Module.mk
@@ -1,6 +1,7 @@
exes += eamiotest
libs_eamiotest := \
+ core \
eamio \
util \
diff --git a/src/main/eamiotest/main.c b/src/main/eamiotest/main.c
index 9880af4a..a2f410f4 100644
--- a/src/main/eamiotest/main.c
+++ b/src/main/eamiotest/main.c
@@ -7,20 +7,29 @@
#include "bemanitools/eamio.h"
-#include "util/log.h"
-#include "util/thread.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log.h"
+#include "core/thread-crt-ext.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
/**
* Tool to test your implementations of eamio.
*/
int main(int argc, char **argv)
{
- log_to_writer(log_writer_stdout, NULL);
+ core_thread_crt_ext_impl_set();
+ core_log_bt_ext_impl_set();
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_bt_ext_init_with_stdout();
- if (!eam_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) {
+ core_log_impl_assign(eam_io_set_loggers);
+
+ if (!eam_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
printf("Initializing eamio failed\n");
return -1;
}
diff --git a/src/main/extiodrv/device.c b/src/main/extiodrv/device.c
index ba14fa7f..e6bc788f 100644
--- a/src/main/extiodrv/device.c
+++ b/src/main/extiodrv/device.c
@@ -2,7 +2,7 @@
#include "device.h"
-#include "util/log.h"
+#include "core/log.h"
HRESULT extiodrv_device_open(const char *port, HANDLE *handle)
{
diff --git a/src/main/extiodrv/extio.c b/src/main/extiodrv/extio.c
index 8c50de2f..5b1ae6a4 100644
--- a/src/main/extiodrv/extio.c
+++ b/src/main/extiodrv/extio.c
@@ -2,7 +2,7 @@
#include "extio.h"
-#include "util/log.h"
+#include "core/log.h"
// static uint8_t _extiodrv_extio_sensor_read_mode_map[5] = {
// 1, // all
diff --git a/src/main/extiotest/Module.mk b/src/main/extiotest/Module.mk
index 73ec1b07..3e05ba08 100644
--- a/src/main/extiotest/Module.mk
+++ b/src/main/extiotest/Module.mk
@@ -3,6 +3,7 @@ exes += extiotest \
libs_extiotest := \
extiodrv \
extio \
+ core \
util \
src_extiotest := \
diff --git a/src/main/extiotest/main.c b/src/main/extiotest/main.c
index 3be152b1..c9e48bab 100644
--- a/src/main/extiotest/main.c
+++ b/src/main/extiotest/main.c
@@ -5,12 +5,15 @@
#include
-#include "extiodrv/extio.h"
+#include "core/log-bt.h"
+#include "core/log-sink-std.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "extiodrv/extio.h"
int main(int argc, char **argv)
{
+ struct core_log_sink log_sink;
HRESULT hr;
const char *port;
HANDLE handle;
@@ -22,8 +25,9 @@ int main(int argc, char **argv)
fprintf(stderr, " COM_PORT: For example COM1\n");
}
- log_to_writer(log_writer_stderr, NULL);
- log_set_level(LOG_LEVEL_MISC);
+ core_log_sink_std_err_open(true, &log_sink);
+ core_log_bt_init(&log_sink);
+ core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC);
port = argv[1];
diff --git a/src/main/ezusb-emu/device.c b/src/main/ezusb-emu/device.c
index 9f1eca82..9cf5c98d 100644
--- a/src/main/ezusb-emu/device.c
+++ b/src/main/ezusb-emu/device.c
@@ -9,6 +9,8 @@
#include
+#include "core/log.h"
+
#include "ezusb/ezusbsys2.h"
#include "ezusb/util.h"
@@ -25,7 +27,6 @@
#include "util/fs.h"
#include "util/hex.h"
#include "util/iobuf.h"
-#include "util/log.h"
#include "util/str.h"
// The max buffer size in iidx's ezusb client library is 4096 for the initial
diff --git a/src/main/ezusb-emu/node-coin.c b/src/main/ezusb-emu/node-coin.c
index 87e75037..6b4aed19 100644
--- a/src/main/ezusb-emu/node-coin.c
+++ b/src/main/ezusb-emu/node-coin.c
@@ -1,11 +1,11 @@
#define LOG_MODULE "ezusb-emu-node-coin"
+#include "core/log.h"
+
#include "ezusb-emu/node-coin.h"
#include "ezusb-iidx/coin-cmd.h"
-#include "util/log.h"
-
static uint8_t ezusb_iidx_emu_node_coin_mode = 0;
uint8_t ezusb_iidx_emu_node_coin_process_cmd(
diff --git a/src/main/ezusb-emu/node-eeprom.c b/src/main/ezusb-emu/node-eeprom.c
index ea6a3fea..f63d866f 100644
--- a/src/main/ezusb-emu/node-eeprom.c
+++ b/src/main/ezusb-emu/node-eeprom.c
@@ -2,12 +2,12 @@
#include
+#include "core/log.h"
+
#include "ezusb-emu/node-eeprom.h"
#include "ezusb-iidx/eeprom-cmd.h"
-#include "util/log.h"
-
/* not verified, but we got calls with 3 pages only so far */
#define EEPROM_NPAGES 3
diff --git a/src/main/ezusb-emu/node-security-mem.c b/src/main/ezusb-emu/node-security-mem.c
index 92422c82..8d11c5ff 100644
--- a/src/main/ezusb-emu/node-security-mem.c
+++ b/src/main/ezusb-emu/node-security-mem.c
@@ -2,11 +2,11 @@
#include
+#include "core/log.h"
+
#include "ezusb-emu/node-security-mem.h"
#include "ezusb-iidx/secmem-cmd.h"
-#include "util/log.h"
-
#define SECURITY2_NPAGES 5
/* Starting GOLD with the new IO2 (C02 is not affected), the game does not
diff --git a/src/main/ezusb-emu/node-security-plug.c b/src/main/ezusb-emu/node-security-plug.c
index 2b05a03a..ed57eed8 100644
--- a/src/main/ezusb-emu/node-security-plug.c
+++ b/src/main/ezusb-emu/node-security-plug.c
@@ -2,6 +2,8 @@
#include
+#include "core/log.h"
+
#include "ezusb-emu/node-eeprom.h"
#include "ezusb-emu/node-security-mem.h"
#include "ezusb-emu/node-security-plug.h"
@@ -11,8 +13,6 @@
#include "security/rp2.h"
#include "security/util.h"
-#include "util/log.h"
-
static struct security_mcode ezusb_iidx_emu_node_security_plug_boot_version;
static uint32_t ezusb_iidx_emu_node_security_plug_boot_seeds[3];
diff --git a/src/main/ezusb-emu/node-sram.c b/src/main/ezusb-emu/node-sram.c
index 200f1caf..dc3846b4 100644
--- a/src/main/ezusb-emu/node-sram.c
+++ b/src/main/ezusb-emu/node-sram.c
@@ -2,12 +2,13 @@
#include
+#include "core/log.h"
+
#include "ezusb-emu/conf.h"
#include "ezusb-emu/node-sram.h"
#include "ezusb-iidx/sram-cmd.h"
#include "util/fs.h"
-#include "util/log.h"
#define SRAM_NPAGES 12
diff --git a/src/main/ezusb-emu/node-wdt.c b/src/main/ezusb-emu/node-wdt.c
index 9185bdde..8c5c5416 100644
--- a/src/main/ezusb-emu/node-wdt.c
+++ b/src/main/ezusb-emu/node-wdt.c
@@ -1,10 +1,10 @@
#define LOG_MODULE "ezusb-emu-node-wdt"
+#include "core/log.h"
+
#include "ezusb-emu/node-wdt.h"
#include "ezusb-iidx/wdt-cmd.h"
-#include "util/log.h"
-
uint8_t ezusb_iidx_emu_node_wdt_process_cmd(
uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2)
{
diff --git a/src/main/ezusb-emu/util.c b/src/main/ezusb-emu/util.c
index 6e2798ae..30edd425 100644
--- a/src/main/ezusb-emu/util.c
+++ b/src/main/ezusb-emu/util.c
@@ -6,10 +6,11 @@
#include
#include
+#include "core/log.h"
+
#include "ezusb-emu/util.h"
#include "util/hex.h"
-#include "util/log.h"
enum ezusb_pipe {
/* This is just the NT driver API. Add 1 to get the actual EP number. */
diff --git a/src/main/ezusb-iidx-16seg-emu/node-16seg.c b/src/main/ezusb-iidx-16seg-emu/node-16seg.c
index 89bc5070..2121235e 100644
--- a/src/main/ezusb-iidx-16seg-emu/node-16seg.c
+++ b/src/main/ezusb-iidx-16seg-emu/node-16seg.c
@@ -6,9 +6,9 @@
#include "bemanitools/iidxio.h"
-#include "ezusb-iidx/seg16-cmd.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "ezusb-iidx/seg16-cmd.h"
uint8_t ezusb_iidx_emu_node_16seg_process_cmd(
uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2)
diff --git a/src/main/ezusb-iidx-emu/Module.mk b/src/main/ezusb-iidx-emu/Module.mk
index d6253631..16f2c1dd 100644
--- a/src/main/ezusb-iidx-emu/Module.mk
+++ b/src/main/ezusb-iidx-emu/Module.mk
@@ -1,6 +1,7 @@
libs += ezusb-iidx-emu
libs_ezusb-iidx-emu := \
+ core \
ezusb-emu \
ezusb-iidx-16seg-emu \
diff --git a/src/main/ezusb-iidx-emu/card-mag.c b/src/main/ezusb-iidx-emu/card-mag.c
index a210fd69..b65414ea 100644
--- a/src/main/ezusb-iidx-emu/card-mag.c
+++ b/src/main/ezusb-iidx-emu/card-mag.c
@@ -2,10 +2,11 @@
#include
+#include "core/log.h"
+
#include "security/mcode.h"
#include "util/crc.h"
-#include "util/log.h"
static const uint16_t ezusb_iidx_emu_card_mag_checksum_table_payload[256] = {
0x0, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF,
diff --git a/src/main/ezusb-iidx-emu/msg.c b/src/main/ezusb-iidx-emu/msg.c
index bcab6566..76b97423 100644
--- a/src/main/ezusb-iidx-emu/msg.c
+++ b/src/main/ezusb-iidx-emu/msg.c
@@ -6,6 +6,8 @@
#include "bemanitools/iidxio.h"
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "ezusb-emu/msg.h"
@@ -21,7 +23,6 @@
#include "ezusb-iidx-16seg-emu/nodes.h"
#include "util/hex.h"
-#include "util/log.h"
/* ------------------------------------------------------------------------ */
diff --git a/src/main/ezusb-iidx-emu/node-fpga.c b/src/main/ezusb-iidx-emu/node-fpga.c
index d66c440c..6615b43f 100644
--- a/src/main/ezusb-iidx-emu/node-fpga.c
+++ b/src/main/ezusb-iidx-emu/node-fpga.c
@@ -2,12 +2,13 @@
#include
+#include "core/log.h"
+
#include "ezusb-iidx-emu/conf.h"
#include "ezusb-iidx-emu/node-fpga.h"
#include "ezusb-iidx/fpga-cmd.h"
#include "util/fs.h"
-#include "util/log.h"
static uint16_t ezusb_iidx_emu_node_fpga_write_ptr;
static uint16_t ezusb_iidx_emu_node_fpga_prog_size;
diff --git a/src/main/ezusb-iidx-emu/node-serial.c b/src/main/ezusb-iidx-emu/node-serial.c
index 378ab02f..7dc65193 100644
--- a/src/main/ezusb-iidx-emu/node-serial.c
+++ b/src/main/ezusb-iidx-emu/node-serial.c
@@ -4,6 +4,9 @@
#include "bemanitools/eamio.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "ezusb-iidx-emu/card-mag.c"
#include "ezusb-iidx-emu/node-serial.h"
#include "ezusb-iidx/serial-cmd.h"
@@ -11,9 +14,7 @@
#include "security/mcode.h"
#include "util/hex.h"
-#include "util/log.h"
#include "util/mem.h"
-#include "util/thread.h"
#define CARD_ID_LEN 8
@@ -292,7 +293,7 @@ void ezusb_iidx_emu_node_serial_init(void)
&ezusb_iidx_emu_node_serial_emulation_state[i].card_cs);
}
- ezusb_iidx_emu_node_serial_emu_thread = thread_create(
+ ezusb_iidx_emu_node_serial_emu_thread = core_thread_create(
ezusb_iidx_emu_node_serial_emu_thread_proc, NULL, 0x4000, 0);
}
diff --git a/src/main/ezusb-iidx-fpga-flash/Module.mk b/src/main/ezusb-iidx-fpga-flash/Module.mk
index c250b35b..320d6f49 100644
--- a/src/main/ezusb-iidx-fpga-flash/Module.mk
+++ b/src/main/ezusb-iidx-fpga-flash/Module.mk
@@ -4,6 +4,7 @@ ldflags_ezusb-iidx-fpga-flash := \
-lsetupapi \
libs_ezusb-iidx-fpga-flash := \
+ core \
ezusb \
ezusb-iidx \
util \
diff --git a/src/main/ezusb-iidx-fpga-flash/main.c b/src/main/ezusb-iidx-fpga-flash/main.c
index a8fb6816..f8dacdd3 100644
--- a/src/main/ezusb-iidx-fpga-flash/main.c
+++ b/src/main/ezusb-iidx-fpga-flash/main.c
@@ -3,11 +3,14 @@
#include
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log.h"
+
#include "ezusb-iidx/fpga.h"
#include "ezusb/ezusb.h"
#include "util/fs.h"
-#include "util/log.h"
int main(int argc, char **argv)
{
@@ -24,7 +27,8 @@ int main(int argc, char **argv)
return -1;
}
- log_to_writer(log_writer_stderr, NULL);
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_stderr();
log_info("Opening ezusb '%s'...", EZUSB_DEVICE_PATH);
diff --git a/src/main/ezusb-iidx-sram-flash/Module.mk b/src/main/ezusb-iidx-sram-flash/Module.mk
index b6e6a73d..a369b060 100644
--- a/src/main/ezusb-iidx-sram-flash/Module.mk
+++ b/src/main/ezusb-iidx-sram-flash/Module.mk
@@ -4,6 +4,7 @@ ldflags_ezusb-iidx-sram-flash := \
-lsetupapi \
libs_ezusb-iidx-sram-flash := \
+ core \
ezusb \
ezusb-iidx \
util \
diff --git a/src/main/ezusb-iidx-sram-flash/main.c b/src/main/ezusb-iidx-sram-flash/main.c
index d22464e0..b4fa94d3 100644
--- a/src/main/ezusb-iidx-sram-flash/main.c
+++ b/src/main/ezusb-iidx-sram-flash/main.c
@@ -3,11 +3,14 @@
#include
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log.h"
+
#include "ezusb-iidx/sram.h"
#include "ezusb/ezusb.h"
#include "util/fs.h"
-#include "util/log.h"
int main(int argc, char **argv)
{
@@ -24,7 +27,8 @@ int main(int argc, char **argv)
return -1;
}
- log_to_writer(log_writer_stdout, NULL);
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_stdout();
log_info("Opening ezusb '%s'...", argv[1]);
diff --git a/src/main/ezusb-iidx/ezusb-iidx.c b/src/main/ezusb-iidx/ezusb-iidx.c
index e82e2145..ae035b73 100644
--- a/src/main/ezusb-iidx/ezusb-iidx.c
+++ b/src/main/ezusb-iidx/ezusb-iidx.c
@@ -1,11 +1,12 @@
#define LOG_MODULE "ezusb-iidx"
+#include "core/log.h"
+
#include "ezusb-iidx/ezusb-iidx.h"
#include "ezusb/ezusbsys2.h"
#include "util/hex.h"
-#include "util/log.h"
#include "util/time.h"
#include "msg.h"
diff --git a/src/main/ezusb-iidx/fpga.c b/src/main/ezusb-iidx/fpga.c
index 23d5fd05..b4d25500 100644
--- a/src/main/ezusb-iidx/fpga.c
+++ b/src/main/ezusb-iidx/fpga.c
@@ -4,7 +4,7 @@
#include
-#include "util/log.h"
+#include "core/log.h"
#include "ezusb-iidx.h"
#include "fpga-cmd.h"
diff --git a/src/main/ezusb-iidx/sram.c b/src/main/ezusb-iidx/sram.c
index f816b383..fcce3840 100644
--- a/src/main/ezusb-iidx/sram.c
+++ b/src/main/ezusb-iidx/sram.c
@@ -1,8 +1,8 @@
#define LOG_MODULE "ezusb-iidx-sram"
-#include "ezusb-iidx/sram.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "ezusb-iidx/sram.h"
#include "ezusb-iidx.h"
#include "sram-cmd.h"
diff --git a/src/main/ezusb-tool/Module.mk b/src/main/ezusb-tool/Module.mk
index 349bc089..b5e81588 100644
--- a/src/main/ezusb-tool/Module.mk
+++ b/src/main/ezusb-tool/Module.mk
@@ -4,6 +4,7 @@ ldflags_ezusb-tool := \
-lsetupapi \
libs_ezusb-tool := \
+ core \
ezusb \
util \
diff --git a/src/main/ezusb-tool/main.c b/src/main/ezusb-tool/main.c
index 115f79c5..ca847815 100644
--- a/src/main/ezusb-tool/main.c
+++ b/src/main/ezusb-tool/main.c
@@ -3,11 +3,13 @@
#include
#include
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log.h"
+
#include "ezusb/ezusb.h"
#include "ezusb/util.h"
-#include "util/log.h"
-
static int info()
{
HANDLE handle;
@@ -103,7 +105,8 @@ int main(int argc, char **argv)
arg_pos = 1;
- log_to_writer(log_writer_stderr, NULL);
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_stderr();
if (!strcmp(argv[arg_pos], "info")) {
return info();
diff --git a/src/main/ezusb/ezusb.c b/src/main/ezusb/ezusb.c
index ce1b828e..7204589a 100644
--- a/src/main/ezusb/ezusb.c
+++ b/src/main/ezusb/ezusb.c
@@ -4,10 +4,11 @@
#include
// clang-format on
+#include "core/log.h"
+
#include "ezusb/ezusb.h"
#include "ezusb/ezusbsys2.h"
-#include "util/log.h"
#include "util/str.h"
static bool ezusb_reset(HANDLE handle, bool hold)
diff --git a/src/main/ezusb/util.c b/src/main/ezusb/util.c
index efc2cd10..5bf18a45 100644
--- a/src/main/ezusb/util.c
+++ b/src/main/ezusb/util.c
@@ -1,11 +1,12 @@
#include
#include
+#include "core/log.h"
+
#include "ezusb/util.h"
#include "util/crc.h"
#include "util/fs.h"
-#include "util/log.h"
#include "util/mem.h"
struct ezusb_firmware *ezusb_firmware_load(const char *file)
diff --git a/src/main/ezusb2-dbg-hook/Module.mk b/src/main/ezusb2-dbg-hook/Module.mk
index 4290f5cf..579e9bfb 100644
--- a/src/main/ezusb2-dbg-hook/Module.mk
+++ b/src/main/ezusb2-dbg-hook/Module.mk
@@ -1,6 +1,7 @@
dlls += ezusb2-dbg-hook
libs_ezusb2-dbg-hook := \
+ core \
hook \
util \
diff --git a/src/main/ezusb2-dbg-hook/main.c b/src/main/ezusb2-dbg-hook/main.c
index e90d3fb0..e1c1bdbb 100644
--- a/src/main/ezusb2-dbg-hook/main.c
+++ b/src/main/ezusb2-dbg-hook/main.c
@@ -10,13 +10,17 @@
#include
#include
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log-sink-file.h"
+#include "core/log.h"
+
#include "ezusb2/cyioctl.h"
#include "hook/table.h"
#include "util/cmdline.h"
#include "util/hex.h"
-#include "util/log.h"
#include "util/str.h"
static HANDLE STDCALL my_CreateFileW(
@@ -367,14 +371,13 @@ static void ezusb2_dbg_hook_terminate_process()
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
if (reason == DLL_PROCESS_ATTACH) {
- FILE *file;
int argc;
char **argv;
wchar_t *buffer;
uint32_t args_success;
- file = fopen("ezusb2_dbg.log", "w+");
- log_to_writer(log_writer_file, file);
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_file("ezusb2_dbg.log", false, false, 0);
hook_table_apply(
NULL,
diff --git a/src/main/ezusb2-emu/device.c b/src/main/ezusb2-emu/device.c
index f4652798..ecba8163 100644
--- a/src/main/ezusb2-emu/device.c
+++ b/src/main/ezusb2-emu/device.c
@@ -9,6 +9,8 @@
#include
+#include "core/log.h"
+
#include "ezusb/util.h"
#include "ezusb2/cyioctl.h"
@@ -27,7 +29,6 @@
#include "util/fs.h"
#include "util/hex.h"
#include "util/iobuf.h"
-#include "util/log.h"
#include "util/str.h"
// The max buffer size in iidx's ezusb client library is 4096 for the initial
diff --git a/src/main/ezusb2-emu/util.c b/src/main/ezusb2-emu/util.c
index 2abd5134..d5b12b92 100644
--- a/src/main/ezusb2-emu/util.c
+++ b/src/main/ezusb2-emu/util.c
@@ -6,13 +6,14 @@
#include
#include
+#include "core/log.h"
+
#include "ezusb2/cyioctl.h"
#include "ezusb2/ezusb2.h"
#include "ezusb-emu/util.h"
#include "util/hex.h"
-#include "util/log.h"
void ezusb2_emu_util_log_usb_msg(const char *prefix, const struct irp *irp)
{
diff --git a/src/main/ezusb2-iidx-emu/msg.c b/src/main/ezusb2-iidx-emu/msg.c
index 1279ea9b..bfc3dce8 100644
--- a/src/main/ezusb2-iidx-emu/msg.c
+++ b/src/main/ezusb2-iidx-emu/msg.c
@@ -6,6 +6,8 @@
#include "bemanitools/iidxio.h"
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "ezusb-emu/msg.h"
@@ -15,7 +17,6 @@
#include "ezusb2-iidx/msg.h"
#include "util/hex.h"
-#include "util/log.h"
/* ------------------------------------------------------------------------ */
diff --git a/src/main/ezusb2-popn-emu/msg.c b/src/main/ezusb2-popn-emu/msg.c
index 6e83f7ac..d696ecc3 100644
--- a/src/main/ezusb2-popn-emu/msg.c
+++ b/src/main/ezusb2-popn-emu/msg.c
@@ -6,6 +6,8 @@
#include "bemanitools/popnio.h"
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "ezusb-emu/msg.h"
@@ -19,7 +21,6 @@
#include "ezusb2-popn/msg.h"
#include "util/hex.h"
-#include "util/log.h"
/* ------------------------------------------------------------------------ */
diff --git a/src/main/ezusb2-popn-shim/Module.mk b/src/main/ezusb2-popn-shim/Module.mk
index aefc2d40..f4536c47 100644
--- a/src/main/ezusb2-popn-shim/Module.mk
+++ b/src/main/ezusb2-popn-shim/Module.mk
@@ -4,6 +4,7 @@ ldflags_ezusb2-popn-shim := \
-lsetupapi \
libs_ezusb2-popn-shim := \
+ core \
ezusb2-emu \
hook \
hooklib \
diff --git a/src/main/ezusb2-popn-shim/dllmain.c b/src/main/ezusb2-popn-shim/dllmain.c
index c8e16fcf..ec7e18f6 100644
--- a/src/main/ezusb2-popn-shim/dllmain.c
+++ b/src/main/ezusb2-popn-shim/dllmain.c
@@ -4,6 +4,8 @@
#include
+#include "core/log.h"
+
#include "ezusb2-emu/desc.h"
#include "ezusb2-emu/device.h"
@@ -13,8 +15,6 @@
#include "ezusb2-popn-shim/proxy.h"
-#include "util/log.h"
-
#define EZUSB_REAL_DLL_FILENAME "ezusb.dll"
static DWORD(STDCALL *real_entrypoint)(HMODULE self, DWORD reason, void *ctx);
diff --git a/src/main/ezusb2-popn-shim/proxy.c b/src/main/ezusb2-popn-shim/proxy.c
index fdf4f9f9..ec47002f 100644
--- a/src/main/ezusb2-popn-shim/proxy.c
+++ b/src/main/ezusb2-popn-shim/proxy.c
@@ -2,7 +2,7 @@
#include
#include
-#include "util/log.h"
+#include "core/log.h"
struct CoinParam;
struct EEP_HISTORY;
diff --git a/src/main/ezusb2-tool/Module.mk b/src/main/ezusb2-tool/Module.mk
index 06115652..87e6dff8 100644
--- a/src/main/ezusb2-tool/Module.mk
+++ b/src/main/ezusb2-tool/Module.mk
@@ -4,6 +4,7 @@ ldflags_ezusb2-tool := \
-lsetupapi \
libs_ezusb2-tool := \
+ core \
ezusb2 \
ezusb \
util \
diff --git a/src/main/ezusb2-tool/main.c b/src/main/ezusb2-tool/main.c
index cdfd179b..0579c077 100644
--- a/src/main/ezusb2-tool/main.c
+++ b/src/main/ezusb2-tool/main.c
@@ -3,11 +3,13 @@
#include
#include
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log.h"
+
#include "ezusb/util.h"
#include "ezusb2/ezusb2.h"
-#include "util/log.h"
-
static int scan()
{
char *path;
@@ -122,7 +124,8 @@ int main(int argc, char **argv)
arg_pos = 1;
- log_to_writer(log_writer_stderr, NULL);
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_stderr();
if (!strcmp(argv[arg_pos], "scan")) {
return scan();
diff --git a/src/main/ezusb2/ezusb2.c b/src/main/ezusb2/ezusb2.c
index 61fabd73..2c1b7b97 100644
--- a/src/main/ezusb2/ezusb2.c
+++ b/src/main/ezusb2/ezusb2.c
@@ -4,6 +4,8 @@
#include
// clang-format on
+#include "core/log.h"
+
#include "ezusb/ezusb.h"
#include "ezusb2/cyioctl.h"
@@ -11,7 +13,6 @@
#include "util/crc.h"
#include "util/fs.h"
-#include "util/log.h"
#include "util/str.h"
#define REQ_TYPE_HOST_TO_DEV 0x40
diff --git a/src/main/geninput/Module.mk b/src/main/geninput/Module.mk
index 1521d806..3115edf0 100644
--- a/src/main/geninput/Module.mk
+++ b/src/main/geninput/Module.mk
@@ -5,6 +5,7 @@ ldflags_geninput := \
-lsetupapi \
libs_geninput := \
+ core \
util \
src_geninput := \
diff --git a/src/main/geninput/dev-list.c b/src/main/geninput/dev-list.c
index 2bfcb4e8..ce6d93ac 100644
--- a/src/main/geninput/dev-list.c
+++ b/src/main/geninput/dev-list.c
@@ -9,9 +9,10 @@
#include
#include
+#include "core/log.h"
+
#include "geninput/dev-list.h"
-#include "util/log.h"
#include "util/mem.h"
void dev_list_init(struct dev_list *devs, const GUID *class_guid)
diff --git a/src/main/geninput/hid-generic.c b/src/main/geninput/hid-generic.c
index 41e73828..46c2924b 100644
--- a/src/main/geninput/hid-generic.c
+++ b/src/main/geninput/hid-generic.c
@@ -12,6 +12,8 @@
#include
// clang-format on
+#include "core/log.h"
+
#include "geninput/hid-generic-strings.h"
#include "geninput/hid-generic.h"
#include "geninput/hid-meta-in.h"
@@ -19,7 +21,6 @@
#include "geninput/hid.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/str.h"
diff --git a/src/main/geninput/hid-meta-in.c b/src/main/geninput/hid-meta-in.c
index bbaf44f1..3a324947 100644
--- a/src/main/geninput/hid-meta-in.c
+++ b/src/main/geninput/hid-meta-in.c
@@ -11,10 +11,11 @@
#include
#include
+#include "core/log.h"
+
#include "geninput/hid-meta-in.h"
#include "geninput/hid-report-in.h"
-#include "util/log.h"
#include "util/mem.h"
static bool
diff --git a/src/main/geninput/hid-meta-out.c b/src/main/geninput/hid-meta-out.c
index 4f87602a..19037851 100644
--- a/src/main/geninput/hid-meta-out.c
+++ b/src/main/geninput/hid-meta-out.c
@@ -12,10 +12,11 @@
#include
#include
+#include "core/log.h"
+
#include "geninput/hid-meta-out.h"
#include "geninput/hid-report-out.h"
-#include "util/log.h"
#include "util/mem.h"
static bool
diff --git a/src/main/geninput/hid-mgr.c b/src/main/geninput/hid-mgr.c
index f22d3a78..2f8a7c13 100644
--- a/src/main/geninput/hid-mgr.c
+++ b/src/main/geninput/hid-mgr.c
@@ -2,9 +2,10 @@
#include
+#include "core/log.h"
+
#include "geninput/hid-mgr.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/str.h"
diff --git a/src/main/geninput/hid-report-in.c b/src/main/geninput/hid-report-in.c
index 721a721d..aec213de 100644
--- a/src/main/geninput/hid-report-in.c
+++ b/src/main/geninput/hid-report-in.c
@@ -10,9 +10,10 @@
#include
#include
+#include "core/log.h"
+
#include "geninput/hid-report-in.h"
-#include "util/log.h"
#include "util/mem.h"
void hid_report_in_init(
diff --git a/src/main/geninput/hid-report-out.c b/src/main/geninput/hid-report-out.c
index 5469e3a3..892cd13f 100644
--- a/src/main/geninput/hid-report-out.c
+++ b/src/main/geninput/hid-report-out.c
@@ -11,9 +11,10 @@
#include
#include
+#include "core/log.h"
+
#include "geninput/hid-report-out.h"
-#include "util/log.h"
#include "util/mem.h"
bool hid_report_out_init(
diff --git a/src/main/geninput/hid.c b/src/main/geninput/hid.c
index 57685b02..889ee80f 100644
--- a/src/main/geninput/hid.c
+++ b/src/main/geninput/hid.c
@@ -1,10 +1,11 @@
#include
#include
+#include "core/log.h"
+
#include "geninput/dev-list.h"
#include "geninput/hid.h"
-#include "util/log.h"
#include "util/str.h"
wchar_t *hid_ri_init_name(const GUID *class_guid, const char *dev_node)
diff --git a/src/main/geninput/hotplug.c b/src/main/geninput/hotplug.c
index 54dad425..d9954d37 100644
--- a/src/main/geninput/hotplug.c
+++ b/src/main/geninput/hotplug.c
@@ -6,13 +6,13 @@
#include
+#include "core/log.h"
+
#include "geninput/hid.h"
#include "geninput/hotplug.h"
#include "geninput/io-thread.h"
#include "geninput/ri.h"
-#include "util/log.h"
-
static HDEVNOTIFY hotplug_handle;
void hotplug_init(HWND wnd)
diff --git a/src/main/geninput/input.c b/src/main/geninput/input.c
index 60c94c26..e67df3d7 100644
--- a/src/main/geninput/input.c
+++ b/src/main/geninput/input.c
@@ -7,6 +7,9 @@
#include "bemanitools/glue.h"
#include "bemanitools/input.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "geninput/hid-mgr.h"
#include "geninput/hid.h"
#include "geninput/io-thread.h"
@@ -14,10 +17,8 @@
#include "geninput/mapper.h"
#include "util/fs.h"
-#include "util/log.h"
#include "util/msg-thread.h"
#include "util/str.h"
-#include "util/thread.h"
static HINSTANCE input_hinst;
static volatile long input_init_count;
@@ -47,7 +48,7 @@ void input_set_loggers(
log_formatter_t warning,
log_formatter_t fatal)
{
- log_to_external(misc, info, warning, fatal);
+ core_log_impl_set(misc, info, warning, fatal);
}
void input_init(
@@ -63,7 +64,7 @@ void input_init(
mapper_inst = mapper_impl_create();
- thread_api_init(create, join, destroy);
+ core_thread_impl_set(create, join, destroy);
msg_thread_init(input_hinst);
io_thread_init();
}
diff --git a/src/main/geninput/io-thread.c b/src/main/geninput/io-thread.c
index ca663ff3..18f5ccca 100644
--- a/src/main/geninput/io-thread.c
+++ b/src/main/geninput/io-thread.c
@@ -2,6 +2,9 @@
#include
+#include "core/log.h"
+#include "core/thread.h"
+
#include "geninput/dev-list.h"
#include "geninput/hid-generic.h"
#include "geninput/hid-mgr.h"
@@ -10,9 +13,7 @@
#include "geninput/pacdrive.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
-#include "util/thread.h"
enum io_thread_cmd {
IO_THREAD_CMD_STOP,
@@ -172,7 +173,7 @@ void io_thread_init(void)
barrier = CreateEvent(NULL, TRUE, FALSE, NULL);
- io_thread_id = thread_create(io_thread_proc, barrier, 16384, 0);
+ io_thread_id = core_thread_create(io_thread_proc, barrier, 16384, 0);
WaitForSingleObject(barrier, INFINITE);
CloseHandle(barrier);
@@ -200,6 +201,6 @@ void io_thread_fini(void)
PostQueuedCompletionStatus(io_thread_cp, 0, (uintptr_t) &msg, NULL);
- thread_join(io_thread_id, NULL);
- thread_destroy(io_thread_id);
+ core_thread_join(io_thread_id, NULL);
+ core_thread_destroy(io_thread_id);
}
diff --git a/src/main/geninput/kbd.c b/src/main/geninput/kbd.c
index 9ae8e5ed..191890b0 100644
--- a/src/main/geninput/kbd.c
+++ b/src/main/geninput/kbd.c
@@ -11,12 +11,13 @@
#include
#include
+#include "core/log.h"
+
#include "geninput/hid.h"
#include "geninput/kbd-data.h"
#include "geninput/kbd.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/str.h"
diff --git a/src/main/geninput/mapper.c b/src/main/geninput/mapper.c
index c3d02143..3c66c19c 100644
--- a/src/main/geninput/mapper.c
+++ b/src/main/geninput/mapper.c
@@ -1,11 +1,12 @@
#include
#include
+#include "core/log.h"
+
#include "geninput/hid-mgr.h"
#include "geninput/mapper.h"
#include "util/array.h"
-#include "util/log.h"
#include "util/mem.h"
struct action_iter {
diff --git a/src/main/geninput/mouse.c b/src/main/geninput/mouse.c
index 2b24d1c8..f1c54bfd 100644
--- a/src/main/geninput/mouse.c
+++ b/src/main/geninput/mouse.c
@@ -12,11 +12,12 @@
#include
#include
+#include "core/log.h"
+
#include "geninput/hid.h"
#include "geninput/mouse.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/str.h"
diff --git a/src/main/geninput/msg-thread.c b/src/main/geninput/msg-thread.c
index cc21ae06..7ca47f32 100644
--- a/src/main/geninput/msg-thread.c
+++ b/src/main/geninput/msg-thread.c
@@ -6,10 +6,11 @@
#include
+#include "core/log.h"
+
#include "geninput/hotplug.h"
#include "geninput/ri.h"
-#include "util/log.h"
#include "util/msg-thread.h"
void msg_window_setup(HWND hwnd)
diff --git a/src/main/geninput/pacdrive.c b/src/main/geninput/pacdrive.c
index 2a5ab36f..b388036f 100644
--- a/src/main/geninput/pacdrive.c
+++ b/src/main/geninput/pacdrive.c
@@ -11,12 +11,13 @@
#include
#include
+#include "core/log.h"
+
#include "geninput/hid.h"
#include "geninput/io-thread.h"
#include "geninput/pacdrive.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
/* The PacDrive appears to have a malformed descriptor for its OUT report.
diff --git a/src/main/geninput/ri.c b/src/main/geninput/ri.c
index b3befee9..45b6d65b 100644
--- a/src/main/geninput/ri.c
+++ b/src/main/geninput/ri.c
@@ -1,5 +1,7 @@
#include
+#include "core/log.h"
+
#include "geninput/hid-mgr.h"
#include "geninput/hid.h"
#include "geninput/kbd.h"
@@ -7,7 +9,6 @@
#include "geninput/ri.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/mem.h"
struct ri_handle {
diff --git a/src/main/hook/com-proxy.h b/src/main/hook/com-proxy.h
index 94671b7c..71d29538 100644
--- a/src/main/hook/com-proxy.h
+++ b/src/main/hook/com-proxy.h
@@ -1,5 +1,7 @@
#pragma once
+#include
+
#include
#include
diff --git a/src/main/hook/d3d9.c b/src/main/hook/d3d9.c
index 45e1fd14..0f09ec68 100644
--- a/src/main/hook/d3d9.c
+++ b/src/main/hook/d3d9.c
@@ -1,11 +1,11 @@
#define LOG_MODULE "hook-d3d9"
-#include "hook/d3d9.h"
+#include "core/log.h"
+
#include "hook/com-proxy.h"
+#include "hook/d3d9.h"
#include "hook/table.h"
-#include "util/log.h"
-
/* ------------------------------------------------------------------------------------------------------------------
*/
diff --git a/src/main/hook/table.c b/src/main/hook/table.c
index ed67b3b6..285a43d3 100644
--- a/src/main/hook/table.c
+++ b/src/main/hook/table.c
@@ -15,12 +15,21 @@ static const size_t apiset_prefix_len = sizeof(apiset_prefix) - 1;
static void hook_table_apply_to_all(
const char *depname, const struct hook_symbol *syms, size_t nsyms);
+static void hook_table_revert_to_all(
+ const char *depname, const struct hook_symbol *syms, size_t nsyms);
+
static void hook_table_apply_to_iid(
HMODULE target,
const pe_iid_t *iid,
const struct hook_symbol *syms,
size_t nsyms);
+static void hook_table_revert_to_iid(
+ HMODULE target,
+ const pe_iid_t *iid,
+ const struct hook_symbol *syms,
+ size_t nsyms);
+
static bool hook_table_match_module(
HMODULE target, const char *iid_name, const char *depname);
@@ -44,6 +53,23 @@ static void hook_table_apply_to_all(
}
}
+static void hook_table_revert_to_all(
+ const char *depname, const struct hook_symbol *syms, size_t nsyms)
+{
+ const peb_dll_t *dll;
+ HMODULE pe;
+
+ for (dll = peb_dll_get_first(); dll != NULL; dll = peb_dll_get_next(dll)) {
+ pe = peb_dll_get_base(dll);
+
+ if (pe == NULL) {
+ continue; /* ?? Happens sometimes. */
+ }
+
+ hook_table_revert(pe, depname, syms, nsyms);
+ }
+}
+
void hook_table_apply(
HMODULE target,
const char *depname,
@@ -73,6 +99,35 @@ void hook_table_apply(
}
}
+void hook_table_revert(
+ HMODULE target,
+ const char *depname,
+ const struct hook_symbol *syms,
+ size_t nsyms)
+{
+ const pe_iid_t *iid;
+ const char *iid_name;
+
+ assert(depname != NULL);
+ assert(syms != NULL || nsyms == 0);
+
+ if (target == NULL) {
+ /* Call out, which will then call us back repeatedly. Awkward, but
+ viewed from the outside it's good for usability. */
+
+ hook_table_revert_to_all(depname, syms, nsyms);
+ } else {
+ for (iid = pe_iid_get_first(target); iid != NULL;
+ iid = pe_iid_get_next(target, iid)) {
+ iid_name = pe_iid_get_name(target, iid);
+
+ if (hook_table_match_module(target, iid_name, depname)) {
+ hook_table_revert_to_iid(target, iid, syms, nsyms);
+ }
+ }
+ }
+}
+
static void hook_table_apply_to_iid(
HMODULE target,
const pe_iid_t *iid,
@@ -101,6 +156,34 @@ static void hook_table_apply_to_iid(
}
}
+static void hook_table_revert_to_iid(
+ HMODULE target,
+ const pe_iid_t *iid,
+ const struct hook_symbol *syms,
+ size_t nsyms)
+{
+ struct pe_iat_entry iate;
+ size_t i;
+ size_t j;
+ const struct hook_symbol *sym;
+
+ i = 0;
+
+ while (pe_iid_get_iat_entry(target, iid, i++, &iate) == S_OK) {
+ for (j = 0; j < nsyms; j++) {
+ sym = &syms[j];
+
+ if (hook_table_match_proc(&iate, sym)) {
+ // Only revert-able if the original pointer was stored
+ // previously
+ if (sym->link != NULL && *sym->link != NULL) {
+ pe_patch(iate.ppointer, sym->link, sizeof(*sym->link));
+ }
+ }
+ }
+ }
+}
+
static bool hook_table_match_module(
HMODULE target, const char *iid_name, const char *depname)
{
diff --git a/src/main/hooklib/acp.c b/src/main/hooklib/acp.c
index 52675b2d..81faa738 100644
--- a/src/main/hooklib/acp.c
+++ b/src/main/hooklib/acp.c
@@ -6,13 +6,14 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "hooklib/acp.h"
#include "util/codepage.h"
#include "util/defs.h"
-#include "util/log.h"
static NTSTATUS NTAPI my_RtlMultiByteToUnicodeN(
wchar_t *dest,
diff --git a/src/main/hooklib/adapter.c b/src/main/hooklib/adapter.c
index 0b94c125..8b3b6d9f 100644
--- a/src/main/hooklib/adapter.c
+++ b/src/main/hooklib/adapter.c
@@ -6,13 +6,14 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "hooklib/adapter.h"
#include "util/codepage.h"
#include "util/defs.h"
-#include "util/log.h"
static DWORD WINAPI
my_GetAdaptersInfo(PIP_ADAPTER_INFO adapter_info, PULONG out_buf_len);
diff --git a/src/main/hooklib/app.c b/src/main/hooklib/app.c
index 7ccd441d..11fb8243 100644
--- a/src/main/hooklib/app.c
+++ b/src/main/hooklib/app.c
@@ -1,5 +1,7 @@
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "hooklib/app.h"
@@ -7,7 +9,6 @@
#include "imports/avs.h"
#include "imports/eapki.h"
-#include "util/log.h"
#include "util/str.h"
static dll_entry_init_t hook_dll_entry_init;
diff --git a/src/main/hooklib/config-adapter.c b/src/main/hooklib/config-adapter.c
index 49c24505..0ddb6806 100644
--- a/src/main/hooklib/config-adapter.c
+++ b/src/main/hooklib/config-adapter.c
@@ -1,8 +1,8 @@
#include "cconfig/cconfig-util.h"
-#include "hooklib/config-adapter.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "hooklib/config-adapter.h"
#define HOOKLIB_CONFIG_ADAPTER_OVERRIDE_IP_KEY "adapter.override_ip"
diff --git a/src/main/hooklib/memfile.c b/src/main/hooklib/memfile.c
index 08dbeba1..09c05878 100644
--- a/src/main/hooklib/memfile.c
+++ b/src/main/hooklib/memfile.c
@@ -3,12 +3,13 @@
#include
#include
+#include "core/log.h"
+
#include "hook/hr.h"
#include "hook/iohook.h"
#include "hook/table.h"
#include "util/array.h"
-#include "util/log.h"
#include "util/str.h"
struct file_entry {
diff --git a/src/main/hooklib/rs232.c b/src/main/hooklib/rs232.c
index 8d6d371f..591c98f4 100644
--- a/src/main/hooklib/rs232.c
+++ b/src/main/hooklib/rs232.c
@@ -14,12 +14,13 @@
#include
#include
+#include "core/log.h"
+
#include "hook/hr.h"
#include "hook/iohook.h"
#include "hook/table.h"
#include "util/array.h"
-#include "util/log.h"
/* RS232 API hooks */
diff --git a/src/main/hooklib/setupapi.c b/src/main/hooklib/setupapi.c
index 07dc72cf..5363c52a 100644
--- a/src/main/hooklib/setupapi.c
+++ b/src/main/hooklib/setupapi.c
@@ -4,12 +4,13 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "hooklib/setupapi.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
/* my hooks */
diff --git a/src/main/iidx-bio2-exit-hook/Module.mk b/src/main/iidx-bio2-exit-hook/Module.mk
index dcf7289b..085af3a8 100644
--- a/src/main/iidx-bio2-exit-hook/Module.mk
+++ b/src/main/iidx-bio2-exit-hook/Module.mk
@@ -4,6 +4,7 @@ ldflags_iidx-bio2-exit-hook := \
-lsetupapi \
libs_iidx-bio2-exit-hook := \
+ core \
bio2drv \
hook \
util \
diff --git a/src/main/iidx-bio2-exit-hook/main.c b/src/main/iidx-bio2-exit-hook/main.c
index 13ac8251..2718717c 100644
--- a/src/main/iidx-bio2-exit-hook/main.c
+++ b/src/main/iidx-bio2-exit-hook/main.c
@@ -11,10 +11,13 @@
#include "bio2/bi2a-iidx.h"
#include "bio2drv/detect.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log.h"
+
#include "hook/iobuf.h"
#include "hook/iohook.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/proc.h"
#include "util/str.h"
@@ -224,7 +227,8 @@ static HRESULT _iohook_handler(struct irp *irp)
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
- log_to_writer(log_writer_stdout, NULL);
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_stdout();
if (reason != DLL_PROCESS_ATTACH) {
return TRUE;
diff --git a/src/main/iidx-ezusb-exit-hook/Module.mk b/src/main/iidx-ezusb-exit-hook/Module.mk
index 4050ebe1..500bd156 100644
--- a/src/main/iidx-ezusb-exit-hook/Module.mk
+++ b/src/main/iidx-ezusb-exit-hook/Module.mk
@@ -1,6 +1,7 @@
dlls += iidx-ezusb-exit-hook
libs_iidx-ezusb-exit-hook := \
+ core \
ezusb-iidx \
hook \
util \
diff --git a/src/main/iidx-ezusb2-exit-hook/Module.mk b/src/main/iidx-ezusb2-exit-hook/Module.mk
index 7828a97b..f449f383 100644
--- a/src/main/iidx-ezusb2-exit-hook/Module.mk
+++ b/src/main/iidx-ezusb2-exit-hook/Module.mk
@@ -1,6 +1,7 @@
dlls += iidx-ezusb2-exit-hook
libs_iidx-ezusb2-exit-hook := \
+ core \
hook \
util \
diff --git a/src/main/iidx-irbeat-patch/Module.mk b/src/main/iidx-irbeat-patch/Module.mk
index df42cd3d..d01645fa 100644
--- a/src/main/iidx-irbeat-patch/Module.mk
+++ b/src/main/iidx-irbeat-patch/Module.mk
@@ -2,6 +2,7 @@ exes += iidx-irbeat-patch
libs_iidx-irbeat-patch := \
util \
+ core \
src_iidx-irbeat-patch := \
main.c \
diff --git a/src/main/iidxhook-d3d9/bb-scale-hd.c b/src/main/iidxhook-d3d9/bb-scale-hd.c
index 60dae6be..84afe7c8 100644
--- a/src/main/iidxhook-d3d9/bb-scale-hd.c
+++ b/src/main/iidxhook-d3d9/bb-scale-hd.c
@@ -2,13 +2,13 @@
#include
+#include "core/log.h"
+
#include "d3d9-util/vertex.h"
#include "bb-scale-hd.h"
#include "util.h"
-#include "util/log.h"
-
static bool iidxhook_d3d9_bb_scale_initialized;
static uint16_t iidxhook_d3d9_bb_scale_hd_width;
static uint16_t iidxhook_d3d9_bb_scale_hd_height;
diff --git a/src/main/iidxhook-d3d9/util.h b/src/main/iidxhook-d3d9/util.h
index 3a77e99b..96b489e0 100644
--- a/src/main/iidxhook-d3d9/util.h
+++ b/src/main/iidxhook-d3d9/util.h
@@ -3,9 +3,9 @@
#include
-#include "d3d9-util/dxerr9.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "d3d9-util/dxerr9.h"
inline void
iidxhook_d3d9_util_check_and_handle_failure(HRESULT hr, const char *msg)
diff --git a/src/main/iidxhook-util/Module.mk b/src/main/iidxhook-util/Module.mk
index 92fe44d8..50dd18dc 100644
--- a/src/main/iidxhook-util/Module.mk
+++ b/src/main/iidxhook-util/Module.mk
@@ -1,6 +1,7 @@
libs += iidxhook-util
libs_iidxhook-util := \
+ core \
util \
src_iidxhook-util := \
diff --git a/src/main/iidxhook-util/acio.c b/src/main/iidxhook-util/acio.c
index 62913361..a52fa766 100644
--- a/src/main/iidxhook-util/acio.c
+++ b/src/main/iidxhook-util/acio.c
@@ -15,6 +15,8 @@
#include "acioemu/emu.h"
#include "acioemu/icca.h"
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "hooklib/rs232.h"
@@ -24,7 +26,6 @@
#include "util/defs.h"
#include "util/iobuf.h"
-#include "util/log.h"
#include "util/str.h"
static struct ac_io_emu iidxhook_util_acio_emu;
diff --git a/src/main/iidxhook-util/chart-patch.c b/src/main/iidxhook-util/chart-patch.c
index 4b2970ec..b6cc290d 100644
--- a/src/main/iidxhook-util/chart-patch.c
+++ b/src/main/iidxhook-util/chart-patch.c
@@ -4,12 +4,13 @@
#include
#include
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "util/crc.h"
#include "util/defs.h"
#include "util/fs.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/str.h"
diff --git a/src/main/iidxhook-util/clock.c b/src/main/iidxhook-util/clock.c
index 8c870fff..dc0e2f2f 100644
--- a/src/main/iidxhook-util/clock.c
+++ b/src/main/iidxhook-util/clock.c
@@ -2,10 +2,11 @@
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "util/defs.h"
-#include "util/log.h"
static BOOL STDCALL my_SetLocalTime(const SYSTEMTIME *lpSystemTime);
static BOOL(STDCALL *real_SetLocalTime)(const SYSTEMTIME *lpSystemTime);
diff --git a/src/main/iidxhook-util/config-eamuse.c b/src/main/iidxhook-util/config-eamuse.c
index f59b03e8..c75bd1a7 100644
--- a/src/main/iidxhook-util/config-eamuse.c
+++ b/src/main/iidxhook-util/config-eamuse.c
@@ -2,12 +2,12 @@
#include "cconfig/cconfig-util.h"
+#include "core/log.h"
+
#include "iidxhook-util/config-eamuse.h"
#include "security/mcode.h"
-#include "util/log.h"
-
#define IIDXHOOK_CONFIG_EAMUSE_CARD_TYPE_KEY "eamuse.card_type"
#define IIDXHOOK_CONFIG_EAMUSE_SERVER_KEY "eamuse.server"
#define IIDXHOOK_CONFIG_EAMUSE_PCBID_KEY "eamuse.pcbid"
diff --git a/src/main/iidxhook-util/config-ezusb.c b/src/main/iidxhook-util/config-ezusb.c
index e860a1d5..14d953d2 100644
--- a/src/main/iidxhook-util/config-ezusb.c
+++ b/src/main/iidxhook-util/config-ezusb.c
@@ -3,9 +3,10 @@
#include "cconfig/cconfig-util.h"
+#include "core/log.h"
+
#include "iidxhook-util/config-ezusb.h"
-#include "util/log.h"
#include "util/mem.h"
#define IIDXHOOK_UTIL_CONFIG_EZUSB_API_CALL_MONITORING_KEY \
diff --git a/src/main/iidxhook-util/config-gfx.c b/src/main/iidxhook-util/config-gfx.c
index e591f480..1be281fe 100644
--- a/src/main/iidxhook-util/config-gfx.c
+++ b/src/main/iidxhook-util/config-gfx.c
@@ -2,9 +2,9 @@
#include "cconfig/cconfig-util.h"
-#include "iidxhook-util/config-gfx.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "iidxhook-util/config-gfx.h"
#define IIDXHOOK_CONFIG_GFX_BGVIDEO_UV_FIX_KEY "gfx.bgvideo_uv_fix"
#define IIDXHOOK_CONFIG_GFX_FRAMED_KEY "gfx.framed"
diff --git a/src/main/iidxhook-util/config-io.c b/src/main/iidxhook-util/config-io.c
index 3055ac6e..13c59f3c 100644
--- a/src/main/iidxhook-util/config-io.c
+++ b/src/main/iidxhook-util/config-io.c
@@ -1,8 +1,8 @@
#include "cconfig/cconfig-util.h"
-#include "iidxhook-util/config-io.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "iidxhook-util/config-io.h"
#define IIDXHOOK_UTIL_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY \
"io.disable_card_reader_emu"
diff --git a/src/main/iidxhook-util/config-misc.c b/src/main/iidxhook-util/config-misc.c
index 7a18499e..fca5ea5a 100644
--- a/src/main/iidxhook-util/config-misc.c
+++ b/src/main/iidxhook-util/config-misc.c
@@ -1,8 +1,8 @@
#include "cconfig/cconfig-util.h"
-#include "iidxhook-util/config-misc.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "iidxhook-util/config-misc.h"
#define IIDXHOOK_CONFIG_MISC_DISABLE_CLOCK_SET_KEY "misc.disable_clock_set"
#define IIDXHOOK_CONFIG_MISC_RTEFFECT_STUB_KEY "misc.rteffect_stub"
diff --git a/src/main/iidxhook-util/config-sec.c b/src/main/iidxhook-util/config-sec.c
index 54cb0eea..a2e9a573 100644
--- a/src/main/iidxhook-util/config-sec.c
+++ b/src/main/iidxhook-util/config-sec.c
@@ -3,12 +3,13 @@
#include "cconfig/cconfig-util.h"
+#include "core/log.h"
+
#include "iidxhook-util/config-sec.h"
#include "security/mcode.h"
#include "security/rp.h"
-#include "util/log.h"
#include "util/mem.h"
#define IIDXHOOK_CONFIG_SEC_BOOT_VERSION_KEY "sec.boot_version"
diff --git a/src/main/iidxhook-util/d3d9.c b/src/main/iidxhook-util/d3d9.c
index 9c877199..eeb5081f 100644
--- a/src/main/iidxhook-util/d3d9.c
+++ b/src/main/iidxhook-util/d3d9.c
@@ -9,6 +9,8 @@
#include
#include
+#include "core/log.h"
+
#include "hook/com-proxy.h"
#include "hook/table.h"
@@ -16,7 +18,6 @@
#include "iidxhook-util/vertex-shader.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
#include "util/time.h"
diff --git a/src/main/iidxhook-util/eamuse.c b/src/main/iidxhook-util/eamuse.c
index 15d77da9..6a127bd3 100644
--- a/src/main/iidxhook-util/eamuse.c
+++ b/src/main/iidxhook-util/eamuse.c
@@ -8,12 +8,13 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "iidxhook-util/eamuse.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
/* ------------------------------------------------------------------------- */
diff --git a/src/main/iidxhook-util/effector.c b/src/main/iidxhook-util/effector.c
index 4f30e279..f313c602 100644
--- a/src/main/iidxhook-util/effector.c
+++ b/src/main/iidxhook-util/effector.c
@@ -2,12 +2,13 @@
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "iidxhook-util/effector.h"
#include "util/defs.h"
-#include "util/log.h"
static BOOL my_EnableEqualizer(int a1);
static BOOL my_GetEqualizerStatus(LPVOID buffer);
diff --git a/src/main/iidxhook-util/log-server.c b/src/main/iidxhook-util/log-server.c
index 1a7f687c..5a2fe3d2 100644
--- a/src/main/iidxhook-util/log-server.c
+++ b/src/main/iidxhook-util/log-server.c
@@ -5,6 +5,9 @@
#include
#include
+#include "core/log.h"
+#include "core/thread.h"
+
#include "hook/table.h"
#include "iidxhook-util/log-server.h"
@@ -12,9 +15,7 @@
#include "imports/avs.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
-#include "util/thread.h"
static int log_thread_proc(void *ctx);
static void
@@ -39,7 +40,7 @@ void log_server_init(void)
log_rv_consumer = CreateSemaphore(NULL, 0, 1, NULL);
ready = CreateEvent(NULL, TRUE, FALSE, NULL);
- log_to_external(
+ core_log_impl_set(
log_post_misc, log_post_info, log_post_warning, log_post_fatal);
log_thread_id = avs_thread_create(log_thread_proc, ready, 16384, 0);
diff --git a/src/main/iidxhook-util/settings.c b/src/main/iidxhook-util/settings.c
index b4f2ce3f..5402f695 100644
--- a/src/main/iidxhook-util/settings.c
+++ b/src/main/iidxhook-util/settings.c
@@ -7,12 +7,13 @@
#include
#include
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "hook/table.h"
#include "util/defs.h"
#include "util/fs.h"
-#include "util/log.h"
#include "util/mem.h"
#include "util/str.h"
diff --git a/src/main/iidxhook1/Module.mk b/src/main/iidxhook1/Module.mk
index fcfad98b..61bb5ff4 100644
--- a/src/main/iidxhook1/Module.mk
+++ b/src/main/iidxhook1/Module.mk
@@ -5,6 +5,7 @@ ldflags_iidxhook1 := \
-liphlpapi \
libs_iidxhook1 := \
+ core \
iidxhook-util \
ezusb-emu \
ezusb-iidx-16seg-emu \
diff --git a/src/main/iidxhook1/config-iidxhook1.c b/src/main/iidxhook1/config-iidxhook1.c
index 5a02c95c..b88d4718 100644
--- a/src/main/iidxhook1/config-iidxhook1.c
+++ b/src/main/iidxhook1/config-iidxhook1.c
@@ -1,8 +1,8 @@
#include "cconfig/cconfig-util.h"
-#include "iidxhook1/config-iidxhook1.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "iidxhook1/config-iidxhook1.h"
#define IIDXHOOK_CONFIG_MISC_HAPPY_SKY_MS_BG_FIX_KEY "misc.happy_sky_ms_bg_fix"
diff --git a/src/main/iidxhook1/dllmain.c b/src/main/iidxhook1/dllmain.c
index a3a4a357..60c61a75 100644
--- a/src/main/iidxhook1/dllmain.c
+++ b/src/main/iidxhook1/dllmain.c
@@ -9,6 +9,14 @@
#include "cconfig/cconfig-hook.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log-sink-debug.h"
+#include "core/log.h"
+#include "core/thread-crt-ext.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
+
#include "ezusb-emu/desc.h"
#include "ezusb-emu/device.h"
#include "ezusb-emu/node-security-plug.h"
@@ -42,8 +50,6 @@
#include "iidxhook1/log-ezusb.h"
#include "util/defs.h"
-#include "util/log.h"
-#include "util/thread.h"
#define IIDXHOOK1_INFO_HEADER \
"iidxhook for 9th Style, 10th Style, RED and HAPPY SKY" \
@@ -68,6 +74,14 @@ static const struct hook_symbol init_hook_syms[] = {
},
};
+static void _iidxhook1_log_init()
+{
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_debug();
+ // TODO change log level support
+ core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC);
+}
+
static void iidxhook1_setup_d3d9_hooks(
const struct iidxhook_config_gfx *config_gfx,
const struct iidxhook_config_iidxhook1 *config_iidxhook1)
@@ -215,20 +229,24 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId)
/* Start up IIDXIO.DLL */
log_info("Starting IIDX IO backend");
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(iidx_io_set_loggers);
- if (!iidx_io_init(thread_create, thread_join, thread_destroy)) {
+ if (!iidx_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing IIDX IO backend failed");
}
/* Start up EAMIO.DLL */
log_misc("Initializing card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
- if (!eam_io_init(thread_create, thread_join, thread_destroy)) {
+ if (!eam_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing card reader backend failed");
}
@@ -261,7 +279,9 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId)
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
if (reason == DLL_PROCESS_ATTACH) {
- log_to_writer(log_writer_debug, NULL);
+ core_thread_crt_ext_impl_set();
+
+ _iidxhook1_log_init();
/* Bootstrap hook for further init tasks (see above) */
diff --git a/src/main/iidxhook1/ezusb-mon.c b/src/main/iidxhook1/ezusb-mon.c
index b76418a6..11f10f9e 100644
--- a/src/main/iidxhook1/ezusb-mon.c
+++ b/src/main/iidxhook1/ezusb-mon.c
@@ -6,12 +6,13 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "iidxhook1/ezusb-mon.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
/* ------------------------------------------------------------------------- */
diff --git a/src/main/iidxhook1/log-ezusb.c b/src/main/iidxhook1/log-ezusb.c
index ac71907b..28a9c6a1 100644
--- a/src/main/iidxhook1/log-ezusb.c
+++ b/src/main/iidxhook1/log-ezusb.c
@@ -6,12 +6,13 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "iidxhook1/log-ezusb.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
/* ------------------------------------------------------------------------- */
diff --git a/src/main/iidxhook2/Module.mk b/src/main/iidxhook2/Module.mk
index c9fd4389..46124426 100644
--- a/src/main/iidxhook2/Module.mk
+++ b/src/main/iidxhook2/Module.mk
@@ -5,6 +5,7 @@ ldflags_iidxhook2 := \
-liphlpapi \
libs_iidxhook2 := \
+ core \
iidxhook-util \
ezusb-emu \
ezusb-iidx-16seg-emu \
diff --git a/src/main/iidxhook2/config-iidxhook2.c b/src/main/iidxhook2/config-iidxhook2.c
index 6e3ac6bd..0db10f3b 100644
--- a/src/main/iidxhook2/config-iidxhook2.c
+++ b/src/main/iidxhook2/config-iidxhook2.c
@@ -1,8 +1,8 @@
#include "cconfig/cconfig-util.h"
-#include "iidxhook2/config-iidxhook2.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "iidxhook2/config-iidxhook2.h"
#define IIDXHOOK_CONFIG_MISC_DISTORTED_MS_BG_FIX_KEY "misc.distorted_ms_bg_fix"
diff --git a/src/main/iidxhook2/dllmain.c b/src/main/iidxhook2/dllmain.c
index 25a76ed9..de8a9160 100644
--- a/src/main/iidxhook2/dllmain.c
+++ b/src/main/iidxhook2/dllmain.c
@@ -9,6 +9,14 @@
#include "cconfig/cconfig-hook.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log-sink-debug.h"
+#include "core/log.h"
+#include "core/thread-crt-ext.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
+
#include "ezusb-emu/desc.h"
#include "ezusb-emu/device.h"
#include "ezusb-emu/node-security-plug.h"
@@ -41,9 +49,6 @@
#include "iidxhook2/config-iidxhook2.h"
-#include "util/log.h"
-#include "util/thread.h"
-
#define IIDXHOOK2_INFO_HEADER \
"iidxhook for DistorteD" \
", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV)
@@ -65,6 +70,14 @@ static const struct hook_symbol init_hook_syms[] = {
.link = (void **) &real_OpenProcess},
};
+static void _iidxhook2_log_init()
+{
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_debug();
+ // TODO change log level support
+ core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC);
+}
+
static void iidxhook2_setup_d3d9_hooks(
const struct iidxhook_config_gfx *config_gfx,
const struct iidxhook_config_iidxhook2 *config_iidxhook2)
@@ -207,20 +220,24 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId)
/* Start up IIDXIO.DLL */
log_info("Starting IIDX IO backend");
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(iidx_io_set_loggers);
- if (!iidx_io_init(thread_create, thread_join, thread_destroy)) {
+ if (!iidx_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing IIDX IO backend failed");
}
/* Start up EAMIO.DLL */
log_misc("Initializing card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
- if (!eam_io_init(thread_create, thread_join, thread_destroy)) {
+ if (!eam_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing card reader backend failed");
}
@@ -254,7 +271,9 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId)
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
if (reason == DLL_PROCESS_ATTACH) {
- log_to_writer(log_writer_debug, NULL);
+ core_thread_crt_ext_impl_set();
+
+ _iidxhook2_log_init();
/* Bootstrap hook for further init tasks (see above) */
diff --git a/src/main/iidxhook3/Module.mk b/src/main/iidxhook3/Module.mk
index e328bec3..6ab9a30f 100644
--- a/src/main/iidxhook3/Module.mk
+++ b/src/main/iidxhook3/Module.mk
@@ -5,6 +5,7 @@ ldflags_iidxhook3 := \
-liphlpapi \
libs_iidxhook3 := \
+ core \
iidxhook-util \
ezusb-emu \
ezusb-iidx-16seg-emu \
diff --git a/src/main/iidxhook3/dllmain.c b/src/main/iidxhook3/dllmain.c
index b2e0e41d..4927fc32 100644
--- a/src/main/iidxhook3/dllmain.c
+++ b/src/main/iidxhook3/dllmain.c
@@ -9,6 +9,14 @@
#include "cconfig/cconfig-hook.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log-sink-debug.h"
+#include "core/log.h"
+#include "core/thread-crt-ext.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
+
#include "ezusb-emu/node-security-plug.h"
#include "ezusb-iidx-emu/node-serial.h"
#include "ezusb-iidx-emu/nodes.h"
@@ -40,9 +48,7 @@
#include "security/rp-sign-key.h"
-#include "util/log.h"
#include "util/str.h"
-#include "util/thread.h"
#define IIDXHOOK3_INFO_HEADER \
"iidxhook for Gold, DJTroopers, Empress and Sirius" \
@@ -64,6 +70,14 @@ static const struct hook_symbol init_hook_syms[] = {
.link = (void **) &real_OpenProcess},
};
+static void _iidxhook3_log_init()
+{
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_debug();
+ // TODO change log level support
+ core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC);
+}
+
static void
iidxhook3_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx)
{
@@ -200,20 +214,24 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId)
/* Start up IIDXIO.DLL */
log_info("Starting IIDX IO backend");
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(iidx_io_set_loggers);
- if (!iidx_io_init(thread_create, thread_join, thread_destroy)) {
+ if (!iidx_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing IIDX IO backend failed");
}
/* Start up EAMIO.DLL */
log_misc("Initializing card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
- if (!eam_io_init(thread_create, thread_join, thread_destroy)) {
+ if (!eam_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing card reader backend failed");
}
@@ -246,7 +264,9 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId)
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
if (reason == DLL_PROCESS_ATTACH) {
- log_to_writer(log_writer_debug, NULL);
+ core_thread_crt_ext_impl_set();
+
+ _iidxhook3_log_init();
/* Bootstrap hook for further init tasks (see above) */
diff --git a/src/main/iidxhook4-cn/Module.mk b/src/main/iidxhook4-cn/Module.mk
index 0f7bceea..8cc34cb1 100644
--- a/src/main/iidxhook4-cn/Module.mk
+++ b/src/main/iidxhook4-cn/Module.mk
@@ -8,6 +8,8 @@ deplibs_iidxhook4-cn := \
avs \
libs_iidxhook4-cn := \
+ avs-util \
+ core \
iidxhook-util \
ezusb-emu \
ezusb-iidx-16seg-emu \
diff --git a/src/main/iidxhook4-cn/avs-boot.c b/src/main/iidxhook4-cn/avs-boot.c
index 378d80cf..4c498c95 100644
--- a/src/main/iidxhook4-cn/avs-boot.c
+++ b/src/main/iidxhook4-cn/avs-boot.c
@@ -3,14 +3,15 @@
#include
#include
+#include "core/log-bt.h"
+#include "core/log.h"
+
#include "hook/table.h"
#include "imports/avs.h"
#include "iidxhook4-cn/avs-boot.h"
-#include "util/log.h"
-
static void (*real_avs_boot)(
struct property_node *config,
void *std_heap,
@@ -35,6 +36,11 @@ static const struct hook_symbol iidxhook4_cn_log_hook_syms[] = {
.link = (void **) &real_avs_boot},
};
+static AVS_LOG_WRITER(_avs_boot_log_writer, chars, nchars, ctx)
+{
+ core_log_bt_direct_sink_write(chars, nchars);
+}
+
static void avs_boot_replace_property_uint32(
struct property_node *node, const char *name, uint32_t val)
{
@@ -87,7 +93,7 @@ static void my_avs_boot(
sz_std_heap,
avs_heap,
sz_avs_heap,
- log_writer_debug,
+ _avs_boot_log_writer,
NULL);
}
diff --git a/src/main/iidxhook4-cn/dllmain.c b/src/main/iidxhook4-cn/dllmain.c
index ea2f42ab..9fa61ba3 100644
--- a/src/main/iidxhook4-cn/dllmain.c
+++ b/src/main/iidxhook4-cn/dllmain.c
@@ -5,10 +5,19 @@
#include
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/iidxio.h"
#include "cconfig/cconfig-hook.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log-sink-debug.h"
+#include "core/log.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
+
#include "ezusb-emu/node-security-plug.h"
#include "ezusb2-emu/desc.h"
@@ -37,8 +46,6 @@
#include "imports/avs.h"
-#include "util/log.h"
-
#define IIDXHOOK4_CN_INFO_HEADER \
"iidxhook for Resort Anthem CN" \
", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV)
@@ -61,6 +68,14 @@ static const struct hook_symbol init_hook_syms[] = {
static struct iidxhook_config_io config_io;
+static void _iidxhook4_cn_log_init()
+{
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_debug();
+ // TODO change log level support
+ core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC);
+}
+
static void
iidxhook4_cn_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx)
{
@@ -183,11 +198,12 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId)
if (!config_io.disable_io_emu) {
log_info("Starting IIDX IO backend");
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(iidx_io_set_loggers);
if (!iidx_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing IIDX IO backend failed");
}
} else {
@@ -221,7 +237,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
return TRUE;
}
- log_to_writer(log_writer_debug, NULL);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+
+ // TODO init debug logging but with avs available? why not use avs logging?
+ _iidxhook4_cn_log_init();
hook_table_apply(
NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms));
diff --git a/src/main/iidxhook4-cn/path.c b/src/main/iidxhook4-cn/path.c
index 4ab6c5a3..5d4ef1dd 100644
--- a/src/main/iidxhook4-cn/path.c
+++ b/src/main/iidxhook4-cn/path.c
@@ -4,11 +4,12 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "iidxhook4-cn/path.h"
-#include "util/log.h"
#include "util/str.h"
#define PATH_A "D:/JDZ-001/contents/"
diff --git a/src/main/iidxhook4/Module.mk b/src/main/iidxhook4/Module.mk
index 40f40b02..6546ac19 100644
--- a/src/main/iidxhook4/Module.mk
+++ b/src/main/iidxhook4/Module.mk
@@ -7,6 +7,8 @@ deplibs_iidxhook4 := \
avs \
libs_iidxhook4 := \
+ avs-util \
+ core \
iidxhook-util \
ezusb-emu \
ezusb-iidx-16seg-emu \
diff --git a/src/main/iidxhook4/dllmain.c b/src/main/iidxhook4/dllmain.c
index d7993dd7..c52336f3 100644
--- a/src/main/iidxhook4/dllmain.c
+++ b/src/main/iidxhook4/dllmain.c
@@ -5,11 +5,16 @@
#include
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/eamio.h"
#include "bemanitools/iidxio.h"
#include "cconfig/cconfig-hook.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "ezusb-iidx-emu/nodes.h"
#include "ezusb2-emu/desc.h"
@@ -36,9 +41,7 @@
#include "imports/avs.h"
-#include "util/log.h"
#include "util/str.h"
-#include "util/thread.h"
#define IIDXHOOK4_INFO_HEADER \
"iidxhook for Resort Anthem" \
@@ -142,11 +145,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (!config_io.disable_io_emu) {
log_info("Starting IIDX IO backend");
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(iidx_io_set_loggers);
if (!iidx_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing IIDX IO backend failed");
}
} else {
@@ -156,11 +160,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (!config_io.disable_card_reader_emu) {
log_misc("Initializing card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
if (!eam_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing card reader backend failed");
}
} else {
@@ -227,8 +232,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
goto end;
}
- log_to_external(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+ avs_util_core_interop_log_avs_impl_set();
app_hook_init(my_dll_entry_init, my_dll_entry_main);
diff --git a/src/main/iidxhook5-cn/Module.mk b/src/main/iidxhook5-cn/Module.mk
index feea3d48..5addce9b 100644
--- a/src/main/iidxhook5-cn/Module.mk
+++ b/src/main/iidxhook5-cn/Module.mk
@@ -8,6 +8,8 @@ deplibs_iidxhook5-cn := \
avs \
libs_iidxhook5-cn := \
+ avs-util \
+ core \
iidxhook-util \
ezusb-emu \
ezusb-iidx-16seg-emu \
diff --git a/src/main/iidxhook5-cn/avs-boot.c b/src/main/iidxhook5-cn/avs-boot.c
index 772832ab..eaa1f459 100644
--- a/src/main/iidxhook5-cn/avs-boot.c
+++ b/src/main/iidxhook5-cn/avs-boot.c
@@ -3,14 +3,15 @@
#include
#include
+#include "core/log-bt.h"
+#include "core/log.h"
+
#include "hook/table.h"
#include "imports/avs.h"
#include "iidxhook5-cn/avs-boot.h"
-#include "util/log.h"
-
static void (*real_avs_boot)(
struct property_node *config,
void *std_heap,
@@ -35,6 +36,11 @@ static const struct hook_symbol iidxhook5_cn_log_hook_syms[] = {
.link = (void **) &real_avs_boot},
};
+static AVS_LOG_WRITER(_avs_boot_log_writer, chars, nchars, ctx)
+{
+ core_log_bt_direct_sink_write(chars, nchars);
+}
+
static void avs_boot_replace_property_uint32(
struct property_node *node, const char *name, uint32_t val)
{
@@ -87,7 +93,7 @@ static void my_avs_boot(
sz_std_heap,
avs_heap,
sz_avs_heap,
- log_writer_debug,
+ _avs_boot_log_writer,
NULL);
}
diff --git a/src/main/iidxhook5-cn/dllmain.c b/src/main/iidxhook5-cn/dllmain.c
index 711c906f..1d327dcf 100644
--- a/src/main/iidxhook5-cn/dllmain.c
+++ b/src/main/iidxhook5-cn/dllmain.c
@@ -5,10 +5,18 @@
#include
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/iidxio.h"
#include "cconfig/cconfig-hook.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log-sink-debug.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "ezusb-emu/node-security-plug.h"
#include "ezusb2-emu/desc.h"
@@ -37,8 +45,6 @@
#include "imports/avs.h"
-#include "util/log.h"
-
#define IIDXHOOK5_CN_INFO_HEADER \
"iidxhook for tricoro CN" \
", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV)
@@ -61,6 +67,14 @@ static const struct hook_symbol init_hook_user32_syms[] = {
static struct iidxhook_config_io config_io;
+static void _iidxhook5_cn_log_init()
+{
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_debug();
+ // TODO change log level support
+ core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC);
+}
+
static void
iidxhook5_cn_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx)
{
@@ -163,11 +177,12 @@ static ATOM WINAPI my_RegisterClassA(const WNDCLASSA *lpWndClass)
if (!config_io.disable_io_emu) {
log_info("Starting IIDX IO backend");
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(iidx_io_set_loggers);
if (!iidx_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing IIDX IO backend failed");
}
} else {
@@ -200,7 +215,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
return TRUE;
}
- log_to_writer(log_writer_debug, NULL);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+
+ // TODO init debug logging but with avs available? why not use avs logging?
+ _iidxhook5_cn_log_init();
hook_table_apply(
NULL,
diff --git a/src/main/iidxhook5-cn/path.c b/src/main/iidxhook5-cn/path.c
index d45bf227..bb4f81d1 100644
--- a/src/main/iidxhook5-cn/path.c
+++ b/src/main/iidxhook5-cn/path.c
@@ -4,11 +4,12 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "iidxhook5-cn/path.h"
-#include "util/log.h"
#include "util/str.h"
#define PATH_A "D:/JDZ-001/contents/"
diff --git a/src/main/iidxhook5/Module.mk b/src/main/iidxhook5/Module.mk
index 78ea3077..28cb7fe4 100644
--- a/src/main/iidxhook5/Module.mk
+++ b/src/main/iidxhook5/Module.mk
@@ -7,6 +7,8 @@ deplibs_iidxhook5 := \
avs \
libs_iidxhook5 := \
+ avs-util \
+ core \
iidxhook-util \
ezusb-emu \
ezusb-iidx-16seg-emu \
diff --git a/src/main/iidxhook5/dllmain.c b/src/main/iidxhook5/dllmain.c
index 268bf395..0912c381 100644
--- a/src/main/iidxhook5/dllmain.c
+++ b/src/main/iidxhook5/dllmain.c
@@ -5,11 +5,16 @@
#include
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/eamio.h"
#include "bemanitools/iidxio.h"
#include "cconfig/cconfig-hook.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "ezusb-iidx-emu/nodes.h"
#include "ezusb2-emu/desc.h"
@@ -36,9 +41,7 @@
#include "imports/avs.h"
-#include "util/log.h"
#include "util/str.h"
-#include "util/thread.h"
#include "ifs-snd-redir.h"
@@ -144,11 +147,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (!config_io.disable_io_emu) {
log_info("Starting IIDX IO backend");
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(iidx_io_set_loggers);
if (!iidx_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing IIDX IO backend failed");
}
} else {
@@ -158,11 +162,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (!config_io.disable_card_reader_emu) {
log_misc("Initializing card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
if (!eam_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing card reader backend failed");
}
} else {
@@ -228,8 +233,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
goto end;
}
- log_to_external(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+ avs_util_core_interop_log_avs_impl_set();
app_hook_init(my_dll_entry_init, my_dll_entry_main);
diff --git a/src/main/iidxhook5/ifs-snd-redir.c b/src/main/iidxhook5/ifs-snd-redir.c
index e73dd5ca..639d16fd 100644
--- a/src/main/iidxhook5/ifs-snd-redir.c
+++ b/src/main/iidxhook5/ifs-snd-redir.c
@@ -3,13 +3,14 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "imports/avs.h"
#include "iidxhook5/ifs-snd-redir.h"
-#include "util/log.h"
#include "util/str.h"
static void *(*real_avs_fs_open)(const char *path, int mode, int flags);
diff --git a/src/main/iidxhook6/Module.mk b/src/main/iidxhook6/Module.mk
index 7fda87b1..fe7e955e 100644
--- a/src/main/iidxhook6/Module.mk
+++ b/src/main/iidxhook6/Module.mk
@@ -7,6 +7,8 @@ deplibs_iidxhook6 := \
avs \
libs_iidxhook6 := \
+ avs-util \
+ core \
iidxhook-d3d9 \
iidxhook-util \
ezusb-emu \
diff --git a/src/main/iidxhook6/dllmain.c b/src/main/iidxhook6/dllmain.c
index b4ca65aa..4b614a48 100644
--- a/src/main/iidxhook6/dllmain.c
+++ b/src/main/iidxhook6/dllmain.c
@@ -5,11 +5,16 @@
#include
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/eamio.h"
#include "bemanitools/iidxio.h"
#include "cconfig/cconfig-hook.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "ezusb-iidx-emu/nodes.h"
#include "ezusb2-emu/desc.h"
@@ -35,9 +40,7 @@
#include "imports/avs.h"
-#include "util/log.h"
#include "util/str.h"
-#include "util/thread.h"
#define IIDXHOOK6_INFO_HEADER \
"iidxhook for Tricoro" \
@@ -121,11 +124,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (!config_io.disable_io_emu) {
log_info("Starting IIDX IO backend");
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(iidx_io_set_loggers);
if (!iidx_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing IIDX IO backend failed");
}
} else {
@@ -135,11 +139,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (!config_io.disable_card_reader_emu) {
log_misc("Initializing card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
if (!eam_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing card reader backend failed");
}
} else {
@@ -203,8 +208,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
goto end;
}
- log_to_external(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+ avs_util_core_interop_log_avs_impl_set();
app_hook_init(my_dll_entry_init, my_dll_entry_main);
diff --git a/src/main/iidxhook7/Module.mk b/src/main/iidxhook7/Module.mk
index a40366af..b1b6d937 100644
--- a/src/main/iidxhook7/Module.mk
+++ b/src/main/iidxhook7/Module.mk
@@ -8,6 +8,8 @@ deplibs_iidxhook7 := \
avs \
libs_iidxhook7 := \
+ avs-util \
+ core \
iidxhook-d3d9 \
iidxhook-util \
cconfig \
diff --git a/src/main/iidxhook7/dllmain.c b/src/main/iidxhook7/dllmain.c
index af948f61..0823e854 100644
--- a/src/main/iidxhook7/dllmain.c
+++ b/src/main/iidxhook7/dllmain.c
@@ -5,11 +5,16 @@
#include
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/eamio.h"
#include "bemanitools/iidxio.h"
#include "cconfig/cconfig-hook.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "ezusb-iidx-emu/nodes.h"
#include "ezusb2-emu/desc.h"
@@ -35,9 +40,7 @@
#include "imports/avs.h"
-#include "util/log.h"
#include "util/str.h"
-#include "util/thread.h"
#define IIDXHOOK7_INFO_HEADER \
"iidxhook for SPADA, PENDUAL, copula and SINOBUZ" \
@@ -121,11 +124,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (!config_io.disable_io_emu) {
log_info("Starting IIDX IO backend");
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(iidx_io_set_loggers);
if (!iidx_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing IIDX IO backend failed");
}
} else {
@@ -135,11 +139,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (!config_io.disable_card_reader_emu) {
log_misc("Initializing card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
if (!eam_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing card reader backend failed");
}
} else {
@@ -203,8 +208,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
goto end;
}
- log_to_external(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+ avs_util_core_interop_log_avs_impl_set();
app_hook_init(my_dll_entry_init, my_dll_entry_main);
diff --git a/src/main/iidxhook8/Module.mk b/src/main/iidxhook8/Module.mk
index e71c8c25..faebbbb9 100644
--- a/src/main/iidxhook8/Module.mk
+++ b/src/main/iidxhook8/Module.mk
@@ -12,6 +12,8 @@ deplibs_iidxhook8 := \
avs \
libs_iidxhook8 := \
+ avs-util \
+ core \
iidxhook-d3d9 \
iidxhook-util \
acioemu \
diff --git a/src/main/iidxhook8/config-io.c b/src/main/iidxhook8/config-io.c
index 8cbb9b24..9f61e130 100644
--- a/src/main/iidxhook8/config-io.c
+++ b/src/main/iidxhook8/config-io.c
@@ -1,8 +1,8 @@
#include "cconfig/cconfig-util.h"
-#include "iidxhook8/config-io.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "iidxhook8/config-io.h"
#define IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY \
"io.disable_card_reader_emu"
diff --git a/src/main/iidxhook8/dllmain.c b/src/main/iidxhook8/dllmain.c
index 13509be4..bf1f55d9 100644
--- a/src/main/iidxhook8/dllmain.c
+++ b/src/main/iidxhook8/dllmain.c
@@ -5,11 +5,16 @@
#include
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/eamio.h"
#include "bemanitools/iidxio.h"
#include "cconfig/cconfig-hook.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "hook/d3d9.h"
#include "hooklib/acp.h"
@@ -34,9 +39,7 @@
#include "imports/avs.h"
-#include "util/log.h"
#include "util/str.h"
-#include "util/thread.h"
#define IIDXHOOK8_INFO_HEADER \
"iidxhook for Cannon Ballers/Rootage" \
@@ -131,11 +134,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
/* Start up IIDXIO.DLL */
if (!iidxhook8_config_io.disable_bio2_emu) {
log_info("Starting IIDX IO backend");
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(iidx_io_set_loggers);
if (!iidx_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing IIDX IO backend failed");
}
}
@@ -143,11 +147,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
/* Start up EAMIO.DLL */
if (!iidxhook8_config_io.disable_card_reader_emu) {
log_misc("Initializing card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
if (!eam_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing card reader backend failed");
}
}
@@ -217,8 +222,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
goto end;
}
- log_to_external(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+ avs_util_core_interop_log_avs_impl_set();
app_hook_init(my_dll_entry_init, my_dll_entry_main);
diff --git a/src/main/iidxhook9/Module.mk b/src/main/iidxhook9/Module.mk
index 30384f11..2328fdc3 100644
--- a/src/main/iidxhook9/Module.mk
+++ b/src/main/iidxhook9/Module.mk
@@ -12,6 +12,8 @@ deplibs_iidxhook9 := \
avs \
libs_iidxhook9 := \
+ avs-util \
+ core \
iidxhook-util \
acioemu \
asio \
diff --git a/src/main/iidxhook9/config-io.c b/src/main/iidxhook9/config-io.c
index ba7ff45a..34deebfb 100644
--- a/src/main/iidxhook9/config-io.c
+++ b/src/main/iidxhook9/config-io.c
@@ -1,8 +1,8 @@
#include "cconfig/cconfig-util.h"
-#include "iidxhook9/config-io.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "iidxhook9/config-io.h"
#define IIDXHOOK9_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY \
"io.disable_card_reader_emu"
diff --git a/src/main/iidxhook9/dllmain.c b/src/main/iidxhook9/dllmain.c
index b7ae85ac..ad9572d5 100644
--- a/src/main/iidxhook9/dllmain.c
+++ b/src/main/iidxhook9/dllmain.c
@@ -5,11 +5,18 @@
#include
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/eamio.h"
#include "bemanitools/iidxio.h"
#include "cconfig/cconfig-hook.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "hooklib/acp.h"
#include "hooklib/adapter.h"
#include "hooklib/app.h"
@@ -38,9 +45,7 @@
#include "imports/avs.h"
#include "util/cmdline.h"
-#include "util/log.h"
#include "util/str.h"
-#include "util/thread.h"
#define IIDXHOOK9_INFO_HEADER \
"iidxhook for Heroic Verse" \
@@ -97,6 +102,9 @@ static bool load_configs()
static bool my_dll_entry_init(char *sidcode, struct property_node *param)
{
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+
// log_server_init is required due to IO occuring in a non avs_thread
log_server_init();
@@ -124,11 +132,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
/* Start up IIDXIO.DLL */
if (!iidxhook9_config_io.disable_bio2_emu) {
log_info("Starting IIDX IO backend");
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(iidx_io_set_loggers);
if (!iidx_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing IIDX IO backend failed");
}
}
@@ -136,11 +145,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
/* Start up EAMIO.DLL */
if (!iidxhook9_config_io.disable_card_reader_emu) {
log_misc("Initializing card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
if (!eam_io_init(
- avs_thread_create, avs_thread_join, avs_thread_destroy)) {
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing card reader backend failed");
}
}
@@ -271,8 +281,8 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
// if AVS is loaded, we're likely too late to be a prehook
// so we warn the user
// and switch the current logging context to AVS so it shows up in logs
- log_to_external(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ avs_util_core_interop_log_avs_impl_set();
+
log_warning("iidxhook9 is designed to be used as a prehook");
log_warning("please ensure that it is being loaded with -B");
log_fatal("cya l8r in the prehook :3");
@@ -280,7 +290,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
// we can't log to external in DllMain (AVS) as we're a prehook
// later during my_dll_entry_init, log_server_init is called
// which sets swaps the main log write to that instead
- log_to_writer(log_writer_file, stdout);
+ core_log_bt_ext_impl_set();
}
pre_hook();
diff --git a/src/main/iidxio-bio2/Module.mk b/src/main/iidxio-bio2/Module.mk
index 09632c21..e91d76a1 100644
--- a/src/main/iidxio-bio2/Module.mk
+++ b/src/main/iidxio-bio2/Module.mk
@@ -4,6 +4,7 @@ ldflags_iidxio-bio2 := \
-lsetupapi \
libs_iidxio-bio2 := \
+ core \
aciodrv \
bio2drv \
cconfig \
diff --git a/src/main/iidxio-ezusb/Module.mk b/src/main/iidxio-ezusb/Module.mk
index ce9982c2..cc64914e 100644
--- a/src/main/iidxio-ezusb/Module.mk
+++ b/src/main/iidxio-ezusb/Module.mk
@@ -5,6 +5,7 @@ ldflags_iidxio-ezusb := \
-lsetupapi \
libs_iidxio-ezusb := \
+ core \
ezusb \
ezusb2 \
ezusb-iidx \
diff --git a/src/main/iidxio-ezusb2/Module.mk b/src/main/iidxio-ezusb2/Module.mk
index f1f19631..3371a785 100644
--- a/src/main/iidxio-ezusb2/Module.mk
+++ b/src/main/iidxio-ezusb2/Module.mk
@@ -5,6 +5,7 @@ ldflags_iidxio-ezusb2 := \
-lsetupapi \
libs_iidxio-ezusb2 := \
+ core \
ezusb2 \
ezusb \
ezusb2-iidx \
diff --git a/src/main/iidxiotest/Module.mk b/src/main/iidxiotest/Module.mk
index ce0536cf..94eca380 100644
--- a/src/main/iidxiotest/Module.mk
+++ b/src/main/iidxiotest/Module.mk
@@ -1,6 +1,7 @@
exes += iidxiotest \
libs_iidxiotest := \
+ core \
iidxio \
util \
diff --git a/src/main/iidxiotest/main.c b/src/main/iidxiotest/main.c
index ddd57cf4..a9b7daaa 100644
--- a/src/main/iidxiotest/main.c
+++ b/src/main/iidxiotest/main.c
@@ -7,8 +7,12 @@
#include "bemanitools/iidxio.h"
-#include "util/log.h"
-#include "util/thread.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log.h"
+#include "core/thread-crt-ext.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
static uint8_t _fix_top_lamps_order(uint8_t top_lamps)
{
@@ -55,12 +59,17 @@ static void _all_lights_off_shutdown()
*/
int main(int argc, char **argv)
{
- log_to_writer(log_writer_stdout, NULL);
+ core_thread_crt_ext_impl_set();
+ core_log_bt_ext_impl_set();
- iidx_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_bt_ext_init_with_stdout();
- if (!iidx_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) {
+ core_log_impl_assign(iidx_io_set_loggers);
+
+ if (!iidx_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
printf("Initializing iidxio failed\n");
return -1;
}
diff --git a/src/main/inject/Module.mk b/src/main/inject/Module.mk
index 549f1792..fd868ef4 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 724ed9ba..e8e7068c 100644
--- a/src/main/inject/debugger.c
+++ b/src/main/inject/debugger.c
@@ -8,10 +8,11 @@
#include
#include
+#include "core/log-bt.h"
+#include "core/log.h"
+
#include "inject/debugger.h"
-#include "inject/logger.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 8f63aa9c..00000000
--- 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 45a8b770..00000000
--- 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 bfb6c1be..07026dcb 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 @@ int main(int argc, char **argv)
debugger_init_fail:
verify_2_fail:
verify_fail:
- logger_finit();
+ core_log_bt_fini();
init_logger_fail:
init_options_fail:
diff --git a/src/main/jbhook-util-p3io/gfx.c b/src/main/jbhook-util-p3io/gfx.c
index 63607fd8..0574b1f0 100644
--- a/src/main/jbhook-util-p3io/gfx.c
+++ b/src/main/jbhook-util-p3io/gfx.c
@@ -9,6 +9,8 @@
#include
#include
+#include "core/log.h"
+
#include "hook/com-proxy.h"
#include "hook/table.h"
@@ -17,7 +19,6 @@
#include "jbhook-util-p3io/gfx.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/str.h"
#include "util/time.h"
diff --git a/src/main/jbhook-util-p3io/mixer.c b/src/main/jbhook-util-p3io/mixer.c
index 30dcace9..ba52a638 100644
--- a/src/main/jbhook-util-p3io/mixer.c
+++ b/src/main/jbhook-util-p3io/mixer.c
@@ -6,10 +6,11 @@
#include
// clang-format on
+#include "core/log.h"
+
#include "hook/table.h"
#include "util/defs.h"
-#include "util/log.h"
MMRESULT STDCALL hook_mixerGetLineControlsA(
HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls);
diff --git a/src/main/jbhook-util-p3io/p3io.c b/src/main/jbhook-util-p3io/p3io.c
index 25b3364f..dd04607a 100644
--- a/src/main/jbhook-util-p3io/p3io.c
+++ b/src/main/jbhook-util-p3io/p3io.c
@@ -5,6 +5,8 @@
#include "bemanitools/jbio.h"
+#include "core/log.h"
+
#include "jbhook-util-p3io/p3io.h"
#include "p3ioemu/emu.h"
@@ -13,8 +15,6 @@
#include "security/rp-sign-key.h"
#include "security/rp3.h"
-#include "util/log.h"
-
static HRESULT jbhook_p3io_read_jamma(void *ctx, uint32_t *state);
static HRESULT jbhook_p3io_get_roundplug(
void *ctx, uint8_t plug_id, uint8_t *rom, uint8_t *eeprom);
diff --git a/src/main/jbhook-util/acio.c b/src/main/jbhook-util/acio.c
index a1f5492e..8a1ed023 100644
--- a/src/main/jbhook-util/acio.c
+++ b/src/main/jbhook-util/acio.c
@@ -16,6 +16,8 @@
#include "acioemu/h44b.h"
#include "acioemu/icca.h"
+#include "core/log.h"
+
#include "hook/iohook.h"
#include "jbhook-util/acio.h"
@@ -25,7 +27,6 @@
#include "util/defs.h"
#include "util/hex.h"
#include "util/iobuf.h"
-#include "util/log.h"
#include "util/str.h"
static struct ac_io_emu ac_io_emu;
diff --git a/src/main/jbhook-util/eamuse.c b/src/main/jbhook-util/eamuse.c
index 0a796259..c9d1d906 100644
--- a/src/main/jbhook-util/eamuse.c
+++ b/src/main/jbhook-util/eamuse.c
@@ -9,10 +9,11 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "util/defs.h"
-#include "util/log.h"
#include "util/net.h"
#include "util/str.h"
diff --git a/src/main/jbhook-util/locale.c b/src/main/jbhook-util/locale.c
index 272bbc64..a6b6d17a 100644
--- a/src/main/jbhook-util/locale.c
+++ b/src/main/jbhook-util/locale.c
@@ -2,10 +2,11 @@
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "util/defs.h"
-#include "util/log.h"
// ANSI/OEM Japanese; Japanese (Shift-JIS)
#define CODEPAGE_SHIFT_JIS 932
diff --git a/src/main/jbhook-util/p4io.c b/src/main/jbhook-util/p4io.c
index ab77d5dc..824ab803 100644
--- a/src/main/jbhook-util/p4io.c
+++ b/src/main/jbhook-util/p4io.c
@@ -4,14 +4,14 @@
#include "bemanitools/jbio.h"
+#include "core/log.h"
+
#include "imports/avs.h"
#include "jbhook-util/p4io.h"
#include "p4io/cmd.h"
-#include "util/log.h"
-
static void jbhook_io_jamma2_read(void *resp, uint32_t nbytes);
static uint32_t jbhook_command_handle(
uint8_t cmd,
diff --git a/src/main/jbhook1/Module.mk b/src/main/jbhook1/Module.mk
index b5e47776..c434f217 100644
--- a/src/main/jbhook1/Module.mk
+++ b/src/main/jbhook1/Module.mk
@@ -11,6 +11,7 @@ ldflags_jbhook1 := \
-lopengl32 \
libs_jbhook1 := \
+ core \
acioemu \
cconfig \
eamio \
diff --git a/src/main/jbhook1/avs-boot.c b/src/main/jbhook1/avs-boot.c
index dccba692..62d67733 100644
--- a/src/main/jbhook1/avs-boot.c
+++ b/src/main/jbhook1/avs-boot.c
@@ -5,14 +5,15 @@
#include
#include
+#include "core/log-bt.h"
+#include "core/log.h"
+
#include "hook/table.h"
#include "imports/avs.h"
#include "jbhook1/avs-boot.h"
-#include "util/log.h"
-
static void (*real_avs_boot)(
struct property_node *config,
void *std_heap,
@@ -52,6 +53,11 @@ static const struct hook_symbol jbhook1_log_gftools_hook_syms2[] = {
.link = (void **) &real_ea3_boot},
};
+static AVS_LOG_WRITER(_avs_boot_log_writer, chars, nchars, ctx)
+{
+ core_log_bt_direct_sink_write(chars, nchars);
+}
+
static void avs_boot_create_property_str(
struct property *config, const char *name, const char *val)
{
@@ -139,7 +145,7 @@ static void my_avs_boot(
sz_std_heap,
avs_heap,
sz_avs_heap,
- log_writer_debug,
+ _avs_boot_log_writer,
NULL);
}
diff --git a/src/main/jbhook1/config-eamuse.c b/src/main/jbhook1/config-eamuse.c
index dba512eb..77170e2c 100644
--- a/src/main/jbhook1/config-eamuse.c
+++ b/src/main/jbhook1/config-eamuse.c
@@ -2,9 +2,10 @@
#include "cconfig/cconfig-util.h"
+#include "core/log.h"
+
#include "jbhook1/config-eamuse.h"
-#include "util/log.h"
#include "util/net.h"
#define JBHOOK1_CONFIG_EAMUSE_SERVER_KEY "eamuse.server"
diff --git a/src/main/jbhook1/config-gfx.c b/src/main/jbhook1/config-gfx.c
index 5215659c..10102fa7 100644
--- a/src/main/jbhook1/config-gfx.c
+++ b/src/main/jbhook1/config-gfx.c
@@ -2,9 +2,9 @@
#include "cconfig/cconfig-util.h"
-#include "jbhook1/config-gfx.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "jbhook1/config-gfx.h"
#define JBHOOK1_CONFIG_GFX_WINDOWED_KEY "gfx.windowed"
#define JBHOOK1_CONFIG_GFX_VERTICAL_KEY "gfx.vertical"
diff --git a/src/main/jbhook1/config-security.c b/src/main/jbhook1/config-security.c
index 565081e4..d6c56b05 100644
--- a/src/main/jbhook1/config-security.c
+++ b/src/main/jbhook1/config-security.c
@@ -2,11 +2,12 @@
#include "cconfig/cconfig-util.h"
+#include "core/log.h"
+
#include "jbhook1/config-security.h"
#include "security/mcode.h"
-#include "util/log.h"
#include "util/net.h"
#define JBHOOK1_CONFIG_SECURITY_MCODE_KEY "security.mcode"
diff --git a/src/main/jbhook1/dllmain.c b/src/main/jbhook1/dllmain.c
index 42f8dc9d..f058d0f3 100644
--- a/src/main/jbhook1/dllmain.c
+++ b/src/main/jbhook1/dllmain.c
@@ -10,6 +10,14 @@
#include "cconfig/cconfig-hook.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log-sink-debug.h"
+#include "core/log.h"
+#include "core/thread-crt-ext.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
+
#include "hook/table.h"
#include "hooklib/acp.h"
@@ -33,8 +41,6 @@
#include "p3ioemu/emu.h"
#include "util/defs.h"
-#include "util/log.h"
-#include "util/thread.h"
#define JBHOOK1_INFO_HEADER \
"jbhook1 for jubeat" \
@@ -89,6 +95,14 @@ static const struct hook_symbol kernel32_hook_syms[] = {
// so our CreateProcessA hook can check
static bool vertical;
+static void _jbhook1_log_init()
+{
+ core_log_bt_ext_impl_set();
+ core_log_bt_ext_init_with_debug();
+ // TODO change log level support
+ core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC);
+}
+
/**
* This seems to be a good entry point to intercept before the game calls
* anything important (very close to the start of WinMain).
@@ -153,19 +167,23 @@ static HWND CDECL my_mwindow_create(
log_info("Starting up jubeat IO backend");
- jb_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(jb_io_set_loggers);
- if (!jb_io_init(thread_create, thread_join, thread_destroy)) {
+ if (!jb_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing jb IO backend failed");
}
log_info("Starting up card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
- if (!eam_io_init(thread_create, thread_join, thread_destroy)) {
+ if (!eam_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
log_fatal("Initializing card reader backend failed");
}
@@ -201,7 +219,12 @@ static HWND CDECL my_mwindow_create(
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
if (reason == DLL_PROCESS_ATTACH) {
- log_to_writer(log_writer_debug, NULL);
+ // TODO why not use AVS threads?
+ core_thread_crt_ext_impl_set();
+
+ // TODO init debug logging but with avs available? why not use avs
+ // logging?
+ _jbhook1_log_init();
/* Bootstrap hook for further init tasks (see above) */
diff --git a/src/main/jbhook1/log-gftools.c b/src/main/jbhook1/log-gftools.c
index 97721736..f0dbf854 100644
--- a/src/main/jbhook1/log-gftools.c
+++ b/src/main/jbhook1/log-gftools.c
@@ -5,9 +5,9 @@
#include
#include
-#include "hook/table.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "hook/table.h"
static int CDECL my_GFReportPuts(
int level,
diff --git a/src/main/jbhook2/Module.mk b/src/main/jbhook2/Module.mk
index 2573867f..7ecebdb9 100644
--- a/src/main/jbhook2/Module.mk
+++ b/src/main/jbhook2/Module.mk
@@ -10,6 +10,8 @@ ldflags_jbhook2 := \
-lopengl32 \
libs_jbhook2 := \
+ avs-util \
+ core \
acioemu \
eamio \
jbio \
diff --git a/src/main/jbhook2/dllmain.c b/src/main/jbhook2/dllmain.c
index a8523ad9..4c06e4dc 100644
--- a/src/main/jbhook2/dllmain.c
+++ b/src/main/jbhook2/dllmain.c
@@ -5,9 +5,14 @@
#include
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/eamio.h"
#include "bemanitools/jbio.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "hook/iohook.h"
#include "hook/table.h"
@@ -36,8 +41,6 @@
#include "security/mcode.h"
#include "util/defs.h"
-#include "util/log.h"
-#include "util/thread.h"
static struct options options;
@@ -80,11 +83,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
log_info("Starting up jubeat IO backend");
- jb_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(jb_io_set_loggers);
- jb_io_ok =
- jb_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
+ jb_io_ok = jb_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
if (!jb_io_ok) {
goto fail;
@@ -99,11 +103,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
log_info("Starting up card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
- eam_io_ok =
- eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
+ eam_io_ok = eam_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
if (!eam_io_ok) {
goto fail;
@@ -224,8 +229,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
return TRUE;
}
- log_to_external(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+ avs_util_core_interop_log_avs_impl_set();
options_init_from_cmdline(&options);
diff --git a/src/main/jbhook2/options.c b/src/main/jbhook2/options.c
index 9e1987e4..63ee6d45 100644
--- a/src/main/jbhook2/options.c
+++ b/src/main/jbhook2/options.c
@@ -9,7 +9,7 @@
#include "util/cmdline.h"
#include "util/defs.h"
#include "util/hex.h"
-#include "util/log.h"
+
#include "util/str.h"
void options_init_from_cmdline(struct options *options)
diff --git a/src/main/jbhook3/Module.mk b/src/main/jbhook3/Module.mk
index a82c4cc9..ca36a439 100644
--- a/src/main/jbhook3/Module.mk
+++ b/src/main/jbhook3/Module.mk
@@ -8,6 +8,8 @@ ldflags_jbhook3 := \
-liphlpapi \
libs_jbhook3 := \
+ avs-util \
+ core \
acioemu \
eamio \
jbio \
diff --git a/src/main/jbhook3/dllmain.c b/src/main/jbhook3/dllmain.c
index b4eada83..30a0eb3d 100644
--- a/src/main/jbhook3/dllmain.c
+++ b/src/main/jbhook3/dllmain.c
@@ -5,9 +5,14 @@
#include
#include
+#include "avs-util/core-interop.h"
+
#include "bemanitools/eamio.h"
#include "bemanitools/jbio.h"
+#include "core/log.h"
+#include "core/thread.h"
+
#include "hook/iohook.h"
#include "hook/table.h"
@@ -31,8 +36,6 @@
#include "security/id.h"
#include "util/defs.h"
-#include "util/log.h"
-#include "util/thread.h"
static struct options options;
@@ -62,11 +65,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (!options.disable_p4ioemu) {
log_info("Starting up jubeat IO backend");
- jb_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(jb_io_set_loggers);
- jb_io_ok =
- jb_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
+ jb_io_ok = jb_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
if (!jb_io_ok) {
goto fail;
@@ -79,11 +83,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (!options.disable_cardemu) {
log_info("Starting up card reader backend");
- eam_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_impl_assign(eam_io_set_loggers);
- eam_io_ok =
- eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
+ eam_io_ok = eam_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get());
if (!eam_io_ok) {
goto fail;
@@ -143,8 +148,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
return TRUE;
}
- log_to_external(
- log_body_misc, log_body_info, log_body_warning, log_body_fatal);
+ // Use AVS APIs
+ avs_util_core_interop_thread_avs_impl_set();
+ avs_util_core_interop_log_avs_impl_set();
options_init_from_cmdline(&options);
diff --git a/src/main/jbhook3/gfx.c b/src/main/jbhook3/gfx.c
index ee3b5ff5..827ac55f 100644
--- a/src/main/jbhook3/gfx.c
+++ b/src/main/jbhook3/gfx.c
@@ -5,12 +5,12 @@
#include
#include
+#include "core/log.h"
+
#include "hook/table.h"
#include "jbhook3/options.h"
-#include "util/log.h"
-
static bool jbhook3_gfx_windowed;
static bool jbhook3_gfx_show_cursor;
diff --git a/src/main/jbhook3/options.c b/src/main/jbhook3/options.c
index 59ffc1eb..8bb544b8 100644
--- a/src/main/jbhook3/options.c
+++ b/src/main/jbhook3/options.c
@@ -6,10 +6,11 @@
#include
#include
+#include "core/log.h"
+
#include "util/cmdline.h"
#include "util/defs.h"
#include "util/hex.h"
-#include "util/log.h"
#include "util/str.h"
void options_init_from_cmdline(struct options *options)
diff --git a/src/main/jbio-p4io/Module.mk b/src/main/jbio-p4io/Module.mk
index b31604df..ca9895e3 100644
--- a/src/main/jbio-p4io/Module.mk
+++ b/src/main/jbio-p4io/Module.mk
@@ -9,6 +9,7 @@ src_jbio-p4io := \
jbio.c \
libs_jbio-p4io := \
+ core \
aciodrv \
aciomgr \
cconfig \
diff --git a/src/main/jbio-p4io/config-h44b.c b/src/main/jbio-p4io/config-h44b.c
index 91d37cb8..98a5f4f2 100644
--- a/src/main/jbio-p4io/config-h44b.c
+++ b/src/main/jbio-p4io/config-h44b.c
@@ -1,8 +1,8 @@
#include "cconfig/cconfig-util.h"
-#include "jbio-p4io/config-h44b.h"
+#include "core/log.h"
-#include "util/log.h"
+#include "jbio-p4io/config-h44b.h"
#define JBIO_CONFIG_H44B_PORT_KEY "h44b.port"
#define JBIO_CONFIG_H44B_BAUD_KEY "h44b.baud"
diff --git a/src/main/jbio-p4io/h44b.c b/src/main/jbio-p4io/h44b.c
index 1d9b77a0..f26aa2a1 100644
--- a/src/main/jbio-p4io/h44b.c
+++ b/src/main/jbio-p4io/h44b.c
@@ -10,7 +10,7 @@
#include "aciomgr/manager.h"
-#include "util/log.h"
+#include "core/log.h"
static int16_t h44b_node_id;
diff --git a/src/main/jbio-p4io/jbio.c b/src/main/jbio-p4io/jbio.c
index 202187fe..58f4db9a 100644
--- a/src/main/jbio-p4io/jbio.c
+++ b/src/main/jbio-p4io/jbio.c
@@ -7,17 +7,17 @@
#include "aciomgr/manager.h"
+#include "bemanitools/jbio.h"
+
#include "cconfig/cconfig-main.h"
-#include "bemanitools/jbio.h"
+#include "core/log.h"
#include "jbio-p4io/config-h44b.h"
#include "jbio-p4io/h44b.h"
#include "p4iodrv/device.h"
-#include "util/log.h"
-
static struct p4iodrv_ctx *p4io_ctx;
static uint16_t jb_io_panels;
static uint8_t jb_io_sys_buttons;
@@ -36,7 +36,7 @@ void jb_io_set_loggers(
{
aciomgr_set_loggers(misc, info, warning, fatal);
- log_to_external(misc, info, warning, fatal);
+ core_log_impl_set(misc, info, warning, fatal);
}
bool jb_io_init(
diff --git a/src/main/jbiotest/Module.mk b/src/main/jbiotest/Module.mk
index f2cf618b..eba9c0b1 100644
--- a/src/main/jbiotest/Module.mk
+++ b/src/main/jbiotest/Module.mk
@@ -1,6 +1,7 @@
exes += jbiotest \
libs_jbiotest := \
+ core \
jbio \
util \
diff --git a/src/main/jbiotest/main.c b/src/main/jbiotest/main.c
index 416b3251..0a6270b4 100644
--- a/src/main/jbiotest/main.c
+++ b/src/main/jbiotest/main.c
@@ -7,8 +7,12 @@
#include "bemanitools/jbio.h"
-#include "util/log.h"
-#include "util/thread.h"
+#include "core/log-bt-ext.h"
+#include "core/log-bt.h"
+#include "core/log.h"
+#include "core/thread-crt-ext.h"
+#include "core/thread-crt.h"
+#include "core/thread.h"
typedef struct {
uint8_t r, g, b;
@@ -23,12 +27,17 @@ enum jbio_light_mode { LIGHTS_OFF, LIGHTS_ON, LIGHTS_INPUT };
*/
int main(int argc, char **argv)
{
- log_to_writer(log_writer_stdout, NULL);
+ core_thread_crt_ext_impl_set();
+ core_log_bt_ext_impl_set();
- jb_io_set_loggers(
- log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
+ core_log_bt_ext_init_with_stdout();
- if (!jb_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) {
+ core_log_impl_assign(jb_io_set_loggers);
+
+ if (!jb_io_init(
+ core_thread_create_impl_get(),
+ core_thread_join_impl_get(),
+ core_thread_destroy_impl_get())) {
printf("Initializing jbio failed\n");
return -1;
}
diff --git a/src/main/launcher/Module.mk b/src/main/launcher/Module.mk
index c9dfd078..39daace5 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 00000000..8669f3d4
--- /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 00000000..692643d3
--- /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 1e391db1..00000000
--- 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 d4532eb4..00000000
--- 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 00000000..4ff0730a
--- /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 00000000..ad2233ac
--- /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 00000000..35915c65
--- /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 00000000..596bf93f
--- /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 00000000..a9e52bbe
--- /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 00000000..4deab8f2
--- /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 00000000..2f40e338
--- /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 00000000..f57ca8ba
--- /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 684ba466..00000000
--- 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 ada44008..00000000
--- 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 00000000..e8c5c4ff
--- /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 00000000..1a6dc7f2
--- /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 00000000..020e17a9
--- /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 00000000..2cba227a
--- /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 00000000..39e560d7
--- /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 00000000..1cd1f7e7
--- /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 00000000..d7be37a7
--- /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 00000000..9d0c5d42
--- /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 00000000..c71abe56
--- /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 00000000..7d6b8a6e
--- /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 00000000..60f32cf2
--- /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 00000000..da1995cc
--- /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 70c5184d..4b1b68a0 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;
- }
-
- /* 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 */
-
- 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);
+ exit(EXIT_FAILURE);
}
- /* 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);
- }
+ launcher_main(&options);
- 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 b3beff26..c0b9ef4f 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 @@ static bool module_replace_dll_iat(HMODULE hModule, struct array *iat_hook_dlls)
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 f2a851eb..ed9b7327 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 757555ec..e116849e 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);
-
- options->override_service = NULL;
- options->override_urlslash_enabled = false;
- options->override_urlslash_value = false;
+ memset(options, 0, sizeof(struct options));
+
+ array_init(&options->hook.hook_dlls);
+ array_init(&options->hook.before_hook_dlls);
+ array_init(&options->hook.iat_hook_dlls);
}
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':
- if (i + 1 >= argc) {
- return false;
- }
-
- options->app_config_path = argv[++i];
-
- break;
-
- case 'E':
+ case 'T':
if (i + 1 >= argc) {
return false;
}
- options->ea3_config_path = argv[++i];
+ options->bootstrap.config_path = argv[++i];
break;
- case 'V':
+ case 'Z':
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,70 +70,65 @@ 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;
- }
+ *array_append(const char *, &options->hook.hook_dlls) =
+ argv[++i];
break;
-#ifdef AVS_HAS_STD_HEAP
- case 'T':
+ case 'B':
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;
- }
+ *array_append(
+ const char *, &options->hook.before_hook_dlls) =
+ argv[++i];
break;
-#endif
- case 'K':
+ case 'I': {
if (i + 1 >= argc) {
return false;
}
- *array_append(const char *, &options->hook_dlls) =
- argv[++i];
+ const char *dll = argv[++i];
+ log_assert(strstr(dll, "=") != NULL);
+
+ *array_append(const char *, &options->hook.iat_hook_dlls) =
+ dll;
break;
+ }
- case 'B':
+ case 'L':
if (i + 1 >= argc) {
return false;
}
- *array_append(const char *, &options->before_hook_dlls) =
- argv[++i];
+ long tmp = strtol(argv[++i], NULL, 0);
- break;
-
- case 'I': {
- if (i + 1 >= argc) {
+ if (tmp < CORE_LOG_BT_LOG_LEVEL_OFF ||
+ tmp > CORE_LOG_BT_LOG_LEVEL_MISC) {
return false;
}
- const char *dll = argv[++i];
- log_assert(strstr(dll, "=") != NULL);
-
- *array_append(const char *, &options->iat_hook_dlls) = dll;
+ 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 13f1c0fb..c0bdfaf2 100644
--- a/src/main/launcher/options.h
+++ b/src/main/launcher/options.h
@@ -4,25 +4,53 @@
#include
#include