From e25081952acd2e6ff40af1390f6a8de71de8a6a3 Mon Sep 17 00:00:00 2001 From: Hayden K Date: Thu, 29 May 2025 17:29:21 -0400 Subject: Fix OE dropping coloured logs early in startup Not perfect, because if something fails extremely early, we won't see it, but that'll never be fully solvable. This is good enough to see what features succeed and fail in normal autoload conditions where we don't expect the plugin to blow up immediately. --- src/con_.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/con_.c') diff --git a/src/con_.c b/src/con_.c index 896faea..c316318 100644 --- a/src/con_.c +++ b/src/con_.c @@ -610,8 +610,28 @@ bool con_detect(int pluginver) { return false; } +static int *find_host_initialized() { + const uchar *insns = colourmsgf; + for (const uchar *p = insns; p - insns < 32;) { + // cmp byte ptr [], + if (p[0] == X86_ALUMI8 && p[1] == X86_MODRM(0, 7, 5)) { + return mem_loadptr(p + 2); + } + NEXT_INSN(p, "host_initialized variable"); + } + return 0; +} + void con_init() { - if (!GAMETYPE_MATCHES(OE)) { + if (GAMETYPE_MATCHES(OE)) { + // if we're autoloaded, we have to set host_initialized early or colour + // log output (including error output!) won't be visible, for some inane + // reason. *as far as we know* this doesn't have any bad side effects. + // note: if this fails, too bad. not like we can log a warning. + int *host_initialized = find_host_initialized(); + if (host_initialized && *host_initialized == 0) *host_initialized = 1; + } + else { colourmsgf = coniface->vtable[vtidx_ConsoleColorPrintf]; dllid = AllocateDLLIdentifier(coniface); } -- cgit v1.2.3-54-g00ecf