r5sdk/r5dev/common/completion.cpp
Kawe Mazidjatari f120354e96 Initial port to CMake
* All libraries have been isolated from each other, and build into separate artifacts.
* Project has been restructured to support isolating libraries.
* CCrashHandler now calls a callback on crash (setup from core/dllmain.cpp, this can be setup in any way for any project. This callback is getting called when the apllication crashes. Useful for flushing buffers before closing handles to logging files for example).
* Tier0 'CoreMsgV' function now calls a callback sink, which could be set by the user (currently setup to the SDK's internal logger in core/dllmain.cpp).

TODO:
* Add a batch file to autogenerate all projects.
* Add support for dedicated server.
* Add support for client dll.

Bugs:
* Game crashes on the title screen after the UI script compiler has finished (root cause unknown).
* Curl error messages are getting logged twice for the dedicated server due to the removal of all "DEDICATED" preprocessor directives to support isolating projects. This has to be fixed properly!
2023-05-10 00:05:38 +02:00

184 lines
6.4 KiB
C++

//=============================================================================//
//
// Purpose: Completion functions for ConCommand callbacks.
//
//=============================================================================//
#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);
}
const int mapcount = (int)g_InstalledMaps.size();
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++)
{
if (strstr(g_InstalledMaps[i].c_str(), substring))
{
strncpy(commands[filtered_count], g_InstalledMaps[i].c_str(), 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_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);
}