From e187c3dd8427dfe177c6291d39b36a834b282603 Mon Sep 17 00:00:00 2001 From: UCyborg Date: Sun, 16 Sep 2018 05:47:02 +0200 Subject: [PATCH] Initial commit --- .gitignore | 332 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 19 +++ dllmain.c | 87 +++++++++++++ hl-mp3-fix.dsp | 110 ++++++++++++++++ hl-mp3-fix.dsw | 29 +++++ 5 files changed, 577 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 dllmain.c create mode 100644 hl-mp3-fix.dsp create mode 100644 hl-mp3-fix.dsw diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7f4738e --- /dev/null +++ b/.gitignore @@ -0,0 +1,332 @@ +# Created by https://www.gitignore.io/api/windows,codeblocks,linux,c,visualstudio + +### Windows ### +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + + +### CodeBlocks ### +# specific to CodeBlocks IDE +*.cbp +*.layout +*.depend + +# generated directories +bin/ +obj/ + + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + + +### C ### +# Object files +*.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ + + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# Database files +*.db +*.opendb + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml diff --git a/README.md b/README.md new file mode 100644 index 0000000..6f5f7ae --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Half-Life 1.1.1.0 MP3 Fix + +Small ASI plugin that fixes the issue with not playing correct MP3 files when playing expansion packs/mods with the old pre-Steam version of Half-Life. +For example, you would always hear the Half-Life soundtrack even if playing Half-Life: Opposing Force. + +Ability to play MP3 files as a substitute for playing soundtrack from CD first appeared with patch 1.1.0.8. It was an undocumented feature that only +became official with Steam version of Half-Life. Please refer to your Steam Half-Life installation directoy to see how files should be named: + +### Half-Life + +\steamapps\common\half-life\valve\media + +### Half-Life: Opposing Force + +\steamapps\common\half-life\gearbox\media + +### Half-Life: Blue Shift + +\steamapps\common\half-life\bshift\media diff --git a/dllmain.c b/dllmain.c new file mode 100644 index 0000000..d67e2f0 --- /dev/null +++ b/dllmain.c @@ -0,0 +1,87 @@ +#define _CRT_SECURE_NO_WARNINGS +#define WIN32_LEAN_AND_MEAN + +#include +#include +#include + +#pragma comment(lib, "Version") + +int (__stdcall *O_AIL_open_stream)(void *, char *, int); +int __stdcall H_AIL_open_stream(void *ptr, char *stream, int arg3) +{ + char szPath[MAX_PATH]; + char *temp; + int ret; + char *basePath = (char *)0x3CFA788; + + temp = strrchr(basePath, '/'); + + sprintf(szPath, "%s%s", temp ? temp + 1 : basePath, stream + 5); + if (ret = O_AIL_open_stream(ptr, szPath, arg3)) return ret; + + return O_AIL_open_stream(ptr, stream, arg3); +} + +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + DWORD_PTR dwPatchBase; + DWORD dwOldProtect; + + if (fdwReason == DLL_PROCESS_ATTACH) + { + char szPath[MAX_PATH]; + DWORD dwSize; + DWORD dwHandle; + void *pVersionInfo; + char *pStringFileInfoValue; + UINT fileInfoLen; + + DisableThreadLibraryCalls(hinstDLL); + + GetModuleFileName(NULL, szPath, sizeof(szPath)); + + if (!(dwSize = GetFileVersionInfoSize(szPath, &dwHandle))) + { + goto fail; + } + + if (!(pVersionInfo = malloc(dwSize))) + { + goto fail; + } + + if (!GetFileVersionInfo(szPath, dwHandle, dwSize, pVersionInfo) + || !VerQueryValue(pVersionInfo, "\\StringFileInfo\\040904b0\\FileDescription", (LPVOID *)&pStringFileInfoValue, &fileInfoLen) + || strcmp(pStringFileInfoValue, "Half-Life Launcher") + || !VerQueryValue(pVersionInfo, "\\StringFileInfo\\040904b0\\FileVersion", (LPVOID *)&pStringFileInfoValue, &fileInfoLen) + || strcmp(pStringFileInfoValue, "1, 1, 1, 0")) + { + free(pVersionInfo); +fail: return FALSE; + } + + free(pVersionInfo); + + dwPatchBase = 0x4AD7E8; + VirtualProtect((LPVOID)dwPatchBase, sizeof(DWORD_PTR), PAGE_READWRITE, &dwOldProtect); + + (DWORD_PTR)O_AIL_open_stream = *(DWORD_PTR *)dwPatchBase; + *(DWORD_PTR *)dwPatchBase = (DWORD_PTR)H_AIL_open_stream; + + VirtualProtect((LPVOID)dwPatchBase, sizeof(DWORD_PTR), dwOldProtect, &dwOldProtect); + } + else if (fdwReason == DLL_PROCESS_DETACH) + { + if (O_AIL_open_stream) + { + dwPatchBase = 0x4AD7E8; + VirtualProtect((LPVOID)dwPatchBase, sizeof(DWORD_PTR), PAGE_READWRITE, &dwOldProtect); + + *(DWORD_PTR *)dwPatchBase = (DWORD_PTR)O_AIL_open_stream; + + VirtualProtect((LPVOID)dwPatchBase, sizeof(DWORD_PTR), dwOldProtect, &dwOldProtect); + } + } + return TRUE; +} diff --git a/hl-mp3-fix.dsp b/hl-mp3-fix.dsp new file mode 100644 index 0000000..d832199 --- /dev/null +++ b/hl-mp3-fix.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="hl-mp3-fix" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=hl-mp3-fix - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "hl-mp3-fix.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "hl-mp3-fix.mak" CFG="hl-mp3-fix - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "hl-mp3-fix - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "hl-mp3-fix - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "hl-mp3-fix - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "hl-mp3-fix_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "hl-mp3-fix_EXPORTS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x424 /d "NDEBUG" +# ADD RSC /l 0x424 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x6a500000" /dll /pdb:none /machine:I386 /out:"Release/hl_mp3_fix.asi" /opt:nowin98 + +!ELSEIF "$(CFG)" == "hl-mp3-fix - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "hl-mp3-fix_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "hl-mp3-fix_EXPORTS" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x424 /d "_DEBUG" +# ADD RSC /l 0x424 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x6a500000" /dll /debug /machine:I386 /out:"Debug/hl_mp3_fix.asi" /pdbtype:sept /opt:nowin98 +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "hl-mp3-fix - Win32 Release" +# Name "hl-mp3-fix - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\dllmain.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/hl-mp3-fix.dsw b/hl-mp3-fix.dsw new file mode 100644 index 0000000..7fc37b6 --- /dev/null +++ b/hl-mp3-fix.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "hl-mp3-fix"=".\hl-mp3-fix.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### +