From 3bd1d7338c735dfc4117fc6b787d22defffb4393 Mon Sep 17 00:00:00 2001 From: KIT! Date: Wed, 24 Apr 2024 14:27:27 +0200 Subject: [PATCH] Fixed an off-by-one error and config loading for reader name Reading card 3 and above resulted in an off by one error that always threw a "this line isn't X bytes long" error. Readername now always gets properly loaded from config : I've added comments in the config file to make it obvious what each line does but that fucked up the reader name config. i'm now discarding the comment after loading the line. Updated readme.md --- meson.build | 2 +- readme.md | 10 ++++++---- src/aimeio.c | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 9f05687..e728d63 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project( 'aimeio_scard', 'c', - version : '0.0.2' + version : '0.4.0' ) inc = include_directories('.') diff --git a/readme.md b/readme.md index ec03a10..a87ff8c 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,8 @@ This allows you to a smartcard reader (specifically the acr122u) with segatools +**This has only been confirmed working with Chunithm Sun and Sun + so far. Luminous doesn't seem to work yet !** + # Acknowledgments This is a plugin destined to be used with [Dniel97](https://gitea.tendokyu.moe/Dniel97)'s [segatools fork](https://gitea.tendokyu.moe/Dniel97/segatools) (but should work on others too). @@ -26,9 +28,9 @@ scan=0x0D ;Sets the key which will be used to insert a card in game. Th ;Everything below this line is optional. -;readerOptional=1 ;Make reader optional, so that you can still use the keyboard -;readerName="ACS ACR122 0" ;Manually select which reader to use -;disableBuzzer=0 ;Disable the buzzer +readerOptional=1 ;Make reader optional, so that you can still use the keyboard +readerName=ACS ACR122 0 ;Manually select which reader to use +disableBuzzer=1 ;Disable the buzzer ;aimePath="" ;Manually specify an aime.txt file ;felicaPath="" ;Manually specify a felica.txt file ;debug=0 ;Display function calls @@ -67,4 +69,4 @@ To build this, you'll need two things : - [Meson 1.1.0](https://mesonbuild.com) - [Build Tools pour Visual Studio 2022](https://visualstudio.microsoft.com/fr/downloads/) -Once you've edited your build64.bat file to point to your local installation of the VS2022 build tools, run build64.bat and the output will be located in `bin/aime.dll`. \ No newline at end of file +Once you've edited your build64.bat file to point to your local installation of the VS2022 build tools, run build64.bat and the output will be located in `bin/aime.dll`. diff --git a/src/aimeio.c b/src/aimeio.c index 3cad94e..3d6d3f1 100644 --- a/src/aimeio.c +++ b/src/aimeio.c @@ -9,6 +9,27 @@ static struct aime_io_config aime_io_cfg; static struct card_data card_data; #pragma region CONFIG +// This is used because otherwise loading a reader with a given name while keeping the comment inline in the config file fails.. +void RemoveCommentAndTruncate(wchar_t *value) +{ + size_t len = wcslen(value); + wchar_t *semicolon = NULL; + + // Remove comments + semicolon = wcschr(value, L';'); + if (semicolon != NULL) + { + *semicolon = L'\0'; + len = wcslen(value); + } + + // Trim trailing whitespaces + while (len > 0 && (value[len - 1] == L' ' || value[len - 1] == L'\t' || value[len - 1] == L'\r' || value[len - 1] == L'\n')) + { + value[--len] = L'\0'; + } +} + static void aime_io_config_read(struct aime_io_config *cfg, const wchar_t *filename) { assert(cfg != NULL); @@ -43,6 +64,7 @@ static void aime_io_config_read(struct aime_io_config *cfg, const wchar_t *filen cfg->reader_name, _countof(cfg->reader_name), filename); + RemoveCommentAndTruncate(cfg->reader_name); cfg->reader_optional = GetPrivateProfileIntW( L"aimeio", @@ -95,7 +117,10 @@ static HRESULT aime_io_read_id_file(const wchar_t *path, uint8_t *bytes, size_t } if (c == '\n') + { currentLine++; + offset++; + } offset++; }