From a1d7ceb963e49cc422b6f4758c6adfe48547f76c Mon Sep 17 00:00:00 2001 From: Ciremun Date: Sat, 11 May 2024 01:31:36 +0300 Subject: [PATCH] improve log macro --- freedom/clrhost.cpp | 110 ++++++++++++------------- freedom/features/aimbot.cpp | 12 +-- freedom/features/difficulty.cpp | 4 +- freedom/features/relax.cpp | 2 +- freedom/hitobject.cpp | 2 +- freedom/input.cpp | 4 +- freedom/parse.cpp | 34 ++++---- freedom/scan.cpp | 49 ++++++++--- freedom/standalone/standalone_main.cpp | 3 +- freedom/ui/config.cpp | 4 +- freedom/ui/ui.cpp | 4 +- include/scan.h | 6 ++ include/ui/debug_log.h | 24 ++++-- 13 files changed, 149 insertions(+), 109 deletions(-) diff --git a/freedom/clrhost.cpp b/freedom/clrhost.cpp index 700c067..dba8e11 100644 --- a/freedom/clrhost.cpp +++ b/freedom/clrhost.cpp @@ -164,7 +164,7 @@ static inline SAFEARRAY* get_types(_AssemblyPtr pAssembly, T... args) { if (pAssembly == 0) { - FR_INFO("[!] get_types failed, pAssembly is null"); + FR_ERROR("get_types failed, pAssembly is null"); return 0; } @@ -179,7 +179,7 @@ static inline SAFEARRAY* get_types(_AssemblyPtr pAssembly, T... args) if (!type_ptr) { std::string type_name_s = get_utf8(type_s); - FR_INFO_FMT("[!] GetType (%s, 0x%X)", type_name_s.c_str(), hr); + FR_ERROR("GetType (%s, 0x%X)", type_name_s.c_str(), hr); SafeArrayDestroy(types); return 0; } @@ -194,12 +194,12 @@ static inline bool variant_ok(VARIANT variant) return V_VT(&variant) != VT_EMPTY; } -static inline bool assemlies_loaded(const char *method) +static inline bool assemblies_loaded(const char *method) { if (osu_assembly == 0) - FR_INFO_FMT("[!] %s failed, osu! assembly is null", method); + FR_ERROR("%s failed, osu! assembly is null", method); if (mscorlib_assembly == 0) - FR_INFO_FMT("[!] %s failed, mscorlib assembly is null", method); + FR_ERROR("%s failed, mscorlib assembly is null", method); return osu_assembly && mscorlib_assembly; } @@ -209,7 +209,7 @@ static inline bool match_class_name_length(_TypePtr c) HRESULT hr = c->get_name(&c_name); if (!c_name) { - FR_INFO_FMT("[!] get_name (0x%X)", hr); + FR_ERROR("get_name (0x%X)", hr); return true; } UINT c_name_length = SysStringLen(c_name); @@ -226,7 +226,7 @@ static inline bool match_method_name_length(_MethodInfoPtr m, ClassMethod cm) HRESULT hr = m->get_name(&m_name); if (!m_name) { - FR_INFO_FMT("[!] get_name (0x%X)", hr); + FR_ERROR("get_name (0x%X)", hr); return true; } UINT m_name_length = SysStringLen(m_name); @@ -242,7 +242,7 @@ static bool verify_classmethod(_TypePtr c, _MethodInfoPtr m, ClassMethod cm) enum TypeAttributes ca; HRESULT hr = c->get_Attributes(&ca); if (FAILED(hr)) - FR_INFO_FMT("[!] get_Attributes (0x%X)", hr); + FR_ERROR("get_Attributes (0x%X)", hr); else { if ((ca & TypeAttributes_Abstract) != (cm.ca & TypeAttributes_Abstract)) return false; @@ -271,7 +271,7 @@ static bool verify_classmethod(_TypePtr c, _MethodInfoPtr m, ClassMethod cm) enum MethodAttributes ma; hr = m->get_Attributes(&ma); if (FAILED(hr)) - FR_INFO_FMT("[!] get_Attributes (0x%X)", hr); + FR_ERROR("get_Attributes (0x%X)", hr); else if (ma != cm.ma) return false; if (*cm.mrt) @@ -279,18 +279,18 @@ static bool verify_classmethod(_TypePtr c, _MethodInfoPtr m, ClassMethod cm) _TypePtr m_return_type = 0; hr = m->get_returnType(&m_return_type); if (!m_return_type) - FR_INFO_FMT("[!] get_returnType (0x%X)", hr); + FR_ERROR("get_returnType (0x%X)", hr); VARIANT_BOOL return_types_equal = VARIANT_TRUE; hr = m_return_type->Equals_2(*cm.mrt, &return_types_equal); if (FAILED(hr)) - FR_INFO_FMT("[!] Equals_2 (0x%X)", hr); + FR_ERROR("Equals_2 (0x%X)", hr); else if (return_types_equal == VARIANT_FALSE) return false; } SAFEARRAY *p = 0; hr = m->GetParameters(&p); if (!p) - FR_INFO_FMT("[!] GetParameters (0x%X)", hr); + FR_ERROR("GetParameters (0x%X)", hr); else { LONG lcnt2 = 0; @@ -298,7 +298,7 @@ static bool verify_classmethod(_TypePtr c, _MethodInfoPtr m, ClassMethod cm) hr = SafeArrayGetLBound(p, 1, &lcnt2); if (FAILED(hr)) { - FR_INFO_FMT("[!] SafeArrayGetLBound (0x%X)", hr); + FR_ERROR("SafeArrayGetLBound (0x%X)", hr); SafeArrayDestroy(p); return true; } @@ -306,7 +306,7 @@ static bool verify_classmethod(_TypePtr c, _MethodInfoPtr m, ClassMethod cm) hr = SafeArrayGetUBound(p, 1, &ucnt2); if (FAILED(hr)) { - FR_INFO_FMT("[!] SafeArrayGetUBound (0x%X)", hr); + FR_ERROR("SafeArrayGetUBound (0x%X)", hr); SafeArrayDestroy(p); return true; } @@ -320,7 +320,7 @@ static bool verify_classmethod(_TypePtr c, _MethodInfoPtr m, ClassMethod cm) bool prepare_methods() { - if (!assemlies_loaded("prepare_methods")) + if (!assemblies_loaded("prepare_methods")) return false; // NOTE(Ciremun): returns zero on race-condition @@ -330,13 +330,13 @@ bool prepare_methods() HRESULT hr = mscorlib_assembly->GetType_2(system_void_b, &system_void_type); SysFreeString(system_void_b); if (!system_void_type) - FR_INFO_FMT("[!] GetType_2 (0x%X)", hr); + FR_ERROR("GetType_2 (0x%X)", hr); BSTR system_double_b = SysAllocString(L"System.Double"); hr = mscorlib_assembly->GetType_2(system_double_b, &system_double_type); SysFreeString(system_double_b); if (!system_double_type) - FR_INFO_FMT("[!] GetType_2 (0x%X)", hr); + FR_ERROR("GetType_2 (0x%X)", hr); _TypePtr runtime_helpers_type = 0; BSTR runtime_helpers_b = SysAllocString(L"System.Runtime.CompilerServices.RuntimeHelpers"); @@ -344,7 +344,7 @@ bool prepare_methods() SysFreeString(runtime_helpers_b); if (!runtime_helpers_type) { - FR_INFO_FMT("[!] GetType_2 (0x%X)", hr); + FR_ERROR("GetType_2 (0x%X)", hr); return false; } @@ -359,7 +359,7 @@ bool prepare_methods() SafeArrayDestroy(types); if (!prepare_method) { - FR_INFO_FMT("[!] GetMethod_5 (0x%X)", hr); + FR_ERROR("GetMethod_5 (0x%X)", hr); return false; } @@ -367,7 +367,7 @@ bool prepare_methods() hr = osu_assembly->GetTypes(&classes); if (!classes) { - FR_INFO_FMT("[!] GetTypes (0x%X)", hr); + FR_ERROR("GetTypes (0x%X)", hr); return false; } @@ -376,7 +376,7 @@ bool prepare_methods() hr = SafeArrayGetLBound(classes, 1, &lcnt); if (FAILED(hr)) { - FR_INFO_FMT("[!] SafeArrayGetLBound (0x%X)", hr); + FR_ERROR("SafeArrayGetLBound (0x%X)", hr); SafeArrayDestroy(classes); return false; } @@ -384,7 +384,7 @@ bool prepare_methods() hr = SafeArrayGetUBound(classes, 1, &ucnt); if (FAILED(hr)) { - FR_INFO_FMT("[!] SafeArrayGetUBound (0x%X)", hr); + FR_ERROR("SafeArrayGetUBound (0x%X)", hr); SafeArrayDestroy(classes); return false; } @@ -410,7 +410,7 @@ bool prepare_methods() hr = SafeArrayGetElement(classes, &i, (void *)&class_); if (!class_) { - FR_INFO_FMT("[!] SafeArrayGetElement (%ld, 0x%X)", i, hr); + FR_ERROR("SafeArrayGetElement (%ld, 0x%X)", i, hr); continue; } @@ -422,7 +422,7 @@ bool prepare_methods() BindingFlags_Instance | BindingFlags_Static), &methods); if (!methods) { - FR_INFO_FMT("[!] GetMethods (0x%X)", hr); + FR_ERROR("GetMethods (0x%X)", hr); continue; } @@ -431,7 +431,7 @@ bool prepare_methods() hr = SafeArrayGetLBound(methods, 1, &lcnt2); if (FAILED(hr)) { - FR_INFO_FMT("[!] SafeArrayGetLBound (0x%X)", hr); + FR_ERROR("SafeArrayGetLBound (0x%X)", hr); SafeArrayDestroy(methods); continue; } @@ -439,7 +439,7 @@ bool prepare_methods() hr = SafeArrayGetUBound(methods, 1, &ucnt2); if (FAILED(hr)) { - FR_INFO_FMT("[!] SafeArrayGetUBound (0x%X)", hr); + FR_ERROR("SafeArrayGetUBound (0x%X)", hr); SafeArrayDestroy(methods); continue; } @@ -452,7 +452,7 @@ bool prepare_methods() hr = SafeArrayGetElement(methods, &j, (void *)&method); if (!method) { - FR_INFO_FMT("[!] SafeArrayGetElement (%ld, 0x%X)", j, hr); + FR_ERROR("SafeArrayGetElement (%ld, 0x%X)", j, hr); continue; } @@ -477,7 +477,7 @@ bool prepare_methods() 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); + FR_ERROR("Invoke (0x%X)", hr); else ++prepared_methods_count; }; @@ -495,14 +495,14 @@ bool prepare_methods() 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); + FR_INFO("Preparing Methods Took: %lfs", ImGui::GetTime() - s); + FR_INFO("Prepared Methods: %d", prepared_methods_count); return true; } intptr_t get_set_presence_ptr() { - if (!assemlies_loaded("get_set_presence_ptr")) + if (!assemblies_loaded("get_set_presence_ptr")) return 0; const wchar_t *type_name = L"DiscordRPC.DiscordRpcClient"; @@ -517,8 +517,8 @@ intptr_t get_set_presence_ptr() SysFreeString(type_name_b); if (!type_ptr) { - FR_INFO_FMT("[!] %s::%s", type_name_s.c_str(), method_name_s.c_str()); - FR_INFO_FMT("[!] GetType (0x%X)", hr); + FR_ERROR("%s::%s", type_name_s.c_str(), method_name_s.c_str()); + FR_ERROR("GetType (0x%X)", hr); return 0; } @@ -528,8 +528,8 @@ intptr_t get_set_presence_ptr() SysFreeString(method_name_b); if (!method_ptr) { - FR_INFO_FMT("[!] %s::%s", type_name_s.c_str(), method_name_s.c_str()); - FR_INFO_FMT("[!] GetMethod (0x%X)", hr); + FR_ERROR("%s::%s", type_name_s.c_str(), method_name_s.c_str()); + FR_ERROR("GetMethod (0x%X)", hr); return 0; } @@ -568,7 +568,7 @@ intptr_t get_set_presence_ptr() get_func_ptr_method_info->Invoke_3(method_handle_value, get_func_ptr_args, &method_handle_ptr); SafeArrayDestroy(get_func_ptr_args); - FR_INFO_FMT("[+] %s::%s", type_name_s.c_str(), method_name_s.c_str()); + FR_INFO("[+] %s::%s", type_name_s.c_str(), method_name_s.c_str()); return variant_ok(method_handle_ptr) ? V_INT(&method_handle_ptr) : 0; } @@ -580,7 +580,7 @@ void free_managed_string(intptr_t gc_handle) SysFreeString(gchandle_b); if (!gchandle_type) { - FR_INFO_FMT("[!] GetType (0x%X)", hr); + FR_ERROR("GetType (0x%X)", hr); return; } @@ -590,7 +590,7 @@ void free_managed_string(intptr_t gc_handle) SysFreeString(free_b); if (!free_method) { - FR_INFO_FMT("[!] GetMethod(\"Free\") (0x%X)", hr); + FR_ERROR("GetMethod(\"Free\") (0x%X)", hr); return; } @@ -601,7 +601,7 @@ void free_managed_string(intptr_t gc_handle) SafeArrayDestroy(params); if (FAILED(hr)) { - FR_INFO_FMT("[!] Invoke(\"Free\") (0x%X)", hr); + FR_ERROR("Invoke(\"Free\") (0x%X)", hr); return; } } @@ -614,7 +614,7 @@ intptr_t allocate_managed_string(const wchar_t *str, intptr_t *gc_handle) SysFreeString(gchandle_b); if (!gchandle_type) { - FR_INFO_FMT("[!] GetType (0x%X)", hr); + FR_ERROR("GetType (0x%X)", hr); return 0; } @@ -629,7 +629,7 @@ intptr_t allocate_managed_string(const wchar_t *str, intptr_t *gc_handle) SafeArrayDestroy(types); if (!alloc_method) { - FR_INFO_FMT("[!] GetMethod(\"Alloc\") (0x%X)", hr); + FR_ERROR("GetMethod(\"Alloc\") (0x%X)", hr); return 0; } @@ -649,7 +649,7 @@ intptr_t allocate_managed_string(const wchar_t *str, intptr_t *gc_handle) SafeArrayDestroy(params); if (FAILED(hr)) { - FR_INFO_FMT("[!] Invoke(\"Alloc\") (0x%X)", hr); + FR_ERROR("Invoke(\"Alloc\") (0x%X)", hr); return 0; } @@ -663,7 +663,7 @@ intptr_t allocate_managed_string(const wchar_t *str, intptr_t *gc_handle) SysFreeString(addrofpinned_b); if (!addr_of_pinned_object_method) { - FR_INFO_FMT("[!] GetMethod(\"AddrOfPinnedObject\") (0x%X)", hr); + FR_ERROR("GetMethod(\"AddrOfPinnedObject\") (0x%X)", hr); return 0; } @@ -672,7 +672,7 @@ intptr_t allocate_managed_string(const wchar_t *str, intptr_t *gc_handle) SafeArrayDestroy(get_func_args); if (FAILED(hr)) { - FR_INFO_FMT("[!] Invoke(\"AddrOfPinnedObject\") (0x%X)", hr); + FR_ERROR("Invoke(\"AddrOfPinnedObject\") (0x%X)", hr); return 0; } @@ -692,23 +692,23 @@ static inline ICorRuntimeHost* init_clr_runtime_host(LPCWSTR sz_runtimeVersion) return NULL; if (FAILED(CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (VOID**)&pMetaHost))) { - FR_INFO("[!] CLRCreateInstance"); + FR_ERROR("CLRCreateInstance"); return NULL; } if (FAILED(pMetaHost->GetRuntime(sz_runtimeVersion, IID_ICLRRuntimeInfo, (VOID**)&pRuntimeInfo))) { - FR_INFO_FMT("[!] GetRuntime failed: %S", sz_runtimeVersion); + FR_ERROR("GetRuntime failed: %S", sz_runtimeVersion); return NULL; } if (FAILED(pRuntimeInfo->IsLoadable(&bLoadable)) || !bLoadable) { - FR_INFO("[!] IsLoadable"); + FR_ERROR("IsLoadable"); return NULL; } if (FAILED(pRuntimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (VOID**)&pRuntimeHost))) { - FR_INFO("[!] GetInterface"); + FR_ERROR("GetInterface"); return NULL; } if (FAILED(pRuntimeHost->Start())) { - FR_INFO("[!] Start"); + FR_ERROR("Start"); return NULL; } return pRuntimeHost; @@ -717,12 +717,12 @@ static inline ICorRuntimeHost* init_clr_runtime_host(LPCWSTR sz_runtimeVersion) static inline _AppDomainPtr get_default_domain(ICorRuntimeHost* pRuntimeHost) { IUnknownPtr pAppDomainThunk = NULL; if (FAILED(pRuntimeHost->GetDefaultDomain(&pAppDomainThunk))) { - FR_INFO("[!] GetDefaultDomain"); + FR_ERROR("GetDefaultDomain"); return NULL; } _AppDomainPtr pDefaultAppDomain = NULL; if (FAILED(pAppDomainThunk->QueryInterface(__uuidof(_AppDomain), (LPVOID*)&pDefaultAppDomain))) { - FR_INFO("[!] QueryInterface"); + FR_ERROR("QueryInterface"); return NULL; } return pDefaultAppDomain; @@ -736,7 +736,7 @@ static inline _AssemblyPtr get_assembly(_AppDomainPtr pDefaultAppDomain, const w SysFreeString(assembly_b); if (!pAssembly) { - FR_INFO_FMT("[!] Load (0x%X)", hr); + FR_ERROR("Load (0x%X)", hr); return NULL; } return pAssembly; @@ -752,12 +752,12 @@ bool init_clrhost() { mscorlib_assembly = get_assembly(pDefaultAppDomain, L"mscorlib.dll"); if (!mscorlib_assembly) - FR_INFO("[!] Get mscorlib.dll Assembly Failed"); + FR_ERROR("Get mscorlib.dll Assembly Failed"); osu_assembly = get_assembly(pDefaultAppDomain, L"osu!"); if (!osu_assembly) - FR_INFO("[!] Get osu! Assembly Failed"); + FR_ERROR("Get osu! Assembly Failed"); return false; } - FR_INFO("[!] C# Get Default Domain Failed"); + FR_ERROR("C# Get Default Domain Failed"); return false; } diff --git a/freedom/features/aimbot.cpp b/freedom/features/aimbot.cpp index 0ff3948..3f3f697 100644 --- a/freedom/features/aimbot.cpp +++ b/freedom/features/aimbot.cpp @@ -47,17 +47,17 @@ void update_aimbot(Circle &circle, const int32_t audio_time) else if (circle.type == HitObjectType::Slider) { uintptr_t osu_manager = *(uintptr_t *)(osu_manager_ptr); - if (!osu_manager) { FR_INFO("[!] Aimbot: osu_manager"); return; } + if (!osu_manager) { FR_ERROR("Aimbot: osu_manager"); return; } uintptr_t hit_manager_ptr = *(uintptr_t *)(osu_manager + OSU_MANAGER_HIT_MANAGER_OFFSET); - if (!hit_manager_ptr) { FR_INFO("[!] Aimbot: hit_manager_ptr"); return; } + if (!hit_manager_ptr) { FR_ERROR("Aimbot: hit_manager_ptr"); return; } uintptr_t hit_objects_list_ptr = *(uintptr_t *)(hit_manager_ptr + OSU_HIT_MANAGER_HIT_OBJECTS_LIST_OFFSET); - if (!hit_objects_list_ptr) { FR_INFO("[!] Aimbot: hit_objects_list_ptr"); return; } + if (!hit_objects_list_ptr) { FR_ERROR("Aimbot: hit_objects_list_ptr"); return; } uintptr_t hit_objects_list_items_ptr = *(uintptr_t *)(hit_objects_list_ptr + 0x4); - if (!hit_objects_list_items_ptr) { FR_INFO("[!] Aimbot: hit_objects_list_items_ptr"); return; } + if (!hit_objects_list_items_ptr) { FR_ERROR("Aimbot: hit_objects_list_items_ptr"); return; } uintptr_t hit_object_ptr = *(uintptr_t *)(hit_objects_list_items_ptr + 0x8 + 0x4 * current_beatmap.hit_object_idx); - if (!hit_object_ptr) { FR_INFO("[!] Aimbot: hit_object_ptr"); return; } + if (!hit_object_ptr) { FR_ERROR("Aimbot: hit_object_ptr"); return; } uintptr_t animation_ptr = *(uintptr_t *)(hit_object_ptr + OSU_HIT_OBJECT_ANIMATION_OFFSET); - if (!animation_ptr) { FR_INFO("[!] Aimbot: animation_ptr"); return; } + if (!animation_ptr) { FR_ERROR("Aimbot: animation_ptr"); return; } float slider_ball_x = *(float *)(animation_ptr + OSU_ANIMATION_SLIDER_BALL_X_OFFSET); float slider_ball_y = *(float *)(animation_ptr + OSU_ANIMATION_SLIDER_BALL_Y_OFFSET); Vector2 slider_ball(slider_ball_x, slider_ball_y); diff --git a/freedom/features/difficulty.cpp b/freedom/features/difficulty.cpp index a7f8268..0418f27 100644 --- a/freedom/features/difficulty.cpp +++ b/freedom/features/difficulty.cpp @@ -178,12 +178,12 @@ void apply_mods_ar() if ((mods & Mods::Nightcore) || (mods & Mods::DoubleTime)) { ar_parameter.calculated_value = compensate_double_time(ar_parameter.value); - FR_INFO_FMT("ar_parameter.calculated_value: %.2f", ar_parameter.calculated_value); + FR_INFO("ar_parameter.calculated_value: %.2f", ar_parameter.calculated_value); return; } } ar_parameter.calculated_value = ar_parameter.value; - FR_INFO_FMT("ar_parameter.calculated_value: %.2f", ar_parameter.calculated_value); + FR_INFO("ar_parameter.calculated_value: %.2f", ar_parameter.calculated_value); } __declspec(naked) void set_approach_rate() diff --git a/freedom/features/relax.cpp b/freedom/features/relax.cpp index f627793..17fe0bb 100644 --- a/freedom/features/relax.cpp +++ b/freedom/features/relax.cpp @@ -81,7 +81,7 @@ void update_relax(Circle &circle, const int32_t audio_time) current_click = current_click == left_click[0] ? right_click[0] : left_click[0]; send_keyboard_input(current_click, 0); - FR_INFO_FMT("Relax hit %d!, %d %d", current_beatmap.hit_object_idx, circle.start_time, circle.end_time); + FR_INFO("Relax hit %d!, %d %d", current_beatmap.hit_object_idx, circle.start_time, circle.end_time); keyup_delay = circle.end_time ? circle.end_time - circle.start_time : 0.5; if (cfg_timewarp_enabled) diff --git a/freedom/hitobject.cpp b/freedom/hitobject.cpp index 2cd6280..11db0d1 100644 --- a/freedom/hitobject.cpp +++ b/freedom/hitobject.cpp @@ -45,7 +45,7 @@ void process_hitobject() if (mods_updated) { char selected_mods[64] = "Unknown"; - FR_INFO_FMT("mods updated: %s", selected_mods_ptr ? mods_to_string(*selected_mods_ptr, selected_mods) : "Unknown"); + FR_INFO("mods updated: %s", selected_mods_ptr ? mods_to_string(*selected_mods_ptr, selected_mods) : "Unknown"); ar_parameter.apply_mods(); mods_updated = false; } diff --git a/freedom/input.cpp b/freedom/input.cpp index a2288c8..7229b70 100644 --- a/freedom/input.cpp +++ b/freedom/input.cpp @@ -24,8 +24,8 @@ void init_input() } } } - FR_INFO_FMT("Left Click: %c", left_click[0]); - FR_INFO_FMT("Right Click: %c", right_click[0]); + FR_INFO("Left Click: %c", left_click[0]); + FR_INFO("Right Click: %c", right_click[0]); primary_monitor.x = (float)GetSystemMetrics(SM_CXSCREEN); primary_monitor.y = (float)GetSystemMetrics(SM_CYSCREEN); diff --git a/freedom/parse.cpp b/freedom/parse.cpp index e644c4e..6e512c6 100644 --- a/freedom/parse.cpp +++ b/freedom/parse.cpp @@ -49,21 +49,21 @@ bool parse_beatmap(uintptr_t osu_manager_ptr, BeatmapData &beatmap_data) if (osu_manager_ptr == 0) { - FR_INFO("[!] Parse Beatmap: osu_manager_ptr"); + FR_ERROR("Parse Beatmap: osu_manager_ptr"); return false; } uintptr_t osu_manager = *(uintptr_t *)(osu_manager_ptr); if (osu_manager == 0) { - FR_INFO("[!] Parse Beatmap: osu_manager"); + FR_ERROR("Parse Beatmap: osu_manager"); return false; } bool replay_mode = *(bool *)(osu_manager + OSU_MANAGER_IS_REPLAY_MODE_OFFSET); if (replay_mode) { - FR_INFO_FMT("Skipping current beatmap: replay mode"); + FR_INFO("Skipping current beatmap: replay mode"); extern bool beatmap_loaded; beatmap_loaded = false; return false; @@ -74,21 +74,21 @@ bool parse_beatmap(uintptr_t osu_manager_ptr, BeatmapData &beatmap_data) uintptr_t hit_manager_ptr = *(uintptr_t *)(osu_manager + OSU_MANAGER_HIT_MANAGER_OFFSET); if (hit_manager_ptr == 0) { - FR_INFO("[!] Parse Beatmap: hit_manager_ptr"); + FR_ERROR("Parse Beatmap: hit_manager_ptr"); return false; } uintptr_t hit_objects_list_ptr = *(uintptr_t *)(hit_manager_ptr + OSU_HIT_MANAGER_HIT_OBJECTS_LIST_OFFSET); if (hit_objects_list_ptr == 0) { - FR_INFO("[!] Parse Beatmap: hit_objects_list_ptr"); + FR_ERROR("Parse Beatmap: hit_objects_list_ptr"); return false; } uintptr_t hit_objects_list_items_ptr = *(uintptr_t *)(hit_objects_list_ptr + 0x4); if (hit_objects_list_items_ptr == 0) { - FR_INFO("[!] Parse Beatmap: hit_objects_list_items_ptr"); + FR_ERROR("Parse Beatmap: hit_objects_list_items_ptr"); return false; } @@ -101,7 +101,7 @@ bool parse_beatmap(uintptr_t osu_manager_ptr, BeatmapData &beatmap_data) uintptr_t hit_object_ptr = *(uintptr_t *)(hit_objects_list_items_ptr + 0x8 + 0x4 * i); if (hit_object_ptr == 0) { - FR_INFO("[!] Parse Beatmap: hit_object_ptr"); + FR_ERROR("Parse Beatmap: hit_object_ptr"); return false; } @@ -128,8 +128,8 @@ bool parse_beatmap(uintptr_t osu_manager_ptr, BeatmapData &beatmap_data) float game_ratio = game_height / 384.f; beatmap_data.scaled_hit_object_radius = beatmap_data.hit_object_radius * game_ratio; - FR_INFO_FMT("Hit Object Radius: %f", beatmap_data.hit_object_radius); - FR_INFO_FMT("Scaled Hit Object Radius: %f", beatmap_data.scaled_hit_object_radius); + FR_INFO("Hit Object Radius: %f", beatmap_data.hit_object_radius); + FR_INFO("Scaled Hit Object Radius: %f", beatmap_data.scaled_hit_object_radius); // TODO(Ciremun): refactor uintptr_t selected_song_ptr = *(uintptr_t *)(osu_manager + OSU_MANAGER_BEATMAP_OFFSET); @@ -281,7 +281,7 @@ bool parse_replay(uintptr_t selected_replay_ptr, ReplayData &replay) static char replay_url[128]; stbsp_snprintf(replay_url, 127, "/web/osu-getreplay.php?c=%lld&m=0&u=%s&h=%s", replay_id, osu_username, osu_client_id); - FR_INFO_FMT("Replay URL: %s", replay_url); + FR_INFO("Replay URL: %s", replay_url); static wchar_t replay_url_w[256]; int bytes_written = MultiByteToWideChar(CP_UTF8, 0, replay_url, 127, replay_url_w, 256); @@ -326,14 +326,14 @@ bool parse_replay(uintptr_t selected_replay_ptr, ReplayData &replay) { dwSize = 0; if (!WinHttpQueryDataAvailable(hRequest, &dwSize)) - FR_INFO_FMT("Error %u in WinHttpQueryDataAvailable.", + FR_INFO("Error %u in WinHttpQueryDataAvailable.", GetLastError()); pszOutBuffer = new char[dwSize]; ZeroMemory(pszOutBuffer, dwSize); if (!WinHttpReadData(hRequest, (LPVOID)pszOutBuffer, dwSize, &dwDownloaded)) - FR_INFO_FMT("Error %u in WinHttpReadData.", GetLastError()); + FR_INFO("Error %u in WinHttpReadData.", GetLastError()); for (DWORD i = 0; i < dwDownloaded; ++i) compressed_data_vec.push_back(pszOutBuffer[i]); @@ -349,7 +349,7 @@ bool parse_replay(uintptr_t selected_replay_ptr, ReplayData &replay) if (!bResults) { - FR_INFO_FMT("Error %d has occurred.", GetLastError()); + FR_INFO("Error %d has occurred.", GetLastError()); return false; } @@ -358,7 +358,7 @@ bool parse_replay(uintptr_t selected_replay_ptr, ReplayData &replay) } else { - FR_INFO("[!] Replay No Compressed Data Found"); + FR_ERROR("Replay No Compressed Data Found"); return false; } } @@ -368,13 +368,13 @@ bool parse_replay(uintptr_t selected_replay_ptr, ReplayData &replay) compressed_data = (uint8_t *)(compressed_data_ptr + 0x8); } - FR_INFO_FMT("Replay Compressed Data Size: %zu", compressed_data_size); + FR_INFO("Replay Compressed Data Size: %zu", compressed_data_size); if (compressed_data_size == 0) return false; size_t replay_data_size = *(size_t *)&compressed_data[LZMA_HEADER_SIZE - 8]; - FR_INFO_FMT("Replay Data Size: %zu", replay_data_size); + FR_INFO("Replay Data Size: %zu", replay_data_size); static std::vector replay_data; replay_data.clear(); replay_data.resize(replay_data_size); @@ -406,7 +406,7 @@ bool parse_replay(uintptr_t selected_replay_ptr, ReplayData &replay) break; replay_data_ptr += (const char *)&replay_data[next_comma_position] - replay_data_ptr + 1; } - FR_INFO_FMT("Replay Size: %zu", replay.entries.size()); + FR_INFO("Replay Size: %zu", replay.entries.size()); replay.ready = true; return true; diff --git a/freedom/scan.cpp b/freedom/scan.cpp index b5305a9..753b92b 100644 --- a/freedom/scan.cpp +++ b/freedom/scan.cpp @@ -57,13 +57,36 @@ uintptr_t client_id_offset = 0; uintptr_t username_offset = 0; uintptr_t check_timewarp_offset = 0; +CodeStart all_code_starts[] = { + { .name = "Parse Beatmap", .ptr = &parse_beatmap_code_start }, + { .name = "Beatmap Onload", .ptr = &beatmap_onload_code_start }, + { .name = "Current Scene", .ptr = ¤t_scene_code_start }, + { .name = "Selected Beatmap", .ptr = &selected_song_code_start }, + { .name = "Audio Time", .ptr = &audio_time_code_start }, + { .name = "Osu Manager", .ptr = &osu_manager_code_start }, + { .name = "Binding Manager", .ptr = &binding_manager_code_start }, + { .name = "Selected Replay", .ptr = &selected_replay_code_start }, + { .name = "Osu Client ID", .ptr = &osu_client_id_code_start }, + { .name = "Osu Username", .ptr = &osu_username_code_start }, + { .name = "Window Manager", .ptr = &window_manager_code_start }, + { .name = "Score Multiplier", .ptr = &score_multiplier_code_start }, + { .name = "Check Flashlight", .ptr = &check_flashlight_code_start }, + { .name = "Update Flashlight", .ptr = &update_flashlight_code_start }, + { .name = "Update Timing", .ptr = &update_timing_code_start }, + { .name = "Set Playback Rate", .ptr = &set_playback_rate_code_start }, + { .name = "Check Timewarp", .ptr = &check_timewarp_code_start }, + { .name = "Selected Mods", .ptr = &selected_mods_code_start }, + { .name = "Update Mods", .ptr = &update_mods_code_start }, + { .name = "Update Variables", .ptr = &hom_update_vars_hidden_loc }, + { .name = "SendInput", .ptr = &nt_user_send_input_dispatch_table_id_found }, +}; + inline bool all_code_starts_found() { - return parse_beatmap_code_start && beatmap_onload_code_start && current_scene_code_start && selected_song_code_start && - osu_manager_code_start && binding_manager_code_start && selected_replay_code_start && - osu_client_id_code_start && osu_username_code_start && window_manager_code_start && nt_user_send_input_dispatch_table_id_found && - score_multiplier_code_start && update_flashlight_code_start && check_flashlight_code_start && update_timing_code_start && check_timewarp_code_start && set_playback_rate_code_start - && hom_update_vars_hidden_loc && selected_mods_code_start && update_mods_code_start; + for (const auto &code_start : all_code_starts) + if (!*code_start.ptr) + return false; + return true; } static inline bool some_feature_requires_update_mods_hook() @@ -93,7 +116,7 @@ static void try_(const char *name, T func) { __try { func(); } __except (filter(GetExceptionCode())) { - FR_INFO_FMT("there was an exception in '%s'", name); + FR_INFO("there was an exception in '%s'", name); } } @@ -159,7 +182,7 @@ static void scan_for_code_starts() nt_user_send_input_dispatch_table_id_found = true; if (all_code_starts_found()) { - FR_INFO_FMT("Memory Scan Took: %lfs", ImGui::GetTime() - s); + FR_INFO("Memory Scan Took: %lfs", ImGui::GetTime() - s); memory_scan_progress = 1.f; return; } @@ -201,13 +224,13 @@ static void scan_for_code_starts() if (all_code_starts_found()) { - FR_INFO_FMT("Memory Scan Took: %lfs", ImGui::GetTime() - s); + FR_INFO("Memory Scan Took: %lfs", ImGui::GetTime() - s); memory_scan_progress = 1.f; return; } } } - FR_INFO_FMT("Memory Scan Took: %lfs", ImGui::GetTime() - s); + FR_INFO("Memory Scan Took: %lfs", ImGui::GetTime() - s); memory_scan_progress = 1.f; } @@ -376,10 +399,10 @@ static inline void init_nt_user_send_input_patch() { nt_user_send_input_ptr = (uintptr_t)GetProcAddress(win32u, "NtUserSendInput"); if (nt_user_send_input_ptr == NULL) - FR_INFO("[!] NtUserSendInput is null"); + FR_ERROR("NtUserSendInput is null"); } else - FR_INFO("[!] win32u.dll is null"); + FR_ERROR("win32u.dll is null"); } static inline void init_hooks_wrapper() @@ -389,6 +412,10 @@ static inline void init_hooks_wrapper() try_("scan_for_code_starts", [](){ scan_for_code_starts(); }); try_("try_find_hook_offsets", [](){ try_find_hook_offsets(); }); + for (const auto &code_start : all_code_starts) + if (!*code_start.ptr) + FR_ERROR("'%s' wasn't found", code_start.name); + if (scene_is_game(current_scene_ptr)) enable_nt_user_send_input_patch(); diff --git a/freedom/standalone/standalone_main.cpp b/freedom/standalone/standalone_main.cpp index f2d75fc..4ee78fd 100644 --- a/freedom/standalone/standalone_main.cpp +++ b/freedom/standalone/standalone_main.cpp @@ -121,7 +121,8 @@ int main(int, char**) set_playback_rate_code_start = 1; for (int i = 0; i < (1 << 8); ++i) - debug_log.add("%s %d\n", "Test Log", i); + FR_INFO("%s %d\n", "Test Log", i); + FR_ERROR("test error"); ImFontConfig config; config.OversampleH = config.OversampleV = 1; diff --git a/freedom/ui/config.cpp b/freedom/ui/config.cpp index 93e16ac..bd1ab9b 100644 --- a/freedom/ui/config.cpp +++ b/freedom/ui/config.cpp @@ -35,7 +35,7 @@ const char *get_imgui_ini_filename(HMODULE hMod) DWORD module_path_length = GetModuleFileNameW(hMod, module_path, MAX_PATH * 2); if (module_path_length == 0) { - FR_INFO_FMT("[!] GetModuleFileName (0x%X)", GetLastError()); + FR_ERROR("GetModuleFileName (0x%X)", GetLastError()); // NOTE(Ciremun): config path from freedom_injector extern LPVOID g_config_path; @@ -69,7 +69,7 @@ const char *get_imgui_ini_filename(HMODULE hMod) memcpy(module_path_u8 + backslash_index + 1, "config.ini", sizeof("config.ini")); - FR_INFO_FMT("config.ini path: %s", module_path_u8); + FR_INFO("config.ini path: %s", module_path_u8); return (const char *)&module_path_u8; } diff --git a/freedom/ui/ui.cpp b/freedom/ui/ui.cpp index 992a2f0..93fc110 100644 --- a/freedom/ui/ui.cpp +++ b/freedom/ui/ui.cpp @@ -111,7 +111,7 @@ void init_ui(IDirect3DDevice9* pDevice) set_imgui_ini_handler(); io.IniFilename = get_imgui_ini_filename(g_module); if (io.IniFilename == 0) - { FR_INFO("[!] Couldn't get config path"); } + { FR_ERROR("Couldn't get config path"); } else ImGui::LoadIniSettingsFromDisk(io.IniFilename); @@ -747,7 +747,7 @@ void draw_debug_log() { ImGui::PopStyleVar(); ImGui::BeginChild("##debug_beatmap", ImVec2(.0f, -30.f)); - ImGui::Text("Current Beatmap:"); + ImGui::Text("Current Beatmap"); ImGui::Text("Hit Objects Count: %zu", current_beatmap.hit_objects.size()); ImGui::Text("Hit Object Index: %u", current_beatmap.hit_object_idx); ImGui::Text("Hit Object Radius: %f", current_beatmap.hit_object_radius); diff --git a/include/scan.h b/include/scan.h index e95cbc4..5fe361f 100644 --- a/include/scan.h +++ b/include/scan.h @@ -28,6 +28,12 @@ typedef HRESULT (__stdcall *twglSwapBuffers)(IDirect3DDevice9* pDevice); +struct CodeStart +{ + const char *name; + uintptr_t *ptr; +}; + extern uintptr_t beatmap_onload_code_start; extern uintptr_t beatmap_onload_offset; extern uintptr_t beatmap_onload_hook_jump_back; diff --git a/include/ui/debug_log.h b/include/ui/debug_log.h index ce021c2..c2d22c2 100644 --- a/include/ui/debug_log.h +++ b/include/ui/debug_log.h @@ -7,16 +7,22 @@ #include "ui/colors.h" #ifdef FR_LOG_TO_CONSOLE -#define FR_ERROR(message) fprintf(stderr, "[!] %s:%d: %s\n", __FUNCSIG__, __LINE__, message) -#define FR_INFO(message) fprintf(stdout, "%s\n", message) -#define FR_INFO_FMT(fmt, ...) fprintf(stdout, fmt "\n", __VA_ARGS__) + #define FR_INFO(fmt, ...) fprintf(stdout, fmt "\n", __VA_ARGS__) + #ifdef NDEBUG + #define FR_ERROR(fmt, ...) fprintf(stderr, "[!] " fmt "\n", __VA_ARGS__) + #else + #define FR_ERROR(fmt, ...) fprintf(stderr, "[!] (%s) %s:%d: " fmt "\n", __FILE__, __FUNCSIG__, __LINE__, __VA_ARGS__) + #endif // NDEBUG #else -#define FR_ERROR(message) debug_log.add("[!] %s:%d: %s\n", __FUNCSIG__, __LINE__, message) -#define FR_INFO(message) debug_log.add("%s\n", message) -#define FR_INFO_FMT(fmt, ...) debug_log.add(fmt "\n", __VA_ARGS__) -#endif // NDEBUG - -#define FR_PTR_INFO(...) FR_INFO_FMT("%-35.35s 0x%X", __VA_ARGS__) + #define FR_INFO(fmt, ...) debug_log.add(fmt, __VA_ARGS__) + #ifdef NDEBUG + #define FR_ERROR(fmt, ...) debug_log.add("[!] " fmt, __VA_ARGS__) + #else + #define FR_ERROR(fmt, ...) debug_log.add("[!] (%s) %s:%d: " fmt, __FILE__, __FUNCSIG__, __LINE__, __VA_ARGS__) + #endif // NDEBUG +#endif // FR_LOG_TO_CONSOLE + +#define FR_PTR_INFO(...) FR_INFO("%-35.35s 0x%X", __VA_ARGS__) struct ImGuiLogger {