Skip to content

Commit aac5dac

Browse files
committed
Initial commit
1 parent 42cecbb commit aac5dac

11 files changed

Lines changed: 701 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,6 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
352+
Release/
353+
O2CSP/Release/

O2CSP.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32819.101
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "O2CSP", "O2CSP\O2CSP.vcxproj", "{00E3EC47-314A-4868-B361-123B3EE5A175}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{00E3EC47-314A-4868-B361-123B3EE5A175}.Debug|x64.ActiveCfg = Debug|x64
17+
{00E3EC47-314A-4868-B361-123B3EE5A175}.Debug|x64.Build.0 = Debug|x64
18+
{00E3EC47-314A-4868-B361-123B3EE5A175}.Debug|x86.ActiveCfg = Debug|Win32
19+
{00E3EC47-314A-4868-B361-123B3EE5A175}.Debug|x86.Build.0 = Debug|Win32
20+
{00E3EC47-314A-4868-B361-123B3EE5A175}.Release|x64.ActiveCfg = Release|x64
21+
{00E3EC47-314A-4868-B361-123B3EE5A175}.Release|x64.Build.0 = Release|x64
22+
{00E3EC47-314A-4868-B361-123B3EE5A175}.Release|x86.ActiveCfg = Release|Win32
23+
{00E3EC47-314A-4868-B361-123B3EE5A175}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {408925D0-1B99-4995-8C9C-AC1E26761329}
30+
EndGlobalSection
31+
EndGlobal

O2CSP/O2CSP.cpp

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#include "O2CSP.h"
2+
3+
#include "framework.h"
4+
5+
#include <iostream>
6+
7+
#include "mem.h"
8+
#include "winver.h"
9+
10+
// TODO: Everything should be done using RAII approach, Initialize-Finalize is C style and is not recommended.
11+
12+
float* f_scale = (float*)0x5EED34;
13+
14+
void ImulEDXHook()
15+
{
16+
int valueEDX = 0;
17+
__asm {
18+
MOV valueEDX,EDX
19+
PUSH EAX
20+
};
21+
float f_result = *f_scale * valueEDX;
22+
int i_result = static_cast<int>(f_result);
23+
__asm {
24+
MOV EDX,i_result
25+
POP EAX
26+
};
27+
return;
28+
/**std::cout <<
29+
"Multiplier: " << *f_scale << "\n"
30+
"EDX: " << valueEDX << "\n"
31+
"Float result: " << f_result << "\n"
32+
"Int result: " << i_result << std::endl;**/
33+
}
34+
35+
void ImulECXHook()
36+
{
37+
int valueECX = 0;
38+
__asm {
39+
MOV valueECX, ECX
40+
PUSH EAX
41+
};
42+
float f_result = *f_scale * valueECX;
43+
int i_result = static_cast<int>(f_result);
44+
__asm {
45+
MOV ECX, i_result
46+
POP EAX
47+
};
48+
return;
49+
/**std::cout <<
50+
"Multiplier: " << *f_scale << "\n"
51+
"ECX: " << valueECX << "\n"
52+
"Float result: " << f_result << "\n"
53+
"Int result: " << i_result << std::endl;**/
54+
}
55+
56+
void ImulEBPHook()
57+
{
58+
int valueEBP = 0;
59+
__asm {
60+
PUSH EAX
61+
PUSH ECX
62+
MOV ECX,[EBP]
63+
MOV valueEBP,ECX
64+
};
65+
float f_result = *f_scale * valueEBP;
66+
int i_result = static_cast<int>(f_result);
67+
__asm {
68+
MOV ECX, i_result
69+
MOV [EBP],ECX
70+
POP ECX
71+
POP EAX
72+
SUB EAX,[EBP]
73+
};
74+
return;
75+
/**std::cout <<
76+
"Multiplier: " << *f_scale << "\n"
77+
"EDX: " << valueEDX << "\n"
78+
"Float result: " << f_result << "\n"
79+
"Int result: " << i_result << std::endl;**/
80+
}
81+
82+
void ImulEBPHook2()
83+
{
84+
int valueEBP = 0;
85+
__asm {
86+
PUSH EAX
87+
PUSH ECX
88+
MOV ECX, [EBP]
89+
MOV valueEBP, ECX
90+
};
91+
float f_result = *f_scale * valueEBP;
92+
int i_result = static_cast<int>(f_result);
93+
__asm {
94+
MOV ECX, i_result
95+
MOV[EBP], ECX
96+
POP ECX
97+
POP EAX
98+
SUB ECX, [EBP]
99+
};
100+
return;
101+
/**std::cout <<
102+
"Multiplier: " << *f_scale << "\n"
103+
"EDX: " << valueEDX << "\n"
104+
"Float result: " << f_result << "\n"
105+
"Int result: " << i_result << std::endl;**/
106+
}
107+
108+
uintptr_t moduleBase;
109+
110+
void ModifyScaleToFloat()
111+
{
112+
DWORD curProtection = 0;
113+
BOOL hResult = VirtualProtect((void*)(moduleBase + 0x07F6B0), 5, PAGE_EXECUTE_READWRITE, &curProtection);
114+
if (hResult == NULL)
115+
{
116+
std::cout << "couldn't set permission on overwrite destination" << std::endl;
117+
}
118+
char data[5] = { 0xD9, 0x5E, 0x10, 0xEB, 0x25 };
119+
char* segmentForReplace = (char*)(moduleBase + 0x07F6B0);
120+
for (int i = 0; i < 5; i++)
121+
{
122+
*segmentForReplace = data[i];
123+
segmentForReplace++;
124+
}
125+
DWORD temp = 0;
126+
hResult = VirtualProtect((void*)(moduleBase + 0x07F6B0), 5, curProtection, &temp);
127+
if (hResult == NULL)
128+
{
129+
// TODO: Throw an error.
130+
// https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualprotect#return-value
131+
}
132+
133+
hResult = VirtualProtect((void*)(moduleBase + 0x07E8E7), 1, PAGE_EXECUTE_READWRITE, &curProtection);
134+
char FMUL = 0xD8;
135+
segmentForReplace = (char*)(moduleBase + 0x07E8E7);
136+
*segmentForReplace = FMUL;
137+
hResult = VirtualProtect((void*)(moduleBase + 0x07E8E7), 1, curProtection, &temp);
138+
if (hResult == NULL)
139+
{
140+
// TODO: Throw an error.
141+
// https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualprotect#return-value
142+
}
143+
}
144+
145+
void O2CSP::Hook()
146+
{
147+
unsigned int g_win10Offset = 0;
148+
// TODO: check for errors.
149+
// https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulehandlea#return-value
150+
if ((moduleBase = (uintptr_t)GetModuleHandle("OTwo.exe")) == 0)
151+
{
152+
std::cout << "No OTwo.exe process found" << std::endl;
153+
return;
154+
}
155+
156+
double g_winver = getSysOpType();
157+
//g_winver = 10;
158+
if (g_winver >= 10)
159+
{
160+
f_scale = (float*)(0x5EED34 + g_win10Offset);
161+
}
162+
std::cout << "winver: " << g_winver << '\n';
163+
std::cout << "win10Offset: " << g_win10Offset << std::endl;
164+
165+
ModifyScaleToFloat();
166+
167+
mem::Detour32((void*)(moduleBase + 0x07E844), (void*)&ImulEDXHook, 7); // Apply scale for measure line position/speed
168+
mem::Detour32((void*)(moduleBase + 0x07E32B), (void*)&ImulECXHook, 7); // Apply scale for rice notes position/speed
169+
mem::Detour32((void*)(moduleBase + 0x07E428), (void*)&ImulEDXHook, 7); // Apply scale for long note head position/speed
170+
mem::Detour32((void*)(moduleBase + 0x07E45A), (void*)&ImulECXHook, 7); // Apply scale for long note tail position/speed
171+
mem::Detour32((void*)(moduleBase + 0x07E3A9), (void*)&ImulEBPHook, 5); // Apply scale for long note body start position/speed
172+
mem::Detour32((void*)(moduleBase + 0x07E3C0), (void*)&ImulEBPHook2, 5); // Apply scale for long note body end position/speed
173+
}

O2CSP/O2CSP.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
namespace O2CSP
4+
{
5+
void Hook();
6+
}

O2CSP/O2CSP.vcxproj

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{00e3ec47-314a-4868-b361-123b3ee5a175}</ProjectGuid>
25+
<RootNamespace>O2CSP</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>DynamicLibrary</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>MultiByte</CharacterSet>
34+
<PreferredToolArchitecture>x86</PreferredToolArchitecture>
35+
</PropertyGroup>
36+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
37+
<ConfigurationType>DynamicLibrary</ConfigurationType>
38+
<UseDebugLibraries>false</UseDebugLibraries>
39+
<PlatformToolset>v143</PlatformToolset>
40+
<WholeProgramOptimization>true</WholeProgramOptimization>
41+
<CharacterSet>MultiByte</CharacterSet>
42+
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
44+
<ConfigurationType>DynamicLibrary</ConfigurationType>
45+
<UseDebugLibraries>true</UseDebugLibraries>
46+
<PlatformToolset>v143</PlatformToolset>
47+
<CharacterSet>MultiByte</CharacterSet>
48+
<PreferredToolArchitecture>x86</PreferredToolArchitecture>
49+
</PropertyGroup>
50+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
51+
<ConfigurationType>DynamicLibrary</ConfigurationType>
52+
<UseDebugLibraries>false</UseDebugLibraries>
53+
<PlatformToolset>v143</PlatformToolset>
54+
<WholeProgramOptimization>true</WholeProgramOptimization>
55+
<CharacterSet>MultiByte</CharacterSet>
56+
</PropertyGroup>
57+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
58+
<ImportGroup Label="ExtensionSettings">
59+
</ImportGroup>
60+
<ImportGroup Label="Shared">
61+
</ImportGroup>
62+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
63+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
64+
</ImportGroup>
65+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
72+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
73+
</ImportGroup>
74+
<PropertyGroup Label="UserMacros" />
75+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
76+
<ClCompile>
77+
<WarningLevel>Level3</WarningLevel>
78+
<SDLCheck>true</SDLCheck>
79+
<PreprocessorDefinitions>WIN32;_DEBUG;O2CSP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
80+
<ConformanceMode>true</ConformanceMode>
81+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
82+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
83+
</ClCompile>
84+
<Link>
85+
<SubSystem>Windows</SubSystem>
86+
<GenerateDebugInformation>true</GenerateDebugInformation>
87+
<EnableUAC>false</EnableUAC>
88+
</Link>
89+
</ItemDefinitionGroup>
90+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
91+
<ClCompile>
92+
<WarningLevel>Level3</WarningLevel>
93+
<FunctionLevelLinking>true</FunctionLevelLinking>
94+
<IntrinsicFunctions>true</IntrinsicFunctions>
95+
<SDLCheck>true</SDLCheck>
96+
<PreprocessorDefinitions>WIN32;NDEBUG;O2CSP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
97+
<ConformanceMode>true</ConformanceMode>
98+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
99+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
100+
</ClCompile>
101+
<Link>
102+
<SubSystem>Windows</SubSystem>
103+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
104+
<OptimizeReferences>true</OptimizeReferences>
105+
<GenerateDebugInformation>true</GenerateDebugInformation>
106+
<EnableUAC>false</EnableUAC>
107+
</Link>
108+
</ItemDefinitionGroup>
109+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
110+
<ClCompile>
111+
<WarningLevel>Level3</WarningLevel>
112+
<SDLCheck>true</SDLCheck>
113+
<PreprocessorDefinitions>_DEBUG;O2CSP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
114+
<ConformanceMode>true</ConformanceMode>
115+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
116+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
117+
</ClCompile>
118+
<Link>
119+
<SubSystem>Windows</SubSystem>
120+
<GenerateDebugInformation>true</GenerateDebugInformation>
121+
<EnableUAC>false</EnableUAC>
122+
</Link>
123+
</ItemDefinitionGroup>
124+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
125+
<ClCompile>
126+
<WarningLevel>Level3</WarningLevel>
127+
<FunctionLevelLinking>true</FunctionLevelLinking>
128+
<IntrinsicFunctions>true</IntrinsicFunctions>
129+
<SDLCheck>true</SDLCheck>
130+
<PreprocessorDefinitions>NDEBUG;O2CSP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
131+
<ConformanceMode>true</ConformanceMode>
132+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
133+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
134+
</ClCompile>
135+
<Link>
136+
<SubSystem>Windows</SubSystem>
137+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
138+
<OptimizeReferences>true</OptimizeReferences>
139+
<GenerateDebugInformation>true</GenerateDebugInformation>
140+
<EnableUAC>false</EnableUAC>
141+
</Link>
142+
</ItemDefinitionGroup>
143+
<ItemGroup>
144+
<ClInclude Include="framework.h" />
145+
<ClInclude Include="O2CSP.h" />
146+
<ClInclude Include="mem.h" />
147+
<ClInclude Include="winver.h" />
148+
</ItemGroup>
149+
<ItemGroup>
150+
<ClCompile Include="dllmain.cpp" />
151+
<ClCompile Include="O2CSP.cpp" />
152+
<ClCompile Include="mem.cpp" />
153+
</ItemGroup>
154+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
155+
<ImportGroup Label="ExtensionTargets">
156+
</ImportGroup>
157+
</Project>

0 commit comments

Comments
 (0)