Skip to content

Commit

Permalink
Implemented missing overlapped commands
Browse files Browse the repository at this point in the history
  • Loading branch information
twist84 committed Sep 4, 2024
1 parent dcca7e3 commit aeb88eb
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 3 deletions.
82 changes: 79 additions & 3 deletions game/source/cseries/async_xoverlapped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct s_overlapped_globals
bool inject_error;
c_static_string<64> inject_error_context;

bool paused;
bool pause;
c_static_string<64> pause_context;

long description_count;
Expand Down Expand Up @@ -165,7 +165,7 @@ void __cdecl overlapped_initialize()
c_virtual_keyboard_task::get_instance(__FILE__, __LINE__, k_any_controller, NULL, NULL, NULL, 0, 0, true);
g_overlapped_globals.toggle_debug_rendering = false;
g_overlapped_globals.inject_error = false;
g_overlapped_globals.paused = false;
g_overlapped_globals.pause = false;
g_overlapped_globals.description_count = false;
}

Expand Down Expand Up @@ -479,7 +479,7 @@ bool __cdecl task_is_complete(s_task_slot* task_slot, dword* return_result, dwor
}
}

if (g_overlapped_globals.paused)
if (g_overlapped_globals.pause)
{
if (g_overlapped_globals.pause_context.is_equal(task_slot->task->get_context_string()))
result = false;
Expand Down Expand Up @@ -653,3 +653,79 @@ void overlapped_tasks_log_to_debug_txt(e_event_level event_level)

}

void overlapped_task_display_task_descriptions()
{
c_async_xoverlapped_scope_lock scope_lock;

generate_event(_event_level_warning, "xoverlapped: dumping task descriptions [count %d]",
g_overlapped_globals.description_count);

for (long description_index = 0; description_index < g_overlapped_globals.description_count; description_index++)
{
generate_event(_event_level_warning, "xoverlapped: %s",
g_overlapped_globals.descriptions[description_index].get_string());
}
}

void overlapped_task_inject_error(char const* context, bool inject_error)
{
c_async_xoverlapped_scope_lock scope_lock;

bool context_matches_description = false;
for (long description_index = 0; description_index < g_overlapped_globals.description_count; description_index++)
{
if (g_overlapped_globals.descriptions[description_index].is_equal(context))
{
context_matches_description = true;
break;
}
}

if (context_matches_description)
{
generate_event(_event_level_warning, "xoverlapped: setting error injection for %s to %s",
context,
inject_error ? "TRUE" : "FALSE");

g_overlapped_globals.inject_error_context.set(context);
g_overlapped_globals.inject_error = inject_error;
}
else
{
generate_event(_event_level_warning, "xoverlapped: failed to find setting error injection for %s to %s",
context,
inject_error ? "TRUE" : "FALSE");
}
}

void overlapped_task_pause(char const* context, bool pause)
{
c_async_xoverlapped_scope_lock scope_lock;

bool context_matches_description = false;
for (long description_index = 0; description_index < g_overlapped_globals.description_count; description_index++)
{
if (g_overlapped_globals.descriptions[description_index].is_equal(context))
{
context_matches_description = true;
break;
}
}

if (context_matches_description)
{
generate_event(_event_level_warning, "xoverlapped: setting pause for %s to %s",
context,
pause ? "TRUE" : "FALSE");

g_overlapped_globals.pause_context.set(context);
g_overlapped_globals.pause = pause;
}
else
{
generate_event(_event_level_warning, "xoverlapped: failed to find setting pause for %s to %s",
context,
pause ? "TRUE" : "FALSE");
}
}

4 changes: 4 additions & 0 deletions game/source/cseries/async_xoverlapped.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ extern bool __cdecl task_is_complete(s_task_slot* task_slot, dword* return_resul
extern void __cdecl task_now_finished(s_task_slot* task_slot, dword return_result, dword calling_result, dword overlapped_error, dword overlapped_extended_error);

extern void overlapped_tasks_log_to_debug_txt(e_event_level event_level);
extern void overlapped_task_display_task_descriptions();
extern void overlapped_task_inject_error(char const* context, bool inject_error);
extern void overlapped_task_pause(char const* context, bool pause);

33 changes: 33 additions & 0 deletions game/source/networking/tools/remote_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2016,3 +2016,36 @@ callback_result_t xoverlapped_debug_render_callback(void const* userdata, long t
return result;
}

callback_result_t overlapped_display_task_descriptions_callback(void const* userdata, long token_count, tokens_t const tokens)
{
COMMAND_CALLBACK_PARAMETER_CHECK;

overlapped_task_display_task_descriptions();

return result;
}

callback_result_t overlapped_task_inject_error_callback(void const* userdata, long token_count, tokens_t const tokens)
{
COMMAND_CALLBACK_PARAMETER_CHECK;

char const* context = tokens[1]->get_string();
long value = token_try_parse_bool(tokens[2]);
if (value != NONE)
overlapped_task_inject_error(context, static_cast<bool>(value - 1));

return result;
}

callback_result_t overlapped_task_pause_callback(void const* userdata, long token_count, tokens_t const tokens)
{
COMMAND_CALLBACK_PARAMETER_CHECK;

char const* context = tokens[1]->get_string();
long value = token_try_parse_bool(tokens[2]);
if (value != NONE)
overlapped_task_pause(context, static_cast<bool>(value - 1));

return result;
}

6 changes: 6 additions & 0 deletions game/source/networking/tools/remote_command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ COMMAND_CALLBACK_DECLARE(levels_add_map_solo);
COMMAND_CALLBACK_DECLARE(levels_add_fake_map_multi);
COMMAND_CALLBACK_DECLARE(levels_add_map_multi);
COMMAND_CALLBACK_DECLARE(xoverlapped_debug_render);
COMMAND_CALLBACK_DECLARE(overlapped_display_task_descriptions);
COMMAND_CALLBACK_DECLARE(overlapped_task_inject_error);
COMMAND_CALLBACK_DECLARE(overlapped_task_pause);

//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -351,6 +354,9 @@ s_command const k_registered_commands[] =
COMMAND_CALLBACK_REGISTER(levels_add_map_multi, 2, "<long> <string>", "<map_id> <scenario_path> adds a map with the specified map id for multiplayer\r\nNETWORK SAFE: Unknown, assumed unsafe"),

COMMAND_CALLBACK_REGISTER(xoverlapped_debug_render, 1, "<bool>", "toggle display a list of active xoverlapped tasks\r\nNETWORK SAFE: Unknown, assumed unsafe"),
COMMAND_CALLBACK_REGISTER(overlapped_display_task_descriptions, 0, "", "displays all tasks\r\nNETWORK SAFE: lol"),
COMMAND_CALLBACK_REGISTER(overlapped_task_inject_error, 2, "<string> <bool>", "inject error for tasks\r\nNETWORK SAFE: lol"),
COMMAND_CALLBACK_REGISTER(overlapped_task_pause, 2, "<string> <bool>", "pause tasks\r\nNETWORK SAFE: lol"),
};

extern void command_tokenize(char const* input, tokens_t& tokens, long* token_count);
Expand Down

0 comments on commit aeb88eb

Please sign in to comment.