diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index 6fba69f6..4acdef6a 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -303,70 +303,77 @@ namespace command return; } - try + const std::string arg = params.get(1); + const std::string arg2 = params.get(2); + const auto count = params.size(); + + scheduler::once([=]() { - const auto arg = params.get(1); - const scripting::entity player = scripting::call("getentbynum", {0}).as(); - auto ps = game::g_entities[0].client; + printf("%i\n", game::Sys_IsMainThread()); - if (arg == "ammo"s) + try { - const auto weapon = player.call("getcurrentweapon").as(); - player.call("givemaxammo", {weapon}); - } - else if (arg == "allammo"s) - { - const auto weapons = player.call("getweaponslist").as(); - for (auto i = 0; i < weapons.size(); i++) - { - player.call("givemaxammo", {weapons[i]}); - } - } - else if (arg == "health"s) - { - if (params.size() > 2) - { - const auto amount = atoi(params.get(2)); - const auto health = player.get("health").as(); - player.set("health", {health + amount}); - } - else - { - const auto amount = game::Dvar_FindVar("g_player_maxhealth")->current.integer; - player.set("health", {amount}); - } - } - else if (arg == "all"s) - { - 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); + const scripting::entity player = scripting::call("getentbynum", {0}).as(); + auto ps = game::g_entities[0].client; - player.call("giveweapon", {asset_name}); - }, true); - } - else - { - const auto wp = game::G_GetWeaponForName(arg); - if (wp) + if (arg == "ammo") { - if (game::G_GivePlayerWeapon(ps, wp, 0, 0, 0, 0)) + const auto weapon = player.call("getcurrentweapon").as(); + player.call("givemaxammo", {weapon}); + } + else if (arg == "allammo") + { + const auto weapons = player.call("getweaponslist").as(); + for (auto i = 0; i < weapons.size(); i++) { - game::G_InitializeAmmo(ps, wp, 0); - game::G_SelectWeapon(0, wp); + player.call("givemaxammo", {weapons[i]}); } } + else if (arg == "health") + { + if (count > 2) + { + const auto amount = atoi(arg2.data()); + const auto health = player.get("health").as(); + player.set("health", {health + amount}); + } + else + { + const auto amount = game::Dvar_FindVar("g_player_maxhealth")->current.integer; + player.set("health", {amount}); + } + } + 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 { - game::CG_GameMessage(0, "Weapon does not exist"); + const auto wp = game::G_GetWeaponForName(arg.data()); + if (wp) + { + if (game::G_GivePlayerWeapon(ps, wp, 0, 0, 0, 0)) + { + game::G_InitializeAmmo(ps, wp, 0); + game::G_SelectWeapon(0, wp); + } + } + else + { + game::CG_GameMessage(0, "Weapon does not exist"); + } } } - } - catch (...) - { - } + catch (...) + { + } + }, scheduler::pipeline::server); }); add("dropweapon", [](const params& params) @@ -376,15 +383,18 @@ namespace command return; } - try + scheduler::once([]() { - const scripting::entity player = scripting::call("getentbynum", {0}).as(); - const auto weapon = player.call("getcurrentweapon"); - player.call("dropitem", {weapon}); - } - catch (...) - { - } + try + { + const scripting::entity player = scripting::call("getentbynum", {0}).as(); + const auto weapon = player.call("getcurrentweapon"); + player.call("dropitem", {weapon}); + } + catch (...) + { + } + }, scheduler::pipeline::server); }); add("take", [](const params& params) @@ -400,23 +410,26 @@ namespace command return; } - const auto weapon = params.get(1); + const std::string weapon = params.get(1); - try + scheduler::once([=]() { - const auto player = scripting::call("getentbynum", {0}).as(); - if (weapon == "all"s) + try { - player.call("takeallweapons"); + const auto player = scripting::call("getentbynum", {0}).as(); + if (weapon == "all"s) + { + player.call("takeallweapons"); + } + else + { + player.call("takeweapon", {weapon}); + } } - else + catch (...) { - player.call("takeweapon", {weapon}); } - } - catch (...) - { - } + }, scheduler::pipeline::server); }); add("kill", [](const params& params) diff --git a/src/client/component/gui.cpp b/src/client/component/gui.cpp index f8187cbe..1cba1a67 100644 --- a/src/client/component/gui.cpp +++ b/src/client/component/gui.cpp @@ -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(); diff --git a/src/client/component/input.cpp b/src/client/component/input.cpp index 7b14cc46..027cd685 100644 --- a/src/client/component/input.cpp +++ b/src/client/component/input.cpp @@ -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(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(local_client_num, key, down); diff --git a/src/client/game/ui_scripting/execution.cpp b/src/client/game/ui_scripting/execution.cpp index fe6e3f7a..e6c8c115 100644 --- a/src/client/game/ui_scripting/execution.cpp +++ b/src/client/game/ui_scripting/execution.cpp @@ -57,6 +57,7 @@ namespace ui_scripting table event{}; event.set("name", name); + event.set("dispatchChildren", true); for (const auto& arg : arguments) {