From 2d5ae1026e72ff5f504d4e9e70b807268b5ef1a9 Mon Sep 17 00:00:00 2001 From: VDm Date: Sun, 25 Feb 2024 23:48:27 +0400 Subject: [PATCH] chore(sound): update SI2::Init() --- src/sound/SI2.cpp | 34 ++++++++++++++++++++++++++++++++-- src/sound/SI2.hpp | 2 ++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/sound/SI2.cpp b/src/sound/SI2.cpp index ef00636..eef2cca 100644 --- a/src/sound/SI2.cpp +++ b/src/sound/SI2.cpp @@ -3,6 +3,9 @@ #include "console/CVar.hpp" #include +FMOD::System* SI2::sm_pGameSystem = nullptr; +FMOD::System* SI2::sm_pChatSystem = nullptr; + void* F_CALL FMOD_Alloc(unsigned int size, FMOD_MEMORY_TYPE type, const char* sourcestr) { return SMemAlloc(size, sourcestr, 0, 0); } @@ -32,8 +35,35 @@ int32_t SI2::Init(int32_t flag) { SI2_LOG("=> Setting up Game Sound:"); SI2_LOG(" - SESound Engine Init"); - auto errcode = FMOD::Memory_Initialize(nullptr, 0, &FMOD_Alloc, &FMOD_ReAlloc, &FMOD_Free); - SI2_ERR(errcode, " - FMOD Memory Init"); + SI2_LOG(" - FMOD Memory Init"); + FMOD::Memory_Initialize(nullptr, 0, &FMOD_Alloc, &FMOD_ReAlloc, &FMOD_Free); + // sub_877440(&off_B1D5E4); + + SI2_LOG(" - FMOD System Create"); + auto errcode = FMOD::System_Create(&sm_pGameSystem); + if (errcode) { + if (errcode != FMOD_ERR_DSP_SILENCE && errcode != FMOD_ERR_INVALID_VECTOR && errcode != FMOD_ERR_RECORD) { + SI2_ERR(errcode, ""); + } + SI2_LOG(" -###########################################################################################"); + SI2_ERR(errcode, " -######## ERROR INITIALIZING. ALL GAME SOUND DISABLED."); + SI2_LOG(" -###########################################################################################"); + sm_pGameSystem->setOutput(FMOD_OUTPUTTYPE_NOSOUND); + goto LABEL_9; + } + + errcode = FMOD::System_Create(&sm_pChatSystem); + if (errcode != FMOD_ERR_DSP_SILENCE && errcode != FMOD_ERR_INVALID_VECTOR && errcode != FMOD_ERR_RECORD) { + SI2_ERR(errcode, ""); + } + + if (sm_pChatSystem && sm_pChatSystem->init(4, FMOD_INIT_NORMAL, nullptr)) { + sm_pChatSystem->setOutput(FMOD_OUTPUTTYPE_NOSOUND); + } + + sm_pGameSystem->setOutput(FMOD_OUTPUTTYPE_AUTODETECT); + +LABEL_9: return 0; } diff --git a/src/sound/SI2.hpp b/src/sound/SI2.hpp index f4f3d43..088327c 100644 --- a/src/sound/SI2.hpp +++ b/src/sound/SI2.hpp @@ -18,6 +18,8 @@ class SI2 { static FrameScript_Method s_ScriptFunctions[]; static uint32_t sm_logFlags; static HSLOG sm_log; + static FMOD::System* sm_pGameSystem; + static FMOD::System* sm_pChatSystem; // Static functions static void RegisterScriptFunctions();