Skip to content

Commit db71ae8

Browse files
committed
Ver 1.1
1 parent f6c678f commit db71ae8

2 files changed

Lines changed: 74 additions & 24 deletions

File tree

CP77HookPath/CustomHooks.cpp

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,97 @@
11
#include "CustomHooks.h"
22

3+
34
std::ofstream outfile;
45
std::mutex mtx;
56

67

8+
std::multimap<std::string,int> CurrentHashLst;
79
std::vector<std::string> memoryFilenames;
8-
std::vector<std::string> CurrentHashLst;
10+
11+
std::wstring ExePath() {
12+
TCHAR buffer[MAX_PATH] = { 0 };
13+
GetModuleFileName(NULL, buffer, MAX_PATH);
14+
std::wstring::size_type pos = std::wstring(buffer).find_last_of(L"\\/");
15+
return std::wstring(buffer).substr(0, pos);
16+
}
17+
std::wstring s2ws(const std::string& str)
18+
{
19+
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
20+
std::wstring wstrTo(size_needed, 0);
21+
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed);
22+
return wstrTo;
23+
}
924

1025
void LoadCurrentHash()
1126
{
1227
std::ifstream csv;
13-
csv.open("archivehashes.csv", std::ios::in);
28+
std::wstring path = ExePath() + s2ws("\\missinghashes.txt");
29+
csv.open(path, std::ios::in);
30+
int i = 0;
1431
if (csv.is_open())
1532
{
1633
std::string hashnumber;
1734
while (getline(csv, hashnumber))
1835
{
19-
hashnumber = hashnumber.substr(hashnumber.find(',') + 1, hashnumber.length() - 1);
20-
CurrentHashLst.push_back(hashnumber);
36+
CurrentHashLst.insert(std::pair<std::string, int>(hashnumber, i));
2137
}
38+
2239
}
2340
else
2441
{
2542
AllocConsole();
2643
freopen("CONOUT$", "w", stdout);
27-
28-
printf("Missing archivehashes.csv file\n");
29-
printf("Please download it from https://github.com/rfuzzo/CP77Tools/blob/main/CP77Tools/Resources/archivehashes.csv \n");
30-
printf("Then copy it into 'Cyberpunk 2077\\bin\\x64'\n");
31-
printf("Thank you !!!\n");
44+
45+
printf("Missing file ");
46+
wprintf(path.c_str());
47+
printf("\n");
48+
printf("Please download it from CP77 Modding Tools discord in 'hash' channel\nLink invite: https://discord.gg/NTA2t5GngV \n");
49+
printf("Then copy it into ");
50+
wprintf(ExePath().c_str());
51+
52+
printf("\nThank you !!!\n");
3253
system("pause");
3354
FreeConsole();
3455
}
3556
}
3657

3758
bool HashExist(std::string hash, std::vector<std::string> CurrentHashLst)
3859
{
60+
3961
return std::any_of(CurrentHashLst.begin(), CurrentHashLst.end(), compare(hash));
4062
}
4163

42-
void WriteFilenames(std::vector<std::string>& memoryFilenames, std::vector<std::string> CurrentHashLst)
64+
void WriteFilenames(std::vector<std::string> memoryFilenames, std::multimap<std::string, int> CurrentHashLst)
4365
{
44-
std::string temp;
45-
for (int i = 0; i < memoryFilenames.size(); i++)
66+
67+
68+
69+
std::string templine;
70+
templine = "";
71+
72+
73+
74+
for (long long i = 0; i < memoryFilenames.size(); i++)
4675
{
76+
4777
std::string hash = memoryFilenames[i].substr(memoryFilenames[i].find(',') + 1, memoryFilenames[i].length() - 1);
48-
if (!HashExist(hash, CurrentHashLst))
78+
79+
if(CurrentHashLst.find(hash) != CurrentHashLst.end())
4980
{
50-
temp += memoryFilenames[i];
51-
temp += '\n';
81+
templine += memoryFilenames[i];
82+
templine += '\n';
83+
5284
}
5385
}
54-
memoryFilenames.clear();
5586

5687
outfile.open("Cyberpunk2077.log", std::ios::out | std::ios::app);
57-
outfile << temp;
88+
outfile << templine;
5889
outfile.close();
90+
91+
92+
93+
94+
5995
}
6096

6197

@@ -72,9 +108,11 @@ HOOKON fpHookOn = NULL;
72108

73109

74110
int counthash = 0;
75-
111+
int temphash = 0;
112+
bool check = 0;
76113
INT64* tHookOn(INT64* unk1, INT64 a2)
77114
{
115+
78116
int rax = 0;
79117
GetRax(rax);
80118
int v2 = *(UINT*)(a2 + 8);
@@ -123,9 +161,13 @@ INT64* tHookOn(INT64* unk1, INT64 a2)
123161

124162
}
125163
// Orignal Function
164+
165+
126166
SetRax(rax);
127167
INT64* res = fpHookOn(unk1, a2);
128168

169+
170+
129171
if (size > 0)
130172
{
131173
line += ',';
@@ -136,11 +178,14 @@ INT64* tHookOn(INT64* unk1, INT64 a2)
136178
mtx.lock();
137179
if (size > 0)
138180
memoryFilenames.push_back(line);
139-
counthash += 1;
140-
if (counthash % 10000 == 0)
181+
182+
if (memoryFilenames.size() % 10000 == 0)
141183
{
142-
WriteFilenames(memoryFilenames, CurrentHashLst);
143-
counthash = 0;
184+
if (!memoryFilenames.empty())
185+
{
186+
WriteFilenames(memoryFilenames, CurrentHashLst);
187+
memoryFilenames.clear();
188+
}
144189
}
145190
mtx.unlock();
146191

@@ -152,6 +197,7 @@ INT64* tHookOn(INT64* unk1, INT64 a2)
152197
void SetupHooks()
153198
{
154199
LoadCurrentHash();
200+
155201
LPVOID hookAddress = GetArchiveFunctionAddress();
156202
MH_Initialize();
157203

CP77HookPath/CustomHooks.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#include <Windows.h>
22
#include "MinHook.h"
3-
#include <iostream>
3+
#include <algorithm>
44
#include <string>
55
#include <vector>
66
#include <fstream>
77
#include "AOBScanner.h"
88
#include <mutex> // std::mute
9-
#include <algorithm>
9+
#include <thread>
10+
#include <iostream>
11+
#include <chrono>
12+
#include <vector>
13+
#include <map>
1014

1115
extern "C" void GetRax(INT64);
1216
extern "C" INT64 SetRax(INT64);

0 commit comments

Comments
 (0)