Skip to content

Commit

Permalink
async prepare, red not found tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciremun committed May 10, 2024
1 parent 9a337a7 commit db719da
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
28 changes: 19 additions & 9 deletions freedom/clrhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct ClassMethod
ClassMethodType t;
};

std::vector<std::future<void>> prepare_method_tasks;
int prepared_methods_count = -1;
_AssemblyPtr mscorlib_assembly = 0;
_AssemblyPtr osu_assembly = 0;
Expand Down Expand Up @@ -401,6 +402,8 @@ bool prepare_methods()
method_info_cls->GetProperty(method_handle_b, (BindingFlags)(BindingFlags_Instance | BindingFlags_Public), &method_handle_prop);
SysFreeString(method_handle_b);

prepare_method_tasks.clear();
prepare_method_tasks.reserve(70);
for (LONG i = 0; i < classes_count; ++i)
{
_TypePtr class_ = 0;
Expand Down Expand Up @@ -461,8 +464,6 @@ bool prepare_methods()
VARIANT method_handle_value;
VariantInit(&method_handle_value);
method_handle_prop->GetValue(method_handle_ptr, method_handle_args, &method_handle_value);

SAFEARRAY *params = get_params(&method_handle_value);
for (const auto& cm : classmethods)
{
if (!match_method_name_length(method, cm) && cm.t != ClassMethodType::UpdateVariables)
Expand All @@ -471,20 +472,29 @@ bool prepare_methods()
if (!verify_classmethod(class_, method, cm))
continue;

hr = prepare_method->Invoke_3(method_handle_value, params, &method_handle_value);
if (FAILED(hr))
FR_INFO_FMT("[!] Invoke (0x%X)", hr);
else
++prepared_methods_count;
const auto prepare = [](_MethodInfoPtr prepare_method, VARIANT method_handle_value) {
SAFEARRAY *params = get_params(&method_handle_value);
HRESULT hr = prepare_method->Invoke_3(method_handle_value, params, &method_handle_value);
SafeArrayDestroy(params);
if (FAILED(hr))
FR_INFO_FMT("[!] Invoke (0x%X)", hr);
else
++prepared_methods_count;
};
prepare_method_tasks.push_back(
std::async(std::launch::async, prepare,
prepare_method, method_handle_value));
break;
}
SafeArrayDestroy(params);
}
SafeArrayDestroy(methods);
}

SafeArrayDestroy(classes);
SafeArrayDestroy(method_handle_args);

for (const auto &task : prepare_method_tasks)
task.wait_for(std::chrono::milliseconds(10 * 1000) / prepare_method_tasks.size());

FR_INFO_FMT("Preparing Methods Took: %lfs", ImGui::GetTime() - s);
FR_INFO_FMT("Prepared Methods: %d", prepared_methods_count);
return true;
Expand Down
4 changes: 2 additions & 2 deletions freedom/features/relax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ static char current_click = cfg_relax_style == 'a' ? right_click[0] : left_click

void calc_od_timing()
{
static const auto rand_range_f = [](float f_min, float f_max) -> float
const auto rand_range_f = [](float f_min, float f_max) -> float
{
float scale = rand() / (float)RAND_MAX;
return f_min + scale * (f_max - f_min);
};
static const auto rand_range_i = [](int i_min, int i_max) -> int
const auto rand_range_i = [](int i_min, int i_max) -> int
{
return rand() % (i_max + 1 - i_min) + i_min;
};
Expand Down
2 changes: 1 addition & 1 deletion freedom/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool parse_beatmap(uintptr_t osu_manager_ptr, BeatmapData &beatmap_data)
else if (beatmap_data.mods & Mods::HalfTime) od_window *= 1.33f;

// FIXME(Ciremun): refactor
static const auto rand_range_f = [](float f_min, float f_max) -> float
const auto rand_range_f = [](float f_min, float f_max) -> float
{
float scale = rand() / (float)RAND_MAX;
return f_min + scale * (f_max - f_min);
Expand Down
4 changes: 3 additions & 1 deletion freedom/ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ void update_ui()
const auto inactive_tab = [](const char *tab_name)
{
ImGui::BeginDisabled();
ImGui::PushStyleColor(ImGuiCol_Text, LOG_ERROR);
ImGui::Selectable(tab_name, false, ImGuiSelectableFlags_DontClosePopups);
ImGui::PopStyleColor();
ImGui::EndDisabled();
};

Expand Down Expand Up @@ -588,7 +590,7 @@ void draw_debug_log()
ImGui::PopStyleVar();
ImGui::BeginChild("##debug_game", ImVec2(.0f, -30.f));
ImGui::Text("Audio Time: %d", audio_time_ptr ? *(int32_t *)audio_time_ptr : 0);
static const auto scene_ptr_to_str = [](Scene *s){
const auto scene_ptr_to_str = [](Scene *s){
if (!s) return "Unknown";
Scene scene = *s;
switch (scene)
Expand Down
2 changes: 2 additions & 0 deletions include/clrhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <vector>
#include <string>
#include <future>
#include <chrono>

#include <stdint.h>

Expand Down
Binary file modified nobuild.exe
Binary file not shown.

0 comments on commit db719da

Please sign in to comment.