19 TracedEditBox(RiseDialog& hud,
int dialogId, Logger& logger)
20 : RiseEditBox(&hud), dialogId(dialogId), logger(logger)
25 void OnFocusIn()
override
27 const bool hadFocus = m_bHasFocus;
30 LogInputState(
"focus gained");
33 void OnFocusOut()
override
35 const bool hadFocus = m_bHasFocus;
38 LogInputState(
"focus lost");
41 void SetVisible(
bool visible)
override
43 const bool wasVisible = m_bVisible;
45 if (wasVisible != visible)
46 LogInputState(visible ?
"shown" :
"hidden");
49 bool MsgProc(UINT message, WPARAM key, LPARAM flags)
override
51 if (message == WM_CHAR && key == VK_RETURN)
52 LogInputState(
"Enter offered to edit control");
57 void Render(
float elapsedTime)
override
60 std::snprintf(message,
sizeof message,
"HUD %d edit %d Inspect v%d focus%d ptr%p",
61 dialogId, GetID(), m_bVisible, m_bHasFocus,
static_cast<void*
>(
this));
62 logger.AddToCallStack(message);
65 std::snprintf(message,
sizeof message,
"HUD %d edit %d caret%d sel%d first%d len%d",
66 dialogId, GetID(), m_nCaret, m_nSelStart, m_nFirstVisible, GetTextLength());
67 logger.AddToCallStack(message);
68 std::snprintf(message,
sizeof message,
"HUD %d edit %d size%dx%d elements%d buffer%p",
69 dialogId, GetID(), m_width, m_height, m_Elements.GetSize(),
70 static_cast<const void*
>(GetText()));
71 logger.AddToCallStack(message);
73 std::snprintf(message,
sizeof message,
"HUD %d edit %d Render", dialogId, GetID());
74 logger.AddToCallStack(message);
76 std::snprintf(message,
sizeof message,
"HUD %d edit %d Render DONE", dialogId, GetID());
77 logger.AddToCallStack(message);
82 void LogInputState(
const char* event)
85 std::snprintf(message,
sizeof message,
86 "ChatInput: %s dialog=%d control=%d visible=%d enabled=%d focus=%d",
87 event, dialogId, GetID(), m_bVisible, m_bEnabled, m_bHasFocus);
96 int RecordNativeException(EXCEPTION_POINTERS* exception,
int dialogId,
Logger& logger)
98 const EXCEPTION_RECORD& record = *exception->ExceptionRecord;
100 if (record.ExceptionCode == 0xe06d7363 || record.ExceptionCode == EXCEPTION_BREAKPOINT ||
101 record.ExceptionCode == EXCEPTION_SINGLE_STEP)
102 return EXCEPTION_CONTINUE_SEARCH;
105 std::snprintf(message,
sizeof message,
"HUD %d native exception 0x%08lX at %p",
106 dialogId, record.ExceptionCode, record.ExceptionAddress);
110 HMODULE module =
nullptr;
111 if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
112 reinterpret_cast<LPCSTR
>(record.ExceptionAddress), &module))
114 char modulePath[MAX_PATH] = {};
115 GetModuleFileNameA(module, modulePath, MAX_PATH);
116 modulePath[MAX_PATH - 1] =
'\0';
117 const char* moduleName = strrchr(modulePath,
'\\');
118 std::snprintf(message,
sizeof message,
"HUD fault module %s base %p RVA 0x%llX",
119 moduleName ? moduleName + 1 : modulePath,
static_cast<void*
>(module),
120 static_cast<unsigned long long>(
reinterpret_cast<std::uintptr_t
>(record.ExceptionAddress) -
121 reinterpret_cast<std::uintptr_t
>(module)));
124 if ((record.ExceptionCode == EXCEPTION_ACCESS_VIOLATION || record.ExceptionCode == EXCEPTION_IN_PAGE_ERROR) &&
125 record.NumberParameters >= 2)
127 std::snprintf(message,
sizeof message,
"HUD fault access %llu (0=read 1=write 8=execute) address %p",
128 static_cast<unsigned long long>(record.ExceptionInformation[0]),
129 reinterpret_cast<void*
>(record.ExceptionInformation[1]));
134 return EXCEPTION_CONTINUE_SEARCH;
140 std::snprintf(message,
sizeof message,
"HUD %d Inspect resources", dialogId);
143 std::snprintf(message,
sizeof message,
"HUD %d manager%p device%p", dialogId,
144 static_cast<void*
>(manager), manager ?
static_cast<void*
>(manager->
GetRenderer()) :
nullptr);
146 std::snprintf(message,
sizeof message,
"HUD %d sprite%p state%p", dialogId,
147 manager ?
static_cast<void*
>(manager->
m_pSprite) :
nullptr,
148 manager ?
static_cast<void*
>(manager->
m_pStateBlock) :
nullptr);
150 std::snprintf(message,
sizeof message,
"HUD %d visible%d minimized%d foreground%d dt%.4f", dialogId,
153 std::snprintf(message,
sizeof message,
"HUD %d OnRender", dialogId);
156 std::snprintf(message,
sizeof message,
"HUD %d OnRender DONE hr%08lX", dialogId, result);
163bool HudDiagnostics::IsEnterMessage(UINT message, WPARAM key)
165 return key == VK_RETURN &&
166 (message == WM_KEYDOWN || message == WM_KEYUP || message == WM_CHAR ||
167 message == WM_SYSKEYDOWN || message == WM_SYSKEYUP || message == WM_SYSCHAR);
170void HudDiagnostics::LogChatInput(
HMI& gui,
const char* event,
int handledByDialog)
173 std::snprintf(message,
sizeof message,
174 "ChatInput: %s stage=%d textMode=%d editing=%d edited=%d hover=%d leftClick=%d foreground=%d handledByDialog=%d",
175 event,
static_cast<int>(
gui.game->displaystage),
static_cast<int>(
g_bTextInput),
176 gui.Editing,
gui.Edited,
gui.cursoroverwindow,
gui.g_bLeftClick,
178 gui.game->logger->Log(message);
188 dialog->editline == -1 && dialog->editfield == -1 && dialog->edittab == -1))
190 std::snprintf(message,
sizeof message,
191 "ChatInput: dialog=%d active=%d minimized=%d layer=%d editLine=%ld editField=%ld editTab=%ld "
192 "hudVisible=%d hudMinimized=%d keyboard=%d position=%.0f,%.0f size=%d,%d",
193 id, dialog->active, dialog->minimized, dialog->layer, dialog->editline,
194 dialog->editfield, dialog->edittab, dialog->HUD.GetVisible(), dialog->HUD.GetMinimized(),
195 dialog->HUD.IsKeyboardInputEnabled(), dialog->windowlocation.x, dialog->windowlocation.y,
196 dialog->width, dialog->height);
197 gui.game->logger->Log(message);
200 auto* control = dialog->HUD.GetEditBox(controlId);
203 std::snprintf(message,
sizeof message,
204 "ChatInput: dialog=%d control=%d visible=%d enabled=%d focus=%d",
205 id, controlId, control->GetVisible(), control->GetEnabled(), control->m_bHasFocus);
206 gui.game->logger->Log(message);
216 return RenderWithBreadcrumbs(hud, elapsedTime, dialogId, logger);
218 __except (RecordNativeException(GetExceptionInformation(), dialogId, logger))
226 auto* edit =
new (std::nothrow) TracedEditBox(hud, dialogId, logger);
228 return E_OUTOFMEMORY;
236 edit->SetID(controlId);
237 edit->SetLocation(1, 1);
239 edit->m_bIsDefault = isDefault;
240 edit->m_bIsPassword =
false;
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
static constexpr std::size_t EntrySize
static DialogBase * dialogs[D_ENUMERATION]
void Log(const char *msg, Level level=Info, int errorCode=0)
void AddToCallStack(const char *msg)
virtual void OnFocusOut()
virtual void SetVisible(bool bVisible)
HRESULT OnRender(float fElapsedTime)
HRESULT AddControl(RiseControl *pControl)
RiseDialogResourceManager * GetManager()
Rendering::RenderDevice * GetRenderer()
Rendering::RenderSprite * m_pSprite
Rendering::RenderStateSnapshot * m_pStateBlock
virtual void Render(float fElapsedTime)
virtual bool MsgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
HRESULT Render(RiseDialog &hud, float elapsedTime, int dialogId, Logger &logger)
HRESULT AddEditBox(RiseDialog &hud, int dialogId, int controlId, bool isDefault, Logger &logger)