Skip to content

Commit

Permalink
better random & rand every time you enter main menu
Browse files Browse the repository at this point in the history
look at the title
  • Loading branch information
poweredbypie committed Jan 29, 2021
1 parent 489de22 commit 86a410e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
22 changes: 12 additions & 10 deletions randomize-menu-music/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
namespace globals {
void(__stdcall* fadeInMusicGate)(const char*) = nullptr;

std::string randomLoop = "";
std::vector<std::string> validLoops;
std::default_random_engine generator;
std::uniform_int_distribution distribution;
}

void __declspec(dllexport) __stdcall fadeInMusicHook(const char* filename) {
std::string path = "menuLoops\\" + globals::randomLoop;
return globals::fadeInMusicGate(path.c_str());
using namespace globals;
return fadeInMusicGate(validLoops[distribution(generator)].c_str());
}

DWORD WINAPI attach(void* hModule) {
using namespace std::filesystem;
constexpr std::string_view filter = " !#$%&'()+,-.0123456789;=@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{}~";

path menuLoops = current_path() / "menuLoops";
std::vector<std::string> validLoops;

if (exists(menuLoops)) {
if (is_directory(menuLoops)) {
Expand All @@ -33,7 +34,7 @@ DWORD WINAPI attach(void* hModule) {
}

if (valid) {
validLoops.push_back(loop.path().filename().u8string());
globals::validLoops.push_back("menuLoops/" + loop.path().filename().u8string());
}
}
}
Expand All @@ -47,16 +48,16 @@ DWORD WINAPI attach(void* hModule) {
else
create_directories(menuLoops);

if (validLoops.empty()) {
if (globals::validLoops.empty()) {
MessageBox(0, L"ERROR: menuLoops is empty!\n"
"I can't give you a random menu loop if you don't have any loops for me to choose from!",
L"I can't give you a random menu loop if you don't have any loops for me to choose from!",
L"menuLoop randomizer", MB_ICONERROR | MB_OK);
}
else {
srand(time(0));
globals::randomLoop = validLoops[rand() % (validLoops.size() - 1)];

char* gdBase = reinterpret_cast<char*>(GetModuleHandle(0));
globals::distribution = std::uniform_int_distribution(0,
static_cast<int>(
globals::validLoops.size() - 1));

hk fadeInMusic = {
gdBase + 0xC4BD0,
Expand All @@ -81,6 +82,7 @@ BOOL APIENTRY DllMain( HMODULE hModule,
case DLL_PROCESS_ATTACH:
_ = CreateThread(0, 0, attach, hModule, 0, 0);
if (_) CloseHandle(_);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
Expand Down
2 changes: 1 addition & 1 deletion randomize-menu-music/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#include <windows.h>
#include <vector>
#include <string_view>
#include <cstdlib>
#include <random>

#endif //PCH_H
11 changes: 10 additions & 1 deletion randomize-menu-music/randomize-menu-music.vcxproj.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommand>C:\Program Files %28x86%29\Steam\steamapps\common\Geometry Dash\GeometryDash.exe</LocalDebuggerCommand>
<LocalDebuggerAttach>true</LocalDebuggerAttach>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommand>C:\Program Files %28x86%29\Steam\steamapps\common\Geometry Dash\GeometryDash.exe</LocalDebuggerCommand>
<LocalDebuggerAttach>true</LocalDebuggerAttach>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

0 comments on commit 86a410e

Please sign in to comment.