diff options
Diffstat (limited to 'src/hud.c')
-rw-r--r-- | src/hud.c | 31 |
1 files changed, 21 insertions, 10 deletions
@@ -1,5 +1,6 @@ /* * Copyright © 2022 Matthew Wozniak <sirtomato999@gmail.com> + * Copyright © 2024 Michael Smith <mikesmiffy128@gmail.com> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,6 +24,7 @@ #include "hook.h" #include "hud.h" #include "intdefs.h" +#include "langext.h" #include "mem.h" #include "os.h" #include "sst.h" @@ -79,10 +81,12 @@ DECL_VFUNC_DYN(void, DrawPolyLine, int *, int *, int) DECL_VFUNC_DYN(void, DrawSetTextFont, struct handlewrap) DECL_VFUNC_DYN(void, DrawSetTextColor, struct rgba) DECL_VFUNC_DYN(void, DrawSetTextPos, int, int) -DECL_VFUNC_DYN(void, DrawPrintText, ushort *, int, int) +DECL_VFUNC_DYN(void, DrawPrintText, hud_wchar *, int, int) DECL_VFUNC_DYN(void, GetScreenSize, int *, int *) DECL_VFUNC_DYN(int, GetFontTall, struct handlewrap) DECL_VFUNC_DYN(int, GetCharacterWidth, struct handlewrap, int) +DECL_VFUNC_DYN(int, GetTextSize, struct handlewrap, const hud_wchar *, + int *, int *) // vgui::Panel DECL_VFUNC_DYN(void, SetPaintEnabled, bool) @@ -92,7 +96,10 @@ static void *matsurf, *toolspanel, *scheme; typedef void (*VCALLCONV Paint_func)(void *); static Paint_func orig_Paint; void VCALLCONV hook_Paint(void *this) { - if (this == toolspanel) EMIT_HudPaint(); + // hopefully a smart branch predictor can figure this out - but we still + // want it to be the "slow" path, so that every other path does *not* need a + // prediction record. or.. I dunno, in theory that does make sense. shrug. + if_cold (this == toolspanel) EMIT_HudPaint(); orig_Paint(this); } @@ -117,7 +124,7 @@ void hud_drawpolyline(int *x, int *y, int npoints, struct rgba colour) { DrawPolyLine(matsurf, x, y, npoints); } -void hud_drawtext(ulong font, int x, int y, struct rgba colour, ushort *str, +void hud_drawtext(ulong font, int x, int y, struct rgba colour, hud_wchar *str, int len) { DrawSetTextFont(matsurf, (struct handlewrap){font}); DrawSetTextPos(matsurf, x, y); @@ -133,10 +140,14 @@ int hud_fontheight(ulong font) { return GetFontTall(matsurf, (struct handlewrap){font}); } -int hud_charwidth(ulong font, int ch) { +int hud_charwidth(ulong font, hud_wchar ch) { return GetCharacterWidth(matsurf, (struct handlewrap){font}, ch); } +void hud_textsize(ulong font, const ushort *s, int *width, int *height) { + GetTextSize(matsurf, (struct handlewrap){font}, s, width, height); +} + static bool find_toolspanel(void *enginevgui) { const uchar *insns = (const uchar *)VFUNC(enginevgui, GetPanel); for (const uchar *p = insns; p - insns < 16;) { @@ -156,21 +167,21 @@ static bool find_toolspanel(void *enginevgui) { INIT { matsurf = factory_engine("MatSystemSurface006", 0); - if (!matsurf) { + if_cold (!matsurf) { errmsg_errorx("couldn't get MatSystemSurface006 interface"); return false; } void *schememgr = factory_engine("VGUI_Scheme010", 0); - if (!schememgr) { + if_cold (!schememgr) { errmsg_errorx("couldn't get VGUI_Scheme010 interface"); return false; } - if (!find_toolspanel(vgui)) { + if_cold (!find_toolspanel(vgui)) { errmsg_errorx("couldn't find engine tools panel"); return false; } void **vtable = *(void ***)toolspanel; - if (!os_mprot(vtable + vtidx_Paint, sizeof(void *), + if_cold (!os_mprot(vtable + vtidx_Paint, sizeof(void *), PAGE_READWRITE)) { errmsg_errorsys("couldn't make virtual table writable"); return false; @@ -184,8 +195,8 @@ INIT { } END { - // don't unhook toolspanel if exiting, it's already long gone! - if (sst_userunloaded) { + // don't unhook toolspanel if exiting: it's already long gone! + if_cold (sst_userunloaded) { unhook_vtable(*(void ***)toolspanel, vtidx_Paint, (void *)orig_Paint); SetPaintEnabled(toolspanel, false); } |