diff --git a/README.md b/README.md index 93b007b..0d5375b 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,10 @@ for translation or other purposes. The available modes are: - `print`: Print the captured text to the console. - `copy`: Copy the captured text to the clipboard. +#### `-texthook_suppress` _list_ +Suppress text hook on specified scenario pages. _list_ is a comma-separated list +of page numbers. + #### `-game` _game_id_ As System1-3 have slight variations depending on the game, `system3` uses the fingerprint of the scenario file (ADISK.DAT) to identify the game being played. diff --git a/src/config.cpp b/src/config.cpp index 66ef025..726471d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -137,6 +137,8 @@ Config::Config(int argc, char *argv[]) scanline = true; else if (strcmp(argv[i], "-texthook") == 0) texthook_mode = parse_texthook_mode(argv[++i]); + else if (strcmp(argv[i], "-texthook_suppress") == 0) + texthook_suppressions = argv[++i]; } } @@ -197,6 +199,8 @@ void Config::load_ini() scanline = to_bool(val, lineno); else if (!strcasecmp(key, "texthook")) texthook_mode = parse_texthook_mode(val, lineno); + else if (!strcasecmp(key, "texthook_suppress")) + texthook_suppressions = val; else WARNING(INIFILENAME ":%d unknown key '%s'", lineno, key); } else if (current_section == STRING) { diff --git a/src/config.h b/src/config.h index a88b6f6..748f42c 100644 --- a/src/config.h +++ b/src/config.h @@ -34,6 +34,7 @@ struct Config { bool no_antialias = false; bool scanline = false; TexthookMode texthook_mode = TEXTHOOK_NONE; + std::string texthook_suppressions; private: void load_ini(); diff --git a/src/sdlmain.cpp b/src/sdlmain.cpp index 11f61eb..5396ed8 100644 --- a/src/sdlmain.cpp +++ b/src/sdlmain.cpp @@ -98,6 +98,7 @@ int main(int argc, char *argv[]) #endif texthook_set_mode(config.texthook_mode); + texthook_set_suppression_list(config.texthook_suppressions.c_str()); int exit_code = NACT_RESTART; while (exit_code == NACT_RESTART) { diff --git a/src/texthook.cpp b/src/texthook.cpp index 1f52807..3a783f0 100644 --- a/src/texthook.cpp +++ b/src/texthook.cpp @@ -1,5 +1,8 @@ #include +#include #include +#include +#include #include #include "texthook.h" @@ -129,6 +132,12 @@ private: } copy; TextHookHandler *handler = &none; +std::unordered_set suppression_set; +enum { + INIT, + SUPPRESSING, + EMITTING, +} suppression_state = INIT; } // namespace @@ -146,20 +155,42 @@ void texthook_set_mode(TexthookMode mode) { } } +// suppressions is a comma-separated list of page numbers to suppress. +void texthook_set_suppression_list(const char *suppressions) { + suppression_set.clear(); + if (!suppressions || !*suppressions) + return; + + char *buf = strdup(suppressions); + char *token = strtok(buf, ","); + while (token) { + suppression_set.insert(atoi(token)); + token = strtok(NULL, ","); + } + free(buf); +} + void texthook_character(int page, int c) { + if (suppression_state == INIT) + suppression_state = suppression_set.count(page) ? SUPPRESSING : EMITTING; + if (suppression_state == SUPPRESSING) + return; handler->character(page, c); } void texthook_newline(void) { handler->newline(); + suppression_state = INIT; } void texthook_nextpage(void) { handler->nextpage(); + suppression_state = INIT; } void texthook_keywait(void) { handler->keywait(); + suppression_state = INIT; } #endif diff --git a/src/texthook.h b/src/texthook.h index 5f4be6c..2ebbc73 100644 --- a/src/texthook.h +++ b/src/texthook.h @@ -10,6 +10,7 @@ enum TexthookMode { }; void texthook_set_mode(TexthookMode mode); +void texthook_set_suppression_list(const char *suppressions); void texthook_character(int page, int character); void texthook_newline(void); void texthook_nextpage(void); diff --git a/system3.ini.example b/system3.ini.example index f63189a..0e9fa75 100644 --- a/system3.ini.example +++ b/system3.ini.example @@ -41,6 +41,11 @@ title = Rance 4.1 ~Save the Medicine Plant!~ ; copy : Automatically copy text to clipboard (for use with text hooker tools) texthook = none +; Suppress text hook on specified scenario pages. +; The value is a comma-separated list of page numbers. +; The example below is for Rance 4.1, to filter out system messages. +;texthook_suppress = 2,7 + ; The [string] section allows you to override Japanese text embedded in the ; game engine. The values below are the original Japanese text. [string]