Some fixes

This commit is contained in:
Federico Cecchetto 2022-04-18 20:01:23 +02:00
parent 87dcfaf91b
commit a8537ed67b
4 changed files with 110 additions and 86 deletions

View File

@ -303,18 +303,25 @@ namespace command
return;
}
const std::string arg = params.get(1);
const std::string arg2 = params.get(2);
const auto count = params.size();
scheduler::once([=]()
{
printf("%i\n", game::Sys_IsMainThread());
try
{
const auto arg = params.get(1);
const scripting::entity player = scripting::call("getentbynum", {0}).as<scripting::entity>();
auto ps = game::g_entities[0].client;
if (arg == "ammo"s)
if (arg == "ammo")
{
const auto weapon = player.call("getcurrentweapon").as<std::string>();
player.call("givemaxammo", {weapon});
}
else if (arg == "allammo"s)
else if (arg == "allammo")
{
const auto weapons = player.call("getweaponslist").as<scripting::array>();
for (auto i = 0; i < weapons.size(); i++)
@ -322,11 +329,11 @@ namespace command
player.call("givemaxammo", {weapons[i]});
}
}
else if (arg == "health"s)
else if (arg == "health")
{
if (params.size() > 2)
if (count > 2)
{
const auto amount = atoi(params.get(2));
const auto amount = atoi(arg2.data());
const auto health = player.get("health").as<int>();
player.set("health", {health + amount});
}
@ -336,20 +343,19 @@ namespace command
player.set("health", {amount});
}
}
else if (arg == "all"s)
else if (arg == "all")
{
const auto type = game::XAssetType::ASSET_TYPE_WEAPON;
fastfiles::enum_assets(type, [&player, type](const game::XAssetHeader header)
{
const auto asset = game::XAsset{type, header};
const auto* const asset_name = game::DB_GetXAssetName(&asset);
player.call("giveweapon", {asset_name});
}, true);
}
else
{
const auto wp = game::G_GetWeaponForName(arg);
const auto wp = game::G_GetWeaponForName(arg.data());
if (wp)
{
if (game::G_GivePlayerWeapon(ps, wp, 0, 0, 0, 0))
@ -367,6 +373,7 @@ namespace command
catch (...)
{
}
}, scheduler::pipeline::server);
});
add("dropweapon", [](const params& params)
@ -376,6 +383,8 @@ namespace command
return;
}
scheduler::once([]()
{
try
{
const scripting::entity player = scripting::call("getentbynum", {0}).as<scripting::entity>();
@ -385,6 +394,7 @@ namespace command
catch (...)
{
}
}, scheduler::pipeline::server);
});
add("take", [](const params& params)
@ -400,8 +410,10 @@ namespace command
return;
}
const auto weapon = params.get(1);
const std::string weapon = params.get(1);
scheduler::once([=]()
{
try
{
const auto player = scripting::call("getentbynum", {0}).as<scripting::entity>();
@ -417,6 +429,7 @@ namespace command
catch (...)
{
}
}, scheduler::pipeline::server);
});
add("kill", [](const params& params)

View File

@ -68,8 +68,15 @@ namespace gui
void new_gui_frame()
{
ImGui::GetIO().MouseDrawCursor = toggled || *game::keyCatchers & 0x1;
*game::keyCatchers |= 0x10 * toggled;
ImGui::GetIO().MouseDrawCursor = toggled;
if (toggled)
{
*game::keyCatchers |= 0x10;
}
else
{
*game::keyCatchers &= ~0x10;
}
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();

View File

@ -26,41 +26,44 @@ namespace input
void cl_char_event_stub(const int local_client_num, const int key)
{
ui_scripting::notify("keypress",
if (!gui::gui_char_event(local_client_num, key))
{
{"keynum", key},
{"key", game::Key_KeynumToString(key, 0, 1)},
});
return;
}
if (!game_console::console_char_event(local_client_num, key))
{
return;
}
if (!gui::gui_char_event(local_client_num, key))
ui_scripting::notify("keypress",
{
return;
}
{"keynum", key},
{"key", game::Key_KeynumToString(key, 0, 1)},
});
cl_char_event_hook.invoke<void>(local_client_num, key);
}
void cl_key_event_stub(const int local_client_num, const int key, const int down)
{
ui_scripting::notify(down ? "keydown" : "keyup",
if (!gui::gui_key_event(local_client_num, key, down))
{
{"keynum", key},
{"key", game::Key_KeynumToString(key, 0, 1)},
});
return;
}
if (!game_console::console_key_event(local_client_num, key, down))
{
return;
}
if (!gui::gui_key_event(local_client_num, key, down))
if (!(*game::keyCatchers & 1) && !(*game::keyCatchers & 0x10))
{
return;
ui_scripting::notify(down ? "keydown" : "keyup",
{
{"keynum", key},
{"key", game::Key_KeynumToString(key, 0, 1)},
});
}
cl_key_event_hook.invoke<void>(local_client_num, key, down);

View File

@ -57,6 +57,7 @@ namespace ui_scripting
table event{};
event.set("name", name);
event.set("dispatchChildren", true);
for (const auto& arg : arguments)
{