diff --git a/Source/Client/Application/ApplicationActivation.cpp b/Source/Client/Application/ApplicationActivation.cpp index 9f7606af..d9457415 100644 --- a/Source/Client/Application/ApplicationActivation.cpp +++ b/Source/Client/Application/ApplicationActivation.cpp @@ -1,19 +1,23 @@ #include "Client/Application/ApplicationActivation.h" #include "Client/Application/ApplicationWindow.h" +#include "Client/Mode/CLoginMode.h" +#include "Client/Session.h" #include "Contents/Configuration/ServiceOptions.h" +#include "Contents/Skills/AutomaticSkills.h" +#include "UI/GameSettings/GameSettingsUI.h" // OFFSET: 0x00E5A190 // FUNCTION: fn_24369 -void ApplicationActivation::Set(int value) { - this->active = value; +void SetApplicationActive(int value) { + g_isAppActive = value; if (value != 0) { - SetPriorityClass(GetCurrentProcess(), this->priority); - if (this->service.Get(ServiceOption::ConfineCursor) != 0) { - ClipApplicationCursor(this->window); + SetPriorityClass(GetCurrentProcess(), dwPriorityClass); + if (g_serviceOptions.Get(ServiceOption::ConfineCursor) != 0) { + ClipApplicationCursor(hWnd); } } else { SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); ClipCursor(nullptr); - this->automaticSkills.DisableAll(); + reinterpret_cast(g_session.unknown_7FB4)->DisableAll(); } } diff --git a/Source/Client/Application/ApplicationActivation.h b/Source/Client/Application/ApplicationActivation.h index dd910963..d442deca 100644 --- a/Source/Client/Application/ApplicationActivation.h +++ b/Source/Client/Application/ApplicationActivation.h @@ -1,17 +1,6 @@ #ifndef RAGNAROK_SOURCE_CLIENT_APPLICATION_APPLICATIONACTIVATION_H #define RAGNAROK_SOURCE_CLIENT_APPLICATION_APPLICATIONACTIVATION_H -#include "Contents/Skills/AutomaticSkills.h" -#include "Contents/Configuration/ServiceOptions.h" - -struct ApplicationActivation { - HWND& window; - const DWORD& priority; - int& active; - ServiceOptions& service; - AutomaticSkills& automaticSkills; - - void Set(int value); -}; +void SetApplicationActive(int value); #endif diff --git a/Source/Client/Application/Launcher.h b/Source/Client/Application/Launcher.h index 29ec3e24..99843464 100644 --- a/Source/Client/Application/Launcher.h +++ b/Source/Client/Application/Launcher.h @@ -6,6 +6,7 @@ extern std::uint32_t g_clientVersion; extern char g_applicationDirectory[0x80]; +extern HINSTANCE g_instance; bool RestartFromCommandLine(char* commandLine); diff --git a/Source/Client/Browser/BrowserAddressBar.cpp b/Source/Client/Browser/BrowserAddressBar.cpp index b5b0679a..89b2fb87 100644 --- a/Source/Client/Browser/BrowserAddressBar.cpp +++ b/Source/Client/Browser/BrowserAddressBar.cpp @@ -1,10 +1,10 @@ -#include "Client/Browser/BrowserAddressBar.h" +#include "Client/Browser/WebBrowser.h" #include // OFFSET: 0x00AB27A0 // FUNCTION: fn_17416 -bool BrowserAddressBar::Create(int width, int requestedHeight) { +bool CWebBrowser::CreateAddressBar(int width, int requestedHeight) { this->rebar = CreateWindowExA( WS_EX_TOOLWINDOW, REBARCLASSNAMEA, "rebar", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_BORDER | RBS_VARHEIGHT | RBS_BANDBORDERS | RBS_REGISTERDROP | RBS_DBLCLKTOGGLE | @@ -42,18 +42,14 @@ bool BrowserAddressBar::Create(int width, int requestedHeight) { this->combo = combo; HWND edit = GetWindow(combo, GW_CHILD); - this->previous = reinterpret_cast(SetWindowLongPtrA(edit, GWLP_WNDPROC, reinterpret_cast(this->procedure))); + lpPrevWndFunc = reinterpret_cast(SetWindowLongPtrA(edit, GWLP_WNDPROC, reinterpret_cast(BrowserAddressEditProc))); RECT rectangle; GetClientRect(this->host, &rectangle); SetWindowPos(this->rebar, nullptr, 0, 0, rectangle.right - rectangle.left, rectangle.bottom - rectangle.top, SWP_NOMOVE); ShowWindow(this->rebar, SW_HIDE); - this->height = 0; - if (this->rebar && this->visible != 0) { - GetClientRect(this->rebar, &rectangle); - this->height = rectangle.bottom - rectangle.top + 4; - } + this->barHeight = this->AddressBarHeight(); return true; } diff --git a/Source/Client/Browser/BrowserAddressBar.h b/Source/Client/Browser/BrowserAddressBar.h deleted file mode 100644 index 0058454f..00000000 --- a/Source/Client/Browser/BrowserAddressBar.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERADDRESSBAR_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERADDRESSBAR_H - -#include - -struct BrowserAddressBar { - HWND const& host; - HWND& rebar; - HWND& combo; - int& height; - const unsigned char& visible; - WNDPROC& previous; - WNDPROC procedure; - - bool Create(int width, int height); -}; - -#endif diff --git a/Source/Client/Browser/BrowserAddressEdit.cpp b/Source/Client/Browser/BrowserAddressEdit.cpp index cfd80d77..2b1ff593 100644 --- a/Source/Client/Browser/BrowserAddressEdit.cpp +++ b/Source/Client/Browser/BrowserAddressEdit.cpp @@ -1,8 +1,11 @@ -#include "Client/Browser/BrowserAddressEdit.h" -#include "Client/Browser/BrowserMessages.h" +#include "Client/Browser/WebBrowser.h" +#include "UI/Window/UIWindowMgr.h" #include +// GLOBAL: gl_24370 +WNDPROC lpPrevWndFunc; + // OFFSET: 0x00AB20F0 // FUNCTION: fn_17411 void __fastcall sub_AB20F0(BSTR* address) { @@ -11,17 +14,17 @@ void __fastcall sub_AB20F0(BSTR* address) { // OFFSET: 0x00AB21F0 // FUNCTION: fn_17412 -LRESULT BrowserAddressEdit::Message(HWND window, UINT message, WPARAM value, LPARAM flags) { +LRESULT CALLBACK BrowserAddressEditProc(HWND window, UINT message, WPARAM value, LPARAM flags) { if (value == VK_RETURN) { if (message == WM_KEYUP || message == WM_CHAR) { return 0; } - if (message == WM_KEYDOWN && this->activeHost) { - SendMessageA(*this->activeHost, WM_COMMAND, static_cast(BrowserCommand::Navigate), 0); + if (message == WM_KEYDOWN && g_windowMgr.activeBrowser) { + SendMessageA(g_windowMgr.activeBrowser->host, WM_COMMAND, static_cast(BrowserCommand::Navigate), 0); return 0; } } - return CallWindowProcA(this->previous, window, message, value, flags); + return CallWindowProcA(lpPrevWndFunc, window, message, value, flags); } diff --git a/Source/Client/Browser/BrowserAddressEdit.h b/Source/Client/Browser/BrowserAddressEdit.h deleted file mode 100644 index b71efd1b..00000000 --- a/Source/Client/Browser/BrowserAddressEdit.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERADDRESSEDIT_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERADDRESSEDIT_H - -#include - -struct BrowserAddressEdit { - WNDPROC const& previous; - HWND const* const& activeHost; - - LRESULT Message(HWND window, UINT message, WPARAM value, LPARAM flags); -}; - -#endif diff --git a/Source/Client/Browser/BrowserClientSite.cpp b/Source/Client/Browser/BrowserClientSite.cpp index 45429f07..e2ecacd3 100644 --- a/Source/Client/Browser/BrowserClientSite.cpp +++ b/Source/Client/Browser/BrowserClientSite.cpp @@ -2,8 +2,8 @@ // OFFSET: 0x00AB1310 // FUNCTION: fn_17334 -BrowserClientSite::BrowserClientSite(HWND window, IUnknown& browser, BrowserFactory& factory, const int& width, const int& height) - : m_window(window), m_browser(&browser), m_events(*this, factory, width, height), m_inPlace(*this, this->m_window, this->m_browser), m_documentUI(*this), +BrowserClientSite::BrowserClientSite(HWND window, IUnknown* browser) + : m_window(window), m_browser(browser), m_events(*this), m_inPlace(*this, this->m_window, this->m_browser), m_documentUI(*this), m_commands(*this) { this->m_browser->AddRef(); } diff --git a/Source/Client/Browser/BrowserClientSite.h b/Source/Client/Browser/BrowserClientSite.h index f96ae762..4bae2363 100644 --- a/Source/Client/Browser/BrowserClientSite.h +++ b/Source/Client/Browser/BrowserClientSite.h @@ -8,7 +8,7 @@ class BrowserClientSite final : public IOleClientSite { public: - BrowserClientSite(HWND window, IUnknown& browser, BrowserFactory& factory, const int& width, const int& height); + BrowserClientSite(HWND window, IUnknown* browser); ~BrowserClientSite(); BrowserClientSite(const BrowserClientSite&) = delete; BrowserClientSite& operator=(const BrowserClientSite&) = delete; diff --git a/Source/Client/Browser/BrowserClose.cpp b/Source/Client/Browser/BrowserClose.cpp index f6b8e5b0..f1a1e2d4 100644 --- a/Source/Client/Browser/BrowserClose.cpp +++ b/Source/Client/Browser/BrowserClose.cpp @@ -1,18 +1,19 @@ -#include "Client/Browser/BrowserClose.h" +#include "Client/Application/ApplicationWindow.h" +#include "Client/Browser/WebBrowser.h" #include "Client/Input/Mouse.h" // OFFSET: 0x00AB24D0 // FUNCTION: fn_45432 -bool BrowserClose::Close() { +bool CWebBrowser::Close() { if (this->cursorState != 0) { SetCursor(nullptr); - this->mouse.Reset(); + g_mouse.Reset(); ShowCursor(FALSE); this->cursorState = 0; } - if (this->attachment.site) { - this->attachment.Detach(); + if (this->site) { + this->DetachSite(); } if (this->externalEvents) { @@ -23,7 +24,7 @@ bool BrowserClose::Close() { if (this->browser) { this->browser->Stop(); SetWindowLongA(this->browserWindow, GWL_STYLE, WS_CHILD); - SetParent(this->browserWindow, this->applicationWindow); + SetParent(this->browserWindow, hWnd); this->browser->Quit(); this->browser->Release(); this->browser = nullptr; diff --git a/Source/Client/Browser/BrowserClose.h b/Source/Client/Browser/BrowserClose.h deleted file mode 100644 index 136dbe32..00000000 --- a/Source/Client/Browser/BrowserClose.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERCLOSE_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERCLOSE_H - -#include "Client/Browser/BrowserSiteAttachment.h" - -class CMouse; - -struct BrowserClose { - BrowserSiteAttachment& attachment; - IWebBrowser2*& browser; - IUnknown*& externalEvents; - HWND& host; - HWND const& browserWindow; - HWND const& applicationWindow; - int& cursorState; - CMouse& mouse; - - bool Close(); -}; - -#endif diff --git a/Source/Client/Browser/BrowserCreation.cpp b/Source/Client/Browser/BrowserCreation.cpp index b620c633..0b4d8c07 100644 --- a/Source/Client/Browser/BrowserCreation.cpp +++ b/Source/Client/Browser/BrowserCreation.cpp @@ -1,20 +1,46 @@ -#include "Client/Browser/BrowserCreation.h" -#include "Client/Browser/BrowserInterface.h" +#include "Client/Browser/WebBrowser.h" +#include "Contents/Configuration/ServiceConfiguration.h" // OFFSET: 0x00AB22B0 // FUNCTION: fn_17413 -bool BrowserCreation::Create(HWND parent, HINSTANCE instance, int width, int height) { - if (!CreateBrowserInterface(this->browser, this->browserWindow)) { +bool CWebBrowser::Create(HWND parent, HINSTANCE instance, int width, int height) { + const HRESULT result = + CoCreateInstance(CLSID_WebBrowser, nullptr, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IWebBrowser2, reinterpret_cast(&this->browser)); + if (FAILED(result)) { + OutputDebugStringA("error : MakeWebBrowserInterface_InProc FAILED \n"); + HLOCAL message = nullptr; + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), 0, + reinterpret_cast(&message), 0, nullptr + ); + OutputDebugStringA(static_cast(LocalLock(message))); return false; } - if (!this->window.Create(parent, instance, width, height)) { + if (this->browser) { + this->browser->get_HWND(reinterpret_cast(&this->browserWindow)); + } + + WNDCLASSEXA windowClass{}; + windowClass.cbSize = sizeof(windowClass); + windowClass.lpfnWndProc = BrowserHostProc; + windowClass.hInstance = instance; + windowClass.hIcon = LoadIconA(instance, MAKEINTRESOURCEA(123)); + windowClass.lpszClassName = "ROWebBrowser"; + RegisterClassExA(&windowClass); + this->host = CreateWindowExA(0, "ROWebBrowser", g_windowName, WS_POPUP | WS_OVERLAPPEDWINDOW, 0, 0, width, height, parent, nullptr, instance, nullptr); + if (!this->host) { + OutputDebugStringA("failed : CreateWindow() \n"); return false; } - if (!this->attachment.Attach()) { + UpdateWindow(this->host); + SetParent(this->browserWindow, this->host); + SetWindowLongA(this->browserWindow, GWL_STYLE, WS_CHILD); + + if (!this->AttachSite()) { return false; } - return this->addressBar.Create(width, 22); + return this->CreateAddressBar(width, 22); } diff --git a/Source/Client/Browser/BrowserCreation.h b/Source/Client/Browser/BrowserCreation.h deleted file mode 100644 index 8b575623..00000000 --- a/Source/Client/Browser/BrowserCreation.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERCREATION_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERCREATION_H - -#include "Client/Browser/BrowserAddressBar.h" -#include "Client/Browser/BrowserHostWindow.h" -#include "Client/Browser/BrowserSiteAttachment.h" - -struct BrowserCreation { - IWebBrowser2*& browser; - HWND& browserWindow; - BrowserHostWindow& window; - BrowserSiteAttachment& attachment; - BrowserAddressBar& addressBar; - - bool Create(HWND parent, HINSTANCE instance, int width, int height); -}; - -#endif diff --git a/Source/Client/Browser/BrowserCursor.cpp b/Source/Client/Browser/BrowserCursor.cpp index 62762f3b..e1d83490 100644 --- a/Source/Client/Browser/BrowserCursor.cpp +++ b/Source/Client/Browser/BrowserCursor.cpp @@ -1,40 +1,39 @@ -#include "Client/Browser/BrowserCursor.h" +#include "Client/Application/ApplicationWindow.h" +#include "Client/Browser/WebBrowser.h" #include "Client/Input/Mouse.h" -#include "Render/RenderSystemBase.h" // OFFSET: 0x00AB32E0 // FUNCTION: fn_45439 -void BrowserCursor::Set(int value) { - if (this->state == value) { +void CWebBrowser::SetCursorState(int value) { + if (this->cursorState == value) { return; } if (value != 0) { SetCursor(LoadCursorA(nullptr, reinterpret_cast(IDC_ARROW))); - this->mouse.SetX(static_cast(this->renderSystem.Width()) / 2); - this->mouse.SetY(static_cast(this->renderSystem.Height()) / 2); - this->mouse.SetX(-100); - this->mouse.SetY(-100); + g_mouse.Center(); + g_mouse.SetX(-100); + g_mouse.SetY(-100); } else { SetCursor(nullptr); } - this->mouse.Reset(); + g_mouse.Reset(); ShowCursor(value); - this->state = value; + this->cursorState = value; } // OFFSET: 0x00AB3230 // FUNCTION: fn_45438 -void BrowserCursor::Poll() { +void CWebBrowser::PollCursor() { POINT point; GetCursorPos(&point); - if (WindowFromPoint(point) != this->applicationWindow) { - if (this->state != 1) { - this->Set(1); + if (WindowFromPoint(point) != hWnd) { + if (this->cursorState != 1) { + this->SetCursorState(1); } - } else if (this->state != 0) { - this->Set(0); + } else if (this->cursorState != 0) { + this->SetCursorState(0); } } diff --git a/Source/Client/Browser/BrowserCursor.h b/Source/Client/Browser/BrowserCursor.h deleted file mode 100644 index 3a46459f..00000000 --- a/Source/Client/Browser/BrowserCursor.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERCURSOR_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERCURSOR_H - -#include - -class CMouse; -class CRenderSystemBase; - -struct BrowserCursor { - int& state; - CMouse& mouse; - CRenderSystemBase& renderSystem; - HWND const& applicationWindow; - - void Set(int value); - void Poll(); -}; - -#endif diff --git a/Source/Client/Browser/BrowserFactory.cpp b/Source/Client/Browser/BrowserFactory.cpp index 8615bb15..d848adee 100644 --- a/Source/Client/Browser/BrowserFactory.cpp +++ b/Source/Client/Browser/BrowserFactory.cpp @@ -1,8 +1,10 @@ -#include "Client/Browser/BrowserRegistry.h" +#include "Client/Application/ApplicationWindow.h" +#include "Client/Application/Launcher.h" #include "Client/Browser/WebBrowser.h" #include "Contents/MessageTable.h" -#include "Client/Browser/BrowserFactory.h" -#include "UI/Chat/ChatNotifications.h" +#include "UI/Window/UIWindowMgr.h" + +#include namespace { constexpr unsigned maximumBrowserCount = 5; @@ -10,18 +12,16 @@ namespace { // OFFSET: 0x00A8C840 // FUNCTION: fn_17136 -CWebBrowser* BrowserFactory::Create(int width, int height) { - if (this->registry.browsers.size() >= maximumBrowserCount) { - this->notifications.Refresh(); - const char* message = LookupMessage(MessageId::MSI_FAILED_ADD_TAB); - this->notifications.Text(message, RGB(255, 0, 0), nullptr, 0, false); - +CWebBrowser* UIWindowMgr::CreateBrowser(int width, int height) { + if (this->browsers.size() >= maximumBrowserCount) { + this->SendNotice(3, 0, 0, 0, 0, 0); + this->SendNotice(1, reinterpret_cast(LookupMessage(MessageId::MSI_FAILED_ADD_TAB)), RGB(255, 0, 0), 0, 0, 0); return nullptr; } - auto* browser = new CWebBrowser(this->context); - if (browser->Create(width, height)) { - this->registry.browsers.emplace(browser->host, browser); + auto* browser = new (std::nothrow) CWebBrowser(); + if (browser && browser->Create(hWnd, g_instance, width, height)) { + this->browsers.emplace(browser->host, browser); return browser; } diff --git a/Source/Client/Browser/BrowserFactory.h b/Source/Client/Browser/BrowserFactory.h deleted file mode 100644 index bbc96011..00000000 --- a/Source/Client/Browser/BrowserFactory.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERFACTORY_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERFACTORY_H - -#include - -class CWebBrowser; -struct WebBrowserContext; -struct BrowserRegistry; -struct ChatNotifications; - -struct BrowserFactory { - BrowserRegistry& registry; - WebBrowserContext& context; - ChatNotifications& notifications; - const bool& languagePrefix; - const int& serviceType; - const WORD& language; - - CWebBrowser* Create(int width, int height); -}; - -#endif diff --git a/Source/Client/Browser/BrowserFrame.cpp b/Source/Client/Browser/BrowserFrame.cpp index 886529dc..60eba9e6 100644 --- a/Source/Client/Browser/BrowserFrame.cpp +++ b/Source/Client/Browser/BrowserFrame.cpp @@ -1,36 +1,36 @@ -#include "Client/Browser/BrowserFrame.h" +#include "Client/Browser/WebBrowser.h" // OFFSET: 0x00AB2610 // FUNCTION: fn_17414 -void BrowserFrame::Normalize() { - if (!this->hasExternalEvents) { +void CWebBrowser::Normalize() { + if (!this->externalEvents) { return; } RECT rectangle; GetWindowRect(this->browserWindow, &rectangle); - if (rectangle.right - rectangle.left != this->sizing.screenWidth || rectangle.bottom - rectangle.top != this->sizing.screenHeight) { + if (rectangle.right - rectangle.left != this->screenWidth || rectangle.bottom - rectangle.top != this->screenHeight) { return; } - this->sizing.browser->put_Visible(VARIANT_FALSE); + this->browser->put_Visible(VARIANT_FALSE); SetWindowLongA(this->browserWindow, GWL_STYLE, WS_CHILD); SetParent(this->browserWindow, this->host); - this->sizing.browser->put_FullScreen(VARIANT_FALSE); - this->sizing.browser->put_AddressBar(VARIANT_FALSE); + this->browser->put_FullScreen(VARIANT_FALSE); + this->browser->put_AddressBar(VARIANT_FALSE); SetParent(this->browserWindow, this->host); SetWindowLongA(this->browserWindow, GWL_STYLE, WS_CHILD); - this->sizing.browser->put_Visible(VARIANT_TRUE); + this->browser->put_Visible(VARIANT_TRUE); } // OFFSET: 0x00AB2E70 // FUNCTION: fn_17419 -void BrowserFrame::Poll() { +void CWebBrowser::Poll() { if (!IsWindowVisible(this->host)) { return; } this->Normalize(); - this->sizing.Refresh(); - this->cursor.Poll(); + this->RefreshSize(); + this->PollCursor(); } diff --git a/Source/Client/Browser/BrowserFrame.h b/Source/Client/Browser/BrowserFrame.h deleted file mode 100644 index dec5b06c..00000000 --- a/Source/Client/Browser/BrowserFrame.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERFRAME_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERFRAME_H - -#include "Client/Browser/BrowserCursor.h" -#include "Client/Browser/BrowserWindowSizing.h" - -struct BrowserFrame { - BrowserWindowSizing& sizing; - BrowserCursor& cursor; - HWND const& host; - HWND const& browserWindow; - const bool& hasExternalEvents; - - void Normalize(); - void Poll(); -}; - -#endif diff --git a/Source/Client/Browser/BrowserHostWindow.cpp b/Source/Client/Browser/BrowserHostWindow.cpp index 2a3d15f5..8a9751bd 100644 --- a/Source/Client/Browser/BrowserHostWindow.cpp +++ b/Source/Client/Browser/BrowserHostWindow.cpp @@ -1,25 +1,24 @@ -#include "Client/Browser/BrowserHostWindow.h" +#include "Client/Browser/WebBrowser.h" +#include "Contents/Configuration/ServiceConfiguration.h" // OFFSET: 0x00AB29D0 // FUNCTION: fn_45435 -bool BrowserHostWindow::Create(HWND parent, HINSTANCE instance, int width, int height) { +bool CWebBrowser::CreateHostWindow(HWND parent, HINSTANCE instance, int width, int height) { WNDCLASSEXA windowClass{}; windowClass.cbSize = sizeof(windowClass); - windowClass.lpfnWndProc = this->procedure; + windowClass.lpfnWndProc = BrowserHostProc; windowClass.hInstance = instance; windowClass.hIcon = LoadIconA(instance, MAKEINTRESOURCEA(123)); windowClass.lpszClassName = "ROWebBrowser"; RegisterClassExA(&windowClass); - - this->host = CreateWindowExA(0, "ROWebBrowser", this->title, WS_POPUP | WS_OVERLAPPEDWINDOW, 0, 0, width, height, parent, nullptr, instance, nullptr); + this->host = CreateWindowExA(0, "ROWebBrowser", g_windowName, WS_POPUP | WS_OVERLAPPEDWINDOW, 0, 0, width, height, parent, nullptr, instance, nullptr); if (!this->host) { OutputDebugStringA("failed : CreateWindow() \n"); return false; } UpdateWindow(this->host); - SetParent(this->browser, this->host); - SetWindowLongA(this->browser, GWL_STYLE, WS_CHILD); - + SetParent(this->browserWindow, this->host); + SetWindowLongA(this->browserWindow, GWL_STYLE, WS_CHILD); return true; } diff --git a/Source/Client/Browser/BrowserHostWindow.h b/Source/Client/Browser/BrowserHostWindow.h deleted file mode 100644 index eb3183b5..00000000 --- a/Source/Client/Browser/BrowserHostWindow.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERHOSTWINDOW_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERHOSTWINDOW_H - -#include - -struct BrowserHostWindow { - HWND& host; - HWND const& browser; - const char* const& title; - WNDPROC procedure; - - bool Create(HWND parent, HINSTANCE instance, int width, int height); -}; - -#endif diff --git a/Source/Client/Browser/BrowserInputHandoff.cpp b/Source/Client/Browser/BrowserInputHandoff.cpp index f0a09cf7..89d5315d 100644 --- a/Source/Client/Browser/BrowserInputHandoff.cpp +++ b/Source/Client/Browser/BrowserInputHandoff.cpp @@ -1,37 +1,38 @@ #include "Client/Application/ApplicationActivation.h" -#include "Client/Browser/BrowserInputHandoff.h" +#include "Client/Application/ApplicationWindow.h" +#include "Client/Browser/WebBrowser.h" #include "Client/Input/Mouse.h" #include "Contents/Configuration/ServiceOptions.h" // OFFSET: 0x00AB2720 // FUNCTION: fn_45433 -void BrowserInputHandoff::Enter() { - if (this->service.Get(ServiceOption::ConfineCursor) == 0) { +void CWebBrowser::EnterInput() { + if (g_serviceOptions.Get(ServiceOption::ConfineCursor) == 0) { return; } - POINT position{this->mouse.x, this->mouse.y}; - this->service.Set(ServiceOption::ConfineCursor, 0); - this->mouse.SetX(position.x); - this->mouse.SetY(position.y); + POINT position{g_mouse.x, g_mouse.y}; + g_serviceOptions.Set(ServiceOption::ConfineCursor, 0); + g_mouse.SetX(position.x); + g_mouse.SetY(position.y); this->restoreOption = 1; - ClientToScreen(this->applicationWindow, &position); + ClientToScreen(hWnd, &position); SetCursorPos(position.x, position.y); } // OFFSET: 0x00AB3350 // FUNCTION: fn_45440 -void BrowserInputHandoff::Restore() { +void CWebBrowser::RestoreInput() { if (this->restoreOption == 0) { return; } POINT position; GetCursorPos(&position); - ScreenToClient(this->applicationWindow, &position); - this->service.Set(ServiceOption::ConfineCursor, 1); - this->mouse.SetX(position.x); - this->mouse.SetY(position.y); - SetActiveWindow(this->applicationWindow); - this->activation.Set(1); + ScreenToClient(hWnd, &position); + g_serviceOptions.Set(ServiceOption::ConfineCursor, 1); + g_mouse.SetX(position.x); + g_mouse.SetY(position.y); + SetActiveWindow(hWnd); + SetApplicationActive(1); } diff --git a/Source/Client/Browser/BrowserInputHandoff.h b/Source/Client/Browser/BrowserInputHandoff.h deleted file mode 100644 index 3e47b10b..00000000 --- a/Source/Client/Browser/BrowserInputHandoff.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERINPUTHANDOFF_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERINPUTHANDOFF_H - -#include - -class CMouse; -struct ServiceOptions; -struct ApplicationActivation; - -struct BrowserInputHandoff { - unsigned char& restoreOption; - HWND const& applicationWindow; - ServiceOptions& service; - CMouse& mouse; - ApplicationActivation& activation; - - void Enter(); - void Restore(); -}; - -#endif diff --git a/Source/Client/Browser/BrowserInterface.cpp b/Source/Client/Browser/BrowserInterface.cpp index c2cc3747..387097c1 100644 --- a/Source/Client/Browser/BrowserInterface.cpp +++ b/Source/Client/Browser/BrowserInterface.cpp @@ -1,13 +1,13 @@ -#include "Client/Browser/BrowserInterface.h" +#include "Client/Browser/WebBrowser.h" #include #include // OFFSET: 0x00AB2CD0 // FUNCTION: fn_45437 -bool CreateBrowserInterface(IWebBrowser2*& browser, HWND& window) { +bool CWebBrowser::CreateInterface() { const HRESULT result = - CoCreateInstance(CLSID_WebBrowser, nullptr, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IWebBrowser2, reinterpret_cast(&browser)); + CoCreateInstance(CLSID_WebBrowser, nullptr, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IWebBrowser2, reinterpret_cast(&this->browser)); if (FAILED(result)) { OutputDebugStringA("error : MakeWebBrowserInterface_InProc FAILED \n"); @@ -21,8 +21,8 @@ bool CreateBrowserInterface(IWebBrowser2*& browser, HWND& window) { return false; } - if (browser) { - browser->get_HWND(reinterpret_cast(&window)); + if (this->browser) { + this->browser->get_HWND(reinterpret_cast(&this->browserWindow)); } return true; @@ -30,8 +30,8 @@ bool CreateBrowserInterface(IWebBrowser2*& browser, HWND& window) { // OFFSET: 0x00AB2C10 // FUNCTION: fn_45436 -bool CreateExternalBrowserInterface(IWebBrowser2*& browser, HWND& window, HWND const& host) { - const HRESULT result = CoCreateInstance(CLSID_InternetExplorer, nullptr, CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, reinterpret_cast(&browser)); +bool CWebBrowser::CreateExternalInterface() { + const HRESULT result = CoCreateInstance(CLSID_InternetExplorer, nullptr, CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, reinterpret_cast(&this->browser)); if (FAILED(result)) { OutputDebugStringA("error : MakeWebBrowserInterface FAILED \n"); @@ -45,13 +45,13 @@ bool CreateExternalBrowserInterface(IWebBrowser2*& browser, HWND& window, HWND c return false; } - if (browser) { - browser->get_HWND(reinterpret_cast(&window)); - SetWindowLongA(window, GWL_STYLE, WS_CHILD); - SetParent(window, host); - browser->put_Top(0); - browser->put_Left(0); - browser->put_StatusBar(VARIANT_FALSE); + if (this->browser) { + this->browser->get_HWND(reinterpret_cast(&this->browserWindow)); + SetWindowLongA(this->browserWindow, GWL_STYLE, WS_CHILD); + SetParent(this->browserWindow, this->host); + this->browser->put_Top(0); + this->browser->put_Left(0); + this->browser->put_StatusBar(VARIANT_FALSE); } return true; @@ -59,8 +59,8 @@ bool CreateExternalBrowserInterface(IWebBrowser2*& browser, HWND& window, HWND c // OFFSET: 0x00AB2D50 // FUNCTION: fn_17418 -bool NavigateBrowser(IWebBrowser2* const& browser, HWND const& host, HWND const& title, std::string address) { - if (!browser) { +bool CWebBrowser::Navigate(std::string address) { + if (!this->browser) { return false; } @@ -73,13 +73,13 @@ bool NavigateBrowser(IWebBrowser2* const& browser, HWND const& host, HWND const& VARIANT optional; VariantInit(&optional); - const HRESULT result = browser->Navigate(url, &optional, &optional, &optional, &optional); + const HRESULT result = this->browser->Navigate(url, &optional, &optional, &optional, &optional); SysFreeString(url); - ShowWindow(host, SW_SHOW); - browser->put_Visible(VARIANT_TRUE); + ShowWindow(this->host, SW_SHOW); + this->browser->put_Visible(VARIANT_TRUE); - if (title) { - SetWindowTextA(title, address.c_str()); + if (this->combo) { + SetWindowTextA(this->combo, address.c_str()); } if (FAILED(result)) { diff --git a/Source/Client/Browser/BrowserInterface.h b/Source/Client/Browser/BrowserInterface.h deleted file mode 100644 index 3f8c07cd..00000000 --- a/Source/Client/Browser/BrowserInterface.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERINTERFACE_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERINTERFACE_H - -#include -#include -#include -#include - -bool CreateBrowserInterface(IWebBrowser2*& browser, HWND& window); -bool CreateExternalBrowserInterface(IWebBrowser2*& browser, HWND& window, HWND const& host); -bool NavigateBrowser(IWebBrowser2* const& browser, HWND const& host, HWND const& title, std::string address); -HRESULT AdviseBrowserEvents(IUnknown* source, IUnknown* sink, REFIID events, DWORD* cookie); -HRESULT UnadviseBrowserEvents(IUnknown* source, REFIID events, DWORD cookie); - -#endif diff --git a/Source/Client/Browser/BrowserMessages.cpp b/Source/Client/Browser/BrowserMessages.cpp index cdf47369..19d0971b 100644 --- a/Source/Client/Browser/BrowserMessages.cpp +++ b/Source/Client/Browser/BrowserMessages.cpp @@ -1,23 +1,23 @@ -#include "Client/Browser/BrowserMessages.h" -#include "Client/Browser/BrowserRegistry.h" +#include "Client/Application/ApplicationWindow.h" #include "Client/Browser/WebBrowser.h" +#include "UI/Window/UIWindowMgr.h" #include // OFFSET: 0x00AB33C0 // FUNCTION: fn_17423 -LRESULT BrowserMessages::Message(HWND window, UINT message, WPARAM value, LPARAM flags) { - CWebBrowser* browser = this->registry.Find(window); +LRESULT CALLBACK BrowserHostProc(HWND window, UINT message, WPARAM value, LPARAM flags) { + CWebBrowser* browser = g_windowMgr.FindBrowser(window); switch (message) { case WM_CREATE: case WM_NCHITTEST: case WM_NCLBUTTONDOWN: case WM_PARENTNOTIFY: - this->active = this->registry.Find(window); + g_windowMgr.activeBrowser = g_windowMgr.FindBrowser(window); break; case WM_DESTROY: - SetFocus(this->applicationWindow); + SetFocus(hWnd); break; case WM_SIZE: if (browser) { @@ -26,7 +26,7 @@ LRESULT BrowserMessages::Message(HWND window, UINT message, WPARAM value, LPARAM } break; case WM_CLOSE: - this->registry.Remove(window); + g_windowMgr.RemoveBrowser(window); break; case WM_HELP: return 1; diff --git a/Source/Client/Browser/BrowserMessages.h b/Source/Client/Browser/BrowserMessages.h deleted file mode 100644 index 9bb9d08c..00000000 --- a/Source/Client/Browser/BrowserMessages.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERMESSAGES_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERMESSAGES_H - -#include - -class CWebBrowser; -struct BrowserRegistry; - -enum class BrowserCommand : WORD { Navigate = 1000 }; - -struct BrowserMessages { - BrowserRegistry& registry; - CWebBrowser*& active; - HWND const& applicationWindow; - - LRESULT Message(HWND window, UINT message, WPARAM value, LPARAM flags); -}; - -#endif diff --git a/Source/Client/Browser/BrowserPopupDispatch.cpp b/Source/Client/Browser/BrowserPopupDispatch.cpp index 2614a833..68dbac35 100644 --- a/Source/Client/Browser/BrowserPopupDispatch.cpp +++ b/Source/Client/Browser/BrowserPopupDispatch.cpp @@ -1,5 +1,6 @@ #include "Client/Browser/WebBrowser.h" -#include "Client/Browser/BrowserFactory.h" +#include "Render/Renderer.h" +#include "UI/Window/UIWindowMgr.h" #include "Client/Browser/BrowserPopupDispatch.h" #include "Utility/Math/ScalarConversion.h" @@ -57,9 +58,9 @@ HRESULT STDMETHODCALLTYPE BrowserPopupDispatch::Invoke(DISPID id, REFIID, LCID, // STATIC: 0x01115448 // GLOBAL: gl_13426 const float scale = 0.7f; - const int height = TruncateToInt(static_cast(this->m_height) * scale); - const int width = TruncateToInt(static_cast(this->m_width) * scale); - CWebBrowser* browser = this->m_factory.Create(width, height); + const int height = TruncateToInt(static_cast(g_renderer->viewport.height) * scale); + const int width = TruncateToInt(static_cast(g_renderer->viewport.width) * scale); + CWebBrowser* browser = g_windowMgr.CreateBrowser(width, height); if (!browser) { return S_OK; diff --git a/Source/Client/Browser/BrowserPopupDispatch.h b/Source/Client/Browser/BrowserPopupDispatch.h index a009144c..c8957b2b 100644 --- a/Source/Client/Browser/BrowserPopupDispatch.h +++ b/Source/Client/Browser/BrowserPopupDispatch.h @@ -4,13 +4,10 @@ #include #include -struct BrowserFactory; - class BrowserPopupDispatch final : public IDispatch { public: // INLINED - BrowserPopupDispatch(IUnknown& site, BrowserFactory& factory, const int& width, const int& height) - : m_site(site), m_factory(factory), m_width(width), m_height(height) { + explicit BrowserPopupDispatch(IUnknown& site) : m_site(site) { } HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** output) override; @@ -24,9 +21,6 @@ public: private: IUnknown& m_site; - BrowserFactory& m_factory; - const int& m_width; - const int& m_height; }; #endif diff --git a/Source/Client/Browser/BrowserRegistry.cpp b/Source/Client/Browser/BrowserRegistry.cpp index 6153ca0e..fa6efff7 100644 --- a/Source/Client/Browser/BrowserRegistry.cpp +++ b/Source/Client/Browser/BrowserRegistry.cpp @@ -1,24 +1,26 @@ -#include "Client/Browser/BrowserRegistry.h" +#include "Client/Application/ApplicationWindow.h" +#include "Client/Application/Launcher.h" #include "Client/Browser/WebBrowser.h" +#include "UI/Window/UIWindowMgr.h" #include // OFFSET: 0x00A91990 // FUNCTION: fn_17167 -CWebBrowser* BrowserRegistry::Find(HWND window) const { +CWebBrowser* UIWindowMgr::FindBrowser(HWND window) { const auto found = this->browsers.find(window); return found == this->browsers.end() ? nullptr : found->second; } // OFFSET: 0x00A8F860 // FUNCTION: fn_17146 -void BrowserRegistry::Remove(HWND window) { +void UIWindowMgr::RemoveBrowser(HWND window) { const auto found = this->browsers.find(window); if (found != this->browsers.end()) { CWebBrowser* browser = found->second; if (browser) { - if (browser == this->special) { - this->special = nullptr; + if (browser == this->specialBrowser) { + this->specialBrowser = nullptr; } delete browser; @@ -28,23 +30,23 @@ void BrowserRegistry::Remove(HWND window) { return; } - if (window == this->special->host) { - delete this->special; - this->special = nullptr; + if (window == this->specialBrowser->host) { + delete this->specialBrowser; + this->specialBrowser = nullptr; } } // OFFSET: 0x00A8C960 // FUNCTION: fn_17138 -CWebBrowser* BrowserRegistry::EnsureSpecial(WebBrowserContext& context, int width, int height) { - if (this->special) { - return this->special; +CWebBrowser* UIWindowMgr::EnsureSpecialBrowser(int width, int height) { + if (this->specialBrowser) { + return this->specialBrowser; } - this->special = new (std::nothrow) CWebBrowser(context); - if (this->special && this->special->Create(width, height)) { - this->browsers.emplace(this->special->host, this->special); + this->specialBrowser = new (std::nothrow) CWebBrowser(); + if (this->specialBrowser && this->specialBrowser->Create(hWnd, g_instance, width, height)) { + this->browsers.emplace(this->specialBrowser->host, this->specialBrowser); } - return this->special; + return this->specialBrowser; } diff --git a/Source/Client/Browser/BrowserRegistry.h b/Source/Client/Browser/BrowserRegistry.h deleted file mode 100644 index 833a529e..00000000 --- a/Source/Client/Browser/BrowserRegistry.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERREGISTRY_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERREGISTRY_H - -#include -#include - -class CWebBrowser; -struct WebBrowserContext; - -struct BrowserRegistry { - std::map& browsers; - CWebBrowser*& special; - - CWebBrowser* Find(HWND window) const; - void Remove(HWND window); - CWebBrowser* EnsureSpecial(WebBrowserContext& context, int width, int height); -}; - -#endif diff --git a/Source/Client/Browser/BrowserSiteAttachment.cpp b/Source/Client/Browser/BrowserSiteAttachment.cpp index 336b47dd..75a525b8 100644 --- a/Source/Client/Browser/BrowserSiteAttachment.cpp +++ b/Source/Client/Browser/BrowserSiteAttachment.cpp @@ -1,15 +1,14 @@ -#include "Client/Browser/BrowserInterface.h" -#include "Client/Browser/BrowserSiteAttachment.h" +#include "Client/Browser/BrowserClientSite.h" +#include "Client/Browser/WebBrowser.h" #include // OFFSET: 0x00AB2AB0 // FUNCTION: fn_17417 -bool BrowserSiteAttachment::Attach() { - this->site = new (std::nothrow) BrowserClientSite(this->host, *this->sizing.browser, this->factory, this->renderWidth, this->renderHeight); - +bool CWebBrowser::AttachSite() { + this->site = new (std::nothrow) BrowserClientSite(this->host, this->browser); IOleObject* object; - HRESULT result = this->sizing.browser->QueryInterface(IID_IOleObject, reinterpret_cast(&object)); + HRESULT result = this->browser->QueryInterface(IID_IOleObject, reinterpret_cast(&object)); if (FAILED(result)) { return false; } @@ -20,11 +19,10 @@ bool BrowserSiteAttachment::Attach() { RECT rectangle; GetClientRect(this->host, &rectangle); result = object->DoVerb(OLEIVERB_INPLACEACTIVATE, nullptr, this->site, 0, this->host, &rectangle); - if (SUCCEEDED(result)) { const int width = rectangle.right - rectangle.left; const int height = rectangle.bottom - rectangle.top; - this->sizing.Resize(width, height); + this->Resize(width, height); result = AdviseBrowserEvents(object, this->site, DIID_DWebBrowserEvents2, &this->cookie); } } @@ -35,9 +33,9 @@ bool BrowserSiteAttachment::Attach() { // OFFSET: 0x00AB2430 // FUNCTION: fn_45431 -void BrowserSiteAttachment::Detach() { +void CWebBrowser::DetachSite() { IOleObject* object; - if (SUCCEEDED(this->sizing.browser->QueryInterface(IID_IOleObject, reinterpret_cast(&object)))) { + if (SUCCEEDED(this->browser->QueryInterface(IID_IOleObject, reinterpret_cast(&object)))) { UnadviseBrowserEvents(object, DIID_DWebBrowserEvents2, this->cookie); object->Release(); } diff --git a/Source/Client/Browser/BrowserSiteAttachment.h b/Source/Client/Browser/BrowserSiteAttachment.h deleted file mode 100644 index 09cc780a..00000000 --- a/Source/Client/Browser/BrowserSiteAttachment.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERSITEATTACHMENT_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERSITEATTACHMENT_H - -#include "Client/Browser/BrowserClientSite.h" -#include "Client/Browser/BrowserWindowSizing.h" - -struct BrowserSiteAttachment { - BrowserWindowSizing& sizing; - HWND const& host; - BrowserClientSite*& site; - DWORD& cookie; - BrowserFactory& factory; - const int& renderWidth; - const int& renderHeight; - - bool Attach(); - void Detach(); -}; - -#endif diff --git a/Source/Client/Browser/BrowserWindowSizing.cpp b/Source/Client/Browser/BrowserWindowSizing.cpp index 164b8194..bd841d81 100644 --- a/Source/Client/Browser/BrowserWindowSizing.cpp +++ b/Source/Client/Browser/BrowserWindowSizing.cpp @@ -1,8 +1,8 @@ -#include "Client/Browser/BrowserWindowSizing.h" +#include "Client/Browser/WebBrowser.h" // OFFSET: 0x00AB3060 // FUNCTION: fn_17421 -void BrowserWindowSizing::Resize(int requestedWidth, int requestedHeight) { +void CWebBrowser::Resize(int requestedWidth, int requestedHeight) { if (!this->browser) { return; } @@ -10,9 +10,9 @@ void BrowserWindowSizing::Resize(int requestedWidth, int requestedHeight) { this->width = requestedWidth == this->screenWidth ? requestedWidth - 1 : requestedWidth; int height = requestedHeight == this->screenHeight ? requestedHeight - 1 : requestedHeight; - if (this->auxiliary && this->auxiliaryVisible != 0) { + if (this->rebar && this->auxiliaryVisible != 0) { RECT rectangle; - GetClientRect(this->auxiliary, &rectangle); + GetClientRect(this->rebar, &rectangle); height -= (rectangle.bottom - rectangle.top + 4); } @@ -20,14 +20,14 @@ void BrowserWindowSizing::Resize(int requestedWidth, int requestedHeight) { this->browser->put_Width(this->width); this->browser->put_Height(this->height); - if (this->auxiliary) { - SetWindowPos(this->auxiliary, nullptr, 0, 0, requestedWidth, requestedHeight, SWP_NOMOVE); + if (this->rebar) { + SetWindowPos(this->rebar, nullptr, 0, 0, requestedWidth, requestedHeight, SWP_NOMOVE); } } // OFFSET: 0x00AB2260 // FUNCTION: fn_45430 -void BrowserWindowSizing::Refresh() { +void CWebBrowser::RefreshSize() { long width = 0; long height = 0; this->browser->get_Width(&width); @@ -40,38 +40,38 @@ void BrowserWindowSizing::Refresh() { // OFFSET: 0x00AB3120 // FUNCTION: fn_17422 -void BrowserAuxiliaryVisibility::Show(unsigned char value) { - if (!this->sizing.browser) { +void CWebBrowser::ShowAuxiliary(unsigned char value) { + if (!this->browser) { return; } - this->visible = value; - if (!this->sizing.auxiliary) { + this->auxiliaryVisible = value; + if (!this->rebar) { return; } - this->sizing.browser->put_Visible(VARIANT_FALSE); - ShowWindow(this->sizing.auxiliary, this->visible != 0 ? SW_SHOW : SW_HIDE); + this->browser->put_Visible(VARIANT_FALSE); + ShowWindow(this->rebar, this->auxiliaryVisible != 0 ? SW_SHOW : SW_HIDE); - if (this->hasSite) { + if (this->externalEvents) { RECT rectangle; GetWindowRect(this->host, &rectangle); POINT origin{}; ClientToScreen(this->host, &origin); - this->sizing.browser->put_Left(-origin.x); + this->browser->put_Left(-origin.x); } long top = 0; - if (this->sizing.auxiliary && this->visible != 0) { + if (this->rebar && this->auxiliaryVisible != 0) { RECT rectangle; - GetClientRect(this->sizing.auxiliary, &rectangle); + GetClientRect(this->rebar, &rectangle); top = rectangle.bottom - rectangle.top + 4; } - this->sizing.browser->put_Top(top); + this->browser->put_Top(top); RECT rectangle; GetClientRect(this->host, &rectangle); - this->sizing.Resize(rectangle.right - rectangle.left, rectangle.bottom - rectangle.top); - this->sizing.browser->put_Visible(VARIANT_TRUE); + this->Resize(rectangle.right - rectangle.left, rectangle.bottom - rectangle.top); + this->browser->put_Visible(VARIANT_TRUE); } diff --git a/Source/Client/Browser/BrowserWindowSizing.h b/Source/Client/Browser/BrowserWindowSizing.h deleted file mode 100644 index 1448868f..00000000 --- a/Source/Client/Browser/BrowserWindowSizing.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERWINDOWSIZING_H -#define RAGNAROK_SOURCE_CLIENT_BROWSER_BROWSERWINDOWSIZING_H - -#include -#include -#include - -struct BrowserWindowSizing { - IWebBrowser2* const& browser; - const int& screenWidth; - const int& screenHeight; - HWND const& auxiliary; - const unsigned char& auxiliaryVisible; - int& width; - int& height; - - void Resize(int requestedWidth, int requestedHeight); - void Refresh(); -}; - -struct BrowserAuxiliaryVisibility { - BrowserWindowSizing& sizing; - const bool& hasSite; - HWND const& host; - unsigned char& visible; - - void Show(unsigned char value); -}; - -#endif diff --git a/Source/Client/Browser/WebBrowser.cpp b/Source/Client/Browser/WebBrowser.cpp index 2ac8393b..c63b8620 100644 --- a/Source/Client/Browser/WebBrowser.cpp +++ b/Source/Client/Browser/WebBrowser.cpp @@ -1,111 +1,98 @@ -#include "Client/Browser/BrowserClose.h" -#include "Client/Browser/BrowserCreation.h" -#include "Client/Browser/BrowserFrame.h" -#include "Client/Browser/BrowserInputHandoff.h" -#include "Client/Browser/BrowserInterface.h" +#include "Client/Application/ApplicationActivation.h" +#include "Client/Application/ApplicationWindow.h" +#include "Client/Browser/BrowserClientSite.h" +#include "UI/Window/UIWindowMgr.h" #include "Client/Browser/WebBrowser.h" #include "Client/Browser/WebEventReceiver.h" +#include "Client/Input/Mouse.h" +#include "Contents/Configuration/ServiceOptions.h" #include #include -namespace { - // INLINED - BrowserWindowSizing Sizing(CWebBrowser& owner) { - return {owner.browser, owner.screenWidth, owner.screenHeight, owner.rebar, owner.auxiliaryVisible, owner.width, owner.height}; - } -} - // OFFSET: 0x00AB1DE0 // FUNCTION: fn_17409 -CWebBrowser::CWebBrowser(WebBrowserContext& context) +CWebBrowser::CWebBrowser() : browser(nullptr), externalEvents(nullptr), site(nullptr), host(nullptr), browserWindow(nullptr), cursorState(0), auxiliaryVisible(0), screenWidth(GetSystemMetrics(SM_CXSCREEN)), screenHeight(GetSystemMetrics(SM_CYSCREEN)), cookie(0), rebar(nullptr), combo(nullptr), barHeight(0), - width(0), height(0), restoreOption(0), context(&context) { + width(0), height(0), restoreOption(0) { OutputDebugStringA("CWebBrowser() \n"); - BrowserInputHandoff handoff{this->restoreOption, context.applicationWindow, context.service, context.mouse, context.activation}; - handoff.Enter(); + if (g_serviceOptions.Get(ServiceOption::ConfineCursor) == 0) { + return; + } + + POINT position{g_mouse.x, g_mouse.y}; + g_serviceOptions.Set(ServiceOption::ConfineCursor, 0); + g_mouse.SetX(position.x); + g_mouse.SetY(position.y); + this->restoreOption = 1; + ClientToScreen(hWnd, &position); + SetCursorPos(position.x, position.y); } // OFFSET: 0x00AB1F20 // FUNCTION: fn_17410 CWebBrowser::~CWebBrowser() { OutputDebugStringA("~CWebBrowser() \n"); - auto& dependencies = *this->context; - BrowserInputHandoff handoff{this->restoreOption, dependencies.applicationWindow, dependencies.service, dependencies.mouse, dependencies.activation}; - handoff.Restore(); - this->Close(); -} + if (this->restoreOption != 0) { + POINT position; + GetCursorPos(&position); + ScreenToClient(hWnd, &position); + g_serviceOptions.Set(ServiceOption::ConfineCursor, 1); + g_mouse.SetX(position.x); + g_mouse.SetY(position.y); + SetActiveWindow(hWnd); + SetApplicationActive(1); + } -// OFFSET: 0x00AB22B0 -bool CWebBrowser::Create(int requestedWidth, int requestedHeight) { - auto& dependencies = *this->context; - auto sizing = Sizing(*this); - BrowserHostWindow window{this->host, this->browserWindow, dependencies.title, dependencies.hostProcedure}; - BrowserSiteAttachment attachment{ - sizing, this->host, this->site, this->cookie, dependencies.popupFactory, dependencies.renderWidth, dependencies.renderHeight - }; - BrowserAddressBar addressBar{ - this->host, this->rebar, this->combo, this->barHeight, this->auxiliaryVisible, dependencies.previousEditProcedure, dependencies.editProcedure - }; - BrowserCreation creation{this->browser, this->browserWindow, window, attachment, addressBar}; + if (this->cursorState != 0) { + SetCursor(nullptr); + g_mouse.Reset(); + ShowCursor(FALSE); + this->cursorState = 0; + } - return creation.Create(dependencies.applicationWindow, dependencies.instance, requestedWidth, requestedHeight); -} + if (this->site) { + IOleObject* object; + if (SUCCEEDED(this->browser->QueryInterface(IID_IOleObject, reinterpret_cast(&object)))) { + UnadviseBrowserEvents(object, DIID_DWebBrowserEvents2, this->cookie); + object->Release(); + } -// OFFSET: 0x00AB24D0 -bool CWebBrowser::Close() { - auto& dependencies = *this->context; - auto sizing = Sizing(*this); - BrowserSiteAttachment attachment{ - sizing, this->host, this->site, this->cookie, dependencies.popupFactory, dependencies.renderWidth, dependencies.renderHeight - }; - BrowserClose operation{attachment, this->browser, this->externalEvents, this->host, this->browserWindow, dependencies.applicationWindow, - this->cursorState, dependencies.mouse}; + delete this->site; + this->site = nullptr; + } - return operation.Close(); + if (this->externalEvents) { + this->externalEvents->Release(); + this->externalEvents = nullptr; + } + + if (this->browser) { + this->browser->Stop(); + SetWindowLongA(this->browserWindow, GWL_STYLE, WS_CHILD); + SetParent(this->browserWindow, hWnd); + this->browser->Quit(); + this->browser->Release(); + this->browser = nullptr; + } + + if (this->host) { + DestroyWindow(this->host); + this->host = nullptr; + } } // OFFSET: 0x00AB2950 // FUNCTION: fn_45434 -bool CWebBrowser::AttachExternalEvents(BrowserRegistry& registry) { - auto* receiver = new (std::nothrow) CWebEventReceiver(registry); +bool CWebBrowser::AttachExternalEvents() { + auto* receiver = new (std::nothrow) CWebEventReceiver(); this->externalEvents = receiver; receiver->AddRef(); return receiver->Register(this->browser, this->host); } -// OFFSET: 0x00AB3060 -void CWebBrowser::Resize(int requestedWidth, int requestedHeight) { - auto sizing = Sizing(*this); - sizing.Resize(requestedWidth, requestedHeight); -} - -// OFFSET: 0x00AB2E70 -void CWebBrowser::Poll() { - auto& dependencies = *this->context; - auto sizing = Sizing(*this); - BrowserCursor cursor{this->cursorState, dependencies.mouse, dependencies.renderSystem, dependencies.applicationWindow}; - const bool hasExternalEvents = this->externalEvents != nullptr; - BrowserFrame frame{sizing, cursor, this->host, this->browserWindow, hasExternalEvents}; - frame.Poll(); -} - -// OFFSET: 0x00AB2D50 -bool CWebBrowser::Navigate(std::string address) { - return NavigateBrowser(this->browser, this->host, this->combo, std::move(address)); -} - -// OFFSET: 0x00AB3120 -void CWebBrowser::ShowAuxiliary(unsigned char value) { - auto sizing = Sizing(*this); - - const bool hasExternalEvents = this->externalEvents != nullptr; - BrowserAuxiliaryVisibility visibility{sizing, hasExternalEvents, this->host, this->auxiliaryVisible}; - visibility.Show(value); -} - // OFFSET: 0x00AB3030 // FUNCTION: fn_17420 bool CWebBrowser::MatchesWindow(HWND window) const { diff --git a/Source/Client/Browser/WebBrowser.h b/Source/Client/Browser/WebBrowser.h index e1683575..c805d176 100644 --- a/Source/Client/Browser/WebBrowser.h +++ b/Source/Client/Browser/WebBrowser.h @@ -8,41 +8,31 @@ #include class BrowserClientSite; -class CMouse; -class CRenderSystemBase; -struct ServiceOptions; -struct BrowserRegistry; -struct BrowserFactory; -struct ApplicationActivation; - -struct WebBrowserContext { - HWND const& applicationWindow; - HINSTANCE const& instance; - const char* const& title; - CMouse& mouse; - CRenderSystemBase& renderSystem; - ServiceOptions& service; - ApplicationActivation& activation; - BrowserFactory& popupFactory; - const int& renderWidth; - const int& renderHeight; - WNDPROC hostProcedure; - WNDPROC editProcedure; - WNDPROC& previousEditProcedure; -}; class CWebBrowser { public: - explicit CWebBrowser(WebBrowserContext& context); + CWebBrowser(); ~CWebBrowser(); CWebBrowser(const CWebBrowser&) = delete; CWebBrowser& operator=(const CWebBrowser&) = delete; - bool Create(int width, int height); + bool Create(HWND parent, HINSTANCE instance, int width, int height); bool Close(); - bool AttachExternalEvents(BrowserRegistry& registry); + bool CreateInterface(); + bool CreateExternalInterface(); + bool AttachExternalEvents(); + bool CreateHostWindow(HWND parent, HINSTANCE instance, int width, int height); + bool AttachSite(); + void DetachSite(); + bool CreateAddressBar(int width, int height); void Resize(int width, int height); + void RefreshSize(); + void Normalize(); void Poll(); + void SetCursorState(int value); + void PollCursor(); + void EnterInput(); + void RestoreInput(); bool Navigate(std::string address); void ShowAuxiliary(unsigned char value); bool MatchesWindow(HWND window) const; @@ -66,16 +56,23 @@ public: /* 0038 */ int height; /* 003C */ unsigned char restoreOption; /* 003D */ unsigned char unknown_003D[3]; - WebBrowserContext* context; }; +extern WNDPROC lpPrevWndFunc; + +LRESULT CALLBACK BrowserHostProc(HWND window, UINT message, WPARAM value, LPARAM flags); +LRESULT CALLBACK BrowserAddressEditProc(HWND window, UINT message, WPARAM value, LPARAM flags); +HRESULT AdviseBrowserEvents(IUnknown* source, IUnknown* sink, REFIID events, DWORD* cookie); +HRESULT UnadviseBrowserEvents(IUnknown* source, REFIID events, DWORD cookie); + +enum class BrowserCommand : WORD { Navigate = 1000 }; + #if defined(_WIN32) && !defined(_WIN64) static_assert(offsetof(CWebBrowser, host) == 0xC); static_assert(offsetof(CWebBrowser, unknown_0019) == 0x19); static_assert(offsetof(CWebBrowser, cookie) == 0x24); static_assert(offsetof(CWebBrowser, restoreOption) == 0x3C); -static_assert(offsetof(CWebBrowser, unknown_003D) == 0x3D); -static_assert(offsetof(CWebBrowser, context) == 0x40); +static_assert(sizeof(CWebBrowser) == 0x40); #endif #endif diff --git a/Source/Client/Browser/WebEventReceiver.cpp b/Source/Client/Browser/WebEventReceiver.cpp index 5d54d679..a7e06fe4 100644 --- a/Source/Client/Browser/WebEventReceiver.cpp +++ b/Source/Client/Browser/WebEventReceiver.cpp @@ -1,6 +1,6 @@ -#include "Client/Browser/BrowserInterface.h" -#include "Client/Browser/BrowserRegistry.h" +#include "Client/Browser/WebBrowser.h" #include "Client/Browser/WebEventReceiver.h" +#include "UI/Window/UIWindowMgr.h" #include #include @@ -9,8 +9,8 @@ // OFFSET: 0x00AB3710 // FUNCTION: fn_17424 -CWebEventReceiver::CWebEventReceiver(BrowserRegistry& registry) - : m_references(0), m_browser(nullptr), m_browserCookie(0), m_document(nullptr), m_documentCookie(0), m_host(nullptr), m_registry(registry) { +CWebEventReceiver::CWebEventReceiver() + : m_references(0), m_browser(nullptr), m_browserCookie(0), m_document(nullptr), m_documentCookie(0), m_host(nullptr) { OutputDebugStringA("CWebEventReceiver() \n"); } @@ -98,7 +98,7 @@ HRESULT CWebEventReceiver::Disconnect() { this->m_browser = nullptr; } - this->m_registry.Remove(this->m_host); + g_windowMgr.RemoveBrowser(this->m_host); return S_OK; } diff --git a/Source/Client/Browser/WebEventReceiver.h b/Source/Client/Browser/WebEventReceiver.h index 35f6f16c..86c578c7 100644 --- a/Source/Client/Browser/WebEventReceiver.h +++ b/Source/Client/Browser/WebEventReceiver.h @@ -5,11 +5,9 @@ #include #include -struct BrowserRegistry; - class CWebEventReceiver final : public IDispatch { public: - explicit CWebEventReceiver(BrowserRegistry& registry); + CWebEventReceiver(); bool Register(IWebBrowser2* browser, HWND host); HRESULT Disconnect(); @@ -30,7 +28,6 @@ private: /* 0010 */ IDispatch* m_document; /* 0014 */ DWORD m_documentCookie; /* 0018 */ HWND m_host; - BrowserRegistry& m_registry; void ReleaseDocument(); }; diff --git a/Source/Client/Mode/CLoginMode.h b/Source/Client/Mode/CLoginMode.h index ad7afea9..afd704fa 100644 --- a/Source/Client/Mode/CLoginMode.h +++ b/Source/Client/Mode/CLoginMode.h @@ -181,6 +181,8 @@ extern char g_zoneServerHost[129]; extern int g_hangameLogin; extern CharacterInfo g_charInfo; extern bool g_replayMode; +extern int g_restoreSurfaces; +extern int g_isAppActive; int GetClientType(); std::string GetMacAddress(); diff --git a/Source/Client/Mode/CMode.h b/Source/Client/Mode/CMode.h index caae93cc..a26abbab 100644 --- a/Source/Client/Mode/CMode.h +++ b/Source/Client/Mode/CMode.h @@ -40,6 +40,7 @@ public: CMode(); std::uint32_t ClearTooltip(); + void ExpireTooltip(); void TakeScreenshot(); void DrawCursor(); void DrawFadeIn(); diff --git a/Source/Client/Mode/LoginMode.cpp b/Source/Client/Mode/LoginMode.cpp index 064d5958..c24c01f8 100644 --- a/Source/Client/Mode/LoginMode.cpp +++ b/Source/Client/Mode/LoginMode.cpp @@ -991,7 +991,7 @@ void CLoginMode::Slot5(int value) { g_windowMgr.ProcessMouse(); if (this->running != 0) { this->SubD97780(this->cursorType); - reinterpret_cast(this)->Expire(g_windowMgr); + this->ExpireTooltip(); } if (g_restoreSurfaces != 0) { @@ -1134,7 +1134,7 @@ void CLoginMode::Update() { g_windowMgr.ProcessMouse(); if (this->running != 0) { this->SubD97780(this->cursorType); - reinterpret_cast(this)->Expire(g_windowMgr); + this->ExpireTooltip(); } reinterpret_cast(g_timeScheduler)->Process(); diff --git a/Source/Client/Mode/ModeTooltip.cpp b/Source/Client/Mode/ModeTooltip.cpp index 8d391b3d..31cbea3e 100644 --- a/Source/Client/Mode/ModeTooltip.cpp +++ b/Source/Client/Mode/ModeTooltip.cpp @@ -61,17 +61,17 @@ void ModeTooltip::Show(const char* value, int x, int y, std::uint32_t color, uns // OFFSET: 0x00AD67A0 // FUNCTION: fn_17843 -void ModeTooltip::Expire(UIWindowMgr& retirement) { - if (!this->window) { +void CMode::ExpireTooltip() { + if (!this->tooltip) { return; } - if (timeGetTime() < this->tick + 100u) { + if (timeGetTime() < this->tooltipTick + 100u) { return; } - retirement.Schedule(this->window); - this->window = nullptr; + g_windowMgr.Schedule(this->tooltip); + this->tooltip = nullptr; } // OFFSET: 0x00AD64B0 diff --git a/Source/Client/Mode/ModeTooltip.h b/Source/Client/Mode/ModeTooltip.h index 9f15d24b..f190d766 100644 --- a/Source/Client/Mode/ModeTooltip.h +++ b/Source/Client/Mode/ModeTooltip.h @@ -22,8 +22,6 @@ struct ModeTooltip { const int& screenHeight; void Show(const char* value, int x, int y, std::uint32_t color, unsigned char option, unsigned char convert); - - void Expire(UIWindowMgr& retirement); }; #endif diff --git a/Source/UI/Window/UIWindowMgr.cpp b/Source/UI/Window/UIWindowMgr.cpp index ceec34ee..51e1defc 100644 --- a/Source/UI/Window/UIWindowMgr.cpp +++ b/Source/UI/Window/UIWindowMgr.cpp @@ -722,8 +722,8 @@ UIWindowMgr::UIWindowMgr() this->window_4F16C = nullptr; this->InitializeWindowPolicy(); this->window_4F174 = nullptr; - this->unknown_09CC = 0; - this->browser_09D0 = nullptr; + this->activeBrowser = nullptr; + this->specialBrowser = nullptr; this->currentHitUid = 0; this->previousHitUid = 0; this->visible_276 = 0; @@ -769,9 +769,9 @@ void UIWindowMgr::Shutdown() { entry.second = nullptr; } this->browsers.clear(); - if (this->browser_09D0) { - delete this->browser_09D0; - this->browser_09D0 = nullptr; + if (this->specialBrowser) { + delete this->specialBrowser; + this->specialBrowser = nullptr; } for (auto entry = this->overlays.begin(); entry != this->overlays.end();) { diff --git a/Source/UI/Window/UIWindowMgr.h b/Source/UI/Window/UIWindowMgr.h index c683bb42..a10601a0 100644 --- a/Source/UI/Window/UIWindowMgr.h +++ b/Source/UI/Window/UIWindowMgr.h @@ -372,8 +372,8 @@ public: /* 0934 */ unsigned char unknown_0934[0x10]; /* 0944 */ unsigned char unknown_0944[0x80]; /* 09C4 */ std::map browsers; - /* 09CC */ int unknown_09CC; - /* 09D0 */ CWebBrowser* browser_09D0; + /* 09CC */ CWebBrowser* activeBrowser; + /* 09D0 */ CWebBrowser* specialBrowser; /* 09D4 */ unsigned char unknown_09D4[0x10]; /* 09E4 */ std::vector messageBoxes; /* 09F0 */ unsigned char unknown_09F0[0x40]; @@ -484,6 +484,10 @@ public: void ClearUnknown04DC(); int ProcessMouse(); void UpdateFrameWindows(); + CWebBrowser* CreateBrowser(int width, int height); + CWebBrowser* EnsureSpecialBrowser(int width, int height); + CWebBrowser* FindBrowser(HWND window); + void RemoveBrowser(HWND window); bool CloseWindow(int id); void CloseWindowExcept251(int id); void RecordWindowPacket(int argument); diff --git a/Source/UI/Window/WindowFrameUpdate.h b/Source/UI/Window/WindowFrameUpdate.h deleted file mode 100644 index c58acc94..00000000 --- a/Source/UI/Window/WindowFrameUpdate.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef RAGNAROK_SOURCE_UI_WINDOW_WINDOWFRAMEUPDATE_H -#define RAGNAROK_SOURCE_UI_WINDOW_WINDOWFRAMEUPDATE_H - -#include -#include - -class UIWindow; -struct BrowserRegistry; - -struct WindowFrameUpdate { - std::list& rendered; - BrowserRegistry& browsers; - std::map& overlays; - - void Update(); -}; - -#endif