Skip to content

Commit

Permalink
improve log macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciremun committed May 10, 2024
1 parent db719da commit a1d7ceb
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 109 deletions.
110 changes: 55 additions & 55 deletions freedom/clrhost.cpp

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions freedom/features/aimbot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions freedom/features/difficulty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion freedom/features/relax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion freedom/hitobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions freedom/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 17 additions & 17 deletions freedom/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand All @@ -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<uint8_t> replay_data;
replay_data.clear();
replay_data.resize(replay_data_size);
Expand Down Expand Up @@ -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;
Expand Down
49 changes: 38 additions & 11 deletions freedom/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = &current_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()
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()
Expand All @@ -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();

Expand Down
3 changes: 2 additions & 1 deletion freedom/standalone/standalone_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions freedom/ui/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions freedom/ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions include/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 15 additions & 9 deletions include/ui/debug_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit a1d7ceb

Please sign in to comment.