The string buffer was moved to the stack on a recent refactor, but the data must persist even outside the function scope. Moved back to class in form of a buffer.
Made the style of the code more consistent. Not much logic-wise had changed during the refactor, but there are some.
Console:
* Removed m_bSuggestUpdate and the logic bound to it, this var was never set and the logic was never used. This was the initial workaround for resetting the autocomplete selection pos to kPark (-1), but this is currently done in a more mature way, but the old code was never removed
* CreateSuggestionsFromPartial() (previously, FindFromPartial()) would break if a ConCommand/ConVar was found that was already added in the list. Although this is an engine/sdk level bug, we shouldn't stop iterating there. Added an assert instead and made the loop continue.
* Removed member m_bCopyToClipBoard, this was used to check if the copy button was pressed, to copy the text the next frame. The copy now happens directly in the site of the Copy button which is a better approach.
* Due to the changes with removing m_bCopyToClipBoard, the mutex for m_colorTextLogger is now released right after rendering the color text to fully minimize blocking time between other threads.
Browser:
* Moved ImGui::Begin() call from RunFrame() to DrawSurface(), it fits better there and we can now also return false if the frame didn't render.
* Improved the "Broadcasting" text formatting when server browser is hosting and broadcasting without a server token (public server).
Both:
* Added virtual Shutdown() method.
ImGui drawing code now takes place in the main thread, a snapshot of the render data is created in CMaterialSystem::SwapBuffers(), and is being rendered in the render thread right before SpinPresent().
The reason why this was necessary, is because ConVar::GetString() isn't thread safe if its not marked FCVAR_MATERIAL_SYSTEM_THREAD or FCVAR_ACCESSIBLE_FROM_THREADS, and we used it for the console suggestions window, which iterates over every ConVar, accessible from threads or not.
Fully implemented ConVar class so we could statically construct all SDK convars, this avoids a level of indirection, and allows for creating ConVar's everywhere in the project.
This patch also removed the settings tab of the ImGui server browser, as it has threading issues, while it technically never caused a crash yet, it has been removed as there was no point keeping it vs the work required to make it thread save (it only managed 2 convars which are perfectly manageable through cfg's or the in-game console).
Also temporarily disabled the creation of ConVar's in the mod system due to a memory leak, we would allocate and register a convar based on details parsed out of a mod file definition, but never unregister and free it.
Properly implement the ConCommandBase and ConCommand classes so we could statically construct all ConCommand objects in the global scope of each translation unit, this way we don't need to put them in a global file and deal with preprocessor directives to compile then in/out for certain projects.
* Use CThreadFastMutex instead
* Rename ISurface to IDebugSurface to prevent a potential name collision with VGUI's ISurface iface if we ever add it
* Fix race condition when setting CPylon::m_HostIP from materialsystem thread, this has been dispatched to the main thread
* Marked 'pylon_matchmaking_hostname' FCVAR_MATERIAL_SYSTEM_THREAD as we use it in the server browser panel.
Avoid heap memory allocation and a level of indirection. This allows the compiler to optimize the program even more. No logic has been changed in this patch.
Fix a rare crash that occurs in AMD driver code, when ImGui shutdown was called. The crash did not occur if the library was shutdown after having rendered one of the ImGui panels for one frame. The fix is to just never call 'ImGui_ImplDX11_NewFrame()', 'ImGui_ImplWin32_NewFrame()' and 'ImGui::NewFrame()', 'ImGui::EndFrame()', 'ImGui::Render()' if none of the windows are visible. code has been tested on a system that would trigger the crash, and after the patch, the crash no longer happened.
The console draws focus as it does SetKeyboardFocusHere(-1) (on the previous widget, which is the input text field). We don't do this in the server browser, so we must explicitly claim focus by calling SetNextWindowFocus() once before the next frame gets renderer.
* Removed extraneous text line for hosting, combined error and hosting into 1.
* Removed extraneous 'Force Start' button. The server will now 'Force Start' when the visibility is offline, else require the user to fill out the required fields in order to host the server.
* Only clear the request message when the color is green and we are no longer hosting. All errors will remain until the server is restarted through the browser panel.
* Only run '_DownloadPlaylists_f()' in the main thread, schedule for next frame if we aren't in the main thread. (this should fix crash cases related to disconnecting from the game).
* Locked read/write to CBrowser members (thread for obtaining the server list is detached, but once the 'slow' post operation in this thread is complete, mutex lock is acquired (locking the render thread if the browser is active) to set the string members of CBrowser, this operation is very fast as we only set the string and the color after the http post operation (this never caused a crash, but the behavior without any lock mechanism is technically undefined regardless).
* Obtain the host name dynamically from the ConVar 'pylon_matchmaking_hostname' (atomic operation). Initial approach was deleting the whole master server pointer just to construct a new httpclient object..
* Eliminated all forms of concurrency for CConsole logger.
* Used enum for determining which theme user loaded (DEFAULT, LEGACY, MODERN).
* Fixed issue where browser panel doesn't have the same frame padding as the console for the modern theme.
* Fixed issue where the history items count shows number higher than maximum until updated (updates vector before displaying, else this happens in g_pConsole->RunTask which is the operation that happens before we add new elements to the vector, thus showing the wrong count as this size is getting corrected the next frame after we painted, we don't update the summary each frame for performance reasons).
* Added new function 'GetAvailablePlaylists' to all VM's.
* Moved function 'GetAvailableMaps' from UI VM to all VM's.
* Improved logic behind 'GetAvailableMaps'.
* Server browser and SQVM now rely on 'MOD_GetAllInstalledMaps'. This new function populates the global vector 'g_vAllMaps' with all installed maps.
* Improved 'KeyValues' structure to use union for shared members.
Before we used the stbsp's, but we don't need to copy these for each maps (we could load existing ones to get working texture streaming for maps that don't have this)
* Add ConVar to allow user to set/unset FCVAR_DEVELOPMENTONLY ConVar's (default behavior would never be hit without this ConVar).
* Add icons to display the flags of a certain CommandBase.
* Fixed Dear ImGui not displaying images correctly (descriptor needs DXGI_FORMAT_R8G8B8A8_UNORM_SRGB due to the nature of this game).
* Dynamically obtain buffer sizes of resources taken from modules.
* Light SDK cleanup.
* sq server browser clean up
* Properly loop through std::vector on GetAvailableMaps.
Co-authored-by: IcePixelx <41352111+PixieCore@users.noreply.github.com>
* IConsole overlay now clears the oldest log entries to stay under the vector limit instead of clearing the whole vector.
* IConsole code cleanup.
* IBrowser code cleanup, reordered class methods.
* Use ConVar utilities to get/set values for strings in IBrowser and IConsole.
* New ConVar's for RUI console overlay to tweak colors.
* Codebase restructured to SourceSDK codebase style and .cpp/.h assertion paths in the game executable.
* Document most functions with valve style 'Purpose' blocks.
* Rename variables to match the rest of the codebase and Valve's naming convention.
* Dedicated DLL and the SDKLauncher now share the same codebase as the DevSDK.
* Obtain globals or pointers directly instead of waiting for runtime initialized data.
* Dynamically search for all functions and globals (this doesn't count for dedicated yet!).
* Initialize most in-SDK variables.
* Move certain prints and other utilities under ConVars to reduce verbosity and increase performance.
* Print all pattern scan results through a virtual function to make it easier to add and debug new patterns in the future.
* Type global var pointers appropriately if class or type is known and implemented.
* Forward declare 'CClient' class to avoid having 2 'g_pClient' copies.
* Add IDA's pseudo definitions for easier prototyping with decompiled assembly code.
* RPAK decompress Command callback implementation.
* Load decompressed RPaks from 'paks\Win32\' overriding the ones in 'paks\Win64\' (the decompress callback will automatically fix the header and write it to 'paks\Win32\').
* VPK decompress Command callback implementation.
* Move CRC32 ands Adler32 to implementation files.
* Server will print out more details about the connecting client.
* Upgrade ImGui lib to v1.86.
* Don't compile id3dx.h for dedicated.
* Don't compile id3dx.cpp for dedicated
* Implement DevMsg print function allowing to print information to the in-game VGUI/RUI console overlay, ImGui console overlay and the external windows console
* Fixed bug where the Error function would not properly terminate the process when an error is called. This caused access violations for critical/non-recoverable errors.
* Fixed bug where the game would crash if the console or server browser was enabled while the game was still starting up.
* Several bug fixes for the dedicated server (warning: dedicated is still considered work-in-progress!).