Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
[Common] Repo reorganization + add HibikiPillarPatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
ActualMandM committed Apr 5, 2023
1 parent 8064d5d commit 7ce62b3
Show file tree
Hide file tree
Showing 26 changed files with 390 additions and 169 deletions.
File renamed without changes.
98 changes: 98 additions & 0 deletions Dependencies/Helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#pragma once

#define _CONCAT2(x, y) x##y
#define CONCAT2(x, y) _CONCAT(x, y)
#define INSERT_PADDING(length) \
uint8_t CONCAT2(pad, __LINE__)[length]

#define ASSERT_OFFSETOF(type, field, offset) \
static_assert(offsetof(type, field) == offset, "offsetof assertion failed")

#define ASSERT_SIZEOF(type, size) \
static_assert(sizeof(type) == size, "sizeof assertion failed")

#ifdef BASE_ADDRESS
const HMODULE MODULE_HANDLE = GetModuleHandle(nullptr);

#define ASLR(address) \
((size_t)MODULE_HANDLE + (size_t)address - (size_t)BASE_ADDRESS)
#endif

#define FUNCTION_PTR(returnType, callingConvention, function, location, ...) \
returnType (callingConvention *function)(__VA_ARGS__) = (returnType(callingConvention*)(__VA_ARGS__))(location)

#define PROC_ADDRESS(libraryName, procName) \
GetProcAddress(LoadLibrary(TEXT(libraryName)), procName)

#define HOOK(returnType, callingConvention, functionName, location, ...) \
typedef returnType callingConvention _##functionName(__VA_ARGS__); \
_##functionName* original##functionName = (_##functionName*)(location); \
returnType callingConvention implOf##functionName(__VA_ARGS__)

#define INSTALL_HOOK(functionName) \
do { \
DetourTransactionBegin(); \
DetourUpdateThread(GetCurrentThread()); \
DetourAttach((void**)&original##functionName, implOf##functionName); \
DetourTransactionCommit(); \
} while(0)

#define VTABLE_HOOK(returnType, callingConvention, className, functionName, ...) \
typedef returnType callingConvention className##functionName(className* This, __VA_ARGS__); \
className##functionName* original##className##functionName; \
returnType callingConvention implOf##className##functionName(className* This, __VA_ARGS__)

#define INSTALL_VTABLE_HOOK(className, object, functionName, functionIndex) \
do { \
if (original##className##functionName == nullptr) \
{ \
original##className##functionName = (*(className##functionName***)object)[functionIndex]; \
DetourTransactionBegin(); \
DetourUpdateThread(GetCurrentThread()); \
DetourAttach((void**)&original##className##functionName, implOf##className##functionName); \
DetourTransactionCommit(); \
} \
} while(0)

#define WRITE_MEMORY(location, type, ...) \
do { \
const type data[] = { __VA_ARGS__ }; \
DWORD oldProtect; \
VirtualProtect((void*)(location), sizeof(data), PAGE_EXECUTE_READWRITE, &oldProtect); \
memcpy((void*)(location), data, sizeof(data)); \
VirtualProtect((void*)(location), sizeof(data), oldProtect, &oldProtect); \
} while(0)

#define WRITE_JUMP(location, function) \
do { \
WRITE_MEMORY((size_t)(location), uint8_t, 0x48, 0xB8); \
WRITE_MEMORY((size_t)(location) + 2, uint64_t, (uint64_t)(function)); \
WRITE_MEMORY((size_t)(location) + 10, uint8_t, 0xFF, 0xE0); \
} while(0)

#define WRITE_CALL(location, function) \
do { \
WRITE_MEMORY((size_t)(location), uint8_t, 0x48, 0xB8); \
WRITE_MEMORY((size_t)(location) + 2, uint64_t, (uint64_t)(function)); \
WRITE_MEMORY((size_t)(location) + 10, uint8_t, 0xFF, 0xD0); \
} while(0)

#define WRITE_NOP(location, count) \
do { \
DWORD oldProtect; \
VirtualProtect((void*)(location), (size_t)(count), PAGE_EXECUTE_READWRITE, &oldProtect); \
for (size_t i = 0; i < (size_t)(count); i++) \
*((uint8_t*)(location) + i) = 0x90; \
VirtualProtect((void*)(location), (size_t)(count), oldProtect, &oldProtect); \
} while(0)

inline uint32_t readUnalignedU32(void* memory)
{
uint8_t* p = (uint8_t*)memory;
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
}

inline void versionWarning(LPCTSTR modName)
{
MessageBox(nullptr, TEXT("Failed to initialize! Please make sure that the Hi-Fi-RUSH executable matches the MD5 hash and try again.\nMD5: 5F0E371201CB33D8813D21337526F063"), modName, MB_ICONERROR);
}
File renamed without changes.
26 changes: 26 additions & 0 deletions HibikiPillarPatch/DllMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "Signature.h"

SIG_SCAN
(
sigPillarbox,
0x143F283C5,
"\xF6\x41\x30\x01\x45\x0F\x29\x43\x00",
"xxxxxxxx?"
);

BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
{
if (reason == DLL_PROCESS_ATTACH)
{
if (sigValid)
{
WRITE_MEMORY((char*)sigPillarbox() + 3, uint8_t, 0);
}
else
{
versionWarning(TEXT("HibikiPillarPatch"));
}
}

return TRUE;
}
31 changes: 31 additions & 0 deletions HibikiPillarPatch/HibikiPillarPatch.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HibikiPillarPatch", "HibikiPillarPatch.vcxproj", "{E985DEF2-A8F3-4161-B92E-9F77AA80F7C3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E985DEF2-A8F3-4161-B92E-9F77AA80F7C3}.Debug|x64.ActiveCfg = Debug|x64
{E985DEF2-A8F3-4161-B92E-9F77AA80F7C3}.Debug|x64.Build.0 = Debug|x64
{E985DEF2-A8F3-4161-B92E-9F77AA80F7C3}.Debug|x86.ActiveCfg = Debug|Win32
{E985DEF2-A8F3-4161-B92E-9F77AA80F7C3}.Debug|x86.Build.0 = Debug|Win32
{E985DEF2-A8F3-4161-B92E-9F77AA80F7C3}.Release|x64.ActiveCfg = Release|x64
{E985DEF2-A8F3-4161-B92E-9F77AA80F7C3}.Release|x64.Build.0 = Release|x64
{E985DEF2-A8F3-4161-B92E-9F77AA80F7C3}.Release|x86.ActiveCfg = Release|Win32
{E985DEF2-A8F3-4161-B92E-9F77AA80F7C3}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F118A005-C71C-45D5-890A-6EB72E31DE6E}
EndGlobalSection
EndGlobal
188 changes: 188 additions & 0 deletions HibikiPillarPatch/HibikiPillarPatch.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{e985def2-a8f3-4161-b92e-9f77aa80f7c3}</ProjectGuid>
<RootNamespace>HibikiPillarPatch</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TargetExt>.asi</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(ProjectDir)Dependencies\Detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>Pch.h</PrecompiledHeaderFile>
<ForcedIncludeFiles>Pch.h</ForcedIncludeFiles>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>detours.lib;syelog.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\Dependencies\Detours\lib\x86</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\Dependencies;..\Dependencies\Detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>Pch.h</PrecompiledHeaderFile>
<ForcedIncludeFiles>Pch.h</ForcedIncludeFiles>
<PreprocessorDefinitions>_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>detours.lib;syelog.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\Dependencies\Detours\lib\x64</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(ProjectDir)Dependencies\Detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>Pch.h</PrecompiledHeaderFile>
<ForcedIncludeFiles>Pch.h</ForcedIncludeFiles>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>detours.lib;syelog.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\Dependencies\Detours\lib\x86</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\Dependencies;..\Dependencies\Detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>Pch.h</PrecompiledHeaderFile>
<ForcedIncludeFiles>Pch.h</ForcedIncludeFiles>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>detours.lib;syelog.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\Dependencies\Detours\lib\x64</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="DllMain.cpp" />
<ClCompile Include="Pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
10 changes: 10 additions & 0 deletions HibikiPillarPatch/HibikiPillarPatch.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClInclude Include="Pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="DllMain.cpp" />
<ClCompile Include="Pch.cpp" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions HibikiPillarPatch/Pch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Pch.h"
15 changes: 15 additions & 0 deletions HibikiPillarPatch/Pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#define WIN32_LEAN_AND_MEAN

// Detours
#include <Windows.h>
#include <detours.h>

// Standard library
#include <cstdint>
#include <cstdio>

// Dependencies
#include <Helpers.h>
#include <Signature.h>
2 changes: 2 additions & 0 deletions HibikiPillarPatch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# HibikiPillarPatch
An ASI plugin for Hi-Fi RUSH that patches out the letter/pillar boxing that appears under certain circumstances.
4 changes: 1 addition & 3 deletions HibikiSigPatch/DllMain.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "Signature.h"

SIG_SCAN
(
sigUTOCSignature,
Expand All @@ -18,7 +16,7 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
}
else
{
MessageBox(nullptr, TEXT("Failed to initialize! Please make sure that the Hi-Fi-RUSH executable matches the MD5 hash and try again.\nMD5: 5F0E371201CB33D8813D21337526F063"), TEXT("HibikiSigPatch"), MB_ICONERROR);
versionWarning(TEXT("HibikiSigPatch"));
}
}

Expand Down
Loading

0 comments on commit 7ce62b3

Please sign in to comment.