Skip to content

Commit

Permalink
Merge pull request #58 from hzqst/master
Browse files Browse the repository at this point in the history
Port to MetaHookSv and add support for the new HL25 engine
  • Loading branch information
LAGonauta authored Nov 19, 2023
2 parents 4067b82 + 25ee672 commit 1f75959
Show file tree
Hide file tree
Showing 16 changed files with 796 additions and 239 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
[submodule "externals/picojson"]
path = externals/picojson
url = https://github.com/kazuho/picojson/
[submodule "externals/MetaHookSv"]
path = externals/MetaHookSv
url = https://github.com/hzqst/MetaHookSv
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.9)

project(MetaAudio)

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

# Configure Alure2 the way we need it
option(METAAUDIO_STATIC_ALURE "Link Alure2 statically" ON)
if(METAAUDIO_STATIC_ALURE)
Expand Down Expand Up @@ -64,26 +66,24 @@ target_include_directories(MetaAudio
${PROJECT_SOURCE_DIR}/externals/steamaudio/include
${PROJECT_SOURCE_DIR}/externals/alure/include/AL
${PROJECT_SOURCE_DIR}/externals/openal-soft/include/AL
${PROJECT_SOURCE_DIR}/externals/metahook/include
${PROJECT_SOURCE_DIR}/externals/metahook/include/interface
${PROJECT_SOURCE_DIR}/externals/metahook/HLSDK/common
${PROJECT_SOURCE_DIR}/externals/metahook/HLSDK/cl_dll
${PROJECT_SOURCE_DIR}/externals/metahook/HLSDK/engine
${PROJECT_SOURCE_DIR}/externals/metahook/HLSDK/public
${PROJECT_SOURCE_DIR}/externals/metahook/HLSDK/pm_shared
${PROJECT_SOURCE_DIR}/externals/MetaHookSv
${PROJECT_SOURCE_DIR}/externals/MetaHookSv/Interface
${PROJECT_SOURCE_DIR}/externals/MetaHookSv/HLSDK/common
${PROJECT_SOURCE_DIR}/externals/MetaHookSv/HLSDK/cl_dll
${PROJECT_SOURCE_DIR}/externals/MetaHookSv/HLSDK/engine
${PROJECT_SOURCE_DIR}/externals/MetaHookSv/HLSDK/public
${PROJECT_SOURCE_DIR}/externals/MetaHookSv/HLSDK/pm_shared
${PROJECT_SOURCE_DIR}/externals/MetaHookSv/capstone/include/capstone
)

find_package(OpenAL REQUIRED)
add_subdirectory(externals/alure)

add_subdirectory(externals/metahook)

if ((MSVC) AND (MSVC_VERSION GREATER_EQUAL 1914))
# Force C++17 as mpark/variant doesn't compile with MSVC
set_property(TARGET ${ALURE2_LIBRARY} PROPERTY CXX_STANDARD 17)
target_compile_options(${ALURE2_LIBRARY} PUBLIC "/Zc:__cplusplus")
target_compile_options(MetaAudio PUBLIC "/Zc:__cplusplus")
target_compile_options(metahook PUBLIC "/Zc:__cplusplus")
endif()

add_dependencies(MetaAudio ${ALURE2_LIBRARY})
Expand Down
4 changes: 0 additions & 4 deletions build-MetaAudio.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ call cmake -B "build" -A Win32 -D "OPENAL_INCLUDE_DIR=%temp%\OpenAL-SDK\include"

call powershell -Command "(gc build\MetaAudio.vcxproj) -replace 'Label=\"PropertySheets\">', 'Label=\"PropertySheets\" ><Import Project=\"..\global.props\" /><Import Project=\"..\MetaAudio.props\" />' | Out-File build\MetaAudio.vcxproj"

call powershell -Command "(gc build\externals\alure\alure2.vcxproj) -replace 'Label=\"PropertySheets\">', 'Label=\"PropertySheets\" ><Import Project=\"..\..\..\global.props\" /><Import Project=\"..\..\..\alure2.props\" />' | Out-File build\externals\alure\alure2.vcxproj"

call powershell -Command "(gc build\externals\metahook\metahook.vcxproj) -replace 'Label=\"PropertySheets\">', 'Label=\"PropertySheets\" ><Import Project=\"..\..\..\global.props\" /><Import Project=\"..\..\..\metahook.props\" />' | Out-File build\externals\metahook\metahook.vcxproj"

for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
set InstallDir=%%i
)
Expand Down
1 change: 1 addition & 0 deletions externals/MetaHookSv
Submodule MetaHookSv added at a22041
3 changes: 2 additions & 1 deletion include/AudioEngine.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <unordered_map>
#include <sstream>

#include "snd_local.h"
#include "alure2.h"
Expand Down Expand Up @@ -76,7 +77,7 @@ namespace MetaAudio
void AL_ResetEFX();
void AL_Devices(bool basic);

void S_Startup();
int SNDDMA_Init();
void S_Init();
void S_Shutdown();

Expand Down
2 changes: 2 additions & 0 deletions include/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

#include "interface.h"
#include "IFileSystem.h"
#include <metahook.h>

extern IFileSystem *g_pFileSystem;
extern IFileSystem_HL25 *g_pFileSystem_HL25;
extern IFileSystem *g_pFullFileSystem;

#endif
6 changes: 0 additions & 6 deletions include/aud_int_internal.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#pragma once

typedef struct
{
}aud_export_t;

extern aud_export_t gAudExports;

#define META_AUDIO_VERSION "Meta Audio Version: 92b7efb1ffebb94e3d20ed89f6dd72b50264b16f"
20 changes: 12 additions & 8 deletions include/plugins.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
class IFileSystem;

extern HINSTANCE g_hInstance, g_hThisModule, g_hEngineModule;
extern DWORD g_dwEngineBase, g_dwEngineSize;
extern PVOID g_dwEngineBase;
extern DWORD g_dwEngineSize;
extern PVOID g_dwEngineTextBase;
extern DWORD g_dwEngineTextSize;
extern PVOID g_dwEngineDataBase;
extern DWORD g_dwEngineDataSize;
extern PVOID g_dwEngineRdataBase;
extern DWORD g_dwEngineRdataSize;
extern DWORD g_dwEngineBuildnum;
extern DWORD g_iVideoMode;
extern bool g_bIsNewEngine;
extern int g_iVideoWidth, g_iVideoHeight;
extern bool g_bWindowed;
extern bool g_bIsDebuggerPresent;
extern IFileSystem *g_pFileSystem;
extern int g_fExternalLoad;
extern int g_iEngineType;

extern IFileSystem* g_pFileSystem;
extern IFileSystem_HL25* g_pFileSystem_HL25;
5 changes: 4 additions & 1 deletion include/snd_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ struct aud_engine_t
int *cszrawsentences;

//s_dma.c
void(*S_Startup)(void);//hooked
int(*SNDDMA_Init)(void);//hooked
void(*S_Startup)(void);//deprecated, use SNDDMA_Init instead
void(*S_Init)(void);//hooked
void(*S_Shutdown)(void);//hooked
sfx_t *(*S_FindName)(char *name, int *pfInCache);//hooked
Expand Down Expand Up @@ -135,5 +136,7 @@ void S_FillAddress(void);

void S_InstallHook(MetaAudio::AudioEngine* engine, MetaAudio::SoundLoader* loader);

void S_UninstallHook();

//common
extern aud_engine_t gAudEngine;
33 changes: 11 additions & 22 deletions src/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,35 +644,22 @@ namespace MetaAudio
catch (const std::exception& e)
{
const size_t size = 4096;
char ar[size] = "Unable to load. Reason:\n";
int zero_index = 0;
for (int i = 0; i < size; ++i)
{
if (ar[i] == 0)
{
zero_index = i;
break;
}
}

for (int i = 0; i < size - zero_index; ++i)
{
if (e.what()[i] == 0 || i == size - zero_index - 1)
{
ar[i + zero_index] = '\0';
break;
}
std::stringstream ss;

ss << "Unable to load. Reason:\n";
ss << e.what();

auto msg = ss.str();
MessageBox(NULL, msg.c_str(), "OpenAL Error", MB_ICONERROR);

ar[i + zero_index] = e.what()[i];
}
MessageBox(NULL, ar, "OpenAL plugin error", MB_ICONERROR);
return false;
}
}

void AudioEngine::S_Startup()
int AudioEngine::SNDDMA_Init()
{
gAudEngine.S_Startup();
int r = gAudEngine.SNDDMA_Init();

//stop mute me first
openal_mute = false;
Expand All @@ -684,6 +671,8 @@ namespace MetaAudio
openal_started = true;
}
}

return r;
}

void AudioEngine::AL_Version()
Expand Down
4 changes: 3 additions & 1 deletion src/Effects/EnvEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <filesystem>
#include <algorithm>

#include "plugins.h"
#include "pm_defs.h"
#include "event_api.h"
#include "snd_local.h"
Expand Down Expand Up @@ -381,7 +382,8 @@ namespace MetaAudio
void EnvEffects::OverrideEffects()
{
std::array<char, 256> directory;
g_pInterface->FileSystem->GetCurrentDirectoryA(directory.data(), directory.size());

FILESYSTEM_ANY_GETCURRENTDIRECTORY(directory.data(), directory.size());

auto possible_file_names = { "efx-reverb.json", "efx-reverbs.json" };
EfxJsonReader reader;
Expand Down
23 changes: 12 additions & 11 deletions src/Loaders/GoldSrcFileBuf.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#include "Loaders/GoldSrcFileBuf.hpp"
#include "FileSystem.h"

Expand All @@ -7,7 +8,7 @@ namespace MetaAudio
{
if (mFile && gptr() == egptr())
{
auto got = g_pFileSystem->Read(mBuffer.data(), mBuffer.size(), mFile);
auto got = FILESYSTEM_ANY_READ(mBuffer.data(), mBuffer.size(), mFile);
if (got)
{
setg(mBuffer.data(), mBuffer.data(), mBuffer.data() + got);
Expand Down Expand Up @@ -44,9 +45,9 @@ namespace MetaAudio
if ((offset >= 0 && offset < off_type(egptr() - gptr())) ||
(offset < 0 && -offset <= off_type(gptr() - eback())))
{
auto initialPos = g_pFileSystem->Tell(mFile);
g_pFileSystem->Seek(mFile, static_cast<int>(offset), seekType);
auto newPos = g_pFileSystem->Tell(mFile);
auto initialPos = FILESYSTEM_ANY_TELL(mFile);
FILESYSTEM_ANY_SEEK(mFile, static_cast<int>(offset), seekType);
auto newPos = FILESYSTEM_ANY_TELL(mFile);
if (newPos - initialPos != offset)
{
return traits_type::eof();
Expand All @@ -58,14 +59,14 @@ namespace MetaAudio
break;

case std::ios_base::end:
offset += g_pFileSystem->Size(mFile);
offset += FILESYSTEM_ANY_SIZE(mFile);
break;

default:
return traits_type::eof();
}

g_pFileSystem->Seek(mFile, static_cast<int>(offset), seekType);
FILESYSTEM_ANY_SEEK(mFile, static_cast<int>(offset), seekType);
auto curPosition = g_pFileSystem->Tell(mFile);

setg(nullptr, nullptr, nullptr);
Expand All @@ -79,26 +80,26 @@ namespace MetaAudio
return traits_type::eof();
}

g_pFileSystem->Seek(mFile, static_cast<int>(pos), FILESYSTEM_SEEK_HEAD);
if (g_pFileSystem->EndOfFile(mFile))
FILESYSTEM_ANY_SEEK(mFile, static_cast<int>(pos), FILESYSTEM_SEEK_HEAD);
if (FILESYSTEM_ANY_EOF(mFile))
{
return traits_type::eof();
}
auto curPosition = g_pFileSystem->Tell(mFile);
auto curPosition = FILESYSTEM_ANY_TELL(mFile);

setg(nullptr, nullptr, nullptr);
return curPosition;
}

bool GoldSrcFileBuf::open(const char* filename) noexcept
{
mFile = g_pFileSystem->Open(filename, "rb");
mFile = FILESYSTEM_ANY_OPEN(filename, "rb");
return mFile;
}

GoldSrcFileBuf::~GoldSrcFileBuf()
{
g_pFileSystem->Close(mFile);
FILESYSTEM_ANY_CLOSE(mFile);
mFile = nullptr;
}
}
6 changes: 3 additions & 3 deletions src/Loaders/GoldSrcFileFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace MetaAudio

namebuffer.append(name);

auto fileExists = g_pFileSystem->FileExists(namebuffer.c_str());
auto fileExists = FILESYSTEM_ANY_FILEEXISTS(namebuffer.c_str());
if (!fileExists)
{
namebuffer.clear();
Expand All @@ -27,14 +27,14 @@ namespace MetaAudio
}
namebuffer.append(name);

fileExists = g_pFileSystem->FileExists(namebuffer.c_str());
fileExists = FILESYSTEM_ANY_FILEEXISTS(namebuffer.c_str());
}

alure::UniquePtr<std::istream> file;
if (fileExists)
{
char final_file_path[260]; // MAX_PATH
g_pFileSystem->GetLocalPath(namebuffer.c_str(), final_file_path, sizeof(final_file_path));
FILESYSTEM_ANY_GETLOCALPATH(namebuffer.c_str(), final_file_path, sizeof(final_file_path));
file = alure::MakeUnique<std::ifstream>(final_file_path, std::ios::binary);
if (file->fail())
{
Expand Down
57 changes: 4 additions & 53 deletions src/exportfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,10 @@ void Sys_ErrorEx(const char *fmt, ...)
if (gEngfuncs.pfnClientCmd)
gEngfuncs.pfnClientCmd("escape\n");

MessageBox(NULL, msg, "Error", MB_ICONERROR);
exit(0);
MessageBox(NULL, msg, "Fatal Error", MB_ICONERROR);
TerminateProcess((HANDLE)-1, 0);
}

cl_exportfuncs_t gClientfuncs =
{
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};

cl_enginefunc_t gEngfuncs;
cl_exportfuncs_t gClientfuncs ={ 0 };

aud_export_t gAudExports =
{
};
cl_enginefunc_t gEngfuncs = { 0 };
Loading

0 comments on commit 1f75959

Please sign in to comment.