Skip to content

Commit e83f32c

Browse files
authored
Merge pull request #1 from Mai-Ooizumi/patch-1
feature: select file to patch it
2 parents cbea267 + 7909c98 commit e83f32c

File tree

2 files changed

+207
-137
lines changed

2 files changed

+207
-137
lines changed

VScriptAutoPatcher/VScriptAutoPatcher.cpp

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <Windows.h>
33
#include <vector>
44
#include <cstdint>
5+
#include <filesystem>
56

67
bool readFile(const std::string& filename, std::vector<uint8_t>& buffer)
78
{
@@ -124,6 +125,48 @@ void PatchFile(std::string fileName, std::vector<uint8_t> originalArray, std::ve
124125
std::cout << "[SUCCESS] " << fileName << " has been patched." << std::endl;
125126
}
126127

128+
static std::string SelectPEFile()
129+
{
130+
TCHAR szBuffer[MAX_PATH] = { 0 };
131+
OPENFILENAME file = { 0 };
132+
133+
ZeroMemory(&file, sizeof(file));
134+
135+
file.hwndOwner = NULL;
136+
file.lStructSize = sizeof(file);
137+
file.lpstrFilter = L"vscript.dll(vscript.dll)\0vscript.dll\0所有文件(*.*)\0*.*\0\0";
138+
file.lpstrInitialDir = L"";
139+
file.lpstrFile = szBuffer;
140+
file.nMaxFile = sizeof(szBuffer) / sizeof(*szBuffer);
141+
file.nFilterIndex = 0;
142+
file.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
143+
144+
if (GetOpenFileName(&file))
145+
{
146+
int size = WideCharToMultiByte(CP_ACP, 0, file.lpstrFile, -1, NULL, 0, NULL, NULL);
147+
if (size == 0)
148+
{
149+
return std::string();
150+
}
151+
std::string result(size - 1, 0);
152+
WideCharToMultiByte(CP_ACP, 0, file.lpstrFile, -1, &result[0], size, NULL, NULL);
153+
return result;
154+
}
155+
else
156+
{
157+
return std::string();
158+
}
159+
}
160+
161+
static void Pause()
162+
{
163+
std::cout << "Press any key to continue..." << std::flush;
164+
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
165+
FlushConsoleInputBuffer(h);
166+
WaitForSingleObject(h, INFINITE);
167+
FlushConsoleInputBuffer(h);
168+
}
169+
127170
int main()
128171
{
129172
std::string filePath = "./bin/win64/vscript.dll";
@@ -134,15 +177,40 @@ int main()
134177
std::cout << "Created by Kroytz (https://github.com/Kroytz)" << std::endl;
135178
std::cout << "Method from Source2ZE (https://github.com/Source2ZE/CS2Fixes)" << std::endl;
136179
std::cout << "Code mainly from RealSkid (https://www.unknowncheats.me/forum/members/3339879.html)" << std::endl;
137-
std::cout << "Place this executable in your <game> folder" << std::endl;
180+
//std::cout << "Place this executable in your <game> folder" << std::endl;
138181
std::cout << " " << std::endl;
139182
std::cout << " " << std::endl;
140183

141-
PatchFile(filePath, { 0xBE, 0x01, 0x2A, 0x2A, 0x2A, 0x2B, 0xD6, 0x74, 0x2A, 0x3B, 0xD6 }, { 0xBE, 0x02 });
184+
//PatchFile(filePath, { 0xBE, 0x01, 0x2A, 0x2A, 0x2A, 0x2B, 0xD6, 0x74, 0x2A, 0x3B, 0xD6 }, { 0xBE, 0x02 });
185+
186+
try
187+
{
188+
if (!std::filesystem::exists(filePath))
189+
{
190+
filePath = SelectPEFile();
191+
}
192+
if (std::filesystem::exists(filePath))
193+
{
194+
std::filesystem::copy(filePath, filePath + ".bak");
195+
196+
PatchFile(filePath, { 0xBE, 0x01, 0x2A, 0x2A, 0x2A, 0x2B, 0xD6, 0x74, 0x2A, 0x3B, 0xD6 }, { 0xBE, 0x02 });
197+
}
198+
199+
}
200+
catch (const std::exception & e)
201+
{
202+
std::cerr << "An error occurred: " << e.what() << std::endl;
203+
204+
Pause();
205+
206+
return 1;
207+
}
208+
142209
std::cout << " " << std::endl;
143210
std::cout << " " << std::endl;
144211

145-
system("pause");
212+
//system("pause");
213+
Pause();
146214

147215
return 0;
148216
}
Lines changed: 136 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,137 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<ItemGroup Label="ProjectConfigurations">
4-
<ProjectConfiguration Include="Debug|Win32">
5-
<Configuration>Debug</Configuration>
6-
<Platform>Win32</Platform>
7-
</ProjectConfiguration>
8-
<ProjectConfiguration Include="Release|Win32">
9-
<Configuration>Release</Configuration>
10-
<Platform>Win32</Platform>
11-
</ProjectConfiguration>
12-
<ProjectConfiguration Include="Debug|x64">
13-
<Configuration>Debug</Configuration>
14-
<Platform>x64</Platform>
15-
</ProjectConfiguration>
16-
<ProjectConfiguration Include="Release|x64">
17-
<Configuration>Release</Configuration>
18-
<Platform>x64</Platform>
19-
</ProjectConfiguration>
20-
</ItemGroup>
21-
<PropertyGroup Label="Globals">
22-
<VCProjectVersion>17.0</VCProjectVersion>
23-
<Keyword>Win32Proj</Keyword>
24-
<ProjectGuid>{b05fc70f-bec8-46c8-b6d5-b509d26ca55d}</ProjectGuid>
25-
<RootNamespace>VScriptAutoPatcher</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27-
</PropertyGroup>
28-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30-
<ConfigurationType>Application</ConfigurationType>
31-
<UseDebugLibraries>true</UseDebugLibraries>
32-
<PlatformToolset>v143</PlatformToolset>
33-
<CharacterSet>Unicode</CharacterSet>
34-
</PropertyGroup>
35-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36-
<ConfigurationType>Application</ConfigurationType>
37-
<UseDebugLibraries>false</UseDebugLibraries>
38-
<PlatformToolset>v143</PlatformToolset>
39-
<WholeProgramOptimization>true</WholeProgramOptimization>
40-
<CharacterSet>Unicode</CharacterSet>
41-
</PropertyGroup>
42-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43-
<ConfigurationType>Application</ConfigurationType>
44-
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v143</PlatformToolset>
46-
<CharacterSet>Unicode</CharacterSet>
47-
</PropertyGroup>
48-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49-
<ConfigurationType>Application</ConfigurationType>
50-
<UseDebugLibraries>false</UseDebugLibraries>
51-
<PlatformToolset>v143</PlatformToolset>
52-
<WholeProgramOptimization>true</WholeProgramOptimization>
53-
<CharacterSet>Unicode</CharacterSet>
54-
</PropertyGroup>
55-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56-
<ImportGroup Label="ExtensionSettings">
57-
</ImportGroup>
58-
<ImportGroup Label="Shared">
59-
</ImportGroup>
60-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62-
</ImportGroup>
63-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65-
</ImportGroup>
66-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68-
</ImportGroup>
69-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71-
</ImportGroup>
72-
<PropertyGroup Label="UserMacros" />
73-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74-
<ClCompile>
75-
<WarningLevel>Level3</WarningLevel>
76-
<SDLCheck>true</SDLCheck>
77-
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
78-
<ConformanceMode>true</ConformanceMode>
79-
</ClCompile>
80-
<Link>
81-
<SubSystem>Console</SubSystem>
82-
<GenerateDebugInformation>true</GenerateDebugInformation>
83-
</Link>
84-
</ItemDefinitionGroup>
85-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
86-
<ClCompile>
87-
<WarningLevel>Level3</WarningLevel>
88-
<FunctionLevelLinking>true</FunctionLevelLinking>
89-
<IntrinsicFunctions>true</IntrinsicFunctions>
90-
<SDLCheck>true</SDLCheck>
91-
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92-
<ConformanceMode>true</ConformanceMode>
93-
</ClCompile>
94-
<Link>
95-
<SubSystem>Console</SubSystem>
96-
<EnableCOMDATFolding>true</EnableCOMDATFolding>
97-
<OptimizeReferences>true</OptimizeReferences>
98-
<GenerateDebugInformation>true</GenerateDebugInformation>
99-
</Link>
100-
</ItemDefinitionGroup>
101-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
102-
<ClCompile>
103-
<WarningLevel>Level3</WarningLevel>
104-
<SDLCheck>true</SDLCheck>
105-
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
106-
<ConformanceMode>true</ConformanceMode>
107-
</ClCompile>
108-
<Link>
109-
<SubSystem>Console</SubSystem>
110-
<GenerateDebugInformation>true</GenerateDebugInformation>
111-
</Link>
112-
</ItemDefinitionGroup>
113-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
114-
<ClCompile>
115-
<WarningLevel>Level3</WarningLevel>
116-
<FunctionLevelLinking>true</FunctionLevelLinking>
117-
<IntrinsicFunctions>true</IntrinsicFunctions>
118-
<SDLCheck>true</SDLCheck>
119-
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120-
<ConformanceMode>true</ConformanceMode>
121-
</ClCompile>
122-
<Link>
123-
<SubSystem>Console</SubSystem>
124-
<EnableCOMDATFolding>true</EnableCOMDATFolding>
125-
<OptimizeReferences>true</OptimizeReferences>
126-
<GenerateDebugInformation>true</GenerateDebugInformation>
127-
</Link>
128-
</ItemDefinitionGroup>
129-
<ItemGroup>
130-
<ClCompile Include="VScriptAutoPatcher.cpp" />
131-
</ItemGroup>
132-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
133-
<ImportGroup Label="ExtensionTargets">
134-
</ImportGroup>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>17.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{b05fc70f-bec8-46c8-b6d5-b509d26ca55d}</ProjectGuid>
25+
<RootNamespace>VScriptAutoPatcher</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<SDLCheck>true</SDLCheck>
77+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
78+
<ConformanceMode>true</ConformanceMode>
79+
</ClCompile>
80+
<Link>
81+
<SubSystem>Console</SubSystem>
82+
<GenerateDebugInformation>true</GenerateDebugInformation>
83+
</Link>
84+
</ItemDefinitionGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
86+
<ClCompile>
87+
<WarningLevel>Level3</WarningLevel>
88+
<FunctionLevelLinking>true</FunctionLevelLinking>
89+
<IntrinsicFunctions>true</IntrinsicFunctions>
90+
<SDLCheck>true</SDLCheck>
91+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92+
<ConformanceMode>true</ConformanceMode>
93+
</ClCompile>
94+
<Link>
95+
<SubSystem>Console</SubSystem>
96+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
97+
<OptimizeReferences>true</OptimizeReferences>
98+
<GenerateDebugInformation>true</GenerateDebugInformation>
99+
</Link>
100+
</ItemDefinitionGroup>
101+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
102+
<ClCompile>
103+
<WarningLevel>Level3</WarningLevel>
104+
<SDLCheck>true</SDLCheck>
105+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
106+
<ConformanceMode>true</ConformanceMode>
107+
<LanguageStandard>stdcpplatest</LanguageStandard>
108+
</ClCompile>
109+
<Link>
110+
<SubSystem>Console</SubSystem>
111+
<GenerateDebugInformation>true</GenerateDebugInformation>
112+
</Link>
113+
</ItemDefinitionGroup>
114+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
115+
<ClCompile>
116+
<WarningLevel>Level3</WarningLevel>
117+
<FunctionLevelLinking>true</FunctionLevelLinking>
118+
<IntrinsicFunctions>true</IntrinsicFunctions>
119+
<SDLCheck>true</SDLCheck>
120+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
121+
<ConformanceMode>true</ConformanceMode>
122+
<LanguageStandard>stdcpp20</LanguageStandard>
123+
</ClCompile>
124+
<Link>
125+
<SubSystem>Console</SubSystem>
126+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
127+
<OptimizeReferences>true</OptimizeReferences>
128+
<GenerateDebugInformation>true</GenerateDebugInformation>
129+
</Link>
130+
</ItemDefinitionGroup>
131+
<ItemGroup>
132+
<ClCompile Include="VScriptAutoPatcher.cpp" />
133+
</ItemGroup>
134+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
135+
<ImportGroup Label="ExtensionTargets">
136+
</ImportGroup>
135137
</Project>

0 commit comments

Comments
 (0)