Merge pull request #9 from ehhbased/main

reworked addbot cmd and added testclient spawn cmd.
This commit is contained in:
MatrixMMOfficial 2023-11-01 11:51:39 -04:00 committed by GitHub
commit 7b862a8391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 3 deletions

View File

@ -398,6 +398,11 @@ void Scr_AddString(scrContext_t* scrContext, const char* value) {
func(scrContext, value);
}
int SL_GetString(const char* value) {
auto func = reinterpret_cast<int(*)(const char*)>(0x14131AE30_g);
return func(value);
}
unsigned int GScr_ExecEntThread(gentity_s* ent, int handle, unsigned int paramcount) {
auto func = reinterpret_cast<unsigned int(*)(gentity_s*, int, unsigned int)>(0x141257D70_g);
return func(ent, handle, paramcount);
@ -461,12 +466,22 @@ short* SV_ClientMP_AddTestClient()
return SV_ClientMP_AddTestClient_func();
}
short* SV_ClientMP_AddBot()
{
auto func = reinterpret_cast<short*(*)(const char* bot_name, unsigned int head, unsigned int body, unsigned int helmet)>(0x14136E210_g);
return func("DONETSK", 0,0,0);
}
void GScr_AddEntity(short* entity)
{
auto GScr_AddEntity_func = reinterpret_cast<void(*)(short* ent)>(0x1412578a0_g);
GScr_AddEntity_func(entity);
}
void GScr_Notify(short* ent, unsigned int stringValue, unsigned int paramcount) {
reinterpret_cast<void(*)(short*, unsigned int, unsigned int)>(0x141259B30_g)(ent, stringValue, paramcount);
}
void SV_ClientMP_SpawnBotOrTestClient(short* entity)
{
auto SV_ClientMP_SpawnBotOrTestClient_func = reinterpret_cast<void(*)(short* ent)>(0x141373640_g);
@ -513,6 +528,7 @@ cmd_function_s set_pointer_f_VAR;
cmd_function_s quit_f_VAR;
cmd_function_s openmenu_f_VAR;
cmd_function_s addbot_f_VAR;
cmd_function_s addTestClient_f_VAR;
cmd_function_s ddldump_f_VAR;
cmd_function_s weapondefdump_f_VAR;
cmd_function_s view_vehicle_ents_f_VAR;

View File

@ -122,6 +122,7 @@ extern cmd_function_s set_pointer_f_VAR;
extern cmd_function_s quit_f_VAR;
extern cmd_function_s openmenu_f_VAR;
extern cmd_function_s addbot_f_VAR;
extern cmd_function_s addTestClient_f_VAR;
extern cmd_function_s ddldump_f_VAR;
extern cmd_function_s weapondefdump_f_VAR;
extern cmd_function_s view_vehicle_ents_f_VAR;
@ -240,6 +241,9 @@ void Com_SetErrorMessage(const char* errorMessage);
void GamerProfile_SetDataByName(unsigned int controllerIndex, const char* settingName, float settingValue);
short* SV_ClientMP_AddTestClient();
short* SV_ClientMP_AddBot();
void GScr_Notify(short* ent, unsigned int stringValue, unsigned int paramcount);
int SL_GetString(const char* value);
void GScr_AddEntity(short* entity);

View File

@ -11,6 +11,7 @@ void addCustomCmds()
Cmd_AddCommandInternal("quit", Cmd_Quit_f, &quit_f_VAR);
Cmd_AddCommandInternal("openmenu", Cmd_OpenMenu_f, &openmenu_f_VAR);
Cmd_AddCommandInternal("addbot", Cmd_AddBot_f, &addbot_f_VAR);
Cmd_AddCommandInternal("addtestclient", Cmd_AddTestClient_f, &addTestClient_f_VAR);
Cmd_AddCommandInternal("ddldump", Cmd_DDLDump_f, &ddldump_f_VAR);
Cmd_AddCommandInternal("weapondefdump", Cmd_WeaponDefDump_f, &weapondefdump_f_VAR);
//Cmd_AddCommandInternal("view_vehicle_ents", Cmd_ViewVehicleEnts_f, &view_vehicle_ents_f_VAR);
@ -283,11 +284,76 @@ void Cmd_OpenMenu_f()
}
}
void Cmd_AddTestClient_f()
{
auto max_clients = *(int*)0x14EEB0CE0_g;
auto client_count = *(int*)0x14E195070_g;
auto spawnable_bots = max_clients - client_count;
if (spawnable_bots <= 0)
return;
int spawn_number = 1;
if (Cmd_Argc() == 2)
{
char command[100]{ 0 };
Cmd_ArgvBuffer(1, command, sizeof(command));
spawn_number = atoll(command);
}
if (spawn_number > spawnable_bots)
spawn_number = spawnable_bots;
std::vector<short*> ents{};
for (int i{}; i < spawn_number; ++i)
{
auto ent = SV_ClientMP_AddTestClient();
if (!ent)
continue;
GScr_AddEntity(ent);
SV_ClientMP_SpawnBotOrTestClient(ent);
ents.push_back(ent);
}
Sleep(100);
for (auto& ent : ents) {
auto scrContext = ScriptContext_Server();
Scr_AddString(scrContext, "class1");
Scr_AddString(scrContext, "class_select");
GScr_Notify(ent, SL_GetString("loadout_class_selected"), 2);
}
}
void Cmd_AddBot_f()
{
auto ent = SV_ClientMP_AddTestClient();
GScr_AddEntity(ent);
SV_ClientMP_SpawnBotOrTestClient(ent);
auto max_clients = *(int*)0x14EEB0CE0_g;
auto client_count = *(int*)0x14E195070_g;
auto spawnable_bots = max_clients - client_count;
if (spawnable_bots <= 0)
return;
int spawn_number = 1;
if (Cmd_Argc() == 2)
{
char command[100]{ 0 };
Cmd_ArgvBuffer(1, command, sizeof(command));
spawn_number = atoll(command);
}
if (spawn_number > spawnable_bots)
spawn_number = spawnable_bots;
for (int i{}; i < spawn_number; ++i)
{
auto ent = SV_ClientMP_AddBot();
if (!ent)
return;
GScr_AddEntity(ent);
SV_ClientMP_SpawnBotOrTestClient(ent);
//Sleep(20);
}
}
void SV_CmdsMP_MapRestart_f()

View File

@ -22,6 +22,8 @@ void Cmd_OpenMenu_f();
void Cmd_AddBot_f();
void Cmd_AddTestClient_f();
void SV_CmdsMP_MapRestart_f();
void SV_CmdsMP_FastRestart_f();