Skip to content

Commit

Permalink
some debug prints. build as RawInput2BunnyhopAPE. maybe fix a path bu…
Browse files Browse the repository at this point in the history
…g (for Win11)
  • Loading branch information
rtldg committed Jan 27, 2024
1 parent 389255d commit ecb72c2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions RawInput2/RawInput2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<ProjectGuid>{2ab1de1d-405e-4347-a24a-8f099d9abe4f}</ProjectGuid>
<RootNamespace>RawInput2</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>RawInput2BunnyhopAPE</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down
44 changes: 33 additions & 11 deletions RawInput2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ void PEInjector(DWORD processID, DWORD Func(DWORD))
CreateRemoteThread(targetProcess, NULL, 0, (LPTHREAD_START_ROUTINE)((DWORD_PTR)Func + deltaImageBase), (LPVOID)GetCurrentProcessId(), 0, NULL);
}

// https://stackoverflow.com/a/14678800
std::string ReplaceString(std::string subject, const std::string& search,
const std::string& replace) {
size_t pos = 0;
while ((pos = subject.find(search, pos)) != std::string::npos) {
subject.replace(pos, search.length(), replace);
pos += replace.length();
}
return subject;
}

// Assumes the libraryfolders.vdf is "well formed"
std::string GetCSSPath()
{
Expand All @@ -418,6 +429,7 @@ std::string GetCSSPath()
DWORD size = sizeof(buf) / sizeof(buf[0]);
RegQueryValueExA(key, "InstallPath", 0, NULL, (BYTE*)buf, &size);
auto steampath = std::string(buf);
printf("steampath = %s\n", steampath.c_str());

std::ifstream libraryfolders(steampath + "\\steamapps\\libraryfolders.vdf");
std::string line, css_path, library_path;
Expand All @@ -427,6 +439,7 @@ std::string GetCSSPath()
if (line.rfind(PPPPP, 0) == 0)
{
library_path = line.substr(sizeof(PPPPP) - 1, line.size() - sizeof(PPPPP));
library_path = ReplaceString(library_path, "\\\\", "\\");
}
if (line.rfind("\t\t\t\"240\"", 0) == 0)
{
Expand All @@ -445,6 +458,7 @@ int main()
SetConsoleTitle("CS:S RawInput2 + BunnyhopAPE");

auto css_path = GetCSSPath();
printf("css path = %s\n\n", css_path.c_str());
auto css_exe = css_path + "hl2.exe";
#if 1
char launch_options[] = "-steam -game cstrike -insecure -novid -console";
Expand All @@ -453,7 +467,24 @@ int main()
#endif
PROCESS_INFORMATION pi = {};
STARTUPINFOA si = {};
CreateProcessA(css_exe.c_str(), launch_options, NULL, NULL, FALSE, 0, NULL, css_path.c_str(), &si, &pi);

if (!CreateProcessA(css_exe.c_str(), launch_options, NULL, NULL, FALSE, 0, NULL, css_path.c_str(), &si, &pi))
{
auto err = GetLastError();
char* buf;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&buf, 0, NULL);

printf("CreateProcessA failed (0x%x): %s\n", err, buf);

while (1)
{
if (_kbhit() && _getch() != VK_RETURN)
return 0;
Sleep(500);
}

return 1;
}

HANDLE g_hProcess = pi.hProcess;
DWORD processID = pi.dwProcessId;
Expand All @@ -465,16 +496,7 @@ int main()
Sleep(1000);
}

DWORD pHL = (DWORD)GetModuleHandleExtern(processID, "hl2.exe");
DWORD* pCmdLine = (DWORD*)(FindPatternEx(g_hProcess, pHL, 0x4000, (PBYTE)"\x85\xC0\x79\x08\x6A\x08", "xxxxxx") - 0x13);
char* cmdLine = new char[255];
ReadProcessMemory(g_hProcess, pCmdLine, &pCmdLine, sizeof(DWORD), NULL);
ReadProcessMemory(g_hProcess, pCmdLine, &pCmdLine, sizeof(DWORD), NULL);
ReadProcessMemory(g_hProcess, pCmdLine, cmdLine, 255, NULL);
if (!strstr(cmdLine, " -insecure"))
Error("-insecure key is missing!");

system("cls");
//system("cls");
printf("Set \"m_rawinput 2\" in game for it to take effect\n\nPress F5 to toggle BunnyhopAPE autobhop prediction (on by default)\nPress F6 to toggle the fullscreen hook (you probably don't want this)\nPress F7 to toggle the viewpunch remover (e.g. from fall-damage) (on by default)\n");

PEInjector(processID, InjectionEntryPoint);
Expand Down

0 comments on commit ecb72c2

Please sign in to comment.