Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Party actually works
Browse files Browse the repository at this point in the history
  • Loading branch information
Soreepeong committed Jun 29, 2017
1 parent a043594 commit cfd9576
Show file tree
Hide file tree
Showing 25 changed files with 601 additions and 311 deletions.
4 changes: 2 additions & 2 deletions DpsViewer/DpsViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
Expand All @@ -41,7 +41,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\Release\</OutputPath>
Expand Down
9 changes: 7 additions & 2 deletions DpsViewer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ public static void Main(string[] args) {
}
});
if (processes.Count == 0) {
MessageBox.Show("FFXIV is not running.");
string k = "";
foreach (var p in Process.GetProcesses())
k += p.ProcessName + "\n";
MessageBox.Show("FFXIV is not running.\n" + k);
} else {
foreach (var p in processes) {
if (p.MainModule.FileName.Contains("KOREA")) continue;
IntPtr ffxivhWnd = IntPtr.Zero;
EnumWindows(new EnumWindowsProc((hWnd, lparam) => {
int size = GetWindowTextLength(hWnd);
Expand All @@ -44,12 +48,13 @@ public static void Main(string[] args) {
MessageBox.Show("FFXIV window not found");
return;
}
// MessageBox.Show("Entrypoint: " + p.MainModule.BaseAddress.ToString("X16")); return;
//
string dllFN = "FFXIVDLL_" + (IntPtr.Size == 4 ? "x86" : "x64") + ".dll";

IntPtr h = OpenProcess(ProcessAccessFlags.All, false, p.Id);
if (h.ToInt32() != -1) {
ejectDll(p.Handle, AppDomain.CurrentDo‌​main.BaseDirectory + dllFN);
// MessageBox.Show("Entrypoint: " + p.MainModule.BaseAddress.ToString("X16")); return;
InjectDLL(p.Handle, AppDomain.CurrentDo‌​main.BaseDirectory + dllFN);
CloseHandle(h);
SetForegroundWindow(ffxivhWnd);
Expand Down
112 changes: 112 additions & 0 deletions FFXIVDLL/ExternalPipe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include "ExternalPipe.h"
#include <functional>



ExternalPipe::ExternalPipe(FFXIVDLL *dll, HANDLE unloadEvent) :
hUnloadEvent(unloadEvent),
dll (dll) {
TCHAR pname[256];
wsprintf(pname, L"\\\\.\\pipe\\ffxivdll_pipe_%d", GetCurrentProcessId());
hPipe = CreateNamedPipe(pname, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 1, 1024 * 16, 1024 * 16, 0, NULL);
if (hPipe == INVALID_HANDLE_VALUE) {
int err = GetLastError();
std::string buf;
buf += "/e create pipe error: ";
buf += std::to_string(err);
dll->addChat(buf);
} else {
hPipeThread = CreateThread(NULL, NULL, ExternalPipe::PipeThreadExternal, this, NULL, NULL);
}
}


ExternalPipe::~ExternalPipe() {
if (hPipe != INVALID_HANDLE_VALUE) {
WaitForSingleObject(hPipeThread, INFINITE);
CloseHandle(hPipeThread);
}
}

void ExternalPipe::SendInfo(std::string str) {
streamQueue.push(str);
SetEvent(hNewChatItemEvent);
}

DWORD ExternalPipe::PipeThread() {
OVERLAPPED ov = { 0 };
ov.hEvent = CreateEvent(NULL, true, false, NULL);
HANDLE objects[2] = { hUnloadEvent, ov.hEvent };
while (WaitForSingleObject(hUnloadEvent, 0) == WAIT_TIMEOUT) {
ResetEvent(ov.hEvent);
ConnectNamedPipe(hPipe, &ov);
if (GetLastError() != ERROR_PIPE_CONNECTED && GetLastError() != ERROR_IO_PENDING) {
std::string e("/e error connecting pipe: ");
e += (int)GetLastError();
dll->addChat(e);
Sleep(100);
continue;
}
WaitForMultipleObjects(2, objects, false, INFINITE);
if (HasOverlappedIoCompleted(&ov)) {
dll->addChat("/e pipe connected");
hPipeEvent = CreateEvent(NULL, true, false, NULL);
ResetEvent(hPipeEvent);
HANDLE reader = CreateThread(0, 0, [](PVOID p_) -> DWORD {
ExternalPipe *p = (ExternalPipe*) p_;
char buffer[1024];
DWORD dwRead;
OVERLAPPED ov = { 0 };
ov.hEvent = CreateEvent(NULL, true, false, NULL);
HANDLE objects[2] = { p->hPipeEvent, ov.hEvent };
while (WaitForSingleObject(p->hUnloadEvent, 0) == WAIT_TIMEOUT) {
ReadFile(p->hPipe, buffer, sizeof(buffer), NULL, &ov);
WaitForMultipleObjects(2, objects, false, INFINITE);
if (!GetOverlappedResult(p->hPipe, &ov, &dwRead, false))
break;
p->dll->addChat(std::string(buffer, dwRead));
}
SetEvent(p->hPipeEvent);
CloseHandle(ov.hEvent);
TerminateThread(GetCurrentThread(), 0);
return 0;
}, this, 0, 0);
HANDLE writer = CreateThread(0, 0, [](PVOID p_) -> DWORD {
ExternalPipe *p = (ExternalPipe*) p_;
OVERLAPPED ov = { 0 };
ov.hEvent = CreateEvent(NULL, true, false, NULL);
HANDLE objects[2] = { p->hPipeEvent, ov.hEvent };
HANDLE objects_chat[3] = { p->hPipeEvent, p->hNewChatItemEvent, ov.hEvent };
while (WaitForMultipleObjects(3, objects_chat, false, INFINITE) != WAIT_TIMEOUT && WaitForSingleObject(p->hUnloadEvent, 0) == WAIT_TIMEOUT) {
std::string chatMessage;
while (p->streamQueue.tryPop(&chatMessage)) {
WriteFile(p->hPipe, chatMessage.c_str(), static_cast<DWORD>(chatMessage.size()), NULL, &ov);
WaitForMultipleObjects(2, objects, false, INFINITE);
if (!HasOverlappedIoCompleted(&ov))
goto done;
}
}
done:
SetEvent(p->hPipeEvent);
CloseHandle(ov.hEvent);
TerminateThread(GetCurrentThread(), 0);
return 0;
}, this, 0, 0);
HANDLE waits[3] = { reader, writer, hUnloadEvent };
if (WaitForMultipleObjects(3, waits, false, INFINITE) != WAIT_TIMEOUT) {
SetEvent(hPipeEvent);
WaitForSingleObject(reader, INFINITE);
WaitForSingleObject(writer, INFINITE);
}
CloseHandle(hPipeEvent);
dll->addChat("/e pipe disconnected");
}
DisconnectNamedPipe(hPipe);
}
if (!HasOverlappedIoCompleted(&ov))
CancelIoEx(hPipe, &ov);
CloseHandle(hPipe);
CloseHandle(ov.hEvent);
TerminateThread(GetCurrentThread(), 0);
return 0;
}
29 changes: 29 additions & 0 deletions FFXIVDLL/ExternalPipe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include<Windows.h>
#include<string>
#include<condition_variable>
#include<deque>
#include "FFXIVDLL.h"
#include "Tools.h"

class ExternalPipe {
friend class Hooks;
private:

HANDLE hPipe, hPipeEvent;
HANDLE hPipeThread = INVALID_HANDLE_VALUE;
HANDLE hNewChatItemEvent = INVALID_HANDLE_VALUE;
HANDLE hUnloadEvent;
FFXIVDLL *dll;
Tools::bqueue<std::string> streamQueue;

public:
ExternalPipe(FFXIVDLL *dll, HANDLE unloadEvent);
~ExternalPipe();

void SendInfo(std::string str);

DWORD PipeThread();
static DWORD WINAPI PipeThreadExternal(PVOID param) { ((ExternalPipe*)param)->PipeThread(); return 0; }
};

Loading

0 comments on commit cfd9576

Please sign in to comment.