Skip to content

Commit

Permalink
Added files
Browse files Browse the repository at this point in the history
  • Loading branch information
Urocu committed Sep 22, 2023
1 parent c5778b6 commit 4936c70
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 0 deletions.
46 changes: 46 additions & 0 deletions MemSubLoader.cbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="MemSubLoader" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/MemSubLoader" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/MemSubLoader" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Linker>
<Add library="gdi32" />
<Add library="user32" />
<Add library="kernel32" />
<Add library="comctl32" />
<Add library="Shlwapi" />
</Linker>
<Unit filename="main.cpp" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
11 changes: 11 additions & 0 deletions MemSubLoader.depend
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# depslib dependency file v1.0
1695385670 source:c:\users\tadeusz bindas\documents\github\memsubloader\memsubloader\main.cpp
<windows.h>
<commdlg.h>
<tchar.h>
<iostream>
<shlwapi.h>
<fstream>
<string>
<vector>

10 changes: 10 additions & 0 deletions MemSubLoader.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="6891" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
217 changes: 217 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
#ifndef UNICODE
#define UNICODE
#endif
#define _WIN32_WINNT 0x0501

#include <windows.h>
#include <commdlg.h>
#include <tchar.h>
#include <iostream>
#include <shlwapi.h>
#include <fstream>
#include <string>
#include <vector>

#define GAME 1
#define TRANSLATION 2
#define START 3

HWND game_text = NULL;
HWND file_text = NULL;
HWND subtitles = NULL;
HWND gameHWND = NULL;
wchar_t gamePath[MAX_PATH] = {};
wchar_t filePath[MAX_PATH] = {};
PROCESS_INFORMATION pi;
STARTUPINFO si;
HWND gWindow = NULL;

bool findAddress(uintptr_t &address, int offset)
{
SIZE_T bytesRead;
int newAddress;
if (ReadProcessMemory(pi.hProcess, (LPCVOID)address, &newAddress, sizeof(newAddress), &bytesRead) )
{
address = newAddress;
address += offset;
return true;
}
return false;

}

void game_start()
{
SIZE_T bytesRead;
int audID;
uintptr_t baseaddress;
uintptr_t addressToRead;

std::vector <std::wstring> Text;

std::wstring ws( filePath );
std::string SfilePath( ws.begin(), ws.end() );
std::wifstream subfile;
subfile.open(SfilePath);
int num;
int offset[6];
if(subfile.is_open() && !subfile.eof())
{
subfile>>baseaddress;
subfile>>num;
for(int i = 0; i<num;i++)
subfile>>offset[i];
while(getline(subfile, ws))
{
Text.push_back(ws);
}
}
else
SetWindowText(subtitles,L"File failed to open");
subfile.close();
int lastID = 0;
SetWindowText(subtitles,Text[0].c_str());
while (WaitForSingleObject( pi.hProcess, 0 ) == WAIT_TIMEOUT)
{
if (ReadProcessMemory(pi.hProcess, (LPCVOID)addressToRead, &audID, sizeof(audID), &bytesRead) && lastID!=audID && audID <Text.size() && audID >0)
{
SetWindowText(subtitles,Text[audID].c_str());
lastID=audID;
}
MSG msg = { };
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
addressToRead = baseaddress;
for( int i = 0; i < num; i++)
findAddress(addressToRead,offset[i]);
DWORD Width = GetSystemMetrics(SM_CXSCREEN);
DWORD Height = GetSystemMetrics(SM_CYSCREEN);
SetWindowPos(subtitles,HWND_TOPMOST, 0,Height-100,Width,100,NULL);
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
DestroyWindow(subtitles);
}

bool OpenFileExplorer(HWND hwnd, wchar_t* filePath, int filePathSize, int button)
{
OPENFILENAME ofn = { sizeof(OPENFILENAME) };
ofn.hwndOwner = hwnd;
if(button == GAME)
ofn.lpstrFilter = L"Executable Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0";
else
ofn.lpstrFilter = L"Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = filePath;
ofn.nMaxFile = filePathSize;
ofn.Flags = OFN_FILEMUSTEXIST;

if (GetOpenFileName(&ofn))
return true;
else
return false;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case GAME:
if (OpenFileExplorer(hwnd, gamePath, MAX_PATH, LOWORD(wParam)))
SetWindowText(game_text, PathFindFileName(gamePath));
break;

case TRANSLATION:
if (OpenFileExplorer(hwnd, filePath, MAX_PATH, LOWORD(wParam)))
SetWindowText(file_text, PathFindFileName(filePath));
break;

case START:
{
if(gamePath[0] != NULL && filePath[0] != NULL)
{

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
CreateProcess(gamePath, NULL,NULL,NULL,FALSE,0,NULL, NULL, &si,&pi);
WaitForInputIdle(pi.hProcess, INFINITE);
subtitles = CreateWindowEx(WS_EX_LAYERED|WS_EX_TRANSPARENT,L"STATIC", L"", WS_VISIBLE|WS_POPUP , 50, 100, 640, 100, hwnd, NULL, NULL, NULL);
SetLayeredWindowAttributes(subtitles, RGB(255, 255, 255), 128, LWA_ALPHA);
SetWindowText(subtitles, L"Loading...");
game_start();
}
else
MessageBox(hwnd, L"You must select both game and file", L"Warning", MB_ICONINFORMATION);
}
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;

case WM_CREATE:
{
HFONT hFont = CreateFont(16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Arial");
game_text = CreateWindow(L"STATIC", L"No Game", WS_CHILD | WS_VISIBLE, 50, 100, 150, 20, hwnd, NULL, NULL, NULL);
file_text = CreateWindow(L"STATIC", L"No File", WS_CHILD | WS_VISIBLE, 440, 100, 150, 20, hwnd, NULL, NULL, NULL);
SendMessage(game_text, WM_SETFONT, (WPARAM)hFont, TRUE);
SendMessage(file_text, WM_SETFONT, (WPARAM)hFont, TRUE);
}
break;

case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
EndPaint(hwnd, &ps);
}
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
const wchar_t CLASS_NAME[] = L"Sample Window Class";

HWND Sub_hwnd;

WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);

RECT desktop;
const HWND hDesktop = GetDesktopWindow();
GetWindowRect(hDesktop, &desktop);

HWND hwnd = CreateWindowEx(0,CLASS_NAME,L"MemSubLoader",WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME,desktop.right/2 - 320,desktop.bottom/2 - 120,640,240,NULL,NULL,hInstance,NULL);

if (hwnd == NULL)
{
return 0;
}

CreateWindow(L"BUTTON", L"Choose Game", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 50, 50, 150, 50, hwnd, (HMENU)GAME, hInstance, NULL);
CreateWindow(L"BUTTON", L"Choose File", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 440, 50, 150, 50, hwnd, (HMENU)TRANSLATION, hInstance, NULL);
CreateWindow(L"BUTTON", L"Start", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 245, 150, 150, 50, hwnd, (HMENU)START, hInstance, NULL);

ShowWindow(hwnd, nCmdShow);

MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
Binary file added obj/Release/main.o
Binary file not shown.

0 comments on commit 4936c70

Please sign in to comment.