Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Merge branch 'luajit'
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWilko committed Aug 30, 2017
2 parents 6d8ec20 + c6eb3b0 commit f3f45c4
Show file tree
Hide file tree
Showing 10 changed files with 819 additions and 657 deletions.
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Payday 2 BLT
An open source Lua hook for Payday 2, designed and created for ease of use for both players and modders.
This is the developer repository, and should only be used if you know what you're doing. If you don't, visit the website at [PaydayMods.com](http://paydaymods.com/) to get an up-to-date drag-drop install.
The Lua component of the BLT which controls mod loading can be found in it's own repository, [Payday-2-BLT-Lua](https://github.com/JamesWilko/Payday-2-BLT-Lua).

## Download
Visit [PaydayMods.com](http://paydaymods.com/) to get the latest stable download.

## Documentation
Documentation for the BLT can be found on the [GitHub Wiki](https://github.com/JamesWilko/Payday-2-BLT/wiki) for the project.

## Dependencies
Payday2 BLT requires the following dependencies, which are all statically linked.
* OpenSSL
Expand All @@ -25,10 +29,27 @@ I had to add SAFESEH handling to the MASM objects in order for this to be compat
### Detours
A compiled version of detours is included, and all terms of the included Microsoft Research Shared Source License Agreement (detours_license.rtf) are applicable.

## Documentation
All documentation can be found via the navigation bar the Payday Mods site, or just [go to it directly](http://payday-2-blt-docs.readthedocs.org/en/latest/). It's also available on [GitHub](https://github.com/JamesWilko/Payday-2-BLT-Docs) (or click the 'Edit on GitHub' button) so that you can contribute stuff if you need to, or need us to fix something.
The documentation is written in [markdown](http://daringfireball.net/projects/markdown/) with the help of [MkDocs](http://www.mkdocs.org/) and [ReadTheDocs](https://readthedocs.org/).

## Developers
The Payday 2 BLT was made by [James Wilkinson](http://jameswilko.com/) and [SirWaddlesworth](http://sirwaddlesworth.com/). We're friendly guys sometimes, so if you need help or want to discuss something you can reach us at any of the contact details we've got listed [over here](http://paydaymods.com/contact/).
We've also had help from a bunch of other people who've tested stuff, reported bugs, suggested changes, and everthing else. So thanks to GREAT BIG BUSHY BEARD, Kail, Dougley, and everybody else!
## Contributors
- Payday 2 BLT Team
* [James Wilkinson](http://jameswilko.com/) ([Twitter](http://twitter.com/_JamesWilko))
* [SirWaddlesworth](http://genj.io/)
* [Will Donohoe](https://will.io/)

- Contributors, Translators, Testers and more
* saltisgood
* Kail
* Dougley
* awcjack
* BangL
* chromKa
* xDarkWolf
* Luffyyy
* NHellFire
* TdlQ
* Mrucux7
* Simon
* goontest
* aayanl
* cjur3
* Kilandor
* and others who haven't been added yet
3 changes: 2 additions & 1 deletion proj/IPHLPAPI.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -13,6 +13,7 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{74B4EB55-E7B5-428A-9FAF-BE86058A56A6}</ProjectGuid>
<RootNamespace>IPHLPAPI</RootNamespace>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down
1,010 changes: 611 additions & 399 deletions src/InitiateState.cpp

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/http/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ void launch_thread_http(HTTPItem *raw_item){
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);

curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 900L);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 30L);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1000L);

if (item->progress){
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, http_progress_call);
Expand Down
109 changes: 30 additions & 79 deletions src/signatures/signatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,120 +5,71 @@
#include <detours.h>

#include "signatures.h"
#include "util/util.h"

#include <algorithm>
#include <vector>

namespace pd2hook
{
namespace
{
MODULEINFO GetModuleInfo(const std::string& szModule)
MODULEINFO GetModuleInfo(std::string szModule)
{
PD2HOOK_TRACE_FUNC;
MODULEINFO modinfo = { nullptr, 0, nullptr };
MODULEINFO modinfo = { 0 };
HMODULE hModule = GetModuleHandle(szModule.c_str());
if (hModule == 0)
return modinfo;
GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO));
return modinfo;
}

const MODULEINFO& GetPd2ModuleInfo()
{
static const MODULEINFO modinfo = GetModuleInfo("payday2_win32_release.exe");
return modinfo;
}

const char *FindPattern(const char *pattern, const char *mask)
unsigned long FindPattern(char* module, const char* funcname, const char* pattern, const char* mask)
{
PD2HOOK_TRACE_FUNC;
const auto& modInfo = GetPd2ModuleInfo();
const char * const base = reinterpret_cast<const char *>(modInfo.lpBaseOfDll);
const DWORD size = modInfo.SizeOfImage;
decltype(size) patternLength = strlen(mask);
for (std::remove_const<decltype(size)>::type i = 0; i < size - patternLength; ++i)
{
MODULEINFO mInfo = GetModuleInfo(module);
DWORD base = (DWORD)mInfo.lpBaseOfDll;
DWORD size = (DWORD)mInfo.SizeOfImage;
DWORD patternLength = (DWORD)strlen(mask);
for (DWORD i = 0; i < size - patternLength; i++){
bool found = true;
for (decltype(i) j = 0; j < patternLength && found; ++j)
{
found &= mask[j] == '?' || pattern[j] == base[i + j];
for (DWORD j = 0; j < patternLength; j++){
found &= mask[j] == '?' || pattern[j] == *(char*)(base + i + j);
}

if (found)
{
if (found) {
// printf("Found %s: 0x%p\n", funcname, base + i);
return base + i;
}
}

return nullptr;
printf("Warning: Failed to locate function %s\n", funcname);
return NULL;
}

bool FindUnassignedSignaturesPredicate(const SignatureF& s)
{
return *s.address == nullptr;
}
std::vector<SignatureF>* allSignatures = NULL;

std::vector<SignatureF> allSignatures;
}
SignatureSearch::SignatureSearch(const char* funcname, void* adress, const char* signature, const char* mask, int offset){
// lazy-init, container gets 'emptied' when initialized on compile.
if (!allSignatures){
allSignatures = new std::vector<SignatureF>();
}

SignatureSearch::SignatureSearch(const void** adress, const char* signature, const char* mask, int offset){
SignatureF ins = { signature, mask, offset, adress };
allSignatures.push_back(ins);
SignatureF ins = { funcname, signature, mask, offset, adress };
allSignatures->push_back(ins);
}

void SignatureSearch::Search(){
PD2HOOK_TRACE_FUNC;
PD2HOOK_LOG_LOG("Scanning for signatures.");

std::for_each(allSignatures.begin(), allSignatures.end(), [](SignatureF& s) { *s.address = FindPattern(s.signature, s.mask) + s.offset; });

const auto end = allSignatures.cend();
auto it = std::find_if(allSignatures.cbegin(), end, FindUnassignedSignaturesPredicate);
int unassigned_count = 0;
while (it != end)
{
++unassigned_count;
PD2HOOK_LOG_WARN("Didn't find signature with pattern: " << it->signature << ", and mask: " << it->mask);
it = std::find_if(it, end, FindUnassignedSignaturesPredicate);
}

if (unassigned_count)
{
PD2HOOK_LOG_WARN("Total: " << unassigned_count << " signatures not found.");
printf("Scanning for signatures.\n");
std::vector<SignatureF>::iterator it;
for (it = allSignatures->begin(); it < allSignatures->end(); it++){
*((void**)it->address) = (void*)(FindPattern("payday2_win32_release.exe", it->funcname, it->signature, it->mask) + it->offset);
}

PD2HOOK_LOG_LOG("Signatures Found.");
}


FuncDetour::FuncDetour(void** oldF, void* newF) : oldFunction(oldF), newFunction(newF){
PD2HOOK_TRACE_FUNC;
//DetourRestoreAfterWith();

#define PD2_DETOUR_CHK_PARAM(param) if(!param) { PD2HOOK_LOG_WARN(#param " is null"); }
PD2_DETOUR_CHK_PARAM(oldF)
PD2_DETOUR_CHK_PARAM(*oldF)
PD2_DETOUR_CHK_PARAM(newF)

LONG result;
#define PD2_DETOUR_CHK_FUNC(func) if((result = func) != ERROR_SUCCESS) { PD2HOOK_LOG_WARN(#func " returns " << result); }
PD2_DETOUR_CHK_FUNC(DetourTransactionBegin())
PD2_DETOUR_CHK_FUNC(DetourUpdateThread(GetCurrentThread()))
PD2_DETOUR_CHK_FUNC(DetourAttach(oldF, newF))
PD2_DETOUR_CHK_FUNC(DetourTransactionCommit())

#undef PD2_DETOUR_CHK_PARAM
#undef PD2_DETOUR_CHK_FUNC
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(oldF, newF);
LONG result = DetourTransactionCommit();
}

FuncDetour::~FuncDetour(){
PD2HOOK_TRACE_FUNC;
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(oldFunction, newFunction);
LONG result = DetourTransactionCommit();
}

}
Loading

0 comments on commit f3f45c4

Please sign in to comment.