From e4df03c4f2341206faa8647ecb5798a82c5db8ce Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 6 Feb 2023 02:16:02 +0100 Subject: [PATCH] Add RPak completion callbacks Add completion for 'pak_requestload' and 'pak_requestunload'. --- r5dev/tier1/cmd.cpp | 4 +-- r5dev/vstdlib/completion.cpp | 69 ++++++++++++++++++++++++++++++------ r5dev/vstdlib/completion.h | 3 ++ 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/r5dev/tier1/cmd.cpp b/r5dev/tier1/cmd.cpp index aeef346b..70c0586b 100644 --- a/r5dev/tier1/cmd.cpp +++ b/r5dev/tier1/cmd.cpp @@ -375,8 +375,8 @@ void ConCommand::Init(void) // RTECH API | ConCommand::Create("rtech_strtoguid", "Calculates the GUID from input data.", FCVAR_DEVELOPMENTONLY, RTech_StringToGUID_f, nullptr); ConCommand::Create("rtech_decompress", "Decompresses the specified RPAK file.", FCVAR_DEVELOPMENTONLY, RTech_Decompress_f, nullptr); - ConCommand::Create("pak_requestload", "Requests asynchronous load for specified RPAK file.", FCVAR_DEVELOPMENTONLY, Pak_RequestLoad_f, nullptr); - ConCommand::Create("pak_requestunload", "Requests unload for specified RPAK file or ID.", FCVAR_DEVELOPMENTONLY, Pak_RequestUnload_f, nullptr); + ConCommand::Create("pak_requestload", "Requests asynchronous load for specified RPAK file.", FCVAR_DEVELOPMENTONLY, Pak_RequestLoad_f, RTech_PakLoad_f_CompletionFunc); + ConCommand::Create("pak_requestunload", "Requests unload for specified RPAK file or ID.", FCVAR_DEVELOPMENTONLY, Pak_RequestUnload_f, RTech_PakUnload_f_CompletionFunc); ConCommand::Create("pak_swap", "Requests swap for specified RPAK file or ID", FCVAR_DEVELOPMENTONLY, Pak_Swap_f, nullptr); ConCommand::Create("pak_listpaks", "Display a list of the loaded Pak files.", FCVAR_RELEASE, Pak_ListPaks_f, nullptr); ConCommand::Create("pak_listtypes", "Display a list of the registered asset types.", FCVAR_RELEASE, Pak_ListTypes_f, nullptr); diff --git a/r5dev/vstdlib/completion.cpp b/r5dev/vstdlib/completion.cpp index ce343630..5e55f534 100644 --- a/r5dev/vstdlib/completion.cpp +++ b/r5dev/vstdlib/completion.cpp @@ -50,13 +50,42 @@ int _Host_Map_f_CompletionFunc(char const* cmdname, char const* partial, char co //----------------------------------------------------------------------------- // Purpose: -// Input : *partial - +// Input : *autocomplete - +// *partial - // context - // longest - // maxcommands - // **commands - // Output : int //----------------------------------------------------------------------------- +int _Host_Pak_f_CompletionFunc(CAutoCompleteFileList* 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 - 4) + { + 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 "; @@ -66,9 +95,6 @@ int Host_SSMap_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPL //----------------------------------------------------------------------------- // Purpose: // Input : *partial - -// context - -// longest - -// maxcommands - // **commands - // Output : int //----------------------------------------------------------------------------- @@ -81,9 +107,6 @@ int Host_Map_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLET //----------------------------------------------------------------------------- // Purpose: // Input : *partial - -// context - -// longest - -// maxcommands - // **commands - // Output : int //----------------------------------------------------------------------------- @@ -96,9 +119,6 @@ int Host_Background_f_CompletionFunc(char const* partial, char commands[COMMAND_ //----------------------------------------------------------------------------- // Purpose: // Input : *partial - -// context - -// longest - -// maxcommands - // **commands - // Output : int //----------------------------------------------------------------------------- @@ -109,8 +129,37 @@ int Host_Changelevel_f_CompletionFunc(char const* partial, char commands[COMMAND } static CAutoCompleteFileList 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 CAutoCompleteFileList 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 CAutoCompleteFileList 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); +} diff --git a/r5dev/vstdlib/completion.h b/r5dev/vstdlib/completion.h index 10aae755..089a6b82 100644 --- a/r5dev/vstdlib/completion.h +++ b/r5dev/vstdlib/completion.h @@ -9,6 +9,9 @@ int Host_Changelevel_f_CompletionFunc(char const* partial, char commands[COMMAND int Game_Give_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH]); +int RTech_PakLoad_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH]); +int RTech_PakUnload_f_CompletionFunc(char const* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH]); + inline CMemory p_CAutoCompleteFileList_AutoCompletionFunc; inline auto v_CAutoCompleteFileList_AutoCompletionFunc = p_CAutoCompleteFileList_AutoCompletionFunc.RCast();