Skip to content

Commit

Permalink
Randomize window title
Browse files Browse the repository at this point in the history
  • Loading branch information
fs-c committed Mar 9, 2024
1 parent 5f62440 commit f49baf1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdexcept>
#include <imgui/backends/imgui_impl_dx9.h>
#include <imgui/backends/imgui_impl_win32.h>
#include <random>

#include <maniac/common.h>

Expand Down Expand Up @@ -87,6 +88,32 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
return ::DefWindowProc(hWnd, msg, wParam, lParam);
}

static std::string generate_random_string(int length) {
std::string random_string;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distrib(0, 61);

for (int i = 0; i < length; ++i) {
int random_index = distrib(gen);
char random_char;
if (random_index < 10) {
random_char = '0' + random_index;
} else if (random_index < 36) {
random_char = 'A' + (random_index - 10);
} else {
random_char = 'a' + (random_index - 36);
}
random_string += random_char;
}

return random_string;
}

static void randomize_window_title(const HWND window) {
SetWindowTextA(window, generate_random_string(16).c_str());
}

void window::start(const std::function<void()> &body) {
// TODO: Refactor this into something readable

Expand All @@ -98,6 +125,8 @@ void window::start(const std::function<void()> &body) {
HWND hwnd = ::CreateWindow(wc.lpszClassName, _T("maniac"), WS_OVERLAPPEDWINDOW, 100, 100, 550,
420, NULL, NULL, wc.hInstance, NULL);

randomize_window_title(hwnd);

// Initialize Direct3D
if (!CreateDeviceD3D(hwnd)) {
CleanupDeviceD3D();
Expand Down
2 changes: 2 additions & 0 deletions lib/osu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ std::vector<HitObject> Osu::get_hit_objects() {
debug("failed getting map player, rescanning")
player_pointer = read_memory<uintptr_t>(find_signature(signatures::player));

// TODO: Break recursion at some point if it keeps failing, maybe exponential back off for some
// time and then fatal error.
return get_hit_objects();
}
}

0 comments on commit f49baf1

Please sign in to comment.