r5sdk/r5dev/common/completion.cpp

196 lines
7.0 KiB
C++
Raw Normal View History

Code base refactor + major performance and readability improvement. Read description for details. * 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!).
2021-12-25 22:36:38 +01:00
//=============================================================================//
//
// Purpose: Completion functions for ConCommand callbacks.
Code base refactor + major performance and readability improvement. Read description for details. * 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!).
2021-12-25 22:36:38 +01:00
//
//=============================================================================//
#include "core/stdafx.h"
#include "public/iconvar.h"
#include "engine/cmodel_bsp.h"
#include "tier1/strtools.h"
#include "completion.h"
#include "vstdlib/autocompletefilelist.h"
//-----------------------------------------------------------------------------
// Purpose:
// Input : *partial -
// context -
// longest -
// maxcommands -
// **commands -
// Output : int
//-----------------------------------------------------------------------------
int _Host_Map_f_CompletionFunc(char const* cmdname, char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
char* substring = (char*)partial;
if (strstr(partial, cmdname))
{
substring = (char*)partial + strlen(cmdname);
}
2023-09-05 17:34:22 +02:00
const int mapcount = g_InstalledMaps.Count();
const int longest = COMMAND_COMPLETION_ITEM_LENGTH;
const int count = MIN(mapcount, COMMAND_COMPLETION_MAXITEMS);
int filtered_count = 0;
if (count > 0)
{
for (int i = 0; i < count; i++)
{
2023-09-05 17:34:22 +02:00
if (strstr(g_InstalledMaps[i].String(), substring))
{
2023-09-05 17:34:22 +02:00
strncpy(commands[filtered_count], g_InstalledMaps[i].String(), longest);
char old[COMMAND_COMPLETION_ITEM_LENGTH];
strncpy(old, commands[filtered_count], sizeof(old));
snprintf(commands[filtered_count], sizeof(commands[filtered_count]), "%s%s", cmdname, old);
commands[filtered_count][strlen(commands[filtered_count])] = '\0';
filtered_count++;
}
}
}
return filtered_count;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *autocomplete -
// *partial -
// context -
// longest -
// maxcommands -
// **commands -
// Output : int
//-----------------------------------------------------------------------------
int _Host_Pak_f_CompletionFunc(CBaseAutoCompleteFileList* autocomplete, char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
int count = autocomplete->AutoCompletionFunc(partial, commands);
if (count > 0)
{
for (size_t i = 0; i < count; i++)
{
size_t cmdsize = strlen(commands[i]);
if (cmdsize < COMMAND_COMPLETION_ITEM_LENGTH - 5)
{
snprintf(&commands[i][cmdsize], 5, "%s", "rpak");
}
else
{
snprintf(commands[i], COMMAND_COMPLETION_ITEM_LENGTH, "%s", "BUFFER_TOO_SMALL!");
}
}
}
return count;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *partial -
// **commands -
// Output : int
//-----------------------------------------------------------------------------
int Host_SSMap_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
char const* cmdname = "ss_map ";
return _Host_Map_f_CompletionFunc(cmdname, partial, commands);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *partial -
// **commands -
// Output : int
//-----------------------------------------------------------------------------
int Host_Map_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
char const* cmdname = "map ";
return _Host_Map_f_CompletionFunc(cmdname, partial, commands);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *partial -
// **commands -
// Output : int
//-----------------------------------------------------------------------------
int Host_Background_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
char const* cmdname = "map_background ";
return _Host_Map_f_CompletionFunc(cmdname, partial, commands);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *partial -
// **commands -
// Output : int
//-----------------------------------------------------------------------------
int Host_Changelevel_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
char const* cmdname = "changelevel ";
return _Host_Map_f_CompletionFunc(cmdname, partial, commands);
}
static CBaseAutoCompleteFileList s_GiveAutoFileList("give", "scripts/weapons", "txt");
//-----------------------------------------------------------------------------
// Purpose:
// Input : *partial -
// **commands -
// Output : int
//-----------------------------------------------------------------------------
int Game_Give_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
return s_GiveAutoFileList.AutoCompletionFunc(partial, commands);
}
static CBaseAutoCompleteFileList s_PakLoadAutoFileList("pak_requestload", "paks/Win64", "rpak");
//-----------------------------------------------------------------------------
// Purpose:
// Input : *partial -
// **commands -
// Output : int
//-----------------------------------------------------------------------------
int RTech_PakLoad_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
return _Host_Pak_f_CompletionFunc(&s_PakLoadAutoFileList, partial, commands);
}
static CBaseAutoCompleteFileList s_PakUnloadAutoFileList("pak_requestunload", "paks/Win64", "rpak");
//-----------------------------------------------------------------------------
// Purpose:
// Input : *partial -
// **commands -
// Output : int
//-----------------------------------------------------------------------------
int RTech_PakUnload_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
return _Host_Pak_f_CompletionFunc(&s_PakUnloadAutoFileList, partial, commands);
}
static CBaseAutoCompleteFileList s_PakCompress("pak_compress", "paks/Win64_override", "rpak");
//-----------------------------------------------------------------------------
// Purpose:
// Input : *partial -
// **commands -
// Output : int
//-----------------------------------------------------------------------------
int RTech_PakCompress_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
return _Host_Pak_f_CompletionFunc(&s_PakCompress, partial, commands);
}
static CBaseAutoCompleteFileList s_PakDecompress("pak_decompress", "paks/Win64", "rpak");
//-----------------------------------------------------------------------------
// Purpose:
// Input : *partial -
// **commands -
// Output : int
//-----------------------------------------------------------------------------
int RTech_PakDecompress_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
return _Host_Pak_f_CompletionFunc(&s_PakDecompress, partial, commands);
}