Last active
October 4, 2024 21:48
-
-
Save waryas/e97672d87b3958f9ce942961f5811cf0 to your computer and use it in GitHub Desktop.
Use mumble_ol.dll to render on any 3D application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OverwolfEmulator.cpp : définit le point d'entrée pour l'application console. | |
// | |
#include "stdafx.h" | |
#include <Windows.h> | |
#include <stdint.h> | |
#define OVERLAY_MAGIC_NUMBER 0x00000005 | |
struct OverlayMsgHeader { | |
unsigned int uiMagic; | |
int iLength; | |
unsigned int uiType; | |
}; | |
#define OVERLAY_MSGTYPE_INIT 0 | |
struct OverlayMsgInit { | |
unsigned int uiWidth; | |
unsigned int uiHeight; | |
}; | |
#define OVERLAY_MSGTYPE_SHMEM 1 | |
struct OverlayMsgShmem { | |
char a_cName[2048]; | |
}; | |
#define OVERLAY_MSGTYPE_BLIT 2 | |
struct OverlayMsgBlit { | |
unsigned int x, y, w, h; | |
}; | |
#define OVERLAY_MSGTYPE_ACTIVE 3 | |
struct OverlayMsgActive { | |
unsigned int x, y, w, h; | |
}; | |
#define OVERLAY_MSGTYPE_PID 4 | |
struct OverlayMsgPid { | |
unsigned int pid; | |
}; | |
#define OVERLAY_MSGTYPE_FPS 5 | |
struct OverlayMsgFps { | |
float fps; | |
}; | |
#define OVERLAY_FPS_INTERVAL 0.25f | |
#define OVERLAY_MSGTYPE_INTERACTIVE 6 | |
struct OverlayMsgInteractive { | |
bool state; | |
}; | |
struct OverlayMsg { | |
union { | |
char headerbuffer[1]; | |
struct OverlayMsgHeader omh; | |
}; | |
union { | |
char msgbuffer[1]; | |
struct OverlayMsgShmem oms; | |
struct OverlayMsgInit omi; | |
struct OverlayMsgBlit omb; | |
struct OverlayMsgActive oma; | |
struct OverlayMsgPid omp; | |
struct OverlayMsgFps omf; | |
struct OverlayMsgInteractive omin; | |
}; | |
}; | |
static HANDLE hPipe; | |
static bool isInit = false; | |
static DWORD bufferSize = 0; | |
static HANDLE hMemory = NULL; | |
static uint8_t* texture = NULL; | |
bool sendMessage(HANDLE hSocket, const OverlayMsg &om) { | |
DWORD dwBytesToWrite = sizeof(OverlayMsgHeader) + om.omh.iLength; | |
DWORD dwBytesWritten = dwBytesToWrite; | |
if (WriteFile(hSocket, om.headerbuffer, sizeof(OverlayMsgHeader) + om.omh.iLength, &dwBytesWritten, NULL)) | |
if (dwBytesToWrite == dwBytesWritten) | |
return true; | |
return false; | |
} | |
void RenderThread() { | |
while (1) { | |
if (hPipe) { | |
if (isInit) { | |
OverlayMsg om; | |
sendMessage(hPipe, om); | |
om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; | |
om.omh.uiType = OVERLAY_MSGTYPE_BLIT; | |
om.omh.iLength = sizeof(OverlayMsgBlit); | |
om.omb.h = 82; | |
om.oma.w = 71; | |
om.oma.x = 10; | |
om.oma.y = 10; | |
memset(texture, rand()%0xFF, bufferSize); | |
sendMessage(hPipe, om); | |
} | |
else if (bufferSize && !texture && !hMemory) { //Initiate Shared Memory | |
printf("Shared memory initialization!\n"); | |
OverlayMsg om; | |
om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; | |
om.omh.uiType = OVERLAY_MSGTYPE_SHMEM; | |
om.omh.iLength = sizeof(OverlayMsgShmem); | |
WideCharToMultiByte(CP_UTF8, 0, L"MyFileMappingObject", om.omh.iLength, om.oms.a_cName, 2048, 0, 0); | |
hMemory = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, bufferSize, L"MyFileMappingObject"); | |
texture = (uint8_t*)MapViewOfFile(hMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0); | |
memset(texture, 0x00, bufferSize); | |
sendMessage(hPipe, om); | |
om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; | |
om.omh.uiType = OVERLAY_MSGTYPE_ACTIVE; | |
om.omh.iLength = sizeof(OverlayMsgActive); | |
om.oma.h = 1080; | |
om.oma.w = 1980; | |
om.oma.x = 0; | |
om.oma.y = 0; | |
sendMessage(hPipe, om); | |
} | |
} | |
Sleep(1000/240); //240fps | |
} | |
} | |
int main(void) | |
{ | |
OverlayMsg buffer; | |
DWORD dwRead; | |
hPipe = CreateNamedPipe(TEXT("\\\\.\\pipe\\MumbleOverlayPipe"), | |
PIPE_ACCESS_DUPLEX | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, // FILE_FLAG_FIRST_PIPE_INSTANCE is not needed but forces CreateNamedPipe(..) to fail if the pipe already exists... | |
PIPE_NOWAIT, | |
1, | |
1024 * 16, | |
1024 * 16, | |
NMPWAIT_USE_DEFAULT_WAIT, | |
NULL); | |
while (hPipe != INVALID_HANDLE_VALUE) | |
{ | |
while (ReadFile(hPipe, &buffer, sizeof(buffer) - 1, &dwRead, NULL) != FALSE) | |
{ | |
if (dwRead <= 0) { | |
Sleep(4); | |
memset(&buffer, 0, sizeof(buffer)); | |
continue; | |
} | |
switch (buffer.omh.uiType) { | |
case OVERLAY_MSGTYPE_FPS: | |
printf("FPS : %f\n", buffer.omf.fps); | |
break; | |
case OVERLAY_MSGTYPE_PID: | |
printf("PID : %08x\n", buffer.omp.pid); | |
break; | |
case OVERLAY_MSGTYPE_SHMEM: | |
printf("Shared Memory success!\n"); | |
isInit = true; | |
break; | |
case OVERLAY_MSGTYPE_INIT: | |
printf("Init : %d x %d\n", buffer.omi.uiWidth, buffer.omi.uiHeight); | |
bufferSize = buffer.omi.uiWidth*buffer.omi.uiHeight * 4; | |
if (!hMemory); | |
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)RenderThread, 0, 0, 0); | |
break; | |
default: | |
printf("Unknown packet from client\n"); | |
} | |
memset(&buffer, 0, sizeof(buffer)); | |
Sleep(250); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment