Skip to content

Commit

Permalink
Merge pull request #80 from matanki-saito/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
matanki-saito authored Mar 15, 2019
2 parents eccad73 + 7ace2d9 commit 669c7d7
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Plugin/Plugin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<ClCompile Include="MapView.cpp" />
<ClCompile Include="MapJustify.cpp" />
<ClCompile Include="mapAdj.cpp" />
<ClCompile Include="moddl.cpp" />
<ClCompile Include="NickNameFix.cpp" />
<ClCompile Include="NoDynastyId.cpp" />
<ClCompile Include="MainTextLineBreak.cpp" />
Expand All @@ -116,6 +117,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="byte_pattern.h" />
<ClInclude Include="moddl.h" />
<ClInclude Include="stdinc.h" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions Plugin/Plugin.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<ClCompile Include="FileSave.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="moddl.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="byte_pattern.h">
Expand All @@ -98,6 +101,9 @@
<ClInclude Include="stdinc.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="moddl.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
8 changes: 8 additions & 0 deletions Plugin/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#include "stdinc.h"
#include "byte_pattern.h"
#include "moddl.h"

BOOL WINAPI DllMain(HMODULE module, DWORD reason, void *reserved)
{
if (reason == DLL_PROCESS_ATTACH)
{
// moddownload
wchar_t myDocumentPath[MAX_PATH];
SHGetSpecialFolderPath(NULL, myDocumentPath, CSIDL_PERSONAL, 0);

const path gameDirPath = path{ myDocumentPath } / L"Paradox Interactive" / L"Crusader Kings II";
if (!InitAutoUpdate(gameDirPath)) exit(-1);

byte_pattern::start_log(L"ck2jps");

// オプションをiniファイルから取得
Expand Down
55 changes: 55 additions & 0 deletions Plugin/moddl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "moddl.h"

bool createProcess(WCHAR* szCmd, DWORD flag) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
WCHAR *message = L"Autoupdate error. Please DELETE 'claes.exe'.";
WCHAR *title = NULL;

memset(&si, 0, sizeof(STARTUPINFO));
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
si.cb = sizeof(STARTUPINFO);

BOOL createProcessSuccess = CreateProcess(NULL, szCmd, NULL, NULL, FALSE, flag, NULL, NULL, &si, &pi);

if (!createProcessSuccess) {
title = L"Autoupdate createProcess failed.";
}
else {
DWORD result = WaitForSingleObject(pi.hProcess, 35 * 1000); // 35 sec
switch (result)
{
case WAIT_FAILED:
title = L"moddownload wait failed.";
break;
case WAIT_TIMEOUT:
title = L"moddownload wait timeout.";
break;
default:
break;
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

if (title != NULL) {
MessageBox(NULL, message, title, MB_OK);
return false;
}
}

return true;
}

bool InitAutoUpdate(const path &pluginsPath)
{
path exeFilePath = path{ pluginsPath } / L"claes.exe";

if (std::experimental::filesystem::exists(exeFilePath)) {
return createProcess(
wcsdup(exeFilePath.c_str()),
CREATE_NO_WINDOW
);
}

return true;
}
11 changes: 11 additions & 0 deletions Plugin/moddl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <filesystem>

using namespace std;
using namespace std::experimental::filesystem::v1;

bool InitAutoUpdate(const path &folder);
1 change: 1 addition & 0 deletions Plugin/stdinc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <utility>
#include <cstring>
#include <filesystem>
#include <shlobj.h>
#include <boost/utility/string_view.hpp>
#include "../include/injector/hooking.hpp"
#include "../include/injector/calling.hpp"
Expand Down

0 comments on commit 669c7d7

Please sign in to comment.