mirror of
https://github.com/XLabsProject/s1x-client.git
synced 2023-08-02 15:02:12 +02:00
Merge pull request #32 from iAmThatMichael/changes
Add listassetpool, consoleList, fix various problems
This commit is contained in:
commit
d01ab885f4
@ -226,6 +226,15 @@ namespace command
|
||||
}
|
||||
}
|
||||
|
||||
void enum_assets(const game::XAssetType type, const std::function<void(game::XAssetHeader)>& callback, const bool includeOverride)
|
||||
{
|
||||
game::DB_EnumXAssets_Internal(type, static_cast<void(*)(game::XAssetHeader, void*)>([](game::XAssetHeader header, void* data)
|
||||
{
|
||||
const auto& cb = *static_cast<const std::function<void(game::XAssetHeader)>*>(data);
|
||||
cb(header);
|
||||
}), &callback, includeOverride);
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
@ -254,6 +263,29 @@ namespace command
|
||||
*reinterpret_cast<int*>(1) = 0;
|
||||
});
|
||||
|
||||
add("consoleList", [](const params& params)
|
||||
{
|
||||
const std::string input = params.get(1);
|
||||
|
||||
std::vector<std::string> matches;
|
||||
game_console::find_matches(input, matches, false);
|
||||
|
||||
for(auto& match : matches)
|
||||
{
|
||||
auto* dvar = game::Dvar_FindVar(match.c_str());
|
||||
if (!dvar)
|
||||
{
|
||||
game_console::print(game_console::con_type_info, "[CMD]\t %s", match.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
game_console::print(game_console::con_type_info, "[DVAR]\t%s \"%s\"", match.c_str(), game::Dvar_ValueToString(dvar, dvar->current));
|
||||
}
|
||||
}
|
||||
|
||||
game_console::print(game_console::con_type_info, "Total %i matches", matches.size());
|
||||
});
|
||||
|
||||
add("dvarDump", []()
|
||||
{
|
||||
game_console::print(game_console::con_type_info,
|
||||
@ -291,6 +323,44 @@ namespace command
|
||||
game_console::print(game_console::con_type_info,
|
||||
"================================ END COMMAND DUMP =================================\n");
|
||||
});
|
||||
|
||||
add("listassetpool", [](const params& params)
|
||||
{
|
||||
if (params.size() < 2)
|
||||
{
|
||||
game_console::print(game_console::con_type_info,
|
||||
"listassetpool <poolnumber>: list all the assets in the specified pool\n");
|
||||
|
||||
for (auto i = 0; i < game::XAssetType::ASSET_TYPE_COUNT; i++)
|
||||
{
|
||||
game_console::print(game_console::con_type_info, "%d %s\n", i, game::g_assetNames[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto type = static_cast<game::XAssetType>(atoi(params.get(1)));
|
||||
|
||||
if (type < 0 || type >= game::XAssetType::ASSET_TYPE_COUNT)
|
||||
{
|
||||
game_console::print(game_console::con_type_error,
|
||||
"Invalid pool passed must be between [%d, %d]", 0,
|
||||
game::XAssetType::ASSET_TYPE_COUNT - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
game_console::print(game_console::con_type_info, "Listing assets in pool %s",
|
||||
game::g_assetNames[type]);
|
||||
|
||||
enum_assets(type, [type](game::XAssetHeader header)
|
||||
{
|
||||
const auto asset = game::XAsset{ type, header };
|
||||
const auto* const asset_name = game::DB_GetXAssetName(&asset);
|
||||
//const auto entry = game::DB_FindXAssetEntry(type, asset_name);
|
||||
//TODO: display which zone the asset is from
|
||||
game_console::print(game_console::con_type_info, "%s", asset_name);
|
||||
}, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void add_commands_sp()
|
||||
|
@ -63,39 +63,6 @@ namespace fastfiles
|
||||
game::DB_LoadXAssets(&info, 1u, game::DBSyncMode::DB_LOAD_SYNC);
|
||||
});
|
||||
|
||||
command::add("materiallist", [](const command::params& params)
|
||||
{
|
||||
game::DB_EnumXAssets_FastFile(game::ASSET_TYPE_MATERIAL, [](const game::XAssetHeader header, void*)
|
||||
{
|
||||
if (header.material && header.material->name)
|
||||
{
|
||||
printf("%s\n", header.material->name);
|
||||
}
|
||||
}, 0, false);
|
||||
});
|
||||
|
||||
command::add("fontlist", [](const command::params& params)
|
||||
{
|
||||
game::DB_EnumXAssets_FastFile(game::ASSET_TYPE_FONT, [](const game::XAssetHeader header, void*)
|
||||
{
|
||||
if (header.font && header.font->fontName)
|
||||
{
|
||||
printf("%s\n", header.font->fontName);
|
||||
}
|
||||
}, 0, false);
|
||||
});
|
||||
|
||||
command::add("rawfilelist", [](const command::params& params)
|
||||
{
|
||||
game::DB_EnumXAssets_FastFile(game::ASSET_TYPE_RAWFILE, [](const game::XAssetHeader header, void*)
|
||||
{
|
||||
if (header.rawfile && header.rawfile->name)
|
||||
{
|
||||
printf("%s\n", header.rawfile->name);
|
||||
}
|
||||
}, 0, false);
|
||||
});
|
||||
|
||||
command::add("g_poolSizes", []()
|
||||
{
|
||||
for (auto i = 0; i < game::ASSET_TYPE_COUNT; i++)
|
||||
|
@ -171,57 +171,7 @@ namespace game_console
|
||||
const auto _y = con.globals.font_height + con.globals.y + (con.globals.font_height * (line + 1)) + 15.0f;
|
||||
|
||||
game::R_AddCmdDrawText(text, 0x7FFFFFFF, console_font, con.globals.x + offset, _y, 1.0f, 1.0f, 0.0f, color,
|
||||
0);
|
||||
}
|
||||
|
||||
bool match_compare(const std::string& input, const std::string& text, const bool exact)
|
||||
{
|
||||
if (exact && text == input) return true;
|
||||
if (!exact && text.find(input) != std::string::npos) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void find_matches(std::string input, std::vector<std::string>& suggestions, const bool exact)
|
||||
{
|
||||
input = utils::string::to_lower(input);
|
||||
|
||||
for (int i = 0; i < *game::dvarCount; i++)
|
||||
{
|
||||
if (game::sortedDvars[i] && game::sortedDvars[i]->name)
|
||||
{
|
||||
std::string name = utils::string::to_lower(game::sortedDvars[i]->name);
|
||||
|
||||
if (match_compare(input, name, exact))
|
||||
{
|
||||
suggestions.push_back(game::sortedDvars[i]->name);
|
||||
}
|
||||
|
||||
if (exact && suggestions.size() > 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
game::cmd_function_s* cmd = (*game::cmd_functions);
|
||||
while (cmd)
|
||||
{
|
||||
if (cmd->name)
|
||||
{
|
||||
std::string name = utils::string::to_lower(cmd->name);
|
||||
|
||||
if (match_compare(input, name, exact))
|
||||
{
|
||||
suggestions.push_back(cmd->name);
|
||||
}
|
||||
|
||||
if (exact && suggestions.size() > 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
cmd = cmd->next;
|
||||
}
|
||||
0);
|
||||
}
|
||||
|
||||
void draw_input()
|
||||
@ -379,7 +329,7 @@ namespace game_console
|
||||
const auto height = ((con.screen_max[1] - con.screen_min[1]) - 32.0f) - 12.0f;
|
||||
|
||||
game::R_AddCmdDrawText(game::Dvar_FindVar("version")->current.string, 0x7FFFFFFF, console_font, x,
|
||||
((height - 16.0f) + y) + console_font->pixelHeight, 1.0f, 1.0f, 0.0f, color_s1, 0);
|
||||
((height - 12.0f) + y) + console_font->pixelHeight, 1.0f, 1.0f, 0.0f, color_s1, 0);
|
||||
|
||||
draw_output_scrollbar(x, y, width, height);
|
||||
draw_output_text(x, y);
|
||||
@ -496,6 +446,7 @@ namespace game_console
|
||||
{
|
||||
clear();
|
||||
con.line_count = 0;
|
||||
con.display_line_offset = 0;
|
||||
con.output.clear();
|
||||
history_index = -1;
|
||||
history.clear();
|
||||
@ -542,6 +493,11 @@ namespace game_console
|
||||
{
|
||||
if (key == game::keyNum_t::K_F10)
|
||||
{
|
||||
if (game::mp::svs_clients[localClientNum].header.state >= 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
game::Cmd_ExecuteSingleCommand(localClientNum, 0, "lui_open menu_systemlink_join\n");
|
||||
}
|
||||
|
||||
@ -672,6 +628,56 @@ namespace game_console
|
||||
return true;
|
||||
}
|
||||
|
||||
bool match_compare(const std::string& input, const std::string& text, const bool exact)
|
||||
{
|
||||
if (exact && text == input) return true;
|
||||
if (!exact && text.find(input) != std::string::npos) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void find_matches(std::string input, std::vector<std::string>& suggestions, const bool exact)
|
||||
{
|
||||
input = utils::string::to_lower(input);
|
||||
|
||||
for (int i = 0; i < *game::dvarCount; i++)
|
||||
{
|
||||
if (game::sortedDvars[i] && game::sortedDvars[i]->name)
|
||||
{
|
||||
std::string name = utils::string::to_lower(game::sortedDvars[i]->name);
|
||||
|
||||
if (game_console::match_compare(input, name, exact))
|
||||
{
|
||||
suggestions.push_back(game::sortedDvars[i]->name);
|
||||
}
|
||||
|
||||
if (exact && suggestions.size() > 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
game::cmd_function_s* cmd = (*game::cmd_functions);
|
||||
while (cmd)
|
||||
{
|
||||
if (cmd->name)
|
||||
{
|
||||
std::string name = utils::string::to_lower(cmd->name);
|
||||
|
||||
if (game_console::match_compare(input, name, exact))
|
||||
{
|
||||
suggestions.push_back(cmd->name);
|
||||
}
|
||||
|
||||
if (exact && suggestions.size() > 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
cmd = cmd->next;
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
@ -713,6 +719,7 @@ namespace game_console
|
||||
{
|
||||
clear();
|
||||
con.line_count = 0;
|
||||
con.display_line_offset = 0;
|
||||
con.output.clear();
|
||||
history_index = -1;
|
||||
history.clear();
|
||||
|
@ -14,4 +14,7 @@ namespace game_console
|
||||
|
||||
bool console_char_event(int local_client_num, int key);
|
||||
bool console_key_event(int local_client_num, int key, int down);
|
||||
|
||||
bool match_compare(const std::string& input, const std::string& text, const bool exact);
|
||||
void find_matches(std::string input, std::vector<std::string>& suggestions, const bool exact);
|
||||
}
|
||||
|
@ -210,6 +210,12 @@ namespace party
|
||||
|
||||
if (!game::environment::is_dedi())
|
||||
{
|
||||
if(game::SV_Loaded())
|
||||
{
|
||||
const auto* args = "Leave";
|
||||
game::UI_RunMenuScript(0, &args);
|
||||
}
|
||||
|
||||
perform_game_initialization();
|
||||
}
|
||||
|
||||
@ -238,11 +244,8 @@ namespace party
|
||||
command::execute(utils::string::va("party_maxplayers %i", maxclients->current.integer), true);
|
||||
}*/
|
||||
|
||||
// StartServer
|
||||
reinterpret_cast<void(*)(unsigned int)>(0x140492260)(0);
|
||||
|
||||
//game::SV_StartMapForParty(0, mapname.data(), false, false);
|
||||
//return;
|
||||
const auto* args = "StartServer";
|
||||
game::UI_RunMenuScript(0, &args);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1059,6 +1059,22 @@ namespace game
|
||||
LuaFile* luaFile;
|
||||
};
|
||||
|
||||
struct XAsset
|
||||
{
|
||||
XAssetType type;
|
||||
XAssetHeader header;
|
||||
};
|
||||
|
||||
struct XAssetEntry
|
||||
{
|
||||
XAsset asset;
|
||||
char zoneIndex;
|
||||
volatile char inuseMask;
|
||||
unsigned int nextHash;
|
||||
unsigned int nextOverride;
|
||||
unsigned int nextPoolEntry;
|
||||
};
|
||||
|
||||
enum TestClientType
|
||||
{
|
||||
TC_NONE = 0x0,
|
||||
|
@ -41,6 +41,11 @@ namespace game
|
||||
|
||||
WEAK symbol<void(XAssetType type, void (__cdecl* func)(XAssetHeader, void*), void* inData, bool includeOverride)>
|
||||
DB_EnumXAssets_FastFile{0x14017D7C0, 0x14026EC10};
|
||||
WEAK symbol<void(XAssetType type, void(__cdecl* func)(game::XAssetHeader, void*), const void* inData, bool includeOverride)>
|
||||
DB_EnumXAssets_Internal{ 0x14017D830, 0x14026EC80 };
|
||||
WEAK symbol<game::XAssetEntry(game::XAssetType type, const char* name)>
|
||||
DB_FindXAssetEntry{ 0x14017D830, 0x14026F020 };
|
||||
WEAK symbol<const char* (const XAsset* asset)> DB_GetXAssetName{0x140151C00, 0x140240DD0};
|
||||
WEAK symbol<int(XAssetType type)> DB_GetXAssetTypeSize{0x140151C20, 0x140240DF0};
|
||||
WEAK symbol<void(XZoneInfo* zoneInfo, unsigned int zoneCount, DBSyncMode syncMode)> DB_LoadXAssets{
|
||||
0x1402F8B50, 0x140270F30
|
||||
@ -193,6 +198,8 @@ namespace game
|
||||
WEAK symbol<SOCKET> query_socket{0, 0x14B5B9180};
|
||||
|
||||
WEAK symbol<void*> DB_XAssetPool{0x140804690, 0x1409B40D0};
|
||||
WEAK symbol<unsigned int> db_hashTable{0x142C3E050, 0x143716B10};
|
||||
WEAK symbol<XAssetEntry> g_assetEntryPool{0x142CC2400, 0x14379F100};
|
||||
WEAK symbol<int> g_poolSize{0x140804140, 0x1409B4B90};
|
||||
WEAK symbol<const char*> g_assetNames{0x140803C90, 0x1409B3180};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user